From patchwork Tue May 3 03:30:15 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: 67053 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp372488qge; Mon, 2 May 2016 20:31:13 -0700 (PDT) X-Received: by 10.98.91.3 with SMTP id p3mr198764pfb.64.1462246268060; Mon, 02 May 2016 20:31:08 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si1844364paw.34.2016.05.02.20.31.07; Mon, 02 May 2016 20:31:08 -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 S932672AbcECDa7 (ORCPT + 29 others); Mon, 2 May 2016 23:30:59 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36796 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932208AbcECDa4 (ORCPT ); Mon, 2 May 2016 23:30:56 -0400 Received: by mail-pf0-f170.google.com with SMTP id c189so4105995pfb.3 for ; Mon, 02 May 2016 20:30:55 -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=/zSkfqzGG8lpQ0Z6n9u3KGCKAvtAzUJcEpLUzW0PpVs=; b=Iu6t5k5Jkab09CsbAc2PnNWa4zqtgSU/aIAbEnXi/3WjaMo+omha+jFM1+Guv8diQ7 cLYTovbHOAKgEVR9VKWu+JMjbJEP8mYJLF+A5N+5KNuF4eepZPsCzDZKtmh+QufPB2bj WdmA2Qg+bLUp50xgq0WeJG8CZzLNLaBJ/TNR0= 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=/zSkfqzGG8lpQ0Z6n9u3KGCKAvtAzUJcEpLUzW0PpVs=; b=fMkFvUDeYeDrMmvG2iU6sqTrrtoql2PHx7zjDBtzr6LaKlSBJP5JUzfXNMzUZGIMEY LixnUpzkg61jJFGzVm3vW6AY+gzTZXPgfJSRJ1Vj1lM8QYqlICTOoUXNyDzQienZqzL+ pBOQbHn0mfZXAo9dnZeJjGdzJ+nQYNCGgOZqRkJyTmjU8mXKCOzFB5eohNFeUFhwaVx+ /Mn0elDAYGrx/MXloe1mCoS1olFN7cbX4UQ8i806y/Yn9P706HnWAHUlSplFyaxF26wC a1kfghOQzYkl7cKCOREb1i4lmRY09T4uXvEacW5qtLhQLvbNc5+qTpr95GXaOct8zIvC u/QA== X-Gm-Message-State: AOPr4FV0Ofj4YCe5Ek/n7kY8rSCuua6CkU+O2XnfunsR485iTfAaQTN2qe/d5DuzUhM3ONrc X-Received: by 10.98.38.130 with SMTP id m124mr212946pfm.14.1462246254832; Mon, 02 May 2016 20:30:54 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id zn7sm1248815pac.41.2016.05.02.20.30.49 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 May 2016 20:30:54 -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, m.szyprowski@samsung.com, ruslan.bilovol@gmail.com, 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, 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: [RESEND PATCH v10 2/4] gadget: Support for the usb charger framework Date: Tue, 3 May 2016 11:30:15 +0800 Message-Id: <210c0053f347f44c4831a914235a7b0d82ae3829.1462245638.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 --- drivers/usb/gadget/udc/udc-core.c | 11 +++++++++++ include/linux/usb/gadget.h | 13 +++++++++++++ 2 files changed, 24 insertions(+) -- 1.7.9.5 diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index 4151597..3a37980 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -28,6 +28,7 @@ #include #include #include +#include /** * struct usb_udc - describes one usb device controller @@ -230,6 +231,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"); } @@ -423,8 +427,14 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, mutex_unlock(&udc_lock); + ret = usb_charger_init(gadget); + if (ret) + goto err5; + return 0; +err5: + device_del(&udc->dev); err4: list_del(&udc->list); mutex_unlock(&udc_lock); @@ -533,6 +543,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 5d4e151..f82ed6b 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -24,6 +24,7 @@ #include #include #include +#include struct usb_ep; @@ -639,6 +640,8 @@ struct usb_gadget { unsigned out_epnum; unsigned in_epnum; struct usb_otg_caps *otg_caps; + /* negotiate the power with the usb charger */ + struct usb_charger *charger; unsigned sg_supported:1; unsigned is_otg:1; @@ -855,10 +858,20 @@ static inline int usb_gadget_vbus_connect(struct usb_gadget *gadget) * 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. */ static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) { + enum usb_charger_type type; + + if (gadget->charger) { + type = usb_charger_get_type(gadget->charger); + usb_charger_set_cur_limit_by_type(gadget->charger, type, mA); + } + if (!gadget->ops->vbus_draw) return -EOPNOTSUPP; return gadget->ops->vbus_draw(gadget, mA);