From patchwork Fri Nov 6 11:35:12 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: 56110 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp953186lbr; Fri, 6 Nov 2015 03:36:41 -0800 (PST) X-Received: by 10.68.138.233 with SMTP id qt9mr16616490pbb.99.1446809801481; Fri, 06 Nov 2015 03:36:41 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dz5si17169390pab.108.2015.11.06.03.36.41; Fri, 06 Nov 2015 03:36:41 -0800 (PST) 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; 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; 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 S1161375AbbKFLg0 (ORCPT + 28 others); Fri, 6 Nov 2015 06:36:26 -0500 Received: from mail-pa0-f51.google.com ([209.85.220.51]:33745 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161334AbbKFLgV (ORCPT ); Fri, 6 Nov 2015 06:36:21 -0500 Received: by pabfh17 with SMTP id fh17so120837524pab.0 for ; Fri, 06 Nov 2015 03:36:20 -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=EAHaxpmtJV5Qzqb1Jl0/ZLtJGVGc+RppeZXU8e9c7Gk=; b=aGcWnzQKbR3EIFUEMyMqYPM3Ifei1EHbJMDNavOn3Sifswnxc4rhljWUfAj7bh1Y65 9oRfF8o4RCMkJq1BhTgWUMMK5HFfUcHpvdFW3NC4rpF5tq3JV4kheVt/ZZPSltiy8JzD lqKxPEEeLCshmNXEo+QEjvoIOj/p9XTXalfSNzehhLuKT5b9wvIpPlUST9JcYaI36qVE gtbg1HTYLgjlvTbHV/1Jp7wveFZuauWfF5aSGOmTOinCeD6FI74gRk3CLW9f9v0RiyAV iNtJWMiuMokLXfMACaxn4gofvAZWHlOa3o6WVXRX5kvHbzbbRycl9Ct2eEwKhfQAvfRQ /hhQ== 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=EAHaxpmtJV5Qzqb1Jl0/ZLtJGVGc+RppeZXU8e9c7Gk=; b=LGowOhrn0Bq32gcX2XZQaJCHsIQZBiUYuEIAOuneRCdXvTxUw1XBL6zNdDxFHk24Iv F4CliS6J3r1tICfmcfgEfT6BezYvDcvf+xrNtnRgoRemwBXSZ4Zpz2jsF5CGLU5j4viz dR9CqMTjw3YLeJJjVTh6kNF0K3BYyDCCH30+0KigO6ibYYDxlAoprohFMq8MGuiS2z0a XOLGyG6HNpKWOgJEr7GYgRLHyI6yw4G/DklEf5Wnc39xF3lA4qhX3O8slxbIt6/4CJBi huR3/DijZxQaQtkzUhd9KShU2EMTnP/yt5wPzYguLvy8Rit0g3qCpJWlmgrzNquJviuX 1J2g== X-Gm-Message-State: ALoCoQnj+G72HYCHyZGbLxx18MZA5PG2vIJfnko60MQ7c2etztqIGiwAEGEh3fkqhgmm7wpzQHYQ X-Received: by 10.66.66.166 with SMTP id g6mr16744470pat.152.1446809780529; Fri, 06 Nov 2015 03:36:20 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id xm4sm13644680pab.27.2015.11.06.03.36.15 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Nov 2015 03:36:19 -0800 (PST) From: Baolin Wang To: balbi@ti.com, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org Cc: broonie@kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org, gregkh@linuxfoundation.org, peter.chen@freescale.com, stern@rowland.harvard.edu, r.baldyga@samsung.com, yoshihiro.shimoda.uh@renesas.com, linux-usb@vger.kernel.org, device-mainlining@lists.linuxfoundation.org, sameo@linux.intel.com, lee.jones@linaro.org, ckeepax@opensource.wolfsonmicro.com, patches@opensource.wolfsonmicro.com, linux-pm@vger.kernel.org Subject: [PATCH v5 3/5] gadget: Support for the usb charger framework Date: Fri, 6 Nov 2015 19:35:12 +0800 Message-Id: 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. 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 | 8 ++++++++ include/linux/usb/gadget.h | 9 +++++++++ 2 files changed, 17 insertions(+) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index 4238fc3..370376e 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 @@ -437,8 +438,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); @@ -513,6 +520,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 755e8bc..c2610c4 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -24,6 +24,7 @@ #include #include #include +#include struct usb_ep; @@ -537,6 +538,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 *); }; /** @@ -611,6 +613,7 @@ struct usb_gadget { struct usb_otg_caps *otg_caps; struct raw_notifier_head nh; struct mutex lock; + struct usb_charger *charger; unsigned sg_supported:1; unsigned is_otg:1; @@ -815,10 +818,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);