From patchwork Wed Mar 16 11:46:07 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: 63923 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1266716lbc; Wed, 16 Mar 2016 04:47:10 -0700 (PDT) X-Received: by 10.66.244.15 with SMTP id xc15mr5064343pac.97.1458128823950; Wed, 16 Mar 2016 04:47:03 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qd3si4759513pab.208.2016.03.16.04.47.03; Wed, 16 Mar 2016 04:47:03 -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; 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966533AbcCPLq7 (ORCPT + 4 others); Wed, 16 Mar 2016 07:46:59 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:35618 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966512AbcCPLq5 (ORCPT ); Wed, 16 Mar 2016 07:46:57 -0400 Received: by mail-pf0-f177.google.com with SMTP id n5so72324223pfn.2 for ; Wed, 16 Mar 2016 04:46: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=tZ6kYQOyqlcLY41KMvC+2wJ1fHYUkJy3WRF2sGhos0k=; b=YEA8uxzIZbBrrO83ZUyvSsfhVtiaD/UflemHgS0fuzBRY48LgBdJUomIfmJPCfU+l4 fhGBPDX/h46NfHn5KfuKGtIXhIFYjrFudG0Chew4WZ3FQmnsNyOIt0vea+9yln5uDbul Pi9+bGCQ0kmlRcI3rK0kfnbH3q39m8E5dgIFE= 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=tZ6kYQOyqlcLY41KMvC+2wJ1fHYUkJy3WRF2sGhos0k=; b=N609VZJaTocQVLQ+Zz2istH+JiXnFn7iWk1UZ7tbQIvcPO0oZX+W3LX8Edr1z1POA2 FRHieMYx8MABd8WPJTqt6KtM19j/K+DeKh8PibG3yoe/K6XMNHVoraG1+Ct+Udz2b85g V3E4Cv0YovL1LYPcdAbFT6QdUwA46o5yhUQ5MmamYWoh93cAb+8axNOeIZdygth4WJeK OCGo/0v4Y23dajJ6TVPr4mpzClBYbsuAmSWdVRB2ZaueqkJEa9X71jGSWEchCOGTwQ8B ZL2Vk5eXKUg9XecMY8vuTgIDiIvc3m2yxTryBl+sWuKH5WHViMWhVwqJVQORLMzcxwic 3q0A== X-Gm-Message-State: AD7BkJJsyAUrYxLcjMa1a+j/rezOZmBuoLoCnAf1JAPIolLIQ4+9zDnkrYO83F0uK9vOFhCG X-Received: by 10.98.16.4 with SMTP id y4mr5101745pfi.45.1458128816985; Wed, 16 Mar 2016 04:46:56 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id 16sm5105990pfk.28.2016.03.16.04.46.52 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Mar 2016 04:46:56 -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 v7 3/4] gadget: Integrate with the usb gadget supporting for usb charger Date: Wed, 16 Mar 2016 19:46:07 +0800 Message-Id: <88abb8df5b135975c5ffff1fa5437c4d82f48514.1458128215.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 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/charger.c | 43 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) -- 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/charger.c b/drivers/usb/gadget/charger.c index 82a9973..76e1a6f 100644 --- a/drivers/usb/gadget/charger.c +++ b/drivers/usb/gadget/charger.c @@ -272,7 +272,11 @@ EXPORT_SYMBOL_GPL(usb_charger_unregister_notify); enum usb_charger_type usb_charger_detect_type(struct usb_charger *uchger) { - if (uchger->psy) { + if (uchger->gadget && 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, @@ -479,6 +483,29 @@ 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 (!uchger) + 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); @@ -635,6 +662,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 */ @@ -655,7 +683,18 @@ fail: int usb_charger_exit(struct usb_gadget *ugadget) { - return 0; + struct usb_charger *uchger = ugadget->charger; + + if (!uchger) + 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_sysfs_init(void)