From patchwork Thu Apr 7 11:48:45 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: 65294 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp26313lbl; Thu, 7 Apr 2016 04:50:38 -0700 (PDT) X-Received: by 10.66.27.208 with SMTP id v16mr891478pag.35.1460029838118; Thu, 07 Apr 2016 04:50:38 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o86si432527pfi.217.2016.04.07.04.50.37; Thu, 07 Apr 2016 04:50:38 -0700 (PDT) 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; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756119AbcDGLuS (ORCPT + 29 others); Thu, 7 Apr 2016 07:50:18 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:33714 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756096AbcDGLuP (ORCPT ); Thu, 7 Apr 2016 07:50:15 -0400 Received: by mail-pa0-f48.google.com with SMTP id zm5so53757443pac.0 for ; Thu, 07 Apr 2016 04:50:15 -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=uLD3r8HhsSyq+Q/Zw+NhvinDhdzLIP5bc+dmLxs/w/U=; b=I5cPo+z4SwBrRNRT4yNZ03nhtMge2vxtbS9ZgNYxqNA0NDvCTE2Vw4vmkSLNAMkocQ n2hdpHEPUk54h1W8Btsk6saLTv7DJHH7ZbR0gPA0DXTFigvnIbN/1aEPruEkIs/YBryF nzNywrEVcrFrvgbZS78obdv2iEIy0RWBt0S40= 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=uLD3r8HhsSyq+Q/Zw+NhvinDhdzLIP5bc+dmLxs/w/U=; b=MlUJyoI1hyZi3de0okvjd0d+48Nzhacwimb+kyCMddyKeyMPUxy9FIDzC4qPHDsW5o bxhTGtZGQcrHnl7D8+EhxVivSQDHe3O5Q3afsg9ceWYbQNkOZ7mLcl7nN+uJCdzvae0n zEmGWrX+onsBbZvOHgGtj4jL+oElpsnCHFgNxpxYiOMzFta04nYv86jCu7R0uvwd+wPP JK//EnVvWk+LGexjENXmwA+lfP1w4I7zmc2bB6+tE02RXWrwYnXny0WcLCyStpS48+X2 rRgDV6q+jKqoxuFndOKIzu9996IbyJkGjLg4F8s1mM2n/Ccpi+OX1XHBPUWfM7CYX19V qpww== X-Gm-Message-State: AD7BkJIPVCjWp6TBfcjnHEuDR0RXGYLxIpTNoVeDnmccQffegfgXqlKLUo2Nxh/vH6R+UA+x X-Received: by 10.66.194.227 with SMTP id hz3mr4245162pac.85.1460029810165; Thu, 07 Apr 2016 04:50:10 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id c4sm11776435pat.19.2016.04.07.04.50.05 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Apr 2016 04:50:09 -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 v10 3/4] gadget: Integrate with the usb gadget supporting for usb charger Date: Thu, 7 Apr 2016 19:48:45 +0800 Message-Id: <8756ede40a4ffcdfe7ec97703186d42bf8a491ca.1460029375.git.baolin.wang@linaro.org> 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 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 diff --git a/drivers/usb/gadget/udc/charger.c b/drivers/usb/gadget/udc/charger.c index e24cb0a..ee711cd 100644 --- a/drivers/usb/gadget/udc/charger.c +++ b/drivers/usb/gadget/udc/charger.c @@ -527,6 +527,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); @@ -683,6 +707,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 = ugadget->state; /* register a new usb charger */ @@ -703,7 +728,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)