platform/kernel/linux-rpi.git
8 years agogreybus: arche-apb-ctrl: Do not coldboot APBs in probe
Vaibhav Hiremath [Tue, 16 Feb 2016 19:57:52 +0000 (01:27 +0530)]
greybus: arche-apb-ctrl: Do not coldboot APBs in probe

Since parent driver (SVC) is controlling APBs directly, we do not
need to bringup APBs in its own probe.

Testing Done: Tested on EVT1.2.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: manifest: Parse cports (within a bundle) in the order from manifest blob
Viresh Kumar [Fri, 12 Feb 2016 16:18:03 +0000 (21:48 +0530)]
greybus: manifest: Parse cports (within a bundle) in the order from manifest blob

The order in which cports (of a bundle) are present in the manifest blob
is important for gbsim, as it allocates hd_cport_id's for them
sequentially.

For example, if there are two cports (1 and 2, in order 1->2) present in
a bundle in the manifest blob, then gbsim allocates hd_cport_id X and
X+1 for them. This is done on the assumption that kernel will do the
same. Though it shouldn't have had any such assumptions since the
beginning.

But with a recent patch that sequence is changed, and it broke the
assumption gbsim had.

While parsing the manifest blob, the cports within a bundle are now
moved to another list using list_move() and then they are picked one by
one from the HEAD of the list.

list_move() first deletes the node and then adds it to HEAD as it uses
list_add() and not list_add_tail(). And that reverses the order in which
the cports were present in the original list.

And because of this, the messages destined for cport 1 are delivered to
cport 2 and the ones for cport 2 are delivered to cport 1.

In order to get gbsim working with greybus, keep the cport list in the
order in which they were present in manifest, by replacing list_move()
with list_move_tail().

Its a trivial patch and shouldn't have any side effects on the working
of greybus with nuttx.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: Don't configure CSI TX in test only mode
Laurent Pinchart [Sun, 14 Feb 2016 00:33:07 +0000 (02:33 +0200)]
greybus: camera: Don't configure CSI TX in test only mode

When the GB_CAMERA_CONFIGURE_STREAMS_TEST_ONLY flag is set by the caller
the configure streams operation should only test the requested settings
without modifying the hardware state. This applies for both the module,
the UniPro links power modes and the AP bridge settings. Return early
when the flag is set to avoid modifying the AP bridge CSI TX settings.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Tested-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: Set power mode after configuring streams
Laurent Pinchart [Sun, 14 Feb 2016 00:33:06 +0000 (02:33 +0200)]
greybus: camera: Set power mode after configuring streams

There's no need to set the power mode before configuring streams, doing
it after simplifies code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Tested-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: Clean up when AP link power mode configuration failed
Laurent Pinchart [Sun, 14 Feb 2016 00:33:05 +0000 (02:33 +0200)]
greybus: camera: Clean up when AP link power mode configuration failed

Restore the module link power mode to the previous state in that case.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Tested-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: Factorize link power mode configuration code into a function
Laurent Pinchart [Sun, 14 Feb 2016 00:33:04 +0000 (02:33 +0200)]
greybus: camera: Factorize link power mode configuration code into a function

Avoid duplicating the same code block multiple times.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: power_supply: convert to bundle driver
Viresh Kumar [Fri, 12 Feb 2016 10:38:33 +0000 (16:08 +0530)]
greybus: power_supply: convert to bundle driver

Convert the legacy power_supply protocol driver to a bundle driver.

This also fixes a potential crash should a (malicious) module have sent
an early request before the private data had been initialised.

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: power_supply: Break supply setup into two parts
Viresh Kumar [Fri, 12 Feb 2016 10:38:32 +0000 (16:08 +0530)]
greybus: power_supply: Break supply setup into two parts

This breaks the power supply setup routine into two parts, the first one
allocates all the necessary resources and the second on registers
supplies to the required frameworks.

This is required to enable only TX on the connection, until we have
allocated all the resources, otherwise the request handler might get
called for partially initialized structures.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: lights: convert to bundle driver
Viresh Kumar [Fri, 12 Feb 2016 10:38:31 +0000 (16:08 +0530)]
greybus: lights: convert to bundle driver

Convert the legacy lights protocol driver to a bundle driver.

This also fixes a potential crash should a (malicious) module have sent
an early request before the private data had been initialised.

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: lights: Break light setup into two parts
Viresh Kumar [Fri, 12 Feb 2016 10:38:30 +0000 (16:08 +0530)]
greybus: lights: Break light setup into two parts

This breaks the light setup routine into two parts, the first one
allocates all the necessary resources and the second on registers lights
to the required frameworks.

This is required to enable only TX on the connection, until we have
allocated all the resources, otherwise the request handler might get
called for partially initialized structures.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: loopback: convert to bundle driver
Viresh Kumar [Fri, 12 Feb 2016 10:38:29 +0000 (16:08 +0530)]
greybus: loopback: convert to bundle driver

Convert the legacy loopback protocol driver to a bundle driver.

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: raw: convert to bundle driver
Viresh Kumar [Mon, 15 Feb 2016 05:17:27 +0000 (10:47 +0530)]
greybus: raw: convert to bundle driver

Convert the legacy raw protocol driver to a bundle driver.

This also fixes a potential crash should a (malicious) module have sent
an early request before the private data had been initialised.

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: raw: Don't use (possibly) uninitialized raw->device in gb_raw_receive()
Viresh Kumar [Fri, 12 Feb 2016 10:38:27 +0000 (16:08 +0530)]
greybus: raw: Don't use (possibly) uninitialized raw->device in gb_raw_receive()

If an incoming request comes on the connection, before the driver has
allocated its raw->device in gb_raw_connection_init(), then it might
result in a crash while printing error messages.

Fix that by using bundle->dev for printing error messages.

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: raw: Use consistent label names in connection_init()
Viresh Kumar [Fri, 12 Feb 2016 10:38:26 +0000 (16:08 +0530)]
greybus: raw: Use consistent label names in connection_init()

Some of the labels are named based on what they are going to undo, while
others are based on where we failed in connection_init().

Follow only the first type of naming.

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: only build arche platform driver if usb3613 is enabled
Greg Kroah-Hartman [Mon, 15 Feb 2016 21:58:21 +0000 (13:58 -0800)]
greybus: only build arche platform driver if usb3613 is enabled

The build is broken if you try to build the arche platform driver
without the usb3163 driver enabled at the same time, so specify that
dependency in the greybus Makefile.

Testing done:  built inside and outside of the build system against
many different kernel versions.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Control usb3613 from arche-platform
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:20 +0000 (02:04 +0530)]
greybus: arche-platform: Control usb3613 from arche-platform

USB3613 hub driver exports control function, which allows caller
to switch the mode of operation of hub device.
As we know that, we have dependency between HUB3613 and APB's where,
HUB supposed to enter into HUB only after APB's brought out of reset.

Until now, we had all userspace driver sequences to control this,
but now since we are moving all resource management strictly to the
driver, it makes sense (even though it looks hacky) to enable control
of hub3613 from arche-platform driver.

Note that, there is another discussion where, the hub.connect IO pin may
get interfaced with MSM gpio, at that time, we can get rid of this hack
and replace it with gpio control.

Testing Done: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-apb-ctrl: Do not export any gpios
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:19 +0000 (02:04 +0530)]
greybus: arche-apb-ctrl: Do not export any gpios

With addition of operational state in driver, user/developer
can switch to FW flashing state through sysfs. So no need to
export any gpios to userspace now.

Testing Done: Tested on EVT1.2 and DB3.5 platform

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Do not export any gpios
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:18 +0000 (02:04 +0530)]
greybus: arche-platform: Do not export any gpios

With addition of operational state in driver, user/developer
can switch to FW flashing state through sysfs. So no need to
export any gpios to userspace now.

Testing Done: Tested on EVT1.2 and DB3.5 platform

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Fix boot, poweroff and fw_flashing seq with APBs
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:17 +0000 (02:04 +0530)]
greybus: arche-platform: Fix boot, poweroff and fw_flashing seq with APBs

Now SVC driver has an access to APBs operational functions
(coldboot, standby_boot, fw_flashing and poweroff), SVC driver
can control APB's as per below rules,

 - If SVC goes down (poweroff state), it will also power off APBs
   and vice a versa for all operational states.
 - On boot, SVC will probe/populate APB device, but will not coldboot
   it. APBs will coldboot only after handshaking with SVC over
   wake/detect line.
   Note that, both APBs share same wake/detect line.

So from user/developer perspective, it is highly recommended that
they should use arche-platform interfaces, instead of individual
apb interface,

 # echo [off/active/standby/fw_flashing] > /sys/devices/arche_platform.*/state

Note: 'standby' mode is not supported as of now.

Testing Done: Testd on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-apb-ctrl: Export operational fns from driver
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:16 +0000 (02:04 +0530)]
greybus: arche-apb-ctrl: Export operational fns from driver

In order to use single wake/detect line for both APB's we need to have
access to APB operational functions to parent/SVC driver.
So export coldboot, standby_boot, fw_flashing and poweroff operation
functions from the driver.

Testing Done: Tested on EVT1.2 and DB3.5 platform

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-apb-ctrl: Rename internal operational state fns
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:15 +0000 (02:04 +0530)]
greybus: arche-apb-ctrl: Rename internal operational state fns

This is preparation for enabling export set of operational fns
to parent driver.
So it is important to differentiate internal ops function against
externally accessed (from parent).

Testing Done: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-apb-ctrl: Introduce ara,init-disable property for APB
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:14 +0000 (02:04 +0530)]
greybus: arche-apb-ctrl: Introduce ara,init-disable property for APB

New DT property "ara,init-disable" will allow user to disable
APB1 or APB2 during boot and enable it only when needed through
command prompt via sysfs interface.

 - To disable APB2 during boot, specify "ara,init-disable" property in
   respective APB node.

 - How to check the state
   # cat /sys/devices/arche_platform.*/apb*/state

   It should be 'off', if 'ara,init-disable' enabled in DT.

 - During runtime if user/developer desired to enable APB2 (strictly and
   only for development purpose) then respective APB can be enabled
   through,

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

Note:
  - If APB device is in 'off,disabled' state, then no state transitions
    are permitted.
  - User/developer must first activate APB device

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

    This will clear the 'init-disable' flag and allow state transition
    from here onwards.
    Note that, 'off,disabled' is only indicative state and is only
    applicable during init/boot.

Testing Done: Tested on EVT1.2 and DB3.5 platform

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-apb-ctrl: Add sysfs to allow user to change state
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:13 +0000 (02:04 +0530)]
greybus: arche-apb-ctrl: Add sysfs to allow user to change state

This patch introduces sysfs interface for the user space to enable
state change of the driver. Driver supports below operational
states,

 - off
 - active
 - standby
 - fw_flashing

To see the current state

i # cat /sys/devices/arche_platform.*/apb*/state

And to change the state
 # echo [off/active/standby/fw_flashing] > /sys/devices/arche_platform.*/apb*/state

Testing Done: Tested on EVT1.2 and DB3.5 platform

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-apb-ctrl: Pass only platform_device to _seq fns
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:12 +0000 (02:04 +0530)]
greybus: arche-apb-ctrl: Pass only platform_device to _seq fns

Pass only pointer to platform_device to _seq fns and fetch handle to
arche_apb_ctrl_drvdata from platform_device.

This is preparation for support for dynamic switching between operational
states for the device, where these functions will be called from parent
driver.

Testing Done: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-apb-ctrl: Set default state value to OFF
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:11 +0000 (02:04 +0530)]
greybus: arche-apb-ctrl: Set default state value to OFF

Explicitly set default apb->state value to ARCHE_PLATFORM_STATE_OFF
in probe() fn.

Testing Done: Tested on EVT1.2 and DB3.5 platform

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-apb-ctrl: Rename init_seq and cleanup fn
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:10 +0000 (02:04 +0530)]
greybus: arche-apb-ctrl: Rename init_seq and cleanup fn

apb_ctrl_coldboot_seq() and apb_ctrl_poweroff_seq()
is appropriate name as per spec and implementation, so rename it.
Also move apb_ctrl_poweroff_seq() fn above, to group it with
other _seq functions.

Testing Done: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-apb-ctrl: Re-arrange init sequence
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:09 +0000 (02:04 +0530)]
greybus: arche-apb-ctrl: Re-arrange init sequence

In order to allow APB2 disable by default on boot/init, and also
provide interface to user to enable it later on, re-arrange the init_seq
fn.
The idea here is, the apb_ctrl_init_seq() fn will be renamed to
apb_ctrl_coldboot_seq(), and should not try to claim any resources.
All the resource claim should happen in apb_ctrl_get_devtree_data() fn.

And also uses devm_gpio_request_one() fn wherever possible.

Testing Done: Tested on EVT1.2 and DB3.5  platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Introduce FW_FLASHING state
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:08 +0000 (02:04 +0530)]
greybus: arche-platform: Introduce FW_FLASHING state

Introduce FW_FLASHING state to arche-platform driver, to enable
user space to flash/upgrade SVC firmware.

Command to enter into flashing state:

  # echo fw_flashing > /sys/devices/arche_platform.*/state

Testing Done: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche_platform: Add sysfs to allow user to change state
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:07 +0000 (02:04 +0530)]
greybus: arche_platform: Add sysfs to allow user to change state

This patch introduces sysfs interface for the user space to enable
operational state change of the driver.
Currently, driver supports, 'off', 'active' and 'standby'

Note that, driver doesn't do anything for standby state as of today.

To see the current state

      # cat /sys/devices/arche_platform.*/state

And to change the state
      # echo [off/active/standby] > /sys/devices/arche_platform.*/state

Testing Done: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Pull wake/detect low in poweroff
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:06 +0000 (02:04 +0530)]
greybus: arche-platform: Pull wake/detect low in poweroff

When SVC goes down, make sure that wake/detect is also pulled low.
Note that this is not the criteria for SVC poweroff, but it is required
to have right state on wake/detect line before powering off.
And on next boot, the boot-sequence code would take care of
handshaking with SVC.

Tested-on: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Add state variable to driver data
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:05 +0000 (02:04 +0530)]
greybus: arche-platform: Add state variable to driver data

This is preparation for operational state support.
So in order to provide operational state transitions, driver needs to
maintain state. So add 'enum arche_platform_state' variable to
'struct arche_platform_drvdata'

Testing Done: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Rename cleanup fn to poweroff_seq
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:04 +0000 (02:04 +0530)]
greybus: arche-platform: Rename cleanup fn to poweroff_seq

In sync with operational states, rename arche_platform_cleanup() fn
to arche_platform_poweroff_seq() fn.

Testing Done: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Cancel delayed_work in driver remove fn
Vaibhav Hiremath [Fri, 12 Feb 2016 19:45:11 +0000 (01:15 +0530)]
greybus: arche-platform: Cancel delayed_work in driver remove fn

This is a bug fix, where as part of cleanup, delayed work was not
canceled in driver remove function. So fix it.

Testing Done: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Introduce coldboot_seq fn
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:03 +0000 (02:04 +0530)]
greybus: arche-platform: Introduce coldboot_seq fn

This is preparation for support for different operational states
(defined by arche_platform_state) in the driver, to enable
user/developer to dynamically configure the state.

arche_platform_coldboot_seq() fn will be responsible for
rebooting SVC device.

Testing Done: Tested on EVT1.2 and DB3.5 platform

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: make apb_state common to both platform drivers
Vaibhav Hiremath [Fri, 12 Feb 2016 20:34:02 +0000 (02:04 +0530)]
greybus: arche-platform: make apb_state common to both platform drivers

Make 'enum apb_state' common to both platform drivers, so that
both drivers can make use of same state and user will have
unified control configuration across devices (SVC, APB1 and APB2)

Testing Done: Tested on EVT1.2 and DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: raw: fix memory leak on disconnect
Johan Hovold [Wed, 10 Feb 2016 10:08:29 +0000 (11:08 +0100)]
greybus: raw: fix memory leak on disconnect

Make sure the class device is freed as well as deregistered on
disconnect.

Also deregister the class device before character device as the former
depends on the latter.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: bundle: remove private data field
Johan Hovold [Wed, 10 Feb 2016 11:31:03 +0000 (12:31 +0100)]
greybus: bundle: remove private data field

Remove the private data field from the bundle structure as it is no
longer needed. Bundle drivers can use the driver data field in the
bundle device.

Update the only current user to use the connection private data until it
has been converted to a bundle driver.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: spi: add bundle-device prefix to error messages
Johan Hovold [Thu, 11 Feb 2016 12:52:50 +0000 (13:52 +0100)]
greybus: spi: add bundle-device prefix to error messages

Replace all pr_err with dev_err so we can tell what device (and driver)
a message was for.

Testing Done: Compiled

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: loopback: add missing pr_fmt
Johan Hovold [Thu, 11 Feb 2016 12:52:49 +0000 (13:52 +0100)]
greybus: loopback: add missing pr_fmt

Add missing pr_fmt so we can at least tell what module the sole
remaining pr_err was from.

Testing Done:
Tested on DB3.5 with the generic bridge firmware on APB2.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: i2c: add bundle-device prefix to error messages
Johan Hovold [Thu, 11 Feb 2016 12:52:48 +0000 (13:52 +0100)]
greybus: i2c: add bundle-device prefix to error messages

Replace all pr_err with dev_err so we can tell what device (and driver)
a message was for.

Testing Done: Compiled

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: core: add device prefix to error messages
Johan Hovold [Thu, 11 Feb 2016 12:52:47 +0000 (13:52 +0100)]
greybus: core: add device prefix to error messages

Use dev_err and dev_warn where appropriate and remove now unused pr_fmt
defines.

Testing Done:
Tested on DB3.5 with the generic bridge firmware on APB2.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: manifest: add interface-device prefix to messages
Johan Hovold [Thu, 11 Feb 2016 12:52:46 +0000 (13:52 +0100)]
greybus: manifest: add interface-device prefix to messages

Use dev_err and friends so that we can tell which interface (and module)
a manifest-parsing error messages was for.

Testing Done:
Tested on DB3.5 with the generic bridge firmware on APB2.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: interface: clear upper 16-bits of version_id and product_id
Michael Scott [Tue, 9 Feb 2016 01:08:46 +0000 (17:08 -0800)]
greybus: interface: clear upper 16-bits of version_id and product_id

Current userspace looks through the sysfs interface entries for
matching vendor_id and product_id any time an interface is opened
by module developers.  The upper 16-bits of ES3 vendor_id and
product_id contain a reverse mask of the lower 16-bits.  This
additional information is never used and should be removed so
that every consumer of these sysfs entries doesn't have to perform
the same bit clearing logic.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
Reviewed-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: Revert "arche-apb-ctrl: Remove extra delay in APB reset"
Vaibhav Hiremath [Tue, 9 Feb 2016 16:39:16 +0000 (22:09 +0530)]
greybus: Revert "arche-apb-ctrl: Remove extra delay in APB reset"

We are seeing failures on DB3.1 board, and Axel root-caused it to this
commit, so revert it as of now.

This reverts commit 942627227684c187b727ba5fb581bc2d886b6708.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: spi: add device_type field to device config
Rui Miguel Silva [Tue, 2 Feb 2016 14:23:16 +0000 (14:23 +0000)]
greybus: spi: add device_type field to device config

Add device_type field in device config operation to get the type of
device and try to expose less the kernel internal over greybus.
This include the spidev, spi-nor will fetch the correct nor id over
jede and a modalias that will have the previous behavior (name will set
the driver to be loaded).

As at it, fix a trivial error path and return immediately.

Tested: using gbsim and confirming that a spidev and mtd device were
created.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: fix double free of tty port
Rui Miguel Silva [Fri, 5 Feb 2016 13:50:37 +0000 (13:50 +0000)]
greybus: uart: fix double free of tty port

When inserting and removing a module with a UART protocol defined a
double free of the tty_port would happen and that would generate a lot
of kernel oops in different places related to memory corruption.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: power_supply: rework get descriptors
Rui Miguel Silva [Thu, 4 Feb 2016 14:00:36 +0000 (14:00 +0000)]
greybus: power_supply: rework get descriptors

Rework the get property descriptors function to fix a memory handling
error for the response structure. This could corrupt the stack and
throw nonalignment PC or SP error:

Internal error: SP or PC abort: 8a000000 1 PREEMPT SMP
Modules linked in: gb_power_supply(O) gb_arche(O) gb_camera(O) gb_es2(O) gb_vibrator(O) gb_raw(O) g]
CPU: 3 PID: 51 Comm: kworker/u16:2 Tainted: G W O 3.10.73-g8a6af60-00118-g599a5c1 #1
Workqueue: greybus1:svc gb_svc_connection_destroy [greybus]
task: ffffffc0ba249580 ti: ffffffc0ba294000 task.ti: ffffffc0ba294000
PC is at gb_power_supply_connection_init+0x81/0x1dc [gb_power_supply]
LR is at gb_power_supply_connection_init+0x81/0x1dc [gb_power_supply]
pc : [<ffffffbffc03b901>] lr : [<ffffffbffc03b901>] pstate: 80000145
sp : ffffffc0ba297a00
x29: 32002e002a001100 x28: ffffffc042cb2c80

To fix this, allocate firstly the operation and handle request and
response using operation payload.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: Add missing return value
Jacopo Mondi [Fri, 5 Feb 2016 08:35:33 +0000 (09:35 +0100)]
greybus: camera: Add missing return value

Add missing return value assignement when changing unipro power mode to
PWM-G1.

Signed-off-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: Reset link speed on failed config
Jacopo Mondi [Fri, 5 Feb 2016 08:35:32 +0000 (09:35 +0100)]
greybus: camera: Reset link speed on failed config

Improve the management of unipro power mode changes in response
to a configure_stream operation.
When sending a "test only" request to camera module, do not change power
mode to HS-G2 as no frame will be actually transmitted.
When receiveing an "adjusted" configuration response, reset power
mode to PWM-G1.

Signed-off-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-apb-ctrl: Remove extra delay in APB reset
Vaibhav Hiremath [Thu, 4 Feb 2016 19:40:56 +0000 (01:10 +0530)]
greybus: arche-apb-ctrl: Remove extra delay in APB reset

With synchronization between SVC <=> AP over wake/detect line to
bring APB's out of reset, we do not need any extra delays now.
So remove it.

Testing Done: Tested for 10 iterations on EVT1

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fix sparse warning in manifest.c
Greg Kroah-Hartman [Wed, 3 Feb 2016 05:31:19 +0000 (21:31 -0800)]
greybus: fix sparse warning in manifest.c

The cport id field is a le16, so treat it as such when comparing it to
something else.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio_manager: add missing header
Bartosz Golaszewski [Wed, 3 Feb 2016 11:53:40 +0000 (12:53 +0100)]
greybus: audio_manager: add missing header

There's a definition missing in audio_manager causing the kernel build
to fail:

  CC [M]  ./greybus/audio_manager.o
./greybus/audio_manager.c:22:8: warning: type defaults to 'int' in declaration of 'DEFINE_IDA' [-Wimplicit-int]
error, forbidden warning: audio_manager.c:22
./kernel/scripts/Makefile.build:308: recipe for target './greybus/audio_manager.o' failed

Including linux/idr.h fixes the issue.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio: use variable 'is_connected' to maintain module state
Vaibhav Agarwal [Thu, 28 Jan 2016 15:45:40 +0000 (21:15 +0530)]
greybus: audio: use variable 'is_connected' to maintain module state

there is race condition between _disconnect() request &
stop_trigger() in case of abrupt module removal.
And sometimes this can lead to deadlock while acquiring
codec_info->lock.
To avoid such situation, atomic variable is used to maintain
codec connected state.
During dai operations (trigger, shutdown, etc.), 'is_connected'
variable is validated to avoid unnecessary lock acquire in
case module already removed.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio: codec driver cleanup
Vaibhav Agarwal [Thu, 28 Jan 2016 15:45:39 +0000 (21:15 +0530)]
greybus: audio: codec driver cleanup

audio codec driver is now moved to bundle driver approach.
This resolved many race conditions related to audio mgmt &
data connection init/exit sequence.
Thus, a lot of helper functions can now be safely removed.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: Fix sparse warnings around locking
Viresh Kumar [Thu, 28 Jan 2016 10:20:48 +0000 (15:50 +0530)]
greybus: connection: Fix sparse warnings around locking

The callers ensures that connection->lock is taken before calling few
routines, but that isn't enough for sparse as it sees an unexpected
unlock.

greybus/connection.c:380:29: warning: context imbalance in 'gb_connection_cancel_operations' - unexpected unlock

Fix that adding __must_lock() attribute to the function declaration.

This also adds the attribute for
gb_connection_flush_incoming_operations(), which isn't showing any
sparse warnings with the current state of code, but with minor
rearrangements of the code.

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: lsgb: remove it, it's in the gb-utils repo
Greg Kroah-Hartman [Wed, 3 Feb 2016 05:35:12 +0000 (21:35 -0800)]
greybus: lsgb: remove it, it's in the gb-utils repo

lsgb does not need to be in this repo, it gets installed as part of
gb-utils now.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: control: Fix sparse warnings
Viresh Kumar [Thu, 28 Jan 2016 10:20:49 +0000 (15:50 +0530)]
greybus: control: Fix sparse warnings

gb_control_get_version() is not used outside of the file and must be
marked as static. Following sparse warnings are reported today:

greybus/control.c:20:5: warning: symbol 'gb_control_get_version' was not declared. Should it be static?

Fix it by marking gb_control_get_version() 'static'.

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: audio: Fix sparse warnings
Viresh Kumar [Thu, 28 Jan 2016 10:20:47 +0000 (15:50 +0530)]
greybus: audio: Fix sparse warnings

greybus/audio_apbridgea.c:13:5: warning: symbol 'gb_audio_apbridgea_set_config' was not declared. Should it be static?
greybus/audio_apbridgea.c:30:5: warning: symbol 'gb_audio_apbridgea_register_cport' was not declared. Should it be static?
greybus/audio_apbridgea.c:44:5: warning: symbol 'gb_audio_apbridgea_unregister_cport' was not declared. Should it be static?
greybus/audio_apbridgea.c:58:5: warning: symbol 'gb_audio_apbridgea_set_tx_data_size' was not declared. Should it be static?
greybus/audio_apbridgea.c:72:5: warning: symbol 'gb_audio_apbridgea_get_tx_delay' was not declared. Should it be static?
greybus/audio_apbridgea.c:80:5: warning: symbol 'gb_audio_apbridgea_start_tx' was not declared. Should it be static?
greybus/audio_apbridgea.c:94:5: warning: symbol 'gb_audio_apbridgea_stop_tx' was not declared. Should it be static?
greybus/audio_apbridgea.c:106:5: warning: symbol 'gb_audio_apbridgea_set_rx_data_size' was not declared. Should it be static?
greybus/audio_apbridgea.c:120:5: warning: symbol 'gb_audio_apbridgea_get_rx_delay' was not declared. Should it be static?
greybus/audio_apbridgea.c:128:5: warning: symbol 'gb_audio_apbridgea_start_rx' was not declared. Should it be static?
greybus/audio_apbridgea.c:141:5: warning: symbol 'gb_audio_apbridgea_stop_rx' was not declared. Should it be static?
greybus/audio_gb.c:14:5: warning: symbol 'gb_audio_gb_get_topology' was not declared. Should it be static?
greybus/audio_gb.c:48:5: warning: symbol 'gb_audio_gb_get_control' was not declared. Should it be static?
greybus/audio_gb.c:70:5: warning: symbol 'gb_audio_gb_set_control' was not declared. Should it be static?
greybus/audio_gb.c:85:5: warning: symbol 'gb_audio_gb_enable_widget' was not declared. Should it be static?
greybus/audio_gb.c:97:5: warning: symbol 'gb_audio_gb_disable_widget' was not declared. Should it be static?
greybus/audio_gb.c:109:5: warning: symbol 'gb_audio_gb_get_pcm' was not declared. Should it be static?
greybus/audio_gb.c:133:5: warning: symbol 'gb_audio_gb_set_pcm' was not declared. Should it be static?
greybus/audio_gb.c:150:5: warning: symbol 'gb_audio_gb_set_tx_data_size' was not declared. Should it be static?
greybus/audio_gb.c:163:5: warning: symbol 'gb_audio_gb_get_tx_delay' was not declared. Should it be static?
greybus/audio_gb.c:183:5: warning: symbol 'gb_audio_gb_activate_tx' was not declared. Should it be static?
greybus/audio_gb.c:195:5: warning: symbol 'gb_audio_gb_deactivate_tx' was not declared. Should it be static?
greybus/audio_gb.c:207:5: warning: symbol 'gb_audio_gb_set_rx_data_size' was not declared. Should it be static?
greybus/audio_gb.c:220:5: warning: symbol 'gb_audio_gb_get_rx_delay' was not declared. Should it be static?
greybus/audio_gb.c:240:5: warning: symbol 'gb_audio_gb_activate_rx' was not declared. Should it be static?
greybus/audio_gb.c:252:5: warning: symbol 'gb_audio_gb_deactivate_rx' was not declared. Should it be static?

Fix them by including the header that declares the exported routines.

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: audio_manager: use an 'ida' for the module id
Greg Kroah-Hartman [Tue, 26 Jan 2016 00:52:17 +0000 (16:52 -0800)]
greybus: audio_manager: use an 'ida' for the module id

Every time we hotplug an audio module, we get a new audio module id.  We
should recycle them instead of just constantly incrementing the number
so we don't see things like:
[178016.832580] Created audio module #6124
in the kernel logs.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: loopback_test: Decrease the max number of devices
Axel Haslam [Fri, 29 Jan 2016 10:34:19 +0000 (11:34 +0100)]
greybus: loopback_test: Decrease the max number of devices

Its unrealistic to expect 50 loopback devices,
and the mask parameter can hold up to "int" anyways
so decrease to max number of devices to sane value.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: firmware: convert to bundle driver
Johan Hovold [Fri, 29 Jan 2016 14:42:31 +0000 (15:42 +0100)]
greybus: firmware: convert to bundle driver

Convert the legacy firmware protocol driver to a bundle driver.

This also fixes a potential crash should a (malicious) module have sent
an early request before the private data had been initialised.

Note that the firmware protocol needs to support the version request
indefinitely since it has been burnt into ROM.

In order to avoid having to update current module-loading scripts, keep
this driver internal to greybus core at least until modalias support is
added.

Note that there is no MODULE_DEVICE_TABLE defined for firmware as we
cannot have two greybus tables in one module on ancient 3.10 kernels and
that the legacy driver is currently also internal to core. This needs be
added once the driver can be built as a module.

Testing Done: Tested on DB3.

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: legacy: remove unimplemented classes from id table
Johan Hovold [Fri, 29 Jan 2016 14:42:30 +0000 (15:42 +0100)]
greybus: legacy: remove unimplemented classes from id table

Remove the unimplemented display, sensor, and svc classes from the
device-id table.

As Viresh noted the SVC protocol is special and having an SVC class
doesn't really make sense at all. Either way, the SVC protocol is
already implemented by core.

Testing Done: Compiled

Reported-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: arche-platform: reduce wait between WAKE_OUT checks
Michael Scott [Thu, 28 Jan 2016 00:41:01 +0000 (16:41 -0800)]
greybus: arche-platform: reduce wait between WAKE_OUT checks

SVC WAKE_OUT loop is estimated 400ms during which wake_detect line
is pulled low for AP detection.  On AP side we have 500ms delay
between checks.  To avoid timing issues, reduce delay between
checks and raise total # of checks so that overall time for sequence
is the same.

Testing Done:
- Used for DB3.5/EVT1.5 hardware during bringup
- Regression tested on DB3.1+ES2, DB3.1+ES3

Signed-off-by: Michael Scott <michael.scott@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: arche-platform: assert wake-detect to complete WAKE_OUT event
Michael Scott [Thu, 28 Jan 2016 00:41:00 +0000 (16:41 -0800)]
greybus: arche-platform: assert wake-detect to complete WAKE_OUT event

After SVC generates WAKE_OUT (pulling wake-detect pin low) and APB is
brought out of reset, we need to assert wake-detect again to complete
SVC WAKE_OUT logic.

Testing Done:
- Used for DB3.5/EVT1.5 hardware during bringup
- Regression tested on DB3.1+ES2, DB3.1+ES3

Signed-off-by: Michael Scott <michael.scott@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: arche-platform: bring SVC out of reset later in probe
Michael Scott [Thu, 28 Jan 2016 00:40:59 +0000 (16:40 -0800)]
greybus: arche-platform: bring SVC out of reset later in probe

Move SVC deassert reset to after wake-detect pin has been pulled
low in probe.  Otherwise, SVC may trigger WAKE_OUT based on a
default high signal.

Testing Done:
- Used for DB3.5/EVT1.5 hardware during bringup
- Regression tested on DB3.1+ES2, DB3.1+ES3

Signed-off-by: Michael Scott <michael.scott@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: arche-platform: ensure wake-detect pin is deasserted
Michael Scott [Thu, 28 Jan 2016 00:40:58 +0000 (16:40 -0800)]
greybus: arche-platform: ensure wake-detect pin is deasserted

During DB3.5 bringup, it was noted that wake_detect signal was not
properly generating SVC edge IRQ.  To ensure signal goes from low
to high correctly, let's bring signal low (regardless of default
pin state).

Testing Done:
- Used for DB3.5/EVT1.5 hardware during bringup
- Regression tested on DB3.1+ES2, DB3.1+ES3

Signed-off-by: Michael Scott <michael.scott@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: hd: fix host-device-removal race
Johan Hovold [Thu, 28 Jan 2016 11:43:29 +0000 (12:43 +0100)]
greybus: hd: fix host-device-removal race

Make sure to tear down the svc and flush any on-going hotplug processing
before removing the remaining interfaces.

This fixes crashes due to host-device removal racing with svc
hotplug/unplug processing (e.g. at "UniPro restart").

Testing Done:
Verified that this fixes crashes reproducible on SDB when unloading the
host-device driver module while generating hotplug/unplug events.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio: Rename Audio class and remove the unused one
Viresh Kumar [Wed, 27 Jan 2016 05:47:00 +0000 (11:17 +0530)]
greybus: audio: Rename Audio class and remove the unused one

There should be a single class macro for Audio and two protocol macros.
Rename class with value 0x12 as GREYBUS_CLASS_AUDIO and remove the other
unused class GREYBUS_CLASS_AUDIO_DATA.

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: audio_codec: convert to bundle driver
Viresh Kumar [Wed, 27 Jan 2016 11:27:48 +0000 (16:57 +0530)]
greybus: audio_codec: convert to bundle driver

Convert the legacy audio management and data protocol drivers to a
bundle driver.

The Audio bundle driver can support a single management and any number
of data cports, and so we expect multiple data cports to be present for
the bundle during initialization.

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: audio_codec: Free gccodec on dia probe failure
Viresh Kumar [Wed, 27 Jan 2016 05:46:58 +0000 (11:16 +0530)]
greybus: audio_codec: Free gccodec on dia probe failure

We aren't freeing the codec, that we allocated before failing to probe
the connection. Free it.

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: audio_codec: Free gccodec on codec probe failure
Viresh Kumar [Wed, 27 Jan 2016 05:46:57 +0000 (11:16 +0530)]
greybus: audio_codec: Free gccodec on codec probe failure

We aren't freeing the codec, that we allocated before failing to probe
the connection. Free it.

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: legacy: fix a null pointer dereference
Bartosz Golaszewski [Wed, 27 Jan 2016 12:17:52 +0000 (13:17 +0100)]
greybus: legacy: fix a null pointer dereference

When gb_protocol_get() fails in legacy_connection_create(), we end up
bailing-out before assigning lc->connection and lc->protocol. Calling
legacy_connection_destroy() in that case results in a null pointer
dereference.

Check if lc->connection is not null before freeing it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: loopback_test: make output to csv file a parameter option
Axel Haslam [Tue, 26 Jan 2016 20:26:02 +0000 (21:26 +0100)]
greybus: loopback_test: make output to csv file a parameter option

Its useful to get a CSV output on stdout for test frameworks to read
and parse the results. However, a csv file is not always needed.

Add the -z option to  create/append a csv file only when the user
asks for it.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc watchdog: allow it to be enabled/disabled from userspace
Greg Kroah-Hartman [Tue, 26 Jan 2016 23:17:08 +0000 (15:17 -0800)]
greybus: svc watchdog: allow it to be enabled/disabled from userspace

Sometimes you want to disable the SVC watchdog without having to patch
your kernel, so provide a sysfs file to do this.  This can let us do
power measurements, and let the firmware developers not go crazy
worrying that the kernel is going to reset their chips with no notice.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: only build module against msm kernel
Greg Kroah-Hartman [Tue, 26 Jan 2016 04:13:15 +0000 (20:13 -0800)]
greybus: camera: only build module against msm kernel

The camera driver currently does not build against anything other than
the msm kernel, due to cross-dependancies, so enable that here so that
we can build against other kernels without failing the build.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Tested-by: Marti Bolivar <mbolivar@leaflabs.com>
Acked-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc: double the ping delay timeout
Greg Kroah-Hartman [Tue, 26 Jan 2016 16:57:50 +0000 (08:57 -0800)]
greybus: svc: double the ping delay timeout

Sometimes the ping response comes back _right_ after we timed out, as
the svc got its act together and squeaked out the ack, yet we miss it
and reset the whole bus.  Double the delay to hopefully give the svc a
little more of a chance to fix itself.  Odds are, it's still in trouble,
but we can just hold off resetting it for a bit more...

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Disable clock as part of driver remove
Vaibhav Hiremath [Tue, 26 Jan 2016 01:53:29 +0000 (07:23 +0530)]
greybus: arche-platform: Disable clock as part of driver remove

As part of driver remove (cleanup) function, disable the clock for both
SVC, APB1 & APB2.

Testing Done:
Tested on EVT1 platform with Connect=>disconnect=>connect
iteration, almost close to 100 iterations have passed (demo branch).
And also tested with kernel-only build.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: Stream config change unipro speed
Jacopo Mondi [Sun, 24 Jan 2016 03:44:46 +0000 (19:44 -0800)]
greybus: camera: Stream config change unipro speed

Unipro network speed was increased at camera initialization time and
never slowed down.
This unnecessary drains power during the entire time camera module is
plugged in.
Increasing/decreasing unipro link speed before issuing stream
configuration request to camera module prevents this from happening.

Signed-off-by: Jacopo Mondi <jacopo.mondi@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc: return proper error code on watchdog create error
Greg Kroah-Hartman [Sun, 24 Jan 2016 01:36:00 +0000 (17:36 -0800)]
greybus: svc: return proper error code on watchdog create error

When the watchdog is not created properly, we need to propagate the
error for this and not just return success.

Reported-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc: add a "watchdog" to check the network health
Greg Kroah-Hartman [Thu, 21 Jan 2016 06:51:49 +0000 (22:51 -0800)]
greybus: svc: add a "watchdog" to check the network health

Now that we have a svc ping command, let's add a watchdog to call it
every so often (1 second at the moment.)  If it finds something went
wrong, post a stern message to the kernel log and call:
start unipro_reset
to reset the whole greybus hardware subsystem.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: lsgb: Minor tweaks
Greg Kroah-Hartman [Sat, 23 Jan 2016 02:26:23 +0000 (18:26 -0800)]
greybus: lsgb: Minor tweaks

Make it executable on an Android system
Change layout to be show heirachy a bit better.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: add semiplanar and planar formats
Gjorgji Rosikopulos [Fri, 22 Jan 2016 15:59:44 +0000 (17:59 +0200)]
greybus: camera: add semiplanar and planar formats

This change adds missing planar and semiplanar
formats from gb specification.

Mbus to Gb format map:
V4L2_MBUS_FMT_NV12_1x8 -> 0x12
V4L2_MBUS_FMT_NV21_1x8 -> 0x13
V4L2_MBUS_FMT_YV12_1x8 -> 0x16
V4L2_MBUS_FMT_YU12_1x8 -> 0x17

Change depends on:
"media: add new mediabus format enums for ara camera"

Signed-off-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc: Expose and retain VID/PID received from bootrom for ES2
Viresh Kumar [Fri, 22 Jan 2016 10:46:08 +0000 (16:16 +0530)]
greybus: svc: Expose and retain VID/PID received from bootrom for ES2

ES2 chips doesn't have efuses for storing module's vendor_id and
product_id and so we have hacked bootrom earlier using firmware
protocol, so that VID/PID can be received for fetching firmware
packages.

Another requirement is to expose them to sysfs, so that modules can be
identified properly.

That can be easily solved by updating interface's VID/PID, when fetched
using firmware protocol and later reusing them while the module switches
its identity from bootrom to firmware.

Do that only if the module is ES2 and the VID/PID sent during hotplug
are both 0.

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: lsgb: add lsgb shell script
Greg Kroah-Hartman [Fri, 22 Jan 2016 22:42:34 +0000 (14:42 -0800)]
greybus: lsgb: add lsgb shell script

Horrid hack, but a start at making it easier for people to see what is
currently connected without having to deal with poking around in sysfs
directly.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio_codec: update codec_name as per driver->name
Vaibhav Agarwal [Thu, 21 Jan 2016 17:03:13 +0000 (22:33 +0530)]
greybus: audio_codec: update codec_name as per driver->name

Originally, driver->name was not poluated from GB and thus
manually set from audio_codec driver as a hack.
This is no more required.
Another patch already removes that hack.

Now, with new driver->name as "legacy.<id-bundle.interface>"
codec is registered with different name.
So, during DAI link registration as well it needs modification.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: firmware: abort if AP_READY fails
Johan Hovold [Thu, 21 Jan 2016 16:34:26 +0000 (17:34 +0100)]
greybus: firmware: abort if AP_READY fails

Abort if the AP_READY request fails.

Also update the comment suggesting that this operation was a temporary
one.

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: vibrator: convert to bundle driver
Johan Hovold [Thu, 21 Jan 2016 16:34:24 +0000 (17:34 +0100)]
greybus: vibrator: convert to bundle driver

Convert the legacy vibrator protocol driver to a bundle driver.

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: hid: convert to bundle driver
Johan Hovold [Thu, 21 Jan 2016 16:34:23 +0000 (17:34 +0100)]
greybus: hid: convert to bundle driver

Convert the legacy HID protocol driver to a bundle driver.

This also fixes a potential crash should a (malicious) module have sent
an early request before the private data had been initialised.

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: hid: clean up init error paths
Johan Hovold [Thu, 21 Jan 2016 16:34:22 +0000 (17:34 +0100)]
greybus: hid: clean up init error paths

Separate success and error paths more clearly.

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: set request handlers at creation
Johan Hovold [Thu, 21 Jan 2016 16:34:21 +0000 (17:34 +0100)]
greybus: connection: set request handlers at creation

Set the connection request handler at creation rather than when enabling
the connection.

This is possible now that connections are created by the drivers that
use them rather than by core at manifest parsing time.

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: legacy: look up protocol at connection creation
Johan Hovold [Thu, 21 Jan 2016 16:34:20 +0000 (17:34 +0100)]
greybus: legacy: look up protocol at connection creation

Look up legacy protocol at connection create instead of at init.

Note that we can now look up the protocol before even creating the
actual connection. This is needed to be able to set a connection request
handler when creating the connection rather than when enabling it.

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: remove legacy protocol id from core
Johan Hovold [Thu, 21 Jan 2016 16:34:19 +0000 (17:34 +0100)]
greybus: connection: remove legacy protocol id from core

Remove legacy protocol-id field that is only used by the legacy-protocol
driver from the connection structure.

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: legacy: add initialized flag
Johan Hovold [Thu, 21 Jan 2016 16:34:18 +0000 (17:34 +0100)]
greybus: legacy: add initialized flag

Add initialized flag and use instead of the connection protocol pointer
to determine when the legacy connection has been initialised.

This is a step in moving legacy connection binding to
connection-creation time.

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: legacy: refactor legacy-connection handling
Johan Hovold [Thu, 21 Jan 2016 16:34:17 +0000 (17:34 +0100)]
greybus: legacy: refactor legacy-connection handling

Add wrapper structure for legacy connections and add helpers to create
and destroy legacy connections.

This is a step in removing legacy connection fields from the core
structures.

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: return error-valued pointer on creation errors
Johan Hovold [Thu, 21 Jan 2016 16:34:16 +0000 (17:34 +0100)]
greybus: connection: return error-valued pointer on creation errors

Return an ERR_PTR on errors when creating connections.

This allows driver probe to fail with a more informative error message
as not all connection creation errors are due to memory exhaustion.

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 connection-create interface
Johan Hovold [Thu, 21 Jan 2016 16:34:15 +0000 (17:34 +0100)]
greybus: connection: rename connection-create interface

Drop the _dynamic suffix from the exported interface that drivers use to
create connections.

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: simplify connection-creation interface
Johan Hovold [Thu, 21 Jan 2016 16:34:14 +0000 (17:34 +0100)]
greybus: connection: simplify connection-creation interface

Simplify the exported generic interface for creating dynamic
connections.

Since all driver connections will have a bundle we can drop the
redundant interface parameter.

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: drop the legacy protocol-id parameter
Johan Hovold [Thu, 21 Jan 2016 16:34:13 +0000 (17:34 +0100)]
greybus: connection: drop the legacy protocol-id parameter

The protocol-id parameter is only used by the legacy driver so remove
it from the generic interface and move it to the legacy driver until it
can be removed completely.

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 helper to create control connections
Johan Hovold [Thu, 21 Jan 2016 16:34:12 +0000 (17:34 +0100)]
greybus: connection: add helper to create control connections

Add dedicated helper to create control connections.

This will allow us to simplify the generic (dynamic) interface.

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: drop protocol parameter from static interface
Johan Hovold [Thu, 21 Jan 2016 16:34:11 +0000 (17:34 +0100)]
greybus: connection: drop protocol parameter from static interface

Drop legacy protocol parameter from static connection interface.

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>