Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1216092yba; Thu, 4 Apr 2019 06:34:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGF6s62qsUzimqIsYh39E4GoLdZno6cLiojKErX9b3cVCZpjfik7KoPDxHiUT2EBzQxKx6 X-Received: by 2002:a62:204b:: with SMTP id g72mr5831239pfg.51.1554384856467; Thu, 04 Apr 2019 06:34:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554384856; cv=none; d=google.com; s=arc-20160816; b=eTJqECupyScu4hlDInwiu7XUXLd1MVlkOfEnNvzRUHyZt0negoNVVNMiENA9oMf6mt 7c131HruxYS+JqTFI2bhQDPp9frvmK8EGT+x35Fn3nSXYWOTP/uhoOdgVYUH22LbCcKl 3c6+rw56HgCHShCbDYxNh7yQ41dnZg2X3L50YXZSwagzwgBaZNjCLQRsK2/OWCuF8ayK 357o6UcbxpkE75HzyZpNDiXRe1nspXNd644sD+jdJY2SIYlqBxpsWtW93Nb7kErI2K7P f1BSo4KHb9Jp89B2iNUpb549g6GVHn1O71wtR3IGzBxRGYZohGztIyFtLnI8+Vjp5RMe ShtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=vprKTMH0s5pzwRwDaWYeUFayMi0Dtbz/dSCWGs59qzA=; b=nEM3Xj0SOacA6+nw4mVvw7hq16gG4/iqAsykaWqzFUojsPKYU+KYHFr+V6wIXUAbRy pN7eT8eYBOU5jM4pMsC2aOlqGNa02nxY88Ib2x+9tX3i4WoF+e1w1oAYcgYnB8/cKbCV F5YqYKcWibJwdwB31AKuw2LFnJhlsR4EPsBj7cmxjW01BkavxrpJJjqbG2AfI+0zYNZT uIxzEC7xNDf3y+NERdQrIQVrESYlmXBXzmkbGAESFFvQiVKr26kHvli7xE80nbbQ5TYq kZW1ftmmX3tqFl1sjmHgnUdv8YYE8Ac/Ra7S0Ih9EfOp6Or5EDH9mxpQgRIo5BrQ7aHE 96Jw== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y14si5693731pge.547.2019.04.04.06.34.00; Thu, 04 Apr 2019 06:34:16 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729636AbfDDNdQ (ORCPT + 99 others); Thu, 4 Apr 2019 09:33:16 -0400 Received: from mga01.intel.com ([192.55.52.88]:44356 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbfDDNdP (ORCPT ); Thu, 4 Apr 2019 09:33:15 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Apr 2019 06:26:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,308,1549958400"; d="scan'208";a="161351469" Received: from kuha.fi.intel.com ([10.237.72.189]) by fmsmga001.fm.intel.com with SMTP; 04 Apr 2019 06:26:03 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Thu, 04 Apr 2019 16:26:02 +0300 Date: Thu, 4 Apr 2019 16:26:02 +0300 From: Heikki Krogerus To: Yu Chen Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, john.stultz@linaro.org, suzhuangluan@hisilicon.com, kongfei@hisilicon.com, liuyu712@hisilicon.com, wanghu17@hisilicon.com, butao@hisilicon.com, chenyao11@huawei.com, fangshengzhou@hisilicon.com, lipengcheng8@huawei.com, songxiaowei@hisilicon.com, xuyiping@hisilicon.com, xuyoujun4@huawei.com, yudongbin@hisilicon.com, zangleigang@hisilicon.com, Greg Kroah-Hartman , Hans de Goede , Andy Shevchenko Subject: Re: [PATCH v5 09/13] usb: roles: Add usb role switch notifier. Message-ID: <20190404132602.GE21319@kuha.fi.intel.com> References: <20190329041409.70138-1-chenyu56@huawei.com> <20190329041409.70138-10-chenyu56@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190329041409.70138-10-chenyu56@huawei.com> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 29, 2019 at 12:14:05PM +0800, Yu Chen wrote: > This patch adds notifier for drivers want to be informed of the usb role > switch. > > Cc: Greg Kroah-Hartman > Cc: Heikki Krogerus > Cc: Hans de Goede > Cc: Andy Shevchenko > Cc: John Stultz > Suggested-by: Heikki Krogerus > Signed-off-by: Yu Chen Reviewed-by: Heikki Krogerus > --- > v5: > * Split the patch into two patches, the first one introduces stubs for the > exiting functions, and this patch adds notifier functions. > --- > --- > drivers/usb/roles/class.c | 20 +++++++++++++++++++- > include/linux/usb/role.h | 16 ++++++++++++++++ > 2 files changed, 35 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c > index f45d8df5cfb8..e2caaa665d6e 100644 > --- a/drivers/usb/roles/class.c > +++ b/drivers/usb/roles/class.c > @@ -20,6 +20,7 @@ struct usb_role_switch { > struct device dev; > struct mutex lock; /* device lock*/ > enum usb_role role; > + struct blocking_notifier_head nh; > > /* From descriptor */ > struct device *usb2_port; > @@ -49,8 +50,10 @@ int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role) > mutex_lock(&sw->lock); > > ret = sw->set(sw->dev.parent, role); > - if (!ret) > + if (!ret) { > sw->role = role; > + blocking_notifier_call_chain(&sw->nh, role, NULL); > + } > > mutex_unlock(&sw->lock); > > @@ -58,6 +61,20 @@ int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role) > } > EXPORT_SYMBOL_GPL(usb_role_switch_set_role); > > +int usb_role_switch_register_notifier(struct usb_role_switch *sw, > + struct notifier_block *nb) > +{ > + return blocking_notifier_chain_register(&sw->nh, nb); > +} > +EXPORT_SYMBOL_GPL(usb_role_switch_register_notifier); > + > +int usb_role_switch_unregister_notifier(struct usb_role_switch *sw, > + struct notifier_block *nb) > +{ > + return blocking_notifier_chain_unregister(&sw->nh, nb); > +} > +EXPORT_SYMBOL_GPL(usb_role_switch_unregister_notifier); > + > /** > * usb_role_switch_get_role - Get the USB role for a switch > * @sw: USB role switch > @@ -271,6 +288,7 @@ usb_role_switch_register(struct device *parent, > return ERR_PTR(-ENOMEM); > > mutex_init(&sw->lock); > + BLOCKING_INIT_NOTIFIER_HEAD(&sw->nh); > > sw->allow_userspace_control = desc->allow_userspace_control; > sw->usb2_port = desc->usb2_port; > diff --git a/include/linux/usb/role.h b/include/linux/usb/role.h > index da2b9641b877..99d8b8e4fe61 100644 > --- a/include/linux/usb/role.h > +++ b/include/linux/usb/role.h > @@ -53,6 +53,10 @@ struct usb_role_switch * > usb_role_switch_register(struct device *parent, > const struct usb_role_switch_desc *desc); > void usb_role_switch_unregister(struct usb_role_switch *sw); > +int usb_role_switch_register_notifier(struct usb_role_switch *sw, > + struct notifier_block *nb); > +int usb_role_switch_unregister_notifier(struct usb_role_switch *sw, > + struct notifier_block *nb); > #else > static inline int usb_role_switch_set_role(struct usb_role_switch *sw, > enum usb_role role) > @@ -80,6 +84,18 @@ usb_role_switch_register(struct device *parent, > } > > static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { } > + > +static int usb_role_switch_register_notifier(struct usb_role_switch *sw, > + struct notifier_block *nb) > +{ > + return -ENODEV; > +} > + > +static int usb_role_switch_unregister_notifier(struct usb_role_switch *sw, > + struct notifier_block *nb) > +{ > + return -ENODEV; > +} > #endif > > #endif /* __LINUX_USB_ROLE_H */ > -- > 2.15.0-rc2 thanks, -- heikki