Commit graph

2465 commits

Author SHA1 Message Date
Johan Hovold 178457e171 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>
2016-07-28 10:04:06 -07:00
Johan Hovold fcba5d04c8 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>
2016-07-28 10:04:06 -07:00
Johan Hovold 23931ffb9a 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>
2016-07-28 07:30:13 -07:00
Johan Hovold 6c298035a1 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>
2016-07-28 07:30:13 -07:00
Vaibhav Hiremath 20de72f5de 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>
2016-07-28 07:27:38 -07:00
Gjorgji Rosikopulos 563c742ada 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>
2016-07-27 17:26:52 -07:00
David Lin 9d3717f71c 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>
2016-07-26 20:58:37 -07:00
David Lin 7c4a0edb38 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>
2016-07-26 20:58:37 -07:00
Viresh Kumar 6136cce89c 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>
2016-07-26 16:16:15 -07:00
Viresh Kumar 5e10f0047a 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>
2016-07-26 16:16:15 -07:00
Viresh Kumar 911415ae6e 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>
2016-07-26 16:16:15 -07:00
Viresh Kumar 0c543f9bb2 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>
2016-07-26 15:29:00 -07:00
Viresh Kumar 47cbaf5e55 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>
2016-07-26 15:29:00 -07:00
Viresh Kumar c57fbb404a 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>
2016-07-26 15:29:00 -07:00
Johan Hovold 2321f049a9 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>
2016-07-26 14:53:19 -07:00
Johan Hovold 112f563e18 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>
2016-07-26 14:53:19 -07:00
Johan Hovold dfcba8626f 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>
2016-07-26 14:53:19 -07:00
Philip Yang 43c85a09b1 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>
2016-07-22 15:25:18 -07:00
Viresh Kumar 68793c4c88 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>
2016-07-22 15:25:18 -07:00
Viresh Kumar 40d276ede9 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>
2016-07-22 15:25:18 -07:00
Viresh Kumar 6d9e6ffca4 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>
2016-07-22 15:25:18 -07:00
Viresh Kumar 2d6f1c2998 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>
2016-07-22 15:25:18 -07:00
Viresh Kumar cc90d6fce8 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>
2016-07-22 15:25:18 -07:00
Ann Chen 633e45eaac 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>
2016-07-22 14:06:39 -07:00
Viresh Kumar 553cba82b1 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>
2016-07-22 13:57:11 -07:00
David Lin e514dec730 greybus: operation: print id when synchronous operation timeout
In case of a synchronous operation timeout error, it's helpful for
purpose of debugging to print the operation id in the error message, so
that we know if the response is received at a later time after operation
time out.

Testing Done:
 - Observe the error message below when response comes later after
operation timeout:

[  792.973978] greybus greybus1: 0/0:0: synchronous operation id 0x0005
of type 0x21 failed: -110
[  800.646694] greybus greybus1: 0/0:0: unexpected response id 0x0005
received

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-22 13:57:11 -07:00
Vaibhav Agarwal 098dfaf45e greybus: audio: Avoid using ARA keyword
It is suggested to avoid using ARA keyword externally. So we need to
update GB codec driver. Also, codec name is currently set to 'gb-codec'.
However, it makes more sense to name it as apb-dummy-codec, since it is
used to control various audio modules connected to APB 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>
2016-07-22 10:26:01 -07:00
Viresh Kumar 92bcaddea3 greybus: spilib: make spilib independent of gbphy
spilib is used by multiple users currently (spi.c and fw-core.c) but
commit aa52b62a0556 broke that hierarchy and introduced gbphy dependent
code in spilib.

This may have unreliable consequences as we are doing following
operation unconditionally now:

	gbphy_dev = to_gbphy_dev(spi->parent);
	gbphy_runtime_get_sync(gbphy_dev);

which may not go well when the parent is of type &bundle->dev
(fw-core.c).

This patch introduces spilib_ops and lets the users of the core register
them. This shall have no functional change for the spi.c usecase and
shall fix the unreliable results for the fw-core.c usecase.

Tested by writing to mtd0 dev and verifying (with print messages) that
the below routines are getting called for a gpbridge-test module.

Fixes: aa52b62a0556 ("spi: Add runtime_pm support")
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-21 19:03:05 -07:00
Viresh Kumar adac4b9594 greybus: firmware: Improve test application
It can take arguments not and we can perform all the operations with a
single binary, sorry for missing that initially.

Usage: ./firmware <gb-fw-mgmt-X> <type: interface/backend> <firmware-tag> <timeout>

And all of them have default values, etc.

Tested with a semco 13 MP module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-21 19:00:26 -07:00
David Lin db2951835b greybus: timesync: do not print frametime by default
Currently frametime are being printed whenever an Interface is
runtime-resumed. This is unnecessarily chatty. This patch moves the
frametime print from using pr_info() to dev_dbg().

Testing Done:
 - $ echo "module greybus +p" > /d/dynamic_debug/control

[   97.699395] greybus 1-svc: greybus frametime: ap=2042778707
1-svc=2042775185 greybus1=2042778397 1-6.6=2042778390

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-21 18:58:35 -07:00
Bartosz Golaszewski f5c93dea8f greybus: pm: add error handling to bundle activation
The firmware now keeps the underlying hardware disabled until
receiving the first Bundle Activate request. Additionally: requesting
transition to a state the bundle is already in is no longer an error.

We can now add proper error handling to the bundle activate call.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-21 18:54:11 -07:00
Johan Hovold 2358024b67 greybus: control: suppress bundle_activate() for bootrom
We always knew backward compatibility with the ES3 bootrom, which was
finalised about a year ago, would be a pain. Here we go again.

The bootrom does not support control requests added after it was burnt
into ROM for obvious reasons. This means that we need to suppress
sending the new bundle_activate() operation to any interface executing
the legacy bootrom.

Do so by adding a new NO_PM interface quirk (we can use the
control-protocol version for this later once we bump it).

Note that the interface-disable path (e.g. for power down) is already
handled by the FORCED_DISABLE quirk, and that the suspend/resume
paths are currently avoided by making sure that the bootrom bundle
never suspends.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Tested-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-21 16:36:48 -07:00
Joel Porquet 350e3ac2ce greybus: firmware.h: rename TFTF firmware filenames
Replace prefix "ara_" with prefix "gmp_" for TFTF firmware filenames.

Testing Done: compiled and flashed EVT2 (bootimage) and tested that
              "gmp_" prefixed tftf files are expected. Pushed one from
	      FDK and checked that it's properly loaded.

Signed-off-by: Joel Porquet <porquet_joel@projectara.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-21 16:33:25 -07:00
Johan Hovold b5d1d1282b greybus: interface: fix interface_id attribute group
All interfaces, regardless of type, should have an interface_id
attribute reflecting its position on the frame.

This has been reported to cause an assertion failure in libmoduleutil
for dummy modules.

Testing done: Verified that the attribute is present for registered
dummy interfaces.

Reported-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Tested-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Reviewed-by: Patrick Titiano <ptitiano@baylibre.com>
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>
2016-07-21 10:07:00 -07:00
Bryan O'Donoghue 10a24b7c09 greybus: timesync: probe shouldn't complete until FrameTime sync does
Currently the probe() function contains the asynchronous() variant of
FrameTime synchronization. This patch converts to the synchronous() version
of synchronization. This is required for two reasons first a probe() cannot
reasonably be considered to be complete without successfully completing a
time synchronization for Interfaces that care about that sync. Secondly
scheduling the operation asynchronously means its possible the PM-runtime
suspend() path can execute before the async timesync operation completes.
For both reasons we want to run synchronization - synchronously.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 12:07:35 -07:00
Ryan Lim 346bae656e greybus: loopback_test: Add -f argument to cancel all tests
To make sure tests on all devices, enabled or not, are cancelled,
specify -f when starting new loopback test.

Signed-off-by: Ryan Lim <limryan@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 11:23:03 -07:00
Ryan Lim bf32654a24 greybus: loopback_test: Fix -z argument bug
The -z argument was missing the break statement needed in the switch
block and was not in the getopt list.

Signed-off-by: Ryan Lim <limryan@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 11:23:03 -07:00
Ryan Lim 2861e20790 greybus: loopback_test: Cancel only the tests running on selected devices
When starting a loopback test, it cancels all currently running tests on
all loopback devices. When -m argument is given, which runs the test on
specific loopback devices, only the tests running on the selected
devices need to be cancelled before starting new tests.

Signed-off-by: Ryan Lim <limryan@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 11:23:03 -07:00
Bryan O'Donoghue 93a7388943 greybus: timesync: reduce initial startup time
Currently we have a long initial delay when initiating the first operation
to synchronize the FrameTime. That made sense during development of the
feature since we did synchronization asynchronously and wanted to give some
grace time for new Interfaces to be added before initiating a new
synchronization. On the PM runtime resume path though we do a synchronous
restoration of FrameTime and in this case waiting for 1 second before
initiating the first operation is clearly wrong.

This patch reduces the initial operation time bringing the synchronous call
time down by 990 milliseconds.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 11:16:25 -07:00
Greg Kroah-Hartman 8a704565eb greybus: move all firmware prefix strings to one place
The firmware prefix is hard-coded in a few different places.  Put it all
in one handy #define, for when/if we ever decide to change it in the
future...

Testing: 'strings gb-firmware.ko gb-bootrom.ko | grep ara_' produced the
	 same output before and after this patch.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.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>
2016-07-20 10:29:07 -07:00
Johan Hovold 4f7e413b2d greybus: interface: hibernate UniPro link in activation error path
To be well-behaved, we should hibernate the link before disabling UniPro
in case the link has already been established (i.e. when the interface
type has been detected as UniPro or Greybus).

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Reviewed-by: Patrick Titiano <ptitiano@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 10:16:54 -07:00
Johan Hovold e21e6bad3f greybus: interface: fix power_state documentation
Reword the power_state attribute documentation to make it clear that an
attempt to boot and possibly enumerate an interface is made when writing
"on" to the file, and that on errors the interface will again be powered
down.

Drop the incorrect claim that writing the currently read value has no
effect, since no such guarantees can be made (e.g. several writers may
be sleeping on the interface mutex).

Also fix some minor language issues.

Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Patrick Titiano <ptitiano@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 10:16:54 -07:00
Viresh Kumar 93e29c8530 greybus: interface: add power_state attribute
User space needs the capability of powering ON or OFF an Interface for
multiple use cases. For example, userspace may want an Interface
currently in its S3 boot stage, to boot into its S2 Loader stage to
update the bridge SPI flash. Or the Interface is running its S2 Loader
stage and updated the SPI flash with the new S2 Loader firmware and
wants to boot into the new S2 Loader firmware.

Another use case can be, Android wants to disable (not eject) a
misbehaving module.

Add a 'power_state' sysfs file within the interface directory. It can be
read to know the current power state of the Interface and can be written
to power ON or power OFF an Interface. Possible values that can be
written or read from it are: "on" and "off".

Testing Done: Tested by enabling/disabling camera module on EVT 2.0.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
CC: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
[johan: drop es3-quirk duplication, add to power attribute group, fix
return value, drop tags ]
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Reviewed-by: Patrick Titiano <ptitiano@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 10:16:54 -07:00
Johan Hovold 12169bc914 greybus: interface: prevent reactivation during removal
Make sure to prevent an interface that is going away from being
reactivated.

This is needed to preemptively close a race between the upcoming feature
to reactivate a powered-down interface and physical removal (i.e.
module_removed event processing) as well as logical removal (e.g. the
current system-suspend hack).

Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Patrick Titiano <ptitiano@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 10:16:54 -07:00
Johan Hovold 62491622db greybus: interface: make sure type is invariant during reactivation
An interface is not expected to change its type after a power down and
reactivation so make sure to treat that as a fatal error.

This is complicated by the current Toshiba ES3 hack which requires us
to retry activation as Greybus interfaces are sometimes misdetected as
UniPro interfaces. Handle that by only retrying activation the first
time an interface is activated, and for interfaces already detected as
having Greybus type.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Reviewed-by: Patrick Titiano <ptitiano@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 10:16:54 -07:00
Johan Hovold 3e93cb6abb greybus: interface: clean up ES3 activation-retry hack
Clean up the ES3 activation retry-hack and isolate it in the interface
code.

This way the retry hack can be reused when we soon start allowing
interfaces to be reactivated after having been powered down.

Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Patrick Titiano <ptitiano@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 10:16:54 -07:00
Johan Hovold 27b9e257dd greybus: interface: do not read DME during reactivation
It will soon be possible to reactivate an interface that has been
powered down after already having been activated. In that case there's
no need to re-read the DME attributes as part of activation as the
values are already cached.

Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Patrick Titiano <ptitiano@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 10:16:54 -07:00
Johan Hovold a212b75867 greybus: interface: use an enum for interface type
Use an enum for the interface type instead of using the SVC protocol
values directly.

Suggested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Reviewed-by: Patrick Titiano <ptitiano@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-20 10:16:54 -07:00
Johan Hovold 6633d80afb greybus: module: suppress activation error message for dummy interfaces
We currently handle dummy interfaces by deactivating them using
activation error paths, but we don't want the corresponding
module_inserted error message to be printed.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-19 19:06:34 -07:00
Johan Hovold c80a982fc1 greybus: interface: amend interface registration message
Amend the interface registration message with the detected interface
type, and only print the Ara VID/PID and DDBL1 attributes for the types
for which they exist.

Also drop the now redundant message about a detected dummy interface
from the activate operation helper.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-19 19:06:34 -07:00
Johan Hovold 835642526e greybus: interface: make attributes type dependent
Make most interface attributes type dependent (e.g only UniPro and
Greybus interfaces should have a DDBL1 Manufacturer ID attribute).

Note that the power attributes (e.g. current_now) will only be visible
for UniPro- and Greybus-type interfaces (i.e. interfaces that can draw
power).

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-19 19:06:34 -07:00
Johan Hovold 441ac1fa9e greybus: interface: partition attribute group
Partition the current attribute group into four groups for UniPro,
Greybus, power and common attributes.

This is a step in refining the interface-type handling as attributes are
type dependent.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-19 19:06:34 -07:00
Johan Hovold 1bb61840c4 greybus: interface: add interface-type attribute
Add an interface-type string attribute that represents the detected
interface type as either "dummy", "unipro", "greybus", or "unknown".

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-19 19:03:32 -07:00
Vaibhav Hiremath d29b67d44a greybus: arche-platform: Add support for init-off feature
Disable wake_detect interrupt after request

As part of SW-4344/SW-7061, now we are enabling FW flashing
to all builds. That means check for need of FW upgrade is
going to be present in all builds, and moving to FW_FlASHING
mode from active is heavy operation; so the idea here is
simplify this process and save the boot time due to switching
back-n-forth between ACTIVE<=>FW_FLASHING modes.

So we decided to put unipro into OFF state by default on boot,
which can be changed through DT property. If arche-platform
device node has "arche,init-off" property set, then unipro
will be in OFF state on boot. User can bring it back by

 # echo active > /sys/devices/arche_platform*/state

And to simply the exit code of probe() fn the
arche_platform_coldboot_seq() has been shifted to the
bottom of the _probe() fn.

Testing Done: Tested on EVT2 platform, with and without
"arche,init-off" property, multiple times.
Note: I am seeing SW-7128, which is not related to these changes.

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>
2016-07-19 18:31:00 -07:00
Johan Hovold 042fd749ab greybus: connection: drop the svc quiescing operation
Connection tear down is being reworked, and the SVC quiescing operation
is going away.

Let's remove this operation now along with the coupled second ping from
our intermediate tear down implementation.

This both avoids unnecessary noise in the logs resulting from the fact
that the SVC side of the quiescing operation was never merged, and
speeds up connection tear down slightly.

Testing done: Tested on EVT2 using runtime PM.

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>
2016-07-19 18:27:35 -07:00
Rui Miguel Silva d53cc1c37e greybus: sdio: add switch voltage operation
Core sd/mmc needs the start_signal_voltage_switch operation to be
defined to issue a voltage switch command. So, we define it here even
though we do not need to take in action on it, since all voltage control
is done in the Module.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-19 16:38:24 -07:00
Rui Miguel Silva 484a4d6677 greybus: sdio: convert vdd kernel values to greybus
We need to convert vdd kernel values to greybus ones. And we get this by
shifting the kernel values by 8.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-19 16:38:24 -07:00
Viresh Kumar 56c78715ea greybus: bootrom: Use "s2l" instead of boot stage in package name
The S3 firmware and S3-BFU firmware images will be named like this going
forward:

S3: ara_00000126_00001001_fffe0001_ffe70018_s3f.tftf
S3-BFU: ara_00000126_00001001_fffe0001_ffe70018_s3_bfu.tftf

But the current naming for S2 loader image is:

ara_00000126_00001001_fffe0001_ffe70018_02.tftf

It makes sense to use similar encoding for all three packages and so it
should be named as:

ara_00000126_00001001_fffe0001_ffe70018_s2l.tftf

Because the boot stage is passed from ES3 bootrom, we can't change its
value now. But the string created to match the package name is created
in bootrom.c and that is the only string we create from bootrom.c.

Update bootrom.c to use "s2l" instead of "02" in the package name.

Compile Tested only.

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>
2016-07-19 13:52:26 -07:00
Bryan O'Donoghue 52764bd8aa greybus: timesync: Bugfix ping should not result in -EAGAIN
gb_timesync_schedule_synchronous() is currently making a synchronous
FrameTime synchronization happen. It does a wait_event_interruptible() and
then goes to check the status of the state-machine. Occasionally the state
indicates PING - which is a completely valid state and should result in a
result code of 0 not -EAGAIN. This patch fixes by making
__gb_timesync_get_status() return 0 instead of -EAGAIN for the PING state.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Tested-by: David Lin <dtwlin@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-19 11:16:25 -07:00
Bryan O'Donoghue 1455db9e1b greybus: greybus_protocols.h: convert __u32 to __le32
All 32 bit declarations associated with data interchange to the greybus
network need to be declared explicitly as little-endian since that is the
byte order we use on the greybus network. struct gb_audio_topology is
declaring its variables as u32. Fortunately this structure isn't currently
used so we can do a conversion from u32 to __le32 without any ancillary
code-churn.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-18 09:22:45 -07:00
Bryan O'Donoghue 6a1d29595e greybus: greybus_protocols.h/es2: Ensure __le32 is used not u32
There is a dangling u32 in es2/greybus_protocols.h that is only obvious
when you try to compile up gbsim. We need to do a cpu_to_le32 and declare
the 32-bit int in the header as __le32. This patch does that and splits out
the assignment of the req->flags parameter to a temporary variable to allow
for later printing.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-18 09:22:45 -07:00
Jacopo Mondi 433aa123f5 greybus: camera: Update CSI config parameters
Remove lines_per_second parameter from csi configuration
structure as VFE driver dropped dependency on it

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>
2016-07-17 10:31:21 +09:00
Jacopo Mondi f88b94ec2a greybus: camera: Configure APB-A with new params
Update the configuration supplied to APB-A to use new parameters, while
keeping compatibility with legacy camera modules.
Substitute hard-coded clock frequency with information provided by camera
module, and retrieve the maximum CSI Long Packet length from the
returned stream configuration.

This patch requires APB-A csi-tx driver to be updated to comply with
newly defined bandwidth requirements.

Testing Done: preview, capture and video recording with updated csi-tx
driver on APB-A side, and legacy white camera module firmware

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>
2016-07-17 10:31:21 +09:00
Jacopo Mondi d165a618a1 greybus: camera: Update Configure Streams Response
As camera specification gets updated, and Configure Stream Response
payload modified, define here the new response structure.
In order to not break non up-to-date camera modules, keep the existing
structure and add the _deprecated suffix to it.

Add the size of both new and old structure in order to discriminate
dynamically which version of Camera Specification the camera module
implements and translate deprecated version of configure_streams response
in the new one.

In order not to break camera functionalities, for testing purposes,
hard-code values the APB-A CSI Tx driver still requires for proper
interface configuration (lines_per_second and num_lanes)

Testing Done: Preview, capture and video recording with white camera
module and APB-A with legacy firmware implementations

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>
2016-07-17 10:31:21 +09:00
Laurent Pinchart 24f9a6e494 greybus: camera: Hardcode the APB-A CSI-2 TX parameters
Camera modules will stop reporting the number of lines per second,
hardcode the parameter in the driver until the APB-A CSI-2 TX
configuration protocol gets updated as well to use a more appropriate
form of bandwidth information.

The number of data lanes is also hardcoded as it should not depend on
the module's CSI-2 bus configuration.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-17 10:31:21 +09:00
Jacopo Mondi fdf73c00c8 greybus: camera: Add wrapper for sync operation with flags
The greybus operation core synchronous operation call doesn't support
operation flags. Create a new synchronous operation wrapper with flags,
and modify the capabilities operation implementation to use it.

The code could be later moved to the greybus core if other drivers have
a similar need.

Signed-off-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-17 10:31:21 +09:00
Jacopo Mondi 6cc270483c greybus: camera: Add bpp to Greybus Format description
Add the bytes per pixel value to the structure describing a Greybus
Protocol Image Format.
The bpp information will be used to compute the length in bytes of a
line of pixel data

Signed-off-by: Jacopo Mondi <jacopo.mondi@linaro.org>
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>
2016-07-17 10:31:21 +09:00
Viresh Kumar a0de502ed3 greybus: audio_topology: Fix compile warning
Fix following compile warning by staticizing gb_generate_enum_strings().

greybus/audio_topology.c:134:12: warning: symbol 'gb_generate_enum_strings' was not declared. Should it be static?

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-17 10:12:59 +09:00
Rui Miguel Silva 7a0d4eae83 greybus: power_supply: add missing defines present in the specification
Some of the Greybus properties values (capacity level and scope) even
though they are defined in the specification were missing from the
protocol header.

They still match the kernel ones, but they should be present in there
for protocol sake.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-16 08:05:33 +09:00
Rui Miguel Silva c10b4ea3b2 greybus: power_supply: remove references to kernel header
In Greybus power supply macro definitions we have a comment that point
to a kernel header, remove it since we have a specification for that.

As at it, align the status values to the upper values.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-16 08:05:33 +09:00
Bryan O'Donoghue fddd7eafc7 greybus: timesync/pm: Make synchronous call to restore FrameTime
When we discussed and agreed a serialized way to-do PM runtime
suspend/resume we omitted the necessity to restore the FrameTime on resume.
This patch restores the FrameTime synchronously such that when an Interface
PM resume callback completes we have either successfully restored the
FrameTime including the new Interface or we've produced a result code to
indicate what went wrong when trying.

Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Tested-by: David Lin <dtwlin@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-16 08:01:17 +09:00
David Lin 1f77b363be greybus: hd: arche-platform: implement greybus shutdown
Implement platform driver shutdown callback to perform proper greybus
shutdown so that the userspace unipro_shutdown service that shuts down
the APB/SVC abruptly can be removed. The shutdown callback in
arche-platform will first remove SVC so that all the Interface can be
Deactivated in a sequence according to the spec before powering off the
APB:

Before:
 -> Arche/APB power off
 -> SoC power off

After this patch:
 -> HD shutdown
     -> SVC shutdown
         -> Module shutdown
             -> Interface shutdown
                 -> Bundle shutdown
 -> Arche/APB power off
 -> SoC power off

Testing Done:
 - Observe all Interfaces are deactivated in the log during shutdown
 - Measure power off current and make sure no regression

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-16 07:58:52 +09:00
Rui Miguel Silva 47becc556d greybus: power_supply: convert greybus properties to power supply properties
We need to translate greybus properties to power supply core properties,
for that when parsing the properties that were fetch during
configuration we check if there is a match to the running kernel version
and store it in a new field (gb_prop) in the gb_power_supply_prop
struct.

If the corresponding property does not exist in the running
kernel (because of version or vendor specific property) we drop that
property.

A collection of properties that, at this time, may diverge are defined
in the kernel_ver.h to avoid breakage at build time and run time if this
properties are not supported by the kernel.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-16 07:55:41 +09:00
Rui Miguel Silva 6e720c277a greybus: power_supply: change property values to integer
To align with power supply core values type (integer) move the val and
previous_val to integer also.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-16 07:55:41 +09:00
Alex Elder fc0c38b3d1 greybus: use memdup_user()
Coccinelle reports that there are two opportunities to use memdup_user()
in "authentication.c".  This patch simplifies the code in cap_ioctl() by
taking advantage of that.  Make use of a local variable "size" to improve
readability.

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>
2016-07-15 09:14:27 +09:00
Alex Elder 99ade1766d greybus: get rid of a compile warning
The compiler has no way of knowing whether a called function will
actually assign something to the object whose address is passed as
an argument.  So it must assume it won't happen, and this leads to a
compile warning.  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>
2016-07-15 09:14:27 +09:00
Axel Haslam e854ff58ed greybus: loopback: add runtime pm support
Add runtime pm to the loopback driver so that
the module wakes up from suspend while a test
is executed.

Testing Done: Let the module enter standby and
execute a loopback test.

Signed-off-by: Axel Haslam <haslam_axel@projectara.com>
Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
Axel Haslam 4c615dcc6a greybus: spi: Add runtime_pm support
Add runtime operations to the spi driver so that the
module is woken up when an spi transfer is started
and put back to sleep when the transfer is done.

Testing Done: Let the module enter standby and initiate
an spi operation. The operation wakes up the module
and succeeds.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
Axel Haslam afa807b8ba greybus: pwm: Add runtime_pm support
Add runtime pm support for the pmw driver.

Testing Done: Set the parameters of pwm0, and enable.
Disable pwm0 and let the module enter standby.
Enable pwm0, and observe that with an oscilloscope
that the wave form is the same as before.

Signed-off-by: Axel Haslam <haslam_axel@projectara.com>
Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
Axel Haslam 993dc992f2 greybus: gpio: Add runtime_pm suppourt
Add runtime pm support for the gpio driver.
Since there is no remote wakeup support, the
module will not suspend as long as a gpio is
requested.

Maybe an optimization could be made, to allow suspend
if all the requested gpios are in output mode, since
the bridge should maintain the state of the gpio
during suspend.

Testing Done: using the test board, let the
gpbrige enter standby and request a gpio.

Signed-off-by: Axel Haslam <haslam_axel@projectara.com>
Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
Axel Haslam 22b8708725 greybus: uart: Add runtime pm support
This adds runtime pm support for the uart driver.

Testing Done: Using the test daughter board, let
the gpb bridge enter standby and do a uart transfer
operation.

Signed-off-by: Axel Haslam <haslam_axel@projectara.com>
Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
David Lin c0e72f6af7 greybus: i2c: add runtime pm support
Add runtime pm support to camera i2c bridged phy device class driver

Testing Done:
 - Passed #gb_test.sh -v -t i2c

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Axel Haslam <haslam_axel@projectara.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
David Lin af5dc7f8c0 greybus: gbphy: add gbphy runtime pm support
Since GBphy is a child of the Bundle device driver, for those runtime pm
settings that are common to all the protocol drivers need to go in to
the GBphy bus driver.

Testing Done:
 - Check gbphy driver can be autosuspended

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
David Lin 211634f2ca greybus: camera: add runtime pm support
Add runtime pm support to camera protocol device class driver.

Testing Done:
 - Make sure white camera module is able to runtime suspend and resume
   when the camera is being used

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
David Lin 6ba7fad430 greybus: audio: add runtime pm support
Add runtime pm support to audio protocol device class driver.

Testing Done:
 - Use white speaker module and check the interface is autosuspended when
   it's idle and resumed when playback audio

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
David Lin 61e13db9cc greybus: bundle: add runtime pm support
This patch adds runtime pm support for the bundle core. Unbound bundle
devices are always deactivated. During probe, Runtime PM status is set
to enabled and active and the usage count is incremented. If the driver
supports runtime PM, it should call pm_runtime_put() in its probe
routine and pm_runtime_get_sync() in remove routine as bundle needs to
be resume before it can be deactivated.

Testing Done:
 - Check runtime_status of the bundle driver when bundle goes to suspend

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
David Lin 30a3bf7b30 greybus: interface: add runtime pm support
Configure and enable runtime pm support for the Interface. Refer to the
12.2. The Interface Lifecycle of the Greybus specification for details
on the requirements for transitioning from ENUMERATED to SUSPEND and
vice versa. All the Bundles for the Interface have to be either OFF or
SUSPENDED before the Interface can be autosuspended.

Testing Done:
 - Check the runtime_status of an interface driver and validate the
   suspend current of a module.

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
David Lin 2d48b5b4a8 greybus: bundle: add activate and deactivate
AP shall send the Bundle Activate Operation to power on a bundle, and
send the Bundle Deactivate Request after closing all the associated
connections for power down.

Testing Done:
 - Check for the return code of the bundle activate and deactivate
  operation sent

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 16:53:55 -05:00
Johan Hovold 165a74ab14 greybus: es2: fix arpc response lookups
Fix arpc response lookups that were truncating the 16-bit response id to
8-bit, something which would have lead to all arpc calls timing out
after the 256th request.

Testing done: Enumerated and ejected a module on EVT2.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 14:36:33 -05:00
Viresh Kumar e818027c0b greybus: es2: Fix 'make check' warnings with arpc
This is what I got:

greybus/es2.c:1130:29: warning: restricted __le16 degrades to integer
greybus/es2.c:1140:22: warning: incorrect type in assignment (different base types)
greybus/es2.c:1140:22:    expected restricted __le16 [usertype] id
greybus/es2.c:1140:22:    got unsigned short [unsigned] [usertype] <noident>
greybus/es2.c:1162:52: warning: incorrect type in argument 8 (different base types)
greybus/es2.c:1162:52:    expected unsigned short [unsigned] [usertype] size
greybus/es2.c:1162:52:    got restricted __le16 [usertype] size
greybus/es2.c:1164:31: warning: restricted __le16 degrades to integer
greybus/es2.c:1253:34: warning: incorrect type in argument 2 (different base types)
greybus/es2.c:1253:34:    expected unsigned char [unsigned] [usertype] id
greybus/es2.c:1253:34:    got restricted __le16 [usertype] id

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-14 14:36:33 -05:00
Vaibhav Agarwal 12ce523147 greybus: audio: Maintain proper codec state during shutdown sequence.
During shutdown sequence, in case all modules are already removed,
codec state is not updated. Though it's not causing any harm for now,
but it's good to maintain proper codec state. Fix this.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com> 
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-13 13:48:07 -05:00
Vaibhav Agarwal cf1caac6cd greybus: audio: Fix incorrect codec state modification
In case module is removed dynamically with ongoing playback, during
module cleanup codec state is mistakenly modified. State should be
modified for module only. Fix this.

Fixes: 76414cb499b7 ("audio: Use single codec driver
registration")

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com> 
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-13 13:48:07 -05:00
Johan Hovold 3487394988 greybus: es2: fix arpc return value
ARPC should return 0 on success, but instead was returning the number of
jiffies left until the timeout.

This caused cport_reset() to report an error and an incorrect error
message to be printed when disabling a connection.

Reported-by: Alex Elder <elder@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Tested-by: Alex Elder <elder@linaro.org>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-13 09:44:05 -05:00
Alexandre Bailon c14118a841 greybus: es2: Implement APBridgeA RPC (ARPC)
Implement ARPC. In first time, we are going to use it to
implement new request but the goal is to update all existing vendor
request to use ARPC.

In addition, Convert the current USB Vendor request for CPort Reset
to ARPC so that we can be sure that the port has been fully reset
by the time the request completes.

Testing Done:
  AP can reset APBA Cports by using the ARPC command.
  In addition, tested with a hacked firmware that cause error during
  the Cport reset, and Greybus printed the error "failed to reset cport".

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-11 15:54:17 -05:00
Alexandre Bailon 9d9d3777a9 greybus: es2: Add a new bulk in endpoint for APBridgeA RPC
Add a new bulk in endpoint in order to get RPC status
from APbridgeA without to have to poll on control endpoint.

So the new endpoint layout is:
EP0: control EP
EP1 and EP2: muxed endpoints (bulk in and out)
EP3 to EP14: direct muxed endpoints (bulk in and out)
EP15: ARPC bulk in endpoint

Note:
This patch is allocating ARPC URBs but does nothing with them.
The following patch will use them.

Testing Done:
  Tested with an APBridgeA enumerating 16 endpoints.
  Kernel doesn't print Not enough endpoints found in device, aborting!

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-11 15:54:17 -05:00
David Lin 576bffb5a8 greybus: interface: send deactivate prepare when interface is disabled
The AP Interface shall exchange a Greybus Control Interface Deactivate
Prepare Operation with the Interface being powered down.

Testing Done:
 - Check for the return code after sending the deactivate prepare operation

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-08 14:56:28 -05:00
David Lin 707a5c42ce greybus: control: add connection suspend and resume calls
Adds function calls for handling control connection suspend and resume,
for now all they do is disable and enable control connection.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-08 14:56:28 -05:00
David Lin cc28c2c228 greybus: interface: implement unipro link hibernate call
Adds AP implementation of unipro link hibernation set power mode call
needed for proper cport closure and interface suspend and power off
transition.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-08 14:56:28 -05:00
David Lin c7dc28ff2b greybus: svc: add power mode call for link hibernation
Due to when using set_power_mode to hibernate a link, it won't trigger a
POWERMODEIND event, hence the hard-coded GB_SVC_SETPWRM_PWR_OK would be
returned and it should also be considered as successful result code for
link hibernation. Therefore, adding this set_power_mode_hibernate
function to separate the two calls in order to check with the correct
result code.

Testing Done:
 - Suspend an Interface and observe no set power mode error.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-08 14:56:28 -05:00
David Lin fc8a402713 greybus: svc: add interface resume operation
Add the AP implementation for the Greybus SVC Interface Resume
Operation. This operation allows the AP to request the SVC to resume an
Interface which was previously SUSPENDED, allowing it to later be
ENUMERATED.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-08 14:56:28 -05:00
David Lin 385227fce6 greybus: control: add interface hibernate abort operation
Add the AP implementation for the Greybus Control Hibernate Abort
Operation. AP may use this Operation to abort a previous Control
Interface Suspend or Control Interface Deactivate Prepare Operation.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-08 14:56:28 -05:00
David Lin 30ea26bdd4 greybus: control: add interface deactivate prepare operation
Add the AP implementation for the Greybus Control Interface Deactivate
Prepare Operation. AP uses this Operation during the Power Down
transition to request the bridge to power down after it detects a
subsequent UniPro link hibernation.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-08 14:56:28 -05:00
David Lin f53be0eaf0 greybus: control: add interface suspend prepare operation
Add the AP implementation for the Greybus Control Interface Suspend
Prepare Operation. AP uses this Operation during the Suspend transition
to request the Interface to enter a low-power mode after it detects a
subsequent UniPro link hibernation.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-08 14:56:28 -05:00
David Lin f61908f94a greybus: control: add bundle deactivate and activate operation
Add the AP implementation for the Greybus Control Bundle Deactivate
Operation. This operation requests a Bundle to enter the BUNDLE_OFF
state. All Connections associated with the Bundle must be closed prior
sending this operation.

Add the AP implementation for the Greybus Control Bundle Activate
Operation. This operation requests a specific Bundle to transition from
the BUNDLE_OFF state to the BUNDLE_ACTIVE state.

[elder@linaro.org: fixed a typo pointed out by Johan]

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-08 14:56:28 -05:00
David Lin 2c8e8841e3 greybus: control: add bundle suspend and resume preparations
Add the AP implementation for the Greybus Control Bundle Suspend
Operation. This Operation is used to request a Bundle to enter the
BUNDLE_SUSPENDED state, all Connections associated with this Bundle must
be closed before issuing this operation.

Add the AP implementation for the Greybus Control Bundle Resume
Operation. This operation request a specific Bundle to transition from
the BUNDLE_SUSPENDED state to the BUNDLE_ACTIVE state.

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-08 14:56:28 -05:00
Fabien Parent 776165481d greybus: connection: remove CDSI1 hack
This hack is not necessary anymore since the firmware is now able to
handle correctly (dis)connect{ed,ing} operations on the CDSI CPort.

Testing Done: Checked that I could start the camera app several time
              and got the preview each time.

Signed-off-by: Fabien Parent <fparent@baylibre.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-06 17:51:32 -05:00
Viresh Kumar 6f4219dd7d greybus: Documentation: Document Authentication interfaces
This patch defined userspace interface of the CAP protocol.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Jun Li <li_jun@projectara.com>
Tested-by: Jun Li <li_jun@projectara.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-06 17:51:32 -05:00
Viresh Kumar e3eda54d0b greybus: Add Component Authentication Protocol support
This patch adds Component Authentication Protocol support in greybus.
The purpose of the CAP protocol is to authenticate the Module hardware,
and it can only be used when it is present as part of the
firmware-management bundle, on a separate CPort.

Compile tested only.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Jun Li <li_jun@projectara.com>
Tested-by: Jun Li <li_jun@projectara.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-06 17:51:32 -05:00
Jacopo Mondi 80b3982b8d greybus: camera: Fix size of configure_streams(0)
When APB-A CSI-Tx configuration fails, it is necessary to unconfigure
the camera module issuesing a 0 stream configuration request.
Fix size of request and response to avoid Greybus core complain about
Response size differences.

Testing Done: Triggering the error condition after APB-A CSI-tx
              configuration does not make Greybus core complain anymore

Signed-off-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-05 21:18:05 -05:00
Jacopo Mondi 36ab1108b6 greybus: camera: Fix number of configured streams
Camera Module may report a lower number of configured streams than the
one requested by the AP.
All the non-supported stream configuration are zeroed.
Make the stream configuration inspection loop take only the valid stream
into account, to avoid unnecessarily accessing zeroed memory areas.

So far, inspecting non valid streams configuration has prove to be
harmless, but as we'll need to inspect stream characteristics as reported
image sizes and format, we have to take only valid configurations into
account.

Testing Done: White Camera Module preview and capture.

Signed-off-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-05 21:18:03 -05:00
Jacopo Mondi 7f93eab7c7 greybus: camera: Early update num_streams and flags
In configure_streams Operation, when returning from the greybus
operation call, we can assign the num_streams and flags variable earlier
so that if the following stream configuration inspection fails, the
caller receives the right number of configured streams anyway

Testing Done: White camera module preview and capture.
              Triggering failure during stream configuration inspection
              makes configuration fails, but avoid segfaulting as
              was previously happening

Signed-off-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-05 21:18:00 -05:00
Vaibhav Agarwal e65579e335 greybus: audio: topology: Enable enumerated control support
Added .get/.set callback and relevant changes in parser to enable
enumerated control support for kcontrols and DAPM widget controls.
Currently, it is limited to enumerated strings only.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mark.greer@animalcreek.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-05 21:17:58 -05:00
Vaibhav Agarwal d4cd9daa49 greybus: audio: topology: Use csize while computing next_ptr in parser
Size of control elements vary in case of enumerated controls. As a
preparation to enable enumerated control in topology parser, this patch
uses csize while parsing controls & wsize while parsing widgets & its
control to update next pointer.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mark.greer@animalcreek.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-05 21:17:56 -05:00
Vaibhav Agarwal bb296b4803 greybus: added warning message in case of missing widget
Additional warning message added to notify in case above layer tries to
access widget that is already removed from the list.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mark.greer@animalcreek.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-05 21:17:54 -05:00
Vaibhav Agarwal 0c15a9e0f3 greybus: audio: topology: Add helper API to map controlid with widget name
This API is used by enumerated controls .get/.set callback functions to
fetch control id associated with a widget.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mark.greer@animalcreek.com>
Signed-off-by: Alex Elder <elder@linaro.org>
2016-07-05 21:17:51 -05:00
Viresh Kumar 957ccca08a greybus: light: Initialize mutex before using it
Light protocol driver is suffering from the same issue that was fixed in
camera driver earlier (commit a7c3b0c3c8da).

Big cleanup function is used instead of fine grained control in the
error path, and in one of the cases the mutex was found uninitialized
and so the oops seen in SW-6752.

Initialize the mutex before any code can access it.

Compile tested only.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-29 16:37:17 -07:00
Johan Hovold 2aae92bdc2 greybus: Revert "greybus: uart: don't use spin_lock_irq()"
This reverts commit bd3c4aa99dc23449699432e0744bcb5af7afa98c.

Someone decided that all use of spin_lock_irq was to be considered a bug
and went on a search-and-replace type "bug-fixing" spree last week.

This is however just plain wrong. Using spin_lock_irq is perfectly fine
in paths were interrupts have not been disabled, and this is in fact
even preferred over the lazy approach of always using spin_lock_irqsave
instead of understanding the code that is being written or modified.

All current uses of spin_lock_irq have already been vetted in this
respect. Also note that it is only used in functions that may sleep,
that is, in functions that must not be called with interrupts disabled
in the first place.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-29 16:37:17 -07:00
Johan Hovold 07af934094 greybus: Revert "greybus: es2.c: don't use spin_lock_irq()"
This reverts commit b44c3b5b0307788750eb4c462ed5982236876a8b.

Someone decided that all use of spin_lock_irq was to be considered a bug
and went on a search-and-replace type "bug-fixing" spree last week.

This is however just plain wrong. Using spin_lock_irq is perfectly fine
in paths were interrupts have not been disabled, and this is in fact
even preferred over the lazy approach of always using spin_lock_irqsave
instead of understanding the code that is being written or modified.

All current uses of spin_lock_irq have already been vetted in this
respect. Also note that it is only used in functions that may sleep,
that is, in functions that must not be called with interrupts disabled
in the first place.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-29 16:37:17 -07:00
Johan Hovold 0b1d262354 greybus: Revert "greybus: gb_connections_lock: don't use spin_lock_irq()"
This reverts commit b022fd95108e8b9d202532a74d39e86152bc8f7f.

Someone decided that all use of spin_lock_irq was to be considered a bug
and went on a search-and-replace type "bug-fixing" spree last week.

This is however just plain wrong. Using spin_lock_irq is perfectly fine
in paths were interrupts have not been disabled, and this is in fact
even preferred over the lazy approach of always using spin_lock_irqsave
instead of understanding the code that is being written or modified.

All current uses of spin_lock_irq have already been vetted in this
respect. Also note that it is only used in functions that may sleep,
that is, in functions that must not be called with interrupts disabled
in the first place.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-29 16:37:17 -07:00
Johan Hovold a29bac623f greybus: Revert "connection: switch to using spin_lock_irqsave/spin_lock_irqrestore excluisvely"
This reverts commit 426237c515b42b9f06d9a2b1021a6d2c4d440c51.

Someone decided that all use of spin_lock_irq was to be considered a bug
and went on a search-and-replace type "bug-fixing" spree last week.

This is however just plain wrong. Using spin_lock_irq is perfectly fine
in paths were interrupts have not been disabled, and this is in fact
even preferred over the lazy approach of always using spin_lock_irqsave
instead of understanding the code that is being written or modified.

All current uses of spin_lock_irq have already been vetted in this
respect. Also note that it is only used in functions that may sleep,
that is, in functions that must not be called with interrupts disabled
in the first place.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-29 16:37:17 -07:00
Sandeep Patil 1beb1fae80 greybus: svc: remove input device handling in SVC protocol
The input device was added before to handle the key(s) connected
directly to SVC, which is not the case anymore. So, this change removes
the gb_svc_key_event() operation and the corresponding input device
code with it.

Testing Done:
Boot tested and tried module insert/removal through AraManager

Change-Id: Iaa541d4aefb5c0ed16caaa39450029de35d7c228
Signed-off-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-28 17:54:38 -07:00
Viresh Kumar 0ef5be1885 greybus: kernel_ver: Add kstrtobool()
It was added in 4.6 and is required for one of the use case, copy it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-28 17:54:38 -07:00
Johan Hovold 74ec7598b5 greybus: es2: add support for greybus cport flags
Add support for Greybus CPort flags that are sent to the bridge through
a new USB vendor request when enabling a CPort as part of connection
establishment.

Currently the Greybus control and high-priority connection flags are
recognised and forwarded to APBA.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 16:22:30 -07:00
Johan Hovold 3094f94773 greybus: connection: add support for high-priority connections
Add connection flag to indicate that a connection has high priority.

For the SVC and control connections this may be used by the host-device
driver as a hint to allocate dedicated DMA channels or to use polling to
avoid message congestion.

We also allow drivers to set this flag on their connections, even though
we currently have no use case for this (and the host-device driver is
again free to ignore it).

Note that this mechanism can be used to indicate also high-bandwidth
connections (e.g. wanting larger buffers or dedicated endpoints), but
that that should be done using a separate high-bandwidth flag rather
than overloading the high-priority flag.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 16:22:30 -07:00
Johan Hovold 1ba30c3309 greybus: connection: prevent drivers from specifying core flags
Prevent drivers from specifying core flags (currently only
GB_CONNECTION_FLAG_CONTROL) when creating connections.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 16:22:30 -07:00
Johan Hovold 6910fa2dd6 greybus: hd: add flag argument to cport_enable callback
Add a flag argument to the host-device cport_enable callback that can be
used to provide hints about the connection being created (e.g.
connection priority).

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 16:22:30 -07:00
Evgeniy Borisov caad3090ab greybus: camera: Add RAW data format
Add support for greybus RAW data format.
Greybus RAW data formats starts from 0x80.

Signed-off-by: Evgeniy Borisov <eborisov@mm-sol.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 16:13:52 -07:00
David Lin 9e138dd479 greybus: audio: remove the unnecessary return statement
The return statement immediately after the BUG_ON of the gbcodec_write()
call is added by mistake. It's not causing any errors right now due to
that gbcodec_reg is currently not being used.

Testing Done:
- Audio playback on EVT2

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 16:06:51 -07:00
Jeffrey Carlyle 2d466c23c6 greybus: connection: switch to using spin_lock_irqsave/spin_lock_irqrestore excluisvely
We know that it is a bad idea to explicitly enable IRQs when we don't
don't know if they were already off before we disabled, so switch to the
save _irqsave and _irqrestore functions.

Ultimately, we need to review places in the Greybus drivers where IRQs
are disabled and remove unnecessary instances. This is only an interim
step.

This code will never run from hard irq context, as it is already taking
mutex in the path.

Testing done: booted EVT2.0, ran suspend/resume test app with a period
of 20s for a few dozen cycles.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 16:06:23 -07:00
Viresh Kumar 326f98ac31 greybus: bootrom: Wait for 10 seconds for mode-switch
The greybus SVC core handles events from the SVC serially today. In some
cases the SVC operations may take too long, for example trying to
activate a dummy interface. If another interface receives a mode-switch
mailbox event in that time, the SVC core wouldn't be able to process it
in quickly enough and bootrom driver will print following error:

bootrom 1-3.3.1: Timed out waiting for Interface Mode Switch from the Module

This can be reproduced easily by attaching a 2x2 module along with any
other normal module like camera or speaker, and doing a unipro_reset
from userspace.

The logs suggest this time to be around 6-7 seconds in most of the
cases. Attaching multiple modules with dummy interfaces may make this
worst.

Lets increase the timeout from 5 to 10 seconds for now, also add a FIXME
for the same.

Testing Done: Tested on EVT 2.0 with camera and a 2x2 module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 16:03:28 -07:00
Viresh Kumar dbb8cfeba9 greybus: bootrom: send timeout in milliseconds to gb_bootrom_set_timeout()
Rename NEXT_REQ_TIMEOUT_J to NEXT_REQ_TIMEOUT_MS and store the timeout
in milliseconds instead of jiffies.

Suggested-by: Alex Elder <alex.elder@linaro.org>
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>
2016-06-24 16:03:28 -07:00
Viresh Kumar a4293e1d4e greybus: bootrom: Enhance timeout error message
The timeout message is very generic today and there are several requests
we can be timing out waiting for.

Update bootrom driver to also track the next expected request and
enhance the error message based on that to confirm the request we timed
out waiting for.

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>
2016-06-24 16:03:28 -07:00
Bryan O'Donoghue fd6d6f61d8 greybus: timesync: Make printout consitent with other greybus messages
The current printout on a TimeSync ping doesn't actually contain the word
greybus and uses the word ping-time in the print string, something that
appears nowhere in our official documentation on this feature. This patch
changes the format string to contain 'greybus' and 'frametime' to bring the
TimeSync printout more in-line with other greybus kernel log strings.

before:
timesync ping-time: ap=8632564 1-svc=8630712 greybus1=8633031 1-8.8=8633026

after:
greybus frametime: ap=8632564 1-svc=8630712 greybus1=8633031 1-8.8=8633026

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 15:49:58 -07:00
Bryan O'Donoghue 50687f3609 greybus: timesync: Initialize the timesync ping fields to zero
Remember to initialize the TimeSync ping fields to zero so that if a
timesync_get_last_event() returns an error - we display a FrameTime that is
obviously incorrect.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 15:49:58 -07:00
Joel Porquet c0e65d026c greybus: add support for the log protocol
Add support for the new Log class/protocol. This protocol allows modules
to send their internal logging messages to the AP in order to make
module debugging easier.

The protocol is, for now, composed a single module-initiated request.
This request contains a message and associated length. The message is
integrated in the kernel log with dev_dbg(). In order to be displayed
with 'dmesg', the following command needs to be entered first:

$ echo "file log.c +p" > /sys/kernel/debug/dynamic_debug/control

The major portion of this file was initially written by Greg KH.

Signed-off-by: Joel Porquet <porquet_joel@projectara.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-24 15:46:52 -07:00
Viresh Kumar 6f7f2ae5df greybus: gb_connections_lock: don't use spin_lock_irq()
spin_[un]lock_irq() routines should be used carefully as they things can
go wrong, if they are mixed with spin_lock_irqsave() or other variants.

The main problem is that spin_[un]lock_irq() routines doesn't check if
the IRQs are already disabled/enabled on the local CPU and so
spin_unlock_irq() will forcefully enable interrupts for example.

This may not work well, if some other code was relying on interrupts
being disabled.

Use spin_lock_irqsave() and spin_unlock_restore() instead.

This patch doesn't claim that it fixes the JIRA completely, but
the issue was harder to reproduce for some iterations after this, which
was quite easy to reproduce earlier on.

Tested on EVT 2.0 with lots of debug patches to kernel and greybus.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 15:30:45 -07:00
Viresh Kumar fe9054155d greybus: es2.c: don't use spin_lock_irq()
spin_[un]lock_irq() routines should be used carefully as they things can
go wrong, if they are mixed with spin_lock_irqsave() or other variants.

The main problem is that spin_[un]lock_irq() routines doesn't check if
the IRQs are already disabled/enabled on the local CPU and so
spin_unlock_irq() will forcefully enable interrupts for example.

This may not work well, if some other code was relying on interrupts
being disabled.

Use spin_lock_irqsave() and spin_unlock_restore() instead.

This patch doesn't claim that it fixes the JIRA completely, but
the issue was harder to reproduce for some iterations after this, which
was quite easy to reproduce earlier on.

Tested on EVT 2.0 with lots of debug patches to kernel and greybus.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 15:18:42 -07:00
Viresh Kumar e9f80f3363 greybus: uart: don't use spin_lock_irq()
spin_[un]lock_irq() routines should be used carefully as they things can
go wrong, if they are mixed with spin_lock_irqsave() or other variants.

The main problem is that spin_[un]lock_irq() routines doesn't check if
the IRQs are already disabled/enabled on the local CPU and so
spin_unlock_irq() will forcefully enable interrupts for example.

This may not work well, if some other code was relying on interrupts
being disabled.

Use spin_lock_irqsave() and spin_unlock_restore() instead.

This patch doesn't claim that it fixes the JIRA completely, but
the issue was harder to reproduce for some iterations after this, which
was quite easy to reproduce earlier on.

Tested on EVT 2.0 with lots of debug patches to kernel and greybus.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 15:17:46 -07:00
Greg Kroah-Hartman 19cdabcf0b greybus: Revert "greybus: don't use spin_lock_irq()"
This reverts commit 469fbe5da0229edcb42aa08bef8e10feaa37e6d7.

It isn't correct in places.

Reported-by: Gjorgji Rosikopulos <rosikopulos_gjorgji@projectara.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 14:20:02 -07:00
Bryan O'Donoghue 1211915127 greybus: timesync: Enforce TimeSync locks as subordinate to Interface locks
gb_timesync_svc_teardown() is called from gb_timesync_svc_del() and issues a
command to a remote Interface to switch off its timers. The lock ordering
is TimeSync => Interface in this case. However gb_module_del() takes an
Interface lock then calls gb_interface_del() => gb_timesync_svc_del() in
this case the lock ordering is Interface => TimeSync.

This patch fixes by removing the taking of the Interface mutex in
gb_interface_timesync_do_something(). If an Interface is present in the
TimeSync linked-list - it is by definition intf->enabled.

Reported-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 14:15:21 -07:00
Viresh Kumar 5e2b63915c greybus: don't use spin_lock_irq()
spin_[un]lock_irq() routines should be used carefully as they things can
go wrong, if they are mixed with spin_lock_irqsave() or other variants.

The main problem is that spin_[un]lock_irq() routines doesn't check if
the IRQs are already disabled/enabled on the local CPU and so
spin_unlock_irq() will forcefully enable interrupts for example.

This may not work well, if some other code was relying on interrupts
being disabled.

Use spin_lock_irqsave() and spin_unlock_restore() instead.

This patch doesn't claim that it fixes the JIRA completely, but
the issue was harder to reproduce for some iterations after this, which
was quite easy to reproduce earlier on.

Tested on EVT 2.0 with lots of debug patches to kernel and greybus.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 14:15:21 -07:00
Viresh Kumar 05e3095563 greybus: Revert "greybus: ratelimit errors usually seen on unipro_reset"
This reverts commit 9b891f4fda8dfd6c1d8dc16479c5f6d418a9ccc7.

We discussed this over the other thread,

[PATCH 0/2] Improve watchdog's implementation a bit,

and decided that we shouldn't be trying to hide the watchdog reboot
problem by using such patches, rather we should make sure they occur
consistently so that the real problem can be fixed.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 14:06:08 -07:00
Michael Scott c13a206f7e greybus: adjust kernel version check for led_sysfs_is_disabled
When building greybus against a 3.18 kernel the following error is generated:
light.c:205:9: error: implicit declaration of function 'led_sysfs_is_disabled'
[-Werror=implicit-function-declaration]

led_sysfs_is_disabled was not added until 3.19 kernel cycle

Verification:
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/include/linux/leds.h?h=linux-3.18.y
(no function led_sysfs_is_disabled defined here)

Testing Done:
- Successfully built greybus for 3.18 kernel

Signed-off-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 11:50:58 -07:00
Vaibhav Hiremath 2d533cf16b greybus: ratelimit errors usually seen on unipro_reset
It is believed that excessive serial messages from greybus
on suspend/resume is leading to watchdog bite.
There is still discussion going on whether ratelimiting
prints would really fix anything, except it may reduce
traffic on serial console and probably bring out real issues
in the front.
So in order to meet the alpha requirement, we all decided to
get ratelimit change "as a TEMP fix" and decide later whether
we should revert back once we get proper suspend/resume implementation.

Please follow the discussion on Jira card SW-6261.

Testing Done: Build tested against ara/main branch.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Konstantin Buhchev <buhchev_konstantin@projectara.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-21 12:28:09 -07:00
Rui Miguel Silva e3b090ea95 greybus: sdio: avoid extra memory operation at data transfer
Right now greybus sdio uses the greybus operation_sync to transfer data,
this will imply an extra memcpy at greybus core that we can avoid.

Also with this change we remove the need for an extra buffer to store
intermediate copy.

So, let us create the operation and do the memory operations in the sdio
driver.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-21 12:28:09 -07:00
Viresh Kumar 0698be0281 greybus: connection: add trace events before disabling connection
This is what we are doing elsewhere:
- Send enable/create trace events after enabling/creating stuff.
- Send disable/remove trace events before disabling/removing stuff.

This wasn't followed in a same way while disabling connections. Fix it.

Compile tested.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-16 10:14:30 -07:00
Viresh Kumar 4ee48a5ecb greybus: firmware: prefix char-device with 'gb-'
This will make it consistent with any other character devices we have
for greybus and let us identify greybus character devices easily.

Compiled tested only.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-16 10:13:20 -07:00
Bryan O'Donoghue 93dbb97a3e greybus: timesync: Rework timesync removal serialization logic
We need to make sure we adequately cancel and quiesce any scheduled
TimeSync synchronization operations in the case of greybus.ko being yanked
out of memory i.e. when doing an EHCI runtime suspend or just a plain
rmmod. The scenario is a new TimeSync sync operation has been scheduled.
Next gb_timesync_svc_remove() runs. In this case we should terminate any
scheduled work, terminate our ktime tracking timer and state transition to
GB_TIMESYNC_STATE_INVALID to ensure no other context may schedule any new
TimeSync operations.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-16 09:07:41 -07:00
Bryan O'Donoghue 0cc3bc6930 greybus: timesync: Fix transitions to the INACTIVE state
Analysing a backtrace associated with the current EHCI runtime suspend code
has highlighted several places where its perfectly valid to make a
transition to GB_TIMESYNC_STATE_INACTIVE when not already in the
GB_TIMESYNC_STATE_INIT state, for example failure to issue a TimeSync
enable command to the SVC can and should legitimately call
gb_timesync_teardown() - at this point the state will be
GB_TIMESYNC_STATE_WAIT_SVC and it's legitimate and desirable to transition
to the INACTIVE state in this case. This patch fixes by removing the
restrictive and incorrect restriction on the transition to INACTIVE only
being valid when state == GB_TIMESYNC_STATE_INIT.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-16 09:07:41 -07:00
Bryan O'Donoghue c9e8f893ee greybus: timesync: Do not hold mutex on cancel_delayed_work_sync
There is a scenario where gb_timesync_svc_remove() can run, attain a mutex
and call cancel_delayed_work_sync(). In the meantime a worker may already
be running and trying to attain the same mutex but will never do so as the
gb_timesync_svc_remove() path is holding the mutex and waiting on the
delayed_work_sync() to complete - leading to deadlock. This patch addresses
by calling the cancel_delayed_work_sync() before locking the relevant
mutex.

Reported-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-16 09:07:41 -07:00
Viresh Kumar df124299d1 greybus: firmware: Add license and copyright header to application
Add license and copyright header to the firmware.c test application.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-16 00:03:43 -07:00
Viresh Kumar 42830f7f63 greybus: manifest: Disallow reuse of control cport
We should be checking if any of the bundles contains a CPort with its id
set to the special value of '0', which is reserved for control CPort.

Discard the bundle in that case.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-15 23:57:20 -07:00
Vaibhav Hiremath 880bc0a4af greybus: svc: Pass the correct pointer to input_free_device()
In gb_svc_input_create() fn, on failure, wrong pointer
was being passed to input_free_device(). Correct it.

svc->input gets initialized only on successful return of this fn,
so it is absolutely wrong to pass svc->input to input_free_device().

Testing Done: Tested on EVT2.0 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-15 23:57:20 -07:00
Laurent Pinchart 9120b9060b greybus: camera: Create and destroy data connection on demand
Creating the data connection at probe time makes it impossible to
support multiple inserted camera modules as they would all try to
establish a data connection to the same CPort on the AP side. Create and
destroy the data connection when configuring the streams instead, as a
single module can be streaming at a time.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Tested-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-15 05:05:47 -07:00
Laurent Pinchart 3b8ebfeb32 greybus: camera: Fix data connection setup
When the module is in the configured state, an attempt to change the
configuration must first tear down the data connection to update its
parameters, as the APB1 bridge doesn't support modifying the CSI
transmitter configuration when it is already started.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Tested-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-15 05:05:47 -07:00
Laurent Pinchart f3d5f6613f greybus: camera: Clean up on stream configuration failure
When the camera pipeline can't be configured due to a failure of one of
the components (failure to start the CSI transmitter for instance),
components that have already been setup for video streaming need to be
set back to a quiescient state. This is especially important to ensure
that a stream configuration failure won't keep the UniPro links in high
speed mode forever.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Tested-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-15 05:05:47 -07:00
Viresh Kumar d1a8c36ec1 greybus: svc: disable connection after all its users are gone
gb_svc_del() can be called during removal of gb-es2.ko module as well,
and in that case we would like to properly shutdown all modules and
interfaces as USB is still alive.

This requires that we don't disable the svc connection, at least for tx,
as that will be used while removing modules and interfaces.

Disable only rx to begin with, as we shouldn't be handling any requests
from the SVC. Disable tx only after all the users of svc connection are
gone.

Tested on EVT 2.0 by remove gb-es2.ko module. There are still few
errors, specially while quiescing the connections (-22), but not that
many.

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>
2016-06-14 12:05:44 -07:00
Viresh Kumar d9e4c4ee12 greybus: camera: Initialize mutex before using it
We are using the mutex from gb_camera_cleanup(), which can get called
even before the mutex is initialized.

Fix it by initializing the mutex early enough.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-13 11:10:09 -07:00
Viresh Kumar 54131222e6 greybus: connection: Return bool from gb_connection_intf_find()
This is used only to check if an existing connection already uses the
cport_id or not and doesn't really need to return pointer to the
connection.

While at it, also rename it to suit its purpose.

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>
2016-06-10 16:32:33 -07:00
Viresh Kumar 60fb3405c7 greybus: Remove extra blank lines
This patch removes few blank lines across the repository at places where
two blank lines were present together or when a blank line is present at
the start or end of a routine.

Note that this doesn't remove most of them from greybus_protocols.h as
they were added on purpose.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-10 16:32:33 -07:00
Viresh Kumar 6554efa28e greybus: firmware: Fix spelling mistake
s/directly/directory :)

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-10 16:32:33 -07:00
Bryan O'Donoghue 4c2f8a48e9 greybus: timesync: Do 64 bit divisions in a 32 friendly way
We need to use 'do_div()' when doing 64 bit division or modulo division
since the kernel will not pull in the gcc builtins __aeabi_ldivmod and
__aeabi_uldivmod on 32 bit builds.

Reported-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-10 16:26:31 -07:00
Bryan O'Donoghue 6db9cc68d7 greybus: uart: Fix minor number leak
On the gb_uart_remove() path we are forgetting to do a release_minor()
leading to a minor number leak. This is a simple one-line fix.

Tested on EVT 2.0

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-10 16:26:31 -07:00
Vaibhav Agarwal c6722ab5d3 greybus: audio: Ratelimit err messages in bundle, topology driver
Earlier I have shared a patch to rate limit err messages in audio_codec
driver. However, missed to include suggestion from Mark to do similar
changes in audio bundle & topology parser as well. Doing it now.

Testing Done: Compile tested

Fixes: 4cb3d109e5fc ("audio: Ratelimit err messages")
Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-10 11:46:06 -07:00
Vaibhav Agarwal f2b6303d45 greybus: Remove apbridgea_shutdown_xx sequence if already done
While reordering gb_deactivate sequence to avoid protocol error this was
mistakenly added even during shutdown_tx/rx. It is supposed to be done
immediately after stop_tx and only once.

Fixes: 739f25d5f490 ("audio: Reorder gb_deactivate sequence to avoid protocol error")
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>
2016-06-09 21:21:09 -07:00
Vaibhav Agarwal 27c243cf5f greybus: Use mute_stream callback to initiate GB data xfer
Currently trigger callback is used to start/stop greybus tx/rx
path. This works well for almost all scenario except few
specially handled usecases by Android Audio subsystem.

In case of Music playback followed by Incoming ringtone, above
layer tries to trigger_pause from one FE dailink and start a
fresh playback via different FE dailink. Since, same BE dailink
is used for both cases, an invalid state transition is requested
i.e. from PAUSE->START. This fails & thus causes ringtone playback
failure. With built-in codec, trigger callback is not required to
initiate data xfer unlike gb-codec driver.

This state transition should be handled in Android layer, but
since it can lead to multiple side effects for various usecase
we are trying to avoid trigger callback in gbcodec driver 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>
2016-06-09 21:21:09 -07:00
Eli Sennesh 8c2522d87a 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.

We must make sure to zero the request structure sent across the wire, lest
bite us most cruelly, and we fix by changing the Set Power Mode
Response structure to use a __u8 rather than a __le16.

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.  Could induce error by initializing request struct with random
nonsense, and can stop it by initializing request struct with zeroes.

Associated Firmware Changes: 1669-1671 on Android N Gerrit for SW-2945

Signed-off-by: Eli Sennesh <esennesh@leaflabs.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 18:14:00 -07:00
Viresh Kumar 62e0462353 greybus: connection: Avoid unnecessary line breaks
Some line breaks weren't required as we never crossed 80 columns, remove
them.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 17:28:02 -07:00
Viresh Kumar 56278c7384 greybus: hd: Export host device tracepoint from hd.c
There is no point keeping this code in core.c, while its only used by
hd.c. Relocate it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 17:28:02 -07:00
Viresh Kumar c05d471b2d greybus: Remove legacy suspend/resume callbacks
We should be using the PM hooks available within the 'struct
device_driver', instead of adding legacy suspend/resume callbacks.
Remove them.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 17:28:02 -07:00
Viresh Kumar 8a285fed1a greybus: Use BIT(2) for GREYBUS_ID_MATCH_CLASS
Bit 2 was left unused, use it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 17:28:02 -07:00
Viresh Kumar 129a6fbe76 greybus: core: Make greybus_match_one_id() return bool
This routine always returns 0 or 1 and a return type of 'bool' suits it
the best. Update it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 17:28:02 -07:00
Viresh Kumar aa62b5e49a greybus: bootrom: Compile as a separate module
User space doesn't break anymore with new greybus modules and its time
to make bootrom a separate module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 17:28:02 -07:00
Marti Bolivar 9e50e987f5 greybus: remove obsolete SVC result codes
The "busy" SVC result codes are gone from the spec. Delete them.

Testing Done: compile.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 17:21:09 -07:00
Viresh Kumar 12e6895d1e greybus: pwm: Fix compilation with v4.3 kernel
pwm_is_enabled() wasn't enabled by v4.2-rc1, but it was based of
v4.2-rc1. It was actually first included in v4.3.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 12:28:48 -07:00
Gjorgji Rosikopulos cb14e97623 greybus: camera: Add debug data format
Add support for greybus debug data format.
Greybus debug data format id is 0x42.

Signed-off-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Acked-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 12:15:06 -07:00
Johan Hovold 82278bfea0 greybus: fix forced disable of offloaded connections
Core disables all connections for bundles whose interface is already
gone in order to avoid unnecessary operation timeouts during driver
disconnect.

This isn't needed for offloaded connections (as the AP can not send
requests over such connections), and in fact must not be done since only
the bundle driver currently knows how to disable I/O on such connections
in a class-specific way (this may eventually be handled by core though).

Also add comment about why connection are disabled early on forced
disconnect.

Testing Done: Tested on EVT2.

Reported-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Tested-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 12:12:43 -07:00
Alex Elder c0b06a6d4e greybus: tracing: drop "greybus" prefix
I posted this once before but it got rejected for fear it would
not be clear which messages were related to Greybus.

Every trace event currently defined for Greybus is recorded in a
function whose name begins with "gb_".  Every trace event reported
in /sys/kernel/debug/tracing/trace includes the name of the function
in which the event was recorded.

Get rid of the "greybus: " prefix in all of the Greybus trace
events.  It just takes up precious space and is not actually
helpful.  Anyone actually enabling individual trace events should
know enough about what they're doing to recognize which ones
are being enabled.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-09 12:12:43 -07:00
Alex Elder 365d79fc20 greybus: don't key on an enumerated constant
The symbol PWMF_ENABLED is defined via an enum, which is not defined
at the time the preprocessor passes through "kernel_ver.h".  So we
can't use it in an #if statement expression.

Use the Linux kernel version instead.

Change-Id: Id427224b1dfecfd886fcdae89c4bcf711b616439
Signed-off-by: Alex Elder <elder@linaro.org>
2016-06-08 12:44:48 -07:00
David Lin 8fb76c3cfd greybus: svc: pwrmon: validate svc protocol op status when getting rail names
AP should check for Greybus SVC Protocol Operation Status to determine if the
operation was successfully completed by the SVC

Testing Done:
- Successfully getting the rail names in the pwrmon_dummy sandbox branch

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-08 10:21:34 -07:00
Greg Kroah-Hartman 44d6449350 greybus: kernel_ver.h: provide pwm_is_enabled()
In the 4.7-rc1 kernel release, PWMF_ENABLED is removed and
pwm_is_enabled() is the correct way to test if a pwm device is enabled,
so provide a version of that function that will work on all older
kernels and change the pwm.c driver to use it so that it will work on
newer kernels as well.

Tested:
	Tree now builds successfully against 3.14.y, 4.4.y, 4.5.y,
	4.6.y, and 4.7-rc2 kernels

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-08 09:29:02 -07:00
Vaibhav Agarwal 4d27574cd3 greybus: audio: Ratelimit err messages
In case of audio mgmt connection failure, GB requests would fail giving
an error message within the driver and reporting error. However there is
no error handling in above HAL and it'll keep on triggering similar
request via GB codec driver. This may overflood serial console. In one
of the instance it locked CPU for >10sec and caused a watchdog bite.
Thus ratelimit those error messages.

Testing Done: compile tested

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-08 09:29:02 -07:00
Jeffrey Carlyle 109fbdfd6a 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>
2016-06-07 21:10:13 -07:00
Bryan O'Donoghue 423042f4b2 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>
2016-06-06 20:50:08 -07:00
Bryan O'Donoghue 00fdbae1a9 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>
2016-06-06 20:50:08 -07:00
Bryan O'Donoghue 6da7c88972 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>
2016-06-06 20:50:08 -07:00
Bryan O'Donoghue 4a4484274f 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>
2016-06-06 20:50:08 -07:00
Bryan O'Donoghue 970dc85bd9 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>
2016-06-06 20:37:47 -07:00
Vaibhav Agarwal 698282f659 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>
2016-06-06 18:41:44 -07:00
Vaibhav Agarwal 02f1c12cca 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>
2016-06-06 18:41:44 -07:00
Alex Elder 0790c09a3b 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>
2016-06-03 17:03:23 -07:00
Alex Elder 495787a792 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>
2016-06-03 17:03:23 -07:00
Alex Elder 79c8c64942 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>
2016-06-03 17:03:23 -07:00
Alex Elder 4f9c5c0bbb 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>
2016-06-03 17:03:23 -07:00
Alex Elder 6879dbf15e 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>
2016-06-03 17:03:23 -07:00
Alex Elder 14a36ae704 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>
2016-06-03 17:03:23 -07:00
Alex Elder c65fdf0318 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>
2016-06-03 17:03:23 -07:00
Alex Elder 1ea3ed54dc 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>
2016-06-03 17:03:23 -07:00
Alex Elder c507397455 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>
2016-06-03 17:03:23 -07:00
Alex Elder 76639ef579 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>
2016-06-03 17:03:23 -07:00
Alex Elder e5f23c4584 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>
2016-06-03 17:03:23 -07:00
Evgeniy Borisov 17ca677018 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>
2016-06-03 08:57:48 -07:00
Evgeniy Borisov 6c5ce637db 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>
2016-06-03 08:57:48 -07:00
Evgeniy Borisov 07f91c75b4 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>
2016-06-03 08:57:48 -07:00
Viresh Kumar 68ee90c29e 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>
2016-06-02 11:16:22 -07:00
Viresh Kumar 7dea1d5f8a 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>
2016-06-02 11:15:49 -07:00
Viresh Kumar 7ff6e0128a 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>
2016-06-02 11:15:49 -07:00
Viresh Kumar c92c1d026b 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>
2016-06-02 11:15:49 -07:00
Viresh Kumar 64060fe954 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>
2016-05-31 22:02:58 -07:00
Viresh Kumar 5e569115e9 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>
2016-05-31 22:02:58 -07:00
Axel Haslam 5dad5c314b 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>
2016-05-31 17:18:18 -07:00
Axel Haslam 2b3b87f056 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>
2016-05-31 17:18:18 -07:00
Axel Haslam a8bc00fb88 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>
2016-05-31 17:18:18 -07:00
Axel Haslam 8d6fbe9bf9 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>
2016-05-31 17:18:18 -07:00
Axel Haslam 219ffcf3a5 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>
2016-05-31 17:18:18 -07:00
Axel Haslam e55c25206d 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>
2016-05-31 17:18:18 -07:00
Johan Hovold 1282317833 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>
2016-05-27 12:26:31 -07:00
Johan Hovold dacf3eb7f3 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>
2016-05-27 12:26:31 -07:00
Johan Hovold 8ccf389b19 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>
2016-05-27 12:24:17 -07:00
Johan Hovold 55742d2a07 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>
2016-05-27 12:24:17 -07:00
Johan Hovold 08f94352e8 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>
2016-05-27 12:24:17 -07:00
Johan Hovold e3fbe48432 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>
2016-05-27 12:24:17 -07:00
Johan Hovold 800d6c8f4e 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>
2016-05-27 12:24:17 -07:00
Johan Hovold 3de5acfafb 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>
2016-05-27 12:24:17 -07:00
Johan Hovold 18079ece81 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>
2016-05-27 12:21:16 -07:00
Johan Hovold 77bbbcf6d3 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>
2016-05-27 12:21:16 -07:00
Johan Hovold 8890f95710 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>
2016-05-27 12:21:16 -07:00
Johan Hovold 1430cc920a 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>
2016-05-27 12:21:16 -07:00
Johan Hovold 00ad6975e7 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>
2016-05-27 12:19:29 -07:00
Johan Hovold e2efe1bbc4 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>
2016-05-27 12:19:29 -07:00
Johan Hovold 6adcf44170 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>
2016-05-27 12:19:29 -07:00
Johan Hovold 3cbe52c2e0 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>
2016-05-27 12:19:29 -07:00
Johan Hovold 96f5ab00c2 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>
2016-05-27 12:19:29 -07:00
Johan Hovold 197616e227 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>
2016-05-27 12:19:29 -07:00
Johan Hovold aca7aab39a 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>
2016-05-27 12:19:29 -07:00
Johan Hovold d9fa3494b7 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>
2016-05-27 12:19:29 -07:00
Johan Hovold a4b08df4e0 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>
2016-05-27 12:19:29 -07:00
Johan Hovold 7aefe7918f 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>
2016-05-27 12:19:29 -07:00
Alex Elder 898d75f4aa 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>
2016-05-27 11:28:16 -07:00
Alex Elder 95073cc2e5 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>
2016-05-27 11:28:16 -07:00
Alex Elder d97fca12e9 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>
2016-05-27 11:28:16 -07:00
Alex Elder 66394300c3 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>
2016-05-27 11:28:16 -07:00
Alex Elder ebc9e3750d 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>
2016-05-27 11:28:16 -07:00
Alex Elder f9340fc7dd 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>
2016-05-27 11:28:16 -07:00
Vaibhav Agarwal 52033fdebc 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>
2016-05-27 11:27:28 -07:00
Vaibhav Agarwal 29a822bdf7 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>
2016-05-27 11:27:28 -07:00
Alex Elder cb4c8441e5 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>
2016-05-26 22:37:19 -07:00
Alex Elder 5451ea0e99 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>
2016-05-26 22:37:19 -07:00
Alex Elder 1f79046bd7 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>
2016-05-26 22:37:19 -07:00
Alex Elder df732546ce 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>
2016-05-26 22:37:19 -07:00