[PATCH 2/8] usb: typec: tcpm: add device managed port registration
From: Sebastian Reichel
Date: Fri Nov 13 2026 - 12:35:39 EST
A few drivers would benefit from having device managed TCPM
port registration, so that their probe routine does not mix
device managed and non-device managed calls.
Signed-off-by: Sebastian Reichel <sebastian.reichel@xxxxxxxxxxxxx>
---
drivers/usb/typec/tcpm/tcpm.c | 25 +++++++++++++++++++++++++
include/linux/usb/tcpm.h | 3 +++
2 files changed, 28 insertions(+)
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 07d2a03d2b8d..7d6378acf018 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -9013,6 +9013,31 @@ void tcpm_unregister_port(struct tcpm_port *port)
}
EXPORT_SYMBOL_GPL(tcpm_unregister_port);
+static void devm_tcpm_unregister_port(void *data)
+{
+ struct tcpm_port *port = data;
+
+ tcpm_unregister_port(port);
+}
+
+struct tcpm_port *devm_tcpm_register_port(struct device *dev,
+ struct tcpc_dev *tcpc)
+{
+ struct tcpm_port *result;
+ int ret;
+
+ result = tcpm_register_port(dev, tcpc);
+ if (IS_ERR(result))
+ return result;
+
+ ret = devm_add_action_or_reset(dev, devm_tcpm_unregister_port, result);
+ if (ret < 0)
+ return ERR_PTR(ret);
+
+ return result;
+}
+EXPORT_SYMBOL_GPL(devm_tcpm_register_port);
+
MODULE_AUTHOR("Guenter Roeck <groeck@xxxxxxxxxxxx>");
MODULE_DESCRIPTION("USB Type-C Port Manager");
MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
index 93079450bba0..fc60980f9f41 100644
--- a/include/linux/usb/tcpm.h
+++ b/include/linux/usb/tcpm.h
@@ -177,6 +177,9 @@ struct tcpm_port;
struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc);
void tcpm_unregister_port(struct tcpm_port *port);
+struct tcpm_port *devm_tcpm_register_port(struct device *dev,
+ struct tcpc_dev *tcpc);
+
void tcpm_vbus_change(struct tcpm_port *port);
void tcpm_cc_change(struct tcpm_port *port);
void tcpm_sink_frs(struct tcpm_port *port);
--
2.53.0