From patchwork Fri May 20 08:38:11 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: 68225 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp3647792qge; Fri, 20 May 2016 01:39:22 -0700 (PDT) X-Received: by 10.66.21.102 with SMTP id u6mr2940037pae.118.1463733560819; Fri, 20 May 2016 01:39:20 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si26461193pfb.137.2016.05.20.01.39.20; Fri, 20 May 2016 01:39:20 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933367AbcETIjQ (ORCPT + 14 others); Fri, 20 May 2016 04:39:16 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:35736 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932900AbcETIjM (ORCPT ); Fri, 20 May 2016 04:39:12 -0400 Received: by mail-pf0-f182.google.com with SMTP id b66so18455588pfb.2 for ; Fri, 20 May 2016 01:39:11 -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=tLS/Q+o2jDr+s5sEFr3o6iAGZOI5XDMN45OoRRWmowY=; b=UN5harw/RFj+zn+kPYCkUFWsgc9PWkD7lrW4oDMkoudhNbxZZIO4Tt3NXD07s2aBHv HT9CllXDZ+5FhmpG/VYwUPraCljjaCd3enoDMUd8ZzLPyFc0kXMtoyE8sR5JJDJDKMS6 gw6L8avTOgRRqiRvJHmQZ2W93AnPnj592Wxqc= 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=tLS/Q+o2jDr+s5sEFr3o6iAGZOI5XDMN45OoRRWmowY=; b=eqqDvE6Qz1mpuM346O42xors3M+PytL3oWrcgj/lWHwPGL9ae13lrVY5At7QD8mtiF uw+26ZughHcCWhD5iyNBwuxlm47Vz1TgALcNd5ySWSHbJaFDuA9e7+yJfJQwKzVBKZH1 huJt7TedxYhJk/ItbweleMnwHLbgkrFo3NOQRYu8BQ10NXy2snb948H9Zmo7NnH5YAED 5G7ykoMJFw5QHGyaZKVh4hAZTwpBxu3yoRthuKvH9dYyFKcF1dClK4qqyhQ8sEhjwa/o MY0OEMVQX5FakK1hVB3TwIfC8dxeYArJdx4XdYj88ORH5zn6pzsIQbbxmXid9oA0r/nw y1JQ== X-Gm-Message-State: AOPr4FXF1A6nW/jqCNYLLu0XXy+gKJlbsNWMuSeG8OyiAF0k5yvUDeDQDA9bsd7hVtHj+tR/ X-Received: by 10.98.38.130 with SMTP id m124mr2994314pfm.14.1463733551317; Fri, 20 May 2016 01:39:11 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id a64sm25310939pfa.6.2016.05.20.01.39.05 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 May 2016 01:39:10 -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, m.szyprowski@samsung.com, ruslan.bilovol@gmail.com, 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 v11 3/4] gadget: Integrate with the usb gadget supporting for usb charger Date: Fri, 20 May 2016 16:38:11 +0800 Message-Id: <3650ebe1e7ed4c93e81ca28ce409d080980b59d4.1463732873.git.baolin.wang@linaro.org> 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 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 --- 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-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/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)