From patchwork Fri Jul 1 06:05:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 71288 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp127388qgy; Thu, 30 Jun 2016 23:07:08 -0700 (PDT) X-Received: by 10.98.88.5 with SMTP id m5mr28560030pfb.27.1467353228874; Thu, 30 Jun 2016 23:07:08 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p64si2506356pfi.102.2016.06.30.23.07.08; Thu, 30 Jun 2016 23:07:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932103AbcGAGGv (ORCPT + 14 others); Fri, 1 Jul 2016 02:06:51 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:34381 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932102AbcGAGGu (ORCPT ); Fri, 1 Jul 2016 02:06:50 -0400 Received: by mail-pf0-f179.google.com with SMTP id h14so37006650pfe.1 for ; Thu, 30 Jun 2016 23:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=6kIEWPVsMtkPGTpzoSCrprpmgWzZcuvE7D5O72FUh64=; b=kmGDknDEBUY6kKPU95uB+swGWomXSj1ecA/HgITT6aSMVQ7CVA4IpNBk0KAmJfrsT2 j0uJocG+bTvNd3pKT4i7QaP+pek9/fxpa6gQ76PBL+3wz4gKzEJLcPOernAt3i1euu7Y 3tn+opUKNGhEtxFhfcNfBM98xNNsbmcqJS6x4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=6kIEWPVsMtkPGTpzoSCrprpmgWzZcuvE7D5O72FUh64=; b=mqOm1xwZyZzEZ46sRKNn2LvkgevIQRsI9+CCrp1ShpMhwsyRNhfMegzYf/6asua/x2 MAt07WAz3EUPI/M4d9mKaJYM5nlI47LNYvQ7g2vdXs8h3A27xtDQlL8/gmklmXAsKT1K FsGhH+ZgzeWBVRW/b74d5o8z4R3vBDY+g8w8E0dHc06TL8ZH1uAf/uooiNUXSolM50UL +yir8mZlEGFqEhIbC1dKMJoU81xWkWYhNmDO4Rjm7n9ZsNOF0sLt9wb72pQmvSA7sXxI k0ZTEiKsL3jH0te5r21fvU4/u0hO9qUO3tMU2EQ5zVEJQPd1EHK4L/jdl/3O7TOKxrUI GG0w== X-Gm-Message-State: ALyK8tKEyKZ7aXsQ2pSy/6GL+m3ohGkPP+Sr7uL4b/1Mjla+dOXF93wdQBM8l65twm+A61f4 X-Received: by 10.98.83.68 with SMTP id h65mr28117639pfb.112.1467353205772; Thu, 30 Jun 2016 23:06:45 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id bw1sm2258917pab.17.2016.06.30.23.06.39 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Jun 2016 23:06:45 -0700 (PDT) From: Baolin Wang To: balbi@kernel.org, gregkh@linuxfoundation.org, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org Cc: robh@kernel.org, jun.li@nxp.com, m.szyprowski@samsung.com, ruslan.bilovol@gmail.com, peter.chen@freescale.com, stern@rowland.harvard.edu, r.baldyga@samsung.com, grygorii.strashko@ti.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 v15 3/4] usb: gadget: Integrate with the usb gadget supporting for usb charger Date: Fri, 1 Jul 2016 14:05:47 +0800 Message-Id: <9e05cbfc9dff2bca09d818c5cadafbd9d666da2a.1467352530.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When the usb gadget supporting for usb charger is ready, the usb charger can implement the usb_charger_plug_by_gadget() function, usb_charger_exit() function and dev_to_uchger() function by getting 'struct usb_charger' from 'struct gadget'. Signed-off-by: Baolin Wang Reviewed-by: Li Jun Tested-by: Li Jun --- drivers/usb/gadget/udc/charger.c | 67 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/gadget/udc/charger.c b/drivers/usb/gadget/udc/charger.c index 54c1712f..57f9fd2 100644 --- a/drivers/usb/gadget/udc/charger.c +++ b/drivers/usb/gadget/udc/charger.c @@ -36,7 +36,9 @@ static unsigned int __usb_charger_get_cur_limit(struct usb_charger *uchger); static struct usb_charger *dev_to_uchger(struct device *dev) { - return NULL; + struct usb_gadget *gadget = container_of(dev, struct usb_gadget, dev); + + return gadget->charger; } /* @@ -305,7 +307,13 @@ static int __usb_charger_set_cur_limit_by_type(struct usb_charger *uchger, int usb_charger_set_cur_limit_by_gadget(struct usb_gadget *gadget, unsigned int cur_limit) { - return 0; + struct usb_charger *uchger = gadget->charger; + + if (!uchger) + return -EINVAL; + + return __usb_charger_set_cur_limit_by_type(uchger, uchger->type, + cur_limit); } EXPORT_SYMBOL_GPL(usb_charger_set_cur_limit_by_gadget); @@ -563,11 +571,52 @@ usb_charger_plug_by_extcon(struct notifier_block *nb, int usb_charger_plug_by_gadget(struct usb_gadget *gadget, unsigned long state) { + struct usb_charger *uchger = gadget->charger; + enum usb_charger_state uchger_state; + + if (WARN(!uchger, "charger can not be NULL")) + return -EINVAL; + + /* + * Report event to power to setting the current limitation + * for this usb charger when one usb charger state is changed + * with detecting by usb gadget state. + */ + if (uchger->old_gadget_state != state) { + uchger->old_gadget_state = state; + + if (state >= USB_STATE_ATTACHED) + uchger_state = USB_CHARGER_PRESENT; + else if (state == USB_STATE_NOTATTACHED) + uchger_state = USB_CHARGER_REMOVE; + else + uchger_state = USB_CHARGER_DEFAULT; + + usb_charger_notify_others(uchger, uchger_state); + } + return 0; } EXPORT_SYMBOL_GPL(usb_charger_plug_by_gadget); /* + * usb_charger_unregister() - Unregister a usb charger. + * @uchger - the usb charger to be unregistered. + */ +static int usb_charger_unregister(struct usb_charger *uchger) +{ + ida_simple_remove(&usb_charger_ida, uchger->id); + sysfs_remove_groups(&uchger->gadget->dev.kobj, usb_charger_groups); + + mutex_lock(&charger_lock); + list_del(&uchger->list); + mutex_unlock(&charger_lock); + + kfree(uchger); + return 0; +} + +/* * usb_charger_register() - Register a new usb charger. * @uchger - the new usb charger instance. */ @@ -647,6 +696,7 @@ int usb_charger_init(struct usb_gadget *ugadget) /* register a notifier on a usb gadget device */ uchger->gadget = ugadget; + ugadget->charger = uchger; uchger->old_gadget_state = USB_STATE_NOTATTACHED; /* register a new usb charger */ @@ -669,7 +719,18 @@ fail: int usb_charger_exit(struct usb_gadget *ugadget) { - return 0; + struct usb_charger *uchger = ugadget->charger; + + if (!uchger) + return -EINVAL; + + ugadget->charger = NULL; + if (uchger->extcon_dev) + extcon_unregister_notifier(uchger->extcon_dev, + EXTCON_USB, + &uchger->extcon_nb.nb); + + return usb_charger_unregister(uchger); } MODULE_AUTHOR("Baolin Wang ");