[RFC PATCH 7/7] usb: typec: mux: Allow default mux mode to be specified

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch allows the default mux mode to be specified using
a firmware property.

Signed-off-by: Mats Karrman <mats.dev.list@xxxxxxxxx>
---
 drivers/usb/typec/mux/pi3usb30532.c | 18 ++++++++++++++++++
 drivers/usb/typec/tcpm.c            |  2 +-
 include/linux/usb/typec.h           |  1 +
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/mux/pi3usb30532.c b/drivers/usb/typec/mux/pi3usb30532.c
index 3e564e6..d1de12c 100644
--- a/drivers/usb/typec/mux/pi3usb30532.c
+++ b/drivers/usb/typec/mux/pi3usb30532.c
@@ -26,6 +26,7 @@ struct pi3usb30532 {
 	struct mutex lock; /* protects the cached conf register */
 	struct typec_switch sw;
 	struct typec_mux mux;
+	enum typec_mux_mode default_mux_mode; /* Mode for TYPEC_MUX_DEFAULT */
 	u8 mode_support; /* Modes supported by hardware as bit flags */
 	u8 conf;
 };
@@ -84,6 +85,9 @@ static int pi3usb30532_mux_set(struct typec_mux *mux, enum typec_mux_mode mode)
 	mutex_lock(&pi->lock);
 	new_conf = pi->conf;
 
+	if (mode == TYPEC_MUX_DEFAULT)
+		mode = pi->default_mux_mode;
+
 	switch (mode) {
 	default:
 	case TYPEC_MUX_NONE:
@@ -116,6 +120,7 @@ static int pi3usb30532_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
 	struct pi3usb30532 *pi;
+	const char *mode_str;
 	int ret;
 
 	pi = devm_kzalloc(dev, sizeof(*pi), GFP_KERNEL);
@@ -129,6 +134,19 @@ static int pi3usb30532_probe(struct i2c_client *client)
 	pi->mux.set = pi3usb30532_mux_set;
 	mutex_init(&pi->lock);
 
+	if (!device_property_present(dev, "default-mux-mode")) {
+		pi->default_mux_mode = TYPEC_MUX_2CH_USBSS;
+	} else {
+		ret = device_property_read_string(dev, "default-mux-mode",
+						  &mode_str);
+		if (ret)
+			return ret;
+		ret = typec_find_mux_mode(mode_str);
+		if (ret < 0)
+			return ret;
+		pi->default_mux_mode = ret;
+	}
+
 	if (device_property_present(dev, "have-2ch-usbss"))
 		pi->mode_support |= 0x1 << TYPEC_MUX_2CH_USBSS;
 	if (device_property_present(dev, "have-4ch-am"))
diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
index aaf6d57..8a9dc1a 100644
--- a/drivers/usb/typec/tcpm.c
+++ b/drivers/usb/typec/tcpm.c
@@ -790,7 +790,7 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached,
 	else
 		usb_role = USB_ROLE_DEVICE;
 
-	ret = tcpm_mux_set(port, TYPEC_MUX_2CH_USBSS, usb_role, orientation);
+	ret = tcpm_mux_set(port, TYPEC_MUX_DEFAULT, usb_role, orientation);
 	if (ret < 0)
 		return ret;
 
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 72cd4a7..85df816 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -74,6 +74,7 @@ enum typec_orientation {
 
 enum typec_mux_mode {
 	TYPEC_MUX_NONE,				/* Open switch */
+	TYPEC_MUX_DEFAULT,			/* Initial mode after connect */
 	TYPEC_MUX_2CH_USBSS,			/* 2ch USB SS */
 	TYPEC_MUX_4CH_AM,			/* 4ch Alt Mode */
 	TYPEC_MUX_2CH_USBSS_2CH_AM,		/* 2ch USB SS + 2ch Alt Mode */
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux