From patchwork Mon Nov 16 06:33:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 56569 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1142775lbb; Sun, 15 Nov 2015 22:34:30 -0800 (PST) X-Received: by 10.68.69.71 with SMTP id c7mr52609506pbu.84.1447655670227; Sun, 15 Nov 2015 22:34:30 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xn5si48496795pbb.194.2015.11.15.22.34.29; Sun, 15 Nov 2015 22:34:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751658AbbKPGeQ (ORCPT + 11 others); Mon, 16 Nov 2015 01:34:16 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:33695 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751543AbbKPGeM (ORCPT ); Mon, 16 Nov 2015 01:34:12 -0500 Received: by pabfh17 with SMTP id fh17so167181893pab.0 for ; Sun, 15 Nov 2015 22:34:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=M6j7s9Id1qGVJ+LeJspEX8KA2Ta4yQOX72Ogh495oak=; b=2I6/vZBJeia79InrKMOYyrIfmoFOX1/GEx0dAn4CoiJ42Mmphbh/+r4ByBU9VNJMBI 6n34EZZ4YAgWBFETHGiMhrelQwTk4bRhV1zXV1mMsk5hGjmJI40JRY6/ePr95nrh/BhY CK13Plk2V0+xP9P7AK23AiXu6aDEusCLn0JNjJQAmgB6mRgDv/CWXy0yBwlaJFtZ12Rv 3wanmnfq+gRpnuv7mo8xkmIyC6Ax825CBpqN2UWzofTKwwDj23K3TrFF+59SzPEBtJvj KJwlUyegNHfoFxJ1jmNhmNTlKGO7m10u4A0HR1u1clHWquT5nmVuUsHuoFyOzrSqJ4WX XMjQ== 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=M6j7s9Id1qGVJ+LeJspEX8KA2Ta4yQOX72Ogh495oak=; b=ZZRFCkbUINxDR9cgCkrljON1CdHOScMOA6lgqv9PD4onv34lYoVDIF6w1IWpGl60Dc 25j2o+Nag6/kV+Hd47+CV+wWGoeBUrW5rtPwkud17RHK3pZWdJuoWOQ3HOh8G15bWjVU Egmmawl7QSRncRlruegAkNRi+RuwwAq3dD2yOUcCNaiANUGZ5wN7hybCQttLEZQRoyZI XdsGa3Rs02A6C9fT8T+uM9Re3llJ+WBqum6/EGvpCMXzhc017TjjSTKBO8hdkaBRMtLm xf5w4BVmPQM9D8KM6gLD5rsRbeTNc6/fAs5oOZiKJZysEEqL55PlHA9qBw87eD2yOkl2 xkxQ== X-Gm-Message-State: ALoCoQmydV3ojzeI+2VZFoC6gQ7PFHe1C3XqPqWIkDlfUSfmZxuBmRndBENDPntNzYWIxvcEBU/d X-Received: by 10.66.253.135 with SMTP id aa7mr51630972pad.14.1447655651505; Sun, 15 Nov 2015 22:34:11 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id l9sm32535196pbq.43.2015.11.15.22.34.06 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 15 Nov 2015 22:34:10 -0800 (PST) From: Baolin Wang To: balbi@ti.com, gregkh@linuxfoundation.org, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org Cc: 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: [PATCH v6 2/4] gadget: Support for the usb charger framework Date: Mon, 16 Nov 2015 14:33:32 +0800 Message-Id: <7919ed1aa73d419b7b422e9545e5c2af2b97c233.1447654606.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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. Introduce a callback 'get_charger_type' which will implemented by user for usb gadget operations to get the usb charger type. Signed-off-by: Baolin Wang --- drivers/usb/gadget/udc/udc-core.c | 11 +++++++++++ include/linux/usb/gadget.h | 10 ++++++++++ 2 files changed, 21 insertions(+) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" 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 f660afb..2727f01 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 @@ -226,6 +227,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"); } @@ -405,8 +409,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); @@ -481,6 +491,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 3d583a1..b8a6d38 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -24,6 +24,7 @@ #include #include #include +#include struct usb_ep; @@ -560,6 +561,7 @@ struct usb_gadget_ops { struct usb_ep *(*match_ep)(struct usb_gadget *, struct usb_endpoint_descriptor *, struct usb_ss_ep_comp_descriptor *); + enum usb_charger_type (*get_charger_type)(struct usb_gadget *); }; /** @@ -632,6 +634,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; @@ -836,10 +840,16 @@ 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, mA); + if (!gadget->ops->vbus_draw) return -EOPNOTSUPP; return gadget->ops->vbus_draw(gadget, mA);