From: Prashant Malani <pmalani@chromium.org>
To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Cc: wonchung@google.com, bleung@chromium.org,
heikki.krogerus@linux.intel.com,
"Prashant Malani" <pmalani@chromium.org>,
"Alan Stern" <stern@rowland.harvard.edu>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Christian König" <christian.koenig@amd.com>,
"Chunfeng Yun" <chunfeng.yun@mediatek.com>,
"Daniel Vetter" <daniel.vetter@ffwll.ch>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
"Rajat Jain" <rajatja@google.com>,
"Rikard Falkeborn" <rikard.falkeborn@gmail.com>,
"Thomas Zimmermann" <tzimmermann@suse.de>
Subject: [PATCH 1/4] usb: typec: Add port registration notifier
Date: Wed, 24 Nov 2021 15:10:08 -0800 [thread overview]
Message-ID: <20211124231028.696982-2-pmalani@chromium.org> (raw)
In-Reply-To: <20211124231028.696982-1-pmalani@chromium.org>
Introduce a blocking notifier to be called when a new Type C port gets
registered with the connector class framework.
Signed-off-by: Prashant Malani <pmalani@chromium.org>
---
NOTE: typec_port_registration_register_notify() is a bit long,
so please let me know if you have any shorter suggestions for naming
this function.
drivers/usb/typec/class.c | 30 ++++++++++++++++++++++++++++++
include/linux/usb/typec.h | 13 +++++++++++++
2 files changed, 43 insertions(+)
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index aeef453aa658..14b82109b0f5 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -16,6 +16,8 @@
#include "bus.h"
#include "class.h"
+static BLOCKING_NOTIFIER_HEAD(typec_port_registration_notifier);
+
static DEFINE_IDA(typec_index_ida);
struct class typec_class = {
@@ -1979,6 +1981,32 @@ void typec_port_register_altmodes(struct typec_port *port,
}
EXPORT_SYMBOL_GPL(typec_port_register_altmodes);
+/**
+ * typec_port_registration_register_notify - Register a notifier for Type C port registration.
+ * @nb: notifier block to signal
+ *
+ * This function allows callers to get a notification when a Type C port is registered with
+ * the connector class.
+ */
+int typec_port_registration_register_notify(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_register(&typec_port_registration_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(typec_port_registration_register_notify);
+
+/**
+ * typec_port_registration_unregister_notify - Unregister a notifier for Type C port registration.
+ * @nb: notifier block to unregister
+ *
+ * This function allows callers to unregister notifiers which were previously registered using
+ * typec_port_registration_register_notify().
+ */
+int typec_port_registration_unregister_notify(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_unregister(&typec_port_registration_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(typec_port_registration_unregister_notify);
+
/**
* typec_register_port - Register a USB Type-C Port
* @parent: Parent device
@@ -2086,6 +2114,8 @@ struct typec_port *typec_register_port(struct device *parent,
if (ret)
dev_warn(&port->dev, "failed to create symlinks (%d)\n", ret);
+ blocking_notifier_call_chain(&typec_port_registration_notifier, 0, port);
+
return port;
}
EXPORT_SYMBOL_GPL(typec_register_port);
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index e2e44bb1dad8..398317835f24 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -3,6 +3,7 @@
#ifndef __LINUX_USB_TYPEC_H
#define __LINUX_USB_TYPEC_H
+#include <linux/notifier.h>
#include <linux/types.h>
/* USB Type-C Specification releases */
@@ -308,6 +309,8 @@ int typec_get_negotiated_svdm_version(struct typec_port *port);
#if IS_REACHABLE(CONFIG_TYPEC)
int typec_link_port(struct device *port);
void typec_unlink_port(struct device *port);
+int typec_port_registration_register_notify(struct notifier_block *nb);
+int typec_port_registration_unregister_notify(struct notifier_block *nb);
#else
static inline int typec_link_port(struct device *port)
{
@@ -315,6 +318,16 @@ static inline int typec_link_port(struct device *port)
}
static inline void typec_unlink_port(struct device *port) { }
+
+int typec_port_registration_register_notify(struct notifier_block *nb)
+{
+ return 0;
+}
+
+int typec_port_registration_unregister_notify(struct notifier_block *nb)
+{
+ return 0;
+}
#endif
#endif /* __LINUX_USB_TYPEC_H */
--
2.34.0.rc2.393.gf8c9666880-goog
next prev parent reply other threads:[~2021-11-24 23:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-24 23:10 [PATCH 0/4] usb: Use notifier for linking Type C ports Prashant Malani
2021-11-24 23:10 ` Prashant Malani [this message]
2021-11-25 3:20 ` [PATCH 1/4] usb: typec: Add port registration notifier Prashant Malani
2021-11-24 23:10 ` [PATCH 2/4] usb: Use notifier to link Type C ports Prashant Malani
2021-11-25 2:15 ` kernel test robot
2021-11-24 23:10 ` [PATCH 3/4] usb: Link the ports to the connectors they are attached to Prashant Malani
2021-11-24 23:10 ` [PATCH 4/4] Revert "usb: Iterator for ports" Prashant Malani
2021-11-26 9:40 ` [PATCH 0/4] usb: Use notifier for linking Type C ports Heikki Krogerus
2021-11-30 11:03 ` Heikki Krogerus
2021-11-30 19:27 ` Prashant Malani
2021-12-01 9:55 ` Heikki Krogerus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211124231028.696982-2-pmalani@chromium.org \
--to=pmalani@chromium.org \
--cc=bhelgaas@google.com \
--cc=bleung@chromium.org \
--cc=christian.koenig@amd.com \
--cc=chunfeng.yun@mediatek.com \
--cc=daniel.vetter@ffwll.ch \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mchehab+huawei@kernel.org \
--cc=rajatja@google.com \
--cc=rikard.falkeborn@gmail.com \
--cc=stern@rowland.harvard.edu \
--cc=tzimmermann@suse.de \
--cc=wonchung@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox