Alex Elder [Tue, 9 Jun 2015 22:42:58 +0000 (17:42 -0500)]
greybus: connection: check for duplicate cport ids
Check at connection creation time for an attempt to create a
connection with an interface CPort ID that's the same as one that's
already been created.
Define a new helper function to look for such a duplicate. The
check for a duplicate is only performed at initialization time,
and CPorts are initialized serially for each bundle, so there's
no need to acquire the list lock for this search.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Tue, 9 Jun 2015 22:42:56 +0000 (17:42 -0500)]
greybus: manifest: rework bundle parsing
Rework the the code that parses the manifest for bundles so it only
touches each manifest descriptor once. (Previously the list was
scanned from the beginning repeatedly until all bundles were found.)
Shorten the name of the descriptor variable, to avoid line wrap.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Tue, 9 Jun 2015 22:42:55 +0000 (17:42 -0500)]
greybus: manifest: rework cport parsing
Rework the the code that parses the manifest for CPorts associated
with a bundle so it only touches each manifest descriptor once.
(Previously the list was scanned from the beginning repeatedly
until all bundle CPorts were found.) Shorten the name of the
descriptor variable, to avoid line wrap.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Tue, 9 Jun 2015 22:42:54 +0000 (17:42 -0500)]
greybus: manifest: use bundle's embedded interface pointer
An initialized bundle structure contains a pointer to its
interface. Because of this there's no need to provide
the interface pointer to gb_manifest_parse_cports(). This
also precludes the possibility of passing a bad interface
pointer.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Tue, 9 Jun 2015 22:42:53 +0000 (17:42 -0500)]
greybus: manifest: really minor cleanups
This patch incorporates some very small cleanups to "manifest.c":
- Rearrange code a bit in gb_manifest_parse() that ensures a
manifest is big enough to hold a header. If the manifest is
exactly the size of a header, the error reported will now be
"...must have 1 interface..." rather than "short manifest".
- Fix the function comment for gb_manifest_parse_cports().
- Use "an interface," not "a interface," and don't capitalize.
- Delete some braces when getting interface product string.
- A few other minor changes to comments and white space.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Tue, 9 Jun 2015 22:42:52 +0000 (17:42 -0500)]
greybus: endo: clean up id assignment code
Recently code was added (back) to assign a unique id to each
endo, so satisfy uniqueness requirements of the Linux device
subsystem. An ID allocator is used to manage the space of IDs.
Now that we have gb_endo_init(), we can initialize the map there,
and fully hide the ID map within "endo.c".
The original functions gb_endo_id_alloc() and gb_endo_id_free()
provided a nice abstract interface, but the direct ID allocation
calls are quite simple, so just call them directly.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Tue, 9 Jun 2015 22:42:51 +0000 (17:42 -0500)]
greybus: endo: define endo_init() and endo_exit()
Define init and exit functions to do one-time setup and teardown
of endo-related functionality. Currently they're place holders;
the next patch will populate them.
Note that we now call gb_operation_exit() from gb_init(), so
we can no longer mark that function with __exit.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Tue, 9 Jun 2015 22:42:50 +0000 (17:42 -0500)]
greybus: tag core init and exit functions
The top-level functions gb_init() and gb_exit() are tagged with
__init and __exit, respectively. These functions call a few
other functions that are similarly used only at initialization
and termination time. So mark those functions accordingly.
Note that, because gb_ap_exit() and gb_debugfs_cleanup()
are called by gb_init() in error paths, these functions
cannot be declared with the __exit attribute.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Tue, 9 Jun 2015 22:42:49 +0000 (17:42 -0500)]
greybus: drop some unnecessary headers
There's no need to include anything other than "greybus.h" in
"connection.c". Same thing in "core.c" and "manifest.c" and
"svc.c". Some files need headers included, but most come along
with "greybus.h".
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark Greer [Tue, 9 Jun 2015 22:29:35 +0000 (15:29 -0700)]
greybus: gb-audio: Reset sample count when CPort deactivated
The sample count placed in Greybus I2S audio messages should be
reset every time a new audio stream is set up. However, the
current code does not do the reset so make it so it does.
Signed-off-by: Mark Greer <mgreer@animalcreek.com> Acked-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The firmware is having a hard time with 4k buffers and memory
allocation, so decrease the size on the host side to 2k. Also move away
from using PAGE_SIZE to denote 4k as that's not the case on all
architectures, and someone, someday, might get a rude surprise.
Reviewed-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Viresh Kumar [Thu, 4 Jun 2015 12:46:45 +0000 (18:16 +0530)]
greybus: Tear down devices in the reverse order
Normally, its a good practice to free resources in the reverse order in
which they are allocated, so that all the dependencies can be sorted out
properly.
This is true while creating/destroying devices as well. For example
consider this scenario (I faced a crash with control protocol due to
this). For a new module, we will first create a bundle+connection for
the control cport and then create other bundles/connections after
parsing manifest.
And while destroying interface on module hot unplug, we are removing the
devices in the order they are added. And so the bundle/connection for
the control cport are destroyed first. But, control cport was still
required while destroying other bundles/connections.
To solve this problem, lets destroy the resources in the reverse order
in which they are added.
Alex Elder [Mon, 8 Jun 2015 17:05:14 +0000 (12:05 -0500)]
greybus: manifest: clean up a few pr_err() calls
Provide a little more information in two pr_err() calls.
Also enclose a reported condition in parentheses, to match
the style used everywhere else in the file.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Mon, 8 Jun 2015 17:05:13 +0000 (12:05 -0500)]
greybus: core: rename greybus_deregister()
Rename greybus_deregister() to be greybus_deregister_driver(), so
its name mirrors the greybus_register_driver() function it matches.
Define greybus_deregister() to be a trivial macro.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Mon, 8 Jun 2015 17:05:12 +0000 (12:05 -0500)]
greybus: uart: properly interpret receive data size
In gb_uart_request_recv(), the receive data size is in little-endian
format. Do the proper byte swapping of that value before using it.
Found by "make check".
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Viresh Kumar [Thu, 4 Jun 2015 04:48:01 +0000 (10:18 +0530)]
greybus: s/bundle_cport_id/intf_cport_id
This isn't unique just for the bundle but the complete interface. Its
wrong to call it bundle_cport_id. Lets name it intf_cport_id to make
things clear.
greybus: uart: Add gb_uart_request_recv for receiving async UART data
gb_uart_request_recv job in life is to process unsolicited greybus
mesages from the UART.
Hook the incoming UART data and pass to the TTY layer.
Line-state changes still TBD.
greybus: uart: Update uart.c to register tty ports
For each new UART connection we need to do a tty_port_init else
we'll crash when trying to access the tty mutex later on.
Base the TTY major/minor numbers on non-zero values.
Supply an empty operations structure for the newly regitered port.
Arbitrary number 255 is both not aligned and probably too big.
Move the UART count down to 16 which is still large but, more realistic.
8 may be too few for future testing setups, 16 should accomodate any.
greybus: uart: Move UART protocol structs/defines to greybus_protocols.h
gbsim depends on the structures and defines in greybus_protocols.h
generally in order to simulate firmware. Move UART defines into this
header to facilitate.
Alex Elder [Wed, 27 May 2015 16:17:52 +0000 (11:17 -0500)]
greybus: endo: drop redundant prefixes from sysfs basenames
This commit: 7e761e2 endo: rework some attributes
added a new "endo_id" attribute, located under a new "Endo"
directory in sysfs. The resulting path looks like:
Documentation/sysfs/endo-TYPE/Endo/endo_id
There's no need to have a separate "Endo" subdirectory to contain
Endo-specific attributes.
That commit also added "svc_" to some other paths related to the
SVC, like:
Documentation/sysfs/endo-TYPE/SVC/svc_version
The additional "svc_" is redundant.
This patch retouches those paths a bit, mainly to remove some
redundancy. It also makes the pathname components all lower case.
As a result, the above two paths now look like:
Documentation/sysfs/endo-TYPE/id
Documentation/sysfs/endo-TYPE/svc/version
Alex Elder [Wed, 27 May 2015 16:17:51 +0000 (11:17 -0500)]
greybus: update sysfs documentation files
Impose a few editorial conventions on the Greybus-related sysfs
files under "Documentation".
- Capitalize "Endo" (except in path names)
- Capitalize "ID" (except in path names)
- Use "..." to indicate unspecified path components (because
".." means something else).
- Add the "0x" prior to the "XXXX" representing the Endo ID.
Johan Hovold [Tue, 26 May 2015 13:29:25 +0000 (15:29 +0200)]
greybus: gpio: fix interrupt protocol
The current interrupt implementation uses the simple irq-flow handler,
which means that the interrupt subsystem makes no irq-chip callbacks
when handling an interrupt. Specifically, no end-of-interrupt message is
sent when the threaded handler has run. This means that we may currently
re-enable an interrupt before it has been serviced (i.e. the irq-event
operation may complete before the threaded handler has run).
The simple flow handler also silently drops a second interrupt arriving
while a handler is running. This means that we may lose a second edge
interrupt with the current firmware.
Switch to a new one-shot interrupt protocol, where the primary handler
(firmware) always masks and acks an interrupt before sending an event to
the AP. The AP is responsible for unmasking the interrupt when it has
been handled. By having the firmware ack an edge interrupt before
sending the event, a second edge interrupt will no longer get lost.
This one-shot protocol can be implemented in the kernel by using the
level irq-flow handler, one-shot interrupts with threaded handlers and
bus-lock synchronisation for slow buses. Note that the same flow handler
is used for both edge and level interrupts.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Fri, 22 May 2015 18:02:08 +0000 (13:02 -0500)]
greybus: introduce SVC protocol
This patch adds support for the Greybus SVC protocol. We may want
to rearrange protocol numbers at some point, since this is a pretty
fundamental protocol.
Note: It has only been compile tested; no SVC CPorts have yet been
defined, so this code is not yet exercised.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Fri, 22 May 2015 17:56:49 +0000 (12:56 -0500)]
greybus: core: don't set up endo until host device is initialized
Currently, the data structure representing an Endo is set up at the
time a host device gets created. This is too early.
Once the control infrastructure is in place, there's no sense in
setting up the Endo utnil after we have heard from the SVC via a
probe operation on our control CPort. And even then, there's
no real point until we've successfully authenticated with the SVC,
which will be indicated by the arrival of the Control protocol
"connected" operation request notifying us that our SVC CPort
is operational.
In addition to this logical argument, we also can't actually
receive any messages on the Control CPort until the host device
is set up and ready to receive messages. At the point we're
currently setting up the Endo data structure, that has not yet
been done.
Define a new exported function greybus_endo_setup(), which will
be used (for now) as the entry point for setting up the Endo
data structure. Arrange to call it in the host USB driver
probe method, *after* we are set up for handling messages.
Note: Once the control protocol has been implemented, this function
may no longer need to be exported.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Fri, 22 May 2015 17:56:48 +0000 (12:56 -0500)]
greybus: endo: record AP interface id
The AP resides in a particular position on an Endo, which is
identified by an interface ID. (For now we'll assume the AP uses
just one interface.) Record the this AP interface ID when creating
an Endo. Add a sysfs attribute to display it as well.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Fri, 22 May 2015 17:56:46 +0000 (12:56 -0500)]
greybus: endo: encapsulate computing the max interface id
The maximum interface id on an Endo is the result of a non-trivial
calculation. It'll be needed for an upcoming patch, so create a
macro to compute it.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Fri, 22 May 2015 17:35:32 +0000 (12:35 -0500)]
greybus: rename "gpbridge.h"
The file "gpbridge.h" is now used as a single place to define
all protocol message structures. These protocols are not
necessarily related to the GP bridge, so the name of the
file is misleading.
Rename it "greybus_protocols.h".
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Fri, 22 May 2015 14:52:43 +0000 (09:52 -0500)]
greybus: endo: pass endo_id to gb_endo_create()
We are going to want to defer creating the endo until we receive a
probe operation from the SVC, which will supply the endo id. Change
gb_endo_create() so it passes the endo_id value as an argument.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex Elder [Fri, 22 May 2015 14:52:42 +0000 (09:52 -0500)]
greybus: endo: rename gb_svc
Change the name of "struct gb_svc" to be "struct svc_info". The
structure now contains only the SVC's serial number and version (and
are place holders anyway). We will be defining a structure that
represents the SVC for the SVC protocol connection, and I want to
take back that name.
Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark A. Greer [Thu, 21 May 2015 22:57:04 +0000 (15:57 -0700)]
greybus: gb-audio: Set samples per message during init
A recent commit moved the I2S samples per message operation
to the PCM's 'hw_params' callback. However, the 'hw_params'
callback is called numerous times while the samples per
message need only be done once (or seldom). Eliminate the
unnecessary samples per message operations by doing it only
once at Greybus protocol init time.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Acked-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark A. Greer [Thu, 21 May 2015 22:57:03 +0000 (15:57 -0700)]
greybus: gb-audio: Set I2S Configuration according to ASOC requests
Currently, the audio driver unconditionally sets the I2S
configuration to have a sample rate of 48KHz, two channels,
16 bits per channel, in little endian order. Make this
more flexible by setting the I2S configuration according to
the arguments passed to the PCM 'hw_params' callback.
To accomplish this, query for the supported I2S configurations
at Greybus protocol init time and save them in the 'snd_dev'
structure. When the 'hw_params' callback is called, compare its
arguments to the table of supported configurations. If there is
a match, set the I2S connection accordingly.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Acked-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark A. Greer [Thu, 21 May 2015 22:57:02 +0000 (15:57 -0700)]
greybus: gb-audio: Activate TX connection Bundle CPort ID
Currently, the audio driver activates & deactivates a predefined
CPort ID but that can vary depending on the manifest data of the
module. Instead, use the TX connection's Bundle CPort ID which
contains the correct CPort ID.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Acked-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark A. Greer [Thu, 21 May 2015 22:57:01 +0000 (15:57 -0700)]
greybus: gb-audio: Activate TX CPort in PCM workqueue
Currently, the I2S TX CPort is configured and activated during
the Greybus audio initialization. Unfortunately, this prevents
the audio driver from ever changing the I2S configuration.
To allow the I2S configuration to change according to ASOC requests,
move the CPort activation & deactivation to the audio-pcm workqueue.
Now, when audio is running but the CPort is not active, it will be
activated. When audio is not running and the CPort is active, it
will be deactivated.
This has the side-effect of sending the first piece of audio data
immediately after activating the CPort which is really how it should
work anyway.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Acked-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark A. Greer [Thu, 21 May 2015 22:57:00 +0000 (15:57 -0700)]
greybus: gb-audio: Remove useless comment
Remove comment about adding start delay since it will
be done when support for A/V synchronization is added.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Acked-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark A. Greer [Thu, 21 May 2015 22:56:59 +0000 (15:56 -0700)]
greybus: gb-audio: Add I2C device for rt5647 codec
Add the I2C device node for the rt5647 codec.
Eventually, this will be done automatically somewhere
else but for now its done in the audio driver.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Acked-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark A. Greer [Thu, 21 May 2015 22:56:58 +0000 (15:56 -0700)]
greybus: gb-audio: cpu_dai.fmt does not exist in v4.1
The asoc_simple_dai structure does not contain the 'fmt'
member in Linux kernel version v4.1 and later so only
build code that uses it when the kernel version is earlier
than v4.1.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Acked-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark A. Greer [Thu, 21 May 2015 22:56:57 +0000 (15:56 -0700)]
greybus: gb-audio: Fix DAI formats and master/slave settings
Set the various DAI formats so the bridge on the module
is the master of all clocks and the codec is the slave.
The only DAI protocol currently supported is I2S.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Acked-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark A. Greer [Thu, 21 May 2015 22:56:56 +0000 (15:56 -0700)]
greybus: gb-audio: Clean up codec name generation
Instead of using the fixed suffix, '6-001b', in the
codec name, generate it from the I2S adapter number
and I2C address of the codec.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Acked-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Mark A. Greer [Thu, 21 May 2015 22:54:48 +0000 (15:54 -0700)]
greybus: gb-audio: Allocate space for 20 configurations
The greybus code requires that an operation's response buffer be
the exact size of the response; however, the size of the response to
the GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS operation is unknown.
To fix this, an extension to the I2S specification is required.
In the meantime, set the number of configurations returned to 20
because that is how many configurations will be returned (using
"insider knowledge" of the firmware).
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Tested-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
(Those are the setting that work, at least). So make the Greybus
audio driver configure the GPBridge with those settings.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Tested-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Johan Hovold [Thu, 21 May 2015 09:47:24 +0000 (11:47 +0200)]
greybus: gpbridge: fix section mismatches
Fix section mismatches introduced by b27227ce93c0 ("greybus: Use
gb_gpbridge_protocol_init()"), which added __exit annotation to
gpbridge-protocol exit functions that are called in the error path of
gpbridge_init, which lives in the init section.
This triggered the following modpost warning:
WARNING: modpost: Found 8 section mismatch(es).
Fixes: 16b33d100bff ("protocol: Add gb_gpbridge_protocol_driver()") Fixes: b27227ce93c0 ("greybus: Use gb_gpbridge_protocol_init()") Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Johan Hovold [Tue, 19 May 2015 09:22:46 +0000 (11:22 +0200)]
greybus: operation: add helper to retrieve max payload size
Add helper to retrieve the maximum payload size for operations on a
specific connection.
Note that the helper is not inlined due to how the header files are
currently organised, but it is not expected to be called after a
connection has been initialised either.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Viresh Kumar [Wed, 20 May 2015 11:01:19 +0000 (16:31 +0530)]
greybus: raw: include uaccess.h to fix warning
This is what I get over mainline:
greybus/raw.c: In function 'gb_raw_send':
greybus/raw.c:153:2: error: implicit declaration of function 'copy_from_user' [-Werror=implicit-function-declaration]
if (copy_from_user(&request->data[0], data, len)) {
^
greybus/raw.c: In function 'raw_read':
greybus/raw.c:305:2: error: implicit declaration of function 'copy_to_user' [-Werror=implicit-function-declaration]
if (copy_to_user(buf, &raw_data->data[0], raw_data->len)) {
^
This adds a driver that implements the greybus Raw protocol as
specified.
It preserves the message boundries by only allowing a read to receive
a "full" message, and any write() call also is passed in a single
greybus request.
Totally untested, given that we have no raw firmware or gbsim code yet.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>