Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753340AbbKWHsD (ORCPT ); Mon, 23 Nov 2015 02:48:03 -0500 Received: from mail-bn1bon0148.outbound.protection.outlook.com ([157.56.111.148]:44672 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751190AbbKWHsA (ORCPT ); Mon, 23 Nov 2015 02:48:00 -0500 Authentication-Results: spf=permerror (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; samsung.com; dkim=none (message not signed) header.d=none;samsung.com; dmarc=none action=none header.from=freescale.com; Date: Mon, 23 Nov 2015 15:44:57 +0800 From: Peter Chen To: Marek Szyprowski CC: , , "Ruslan Bilovol" , Bartlomiej Zolnierkiewicz Subject: Re: [PATCH v6 4/4] usb: gadget: udc-core: independent registration of gadgets and gadget drivers Message-ID: <20151123074456.GD16321@shlinux2> References: <1448009652-14716-1-git-send-email-m.szyprowski@samsung.com> <1448009652-14716-5-git-send-email-m.szyprowski@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1448009652-14716-5-git-send-email-m.szyprowski@samsung.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD032;1:LdFzdNGKiUuHPIh6TrexgRGOaoH9sEL6IyBG4XcseQdO9BzeM91bKs3vRYOfTPf3Z0HcGRXKeCbgk/IDVNrBlaRfy3og8gabL5h0dxBLOHJc4F/mbwJNJfKY/5eewsODVcFzLQeHYbS46eRtk0Wa+Y36fYFnQBzl++L5xodrhAUtpyvyxRdINedZrIJoALkIABxn/JKQLVKD3ur0yY6EpaxaAqk0ZtPhWNPRN6aTlbDoU/icwT4G1NAFuXM6x1jtxp53xpUJhv5FOiBepuzLK2EByf2R6VXTS+csZ5X3oUQTVVnTCtXrFnHzQRS4eWQFBKKRcw29VJUY8rjl48xOxpnxVJJT0m1Eb5CfTY3L+OQV4RUdp1ap3JEFxRJ49YOs X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(1060300003)(2980300002)(448002)(24454002)(189002)(199003)(104016004)(77096005)(5008740100001)(19580405001)(76176999)(106466001)(50986999)(83506001)(46406003)(33656002)(92566002)(54356999)(85326001)(606003)(87936001)(11100500001)(5001960100002)(33716001)(2950100001)(6806005)(50466002)(97736004)(86362001)(4290100001)(97756001)(23726003)(5007970100001)(5001920100001)(81156007)(110436001)(47776003)(4001350100001)(19580395003)(110136002);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR0301MB1229;H:tx30smr01.am.freescale.net;FPR:;SPF:PermError;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1229;2:WZgm2it26igwxxGzCl8+d++WpQDtMqEyeTBpG4Gdo6Crme3VDyIVeccPwjM48vjtQBjf4eT/WXrVVU36xIzNGA10RmX7NFQBL9qKAvK7TQrUMzdd/nC6WDdWWIoRwpMX+sNW5OIyvpzz+L7gLBAPkR8jKVyuvXbcfWsqzquQhEs=;3:b4a77RIseCYsAl81HG0jPI1Q3vBL7tERZMKq5jK1ZQUccXMxOIaF4okH0YZJcorRPLleZTLQjzqYOEguiPbAis8D2y1ZwWuluodtI/Q1QMu07uC5XNFj5+wtFdYGPkPsy3TMnQUJcvcCOPds9OBnv3AC9KUtIV0QOVt+P7HL5Mza00K7iYAVfcQxeBsJeec35a/rkBU5ZW59NiXyd6x9O2UhPxUT6ULA0lzdE4HRNWI=;25:diP5mz5pmm/OXydKCk8piGpKtFXdbolrpcinkJK8jslH7pCrwSN02sQfC2/QQf8YHYkbPTIFF49ppSRsIDI5H/3hI6Dvx76mHMgJICmrh3HyRsyo6PfO4JJ9gX4S2nJUf84WdYmn+q0ISObnPAA06p5r5g6VeCPxFhR2wk0mBdHdeIjsByusubSfBEmTLcLB0flZylaIVoxfRLtKMsmit6nhpM7y39XGK7i+jH8vAvYyjSt3ycrLIBJ07dSvkIrlNW2uWQBthKh+FyJqCjbatg== X-Microsoft-Antispam: UriScan:;BCL:1;PCL:0;RULEID:;SRVR:DM2PR0301MB1229; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1229;20:6ocXrjJ7d45Z4X7qyQKKoHA7om86qhEWkptFhxWMuodD+agvncGP4ZmOH6aSEPzhX5s/44/mQBHHd9bv9hJM701Kp0iSa+ntE5JLss9jJSRoxMXklbHqUSuyQbQVAhk2c2cqETAN//nGuSc4HdrBZRdzwnNbTIQpdinuirA9QNrgU64SE2a0eOmajyi4cqvUOfxhdSLjxarzQnbwsLiLI9FVHQvPcted1uXzrhxkeZ71+c9mt/UzNpPKE6S08VSSvwjtTzB95G5AuN9N56KDkEQVnq16se1A+lUxjcPGDpbOB/sAZfD2avZuqERlkA8gBJDoKYU8rayzCnnNnTO723CWSEXyuhLqpqjp3vJYFko=;4:yAROhexwhzUkuRAmXCzP2aB3HHRULCaxA0UhOUPC1bKj6CxBiU20uPAMe/VuNZGsN+XQyDa1y8O9b4xewhkjB9+cwhMzQoC4vgm34gPFfNAQpWSc0k7B02B2ISHUPX9lxv0VynQB6qIP+nvoljGVcpTd/pYlgiWvIQSBzJjay/IBT5HyYENm3205OxeXGiiQ0NbRelII6r0UMRP0TbROfbxsFDX3AnPdEhvMNsJheP4+bXyBJgGN5z251rqo4uGRaOhZFCnUM4oE6YesknnkPW1R+FeQej+9d/3150WXU+Uzumziwfk5UlGUHEuBcBji7tL85/0AU5xoGF/QuEzVevSrxUMgvia/aFe3JJ1WfnyPN0VdOVVdwUKZd1WiZsoEjnortJqA3qmZsmIdwu5JQw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:1;PCL:0;RULEID:(601004)(2401047)(5005006)(520078)(1201001)(8121501046)(3002001)(10201501046);SRVR:DM2PR0301MB1229;BCL:1;PCL:0;RULEID:;SRVR:DM2PR0301MB1229; X-Forefront-PRVS: 07697999E6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR0301MB1229;23:ImJRxqvKSTS4M0YoYTLeNuS2pJ5Cxh1yAznCULU?= =?us-ascii?Q?QyfNzDq+I2ZI9i2Ylpku2SGfmjzHpZ1MJZEHg6APhFQbWnhSRWHGovgDrLek?= =?us-ascii?Q?ZIvD9gCAO6yQGg1YXUVnTrhuwzypxefzhUIbP9fUCwgw/pCLLOXwpDzy/mhP?= =?us-ascii?Q?W/Qg6SSjH0LitHFAVeT8ZMTf6pyZrNrzuAisAGnX3Obt4wky8IQsGkVShdyV?= =?us-ascii?Q?EA/cGtjZACc5E5a5mZ4RQNReT8AtX8XzTQeR3pHMhnG+56haP0odZD4BbdAS?= =?us-ascii?Q?ZgAUltABVZDpJWxCkEe+Sz3kkLfDKiMtx2QlOxzSuuM2RR4nDuFl5e78LYYS?= =?us-ascii?Q?I5xO8FzPt+voC2bYsW/CGctMz0EjRLxmTUGLS3pftr4bNLY58GdKL1ONBJ8u?= =?us-ascii?Q?vZSIzn1Gr81k6RB2GwqDo+WBtNKgS12iboG8F8Lm0IolnXlBg66XMuDKitR5?= =?us-ascii?Q?KaCRQfudmA+xzF1R4x+mVTh6BTrkaijCuWO7oxSgHM2opP9tL43K0VJZ0qL7?= =?us-ascii?Q?HPAbtv7CsYYWMTTJC0NM5KJTQIfvIdVdjLpTi3Uojt0nAB47Wh2bIbQzjGWh?= =?us-ascii?Q?VibqHeExzvR8Blv/SocvwAhZveO5uiiBz/JDUcyei8NG7foRwEIGfX8GYp6/?= =?us-ascii?Q?QjA3e/o7z66mt7MioDjGqil88FAKlSRlxNOvj07h2n/Bc1qJOFx83+QjfeI7?= =?us-ascii?Q?0sbL2yUF/zyYaN+5JJZYbMn01Kf/7N13Gc7PkUB96N+cxPv43PxxTuXo/5J6?= =?us-ascii?Q?NZEYJmaXNScMFoiYISKINEDUh4ieI1D267Pw2ddpHj3p1i2sASvRR8UR6tZ5?= =?us-ascii?Q?2tW9NX1om8Bq3Yxpm3Ly65B8eYffwzz1Pfrh/80CF6uDaVeBWayFWLKH6lhR?= =?us-ascii?Q?/YqciqAo8WYQqVA7cHLiS7CP4PRBq8OJXaCcG07Spa+LoiAFcViVj6NBBZnt?= =?us-ascii?Q?o3e9d+QgWmoCc62KzKBAp4iM+5iYKNH7CvKPgaZ1B9cyBKFSKim7TwwjzV+N?= =?us-ascii?Q?Hgaxcks473mx0OlZOTcimnog27IL/t5xExtwkRwy9wv1oQUHw2h6wV/BF+km?= =?us-ascii?Q?uUF6QN9hTn9//MjXMhazob/efSuBZmDa/51YopWn01vcIr7eY/m2mw1shC8d?= =?us-ascii?Q?Z1ZNZ97DWCVI=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1229;5:Lh7W2nyjz8zUxSuI5tLXSEa0CPdYJunloJGJpu8A0/bgF5WOCAELuGcql1GfdqmwmiJUnciTvSA7u5JLT21Sbt8Z5HKylWDN2lBfhNcuclqnELaurAmlLoETEyQKY/atc58cyDw9ZxSnqKdtfOJaEQ==;24:IvTYA/g/cezLyloMSolKTaIVn7qhWFGOEQz1Q7kOS9wVBOpacT0Gd2eOaSq5hgOJzxaVvwzAaGlMaAfZJEU+ehlK9Fc/2RMvDcS/4+3TIzE=;20:ke25266FaYytS1TKusjdtcDDcPefQwdQ6yrI1SnvLnmw+JGWUcMZA4WRH4qn/DaTPh1LBkv4u0E7LhC5y5Pj/A== SpamDiagnosticOutput: 1:5 SpamDiagnosticMetadata: 00000000%2D0000%2D0000%2D0000%2D000000000000 SpamDiagnosticMetadata: 1 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Nov 2015 07:47:56.7732 (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: 4584 Lines: 133 On Fri, Nov 20, 2015 at 09:54:12AM +0100, Marek Szyprowski wrote: > From: Ruslan Bilovol > > Change behavior during registration of gadgets and > gadget drivers in udc-core. Instead of previous > approach when for successful probe of usb gadget driver > at least one usb gadget should be already registered > use another one where gadget drivers and gadgets > can be registered in udc-core independently. > > Independent registration of gadgets and gadget drivers > is useful for built-in into kernel gadget and gadget > driver case - because it's possible that gadget is > really probed only on late_init stage (due to deferred > probe) whereas gadget driver's probe is silently failed > on module_init stage due to no any UDC added. > > Also it is useful for modules case - now there is no > difference what module to insert first: gadget module > or gadget driver one. > > Tested-by: Maxime Ripard > Signed-off-by: Ruslan Bilovol > [simplified code as requested by Alan Stern and Felipe Balbi] > Signed-off-by: Marek Szyprowski > --- > drivers/usb/gadget/udc/udc-core.c | 43 +++++++++++++++++++++++++++++++-------- > include/linux/usb/gadget.h | 2 ++ > 2 files changed, 37 insertions(+), 8 deletions(-) > > diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c > index f76ebc8..461b311 100644 > --- a/drivers/usb/gadget/udc/udc-core.c > +++ b/drivers/usb/gadget/udc/udc-core.c > @@ -51,8 +51,12 @@ struct usb_udc { > > static struct class *udc_class; > static LIST_HEAD(udc_list); > +static LIST_HEAD(gadget_driver_pending_list); > static DEFINE_MUTEX(udc_lock); > > +static int udc_bind_to_driver(struct usb_udc *udc, > + struct usb_gadget_driver *driver); > + > /* ------------------------------------------------------------------------- */ > > #ifdef CONFIG_HAS_DMA > @@ -356,6 +360,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, > void (*release)(struct device *dev)) > { > struct usb_udc *udc; > + struct usb_gadget_driver *driver; > int ret = -ENOMEM; > > udc = kzalloc(sizeof(*udc), GFP_KERNEL); > @@ -403,6 +408,18 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, > usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); > udc->vbus = true; > > + /* pick up one of pending gadget drivers */ > + list_for_each_entry(driver, &gadget_driver_pending_list, pending) { > + if (!driver->udc_name || strcmp(driver->udc_name, > + dev_name(&udc->dev)) == 0) { > + ret = udc_bind_to_driver(udc, driver); > + if (ret) > + goto err4; > + list_del(&driver->pending); > + break; > + } > + } > + > mutex_unlock(&udc_lock); > > return 0; > @@ -475,9 +492,16 @@ void usb_del_gadget_udc(struct usb_gadget *gadget) > list_del(&udc->list); > mutex_unlock(&udc_lock); > > - if (udc->driver) > + if (udc->driver) { > + struct usb_gadget_driver *driver = udc->driver; > + > usb_gadget_remove_driver(udc); > > + mutex_lock(&udc_lock); > + list_add(&driver->pending, &gadget_driver_pending_list); > + mutex_unlock(&udc_lock); > + } > + > kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); > flush_work(&gadget->work); > device_unregister(&udc->dev); > @@ -535,11 +559,7 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver) > if (!ret) > break; > } > - if (ret) > - ret = -ENODEV; > - else if (udc->driver) > - ret = -EBUSY; > - else > + if (!ret && !udc->driver) > goto found; > } else { > list_for_each_entry(udc, &udc_list, list) { > @@ -549,9 +569,12 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver) > } > } > > - pr_debug("couldn't find an available UDC\n"); > + list_add_tail(&driver->pending, &gadget_driver_pending_list); > + pr_info("udc-core: couldn't find an available UDC " > + "- added [%s] to list of pending drivers\n", > + driver->function); There is an warning when trying to apply it: WARNING: quoted string split across lines. I tested this series, it works ok for both module and build-in function, it fixed gadget function broken if it is build-in at imx6qdl sabreauto board. Tested-by: Peter Chen -- 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/