Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754033AbbHQBvQ (ORCPT ); Sun, 16 Aug 2015 21:51:16 -0400 Received: from mail-by2on0130.outbound.protection.outlook.com ([207.46.100.130]:34069 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752809AbbHQBvN (ORCPT ); Sun, 16 Aug 2015 21:51:13 -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; Date: Mon, 17 Aug 2015 08:40:10 +0800 From: Peter Chen To: Baolin Wang CC: , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v2 1/3] gadget: Support for the usb charger framework Message-ID: <20150817004009.GB1864@shlinux2> References: <33e56f632418b8e42162d5b64decb6ffc8de3e01.1439519412.git.baolin.wang@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <33e56f632418b8e42162d5b64decb6ffc8de3e01.1439519412.git.baolin.wang@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD031;1:qTpU0C7Ge9o2Uqx1sijwMJQslaP15/d9nkrbDkmubAjcK2WcnMbwz/1zA5WGtLH0tN+Vngkc9Siwd5mLH0/oFHm8uHZE+AA0CK0bw6j4FFX4w1WxR3BtQFQgIjHscxu+rLfqPuByHaeFyP9gA+yGp1BO6sVOIfzFtlrFRhPgrHWbZyDqcKMDFbSe75HjK2dz6jbtOagmIftGo/ckk2KkyOqDXnx6YVSP2d2T97PcHrnBFT6Kczw5hRNliSPpjJDlTvnNow/H/5wf4s9GNGBkOp2anlT2wNg1tKAKiFHUj44NOKXkFpjIrX4WvZs3PTDXRoHgjN/qB6zRq8sJFLY8Eip0K3DeXa2CbRvq0FL8oNO+3OAg6lqhAXitqQrhmjvVZlpFec0zvRCjEQIB1ZhV1A== X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(3050300001)(339900001)(24454002)(189002)(199003)(92566002)(2950100001)(62966003)(50466002)(104016003)(77156002)(68736005)(77096005)(33656002)(46102003)(83506001)(85426001)(23726002)(69596002)(46406003)(47776003)(33716001)(54356999)(87936001)(97756001)(64706001)(106466001)(19580395003)(19580405001)(86362001)(6806004)(110136002)(5001860100001)(5890100001)(81156007)(97736004)(4001540100001)(76176999)(5001830100001)(4001350100001)(50986999)(5001960100002)(105606002)(189998001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL2PR03MB483;H:az84smr01.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB483;2:0vQAHXaQ7CDFPVTaj8VLvJqi6u/ConM7MvBoHySpMLwBWp6hy35o7gUp5qGyzGOowhDo02V9HMKyCgZkPbb6uy3Y5tRt96b9GN+RNkRXiUZQ2MGBo7ekYMKnOYDc6fFI4x3T2NvbCj1pFcxh8bxad4niDzRklhq/QQDXmqNt52U=;3:T+vnpqDhSTnKxpkMwePAteS9ytv3uP2SjeZG4rlTobf1V/cP3i5we6YU5qTwpQymdFpLiYT89yDmOtJxdFe4uaKWNTG3XZS3r3xjqJHPVSGT8fAV45nvoM5wdw7aebBvdNcM/4CuDiYa+NHGbi/EjWQE5kblL1J/GeLBujX7E9zyDmFQ8IH5iKs2HIyC+/aVYUeZI8xLapUNWF+PLHjmk2TC36I3r0XjQnLSEiYnslY=;25:oT7Oq2jyooj1+k+i5KJaln1P6DU+h1Qp3pTJRbTvy3q4GnkzZkIBGalfq1nzVWZCvJE2/IKZ4zZyRcIPb0aE5+0Lgtf6wflC/bB9Y9J/9e0r7RVw/CtMOJPfiBfIbIfDwjKS6/RCg/Vw2Cv1Yex5J6EvYiqJQak25N/0pHWOgcrTYQUJapn7+id9fpsK0C+/mdEvYJ0UB7jVwWsBMZ/0la7WacdUvUAxG2tQXWXK6QUSmboDMg7QGygNHrxzgLwc X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB483; X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB483;20:WdYaxRJgNEGIZOWkLOc3r6m9Den5nV6HnT2YZbJPww4xXG6lG5Smm7ozuqR5CWJTgJfJWQH1IiBzCYk0TxTFyvxST0H9yM6mvr60cEfOU11gvtOlBhwkycec4TS9gF6wVbJhev6Ij7BZ8ftjKGOJrfJLosqzadlCV2tbg9QvvnkaCTuDfO+RY6vqABK+GEBzbBqi5dF0K8j1R9+sCM6p3iOlSkJySrtk68Tu52yxXsWPHVjO0cQApHju44BJ5jJsAeThpYfxMq7AOQLDJZkde0KB3Beq/dMXv5lfN/QjW0BHCtRmSNKMYRK8Kfbi2oOVTL/L54EgKTHy53BlwKD1brVaxXOyuAtxjWWS9EseXIg=;4:6OSEMW7+2/ByOSmp9lPBGzu+eOer8UhMZ4Dx051JXamIPECR3wu9RrQS2Tk6pozIdjfeJ221aPA1N+pEc5D8l+cDzbFFR2QgsKeg7FdeEAIQXtnhU7PxdvrojYF69WMnXTP+32l4eRGP7jOqgMuR9jLMFXYUCSgEDQMTUIy7h6KuBzTPV8jPOkcjuvG97FLlbgH82rx7tcWW5aae8j5A9rqh6NtVKfzoWH7VSs+Z5/4PWh9aSHKjEH+1HASEzH3Cd21RWyc/YyrZLvW2ZA7Rfsqso6bo6Rp6D2PRPeQe0dMK4dNJP6RSMZCuE4pxxzV1 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:BL2PR03MB483;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB483; X-Forefront-PRVS: 0671F32598 X-Microsoft-Exchange-Diagnostics: =?us-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W/1zQCEVIzqkhUbwGODXy1ye?= =?us-ascii?Q?rAr5rmJMlKXq0aPVS4zQ/+viDqnPYQB8D06dfNBhkShK4nEPnJmtGZWSmdlU?= =?us-ascii?Q?hp2dPPHQzce7ygNNrSwKnkUCTbRzBcJ1EMdd1lHgZbBrozbL5KZMwexQI8j6?= =?us-ascii?Q?l/1eu8lGxlCjA0iYJrmai3jpEVD6na5hnSv1DbcKN+KQe3KTRBvsbOJT/E5H?= =?us-ascii?Q?hv/N1H9WoQ4DM19S2HVamuAJ1q1po/TXn4RMzAGPQ3su7CDyRbIzMUVMxpz/?= =?us-ascii?Q?2234Xk4bvjbn6jCfW13L91mxOWzA1q7hkYlyVPGQpYX2ZtjUuunbDEG6m1i4?= =?us-ascii?Q?VDyLikKumKGDRhgo5jvoZOoqxSUFQhvqD++qvK7pXQ0O9T0tYBpFBKaw=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB483;5:VxiCCCbn1vVvqSH2nkt1SmG2jC68rNC0IinT9Ht44+9BvOT+UyJSXrMPIhoHg0BebK2OVJAGx5IqaYrqDfmiujYUW8KUT7q5QkosTSiyZ9Feg5FNplI11fuDngDGQ4am2Omrn5eGkwCfXYJjkIJsKg==;24:4n7xoshohmYWq2fM3/64xpQvnkzSV7STvFKOsuM/MViW+31ajp3rKa60IhH7iwqrnLSxo2eRLazEs81w0IrP7b5IIoLgX+bOntUKkfKzYlo=;20:EFAepRDQyFUAY6W+UYfDYTVdMU4pFTQfxRi9X/8tJGfog9gA6Chamz06/j9sSoRnk+NvbhXqUqHYrhaX0qDEVw== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2015 01:51:09.9561 (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: BL2PR03MB483 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5191 Lines: 164 On Fri, Aug 14, 2015 at 05:47:44PM +0800, Baolin Wang wrote: > The usb charger framework is based on usb gadget, and each usb gadget > can be one usb charger to set the current limitation. > > This patch adds a notifier mechanism for usb charger to report to usb > charger when the usb gadget state is changed. > > Also we introduce a callback 'get_charger_type' which will implemented > by user for usb gadget operations to get the usb charger type. > > Signed-off-by: Baolin Wang > --- > drivers/usb/gadget/udc/udc-core.c | 38 +++++++++++++++++++++++++++++++++++++ > include/linux/usb/gadget.h | 20 +++++++++++++++++++ > 2 files changed, 58 insertions(+) > > diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c > index f660afb..47b231c 100644 > --- a/drivers/usb/gadget/udc/udc-core.c > +++ b/drivers/usb/gadget/udc/udc-core.c > @@ -28,6 +28,7 @@ > #include > #include > #include > +#include > > /** > * struct usb_udc - describes one usb device controller > @@ -129,6 +130,32 @@ void usb_gadget_giveback_request(struct usb_ep *ep, > } > EXPORT_SYMBOL_GPL(usb_gadget_giveback_request); > > +int usb_gadget_register_notify(struct usb_gadget *gadget, > + struct notifier_block *nb) > +{ > + int ret; > + > + mutex_lock(&gadget->lock); > + ret = raw_notifier_chain_register(&gadget->nh, nb); > + mutex_unlock(&gadget->lock); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(usb_gadget_register_notify); > + > +int usb_gadget_unregister_notify(struct usb_gadget *gadget, > + struct notifier_block *nb) > +{ > + int ret; > + > + mutex_lock(&gadget->lock); > + ret = raw_notifier_chain_unregister(&gadget->nh, nb); > + mutex_unlock(&gadget->lock); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(usb_gadget_unregister_notify); > + > /* ------------------------------------------------------------------------- */ > > /** > @@ -226,6 +253,10 @@ static void usb_gadget_state_work(struct work_struct *work) > struct usb_gadget *gadget = work_to_gadget(work); > struct usb_udc *udc = gadget->udc; > > + mutex_lock(&gadget->lock); > + raw_notifier_call_chain(&gadget->nh, gadget->state, gadget); > + mutex_unlock(&gadget->lock); > + > if (udc) > sysfs_notify(&udc->dev.kobj, NULL, "state"); > } > @@ -364,6 +395,8 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, > > dev_set_name(&gadget->dev, "gadget"); > INIT_WORK(&gadget->work, usb_gadget_state_work); > + RAW_INIT_NOTIFIER_HEAD(&gadget->nh); > + mutex_init(&gadget->lock); > gadget->dev.parent = parent; > > #ifdef CONFIG_HAS_DMA > @@ -405,6 +438,10 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, > > mutex_unlock(&udc_lock); > > + ret = usb_charger_init(gadget); > + if (ret) > + goto err4; > + If the charger's initialization fails, you may need to call device_del(&udc->dev). Peter > return 0; > > err4: > @@ -481,6 +518,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget) > kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); > flush_work(&gadget->work); > device_unregister(&udc->dev); > + usb_charger_exit(gadget); > device_unregister(&gadget->dev); > } > EXPORT_SYMBOL_GPL(usb_del_gadget_udc); > diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h > index c14a69b..78cc862 100644 > --- a/include/linux/usb/gadget.h > +++ b/include/linux/usb/gadget.h > @@ -537,6 +537,7 @@ struct usb_gadget_ops { > struct usb_ep *(*match_ep)(struct usb_gadget *, > struct usb_endpoint_descriptor *, > struct usb_ss_ep_comp_descriptor *); > + enum usb_charger_type (*get_charger_type)(struct usb_gadget *); > }; > > /** > @@ -609,6 +610,9 @@ struct usb_gadget { > unsigned out_epnum; > unsigned in_epnum; > struct usb_otg_caps *otg_caps; > + struct raw_notifier_head nh; > + struct usb_charger *uchger; > + struct mutex lock; > > unsigned sg_supported:1; > unsigned is_otg:1; > @@ -1183,6 +1187,22 @@ extern void usb_gadget_unmap_request(struct usb_gadget *gadget, > > /*-------------------------------------------------------------------------*/ > > +/** > + * Register a notifiee to get notified by any attach status changes from > + * the usb gadget > + */ > +int usb_gadget_register_notify(struct usb_gadget *gadget, > + struct notifier_block *nb); > + > +/*-------------------------------------------------------------------------*/ > + > + > +/* Unregister a notifiee from the usb gadget */ > +int usb_gadget_unregister_notify(struct usb_gadget *gadget, > + struct notifier_block *nb); > + > +/*-------------------------------------------------------------------------*/ > + > /* utility to set gadget state properly */ > > extern void usb_gadget_set_state(struct usb_gadget *gadget, > -- > 1.7.9.5 > -- 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/