diff mbox

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

Message ID 1525213273-6103-4-git-send-email-mats.dev.list@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mats Karrman May 1, 2018, 10:21 p.m. UTC
Signed-off-by: Mats Karrman <mats.dev.list@gmail.com>
---
 drivers/usb/typec/class.c | 22 ++++++++++++++++++++++
 include/linux/usb/typec.h |  1 +
 2 files changed, 23 insertions(+)
diff mbox

Patch

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 53df10d..c5432f4 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -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
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index d356577..72cd4a7 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -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);