cascardo/linux.git
8 years agogreybus: svc: implement connection_quiescing call
Jeffrey Carlyle [Tue, 7 Jun 2016 15:22:22 +0000 (08:22 -0700)]
greybus: svc: implement connection_quiescing call

Implement Greybus remote call to connection_quiescing operation. This
operation disables flow contorl for the connection and resets associated
attributes.

Testing done: tested along with required NuttX firmware changes, booted
EVT2, inserted module, removed module, inserted module. Verified module
was functioning as expected.

Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: timesync: Add debugfs entry to display frame-ping in ktime
Bryan O'Donoghue [Sun, 5 Jun 2016 13:03:30 +0000 (14:03 +0100)]
greybus: timesync: Add debugfs entry to display frame-ping in ktime

This patch makes a debugfs entry in
/sys/kernel/debug/greybus/X-svc/frame-ktime that generates a TimeSync ping
event to the system and then subsequently presents that data to user-space
as a ktime/timespec clock-monotonic value rather than as a raw frame-time,
to aid humans in debugging and understanding frame-time and to provide an
example of the converting a frame-time to timespec/ktime to other
developers.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Acked-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: timesync: Add gb_timesync_frame_time_to_timespec()
Bryan O'Donoghue [Sun, 5 Jun 2016 13:03:29 +0000 (14:03 +0100)]
greybus: timesync: Add gb_timesync_frame_time_to_timespec()

This patch adds gb_timesync_to_timespec_by_svc() and
gb_timesync_to_timespec_by_interface() respectively. These routines will
convert from a given FrameTime to a ktime/timespec within an envelope of
about 17 seconds. The purpose of this routine is to enable reporting of a
FrameTime from a Module such as a Camera Module and to allow the AP to
then convert this timestamp into a Linux-native timestamp such as ktime.
This is useful and required in the v4l layer.

At 19.2MHz the accuracy of this conversion is about .3 femtoseconds per
count, which means at a 1 second offset from the reference the cumulative
error is about 1.59 nanoseconds. 1.59 nanoseconds is still less than 1
clock's worth of error @ 19.2MHz where each clock is 52.0833~ nanoseconds.

We're aiming for a maximum error rate of 30 nanoseconds which means at the
clock rate we are running at, the conversion from a FrameTime to a Linux
ktime/timespec can be plus-or-minus about 17 seconds from the reference
FrameTime/ktime pair before the routine will refuse to convert.

A realistic use-case for this routine is envisaged to be

- Greybus message received
- Some processing takes place - taking milliseconds
- Call into this routine is made
- Actual time between event in Module and conversion in AP < 1 second
- Error rate in conversion at 1.59 nanoseconds is less than 1 clock
  @ 19.2MHz

This routine is not designed to allow for conversions for events with
large gaps between the event time and the current reference time for
conversion. Since FrameTime can be a very large integer we cannot convert
an arbitrarily large FrameTime to ktime, the feeling and objective here is
to make an over-provisioned envelope that in practical terms can never be
exceeded by expected use-cases. To convert longer gaps more work would have
to be done but ultimately some limit needs to be imposed and right now 0.3
femotseconds per clock on MSM8994 is both accurate and generous.

Adds:
- timesync.c::gb_timesync_frame_time_to_timespec_by_svc(
 struct gb_svc *,
 u64 frame_time,
                                                 struct timespec *ts)
  - gb_svc is a pointer to a standard greybus SVC data structure
  - frame_time is a system FrameTime.
  - ts is an output parameter which represents the converted FrameTime
    as a CLOCK_MONOTONIC timespec value.
  - Returns 0 on success or a negative number indicating the type of
    error on failure.

- timesync.c::gb_timesync_frame_time_to_timespec_by_interface(
 struct gb_interface *,
 u64 frame_time,
                                                 struct timespec *ts)
  - gb_svc is a pointer to a standard greybus Interface data structure
  - frame_time is a system FrameTime.
  - ts is an output parameter which represents the converted FrameTime
    as a CLOCK_MONOTONIC timespec value.
  - Returns 0 on success or a negative number indicating the type of
    error on failure.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Acked-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracepoints: Add standard Linux tracepoint for TimeSync event
Bryan O'Donoghue [Sun, 5 Jun 2016 13:03:28 +0000 (14:03 +0100)]
greybus: tracepoints: Add standard Linux tracepoint for TimeSync event

This patch adds a tracepoint to the TimeSync ISR, the purpose of which is
to indicate a TimeSync event has happened. This tracepoint can be enabled
by issuing the following command:

echo 1 > /sys/kernel/debug/tracing/events/greybus/gb_timesync_irq/enable

Synchronization looks like this:

 TIMESTAMP  FUNCTION
    |         |
147.865788: gb_timesync_irq: strobe 1/4 frame-time 2910076529
147.866781: gb_timesync_irq: strobe 2/4 frame-time 2910095689
147.867777: gb_timesync_irq: strobe 3/4 frame-time 2910114820
147.868791: gb_timesync_irq: strobe 4/4 frame-time 2910134038

A ping can be triggered like this:

cat /sys/kernel/debug/greybus/frame-time

And that ping looks like this:

 TIMESTAMP  FUNCTION
    |         |
147.934678: gb_timesync_irq: ping 4/4 frame-time 2911380356
169.280551: gb_timesync_irq: ping 4/4 frame-time 3321221069

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Acked-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: timesync: Bind TimeSync into Greybus
Bryan O'Donoghue [Sun, 5 Jun 2016 13:03:27 +0000 (14:03 +0100)]
greybus: timesync: Bind TimeSync into Greybus

TimeSync needs to bind into Greybus in a few places.

- core.c
  To initialize its internal state and tear-down its internal state.
  To schedule a timesync to a newly added Bundle after probe() completes.

- svc.c
  To get access to the SVC and enable/disable timesync as well as
  extracting the authoritative time from the SVC to subsequently
  disseminate to other entities in the system.

- interface.c
  To get access to an Interface in order to inform APBx of timesync
  enable/disable and authoritative operations.

This patch adds those bindings into Greybus core.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Acked-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: timesync: Add timesync core driver
Bryan O'Donoghue [Sun, 5 Jun 2016 13:03:26 +0000 (14:03 +0100)]
greybus: timesync: Add timesync core driver

This patch adds the core timesync functionality.

0. arche-platform.c/arche-apb-ctrl.c
   Modifies the platform layer to hook the incoming TIME_SYNC signal up to
   the timesync strobe IRQ handler. If the arche-platform driver can't
   satisfy the request for the wake-detect line, it will return -EAGAIN and
   the calling work-queue must reschedule the attempt to get exclusive
   access to the wake-detect pin logic. A private data field is added to
   the arche-platform driver to enable passing of a timesync pointer to the
   ISR responsible for synchronizing time.

1. timesync.c
   A new file added which contains all of the logic associated with sending
   greybus commands to SVC, APBx or Interfaces to enable, disable and
   disseminate timing information.

2. timesync_platform.c
   Any platform/arch specific code goes into timesync_platform.c.
   Originally the idea was to keep the x86 and ARM arch dependencies in a
   timesync_platform_arch.c file - however with further refinement that's
   currently not necessary however just-in-case it becomes necessary to
   resuscitate arch or platform specific methods for accessing timer
   resources that access shouldn't be part of the core timesync.c logic and
   so for the moment we access these timer resources through a thin access
   layer in timesync_platform.c. Expect this to go away long term ideally.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Acked-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio: Report DISCONNECT event after resource cleanup.
Vaibhav Agarwal [Fri, 3 Jun 2016 12:15:30 +0000 (17:45 +0530)]
greybus: audio: Report DISCONNECT event after resource cleanup.

Reporting DISCONNECT event immediately on module removal causes
race condition while re-populating mixer controls by above HAL. The
original intent was to avoid any (invalid) mixer control modification
request from above layer.

Ideally, it should report 'MODULE_NOT_READY' on module plug-out and
DISCONNECT after resource cleanup. This would involve changes in GB
Audio manager and HAL layer.

Since we already have a plan to remove GB Audio manager, I'm making this
change in GB codec driver to avoid any race condition. Also, codec
driver already ensures mixer control modifcations for disconnected
modules are not triggered to AP Bridge audio FW & reported invalid.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio: Report warning in case module is already removed
Vaibhav Agarwal [Fri, 3 Jun 2016 12:15:29 +0000 (17:45 +0530)]
greybus: audio: Report warning in case module is already removed

Added warning message in find_gb_module(). This will help to identify
invalid mixer control/widget modification triggered from above layer.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: fix message traces
Alex Elder [Fri, 3 Jun 2016 20:55:39 +0000 (15:55 -0500)]
greybus: tracing: fix message traces

The original message trace events were defined long before the
recent tracing updates.  It records information that's not
really directly related to a message.  Change the information
recorded and reported for message events to just be the content
of the message header.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: add timing traces
Alex Elder [Fri, 3 Jun 2016 20:55:38 +0000 (15:55 -0500)]
greybus: tracing: add timing traces

Bryan reports he used certain message traces to determine when time
sync messages transit the boundary between the Greybus core and the
host device.  This patch adds two trace events--one a message event
for outbound messages (because it indicates its operation and its
destination), and one host device event for incoming messages
(because message information isn't available as early as desired).
These events are being created to allow the same sort of analysis
of messages without having to store extra information for every
message trace.  (The next patch changes the information a message
trace records.)

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: define connection traces
Alex Elder [Fri, 3 Jun 2016 20:55:37 +0000 (15:55 -0500)]
greybus: tracing: define connection traces

Define a new gb_connection trace point event class, used to trace
events associated with the connection abstraction.  Define four basic
trace events for this--creation, drop of last reference, and when
adding or dropping any other reference.  There are certainly
more events that we might want to add, but aim is to just get the
basic framework in place.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: define bundle traces
Alex Elder [Fri, 3 Jun 2016 20:55:36 +0000 (15:55 -0500)]
greybus: tracing: define bundle traces

Define a new gb_bundle trace point event class, used to trace events
associated with the bundle abstraction.  Define four basic trace
points for this--creation time, drop of last reference, before
adding it to its interface and when removed when its interface
is destroyed.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: add interface mode_switch
Alex Elder [Fri, 3 Jun 2016 20:55:35 +0000 (15:55 -0500)]
greybus: tracing: add interface mode_switch

Add the value of an interface's mode_switch field to the information
tracked and reported for tracing.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: assign "parent" id first
Alex Elder [Fri, 3 Jun 2016 20:55:34 +0000 (15:55 -0500)]
greybus: tracing: assign "parent" id first

Most abstractions to be traced will have a sort of "parent" object
it is associated with, and an identifier for that parent is stored
with the as trace event data.  For example, the parent of a message
is the operation it's a part of, and the parent of an operation is
the connection it uses.

We'll arrange to define that parent id first in all events.  Most
abstractions already do this.  Move an interface's module id so it's
defined and assigned first.  The message traces are going to be
changed soon, so leave that one alone.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: fix module num_interfaces
Alex Elder [Fri, 3 Jun 2016 20:55:33 +0000 (15:55 -0500)]
greybus: tracing: fix module num_interfaces

A module's num_interfaces field is included in the data to be
recorded for tracing, but it's never assigned or reported.  Fix
its type to be size_t, to match its definition in the gb_module
structure.

Also correct a format length modifier used for a host device's
num_cports field.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: reorder trace definitions
Alex Elder [Fri, 3 Jun 2016 20:55:32 +0000 (15:55 -0500)]
greybus: tracing: reorder trace definitions

Move the definition of the module trace events below those for the
interface.  We'll define them in an order that represents a sort of
layering of the abstractions (note not all of these are defined yet):
    message
    operation
    connection
    bundle
    interface
    module
    host device
Other tracepoints (like perhaps some tied to timesync) will go at the
beginning or end.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: fix host device num_cports
Alex Elder [Fri, 3 Jun 2016 20:55:31 +0000 (15:55 -0500)]
greybus: tracing: fix host device num_cports

The type of the gb_host_device num_cports field is size_t.  Correct
the num_cports data recorded with a host device event so its type
matches that; fix the format length modifier used for it as well.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: define BUNDLE_ID_NONE
Alex Elder [Fri, 3 Jun 2016 20:55:30 +0000 (15:55 -0500)]
greybus: define BUNDLE_ID_NONE

Define a bundle ID that means "no bundle".  This will be used for
tracing connection events during the portion of a connection's
lifetime when it has no bundle associated with it.  Don't allow
any bundle to be created using that ID.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: fix "make check" warnings
Alex Elder [Fri, 3 Jun 2016 20:55:29 +0000 (15:55 -0500)]
greybus: tracing: fix "make check" warnings

Some of the trace buffer fields were defined as Booleans.  This
leads to two problems reported by "make check":
    - the __field() macro (or some descendent macro) performs
      a sizeof(bool) operation, which results in a warning
    - The TP_printk() macro, which specifies a printf() style
      format string, produces a warning when one attempts to
      format a Boolean as an integer.
Fix both problems implicitly converting Boolean values from the data
structures into integers in the trace buffer.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera-gb: Implement camera module reference counting as subject.
Evgeniy Borisov [Tue, 31 May 2016 08:33:11 +0000 (11:33 +0300)]
greybus: camera-gb: Implement camera module reference counting as subject.

In explanation:

The main idea for implementing reference counting is to not block exit
until any other modules are in use. Camera responsibility is to handle
properly any additional calls after camera exit and that what this
patch is doing:

1. Free camera module when reference count is zero.
2. After camera cleanup handle properly any additional ongoing
   transaction. Return error if connection is destroyed.

Signed-off-by: Evgeniy Borisov <eborisov@mm-sol.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera-gb: Extend gb camera module structure
Evgeniy Borisov [Tue, 31 May 2016 08:33:10 +0000 (11:33 +0300)]
greybus: camera-gb: Extend gb camera module structure

Add additional information in gb camera module.
 - interface ID
 - reference count
 - release handle

Signed-off-by: Evgeniy Borisov <eborisov@mm-sol.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera-gb: Add description of interface header
Evgeniy Borisov [Tue, 31 May 2016 08:33:09 +0000 (11:33 +0300)]
greybus: camera-gb: Add description of interface header

Add description for all interface structures in
gb-camera.h.

Signed-off-by: Evgeniy Borisov <eborisov@mm-sol.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Add comment about the mode_switch_started flag
Viresh Kumar [Mon, 30 May 2016 09:02:09 +0000 (14:32 +0530)]
greybus: Add comment about the mode_switch_started flag

Add a comment to describe the purpose of the flag.

Suggested-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: interface: Mode switch takes over a second
Viresh Kumar [Mon, 30 May 2016 07:35:10 +0000 (13:05 +0530)]
greybus: interface: Mode switch takes over a second

Mode switch takes just over a second to complete and the current timeout
of one second isn't sufficient.

Mode-switch logs from EVT 1.5:

[   56.709082] gb-firmware 1-3.3.1: Requested firmware package 'ara_00000126_00001002_fffe0001_ff980067_03.tftf'
[   57.003968] gb_control_mode_switch_operation: 176
[   58.041616] greybus 1-3.3: mode switch detected

Increase the timeout to two seconds.

Tested with EVT 1.5 with gpbridge-test module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Karthik Ravi Shankar <karthikrs@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: control: Mode-switch is a 'core' operation
Viresh Kumar [Mon, 30 May 2016 07:35:09 +0000 (13:05 +0530)]
greybus: control: Mode-switch is a 'core' operation

The operation layer allows only the 'core' operations on a connection,
which is in its 'disconnecting' state.

Mode switch is sent at the very end of interface-disable sequence, and
the control connection is already in its 'disconnecting' state at that
time. And so gb_operation_get_active() always fail with error -ENOTCONN.

The operation core already has support for such 'core' operations, just
that we were missing the needed flag while creating the mode switch
operation.

Fix that.

Tested on EVT 1.5 with gpbridge-test module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Karthik Ravi Shankar <karthikrs@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fw-mgmt: Add hooks to do mode-switch
Viresh Kumar [Mon, 30 May 2016 07:35:08 +0000 (13:05 +0530)]
greybus: fw-mgmt: Add hooks to do mode-switch

This is the last step to required to finish the mode switch story.  That
is, call the hook provided by Interface layer to accomplish mode switch.

Tested on EVT 1.5 with gpbridge-test module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Karthik Ravi Shankar <karthikrs@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: gbphy: Remove protocol specific version handling
Viresh Kumar [Mon, 30 May 2016 06:01:53 +0000 (11:31 +0530)]
greybus: gbphy: Remove protocol specific version handling

We should be using the generic version handling at bundle level, instead
of at protocol level for bridged PHY devices as well.

The bundle version handling is already in place, though it is *not* used
today as we haven't bumped the version of control protocol yet.

Remove protocol specific handling for bridged PHY devices.

Tested on EVT 1.5 with gpbridge-test module. No nuttx changes are
required with this.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Remove unused VERSION specific macros
Viresh Kumar [Mon, 30 May 2016 06:01:52 +0000 (11:31 +0530)]
greybus: Remove unused VERSION specific macros

We don't use these anymore. Drop them.

Note that some macro's specific to bridged PHY devices aren't removed in
the patch, as gbsim will break otherwise. They will be removed
separately.

Compile tested.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: wait for credits on shutdown
Axel Haslam [Tue, 31 May 2016 12:36:13 +0000 (14:36 +0200)]
greybus: uart: wait for credits on shutdown

We should try to wait until all credits are accounted
for before returning from shutdown.

For this purpose add a helper function that will
wait on completion, and call it form the shutdown.
This helper will also be useful when "wait until sent" is
implemented.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: Implement flush_buffer
Axel Haslam [Tue, 31 May 2016 12:36:12 +0000 (14:36 +0200)]
greybus: uart: Implement flush_buffer

Data may be held pening in the hardware because of flow
control mechanisms. When the port is closed, we need to flush
all data that was not sent.

For this, use the greybus message GB_UART_TYPE_FLUSH_FIFOS
which will flush all data queued on the module but not
yet sent on the data line.

Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: Add credits based tracking for transmit path
Axel Haslam [Tue, 31 May 2016 12:36:11 +0000 (14:36 +0200)]
greybus: uart: Add credits based tracking for transmit path

To avoid polling the firmware for space, a credit based system
is implemented.

The host will keep track of how many credits (bytes) it has
sent to the firmware, and stop sending data when the quota
is filled.

The host will be informed that the firmware has more
room for data when it handles the receive_credits request
message from the firmware, and will continue to write data
as credits become available.

The firmware and the host may implement an algorithm to aggregate
credits, and avoid extra greybus traffic.

Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: Use a fifo to send data to the modules
Axel Haslam [Tue, 31 May 2016 12:36:10 +0000 (14:36 +0200)]
greybus: uart: Use a fifo to send data to the modules

The firmware now buffers data instead of blocking while the transfer
is sent, and the write operation cannot sleep.

Instead of using gb_transfer_sync (which sleeps) in the write callback,
buffer data in a fifo and send it from from a work queue.

The write_room callback will will report 1 byte less that what is really
available in the fifo, to leave space for extra characters that may
be added by the tty layer.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: Implement dtr_rts callback.
Axel Haslam [Tue, 31 May 2016 12:36:09 +0000 (14:36 +0200)]
greybus: uart: Implement dtr_rts callback.

Dtr_dts allows the tty layer to set the flow control lines
to the correct state during open and close.

Note that locking for newctrl is missing throughout the
driver and will be addressed on a separate patch.

Suggested-and-reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: Handle CRTSCTS flag in termios
Axel Haslam [Tue, 31 May 2016 12:36:08 +0000 (14:36 +0200)]
greybus: uart: Handle CRTSCTS flag in termios

Handle the CRTSCTS flag in set_termios, so that auto
flow control can be turned off. For this, add a new flag
in the line coding request specifically for this purpose.

Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: hd: fix gb_hd_release tracepoint
Johan Hovold [Fri, 27 May 2016 16:23:01 +0000 (18:23 +0200)]
greybus: hd: fix gb_hd_release tracepoint

The recently added gb_hd_release tracepoint was added to the wrong
function.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fix tracepoint-related whitespace issues
Johan Hovold [Fri, 27 May 2016 16:23:02 +0000 (18:23 +0200)]
greybus: fix tracepoint-related whitespace issues

Fix some whitespace issues introduced by the recent tracepoint changes.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc: remove deprecated hotplug operations
Johan Hovold [Fri, 27 May 2016 15:26:41 +0000 (17:26 +0200)]
greybus: svc: remove deprecated hotplug operations

Now that firmware has made the switch to the new interface boot
sequence, we can remove support for the deprecated hotplug and
hot-unplug operations.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: interface: implement generic mode-switch functionality
Johan Hovold [Fri, 27 May 2016 15:26:40 +0000 (17:26 +0200)]
greybus: interface: implement generic mode-switch functionality

Add a generic interface for bundle drivers to use to request that a
mode switch is carried out on its behalf.

Mode switching involves tearing down all connections to an interface,
sending a unidirectional mode-switch request, and waiting for a mailbox
event that triggers deferred control connection reset and re-enumeration
of the interface. In case of a timeout waiting for the interface mailbox
event, or on other errors, the interface is powered off.

All of this needs to be done by core from work-queue context in order
not to block incoming SVC requests and bundle-device tear down. Care
must also be taken to serialise against concurrent module removal events
and eject requests.

Special handling of legacy mode-switching is also added in order to
continue to support the ES3 bootrom.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: control: add error message to mode-switch helper
Johan Hovold [Fri, 27 May 2016 15:26:39 +0000 (17:26 +0200)]
greybus: control: add error message to mode-switch helper

Print an informative error message in case sending the mode-switch
request fails.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: kernel_ver: backport reinit_completion to pre-3.13
Johan Hovold [Fri, 27 May 2016 15:26:38 +0000 (17:26 +0200)]
greybus: kernel_ver: backport reinit_completion to pre-3.13

Backport upstream reinit_completion() to pre-3.13 kernels.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: add flush host-device callback
Johan Hovold [Fri, 27 May 2016 15:26:37 +0000 (17:26 +0200)]
greybus: connection: add flush host-device callback

Add a new host-device callback to flush any host-device queues,
including any ongoing transfers, as part of connection tear down.

The host-device buffers are flushed after the disconnecting operation
have completed and the AP queues have been emptied.

This can be used to flush already queued messages which upon reception
would have been discarded by the remote end anyway.

Note that this does not remove the need to flush any host-device queues
as part of CPort disable which needs to make the CPort ready for reuse
after deallocating all associated state and resetting the port.

Suggested-by: Mitchell Tasman <tasman@leaflabs.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: implement proper connection closure
Johan Hovold [Fri, 27 May 2016 15:26:36 +0000 (17:26 +0200)]
greybus: connection: implement proper connection closure

Implement proper connection closure, which includes sending ping
requests on the connection being tore down while coordinating with the
remote interface as well as the SVC.

This specifically implements the new ping operation, which in case of
offloaded connections is handled by the host-device driver in an
implementation-defined manner through a new callback.

Note that the normal connection tear-down procedure is executed in case
of failed connection establishment due to failed connected operation.
Specifically, the disconnecting request is sent also in case the
connected operation never succeeded. This is needed since the interface
may have enabled FCT flow upon receiving the connected request.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: operation: add helper for creating core operations
Johan Hovold [Fri, 27 May 2016 15:26:35 +0000 (17:26 +0200)]
greybus: operation: add helper for creating core operations

Add a new core operation flag and a helper that core can use to create
core operations.

This will be used to implement the ping operations that core sends as
part of connection tear down.

Note that a new trace point is also added.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: operation: restructure activation state handling
Johan Hovold [Fri, 27 May 2016 15:26:34 +0000 (17:26 +0200)]
greybus: operation: restructure activation state handling

Restructure the operation activation state handling in preparation for a
new disconnecting state.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: operation: clean up early connection-state check
Johan Hovold [Fri, 27 May 2016 15:26:33 +0000 (17:26 +0200)]
greybus: operation: clean up early connection-state check

Now that the legacy invalid state is gone, clean up the early
connection-state check in the receive path and explicitly drop incoming
messages for disabled connection.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: remove unused invalid state
Johan Hovold [Fri, 27 May 2016 15:26:32 +0000 (17:26 +0200)]
greybus: connection: remove unused invalid state

Remove the unused legacy INVALID connection state.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: move CPort Buffer configuration out of svc helpers
Johan Hovold [Fri, 27 May 2016 15:26:31 +0000 (17:26 +0200)]
greybus: connection: move CPort Buffer configuration out of svc helpers

The CPort Buffer configuration in the host-device needs to match the
CPort feature flags set by the SVC, but they need not always be
configured at the same point in time.

This will be used when implementing proper connection tear down.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: rename an error label
Johan Hovold [Fri, 27 May 2016 15:26:30 +0000 (17:26 +0200)]
greybus: connection: rename an error label

Rename an error label to make it more descriptive.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: es2: reset cports at disable
Johan Hovold [Fri, 27 May 2016 15:26:29 +0000 (17:26 +0200)]
greybus: es2: reset cports at disable

Make sure to reset CPorts at disable rather than enable as per
specification.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: log cport-enable error messages
Johan Hovold [Fri, 27 May 2016 15:26:28 +0000 (17:26 +0200)]
greybus: connection: log cport-enable error messages

Log failures to disable a host cport, and include the connection name in
cport enable/disable error messages.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc: add stub connection-quiescing operation
Johan Hovold [Fri, 27 May 2016 15:26:27 +0000 (17:26 +0200)]
greybus: svc: add stub connection-quiescing operation

Add stubbed out connection-quiescing operation that is needed for proper
connection tear down.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: control: implement disconnecting operation
Johan Hovold [Fri, 27 May 2016 15:26:26 +0000 (17:26 +0200)]
greybus: control: implement disconnecting operation

Implement the new disconnecting control operation needed for proper
connection tear down.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: add control connection flag
Johan Hovold [Fri, 27 May 2016 15:26:25 +0000 (17:26 +0200)]
greybus: connection: add control connection flag

Add control connection flag which will be set for control connections.

Also add a helper function to test if the flag is set.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: interface: avoid I/O to bootrom during removal
Johan Hovold [Fri, 27 May 2016 15:26:24 +0000 (17:26 +0200)]
greybus: interface: avoid I/O to bootrom during removal

Add an interface quirk flag to suppress I/O during interface disable.

This is needed to prevent I/O to the bootrom during controlled
connection tear down (e.g. eject or driver unbind). This will be more
obvious with the new connection tear-down procedure.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: interface: clean up bootrom quirk handling
Johan Hovold [Fri, 27 May 2016 15:26:23 +0000 (17:26 +0200)]
greybus: interface: clean up bootrom quirk handling

Clean up bootrom quirk handling in preparation for addition of further
flags.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: core: avoid I/O to disconnected interfaces
Johan Hovold [Fri, 27 May 2016 15:26:22 +0000 (17:26 +0200)]
greybus: core: avoid I/O to disconnected interfaces

Add new helper to disable connections to interfaces that have already
been disconnected (e.g. forcibly removed).

The connection tear-down procedure differs enough depending on whether
the interface is still present or already gone to warrant a dedicated
helper. This will become more obvious with the new tear-down procedure,
which involves I/O on the connection being tore down.

This also simplifies handling of the legacy bootrom, which does not
support the new tear-down operations.

Specifically, this allows us to remove the early control-connection
tear down during interface disable, and also avoids some error messages
currently printed during legacy mode switch (i.e. bootrom
boot-over-UniPro) and forcible removal.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: drop a bogus semicolon
Alex Elder [Tue, 24 May 2016 18:34:52 +0000 (13:34 -0500)]
greybus: drop a bogus semicolon

Coccinelle reports that gb_svc_pwrmon_debugfs_init() has a block of
a for loop which is followed by an unnecessary semicolon.  Get rid
of that semicolon.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: use PTR_ERR_OR_ZERO()
Alex Elder [Tue, 24 May 2016 18:34:51 +0000 (13:34 -0500)]
greybus: use PTR_ERR_OR_ZERO()

Coccinelle points out that the macro PTR_ERR_OR_ZERO() handles the
frequent case of converting a pointer into either error code (if its
value is an encoded error value) or 0 (otherwise).  Switch some code
in gb_power_supply_register() to use that macro.  I have verified
this is true of the kernel we're now working with (arche-6.0).

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fix pointless null check
Alex Elder [Tue, 24 May 2016 18:34:50 +0000 (13:34 -0500)]
greybus: fix pointless null check

Coccinelle points out that a call in gb_lights_channel_free() to
flush_work() is passed which is always non-null.   Prior to the
call, there is an unnecessary check to see if that address is null.
Get rid of the test.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: eliminate unneeded null check
Alex Elder [Tue, 24 May 2016 18:34:49 +0000 (13:34 -0500)]
greybus: eliminate unneeded null check

Coccinelle points out that debugfs_remove_recursive() handles a null
argument properly, so there's no need to check for NULL before
making the call.  I have verified this is true of the kernel we're
now working with (arche-6.0).

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fix unbalanced mutex
Alex Elder [Tue, 24 May 2016 18:34:48 +0000 (13:34 -0500)]
greybus: fix unbalanced mutex

Running "make coccicheck" on the Greybus code reports that
gb_mmc_get_ro() and gb_mmc_get_cd() can return without releasing
the mutex it acquired if there's an error.  Fix this.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: report right error value
Alex Elder [Tue, 24 May 2016 18:34:47 +0000 (13:34 -0500)]
greybus: report right error value

Running "make coccicheck" on the Greybus code discovered that
an error message in gb_camera_debugfs_init() was interpreting
the wrong value in reporting the error code.  Fix that.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: es2: Release reserved cports CDSI0 and CDSI1
Vaibhav Agarwal [Fri, 27 May 2016 05:19:24 +0000 (10:49 +0530)]
greybus: es2: Release reserved cports CDSI0 and CDSI1

Unique ids were reserved for CDSI0 and CDSI1 during _probe, however
missed to release those ids during disconnect. This causes a memory leak
of 128 bytes for each iteration of unipro_reset. Fix this.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: hd: Add API to release reserved CPorts
Vaibhav Agarwal [Fri, 27 May 2016 05:19:23 +0000 (10:49 +0530)]
greybus: hd: Add API to release reserved CPorts

It is required to release all unique ids registered via ida_get_simple
to avoid any possible memory leak. cport_release() already exists with
special handling for ES2_CPORT_CDSI1, i.e. updating in_use flag without
removing associated ida.

So, added another API to release reserved cports CDSI0 and CDSI1. This
is intended to  be used only during es2_destroy().

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: define interface traces
Alex Elder [Tue, 24 May 2016 04:05:32 +0000 (23:05 -0500)]
greybus: tracing: define interface traces

Define a new gb_module trace point event class, used to trace events
associated with the interface abstraction.  Define four basic trace
points for this--creation time, drop of last reference, before
registring interfaces and after de-registering them.  In addition,
define traces for activating and deactivating, and enabling and
disabling an interface.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: add module traces
Alex Elder [Tue, 24 May 2016 04:05:31 +0000 (23:05 -0500)]
greybus: tracing: add module traces

Define a new gb_module trace point event class, used to trace events
associated with the module abstraction.  Define four basic trace
points for this--creation time, drop of last reference, before
registring interfaces and after de-registering them.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: fix hd traces
Alex Elder [Tue, 24 May 2016 04:05:30 +0000 (23:05 -0500)]
greybus: tracing: fix hd traces

Currently there are two trace points defined for the Greybus host
device structure.  One records information when a message gets sent,
and another when it gets received.  Neither of these is really a
host device event.

We have trace points defined for messages that dump information
about all sent and received messages.  As a result, the information
about sending messages over a host is redundant, and can go away.
(Note that the message traces may need a little refinement so they
produce all desired information.)

Instead of these trace points, define some that are directly
related to the host device abstraction: when one is created,
added, deleted, or released (destroyed).  These do not require
a CPort ID or payload size, so eliminate those two parameters
from the host device trace point prototype.  Change the trace
information recorded for a host device to be just a subset of
interesting fields in a host device.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: fix a bad tracepoint
Alex Elder [Tue, 24 May 2016 04:05:29 +0000 (23:05 -0500)]
greybus: tracing: fix a bad tracepoint

In gb_operation_put_active(), the wrong trace point is being called.
Fix that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: remove redundant latency-tag sanity checks
Johan Hovold [Wed, 25 May 2016 20:18:15 +0000 (22:18 +0200)]
greybus: remove redundant latency-tag sanity checks

Core will never call host-device callbacks with invalid arguments (and
that would still need to be verified in bridge firmware anyway), so
remove the redundant and insufficient sanity check from the callbacks.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: interface: fix svc-resource error messages
Johan Hovold [Wed, 25 May 2016 20:18:14 +0000 (22:18 +0200)]
greybus: interface: fix svc-resource error messages

The interface svc-resource helper are used to enable as well as disable
the corresponding SVC resources so make sure the error messages reflect
that.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Documentation/sysfs: gbphy0 is an invalid name
Viresh Kumar [Wed, 25 May 2016 07:19:26 +0000 (12:49 +0530)]
greybus: Documentation/sysfs: gbphy0 is an invalid name

The numbering of gbphy devices is going to start from 1 and not 0.
Reflect the same in sysfs hierarchy.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Documentation/sysfs: Rename gpbridge to gbphy
Viresh Kumar [Wed, 25 May 2016 07:16:24 +0000 (12:46 +0530)]
greybus: Documentation/sysfs: Rename gpbridge to gbphy

These were left in the earlier renaming series, fix them as well.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Fix loopback app after rename to gpphy
Axel Haslam [Tue, 24 May 2016 14:21:29 +0000 (16:21 +0200)]
greybus: Fix loopback app after rename to gpphy

commit 6d94670 gpbridge: rename 'gpbridge' to 'gbphy' everywhere
missed renaming the loopback test app. So do it too.

Testing done: complie and run loopback test

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Enable SVC clock during FW_FLASHING state
Vaibhav Hiremath [Tue, 24 May 2016 13:02:04 +0000 (18:32 +0530)]
greybus: arche-platform: Enable SVC clock during FW_FLASHING state

The issue is, as part of kernel-only build we started seeing
failures in SVC FW flashing. It was reproducible easily in kernel-only
build, but never observed on Android build.

During debugging, there were couple of observations,

1. If SVC clock enabled and disables (which is REFCLK_MAIN), then SVC FW
   flashing works.
2. If we do not switch SVC to HSE (external clock source) it works.
   Recently, SVC code has been updated to switch HSE clock, so removing
   it (remove/skip rcc_switch_ara_pll() fn) would use internal clock only.

As per STM32 spec, for flashing through USART we do not need
to enable HSE, but the above observation contradicts with it.

There is still something missing in terms of understanding of how STM32
device functions as far as Flashing is concerned. There is something
hidden in HW, which probably still need to identify.

So as a interim solution we will enable clock for FW_FLASHING state,
which seems to be fixing the issue here.

Testing Done: Tested on EVT1.5 with arche6.0 and kernel-only build.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Enter ACTIVE state only from OFF state
Vaibhav Hiremath [Tue, 24 May 2016 13:02:03 +0000 (18:32 +0530)]
greybus: arche-platform: Enter ACTIVE state only from OFF state

Make sure that, transition to active state happens only from OFF state.
Instead of imposing the restriction to user-space, driver internally
switches to OFF state and then to ACTIVE state.

Testing Done: Tested on EVT1.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Make fw_flashing_seq() return error
Vaibhav Hiremath [Tue, 24 May 2016 13:02:02 +0000 (18:32 +0530)]
greybus: arche-platform: Make fw_flashing_seq() return error

Make arche_platform_fw_flashing_seq() return error value, needed
later when we add clock enable support for FW flashing.

Testing Done: Tested on EVT1.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Revert "update UniPro Set Interface Power Mode operation to match spec"
Jeffrey Carlyle [Wed, 25 May 2016 23:38:47 +0000 (16:38 -0700)]
greybus: Revert "update UniPro Set Interface Power Mode operation to match spec"

This reverts commit 29fee8c55b59bb6ac59b99a0563c89c514cba42b.

This change and its companion NuttX changes seem to be triggering a
storm of POWERMODEIND switch interrupts on the SVC.

Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Acked-by: Sandeep Patil <sspatil@google.com>
8 years agogreybus: update UniPro Set Interface Power Mode operation to match spec
Eli Sennesh [Mon, 16 May 2016 18:55:17 +0000 (14:55 -0400)]
greybus: update UniPro Set Interface Power Mode operation to match spec

Bring the gb_svc_intf_set_power_mode() up-to-date with the current Greybus
specification.  This largely involves adding more members to the structure
sent across the wire.  Also change the camera code to use the new
operation properly, with default values passed for the new necessary
arguments.  The correctness of these default values is confirmed via testing
and by asking Rob Johnson.

Testing Done: Took a picture with a camera module, received error code
when passing deliberately incorrect values for new parameters, got proper
-EIO and Greybus result code printed when operation stopped halfway
through.

Associated Firmware Changes: 6810-6812 on Gerrit for SW-1239, 6870 and
5612-5613 on Gerrit for SW-2945

Signed-off-by: Eli Sennesh <esennesh@leaflabs.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Fix unbalanced irq_enable() backtrace
Bryan O'Donoghue [Mon, 23 May 2016 14:01:08 +0000 (15:01 +0100)]
greybus: Fix unbalanced irq_enable() backtrace

Tip-of-tree is exhibiting a backtrace when loading-up the set of greybus
kernel modules due to calling arche_platform_wd_irq_en() directly after a
call to devm_request_threaded_irq().

At the point we call arch_platform_wd_irq_en() the relevant IRQ will
already be enabled. What we want to do in this situation is configure the
GPIO line as an input. This patch fixes the backtrace by supplanting
arche_platform_wd_irq_en() with
gpio_direction_input(arche_pdata->wake_detect_gpio) in
arche_platform_probe().

WARNING: at msm-ara-3.10/kernel/irq/manage.c:457 __enable_irq+0x74/0xc0()
Unbalanced enable for IRQ 687
Modules linked in: gb_arche(O+) gb_camera(O) gb_es2(O) gb_vibrator(O)
gb_raw(O) gb_power_supply(O) gb_loopback(O) gb_light(O) gb_hid(O)
greybus(O)
CPU: 0 PID: 415 Comm: insmod Tainted: G        W  O 3.10.78-g2a4dec8 #65
Call trace:
[<ffffffc000206adc>] dump_backtrace+0x0/0x248
[<ffffffc000206d34>] show_stack+0x10/0x1c
[<ffffffc000c6c698>] dump_stack+0x1c/0x28
[<ffffffc00021c95c>] warn_slowpath_common+0x74/0x9c
[<ffffffc00021c9d0>] warn_slowpath_fmt+0x4c/0x58
[<ffffffc000269d7c>] __enable_irq+0x70/0xc0
[<ffffffc000269e34>] enable_irq+0x68/0x7c
[<ffffffbffc0609b4>] arche_platform_probe+0x3b4/0x4f4 [gb_arche]
[<ffffffc0005ace30>] platform_drv_probe+0x14/0x20
[<ffffffc0005ab980>] driver_probe_device+0x160/0x374
[<ffffffc0005abc40>] __driver_attach+0x60/0x90
[<ffffffc0005aa768>] bus_for_each_dev+0x74/0x94
[<ffffffc0005ab2c4>] driver_attach+0x1c/0x28
[<ffffffc0005aae74>] bus_add_driver+0x124/0x248
[<ffffffc0005ac270>] driver_register+0x94/0x110
[<ffffffc0005ad3c4>] platform_driver_register+0x58/0x64
[<ffffffbffc065020>] $x+0x20/0x58 [gb_arche]
[<ffffffc0002007dc>] do_one_initcall+0xb0/0x14c
[<ffffffc00028252c>] load_module+0x19d0/0x1b18
[<ffffffc00028278c>] SyS_init_module+0x118/0x130

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiermath@linaro.org>
Tested-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio: Fix memory leak
Vaibhav Agarwal [Mon, 23 May 2016 18:01:14 +0000 (23:31 +0530)]
greybus: audio: Fix memory leak

Topology data pointer was mistakenly set to NULL before freeing it. Fix
this.

Fixes: 64a86d9ba850 ("audio: Add module specific driver")
Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: legacy: remove protocol.o from the makefile
David Lin [Sat, 21 May 2016 01:37:02 +0000 (18:37 -0700)]
greybus: legacy: remove protocol.o from the makefile

Commit 0917cba11 ("legacy: remove legacy driver support")
removed protocol.c, however, the corresponding target in the Makefile
was not removed therefore broken the build.

Testing Done:
- Build & boot on EVT1.5

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: refine comments
Alex Elder [Fri, 20 May 2016 16:44:57 +0000 (11:44 -0500)]
greybus: tracing: refine comments

I believe that duplicating the tracepoint name in comments prior to
the tracepoint is redundant, and doesn't add a lot of value.

I also believe that we can provide a little more information about
what exactly an event means, or when exactly it is called.

I don't claim this is a huge improvement, but it's a proposal.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: eliminate "location" comments
Alex Elder [Fri, 20 May 2016 16:44:56 +0000 (11:44 -0500)]
greybus: tracing: eliminate "location" comments

Each message event has a set of comments preceeding its definition.
One of them, "location", indicates where that event is used.  I
am certain that this comment will become out of date very easily.
Hopefully just the name of the event is a good enough suggestion
about where it will be used.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: define events using macros
Alex Elder [Fri, 20 May 2016 16:44:55 +0000 (11:44 -0500)]
greybus: tracing: define events using macros

A tracepoint event is defined with TP_PROTO() and TP_ARGS macros
that match that of the event's class.  A lot of repetition (and
opportunity for inadvertent errors) in tracepoint event definitions
can be eliminated by using a macro.  Define and use class-specific
event definition macros for gb_message and gb_host_device class
events.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: add operation traces
Alex Elder [Fri, 20 May 2016 16:59:57 +0000 (11:59 -0500)]
greybus: add operation traces

Define a new gb_operation event class, and define and use trace
events that record when an operation is created, finally destroyed,
and when its active count changes.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: legacy: remove legacy driver support
David Lin [Fri, 20 May 2016 11:33:36 +0000 (14:33 +0300)]
greybus: legacy: remove legacy driver support

This patch removes the greybus legacy driver support

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: Convert to bundle driver
Laurent Pinchart [Fri, 20 May 2016 11:33:35 +0000 (14:33 +0300)]
greybus: camera: Convert to bundle driver

Convert the legacy camera protocol driver to a bundle driver.

Modules now can (and must) declare the camera data cport in their
manifest as the data connection isn't hardcoded anymore.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fw-management: Fix error message's text
Viresh Kumar [Thu, 19 May 2016 12:56:27 +0000 (18:26 +0530)]
greybus: fw-management: Fix error message's text

Just reword it to make it sound better.

Compile tested.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fw-core: destroy connections on error
Viresh Kumar [Thu, 19 May 2016 12:57:25 +0000 (18:27 +0530)]
greybus: fw-core: destroy connections on error

In one of the error cases we aren't destroying the connections created
earlier. Fix it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc: use EREMOTEIO for remote errors
Johan Hovold [Thu, 19 May 2016 14:20:16 +0000 (16:20 +0200)]
greybus: svc: use EREMOTEIO for remote errors

Return -EREMOTEIO consistently for unspecified remote errors (e.g. a
failed DME attribute read due to a remote UniPro error).

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio_apbridgea: fix two return values
Johan Hovold [Thu, 19 May 2016 14:20:15 +0000 (16:20 +0200)]
greybus: audio_apbridgea: fix two return values

Errno -ENOSYS is reserved for missing syscalls, replace it with
-EOPNOTSUPP for the the two stub operations that used it.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc: fix another pwrmon return value
Johan Hovold [Thu, 19 May 2016 14:20:14 +0000 (16:20 +0200)]
greybus: svc: fix another pwrmon return value

Errno -ENOSYS is reserved for missing syscalls, replace it with -ENOMSG.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Rename assert_wakedetect=>arche_platform_wd_irq_en
Vaibhav Hiremath [Tue, 17 May 2016 17:09:47 +0000 (22:39 +0530)]
greybus: arche-platform: Rename assert_wakedetect=>arche_platform_wd_irq_en

Now, since AP module does not send any signal to SVC, so it
automatically restricts the wake/detect gpio to input.
So rename assert_wakedetect() fn to arche_platform_wd_irq_en(),
as per implementation.

Testing Done: Tested on EVT1.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Do not assert wake/detect signal to SVC
Vaibhav Hiremath [Tue, 17 May 2016 17:09:46 +0000 (22:39 +0530)]
greybus: arche-platform: Do not assert wake/detect signal to SVC

With new definition of AP module boot flow (from HotPlug camp),
AP is not supposed to send any wake/detect signal to SVC, instead,
during boot SVC would straight away send wake_out pulse on wake/detect
line.
Note that, pin configuration of wake/detect line would be set to
active-high by default, so wake/detect line would always stay high,
unless SVC drives it. AP module uses wake/detect line strictly in input
mode.

Testing Done: Tested on EVT1.5 platform.

Note: We are yet to decide on PM support for APBx, so we may need to
generate/handshake with SVC over wake/detect line in the future. As of
now, follow the implementation and add stuff as and when they come.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: gpbridge: rename 'gpbridge' to 'gbphy' everywhere
Sandeep Patil [Thu, 19 May 2016 15:52:39 +0000 (08:52 -0700)]
greybus: gpbridge: rename 'gpbridge' to 'gbphy' everywhere

The 'gpbridge' name didn't relaly reflect what the bus is; which
is a bus for bridged-phy devices. So, rename all instances
of 'gpbridge' to more appropriate 'gbphy'

Testing Done:
Build and boot tested. 'lsgb' will stop displaying 'GPBridge' devices
until I change the library to reflect this change.

Signed-off-by: Sandeep Patil <patil_sandeep@projectara.com>
Suggested-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: interface: retry enumeration of UniPro-only modules
Jeffrey Carlyle [Thu, 19 May 2016 01:55:13 +0000 (18:55 -0700)]
greybus: interface: retry enumeration of UniPro-only modules

Greybus modules will sometimes fail to send the mailbox poke and
erroneously be enumerated as UniPro-only modules. The root cause for
this on the module side is not fully understand, but it seems that this
may be due to "the bootrom bug:" a known problem with the bootrom where
linkup will occasionally fail because of a race condition.

Before the new hotplug code was implemented in the firmware, the SVC
would retry enumeration of modules that did not send the mailbox poke;
this patch ports that functionality to the AP.

Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart fix missing negation on DTR setting
Axel Haslam [Mon, 16 May 2016 15:39:32 +0000 (17:39 +0200)]
greybus: uart fix missing negation on DTR setting

The unset the DTR flag is missing "~"

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: verify disabled when destroyed
Alex Elder [Tue, 17 May 2016 14:13:16 +0000 (09:13 -0500)]
greybus: connection: verify disabled when destroyed

A connection must be in DISABLED state before it gets destroyed.
Warn if this is ever not the case (and do the disconnect) before
proceeding with connection destruction.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio: gb_manager: Use valid argument while removing ida allocated id.
Vaibhav Agarwal [Tue, 17 May 2016 16:59:08 +0000 (22:29 +0530)]
greybus: audio: gb_manager: Use valid argument while removing ida allocated id.

module->id is used as an argument to ida_simple_remove(). Since module
is already dereferenced, module->id might contain invalid data. So fix
this.

Fixes: da4cc2d0b066 ("audio:gb_manager: Use proper locking around kobject_xxx")
Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: operation: fix broken activation logic
Johan Hovold [Wed, 18 May 2016 13:47:48 +0000 (15:47 +0200)]
greybus: operation: fix broken activation logic

An operation should only be added to the connection active list if the
connection is in the enabled state, or if it is in the enabled_tx state
and the operation is not incoming.

This fixes a race where an early or late incoming request could be added
to the active list while the connection is being enabled or disabled,
something which could lead to use-after-free issues or worse.

Note that the early connection-state checks in the receive path
limited the impact of this bug.

Fixes: e903a2ce7379 ("connection: add unidirectional enabled state")
Reported-by: Alex Elder <elder@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>