From patchwork Thu Sep 24 17:39:23 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: 54122 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 0841A22DC2 for ; Thu, 24 Sep 2015 17:40:23 +0000 (UTC) Received: by wisv5 with SMTP id v5sf45100402wis.0 for ; Thu, 24 Sep 2015 10:40:22 -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=caQh+QvDPSAPS6SdRejUtHMWdgPPkxPx5tMI27AxCkk=; b=T1vUmpvHbJQXR6U5ZDqg9NMnLhyqKgL2RPY/hZduBZ9Et6Zh2ipCSM5WzDlPObol25 K5hywzjZWXxD3xxwm8bJWZeGmUkjWtRxvyLHcBzlTCULocOm8cV4KXbG2nY+qRaN0nLK uXiNYpjYQYIckLiRY+P2Z1IsAFzpOX+OfC0+Qytb3sF1O3hfdSwDaQIiEp4sIRrrGoWj Jts84omoBc/hM1CClnr8NrcFSlEEIoHnUrvFI5wDZFgzeSsMLOsV262XR3vIQIQie+D1 Hl4qXa6rqIJGQkJIvD5Hv/fAXnkxJQ+GZx05bm9WbYc47K0eb1HMCmqIlyGINZMKRQdN dDaw== X-Gm-Message-State: ALoCoQm4VovuDN+qELTzT3kKLluZD3dkCwiQFwMR96kC3lNTJo17RJKSxBKg8OmEmIgaLOnhBTiq X-Received: by 10.112.78.101 with SMTP id a5mr155553lbx.9.1443116422360; Thu, 24 Sep 2015 10:40:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.3.138 with SMTP id c10ls126280lac.46.gmail; Thu, 24 Sep 2015 10:40:22 -0700 (PDT) X-Received: by 10.112.51.142 with SMTP id k14mr239450lbo.76.1443116422085; Thu, 24 Sep 2015 10:40:22 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id s3si7048627lae.143.2015.09.24.10.40.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Sep 2015 10:40:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lahh2 with SMTP id h2so70988827lah.0 for ; Thu, 24 Sep 2015 10:40:22 -0700 (PDT) X-Received: by 10.25.40.130 with SMTP id o124mr168658lfo.41.1443116421911; Thu, 24 Sep 2015 10:40:21 -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.59.35 with SMTP id w3csp471339lbq; Thu, 24 Sep 2015 10:40:21 -0700 (PDT) X-Received: by 10.68.166.196 with SMTP id zi4mr1038729pbb.83.1443116420878; Thu, 24 Sep 2015 10:40:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mp9si19784523pbc.76.2015.09.24.10.40.20; Thu, 24 Sep 2015 10:40:20 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757602AbbIXRkQ (ORCPT + 4 others); Thu, 24 Sep 2015 13:40:16 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:35202 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757336AbbIXRkN (ORCPT ); Thu, 24 Sep 2015 13:40:13 -0400 Received: by pacfv12 with SMTP id fv12so80245126pac.2 for ; Thu, 24 Sep 2015 10:40:12 -0700 (PDT) X-Received: by 10.66.251.136 with SMTP id zk8mr1037946pac.143.1443116412851; Thu, 24 Sep 2015 10:40:12 -0700 (PDT) Received: from ubuntu.localdomain ([70.35.39.2]) by smtp.gmail.com with ESMTPSA id c16sm14716394pbu.37.2015.09.24.10.40.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Sep 2015 10:40:12 -0700 (PDT) From: Baolin Wang To: balbi@ti.com, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org Cc: gregkh@linuxfoundation.org, peter.chen@freescale.com, stern@rowland.harvard.edu, r.baldyga@samsung.com, sojka@merica.cz, yoshihiro.shimoda.uh@renesas.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, sameo@linux.intel.com, lee.jones@linaro.org, ckeepax@opensource.wolfsonmicro.com, broonie@kernel.org, patches@opensource.wolfsonmicro.com, linux-pm@vger.kernel.org, device-mainlining@lists.linuxfoundation.org, baolin.wang@linaro.org Subject: [PATCH v4 1/5] gadget: Introduce the notifier functions Date: Thu, 24 Sep 2015 10:39:23 -0700 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@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.215.48 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,