[PATCH 3/4] usb: typec: add typec_find_port_power_role() and typec_find_pwr_opmode()
Sascha Hauer
s.hauer at pengutronix.de
Mon Apr 20 02:02:19 PDT 2026
Add helpers to parse 'power-role' and 'typec-power-opmode' DT strings
into their respective enum values, mirroring the Linux typec framework.
Move enum typec_port_type and enum typec_pwr_opmode from driver-local
definitions into the typec framework header where they belong.
Co-Authored-By: Claude Sonnet 4.6 <noreply at anthropic.com>
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
drivers/usb/typec/class.c | 28 ++++++++++++++++++++++++++++
include/linux/usb/typec.h | 16 ++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index b88e1c1e46..363c5b8cbb 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -11,6 +11,7 @@
#include <init.h>
#include <linux/kernel.h>
#include <linux/list.h>
+#include <linux/string.h>
#include <linux/usb/role.h>
#include <linux/usb/typec.h>
#include <linux/usb/typec_altmode.h>
@@ -151,6 +152,33 @@ void *typec_get_drvdata(struct typec_port *port)
}
EXPORT_SYMBOL_GPL(typec_get_drvdata);
+static const char * const typec_port_power_roles[] = {
+ [TYPEC_PORT_SRC] = "source",
+ [TYPEC_PORT_SNK] = "sink",
+ [TYPEC_PORT_DRP] = "dual",
+};
+
+static const char * const typec_pwr_opmodes[] = {
+ [TYPEC_PWR_MODE_USB] = "default",
+ [TYPEC_PWR_MODE_1_5A] = "1.5A",
+ [TYPEC_PWR_MODE_3_0A] = "3.0A",
+ [TYPEC_PWR_MODE_PD] = "usb_power_delivery",
+};
+
+int typec_find_port_power_role(const char *name)
+{
+ return match_string(typec_port_power_roles,
+ ARRAY_SIZE(typec_port_power_roles), name);
+}
+EXPORT_SYMBOL_GPL(typec_find_port_power_role);
+
+int typec_find_pwr_opmode(const char *name)
+{
+ return match_string(typec_pwr_opmodes,
+ ARRAY_SIZE(typec_pwr_opmodes), name);
+}
+EXPORT_SYMBOL_GPL(typec_find_pwr_opmode);
+
static int typec_register_port_dev(struct typec_port *port, const char *name, int id)
{
port->dev.id = id;
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 315dee95e4..a8fa314d9e 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -8,6 +8,19 @@
struct typec_port;
+enum typec_port_type {
+ TYPEC_PORT_SRC,
+ TYPEC_PORT_SNK,
+ TYPEC_PORT_DRP,
+};
+
+enum typec_pwr_opmode {
+ TYPEC_PWR_MODE_USB,
+ TYPEC_PWR_MODE_1_5A,
+ TYPEC_PWR_MODE_3_0A,
+ TYPEC_PWR_MODE_PD,
+};
+
struct device;
struct device_node;
@@ -51,4 +64,7 @@ int typec_set_role(struct typec_port *port, enum usb_role role);
void *typec_get_drvdata(struct typec_port *port);
+int typec_find_port_power_role(const char *name);
+int typec_find_pwr_opmode(const char *name);
+
#endif /* __LINUX_USB_TYPEC_H */
--
2.47.3
More information about the barebox
mailing list