From patchwork Wed Oct 19 02:37:35 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: 78165 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp22475qge; Tue, 18 Oct 2016 19:38:26 -0700 (PDT) X-Received: by 10.99.144.74 with SMTP id a71mr5243920pge.101.1476844706464; Tue, 18 Oct 2016 19:38:26 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zf5si14630844pac.42.2016.10.18.19.38.26; Tue, 18 Oct 2016 19:38:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-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-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-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 S1756592AbcJSCiV (ORCPT + 4 others); Tue, 18 Oct 2016 22:38:21 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:34393 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756580AbcJSCiN (ORCPT ); Tue, 18 Oct 2016 22:38:13 -0400 Received: by mail-pf0-f181.google.com with SMTP id r16so6880901pfg.1 for ; Tue, 18 Oct 2016 19:38:13 -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=jmkt3JpPZ3ecUXjpeYLLI9ihaUhDfuK73R3xQ7y3XXU=; b=F5TJYzbLBjvabu14sr/XQmcOGJidlp2N3CTPDBbi1eUUuOJIPSbtNOCZcxpcrm82eV sO37hJrarZWbzYOFlLbgB1WnuDUar813pBCFl1rGtmVtza1WGzm8p3OJ+xdg53RPBR8/ ycAvTxjKL0VK9cJHkp9vRMeQU0v2+0zXUHLVY= 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=jmkt3JpPZ3ecUXjpeYLLI9ihaUhDfuK73R3xQ7y3XXU=; b=CSRTbOuZZRLbdR3iP4+EeAJaI963L2l85/nsbCAJYsqSDDeApbmyRG19LtTcPXnH57 Tpg1GFyFaqLs+NW1fBSVhXjUffVGxMlc2emCy/4e8BbU7WcAViOtd3c5A1pYFOYf9YYH AMxLygEUpxxdPj8U0f3Nzv0URjqlwwLqSvZEGzZu3N9bxDcdPtX7QDcdw4UBY0iPZJs9 saw6cbuyyiQgyYz8eLVc52YS4ZJ98qaYvlyYGu/XKHQjwrUFIhCBEQoziV8uVVNo7A52 c1pgjHkj7F9a3PTEajou27cAVF8nAdkNnzDPSrseuogDL74vrF9MF/yIsOVk3sJXaWeP 4h8w== X-Gm-Message-State: AA6/9Rl2oSot3g9ee0lx9ChXMErgKGz/dxaXGFVhx6wGMumIQCp/LIEO33WomU3bUsnUEhwK X-Received: by 10.98.217.135 with SMTP id b7mr6509626pfl.103.1476844692139; Tue, 18 Oct 2016 19:38:12 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id d26sm8456006pfb.37.2016.10.18.19.38.06 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Oct 2016 19:38:11 -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, grygorii.strashko@ti.com, yoshihiro.shimoda.uh@renesas.com, lee.jones@linaro.org, broonie@kernel.org, john.stultz@linaro.org, neilb@suse.com, 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 v18 2/4] usb: gadget: Support for the usb charger framework Date: Wed, 19 Oct 2016 10:37:35 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@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 | 19 ++++++++++++++++++- include/linux/usb/gadget.h | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" 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/core.c b/drivers/usb/gadget/udc/core.c index 9483489..90df022 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 @@ -576,12 +577,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; @@ -963,6 +969,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"); } @@ -1132,6 +1141,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; @@ -1143,7 +1156,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, if (ret != -EPROBE_DEFER) list_del(&driver->pending); if (ret) - goto err5; + goto err6; break; } } @@ -1152,6 +1165,9 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, return 0; +err6: + usb_charger_exit(gadget); + err5: device_del(&udc->dev); @@ -1263,6 +1279,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 8e81f9e..82a0d63 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. @@ -387,6 +389,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;