cascardo/linux.git
7 years agogreybus: svc: fix timeout indentation
Johan Hovold [Fri, 26 Aug 2016 10:59:45 +0000 (12:59 +0200)]
greybus: svc: fix timeout indentation

Make sure the timeout values are aligned.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: remove obsolete cport-reset ARPC
Johan Hovold [Fri, 26 Aug 2016 10:55:51 +0000 (12:55 +0200)]
greybus: es2: remove obsolete cport-reset ARPC

Remove the now obsolete and redundant cport-reset ARPC, along with the
consequently unused cport_disable callback.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: hd/es2: remove obsolete callbacks
Johan Hovold [Fri, 26 Aug 2016 10:55:50 +0000 (12:55 +0200)]
greybus: hd/es2: remove obsolete callbacks

Remove the now obsolete ping and cport_features_enable/disable
callbacks.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: connection: implement new connection handling
Johan Hovold [Fri, 26 Aug 2016 10:55:49 +0000 (12:55 +0200)]
greybus: connection: implement new connection handling

Implement the new connection setup and tear-down sequences for control
connections and bundle connections (offloaded and non-offloaded).

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: implement shutdown callback
Johan Hovold [Fri, 26 Aug 2016 10:55:48 +0000 (12:55 +0200)]
greybus: es2: implement shutdown callback

Implement the shutdown callback which is used to execute shutdown
operations on offloaded connections.

This adds a new shutdown ARPC.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: implement flush callback
Johan Hovold [Fri, 26 Aug 2016 10:55:47 +0000 (12:55 +0200)]
greybus: es2: implement flush callback

Implement the flush callback which is called as part of connection tear
down to flush host-device queues and stop any ongoing transfers.

Note that this should be considered an optimisation of sort since if
the CPort is stuck waiting for credit, the CPort is likely still stuck
when we try to send the cport_shutdown request over it after the
callback returns.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: power_supply: fix name setting location
Rui Miguel Silva [Fri, 26 Aug 2016 10:52:05 +0000 (11:52 +0100)]
greybus: power_supply: fix name setting location

We were checking for existing power supply names in the wrong place,
i.e, we were checking before any of the module power supply were
registered, because of that of course no name collision was detected.

Move the check to the register loop and with that we guarantee that this
mechanism works for greybus power supply naming.

Tested: using gbsim and using power supply with the same name and check
that: 1. no problems creating sysfs entries; 2. naming is done following
the desired rules.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: lights: Control runtime pm suspend/resume on AP side
Kris Huang [Thu, 25 Aug 2016 08:57:14 +0000 (16:57 +0800)]
greybus: lights: Control runtime pm suspend/resume on AP side

According to runtime pm architecture, the kernel side driver should be
as smart as needed to know when the module is idle or active, so that it can
issue the suspend/resume operations to the firmware side at the right time.
To add logics prevents AP from issuing the suspend request to the firmware
when a channel turning to active state, and put it to suspend if the state
is going to inactive with still holding a reference.

Testing Done: Compiled and verified on EVT2 and gpbridge-test module
              with device class daughter board.

Signed-off-by: Kris Huang <huang_kris@projectara.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: light: fix incorrect led attribute files allocation
David Lin [Mon, 22 Aug 2016 22:51:11 +0000 (15:51 -0700)]
greybus: light: fix incorrect led attribute files allocation

Fix incorrect attribute size when the channel supports fader, as well as
fixing the issue that the attribute list is not null terminated.

Testing Done:
 - Verified by setting brightness and color on red/green/blue leds
   of the device class test board.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: Fix incorrect direction value when enabling RX
Mark Greer [Sat, 20 Aug 2016 23:25:06 +0000 (16:25 -0700)]
greybus: audio: Fix incorrect direction value when enabling RX

The direction value passed to gb_audio_apbridgea_register_cport()
in the gbaudio_module_enable_rx() routine is TX and not RX like
it should be so fix it.

Testing Done: Recorded microphone data from a headset.

Signed-off-by: Mark Greer <mgreer@animalcreek.com>
Fixes: c80e7c6fafa5 ("audio: Split helper APIs based on stream direction")
Tested-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewd-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: svc: drop unnecessary symbol exports
Johan Hovold [Fri, 19 Aug 2016 07:42:21 +0000 (09:42 +0200)]
greybus: svc: drop unnecessary symbol exports

The svc functions are only supposed to be called by core and should not
be exported.

Most of these functions should never have been exported in the first
place, while a few no longer needs to be (e.g. since core gained support
for offloaded connections).

The only remaining exception is gb_svc_intf_set_power_mode() which is
needed by the camera driver until proper link management is in place.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: Revert "svc: drop all symbol exports"
Greg Kroah-Hartman [Thu, 18 Aug 2016 19:30:19 +0000 (21:30 +0200)]
greybus: Revert "svc: drop all symbol exports"

This reverts commit a0e559d03bbb3f9774a091e31c0f77d98db1f60d.

It breaks the camera driver :(

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: svc: drop all symbol exports
Johan Hovold [Thu, 18 Aug 2016 15:43:22 +0000 (17:43 +0200)]
greybus: svc: drop all symbol exports

The svc functions are only supposed to be called by core and should not
be exported.

Most of these functions should never have been exported in the first
place, while a few no longer needs to be (e.g. since core gained support
for offloaded connections).

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: power_supply: invalidate cache at update request
Rui Miguel Silva [Tue, 16 Aug 2016 21:31:57 +0000 (22:31 +0100)]
greybus: power_supply: invalidate cache at update request

When we receive a update request we shall not trust the cache mechanism
and for that we need a way to invalidate the cache. Add a field that
will control the cache status and refactor the code to check if cache is
valid in a helper function.

This will fix the scenario where an update request is received within
the cache expiration time after a previous update as happened and would
be ignored.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: power_supply: fix update interval check at request handler
Rui Miguel Silva [Tue, 16 Aug 2016 21:31:56 +0000 (22:31 +0100)]
greybus: power_supply: fix update interval check at request handler

We use the update interval to control the remove path and we set it to
zero when we do not want to have more updates in transit. That means
that the check in the request handler needs to be for interval update
zero to discard the newly received request and not the other way around
like it is.

This will fix the issue that all incoming requests were being discard.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: power_supply: add callback to handle power supply changes
Rui Miguel Silva [Tue, 16 Aug 2016 21:31:55 +0000 (22:31 +0100)]
greybus: power_supply: add callback to handle power supply changes

When checking for property changes we may need to act upon that change
besides reporting it using power_supply_changed. So, add a function that
will be call if the specific property changed.

As at it, adjust some indentation of the psy_props_changes array.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: Use valid control pointer while freeing memory
Vaibhav Agarwal [Tue, 16 Aug 2016 07:06:51 +0000 (12:36 +0530)]
greybus: Use valid control pointer while freeing memory

While releasing memory during error path exit, invalid memory pointer
was used for dapm_routes. Use a valid one.

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>
7 years agogreybus: audio: Add check for invalid index while mapping control
Vaibhav Agarwal [Tue, 16 Aug 2016 07:06:50 +0000 (12:36 +0530)]
greybus: audio: Add check for invalid index while mapping control

While mapping control id to define DAPM routes, invalid control index
may cause kernel oops. Add extra check to validate index while mapping
names to control_id.

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>
7 years agogreybus: Add workqueue to handle vibrator timeout
Ann Chen [Wed, 17 Aug 2016 08:38:56 +0000 (16:38 +0800)]
greybus: Add workqueue to handle vibrator timeout

In the beginning, module side can control the vibrator timeout value,
it can disable vibrator until timeout. But after Runtime PM control added
in, AP side didn't know when module can be suspended, the vibrator
task will be interrupted by suspending event.

Because of this problem, the module can not be in charge of counting down
the timeout value, it is now up to the AP to manage this. So add workqueue
to handle the vibrator timeout.

Signed-off-by: Ann Chen <chen_ann@projectara.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: fix memory leak in probe error path
Johan Hovold [Wed, 17 Aug 2016 13:43:32 +0000 (15:43 +0200)]
greybus: es2: fix memory leak in probe error path

In case a bulk-in transfer-buffer allocation failed during probe, we'd
currently leak the corresponding URB.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: camera: Remove support for legacy modules
Jacopo Mondi [Fri, 12 Aug 2016 08:05:41 +0000 (10:05 +0200)]
greybus: camera: Remove support for legacy modules

Remove support for module implementing legacy version of camera bandwidth
requirements specifications, now that all available camera modules have
been updated to use the new version

Signed-off-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: firmware: add comment to show size calculations
Viresh Kumar [Thu, 11 Aug 2016 20:27:25 +0000 (13:27 -0700)]
greybus: firmware: add comment to show size calculations

The firmware file name's maximum length is set to 56 right now, but it
isn't very much readable how we got to that value (unless someone reads
that line).

Update the comment to show calculations.

Reported-by: Alex Elder <alex.elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: firmware: s/should/must
Viresh Kumar [Thu, 11 Aug 2016 20:27:24 +0000 (13:27 -0700)]
greybus: firmware: s/should/must

Replace 'should' with 'must' to clear the expectation a bit more.

Reported-by: Alex Elder <alex.elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: firmware: s/_LEN/_SIZE
Viresh Kumar [Thu, 11 Aug 2016 20:27:23 +0000 (13:27 -0700)]
greybus: firmware: s/_LEN/_SIZE

Alex Elder pointed out that the macros also count the trailing NULL
('\0') character and so it should be using SIZE instead of LEN.

This patch makes that change.

Reported-by: Alex Elder <alex.elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: firmware: Remove extra parenthesis
Viresh Kumar [Thu, 11 Aug 2016 20:27:22 +0000 (13:27 -0700)]
greybus: firmware: Remove extra parenthesis

Remove the unnecessary parenthesis.

Reported-by: Alex Elder <alex.elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: firmware: Fix typo in documentation
Viresh Kumar [Wed, 10 Aug 2016 17:48:32 +0000 (10:48 -0700)]
greybus: firmware: Fix typo in documentation

s/shall be used the user/shall be used by the user/

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: firmware: use 'tag' instead of 'firmware_tag'
Viresh Kumar [Wed, 10 Aug 2016 17:48:31 +0000 (10:48 -0700)]
greybus: firmware: use 'tag' instead of 'firmware_tag'

We already have another direct pointer for this, use that instead.

Testing Done: Compiled.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: control: make disconnecting a core operation
Johan Hovold [Wed, 10 Aug 2016 10:58:46 +0000 (12:58 +0200)]
greybus: control: make disconnecting a core operation

Make the control-protocol disconnecting operation a "core" operation.

This is needed to be able to use the operation in the new connection
tear-down sequence of control connections, which moves disconnecting
after the flush barrier.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: hd: add cport_shutdown callback
Johan Hovold [Wed, 10 Aug 2016 10:58:45 +0000 (12:58 +0200)]
greybus: hd: add cport_shutdown callback

Add a host-device cport_shutdown callback which will be called as part
of the new connection tear-down sequence for offloaded connection in
order to do a cport_shutdown operation on behalf of the AP.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: hd/es2: add cport_clear callback and ARPC
Johan Hovold [Wed, 10 Aug 2016 10:58:44 +0000 (12:58 +0200)]
greybus: hd/es2: add cport_clear callback and ARPC

Add a host-device cport_clear callback, which will be called as part
of the new connection tear-down sequence to reset the CPort state.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: hd/es2: add cport_quiesce callback and ARPC
Johan Hovold [Wed, 10 Aug 2016 10:58:43 +0000 (12:58 +0200)]
greybus: hd/es2: add cport_quiesce callback and ARPC

Add a host-device cport_quiesce callback, which will be called as part
of the new connection tear-down sequence to disable flow control after
first making sure that enough peer buffer space is available for the
next messages about to be sent.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: hd/es2: add cport_connected callback and ARPC
Johan Hovold [Wed, 10 Aug 2016 10:58:42 +0000 (12:58 +0200)]
greybus: hd/es2: add cport_connected callback and ARPC

Add a host-device cport_connected callback, which will be called after a
connection has been created and that can be used by the host-device
driver to make sure its internal state is updated to match the CPort
attributes set by the SVC.

This callback will eventually replace the cport_features_enable
callback.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: fix up copyright dates on arpc.h
Greg Kroah-Hartman [Wed, 10 Aug 2016 15:02:05 +0000 (17:02 +0200)]
greybus: fix up copyright dates on arpc.h

I got them wrong, Johan was right, my fault.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: lights: enable multi color LED support
Kris Huang [Tue, 9 Aug 2016 03:28:37 +0000 (11:28 +0800)]
greybus: lights: enable multi color LED support

A backport (commit 79c4de08c0e5a26b04a4ac9e6543dad6379f0b40) was
applied in kernel which adding attribute-group support in led-class.
Remove the LED_HAVE_GROUPS flag check entirely that allow led
drivers to create custom attributes like color/fade_in/fade_out.

Testing Done: Compiled and verified on EVT2 and gpbridge-test module
              with device class daughter board.

Signed-off-by: Kris Huang <huang_kris@projectara.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: greybus-driver: Add intf_oops operation
Georgi Dobrev [Tue, 9 Aug 2016 21:37:32 +0000 (14:37 -0700)]
greybus: greybus-driver: Add intf_oops operation

Add intf_oops operation to SVC Protocol. This
operation will notify the AP about a fatal error
in a module. The request has two arguments:
    -u8 intf - the interface in question
    -u8 reason - reason of the error
The response has no payload.
Upon receiving the Request, the driver disables
the Interface.

Signed-off-by: Georgi Dobrev <gdobrev@mm-sol.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Ashwin Chaugule <ashwinch@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: camera: Remove reference to ara subdevice
Jacopo Mondi [Wed, 10 Aug 2016 07:08:19 +0000 (09:08 +0200)]
greybus: camera: Remove reference to ara subdevice

Remove last occurrence of "ara" term in camera driver.
Replace reference to "ara subdevice" with "gmp subdevice"

Signed-off-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: arpc: move arpc definitions to their own header
Johan Hovold [Wed, 10 Aug 2016 10:58:41 +0000 (12:58 +0200)]
greybus: arpc: move arpc definitions to their own header

Move the ARPC definitions to their own header.

ARPC is not part of greybus, but is rather an implementation-specific
means of communicating with a certain class of host-device hardware.

Note that the same is true for the APBA USB vendor requests, but we keep
them in the greybus header for the time being.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: fix USB vendor-request prefixes
Johan Hovold [Wed, 10 Aug 2016 10:58:40 +0000 (12:58 +0200)]
greybus: es2: fix USB vendor-request prefixes

Make sure to use the common GB_APB prefix for all APBA USB vendor
requests.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: greybus_protocols: fix apba vendor-request comment
Johan Hovold [Wed, 10 Aug 2016 10:58:39 +0000 (12:58 +0200)]
greybus: greybus_protocols: fix apba vendor-request comment

Fix copy-paste error in an APBA USB vendor-request comment.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: sdio: increase maximum segment size
Rui Miguel Silva [Tue, 9 Aug 2016 22:35:35 +0000 (23:35 +0100)]
greybus: sdio: increase maximum segment size

Adjust maximum segment size of the sg list to meet the maximum request
size, this will allow to have less segments which increase the
performance of data movement during transfer operations.

Test Done: using mmc_test with best-case read/write performance and see
that only one segment is used and that the results are better (288KiB vs
300KiB in read operation).

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: greybus_protocol: fix order of sdio get caps response
Rui Miguel Silva [Tue, 9 Aug 2016 22:35:34 +0000 (23:35 +0100)]
greybus: greybus_protocol: fix order of sdio get caps response

Order of the field of the sdio get caps operation response were wrong,
that influence later the frequencies used by core, during normal
operation.

Tested: verified that the values inserted by the fw are the correct ones
for the field.

Suggested-by: Jackson Chang <jacksonc@bsquare.com>
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: interface: fix timesync registration sequencing
David Lin [Fri, 5 Aug 2016 22:08:40 +0000 (15:08 -0700)]
greybus: interface: fix timesync registration sequencing

When enabling an interface, control device should be registered after
having successfully added the timesync. Similarly for the interface
disable path, control device should be removed first before removing
timesync.

Testing Done:
 - Enable and disable the interface

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: Report jack removal along with module removal
Vaibhav Agarwal [Fri, 5 Aug 2016 12:46:30 +0000 (18:16 +0530)]
greybus: audio: Report jack removal along with module removal

For GB module with jack slot supported, headset/headphone can still
be inserted at the time of module removal. In this case, above layer is
unaware about jack removal event which happened due to module removal.
This may lead to inconsistent state in above HAL layer.  Fix this by
reporting jack removal event explicitly.

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>
7 years agogreybus: lights: Add runtime pm support
Kris Huang [Fri, 5 Aug 2016 04:59:08 +0000 (12:59 +0800)]
greybus: lights: Add runtime pm support

Modify Lights greybus driver to support runtime PM framework.
The suspend and resume function have been tested with gpbridge-test
image by sysfs. Lights functions work well on suspend/resume.

Testing Done: Compiled and verified on EVT2 and gpbridge-test module
              with device class daughter board.

Signed-off-by: Kris Huang <huang_kris@projectara.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: SDIO: Add runtime pm support
Jackson Chang [Fri, 5 Aug 2016 02:22:02 +0000 (10:22 +0800)]
greybus: SDIO: Add runtime pm support

Modify SDIO greybus driver to support runtime PM framework.
To enable SDIO runtime PM, it needs to remove MMC_CAP_NEEDS_POLL
and add MMC_CAP2_CORE_RUNTIME_PM in set_host_caps().
The suspend function and resume function have been tested
with micron-sdio image by sysfs. SDIO functions work well
on suspend/resume.

Testing Done: Compiled and verified on EVT2.0 + Micron ARA
              SD module with USB connector

Signed-off-by: Jackson Chang <chang_jackson@projectara.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: Maintain module stream state for each data connection
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:39 +0000 (15:14 +0530)]
greybus: audio: Maintain module stream state for each data connection

For SPK module, each data connection corresponds to codec DAI. Now
stream state is maintained for each DAI. So, need to maintain stream
state for each DAI/data connection for individual module as well.

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>
7 years agogreybus: audio: Maintain runtime stream params for each DAI
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:38 +0000 (15:14 +0530)]
greybus: audio: Maintain runtime stream params for each DAI

Runtime streams are required while configuring GB module plugged-in
during active stream. Currently, it is maintained for single stream.
However, this should be maintained for a stream corresponding to each
DAI. Fix this!

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>
7 years agogreybus: audio: Update pm runtime support in dai_ops callback
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:37 +0000 (15:14 +0530)]
greybus: audio: Update pm runtime support in dai_ops callback

Ensure pm runtime get_sync/put protection in codec_dai ops callback
functions before accessing apbridge.

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>
7 years agogreybus: Remove unused field from data_connection
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:36 +0000 (15:14 +0530)]
greybus: Remove unused field from data_connection

Audio codec driver internally maintains a struct containing info about
module's data connection. Remove unused field from this struct.

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>
7 years agogreybus: audio: Find data connection based on id
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:35 +0000 (15:14 +0530)]
greybus: audio: Find data connection based on id

Currently we are using dai->name to identify data connection from list
for a module. Now since we are enabling data path based on widget,
dai->name might be invalid by the time driver receives disable request
for a widget. So, use id fetched from AIF widget->sname to identify data
connection for a module.

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>
7 years agogreybus: audio: Add id to identify data connection
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:34 +0000 (15:14 +0530)]
greybus: audio: Add id to identify data connection

Added id field to data connection struct. This is used to identify which
data connection to use while enabling interface between module & APB.

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>
7 years agogreybus: audio: Use AIF widget to enable path between module & APB
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:33 +0000 (15:14 +0530)]
greybus: audio: Use AIF widget to enable path between module & APB

Currently, SPK Amp switch is used to identify when to enable data path
between module and APB. With headset, other switch controls added, it is
not possible to use this switch to control data path. Instead path
should be established based on AIF widget.

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>
7 years agogreybus: audio: Update parameters for gbaudio_module_update API
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:32 +0000 (15:14 +0530)]
greybus: audio: Update parameters for gbaudio_module_update API

Earlier, module path was enabled based on module's control switch e.g.
'SPK Amp switch'.  Thus widget's name was sufficient to parse and
identify the direction. Now individual modules' path will be enabled
based on AIF widget status. So, it is required to get complete widget
details, say w->type is used to identify direction (playback/capture)
and w->sname is used to identify module's DATA connection used for
communication via greybus.

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>
7 years agogreybus: audio: Update dai_driver table with appropriate fields
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:31 +0000 (15:14 +0530)]
greybus: audio: Update dai_driver table with appropriate fields

Currently, the stream name for the DAI driver is generically set to "GB
Audio Playback" and "GB Audio Capture". This is OK since we use a single
interface on APB1 but that could change in the future.  Update the DAI
driver table entries to properly reflect the interface used.

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>
7 years agogreybus: audio: Split helper APIs based on stream direction
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:30 +0000 (15:14 +0530)]
greybus: audio: Split helper APIs based on stream direction

Now, module is enabled/disabled based on widget event only and not
during startup/shutdown callbacks. Thus, we needn't compare codec_state
in enable/disable module helper APIs. Also, these can be further
simplified based on stream direction.

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>
7 years agogreybus: audio: Enable audio path based on control switch state only
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:29 +0000 (15:14 +0530)]
greybus: audio: Enable audio path based on control switch state only

As per current implementation, audio data is played from each individual
SPK module connected to endo frame. This is not a valid requirement in
case of capture/headset path. So, provide a mechanism to enable
individual module path based on it's control switch state.

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>
7 years agogreybus: audio: Remove un-necessary goto statement
Vaibhav Agarwal [Thu, 4 Aug 2016 09:44:28 +0000 (15:14 +0530)]
greybus: audio: Remove un-necessary goto statement

For most of the helper functions, goto statement is widely used.  It was
originally used with an intent of single exit point for the function
with some cleanup required. This is no more the case. So, simplify code
by avoiding un-necessary gotos.

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>
7 years agogreybus: arche-platform: Add support for SPI bus sharing for Mihi
Vaibhav Hiremath [Thu, 28 Jul 2016 08:17:37 +0000 (13:47 +0530)]
greybus: arche-platform: Add support for SPI bus sharing for Mihi

In case of Mihi, SPI bus is shared between APB1 and APB2
SPI ROMs, so their FW flashing must be sequential and
arche-platform driver should make sure that they are mutual
exclusive in nature.

So this patch adds certain restrictions to the user of the
arche-platform driver,

 - User can no longer flash APB1 and APB2 SPI ROM in parallel
 - SPI bus becomes an resource, so user must claim it by moving
   respective APB device into FW_FLASHING mode and release it
   by exiting FW_FLASHING mode. User can exit FW_FLASHING mode by
   switching to any other modes (ACTIVE, OFF, STANDBY).
 - If APB1 is in FW_FLASHING mode, APB2 can no longer enter into
   FW_FLASHING mode. User will get -EBUSY.

Having said that, while APB1 is into FW_FLASHING mode,
APB2 can independently boot from its own SPI ROM.

Testing Done: Tested by simulating usecase on EVT2.
 - Made sure that APB1 and APB2 FW_FLASHING mode is mutual exclusive
   in nature. Confirmed that an attempt on second device return -EBUSY.
 - Added simulating code, where printed state of dummy gpio for
   spi-en and verified that it shows right pin status for both APBs

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: arche-platform: Reset SVC & APB only if turned off by SUSPEND_PREPARE
Vaibhav Hiremath [Wed, 3 Aug 2016 11:45:38 +0000 (17:15 +0530)]
greybus: arche-platform: Reset SVC & APB only if turned off by SUSPEND_PREPARE

There is possible race condition in arche platform driver for
maintaining of ->state field, when shared with timesync driver.

Assume device booted fine, all connected modules have been enumerated
correctly. As part of suspend-resume operation we have pm_notifier
callback, where we turn off SVC & APB and coldboot on resume.
In the process of resume, all modules gets enumerated again, and
timesync driver does come into picture everytime.
So when timesync driver requests arche-platform to change the state
to TIMESYNC and in the middle of sync operation, if suspend gets
triggered, then execution lands into arche-platform->pm_notifier callback,
leading to race condition in the driver, where it checks for (state != ACTIVE)
in PM_SUSPEND_PREPARE and returns, but in PM_POST_SUSPEND it just simply
coldboots SVC & APB, which would inbalance all resources (including IRQ).

So we need a add check in PM_POST_SUSPEND, to make sure that, we only
coldboot devices if they are in to off state,
i.e. if (state != OFF) then return.

Testing Done: Done regressive suspend/resume testing on EVT2 platform.
Note that, I some time hit issue.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: rename USB vendor-request timeout define
Johan Hovold [Wed, 3 Aug 2016 12:09:35 +0000 (14:09 +0200)]
greybus: es2: rename USB vendor-request timeout define

Give the USB vendor-request timeout define a more descriptive name.

Also drop the since-long obsolete comments about allowing "the SVC to do
something" and "SVC messages go down our control pipe".

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: add define for ARPC CPort requests
Johan Hovold [Wed, 3 Aug 2016 12:09:34 +0000 (14:09 +0200)]
greybus: es2: add define for ARPC CPort requests

Add dedicated define for ARPC CPort requests instead of using the
default timeout for USB vendor requests.

We still allow responses to take 500 ms to arrive, but note that this
adds on top of the 500ms already allowed for a requests to be
acknowledged. This should probably be tightened up at some point.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: allow ARPC result to be ignored
Johan Hovold [Wed, 3 Aug 2016 12:09:33 +0000 (14:09 +0200)]
greybus: es2: allow ARPC result to be ignored

Allow user of ARPC to pass a NULL pointer for the ARPC result.

For simple requests there may only be one error code for remote errors,
or the caller may simply not care to differentiate them.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: always set result value
Johan Hovold [Wed, 3 Aug 2016 12:09:32 +0000 (14:09 +0200)]
greybus: es2: always set result value

Make sure to always set the result value for ARPC instead of forcing
every caller to do it in order to avoid compiler warnings.

The ARPC result should still be ignored unless arpc_sync returns
-EREMOTEIO.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: clean up ARPC symbol names
Johan Hovold [Wed, 3 Aug 2016 12:09:31 +0000 (14:09 +0200)]
greybus: es2: clean up ARPC symbol names

Add a _req suffix to request message structures, and a _TYPE_ infix to
request type defines.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: connection: fix offloaded-connection ping cport id
Johan Hovold [Wed, 3 Aug 2016 12:09:30 +0000 (14:09 +0200)]
greybus: connection: fix offloaded-connection ping cport id

The host-device cport_ping callback expects the AP side cport id, but
was incorrectly passed the interface cport id.

Note that no host-device driver currently implements this callback, and
that it is soon even to be removed.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: control: remove some braces
Johan Hovold [Wed, 3 Aug 2016 12:09:29 +0000 (14:09 +0200)]
greybus: control: remove some braces

Remove some no-longer-needed braces around an error path.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: remove unused protocol-version messages
Johan Hovold [Wed, 3 Aug 2016 12:09:28 +0000 (14:09 +0200)]
greybus: remove unused protocol-version messages

Remove the unused protocol-version messages.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: Remove GET_TX/RX_DELAY message types
Mark Greer [Wed, 3 Aug 2016 03:30:28 +0000 (20:30 -0700)]
greybus: audio: Remove GET_TX/RX_DELAY message types

The 'GB_AUDIO_TYPE_GET_TX_DELAY' and 'GB_AUDIO_TYPE_GET_RX_DELAY'
are no longer a part of the Greybus Audio Device Class Protocol
so remove support for them.  The message numbers are not coalesced
to prevent compatibility issues between the AP and the module.

Testing Done: Played music using a speaker module

Signed-off-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: apbridgea: Remove GET_TX/RX_DELAY message types
Mark Greer [Wed, 3 Aug 2016 03:36:07 +0000 (20:36 -0700)]
greybus: audio: apbridgea: Remove GET_TX/RX_DELAY message types

The 'AUDIO_APBRIDGEA_TYPE_GET_TX_DELAY' and
'AUDIO_APBRIDGEA_TYPE_GET_RX_DELAY' message types have been
removed from the AP <-> APBrigdeA Audio Protocol so remove
them from the code.  Do not coalesce the message type numbers
to prevent compatibility issues between the AP and APBridgeA.

Testing Done: Played music using a speaker module

Signed-off-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: timesync: Printout strobe count on sync failure
Bryan O'Donoghue [Tue, 2 Aug 2016 12:18:29 +0000 (13:18 +0100)]
greybus: timesync: Printout strobe count on sync failure

If we failed to synchronize the FrameTime it would be useful to know how
many of the expected strobes arrived, for example a value of 0/5 would
indicate the SVC was completely dead but a value of 4/5 would indicate one
GPIO pulse got lost i.e. the AP was too slow reacting to an interrupt and
completely missed one of the strobe events. In either case the actual
number of strobes is a useful thing to print out.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: timesync: Ensure parallel synchronous calls succeed
Bryan O'Donoghue [Tue, 2 Aug 2016 12:18:28 +0000 (13:18 +0100)]
greybus: timesync: Ensure parallel synchronous calls succeed

The guard for initiating a new synchronization operation should allow for
that resync to happen in every single state except for INVALID. This patch
fixes by ensuring the guard does just that. With local testing it was
possible to break a sync to a Module. This hasn't been observed in a buglog
but should be fixed anyway.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Acked-by: David Lin <dtwlin@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: timesync: Implement a retry mechanism
Bryan O'Donoghue [Tue, 2 Aug 2016 12:18:30 +0000 (13:18 +0100)]
greybus: timesync: Implement a retry mechanism

It's possible the AP could miss an incoming SVC timesync pulse i.e. the AP
could have interrupts switched off for long enough that one SVC GPIO strobe
ends up over-lapping another one. TimeSync should be able to deal with this
type of transitory failure by retrying a failed synchronous TimeSync resync
up to 'n' number of times. For this patch 'n' has been set to five, which
is a hand-wavy choice that 'feels' right.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: svc_watchdog: use schedule_delayed_work helper
David Lin [Tue, 2 Aug 2016 03:51:38 +0000 (20:51 -0700)]
greybus: svc_watchdog: use schedule_delayed_work helper

Instead of using the queue_delayed_work call for delayed work on
system_wq, use the schedule_delayed_work helper to be more consistent on
the style.

Testing Done:
 - Check SVC watchdog is pining after the change.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: interface: delete control device upon enable failure
David Lin [Tue, 2 Aug 2016 22:34:46 +0000 (15:34 -0700)]
greybus: interface: delete control device upon enable failure

There is an issue that when an interface failed to be enabled due to
timesync failure, a previously added control device is not deleted as
part of the error clean-up. This causes a leak in the sysfs file when
the interface is disabled. This would eventually cause this particular
interface to be unable to register future control device even after
unipro_reset. See failure logs below:

[  906.495261] greybus 1-3.3: failed to add to timesync: -19
[  906.516497] greybus 1-3.3: failed to re-enable interface: -19
[  907.016016] greybus 1-3.3: Interface removed
...
[ 1623.677343] ------------[ cut here ]------------
[ 1623.681116] WARNING: at kernel/arche/fs/sysfs/dir.c:530 sysfs_add_one+0x98/0xb4()
[ 1623.681128] sysfs: cannot create duplicate filename '/bus/greybus/devices/1-3.3.ctrl'
[ 1623.681252] Call trace:
[ 1623.681265] [<ffffffc000207b40>] dump_backtrace+0x0/0x268
[ 1623.681272] [<ffffffc000207db8>] show_stack+0x10/0x1c
[ 1623.681284] [<ffffffc000ccb890>] dump_stack+0x1c/0x28
[ 1623.681295] [<ffffffc00021f9dc>] warn_slowpath_common+0x74/0x9c
[ 1623.681301] [<ffffffc00021fa60>] warn_slowpath_fmt+0x5c/0x80
[ 1623.681307] [<ffffffc000366624>] sysfs_add_one+0x94/0xb4
[ 1623.681315] [<ffffffc0003670b4>] sysfs_do_create_link_sd+0x100/0x1c8
[ 1623.681320] [<ffffffc0003671a8>] sysfs_create_link+0x2c/0x38
[ 1623.681332] [<ffffffc0005d5890>] bus_add_device+0xd8/0x190
[ 1623.681338] [<ffffffc0005d39ec>] device_add+0x2b4/0x604
[ 1623.681349] [<ffffffbffc006dfc>] gb_control_add+0x10/0x40 [greybus]
[ 1623.681362] [<ffffffbffc003dac>] gb_interface_enable+0x20c/0x3b8 [greybus]
[ 1623.681373] [<ffffffbffc002a30>] gb_module_add+0x124/0x174 [greybus]
[ 1623.681385] [<ffffffbffc0082cc>] gb_svc_intf_set_power_mode+0xdd4/0xfe8 [greybus]
[ 1623.681394] [<ffffffc00023888c>] process_one_work+0x268/0x3c8
[ 1623.681400] [<ffffffc000239a64>] worker_thread+0x204/0x358
[ 1623.681410] [<ffffffc00023f43c>] kthread+0xb8/0xc4
[ 1623.681414] ---[ end trace 44489577dd9220db ]---
[ 1623.681818] greybus 1-3.3.ctrl: failed to register control device: -17

Testing Done:
 - Continuous unipro_reset stress test

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: fix arpc active-list corruption
Johan Hovold [Wed, 27 Jul 2016 14:37:22 +0000 (16:37 +0200)]
greybus: es2: fix arpc active-list corruption

Fix ARPC active-list corruption due to incorrect list-interface usage.

The corruption manifested itself as ARPC timeouts due to expected
responses not being recognised whenever more than one ARPC was active.

This could be seen for example when two interfaces were being runtime
suspended in parallel:

[  165.739896] usb 1-1.1: invalid arpc response id received: 13
[  165.794743] greybus 1-5.5: gb_interface_refclk_set - 0
[  166.241202] usb 1-1.1: failed to execute ARPC: -110

Fortunately the impact of this bug has so far been limited to such
timeouts and error messages due to ARPC currently only being used for
CPort reset in the connection tear-down path.

Reported-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: fix arpc error message
Johan Hovold [Wed, 27 Jul 2016 14:37:21 +0000 (16:37 +0200)]
greybus: es2: fix arpc error message

Add missing le16_to_cpu() to an ARPC error message in the receive path,
and also use %u to print the unsigned id.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: fix arpc response-allocation error handling
Johan Hovold [Wed, 27 Jul 2016 14:37:20 +0000 (16:37 +0200)]
greybus: es2: fix arpc response-allocation error handling

The wrong pointer was checked for allocation failures when allocating
the ARPC response buffer, something which would lead to allocation
failures going undetected.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: replace Ara references
Johan Hovold [Thu, 28 Jul 2016 09:40:53 +0000 (11:40 +0200)]
greybus: replace Ara references

Replace all occurrences of the term "Ara" with "GMP" in core.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: Documentation/sysfs: replace Ara references
Johan Hovold [Thu, 28 Jul 2016 09:40:52 +0000 (11:40 +0200)]
greybus: Documentation/sysfs: replace Ara references

Refer to the MDK as GMP MDK.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: arche-apb-ctrl: Rename ara,init-disable => arche,init-disable
Vaibhav Hiremath [Thu, 28 Jul 2016 08:26:44 +0000 (13:56 +0530)]
greybus: arche-apb-ctrl: Rename ara,init-disable => arche,init-disable

Inline with other properties used for arche-platform driver,
rename ara,init-disable => arche,init-disable.

Testing Done: Boot tested on EVT2 platform

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: camera: Rename debug and metadata mbus formats
Gjorgji Rosikopulos [Wed, 27 Jul 2016 18:47:01 +0000 (11:47 -0700)]
greybus: camera: Rename debug and metadata mbus formats

Change ARA prefix to GB_CAM for greyus camera specific
formats.

Change-Id: I1a0552516e8ea727c48085c59fc49f2409a89486
Signed-off-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Signed-off-by: Blagovest Borisov Kolenichev <kolenichev_blagovest@projectara.com>
Acked-by: Laurent Pinchart <laurent.pinchart@linaro.org>
7 years agogreybus: audio: add runtime pm to enumerated control and DAPM widget
David Lin [Mon, 25 Jul 2016 23:29:20 +0000 (16:29 -0700)]
greybus: audio: add runtime pm to enumerated control and DAPM widget

There's an issue that the userspace is not able to control both the
enumerated control and DAPM widget when audio bundle is in the SUSPEND
state. This patch fixes the issue by adding pm_runtime_get/put() calls
for the both controls.

Testing Done:
 - Use tinymix to get and put both enumerated control and DAPM widget as
   the followings, and observe audio bundle is able to wake up from
   suspend.

$ tinymix "GB 3 PB source" 1
$ tinymix "GB 3 PB source"
GB 3 PB source: AIF1 >AIF2

$ tinymix "GB 3 AIF1_RX MUX" 2
$ tinymix "GB 3 AIF1_RX MUX"
GB 3 AIF1_RX MUX: Stereo Left >Right

Reported-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: svc_watchdog: Add sysfs file to change the behavior of bite
David Lin [Tue, 26 Jul 2016 23:27:28 +0000 (16:27 -0700)]
greybus: svc_watchdog: Add sysfs file to change the behavior of bite

Currently, AP performs unipro_reset if SVC fails to response to its
ping. While this error recovery is best suited for the end-user
experience, errors in the UniPro network could potentially go unnoticed
by the QA and fishfooders in the development phase of the project. This
patch adds an option to trigger a kernel panic so logs can be collected
for analysis.

Testing Done:
 - Reproduce issue and observe kernel panic when
   watchdob_control is changed to 'panic'

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>
7 years agogreybus: firmware: Update Documentation and sample application
Viresh Kumar [Mon, 25 Jul 2016 21:38:09 +0000 (14:38 -0700)]
greybus: firmware: Update Documentation and sample application

Update documentation and sample application to capture the 'status' byte
in backend version operation and new error types in backend firmware
update operation.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: firmware: Add 'status' byte to backend fw version response
Viresh Kumar [Mon, 25 Jul 2016 21:38:08 +0000 (14:38 -0700)]
greybus: firmware: Add 'status' byte to backend fw version response

The backend processor may not be ready to return the version of firmware
it is running by the time AP requests for it. The greybus specification
is updated to return 1-byte 'status' to return the error type, RETRY is
one of them.

This patch implements that in greybus now.

Note that the version structure was common across interface and backend
version requests earlier, but that is changing as well.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: firmware: Add new status types for backend updated request
Viresh Kumar [Mon, 25 Jul 2016 21:38:07 +0000 (14:38 -0700)]
greybus: firmware: Add new status types for backend updated request

The specification got updated with two more status values, add their
support in greybus.

As retry isn't really an error, skip printing error messages for it as
well.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: interface: Add quirk for no PM for S2 Loader
Viresh Kumar [Tue, 26 Jul 2016 20:41:04 +0000 (13:41 -0700)]
greybus: interface: Add quirk for no PM for S2 Loader

S2 Loader doesn't support runtime PM operations currently and we will
fail to suspend/resume the bundle for firmware management protocols.

Once that happens, the bundle and its connections will be pretty much
useless as we would have tried to disable/enable all connections during
such an operation and the S2 loader doesn't expect the connections to go
away during normal operation (except in the case of mode-switch).

This patch defines a new quirk GB_INTERFACE_QUIRK_NO_PM and uses a new
interface init status value (GB_INIT_S2_LOADER_INITIALIZED) which will
be advertised by S2 Loader now in the init status.

After detecting the currently running stage as S2 Loader, the kernel
wouldn't attempt suspending or resuming the bundle.

Reviewed-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: interface: Rename *_NO_PM as *_NO_BUNDLE_ACTIVATE
Viresh Kumar [Tue, 26 Jul 2016 20:41:03 +0000 (13:41 -0700)]
greybus: interface: Rename *_NO_PM as *_NO_BUNDLE_ACTIVATE

Its a special quirk just for the bootrom as it doesn't have any PM
operations implemented. As the greybus bootrom bundle driver doesn't try
to do any PM stuff, this quirk is used only to skip bundle activate
operation currently.

Rename the GB_INTERFACE_QUIRK_NO_PM quirk to
GB_INTERFACE_QUIRK_NO_BUNDLE_ACTIVATE to suit its purpose better as the
GB_INTERFACE_QUIRK_NO_PM will be used for other quirk now.

Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: firmware: Add runtime PM support
Viresh Kumar [Tue, 26 Jul 2016 20:41:02 +0000 (13:41 -0700)]
greybus: firmware: Add runtime PM support

This patch implements runtime PM support for firmware management bundle.
This guarantees that the bundle will be active, while the AP or the
Module is trying to exchange any operations over any of the CPorts.

- Firmware Management CPort:

  Runtime PM get/put calls are placed around the ioctl calls, which are
  all implemented as blocking ioctls.

- Component Authentication CPort:

  Runtime PM get/put calls are placed around the ioctl calls, which are
  all implemented as blocking ioctls.

- SPI:

  Uses the interface provided by spilib.c and runtime PM get/put are
  called around connection usage.

- firmware-download:

  This is the most tricky one. All operations on this CPort are
  initiated from the Module and not from the AP. And the AP needs to do
  runtime_pm_get() before any request is received over this CPort.

  The module doesn't send any request over this connection, unless the
  AP has requested the module over firmware management CPort to download
  a firmware package over firmware download CPort.

  And so the runtime PM get/put calls around the ioctls in
  fw-management.c are sufficient to handle the firmware management CPort
  as well.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: operation: clean up request handler
Johan Hovold [Tue, 26 Jul 2016 15:11:30 +0000 (17:11 +0200)]
greybus: operation: clean up request handler

Clean up the incoming request handler somewhat by passing a properly
aligned header and dropping the now redundant id and type parameters.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: operation: fix broken response tracepoint
Johan Hovold [Tue, 26 Jul 2016 15:11:29 +0000 (17:11 +0200)]
greybus: operation: fix broken response tracepoint

The response-received tracepoint is currently broken. Instead of parsing
the received message header it was tracing a bunch of zeroed fields from
an uninitialised response buffer.

Fix this by moving the tracepoint after were the response buffer is
initialised.

Fixes: 7cb496e6890e ("greybus: tracing: fix message traces")
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: operation: fix broken response error messages
Johan Hovold [Tue, 26 Jul 2016 15:11:28 +0000 (17:11 +0200)]
greybus: operation: fix broken response error messages

The operation type included in the error message printed for malformed
responses has never been correct. An uninitialised buffer was used to
retrieve the type, resulting in the type always being reported as 0.

Fix this by passing a properly aligned header to the response handler,
and drop the now redundant id and result parameters.

Fixes: cb0ef0c019ab ("operation: print message type on errors")
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: HID: Add runtime pm support
Philip Yang [Fri, 22 Jul 2016 21:48:14 +0000 (05:48 +0800)]
greybus: HID: Add runtime pm support

Modify HID greybus driver to support runtime PM framework.
The suspend and resume fucntion have been test with tutorial-hid,
e-ink-display and gpbridge-test image by sysfs resume, all HID
buttons work well on suspend/resume.

Testing Done: Compiled and verified on EVT2, DB3.5, GPB test module
              with daughter board, Red module.

Signed-off-by: Philip Yang <yang_philip@projectara.com>
Reviewed-by: David Lin <dtwlin@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: bootrom: Rename download_firmware() as find_firmware()
Viresh Kumar [Fri, 22 Jul 2016 21:13:44 +0000 (14:13 -0700)]
greybus: bootrom: Rename download_firmware() as find_firmware()

The download_firmware() function isn't downloading the firmware but just
finding if one is available or not. The same applies to the error
message printed by it.

Replace 'download' with 'find' to make it sound better.

Reported-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: bootrom: Create gb_bootrom_cancel_timeout()
Viresh Kumar [Fri, 22 Jul 2016 21:13:43 +0000 (14:13 -0700)]
greybus: bootrom: Create gb_bootrom_cancel_timeout()

We set timeouts using gb_bootrom_set_timeout(), which hides the internal
implementation, i.e. workqueues.

While canceling timeouts, we do cancel_delayed_work_sync(), which
exposes the internal implementation and doesn't look that clean.

Create gb_bootrom_cancel_timeout() to hide the internal implementation
here as well.

Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: bootrom: Set timeout before sending AP_READY
Viresh Kumar [Fri, 22 Jul 2016 21:13:42 +0000 (14:13 -0700)]
greybus: bootrom: Set timeout before sending AP_READY

A special race is observed in the case where the phone boots with
modules attached to it.

In that case, the AP processes a later FIRMWARE_SIZE request from the
bootrom, before processing the response to the earlier AP_READY request.
And because of that, we set the timeout from gb_bootrom_probe() after
trying to cancel it from gb_bootrom_firmware_size_request().

And with that, if the firmware package isn't available for the kernel to
directly read from, then we get a timeout print message like below:

[   23.669764] bootrom 1-3.3.1: Firmware file 'ara_00000126_00001001_fffe0001_ffe5001a_s2l.tftf' requested
[   24.680528] bootrom 1-3.3.1: Timed out waiting for Firmware Size Request from the Module

Note that this doesn't happen if the module is inserted into the frame,
after the phone is already booted.

This behavior is the result of an earlier commit cdd1cb3f4943
("operation: add completion work queue").

This perhaps happens only at boot time because the UNBOUND wq
(connection->wq) gets a chance to run on other CPUs, while the BOUND wq
(gb_operation_completion_wq) doesn't at that stage (24 seconds since
boot).

Setting the timeout before sending the AP_READY request fixes it for
now.

Reported-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: bootrom: Don't print duplicate error messages
Viresh Kumar [Fri, 22 Jul 2016 21:13:41 +0000 (14:13 -0700)]
greybus: bootrom: Don't print duplicate error messages

On failing to find a firmware image, we get these today:

bootrom 1-3.3.1: Firmware request for ara_00000126_00001001_fffe0001_ffe5001a_s2l.tftf has failed : -12
bootrom 1-3.3.1: gb_bootrom_firmware_size_request: failed to download firmware (-12)

Which are more or less duplicate, as they print error for the same root
cause.

With this patch this is all we get now:

bootrom 1-3.3.1: failed to download ara_00000126_00001001_fffe0001_ffe5001a_s2l.tftf firmware (-12)

Reported-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: bootrom: Skip setting timeout in failure path of size request
Viresh Kumar [Fri, 22 Jul 2016 21:13:40 +0000 (14:13 -0700)]
greybus: bootrom: Skip setting timeout in failure path of size request

The currently set value of next_request_type in the error path of
gb_bootrom_firmware_size_request() is not correct, as it should have
been NEXT_REQ_FIRMWARE_SIZE for the failure case (as we should be
waiting for another similar request).

But, if an error occurs in gb_bootrom_firmware_size_request(), then the
ES3 bootrom will never be able to recover from it and send another
request. And so there is no point waiting for another request and timing
out.

Skip doing that in error path.

Reported-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: vibrator: integrate runtime pm
Ann Chen [Fri, 22 Jul 2016 07:33:55 +0000 (15:33 +0800)]
greybus: vibrator: integrate runtime pm

Integrate greybus drivers with the Linux Kernel RuntimePM framework
for vibrator driver.

Testing Done: AP side (kernel) can control the vibrator driver with
suspend and resume.

Signed-off-by: Ann Chen <chen_ann@projectara.com>
Reviewed-by: David Lin <dtwlin@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: control: Print bundle-id in print messages
Viresh Kumar [Fri, 22 Jul 2016 05:41:05 +0000 (22:41 -0700)]
greybus: control: Print bundle-id in print messages

The new power management specific operations added to the control
protocol do not print the bundle-id in the error messages and it is not
possible to identify which bundle-id the operation failed for.

Fix that and do minor rewriting of the print messages to make them more
readable.

Tested on EVT 2.0 with gpbridge-test module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>