mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Cc: "Claude Sonnet 4.6" <noreply@anthropic.com>
Subject: [PATCH 3/4] usb: typec: add typec_find_port_power_role() and typec_find_pwr_opmode()
Date: Mon, 20 Apr 2026 11:02:19 +0200	[thread overview]
Message-ID: <20260420-usb-typec-stusb160x-v1-3-5875bbae80ab@pengutronix.de> (raw)
In-Reply-To: <20260420-usb-typec-stusb160x-v1-0-5875bbae80ab@pengutronix.de>

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@anthropic.com>
Signed-off-by: Sascha Hauer <s.hauer@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




  parent reply	other threads:[~2026-04-20  9:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20  9:02 [PATCH 0/4] usb: typec: STUSB160x support Sascha Hauer
2026-04-20  9:02 ` [PATCH 1/4] usb: otg: Add function to set dr_mode Sascha Hauer
2026-04-20 10:42   ` Ahmad Fatoum
2026-04-20  9:02 ` [PATCH 2/4] usb: typec: wire USB role changes to OTG device Sascha Hauer
2026-04-20 11:08   ` Ahmad Fatoum
2026-04-20 12:02     ` Sascha Hauer
2026-04-20  9:02 ` Sascha Hauer [this message]
2026-04-20  9:02 ` [PATCH 4/4] USB: typec: Add STUSB160x driver Sascha Hauer
2026-04-20 11:14   ` Ahmad Fatoum
2026-04-20 11:30     ` Sascha Hauer

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=20260420-usb-typec-stusb160x-v1-3-5875bbae80ab@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=noreply@anthropic.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