From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751972AbbIFISu (ORCPT ); Sun, 6 Sep 2015 04:18:50 -0400 Received: from mail-bl2on0136.outbound.protection.outlook.com ([65.55.169.136]:60404 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751226AbbIFISm (ORCPT ); Sun, 6 Sep 2015 04:18:42 -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;vger.kernel.org; dmarc=none action=none header.from=freescale.com; Date: Sun, 6 Sep 2015 15:06:32 +0800 From: Peter Chen To: Roger Quadros CC: , , , , , , , , , , , Subject: Re: [PATCH v4 00/13] USB: OTG/DRD Core functionality Message-ID: <20150906070631.GE4914@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;BL2FFO11FD030;1:iNtgr0xlAm3UJDJq5tP/tvuFOTWIP9LaZqRFWfocUIKFnV2KlxF9hQ/PugFc/jHNfnZbCnL0lruZgFSEKC0ou1D07+6JomXB2HqtkFfDZQD6C6VIBq6tXg7TGGCzR9Cg/PhuhaaZacG7/Hc5AT6YGoNY6adNLB1LeLo76hETehPWh70Tu3E9XC2phhPCZir9mt0k6S/lXVA3j/1TJSLAspquyWcPcWaNnzDOOU8a/XqWFE4L9hK1Qn5xJvfR6oKnAGcVnSp6oQRb6bfYE8/jYNv4D27FDYig1sr05wLCKiYYb3FJQJpGCUohS3f8cRauNtp/Z7b7ZQ3vFI6zXD6Inv040xDe95PJFWtZ6VQwHmiQSFv3d/UmZH5Ppqg1rGjDrXozdAhBRnRB0tj9CGSk9WdCoRFPtSM9V50QPcikCC8= X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(1109001)(339900001)(189002)(199003)(54534003)(24454002)(46406003)(54356999)(104016003)(5001830100001)(189998001)(5001860100001)(105606002)(110136002)(68736005)(46102003)(50466002)(4001350100001)(97736004)(5007970100001)(77156002)(69596002)(62966003)(81156007)(92566002)(4001540100001)(33716001)(23726002)(2950100001)(86362001)(77096005)(50986999)(83506001)(64706001)(97756001)(76176999)(47776003)(5001960100002)(85426001)(33656002)(19580395003)(6806004)(106466001)(87936001);DIR:OUT;SFP:1102;SCL:1;SRVR:CY1PR0301MB1228;H:az84smr01.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB1228;2:D5q2qHaJcHyq9WrbhOwQGdvK3odD4yxlg1+uvmQgWPZvUDOlpnJmXIuGvpy8RkksFFcQNEo2buYv99AobJwsKD2aJzM8uNLXFInSQ7oPDeB/UHmVkGtTwF+E8oJcKC0i3beq2Kfbt6FqjbiuH0Bi5BAMPpjstDTShzdR8r4MmZs=;3:iXXoCD/RL8ooY4hJEoCU3uA7v09Gzl2H28qIyF8PaC2g/cJBfEi9m0XecDBZb94Z17OAmM8NfzRpGltcX9OSgF1ynvtCfhgoE7xdUqsxNj5SkRmzQDU0KmueDJujrWprIXHTSPmurkr78LY3rwWK4FU09op60fw2LdTCZT2whkz/+J9wh3JpJfF4pcE5tcf8XuAWMpgC/y1mlj2ksnolGQIVAUWP6ikxFud5H0iQFko=;25:JQRH7YR+RGwYlFLgUlo38JK5pizZ+6BpaU0jxshWN3C+IepxV8dj2b7MhN9xxYRKz/A+x/FXDj/PM2RT5tNilz+2+24gvHFZ6sFUXYGeNzFzL1zYeCjS/3gctKbJMPYB7+smLM+kbAtWWRHLjbxGH0n1khL3YA4OTaLlyb7SUX0PW7Oj3xJRkq3g7s7NZIGngEV6UWRRYwHRP2lhUj4Q3uPH0mnjwmam5fole9Aw8F7QtgOeum3yTC7qrSLCdYppNHFHCl4ICpjQE9/eFyzmJA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB1228; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB1228;20:G1sPsENlrM4+nnHnOp+mgImabJ1cL6pVfCjEfNNocTnzSiC0pf4WGVJZKjrxL5sLbznZkg5jen+xjSioN8Zyoh9vWZhREDEdnkSwb4Mf3Qw3j74b5hf/8tB820jNG+2PQFoPxhHqog6Wb4x9GviTwbKR+DWDejR4aypPVDpA8tdbrNvbQJhxlDcIFEXT6o4qvF1WdcyTMe0T2rFise5BPOTkatynGewnmGVDSaoCacdKzav1nThc0DupKK2UMrazyyG8U2BuYHaa8ySqGm7D1mi9YPJJGXGtIIAx+zyk93xmc0Y5zYpKZMpKj6uJTXab9I52UvvPCOddPni7Uf3UIFgQkiQW2WCVxdR7+BpzWsU=;4:sOK+foZSwIej7Rlf+tFjCbEvMyHL52YfGhPcVuA0pprz89+Q7mvMHT8Eb26kgAevAMaeNhiocQDwxlc3cHIYzYRv0KofrXodj4zcOoHv6nyI6fLKuNpg1sdpZEZNvH2rha0I82hg7h8LUZLwv2BOpYcQqz5Z9QQ8C0C5i7IyxRgpTcVqd9MqZvpzAjRoxYrTdUth+DYnkjIyEbSiguJ7sF7W/DYBb9gTWboAqV3HEPA2ApzNjMQWwxbdtn471V3OM3dL7vVCnrsh/24nv+IhSKv5a42lSXTHc8tD3d8logv66u0bbiaYiKYC/ANqIwSP X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(8121501046)(3002001);SRVR:CY1PR0301MB1228;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB1228; X-Forefront-PRVS: 06911FE69E X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR0301MB1228;23:isRihXp1vDXpP8IvX5oTbGvwPtusM3/hVR38qQ/?= =?us-ascii?Q?CnrW7Ao3DUT1bRebyJjasjAGICvMQM7XhHTNstsrI+Sqo7FDhVGE6/FfB/VF?= =?us-ascii?Q?CLkOKuJ6VU9mWCL+NMACCcI1WzxqIvevAFz8yY0aXJb4BdhXSJnjHyda5Z6R?= =?us-ascii?Q?qy0ChumxM3eIe+bezooW3GWYKvc9LadFf1Gl1FE1pecE1xk7opQHZyGuadAi?= =?us-ascii?Q?3eHOvXn9jMk4EieasE6IfAad1RnuN44Xfi1ZQEXtET/DowbxdwBmlR77wkh6?= =?us-ascii?Q?EMfl0tG03Ls4Z000sAwF0RXKwKE8O81+T6GvXXBmYpJt8RCjQyR55RswlFWJ?= =?us-ascii?Q?SALuLCqjlA6NuCstrKu5rwJriYHynIwrwDPbSGH4qR5wpausV1fpxFS+apAn?= =?us-ascii?Q?j4321eETX9G2JLf2fyXA5ijyCntgcET3o5Pdql4urgzT/sHCSPQbW3ZW1Nij?= =?us-ascii?Q?aDk5XBe5ucxssMZKPLdGBtESXfpJeZbohloJNvG5RT0iU3EwBWJJSVZvdBNM?= =?us-ascii?Q?yiAeSV9EZH9dflr3MgPr9Rqo3TelXIqz6jvT3ZYw4I/07fmYjEtUaOa+J4UY?= =?us-ascii?Q?YfM0TyVK8elYmmD4qg3LxaLZ9/kt+eLqgyj2hBw97mSEk2pKsHbFrOpFCgbc?= =?us-ascii?Q?B6e8p2fPJIolrRqFpm+Va0j+5ZsmL04WFYC3kUyvtthqhz6hm2fzeKUU9Nym?= =?us-ascii?Q?FJfs6Mu5nNE7RvdhL6ZEWQOmPs6n+UkprsHzXUAZXx/9y/CalkS6bGZgu21q?= =?us-ascii?Q?q3ghGhdTuB/vV5lR8sZe+IaGOrWev37YLpD2wdkwjIguqNkzDDj96kXEtxBc?= =?us-ascii?Q?URizpWwFzt5loHdjr8ia3QRsjiR2xVzdCP5piTDnaWQBrhZZIEzBo42qESH9?= =?us-ascii?Q?/vbycJhl36wv3Km0ZRdXGkkonIMlnP71+cRN2Hyc0RZvx/GhuL0WL/JahCP2?= =?us-ascii?Q?qBOv61tRfgc1ece86VaFhbG4JwBu8zRmROqFIB3/a8QmbV4jiw+G5HGbFR4V?= =?us-ascii?Q?meryvFt2+087rKs2Ko8kTIP2qtfRIH9l+juK62ArZl/8j6SZyKvj+Y+PRJtQ?= =?us-ascii?Q?4VqAdviclG1pSCUD1qFTBaa3rpy+sL3wTHSIWnrUwvYk8jJfY2EuUb+QvSeI?= =?us-ascii?Q?RVOws+z8Tgw1s204aRmIn+HWn/BCZztZrfh57+Zem7nOrP5kx1ezBO2/EXYf?= =?us-ascii?Q?cZXadsCPD4KTew0GzFeiMG5urjpgh7An2vF5NB8EGkV4otseLpgtRMFnFhg?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB1228;5:ultfOtxnWHiY0sGD+cSRxbhaxg5W3w2uLXa5swWiEpw5FAHGwBToqBNjkd3Kh2QhUxQGrxy0VL1zq1hZlSauMA/ZLUAi5t6UuDnGL3MpMCVEmyMOwecEZSXFKzG1fN8BA6kyqikVB50DRUgpt1AdsA==;24:7Ch5SE42rm4arNrwHu5oNEnXI3PypZqwxWXt+EdVLIWWku09RlJPKFOO+YdPXAjUXJvFCnaacaFZ+SdwjnzpPtc+RBa5O4ZCPMdt2f0TVP0=;20:QTaaDPhWdlqH7CvFgZ4S8fR0nIfvzEhjHrQH1xnEyF7oTUmz9SxHjiCw2qa/Y6YYFJRSOFqQtTsGqIsQsYsN4g== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2015 08:18:37.4643 (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: CY1PR0301MB1228 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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 Roger, thanks for your hard work. Since it is complicated, and can't know its correctness and scalable well just reading code. I will run it for chipidea driver, wait some time please. Peter > > 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