History log of /linux-master/drivers/staging/greybus/arche-platform.c
Revision Date Author Comments
# decb929f 14-Jul-2023 Rob Herring <robh@kernel.org>

staging: Explicitly include correct DT includes

The DT of_device.h and of_platform.h date back to the separate
of_platform_bus_type before it as merged into the regular platform bus.
As part of that merge prepping Arm DT support 13 years ago, they
"temporarily" include each other. They also include platform_device.h
and of.h. As a result, there's a pretty much random mix of those include
files used throughout the tree. In order to detangle these headers and
replace the implicit includes with struct declarations, users need to
explicitly include the correct includes.

Signed-off-by: Rob Herring <robh@kernel.org>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> # tegra-video
Acked-by: Parthiban Veerasooran <parthiban.veerasooran@microchip.com>
Acked-by: Alex Elder <elder@linaro.org>
Link: https://lore.kernel.org/r/20230714175002.4064428-1-robh@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 7846a2ae 03-Apr-2023 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

staging: greybus: arche: Convert to platform remove callback returning void

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20230403154014.2564054-6-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 3a9aaf04 30-Apr-2022 Nickalas Cason <nickalas@cason.dev>

staging: greybus: correct typo in comment

Correct misspelling in comment. Issue found with checkpatch.

Signed-off-by: Nickalas Cason <nickalas@cason.dev>
Link: https://lore.kernel.org/r/20220430230139.7i772mvejlhevamn@desktop
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 0778f04b 01-Apr-2021 Beatriz Martins de Carvalho <martinsdecarvalhobeatriz@gmail.com>

staging: greybus: arche-platform: Ending line with argument

Remove checkpatch check "CHECK: Lines should not end with a '('"
with argument present in next line.

Signed-off-by: Beatriz Martins de Carvalho <martinsdecarvalhobeatriz@gmail.com>
Link: https://lore.kernel.org/r/20210401090754.116522-1-martinsdecarvalhobeatriz@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# ec0ad868 24-Aug-2019 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

staging: greybus: move core include files to include/linux/greybus/

With the goal of moving the core of the greybus code out of staging, the
include files need to be moved to include/linux/greybus.h and
include/linux/greybus/

Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Vaibhav Agarwal <vaibhav.sr@gmail.com>
Cc: Rui Miguel Silva <rmfrfs@gmail.com>
Cc: David Lin <dtwlin@gmail.com>
Cc: "Bryan O'Donoghue" <pure.logic@nexus-software.ie>
Cc: greybus-dev@lists.linaro.org
Cc: devel@driverdev.osuosl.org
Acked-by: Mark Greer <mgreer@animalcreek.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Alex Elder <elder@kernel.org>
Link: https://lore.kernel.org/r/20190825055429.18547-8-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 4207b587 14-Jan-2019 Nishad Kamdar <nishadkamdar@gmail.com>

staging: greybus: arche-platform: Switch to the gpio descriptor interface

Use the gpiod interface instead of the deprecated old non-descriptor
interface while continuing to ignore gpio flags from device tree in
"svc_reset_onoff()" for now.

Reviewed-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Nishad Kamdar <nishadkamdar@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# a2e63709 27-Apr-2018 Arvind Yadav <arvind.yadav.cs@gmail.com>

staging: greybus: Use gpio_is_valid()

Replace the manual validity checks for the GPIO with the
gpio_is_valid().

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 1dab154e 19-Apr-2018 Wolfram Sang <wsa+renesas@sang-engineering.com>

staging: greybus: simplify getting .drvdata

We should get drvdata from struct device directly. Going via
platform_device is an unneeded step back and forth.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 07df5b7c 17-Dec-2017 Kamal Heib <kamalheib1@gmail.com>

staging: greybus: arche-platform.c: Fix alignment should match open parenthesis

Fix "alignment should match open parenthesis" checkpatch.pl error.

Signed-off-by: Kamal Heib <kamalheib1@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 863dbc52 07-Nov-2017 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

staging: greybus: Remove redundant license text

Now that the SPDX tag is in all greybus files, that identifies the
license in a specific and legally-defined manner. So the extra GPL text
wording can be removed as it is no longer needed at all.

This is done on a quest to remove the 700+ different ways that files in
the kernel describe the GPL license text. And there's unneeded stuff
like the address (sometimes incorrect) for the FSF which is never
needed.

No copyright headers or other non-license-description text was removed.

Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Acked-by: Vaibhav Agarwal <vaibhav.sr@gmail.com>
Acked-by: David Lin <dtwlin@gmail.com>
Acked-by: Johan Hovold <johan@kernel.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Mark Greer <mgreer@animalcreek.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Acked-by: "Bryan O'Donoghue" <pure.logic@nexus-software.ie>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# eb50fd3a 07-Nov-2017 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

staging: greybus: add SPDX identifiers to all greybus driver files

It's good to have SPDX identifiers in all files to make it easier to
audit the kernel tree for correct licenses.

Update the drivers/staging/greybus files files with the correct SPDX
license identifier based on the license text in the file itself. The
SPDX identifier is a legally binding shorthand, which can be used
instead of the full boiler plate text.

This work is based on a script and data from Thomas Gleixner, Philippe
Ombredanne, and Kate Stewart.

Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com>
Cc: "Bryan O'Donoghue" <pure.logic@nexus-software.ie>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Acked-by: Vaibhav Agarwal <vaibhav.sr@gmail.com>
Acked-by: David Lin <dtwlin@gmail.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Acked-by: Johan Hovold <johan@kernel.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Mark Greer <mgreer@animalcreek.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 4a27e3e0 21-Aug-2017 Eames Trinh <eamestrinh@gmail.com>

Staging: greybus: Fix spelling error in comment

Fixed a spelling error.

Signed-off-by: Eames Trinh <eamestrinh@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 100330ec 26-Jul-2017 Amitoj Kaur Chawla <amitoj1606@gmail.com>

staging: greybus: Remove unnecessary platform_set_drvdata

Unnecessary platform_set_drvdata() has been removed since the driver
core clears the driver data to NULL after device release or on
probe failure. There is no need to manually clear the device
driver data to NULL.

The Coccinelle semantic patch used to make this change is as follows:
//<smpl>
@@
struct platform_device *pdev;
@@
- platform_set_drvdata(pdev, NULL);
//</smpl>

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# bf766625 10-Jul-2017 Mitchell Tasman <tasman@leaflabs.com>

staging: greybus: arche: wrap over-length lines

Adjust formatting of several comments to keep line length within
the 80 column limit preferred by the Linux kernel coding style.

Signed-off-by: Mitchell Tasman <tasman@leaflabs.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 0687090a 18-May-2017 Arnd Bergmann <arnd@arndb.de>

staging: greybus: mark PM functions as __maybe_unused

Enabling the arche platform for compile testing showed a harmless
warning with CONFIG_PM=n:

drivers/staging/greybus/arche-platform.c:632:12: error: 'arche_platform_resume' defined but not used [-Werror=unused-function]
drivers/staging/greybus/arche-platform.c:618:12: error: 'arche_platform_suspend' defined but not used [-Werror=unused-function]

This marks the functions as __maybe_unused to shut up the warnings.

Fixes: 2eccd4aa19fc ("staging: greybus: enable compile testing of arche driver")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 2eccd4aa 16-May-2017 Johan Hovold <johan@kernel.org>

staging: greybus: enable compile testing of arche driver

Add Arche platform-driver config option and allow the driver to be
compile tested also without the out-of-tree usb3613 driver.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 1e029b83 16-May-2017 Johan Hovold <johan@kernel.org>

staging: greybus: arche: remove timesync remains

Remove the remaining timesync bits that were left in the arche platform
driver and which prevented the driver from being compiled.

Fixes: bdfb95c4baab ("staging: greybus: remove timesync protocol support")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 461ab807 09-Feb-2017 Gioh Kim <gi-oh.kim@profitbricks.com>

staging: greybus: fix "line over 80 characters" coding style issues

This patch fixes only obvious lines.
There are still more issues.

Signed-off-by: Gioh Kim <gi-oh.kim@profitbricks.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# d9966f1d 01-Nov-2016 Johan Hovold <johan@kernel.org>

staging: greybus: arche-platform: fix device reference leak

Make sure to drop the device reference taken by of_find_device_by_node()
before returning from arche_platform_change_state().

Note that this code is expected to be removed, but let's fix up the leak
nonetheless.

Fixes: 886aba558b9e ("greybus: arche-platform: Export fn to allow...")
Signed-off-by: Johan Hovold <johan@kernel.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <hvaibhav.linux@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 25633d1f 17-Oct-2016 Wei Yongjun <weiyongjun1@huawei.com>

greybus: arche-platform: Add missing of_node_put() in arche_platform_change_state()

This node pointer is returned by of_find_compatible_node() with
refcount incremented in this function. of_node_put() on it before
exitting this function.

This is detected by Coccinelle semantic patch.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Acked-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# cf3ba55d 12-Oct-2016 Elise Lennion <elise.lennion@gmail.com>

staging: greybus: arche-platform: Format block comments.

Fix checkpatch warning:

WARNING: Block comments use a trailing */ on a separate line

Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# cdcffc0c 22-Sep-2016 Eva Rachel Retuya <eraretuya@gmail.com>

staging: greybus: arche-platform: declare struct of_device_id as const

Declare the arrays 'arche_platform_of_match' and 'arche_combined_id' as const.

'arche_platform_of_match' is only stored in the .of_match_table field of a
device_driver structure, which is declared as const.

'arche_combined_id' is passed to MODULE_DEVICE_TABLE. This macro does not
modify the array and therefore the array can be declared as const. Checkpatch
pointed out both issues.

WARNING: struct of_device_id should be normally const

Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 5a420d15 20-Sep-2016 Eva Rachel Retuya <eraretuya@gmail.com>

staging: greybus: arche-platform: compress return logic into one line

Modify return statement to use the value being returned directly instead of
assigning it first to 'ret' and returning this variable. Coccinelle semantic
patch used:

@@
expression e;
local idexpression ret;
@@

-ret =
+return
e;
-return ret;

Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 921dbe52 28-Jul-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Add support for SPI bus sharing for Mihi

In case of Mihi, SPI bus is shared between APB1 and APB2
SPI ROMs, so their FW flashing must be sequential and
arche-platform driver should make sure that they are mutual
exclusive in nature.

So this patch adds certain restrictions to the user of the
arche-platform driver,

- User can no longer flash APB1 and APB2 SPI ROM in parallel
- SPI bus becomes an resource, so user must claim it by moving
respective APB device into FW_FLASHING mode and release it
by exiting FW_FLASHING mode. User can exit FW_FLASHING mode by
switching to any other modes (ACTIVE, OFF, STANDBY).
- If APB1 is in FW_FLASHING mode, APB2 can no longer enter into
FW_FLASHING mode. User will get -EBUSY.

Having said that, while APB1 is into FW_FLASHING mode,
APB2 can independently boot from its own SPI ROM.

Testing Done: Tested by simulating usecase on EVT2.
- Made sure that APB1 and APB2 FW_FLASHING mode is mutual exclusive
in nature. Confirmed that an attempt on second device return -EBUSY.
- Added simulating code, where printed state of dummy gpio for
spi-en and verified that it shows right pin status for both APBs

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 8ef0b538 03-Aug-2016 Vaibhav Hiremath <hiremath_vaibhav@projectara.com>

greybus: arche-platform: Reset SVC & APB only if turned off by SUSPEND_PREPARE

There is possible race condition in arche platform driver for
maintaining of ->state field, when shared with timesync driver.

Assume device booted fine, all connected modules have been enumerated
correctly. As part of suspend-resume operation we have pm_notifier
callback, where we turn off SVC & APB and coldboot on resume.
In the process of resume, all modules gets enumerated again, and
timesync driver does come into picture everytime.
So when timesync driver requests arche-platform to change the state
to TIMESYNC and in the middle of sync operation, if suspend gets
triggered, then execution lands into arche-platform->pm_notifier callback,
leading to race condition in the driver, where it checks for (state != ACTIVE)
in PM_SUSPEND_PREPARE and returns, but in PM_POST_SUSPEND it just simply
coldboots SVC & APB, which would inbalance all resources (including IRQ).

So we need a add check in PM_POST_SUSPEND, to make sure that, we only
coldboot devices if they are in to off state,
i.e. if (state != OFF) then return.

Testing Done: Done regressive suspend/resume testing on EVT2 platform.
Note that, I some time hit issue.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# d29b67d4 19-Jul-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Add support for init-off feature

Disable wake_detect interrupt after request

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

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

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

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

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

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 1f77b363 12-Jul-2016 David Lin <dtwlin@google.com>

greybus: hd: arche-platform: implement greybus shutdown

Implement platform driver shutdown callback to perform proper greybus
shutdown so that the userspace unipro_shutdown service that shuts down
the APB/SVC abruptly can be removed. The shutdown callback in
arche-platform will first remove SVC so that all the Interface can be
Deactivated in a sequence according to the spec before powering off the
APB:

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

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

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

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 970dc85b 05-Jun-2016 Bryan O'Donoghue <bryan.odonoghue@linaro.org>

greybus: timesync: Add timesync core driver

This patch adds the core timesync functionality.

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

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

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

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


# 7a867d14 24-May-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Enable SVC clock during FW_FLASHING state

The issue is, as part of kernel-only build we started seeing
failures in SVC FW flashing. It was reproducible easily in kernel-only
build, but never observed on Android build.

During debugging, there were couple of observations,

1. If SVC clock enabled and disables (which is REFCLK_MAIN), then SVC FW
flashing works.
2. If we do not switch SVC to HSE (external clock source) it works.
Recently, SVC code has been updated to switch HSE clock, so removing
it (remove/skip rcc_switch_ara_pll() fn) would use internal clock only.

As per STM32 spec, for flashing through USART we do not need
to enable HSE, but the above observation contradicts with it.

There is still something missing in terms of understanding of how STM32
device functions as far as Flashing is concerned. There is something
hidden in HW, which probably still need to identify.

So as a interim solution we will enable clock for FW_FLASHING state,
which seems to be fixing the issue here.

Testing Done: Tested on EVT1.5 with arche6.0 and kernel-only build.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 0b1283e3 24-May-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Enter ACTIVE state only from OFF state

Make sure that, transition to active state happens only from OFF state.
Instead of imposing the restriction to user-space, driver internally
switches to OFF state and then to ACTIVE state.

Testing Done: Tested on EVT1.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# c61a8b49 24-May-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Make fw_flashing_seq() return error

Make arche_platform_fw_flashing_seq() return error value, needed
later when we add clock enable support for FW flashing.

Testing Done: Tested on EVT1.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# d7be800f 23-May-2016 Bryan O'Donoghue <bryan.odonoghue@linaro.org>

greybus: Fix unbalanced irq_enable() backtrace

Tip-of-tree is exhibiting a backtrace when loading-up the set of greybus
kernel modules due to calling arche_platform_wd_irq_en() directly after a
call to devm_request_threaded_irq().

At the point we call arch_platform_wd_irq_en() the relevant IRQ will
already be enabled. What we want to do in this situation is configure the
GPIO line as an input. This patch fixes the backtrace by supplanting
arche_platform_wd_irq_en() with
gpio_direction_input(arche_pdata->wake_detect_gpio) in
arche_platform_probe().

WARNING: at msm-ara-3.10/kernel/irq/manage.c:457 __enable_irq+0x74/0xc0()
Unbalanced enable for IRQ 687
Modules linked in: gb_arche(O+) gb_camera(O) gb_es2(O) gb_vibrator(O)
gb_raw(O) gb_power_supply(O) gb_loopback(O) gb_light(O) gb_hid(O)
greybus(O)
CPU: 0 PID: 415 Comm: insmod Tainted: G W O 3.10.78-g2a4dec8 #65
Call trace:
[<ffffffc000206adc>] dump_backtrace+0x0/0x248
[<ffffffc000206d34>] show_stack+0x10/0x1c
[<ffffffc000c6c698>] dump_stack+0x1c/0x28
[<ffffffc00021c95c>] warn_slowpath_common+0x74/0x9c
[<ffffffc00021c9d0>] warn_slowpath_fmt+0x4c/0x58
[<ffffffc000269d7c>] __enable_irq+0x70/0xc0
[<ffffffc000269e34>] enable_irq+0x68/0x7c
[<ffffffbffc0609b4>] arche_platform_probe+0x3b4/0x4f4 [gb_arche]
[<ffffffc0005ace30>] platform_drv_probe+0x14/0x20
[<ffffffc0005ab980>] driver_probe_device+0x160/0x374
[<ffffffc0005abc40>] __driver_attach+0x60/0x90
[<ffffffc0005aa768>] bus_for_each_dev+0x74/0x94
[<ffffffc0005ab2c4>] driver_attach+0x1c/0x28
[<ffffffc0005aae74>] bus_add_driver+0x124/0x248
[<ffffffc0005ac270>] driver_register+0x94/0x110
[<ffffffc0005ad3c4>] platform_driver_register+0x58/0x64
[<ffffffbffc065020>] $x+0x20/0x58 [gb_arche]
[<ffffffc0002007dc>] do_one_initcall+0xb0/0x14c
[<ffffffc00028252c>] load_module+0x19d0/0x1b18
[<ffffffc00028278c>] SyS_init_module+0x118/0x130

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiermath@linaro.org>
Tested-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 7ba535ec 17-May-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Rename assert_wakedetect=>arche_platform_wd_irq_en

Now, since AP module does not send any signal to SVC, so it
automatically restricts the wake/detect gpio to input.
So rename assert_wakedetect() fn to arche_platform_wd_irq_en(),
as per implementation.

Testing Done: Tested on EVT1.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 16fd976c 17-May-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Do not assert wake/detect signal to SVC

With new definition of AP module boot flow (from HotPlug camp),
AP is not supposed to send any wake/detect signal to SVC, instead,
during boot SVC would straight away send wake_out pulse on wake/detect
line.
Note that, pin configuration of wake/detect line would be set to
active-high by default, so wake/detect line would always stay high,
unless SVC drives it. AP module uses wake/detect line strictly in input
mode.

Testing Done: Tested on EVT1.5 platform.

Note: We are yet to decide on PM support for APBx, so we may need to
generate/handshake with SVC over wake/detect line in the future. As of
now, follow the implementation and add stuff as and when they come.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# a974f469 13-May-2016 Sandeep Patil <sspatil@google.com>

greybus: arche-platform: Fix the MODULE_LICENSE to match with header

The header calls out the license to be GPL v2, while the module declares
itself as "GPL"

Testing Done: Trivial

Signed-off-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# c4058b79 05-May-2016 Bryan O'Donoghue <bryan.odonoghue@linaro.org>

greybus: arche-platform: Rework platform/wd-line state transition logic

This patch simplifies and improves the readability of the internal state
transition logic of arche platform driver state transition logic by:

1. Making a dedicated function to state-transition the platform code.
2. Condense the decision to swtich states down to a single switch
statement instead of four separate if/else clauses.

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


# 886aba55 05-May-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Export fn to allow timesync driver to change the state

With the addition of the timesync driver and looking at the hardware
interfaces we have, its clear we need to add a new arche-platform state.

This patch adds ARCHE_PLATFORM_STATE_TIME_SYNC to the arche-platform driver
to facilitate transition to the TIME_SYNC state if-and-only-if the
arche-platform driver is in the ACTIVE state.

This is mainly needed as wake/detect lines are shared between TIMESYNC
operation and basic control functionality of APBs. So during TIMESYNC
we want to make sure that the events on wake/detect lines are
ignored by the arche-platform APB reset logic.

This patch adds one exported function, which can be invoked from
timesync driver code, allowing, switching between
ARCHE_PLATFORM_STATE_TIME_SYNC <=> ARCHE_PLATFORM_STATE_ACTIVE states.

[ bryan.odonoghue@linaro.org: Added mutex, massaged commit text ]

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


# 6c1ca56d 05-May-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Rename spinlock variable lock => wake_detect_lock

With addition of exported function, required for TIMESYNC operation,
we need more locking mechanism for driver state, so to avoid confusion
rename existing spinlock variable to its appropriate name.

Testing Done: Tested on DB3.5 platform.

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


# 7b62b61c 20-Apr-2016 Viresh Kumar <viresh.kumar@linaro.org>

greybus: arche-ctrl: Don't expose driver internals to arche-platform driver

We have chosen the *ugly* way of registering two platform drivers from
the module_init() of only one of them, so that we can avoid having two
separate modules for them.

But we should still be doing this in a sane way. There is no need to
expose internals of arche-ctrl to arche-platform, like PM-ops, probe,
resume, id-table, etc. Just expose an init and a exit callback.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 9160b7c7 15-Apr-2016 David Lin <dtwlin@google.com>

greybus: arche-platform: Power-off unipro subsystem upon suspend

Switch off APBs/SVC/Switch in the suspend call notifier. Note that
this is an interim solution to enable fishfooding.

Testing done:
- Passed QA sanity test on EVT1.5
- Suspend current measured at ~70mW

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
[vaibhav.hiremath@linaro.org: Updated commit description]
Tested-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# a7ddda1f 12-Apr-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platfrom: Get rid of 2sec delay in USB3613 configuration

Earlier during boot sequence implementation, we had seen race between
USb3613 and APB boot, and since APB boot time is ~2sec, we delayed
USb3613 configuration for 2sec after APB deassertion of reset.

This obviously won't work in the case of suspend/resume, where we would
like to put APB into OFF state and coldboot in resume.

With the latest FW changes, we do not see any race issue. I have done
regression testing (> 50 iteration of reboot + unipro link up and down)
without any issues.

So lets get rid of the 2sec delay with this patch.

Testing Done: Tested on EVT 1.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: David Lin <dtwlin@google.com>
Reviewed-by: David Lin <dtwlin@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 7fe93014 07-Mar-2016 David Lin <dtwlin@google.com>

greybus: arche-platform: fix incorrect gpio variable type

GPIO number obtained from of_get_named_gpio() should be signed to allow
error handling.

Testing Done:
Built & booted on EVT1.5

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# e915ce48 25-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Disable HUB3613 only in APB poweroff fn

HUB3613 configuration, either disable (Standby mode) or enable (HUB mode)
is related to APB. So it makes perfect sense to put both of them
together in one function.

HUB3613 enable happens only at one place, in hub_conf_delayed_work() fn,
but disable is initiated from multiple places.
Move all calls to usb3613_hub_mode_ctrl(false) to apb_poweroff().

Testing Done: Tested on DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# ff788de0 25-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Make sure APB power cycles on coldboot

On first wake/detect pulse, everything works fine, as APB would be
in poweroff state initially.
But on subsequent wake/detect pulses, where APB is already in active
state, internal function just returns doing nothing, as it finds that
device is already in active state.

So the solution would be to make sure that, whenever execution reaches
to coldboot, make sure we power cycle it. Power off first, before
powering on.

Interrupt handler takes care of ignoring < 30msec pulses, so we should
be safe here to power cycle APB.

Testing Done: Testd on DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# d2320b2d 24-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Disable wake/detect interrupt in poweroff

In poweroff() fn, we are shutting down SVC, so disable interrupt
as well.

Testing Done: Tested on DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Michael Scott <michael.scott@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 0786212d 24-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Set direction of wake/detect gpio in poweroff fn

With support of interrupt based mechanism, gpio is not longer set to
output mode, so gpio_set_value won't work. So use
gpio_direction_output() fn in poweroff(), while setting value on
wake/detect line.

Testing Done: Tested on DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Michael Scott <michael.scott@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 16fe18ca 24-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Assert wake/detect after SVC reset without delay

Since now driver supports interrupt based mechanism to read events
from SVC over wake/detect line, no need to delay wake/detect assertion.
We can assert wake/detect after SVC reset deassertion, so during boot
itself SVC will start sending wake_out pulses.

Testing Done: Tested on DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Michael Scott <michael.scott@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# f760bbfb 24-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Enable interrupt support on wake/detect line

This patch enabled interrupt support on events received over wake/detect
line. The driver follows below state machine,

Default: wake/detect line is high (WD_STATE_IDLE)
On Falling edge:
SVC initiates boot (either cold/standby).
On ES3, > 30msec = coldboot, else standby boot.
Driver moves to WD_STATE_BOOT_INIT
On rising edge (> 30msec):
SVC expects APB to coldboot
Driver wakes irq thread which kicks off APB coldboot
(WD_STATE_COLDBOOT_TRIG)
On rising edge (< 30msec):
Driver ignores it, do nothing.

After coldboot of APB, HUB configuration work is scheduled after 2 sec,
allowing enough time for APB<->SVC/Switch to linkup (in multiple
iterations)

Testing Done: Tested on DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Michael Scott <michael.scott@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 685353c1 24-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Add wake detect state based on functionality

If driver needs to process wake/detect events from SVC, by enabling
interrupt support on wake/detect event, it becomes easier to maintain
state of wake/detect line based on functionality.

Testing Done: Tested on DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Michael Scott <michael.scott@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# db5a3bca 24-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Convert delayed work to do only hub3613 configuration

This is preparation of interrupt handling support, where APB coldboot
and wake/detect handling will be handled as response to wake/detect
interrupt.
Due to slower I2C write operations in HUB configuration, it is important
to separate HUB configuration, and probably delay it after APB is
cold booted.

Note that delayed work will be scheduled from interrupt handler,
in following patches.

To satisfy build (and bisect), remove apb_cold_boot() fn, which will be
added back in the patch where it gets used again.

Testing Done: Tested on DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Michael Scott <michael.scott@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 6743a6fd 24-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Fix exit path in probe fn

If SVC coldboot fails or if of_platform_populate() fn fails,
then state of device needs to be reverted.

Importantly, if of_platform_populate() fails, then poweroff the SVC.

Testing Done: Tested on DB3.5 platform.

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>


# 25847ee7 22-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Avoid doing same thing again in poweroff fn

If user switches from fw_flashing => off mode, then we do not need
to do same things again, for example, clk_disable and wake/detect event,
as while switching to fw_flashing, driver makes sure that device goes
to off state and then brings back in fw_flashing state.

Testing Done: Tested on DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 599159b6 22-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Return immediately if in same state from state change fns

Have a check inside all individual operational state change functions
to check whether device is in same state, and if yes, then return
immediately.

Testing Done: Tested on DB3.5 platform

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# ad4d3f95 12-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# b0324939 12-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# fd60ac58 12-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# 7691fed2 12-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# 2923c58e 12-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# b4c95fca 12-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# e74d04a5 12-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# 5993e2bf 12-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# 49e6e04b 12-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# 758ca99d 12-Feb-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# a3043d9e 27-Jan-2016 Michael Scott <michael.scott@linaro.org>

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>


# 1e83ee33 27-Jan-2016 Michael Scott <michael.scott@linaro.org>

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>


# 9e1aef82 27-Jan-2016 Michael Scott <michael.scott@linaro.org>

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>


# 057aad29 27-Jan-2016 Michael Scott <michael.scott@linaro.org>

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>


# d8b16338 25-Jan-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

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>


# a463fc15 11-Jan-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Add wake/detect support along with handshaking with AP

Add wake_detect support to arche-platform driver which is responsible
for SVC control. This patch also adds code for handshaking between
AP <=> SVC. The sequence is,

1. AP boots
To keep compatibility between DB3 and EVT platform, SVC will be
help in reset and AP driver would release it at appropriate time.
wake/detect pin (WD8A) = Low
reset (SVC/APB1/APB2) = Asserted (as per polarity)
2. AP Driver gets inserted
2.1. AP will deassert reset to SVC (following power on sequence)
2.2. SVC allows 360 milliseconds to elapse after switch boots to work
around bug described in ENG-330.
2.3. AP asserts wake/detect pin (WD8A = HIGH)
3. SVC detects assertion of wake/detect pin, and sends "wake out" signal to AP
4. AP receives "wake out" signal, takes AP Bridges through their power
on reset sequence as defined in the bridge ASIC reference manuals
5. AP takes USB3613 through its power on reset sequence
6. AP should enumerates AP Bridges

Note: ISR has been deliberately removed (not merged) as we are still
not sure how it will be used, in runtime usage context. Driver as such
doesn't do anything for runtime assert-n-deassert of reset to SVC/APB's,
it just simply offloads it to user by exporting required gpio's.
The exported gpio's are required for FW flashing from user space.
When it comes to usersace manipulated control sequence, user has to manage.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 3b858df0 10-Jan-2016 Viresh Kumar <viresh.kumar@linaro.org>

greybus: arche: Remove unwanted headers and rearrange others

This removes few unwanted headers related to irq, interrupt, regulator,
spinlock, etc.

Also arrange the rest in alphabetical order to make it more readable.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# f1f251b5 10-Jan-2016 Viresh Kumar <viresh.kumar@linaro.org>

greybus: arche-platform: propagate errors returned by gpiolib

Propagate errors returned by of_get_named_gpio() instead of sending
-ENODEV.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 140741ec 10-Jan-2016 Viresh Kumar <viresh.kumar@linaro.org>

greybus: arche-platform: svc_reset_gpio can't be invalid in arche_platform_cleanup()

svc_reset_gpio is guaranteed to be valid in arche_platform_cleanup. Drop
the useless check.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 72a8c24b 10-Jan-2016 Viresh Kumar <viresh.kumar@linaro.org>

greybus: arche-platform: Put APB in reset if of_platform_populate() fails

The current implementation around of_platform_populate() is not so
great. On error, we first print an error message, followed by a success
message and finally we return an error.

And over that we don't undo what we did initially.

This patch puts the APB back into reset and create a separate error
path to make things clear.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 8adf71d1 10-Jan-2016 Viresh Kumar <viresh.kumar@linaro.org>

greybus: arche-platform: Export GPIOs after populating APBs

Populating APBs operation can potentially fail and it would be better if
we export the GPIOs towards then end of the routine, so that we don't
need to unexport them on error cases.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 73658f2a 10-Jan-2016 Viresh Kumar <viresh.kumar@linaro.org>

greybus: arche-platform: arche_pdata is guaranteed to be valid

arche_pdata is guaranteed to be valid in arche_platform_remove().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 6da86df3 05-Jan-2016 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche-platform: Export gpio (reset & sys_boot) to user

In order to allow user to flash the firmware to,

SVC:
user need to assert the reset first, set sysboot pin and
deassert reset. And then issue a flashing command.

And APB:
User need to assert the reset first, and then issue flashing
command.

So this patch exports the gpio's to user.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 1e5dd1f8 30-Dec-2015 Greg Kroah-Hartman <gregkh@google.com>

greybus: arche-platform: merge arche-apb-ctrl and arche-platform

No need to have two separate arche platform drivers, that's just crazy,
so merge them both together to be only one kernel module.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>


# bc142bbb 28-Dec-2015 Vaibhav Hiremath <vaibhav.hiremath@linaro.org>

greybus: arche_platform: Remove child's platform device as part of _remove() fn

It seems we need to delete platform_dev of all childs explicitly,
in _remove() fn callback of parent driver.
There were some discussions about having of_platform_unpopulate(),
but it never made it to mainline.

https://lkml.org/lkml/2013/7/19/615

There are some drivers which are removing platform_dev explicitly,
as done in this patch.

Note that, without this, multiple insmod-rmmod won't work, as I see
driver probe gets invoked twice and leads to failure of probe.

Signed-off-by: Vaibhav Hiremath <hiremath_vaibhav@projectara.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>


# 7fa60654 16-Dec-2015 Vaibhav Hiremath <hiremath_vaibhav@projectara.com>

greybus: arche-platform: Rename db3-platform to arche-platform

With multiple platforms getting rolled into ara,
db3 name is confusing. And this driver is applicable
to all arche platforms, so make sense to rename it to
arche-platform.c. Also rename all internal functions
accordingly.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>