From patchwork Fri Nov 6 11:35:10 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: 56108 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp953013lbr; Fri, 6 Nov 2015 03:36:16 -0800 (PST) X-Received: by 10.68.238.41 with SMTP id vh9mr17161847pbc.147.1446809776852; Fri, 06 Nov 2015 03:36:16 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wu1si4054305pbc.138.2015.11.06.03.36.16; Fri, 06 Nov 2015 03:36:16 -0800 (PST) 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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033222AbbKFLgN (ORCPT + 28 others); Fri, 6 Nov 2015 06:36:13 -0500 Received: from mail-pa0-f52.google.com ([209.85.220.52]:34842 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033156AbbKFLgH (ORCPT ); Fri, 6 Nov 2015 06:36:07 -0500 Received: by pasz6 with SMTP id z6so124994556pas.2 for ; Fri, 06 Nov 2015 03:36:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=8g9I25J6fj3uKx/KDzPoglTEIb1jMAZtT7ki6X2L8E0=; b=swYDycejydVCx3E6GdOOUrckzishahGinW/0yKbTaTydp8CEKE+o1hqmt7q3o4EcZ7 hYnkljv8HrD3f/b8fOtGAUP+c3ykVFNed8oQvdjuNHa2bArYiX5tqY6WSg0wW27k3Q16 akJfqbAM81MXlKE6zaIOUwKiZnCFf5LLhB8KjdQ1oJgP5ub7ECNZlrryPsfKZIJAgnA6 7uMDO609H3iPocpOmDtPlkK/9tiOgouQUzmqbXnaxLXooZuYEKwN5b198mLjN9rSxM4u XQ9MbzGeyWg/Q87kY/tEHjLwIZFqdh96iAWWGSUeP4/4Fhy/J85A9Q1Ld5JbCOOtVIom Fqvw== 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=8g9I25J6fj3uKx/KDzPoglTEIb1jMAZtT7ki6X2L8E0=; b=KB1wVl28FlWhGmZ/k5Ej1cCRd6qCyjlWeUkLU3gS/9uQWA2ZOl4sa5HyNVH14ZKH4y NeEUZCWb2G5/RglSdcMGH62ZYrcWgqXvNReNdT8/fI/EVOAKrB00Bs3o9+Uk61vAHI8c M5kVrg2hlsdHVg3kgk4kJuqXNohhTATKzztaA9yDmL+k6OCC13Pxg+k7fC2r+ITRraPS P1QCIteqTXuB9KCySnC/Ngyf46hwMqVlv8HScK1if7wa1bTBmzNS/Is2qVoq37FkIUlK pUGzdf0NTF2Fet3Xhd6wnrQ3KplPAImm/kLtTkcejrEim7696mxzw7uQLi/tuJ1CaJrp Dyrw== X-Gm-Message-State: ALoCoQlgqUnsEUCEbGljMPg4ZTrRy0aj4xAkb6AWKzoL2VB3O8zv76pFocGZTTrp+FSSkchHVnA/ X-Received: by 10.68.228.228 with SMTP id sl4mr16913537pbc.51.1446809767091; Fri, 06 Nov 2015 03:36:07 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id xm4sm13644680pab.27.2015.11.06.03.36.01 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Nov 2015 03:36:06 -0800 (PST) From: Baolin Wang To: balbi@ti.com, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org Cc: broonie@kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org, gregkh@linuxfoundation.org, peter.chen@freescale.com, stern@rowland.harvard.edu, r.baldyga@samsung.com, yoshihiro.shimoda.uh@renesas.com, linux-usb@vger.kernel.org, device-mainlining@lists.linuxfoundation.org, sameo@linux.intel.com, lee.jones@linaro.org, ckeepax@opensource.wolfsonmicro.com, patches@opensource.wolfsonmicro.com, linux-pm@vger.kernel.org Subject: [PATCH v5 1/5] gadget: Introduce the notifier functions Date: Fri, 6 Nov 2015 19:35:10 +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: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(+) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ 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,