From patchwork Tue Jun 21 08:39:14 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: 70534 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1901235qgy; Tue, 21 Jun 2016 01:41:24 -0700 (PDT) X-Received: by 10.107.148.79 with SMTP id w76mr29622470iod.63.1466498484119; Tue, 21 Jun 2016 01:41:24 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xq1si16875945pab.11.2016.06.21.01.41.23; Tue, 21 Jun 2016 01:41:24 -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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752948AbcFUIk7 (ORCPT + 5 others); Tue, 21 Jun 2016 04:40:59 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:35463 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751450AbcFUIk4 (ORCPT ); Tue, 21 Jun 2016 04:40:56 -0400 Received: by mail-pa0-f52.google.com with SMTP id hl6so4365448pac.2 for ; Tue, 21 Jun 2016 01:40:56 -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=dbGIuBUDl2osxFuP+G7H6NBVsUI+MGuLPll5I3utAJg=; b=S4Wb9wgtPkUpWjtQd6eWS0/hJ3guj7XVX9l2PSvl6RC7uo0iE/QY0Ymjf5NN+2AD0r Bhi/nwefNUCi2RSY/4TeSCV4O2sD9eevgVtz9aL/02EEGtem7/oUfAr00Dpo5SG0X++I 5zdeRGdYZfESZYRh5Uk23kgacXbHV279dUmIo= 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=dbGIuBUDl2osxFuP+G7H6NBVsUI+MGuLPll5I3utAJg=; b=iIXFaQm6JqiWWlWUEwEYeUetTzOk+FRnL0tC3v/FRic+Hsz7RvL09MMbx+ZUmhjqAg L9uP3qwuUjeFXZX/vloRk9VBap/i5ZHD746v8ToJRmkJEC6l4mjNQqYw4QJrn7K8Of4O AXCseeEH0zyohrt/GQOe5pluyR8q7sX7SJzQSdzuNbj7QFl9EyxckmC5/RmFPsLxbfHn /SzgKSFnKJ2vWCXRSyOmzByE4oDR0spUBwcE/Gy+PbVVfc5C0tQKyVYreipQM4uZI6Fo 9MfnsFxFbdh6hneWGNjI1B+NpCz1fxUM2CxwY0Xs0cQU153XBChlgSZuchhUTiUczgMC ZEzQ== X-Gm-Message-State: ALyK8tJD4iBUUb9jkiWmCdFNoVunyoBM/G2GsrcQXDtq1W12CVHdyXD4r2FyURYkfQVOppqM X-Received: by 10.66.171.202 with SMTP id aw10mr27116259pac.100.1466498456087; Tue, 21 Jun 2016 01:40:56 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id w27sm23141565pfa.54.2016.06.21.01.40.49 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Jun 2016 01:40:55 -0700 (PDT) From: Baolin Wang To: balbi@kernel.org, gregkh@linuxfoundation.org, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org Cc: robh@kernel.org, jun.li@nxp.com, m.szyprowski@samsung.com, ruslan.bilovol@gmail.com, peter.chen@freescale.com, stern@rowland.harvard.edu, r.baldyga@samsung.com, grygorii.strashko@ti.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 v12 3/4] gadget: Integrate with the usb gadget supporting for usb charger Date: Tue, 21 Jun 2016 16:39:14 +0800 Message-Id: <2f57bf9df3a5dc6cce45834eaeec4f00b25808b7.1466497506.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 When the usb gadget supporting for usb charger is ready, the usb charger can implement the usb_charger_plug_by_gadget() function and usb_charger_exit() function by getting 'struct usb_charger' from 'struct gadget'. Signed-off-by: Baolin Wang Reviewed-by: Li Jun Tested-by: Li Jun --- drivers/usb/gadget/udc/charger.c | 39 +++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) -- 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/charger.c b/drivers/usb/gadget/udc/charger.c index 7be4c76..949396f 100644 --- a/drivers/usb/gadget/udc/charger.c +++ b/drivers/usb/gadget/udc/charger.c @@ -568,6 +568,30 @@ usb_charger_plug_by_extcon(struct notifier_block *nb, int usb_charger_plug_by_gadget(struct usb_gadget *gadget, unsigned long state) { + struct usb_charger *uchger = gadget->charger; + enum usb_charger_state uchger_state; + + if (WARN(!uchger, "charger can not be NULL")) + return -EINVAL; + + /* + * Report event to power to setting the current limitation + * for this usb charger when one usb charger state is changed + * with detecting by usb gadget state. + */ + if (uchger->old_gadget_state != state) { + uchger->old_gadget_state = state; + + if (state >= USB_STATE_ATTACHED) + uchger_state = USB_CHARGER_PRESENT; + else if (state == USB_STATE_NOTATTACHED) + uchger_state = USB_CHARGER_REMOVE; + else + uchger_state = USB_CHARGER_DEFAULT; + + usb_charger_notify_others(uchger, uchger_state); + } + return 0; } EXPORT_SYMBOL_GPL(usb_charger_plug_by_gadget); @@ -724,6 +748,7 @@ int usb_charger_init(struct usb_gadget *ugadget) /* register a notifier on a usb gadget device */ uchger->gadget = ugadget; + ugadget->charger = uchger; uchger->old_gadget_state = USB_STATE_NOTATTACHED; /* register a new usb charger */ @@ -744,7 +769,19 @@ fail: int usb_charger_exit(struct usb_gadget *ugadget) { - return 0; + struct usb_charger *uchger = ugadget->charger; + + if (WARN(!uchger, "charger can not be NULL")) + return -EINVAL; + + if (uchger->extcon_dev) + extcon_unregister_notifier(uchger->extcon_dev, + EXTCON_USB, + &uchger->extcon_nb.nb); + + ida_simple_remove(&usb_charger_ida, uchger->id); + + return usb_charger_unregister(uchger); } static int __init usb_charger_class_init(void)