From patchwork Tue Jun 21 08:39:13 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: 70536 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1901331qgy; Tue, 21 Jun 2016 01:41:44 -0700 (PDT) X-Received: by 10.36.123.199 with SMTP id q190mr3604459itc.42.1466498504812; Tue, 21 Jun 2016 01:41:44 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gk6si7960312pac.121.2016.06.21.01.41.44; Tue, 21 Jun 2016 01:41:44 -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 S1752977AbcFUIlE (ORCPT + 5 others); Tue, 21 Jun 2016 04:41:04 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:34772 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752947AbcFUIk6 (ORCPT ); Tue, 21 Jun 2016 04:40:58 -0400 Received: by mail-pa0-f52.google.com with SMTP id bz2so4346264pad.1 for ; Tue, 21 Jun 2016 01:40:53 -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=VHGEzIJoM8UrUruV0hzybUSnqNY6Z6tCMWGf51ZX33s=; b=QP1qyNeySAJ2fKh4+iGm2/T1EcjZj4ipLYKaeeBcgc7iOd9xGhQftXnLeVA3XhEyuf x+CqdYlNAL/uwZ7WzQxnCpyNuMrdIIBVby3IOg7sfvPifEM9p25KFvNpR9BvjnxAcJJ/ 6DgKmdKf8Xf8c2rvbNEL8TppY+Z2NVVXn5RXo= 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=VHGEzIJoM8UrUruV0hzybUSnqNY6Z6tCMWGf51ZX33s=; b=Xf0CmBPfVZHAHIG41uvDbnXmMMxlSm0F3xxfeAW53JNaDAwoFZBjEL4cZxZfyr0ShT JDCntJPtGVXqO9Btt6UB1tPaJ6kduDfMaG2uOeOrFwewtDi1LgBAxQEc4YmYlek/fyH2 V07SxmHJ5iIHhdCXIHm3c8vyg3pcdNDYIOCaPpjf2E7RfQ6x6+pckjsCeT1yDtcV9qly OVUWCHc9xgjs1ZKEO0D6c8rNwfb35cy7uhSnlQpXzCX6o0bZlyVExwvBJ6hI1S+iadsQ gHKMFaRX4QD99NV6u0t/y5eRSpNWtBHNEHrg6QP757HmE9wFuv1yUpsU6TVtj9sQjg9Z /OYA== X-Gm-Message-State: ALyK8tJmAR3BW/US5UiUoT1qOvl6WTY1bmes4tYx9RIYx+5Ig0ZTZ4z/b4Wuaf4G/9klPIfs X-Received: by 10.66.218.195 with SMTP id pi3mr26620981pac.83.1466498447765; Tue, 21 Jun 2016 01:40:47 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id w27sm23141565pfa.54.2016.06.21.01.40.41 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Jun 2016 01:40:47 -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 v12 2/4] gadget: Support for the usb charger framework Date: Tue, 21 Jun 2016 16:39:13 +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/udc-core.c | 11 +++++++++++ include/linux/usb/gadget.h | 11 +++++++++++ 2 files changed, 22 insertions(+) -- 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/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index 6e8300d..84c098c 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 @@ -242,6 +243,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"); } @@ -411,6 +415,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; @@ -431,6 +439,8 @@ 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); @@ -539,6 +549,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 457651b..40390ec 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,18 @@ 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) { + if (gadget->charger) + usb_charger_set_cur_limit_by_type(gadget->charger, + gadget->charger->type, + mA); + if (!gadget->ops->vbus_draw) return -EOPNOTSUPP; return gadget->ops->vbus_draw(gadget, mA);