Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1371633 > unrolled thread
| Started by | Roger Quadros <rogerq@ti.com> |
|---|---|
| First post | 2016-04-05 16:10 +0200 |
| Last post | 2016-04-05 16:20 +0200 |
| Articles | 20 on this page of 34 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH v6 00/12] USB OTG/dual-role framework Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
[PATCH v6 10/12] usb: doc: dt-binding: Add otg-controller property Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
[PATCH v6 09/12] usb: gadget: udc: adapt to OTG core Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
[PATCH v6 12/12] usb: host: xhci-plat: Add otg device to platform data Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
RE: [PATCH v6 12/12] usb: host: xhci-plat: Add otg device to platform data Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> - 2016-04-06 05:30 +0200
Re: [PATCH v6 12/12] usb: host: xhci-plat: Add otg device to platform data Roger Quadros <rogerq@ti.com> - 2016-04-06 08:40 +0200
[PATCH v6 06/12] usb: otg: get rid of CONFIG_USB_OTG_FSM in favour of CONFIG_USB_OTG Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
[PATCH v6 07/12] usb: otg: add OTG/dual-role core Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> - 2016-04-07 11:00 +0200
Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Roger Quadros <rogerq@ti.com> - 2016-04-07 13:50 +0200
RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> - 2016-04-08 13:30 +0200
Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Roger Quadros <rogerq@ti.com> - 2016-04-11 13:00 +0200
RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> - 2016-04-14 10:40 +0200
Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Roger Quadros <rogerq@ti.com> - 2016-04-14 13:10 +0200
RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> - 2016-04-14 13:20 +0200
Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Roger Quadros <rogerq@ti.com> - 2016-04-14 13:40 +0200
RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> - 2016-04-15 12:00 +0200
Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Roger Quadros <rogerq@ti.com> - 2016-04-15 13:00 +0200
RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> - 2016-04-15 12:10 +0200
Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Peter Chen <hzpeterchen@gmail.com> - 2016-04-15 11:40 +0200
Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core Roger Quadros <rogerq@ti.com> - 2016-04-15 13:10 +0200
[PATCH v6 05/12] usb: gadget.h: Add OTG to gadget interface Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
[PATCH v6 02/12] usb: hcd.h: Add OTG to HCD interface Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
[PATCH v6 04/12] usb: otg-fsm: move host controller operations into usb_otg->hcd_ops Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
[PATCH v6 11/12] usb: core: hub: Notify OTG fsm when A device sets b_hnp_enable Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
[PATCH v6 01/12] usb: hcd: Initialize hcd->flags to 0 Roger Quadros <rogerq@ti.com> - 2016-04-05 16:10 +0200
Re: [PATCH v6 01/12] usb: hcd: Initialize hcd->flags to 0 Felipe Balbi <balbi@kernel.org> - 2016-04-06 08:20 +0200
Re: [PATCH v6 01/12] usb: hcd: Initialize hcd->flags to 0 Roger Quadros <rogerq@ti.com> - 2016-04-06 08:40 +0200
Re: [PATCH v6 01/12] usb: hcd: Initialize hcd->flags to 0 Peter Chen <hzpeterchen@gmail.com> - 2016-04-07 11:50 +0200
Re: [PATCH v6 01/12] usb: hcd: Initialize hcd->flags to 0 Roger Quadros <rogerq@ti.com> - 2016-04-07 12:50 +0200
Re: [PATCH v6 01/12] usb: hcd: Initialize hcd->flags to 0 Peter Chen <hzpeterchen@gmail.com> - 2016-04-08 03:10 +0200
Re: [PATCH v6 01/12] usb: hcd: Initialize hcd->flags to 0 Roger Quadros <rogerq@ti.com> - 2016-04-08 09:20 +0200
Re: [PATCH v6 01/12] usb: hcd: Initialize hcd->flags to 0 Peter Chen <hzpeterchen@gmail.com> - 2016-04-08 10:00 +0200
[PATCH v6 08/12] usb: hcd: Adapt to OTG core Roger Quadros <rogerq@ti.com> - 2016-04-05 16:20 +0200
Page 1 of 2 [1] 2 Next page →
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-05 16:10 +0200 |
| Subject | [PATCH v6 00/12] USB OTG/dual-role framework |
| Message-ID | <rkzQ5-4UX-1@gated-at.bofh.it> |
Hi,
This series centralizes OTG/Dual-role functionality in the kernel.
As of now I've got Dual-role functionality working pretty reliably on
dra7-evm and am437x-gp-evm.
DWC3 controller and platform related patches will be sent separately.
Series is based on v4.6-rc1 and depends on [1]
[1] - OTG fsm cleanup - https://lkml.org/lkml/2016/3/30/186
Why?:
----
Currently there is no central location where OTG/dual-role functionality is
implemented in the Linux USB stack and every USB controller driver is
doing their own thing for OTG/dual-role. We can benefit from code-reuse
and simplicity by adding the OTG/dual-role core driver.
Newer OTG cores support standard host interface (e.g. xHCI) so
host and gadget functionality are no longer closely knit like older
cores. There needs to be a way to co-ordinate the operation of the
host and gadget controllers in dual-role mode. i.e. to stop and start them
from a central location. This central location should be the
USB OTG/dual-role core.
Host and gadget controllers might be sharing resources and can't
be always running. One has to be stopped for the other to run.
This couldn't be done till now but can be done from the OTG core.
What?:
-----
The OTG/dual-role core consists of a set of APIs that allow
registration of OTG controller device and OTG capable host and gadget
controllers.
- The OTG controller driver can provide the OTG capabilities and the
Finite State Machine work function via 'struct usb_otg_config'
at the time of registration i.e. usb_otg_register();
struct usb_otg *usb_otg_register(struct device *dev,
struct usb_otg_config *config);
int usb_otg_unregister(struct device *dev);
/**
* struct usb_otg_config - otg controller configuration
* @caps: otg capabilities of the controller
* @ops: otg fsm operations
* @otg_work: optional custom otg state machine work function
*/
struct usb_otg_config {
struct usb_otg_caps *otg_caps;
struct otg_fsm_ops *fsm_ops;
void (*otg_work)(struct work_struct *work);
};
The dual-role state machine is built-into the OTG core so nothing
special needs to be provided if only dual-role functionality is desired.
The low level OTG controller driver ops are povided via
'struct otg_fsm_ops *fsm_ops' in the 'struct usb_otg_config'.
After registration, the OTG core waits for host, gadget controller
and the gadget function driver to be registered. Once all resources are
available it instantiates the Finite State Machine (FSM).
The host/gadget controllers are started/stopped according to the FSM.
- Host and gadget controllers that are a part of OTG/dual-role port must
use the OTG core provided APIs to add/remove the host/gadget.
i.e. hosts must use usb_otg_add_hcd() usb_otg_remove_hcd(),,
gadgets must use usb_otg_add_gadget_udc() usb_del_gadget_udc().
This ensures that the host and gadget controllers are not started till
the state machine is ready and the right bus conditions are met.
It also allows the host and gadget controllers to provide the OTG
controller device to link them together. For Device tree boots
the related OTG controller is automatically picked up via the
'otg-controller' property in the Host/Gadget controller nodes.
int usb_otg_add_hcd(struct usb_hcd *hcd,
unsigned int irqnum, unsigned long irqflags,
struct device *otg_dev);
void usb_otg_remove_hcd(struct usb_hcd *hcd);
int usb_otg_add_gadget_udc(struct device *parent,
struct usb_gadget *gadget,
struct device *otg_dev);
usb_del_gadget_udc() must be used for removal.
- During the lifetime of the FSM, the OTG controller driver can provide
inputs event changes using usb_otg_sync_inputs(). The OTG core will
then schedule the FSM work function (or internal dual-role state machine)
to update the FSM state. The FSM then calls the OTG controller
operations (fsm_ops) as necessary.
void usb_otg_sync_inputs(struct usb_otg *otg);
- The following 2 functions are provided as helpers for use by the
OTG controller driver to start/stop the host/gadget controllers.
int usb_otg_start_host(struct usb_otg *otg, int on);
int usb_otg_start_gadget(struct usb_otg *otg, int on);
- The following function is provided for use by the USB host stack
to sync OTG related events to the OTG state machine.
e.g. change in host_bus->b_hnp_enable, gadget->b_hnp_enable
int usb_otg_kick_fsm(struct device *otg_device);
Changelog:
---------
v6:
- added otg specific APIs for host/gadget registration. behaviour of
original host/gadget API remains unchanged. Platform devices can now
pass the otg device explicitly while registering host/gadget.
- moved hcd specific operations from struct otg_fsm to struct hcd_ops.
- made struct usb_otg mandatory for all otg related APIs.
- allow otg controller to provide it's own otg_work function so that
it can implement it's own state machine.
- removed otg fsm and timers from usb-otg.c. Only dual-role state machine
is implemented.
- vbus is controlled in the dual-role state machine.
- PM runtime is used around drd_statemachine().
- added otg_dev to xhci platform data to allow platform code to specify
the otg controller tied to the xhci host controller.
v5: Internal version. Not sent to mailing list
v4:
- Added DT support for tying otg-controller to host and gadget
controllers. For DT we no longer have the constraint that
OTG controller needs to be parent of host and gadget. They can be
tied together using the "otg-controller" property.
- Relax the requirement for DT case that otg controller must register
before host/gadget. We maintain a wait list of host/gadget devices
waiting on the otg controller.
- Use a single struct usb_otg for otg data.
- Don't override host/gadget start/stop APIs. Let the controller
drivers do what they want as they know best. Helper API is provided
for controller start/stop that controller driver can use.
- Introduce struct usb_otg_config to pass the otg capabilities,
otg ops and otg timer timeouts during otg controller registration.
- rebased on Greg's usb.git/usb-next
v3:
- all otg related definations now in otg.h
- single kernel config USB_OTG to enable OTG core and FSM.
- resolved symbol dependency issues.
- use dev_vdbg instead of VDBG() in usb-otg-fsm.c
- rebased on v4.2-rc1
v2:
- Use add/remove_hcd() instead of start/stop_hcd() to enable/disable
the host controller
- added dual-role-device (DRD) state machine which is a much simpler
mode of operation when compared to OTG. Here we don't support fancy
OTG features like HNP, SRP, on the fly role-swap. The mode of operation
is determined based on ID pin (cable type) and the role doesn't change
till the cable type changes.
--
cheers,
-roger
Roger Quadros (12):
usb: hcd: Initialize hcd->flags to 0
usb: hcd.h: Add OTG to HCD interface
usb: otg-fsm: use usb_otg wherever possible
usb: otg-fsm: move host controller operations into usb_otg->hcd_ops
usb: gadget.h: Add OTG to gadget interface
usb: otg: get rid of CONFIG_USB_OTG_FSM in favour of CONFIG_USB_OTG
usb: otg: add OTG/dual-role core
usb: hcd: Adapt to OTG core
usb: gadget: udc: adapt to OTG core
usb: doc: dt-binding: Add otg-controller property
usb: core: hub: Notify OTG fsm when A device sets b_hnp_enable
usb: host: xhci-plat: Add otg device to platform data
Documentation/devicetree/bindings/usb/generic.txt | 3 +
Documentation/usb/chipidea.txt | 2 +-
drivers/usb/Makefile | 1 +
drivers/usb/chipidea/Makefile | 2 +-
drivers/usb/chipidea/ci.h | 3 +-
drivers/usb/chipidea/core.c | 12 +-
drivers/usb/chipidea/debug.c | 2 +-
drivers/usb/chipidea/otg_fsm.c | 178 ++--
drivers/usb/chipidea/otg_fsm.h | 2 +-
drivers/usb/chipidea/udc.c | 17 +-
drivers/usb/common/Makefile | 3 +-
drivers/usb/common/usb-otg-fsm.c | 191 ++--
drivers/usb/common/usb-otg.c | 1058 ++++++++++++++++++++
.../usb/{chipidea/otg_fsm.h => common/usb-otg.h} | 61 +-
drivers/usb/core/Kconfig | 10 +-
drivers/usb/core/hcd.c | 72 ++
drivers/usb/core/hub.c | 17 +-
drivers/usb/gadget/udc/udc-core.c | 166 ++-
drivers/usb/host/xhci-plat.c | 35 +-
drivers/usb/phy/Kconfig | 2 +-
drivers/usb/phy/phy-fsl-usb.c | 150 +--
drivers/usb/phy/phy-fsl-usb.h | 3 +-
include/linux/usb/gadget.h | 20 +
include/linux/usb/hcd.h | 29 +
include/linux/usb/otg-fsm.h | 139 +--
include/linux/usb/otg.h | 259 ++++-
include/linux/usb/xhci_pdriver.h | 3 +
27 files changed, 1973 insertions(+), 467 deletions(-)
create mode 100644 drivers/usb/common/usb-otg.c
copy drivers/usb/{chipidea/otg_fsm.h => common/usb-otg.h} (63%)
--
2.5.0
[toc] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-05 16:10 +0200 |
| Subject | [PATCH v6 10/12] usb: doc: dt-binding: Add otg-controller property |
| Message-ID | <rkzQ6-4UX-7@gated-at.bofh.it> |
| In reply to | #1371633 |
The otg-controller property is used to link the host/gadget controllers to the otg controller. otg-controller property must contain the phandle of the otg controller. The otg core uses this property to tie the host/gadget controllres to the correct otg controller. Signed-off-by: Roger Quadros <rogerq@ti.com> --- Documentation/devicetree/bindings/usb/generic.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt index bba8257..f6866c1 100644 --- a/Documentation/devicetree/bindings/usb/generic.txt +++ b/Documentation/devicetree/bindings/usb/generic.txt @@ -24,6 +24,9 @@ Optional properties: optional for OTG device. - adp-disable: tells OTG controllers we want to disable OTG ADP, ADP is optional for OTG device. + - otg-controller: phandle to otg controller. Host or gadget controllers can + contain this property to link it to a particular OTG + controller. This is an attribute to a USB controller such as: -- 2.5.0
[toc] | [prev] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-05 16:10 +0200 |
| Subject | [PATCH v6 09/12] usb: gadget: udc: adapt to OTG core |
| Message-ID | <rkzQ6-4UX-19@gated-at.bofh.it> |
| In reply to | #1371633 |
The OTG state machine needs a mechanism to start and
stop the gadget controller. Add usb_gadget_start()
and usb_gadget_stop().
Introduce usb_otg_add_gadget_udc() to allow controller drivers
to register a gadget controller that is part of an OTG instance.
Register with OTG core when gadget function driver
is available and unregister when function driver is unbound.
We need to unlock the usb_lock mutexbefore calling
usb_otg_register_gadget() in udc_bind_to_driver() and
usb_gadget_remove_driver() else it will cause a circular
locking dependency.
Ignore softconnect sysfs control when we're in OTG
mode as OTG FSM takes care of gadget softconnect using
the b_bus_req mechanism.
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
drivers/usb/gadget/udc/udc-core.c | 166 +++++++++++++++++++++++++++++++++++---
include/linux/usb/gadget.h | 4 +
2 files changed, 161 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c
index 4151597..9b9702f 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,10 @@
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
#include <linux/usb.h>
+#include <linux/usb/otg.h>
+
+#include <linux/of.h>
+#include <linux/of_platform.h>
/**
* struct usb_udc - describes one usb device controller
@@ -304,6 +308,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_udc_reset);
*/
static inline int usb_gadget_udc_start(struct usb_udc *udc)
{
+ dev_dbg(&udc->dev, "%s\n", __func__);
return udc->gadget->ops->udc_start(udc->gadget, udc->driver);
}
@@ -321,10 +326,81 @@ static inline int usb_gadget_udc_start(struct usb_udc *udc)
*/
static inline void usb_gadget_udc_stop(struct usb_udc *udc)
{
+ dev_dbg(&udc->dev, "%s\n", __func__);
udc->gadget->ops->udc_stop(udc->gadget);
}
/**
+ * usb_gadget_start - start the usb gadget controller and connect to bus
+ * @gadget: the gadget device to start
+ *
+ * This is external API for use by OTG core.
+ *
+ * Start the usb device controller and connect to bus (enable pull).
+ */
+static int usb_gadget_start(struct usb_gadget *gadget)
+{
+ int ret;
+ struct usb_udc *udc = NULL;
+
+ dev_dbg(&gadget->dev, "%s\n", __func__);
+ mutex_lock(&udc_lock);
+ list_for_each_entry(udc, &udc_list, list)
+ if (udc->gadget == gadget)
+ goto found;
+
+ dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+ __func__);
+ mutex_unlock(&udc_lock);
+ return -EINVAL;
+
+found:
+ ret = usb_gadget_udc_start(udc);
+ if (ret)
+ dev_err(&udc->dev, "USB Device Controller didn't start: %d\n",
+ ret);
+ else
+ usb_udc_connect_control(udc);
+
+ mutex_unlock(&udc_lock);
+
+ return ret;
+}
+
+/**
+ * usb_gadget_stop - disconnect from bus and stop the usb gadget
+ * @gadget: The gadget device we want to stop
+ *
+ * This is external API for use by OTG core.
+ *
+ * Disconnect from the bus (disable pull) and stop the
+ * gadget controller.
+ */
+static int usb_gadget_stop(struct usb_gadget *gadget)
+{
+ struct usb_udc *udc = NULL;
+
+ dev_dbg(&gadget->dev, "%s\n", __func__);
+ mutex_lock(&udc_lock);
+ list_for_each_entry(udc, &udc_list, list)
+ if (udc->gadget == gadget)
+ goto found;
+
+ dev_err(gadget->dev.parent, "%s: gadget not registered.\n",
+ __func__);
+ mutex_unlock(&udc_lock);
+ return -EINVAL;
+
+found:
+ usb_gadget_disconnect(udc->gadget);
+ udc->driver->disconnect(udc->gadget);
+ usb_gadget_udc_stop(udc);
+ mutex_unlock(&udc_lock);
+
+ return 0;
+}
+
+/**
* usb_udc_release - release the usb_udc struct
* @dev: the dev member within usb_udc
*
@@ -486,6 +562,48 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
}
EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
+/**
+ * usb_otg_add_gadget_udc - adds a new gadget to the udc class driver list
+ * @parent: the parent device to this udc. Usually the controller
+ * driver's device.
+ * @gadget: the gadget to be added to the list
+ * @otg_dev: the OTG controller device
+ *
+ * If otg_dev is NULL then device tree node is checked
+ * for OTG controller via the otg-controller property.
+ * Returns zero on success, negative errno otherwise.
+ */
+int usb_otg_add_gadget_udc(struct device *parent, struct usb_gadget *gadget,
+ struct device *otg_dev)
+{
+ if (!otg_dev) {
+ struct device_node *np;
+ struct platform_device *pdev;
+
+ np = of_parse_phandle(parent->of_node, "otg-controller", 0);
+ if (!np) {
+ dev_err(parent,
+ "otg_dev is NULL or no otg-controller property in DT\n");
+ return -EINVAL;
+ }
+
+ pdev = of_find_device_by_node(np);
+ of_node_put(np);
+ if (!pdev) {
+ dev_err(parent, "couldn't get otg-controller device\n");
+ return -ENODEV;
+ }
+
+ gadget->otg_dev = &pdev->dev;
+ } else {
+ gadget->otg_dev = otg_dev;
+ }
+
+ return usb_add_gadget_udc_release(parent, gadget, NULL);
+}
+EXPORT_SYMBOL_GPL(usb_otg_add_gadget_udc);
+
+/* udc_lock must be held */
static void usb_gadget_remove_driver(struct usb_udc *udc)
{
dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n",
@@ -493,10 +611,18 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
- usb_gadget_disconnect(udc->gadget);
- udc->driver->disconnect(udc->gadget);
+ /* If OTG, the otg core ensures UDC is stopped on unregister */
+ if (udc->gadget->otg_dev) {
+ mutex_unlock(&udc_lock);
+ usb_otg_unregister_gadget(udc->gadget);
+ mutex_lock(&udc_lock);
+ } else {
+ usb_gadget_disconnect(udc->gadget);
+ udc->driver->disconnect(udc->gadget);
+ usb_gadget_udc_stop(udc);
+ }
+
udc->driver->unbind(udc->gadget);
- usb_gadget_udc_stop(udc);
udc->driver = NULL;
udc->dev.driver = NULL;
@@ -530,6 +656,8 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
}
mutex_unlock(&udc_lock);
+ mutex_unlock(&udc_lock);
+
kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
flush_work(&gadget->work);
device_unregister(&udc->dev);
@@ -539,6 +667,12 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
/* ------------------------------------------------------------------------- */
+struct otg_gadget_ops otg_gadget_intf = {
+ .start = usb_gadget_start,
+ .stop = usb_gadget_stop,
+};
+
+/* udc_lock must be held */
static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
{
int ret;
@@ -553,12 +687,20 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
ret = driver->bind(udc->gadget, driver);
if (ret)
goto err1;
- ret = usb_gadget_udc_start(udc);
- if (ret) {
- driver->unbind(udc->gadget);
- goto err1;
+
+ /* If OTG, the otg core starts the UDC when needed */
+ if (udc->gadget->otg_dev) {
+ mutex_unlock(&udc_lock);
+ usb_otg_register_gadget(udc->gadget, &otg_gadget_intf);
+ mutex_lock(&udc_lock);
+ } else {
+ ret = usb_gadget_udc_start(udc);
+ if (ret) {
+ driver->unbind(udc->gadget);
+ goto err1;
+ }
+ usb_udc_connect_control(udc);
}
- usb_udc_connect_control(udc);
kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
return 0;
@@ -660,9 +802,15 @@ static ssize_t usb_udc_softconn_store(struct device *dev,
return -EOPNOTSUPP;
}
+ /* In OTG mode we don't support softconnect, but b_bus_req */
+ if (udc->gadget->otg_dev) {
+ dev_err(dev, "soft-connect not supported in OTG mode\n");
+ return -EOPNOTSUPP;
+ }
+
if (sysfs_streq(buf, "connect")) {
usb_gadget_udc_start(udc);
- usb_gadget_connect(udc->gadget);
+ usb_udc_connect_control(udc);
} else if (sysfs_streq(buf, "disconnect")) {
usb_gadget_disconnect(udc->gadget);
udc->driver->disconnect(udc->gadget);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 1878ae1..061f09e4 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -1160,6 +1160,10 @@ extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget);
extern void usb_del_gadget_udc(struct usb_gadget *gadget);
extern char *usb_get_gadget_udc_name(void);
+extern int usb_otg_add_gadget_udc(struct device *parent,
+ struct usb_gadget *gadget,
+ struct device *otg_dev);
+
/*-------------------------------------------------------------------------*/
/* utility to simplify dealing with string descriptors */
--
2.5.0
[toc] | [prev] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-05 16:10 +0200 |
| Subject | [PATCH v6 12/12] usb: host: xhci-plat: Add otg device to platform data |
| Message-ID | <rkzQ7-4UX-39@gated-at.bofh.it> |
| In reply to | #1371633 |
Host controllers that are part of an OTG/dual-role instance
need to somehow pass the OTG controller device information
to the HCD core.
We use platform data to pass the OTG controller device.
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
drivers/usb/host/xhci-plat.c | 35 ++++++++++++++++++++++++++++-------
include/linux/usb/xhci_pdriver.h | 3 +++
2 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 5c15e9b..3d0f597 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -230,11 +230,20 @@ static int xhci_plat_probe(struct platform_device *pdev)
goto put_usb3_hcd;
}
- ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+ if (pdata->otg_dev)
+ ret = usb_otg_add_hcd(hcd, irq, IRQF_SHARED, pdata->otg_dev);
+ else
+ ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+
if (ret)
goto disable_usb_phy;
- ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
+ if (pdata->otg_dev)
+ ret = usb_otg_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED,
+ pdata->otg_dev);
+ else
+ ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
+
if (ret)
goto dealloc_usb2_hcd;
@@ -242,7 +251,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
dealloc_usb2_hcd:
- usb_remove_hcd(hcd);
+ if (pdata->otg_dev)
+ usb_otg_remove_hcd(hcd);
+ else
+ usb_remove_hcd(hcd);
disable_usb_phy:
usb_phy_shutdown(hcd->usb_phy);
@@ -260,16 +272,25 @@ put_hcd:
return ret;
}
-static int xhci_plat_remove(struct platform_device *dev)
+static int xhci_plat_remove(struct platform_device *pdev)
{
- struct usb_hcd *hcd = platform_get_drvdata(dev);
+ struct usb_hcd *hcd = platform_get_drvdata(pdev);
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct clk *clk = xhci->clk;
+ struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
+
+ if (pdata->otg_dev)
+ usb_otg_remove_hcd(xhci->shared_hcd);
+ else
+ usb_remove_hcd(xhci->shared_hcd);
- usb_remove_hcd(xhci->shared_hcd);
usb_phy_shutdown(hcd->usb_phy);
- usb_remove_hcd(hcd);
+ if (pdata->otg_dev)
+ usb_otg_remove_hcd(hcd);
+ else
+ usb_remove_hcd(hcd);
+
usb_put_hcd(xhci->shared_hcd);
if (!IS_ERR(clk))
diff --git a/include/linux/usb/xhci_pdriver.h b/include/linux/usb/xhci_pdriver.h
index 376654b..5c68b83 100644
--- a/include/linux/usb/xhci_pdriver.h
+++ b/include/linux/usb/xhci_pdriver.h
@@ -18,10 +18,13 @@
*
* @usb3_lpm_capable: determines if this xhci platform supports USB3
* LPM capability
+ * @otg_dev: OTG controller device. Only requied if part of
+ * OTG/dual-role.
*
*/
struct usb_xhci_pdata {
unsigned usb3_lpm_capable:1;
+ struct device *otg_dev;
};
#endif /* __USB_CORE_XHCI_PDRIVER_H */
--
2.5.0
[toc] | [prev] | [next] | [standalone]
| From | Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
|---|---|
| Date | 2016-04-06 05:30 +0200 |
| Subject | RE: [PATCH v6 12/12] usb: host: xhci-plat: Add otg device to platform data |
| Message-ID | <rkMkh-63B-3@gated-at.bofh.it> |
| In reply to | #1371643 |
Hi,
> Sent: Tuesday, April 05, 2016 11:05 PM
>
> Host controllers that are part of an OTG/dual-role instance
> need to somehow pass the OTG controller device information
> to the HCD core.
>
> We use platform data to pass the OTG controller device.
>
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
> drivers/usb/host/xhci-plat.c | 35 ++++++++++++++++++++++++++++-------
> include/linux/usb/xhci_pdriver.h | 3 +++
> 2 files changed, 31 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index 5c15e9b..3d0f597 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -230,11 +230,20 @@ static int xhci_plat_probe(struct platform_device *pdev)
> goto put_usb3_hcd;
> }
>
> - ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
> + if (pdata->otg_dev)
I think that this should be changed like below:
if (pdata && pdata->otg_dev)
Otherwise, panic happened on my environment (arm64 / r8a7795 board) because the pdata was NULL.
> + ret = usb_otg_add_hcd(hcd, irq, IRQF_SHARED, pdata->otg_dev);
> + else
> + ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
> +
> if (ret)
> goto disable_usb_phy;
>
> - ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
> + if (pdata->otg_dev)
Ditto.
> + ret = usb_otg_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED,
> + pdata->otg_dev);
> + else
> + ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
> +
> if (ret)
> goto dealloc_usb2_hcd;
>
> @@ -242,7 +251,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
>
>
> dealloc_usb2_hcd:
> - usb_remove_hcd(hcd);
> + if (pdata->otg_dev)
Ditto.
> + usb_otg_remove_hcd(hcd);
> + else
> + usb_remove_hcd(hcd);
>
> disable_usb_phy:
> usb_phy_shutdown(hcd->usb_phy);
> @@ -260,16 +272,25 @@ put_hcd:
> return ret;
> }
>
> -static int xhci_plat_remove(struct platform_device *dev)
> +static int xhci_plat_remove(struct platform_device *pdev)
> {
> - struct usb_hcd *hcd = platform_get_drvdata(dev);
> + struct usb_hcd *hcd = platform_get_drvdata(pdev);
> struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> struct clk *clk = xhci->clk;
> + struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
> +
> + if (pdata->otg_dev)
Ditto.
> + usb_otg_remove_hcd(xhci->shared_hcd);
> + else
> + usb_remove_hcd(xhci->shared_hcd);
>
> - usb_remove_hcd(xhci->shared_hcd);
> usb_phy_shutdown(hcd->usb_phy);
>
> - usb_remove_hcd(hcd);
> + if (pdata->otg_dev)
Ditto.
Best regards,
Yoshihiro Shimoda
> + usb_otg_remove_hcd(hcd);
> + else
> + usb_remove_hcd(hcd);
> +
> usb_put_hcd(xhci->shared_hcd);
>
> if (!IS_ERR(clk))
> diff --git a/include/linux/usb/xhci_pdriver.h b/include/linux/usb/xhci_pdriver.h
> index 376654b..5c68b83 100644
> --- a/include/linux/usb/xhci_pdriver.h
> +++ b/include/linux/usb/xhci_pdriver.h
> @@ -18,10 +18,13 @@
> *
> * @usb3_lpm_capable: determines if this xhci platform supports USB3
> * LPM capability
> + * @otg_dev: OTG controller device. Only requied if part of
> + * OTG/dual-role.
> *
> */
> struct usb_xhci_pdata {
> unsigned usb3_lpm_capable:1;
> + struct device *otg_dev;
> };
>
> #endif /* __USB_CORE_XHCI_PDRIVER_H */
> --
> 2.5.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[toc] | [prev] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-06 08:40 +0200 |
| Subject | Re: [PATCH v6 12/12] usb: host: xhci-plat: Add otg device to platform data |
| Message-ID | <rkPia-8gZ-11@gated-at.bofh.it> |
| In reply to | #1372167 |
Hi,
On 06/04/16 06:23, Yoshihiro Shimoda wrote:
> Hi,
>
>> Sent: Tuesday, April 05, 2016 11:05 PM
>>
>> Host controllers that are part of an OTG/dual-role instance
>> need to somehow pass the OTG controller device information
>> to the HCD core.
>>
>> We use platform data to pass the OTG controller device.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>> drivers/usb/host/xhci-plat.c | 35 ++++++++++++++++++++++++++++-------
>> include/linux/usb/xhci_pdriver.h | 3 +++
>> 2 files changed, 31 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
>> index 5c15e9b..3d0f597 100644
>> --- a/drivers/usb/host/xhci-plat.c
>> +++ b/drivers/usb/host/xhci-plat.c
>> @@ -230,11 +230,20 @@ static int xhci_plat_probe(struct platform_device *pdev)
>> goto put_usb3_hcd;
>> }
>>
>> - ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
>> + if (pdata->otg_dev)
>
> I think that this should be changed like below:
> if (pdata && pdata->otg_dev)
Indeed, I'll fix this and the remaining occurrences. Thanks.
cheers,
-roger
>
> Otherwise, panic happened on my environment (arm64 / r8a7795 board) because the pdata was NULL.
>
>> + ret = usb_otg_add_hcd(hcd, irq, IRQF_SHARED, pdata->otg_dev);
>> + else
>> + ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
>> +
>> if (ret)
>> goto disable_usb_phy;
>>
>> - ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
>> + if (pdata->otg_dev)
>
> Ditto.
>
>> + ret = usb_otg_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED,
>> + pdata->otg_dev);
>> + else
>> + ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
>> +
>> if (ret)
>> goto dealloc_usb2_hcd;
>>
>> @@ -242,7 +251,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
>>
>>
>> dealloc_usb2_hcd:
>> - usb_remove_hcd(hcd);
>> + if (pdata->otg_dev)
>
> Ditto.
>
>> + usb_otg_remove_hcd(hcd);
>> + else
>> + usb_remove_hcd(hcd);
>>
>> disable_usb_phy:
>> usb_phy_shutdown(hcd->usb_phy);
>> @@ -260,16 +272,25 @@ put_hcd:
>> return ret;
>> }
>>
>> -static int xhci_plat_remove(struct platform_device *dev)
>> +static int xhci_plat_remove(struct platform_device *pdev)
>> {
>> - struct usb_hcd *hcd = platform_get_drvdata(dev);
>> + struct usb_hcd *hcd = platform_get_drvdata(pdev);
>> struct xhci_hcd *xhci = hcd_to_xhci(hcd);
>> struct clk *clk = xhci->clk;
>> + struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
>> +
>> + if (pdata->otg_dev)
>
> Ditto.
>
>> + usb_otg_remove_hcd(xhci->shared_hcd);
>> + else
>> + usb_remove_hcd(xhci->shared_hcd);
>>
>> - usb_remove_hcd(xhci->shared_hcd);
>> usb_phy_shutdown(hcd->usb_phy);
>>
>> - usb_remove_hcd(hcd);
>> + if (pdata->otg_dev)
>
> Ditto.
>
> Best regards,
> Yoshihiro Shimoda
>
>> + usb_otg_remove_hcd(hcd);
>> + else
>> + usb_remove_hcd(hcd);
>> +
>> usb_put_hcd(xhci->shared_hcd);
>>
>> if (!IS_ERR(clk))
>> diff --git a/include/linux/usb/xhci_pdriver.h b/include/linux/usb/xhci_pdriver.h
>> index 376654b..5c68b83 100644
>> --- a/include/linux/usb/xhci_pdriver.h
>> +++ b/include/linux/usb/xhci_pdriver.h
>> @@ -18,10 +18,13 @@
>> *
>> * @usb3_lpm_capable: determines if this xhci platform supports USB3
>> * LPM capability
>> + * @otg_dev: OTG controller device. Only requied if part of
>> + * OTG/dual-role.
>> *
>> */
>> struct usb_xhci_pdata {
>> unsigned usb3_lpm_capable:1;
>> + struct device *otg_dev;
>> };
>>
>> #endif /* __USB_CORE_XHCI_PDRIVER_H */
>> --
>> 2.5.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
[toc] | [prev] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-05 16:10 +0200 |
| Subject | [PATCH v6 06/12] usb: otg: get rid of CONFIG_USB_OTG_FSM in favour of CONFIG_USB_OTG |
| Message-ID | <rkzQ7-4UX-49@gated-at.bofh.it> |
| In reply to | #1371633 |
Let's use CONFIG_USB_OTG as a single config option to enable
USB OTG and the OTG FSM. This makes things a lot less confusing.
Update all users of CONFIG_USB_OTG_FSM to CONFIG_USB_OTG.
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
Documentation/usb/chipidea.txt | 2 +-
drivers/usb/Makefile | 1 +
drivers/usb/chipidea/Makefile | 2 +-
drivers/usb/chipidea/ci.h | 2 +-
drivers/usb/chipidea/otg_fsm.h | 2 +-
drivers/usb/common/Makefile | 3 ++-
drivers/usb/core/Kconfig | 8 --------
drivers/usb/phy/Kconfig | 2 +-
8 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/Documentation/usb/chipidea.txt b/Documentation/usb/chipidea.txt
index 678741b..3b1f263 100644
--- a/Documentation/usb/chipidea.txt
+++ b/Documentation/usb/chipidea.txt
@@ -5,7 +5,7 @@ with 2 Freescale i.MX6Q sabre SD boards.
1.1 How to enable OTG FSM in menuconfig
---------------------------------------
-Select CONFIG_USB_OTG_FSM, rebuild kernel Image and modules.
+Select CONFIG_USB_OTG, rebuild kernel Image and modules.
If you want to check some internal variables for otg fsm,
mount debugfs, there are 2 files which can show otg fsm
variables and some controller registers value:
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index dca7856..16a5b55 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -59,5 +59,6 @@ obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs/
obj-$(CONFIG_USB_GADGET) += gadget/
obj-$(CONFIG_USB_COMMON) += common/
+obj-$(CONFIG_USB_OTG) += common/
obj-$(CONFIG_USBIP_CORE) += usbip/
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index 518e445..45aa24d 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -3,7 +3,7 @@ obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc.o
ci_hdrc-y := core.o otg.o debug.o
ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC) += udc.o
ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST) += host.o
-ci_hdrc-$(CONFIG_USB_OTG_FSM) += otg_fsm.o
+ci_hdrc-$(CONFIG_USB_OTG) += otg_fsm.o
# Glue/Bridge layers go here
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index c523975..1a32b8c 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -406,7 +406,7 @@ static inline u32 hw_test_and_write(struct ci_hdrc *ci, enum ci_hw_regs reg,
*/
static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci)
{
-#ifdef CONFIG_USB_OTG_FSM
+#ifdef CONFIG_USB_OTG
struct usb_otg_caps *otg_caps = &ci->platdata->ci_otg_caps;
return ci->is_otg && ci->roles[CI_ROLE_HOST] &&
diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h
index 6366fe3..2d451bb 100644
--- a/drivers/usb/chipidea/otg_fsm.h
+++ b/drivers/usb/chipidea/otg_fsm.h
@@ -64,7 +64,7 @@
#define TB_AIDL_BDIS (20) /* 4ms ~ 150ms, section 5.2.1 */
-#if IS_ENABLED(CONFIG_USB_OTG_FSM)
+#if IS_ENABLED(CONFIG_USB_OTG)
int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci);
int ci_otg_fsm_work(struct ci_hdrc *ci);
diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index 6bbb3ec..f8f2c88 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -6,5 +6,6 @@ obj-$(CONFIG_USB_COMMON) += usb-common.o
usb-common-y += common.o
usb-common-$(CONFIG_USB_LED_TRIG) += led.o
-obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
obj-$(CONFIG_USB_ULPI_BUS) += ulpi.o
+usbotg-y := usb-otg-fsm.o
+obj-$(CONFIG_USB_OTG) += usbotg.o
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index dd28010..ae228d0 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -75,14 +75,6 @@ config USB_OTG_BLACKLIST_HUB
and software costs by not supporting external hubs. So
are "Embedded Hosts" that don't offer OTG support.
-config USB_OTG_FSM
- tristate "USB 2.0 OTG FSM implementation"
- depends on USB && USB_OTG
- select USB_PHY
- help
- Implements OTG Finite State Machine as specified in On-The-Go
- and Embedded Host Supplement to the USB Revision 2.0 Specification.
-
config USB_ULPI_BUS
tristate "USB ULPI PHY interface support"
depends on USB_SUPPORT
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index c690474..06794e2 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -20,7 +20,7 @@ config AB8500_USB
config FSL_USB2_OTG
bool "Freescale USB OTG Transceiver Driver"
- depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_OTG_FSM && PM
+ depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_OTG && PM
select USB_PHY
help
Enable this to support Freescale USB OTG transceiver.
--
2.5.0
[toc] | [prev] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-05 16:10 +0200 |
| Subject | [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <rkzQ7-4UX-35@gated-at.bofh.it> |
| In reply to | #1371633 |
It provides APIs for the following tasks
- Registering an OTG/dual-role capable controller
- Registering Host and Gadget controllers to OTG core
- Providing inputs to and kicking the OTG state machine
Provide a dual-role device (DRD) state machine.
DRD mode is a reduced functionality OTG mode. In this mode
we don't support SRP, HNP and dynamic role-swap.
In DRD operation, the controller mode (Host or Peripheral)
is decided based on the ID pin status. Once a cable plug (Type-A
or Type-B) is attached the controller selects the state
and doesn't change till the cable in unplugged and a different
cable type is inserted.
As we don't need most of the complex OTG states and OTG timers
we implement a lean DRD state machine in usb-otg.c.
The DRD state machine is only interested in 2 hardware inputs
'id' and 'b_sess_vld'.
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
drivers/usb/common/Makefile | 2 +-
drivers/usb/common/usb-otg.c | 1058 ++++++++++++++++++++++++++++++++++++++++++
drivers/usb/common/usb-otg.h | 71 +++
drivers/usb/core/Kconfig | 2 +-
include/linux/usb/gadget.h | 2 +
include/linux/usb/hcd.h | 1 +
include/linux/usb/otg-fsm.h | 7 +
include/linux/usb/otg.h | 154 +++++-
8 files changed, 1292 insertions(+), 5 deletions(-)
create mode 100644 drivers/usb/common/usb-otg.c
create mode 100644 drivers/usb/common/usb-otg.h
diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index f8f2c88..730d928 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -7,5 +7,5 @@ usb-common-y += common.o
usb-common-$(CONFIG_USB_LED_TRIG) += led.o
obj-$(CONFIG_USB_ULPI_BUS) += ulpi.o
-usbotg-y := usb-otg-fsm.o
+usbotg-y := usb-otg.o usb-otg-fsm.o
obj-$(CONFIG_USB_OTG) += usbotg.o
diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
new file mode 100644
index 0000000..41e762a
--- /dev/null
+++ b/drivers/usb/common/usb-otg.c
@@ -0,0 +1,1058 @@
+/**
+ * drivers/usb/common/usb-otg.c - USB OTG core
+ *
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <rogerq@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/ktime.h>
+#include <linux/hrtimer.h>
+#include <linux/list.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/gadget.h>
+#include <linux/workqueue.h>
+
+#include "usb-otg.h"
+
+struct otg_gcd {
+ struct usb_gadget *gadget;
+ struct otg_gadget_ops *ops;
+};
+
+/* OTG device list */
+LIST_HEAD(otg_list);
+static DEFINE_MUTEX(otg_list_mutex);
+
+/* Hosts and Gadgets waiting for OTG controller */
+struct otg_wait_data {
+ struct device *dev; /* OTG controller device */
+
+ struct otg_hcd primary_hcd;
+ struct otg_hcd shared_hcd;
+ struct otg_gcd gcd;
+ struct list_head list;
+};
+
+LIST_HEAD(wait_list);
+static DEFINE_MUTEX(wait_list_mutex);
+
+static int usb_otg_hcd_is_primary_hcd(struct usb_hcd *hcd)
+{
+ if (!hcd->primary_hcd)
+ return 1;
+ return hcd == hcd->primary_hcd;
+}
+
+/**
+ * Check if the OTG device is in our wait list and return
+ * otg_wait_data, else NULL.
+ *
+ * wait_list_mutex must be held.
+ */
+static struct otg_wait_data *usb_otg_get_wait(struct device *otg_dev)
+{
+ struct otg_wait_data *wait;
+
+ if (!otg_dev)
+ return NULL;
+
+ /* is there an entry for this otg_dev ?*/
+ list_for_each_entry(wait, &wait_list, list) {
+ if (wait->dev == otg_dev)
+ return wait;
+ }
+
+ return NULL;
+}
+
+/**
+ * Add the hcd to our wait list
+ */
+static int usb_otg_hcd_wait_add(struct device *otg_dev, struct usb_hcd *hcd,
+ unsigned int irqnum, unsigned long irqflags,
+ struct otg_hcd_ops *ops)
+{
+ struct otg_wait_data *wait;
+ int ret = -EINVAL;
+
+ mutex_lock(&wait_list_mutex);
+
+ wait = usb_otg_get_wait(otg_dev);
+ if (!wait) {
+ /* Not yet in wait list? allocate and add */
+ wait = kzalloc(sizeof(*wait), GFP_KERNEL);
+ if (!wait) {
+ ret = -ENOMEM;
+ goto fail;
+ }
+
+ wait->dev = otg_dev;
+ list_add_tail(&wait->list, &wait_list);
+ }
+
+ if (usb_otg_hcd_is_primary_hcd(hcd)) {
+ if (wait->primary_hcd.hcd) /* already assigned? */
+ goto fail;
+
+ wait->primary_hcd.hcd = hcd;
+ wait->primary_hcd.irqnum = irqnum;
+ wait->primary_hcd.irqflags = irqflags;
+ wait->primary_hcd.ops = ops;
+ wait->primary_hcd.otg_dev = otg_dev;
+ } else {
+ if (wait->shared_hcd.hcd) /* already assigned? */
+ goto fail;
+
+ wait->shared_hcd.hcd = hcd;
+ wait->shared_hcd.irqnum = irqnum;
+ wait->shared_hcd.irqflags = irqflags;
+ wait->shared_hcd.ops = ops;
+ wait->shared_hcd.otg_dev = otg_dev;
+ }
+
+ mutex_unlock(&wait_list_mutex);
+ return 0;
+
+fail:
+ mutex_unlock(&wait_list_mutex);
+ return ret;
+}
+
+/**
+ * Check and free wait list entry if empty
+ *
+ * wait_list_mutex must be held
+ */
+static void usb_otg_check_free_wait(struct otg_wait_data *wait)
+{
+ if (wait->primary_hcd.hcd || wait->shared_hcd.hcd || wait->gcd.gadget)
+ return;
+
+ list_del(&wait->list);
+ kfree(wait);
+}
+
+/**
+ * Remove the hcd from our wait list
+ */
+static int usb_otg_hcd_wait_remove(struct usb_hcd *hcd)
+{
+ struct otg_wait_data *wait;
+
+ mutex_lock(&wait_list_mutex);
+
+ /* is there an entry for this hcd ?*/
+ list_for_each_entry(wait, &wait_list, list) {
+ if (wait->primary_hcd.hcd == hcd) {
+ wait->primary_hcd.hcd = 0;
+ goto found;
+ } else if (wait->shared_hcd.hcd == hcd) {
+ wait->shared_hcd.hcd = 0;
+ goto found;
+ }
+ }
+
+ mutex_unlock(&wait_list_mutex);
+ return -EINVAL;
+
+found:
+ usb_otg_check_free_wait(wait);
+ mutex_unlock(&wait_list_mutex);
+
+ return 0;
+}
+
+/**
+ * Add the gadget to our wait list
+ */
+static int usb_otg_gadget_wait_add(struct device *otg_dev,
+ struct usb_gadget *gadget,
+ struct otg_gadget_ops *ops)
+{
+ struct otg_wait_data *wait;
+ int ret = -EINVAL;
+
+ mutex_lock(&wait_list_mutex);
+
+ wait = usb_otg_get_wait(otg_dev);
+ if (!wait) {
+ /* Not yet in wait list? allocate and add */
+ wait = kzalloc(sizeof(*wait), GFP_KERNEL);
+ if (!wait) {
+ ret = -ENOMEM;
+ goto fail;
+ }
+
+ wait->dev = otg_dev;
+ list_add_tail(&wait->list, &wait_list);
+ }
+
+ if (wait->gcd.gadget) /* already assigned? */
+ goto fail;
+
+ wait->gcd.gadget = gadget;
+ wait->gcd.ops = ops;
+ mutex_unlock(&wait_list_mutex);
+
+ return 0;
+
+fail:
+ mutex_unlock(&wait_list_mutex);
+ return ret;
+}
+
+/**
+ * Remove the gadget from our wait list
+ */
+static int usb_otg_gadget_wait_remove(struct usb_gadget *gadget)
+{
+ struct otg_wait_data *wait;
+
+ mutex_lock(&wait_list_mutex);
+
+ /* is there an entry for this gadget ?*/
+ list_for_each_entry(wait, &wait_list, list) {
+ if (wait->gcd.gadget == gadget) {
+ wait->gcd.gadget = 0;
+ goto found;
+ }
+ }
+
+ mutex_unlock(&wait_list_mutex);
+
+ return -EINVAL;
+
+found:
+ usb_otg_check_free_wait(wait);
+ mutex_unlock(&wait_list_mutex);
+
+ return 0;
+}
+
+/**
+ * Register pending host/gadget and remove entry from wait list
+ */
+static void usb_otg_flush_wait(struct device *otg_dev)
+{
+ struct otg_wait_data *wait;
+ struct otg_hcd *host;
+ struct otg_gcd *gadget;
+
+ mutex_lock(&wait_list_mutex);
+
+ wait = usb_otg_get_wait(otg_dev);
+ if (!wait)
+ goto done;
+
+ dev_dbg(otg_dev, "otg: registering pending host/gadget\n");
+ gadget = &wait->gcd;
+ if (gadget)
+ usb_otg_register_gadget(gadget->gadget, gadget->ops);
+
+ host = &wait->primary_hcd;
+ if (host->hcd)
+ usb_otg_register_hcd(host->hcd, host->irqnum, host->irqflags,
+ host->ops);
+
+ host = &wait->shared_hcd;
+ if (host->hcd)
+ usb_otg_register_hcd(host->hcd, host->irqnum, host->irqflags,
+ host->ops);
+
+ list_del(&wait->list);
+ kfree(wait);
+
+done:
+ mutex_unlock(&wait_list_mutex);
+}
+
+/**
+ * Check if the OTG device is in our OTG list and return
+ * usb_otg data, else NULL.
+ *
+ * otg_list_mutex must be held.
+ */
+static struct usb_otg *usb_otg_get_data(struct device *otg_dev)
+{
+ struct usb_otg *otg;
+
+ if (!otg_dev)
+ return NULL;
+
+ list_for_each_entry(otg, &otg_list, list) {
+ if (otg->dev == otg_dev)
+ return otg;
+ }
+
+ return NULL;
+}
+
+/**
+ * usb_otg_start_host - start/stop the host controller
+ * @otg: usb_otg instance
+ * @on: true to start, false to stop
+ *
+ * Start/stop the USB host controller. This function is meant
+ * for use by the OTG controller driver.
+ */
+int usb_otg_start_host(struct usb_otg *otg, int on)
+{
+ struct otg_hcd_ops *hcd_ops = otg->hcd_ops;
+
+ dev_dbg(otg->dev, "otg: %s %d\n", __func__, on);
+ if (!otg->host) {
+ WARN_ONCE(1, "otg: fsm running without host\n");
+ return 0;
+ }
+
+ if (on) {
+ if (otg->flags & OTG_FLAG_HOST_RUNNING)
+ return 0;
+
+ otg->flags |= OTG_FLAG_HOST_RUNNING;
+
+ /* start host */
+ hcd_ops->add(otg->primary_hcd.hcd, otg->primary_hcd.irqnum,
+ otg->primary_hcd.irqflags);
+ if (otg->shared_hcd.hcd) {
+ hcd_ops->add(otg->shared_hcd.hcd,
+ otg->shared_hcd.irqnum,
+ otg->shared_hcd.irqflags);
+ }
+ } else {
+ if (!(otg->flags & OTG_FLAG_HOST_RUNNING))
+ return 0;
+
+ otg->flags &= ~OTG_FLAG_HOST_RUNNING;
+
+ /* stop host */
+ if (otg->shared_hcd.hcd)
+ hcd_ops->remove(otg->shared_hcd.hcd);
+
+ hcd_ops->remove(otg->primary_hcd.hcd);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(usb_otg_start_host);
+
+/**
+ * usb_otg_start_gadget - start/stop the gadget controller
+ * @otg: usb_otg instance
+ * @on: true to start, false to stop
+ *
+ * Start/stop the USB gadget controller. This function is meant
+ * for use by the OTG controller driver.
+ */
+int usb_otg_start_gadget(struct usb_otg *otg, int on)
+{
+ struct usb_gadget *gadget = otg->gadget;
+
+ dev_dbg(otg->dev, "otg: %s %d\n", __func__, on);
+ if (!gadget) {
+ WARN_ONCE(1, "otg: fsm running without gadget\n");
+ return 0;
+ }
+
+ if (on) {
+ if (otg->flags & OTG_FLAG_GADGET_RUNNING)
+ return 0;
+
+ otg->flags |= OTG_FLAG_GADGET_RUNNING;
+ otg->gadget_ops->start(otg->gadget);
+ } else {
+ if (!(otg->flags & OTG_FLAG_GADGET_RUNNING))
+ return 0;
+
+ otg->flags &= ~OTG_FLAG_GADGET_RUNNING;
+ otg->gadget_ops->stop(otg->gadget);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(usb_otg_start_gadget);
+
+/**
+ * Change USB protocol when there is a protocol change.
+ * fsm->lock must be held.
+ */
+static int drd_set_protocol(struct otg_fsm *fsm, int protocol)
+{
+ struct usb_otg *otg = container_of(fsm, struct usb_otg, fsm);
+ int ret = 0;
+
+ if (fsm->protocol != protocol) {
+ dev_dbg(otg->dev, "otg: changing role fsm->protocol= %d; new protocol= %d\n",
+ fsm->protocol, protocol);
+ /* stop old protocol */
+ if (fsm->protocol == PROTO_HOST)
+ ret = otg_start_host(otg, 0);
+ else if (fsm->protocol == PROTO_GADGET)
+ ret = otg_start_gadget(otg, 0);
+ if (ret)
+ return ret;
+
+ /* start new protocol */
+ if (protocol == PROTO_HOST)
+ ret = otg_start_host(otg, 1);
+ else if (protocol == PROTO_GADGET)
+ ret = otg_start_gadget(otg, 1);
+ if (ret)
+ return ret;
+
+ fsm->protocol = protocol;
+ return 0;
+ }
+
+ return 0;
+}
+
+/**
+ * Called when entering a DRD state.
+ * fsm->lock must be held.
+ */
+static void drd_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
+{
+ struct usb_otg *otg = container_of(fsm, struct usb_otg, fsm);
+
+ if (otg->state == new_state)
+ return;
+
+ fsm->state_changed = 1;
+ dev_dbg(otg->dev, "otg: set state: %s\n",
+ usb_otg_state_string(new_state));
+ switch (new_state) {
+ case OTG_STATE_B_IDLE:
+ drd_set_protocol(fsm, PROTO_UNDEF);
+ otg_drv_vbus(otg, 0);
+ break;
+ case OTG_STATE_B_PERIPHERAL:
+ drd_set_protocol(fsm, PROTO_GADGET);
+ otg_drv_vbus(otg, 0);
+ break;
+ case OTG_STATE_A_HOST:
+ drd_set_protocol(fsm, PROTO_HOST);
+ otg_drv_vbus(otg, 1);
+ break;
+ case OTG_STATE_UNDEFINED:
+ case OTG_STATE_B_SRP_INIT:
+ case OTG_STATE_B_WAIT_ACON:
+ case OTG_STATE_B_HOST:
+ case OTG_STATE_A_IDLE:
+ case OTG_STATE_A_WAIT_VRISE:
+ case OTG_STATE_A_WAIT_BCON:
+ case OTG_STATE_A_SUSPEND:
+ case OTG_STATE_A_PERIPHERAL:
+ case OTG_STATE_A_WAIT_VFALL:
+ case OTG_STATE_A_VBUS_ERR:
+ default:
+ dev_warn(otg->dev, "%s: otg: invalid state: %s\n",
+ __func__, usb_otg_state_string(new_state));
+ break;
+ }
+
+ otg->state = new_state;
+}
+
+/**
+ * DRD state change judgement
+ *
+ * For DRD we're only interested in some of the OTG states
+ * i.e. OTG_STATE_B_IDLE: both peripheral and host are stopped
+ * OTG_STATE_B_PERIPHERAL: peripheral active
+ * OTG_STATE_A_HOST: host active
+ * we're only interested in the following inputs
+ * fsm->id, fsm->b_sess_vld
+ */
+int drd_statemachine(struct usb_otg *otg)
+{
+ struct otg_fsm *fsm = &otg->fsm;
+ enum usb_otg_state state;
+ int ret;
+
+ mutex_lock(&fsm->lock);
+
+ fsm->state_changed = 0;
+ state = otg->state;
+
+ switch (state) {
+ case OTG_STATE_UNDEFINED:
+ if (!fsm->id)
+ drd_set_state(fsm, OTG_STATE_A_HOST);
+ else if (fsm->id && fsm->b_sess_vld)
+ drd_set_state(fsm, OTG_STATE_B_PERIPHERAL);
+ else
+ drd_set_state(fsm, OTG_STATE_B_IDLE);
+ break;
+ case OTG_STATE_B_IDLE:
+ if (!fsm->id)
+ drd_set_state(fsm, OTG_STATE_A_HOST);
+ else if (fsm->b_sess_vld)
+ drd_set_state(fsm, OTG_STATE_B_PERIPHERAL);
+ break;
+ case OTG_STATE_B_PERIPHERAL:
+ if (!fsm->id)
+ drd_set_state(fsm, OTG_STATE_A_HOST);
+ else if (!fsm->b_sess_vld)
+ drd_set_state(fsm, OTG_STATE_B_IDLE);
+ break;
+ case OTG_STATE_A_HOST:
+ if (fsm->id && fsm->b_sess_vld)
+ drd_set_state(fsm, OTG_STATE_B_PERIPHERAL);
+ else if (fsm->id && !fsm->b_sess_vld)
+ drd_set_state(fsm, OTG_STATE_B_IDLE);
+ break;
+
+ /* invalid states for DRD */
+ case OTG_STATE_B_SRP_INIT:
+ case OTG_STATE_B_WAIT_ACON:
+ case OTG_STATE_B_HOST:
+ case OTG_STATE_A_IDLE:
+ case OTG_STATE_A_WAIT_VRISE:
+ case OTG_STATE_A_WAIT_BCON:
+ case OTG_STATE_A_SUSPEND:
+ case OTG_STATE_A_PERIPHERAL:
+ case OTG_STATE_A_WAIT_VFALL:
+ case OTG_STATE_A_VBUS_ERR:
+ dev_err(otg->dev, "%s: otg: invalid usb-drd state: %s\n",
+ __func__, usb_otg_state_string(state));
+ drd_set_state(fsm, OTG_STATE_UNDEFINED);
+ break;
+ }
+
+ ret = fsm->state_changed;
+ mutex_unlock(&fsm->lock);
+ dev_dbg(otg->dev, "otg: quit statemachine, changed %d\n",
+ fsm->state_changed);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(drd_statemachine);
+
+/**
+ * OTG FSM/DRD work function
+ */
+static void usb_otg_work(struct work_struct *work)
+{
+ struct usb_otg *otg = container_of(work, struct usb_otg, work);
+
+ pm_runtime_get_sync(otg->dev);
+ drd_statemachine(otg);
+ pm_runtime_put_sync(otg->dev);
+}
+
+/**
+ * usb_otg_register() - Register the OTG/dual-role device to OTG core
+ * @dev: OTG/dual-role controller device.
+ * @config: OTG configuration.
+ *
+ * Registers the OTG/dual-role controller device with the USB OTG core.
+ *
+ * Return: struct usb_otg * if success, ERR_PTR() if error.
+ */
+struct usb_otg *usb_otg_register(struct device *dev,
+ struct usb_otg_config *config)
+{
+ struct usb_otg *otg;
+ struct otg_wait_data *wait;
+ int ret = 0;
+
+ if (!dev || !config || !config->fsm_ops)
+ return ERR_PTR(-EINVAL);
+
+ /* already in list? */
+ mutex_lock(&otg_list_mutex);
+ if (usb_otg_get_data(dev)) {
+ dev_err(dev, "otg: %s: device already in otg list\n",
+ __func__);
+ ret = -EINVAL;
+ goto unlock;
+ }
+
+ /* allocate and add to list */
+ otg = kzalloc(sizeof(*otg), GFP_KERNEL);
+ if (!otg) {
+ ret = -ENOMEM;
+ goto unlock;
+ }
+
+ otg->dev = dev;
+ otg->caps = config->otg_caps;
+
+ if ((otg->caps->hnp_support || otg->caps->srp_support ||
+ otg->caps->adp_support) && !config->otg_work)
+ dev_info(dev, "otg: limiting to dual-role\n");
+
+ if (config->otg_work) /* custom otg_work ? */
+ INIT_WORK(&otg->work, config->otg_work);
+ else
+ INIT_WORK(&otg->work, usb_otg_work);
+
+ otg->wq = create_singlethread_workqueue("usb_otg");
+ if (!otg->wq) {
+ dev_err(dev, "otg: %s: can't create workqueue\n",
+ __func__);
+ ret = -ENOMEM;
+ goto err_wq;
+ }
+
+ /* set otg ops */
+ otg->fsm.ops = config->fsm_ops;
+
+ mutex_init(&otg->fsm.lock);
+
+ list_add_tail(&otg->list, &otg_list);
+ mutex_unlock(&otg_list_mutex);
+
+ /* were we in wait list? */
+ mutex_lock(&wait_list_mutex);
+ wait = usb_otg_get_wait(dev);
+ mutex_unlock(&wait_list_mutex);
+ if (wait) {
+ /* register pending host/gadget and flush from list */
+ usb_otg_flush_wait(dev);
+ }
+
+ return otg;
+
+err_wq:
+ kfree(otg);
+unlock:
+ mutex_unlock(&otg_list_mutex);
+ return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(usb_otg_register);
+
+/**
+ * usb_otg_unregister() - Unregister the OTG/dual-role device from USB OTG core
+ * @dev: OTG controller device.
+ *
+ * Unregisters the OTG/dual-role controller device from USB OTG core.
+ * Prevents unregistering till both the associated Host and Gadget controllers
+ * have unregistered from the OTG core.
+ *
+ * Return: 0 on success, error value otherwise.
+ */
+int usb_otg_unregister(struct device *dev)
+{
+ struct usb_otg *otg;
+
+ mutex_lock(&otg_list_mutex);
+ otg = usb_otg_get_data(dev);
+ if (!otg) {
+ dev_err(dev, "otg: %s: device not in otg list\n",
+ __func__);
+ mutex_unlock(&otg_list_mutex);
+ return -EINVAL;
+ }
+
+ /* prevent unregister till both host & gadget have unregistered */
+ if (otg->host || otg->gadget) {
+ dev_err(dev, "otg: %s: host/gadget still registered\n",
+ __func__);
+ return -EBUSY;
+ }
+
+ /* OTG FSM is halted when host/gadget unregistered */
+ destroy_workqueue(otg->wq);
+
+ /* remove from otg list */
+ list_del(&otg->list);
+ kfree(otg);
+ mutex_unlock(&otg_list_mutex);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(usb_otg_unregister);
+
+/**
+ * start/kick the OTG FSM if we can
+ * fsm->lock must be held
+ */
+static void usb_otg_start_fsm(struct usb_otg *otg)
+{
+ struct otg_fsm *fsm = &otg->fsm;
+
+ if (fsm->running)
+ goto kick_fsm;
+
+ if (!otg->host) {
+ dev_info(otg->dev, "otg: can't start till host registers\n");
+ return;
+ }
+
+ if (!otg->gadget) {
+ dev_info(otg->dev, "otg: can't start till gadget registers\n");
+ return;
+ }
+
+ fsm->running = true;
+kick_fsm:
+ queue_work(otg->wq, &otg->work);
+}
+
+/**
+ * stop the OTG FSM. Stops Host & Gadget controllers as well.
+ * fsm->lock must be held
+ */
+static void usb_otg_stop_fsm(struct usb_otg *otg)
+{
+ struct otg_fsm *fsm = &otg->fsm;
+
+ if (!fsm->running)
+ return;
+
+ /* no more new events queued */
+ fsm->running = false;
+
+ flush_workqueue(otg->wq);
+ otg->state = OTG_STATE_UNDEFINED;
+
+ /* stop host/gadget immediately */
+ if (fsm->protocol == PROTO_HOST)
+ otg_start_host(otg, 0);
+ else if (fsm->protocol == PROTO_GADGET)
+ otg_start_gadget(otg, 0);
+ fsm->protocol = PROTO_UNDEF;
+}
+
+/**
+ * usb_otg_sync_inputs - Sync OTG inputs with the OTG state machine
+ * @fsm: OTG FSM instance
+ *
+ * Used by the OTG driver to update the inputs to the OTG
+ * state machine.
+ *
+ * Can be called in IRQ context.
+ */
+void usb_otg_sync_inputs(struct usb_otg *otg)
+{
+ /* Don't kick FSM till it has started */
+ if (!otg->fsm.running)
+ return;
+
+ /* Kick FSM */
+ queue_work(otg->wq, &otg->work);
+}
+EXPORT_SYMBOL_GPL(usb_otg_sync_inputs);
+
+/**
+ * usb_otg_kick_fsm - Kick the OTG state machine
+ * @otg_dev: OTG controller device
+ *
+ * Used by USB host/device stack to sync OTG related
+ * events to the OTG state machine.
+ * e.g. change in host_bus->b_hnp_enable, gadget->b_hnp_enable
+ *
+ * Returns: 0 on success, error value otherwise.
+ */
+int usb_otg_kick_fsm(struct device *otg_dev)
+{
+ struct usb_otg *otg;
+
+ mutex_lock(&otg_list_mutex);
+ otg = usb_otg_get_data(otg_dev);
+ mutex_unlock(&otg_list_mutex);
+ if (!otg) {
+ dev_dbg(otg_dev, "otg: %s: invalid otg device\n",
+ __func__);
+ return -ENODEV;
+ }
+
+ usb_otg_sync_inputs(otg);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(usb_otg_kick_fsm);
+
+/**
+ * usb_otg_register_hcd - Register the host controller to OTG core
+ * @hcd: host controller device
+ * @irqnum: interrupt number
+ * @irqflags: interrupt flags
+ * @ops: HCD ops to interface with the HCD
+ *
+ * This is used by the USB Host stack to register the host controller
+ * to the OTG core. Host controller must not be started by the
+ * caller as it is left upto the OTG state machine to do so.
+ * hcd->otg_dev must contain the related otg controller device.
+ *
+ * Returns: 0 on success, error value otherwise.
+ */
+int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
+ unsigned long irqflags, struct otg_hcd_ops *ops)
+{
+ struct usb_otg *otg;
+ struct device *hcd_dev = hcd->self.controller;
+ struct device *otg_dev = hcd->otg_dev;
+
+ if (!otg_dev)
+ return -EINVAL;
+
+ /* we're otg but otg controller might not yet be registered */
+ mutex_lock(&otg_list_mutex);
+ otg = usb_otg_get_data(otg_dev);
+ mutex_unlock(&otg_list_mutex);
+ if (!otg) {
+ dev_dbg(hcd_dev,
+ "otg: controller not yet registered. waiting..\n");
+ /*
+ * otg controller might register later. Put the hcd in
+ * wait list and call us back when ready
+ */
+ if (usb_otg_hcd_wait_add(otg_dev, hcd, irqnum, irqflags, ops)) {
+ dev_err(hcd_dev, "otg: failed to add hcd to wait list\n");
+ return -EINVAL;
+ }
+
+ return 0;
+ }
+
+ /* HCD will be started by OTG fsm when needed */
+ mutex_lock(&otg->fsm.lock);
+ if (otg->primary_hcd.hcd) {
+ /* probably a shared HCD ? */
+ if (usb_otg_hcd_is_primary_hcd(hcd)) {
+ dev_err(otg_dev, "otg: primary host already registered\n");
+ goto err;
+ }
+
+ if (hcd->shared_hcd == otg->primary_hcd.hcd) {
+ if (otg->shared_hcd.hcd) {
+ dev_err(otg_dev, "otg: shared host already registered\n");
+ goto err;
+ }
+
+ otg->shared_hcd.hcd = hcd;
+ otg->shared_hcd.irqnum = irqnum;
+ otg->shared_hcd.irqflags = irqflags;
+ otg->shared_hcd.ops = ops;
+ dev_info(otg_dev, "otg: shared host %s registered\n",
+ dev_name(hcd->self.controller));
+ } else {
+ dev_err(otg_dev, "otg: invalid shared host %s\n",
+ dev_name(hcd->self.controller));
+ goto err;
+ }
+ } else {
+ if (!usb_otg_hcd_is_primary_hcd(hcd)) {
+ dev_err(otg_dev, "otg: primary host must be registered first\n");
+ goto err;
+ }
+
+ otg->primary_hcd.hcd = hcd;
+ otg->primary_hcd.irqnum = irqnum;
+ otg->primary_hcd.irqflags = irqflags;
+ otg->primary_hcd.ops = ops;
+ otg->hcd_ops = ops;
+ dev_info(otg_dev, "otg: primary host %s registered\n",
+ dev_name(hcd->self.controller));
+ }
+
+ /*
+ * we're ready only if we have shared HCD
+ * or we don't need shared HCD.
+ */
+ if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
+ otg->host = hcd_to_bus(hcd);
+ /* FIXME: set bus->otg_port if this is true OTG port with HNP */
+
+ /* start FSM */
+ usb_otg_start_fsm(otg);
+ } else {
+ dev_dbg(otg_dev, "otg: can't start till shared host registers\n");
+ }
+
+ mutex_unlock(&otg->fsm.lock);
+
+ return 0;
+
+err:
+ mutex_unlock(&otg->fsm.lock);
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(usb_otg_register_hcd);
+
+/**
+ * usb_otg_unregister_hcd - Unregister the host controller from OTG core
+ * @hcd: host controller device
+ *
+ * This is used by the USB Host stack to unregister the host controller
+ * from the OTG core. Ensures that host controller is not running
+ * on successful return.
+ *
+ * Returns: 0 on success, error value otherwise.
+ */
+int usb_otg_unregister_hcd(struct usb_hcd *hcd)
+{
+ struct usb_otg *otg;
+ struct device *hcd_dev = hcd_to_bus(hcd)->controller;
+ struct device *otg_dev = hcd->otg_dev;
+
+ if (!otg_dev)
+ return -EINVAL; /* we're definitely not OTG */
+
+ mutex_lock(&otg_list_mutex);
+ otg = usb_otg_get_data(otg_dev);
+ mutex_unlock(&otg_list_mutex);
+ if (!otg) {
+ /* are we in wait list? */
+ if (!usb_otg_hcd_wait_remove(hcd))
+ return 0;
+
+ dev_dbg(hcd_dev, "otg: host wasn't registered with otg\n");
+ return -EINVAL;
+ }
+
+ mutex_lock(&otg->fsm.lock);
+ if (hcd == otg->primary_hcd.hcd) {
+ otg->primary_hcd.hcd = NULL;
+ dev_info(otg_dev, "otg: primary host %s unregistered\n",
+ dev_name(hcd_dev));
+ } else if (hcd == otg->shared_hcd.hcd) {
+ otg->shared_hcd.hcd = NULL;
+ dev_info(otg_dev, "otg: shared host %s unregistered\n",
+ dev_name(hcd_dev));
+ } else {
+ dev_err(otg_dev, "otg: host %s wasn't registered with otg\n",
+ dev_name(hcd_dev));
+ mutex_unlock(&otg->fsm.lock);
+ return -EINVAL;
+ }
+
+ /* stop FSM & Host */
+ usb_otg_stop_fsm(otg);
+ otg->host = NULL;
+
+ mutex_unlock(&otg->fsm.lock);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(usb_otg_unregister_hcd);
+
+/**
+ * usb_otg_register_gadget - Register the gadget controller to OTG core
+ * @gadget: gadget controller
+ *
+ * This is used by the USB gadget stack to register the gadget controller
+ * to the OTG core. Gadget controller must not be started by the
+ * caller as it is left upto the OTG state machine to do so.
+ *
+ * Gadget core must call this only when all resources required for
+ * gadget controller to run are available.
+ * i.e. gadget function driver is available.
+ *
+ * Returns: 0 on success, error value otherwise.
+ */
+int usb_otg_register_gadget(struct usb_gadget *gadget,
+ struct otg_gadget_ops *ops)
+{
+ struct usb_otg *otg;
+ struct device *gadget_dev = &gadget->dev;
+ struct device *otg_dev = gadget->otg_dev;
+
+ if (!otg_dev)
+ return -EINVAL; /* we're definitely not OTG */
+
+ /* we're otg but otg controller might not yet be registered */
+ mutex_lock(&otg_list_mutex);
+ otg = usb_otg_get_data(otg_dev);
+ mutex_unlock(&otg_list_mutex);
+ if (!otg) {
+ dev_dbg(gadget_dev,
+ "otg: controller not yet registered. waiting..\n");
+ /*
+ * otg controller might register later. Put the gadget in
+ * wait list and call us back when ready
+ */
+ if (usb_otg_gadget_wait_add(otg_dev, gadget, ops)) {
+ dev_err(gadget_dev,
+ "otg: failed to add to gadget to wait list\n");
+ return -EINVAL;
+ }
+
+ return 0;
+ }
+
+ mutex_lock(&otg->fsm.lock);
+ if (otg->gadget) {
+ dev_err(otg_dev, "otg: gadget already registered with otg\n");
+ mutex_unlock(&otg->fsm.lock);
+ return -EINVAL;
+ }
+
+ otg->gadget = gadget;
+ otg->gadget_ops = ops;
+ dev_info(otg_dev, "otg: gadget %s registered\n",
+ dev_name(&gadget->dev));
+
+ /* start FSM */
+ usb_otg_start_fsm(otg);
+ mutex_unlock(&otg->fsm.lock);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(usb_otg_register_gadget);
+
+/**
+ * usb_otg_unregister_gadget - Unregister the gadget controller from OTG core
+ * @gadget: gadget controller
+ *
+ * This is used by the USB gadget stack to unregister the gadget controller
+ * from the OTG core. Ensures that gadget controller is halted
+ * on successful return.
+ *
+ * Returns: 0 on success, error value otherwise.
+ */
+int usb_otg_unregister_gadget(struct usb_gadget *gadget)
+{
+ struct usb_otg *otg;
+ struct device *gadget_dev = &gadget->dev;
+ struct device *otg_dev = gadget->otg_dev;
+
+ if (!otg_dev)
+ return -EINVAL;
+
+ mutex_lock(&otg_list_mutex);
+ otg = usb_otg_get_data(otg_dev);
+ mutex_unlock(&otg_list_mutex);
+ if (!otg) {
+ /* are we in wait list? */
+ if (!usb_otg_gadget_wait_remove(gadget))
+ return 0;
+
+ dev_dbg(gadget_dev, "otg: gadget wasn't registered with otg\n");
+ return -EINVAL;
+ }
+
+ mutex_lock(&otg->fsm.lock);
+ if (otg->gadget != gadget) {
+ dev_err(otg_dev, "otg: gadget %s wasn't registered with otg\n",
+ dev_name(&gadget->dev));
+ mutex_unlock(&otg->fsm.lock);
+ return -EINVAL;
+ }
+
+ /* Stop FSM & gadget */
+ usb_otg_stop_fsm(otg);
+ otg->gadget = NULL;
+ mutex_unlock(&otg->fsm.lock);
+
+ dev_info(otg_dev, "otg: gadget %s unregistered\n",
+ dev_name(&gadget->dev));
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(usb_otg_unregister_gadget);
diff --git a/drivers/usb/common/usb-otg.h b/drivers/usb/common/usb-otg.h
new file mode 100644
index 0000000..2bf3fbf
--- /dev/null
+++ b/drivers/usb/common/usb-otg.h
@@ -0,0 +1,71 @@
+/**
+ * drivers/usb/common/usb-otg.h - USB OTG core local header
+ *
+ * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <rogerq@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __DRIVERS_USB_COMMON_USB_OTG_H
+#define __DRIVERS_USB_COMMON_USB_OTG_H
+
+/*
+ * A-DEVICE timing constants
+ */
+
+/* Wait for VBUS Rise */
+#define TA_WAIT_VRISE (100) /* a_wait_vrise: section 7.1.2
+ * a_wait_vrise_tmr: section 7.4.5.1
+ * TA_VBUS_RISE <= 100ms, section 4.4
+ * Table 4-1: Electrical Characteristics
+ * ->DC Electrical Timing
+ */
+/* Wait for VBUS Fall */
+#define TA_WAIT_VFALL (1000) /* a_wait_vfall: section 7.1.7
+ * a_wait_vfall_tmr: section: 7.4.5.2
+ */
+/* Wait for B-Connect */
+#define TA_WAIT_BCON (10000) /* a_wait_bcon: section 7.1.3
+ * TA_WAIT_BCON: should be between 1100
+ * and 30000 ms, section 5.5, Table 5-1
+ */
+/* A-Idle to B-Disconnect */
+#define TA_AIDL_BDIS (5000) /* a_suspend min 200 ms, section 5.2.1
+ * TA_AIDL_BDIS: section 5.5, Table 5-1
+ */
+/* B-Idle to A-Disconnect */
+#define TA_BIDL_ADIS (500) /* TA_BIDL_ADIS: section 5.2.1
+ * 500ms is used for B switch to host
+ * for safe
+ */
+
+/*
+ * B-device timing constants
+ */
+
+/* Data-Line Pulse Time*/
+#define TB_DATA_PLS (10) /* b_srp_init,continue 5~10ms
+ * section:5.1.3
+ */
+/* SRP Fail Time */
+#define TB_SRP_FAIL (6000) /* b_srp_init,fail time 5~6s
+ * section:5.1.6
+ */
+/* A-SE0 to B-Reset */
+#define TB_ASE0_BRST (155) /* minimum 155 ms, section:5.3.1 */
+/* SE0 Time Before SRP */
+#define TB_SE0_SRP (1000) /* b_idle,minimum 1s, section:5.1.2 */
+/* SSEND time before SRP */
+#define TB_SSEND_SRP (1500) /* minimum 1.5 sec, section:5.1.2 */
+
+#define TB_SESS_VLD (1000)
+
+#endif /* __DRIVERS_USB_COMMON_USB_OTG_H */
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index ae228d0..b468a9f 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -42,7 +42,7 @@ config USB_DYNAMIC_MINORS
If you are unsure about this, say N here.
config USB_OTG
- bool "OTG support"
+ bool "OTG/Dual-role support"
depends on PM
default n
help
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 8c0ae64..1878ae1 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -583,6 +583,7 @@ struct usb_gadget_ops {
* @out_epnum: last used out ep number
* @in_epnum: last used in ep number
* @otg_caps: OTG capabilities of this gadget.
+ * @otg_dev: OTG controller device, if needs to be used with OTG core.
* @sg_supported: true if we can handle scatter-gather
* @is_otg: True if the USB device port uses a Mini-AB jack, so that the
* gadget driver must provide a USB OTG descriptor.
@@ -639,6 +640,7 @@ struct usb_gadget {
unsigned out_epnum;
unsigned in_epnum;
struct usb_otg_caps *otg_caps;
+ struct device *otg_dev;
unsigned sg_supported:1;
unsigned is_otg:1;
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 861ccaa..2017cd4 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -184,6 +184,7 @@ struct usb_hcd {
struct mutex *bandwidth_mutex;
struct usb_hcd *shared_hcd;
struct usb_hcd *primary_hcd;
+ struct device *otg_dev; /* OTG controller device */
#define HCD_BUFFER_POOLS 4
diff --git a/include/linux/usb/otg-fsm.h b/include/linux/usb/otg-fsm.h
index 36f0cf9..ba6755c 100644
--- a/include/linux/usb/otg-fsm.h
+++ b/include/linux/usb/otg-fsm.h
@@ -61,6 +61,11 @@ enum otg_fsm_timer {
/**
* struct otg_fsm - OTG state machine according to the OTG spec
*
+ * DRD mode hardware Inputs
+ *
+ * @id: TRUE for B-device, FALSE for A-device.
+ * @b_sess_vld: VBUS voltage in regulation.
+ *
* OTG hardware Inputs
*
* Common inputs for A and B device
@@ -133,6 +138,7 @@ enum otg_fsm_timer {
* a_clr_err: Asserted (by application ?) to clear a_vbus_err due to an
* overcurrent condition and causes the A-device to transition
* to a_wait_vfall
+ * running: state machine running/stopped indicator
*/
struct otg_fsm {
/* Input */
@@ -188,6 +194,7 @@ struct otg_fsm {
int b_ase0_brst_tmout;
int a_bidl_adis_tmout;
+ bool running;
struct otg_fsm_ops *ops;
/* Current usb protocol used: 0:undefine; 1:host; 2:client */
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index 85b8fb5..b094352 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -10,10 +10,55 @@
#define __LINUX_USB_OTG_H
#include <linux/phy/phy.h>
-#include <linux/usb/phy.h>
-#include <linux/usb/otg-fsm.h>
+#include <linux/device.h>
+#include <linux/hrtimer.h>
+#include <linux/ktime.h>
+#include <linux/usb.h>
#include <linux/usb/hcd.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/otg-fsm.h>
+#include <linux/usb/phy.h>
+/**
+ * struct otg_hcd - host controller state and interface
+ *
+ * @hcd: host controller
+ * @irqnum: irq number
+ * @irqflags: irq flags
+ * @ops: otg to host controller interface
+ * @ops: otg to host controller interface
+ * @otg_dev: otg controller device
+ */
+struct otg_hcd {
+ struct usb_hcd *hcd;
+ unsigned int irqnum;
+ unsigned long irqflags;
+ struct otg_hcd_ops *ops;
+ struct device *otg_dev;
+};
+
+/**
+ * struct usb_otg - usb otg controller state
+ *
+ * @default_a: Indicates we are an A device. i.e. Host.
+ * @phy: USB phy interface
+ * @usb_phy: old usb_phy interface
+ * @host: host controller bus
+ * @gadget: gadget device
+ * @state: current otg state
+ * @dev: otg controller device
+ * @caps: otg capabilities revision, hnp, srp, etc
+ * @fsm: otg finite state machine
+ * @hcd_ops: host controller interface
+ * ------- internal use only -------
+ * @primary_hcd: primary host state and interface
+ * @shared_hcd: shared host state and interface
+ * @gadget_ops: gadget controller interface
+ * @list: list of otg controllers
+ * @work: otg state machine work
+ * @wq: otg state machine work queue
+ * @flags: to track if host/gadget is running
+ */
struct usb_otg {
u8 default_a;
@@ -24,9 +69,24 @@ struct usb_otg {
struct usb_gadget *gadget;
enum usb_otg_state state;
+ struct device *dev;
+ struct usb_otg_caps *caps;
struct otg_fsm fsm;
struct otg_hcd_ops *hcd_ops;
+ /* internal use only */
+ struct otg_hcd primary_hcd;
+ struct otg_hcd shared_hcd;
+ struct otg_gadget_ops *gadget_ops;
+ struct list_head list;
+ struct work_struct work;
+ struct workqueue_struct *wq;
+ u32 flags;
+#define OTG_FLAG_GADGET_RUNNING (1 << 0)
+#define OTG_FLAG_HOST_RUNNING (1 << 1)
+ /* use otg->fsm.lock for serializing access */
+
+/*------------- deprecated interface -----------------------------*/
/* bind/unbind the host controller */
int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
@@ -42,7 +102,7 @@ struct usb_otg {
/* start or continue HNP role switch */
int (*start_hnp)(struct usb_otg *otg);
-
+/*---------------------------------------------------------------*/
};
/**
@@ -60,8 +120,92 @@ struct usb_otg_caps {
bool adp_support;
};
+/**
+ * struct usb_otg_config - otg controller configuration
+ * @caps: otg capabilities of the controller
+ * @ops: otg fsm operations
+ * @otg_work: optional custom otg state machine work function
+ */
+struct usb_otg_config {
+ struct usb_otg_caps *otg_caps;
+ struct otg_fsm_ops *fsm_ops;
+ void (*otg_work)(struct work_struct *work);
+};
+
extern const char *usb_otg_state_string(enum usb_otg_state state);
+#if IS_ENABLED(CONFIG_USB_OTG)
+struct usb_otg *usb_otg_register(struct device *dev,
+ struct usb_otg_config *config);
+int usb_otg_unregister(struct device *dev);
+int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
+ unsigned long irqflags, struct otg_hcd_ops *ops);
+int usb_otg_unregister_hcd(struct usb_hcd *hcd);
+int usb_otg_register_gadget(struct usb_gadget *gadget,
+ struct otg_gadget_ops *ops);
+int usb_otg_unregister_gadget(struct usb_gadget *gadget);
+void usb_otg_sync_inputs(struct usb_otg *otg);
+int usb_otg_kick_fsm(struct device *otg_dev);
+int usb_otg_start_host(struct usb_otg *otg, int on);
+int usb_otg_start_gadget(struct usb_otg *otg, int on);
+
+#else /* CONFIG_USB_OTG */
+
+static inline struct usb_otg *usb_otg_register(struct device *dev,
+ struct usb_otg_config *config)
+{
+ return ERR_PTR(-ENOTSUPP);
+}
+
+static inline int usb_otg_unregister(struct device *dev)
+{
+ return -ENOTSUPP;
+}
+
+static inline int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
+ unsigned long irqflags,
+ struct otg_hcd_ops *ops)
+{
+ return -ENOTSUPP;
+}
+
+static inline int usb_otg_unregister_hcd(struct usb_hcd *hcd)
+{
+ return -ENOTSUPP;
+}
+
+static inline int usb_otg_register_gadget(struct usb_gadget *gadget,
+ struct otg_gadget_ops *ops)
+{
+ return -ENOTSUPP;
+}
+
+static inline int usb_otg_unregister_gadget(struct usb_gadget *gadget)
+{
+ return -ENOTSUPP;
+}
+
+static inline void usb_otg_sync_inputs(struct usb_otg *otg)
+{
+}
+
+static inline int usb_otg_kick_fsm(struct device *otg_dev)
+{
+ return -ENOTSUPP;
+}
+
+static inline int usb_otg_start_host(struct usb_otg *otg, int on)
+{
+ return -ENOTSUPP;
+}
+
+static inline int usb_otg_start_gadget(struct usb_otg *otg, int on)
+{
+ return -ENOTSUPP;
+}
+#endif /* CONFIG_USB_OTG */
+
+/*------------- deprecated interface -----------------------------*/
/* Context: can sleep */
static inline int
otg_start_hnp(struct usb_otg *otg)
@@ -113,6 +257,8 @@ otg_start_srp(struct usb_otg *otg)
return -ENOTSUPP;
}
+/*---------------------------------------------------------------*/
+
/* for OTG controller drivers (and maybe other stuff) */
extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
@@ -237,4 +383,6 @@ static inline int otg_start_gadget(struct usb_otg *otg, int on)
return otg->fsm.ops->start_gadget(otg, on);
}
+int drd_statemachine(struct usb_otg *otg);
+
#endif /* __LINUX_USB_OTG_H */
--
2.5.0
[toc] | [prev] | [next] | [standalone]
| From | Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
|---|---|
| Date | 2016-04-07 11:00 +0200 |
| Subject | RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <rldXd-1d9-21@gated-at.bofh.it> |
| In reply to | #1371645 |
Hi,
> From: Roger Quadros
> Sent: Tuesday, April 05, 2016 11:05 PM
>
> It provides APIs for the following tasks
>
> - Registering an OTG/dual-role capable controller
> - Registering Host and Gadget controllers to OTG core
> - Providing inputs to and kicking the OTG state machine
>
> Provide a dual-role device (DRD) state machine.
> DRD mode is a reduced functionality OTG mode. In this mode
> we don't support SRP, HNP and dynamic role-swap.
>
> In DRD operation, the controller mode (Host or Peripheral)
> is decided based on the ID pin status. Once a cable plug (Type-A
> or Type-B) is attached the controller selects the state
> and doesn't change till the cable in unplugged and a different
> cable type is inserted.
>
> As we don't need most of the complex OTG states and OTG timers
> we implement a lean DRD state machine in usb-otg.c.
> The DRD state machine is only interested in 2 hardware inputs
> 'id' and 'b_sess_vld'.
>
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
I tried to implement this framework on my environment,
and it seemed work if I added a local hack to this patch :)
< snip >
> + /* HCD will be started by OTG fsm when needed */
> + mutex_lock(&otg->fsm.lock);
> + if (otg->primary_hcd.hcd) {
> + /* probably a shared HCD ? */
> + if (usb_otg_hcd_is_primary_hcd(hcd)) {
> + dev_err(otg_dev, "otg: primary host already registered\n");
My environment is arm64 / r8a7795, renesas_usbhs (as a gadget), EHCI and OHCI.
In this case, OHCI driver is also a primary_hcd. So, this error happened.
To avoid this, I assumes that the OHCI hcd is as shared_hcd like a patch below:
diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
index 41e762a..4d7f043 100644
--- a/drivers/usb/common/usb-otg.c
+++ b/drivers/usb/common/usb-otg.c
@@ -825,11 +825,16 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
if (otg->primary_hcd.hcd) {
/* probably a shared HCD ? */
if (usb_otg_hcd_is_primary_hcd(hcd)) {
+ if (hcd->driver->flags & HCD_USB11) {
+ dev_info(otg_dev, "this assumes usb 1.1 hc is as shared_hcd\n");
+ goto check_shared_hcd;
+ }
dev_err(otg_dev, "otg: primary host already registered\n");
goto err;
}
if (hcd->shared_hcd == otg->primary_hcd.hcd) {
+check_shared_hcd:
if (otg->shared_hcd.hcd) {
dev_err(otg_dev, "otg: shared host already registered\n");
goto err;
What do you think this local hack?
I also wonder if array of hcd may be good for both xHCI and EHCI/OHCI.
For example of xHCI:
- otg->hcds[0] = primary_hcd
- otg->hcds[1] = shared_hcd
For example of EHCI/OHCI:
- otg->hcds[0] = primary_hcd of EHCI
- otg->hcds[1] = primary_hcd of OHCI
Best regards,
Yoshihiro Shimoda
[toc] | [prev] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-07 13:50 +0200 |
| Subject | Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <rlgBI-3br-11@gated-at.bofh.it> |
| In reply to | #1373172 |
Hi,
On 07/04/16 11:52, Yoshihiro Shimoda wrote:
> Hi,
>
>> From: Roger Quadros
>> Sent: Tuesday, April 05, 2016 11:05 PM
>>
>> It provides APIs for the following tasks
>>
>> - Registering an OTG/dual-role capable controller
>> - Registering Host and Gadget controllers to OTG core
>> - Providing inputs to and kicking the OTG state machine
>>
>> Provide a dual-role device (DRD) state machine.
>> DRD mode is a reduced functionality OTG mode. In this mode
>> we don't support SRP, HNP and dynamic role-swap.
>>
>> In DRD operation, the controller mode (Host or Peripheral)
>> is decided based on the ID pin status. Once a cable plug (Type-A
>> or Type-B) is attached the controller selects the state
>> and doesn't change till the cable in unplugged and a different
>> cable type is inserted.
>>
>> As we don't need most of the complex OTG states and OTG timers
>> we implement a lean DRD state machine in usb-otg.c.
>> The DRD state machine is only interested in 2 hardware inputs
>> 'id' and 'b_sess_vld'.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>
> I tried to implement this framework on my environment,
> and it seemed work if I added a local hack to this patch :)
Great. Thanks for testing :).
>
> < snip >
>> + /* HCD will be started by OTG fsm when needed */
>> + mutex_lock(&otg->fsm.lock);
>> + if (otg->primary_hcd.hcd) {
>> + /* probably a shared HCD ? */
>> + if (usb_otg_hcd_is_primary_hcd(hcd)) {
>> + dev_err(otg_dev, "otg: primary host already registered\n");
>
> My environment is arm64 / r8a7795, renesas_usbhs (as a gadget), EHCI and OHCI.
> In this case, OHCI driver is also a primary_hcd. So, this error happened.
> To avoid this, I assumes that the OHCI hcd is as shared_hcd like a patch below:
>
> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> index 41e762a..4d7f043 100644
> --- a/drivers/usb/common/usb-otg.c
> +++ b/drivers/usb/common/usb-otg.c
> @@ -825,11 +825,16 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> if (otg->primary_hcd.hcd) {
> /* probably a shared HCD ? */
> if (usb_otg_hcd_is_primary_hcd(hcd)) {
> + if (hcd->driver->flags & HCD_USB11) {
> + dev_info(otg_dev, "this assumes usb 1.1 hc is as shared_hcd\n");
> + goto check_shared_hcd;
> + }
> dev_err(otg_dev, "otg: primary host already registered\n");
> goto err;
> }
>
> if (hcd->shared_hcd == otg->primary_hcd.hcd) {
> +check_shared_hcd:
> if (otg->shared_hcd.hcd) {
> dev_err(otg_dev, "otg: shared host already registered\n");
> goto err;
>
> What do you think this local hack?
Is it guaranteed that EHCI hcd registers before OHCI hcd?
If not we need to improve the code still.
We will also need to remove the constraint that primary_hcd must be registered
first in usb_otg_register_hcd(). I think that constraint is no longer
needed anyways.
If EHCI & OHCI HCDs register before OTG driver then things will break unless
we fix usb_otg_hcd_wait_add(). We need to add this HCD_USB11 check there to
populate wait->shared_hcd.
> I also wonder if array of hcd may be good for both xHCI and EHCI/OHCI.
> For example of xHCI:
> - otg->hcds[0] = primary_hcd
> - otg->hcds[1] = shared_hcd
>
> For example of EHCI/OHCI:
> - otg->hcds[0] = primary_hcd of EHCI
> - otg->hcds[1] = primary_hcd of OHCI
The bigger problem is that how do we know in the OHCI/EHCI case that we need to wait
for both of them before starting the OTG FSM?
Some systems might use just OHCI or just EHCI.
There is no guarantee that OTG driver registers before the HCDs so this piece
of information must come from the HCD itself. i.e. whether it needs a companion or not.
cheers,
-roger
[toc] | [prev] | [next] | [standalone]
| From | Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
|---|---|
| Date | 2016-04-08 13:30 +0200 |
| Subject | RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <rlCLU-30J-13@gated-at.bofh.it> |
| In reply to | #1373302 |
Hi,
> From: Roger Quadros
> Sent: Thursday, April 07, 2016 8:45 PM
>
> Hi,
>
> On 07/04/16 11:52, Yoshihiro Shimoda wrote:
> > Hi,
> >
> >> From: Roger Quadros
> >> Sent: Tuesday, April 05, 2016 11:05 PM
< snip >
> > diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> > index 41e762a..4d7f043 100644
> > --- a/drivers/usb/common/usb-otg.c
> > +++ b/drivers/usb/common/usb-otg.c
> > @@ -825,11 +825,16 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> > if (otg->primary_hcd.hcd) {
> > /* probably a shared HCD ? */
> > if (usb_otg_hcd_is_primary_hcd(hcd)) {
> > + if (hcd->driver->flags & HCD_USB11) {
> > + dev_info(otg_dev, "this assumes usb 1.1 hc is as shared_hcd\n");
> > + goto check_shared_hcd;
> > + }
> > dev_err(otg_dev, "otg: primary host already registered\n");
> > goto err;
> > }
> >
> > if (hcd->shared_hcd == otg->primary_hcd.hcd) {
> > +check_shared_hcd:
> > if (otg->shared_hcd.hcd) {
> > dev_err(otg_dev, "otg: shared host already registered\n");
> > goto err;
> >
> > What do you think this local hack?
>
> Is it guaranteed that EHCI hcd registers before OHCI hcd?
Thank you for the comment. No, it is not guaranteed.
> If not we need to improve the code still.
> We will also need to remove the constraint that primary_hcd must be registered
> first in usb_otg_register_hcd(). I think that constraint is no longer
> needed anyways.
I got it.
So, I made a patch to avoid the constraint using an additional property "otg-hcds".
The patch is in this end of email. What do you think about the patch?
> If EHCI & OHCI HCDs register before OTG driver then things will break unless
> we fix usb_otg_hcd_wait_add(). We need to add this HCD_USB11 check there to
> populate wait->shared_hcd.
I see. In my environment, since EHCI & OHCI HCDs need phy driver and phy driver
will calls usb_otg_register(), the order is right. In other words,
EHCI & OHCI HCDs never register before OTG driver because even if EHCI driver
is probed first, the driver will be deferred (EHCI driver needs the phy driver).
> > I also wonder if array of hcd may be good for both xHCI and EHCI/OHCI.
> > For example of xHCI:
> > - otg->hcds[0] = primary_hcd
> > - otg->hcds[1] = shared_hcd
> >
> > For example of EHCI/OHCI:
> > - otg->hcds[0] = primary_hcd of EHCI
> > - otg->hcds[1] = primary_hcd of OHCI
>
> The bigger problem is that how do we know in the OHCI/EHCI case that we need to wait
> for both of them before starting the OTG FSM?
> Some systems might use just OHCI or just EHCI.
>
> There is no guarantee that OTG driver registers before the HCDs so this piece
> of information must come from the HCD itself. i.e. whether it needs a companion or not.
I understood these problems. I wonder if my patch can resolve these problems.
Best regards,
Yoshihiro Shimoda
---
diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt
index f6866c1..518b9eb 100644
--- a/Documentation/devicetree/bindings/usb/generic.txt
+++ b/Documentation/devicetree/bindings/usb/generic.txt
@@ -27,6 +27,12 @@ Optional properties:
- otg-controller: phandle to otg controller. Host or gadget controllers can
contain this property to link it to a particular OTG
controller.
+ - otg-hcds: phandle to host controller(s). An OTG controller can contain this
+ property. The first one is as "primary", and (optional) the second
+ one is as "shared".
+ - For example for xHCI: otg-hcds = <&xhci>, <&xhci>;
+ - For example for EHCI/OHCI: otg-hcds = <&ehci>, <&ohci>;
+ - For example for just EHCI: otg-hcds = <&ehci>;
This is an attribute to a USB controller such as:
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 741d9d2..9dcf76ac 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -1253,6 +1253,7 @@
compatible = "renesas,usb2-phy-r8a7795";
reg = <0 0xee080200 0 0x700>;
interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>;
+ otg-hcds = <&ehci0>, <&ohci0>;
clocks = <&cpg CPG_MOD 703>;
power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
#phy-cells = <0>;
diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
index 41e762a..9a78482 100644
--- a/drivers/usb/common/usb-otg.c
+++ b/drivers/usb/common/usb-otg.c
@@ -258,7 +258,8 @@ static void usb_otg_flush_wait(struct device *otg_dev)
dev_dbg(otg_dev, "otg: registering pending host/gadget\n");
gadget = &wait->gcd;
- if (gadget)
+ /* I'm not sure but gadget->gadget is possible to be NULL */
+ if (gadget && gadget->gadget)
usb_otg_register_gadget(gadget->gadget, gadget->ops);
host = &wait->primary_hcd;
@@ -567,6 +568,8 @@ struct usb_otg *usb_otg_register(struct device *dev,
{
struct usb_otg *otg;
struct otg_wait_data *wait;
+ struct device_node *np;
+ struct platform_device *pdev;
int ret = 0;
if (!dev || !config || !config->fsm_ops)
@@ -616,6 +619,40 @@ struct usb_otg *usb_otg_register(struct device *dev,
list_add_tail(&otg->list, &otg_list);
mutex_unlock(&otg_list_mutex);
+ /* Get primary hcd device (mandatory) */
+ np = of_parse_phandle(dev->of_node, "otg-hcds", 0);
+ if (!np) {
+ dev_err(dev, "no otg-hcds\n");
+ ret = -EINVAL;
+ goto err_dt;
+ }
+ pdev = of_find_device_by_node(np);
+ of_node_put(np);
+ if (!pdev) {
+ dev_err(dev, "coulnd't get primary hcd device\n");
+ ret = -ENODEV;
+ goto err_dt;
+ }
+ otg->primary_dev = &pdev->dev;
+
+ /* Get shared hcd device (optional) */
+ np = of_parse_phandle(dev->of_node, "otg-hcds", 1);
+ if (np) {
+ pdev = of_find_device_by_node(np);
+ of_node_put(np);
+ if (!pdev) {
+ dev_err(dev, "coulnd't get shared hcd device\n");
+ ret = -ENODEV;
+ goto err_dt;
+ }
+ otg->shared_dev = &pdev->dev;
+ } else {
+ dev_dbg(dev, "no shared hcd\n");
+ }
+
+ if (otg->primary_dev != otg->shared_dev)
+ otg->flags |= OTG_FLAG_SHARED_IS_2ND_PRIMARY;
+
/* were we in wait list? */
mutex_lock(&wait_list_mutex);
wait = usb_otg_get_wait(dev);
@@ -627,6 +664,8 @@ struct usb_otg *usb_otg_register(struct device *dev,
return otg;
+err_dt:
+ destroy_workqueue(otg->wq);
err_wq:
kfree(otg);
unlock:
@@ -822,50 +861,42 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
/* HCD will be started by OTG fsm when needed */
mutex_lock(&otg->fsm.lock);
- if (otg->primary_hcd.hcd) {
- /* probably a shared HCD ? */
- if (usb_otg_hcd_is_primary_hcd(hcd)) {
- dev_err(otg_dev, "otg: primary host already registered\n");
- goto err;
+ if (!otg->primary_hcd.hcd) {
+ dev_info(hcd_dev, "%s: primary %s, now %s\n", __func__,
+ dev_name(otg->primary_dev),
+ dev_name(hcd->self.controller));
+ if (otg->primary_dev == hcd->self.controller) {
+ otg->primary_hcd.hcd = hcd;
+ otg->primary_hcd.irqnum = irqnum;
+ otg->primary_hcd.irqflags = irqflags;
+ otg->primary_hcd.ops = ops;
+ otg->hcd_ops = ops;
+ dev_info(otg_dev, "otg: primary host %s registered\n",
+ dev_name(hcd->self.controller));
}
+ }
- if (hcd->shared_hcd == otg->primary_hcd.hcd) {
- if (otg->shared_hcd.hcd) {
- dev_err(otg_dev, "otg: shared host already registered\n");
- goto err;
- }
-
+ if (!otg->shared_hcd.hcd && (!usb_otg_hcd_is_primary_hcd(hcd) ||
+ otg->flags & OTG_FLAG_SHARED_IS_2ND_PRIMARY)) {
+ dev_info(hcd_dev, "%s: shared %s, now %s\n", __func__,
+ dev_name(otg->shared_dev),
+ dev_name(hcd->self.controller));
+ if (otg->shared_dev == hcd->self.controller) {
otg->shared_hcd.hcd = hcd;
otg->shared_hcd.irqnum = irqnum;
otg->shared_hcd.irqflags = irqflags;
otg->shared_hcd.ops = ops;
dev_info(otg_dev, "otg: shared host %s registered\n",
dev_name(hcd->self.controller));
- } else {
- dev_err(otg_dev, "otg: invalid shared host %s\n",
- dev_name(hcd->self.controller));
- goto err;
- }
- } else {
- if (!usb_otg_hcd_is_primary_hcd(hcd)) {
- dev_err(otg_dev, "otg: primary host must be registered first\n");
- goto err;
}
-
- otg->primary_hcd.hcd = hcd;
- otg->primary_hcd.irqnum = irqnum;
- otg->primary_hcd.irqflags = irqflags;
- otg->primary_hcd.ops = ops;
- otg->hcd_ops = ops;
- dev_info(otg_dev, "otg: primary host %s registered\n",
- dev_name(hcd->self.controller));
}
/*
* we're ready only if we have shared HCD
* or we don't need shared HCD.
*/
- if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
+ if (otg->primary_hcd.hcd && (!otg->shared_dev ||
+ (otg->shared_dev && otg->shared_hcd.hcd))) {
otg->host = hcd_to_bus(hcd);
/* FIXME: set bus->otg_port if this is true OTG port with HNP */
@@ -878,10 +909,6 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
mutex_unlock(&otg->fsm.lock);
return 0;
-
-err:
- mutex_unlock(&otg->fsm.lock);
- return -EINVAL;
}
EXPORT_SYMBOL_GPL(usb_otg_register_hcd);
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index b094352..ed08865 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -51,6 +51,8 @@ struct otg_hcd {
* @fsm: otg finite state machine
* @hcd_ops: host controller interface
* ------- internal use only -------
+ * @primary_dev: primary host device for matching
+ * @shared_dev: (optional) shared or other primary host device for matching
* @primary_hcd: primary host state and interface
* @shared_hcd: shared host state and interface
* @gadget_ops: gadget controller interface
@@ -75,6 +77,8 @@ struct usb_otg {
struct otg_hcd_ops *hcd_ops;
/* internal use only */
+ struct device *primary_dev;
+ struct device *shared_dev;
struct otg_hcd primary_hcd;
struct otg_hcd shared_hcd;
struct otg_gadget_ops *gadget_ops;
@@ -84,6 +88,7 @@ struct usb_otg {
u32 flags;
#define OTG_FLAG_GADGET_RUNNING (1 << 0)
#define OTG_FLAG_HOST_RUNNING (1 << 1)
+#define OTG_FLAG_SHARED_IS_2ND_PRIMARY (1 << 2)
/* use otg->fsm.lock for serializing access */
/*------------- deprecated interface -----------------------------*/
[toc] | [prev] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-11 13:00 +0200 |
| Subject | Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <rmHJw-4qq-9@gated-at.bofh.it> |
| In reply to | #1374169 |
On 08/04/16 14:22, Yoshihiro Shimoda wrote:
> Hi,
>
>> From: Roger Quadros
>> Sent: Thursday, April 07, 2016 8:45 PM
>>
>> Hi,
>>
>> On 07/04/16 11:52, Yoshihiro Shimoda wrote:
>>> Hi,
>>>
>>>> From: Roger Quadros
>>>> Sent: Tuesday, April 05, 2016 11:05 PM
> < snip >
>>> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
>>> index 41e762a..4d7f043 100644
>>> --- a/drivers/usb/common/usb-otg.c
>>> +++ b/drivers/usb/common/usb-otg.c
>>> @@ -825,11 +825,16 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
>>> if (otg->primary_hcd.hcd) {
>>> /* probably a shared HCD ? */
>>> if (usb_otg_hcd_is_primary_hcd(hcd)) {
>>> + if (hcd->driver->flags & HCD_USB11) {
>>> + dev_info(otg_dev, "this assumes usb 1.1 hc is as shared_hcd\n");
>>> + goto check_shared_hcd;
>>> + }
>>> dev_err(otg_dev, "otg: primary host already registered\n");
>>> goto err;
>>> }
>>>
>>> if (hcd->shared_hcd == otg->primary_hcd.hcd) {
>>> +check_shared_hcd:
>>> if (otg->shared_hcd.hcd) {
>>> dev_err(otg_dev, "otg: shared host already registered\n");
>>> goto err;
>>>
>>> What do you think this local hack?
>>
>> Is it guaranteed that EHCI hcd registers before OHCI hcd?
>
> Thank you for the comment. No, it is not guaranteed.
>
>> If not we need to improve the code still.
>> We will also need to remove the constraint that primary_hcd must be registered
>> first in usb_otg_register_hcd(). I think that constraint is no longer
>> needed anyways.
>
> I got it.
> So, I made a patch to avoid the constraint using an additional property "otg-hcds".
> The patch is in this end of email. What do you think about the patch?
This might only solve the issue for device tree but what about non-device tree?
We need to deal with both cases.
>
>> If EHCI & OHCI HCDs register before OTG driver then things will break unless
>> we fix usb_otg_hcd_wait_add(). We need to add this HCD_USB11 check there to
>> populate wait->shared_hcd.
>
> I see. In my environment, since EHCI & OHCI HCDs need phy driver and phy driver
> will calls usb_otg_register(), the order is right. In other words,
> EHCI & OHCI HCDs never register before OTG driver because even if EHCI driver
> is probed first, the driver will be deferred (EHCI driver needs the phy driver).
But still we cannot assume this is true for all platforms. OTG driver can also
be a separate entity than PHY driver.
>
>>> I also wonder if array of hcd may be good for both xHCI and EHCI/OHCI.
>>> For example of xHCI:
>>> - otg->hcds[0] = primary_hcd
>>> - otg->hcds[1] = shared_hcd
>>>
>>> For example of EHCI/OHCI:
>>> - otg->hcds[0] = primary_hcd of EHCI
>>> - otg->hcds[1] = primary_hcd of OHCI
>>
>> The bigger problem is that how do we know in the OHCI/EHCI case that we need to wait
>> for both of them before starting the OTG FSM?
>> Some systems might use just OHCI or just EHCI.
>>
>> There is no guarantee that OTG driver registers before the HCDs so this piece
>> of information must come from the HCD itself. i.e. whether it needs a companion or not.
>
> I understood these problems. I wonder if my patch can resolve these problems.
>
> Best regards,
> Yoshihiro Shimoda
> ---
> diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt
> index f6866c1..518b9eb 100644
> --- a/Documentation/devicetree/bindings/usb/generic.txt
> +++ b/Documentation/devicetree/bindings/usb/generic.txt
> @@ -27,6 +27,12 @@ Optional properties:
> - otg-controller: phandle to otg controller. Host or gadget controllers can
> contain this property to link it to a particular OTG
> controller.
> + - otg-hcds: phandle to host controller(s). An OTG controller can contain this
> + property. The first one is as "primary", and (optional) the second
> + one is as "shared".
> + - For example for xHCI: otg-hcds = <&xhci>, <&xhci>;
> + - For example for EHCI/OHCI: otg-hcds = <&ehci>, <&ohci>;
> + - For example for just EHCI: otg-hcds = <&ehci>;
>
This is kind of duplicating the information. We are already specifying in the
hcd nodes as to which otg controller it is linked to.
Instead, how about just adding a boolean property in the otg node saying that
HCD needs companion. e.g.
hcd-needs-compainion: must be present if otg controller is dealing with
EHCI host controller that needs a companion OHCI host controller.
This can also be added in struct usb_otg_config so that it can deal with non-DT cases.
So if this property is true, the OTG core will wait for 2 primary HCDs to be registered.
cheers,
-roger
> This is an attribute to a USB controller such as:
>
> diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
> index 741d9d2..9dcf76ac 100644
> --- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
> +++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
> @@ -1253,6 +1253,7 @@
> compatible = "renesas,usb2-phy-r8a7795";
> reg = <0 0xee080200 0 0x700>;
> interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>;
> + otg-hcds = <&ehci0>, <&ohci0>;
> clocks = <&cpg CPG_MOD 703>;
> power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
> #phy-cells = <0>;
> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> index 41e762a..9a78482 100644
> --- a/drivers/usb/common/usb-otg.c
> +++ b/drivers/usb/common/usb-otg.c
> @@ -258,7 +258,8 @@ static void usb_otg_flush_wait(struct device *otg_dev)
>
> dev_dbg(otg_dev, "otg: registering pending host/gadget\n");
> gadget = &wait->gcd;
> - if (gadget)
> + /* I'm not sure but gadget->gadget is possible to be NULL */
> + if (gadget && gadget->gadget)
> usb_otg_register_gadget(gadget->gadget, gadget->ops);
>
> host = &wait->primary_hcd;
> @@ -567,6 +568,8 @@ struct usb_otg *usb_otg_register(struct device *dev,
> {
> struct usb_otg *otg;
> struct otg_wait_data *wait;
> + struct device_node *np;
> + struct platform_device *pdev;
> int ret = 0;
>
> if (!dev || !config || !config->fsm_ops)
> @@ -616,6 +619,40 @@ struct usb_otg *usb_otg_register(struct device *dev,
> list_add_tail(&otg->list, &otg_list);
> mutex_unlock(&otg_list_mutex);
>
> + /* Get primary hcd device (mandatory) */
> + np = of_parse_phandle(dev->of_node, "otg-hcds", 0);
> + if (!np) {
> + dev_err(dev, "no otg-hcds\n");
> + ret = -EINVAL;
> + goto err_dt;
> + }
> + pdev = of_find_device_by_node(np);
> + of_node_put(np);
> + if (!pdev) {
> + dev_err(dev, "coulnd't get primary hcd device\n");
> + ret = -ENODEV;
> + goto err_dt;
> + }
> + otg->primary_dev = &pdev->dev;
> +
> + /* Get shared hcd device (optional) */
> + np = of_parse_phandle(dev->of_node, "otg-hcds", 1);
> + if (np) {
> + pdev = of_find_device_by_node(np);
> + of_node_put(np);
> + if (!pdev) {
> + dev_err(dev, "coulnd't get shared hcd device\n");
> + ret = -ENODEV;
> + goto err_dt;
> + }
> + otg->shared_dev = &pdev->dev;
> + } else {
> + dev_dbg(dev, "no shared hcd\n");
> + }
> +
> + if (otg->primary_dev != otg->shared_dev)
> + otg->flags |= OTG_FLAG_SHARED_IS_2ND_PRIMARY;
> +
> /* were we in wait list? */
> mutex_lock(&wait_list_mutex);
> wait = usb_otg_get_wait(dev);
> @@ -627,6 +664,8 @@ struct usb_otg *usb_otg_register(struct device *dev,
>
> return otg;
>
> +err_dt:
> + destroy_workqueue(otg->wq);
> err_wq:
> kfree(otg);
> unlock:
> @@ -822,50 +861,42 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
>
> /* HCD will be started by OTG fsm when needed */
> mutex_lock(&otg->fsm.lock);
> - if (otg->primary_hcd.hcd) {
> - /* probably a shared HCD ? */
> - if (usb_otg_hcd_is_primary_hcd(hcd)) {
> - dev_err(otg_dev, "otg: primary host already registered\n");
> - goto err;
> + if (!otg->primary_hcd.hcd) {
> + dev_info(hcd_dev, "%s: primary %s, now %s\n", __func__,
> + dev_name(otg->primary_dev),
> + dev_name(hcd->self.controller));
> + if (otg->primary_dev == hcd->self.controller) {
> + otg->primary_hcd.hcd = hcd;
> + otg->primary_hcd.irqnum = irqnum;
> + otg->primary_hcd.irqflags = irqflags;
> + otg->primary_hcd.ops = ops;
> + otg->hcd_ops = ops;
> + dev_info(otg_dev, "otg: primary host %s registered\n",
> + dev_name(hcd->self.controller));
> }
> + }
>
> - if (hcd->shared_hcd == otg->primary_hcd.hcd) {
> - if (otg->shared_hcd.hcd) {
> - dev_err(otg_dev, "otg: shared host already registered\n");
> - goto err;
> - }
> -
> + if (!otg->shared_hcd.hcd && (!usb_otg_hcd_is_primary_hcd(hcd) ||
> + otg->flags & OTG_FLAG_SHARED_IS_2ND_PRIMARY)) {
> + dev_info(hcd_dev, "%s: shared %s, now %s\n", __func__,
> + dev_name(otg->shared_dev),
> + dev_name(hcd->self.controller));
> + if (otg->shared_dev == hcd->self.controller) {
> otg->shared_hcd.hcd = hcd;
> otg->shared_hcd.irqnum = irqnum;
> otg->shared_hcd.irqflags = irqflags;
> otg->shared_hcd.ops = ops;
> dev_info(otg_dev, "otg: shared host %s registered\n",
> dev_name(hcd->self.controller));
> - } else {
> - dev_err(otg_dev, "otg: invalid shared host %s\n",
> - dev_name(hcd->self.controller));
> - goto err;
> - }
> - } else {
> - if (!usb_otg_hcd_is_primary_hcd(hcd)) {
> - dev_err(otg_dev, "otg: primary host must be registered first\n");
> - goto err;
> }
> -
> - otg->primary_hcd.hcd = hcd;
> - otg->primary_hcd.irqnum = irqnum;
> - otg->primary_hcd.irqflags = irqflags;
> - otg->primary_hcd.ops = ops;
> - otg->hcd_ops = ops;
> - dev_info(otg_dev, "otg: primary host %s registered\n",
> - dev_name(hcd->self.controller));
> }
>
> /*
> * we're ready only if we have shared HCD
> * or we don't need shared HCD.
> */
> - if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> + if (otg->primary_hcd.hcd && (!otg->shared_dev ||
> + (otg->shared_dev && otg->shared_hcd.hcd))) {
> otg->host = hcd_to_bus(hcd);
> /* FIXME: set bus->otg_port if this is true OTG port with HNP */
>
> @@ -878,10 +909,6 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> mutex_unlock(&otg->fsm.lock);
>
> return 0;
> -
> -err:
> - mutex_unlock(&otg->fsm.lock);
> - return -EINVAL;
> }
> EXPORT_SYMBOL_GPL(usb_otg_register_hcd);
>
> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
> index b094352..ed08865 100644
> --- a/include/linux/usb/otg.h
> +++ b/include/linux/usb/otg.h
> @@ -51,6 +51,8 @@ struct otg_hcd {
> * @fsm: otg finite state machine
> * @hcd_ops: host controller interface
> * ------- internal use only -------
> + * @primary_dev: primary host device for matching
> + * @shared_dev: (optional) shared or other primary host device for matching
> * @primary_hcd: primary host state and interface
> * @shared_hcd: shared host state and interface
> * @gadget_ops: gadget controller interface
> @@ -75,6 +77,8 @@ struct usb_otg {
> struct otg_hcd_ops *hcd_ops;
>
> /* internal use only */
> + struct device *primary_dev;
> + struct device *shared_dev;
> struct otg_hcd primary_hcd;
> struct otg_hcd shared_hcd;
> struct otg_gadget_ops *gadget_ops;
> @@ -84,6 +88,7 @@ struct usb_otg {
> u32 flags;
> #define OTG_FLAG_GADGET_RUNNING (1 << 0)
> #define OTG_FLAG_HOST_RUNNING (1 << 1)
> +#define OTG_FLAG_SHARED_IS_2ND_PRIMARY (1 << 2)
> /* use otg->fsm.lock for serializing access */
>
> /*------------- deprecated interface -----------------------------*/
>
>
[toc] | [prev] | [next] | [standalone]
| From | Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
|---|---|
| Date | 2016-04-14 10:40 +0200 |
| Subject | RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <rnKYF-7jf-1@gated-at.bofh.it> |
| In reply to | #1375684 |
Hi,
> From: Roger Quadros
> Sent: Monday, April 11, 2016 7:55 PM
>
> On 08/04/16 14:22, Yoshihiro Shimoda wrote:
> > Hi,
> >
> >> From: Roger Quadros
> >> Sent: Thursday, April 07, 2016 8:45 PM
> >>
> >> Hi,
> >>
> >> On 07/04/16 11:52, Yoshihiro Shimoda wrote:
> >>> Hi,
> >>>
> >>>> From: Roger Quadros
> >>>> Sent: Tuesday, April 05, 2016 11:05 PM
> > < snip >
> >>> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> >>> index 41e762a..4d7f043 100644
> >>> --- a/drivers/usb/common/usb-otg.c
> >>> +++ b/drivers/usb/common/usb-otg.c
> >>> @@ -825,11 +825,16 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> >>> if (otg->primary_hcd.hcd) {
> >>> /* probably a shared HCD ? */
> >>> if (usb_otg_hcd_is_primary_hcd(hcd)) {
> >>> + if (hcd->driver->flags & HCD_USB11) {
> >>> + dev_info(otg_dev, "this assumes usb 1.1 hc is as shared_hcd\n");
> >>> + goto check_shared_hcd;
> >>> + }
> >>> dev_err(otg_dev, "otg: primary host already registered\n");
> >>> goto err;
> >>> }
> >>>
> >>> if (hcd->shared_hcd == otg->primary_hcd.hcd) {
> >>> +check_shared_hcd:
> >>> if (otg->shared_hcd.hcd) {
> >>> dev_err(otg_dev, "otg: shared host already registered\n");
> >>> goto err;
> >>>
> >>> What do you think this local hack?
> >>
> >> Is it guaranteed that EHCI hcd registers before OHCI hcd?
> >
> > Thank you for the comment. No, it is not guaranteed.
> >
> >> If not we need to improve the code still.
> >> We will also need to remove the constraint that primary_hcd must be registered
> >> first in usb_otg_register_hcd(). I think that constraint is no longer
> >> needed anyways.
> >
> > I got it.
> > So, I made a patch to avoid the constraint using an additional property "otg-hcds".
> > The patch is in this end of email. What do you think about the patch?
>
> This might only solve the issue for device tree but what about non-device tree?
> We need to deal with both cases.
Thank you for the comment. I got it.
> >> If EHCI & OHCI HCDs register before OTG driver then things will break unless
> >> we fix usb_otg_hcd_wait_add(). We need to add this HCD_USB11 check there to
> >> populate wait->shared_hcd.
> >
> > I see. In my environment, since EHCI & OHCI HCDs need phy driver and phy driver
> > will calls usb_otg_register(), the order is right. In other words,
> > EHCI & OHCI HCDs never register before OTG driver because even if EHCI driver
> > is probed first, the driver will be deferred (EHCI driver needs the phy driver).
>
> But still we cannot assume this is true for all platforms. OTG driver can also
> be a separate entity than PHY driver.
I understood it.
> >>> I also wonder if array of hcd may be good for both xHCI and EHCI/OHCI.
> >>> For example of xHCI:
> >>> - otg->hcds[0] = primary_hcd
> >>> - otg->hcds[1] = shared_hcd
> >>>
> >>> For example of EHCI/OHCI:
> >>> - otg->hcds[0] = primary_hcd of EHCI
> >>> - otg->hcds[1] = primary_hcd of OHCI
> >>
> >> The bigger problem is that how do we know in the OHCI/EHCI case that we need to wait
> >> for both of them before starting the OTG FSM?
> >> Some systems might use just OHCI or just EHCI.
> >>
> >> There is no guarantee that OTG driver registers before the HCDs so this piece
> >> of information must come from the HCD itself. i.e. whether it needs a companion or not.
> >
> > I understood these problems. I wonder if my patch can resolve these problems.
> >
> > Best regards,
> > Yoshihiro Shimoda
> > ---
> > diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt
> > index f6866c1..518b9eb 100644
> > --- a/Documentation/devicetree/bindings/usb/generic.txt
> > +++ b/Documentation/devicetree/bindings/usb/generic.txt
> > @@ -27,6 +27,12 @@ Optional properties:
> > - otg-controller: phandle to otg controller. Host or gadget controllers can
> > contain this property to link it to a particular OTG
> > controller.
> > + - otg-hcds: phandle to host controller(s). An OTG controller can contain this
> > + property. The first one is as "primary", and (optional) the second
> > + one is as "shared".
> > + - For example for xHCI: otg-hcds = <&xhci>, <&xhci>;
> > + - For example for EHCI/OHCI: otg-hcds = <&ehci>, <&ohci>;
> > + - For example for just EHCI: otg-hcds = <&ehci>;
> >
>
> This is kind of duplicating the information. We are already specifying in the
> hcd nodes as to which otg controller it is linked to.
>
> Instead, how about just adding a boolean property in the otg node saying that
> HCD needs companion. e.g.
> hcd-needs-compainion: must be present if otg controller is dealing with
> EHCI host controller that needs a companion OHCI host controller.
>
> This can also be added in struct usb_otg_config so that it can deal with non-DT cases.
>
> So if this property is true, the OTG core will wait for 2 primary HCDs to be registered.
Thank you for your suggestion. I agree with you.
So, I made such a patch which. It is simple than my previous patch.
What do you think?
Best regards,
Yoshihiro Shimoda
---
Documentation/devicetree/bindings/usb/generic.txt | 3 +++
drivers/usb/common/common.c | 2 ++
drivers/usb/common/usb-otg.c | 11 +++++++----
include/linux/usb/otg.h | 2 ++
4 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt
index f6866c1..1db1c33 100644
--- a/Documentation/devicetree/bindings/usb/generic.txt
+++ b/Documentation/devicetree/bindings/usb/generic.txt
@@ -27,6 +27,9 @@ Optional properties:
- otg-controller: phandle to otg controller. Host or gadget controllers can
contain this property to link it to a particular OTG
controller.
+ - hcd-needs-companion: must be present if otg controller is dealing with
+ EHCI host controller that needs a companion OHCI host
+ controller.
This is an attribute to a USB controller such as:
diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index e3d0161..8b74715 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -233,6 +233,8 @@ int of_usb_update_otg_caps(struct device_node *np,
if (of_find_property(np, "adp-disable", NULL) ||
(otg_caps->otg_rev < 0x0200))
otg_caps->adp_support = false;
+ if (of_find_property(np, "hcd-needs-companion", NULL))
+ otg_caps->needs_companion = true;
return 0;
}
diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
index 41e762a..e0df839 100644
--- a/drivers/usb/common/usb-otg.c
+++ b/drivers/usb/common/usb-otg.c
@@ -823,13 +823,15 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
/* HCD will be started by OTG fsm when needed */
mutex_lock(&otg->fsm.lock);
if (otg->primary_hcd.hcd) {
- /* probably a shared HCD ? */
- if (usb_otg_hcd_is_primary_hcd(hcd)) {
+ /* probably a shared HCD or a companion OHCI HCD ? */
+ if (!otg->caps->needs_companion &&
+ usb_otg_hcd_is_primary_hcd(hcd)) {
dev_err(otg_dev, "otg: primary host already registered\n");
goto err;
}
- if (hcd->shared_hcd == otg->primary_hcd.hcd) {
+ if (otg->caps->needs_companion ||
+ (hcd->shared_hcd == otg->primary_hcd.hcd)) {
if (otg->shared_hcd.hcd) {
dev_err(otg_dev, "otg: shared host already registered\n");
goto err;
@@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
* we're ready only if we have shared HCD
* or we don't need shared HCD.
*/
- if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
+ if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
+ !otg->primary_hcd.hcd->shared_hcd)) {
otg->host = hcd_to_bus(hcd);
/* FIXME: set bus->otg_port if this is true OTG port with HNP */
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index b094352..64a7db8 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -112,12 +112,14 @@ struct usb_otg {
* @hnp_support: Indicates if the device supports HNP.
* @srp_support: Indicates if the device supports SRP.
* @adp_support: Indicates if the device supports ADP.
+ * @needs_companion: Indicates if the device needs a companion controller.
*/
struct usb_otg_caps {
u16 otg_rev;
bool hnp_support;
bool srp_support;
bool adp_support;
+ bool needs_companion;
};
/**
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-14 13:10 +0200 |
| Subject | Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <rnNjQ-J5-19@gated-at.bofh.it> |
| In reply to | #1378596 |
On 14/04/16 11:36, Yoshihiro Shimoda wrote:
> Hi,
>
>> From: Roger Quadros
>> Sent: Monday, April 11, 2016 7:55 PM
>>
>> On 08/04/16 14:22, Yoshihiro Shimoda wrote:
>>> Hi,
>>>
>>>> From: Roger Quadros
>>>> Sent: Thursday, April 07, 2016 8:45 PM
>>>>
>>>> Hi,
>>>>
>>>> On 07/04/16 11:52, Yoshihiro Shimoda wrote:
>>>>> Hi,
>>>>>
>>>>>> From: Roger Quadros
>>>>>> Sent: Tuesday, April 05, 2016 11:05 PM
>>> < snip >
>>>>> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
>>>>> index 41e762a..4d7f043 100644
>>>>> --- a/drivers/usb/common/usb-otg.c
>>>>> +++ b/drivers/usb/common/usb-otg.c
>>>>> @@ -825,11 +825,16 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
>>>>> if (otg->primary_hcd.hcd) {
>>>>> /* probably a shared HCD ? */
>>>>> if (usb_otg_hcd_is_primary_hcd(hcd)) {
>>>>> + if (hcd->driver->flags & HCD_USB11) {
>>>>> + dev_info(otg_dev, "this assumes usb 1.1 hc is as shared_hcd\n");
>>>>> + goto check_shared_hcd;
>>>>> + }
>>>>> dev_err(otg_dev, "otg: primary host already registered\n");
>>>>> goto err;
>>>>> }
>>>>>
>>>>> if (hcd->shared_hcd == otg->primary_hcd.hcd) {
>>>>> +check_shared_hcd:
>>>>> if (otg->shared_hcd.hcd) {
>>>>> dev_err(otg_dev, "otg: shared host already registered\n");
>>>>> goto err;
>>>>>
>>>>> What do you think this local hack?
>>>>
>>>> Is it guaranteed that EHCI hcd registers before OHCI hcd?
>>>
>>> Thank you for the comment. No, it is not guaranteed.
>>>
>>>> If not we need to improve the code still.
>>>> We will also need to remove the constraint that primary_hcd must be registered
>>>> first in usb_otg_register_hcd(). I think that constraint is no longer
>>>> needed anyways.
>>>
>>> I got it.
>>> So, I made a patch to avoid the constraint using an additional property "otg-hcds".
>>> The patch is in this end of email. What do you think about the patch?
>>
>> This might only solve the issue for device tree but what about non-device tree?
>> We need to deal with both cases.
>
> Thank you for the comment. I got it.
>
>>>> If EHCI & OHCI HCDs register before OTG driver then things will break unless
>>>> we fix usb_otg_hcd_wait_add(). We need to add this HCD_USB11 check there to
>>>> populate wait->shared_hcd.
>>>
>>> I see. In my environment, since EHCI & OHCI HCDs need phy driver and phy driver
>>> will calls usb_otg_register(), the order is right. In other words,
>>> EHCI & OHCI HCDs never register before OTG driver because even if EHCI driver
>>> is probed first, the driver will be deferred (EHCI driver needs the phy driver).
>>
>> But still we cannot assume this is true for all platforms. OTG driver can also
>> be a separate entity than PHY driver.
>
> I understood it.
>
>>>>> I also wonder if array of hcd may be good for both xHCI and EHCI/OHCI.
>>>>> For example of xHCI:
>>>>> - otg->hcds[0] = primary_hcd
>>>>> - otg->hcds[1] = shared_hcd
>>>>>
>>>>> For example of EHCI/OHCI:
>>>>> - otg->hcds[0] = primary_hcd of EHCI
>>>>> - otg->hcds[1] = primary_hcd of OHCI
>>>>
>>>> The bigger problem is that how do we know in the OHCI/EHCI case that we need to wait
>>>> for both of them before starting the OTG FSM?
>>>> Some systems might use just OHCI or just EHCI.
>>>>
>>>> There is no guarantee that OTG driver registers before the HCDs so this piece
>>>> of information must come from the HCD itself. i.e. whether it needs a companion or not.
>>>
>>> I understood these problems. I wonder if my patch can resolve these problems.
>>>
>>> Best regards,
>>> Yoshihiro Shimoda
>>> ---
>>> diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt
>>> index f6866c1..518b9eb 100644
>>> --- a/Documentation/devicetree/bindings/usb/generic.txt
>>> +++ b/Documentation/devicetree/bindings/usb/generic.txt
>>> @@ -27,6 +27,12 @@ Optional properties:
>>> - otg-controller: phandle to otg controller. Host or gadget controllers can
>>> contain this property to link it to a particular OTG
>>> controller.
>>> + - otg-hcds: phandle to host controller(s). An OTG controller can contain this
>>> + property. The first one is as "primary", and (optional) the second
>>> + one is as "shared".
>>> + - For example for xHCI: otg-hcds = <&xhci>, <&xhci>;
>>> + - For example for EHCI/OHCI: otg-hcds = <&ehci>, <&ohci>;
>>> + - For example for just EHCI: otg-hcds = <&ehci>;
>>>
>>
>> This is kind of duplicating the information. We are already specifying in the
>> hcd nodes as to which otg controller it is linked to.
>>
>> Instead, how about just adding a boolean property in the otg node saying that
>> HCD needs companion. e.g.
>> hcd-needs-compainion: must be present if otg controller is dealing with
>> EHCI host controller that needs a companion OHCI host controller.
>>
>> This can also be added in struct usb_otg_config so that it can deal with non-DT cases.
>>
>> So if this property is true, the OTG core will wait for 2 primary HCDs to be registered.
>
> Thank you for your suggestion. I agree with you.
> So, I made such a patch which. It is simple than my previous patch.
> What do you think?
>
> Best regards,
> Yoshihiro Shimoda
>
> ---
> Documentation/devicetree/bindings/usb/generic.txt | 3 +++
> drivers/usb/common/common.c | 2 ++
> drivers/usb/common/usb-otg.c | 11 +++++++----
> include/linux/usb/otg.h | 2 ++
> 4 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt
> index f6866c1..1db1c33 100644
> --- a/Documentation/devicetree/bindings/usb/generic.txt
> +++ b/Documentation/devicetree/bindings/usb/generic.txt
> @@ -27,6 +27,9 @@ Optional properties:
> - otg-controller: phandle to otg controller. Host or gadget controllers can
> contain this property to link it to a particular OTG
> controller.
> + - hcd-needs-companion: must be present if otg controller is dealing with
> + EHCI host controller that needs a companion OHCI host
> + controller.
>
> This is an attribute to a USB controller such as:
>
> diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
> index e3d0161..8b74715 100644
> --- a/drivers/usb/common/common.c
> +++ b/drivers/usb/common/common.c
> @@ -233,6 +233,8 @@ int of_usb_update_otg_caps(struct device_node *np,
> if (of_find_property(np, "adp-disable", NULL) ||
> (otg_caps->otg_rev < 0x0200))
> otg_caps->adp_support = false;
> + if (of_find_property(np, "hcd-needs-companion", NULL))
> + otg_caps->needs_companion = true;
I'm not sure if otg_caps structure is a right place for this. Maybe Peter can confirm
if this is OK or not.
I was thinking more about adding this bit in the otg_config structure.
>
> return 0;
> }
> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> index 41e762a..e0df839 100644
> --- a/drivers/usb/common/usb-otg.c
> +++ b/drivers/usb/common/usb-otg.c
> @@ -823,13 +823,15 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> /* HCD will be started by OTG fsm when needed */
> mutex_lock(&otg->fsm.lock);
> if (otg->primary_hcd.hcd) {
> - /* probably a shared HCD ? */
> - if (usb_otg_hcd_is_primary_hcd(hcd)) {
> + /* probably a shared HCD or a companion OHCI HCD ? */
> + if (!otg->caps->needs_companion &&
> + usb_otg_hcd_is_primary_hcd(hcd)) {
> dev_err(otg_dev, "otg: primary host already registered\n");
> goto err;
> }
>
> - if (hcd->shared_hcd == otg->primary_hcd.hcd) {
> + if (otg->caps->needs_companion ||
> + (hcd->shared_hcd == otg->primary_hcd.hcd)) {
> if (otg->shared_hcd.hcd) {
> dev_err(otg_dev, "otg: shared host already registered\n");
> goto err;
> @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> * we're ready only if we have shared HCD
> * or we don't need shared HCD.
> */
> - if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> + if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
> + !otg->primary_hcd.hcd->shared_hcd)) {
> otg->host = hcd_to_bus(hcd);
> /* FIXME: set bus->otg_port if this is true OTG port with HNP */
>
These changes look good to me. Thanks.
> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
> index b094352..64a7db8 100644
> --- a/include/linux/usb/otg.h
> +++ b/include/linux/usb/otg.h
> @@ -112,12 +112,14 @@ struct usb_otg {
> * @hnp_support: Indicates if the device supports HNP.
> * @srp_support: Indicates if the device supports SRP.
> * @adp_support: Indicates if the device supports ADP.
> + * @needs_companion: Indicates if the device needs a companion controller.
Description is not exact. How about this.
"Indicates if host controller needs a companion controller"
Is hcd_needs_companion is better than just needs_companion?
> */
> struct usb_otg_caps {
> u16 otg_rev;
> bool hnp_support;
> bool srp_support;
> bool adp_support;
> + bool needs_companion;
> };
>
> /**
>
cheers,
-roger
[toc] | [prev] | [next] | [standalone]
| From | Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
|---|---|
| Date | 2016-04-14 13:20 +0200 |
| Subject | RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <rnNtw-MQ-19@gated-at.bofh.it> |
| In reply to | #1378691 |
Hi,
> From: Roger Quadros
> Sent: Thursday, April 14, 2016 8:00 PM
>
> On 14/04/16 11:36, Yoshihiro Shimoda wrote:
> > Hi,
> >
< snip >
> > diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
> > index e3d0161..8b74715 100644
> > --- a/drivers/usb/common/common.c
> > +++ b/drivers/usb/common/common.c
> > @@ -233,6 +233,8 @@ int of_usb_update_otg_caps(struct device_node *np,
> > if (of_find_property(np, "adp-disable", NULL) ||
> > (otg_caps->otg_rev < 0x0200))
> > otg_caps->adp_support = false;
> > + if (of_find_property(np, "hcd-needs-companion", NULL))
> > + otg_caps->needs_companion = true;
>
> I'm not sure if otg_caps structure is a right place for this. Maybe Peter can confirm
> if this is OK or not.
>
> I was thinking more about adding this bit in the otg_config structure.
I see. I also think the otg_config is more suitable.
> >
> > return 0;
> > }
> > diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> > index 41e762a..e0df839 100644
> > --- a/drivers/usb/common/usb-otg.c
> > +++ b/drivers/usb/common/usb-otg.c
> > @@ -823,13 +823,15 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> > /* HCD will be started by OTG fsm when needed */
> > mutex_lock(&otg->fsm.lock);
> > if (otg->primary_hcd.hcd) {
> > - /* probably a shared HCD ? */
> > - if (usb_otg_hcd_is_primary_hcd(hcd)) {
> > + /* probably a shared HCD or a companion OHCI HCD ? */
> > + if (!otg->caps->needs_companion &&
> > + usb_otg_hcd_is_primary_hcd(hcd)) {
> > dev_err(otg_dev, "otg: primary host already registered\n");
> > goto err;
> > }
> >
> > - if (hcd->shared_hcd == otg->primary_hcd.hcd) {
> > + if (otg->caps->needs_companion ||
> > + (hcd->shared_hcd == otg->primary_hcd.hcd)) {
> > if (otg->shared_hcd.hcd) {
> > dev_err(otg_dev, "otg: shared host already registered\n");
> > goto err;
> > @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> > * we're ready only if we have shared HCD
> > * or we don't need shared HCD.
> > */
> > - if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> > + if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
> > + !otg->primary_hcd.hcd->shared_hcd)) {
> > otg->host = hcd_to_bus(hcd);
> > /* FIXME: set bus->otg_port if this is true OTG port with HNP */
> >
>
> These changes look good to me. Thanks.
Thank you for the comment.
If we change the "needs_companion" place to the otg_config,
do we need to add a flag into the otg, instead of otg->caps?
> > diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
> > index b094352..64a7db8 100644
> > --- a/include/linux/usb/otg.h
> > +++ b/include/linux/usb/otg.h
> > @@ -112,12 +112,14 @@ struct usb_otg {
> > * @hnp_support: Indicates if the device supports HNP.
> > * @srp_support: Indicates if the device supports SRP.
> > * @adp_support: Indicates if the device supports ADP.
> > + * @needs_companion: Indicates if the device needs a companion controller.
>
> Description is not exact. How about this.
> "Indicates if host controller needs a companion controller"
>
> Is hcd_needs_companion is better than just needs_companion?
I agree with you.
So, I will modify my local patch and test it tomorrow.
Best regards,
Yoshihiro Shimoda
>
> > */
> > struct usb_otg_caps {
> > u16 otg_rev;
> > bool hnp_support;
> > bool srp_support;
> > bool adp_support;
> > + bool needs_companion;
> > };
> >
> > /**
> >
>
> cheers,
> -roger
[toc] | [prev] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-14 13:40 +0200 |
| Subject | Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <rnNMS-Ww-15@gated-at.bofh.it> |
| In reply to | #1378698 |
On 14/04/16 14:15, Yoshihiro Shimoda wrote:
> Hi,
>
>> From: Roger Quadros
>> Sent: Thursday, April 14, 2016 8:00 PM
>>
>> On 14/04/16 11:36, Yoshihiro Shimoda wrote:
>>> Hi,
>>>
> < snip >
>>> diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
>>> index e3d0161..8b74715 100644
>>> --- a/drivers/usb/common/common.c
>>> +++ b/drivers/usb/common/common.c
>>> @@ -233,6 +233,8 @@ int of_usb_update_otg_caps(struct device_node *np,
>>> if (of_find_property(np, "adp-disable", NULL) ||
>>> (otg_caps->otg_rev < 0x0200))
>>> otg_caps->adp_support = false;
>>> + if (of_find_property(np, "hcd-needs-companion", NULL))
>>> + otg_caps->needs_companion = true;
>>
>> I'm not sure if otg_caps structure is a right place for this. Maybe Peter can confirm
>> if this is OK or not.
>>
>> I was thinking more about adding this bit in the otg_config structure.
>
> I see. I also think the otg_config is more suitable.
>
>>>
>>> return 0;
>>> }
>>> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
>>> index 41e762a..e0df839 100644
>>> --- a/drivers/usb/common/usb-otg.c
>>> +++ b/drivers/usb/common/usb-otg.c
>>> @@ -823,13 +823,15 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
>>> /* HCD will be started by OTG fsm when needed */
>>> mutex_lock(&otg->fsm.lock);
>>> if (otg->primary_hcd.hcd) {
>>> - /* probably a shared HCD ? */
>>> - if (usb_otg_hcd_is_primary_hcd(hcd)) {
>>> + /* probably a shared HCD or a companion OHCI HCD ? */
>>> + if (!otg->caps->needs_companion &&
>>> + usb_otg_hcd_is_primary_hcd(hcd)) {
>>> dev_err(otg_dev, "otg: primary host already registered\n");
>>> goto err;
>>> }
>>>
>>> - if (hcd->shared_hcd == otg->primary_hcd.hcd) {
>>> + if (otg->caps->needs_companion ||
>>> + (hcd->shared_hcd == otg->primary_hcd.hcd)) {
>>> if (otg->shared_hcd.hcd) {
>>> dev_err(otg_dev, "otg: shared host already registered\n");
>>> goto err;
>>> @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
>>> * we're ready only if we have shared HCD
>>> * or we don't need shared HCD.
>>> */
>>> - if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
>>> + if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
>>> + !otg->primary_hcd.hcd->shared_hcd)) {
>>> otg->host = hcd_to_bus(hcd);
>>> /* FIXME: set bus->otg_port if this is true OTG port with HNP */
>>>
>>
>> These changes look good to me. Thanks.
>
> Thank you for the comment.
> If we change the "needs_companion" place to the otg_config,
> do we need to add a flag into the otg, instead of otg->caps?
Yes we can add a flag in struct usb_otg.
cheers,
-roger
>
>>> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
>>> index b094352..64a7db8 100644
>>> --- a/include/linux/usb/otg.h
>>> +++ b/include/linux/usb/otg.h
>>> @@ -112,12 +112,14 @@ struct usb_otg {
>>> * @hnp_support: Indicates if the device supports HNP.
>>> * @srp_support: Indicates if the device supports SRP.
>>> * @adp_support: Indicates if the device supports ADP.
>>> + * @needs_companion: Indicates if the device needs a companion controller.
>>
>> Description is not exact. How about this.
>> "Indicates if host controller needs a companion controller"
>>
>> Is hcd_needs_companion is better than just needs_companion?
>
> I agree with you.
>
> So, I will modify my local patch and test it tomorrow.
>
> Best regards,
> Yoshihiro Shimoda
>
>>
>>> */
>>> struct usb_otg_caps {
>>> u16 otg_rev;
>>> bool hnp_support;
>>> bool srp_support;
>>> bool adp_support;
>>> + bool needs_companion;
>>> };
>>>
>>> /**
>>>
>>
>> cheers,
>> -roger
[toc] | [prev] | [next] | [standalone]
| From | Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
|---|---|
| Date | 2016-04-15 12:00 +0200 |
| Subject | RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <ro8HF-YX-17@gated-at.bofh.it> |
| In reply to | #1378706 |
Hi,
> From: Roger Quadros
> Sent: Thursday, April 14, 2016 8:32 PM
>
> On 14/04/16 14:15, Yoshihiro Shimoda wrote:
> > Hi,
> >
< snip >
> >>> @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> >>> * we're ready only if we have shared HCD
> >>> * or we don't need shared HCD.
> >>> */
> >>> - if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> >>> + if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
> >>> + !otg->primary_hcd.hcd->shared_hcd)) {
> >>> otg->host = hcd_to_bus(hcd);
> >>> /* FIXME: set bus->otg_port if this is true OTG port with HNP */
> >>>
> >>
> >> These changes look good to me. Thanks.
> >
> > Thank you for the comment.
> > If we change the "needs_companion" place to the otg_config,
> > do we need to add a flag into the otg, instead of otg->caps?
>
> Yes we can add a flag in struct usb_otg.
Thank you for the comment.
I made a fixed patch.
So, should I send this patch to ML after you sent v7 patches?
Or, would you apply this patch before you send v7 patches?
Best regards,
Yoshihiro Shimoda
---
[toc] | [prev] | [next] | [standalone]
| From | Roger Quadros <rogerq@ti.com> |
|---|---|
| Date | 2016-04-15 13:00 +0200 |
| Subject | Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <ro9DK-1Ev-53@gated-at.bofh.it> |
| In reply to | #1379657 |
On 15/04/16 12:59, Yoshihiro Shimoda wrote:
> Hi,
>
>> From: Roger Quadros
>> Sent: Thursday, April 14, 2016 8:32 PM
>>
>> On 14/04/16 14:15, Yoshihiro Shimoda wrote:
>>> Hi,
>>>
> < snip >
>>>>> @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
>>>>> * we're ready only if we have shared HCD
>>>>> * or we don't need shared HCD.
>>>>> */
>>>>> - if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
>>>>> + if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
>>>>> + !otg->primary_hcd.hcd->shared_hcd)) {
>>>>> otg->host = hcd_to_bus(hcd);
>>>>> /* FIXME: set bus->otg_port if this is true OTG port with HNP */
>>>>>
>>>>
>>>> These changes look good to me. Thanks.
>>>
>>> Thank you for the comment.
>>> If we change the "needs_companion" place to the otg_config,
>>> do we need to add a flag into the otg, instead of otg->caps?
>>
>> Yes we can add a flag in struct usb_otg.
>
> Thank you for the comment.
>
> I made a fixed patch.
> So, should I send this patch to ML after you sent v7 patches?
> Or, would you apply this patch before you send v7 patches?
>
Thanks for working on this and testing the series. I will pick your patch
as part of v7.
cheers,
-roger
[toc] | [prev] | [next] | [standalone]
| From | Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
|---|---|
| Date | 2016-04-15 12:10 +0200 |
| Subject | RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <ro8Rk-1jQ-17@gated-at.bofh.it> |
| In reply to | #1378706 |
Hi,
> From: Yoshihiro Shimoda
> Sent: Friday, April 15, 2016 6:59 PM
>
> Hi,
>
> > From: Roger Quadros
> > Sent: Thursday, April 14, 2016 8:32 PM
> >
> > On 14/04/16 14:15, Yoshihiro Shimoda wrote:
> > > Hi,
> > >
> < snip >
> > >>> @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> > >>> * we're ready only if we have shared HCD
> > >>> * or we don't need shared HCD.
> > >>> */
> > >>> - if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> > >>> + if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
> > >>> + !otg->primary_hcd.hcd->shared_hcd)) {
> > >>> otg->host = hcd_to_bus(hcd);
> > >>> /* FIXME: set bus->otg_port if this is true OTG port with HNP */
> > >>>
> > >>
> > >> These changes look good to me. Thanks.
> > >
> > > Thank you for the comment.
> > > If we change the "needs_companion" place to the otg_config,
> > > do we need to add a flag into the otg, instead of otg->caps?
> >
> > Yes we can add a flag in struct usb_otg.
>
> Thank you for the comment.
>
> I made a fixed patch.
> So, should I send this patch to ML after you sent v7 patches?
> Or, would you apply this patch before you send v7 patches?
Oops, I sent this email without my patch...
---
Subject: [PATCH] usb: otg: add hcd companion support
Since some host controller (e.g. EHCI) needs a companion host controller
(e.g. OHCI), this patch adds such a configuration to use it in the OTG
core.
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
Documentation/devicetree/bindings/usb/generic.txt | 3 +++
drivers/usb/common/usb-otg.c | 17 +++++++++++++----
include/linux/usb/otg.h | 7 ++++++-
3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt
index f6866c1..1db1c33 100644
--- a/Documentation/devicetree/bindings/usb/generic.txt
+++ b/Documentation/devicetree/bindings/usb/generic.txt
@@ -27,6 +27,9 @@ Optional properties:
- otg-controller: phandle to otg controller. Host or gadget controllers can
contain this property to link it to a particular OTG
controller.
+ - hcd-needs-companion: must be present if otg controller is dealing with
+ EHCI host controller that needs a companion OHCI host
+ controller.
This is an attribute to a USB controller such as:
diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
index 41e762a..83c8c96 100644
--- a/drivers/usb/common/usb-otg.c
+++ b/drivers/usb/common/usb-otg.c
@@ -20,6 +20,7 @@
#include <linux/list.h>
#include <linux/of.h>
#include <linux/of_platform.h>
+#include <linux/usb/of.h>
#include <linux/usb/otg.h>
#include <linux/usb/gadget.h>
#include <linux/workqueue.h>
@@ -600,6 +601,10 @@ struct usb_otg *usb_otg_register(struct device *dev,
else
INIT_WORK(&otg->work, usb_otg_work);
+ if (of_find_property(dev->of_node, "hcd-needs-companion", NULL) ||
+ config->hcd_needs_companion) /* needs comanion ? */
+ otg->flags |= OTG_FLAG_HCD_NEEDS_COMPANION;
+
otg->wq = create_singlethread_workqueue("usb_otg");
if (!otg->wq) {
dev_err(dev, "otg: %s: can't create workqueue\n",
@@ -823,13 +828,15 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
/* HCD will be started by OTG fsm when needed */
mutex_lock(&otg->fsm.lock);
if (otg->primary_hcd.hcd) {
- /* probably a shared HCD ? */
- if (usb_otg_hcd_is_primary_hcd(hcd)) {
+ /* probably a shared HCD or a companion OHCI HCD ? */
+ if (!(otg->flags & OTG_FLAG_HCD_NEEDS_COMPANION) &&
+ usb_otg_hcd_is_primary_hcd(hcd)) {
dev_err(otg_dev, "otg: primary host already registered\n");
goto err;
}
- if (hcd->shared_hcd == otg->primary_hcd.hcd) {
+ if (otg->flags & OTG_FLAG_HCD_NEEDS_COMPANION ||
+ (hcd->shared_hcd == otg->primary_hcd.hcd)) {
if (otg->shared_hcd.hcd) {
dev_err(otg_dev, "otg: shared host already registered\n");
goto err;
@@ -865,7 +872,9 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
* we're ready only if we have shared HCD
* or we don't need shared HCD.
*/
- if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
+ if (otg->shared_hcd.hcd ||
+ (!(otg->flags & OTG_FLAG_HCD_NEEDS_COMPANION) &&
+ !otg->primary_hcd.hcd->shared_hcd)) {
otg->host = hcd_to_bus(hcd);
/* FIXME: set bus->otg_port if this is true OTG port with HNP */
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index b094352..6f4ca77 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -57,7 +57,8 @@ struct otg_hcd {
* @list: list of otg controllers
* @work: otg state machine work
* @wq: otg state machine work queue
- * @flags: to track if host/gadget is running
+ * @flags: to track if host/gadget is running, or to indicate if hcd needs
+ * companion
*/
struct usb_otg {
u8 default_a;
@@ -84,6 +85,7 @@ struct usb_otg {
u32 flags;
#define OTG_FLAG_GADGET_RUNNING (1 << 0)
#define OTG_FLAG_HOST_RUNNING (1 << 1)
+#define OTG_FLAG_HCD_NEEDS_COMPANION (1 << 2)
/* use otg->fsm.lock for serializing access */
/*------------- deprecated interface -----------------------------*/
@@ -125,11 +127,14 @@ struct usb_otg_caps {
* @caps: otg capabilities of the controller
* @ops: otg fsm operations
* @otg_work: optional custom otg state machine work function
+ * @hcd_needs_companion: Indicates if host controller needs a companion
+ * controller
*/
struct usb_otg_config {
struct usb_otg_caps *otg_caps;
struct otg_fsm_ops *fsm_ops;
void (*otg_work)(struct work_struct *work);
+ bool hcd_needs_companion;
};
extern const char *usb_otg_state_string(enum usb_otg_state state);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Peter Chen <hzpeterchen@gmail.com> |
|---|---|
| Date | 2016-04-15 11:40 +0200 |
| Subject | Re: [PATCH v6 07/12] usb: otg: add OTG/dual-role core |
| Message-ID | <ro8oi-S5-13@gated-at.bofh.it> |
| In reply to | #1371645 |
On Tue, Apr 05, 2016 at 05:05:12PM +0300, Roger Quadros wrote:
> + * usb_otg_register() - Register the OTG/dual-role device to OTG core
> + * @dev: OTG/dual-role controller device.
> + * @config: OTG configuration.
> + *
> + * Registers the OTG/dual-role controller device with the USB OTG core.
> + *
> + * Return: struct usb_otg * if success, ERR_PTR() if error.
> + */
> +struct usb_otg *usb_otg_register(struct device *dev,
> + struct usb_otg_config *config)
> +{
> + struct usb_otg *otg;
> + struct otg_wait_data *wait;
> + int ret = 0;
> +
> + if (!dev || !config || !config->fsm_ops)
> + return ERR_PTR(-EINVAL);
> +
> + /* already in list? */
> + mutex_lock(&otg_list_mutex);
> + if (usb_otg_get_data(dev)) {
> + dev_err(dev, "otg: %s: device already in otg list\n",
> + __func__);
> + ret = -EINVAL;
> + goto unlock;
> + }
> +
> + /* allocate and add to list */
> + otg = kzalloc(sizeof(*otg), GFP_KERNEL);
> + if (!otg) {
> + ret = -ENOMEM;
> + goto unlock;
> + }
> +
> + otg->dev = dev;
> + otg->caps = config->otg_caps;
> +
> + if ((otg->caps->hnp_support || otg->caps->srp_support ||
> + otg->caps->adp_support) && !config->otg_work)
> + dev_info(dev, "otg: limiting to dual-role\n");
What does above mean? Customized otg_work item may be dual-role,
may be full otg.
> +
> + if (config->otg_work) /* custom otg_work ? */
> + INIT_WORK(&otg->work, config->otg_work);
> + else
> + INIT_WORK(&otg->work, usb_otg_work);
> +
> + otg->wq = create_singlethread_workqueue("usb_otg");
> + if (!otg->wq) {
> + dev_err(dev, "otg: %s: can't create workqueue\n",
> + __func__);
> + ret = -ENOMEM;
> + goto err_wq;
> + }
I found a bug that caused by non-freezable workqueue, change it
as freezable please.
https://marc.ttias.be/linux-stable/2016-03/msg00723.php
I will review the whole set from next week.
Peter
> +
> + /* set otg ops */
> + otg->fsm.ops = config->fsm_ops;
> +
> + mutex_init(&otg->fsm.lock);
> +
> + list_add_tail(&otg->list, &otg_list);
> + mutex_unlock(&otg_list_mutex);
> +
> + /* were we in wait list? */
> + mutex_lock(&wait_list_mutex);
> + wait = usb_otg_get_wait(dev);
> + mutex_unlock(&wait_list_mutex);
> + if (wait) {
> + /* register pending host/gadget and flush from list */
> + usb_otg_flush_wait(dev);
> + }
> +
> + return otg;
> +
> +err_wq:
> + kfree(otg);
> +unlock:
> + mutex_unlock(&otg_list_mutex);
> + return ERR_PTR(ret);
> +}
> +EXPORT_SYMBOL_GPL(usb_otg_register);
> +
> +/**
> + * usb_otg_unregister() - Unregister the OTG/dual-role device from USB OTG core
> + * @dev: OTG controller device.
> + *
> + * Unregisters the OTG/dual-role controller device from USB OTG core.
> + * Prevents unregistering till both the associated Host and Gadget controllers
> + * have unregistered from the OTG core.
> + *
> + * Return: 0 on success, error value otherwise.
> + */
> +int usb_otg_unregister(struct device *dev)
> +{
> + struct usb_otg *otg;
> +
> + mutex_lock(&otg_list_mutex);
> + otg = usb_otg_get_data(dev);
> + if (!otg) {
> + dev_err(dev, "otg: %s: device not in otg list\n",
> + __func__);
> + mutex_unlock(&otg_list_mutex);
> + return -EINVAL;
> + }
> +
> + /* prevent unregister till both host & gadget have unregistered */
> + if (otg->host || otg->gadget) {
> + dev_err(dev, "otg: %s: host/gadget still registered\n",
> + __func__);
> + return -EBUSY;
> + }
> +
> + /* OTG FSM is halted when host/gadget unregistered */
> + destroy_workqueue(otg->wq);
> +
> + /* remove from otg list */
> + list_del(&otg->list);
> + kfree(otg);
> + mutex_unlock(&otg_list_mutex);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(usb_otg_unregister);
> +
> +/**
> + * start/kick the OTG FSM if we can
> + * fsm->lock must be held
> + */
> +static void usb_otg_start_fsm(struct usb_otg *otg)
> +{
> + struct otg_fsm *fsm = &otg->fsm;
> +
> + if (fsm->running)
> + goto kick_fsm;
> +
> + if (!otg->host) {
> + dev_info(otg->dev, "otg: can't start till host registers\n");
> + return;
> + }
> +
> + if (!otg->gadget) {
> + dev_info(otg->dev, "otg: can't start till gadget registers\n");
> + return;
> + }
> +
> + fsm->running = true;
> +kick_fsm:
> + queue_work(otg->wq, &otg->work);
> +}
> +
> +/**
> + * stop the OTG FSM. Stops Host & Gadget controllers as well.
> + * fsm->lock must be held
> + */
> +static void usb_otg_stop_fsm(struct usb_otg *otg)
> +{
> + struct otg_fsm *fsm = &otg->fsm;
> +
> + if (!fsm->running)
> + return;
> +
> + /* no more new events queued */
> + fsm->running = false;
> +
> + flush_workqueue(otg->wq);
> + otg->state = OTG_STATE_UNDEFINED;
> +
> + /* stop host/gadget immediately */
> + if (fsm->protocol == PROTO_HOST)
> + otg_start_host(otg, 0);
> + else if (fsm->protocol == PROTO_GADGET)
> + otg_start_gadget(otg, 0);
> + fsm->protocol = PROTO_UNDEF;
> +}
> +
> +/**
> + * usb_otg_sync_inputs - Sync OTG inputs with the OTG state machine
> + * @fsm: OTG FSM instance
> + *
> + * Used by the OTG driver to update the inputs to the OTG
> + * state machine.
> + *
> + * Can be called in IRQ context.
> + */
> +void usb_otg_sync_inputs(struct usb_otg *otg)
> +{
> + /* Don't kick FSM till it has started */
> + if (!otg->fsm.running)
> + return;
> +
> + /* Kick FSM */
> + queue_work(otg->wq, &otg->work);
> +}
> +EXPORT_SYMBOL_GPL(usb_otg_sync_inputs);
> +
> +/**
> + * usb_otg_kick_fsm - Kick the OTG state machine
> + * @otg_dev: OTG controller device
> + *
> + * Used by USB host/device stack to sync OTG related
> + * events to the OTG state machine.
> + * e.g. change in host_bus->b_hnp_enable, gadget->b_hnp_enable
> + *
> + * Returns: 0 on success, error value otherwise.
> + */
> +int usb_otg_kick_fsm(struct device *otg_dev)
> +{
> + struct usb_otg *otg;
> +
> + mutex_lock(&otg_list_mutex);
> + otg = usb_otg_get_data(otg_dev);
> + mutex_unlock(&otg_list_mutex);
> + if (!otg) {
> + dev_dbg(otg_dev, "otg: %s: invalid otg device\n",
> + __func__);
> + return -ENODEV;
> + }
> +
> + usb_otg_sync_inputs(otg);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(usb_otg_kick_fsm);
> +
> +/**
> + * usb_otg_register_hcd - Register the host controller to OTG core
> + * @hcd: host controller device
> + * @irqnum: interrupt number
> + * @irqflags: interrupt flags
> + * @ops: HCD ops to interface with the HCD
> + *
> + * This is used by the USB Host stack to register the host controller
> + * to the OTG core. Host controller must not be started by the
> + * caller as it is left upto the OTG state machine to do so.
> + * hcd->otg_dev must contain the related otg controller device.
> + *
> + * Returns: 0 on success, error value otherwise.
> + */
> +int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> + unsigned long irqflags, struct otg_hcd_ops *ops)
> +{
> + struct usb_otg *otg;
> + struct device *hcd_dev = hcd->self.controller;
> + struct device *otg_dev = hcd->otg_dev;
> +
> + if (!otg_dev)
> + return -EINVAL;
> +
> + /* we're otg but otg controller might not yet be registered */
> + mutex_lock(&otg_list_mutex);
> + otg = usb_otg_get_data(otg_dev);
> + mutex_unlock(&otg_list_mutex);
> + if (!otg) {
> + dev_dbg(hcd_dev,
> + "otg: controller not yet registered. waiting..\n");
> + /*
> + * otg controller might register later. Put the hcd in
> + * wait list and call us back when ready
> + */
> + if (usb_otg_hcd_wait_add(otg_dev, hcd, irqnum, irqflags, ops)) {
> + dev_err(hcd_dev, "otg: failed to add hcd to wait list\n");
> + return -EINVAL;
> + }
> +
> + return 0;
> + }
> +
> + /* HCD will be started by OTG fsm when needed */
> + mutex_lock(&otg->fsm.lock);
> + if (otg->primary_hcd.hcd) {
> + /* probably a shared HCD ? */
> + if (usb_otg_hcd_is_primary_hcd(hcd)) {
> + dev_err(otg_dev, "otg: primary host already registered\n");
> + goto err;
> + }
> +
> + if (hcd->shared_hcd == otg->primary_hcd.hcd) {
> + if (otg->shared_hcd.hcd) {
> + dev_err(otg_dev, "otg: shared host already registered\n");
> + goto err;
> + }
> +
> + otg->shared_hcd.hcd = hcd;
> + otg->shared_hcd.irqnum = irqnum;
> + otg->shared_hcd.irqflags = irqflags;
> + otg->shared_hcd.ops = ops;
> + dev_info(otg_dev, "otg: shared host %s registered\n",
> + dev_name(hcd->self.controller));
> + } else {
> + dev_err(otg_dev, "otg: invalid shared host %s\n",
> + dev_name(hcd->self.controller));
> + goto err;
> + }
> + } else {
> + if (!usb_otg_hcd_is_primary_hcd(hcd)) {
> + dev_err(otg_dev, "otg: primary host must be registered first\n");
> + goto err;
> + }
> +
> + otg->primary_hcd.hcd = hcd;
> + otg->primary_hcd.irqnum = irqnum;
> + otg->primary_hcd.irqflags = irqflags;
> + otg->primary_hcd.ops = ops;
> + otg->hcd_ops = ops;
> + dev_info(otg_dev, "otg: primary host %s registered\n",
> + dev_name(hcd->self.controller));
> + }
> +
> + /*
> + * we're ready only if we have shared HCD
> + * or we don't need shared HCD.
> + */
> + if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> + otg->host = hcd_to_bus(hcd);
> + /* FIXME: set bus->otg_port if this is true OTG port with HNP */
> +
> + /* start FSM */
> + usb_otg_start_fsm(otg);
> + } else {
> + dev_dbg(otg_dev, "otg: can't start till shared host registers\n");
> + }
> +
> + mutex_unlock(&otg->fsm.lock);
> +
> + return 0;
> +
> +err:
> + mutex_unlock(&otg->fsm.lock);
> + return -EINVAL;
> +}
> +EXPORT_SYMBOL_GPL(usb_otg_register_hcd);
> +
> +/**
> + * usb_otg_unregister_hcd - Unregister the host controller from OTG core
> + * @hcd: host controller device
> + *
> + * This is used by the USB Host stack to unregister the host controller
> + * from the OTG core. Ensures that host controller is not running
> + * on successful return.
> + *
> + * Returns: 0 on success, error value otherwise.
> + */
> +int usb_otg_unregister_hcd(struct usb_hcd *hcd)
> +{
> + struct usb_otg *otg;
> + struct device *hcd_dev = hcd_to_bus(hcd)->controller;
> + struct device *otg_dev = hcd->otg_dev;
> +
> + if (!otg_dev)
> + return -EINVAL; /* we're definitely not OTG */
> +
> + mutex_lock(&otg_list_mutex);
> + otg = usb_otg_get_data(otg_dev);
> + mutex_unlock(&otg_list_mutex);
> + if (!otg) {
> + /* are we in wait list? */
> + if (!usb_otg_hcd_wait_remove(hcd))
> + return 0;
> +
> + dev_dbg(hcd_dev, "otg: host wasn't registered with otg\n");
> + return -EINVAL;
> + }
> +
> + mutex_lock(&otg->fsm.lock);
> + if (hcd == otg->primary_hcd.hcd) {
> + otg->primary_hcd.hcd = NULL;
> + dev_info(otg_dev, "otg: primary host %s unregistered\n",
> + dev_name(hcd_dev));
> + } else if (hcd == otg->shared_hcd.hcd) {
> + otg->shared_hcd.hcd = NULL;
> + dev_info(otg_dev, "otg: shared host %s unregistered\n",
> + dev_name(hcd_dev));
> + } else {
> + dev_err(otg_dev, "otg: host %s wasn't registered with otg\n",
> + dev_name(hcd_dev));
> + mutex_unlock(&otg->fsm.lock);
> + return -EINVAL;
> + }
> +
> + /* stop FSM & Host */
> + usb_otg_stop_fsm(otg);
> + otg->host = NULL;
> +
> + mutex_unlock(&otg->fsm.lock);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(usb_otg_unregister_hcd);
> +
> +/**
> + * usb_otg_register_gadget - Register the gadget controller to OTG core
> + * @gadget: gadget controller
> + *
> + * This is used by the USB gadget stack to register the gadget controller
> + * to the OTG core. Gadget controller must not be started by the
> + * caller as it is left upto the OTG state machine to do so.
> + *
> + * Gadget core must call this only when all resources required for
> + * gadget controller to run are available.
> + * i.e. gadget function driver is available.
> + *
> + * Returns: 0 on success, error value otherwise.
> + */
> +int usb_otg_register_gadget(struct usb_gadget *gadget,
> + struct otg_gadget_ops *ops)
> +{
> + struct usb_otg *otg;
> + struct device *gadget_dev = &gadget->dev;
> + struct device *otg_dev = gadget->otg_dev;
> +
> + if (!otg_dev)
> + return -EINVAL; /* we're definitely not OTG */
> +
> + /* we're otg but otg controller might not yet be registered */
> + mutex_lock(&otg_list_mutex);
> + otg = usb_otg_get_data(otg_dev);
> + mutex_unlock(&otg_list_mutex);
> + if (!otg) {
> + dev_dbg(gadget_dev,
> + "otg: controller not yet registered. waiting..\n");
> + /*
> + * otg controller might register later. Put the gadget in
> + * wait list and call us back when ready
> + */
> + if (usb_otg_gadget_wait_add(otg_dev, gadget, ops)) {
> + dev_err(gadget_dev,
> + "otg: failed to add to gadget to wait list\n");
> + return -EINVAL;
> + }
> +
> + return 0;
> + }
> +
> + mutex_lock(&otg->fsm.lock);
> + if (otg->gadget) {
> + dev_err(otg_dev, "otg: gadget already registered with otg\n");
> + mutex_unlock(&otg->fsm.lock);
> + return -EINVAL;
> + }
> +
> + otg->gadget = gadget;
> + otg->gadget_ops = ops;
> + dev_info(otg_dev, "otg: gadget %s registered\n",
> + dev_name(&gadget->dev));
> +
> + /* start FSM */
> + usb_otg_start_fsm(otg);
> + mutex_unlock(&otg->fsm.lock);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(usb_otg_register_gadget);
> +
> +/**
> + * usb_otg_unregister_gadget - Unregister the gadget controller from OTG core
> + * @gadget: gadget controller
> + *
> + * This is used by the USB gadget stack to unregister the gadget controller
> + * from the OTG core. Ensures that gadget controller is halted
> + * on successful return.
> + *
> + * Returns: 0 on success, error value otherwise.
> + */
> +int usb_otg_unregister_gadget(struct usb_gadget *gadget)
> +{
> + struct usb_otg *otg;
> + struct device *gadget_dev = &gadget->dev;
> + struct device *otg_dev = gadget->otg_dev;
> +
> + if (!otg_dev)
> + return -EINVAL;
> +
> + mutex_lock(&otg_list_mutex);
> + otg = usb_otg_get_data(otg_dev);
> + mutex_unlock(&otg_list_mutex);
> + if (!otg) {
> + /* are we in wait list? */
> + if (!usb_otg_gadget_wait_remove(gadget))
> + return 0;
> +
> + dev_dbg(gadget_dev, "otg: gadget wasn't registered with otg\n");
> + return -EINVAL;
> + }
> +
> + mutex_lock(&otg->fsm.lock);
> + if (otg->gadget != gadget) {
> + dev_err(otg_dev, "otg: gadget %s wasn't registered with otg\n",
> + dev_name(&gadget->dev));
> + mutex_unlock(&otg->fsm.lock);
> + return -EINVAL;
> + }
> +
> + /* Stop FSM & gadget */
> + usb_otg_stop_fsm(otg);
> + otg->gadget = NULL;
> + mutex_unlock(&otg->fsm.lock);
> +
> + dev_info(otg_dev, "otg: gadget %s unregistered\n",
> + dev_name(&gadget->dev));
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(usb_otg_unregister_gadget);
> diff --git a/drivers/usb/common/usb-otg.h b/drivers/usb/common/usb-otg.h
> new file mode 100644
> index 0000000..2bf3fbf
> --- /dev/null
> +++ b/drivers/usb/common/usb-otg.h
> @@ -0,0 +1,71 @@
> +/**
> + * drivers/usb/common/usb-otg.h - USB OTG core local header
> + *
> + * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com
> + * Author: Roger Quadros <rogerq@ti.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#ifndef __DRIVERS_USB_COMMON_USB_OTG_H
> +#define __DRIVERS_USB_COMMON_USB_OTG_H
> +
> +/*
> + * A-DEVICE timing constants
> + */
> +
> +/* Wait for VBUS Rise */
> +#define TA_WAIT_VRISE (100) /* a_wait_vrise: section 7.1.2
> + * a_wait_vrise_tmr: section 7.4.5.1
> + * TA_VBUS_RISE <= 100ms, section 4.4
> + * Table 4-1: Electrical Characteristics
> + * ->DC Electrical Timing
> + */
> +/* Wait for VBUS Fall */
> +#define TA_WAIT_VFALL (1000) /* a_wait_vfall: section 7.1.7
> + * a_wait_vfall_tmr: section: 7.4.5.2
> + */
> +/* Wait for B-Connect */
> +#define TA_WAIT_BCON (10000) /* a_wait_bcon: section 7.1.3
> + * TA_WAIT_BCON: should be between 1100
> + * and 30000 ms, section 5.5, Table 5-1
> + */
> +/* A-Idle to B-Disconnect */
> +#define TA_AIDL_BDIS (5000) /* a_suspend min 200 ms, section 5.2.1
> + * TA_AIDL_BDIS: section 5.5, Table 5-1
> + */
> +/* B-Idle to A-Disconnect */
> +#define TA_BIDL_ADIS (500) /* TA_BIDL_ADIS: section 5.2.1
> + * 500ms is used for B switch to host
> + * for safe
> + */
> +
> +/*
> + * B-device timing constants
> + */
> +
> +/* Data-Line Pulse Time*/
> +#define TB_DATA_PLS (10) /* b_srp_init,continue 5~10ms
> + * section:5.1.3
> + */
> +/* SRP Fail Time */
> +#define TB_SRP_FAIL (6000) /* b_srp_init,fail time 5~6s
> + * section:5.1.6
> + */
> +/* A-SE0 to B-Reset */
> +#define TB_ASE0_BRST (155) /* minimum 155 ms, section:5.3.1 */
> +/* SE0 Time Before SRP */
> +#define TB_SE0_SRP (1000) /* b_idle,minimum 1s, section:5.1.2 */
> +/* SSEND time before SRP */
> +#define TB_SSEND_SRP (1500) /* minimum 1.5 sec, section:5.1.2 */
> +
> +#define TB_SESS_VLD (1000)
> +
> +#endif /* __DRIVERS_USB_COMMON_USB_OTG_H */
> diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
> index ae228d0..b468a9f 100644
> --- a/drivers/usb/core/Kconfig
> +++ b/drivers/usb/core/Kconfig
> @@ -42,7 +42,7 @@ config USB_DYNAMIC_MINORS
> If you are unsure about this, say N here.
>
> config USB_OTG
> - bool "OTG support"
> + bool "OTG/Dual-role support"
> depends on PM
> default n
> help
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index 8c0ae64..1878ae1 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -583,6 +583,7 @@ struct usb_gadget_ops {
> * @out_epnum: last used out ep number
> * @in_epnum: last used in ep number
> * @otg_caps: OTG capabilities of this gadget.
> + * @otg_dev: OTG controller device, if needs to be used with OTG core.
> * @sg_supported: true if we can handle scatter-gather
> * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
> * gadget driver must provide a USB OTG descriptor.
> @@ -639,6 +640,7 @@ struct usb_gadget {
> unsigned out_epnum;
> unsigned in_epnum;
> struct usb_otg_caps *otg_caps;
> + struct device *otg_dev;
>
> unsigned sg_supported:1;
> unsigned is_otg:1;
> diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
> index 861ccaa..2017cd4 100644
> --- a/include/linux/usb/hcd.h
> +++ b/include/linux/usb/hcd.h
> @@ -184,6 +184,7 @@ struct usb_hcd {
> struct mutex *bandwidth_mutex;
> struct usb_hcd *shared_hcd;
> struct usb_hcd *primary_hcd;
> + struct device *otg_dev; /* OTG controller device */
>
>
> #define HCD_BUFFER_POOLS 4
> diff --git a/include/linux/usb/otg-fsm.h b/include/linux/usb/otg-fsm.h
> index 36f0cf9..ba6755c 100644
> --- a/include/linux/usb/otg-fsm.h
> +++ b/include/linux/usb/otg-fsm.h
> @@ -61,6 +61,11 @@ enum otg_fsm_timer {
> /**
> * struct otg_fsm - OTG state machine according to the OTG spec
> *
> + * DRD mode hardware Inputs
> + *
> + * @id: TRUE for B-device, FALSE for A-device.
> + * @b_sess_vld: VBUS voltage in regulation.
> + *
> * OTG hardware Inputs
> *
> * Common inputs for A and B device
> @@ -133,6 +138,7 @@ enum otg_fsm_timer {
> * a_clr_err: Asserted (by application ?) to clear a_vbus_err due to an
> * overcurrent condition and causes the A-device to transition
> * to a_wait_vfall
> + * running: state machine running/stopped indicator
> */
> struct otg_fsm {
> /* Input */
> @@ -188,6 +194,7 @@ struct otg_fsm {
> int b_ase0_brst_tmout;
> int a_bidl_adis_tmout;
>
> + bool running;
> struct otg_fsm_ops *ops;
>
> /* Current usb protocol used: 0:undefine; 1:host; 2:client */
> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
> index 85b8fb5..b094352 100644
> --- a/include/linux/usb/otg.h
> +++ b/include/linux/usb/otg.h
> @@ -10,10 +10,55 @@
> #define __LINUX_USB_OTG_H
>
> #include <linux/phy/phy.h>
> -#include <linux/usb/phy.h>
> -#include <linux/usb/otg-fsm.h>
> +#include <linux/device.h>
> +#include <linux/hrtimer.h>
> +#include <linux/ktime.h>
> +#include <linux/usb.h>
> #include <linux/usb/hcd.h>
> +#include <linux/usb/gadget.h>
> +#include <linux/usb/otg-fsm.h>
> +#include <linux/usb/phy.h>
>
> +/**
> + * struct otg_hcd - host controller state and interface
> + *
> + * @hcd: host controller
> + * @irqnum: irq number
> + * @irqflags: irq flags
> + * @ops: otg to host controller interface
> + * @ops: otg to host controller interface
> + * @otg_dev: otg controller device
> + */
> +struct otg_hcd {
> + struct usb_hcd *hcd;
> + unsigned int irqnum;
> + unsigned long irqflags;
> + struct otg_hcd_ops *ops;
> + struct device *otg_dev;
> +};
> +
> +/**
> + * struct usb_otg - usb otg controller state
> + *
> + * @default_a: Indicates we are an A device. i.e. Host.
> + * @phy: USB phy interface
> + * @usb_phy: old usb_phy interface
> + * @host: host controller bus
> + * @gadget: gadget device
> + * @state: current otg state
> + * @dev: otg controller device
> + * @caps: otg capabilities revision, hnp, srp, etc
> + * @fsm: otg finite state machine
> + * @hcd_ops: host controller interface
> + * ------- internal use only -------
> + * @primary_hcd: primary host state and interface
> + * @shared_hcd: shared host state and interface
> + * @gadget_ops: gadget controller interface
> + * @list: list of otg controllers
> + * @work: otg state machine work
> + * @wq: otg state machine work queue
> + * @flags: to track if host/gadget is running
> + */
> struct usb_otg {
> u8 default_a;
>
> @@ -24,9 +69,24 @@ struct usb_otg {
> struct usb_gadget *gadget;
>
> enum usb_otg_state state;
> + struct device *dev;
> + struct usb_otg_caps *caps;
> struct otg_fsm fsm;
> struct otg_hcd_ops *hcd_ops;
>
> + /* internal use only */
> + struct otg_hcd primary_hcd;
> + struct otg_hcd shared_hcd;
> + struct otg_gadget_ops *gadget_ops;
> + struct list_head list;
> + struct work_struct work;
> + struct workqueue_struct *wq;
> + u32 flags;
> +#define OTG_FLAG_GADGET_RUNNING (1 << 0)
> +#define OTG_FLAG_HOST_RUNNING (1 << 1)
> + /* use otg->fsm.lock for serializing access */
> +
> +/*------------- deprecated interface -----------------------------*/
> /* bind/unbind the host controller */
> int (*set_host)(struct usb_otg *otg, struct usb_bus *host);
>
> @@ -42,7 +102,7 @@ struct usb_otg {
>
> /* start or continue HNP role switch */
> int (*start_hnp)(struct usb_otg *otg);
> -
> +/*---------------------------------------------------------------*/
> };
>
> /**
> @@ -60,8 +120,92 @@ struct usb_otg_caps {
> bool adp_support;
> };
>
> +/**
> + * struct usb_otg_config - otg controller configuration
> + * @caps: otg capabilities of the controller
> + * @ops: otg fsm operations
> + * @otg_work: optional custom otg state machine work function
> + */
> +struct usb_otg_config {
> + struct usb_otg_caps *otg_caps;
> + struct otg_fsm_ops *fsm_ops;
> + void (*otg_work)(struct work_struct *work);
> +};
> +
> extern const char *usb_otg_state_string(enum usb_otg_state state);
>
> +#if IS_ENABLED(CONFIG_USB_OTG)
> +struct usb_otg *usb_otg_register(struct device *dev,
> + struct usb_otg_config *config);
> +int usb_otg_unregister(struct device *dev);
> +int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> + unsigned long irqflags, struct otg_hcd_ops *ops);
> +int usb_otg_unregister_hcd(struct usb_hcd *hcd);
> +int usb_otg_register_gadget(struct usb_gadget *gadget,
> + struct otg_gadget_ops *ops);
> +int usb_otg_unregister_gadget(struct usb_gadget *gadget);
> +void usb_otg_sync_inputs(struct usb_otg *otg);
> +int usb_otg_kick_fsm(struct device *otg_dev);
> +int usb_otg_start_host(struct usb_otg *otg, int on);
> +int usb_otg_start_gadget(struct usb_otg *otg, int on);
> +
> +#else /* CONFIG_USB_OTG */
> +
> +static inline struct usb_otg *usb_otg_register(struct device *dev,
> + struct usb_otg_config *config)
> +{
> + return ERR_PTR(-ENOTSUPP);
> +}
> +
> +static inline int usb_otg_unregister(struct device *dev)
> +{
> + return -ENOTSUPP;
> +}
> +
> +static inline int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum,
> + unsigned long irqflags,
> + struct otg_hcd_ops *ops)
> +{
> + return -ENOTSUPP;
> +}
> +
> +static inline int usb_otg_unregister_hcd(struct usb_hcd *hcd)
> +{
> + return -ENOTSUPP;
> +}
> +
> +static inline int usb_otg_register_gadget(struct usb_gadget *gadget,
> + struct otg_gadget_ops *ops)
> +{
> + return -ENOTSUPP;
> +}
> +
> +static inline int usb_otg_unregister_gadget(struct usb_gadget *gadget)
> +{
> + return -ENOTSUPP;
> +}
> +
> +static inline void usb_otg_sync_inputs(struct usb_otg *otg)
> +{
> +}
> +
> +static inline int usb_otg_kick_fsm(struct device *otg_dev)
> +{
> + return -ENOTSUPP;
> +}
> +
> +static inline int usb_otg_start_host(struct usb_otg *otg, int on)
> +{
> + return -ENOTSUPP;
> +}
> +
> +static inline int usb_otg_start_gadget(struct usb_otg *otg, int on)
> +{
> + return -ENOTSUPP;
> +}
> +#endif /* CONFIG_USB_OTG */
> +
> +/*------------- deprecated interface -----------------------------*/
> /* Context: can sleep */
> static inline int
> otg_start_hnp(struct usb_otg *otg)
> @@ -113,6 +257,8 @@ otg_start_srp(struct usb_otg *otg)
> return -ENOTSUPP;
> }
>
> +/*---------------------------------------------------------------*/
> +
> /* for OTG controller drivers (and maybe other stuff) */
> extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
>
> @@ -237,4 +383,6 @@ static inline int otg_start_gadget(struct usb_otg *otg, int on)
> return otg->fsm.ops->start_gadget(otg, on);
> }
>
> +int drd_statemachine(struct usb_otg *otg);
> +
> #endif /* __LINUX_USB_OTG_H */
> --
> 2.5.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Best Regards,
Peter Chen
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | linux.kernel
csiph-web