Commit Graph

804 Commits

Author SHA1 Message Date
Alex Elder 8267616b3e greybus: bundle: check for duplicate bundle ids
Check at bundle creation time to ensure we're not creating a bundle
with an id that's the same as one that's already been created.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-10 10:38:23 -07:00
Alex Elder c27a253fc0 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>
2015-06-10 10:38:23 -07:00
Alex Elder a6b13eb648 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>
2015-06-10 10:38:23 -07:00
Alex Elder c46839d1cc 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>
2015-06-10 10:38:23 -07:00
Alex Elder d393c98f11 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>
2015-06-10 10:38:23 -07:00
Alex Elder 79dda60987 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>
2015-06-10 10:38:23 -07:00
Alex Elder f35ab903ef 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>
2015-06-10 10:38:23 -07:00
Alex Elder 47ed2c9240 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>
2015-06-10 10:38:23 -07:00
Alex Elder 190241a362 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>
2015-06-10 10:38:23 -07:00
Mark Greer 45f427a02e 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>
2015-06-10 10:35:03 -07:00
Greg Kroah-Hartman cce3103676 greybus: es?: decrease buffer size to 2k
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>
2015-06-10 10:35:03 -07:00
Phong Tran 61b65a394c greybus: uart: remove the redundant unregister chrdev
The unregister_chrdev_region() does twice here.
The chrdev region was unregistered
inside tty_unregister_driver().

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-09 13:35:47 -07:00
Phong Tran f2e2b06fef greybus: endo: move endo id map declaration to endo.h
There is a sparse warning. The endo id map is also
used in endo.c. Should define in endo.h

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-09 13:35:47 -07:00
Viresh Kumar 928f2abd5f 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.

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>
2015-06-09 13:31:23 -07:00
Alex Elder d51c0ffb5c 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>
2015-06-08 15:19:56 -07:00
Alex Elder fd1c2e541c 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>
2015-06-08 15:19:56 -07:00
Alex Elder 81c3a77207 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>
2015-06-08 15:19:56 -07:00
Alex Elder 8bd0ae6e72 greybus: connection: make gb_connection_hd_find() private
Give gb_connection_hd_find() static scope; it's never used
outside "connection.c".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-08 15:19:56 -07:00
Alex Elder 0dac67c84c greybus: svc: driver is basic to Greybus (not GP Bridge)
The SVC protocol driver should have been defined as a basic
Greybus protocol driver, not a GP Bridge protocol driver.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-08 15:19:56 -07:00
Viresh Kumar cf6b62d904 greybus: Prefix module-id with endo id
Prefix module-id with endo-id to uniquely identify it for the entire
kernel.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-08 15:18:02 -07:00
Viresh Kumar 4a04187008 greybus: Generate greybus wide unique ids for endo devices
Currently we name the endo device as "endo". And it shows up with the
same name in sysfs directory: /sys/bus/greybus/devices/.

But each device in kernel should be represented by a unique id in
kernel, and "endo" isn't unique.

Lets generate unique ids for endo devices. The ida mechanism for
allocating ids may be overkill but it works.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-08 15:18:02 -07:00
Viresh Kumar d7353ceada 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.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:15:29 +09:00
Viresh Kumar 4cfabf09db greybus: operation: Remove unused variable 'buffer'
'buffer' isn't used in this function, remove it.

Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:15:29 +09:00
Bryan O'Donoghue 62229a1bda greybus: uart: Remove magic numbers make struct gb_tty variable names consistent
Use defines for the data format command.
Tidy up naming of gb_tty variables.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:11:05 +09:00
Bryan O'Donoghue 1c087015b9 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.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:11:05 +09:00
Bryan O'Donoghue dd1c64ede9 greybus: uart: kmalloc for send_data once only
Make kmalloc for the send buffer a one time alloc based on the MTU for
a given greybus link.

The write_room for an gb_operation_sync then will be the size of the
buffer we use for a single operation.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:11:05 +09:00
Bryan O'Donoghue 563bd79b2d greybus: uart: send_data should return size or error
gb_operation_sync returns 0 on success but the calling function
expects the number of bytes written on success or a negative errno

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:08:22 +09:00
Bryan O'Donoghue f95ad78c72 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.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:08:22 +09:00
Bryan O'Donoghue f5537d46cb greybus: uart: Reduce UART count from 255 to 16
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.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:08:21 +09:00
Bryan O'Donoghue 11fca140c9 greybus: uart: Tidy naming convention to more closely match spec
Update tabs and naming of structures to match the naming used in the greybus
specification more closely.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:05:48 +09:00
Bryan O'Donoghue 4ef53485c3 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.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:05:48 +09:00
Phong Tran 55f2291142 greybus: uart: Fix the memory leak in connection init
If alloc minor is error, gb_tty should free.

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:04:18 +09:00
Viresh Kumar 3cb494cd6c greybus: endo: Add missing '\n' sprintf() for sysfs files
Because of the missing '\n', this is how the output of reading endo
sysfs files looks:

root# cat /sys/bus/greybus/devices/endo/id
0x4755root#

Fix it by including \n to the end of the printed string.

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>
2015-06-04 14:02:38 +09:00
Johan Hovold 7ba864a19f greybus: gpio: add irq-type defines
Add Greybus GPIO IRQ-type defines rather than rely on the current
Linux implementation.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-28 14:48:30 -07:00
Johan Hovold 4bf3780982 greybus: gpio: remove unused debounce define
Remove unused debounce define from protocol header.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-28 14:48:14 -07:00
Alex Elder e6cebf8770 greybus: endo: delete "0xXXXX" portion in sysfs "endo" directory
With the Endo "id" attribute in place, there's no need to encode
the ID of an Endo in its sysfs path.  So get rid of it.

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>
2015-05-28 14:45:56 -07:00
Alex Elder 312bb84942 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

All other Endo sysfs files are updated similarly.

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>
2015-05-28 14:45:56 -07:00
Alex Elder 28e3cedcce 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.

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>
2015-05-28 14:45:56 -07:00
Alex Elder b4dbf1e132 greybus: add documentation for Endo sysfs files
Update the files documenting Greybus-related sysfs files under
Documentation/ to reflect the addition of the two recently-added
Endo attributes.

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>
2015-05-28 14:45:20 -07:00
Phong Tran df76422113 greybus: audio: Remove the MODULE_LICENSE()
This is not a kernel module. It should not use
the module license macro.

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-28 14:38:38 -07:00
Phong Tran bcd8215b49 greybus: audio: Fix typo for macro I2S data version minor
This macro should be DATA not MGMT.

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-28 14:38:38 -07:00
Alex Elder 012d7d4fbe greybus: greybus_protocols: fix guard tag
I neglected to update the "#ifndef/#define" when I renamed
"greybus_protocols.h".  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>
2015-05-28 14:04:08 -07:00
Johan Hovold 47bf0b4427 greybus: gpio: update operation types
Update the remaining operation types now that the ack operation is gone
to avoid leaving a hole in the type definitions.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-28 14:02:13 -07:00
Greg Kroah-Hartman 23bd25a798 greybus: Merge branch 'master' of github.com:gregkh/greybus 2015-05-28 14:02:02 -07:00
Phong Tran b61fa7bce4 greybus: svc: use macro for init and exit protocol
Change to gb_gpbridge_protocol_driver for
making the consitent with other drivers.

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-28 13:58:29 -07:00
Phong Tran ea15a40b32 greybus: svc: Fix endian of hotplug request data
data of hotplug request should exchange to native
CPU format before assignment.

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-28 13:58:29 -07:00
Johan Hovold 1409c4d6a8 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>
2015-05-26 15:27:39 -07:00
Johan Hovold 25f11ed965 greybus: gpio: fix atomic sleep when using interrupts
The irq-chip callbacks are made in atomic context where we must not do
any synchronous greybus operations.

Fix the current gpio-interrupt implementation by using the bus-lock
functionality provided by the irq subsystem.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-26 15:26:08 -07:00
Johan Hovold 0cb918d72d greybus: gpio: rename irq mask and unmask callbacks
Rename irq mask and unmask functions to match the callback names.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-26 15:26:08 -07:00
Johan Hovold ec762115a5 greybus: gpio: use irq-domain lookups
Use irq_find_mapping directly rather than go through the legacy gpio
interface.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-26 15:25:17 -07:00