From patchwork Fri Apr 1 07:21:51 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: 64829 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp577461lbc; Fri, 1 Apr 2016 00:23:17 -0700 (PDT) X-Received: by 10.98.10.147 with SMTP id 19mr28564622pfk.87.1459495396216; Fri, 01 Apr 2016 00:23:16 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yx1si19542982pab.52.2016.04.01.00.23.15; Fri, 01 Apr 2016 00:23:16 -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 S932304AbcDAHXI (ORCPT + 13 others); Fri, 1 Apr 2016 03:23:08 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:33393 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758466AbcDAHXG (ORCPT ); Fri, 1 Apr 2016 03:23:06 -0400 Received: by mail-pa0-f43.google.com with SMTP id zm5so84724444pac.0 for ; Fri, 01 Apr 2016 00:23:06 -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=wCXvwE55JKcBKkPzScdMMne70sp3AXQkOsdhVUgRQ0s=; b=Bnq71KGqJIa86zJ4wQ1a1nPqPr/Oxpp3Er/RXML9NTDGTnCAoT4DbhgCHZL50Yvi17 QPJViFPXbbnwIeAwjAk9UwkW8zezf7aO9ZcN4BZc0oX+p/d17C27W5HFmh0Bs813ylqF MzQ+yUso7OwrrVxU6T9tplSvniBMN+CdkEoek= 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=wCXvwE55JKcBKkPzScdMMne70sp3AXQkOsdhVUgRQ0s=; b=RRTHlSWbV+IaTXUg0OVuQUJN8jpJb8ZKrktYstaBqxnzPbEbR4ra4kdbgNZHIYqaU6 x5AnzK4Tu+sShZ5pca208gfyq78lxXWpAzNES8lbMB2JNXpb8l1gQVfVlbPBu+nymZcV OurQJhEzfY3fWqWEHjibK7QAowodpQCVGst5tVSUY8cwPROsFR7H3uaY3+dRvBnm17bW ufPmDqs8vs6qMLZU4eu+JCUvc4Fjpi1D6S0v2BaNIoB8qzOugXFfo2/iy6EXOPCyPzw3 1hD89V75p/P3KyDHwxFhqgo/sG+AdGS845vcziVr/Is7Tui2gM+FbiAx/r3cyaDppY2/ cveg== X-Gm-Message-State: AD7BkJJwc8MXe7HKbTmMq4O3goE9nZNy35SOZdbotHNJ1qOwgRyrkb6sz7z1Z01Ndxe5l//b X-Received: by 10.66.160.7 with SMTP id xg7mr28168530pab.10.1459495385813; Fri, 01 Apr 2016 00:23:05 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id u2sm18129493pfi.26.2016.04.01.00.23.00 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Apr 2016 00:23:05 -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 v9 3/4] gadget: Integrate with the usb gadget supporting for usb charger Date: Fri, 1 Apr 2016 15:21:51 +0800 Message-Id: <3d6c7d06725405e48281679de008b06f7550e640.1459494744.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 should get the type by the 'get_charger_type' callback which is implemented by the usb gadget operations, and get the usb charger pointer from struct 'usb_gadget'. Signed-off-by: Baolin Wang --- drivers/usb/gadget/udc/charger.c | 44 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) -- 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 251f42b..73f0531 100644 --- a/drivers/usb/gadget/udc/charger.c +++ b/drivers/usb/gadget/udc/charger.c @@ -272,7 +272,10 @@ usb_charger_get_type_by_others(struct usb_charger *uchger) if (uchger->type != UNKNOWN_TYPE) return uchger->type; - if (uchger->psy) { + if (uchger->gadget->ops && uchger->gadget->ops->get_charger_type) { + uchger->type = + uchger->gadget->ops->get_charger_type(uchger->gadget); + } else if (uchger->psy) { union power_supply_propval val; power_supply_get_property(uchger->psy, @@ -554,6 +557,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); @@ -712,6 +739,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 */ @@ -732,7 +760,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)