Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756656AbbHZHb2 (ORCPT ); Wed, 26 Aug 2015 03:31:28 -0400 Received: from mail-bn1bon0147.outbound.protection.outlook.com ([157.56.111.147]:53921 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756446AbbHZHbX (ORCPT ); Wed, 26 Aug 2015 03:31:23 -0400 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none; Date: Wed, 26 Aug 2015 14:19:51 +0800 From: Peter Chen To: Roger Quadros CC: , , , , , , , , , , , Subject: Re: [PATCH v4 00/13] USB: OTG/DRD Core functionality Message-ID: <20150826061950.GB6435@shlinux2> References: <1440422484-4737-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1440422484-4737-1-git-send-email-rogerq@ti.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD011;1:Dh7wJxgWvLU6qoWDV4pCj/50JpNjk+kKU6ABw/XKJ/eAwnsjlnzBtiDGmX2b04R3Mdqhgnq+wbX0EaI9zBu+mcF0+PD0+Pl4+U5gOS34RHyeUfZG2RGCZICxsrUeLhr6D/MFFiyk5gtL4+18OOlPnC0TImVlqzsKC6bTI80ZRJRVJe4ZC4jCtdgA+7clTlPXWt3Tz72tSooBMEW3Is+atNuMKKeFI1m8oYE7bvkIUTOL4AEUAeLeNU1UvPj9w3wn7Ezx0j7pteqj93cJ1sVjGlCVpMRoUhFS5/hmvmwtyYwu8Ni6hRPk/wh1fhoEOUTQZV6/3WWCNEmSo8JVIjHmw8//JV8qAKsbvwTg7crpJBOOEwrWibe3hFg/+jhZ2c/Kzhu/2bLs4CfnopQpkT0VNQ== X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(3050300001)(339900001)(54534003)(189002)(24454002)(199003)(50466002)(104016003)(77156002)(62966003)(5007970100001)(77096005)(19580395003)(4001350100001)(4001540100001)(23726002)(81156007)(189998001)(46406003)(5001860100001)(110136002)(85426001)(33656002)(33716001)(5001830100001)(97736004)(92566002)(5001960100002)(6806004)(2950100001)(105606002)(76176999)(68736005)(46102003)(50986999)(87936001)(83506001)(86362001)(69596002)(97756001)(106466001)(64706001)(54356999)(47776003);DIR:OUT;SFP:1102;SCL:1;SRVR:BN3PR0301MB1218;H:az84smr01.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN3PR0301MB1218;2:LdEC75hAw8sWq7PElO641NmTbKudGPk0WA3PkrFmsbwJ8aQRiP1DzSGWaNxGn3NbNCtD3hlj+Uyo7YJ9wlJUwG1VBSI4ZqckBrVIXUPIvm6nQwYxENd6OF+sxaskI/X2IpKbbFIu3osumLJCGtGxy3ahJfE+P1Oa138gOQSegIA=;3:1XDUyn8qbeeDCMBegDEkvWCUsu9OCQw5TX0NwmelT+LK9ygnPOW01AocBFC62COLPPrKfhh3D/sy0M+MBc8hXBWkAl5H646411vDuUeEidEpyFk+8JvEV157hEydCVd2mL4TGwZZo+DXZL+vRZ07GlZB7Zd3sjPwDGq7/BuYik3jfpCbcQ+N/gSpBYRWTs2uQPJelmXy1gnUCM1jDYxgpJUVzCmrtZAkUEWjt50sv4Q=;25:k94mwguJV1ObR473Ra/ch233EMQabVb4Z40yCS5jjnN55cUnlGVdsbddErWQLxHGSRyfiVOk65vEGEV4YVgypKAGJ2a0MUiSuW8rre5BBL1wLP0Gk4DaG1gw4DHWJeBjEPaANVEf8/OgqVA8gnFxwSZaHFIdCAP1JYcsKDHA2cud617wa6mmshWmAgvxqW2SXVly0/CmxZ+zbnmPVP03QyEJwWA0V7traYP+3oid2+ZlnueYeNMwJ0fo971iHk94BuVsn3H1IhIpfZZFC0NKoQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0301MB1218; X-Microsoft-Exchange-Diagnostics: 1;BN3PR0301MB1218;20:GbDWMdJMyrJwCb+lgpd/NzgQmQ2kT9Srwf8AbtUCShGRE5XQJD0ULqpbMndyh+sABq+x4EM8mrBlQ2b/uBRaj+Ta8POWJ0W2oAyPoXlZwplRKmojOrltrmcapAW5I8sSGNC0e4vPsuZ0ujoyBhGplBUOLdN5Yi3YlnBjKqrwnEwKw2C1dKVVWKikaYhZ+fXLfwwIKJp66aeN4oRT1U8pGLW2UMqW70yfDUv1+h/vxWpdwwXpsOnhoAWKkFrri40ocVbZqM1BIUtue2AnrWMxe6a9Z0aRLGP9WqPztgQIMa+u9675PFJzCgqHayStYKtuWFCL628oU+fueIXCQ1YRxcwwfVft0DcidnDwVbTrKtE=;4:/QczrbNAUCnLR4h4tq3u9AyJv+7338CVFY9pG2pSALiUcas3wqEZq4qJX7c/+kjFpIglYrhDHlg6TCO0ki/5x+SubBLbTLir5TxNgUgg66/BE9c664P/rGA8u0VycSWmybnIT5vL5bYNpyLmi6KRUiaSFG0ruMMWvt17WWer1VTH9IWkc33EHiO7JgHX+Cw9ILDDdPJADq51NMcTweNRvhaKGYDDMULRqHPTIg5k+jfTLbVdRBWYpnXYEghbIjLqg89xroirEkqxQmOs4D0kBDbE+I67mAyzkXEUrQj4Vv6fSQ9sTh/QG+491T25gG8K X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(8121501046)(5005006)(3002001);SRVR:BN3PR0301MB1218;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0301MB1218; X-Forefront-PRVS: 0680FADD48 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BN3PR0301MB1218;23:V8GcJtR+BpeN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ii?Q?BGsdRgfklbhkw9C1ToE89c4URYCrGVggJlEkpVmUPSTcJXfQR0vXVSADyRek?= =?us-ascii?Q?Rrs36Y00pfcSq+jATPhjWjNCsQC77FQ9XB+wlYHJWw3By336HRorN4LZDI/M?= =?us-ascii?Q?utRVXOdaJJSRfksiN82i0EzvVCWuYu3LvGEuzl6xfoBi+4aMkKeNwrYwfI7P?= =?us-ascii?Q?PQ1G7zajJlLNbG0xZzzqKppVbuc4k0oR06wMRMyfcfkJlvphoMy/+dlbpwZn?= =?us-ascii?Q?Wtzyy7kR/w8piNBS9R7RbaqAsCRUZ47W0mcrHuiqtFlyEQxw2eSAcWme5c7g?= =?us-ascii?Q?JH4hkOcCuYguNqN0QPKrf1XPfOhCbicIbHl0mMF7JUPg8ozEq3N+tYVlhVg?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;BN3PR0301MB1218;5:q411U9aeik7/2LA05LsFqHhBFL6ytvs02NV8uSGgOHSy9h+87jz/tUpg5e0vU1WzhXRnkw4aJpWJ/IQq5zNicOar99is4F0orC0P3FxiXetePgVDSnmrOiIfNPw90ktyNmPnGn/DsMQaLlJ9AieHWA==;24:HhaNw8z54CHBVh5Fcbiy4ZTcGorXRBT0G2fjiN7DKVjbyXN+gbqcXQmq5hODhVFylQPa0Q87TjAXAdI03LvP5Ox0+O5ED5fA2IsMwyrLtnA=;20:K9wXLOtSuP32j+E5s4+xijtyo9ezIco9HatUqoNX1u9gDBPifmkr1sn2OTT6BdeDopih5ZLGOqTlTVdes2g2cA== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2015 07:31:19.2216 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0301MB1218 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9741 Lines: 220 On Mon, Aug 24, 2015 at 04:21:11PM +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. > > DWC3 controller and platform related patches will be sent separately. > I will review this patch set after you send the above, it will be more clear if there are users for code. Peter > Series is based on Greg's usb-next tree. > > Changelog: > --------- > 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. > > 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 *dev, > struct usb_otg_config *config); > > int usb_otg_unregister(struct device *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. > > - Helper APIs for starting/stopping host/gadget controllers > int usb_otg_start_host(struct otg_fsm *fsm, int on); > int usb_otg_start_gadget(struct otg_fsm *fsm, int on); > > Usage model: > ----------- > > - The OTG core needs to know what host and gadget controllers are > linked to the OTG controller. For DT boots we can provide that > information by adding "otg-controller" property to the host and > gadget controller nodes that points to the right otg controller. > For legacy boot we assume that OTG controller is the parent > of the host and gadget controllers. For DT if "otg-controller" > property is not present then parent child relationship constraint > applies. > > - The OTG controller driver must call usb_otg_register() to register > itself with the OTG core. It must also provide the required > OTG configuration, fsm operations and timer timeouts (optional) > via struct usb_otg_config. The fsm operations will be called > depending on the 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. > For DT boots, If the OTG controller hasn't yet been registered > while the host/gadget are added, the OTG core will hold it in a wait list > and register them when the OTG controller registers. > > - 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 none of the otg features are 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 machine, inputs can be > provided to it by modifying the appropriate members of 'struct otg_fsm' > and calling usb_otg_sync_inputs(). This is typically done by the > OTG controller driver that called usb_otg_register(). > > -- > cheers, > -roger > > Roger Quadros (13): > usb: otg-fsm: Add documentation for struct otg_fsm > usb: otg-fsm: support multiple instances > usb: otg-fsm: Prevent build warning "VDBG" redefined > otg-fsm: move usb_bus_start_enum into otg-fsm->ops > usb: hcd.h: Add OTG to HCD interface > usb: gadget.h: Add OTG to gadget interface > usb: otg: add OTG core > usb: doc: dt-binding: Add otg-controller property > usb: chipidea: move from CONFIG_USB_OTG_FSM to CONFIG_USB_OTG > usb: hcd: Adapt to OTG core > usb: core: hub: Notify OTG fsm when A device sets b_hnp_enable > usb: gadget: udc: adapt to OTG core > usb: otg: Add dual-role device (DRD) support > > Documentation/devicetree/bindings/usb/generic.txt | 5 + > Documentation/usb/chipidea.txt | 2 +- > MAINTAINERS | 4 +- > drivers/usb/Kconfig | 2 +- > drivers/usb/Makefile | 1 + > drivers/usb/chipidea/Makefile | 2 +- > drivers/usb/chipidea/ci.h | 2 +- > drivers/usb/chipidea/otg_fsm.c | 1 + > drivers/usb/chipidea/otg_fsm.h | 2 +- > drivers/usb/common/Makefile | 3 +- > drivers/usb/common/usb-otg-fsm.c | 26 +- > drivers/usb/common/usb-otg.c | 1223 +++++++++++++++++++++ > drivers/usb/common/usb-otg.h | 71 ++ > drivers/usb/core/Kconfig | 11 +- > drivers/usb/core/hcd.c | 55 +- > drivers/usb/core/hub.c | 10 +- > drivers/usb/gadget/udc/udc-core.c | 124 ++- > drivers/usb/phy/Kconfig | 2 +- > drivers/usb/phy/phy-fsl-usb.c | 3 + > include/linux/usb/gadget.h | 14 + > include/linux/usb/hcd.h | 14 + > include/linux/usb/otg-fsm.h | 116 +- > include/linux/usb/otg.h | 191 +++- > 23 files changed, 1808 insertions(+), 76 deletions(-) > create mode 100644 drivers/usb/common/usb-otg.c > create mode 100644 drivers/usb/common/usb-otg.h > > -- > 2.1.4 > -- Best Regards, Peter Chen -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/