From patchwork Mon Jan 4 03:04:28 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: 59114 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp5120698lbb; Sun, 3 Jan 2016 19:06:21 -0800 (PST) X-Received: by 10.67.6.195 with SMTP id cw3mr124033588pad.88.1451876775484; Sun, 03 Jan 2016 19:06:15 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qy6si39874375pab.19.2016.01.03.19.06.15; Sun, 03 Jan 2016 19:06:15 -0800 (PST) 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; 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752729AbcADDGI (ORCPT + 4 others); Sun, 3 Jan 2016 22:06:08 -0500 Received: from mail-pf0-f171.google.com ([209.85.192.171]:36511 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752646AbcADDFu (ORCPT ); Sun, 3 Jan 2016 22:05:50 -0500 Received: by mail-pf0-f171.google.com with SMTP id 65so149679940pff.3 for ; Sun, 03 Jan 2016 19:05:49 -0800 (PST) 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=8p2qApvUjIG3FYr2FI1fN/QwfM23d35Swe+cZ3TW0eQ=; b=BImadeHxY/iFor7VouH5zSSgqAe/E9SWqrLfMWqmnbV0I4JDosZ+3egcADmfKJuF1t iln962DvS4fBV2cACMz+j8ZRUX72U9Oua4Oy0lZZjdg6qPd8el1gQnttH3jPT3EFdGhh utwkqbsNZ+0foZ767FirH1RrX87Q7LPL0s8Ss= 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=doFNmVhmBKxjha6jcWEVoE3X2p+nmD1GACgTq3B3jeJkl80OHLI4vJ0OmL9qatHLad A2ZHqyHkeOLUKi7UHoS+FyX7MN30riJGkoB250Y5D0kzRCCauxDBLXXbqO5zN0UY+JXX Y6sY7sQYVdvqeOflw0mziYEGOYUtnosfBqHeN56ZI1xmUcv5+3aV1AdxnpWIqsv2KNAQ ptx4JlSYZFRWSQH2OMnyOuDAh7hUTwrVk9tyLMlVwo8bjcqlIGoigG6sbTzo/mH9GK5B xYq59VzlZzWKEO6gwwMTN8gmX+KfQF09RnbNiEFvaqipXJdVf3KLa5JkXQoHvOuwHDTh 60Kg== X-Gm-Message-State: ALoCoQlGxNeIbFDnjLit48Pfl1JZCPDZ4y9xv0IQ3SjjzJ1i4wprjyHCPaJFBxT5AUE57Uf5Sz9DLYIsX80paRF0AuarHuhe3w== X-Received: by 10.98.67.195 with SMTP id l64mr70618946pfi.109.1451876749663; Sun, 03 Jan 2016 19:05:49 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id c87sm18766187pfj.79.2016.01.03.19.05.44 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Jan 2016 19:05:48 -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: Mon, 4 Jan 2016 11:04:28 +0800 Message-Id: <6eaa0db83cff5eaffa2e10fe51f5b3e47b1dd4c3.1451876014.git.baolin.wang@linaro.org> 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. 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-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 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);