Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758008AbcDHJ4R (ORCPT ); Fri, 8 Apr 2016 05:56:17 -0400 Received: from mail-yw0-f178.google.com ([209.85.161.178]:36862 "EHLO mail-yw0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753730AbcDHJ4P (ORCPT ); Fri, 8 Apr 2016 05:56:15 -0400 MIME-Version: 1.0 In-Reply-To: References: <6b323d5168c10ccb47882687b1251c31b6cad587.1460029375.git.baolin.wang@linaro.org> Date: Fri, 8 Apr 2016 17:56:13 +0800 Message-ID: Subject: Re: [PATCH v10 1/4] gadget: Introduce the usb charger framework From: Baolin Wang 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" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3299 Lines: 104 Hi Jun, On 8 April 2016 at 16:04, Jun Li wrote: > Hi, Baolin > >> +/* >> + * 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. > > 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; >> +} >> + -- Baolin.wang Best Regards