From patchwork Fri Aug 14 09:47:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 52415 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by patches.linaro.org (Postfix) with ESMTPS id 3373F2031F for ; Fri, 14 Aug 2015 09:49:36 +0000 (UTC) Received: by labd1 with SMTP id d1sf26155423lab.0 for ; Fri, 14 Aug 2015 02:49:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=TG1oGAETWnXuWgwXgYSUHnfbVFmvZG+4pQVeCDQSSXQ=; b=MUSV3gZRS0Ve1XxFvXDJn10K5iVF7zgtc6gBdH2m3vNajk4DMYg8nevcrfwbi1eksE dvn5EEoqIp+l5504Q/xCEnBrY2P0LfKehGux6IkyIvSC3NeNadkwAZ+m2TpPQsdqEttX YiKO8J0PiB8MkWN12E13HlFjo+E1E3DcAGZ0wp7c5N2vbaosZmaytZCOGfNRGlgNSyf+ ADnxixLw6elSPdghwkBvg5C8oUrMXR0ggDA25OlyUiwpRzentSkzZW0T+RYNp2BUcFyI uxsGz2C6GsELChhzZV5DUEu1U86r5UTq6l7vmxn5vTGukIzl1ZCKrcBL/8nplMKpQ3b3 ghow== X-Gm-Message-State: ALoCoQkHCx4tKjhg4YM50cuOpnCBgFp3PhqdNsE4Nvg+pQX/POKTCPuxBSIt2ro513qdZsz7YrHe X-Received: by 10.152.9.99 with SMTP id y3mr12640140laa.10.1439545775192; Fri, 14 Aug 2015 02:49:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.146 with SMTP id j18ls330377laa.44.gmail; Fri, 14 Aug 2015 02:49:34 -0700 (PDT) X-Received: by 10.112.210.6 with SMTP id mq6mr42662542lbc.83.1439545774855; Fri, 14 Aug 2015 02:49:34 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id kg7si5593999lbc.176.2015.08.14.02.49.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Aug 2015 02:49:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbbsx3 with SMTP id sx3so42290373lbb.0 for ; Fri, 14 Aug 2015 02:49:34 -0700 (PDT) X-Received: by 10.112.176.228 with SMTP id cl4mr42858883lbc.106.1439545774729; Fri, 14 Aug 2015 02:49:34 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp1489904lba; Fri, 14 Aug 2015 02:49:33 -0700 (PDT) X-Received: by 10.70.24.33 with SMTP id r1mr85178077pdf.20.1439545773194; Fri, 14 Aug 2015 02:49:33 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10si8153521pdp.182.2015.08.14.02.49.32; Fri, 14 Aug 2015 02:49:33 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754914AbbHNJtb (ORCPT + 28 others); Fri, 14 Aug 2015 05:49:31 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:33972 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754891AbbHNJt3 (ORCPT ); Fri, 14 Aug 2015 05:49:29 -0400 Received: by paccq16 with SMTP id cq16so13403811pac.1 for ; Fri, 14 Aug 2015 02:49:28 -0700 (PDT) X-Received: by 10.68.182.3 with SMTP id ea3mr86150035pbc.126.1439545768580; Fri, 14 Aug 2015 02:49:28 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id fs13sm5424998pdb.29.2015.08.14.02.49.20 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Aug 2015 02:49:27 -0700 (PDT) From: Baolin Wang To: balbi@ti.com Cc: broonie@kernel.org, linus.walleij@linaro.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org, gregkh@linuxfoundation.org, peter.chen@freescale.com, sojka@merica.cz, stern@rowland.harvard.edu, r.baldyga@samsung.com, yoshihiro.shimoda.uh@renesas.com, linux-usb@vger.kernel.org, device-mainlining@lists.linuxfoundation.org, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org, sameo@linux.intel.com, lee.jones@linaro.org, patches@opensource.wolfsonmicro.com, linux-pm@vger.kernel.org Subject: [PATCH v2 1/3] gadget: Support for the usb charger framework Date: Fri, 14 Aug 2015 17:47:44 +0800 Message-Id: <33e56f632418b8e42162d5b64decb6ffc8de3e01.1439519412.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: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: baolin.wang@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The usb charger framework is based on usb gadget, and each usb gadget can be one usb charger to set the current limitation. This patch adds a notifier mechanism for usb charger to report to usb charger when the usb gadget state is changed. Also we introduce a callback 'get_charger_type' which will implemented by user for usb gadget operations to get the usb charger type. Signed-off-by: Baolin Wang --- drivers/usb/gadget/udc/udc-core.c | 38 +++++++++++++++++++++++++++++++++++++ include/linux/usb/gadget.h | 20 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index f660afb..47b231c 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -28,6 +28,7 @@ #include #include #include +#include /** * struct usb_udc - describes one usb device controller @@ -129,6 +130,32 @@ void usb_gadget_giveback_request(struct usb_ep *ep, } EXPORT_SYMBOL_GPL(usb_gadget_giveback_request); +int usb_gadget_register_notify(struct usb_gadget *gadget, + struct notifier_block *nb) +{ + int ret; + + mutex_lock(&gadget->lock); + ret = raw_notifier_chain_register(&gadget->nh, nb); + mutex_unlock(&gadget->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(usb_gadget_register_notify); + +int usb_gadget_unregister_notify(struct usb_gadget *gadget, + struct notifier_block *nb) +{ + int ret; + + mutex_lock(&gadget->lock); + ret = raw_notifier_chain_unregister(&gadget->nh, nb); + mutex_unlock(&gadget->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(usb_gadget_unregister_notify); + /* ------------------------------------------------------------------------- */ /** @@ -226,6 +253,10 @@ static void usb_gadget_state_work(struct work_struct *work) struct usb_gadget *gadget = work_to_gadget(work); struct usb_udc *udc = gadget->udc; + mutex_lock(&gadget->lock); + raw_notifier_call_chain(&gadget->nh, gadget->state, gadget); + mutex_unlock(&gadget->lock); + if (udc) sysfs_notify(&udc->dev.kobj, NULL, "state"); } @@ -364,6 +395,8 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, dev_set_name(&gadget->dev, "gadget"); INIT_WORK(&gadget->work, usb_gadget_state_work); + RAW_INIT_NOTIFIER_HEAD(&gadget->nh); + mutex_init(&gadget->lock); gadget->dev.parent = parent; #ifdef CONFIG_HAS_DMA @@ -405,6 +438,10 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, mutex_unlock(&udc_lock); + ret = usb_charger_init(gadget); + if (ret) + goto err4; + return 0; err4: @@ -481,6 +518,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget) kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); flush_work(&gadget->work); device_unregister(&udc->dev); + usb_charger_exit(gadget); device_unregister(&gadget->dev); } EXPORT_SYMBOL_GPL(usb_del_gadget_udc); diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index c14a69b..78cc862 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -537,6 +537,7 @@ struct usb_gadget_ops { struct usb_ep *(*match_ep)(struct usb_gadget *, struct usb_endpoint_descriptor *, struct usb_ss_ep_comp_descriptor *); + enum usb_charger_type (*get_charger_type)(struct usb_gadget *); }; /** @@ -609,6 +610,9 @@ struct usb_gadget { unsigned out_epnum; unsigned in_epnum; struct usb_otg_caps *otg_caps; + struct raw_notifier_head nh; + struct usb_charger *uchger; + struct mutex lock; unsigned sg_supported:1; unsigned is_otg:1; @@ -1183,6 +1187,22 @@ extern void usb_gadget_unmap_request(struct usb_gadget *gadget, /*-------------------------------------------------------------------------*/ +/** + * Register a notifiee to get notified by any attach status changes from + * the usb gadget + */ +int usb_gadget_register_notify(struct usb_gadget *gadget, + struct notifier_block *nb); + +/*-------------------------------------------------------------------------*/ + + +/* Unregister a notifiee from the usb gadget */ +int usb_gadget_unregister_notify(struct usb_gadget *gadget, + struct notifier_block *nb); + +/*-------------------------------------------------------------------------*/ + /* utility to set gadget state properly */ extern void usb_gadget_set_state(struct usb_gadget *gadget,