From patchwork Tue Dec 8 08:36:02 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: 57834 Delivered-To: patch@linaro.org Received: by 10.112.147.194 with SMTP id tm2csp1655270lbb; Tue, 8 Dec 2015 00:36:48 -0800 (PST) X-Received: by 10.98.67.207 with SMTP id l76mr3225186pfi.59.1449563808141; Tue, 08 Dec 2015 00:36:48 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 70si3728976pfq.154.2015.12.08.00.36.47; Tue, 08 Dec 2015 00:36:48 -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 S964850AbbLHIgn (ORCPT + 11 others); Tue, 8 Dec 2015 03:36:43 -0500 Received: from mail-pa0-f41.google.com ([209.85.220.41]:35023 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964818AbbLHIgk (ORCPT ); Tue, 8 Dec 2015 03:36:40 -0500 Received: by pacej9 with SMTP id ej9so8757008pac.2 for ; Tue, 08 Dec 2015 00:36:40 -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=8p2qApvUjIG3FYr2FI1fN/QwfM23d35Swe+cZ3TW0eQ=; b=Kc1qJv4HQcGiTss/7mnRM+2/VdTauqGCX4pK0QX4Du8aNipAtnBYqeZNuvOZdBOxAc ypwnmLYLY4ivoUBRq0a1hDsyJZkUuswn36kpYf/VuIJMC4s57xbQ8+NjPMwwcoPORUxi aYtV61wzI9GbIE5MxtDlLF8fMUUmHh7IG+vu2OWgWbTibzP3ylsfOQOhFYyjIh5oRcws 2acTOSJRtLYplG8yXs+ldT1waNCUa3J4+0HBfUjsFxA9lozrtqbiA9HccYu8zvfZ5e16 y3gYbSiQGGmbZC3DEqJpAIFcsiFefx5yYpWFrToZip9jYKytVexiA8jyhmNYnplDW3A/ csPQ== 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=8p2qApvUjIG3FYr2FI1fN/QwfM23d35Swe+cZ3TW0eQ=; b=YKToVHleDm4LsNGFwBfMwcAEym3FEr7kR0YEigm2YU4VI3rkokFz6AfKfFkgrgiy1J N5SOzCGkFsk52M2cfteudE+hwmcr7/aD4fVs+/t9oW27+LiEDasks2Fv3n6aUOfoeM9M iaWjO4vI7RtCm88HNsasyTupqRKBXDUEfabDgxBDGnizEz/S8YQgupdeYyct1XK2AhPx SQVGFJNO+IG9TJSbMWOW1zdiGdVVaJT9l//oT//phwZOgjVFACZgPhEwfVzOeK5TB7+O BTfPKydvVLZBUw6c8LKw+VL3Foi9o4nzfTQgYlzoGgzoPxIGk+LhR93n67JXTf+edAW6 a9ew== X-Gm-Message-State: ALoCoQlnXdtMDXPsYTEkmWZSTzMSPv+tyT7YcVMklfPCNEj9+WfHn849CJ10NlEoOo4Kxl0JoltBWEQwKWZeb4uZ71FV2zCx5A== X-Received: by 10.66.190.66 with SMTP id go2mr3270604pac.114.1449563800110; Tue, 08 Dec 2015 00:36:40 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id fm1sm3049954pab.6.2015.12.08.00.36.35 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Dec 2015 00:36:39 -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 v7 2/4] gadget: Support for the usb charger framework Date: Tue, 8 Dec 2015 16:36:02 +0800 Message-Id: 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 | 11 +++++++++++ 2 files changed, 22 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..52c19b1 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,17 @@ 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, + usb_charger_detect_type(gadget->charger), mA); + if (!gadget->ops->vbus_draw) return -EOPNOTSUPP; return gadget->ops->vbus_draw(gadget, mA);