From patchwork Mon Aug 1 07:09:31 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: 73083 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp2550436qga; Mon, 1 Aug 2016 00:12:03 -0700 (PDT) X-Received: by 10.98.75.219 with SMTP id d88mr93642799pfj.91.1470035523367; Mon, 01 Aug 2016 00:12:03 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jj1si33645955pac.71.2016.08.01.00.12.02; Mon, 01 Aug 2016 00:12:03 -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 S1751979AbcHAHLK (ORCPT + 27 others); Mon, 1 Aug 2016 03:11:10 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:36844 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751052AbcHAHK6 (ORCPT ); Mon, 1 Aug 2016 03:10:58 -0400 Received: by mail-pa0-f52.google.com with SMTP id pp5so50012448pac.3 for ; Mon, 01 Aug 2016 00:10:22 -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=Rhnx46AxeUq1Snlbi1ykckO2uIzra7lWzZADFXoOCLTt0vovCnvvKyRwZiC1iu/f4v u1PLF8TOuZsHzAEE6pnr1O6FUYe8jIqf/WB7he6XJB4GKH8VqLZMfKjXa0n5ymK5zncO kW9LZCXzoxZP9g7/sQdA2wRVavwFR2MqmCrdA= 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=My9zyXHTDU9qSJR1v91A6G0+gf8E8dWNl/ryo6C8sAmBP3c128XTvfyk0vc1ki9nNV XyvdjiWHGSgJSzdFRGOuM/rvCQttmNoMWZNNGe8qAt9xCinNqu4PLXCOdGCi+r7FRlAQ MdgtEfFgu+eQg2lRABHVV65VcLoewg6iB1HWciZ77I5ioUCSLaWTIVvR8+wTL35n7Ooj FsfspT/GLbYkR1oHR7Y6aQ+6bwjjbLzCH7EFJ8IbvV8gVi4rKepxiwT/1mzUjb8Binng ecZ/zI2NngPW1ghYl5aFvzYBY/EgnKnmLGnLj62aLC47DJQjmHbkuZCqYw3gQkK1IWwX 3ZXg== X-Gm-Message-State: AEkoouuseGLZxjvGR9FczQMhTGcYoooZfQzTqk+lhB0/5Hx+unpevLJb9PxrLZEDLvfCWIHj X-Received: by 10.66.55.35 with SMTP id o3mr92593868pap.90.1470035421837; Mon, 01 Aug 2016 00:10:21 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id r21sm42658639pfi.52.2016.08.01.00.10.16 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Aug 2016 00:10:21 -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 v16 2/4] usb: gadget: Support for the usb charger framework Date: Mon, 1 Aug 2016 15:09:31 +0800 Message-Id: <996bd04bc6fa4afef6c0a20fbe2bca6529688fc8.1470034830.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;