Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-17 Thread Roger Quadros
On 16/07/15 21:29, Andrew Bresticker wrote:
 Hi Roger,
 
 On Wed, Jul 15, 2015 at 6:26 AM, Roger Quadros rog...@ti.com wrote:
 Hi Andrew,

 On 13/07/15 22:14, Andrew Bresticker wrote:
 Hi Roger,

 On Wed, Jul 8, 2015 at 3:19 AM, Roger Quadros rog...@ti.com wrote:
 Usage model:
 ---

 - The OTG controller device is assumed to be the parent of
 the host and gadget controller. It must call usb_otg_register()
 before populating the host and gadget devices so that the OTG
 core is aware that it is an OTG device before the host  gadget
 register. The OTG controller must provide struct otg_fsm_ops *
 which will be called by the OTG core depending on OTG bus state.

 I'm wondering if the requirement that the OTG controller be the parent
 of the USB host/device-controllers makes sense.  For some context, I'm
 working on adding dual-role support for Tegra210, specifically on a
 system with USB Type-C.  On Tegra, the USB host-controller and USB
 device-controller are two separate IP blocks (XUSB host and XUSB
 device) with another, separate, IP block (XUSB padctl) for the USB PHY
 and OTG support.  In the non-Type-C case, your OTG framework could
 work well, though it's debatable as to whether or not the XUSB padctl
 device should be a parent to the XUSB host/device-controller devices
 (currently it isn't - it's just a PHY provider).  But in the Type-C
 case, it's an off-chip embedded controller that determines the
 dual-role status of the Type-C port, so the above requirement doesn't
 make sense at all.

 My idea was to have the OTG/DRD controller explicitly specify its host
 and device controllers, so in DT, something like:

 otg-controller {
 ...
 device-controller = usb_device;
 host-controller = usb_host;
 ...
 };

 usb_device: usb-device@ {
 ...
 };

 usb_host: usb-host@... {
 ...
 };

 What do you think?

 I agree that we need to support your use case but how to do it
 is not yet clear to me.

 In your above example the otg controller knows what are the host
 and gadget controllers but the host/gadget devices don't
 know who is their otg controller.

 So the problem is that when usb_otg_register_hcd/gadget() is called
 we need to get a handle to the otg controller.

 One solution I see is to iterate over the registered otg_controller_list
 and check if we match the host/gadget controller in there.

 Then there is also a possibility that host/gadget controllers get
 registered before the OTG controller. Then we can't know for sure if
 the host/gadget controller was meant for dual-role operation or not
 and it will resort to single role operation.

 Any idea to prevent the above situation?

 Maybe we need to add some logic in host/gadget cores to check if the port
 is meant for dual-role use and defer probe if OTG controller is not yet
 registered?
 
 In the DT case, I think we could add an otg-controller property to
 the host and gadget nodes, and in usb_otg_register_{hcd,gadget}()
 check for that property and defer probe if the referenced OTG
 controller has not yet been registered.  Not sure how to indicate that
 a host/gadget is meant for dual-role operation on non-DT platforms
 though.
 

Sounds fine for DT case.

For non DT case I don't see any other way to connect the OTG controller
to the host/gadget controllers other than the parent child relationship.

Maybe for non DT case we can still have that constraint.
We can have this constraint regardless so that DT users who fit
in that model don't need to add 'otg-controller' property.

cheers,
-roger
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-16 Thread Andrew Bresticker
Hi Roger,

On Wed, Jul 15, 2015 at 6:26 AM, Roger Quadros rog...@ti.com wrote:
 Hi Andrew,

 On 13/07/15 22:14, Andrew Bresticker wrote:
 Hi Roger,

 On Wed, Jul 8, 2015 at 3:19 AM, Roger Quadros rog...@ti.com wrote:
 Usage model:
 ---

 - The OTG controller device is assumed to be the parent of
 the host and gadget controller. It must call usb_otg_register()
 before populating the host and gadget devices so that the OTG
 core is aware that it is an OTG device before the host  gadget
 register. The OTG controller must provide struct otg_fsm_ops *
 which will be called by the OTG core depending on OTG bus state.

 I'm wondering if the requirement that the OTG controller be the parent
 of the USB host/device-controllers makes sense.  For some context, I'm
 working on adding dual-role support for Tegra210, specifically on a
 system with USB Type-C.  On Tegra, the USB host-controller and USB
 device-controller are two separate IP blocks (XUSB host and XUSB
 device) with another, separate, IP block (XUSB padctl) for the USB PHY
 and OTG support.  In the non-Type-C case, your OTG framework could
 work well, though it's debatable as to whether or not the XUSB padctl
 device should be a parent to the XUSB host/device-controller devices
 (currently it isn't - it's just a PHY provider).  But in the Type-C
 case, it's an off-chip embedded controller that determines the
 dual-role status of the Type-C port, so the above requirement doesn't
 make sense at all.

 My idea was to have the OTG/DRD controller explicitly specify its host
 and device controllers, so in DT, something like:

 otg-controller {
 ...
 device-controller = usb_device;
 host-controller = usb_host;
 ...
 };

 usb_device: usb-device@ {
 ...
 };

 usb_host: usb-host@... {
 ...
 };

 What do you think?

 I agree that we need to support your use case but how to do it
 is not yet clear to me.

 In your above example the otg controller knows what are the host
 and gadget controllers but the host/gadget devices don't
 know who is their otg controller.

 So the problem is that when usb_otg_register_hcd/gadget() is called
 we need to get a handle to the otg controller.

 One solution I see is to iterate over the registered otg_controller_list
 and check if we match the host/gadget controller in there.

 Then there is also a possibility that host/gadget controllers get
 registered before the OTG controller. Then we can't know for sure if
 the host/gadget controller was meant for dual-role operation or not
 and it will resort to single role operation.

 Any idea to prevent the above situation?

 Maybe we need to add some logic in host/gadget cores to check if the port
 is meant for dual-role use and defer probe if OTG controller is not yet
 registered?

In the DT case, I think we could add an otg-controller property to
the host and gadget nodes, and in usb_otg_register_{hcd,gadget}()
check for that property and defer probe if the referenced OTG
controller has not yet been registered.  Not sure how to indicate that
a host/gadget is meant for dual-role operation on non-DT platforms
though.

Thanks,
Andrew
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-15 Thread Roger Quadros
On 13/07/15 16:04, Li Jun wrote:
 On Mon, Jul 13, 2015 at 01:24:05PM +0300, Roger Quadros wrote:
 Hi,

 On 10/07/15 10:58, Li Jun wrote:
 On Wed, Jul 08, 2015 at 01:19:26PM +0300, Roger Quadros wrote:
 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. xhci side of things for OTG/DRD use are already
 in v4.2

 Do you have any plan to implement OTG(HNP) on some of your platforms based 
 on
 this OTG core?

 Not yet but Joao Pinto was interested to implement full OTG for dwc3
 controllers.

 Would you be interested to try out one of your platforms so that we can
 address any issues early?

 cheers,
 -roger

 
 Yes, I am considering to try out OTG on chipidea driver for FSL i.mx6x 
 platform
 , which will based on your OTG core and my previous gadget update patchset.

Great :)
 
 I will comment your patchset if find any issues. Since there is still much 
 work
 to do to complete OTG HNP/SRP, so I assume this will not be done in a short 
 time.

Yes. My plan was to first get DRD working reliably and then add missing HNP/SRP 
stuff.
The first user of HNP/SRP will know what issues are and what needs to be added.

cheers,
-roger
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-15 Thread Roger Quadros
Hi Andrew,

On 13/07/15 22:14, Andrew Bresticker wrote:
 Hi Roger,
 
 On Wed, Jul 8, 2015 at 3:19 AM, Roger Quadros rog...@ti.com wrote:
 Usage model:
 ---

 - The OTG controller device is assumed to be the parent of
 the host and gadget controller. It must call usb_otg_register()
 before populating the host and gadget devices so that the OTG
 core is aware that it is an OTG device before the host  gadget
 register. The OTG controller must provide struct otg_fsm_ops *
 which will be called by the OTG core depending on OTG bus state.
 
 I'm wondering if the requirement that the OTG controller be the parent
 of the USB host/device-controllers makes sense.  For some context, I'm
 working on adding dual-role support for Tegra210, specifically on a
 system with USB Type-C.  On Tegra, the USB host-controller and USB
 device-controller are two separate IP blocks (XUSB host and XUSB
 device) with another, separate, IP block (XUSB padctl) for the USB PHY
 and OTG support.  In the non-Type-C case, your OTG framework could
 work well, though it's debatable as to whether or not the XUSB padctl
 device should be a parent to the XUSB host/device-controller devices
 (currently it isn't - it's just a PHY provider).  But in the Type-C
 case, it's an off-chip embedded controller that determines the
 dual-role status of the Type-C port, so the above requirement doesn't
 make sense at all.
 
 My idea was to have the OTG/DRD controller explicitly specify its host
 and device controllers, so in DT, something like:
 
 otg-controller {
 ...
 device-controller = usb_device;
 host-controller = usb_host;
 ...
 };
 
 usb_device: usb-device@ {
 ...
 };
 
 usb_host: usb-host@... {
 ...
 };
 
 What do you think?

I agree that we need to support your use case but how to do it
is not yet clear to me.

In your above example the otg controller knows what are the host
and gadget controllers but the host/gadget devices don't
know who is their otg controller.

So the problem is that when usb_otg_register_hcd/gadget() is called
we need to get a handle to the otg controller.

One solution I see is to iterate over the registered otg_controller_list
and check if we match the host/gadget controller in there.

Then there is also a possibility that host/gadget controllers get
registered before the OTG controller. Then we can't know for sure if
the host/gadget controller was meant for dual-role operation or not
and it will resort to single role operation.

Any idea to prevent the above situation?

Maybe we need to add some logic in host/gadget cores to check if the port
is meant for dual-role use and defer probe if OTG controller is not yet
registered?

cheers,
-roger
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-14 Thread Andrew Bresticker
Hi Peter,

On Mon, Jul 13, 2015 at 5:59 PM, Peter Chen peter.c...@freescale.com wrote:
 On Mon, Jul 13, 2015 at 12:14:43PM -0700, Andrew Bresticker wrote:
 Hi Roger,

 On Wed, Jul 8, 2015 at 3:19 AM, Roger Quadros rog...@ti.com wrote:
  Usage model:
  ---
 
  - The OTG controller device is assumed to be the parent of
  the host and gadget controller. It must call usb_otg_register()
  before populating the host and gadget devices so that the OTG
  core is aware that it is an OTG device before the host  gadget
  register. The OTG controller must provide struct otg_fsm_ops *
  which will be called by the OTG core depending on OTG bus state.

 I'm wondering if the requirement that the OTG controller be the parent
 of the USB host/device-controllers makes sense.  For some context, I'm
 working on adding dual-role support for Tegra210, specifically on a
 system with USB Type-C.  On Tegra, the USB host-controller and USB
 device-controller are two separate IP blocks (XUSB host and XUSB
 device) with another, separate, IP block (XUSB padctl) for the USB PHY
 and OTG support.  In the non-Type-C case, your OTG framework could
 work well, though it's debatable as to whether or not the XUSB padctl
 device should be a parent to the XUSB host/device-controller devices
 (currently it isn't - it's just a PHY provider).  But in the Type-C
 case, it's an off-chip embedded controller that determines the
 dual-role status of the Type-C port, so the above requirement doesn't
 make sense at all.

 Hi Andrew,

 I think your problem is how to add your core driver to manage device and
 host functionality together, and once you find how (through padctl/type-c
 controller) to do it based on current code, it will be clear how to use roger
 proposal framework at that time.

 Most of current core drivers, we use extcon driver (through gpio) or USB
 vbus/id pin (through internal registers) to manager roles.

Right, currently I'm modeling the Type-C controller as an extcon
device and handle the role-changes in the core drivers, but that
doesn't really make sense for the non-Type-C case where we use the
XUSB padctl controller and need a full OTG state-machine.  Roger's new
OTG/DRD framework would fit my situation perfectly since it makes the
host/device-controller drivers independent from all the
OTG/role-changing logic.  The only issue is the requirement that the
OTG/DRD controller be the parent device of the host/device
controllers.

Thanks,
Andrew
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-14 Thread Peter Chen
On Tue, Jul 14, 2015 at 11:18:30AM -0700, Andrew Bresticker wrote:
 Hi Peter,
 
 On Mon, Jul 13, 2015 at 5:59 PM, Peter Chen peter.c...@freescale.com wrote:
  On Mon, Jul 13, 2015 at 12:14:43PM -0700, Andrew Bresticker wrote:
  Hi Roger,
 
  On Wed, Jul 8, 2015 at 3:19 AM, Roger Quadros rog...@ti.com wrote:
   Usage model:
   ---
  
   - The OTG controller device is assumed to be the parent of
   the host and gadget controller. It must call usb_otg_register()
   before populating the host and gadget devices so that the OTG
   core is aware that it is an OTG device before the host  gadget
   register. The OTG controller must provide struct otg_fsm_ops *
   which will be called by the OTG core depending on OTG bus state.
 
  I'm wondering if the requirement that the OTG controller be the parent
  of the USB host/device-controllers makes sense.  For some context, I'm
  working on adding dual-role support for Tegra210, specifically on a
  system with USB Type-C.  On Tegra, the USB host-controller and USB
  device-controller are two separate IP blocks (XUSB host and XUSB
  device) with another, separate, IP block (XUSB padctl) for the USB PHY
  and OTG support.  In the non-Type-C case, your OTG framework could
  work well, though it's debatable as to whether or not the XUSB padctl
  device should be a parent to the XUSB host/device-controller devices
  (currently it isn't - it's just a PHY provider).  But in the Type-C
  case, it's an off-chip embedded controller that determines the
  dual-role status of the Type-C port, so the above requirement doesn't
  make sense at all.
 
  Hi Andrew,
 
  I think your problem is how to add your core driver to manage device and
  host functionality together, and once you find how (through padctl/type-c
  controller) to do it based on current code, it will be clear how to use 
  roger
  proposal framework at that time.
 
  Most of current core drivers, we use extcon driver (through gpio) or USB
  vbus/id pin (through internal registers) to manager roles.
 
 Right, currently I'm modeling the Type-C controller as an extcon
 device and handle the role-changes in the core drivers, but that
 doesn't really make sense for the non-Type-C case where we use the
 XUSB padctl controller and need a full OTG state-machine.

The full OTG FSM is only applied if your board needs it, you can
disable it through dts. Jun [1] and Roger's patchset are for it.

 Roger's new
 OTG/DRD framework would fit my situation perfectly since it makes the
 host/device-controller drivers independent from all the
 OTG/role-changing logic.  The only issue is the requirement that the
 OTG/DRD controller be the parent device of the host/device
 controllers.
 

The core device is the parent for host/device device, the OTG core
just use the pointer of it, Roger does an example using dwc3 [2].

[1] http://www.spinics.net/lists/linux-usb/msg127110.html
[2] http://www.spinics.net/lists/linux-usb/msg126999.html
-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-13 Thread Roger Quadros
Hi,

On 10/07/15 10:58, Li Jun wrote:
 On Wed, Jul 08, 2015 at 01:19:26PM +0300, Roger Quadros wrote:
 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. xhci side of things for OTG/DRD use are already
 in v4.2
 
 Do you have any plan to implement OTG(HNP) on some of your platforms based on
 this OTG core?

Not yet but Joao Pinto was interested to implement full OTG for dwc3
controllers.

Would you be interested to try out one of your platforms so that we can
address any issues early?

cheers,
-roger

 
 Li Jun

 http://thread.gmane.org/gmane.linux.kernel/1923161

 DWC3 controller and platform related patches are sent separately.

 Changelog:
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-13 Thread Li Jun
On Mon, Jul 13, 2015 at 01:24:05PM +0300, Roger Quadros wrote:
 Hi,
 
 On 10/07/15 10:58, Li Jun wrote:
  On Wed, Jul 08, 2015 at 01:19:26PM +0300, Roger Quadros wrote:
  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. xhci side of things for OTG/DRD use are already
  in v4.2
  
  Do you have any plan to implement OTG(HNP) on some of your platforms based 
  on
  this OTG core?
 
 Not yet but Joao Pinto was interested to implement full OTG for dwc3
 controllers.
 
 Would you be interested to try out one of your platforms so that we can
 address any issues early?
 
 cheers,
 -roger
 

Yes, I am considering to try out OTG on chipidea driver for FSL i.mx6x platform
, which will based on your OTG core and my previous gadget update patchset.

I will comment your patchset if find any issues. Since there is still much work
to do to complete OTG HNP/SRP, so I assume this will not be done in a short 
time.

Li Jun
  
  Li Jun
 
  http://thread.gmane.org/gmane.linux.kernel/1923161
 
  DWC3 controller and platform related patches are sent separately.
 
  Changelog:
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-13 Thread Peter Chen
On Mon, Jul 13, 2015 at 12:14:43PM -0700, Andrew Bresticker wrote:
 Hi Roger,
 
 On Wed, Jul 8, 2015 at 3:19 AM, Roger Quadros rog...@ti.com wrote:
  Usage model:
  ---
 
  - The OTG controller device is assumed to be the parent of
  the host and gadget controller. It must call usb_otg_register()
  before populating the host and gadget devices so that the OTG
  core is aware that it is an OTG device before the host  gadget
  register. The OTG controller must provide struct otg_fsm_ops *
  which will be called by the OTG core depending on OTG bus state.
 
 I'm wondering if the requirement that the OTG controller be the parent
 of the USB host/device-controllers makes sense.  For some context, I'm
 working on adding dual-role support for Tegra210, specifically on a
 system with USB Type-C.  On Tegra, the USB host-controller and USB
 device-controller are two separate IP blocks (XUSB host and XUSB
 device) with another, separate, IP block (XUSB padctl) for the USB PHY
 and OTG support.  In the non-Type-C case, your OTG framework could
 work well, though it's debatable as to whether or not the XUSB padctl
 device should be a parent to the XUSB host/device-controller devices
 (currently it isn't - it's just a PHY provider).  But in the Type-C
 case, it's an off-chip embedded controller that determines the
 dual-role status of the Type-C port, so the above requirement doesn't
 make sense at all.

Hi Andrew,

I think your problem is how to add your core driver to manage device and
host functionality together, and once you find how (through padctl/type-c
controller) to do it based on current code, it will be clear how to use roger
proposal framework at that time.

Most of current core drivers, we use extcon driver (through gpio) or USB
vbus/id pin (through internal registers) to manager roles.

 
 My idea was to have the OTG/DRD controller explicitly specify its host
 and device controllers, so in DT, something like:
 
 otg-controller {
 ...
 device-controller = usb_device;
 host-controller = usb_host;
 ...
 };
 
 usb_device: usb-device@ {
 ...
 };
 
 usb_host: usb-host@... {
 ...
 };
 
 What do you think?
 
 Thanks,
 Andrew

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-13 Thread Andrew Bresticker
Hi Roger,

On Wed, Jul 8, 2015 at 3:19 AM, Roger Quadros rog...@ti.com wrote:
 Usage model:
 ---

 - The OTG controller device is assumed to be the parent of
 the host and gadget controller. It must call usb_otg_register()
 before populating the host and gadget devices so that the OTG
 core is aware that it is an OTG device before the host  gadget
 register. The OTG controller must provide struct otg_fsm_ops *
 which will be called by the OTG core depending on OTG bus state.

I'm wondering if the requirement that the OTG controller be the parent
of the USB host/device-controllers makes sense.  For some context, I'm
working on adding dual-role support for Tegra210, specifically on a
system with USB Type-C.  On Tegra, the USB host-controller and USB
device-controller are two separate IP blocks (XUSB host and XUSB
device) with another, separate, IP block (XUSB padctl) for the USB PHY
and OTG support.  In the non-Type-C case, your OTG framework could
work well, though it's debatable as to whether or not the XUSB padctl
device should be a parent to the XUSB host/device-controller devices
(currently it isn't - it's just a PHY provider).  But in the Type-C
case, it's an off-chip embedded controller that determines the
dual-role status of the Type-C port, so the above requirement doesn't
make sense at all.

My idea was to have the OTG/DRD controller explicitly specify its host
and device controllers, so in DT, something like:

otg-controller {
...
device-controller = usb_device;
host-controller = usb_host;
...
};

usb_device: usb-device@ {
...
};

usb_host: usb-host@... {
...
};

What do you think?

Thanks,
Andrew
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-10 Thread Li Jun
On Wed, Jul 08, 2015 at 01:19:26PM +0300, Roger Quadros wrote:
 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. xhci side of things for OTG/DRD use are already
 in v4.2

Do you have any plan to implement OTG(HNP) on some of your platforms based on
this OTG core?

Li Jun
 
 http://thread.gmane.org/gmane.linux.kernel/1923161
 
 DWC3 controller and platform related patches are sent separately.
 
 Changelog:
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 00/11] USB: OTG/DRD Core functionality

2015-07-08 Thread Roger Quadros
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. xhci side of things for OTG/DRD use are already
in v4.2

http://thread.gmane.org/gmane.linux.kernel/1923161

DWC3 controller and platform related patches are sent separately.

Changelog:
-
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.

Why?:


Most of the OTG drivers have been dealing with the OTG state machine
themselves and there is a scope for code re-use. This has been
partly addressed by the usb/common/usb-otg-fsm.c but it still
leaves the instantiation of the state machine and OTG timers
to the controller drivers. We re-use usb-otg-fsm.c but
go one step further by instantiating the state machine and timers
thus making it easier for drivers to implement OTG functionality.

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 in OTG mode. i.e. to stop and start them from a
central location. This central location should be the USB OTG 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 can't be done as of now and can be done from the OTG core.

What?:
-

The OTG core instantiates the OTG/DRD Finite State Machine
per OTG controller and manages starting/stopping the
host and gadget controllers based on the bus state.

It provides APIs for the following

- Registering an OTG capable controller
struct otg_fsm *usb_otg_register(struct device *parent_dev,
 struct otg_fsm_ops *fsm_ops,
 bool drd_only);
int usb_otg_unregister(struct device *parent_dev);

- Registering Host controllers to OTG core (used by hcd-core)
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);


- Registering Gadget controllers to OTG core (used by udc-core)
int usb_otg_register_gadget(struct usb_gadget *gadget,
struct otg_gadget_ops *ops);
int usb_otg_unregister_gadget(struct usb_gadget *gadget);


- Providing inputs to and kicking the OTG state machine
void usb_otg_sync_inputs(struct otg_fsm *fsm);
int usb_otg_kick_fsm(struct device *hcd_gcd_device);

- Getting controller device structure from OTG state machine instance
struct device *usb_otg_fsm_to_dev(struct otg_fsm *fsm);

'struct otg_fsm' is the interface to the OTG state machine.
It contains inputs to the fsm, status of the fsm and operations
for the OTG controller driver.

Usage model:
---

- The OTG controller device is assumed to be the parent of
the host and gadget controller. It must call usb_otg_register()
before populating the host and gadget devices so that the OTG
core is aware that it is an OTG device before the host  gadget
register. The OTG controller must provide struct otg_fsm_ops *
which will be called by the OTG core depending on OTG bus state.

- The host/gadget core stacks are modified to inform the OTG core
whenever a new host/gadget device is added. The OTG core then
checks if the host/gadget is part of the OTG controller and if yes
then prevents the host/gadget from starting till both host and
gadget are registered, OTG state machine is running and the
USB bus state is appropriate to start host/gadget.
 For this APIs have been added to host/gadget stacks to start/stop
the controllers from the OTG core.

- No modification is needed for the host/gadget controller drivers.
They must ensure that their start/stop methods can be called repeatedly
and any shared resources between host  gadget are properly managed.
The OTG core ensures that both are not started simultaneously.

- The OTG core instantiates one OTG state machine per OTG
controller and the necessary OTG timers to manage OTG state timeouts.
If drd_only parameter is set during usb_otg_register() then it instanciates
a DRD (dual-role device) state machine instead.
The state machine is started when both host  gadget register and
stopped when either of them unregisters. The controllers are started
and stopped depending on bus state.

- During the lifetime of the OTG state