platform/kernel/linux-rpi.git
8 years agogreybus: timesync: Fix transitions to the INACTIVE state
Bryan O'Donoghue [Thu, 16 Jun 2016 12:42:15 +0000 (13:42 +0100)]
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>
8 years agogreybus: timesync: Do not hold mutex on cancel_delayed_work_sync
Bryan O'Donoghue [Thu, 16 Jun 2016 12:42:14 +0000 (13:42 +0100)]
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>
8 years agogreybus: firmware: Add license and copyright header to application
Viresh Kumar [Thu, 16 Jun 2016 04:33:57 +0000 (10:03 +0530)]
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>
8 years agogreybus: manifest: Disallow reuse of control cport
Viresh Kumar [Sat, 11 Jun 2016 02:31:01 +0000 (08:01 +0530)]
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>
8 years agogreybus: svc: Pass the correct pointer to input_free_device()
Vaibhav Hiremath [Wed, 15 Jun 2016 04:53:23 +0000 (10:23 +0530)]
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>
8 years agogreybus: camera: Create and destroy data connection on demand
Laurent Pinchart [Tue, 14 Jun 2016 12:59:25 +0000 (15:59 +0300)]
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>
8 years agogreybus: camera: Fix data connection setup
Laurent Pinchart [Tue, 14 Jun 2016 12:59:24 +0000 (15:59 +0300)]
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>
8 years agogreybus: camera: Clean up on stream configuration failure
Laurent Pinchart [Tue, 14 Jun 2016 12:59:23 +0000 (15:59 +0300)]
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>
8 years agogreybus: svc: disable connection after all its users are gone
Viresh Kumar [Mon, 13 Jun 2016 16:18:28 +0000 (21:48 +0530)]
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>
8 years agogreybus: camera: Initialize mutex before using it
Viresh Kumar [Mon, 13 Jun 2016 09:38:01 +0000 (15:08 +0530)]
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>
8 years agogreybus: connection: Return bool from gb_connection_intf_find()
Viresh Kumar [Fri, 10 Jun 2016 09:29:09 +0000 (14:59 +0530)]
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>
8 years agogreybus: Remove extra blank lines
Viresh Kumar [Fri, 10 Jun 2016 09:29:07 +0000 (14:59 +0530)]
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>
8 years agogreybus: firmware: Fix spelling mistake
Viresh Kumar [Fri, 10 Jun 2016 06:07:54 +0000 (11:37 +0530)]
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>
8 years agogreybus: timesync: Do 64 bit divisions in a 32 friendly way
Bryan O'Donoghue [Fri, 10 Jun 2016 15:10:12 +0000 (16:10 +0100)]
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>
8 years agogreybus: uart: Fix minor number leak
Bryan O'Donoghue [Fri, 10 Jun 2016 16:33:03 +0000 (17:33 +0100)]
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>
8 years agogreybus: audio: Ratelimit err messages in bundle, topology driver
Vaibhav Agarwal [Fri, 10 Jun 2016 07:29:11 +0000 (12:59 +0530)]
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>
8 years agogreybus: Remove apbridgea_shutdown_xx sequence if already done
Vaibhav Agarwal [Thu, 9 Jun 2016 04:00:40 +0000 (09:30 +0530)]
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>
8 years agogreybus: Use mute_stream callback to initiate GB data xfer
Vaibhav Agarwal [Thu, 9 Jun 2016 04:00:39 +0000 (09:30 +0530)]
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>
8 years agogreybus: update UniPro Set Interface Power Mode operation to match spec
Eli Sennesh [Fri, 3 Jun 2016 15:24:44 +0000 (11:24 -0400)]
greybus: update UniPro Set Interface Power Mode operation to match spec

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

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>
8 years agogreybus: connection: Avoid unnecessary line breaks
Viresh Kumar [Thu, 9 Jun 2016 11:04:42 +0000 (16:34 +0530)]
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>
8 years agogreybus: hd: Export host device tracepoint from hd.c
Viresh Kumar [Thu, 9 Jun 2016 11:04:40 +0000 (16:34 +0530)]
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>
8 years agogreybus: Remove legacy suspend/resume callbacks
Viresh Kumar [Thu, 9 Jun 2016 11:04:39 +0000 (16:34 +0530)]
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>
8 years agogreybus: Use BIT(2) for GREYBUS_ID_MATCH_CLASS
Viresh Kumar [Thu, 9 Jun 2016 11:04:38 +0000 (16:34 +0530)]
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>
8 years agogreybus: core: Make greybus_match_one_id() return bool
Viresh Kumar [Thu, 9 Jun 2016 11:04:36 +0000 (16:34 +0530)]
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>
8 years agogreybus: bootrom: Compile as a separate module
Viresh Kumar [Thu, 9 Jun 2016 11:04:35 +0000 (16:34 +0530)]
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>
8 years agogreybus: remove obsolete SVC result codes
Marti Bolivar [Thu, 9 Jun 2016 21:46:47 +0000 (17:46 -0400)]
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>
8 years agogreybus: pwm: Fix compilation with v4.3 kernel
Viresh Kumar [Thu, 9 Jun 2016 11:04:34 +0000 (16:34 +0530)]
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>
8 years agogreybus: camera: Add debug data format
Gjorgji Rosikopulos [Thu, 9 Jun 2016 08:53:15 +0000 (11:53 +0300)]
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>
8 years agogreybus: fix forced disable of offloaded connections
Johan Hovold [Thu, 9 Jun 2016 16:42:19 +0000 (18:42 +0200)]
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>
8 years agogreybus: tracing: drop "greybus" prefix
Alex Elder [Wed, 8 Jun 2016 21:54:01 +0000 (16:54 -0500)]
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>
8 years agogreybus: don't key on an enumerated constant
Alex Elder [Wed, 8 Jun 2016 19:44:22 +0000 (12:44 -0700)]
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>
8 years agogreybus: svc: pwrmon: validate svc protocol op status when getting rail names
David Lin [Wed, 8 Jun 2016 07:39:00 +0000 (09:39 +0200)]
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>
8 years agogreybus: kernel_ver.h: provide pwm_is_enabled()
Greg Kroah-Hartman [Wed, 8 Jun 2016 04:33:54 +0000 (21:33 -0700)]
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>
8 years agogreybus: audio: Ratelimit err messages
Vaibhav Agarwal [Wed, 8 Jun 2016 15:03:26 +0000 (20:33 +0530)]
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>
8 years agogreybus: svc: implement connection_quiescing call
Jeffrey Carlyle [Tue, 7 Jun 2016 15:22:22 +0000 (08:22 -0700)]
greybus: svc: implement connection_quiescing call

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Synchronization looks like this:

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

A ping can be triggered like this:

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

And that ping looks like this:

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

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

TimeSync needs to bind into Greybus in a few places.

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

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

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

This patch adds those bindings into Greybus core.

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

This patch adds the core timesync functionality.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

In explanation:

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

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

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

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

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

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

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

Add a comment to describe the purpose of the flag.

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

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

Mode-switch logs from EVT 1.5:

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

Increase the timeout to two seconds.

Tested with EVT 1.5 with gpbridge-test module.

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

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

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

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

Fix that.

Tested on EVT 1.5 with gpbridge-test module.

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

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

Tested on EVT 1.5 with gpbridge-test module.

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

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

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

Remove protocol specific handling for bridged PHY devices.

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

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

We don't use these anymore. Drop them.

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

Compile tested.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fix some whitespace issues introduced by the recent tracepoint changes.

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

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

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

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

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

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

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

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

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

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

Backport upstream reinit_completion() to pre-3.13 kernels.

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

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

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

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

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

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

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

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

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

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

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

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

Note that a new trace point is also added.

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

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

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

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

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

Remove the unused legacy INVALID connection state.

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

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

This will be used when implementing proper connection tear down.

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

Rename an error label to make it more descriptive.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>