Skip to contentSkip to conversation

usb: typec: Add API to find mux mode from its string representation

RFC New Mats Karrman 1 participant 1 message May 1, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 3/7 usb: typec: Add API to find mux mode from its string representation

---
 drivers/usb/typec/class.c | 22 ++++++++++++++++++++++
 include/linux/usb/typec.h |  1 +
 2 files changed, 23 insertions(+)
drivers/usb/typec/class.c +22 -0
index 53df10d..c5432f4 100644
@@ -1255,6 +1255,28 @@ EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);
 /* ------------------------------------------ */
 /* API for Multiplexer/DeMultiplexer Switches */
 
+static const char * const typec_mux_modes[] = {
+	[TYPEC_MUX_NONE] = "none",
+	[TYPEC_MUX_2CH_USBSS] = "2ch-usbss",
+	[TYPEC_MUX_4CH_AM] = "4ch-am",
+	[TYPEC_MUX_2CH_USBSS_2CH_AM] = "2ch-usbss-2ch-am",
+	[TYPEC_MUX_4CH_USBSS] = "4ch-usbss",
+	[TYPEC_MUX_2CH_USBSS_2CH_AM_B] = "2ch-usbss-2ch-am-b",
+};
+
+/**
+ * typec_find_mux_mode - Get the typec mux mode from its string representation
+ * @name: mux mode string
+ *
+ * Returns typec_mux_mode if success, otherwise negative error code.
+ */
+int typec_find_mux_mode(const char *name)
+{
+	return match_string(typec_mux_modes, ARRAY_SIZE(typec_mux_modes),
+			    name);
+}
+EXPORT_SYMBOL_GPL(typec_find_mux_mode);
+
 /**
  * typec_set_orientation - Set USB Type-C cable plug orientation
  * @port: USB Type-C Port
include/linux/usb/typec.h +1 -0
index d356577..72cd4a7 100644
@@ -274,6 +274,7 @@ void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
 void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
 void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
 
+int typec_find_mux_mode(const char *name);
 int typec_set_orientation(struct typec_port *port,
 			  enum typec_orientation orientation);
 int typec_set_mode(struct typec_port *port, int mode);