Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752447AbcDKBir (ORCPT ); Sun, 10 Apr 2016 21:38:47 -0400 Received: from mail-am1on0100.outbound.protection.outlook.com ([157.56.112.100]:4672 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752200AbcDKBio (ORCPT ); Sun, 10 Apr 2016 21:38:44 -0400 From: Jun Li To: Baolin Wang CC: "balbi@kernel.org" , "gregkh@linuxfoundation.org" , "sre@kernel.org" , "dbaryshkov@gmail.com" , "dwmw2@infradead.org" , "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/ZtSAgABxaYCAAAFrAIAAEIWAgAAAPzCAAA3xAIAAMU2g Date: Mon, 11 Apr 2016 01:38:39 +0000 Message-ID: References: <6b323d5168c10ccb47882687b1251c31b6cad587.1460029375.git.baolin.wang@linaro.org> In-Reply-To: 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: [192.158.241.86] x-ms-office365-filtering-correlation-id: eb6f7e99-2061-4397-003e-08d361aa0250 x-microsoft-exchange-diagnostics: 1;AM4PR04MB2130;5:fhgeAfklQY3+6MfM7xS1jrWD4nghGUPUUs82p2H+QZFC0SuxXiaxb4ST6Gm7HvxWee1ebRpTA2LUSmV66hpXUfGfFzs5AdNM/Ps7aJRnhBcEq/msQaW54peYuvcj91JEu/HEL80Gbmnx0oJfTguoEw==;24:t0GjTQrhG4aDfRpQDaAt8vQ1tMBw1cEfsQJ/dpco92x03jDz8HUC7Vp9MQwQRTge2i2P6rFvV2+wjnO/ooc1pb5G1bXDnXVEdDhTQIQJ0hA= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM4PR04MB2130; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026);SRVR:AM4PR04MB2130;BCL:0;PCL:0;RULEID:;SRVR:AM4PR04MB2130; x-forefront-prvs: 09090B6B69 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(377454003)(24454002)(13464003)(5004730100002)(3660700001)(2906002)(106116001)(77096005)(11100500001)(3846002)(122556002)(102836003)(6116002)(586003)(5003600100002)(5008740100001)(33656002)(2950100001)(10400500002)(3280700002)(74316001)(81166005)(9686002)(19580395003)(19580405001)(86362001)(5002640100001)(66066001)(87936001)(93886004)(92566002)(189998001)(110136002)(1220700001)(1096002)(76576001)(54356999)(4326007)(76176999)(50986999)(7059030);DIR:OUT;SFP:1101;SCL:1;SRVR:AM4PR04MB2130;H:AM4PR04MB2130.eurprd04.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Apr 2016 01:38:39.9722 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR04MB2130 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id u3B1cwE1030567 Content-Length: 5542 Lines: 141 Hi > -----Original Message----- > From: Baolin Wang [mailto:baolin.wang@linaro.org] > Sent: Friday, April 08, 2016 7:51 PM > To: Jun Li > Cc: balbi@kernel.org; gregkh@linuxfoundation.org; sre@kernel.org; > dbaryshkov@gmail.com; dwmw2@infradead.org; 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 > > On 8 April 2016 at 19:27, Jun Li wrote: > > > > > >> -----Original Message----- > >> From: Baolin Wang [mailto:baolin.wang@linaro.org] > >> Sent: Friday, April 08, 2016 7:00 PM > >> To: Jun Li > >> Cc: balbi@kernel.org; gregkh@linuxfoundation.org; sre@kernel.org; > >> dbaryshkov@gmail.com; dwmw2@infradead.org; 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 > >> > >> Hi Jun, > >> > >> >> >> +/* > >> >> >> + * 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. > >> >> > >> >> This API is used for detecting the charger type manually (software > >> >> charger detection), so if user's udc driver is needed to do this, > >> >> then they can issue it at their right place to make it more flexible. > >> >> But let us see other people's suggestion. Thanks. > >> > > >> > Ok, actually this API can be used for what ever charger detection > >> > type, user can implement any method(manual detection, directly read > >> > result from some HW...what ever) in uchger->charger_detect(), > >> > target is > >> > >> But reading result from some HW dose not means *detect*, actually is > *get*. > >> We can not mix them together with the different semantics. > > > > It doesn’t matter here, you already define the _get_ API for just read > > the charger type from the saved value(uchger->type), so we can think > > the API to make uchger->type from UNKNOW to ONE KNOWN type is > > *detect*, because we don't need 2 separate API one for *get* type from > > HW and another one for *detect* from HW, only one API involve HW access > is enough. > > But another issue is some users may need to get the charger type from > power supply by "power_supply_get_property()" function, we need to > integrate with the power supply things in the usb charger framework, not > user to implement that. Why this user(your case) can't put the charger type get by "power_supply_get_property()" in its uchger->charger_detect(), any special reason prevent you doing it? I am not sure if this case is very common, even if it is, you also can put it in usb_charger_detect_type() usb_charger_detect_type() { If can get from power_supply_get_property() ... else if uchger->charger_detect uchger->charger_detect(); ... } I don't know if most design of usb charger detection now days is as easy as your PMIC for software(HW does the whole detection process and prevent the vbus generation until detection has completed), anyway if your framework can guarantee the detection process finished before gadget connect, then each user don't have to worry about the HW detection process details and seek a proper place to do it. Li Jun > > > > > - Detect: (write to and) read from HW to get the charger type, > > save to uchger->type; > > - Get: read the charger type from uchger->type. > > > >> > >> > to have the charger type and set uchger->type, then you no need to > >> > add the comments/description to limit it usage. Also I do see there > >> > is > >> possible central place to do this. > >> > > >> > >> -- > >> Baolin.wang > >> Best Regards > > > > -- > Baolin.wang > Best Regards