From patchwork Thu Mar 24 12:35:55 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: 64344 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp612084lbc; Thu, 24 Mar 2016 05:37:31 -0700 (PDT) X-Received: by 10.98.15.17 with SMTP id x17mr12609716pfi.52.1458823040528; Thu, 24 Mar 2016 05:37:20 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xw2si11983293pac.192.2016.03.24.05.37.20; Thu, 24 Mar 2016 05:37:20 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757491AbcCXMhI (ORCPT + 4 others); Thu, 24 Mar 2016 08:37:08 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:33998 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755877AbcCXMhD (ORCPT ); Thu, 24 Mar 2016 08:37:03 -0400 Received: by mail-pf0-f171.google.com with SMTP id x3so56016850pfb.1 for ; Thu, 24 Mar 2016 05:36:57 -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=xxkDWGUc0feKFBm1NQI9MS64aKHGNOjertAVyaggILc=; b=bpcdZs3JVUUE4AVkk9icm3SrTctBrb1zqydZ/73MOaMolWsWl/4M0D2FQHGIQQF8/D ODzJRyggjDsTWDp2p26V/PFxdrLXHZR6y6SBINVgrbNIKuD2f2w6XaSS32mSQjI0Jx6f yqRb/Eya27u4NUZKUv3QR3rkdo3Pvr3ebVJiQ= 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=xxkDWGUc0feKFBm1NQI9MS64aKHGNOjertAVyaggILc=; b=h6JGqEjAThWF/BL4yXyLZxsp+N9LdLZQN/Jbb64lxQyEToRJnaQvngXBPEkg1Huv2/ dz9JZVknTDCO3zkOFW0XU1B90B6G4+AOqvQdeXIUfmMK/5AdVcQ9emL9n6OiCosnfcQM ogXuqitp3iVuXZcpgurN2To9PkBQLORivym8vmBhV+cNT1R0c9vM4y9NPVMt212dQc21 Ogmdwj8iRa0ir/0AWAbwnmE1+bbwjem5LxKPFPiRSxfZ/VUwMUNMaiNxH5baSn7HRl51 q1VjOE3fBVG/hNS/f8Bekd9gtY18Kat3JjbjDiOvH+Np4KyG+/XLk4ybFIKYtAUaY5lC eAuw== X-Gm-Message-State: AD7BkJJ+9OxYi9xU96YZLO8V+seawVTYXtWQYHoXRa9xT61waPMrzW/0rNjBPg5bQrn6TFF8 X-Received: by 10.98.19.2 with SMTP id b2mr12311552pfj.93.1458823012357; Thu, 24 Mar 2016 05:36:52 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id 9sm10202285pfm.10.2016.03.24.05.36.47 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Mar 2016 05:36:51 -0700 (PDT) From: Baolin Wang To: balbi@kernel.org, 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 v8 2/4] gadget: Support for the usb charger framework Date: Thu, 24 Mar 2016 20:35:55 +0800 Message-Id: <1fd60a573ba0d1966c6ab434574633138159b1de.1458822334.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 b86a6f0..3d9a489 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 @@ -230,6 +231,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"); } @@ -423,8 +427,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); @@ -503,6 +513,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 d82d006..024b33d 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -24,6 +24,7 @@ #include #include #include +#include struct usb_ep; @@ -563,6 +564,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 *); }; /** @@ -635,6 +637,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; @@ -839,10 +843,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);