Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932418AbcDHIEb (ORCPT ); Fri, 8 Apr 2016 04:04:31 -0400 Received: from mail-db3on0088.outbound.protection.outlook.com ([157.55.234.88]:44784 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753498AbcDHIEZ convert rfc822-to-8bit (ORCPT ); Fri, 8 Apr 2016 04:04:25 -0400 From: Jun Li To: Baolin Wang , "balbi@kernel.org" , "gregkh@linuxfoundation.org" , "sre@kernel.org" , "dbaryshkov@gmail.com" , "dwmw2@infradead.org" CC: "peter.chen@freescale.com" , "stern@rowland.harvard.edu" , "r.baldyga@samsung.com" , "yoshihiro.shimoda.uh@renesas.com" , "lee.jones@linaro.org" , "broonie@kernel.org" , "ckeepax@opensource.wolfsonmicro.com" , "patches@opensource.wolfsonmicro.com" , "linux-pm@vger.kernel.org" , "linux-usb@vger.kernel.org" , "device-mainlining@lists.linuxfoundation.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v10 1/4] gadget: Introduce the usb charger framework Thread-Topic: [PATCH v10 1/4] gadget: Introduce the usb charger framework Thread-Index: AQHRkMPGtHshVOWiT0CKGo87VBT6+J9/ZtSA Date: Fri, 8 Apr 2016 08:04:20 +0000 Message-ID: References: <6b323d5168c10ccb47882687b1251c31b6cad587.1460029375.git.baolin.wang@linaro.org> In-Reply-To: <6b323d5168c10ccb47882687b1251c31b6cad587.1460029375.git.baolin.wang@linaro.org> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=nxp.com; x-originating-ip: [123.151.195.51] x-ms-office365-filtering-correlation-id: e50f5684-2f94-4d1b-68c8-08d35f8463c5 x-microsoft-exchange-diagnostics: 1;AM4PR04MB2129;5:woIWj7B73EfJX7A1nnk2LAMqR4SnTvuHT23lHMZ6KcD9fCNoBqK0X60hAwrNYCIm+aGwPRIL6AlrQ1WcoGzRPBxt8uSjf6KQTGXuFyguh35lUrImHKDyNwTROKql4zUz65+O+lI6o8nkwr6b3p1rHw==;24:nbYE9Ye3eMitnpCveZr8azs0W3MWmxVjtesIrOP/yDHVKsCZNK1tjoRgINMLH1AERD24mMW2WlgA9TRk4vd1cO00Bpl6DOn2VPrE4eR6zlg= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM4PR04MB2129; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026);SRVR:AM4PR04MB2129;BCL:0;PCL:0;RULEID:;SRVR:AM4PR04MB2129; x-forefront-prvs: 0906E83A25 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(76104003)(13464003)(377454003)(2900100001)(5001770100001)(2950100001)(5004730100002)(19580395003)(189998001)(10400500002)(1096002)(19580405001)(1220700001)(3660700001)(122556002)(586003)(3280700002)(4326007)(86362001)(2906002)(6116002)(2501003)(3846002)(5008740100001)(81166005)(11100500001)(77096005)(66066001)(102836003)(92566002)(76576001)(50986999)(76176999)(74316001)(54356999)(9686002)(2201001)(5003600100002)(87936001)(33656002)(106116001)(5002640100001)(7059030);DIR:OUT;SFP:1101;SCL:1;SRVR:AM4PR04MB2129;H:AM4PR04MB2130.eurprd04.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Apr 2016 08:04:20.2169 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR04MB2129 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4837 Lines: 143 Hi, Baolin > -----Original Message----- > From: linux-usb-owner@vger.kernel.org [mailto:linux-usb- > owner@vger.kernel.org] On Behalf Of Baolin Wang > Sent: Thursday, April 07, 2016 7:49 PM > To: balbi@kernel.org; gregkh@linuxfoundation.org; sre@kernel.org; > dbaryshkov@gmail.com; dwmw2@infradead.org > Cc: peter.chen@freescale.com; stern@rowland.harvard.edu; > r.baldyga@samsung.com; yoshihiro.shimoda.uh@renesas.com; > lee.jones@linaro.org; broonie@kernel.org; > ckeepax@opensource.wolfsonmicro.com; patches@opensource.wolfsonmicro.com; > baolin.wang@linaro.org; linux-pm@vger.kernel.org; linux- > usb@vger.kernel.org; device-mainlining@lists.linuxfoundation.org; linux- > kernel@vger.kernel.org > Subject: [PATCH v10 1/4] gadget: Introduce the usb charger framework > > This patch introduces the usb charger driver based on usb gadget that > makes an enhancement to a power driver. It works well in practice but that > requires a system with suitable hardware. > > The basic conception of the usb charger is that, when one usb charger is > added or removed by reporting from the usb gadget state change or the > extcon device state change, the usb charger will report to power user to > set the current limitation. > > The usb charger will register notifiees on the usb gadget or the extcon > device to get notified the usb charger state. It also supplies the > notification mechanism to userspace When the usb charger state is changed. > > Power user will register a notifiee on the usb charger to get notified by > status changes from the usb charger. It will report to power user to set > the current limitation when detecting the usb charger is added or removed > from extcon device state or usb gadget state. > > This patch doesn't yet integrate with the gadget code, so some functions > which rely on the 'gadget' are not completed, that will be implemented in > the following patches. > > Signed-off-by: Baolin Wang > --- > drivers/usb/gadget/Kconfig | 7 + > drivers/usb/gadget/udc/Makefile | 1 + > drivers/usb/gadget/udc/charger.c | 729 > ++++++++++++++++++++++++++++++++++++++ > include/linux/usb/charger.h | 173 +++++++++ > include/uapi/linux/usb/charger.h | 31 ++ > 5 files changed, 941 insertions(+) > create mode 100644 drivers/usb/gadget/udc/charger.c create mode 100644 > include/linux/usb/charger.h create mode 100644 > include/uapi/linux/usb/charger.h > ... > + > +/* > + * usb_charger_detect_type() - detect the charger type manually. > + * @uchger - usb charger device > + * > + * Note: You should ensure you need to detect the charger type manually > +on your > + * platform. > + * You should call it at the right gadget state to avoid affecting > +gadget > + * enumeration. > + */ > +int usb_charger_detect_type(struct usb_charger *uchger) { > + enum usb_charger_type type; > + > + if (WARN(!uchger->charger_detect, > + "charger detection method should not be NULL")) > + return -EINVAL; > + > + type = uchger->charger_detect(uchger); > + > + mutex_lock(&uchger->lock); > + uchger->type = type; > + mutex_unlock(&uchger->lock); > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(usb_charger_detect_type); I still recommend have a central place to call usb_charger_detect_type() to cover real charger detection instead of leaving this question open to diff users. This can be done after vbus-on is detected and before do gadget connect. I don't think this will make your framework complicated. Hi Felipe, what do you think of this? Li Jun > + > +/* > + * usb_charger_get_type_by_others() - Get the usb charger type by the > +callback > + * which is implemented by users. > + * @uchger - the usb charger device. > + * > + * Note: This function is just used for getting the charger type, not > +for > + * detecting charger type which might affect the DP/DM line when gadget > +is on > + * enumeration state. > + */ > +static enum usb_charger_type > +usb_charger_get_type_by_others(struct usb_charger *uchger) { > + if (uchger->type != UNKNOWN_TYPE) > + return uchger->type; > + > + if (uchger->psy) { > + union power_supply_propval val; > + > + power_supply_get_property(uchger->psy, > + POWER_SUPPLY_PROP_CHARGE_TYPE, > + &val); > + switch (val.intval) { > + case POWER_SUPPLY_TYPE_USB: > + uchger->type = SDP_TYPE; > + break; > + case POWER_SUPPLY_TYPE_USB_DCP: > + uchger->type = DCP_TYPE; > + break; > + case POWER_SUPPLY_TYPE_USB_CDP: > + uchger->type = CDP_TYPE; > + break; > + case POWER_SUPPLY_TYPE_USB_ACA: > + uchger->type = ACA_TYPE; > + break; > + default: > + uchger->type = UNKNOWN_TYPE; > + break; > + } > + } else if (uchger->get_charger_type) { > + uchger->type = uchger->get_charger_type(uchger); > + } else { > + uchger->type = UNKNOWN_TYPE; > + } > + > + return uchger->type; > +} > +