Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751993AbbDTQf3 (ORCPT ); Mon, 20 Apr 2015 12:35:29 -0400 Received: from mail-bn1on0134.outbound.protection.outlook.com ([157.56.110.134]:27197 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750703AbbDTQf1 convert rfc822-to-8bit (ORCPT ); Mon, 20 Apr 2015 12:35:27 -0400 From: Ramneek Mehresh To: Alan Stern CC: "linux-kernel@vger.kernel.org" , "linux-usb@vger.kernel.org" , "balbi@ti.com" , "gregkh@linuxfoundation.org" Subject: RE: [PATCH 2/9][v2]usb:fsl:otg: Add support to add/remove usb host driver Thread-Topic: [PATCH 2/9][v2]usb:fsl:otg: Add support to add/remove usb host driver Thread-Index: AQHQcSi/2zTkpfehVEuvEK816ihA7p1Bs26AgBR4/RA= Date: Mon, 20 Apr 2015 16:35:24 +0000 Message-ID: References: <1428407919-24655-2-git-send-email-ramneek.mehresh@freescale.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: rowland.harvard.edu; dkim=none (message not signed) header.d=none; x-originating-ip: [192.88.166.1] x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB161; x-microsoft-antispam-prvs: x-forefront-antispam-report: BMV:1;SFV:NSPM;SFS:(10019020)(6009001)(377454003)(51704005)(13464003)(2900100001)(102836002)(106116001)(66066001)(110136001)(2950100001)(54356999)(76176999)(50986999)(87936001)(2656002)(2171001)(19580395003)(19580405001)(74316001)(76576001)(86362001)(62966003)(77156002)(99286002)(33656002)(46102003)(40100003)(122556002)(92566002);DIR:OUT;SFP:1102;SCL:1;SRVR:BL2PR03MB161;H:BL2PR03MB161.namprd03.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(5005006)(5002010);SRVR:BL2PR03MB161;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB161; x-forefront-prvs: 05529C6FDB Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Apr 2015 16:35:25.0847 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR03MB161 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4059 Lines: 114 > -----Original Message----- > From: Alan Stern [mailto:stern@rowland.harvard.edu] > Sent: Tuesday, April 07, 2015 9:23 PM > To: Mehresh Ramneek-B31383 > Cc: linux-kernel@vger.kernel.org; linux-usb@vger.kernel.org; balbi@ti.com; > gregkh@linuxfoundation.org > Subject: Re: [PATCH 2/9][v2]usb:fsl:otg: Add support to add/remove usb > host driver > > On Tue, 7 Apr 2015, Ramneek Mehresh wrote: > > > Add workqueue to add/remove host driver (outside interrupt context) > > upon each id change > > This patch needs to be fixed. See below. > Thanks Alan. I'll correct the patch. > > Signed-off-by: Ramneek Mehresh > > --- > > drivers/usb/host/ehci-fsl.c | 107 > ++++++++++++++++++++++++++++++++++++-------- > > drivers/usb/host/ehci.h | 1 - > > 2 files changed, 88 insertions(+), 20 deletions(-) > > > > diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c > > index ab4eee3..9c91fbe 100644 > > --- a/drivers/usb/host/ehci-fsl.c > > +++ b/drivers/usb/host/ehci-fsl.c > > @@ -33,6 +33,58 @@ > > > > #include "ehci-fsl.h" > > > > +struct ehci_fsl { > > + struct ehci_hcd ehci; > > + > > +#ifdef CONFIG_PM > > + /* Saved USB PHY settings, need to restore after deep sleep. */ > > + u32 usb_ctrl; > > +#if defined(CONFIG_FSL_USB2_OTG) || > defined(CONFIG_FSL_USB2_OTG_MODULE) > > + struct work_struct change_hcd_work; > > +#endif > > +#endif > > + > > + /* store current hcd state for otg; > > + * have_hcd is true when host drv al already part of otg framework, > > + * otherwise false; > > + * hcd_add is true when otg framework wants to add host > > + * drv as part of otg;flase when it wants to remove it > > + */ > > + unsigned have_hcd:1; > > + unsigned hcd_add:1; > > +}; > > This is the wrong way to connect platform-private data with the ehci_hcd > structure. The right way is to use an ehci_driver_overrides structure, like in > ehci-omap.c and quite a few other EHCI platform drivers. > Will correct > > +#if defined(CONFIG_FSL_USB2_OTG) || > > +defined(CONFIG_FSL_USB2_OTG_MODULE) > > +static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd) { > > + struct ehci_hcd *ehci = hcd_to_ehci(hcd); > > + > > + return container_of(ehci, struct ehci_fsl, ehci); } > > This is bound to fail no matter what, because the ehci_hcd structure is > already embedded in the usb_hcd structure. It can't be embedded in an > ehci_fsl structure too. > > (Of course, this won't matter when you switch to the approved way of > connecting private data.) > Will correct > > +static void do_change_hcd(struct work_struct *work) { > > + struct ehci_fsl *ehci_fsl = container_of(work, struct ehci_fsl, > > + change_hcd_work); > > + struct ehci_hcd *ehci = &ehci_fsl->ehci; > > + struct usb_hcd *hcd = ehci_to_hcd(ehci); > > + > > + void __iomem *non_ehci = hcd->regs; > > + int retval; > > + > > + if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) { > > + writel(USBMODE_CM_HOST, non_ehci + > FSL_SOC_USB_USBMODE); > > + /* host, gadget and otg share same int line */ > > + retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); > > + if (retval == 0) > > + ehci_fsl->have_hcd = 1; > > + } else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) { > > + usb_remove_hcd(hcd); > > + ehci_fsl->have_hcd = 0; > > + } > > +} > > Does this really work right? What about things like > device_wakeup_enable()? Don't you need to disable the controller when > leaving host mode and enable it when entering host mode? > Yes, this does work, it's tested. Yes, controller needs to be disabled when switching the mode from Host to gadget and vice-versa. Only one driver can have control of the hardware at a time. that's why call to usb_remove_hcd() is made. Gadget driver configures the controller in gadget mode, and takes control of the hardware > Alan Stern -- 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/