From patchwork Fri Jul 1 06:05:46 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: 71287 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp127254qgy; Thu, 30 Jun 2016 23:06:51 -0700 (PDT) X-Received: by 10.66.150.105 with SMTP id uh9mr28782426pab.73.1467353208947; Thu, 30 Jun 2016 23:06:48 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zz14si2047984pab.68.2016.06.30.23.06.48; Thu, 30 Jun 2016 23:06:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932101AbcGAGGo (ORCPT + 30 others); Fri, 1 Jul 2016 02:06:44 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:36190 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752281AbcGAGGj (ORCPT ); Fri, 1 Jul 2016 02:06:39 -0400 Received: by mail-pf0-f176.google.com with SMTP id t190so37092155pfb.3 for ; Thu, 30 Jun 2016 23:06:38 -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=hl+EqdCFFZnlXaRLiBwbT5BGLpiA1JZTtc6Ghcf1sxw=; b=aJUF/evLEhwdYqQ470db/S80d818afHyiykOFSr+3ZtDVh3QrYcjSAKZKDmrpIvlNT 5sWP4ePP8q874VtuSrssEvoQO/ARlufV2pKCP/Hd3FkJMiUbvX6yUPcG8+z1yIVmNDxn 2djCujCS0oXftJyb7tdgtDOKcq2Kg18snoqIk= 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=hl+EqdCFFZnlXaRLiBwbT5BGLpiA1JZTtc6Ghcf1sxw=; b=LoN9r0XkJCacS1Y61J6Sspv2iVrDPFWsOmLE7g7kh3ikQa8qd0TaFSDo48spaTfhBd GFu/TGkZmqYmlYi1U0JLRjY8vr3HYnftxm5JXP8BOLdP4AXn3vUtgK9AFFXYiD1RMQcL 8bwTpXpow2LsFWdAJAmc/V6f4hINsUTxna8gYQGmcpY7+8xYX/SnXJUKaEulINrPNRzp tphKblFbVZewY3/sh9wul2FVuOOCDVR1BJoyJCLD+x+D5h21R8q18btR7HyOEn+t90YJ Dm/oTIw6LTGJ4Z+d6tzFeXUfoCCCzVEWNLrK8CAwgYJ9JrETzXo1RsdqjDrx5PWw5fyX AOog== X-Gm-Message-State: ALyK8tKjHgeeNZPtp2lrmfqgX1hU2nl6odnuhC2UeA954g5gkYLgbBGpmdUAe+/OiSb9jjgK X-Received: by 10.98.9.141 with SMTP id 13mr28421609pfj.130.1467353198080; Thu, 30 Jun 2016 23:06:38 -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.31 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Jun 2016 23:06:37 -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 2/4] usb: gadget: Support for the usb charger framework Date: Fri, 1 Jul 2016 14:05:46 +0800 Message-Id: <4188757dbce70ff5e7d0c9c60f568d18ef1505c8.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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For supporting the usb charger, it adds the usb_charger_init() and usb_charger_exit() functions for usb charger initialization and exit. It will report to the usb charger when the gadget state is changed, then the usb charger can do the power things. Signed-off-by: Baolin Wang Reviewed-by: Li Jun Tested-by: Li Jun --- drivers/usb/gadget/udc/core.c | 17 +++++++++++++++++ include/linux/usb/gadget.h | 3 +++ 2 files changed, 20 insertions(+) -- 1.7.9.5 diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index ff8685e..bdf1874 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -578,12 +579,17 @@ EXPORT_SYMBOL_GPL(usb_gadget_vbus_connect); * reporting how much power the device may consume. For example, this * could affect how quickly batteries are recharged. * + * It will also notify the USB charger how much power the device may + * consume if there is a USB charger linking with the gadget. + * * Returns zero on success, else negative errno. */ int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) { int ret = 0; + usb_charger_set_cur_limit_by_gadget(gadget, mA); + if (!gadget->ops->vbus_draw) { ret = -EOPNOTSUPP; goto out; @@ -965,6 +971,9 @@ static void usb_gadget_state_work(struct work_struct *work) struct usb_gadget *gadget = work_to_gadget(work); struct usb_udc *udc = gadget->udc; + /* when the gadget state is changed, then report to USB charger */ + usb_charger_plug_by_gadget(gadget, gadget->state); + if (udc) sysfs_notify(&udc->dev.kobj, NULL, "state"); } @@ -1134,6 +1143,10 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, if (ret) goto err4; + ret = usb_charger_init(gadget); + if (ret) + goto err5; + usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); udc->vbus = true; @@ -1154,6 +1167,9 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, return 0; +err5: + device_del(&udc->dev); + err4: list_del(&udc->list); mutex_unlock(&udc_lock); @@ -1262,6 +1278,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 612dbdf..c864b51 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -24,6 +24,7 @@ #include #include #include +#include #define UDC_TRACE_STR_MAX 512 @@ -328,6 +329,7 @@ struct usb_gadget_ops { * @in_epnum: last used in ep number * @mA: last set mA value * @otg_caps: OTG capabilities of this gadget. + * @charger: Negotiate the power with the usb charger. * @sg_supported: true if we can handle scatter-gather * @is_otg: True if the USB device port uses a Mini-AB jack, so that the * gadget driver must provide a USB OTG descriptor. @@ -385,6 +387,7 @@ struct usb_gadget { unsigned in_epnum; unsigned mA; struct usb_otg_caps *otg_caps; + struct usb_charger *charger; unsigned sg_supported:1; unsigned is_otg:1;