Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758802AbbLCIXd (ORCPT ); Thu, 3 Dec 2015 03:23:33 -0500 Received: from mail-bn1on0114.outbound.protection.outlook.com ([157.56.110.114]:51552 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751580AbbLCIXa (ORCPT ); Thu, 3 Dec 2015 03:23:30 -0500 Authentication-Results: spf=permerror (sender IP is 192.88.168.50) 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: Thu, 3 Dec 2015 16:19:52 +0800 From: Peter Chen To: Roger Quadros CC: , , , , , , , , , , , Subject: Re: [PATCH v4 00/13] USB: OTG/DRD Core functionality Message-ID: <20151203081951.GA18533@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;BN1AFFO11FD019;1:BoTUD9d9ZZl/dPjleiXjUjDoORDUtj7yAL0WY3WvCNSAv3gjgCX/AafTImzLDnUKK0th09vXJ3PrZoyYQ3+/Vtv6mW3/9GxoQh+jojfwrzyvL2U+omOpMJd6DjXNffkulUN66yRWzalaB2bneMMszOd2vleCehMuU0xSGcdFGFSQpJqCLH7FEhV55HgRYU8yEl1xaLSA2Gj3g6W+GgFxf7y/kQGv6dhSZlBLQgXmYgRrcWCLRfihteeksS9vPXv7C0JzcjqjbrI4VtvsjkMx5NrrCZKwMivSK65MwPWDoxBOv+xlLMU64oXiWtOeH2o0l0K2LjinZOV/dl44n/6FTN+N4rMWUBKKV7QO+0jJBv/KDN7/gkal/jTXqhbSJJIQk8o76JYaBw+25kdyn6J5iouFJk1RgnoCpPt5unqJyV0o1m3dd14Y0N0czgEs7OLYDseJWAzdoXLUdfWBx0OPvg== X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(448002)(54534003)(24454002)(199003)(189002)(33656002)(1076002)(1220700001)(1096002)(189998001)(586003)(23726003)(104016004)(5008740100001)(54356999)(86362001)(76176999)(50986999)(6806005)(50466002)(106466001)(5001960100002)(19580395003)(110136002)(46406003)(83506001)(97736004)(2950100001)(85326001)(81156007)(87936001)(4001350100001)(77096005)(47776003)(33716001)(92566002)(97756001)(11100500001);DIR:OUT;SFP:1102;SCL:1;SRVR:BY1PR0301MB1224;H:tx30smr01.am.freescale.net;FPR:;SPF:PermError;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY1PR0301MB1224;2:1ZzVxTuepHc2oU1Vo5GvHvv1hzLXS+jHbzsbOlcRGQGpkEQ6dUIBpNCFCTje1LZaRowvwlBj5mTpfJlqLzHdZEfWVOZEMTQiUIliqZX6iLAIMJV/nh2uTXkmFn0zmANzAjSd3TrR8Q2CnYakf/VPQw==;3:Ra46Bj0im/57tmh7+f6DJ2QJSPzmgrN8OerGAKF6NoQVMi5IBGaRFKEGWsj6X9PD+GB4ynyhfDAJCbnl4kKQ7NXE/PIngj2GwlUvYHJDqIYUic4yA3CV02cbyRXONw0sRq3nalydzXdpQ675y/H0scdSHp+YwV5yBItZ8fg5XLpFLJlmpTHINn+TpHepJGWSXaGgqEIMjU+O2gY1aCTlhIXcsJcsNVyt+Bo+UkKW3Zk=;25:Qufuu/FZk+gaohtAgUZpW87V+s8rWtdEzll55RBCFIlnuN0unqW0VPgK6gk4ND4mCg4adwdKVwbPhPZ06n7TKisHMz75mEVSgkoGj//CZeVU8F/aJFENIupbwfzl9s5gFfqM0kkqgz8xbhW6qgfDTZIXqkkN2GARNdJMjjG0pXFct3ta3CH7elbqgUUwVkIJ9tk7VksSDvTkaQyzPNR8jdSMHvnz8WsOnLnRX4T+hsI7mBhwdUJSY/MpZb3ayKfq5C0orJgcQX6SYQl9L1cmjw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0301MB1224; X-Microsoft-Exchange-Diagnostics: 1;BY1PR0301MB1224;20:K2Fd2oQYZCC+yBOVgzkWWka11+81o3wDN/vJinMJ/T9FWZnxeed2sglpQHQjUZIQAQUn7dhQEYyT3GUTqs3sedu44ew3fuiL7dECyuSqKKD9Gay1aTJpYOf3tnxFTzg1QtxHnNLOFfADfu8UTM5SNjXBmohdq2Z5137yTvuku7Aa8xOCvJ/O3YkHvk4E1sfSJOdN18t4j7e/p9NjhPP02Z6nCRylTVqC7rqYjrnp+ZkFDqkI9CDnnAoMhTxdeTqDkOsgAv/XxOnZcfJ6wevo8J+49z43f6vqooFg4xWKo2xlEZpu7Mjq/SQcYz8a26h8kz4QMDnQ7ofK0MMd1iTQWfzk2M4N+H8/jxaGmGWVzlM=;4:XChIIZHbDgDDsKtVkNuDs1tmG8DI0uwj17Y733BpXZG7XD78sDDohLgsj7WRooRU24WEdtpabAm9Gf92TUw50G+azvWb4CsZHBURAjCpH0LqrL/Wqw5FdJdA8dwbv9bJpDo1IbS2os0MyVgOpKOaKFFglFPH3Vh0R1UrWc03JxJ/+ypHL61TlyotXUpUM//caLgeyzTPDJeCur0x4TGbPucCq0n5Lj+9Lx0Nr1tm3quFi5pwlxIOzMUpyWxF7hyuE0K2d6oPm0n3W/iJmLUN/X/TPvbf2TMEx9mhJOJBcH7aW4tcVYF4rXTL7zSixdmW9MnAkY/nhQz31pMBHFpKiVohT7a/p9UJ+GYcTlD9Kswkkpoi1QxV14QEbTn9pMyR X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(520078)(3002001)(10201501046);SRVR:BY1PR0301MB1224;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0301MB1224; X-Forefront-PRVS: 077929D941 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY1PR0301MB1224;23:Ztyisci5BPhOYmjiFq2xyy6KT/6DJOdSasI1wvQ?= =?us-ascii?Q?vZxF1GkUy252+ss8xXH0pz1zQWbr6vAEIuUt1bJSu7PHQhZ4SrNJ0embJvj7?= =?us-ascii?Q?r2/Y6LMofsUYdcUT1Nf8RrdxGKOzUdYZiI38bBQCrT7Uom2TS+CL3HaFxX2S?= =?us-ascii?Q?okxwYUlEBW2riaAwDoI2a8xtQwAdFkiSrsDZIcJuk+Ts9xWuBvUue1t8X33I?= =?us-ascii?Q?rqvNTlu3FVOYFqqrWp6U/pS4+Ukl/lxuyGkMVGym2v930VCr/MXNLKxDWMH3?= =?us-ascii?Q?3hbiAJ9xIqp3G+nxUFahV3ZCoriyT4a+k3b5yn25/kQZHyLDgdtd2Bp0OWQf?= =?us-ascii?Q?dE0OmI88IxRaLABRYKMm6uq5LzCulTcwpyqsgYHaCXvCrGrUnShUK9DBjs7f?= =?us-ascii?Q?khGi+qhhG5mNrxbaOnL+5ZYwOzYhiDfq//n0EKieQjxG62mhtcxAXjVMaw01?= =?us-ascii?Q?5WgMCx8sferBs2v74OAoV+g/10AULHpILnF3oiAQnbODHHFNOc1jG1+9B4GC?= =?us-ascii?Q?35cQKLH+Zsazss/Mnv1PpJSgdBQm0IimCctIT/2XlZtCJDyYQpAKDeqVKntL?= =?us-ascii?Q?JDw+nR/X+cXiWyQhta6Nqw6pySyGQM26Nyh58ZaWeQqzvJzTigQu0X4MTC0+?= =?us-ascii?Q?Um0r+b+fcN8bva5PAznY4RZEfb9yXdiHoa/xaL4J8ZhP8CmPTY3Xmpa50fMT?= =?us-ascii?Q?EFH57bs0WTZpmDxWJHSXFcxALrvcnWHPxFsCnpvAe7AzCCEB3PzpxB2z+Esv?= =?us-ascii?Q?TmPV9QIuDMT63zRf7jDlDN0q0ChJdY460vg6Ud8bo19BGmMFbtKGmxIkoLNo?= =?us-ascii?Q?aFXRA3pLBIXk54rTO1z+giBizdma4XjjP8skvkh+0xAO9Xt8TvvhY5JaWejD?= =?us-ascii?Q?3cYRjWQhNv5X+Qdg+JN3SHLz8NBvPnBiPPLRIZyqr05yQu9V3knRcGCd5NWf?= =?us-ascii?Q?Bp8sM6Lt11RmP3NmBBW8faVI/5LjaDVDRVy4B/ReS09o4vJmqT9W43XJQSgz?= =?us-ascii?Q?pYKCzuuDQPX2E5H808HwLwwpCH35Oj+EFoczeKqxdYRiRBc+KYdQypsqoWeL?= =?us-ascii?Q?5PYXlfkM=3D?= X-Microsoft-Exchange-Diagnostics: 1;BY1PR0301MB1224;5:r4z3tFKsNFKA2H+ktACDUlBYG62ofUzQ+FNV7Jn+worH2fEQHPIG0kjrwzHYeZ3CzJ0XHS4hNHgVd5Yich7XvcUiCwlAubiHm2txLpcNCG+rkD7LsMOBJDtJLYDKSUBMtkvTo/HV1h6C/KT3V4QBRw==;24:xicak1X+lgLylUenpbvAGf0of22OmVl2smEMCii3RrsPDeO9G1WaFNwRVuzfBWWv9QmQq9D/gm/txrs3ujYmpTtj+l/4Y2BKaPvvktIWWDU= X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2015 08:23:26.6164 (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.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0301MB1224 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9681 Lines: 221 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. Hi Roger, Will you go on for this patch set? Peter > > 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/