Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757309AbbGQI6H (ORCPT ); Fri, 17 Jul 2015 04:58:07 -0400 Received: from mail-by2on0101.outbound.protection.outlook.com ([207.46.100.101]:62336 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932438AbbGQI55 (ORCPT ); Fri, 17 Jul 2015 04:57:57 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none; Date: Fri, 17 Jul 2015 15:48:35 +0800 From: Li Jun To: Roger Quadros CC: , , , , , , , , , , , Subject: Re: [PATCH v3 07/11] usb: otg: add OTG core Message-ID: <20150717074832.GA4515@shlinux2> References: <1436350777-28056-1-git-send-email-rogerq@ti.com> <1436350777-28056-8-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1436350777-28056-8-git-send-email-rogerq@ti.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11OLC011;1:H6wvG7LW+qibXADV1QjQE8UGX0GgXwbeHmfssjrLSdLYjiCnnPBVjTLI4jxsYo9D8/Vj1gz2G6p9tXokaC8xWByxMAxVlCVam6PZ972TLVOosSMSR+uAYoHhglwFr3s9LbPu9DjCTRFaBCX0RCMdh9nLyeb4ArxN+pjE5u/MGgAA3JG74J60HPwLhl3JeMdnjRVd7unj5Nbny36uTLrSiBJ8kx1pmjCyNv4nn66/viyp3I0alu1/7iEc3NW4xcj5WkqGuJv2dSuGGTecM7CgnwY4fRolRRKWtGFBAPuRArnWbj3OWwqcFbnbwd4ra7r9LfcQbWW07avi/9kgLTcAj6L+d9D96WFWU8mBkEa2aN1NnRb4fSErsvdAh9gJ5arXJTZddp7paSGqoIvb3lFVf82ONSZ93MsOukjdLFthKLIXmCHygqXA+0WmiWRDf/hy X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(339900001)(43544003)(199003)(189002)(24454002)(104016003)(19580395003)(85426001)(15975445007)(23726002)(87936001)(77096005)(2950100001)(105606002)(47776003)(6806004)(92566002)(46406003)(77156002)(83506001)(19580405001)(16601075003)(189998001)(5001920100001)(50466002)(110136002)(5001960100002)(46102003)(54356999)(76176999)(33656002)(97756001)(50986999)(4001350100001)(106466001)(33716001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR0301MB1229;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1229;2:FIOrW6zYqT8pDA3xW7S7iBOAy8IyqPk6tH9CGZ8X/0PMvqKN82tnzNPcA40DFC6Y;3:wWymkdNyFuyEb506ucmqAztmLtvWE1X+QgrcdEWRSqPpqRJggN7SVqMi4NHt+XwqKQdakS26ebG9G7HoirWZEvKg9zDDaOX7rqs80jMpelTtXHIFaiUpJxvWIJEjiPlMPeS/QT5d1VycBwwg19zxw+4D16ePAv5TEij3TyxWcjoyQ+TaweE77I6XFGZmGb9csysgp+bqwdwVIJCHTGnUDz/RhxJNa8nI3BrcgpQECpo=;25:Uj4aB9Esy9gDlCY+mI/RTzNwwDe320SffkFjz0SiiczGcC3GEqVkojeilZa9F2Hj9UGuSouzfQnL2JUPjXFfmisgQkIenG5Icwu/ujGkQWXpC/BZ1V137Dw0WndPAOeOJgnl44Kk6Z8Xt6JxKfTsK8N8F9shfZh8w8X/7Vggt0GHc1fKK8/XZrvBS91eV/T5xTCavF1ezyVVgsX3mvmHjM6+OhTFv9ULXwtR90L7G0njv0xUTl/V6P3x4ig0MfDy4b0UfFzuFRBttIlUFe1dOQ==;20:p46dHjkmYnslZdqpuqMypO6FTfX5RFwjgNs6/5DhEHTJrjoUH6oe40KFvfChE8gUdnQqXS/nVmcPlc3lwsB9jChuZ9Hm0GL3bKGpdAh47RuXsPrwhPOs58A01UAzKrFYnDcrt/2nmqtip/OeFEy2S8rXg+rsIz5wvan67/S4Ywz8DBVSRal2gO/m7b/44JU/aFHRPU9I4MyJnVFk9nzmlU2iyrCjjlN1BWppKh5AmWk7xiqUWj9AUCE5YC4N/LH7SFEohda14AUQ3w4xeqmmiWSCVH9BIW8jjRRqcIlsTCCDkuuwXIpTR8r2RtiD8anbwsL+jQKeuHGlhCygYvFAsNnhltOAiTYf7OWOv10M86k= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1229; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:DM2PR0301MB1229;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1229; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1229;4:78nqdPtS7Uce+u0zeCQ1QA0t61Zkv6fkTWypEaq0UBTiJcK/SeCtqx0712RgT2bGbe9Fvy6kuvzL+PiAcomDzdWkaAxfPTlGqYN/G6omIqGfFUtMwIZnAdoCghOusm8YbG01dzr6YJLJgr7mL2FkyeNHSdGjL0tWPtyTAqrP6ho9wIYlSqi/B/iArRjWNYU3yyLO+fJVe8WK1171qPPS2b35YQOy2sihPQGyQXjWPvPnn07cqPr7khMPnAW78xPo25NC2GXs7kPoxEZBturfVCIoLQgn3uA+/8TfT4N3xbE= X-Forefront-PRVS: 06400060E1 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR0301MB1229;23:ZWTDhQgO/OMnImNzLmkhWU9iBxXmq6mC0gS3Ixm?= =?us-ascii?Q?eOFnPzxGofD3efvaRPTy3YMK1vt5KeuVNtk+3EDMdA70AckwCi1UNYPs9FjN?= =?us-ascii?Q?COX2kY1pjRTJMJhH25NOpykIiUOlZ+KSas5cY0MHSW+ODKi6F9v2UbEqaf8E?= =?us-ascii?Q?clnmsIYWQgecuwQq72cAqFD5aEghvhC4AuH4qfgciK49oLH077SKHINKr1yg?= =?us-ascii?Q?Y1Kt5aTC+LYjrx8lRevYWgwgYwQ2NvejN4UkuYsBAuxEu7wPWTIWzBCsV2pZ?= =?us-ascii?Q?NvMCnl+ob+DMdOYbFzLB+8rHCyYZL1AlEJDnzBH6bptk3EnaG+I5vq0KoY57?= =?us-ascii?Q?nWx/cKUsuUJ8J7FC9RKz3ENnpD6RsXh5bAq/JRTZHs8NqnGc9Dj1ofaGhum7?= =?us-ascii?Q?Yn+qlK+n6MVRo6EaOkzrMhe7+QbM8ACrm/4rOEQMsNWpYelJTqP71VKBrV1O?= =?us-ascii?Q?OSbuT4TLBcv4xcbNhL9cJBcqWa5F9qALy1O5xDEezUl9nxOJR0rgR1vt1bXn?= =?us-ascii?Q?AYPIkapo36zHkB/9ROGAJZCeigBVGchQId5OXuzX9L+fRutb+Wy1TlxpViEr?= =?us-ascii?Q?CosC3nfIrTFQICK8iVMiLwDg8toy7VTVD9mvdr2n13bwB+VgleYCnkCLqdTs?= =?us-ascii?Q?uRiPHBGv7NgBipj5nn930GdVlHtdTKVVDKvVv7LM9MlvNiK5X85IVb8/ybh7?= =?us-ascii?Q?M8MxN3tQsPM93vpsKyBWQKmE+bmITo0wgj6fC5lN1/rKoAWsUGB6z355aq5j?= =?us-ascii?Q?vh03cLzVvA34LbJWSMZWkgtdUQQ+y+uxyRYYth1dwnxQgbUuXak19ZKEE8MH?= =?us-ascii?Q?LIwB+HMLtX0sy8lzQly1AIai6jVElmkfgytWVs66ccmk0zI7A2P/4QASK8K6?= =?us-ascii?Q?qYd8/bKCAOpTMkb3cMUSEpDOhi4kB/dPek5BGFOLTvBERCITw89YGrgLtSo7?= =?us-ascii?Q?5JcitLmfK4kVWgipyPSFGAtPVjDc33S3LjjgktMfG0PK087IbBHwjIkCDVU0?= =?us-ascii?Q?LfXv4tpo1aLvNkaQrupU9J239?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1229;5:UpRyAOFmZX8uhCY3TZhWoN6HgtBsPiVauovJ38X9WnzdOHjc/IfNXBRkHrJFD5HZ7B5t8IAw3kBus0UXY5+w9tf7Ovlerqj9ITGkpthHiM2ojjolc2wulAouSRrKpSPL+/yO/b3fQTgPNi/OGxuKbw==;24:wWQtPrkPRCPMhZN6YtS/krAWgWGWHMjQwWjnV74EskCmkB1+pfEPzW+9jlOV9LoOc+9H/pEeiplMFPLF4jGzNkzzOZre8SQVArAa5XA5Jwo=;20:puqaCc1uy/M/QOqgZ7LScR4LdfMBDp7YXxP6itVPPn+VsCJ7pnpD22nCZy/h8BJrsLVnrK0snMIMb5/InEWA7g== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2015 08:57:53.9302 (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: DM2PR0301MB1229 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 34086 Lines: 1138 Hi, Roger On Wed, Jul 08, 2015 at 01:19:33PM +0300, Roger Quadros wrote: > The OTG core instantiates the OTG 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 tasks > > - Registering an OTG capable controller > - Registering Host and Gadget controllers to OTG core > - Providing inputs to and kicking the OTG state machine > > Signed-off-by: Roger Quadros > --- > MAINTAINERS | 4 +- > drivers/usb/Kconfig | 2 +- > drivers/usb/Makefile | 1 + > drivers/usb/common/Makefile | 3 +- > drivers/usb/common/usb-otg.c | 768 +++++++++++++++++++++++++++++++++++++++++++ > drivers/usb/common/usb-otg.h | 71 ++++ > drivers/usb/core/Kconfig | 11 +- > include/linux/usb/otg.h | 91 ++++- > 8 files changed, 930 insertions(+), 21 deletions(-) > create mode 100644 drivers/usb/common/usb-otg.c > create mode 100644 drivers/usb/common/usb-otg.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index 8133cef..b21278e 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -10640,12 +10640,14 @@ S: Maintained > F: Documentation/usb/ohci.txt > F: drivers/usb/host/ohci* > > -USB OTG FSM (Finite State Machine) > +USB OTG/DRD core and FSM (Finite State Machine) > M: Peter Chen > +M: Roger Quadros > T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git > L: linux-usb@vger.kernel.org > S: Maintained > F: drivers/usb/common/usb-otg-fsm.c > +F: drivers/usb/common/usb-otg.c > > USB OVER IP DRIVER > M: Valentina Manea > diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig > index 8ed451d..5b625e2 100644 > --- a/drivers/usb/Kconfig > +++ b/drivers/usb/Kconfig > @@ -32,7 +32,7 @@ if USB_SUPPORT > config USB_COMMON > tristate > default y > - depends on USB || USB_GADGET > + depends on USB || USB_GADGET || USB_OTG > > config USB_ARCH_HAS_HCD > def_bool y > diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile > index d8926c6..769d13b 100644 > --- a/drivers/usb/Makefile > +++ b/drivers/usb/Makefile > @@ -60,5 +60,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/common/Makefile b/drivers/usb/common/Makefile > index 6bbb3ec..730d928 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.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..0379034 > --- /dev/null > +++ b/drivers/usb/common/usb-otg.c > @@ -0,0 +1,768 @@ > +/** > + * drivers/usb/common/usb-otg.c - USB OTG core > + * > + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com > + * Author: Roger Quadros > + * > + * 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 > +#include > +#include > +#include > +#include > +#include /* enum usb_otg_state */ > +#include > +#include > + > +#include "usb-otg.h" > + > +/* to link timer with callback data */ > +struct otg_timer { > + struct hrtimer timer; > + ktime_t timeout; > + /* callback data */ > + int *timeout_bit; > + struct otg_data *otgd; > +}; > + > +struct otg_hcd { > + struct usb_hcd *hcd; > + unsigned int irqnum; > + unsigned long irqflags; > + struct otg_hcd_ops *ops; > +}; > + > +struct otg_data { > + struct device *dev; /* HCD & GCD's parent device */ > + > + struct otg_fsm fsm; > + /* HCD, GCD and usb_otg_state are present in otg_fsm->otg > + * HCD is bus_to_hcd(fsm->otg->host) > + * GCD is fsm->otg->gadget > + */ > + struct otg_fsm_ops fsm_ops; /* private copy for override */ > + struct usb_otg otg; /* allocator for fsm->otg */ > + > + struct otg_hcd primary_hcd; > + struct otg_hcd shared_hcd; > + > + struct otg_gadget_ops *gadget_ops; /* interface to gadget f/w */ > + > + /* saved hooks to OTG device */ > + int (*start_host)(struct otg_fsm *fsm, int on); > + int (*start_gadget)(struct otg_fsm *fsm, int on); > + > + struct list_head list; > + > + struct work_struct work; /* OTG FSM work */ > + struct workqueue_struct *wq; > + > + struct otg_timer timers[NUM_OTG_FSM_TIMERS]; > + > + bool fsm_running; > + /* use otg->fsm.lock for serializing access */ > +}; > + > +/* OTG device list */ > +LIST_HEAD(otg_list); > +static DEFINE_MUTEX(otg_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 device is in our OTG list and return > + * otg_data, else NULL. > + * > + * otg_list_mutex must be held. > + */ > +static struct otg_data *usb_otg_device_get_otgd(struct device *parent_dev) > +{ > + struct otg_data *otgd; > + > + list_for_each_entry(otgd, &otg_list, list) { > + if (otgd->dev == parent_dev) > + return otgd; > + } > + > + return NULL; > +} > + > +/** > + * timer callback to set timeout bit and kick FSM > + */ > +static enum hrtimer_restart set_tmout(struct hrtimer *data) > +{ > + struct otg_timer *otgtimer; > + > + otgtimer = container_of(data, struct otg_timer, timer); > + if (otgtimer->timeout_bit) > + *otgtimer->timeout_bit = 1; > + > + usb_otg_sync_inputs(&otgtimer->otgd->fsm); > + > + return HRTIMER_NORESTART; > +} > + > +/** > + * Initialize one OTG timer with callback, timeout and timeout bit > + */ > +static void otg_timer_init(enum otg_fsm_timer id, struct otg_data *otgd, > + enum hrtimer_restart (*callback)(struct hrtimer *), > + unsigned long expires_ms, > + int *timeout_bit) > +{ > + struct otg_timer *otgtimer = &otgd->timers[id]; > + struct hrtimer *timer = &otgtimer->timer; > + > + otgtimer->timeout = ms_to_ktime(expires_ms); > + hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); > + timer->function = callback; > + > + otgtimer->timeout_bit = timeout_bit; > + otgtimer->otgd = otgd; > +} > + > +/** > + * Initialize standard OTG timers > + */ > +static void usb_otg_init_timers(struct otg_data *otgd) > +{ > + struct otg_fsm *fsm = &otgd->fsm; > + > + otg_timer_init(A_WAIT_VRISE, otgd, set_tmout, TA_WAIT_VRISE, > + &fsm->a_wait_vrise_tmout); > + otg_timer_init(A_WAIT_VFALL, otgd, set_tmout, TA_WAIT_VFALL, > + &fsm->a_wait_vfall_tmout); > + otg_timer_init(A_WAIT_BCON, otgd, set_tmout, TA_WAIT_BCON, > + &fsm->a_wait_bcon_tmout); > + otg_timer_init(A_AIDL_BDIS, otgd, set_tmout, TA_AIDL_BDIS, > + &fsm->a_aidl_bdis_tmout); > + otg_timer_init(A_BIDL_ADIS, otgd, set_tmout, TA_BIDL_ADIS, > + &fsm->a_bidl_adis_tmout); > + otg_timer_init(B_ASE0_BRST, otgd, set_tmout, TB_ASE0_BRST, > + &fsm->b_ase0_brst_tmout); > + > + otg_timer_init(B_SE0_SRP, otgd, set_tmout, TB_SE0_SRP, &fsm->b_se0_srp); > + otg_timer_init(B_SRP_FAIL, otgd, set_tmout, TB_SRP_FAIL, > + &fsm->b_srp_done); > + > + otg_timer_init(A_WAIT_ENUM, otgd, set_tmout, TB_SRP_FAIL, NULL); 2 timers are missing: B_DATA_PLS, B_SSEND_SRP. > +} > + > +/** > + * OTG FSM ops function to add timer > + */ > +static void usb_otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer id) > +{ > + struct otg_data *otgd = container_of(fsm, struct otg_data, fsm); > + struct otg_timer *otgtimer = &otgd->timers[id]; > + struct hrtimer *timer = &otgtimer->timer; > + > + if (!otgd->fsm_running) > + return; > + > + /* if timer is already active, exit */ > + if (hrtimer_active(timer)) { > + dev_err(otgd->dev, "otg: timer %d is already running\n", id); > + return; > + } > + > + hrtimer_start(timer, otgtimer->timeout, HRTIMER_MODE_REL); > +} > + > +/** > + * OTG FSM ops function to delete timer > + */ > +static void usb_otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer id) > +{ > + struct otg_data *otgd = container_of(fsm, struct otg_data, fsm); > + struct hrtimer *timer = &otgd->timers[id].timer; > + > + hrtimer_cancel(timer); > +} > + > +/** > + * OTG FSM ops function to start/stop host > + */ > +static int usb_otg_start_host(struct otg_fsm *fsm, int on) > +{ > + struct otg_data *otgd = container_of(fsm, struct otg_data, fsm); > + struct otg_hcd_ops *hcd_ops; > + > + dev_dbg(otgd->dev, "otg: %s %d\n", __func__, on); > + if (!fsm->otg->host) { > + WARN_ONCE(1, "otg: fsm running without host\n"); > + return 0; > + } > + > + if (on) { > + /* OTG device operations */ > + if (otgd->start_host) > + otgd->start_host(fsm, on); > + > + /* start host */ > + hcd_ops = otgd->primary_hcd.ops; > + hcd_ops->add(otgd->primary_hcd.hcd, otgd->primary_hcd.irqnum, > + otgd->primary_hcd.irqflags); > + if (otgd->shared_hcd.hcd) { > + hcd_ops = otgd->shared_hcd.ops; > + hcd_ops->add(otgd->shared_hcd.hcd, > + otgd->shared_hcd.irqnum, > + otgd->shared_hcd.irqflags); > + } > + } else { > + /* stop host */ > + if (otgd->shared_hcd.hcd) { > + hcd_ops = otgd->shared_hcd.ops; > + hcd_ops->remove(otgd->shared_hcd.hcd); > + } > + hcd_ops = otgd->primary_hcd.ops; > + hcd_ops->remove(otgd->primary_hcd.hcd); > + > + /* OTG device operations */ > + if (otgd->start_host) > + otgd->start_host(fsm, on); > + } > + > + return 0; > +} I do not see much benefit by this override function, usb_add/remove_hcd can be simply included by controller's start_host function, also there maybe some additional operations after usb_add_hcd, but this override function limit usb_add_hcd() is the last step. Maybe your intention is to make usb_add_hcd is the only operation required to start host, so ideally controller driver need not define its start_host routine for this otg ops, I am not sure if this can work for different otg platforms. If the shared code is only usb_add/remove_hcd(), maybe leave this ops defined by controller driver can make core code simple and give flexibility to controller drivers. > + > +/** > + * OTG FSM ops function to start/stop gadget > + */ > +static int usb_otg_start_gadget(struct otg_fsm *fsm, int on) > +{ > + struct otg_data *otgd = container_of(fsm, struct otg_data, fsm); > + struct usb_gadget *gadget = fsm->otg->gadget; > + > + dev_dbg(otgd->dev, "otg: %s %d\n", __func__, on); > + if (!gadget) { > + WARN_ONCE(1, "otg: fsm running without gadget\n"); > + return 0; > + } > + > + if (on) { > + /* OTG device operations */ > + if (otgd->start_gadget) > + otgd->start_gadget(fsm, on); > + > + otgd->gadget_ops->start(fsm->otg->gadget); > + } else { > + otgd->gadget_ops->stop(fsm->otg->gadget); > + > + /* OTG device operations */ > + if (otgd->start_gadget) > + otgd->start_gadget(fsm, on); > + } > + > + return 0; > +} > + > +/** > + * OTG FSM work function > + */ > +static void usb_otg_work(struct work_struct *work) > +{ > + struct otg_data *otgd = container_of(work, struct otg_data, work); > + > + otg_statemachine(&otgd->fsm); Need consider runtime pm, or you want to rely on controller driver take care of it? > +} > + > +/** > + * usb_otg_register() - Register the OTG device to OTG core > + * @parent_device: parent device of Host & Gadget controllers. > + * @otg_fsm_ops: otg state machine ops. > + * > + * Register parent device that contains both HCD and GCD into > + * the USB OTG core. HCD and GCD will be prevented from starting > + * till both are available for use. > + * > + * Return: struct otg_fsm * if success, NULL if error. > + */ > +struct otg_fsm *usb_otg_register(struct device *parent_dev, > + struct otg_fsm_ops *fsm_ops) > +{ > + struct otg_data *otgd; > + int ret = 0; > + > + if (!parent_dev || !fsm_ops) > + return ERR_PTR(-EINVAL); > + > + /* already in list? */ > + mutex_lock(&otg_list_mutex); > + if (usb_otg_device_get_otgd(parent_dev)) { > + dev_err(parent_dev, "otg: %s: device already in otg list\n", > + __func__); > + ret = -EINVAL; > + goto unlock; > + } > + > + /* allocate and add to list */ > + otgd = kzalloc(sizeof(*otgd), GFP_KERNEL); > + if (!otgd) { > + ret = -ENOMEM; > + goto unlock; > + } > + > + otgd->dev = parent_dev; > + INIT_WORK(&otgd->work, usb_otg_work); > + otgd->wq = create_singlethread_workqueue("usb_otg"); > + if (!otgd->wq) { > + dev_err(parent_dev, "otg: %s: can't create workqueue\n", > + __func__); > + ret = -ENODEV; > + goto err_wq; > + } > + > + usb_otg_init_timers(otgd); > + > + /* save original start host/gadget ops */ > + otgd->start_host = fsm_ops->start_host; > + otgd->start_gadget = fsm_ops->start_gadget; > + /* create copy of original ops */ > + otgd->fsm_ops = *fsm_ops; > + /* override ops */ > + otgd->fsm_ops.start_host = usb_otg_start_host; > + otgd->fsm_ops.start_gadget = usb_otg_start_gadget; > + /* FIXME: we ignore caller's timer ops */ > + otgd->fsm_ops.add_timer = usb_otg_add_timer; > + otgd->fsm_ops.del_timer = usb_otg_del_timer; > + /* set otg ops */ > + otgd->fsm.ops = &otgd->fsm_ops; > + otgd->fsm.otg = &otgd->otg; > + > + mutex_init(&otgd->fsm.lock); > + > + list_add_tail(&otgd->list, &otg_list); > + mutex_unlock(&otg_list_mutex); > + return &otgd->fsm; > + > +err_wq: > + kfree(otgd); > +unlock: > + mutex_unlock(&otg_list_mutex); > + return ERR_PTR(ret); > +} > +EXPORT_SYMBOL_GPL(usb_otg_register); > + > +/** > + * usb_otg_unregister() - Unregister the OTG device from USB OTG core > + * @parent_device: parent device of Host & Gadget controllers. > + * > + * Unregister parent OTG deviced from USB OTG core. > + * Prevents unregistering till both Host and Gadget controllers > + * have unregistered from the OTG core. > + * > + * Return: 0 on success, error value otherwise. > + */ > +int usb_otg_unregister(struct device *parent_dev) > +{ > + struct otg_data *otgd; > + > + mutex_lock(&otg_list_mutex); > + otgd = usb_otg_device_get_otgd(parent_dev); > + if (!otgd) { > + dev_err(parent_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 (otgd->fsm.otg->host || otgd->fsm.otg->gadget) { > + dev_err(parent_dev, "otg: %s: host/gadget still registered\n", > + __func__); > + return -EBUSY; > + } > + > + /* OTG FSM is halted when host/gadget unregistered */ > + destroy_workqueue(otgd->wq); > + > + /* remove from otg list */ > + list_del(&otgd->list); > + kfree(otgd); > + 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 otg_fsm *fsm) > +{ > + struct otg_data *otgd = container_of(fsm, struct otg_data, fsm); > + > + if (otgd->fsm_running) > + goto kick_fsm; > + > + if (!fsm->otg->host) { > + dev_info(otgd->dev, "otg: can't start till host registers\n"); > + return; > + } > + This cannot work, fsm->otg->host is set in usb_otg_register_hcd(), which is called by usb_add_hcd(), but usb_add_hcd() should be called only if otg fsm already started to some A-device state, deadlock. > + if (!fsm->otg->gadget) { > + dev_info(otgd->dev, "otg: can't start till gadget registers\n"); > + return; > + } > + > + otgd->fsm_running = true; > +kick_fsm: > + queue_work(otgd->wq, &otgd->work); > +} > + > +/** > + * stop the OTG FSM. Stops Host & Gadget controllers as well. > + * fsm->lock must be held > + */ > +static void usb_otg_stop_fsm(struct otg_fsm *fsm) > +{ > + struct otg_data *otgd = container_of(fsm, struct otg_data, fsm); > + int i; > + > + if (!otgd->fsm_running) > + return; > + > + /* no more new events queued */ > + otgd->fsm_running = false; > + > + /* Stop state machine / timers */ > + for (i = 0; i < ARRAY_SIZE(otgd->timers); i++) > + hrtimer_cancel(&otgd->timers[i].timer); > + > + flush_workqueue(otgd->wq); > + fsm->otg->state = OTG_STATE_UNDEFINED; > + > + /* stop host/gadget immediately */ > + if (fsm->protocol == PROTO_HOST) > + otg_start_host(fsm, 0); > + else if (fsm->protocol == PROTO_GADGET) > + otg_start_gadget(fsm, 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 otg_fsm *fsm) > +{ > + struct otg_data *otgd = container_of(fsm, struct otg_data, fsm); > + > + /* Don't kick FSM till it has started */ > + if (!otgd->fsm_running) > + return; > + > + /* Kick FSM */ > + queue_work(otgd->wq, &otgd->work); > +} > +EXPORT_SYMBOL_GPL(usb_otg_sync_inputs); > + > +/** > + * usb_otg_kick_fsm - Kick the OTG state machine > + * @hcd_gcd_device: Host/Gadget 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 *hcd_gcd_device) > +{ > + struct otg_data *otgd; > + > + mutex_lock(&otg_list_mutex); > + otgd = usb_otg_device_get_otgd(hcd_gcd_device->parent); > + if (!otgd) { > + dev_err(hcd_gcd_device, "otg: %s: invalid host/gadget device\n", > + __func__); > + mutex_unlock(&otg_list_mutex); > + return -ENODEV; > + } > + > + mutex_unlock(&otg_list_mutex); > + usb_otg_sync_inputs(&otgd->fsm); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(usb_otg_kick_fsm); > + > +/** > + * usb_otg_register_hcd - Register Host controller to OTG core > + * @hcd: Host controller device > + * @irqnum: interrupt number > + * @irqflags: interrupt flags > + * @ops: HCD ops to add/remove 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. > + * > + * 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 otg_data *otgd; > + struct device *otg_dev = hcd->self.controller->parent; > + > + mutex_lock(&otg_list_mutex); > + otgd = usb_otg_device_get_otgd(otg_dev); > + if (!otgd) { > + dev_dbg(otg_dev, "otg: %s: device not registered to otg core\n", > + __func__); > + mutex_unlock(&otg_list_mutex); > + return -EINVAL; > + } > + > + mutex_unlock(&otg_list_mutex); > + /* HCD will be started by OTG fsm when needed */ > + mutex_lock(&otgd->fsm.lock); > + if (otgd->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 == otgd->primary_hcd.hcd) { > + if (otgd->shared_hcd.hcd) { > + dev_err(otg_dev, "otg: shared host already registered\n"); > + goto err; > + } > + > + otgd->shared_hcd.hcd = hcd; > + otgd->shared_hcd.irqnum = irqnum; > + otgd->shared_hcd.irqflags = irqflags; > + otgd->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; > + } > + > + otgd->primary_hcd.hcd = hcd; > + otgd->primary_hcd.irqnum = irqnum; > + otgd->primary_hcd.irqflags = irqflags; > + otgd->primary_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 (otgd->shared_hcd.hcd || !otgd->primary_hcd.hcd->shared_hcd) { > + otgd->fsm.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(&otgd->fsm); usb_otg_register_hcd() is called before usb_otg_add_hcd(), start fsm on this point can make sense since hcd has not been added? > + } else { > + dev_dbg(otg_dev, "otg: can't start till shared host registers\n"); > + } > + > + mutex_unlock(&otgd->fsm.lock); > + > + return 0; > + > +err: > + mutex_unlock(&otgd->fsm.lock); > + return -EINVAL; > +} > +EXPORT_SYMBOL_GPL(usb_otg_register_hcd); > + > +/** > + * usb_otg_unregister_hcd - Unregister 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 otg_data *otgd; > + struct usb_bus *bus = hcd_to_bus(hcd); > + struct device *otg_dev = bus->controller->parent; > + > + mutex_lock(&otg_list_mutex); > + otgd = usb_otg_device_get_otgd(otg_dev); > + if (!otgd) { > + dev_err(otg_dev, "otg: %s: device not registered to otg core\n", > + __func__); > + mutex_unlock(&otg_list_mutex); > + return -EINVAL; > + } > + > + mutex_unlock(&otg_list_mutex); > + > + mutex_lock(&otgd->fsm.lock); > + if (hcd == otgd->primary_hcd.hcd) { > + otgd->primary_hcd.hcd = NULL; > + dev_info(otg_dev, "otg: primary host %s unregistered\n", > + dev_name(bus->controller)); > + } else if (hcd == otgd->shared_hcd.hcd) { > + otgd->shared_hcd.hcd = NULL; > + dev_info(otg_dev, "otg: shared host %s unregistered\n", > + dev_name(bus->controller)); > + } else { > + dev_err(otg_dev, "otg: host %s wasn't registered with otg\n", > + dev_name(bus->controller)); > + mutex_unlock(&otgd->fsm.lock); > + return -EINVAL; > + } > + > + /* stop FSM & Host */ > + usb_otg_stop_fsm(&otgd->fsm); > + otgd->fsm.otg->host = NULL; > + > + mutex_unlock(&otgd->fsm.lock); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(usb_otg_unregister_hcd); > + > +/** > + * usb_otg_register_gadget - Register 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 otg_data *otgd; > + struct device *otg_dev = gadget->dev.parent; > + > + mutex_lock(&otg_list_mutex); > + otgd = usb_otg_device_get_otgd(otg_dev); > + if (!otgd) { > + dev_err(otg_dev, "otg: %s: device not registered to otg core\n", > + __func__); > + mutex_unlock(&otg_list_mutex); > + return -EINVAL; > + } > + > + mutex_unlock(&otg_list_mutex); > + > + mutex_lock(&otgd->fsm.lock); > + if (otgd->fsm.otg->gadget) { > + dev_err(otg_dev, "otg: gadget already registered with otg\n"); > + mutex_unlock(&otgd->fsm.lock); > + return -EINVAL; > + } > + > + otgd->fsm.otg->gadget = gadget; > + otgd->gadget_ops = ops; > + dev_info(otg_dev, "otg: gadget %s registered\n", > + dev_name(&gadget->dev)); > + > + /* start FSM */ > + usb_otg_start_fsm(&otgd->fsm); > + mutex_unlock(&otgd->fsm.lock); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(usb_otg_register_gadget); > + > +/** > + * usb_otg_unregister_gadget - Unregister 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 not running > + * on successful return. > + * > + * Returns: 0 on success, error value otherwise. > + */ > +int usb_otg_unregister_gadget(struct usb_gadget *gadget) > +{ > + struct otg_data *otgd; > + struct device *otg_dev = gadget->dev.parent; > + > + mutex_lock(&otg_list_mutex); > + otgd = usb_otg_device_get_otgd(otg_dev); > + if (!otgd) { > + dev_err(otg_dev, "otg: %s: device not registered to otg core\n", > + __func__); > + mutex_unlock(&otg_list_mutex); > + return -EINVAL; > + } > + > + mutex_unlock(&otg_list_mutex); > + > + mutex_lock(&otgd->fsm.lock); > + if (otgd->fsm.otg->gadget != gadget) { > + dev_err(otg_dev, "otg: gadget %s wasn't registered with otg\n", > + dev_name(&gadget->dev)); > + mutex_unlock(&otgd->fsm.lock); > + return -EINVAL; > + } > + > + /* Stop FSM & gadget */ > + usb_otg_stop_fsm(&otgd->fsm); > + otgd->fsm.otg->gadget = NULL; > + mutex_unlock(&otgd->fsm.lock); > + > + dev_info(otg_dev, "otg: gadget %s unregistered\n", > + dev_name(&gadget->dev)); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(usb_otg_unregister_gadget); > + > +/** > + * usb_otg_fsm_to_dev - Get OTG controller device from struct otg_fsm > + * @fsm: otg_fsm data structure > + * > + * This is used by the OTG controller driver to get it's device node > + * from any of the otg_fsm->ops. > + */ > +struct device *usb_otg_fsm_to_dev(struct otg_fsm *fsm) > +{ > + struct otg_data *otgd = container_of(fsm, struct otg_data, fsm); > + > + return otgd->dev; > +} > +EXPORT_SYMBOL_GPL(usb_otg_fsm_to_dev); > diff --git a/drivers/usb/common/usb-otg.h b/drivers/usb/common/usb-otg.h > new file mode 100644 > index 0000000..05331f0 > --- /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) 2015 Texas Instruments Incorporated - http://www.ti.com > + * Author: Roger Quadros > + * > + * 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) > + All otg timer timeout value should be in some *range* defined by otg spec, not some specific value, I don't think one specific value can meet all otg platforms, so we need find a way to make those value can be configured by controller drivers. > +#endif /* __DRIVERS_USB_COMMON_USB_OTG_H */ > diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig > index a99c89e..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 > @@ -75,15 +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 > - select 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/include/linux/usb/otg.h b/include/linux/usb/otg.h > index 52661c5..ce6f8d8 100644 > --- a/include/linux/usb/otg.h > +++ b/include/linux/usb/otg.h > @@ -10,6 +10,11 @@ > #define __LINUX_USB_OTG_H > > #include > +#include > +#include > +#include > +#include > +#include > #include > > struct usb_otg { > @@ -23,6 +28,7 @@ struct usb_otg { > > enum usb_otg_state state; > > +/*------------- deprecated interface -----------------------------*/ > /* bind/unbind the host controller */ > int (*set_host)(struct usb_otg *otg, struct usb_bus *host); > > @@ -38,11 +44,85 @@ struct usb_otg { > > /* start or continue HNP role switch */ > int (*start_hnp)(struct usb_otg *otg); > - > +/*---------------------------------------------------------------*/ > }; > > extern const char *usb_otg_state_string(enum usb_otg_state state); > > +enum usb_dr_mode { > + USB_DR_MODE_UNKNOWN, > + USB_DR_MODE_HOST, > + USB_DR_MODE_PERIPHERAL, > + USB_DR_MODE_OTG, > +}; > + > +#if IS_ENABLED(CONFIG_USB_OTG) > +struct otg_fsm *usb_otg_register(struct device *parent_dev, > + struct otg_fsm_ops *fsm_ops); > +int usb_otg_unregister(struct device *parent_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 otg_fsm *fsm); > +int usb_otg_kick_fsm(struct device *hcd_gcd_device); > +struct device *usb_otg_fsm_to_dev(struct otg_fsm *fsm); > + > +#else /* CONFIG_USB_OTG */ > + > +static inline struct otg_fsm *usb_otg_register(struct device *parent_dev, > + struct otg_fsm_ops *fsm_ops) > +{ > + return ERR_PTR(-ENOSYS); > +} > + > +static inline int usb_otg_unregister(struct device *parent_dev) > +{ > + return -ENOSYS; > +} > + > +static inline int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned int irqnum, > + unsigned long irqflags, > + struct otg_hcd_ops *ops) > +{ > + return -ENOSYS; > +} > + > +static inline int usb_otg_unregister_hcd(struct usb_hcd *hcd) > +{ > + return -ENOSYS; > +} > + > +static inline int usb_otg_register_gadget(struct usb_gadget *gadget, > + struct otg_gadget_ops *ops) > +{ > + return -ENOSYS; > +} > + > +static inline int usb_otg_unregister_gadget(struct usb_gadget *gadget) > +{ > + return -ENOSYS; > +} > + > +static inline void usb_otg_sync_inputs(struct otg_fsm *fsm) > +{ > +} > + > +static inline int usb_otg_kick_fsm(struct device *hcd_gcd_device) > +{ > + return -ENOSYS; > +} > + > +static inline struct device *usb_otg_fsm_to_dev(struct otg_fsm *fsm) > +{ > + return NULL; > +} > + > +#endif /* CONFIG_USB_OTG */ > + > +/*------------- deprecated interface -----------------------------*/ > /* Context: can sleep */ > static inline int > otg_start_hnp(struct usb_otg *otg) > @@ -94,14 +174,9 @@ 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); > > -enum usb_dr_mode { > - USB_DR_MODE_UNKNOWN, > - USB_DR_MODE_HOST, > - USB_DR_MODE_PERIPHERAL, > - USB_DR_MODE_OTG, > -}; > - > #endif /* __LINUX_USB_OTG_H */ > -- > 2.1.4 > I assume I will have more comments after try more. Li Jun -- 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/