From patchwork Thu Jun 23 08:57:59 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: 70745 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp321388qgy; Thu, 23 Jun 2016 01:59:09 -0700 (PDT) X-Received: by 10.98.15.68 with SMTP id x65mr41526115pfi.66.1466672346719; Thu, 23 Jun 2016 01:59:06 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4si5809739pac.21.2016.06.23.01.59.06; Thu, 23 Jun 2016 01:59:06 -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 S1751272AbcFWI6v (ORCPT + 5 others); Thu, 23 Jun 2016 04:58:51 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:34547 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752015AbcFWI6s (ORCPT ); Thu, 23 Jun 2016 04:58:48 -0400 Received: by mail-pf0-f171.google.com with SMTP id h14so26888765pfe.1 for ; Thu, 23 Jun 2016 01:58:48 -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=vAq6AbFL2XqXB9qmQscyOKVK+SdxId0P0TqGFfc7+Kg=; b=YzElt9BIDVb12G0F7u1FjyO8+IrLQ47XPVFrbPPCHvI6NtNurfPqDh2RQLQZ0i95H8 AcCh+jVBWigsVFWSf0KhuWvWiEk1ZYxAiF2c9iSc7vKaObzTrOj9OObKrYOxezXFhLbh Jzn0VlWd1ED2I9uJLmvhHbHkLjjydXVyzsTy8= 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=vAq6AbFL2XqXB9qmQscyOKVK+SdxId0P0TqGFfc7+Kg=; b=GJfwXuptDKBGjhUtaGMGuZxS+10sYFiRBTPEkswmSpuKPuJsw1or8/FITybEwd4J/R dEwqr8S3Y1QKun/clSsP4BcSJJLyItNbIMLK47nqiqfu4Ppt/Mv9vqnmkEjxoRkwrUdO b05IJfrXtVPE3/E7T27/D6gr4L/K+naqhHHNkCuYqECbgeFStsRmgWC8VIDrenAWbfWB eSc9L3pfLy6satNPlhilVql26xNLvzwcnXgpG4o24104/vTib0+POmWuhv7Iats39K7W eIGHa+oC8JUtDmoP47emFP2Y5unnIVWZZR6/n0NEXNPo5FJ7puYEb+VXtJKRkoLLBu8e NRYw== X-Gm-Message-State: ALyK8tKr+lwRpxO0+bNGC89bHG9f4x4cKGk87VrDQD9Ja2qCnMOy2w5piaP5e/RRrk7TFX7Z X-Received: by 10.98.59.150 with SMTP id w22mr40946108pfj.4.1466672327635; Thu, 23 Jun 2016 01:58:47 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id bt5sm5494315pac.47.2016.06.23.01.58.42 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Jun 2016 01:58:47 -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 v13 3/4] usb: gadget: Integrate with the usb gadget supporting for usb charger Date: Thu, 23 Jun 2016 16:57:59 +0800 Message-Id: <004088a5c0158c479d1207e45ddc364a4a26a0d9.1466671672.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, usb_charger_exit() function and dev_to_uchger() 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 | 62 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 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/udc/charger.c b/drivers/usb/gadget/udc/charger.c index a0dd0cf..e04273c 100644 --- a/drivers/usb/gadget/udc/charger.c +++ b/drivers/usb/gadget/udc/charger.c @@ -35,7 +35,9 @@ static unsigned int usb_charger_get_cur_limit(struct usb_charger *uchger); static struct usb_charger *dev_to_uchger(struct device *dev) { - return NULL; + struct usb_gadget *gadget = container_of(dev, struct usb_gadget, dev); + + return gadget->charger; } /* @@ -548,11 +550,55 @@ 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); /* + * usb_charger_unregister() - Unregister a usb charger. + * @uchger - the usb charger to be unregistered. + */ +static int usb_charger_unregister(struct usb_charger *uchger) +{ + if (WARN(!uchger, "charger can not be NULL")) + return -EINVAL; + + ida_simple_remove(&usb_charger_ida, uchger->id); + sysfs_remove_groups(&uchger->gadget->dev.kobj, usb_charger_groups); + + mutex_lock(&charger_lock); + list_del(&uchger->list); + mutex_unlock(&charger_lock); + + kfree(uchger); + return 0; +} + +/* * usb_charger_register() - Register a new usb charger. * @uchger - the new usb charger instance. */ @@ -635,6 +681,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 */ @@ -657,7 +704,18 @@ 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; + + ugadget->charger = NULL; + if (uchger->extcon_dev) + extcon_unregister_notifier(uchger->extcon_dev, + EXTCON_USB, + &uchger->extcon_nb.nb); + + return usb_charger_unregister(uchger); } MODULE_AUTHOR("Baolin Wang ");