From patchwork Wed Aug 19 09:13: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: 52529 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 37C1A22DB1 for ; Wed, 19 Aug 2015 09:14:26 +0000 (UTC) Received: by labpx14 with SMTP id px14sf4636587lab.1 for ; Wed, 19 Aug 2015 02:14:25 -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=yZpJojTJcrIDYRqZ8YVP727jWjSecf1zMdpr5WvGe+E=; b=DOjZCK+/+GougxjZyFf3xpTFnZPS5/X9q68+pYsFRG3Oa96SNYI+0pd/j4qXPoMmi6 69+KTNgdK5Pjrg5UcCkXjiwpefo3Z5HQivbPR4mYT2EDLXRBiwFhec3AmeD6Jd0isC8Z VnyuzVG+ai4gs9/KRGIGdabm3DXd0NPZurJ2m1f4a2Qbr1CWowSnovKWnJKbX5SPPftZ OsHgX4wadNC73wg5Dg+VLHVBhhwunRci6xfJfIXfR6fUg+bQa7tQTcuUsf+evxCgPcqr UqSDkRLw3tSnqVAcxDtP8uaonLhqYkJD37u17yXtK8RmO9CYmZ4fDfMyVrb5aXI6zKQW QdOA== X-Gm-Message-State: ALoCoQlb50RcMzS09awmwEphclLYB0bhWPkBtX+ImgKPD4NopB29qHxDqdascGNc5VmBz4d0Z3Qt X-Received: by 10.112.78.101 with SMTP id a5mr2977815lbx.9.1439975665217; Wed, 19 Aug 2015 02:14:25 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.170 with SMTP id l10ls2574lah.82.gmail; Wed, 19 Aug 2015 02:14:24 -0700 (PDT) X-Received: by 10.152.44.130 with SMTP id e2mr10326457lam.14.1439975664908; Wed, 19 Aug 2015 02:14:24 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id z1si30447lbw.159.2015.08.19.02.14.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Aug 2015 02:14:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbsx3 with SMTP id sx3so119577674lbb.0 for ; Wed, 19 Aug 2015 02:14:24 -0700 (PDT) X-Received: by 10.112.125.34 with SMTP id mn2mr9345722lbb.76.1439975664467; Wed, 19 Aug 2015 02:14:24 -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.162.200 with SMTP id yc8csp233918lbb; Wed, 19 Aug 2015 02:14:23 -0700 (PDT) X-Received: by 10.66.196.15 with SMTP id ii15mr22571991pac.108.1439975662465; Wed, 19 Aug 2015 02:14:22 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ry8si116710pbb.86.2015.08.19.02.14.20; Wed, 19 Aug 2015 02:14:22 -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 S1753250AbbHSJOS (ORCPT + 28 others); Wed, 19 Aug 2015 05:14:18 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:36168 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752811AbbHSJON (ORCPT ); Wed, 19 Aug 2015 05:14:13 -0400 Received: by pawq9 with SMTP id q9so56776166paw.3 for ; Wed, 19 Aug 2015 02:14:12 -0700 (PDT) X-Received: by 10.66.231.36 with SMTP id td4mr11559674pac.33.1439975652597; Wed, 19 Aug 2015 02:14:12 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id w6sm91903pdn.46.2015.08.19.02.14.07 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Aug 2015 02:14:12 -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 v4 1/5] gadget: Introduce the notifier functions Date: Wed, 19 Aug 2015 17:13:44 +0800 Message-Id: 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.170 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. The usb charger need to be notified the state changing of usb gadget to confirm the usb charger state. Thus this patch adds a notifier mechanism for usb gadget to report a event to usb charger when the usb gadget state is changed. Signed-off-by: Baolin Wang --- drivers/usb/gadget/udc/udc-core.c | 32 ++++++++++++++++++++++++++++++++ include/linux/usb/gadget.h | 18 ++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index f660afb..4238fc3 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -129,6 +129,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 +252,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 +394,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 diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index c14a69b..755e8bc 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -609,6 +609,8 @@ struct usb_gadget { unsigned out_epnum; unsigned in_epnum; struct usb_otg_caps *otg_caps; + struct raw_notifier_head nh; + struct mutex lock; unsigned sg_supported:1; unsigned is_otg:1; @@ -1183,6 +1185,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,