Skip to contentSkip to conversation

dt-bindings: usb: add documentation for typec switch via GPIO

PATCH Superseded Jun Li 2 participants 4 messages Mar 1, 2019 – Mar 5, 2019

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jun Li

author
#0 lore raw

PATCH v2 1/2 dt-bindings: usb: add documentation for typec switch via GPIO

Some typec super speed active channel switch can be controlled via a GPIO, this binding can be used to specify the switch node by a GPIO and the remote endpoint of its consumre.

---
No change on v2 for this patch.

 .../devicetree/bindings/usb/typec-switch-gpio.txt  | 30 ++++++++++++++++++++++
 1 file changed, 30 insertions(+)
Documentation/devicetree/bindings/usb/typec-switch-gpio.txt new file +30 -0
new file mode 100644
index 0000000..4ef76cf
@@ -0,0 +1,30 @@
+Typec orientation switch via a GPIO
+-----------------------------------
+
+Required properties:
+- compatible: should be set one of following:
+	- "nxp,ptn36043" for NXP Type-C SuperSpeed active switch.
+
+- gpios: the GPIO used to switch the super speed active channel,
+		GPIO_ACTIVE_HIGH: GPIO state high for cc1;
+		GPIO_ACTIVE_LOW:  GPIO state low for cc1.
+- orientation-switch: must be present.
+
+Required sub-node:
+- port: specify the remote endpoint of typec switch consumer.
+
+Example:
+
+ptn36043 {
+	compatible = "nxp,ptn36043";
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_ss_sel>;
+	gpios = <&gpio3 15 GPIO_ACTIVE_HIGH>;
+	orientation-switch;
+
+	port {
+		usb3_data_ss: endpoint {
+			remote-endpoint = <&typec_con_ss>;
+		};
+	};
+};
author
#1 lore raw

PATCH v2 2/2 usb: typec: add typec switch via GPIO control

This patch adds a simple typec switch driver which only needs a GPIO to switch the super speed active channel according to typec orientation.

---

Changes for v2:
- Use the correct head files for gpio api and of_device_id:
#include <linux/gpio/consumer.h>
#include <linux/mod_devicetable.h>
- Add driver dependency on GPIOLIB

 drivers/usb/typec/mux/Kconfig       |   7 +++
 drivers/usb/typec/mux/Makefile      |   1 +
 drivers/usb/typec/mux/gpio-switch.c | 105 ++++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+)
drivers/usb/typec/mux/Kconfig +7 -0
index 01ed0d5..27120e6 100644
@@ -9,4 +9,11 @@ config TYPEC_MUX_PI3USB30532
 	  Say Y or M if your system has a Pericom PI3USB30532 Type-C cross
 	  switch / mux chip found on some devices with a Type-C port.
 
+config TYPEC_SWITCH_GPIO
+	tristate "Simple Super Speed Active Switch via GPIO"
+	depends on GPIOLIB
+	help
+	  Say Y or M if your system has a typec super speed channel
+	  switch via a simple GPIO control.
+
 endmenu
drivers/usb/typec/mux/Makefile +1 -0
index 1332e46..e29377c 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_TYPEC_MUX_PI3USB30532)	+= pi3usb30532.o
+obj-$(CONFIG_TYPEC_SWITCH_GPIO)		+= gpio-switch.o
drivers/usb/typec/mux/gpio-switch.c new file +105 -0

105 lines not on this page · raw message

Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] usb: typec: add typec switch via GPIO control

Quoted 4 lines · Jun Li

This patch adds a simple typec switch driver which only needs a GPIO to switch the super speed active channel according to typec orientation.

FWIW,

One minor below.

Quoted 46 lines

---

Changes for v2:
- Use the correct head files for gpio api and of_device_id:
#include <linux/gpio/consumer.h>
#include <linux/mod_devicetable.h>
- Add driver dependency on GPIOLIB

 drivers/usb/typec/mux/Kconfig       |   7 +++
 drivers/usb/typec/mux/Makefile      |   1 +
 drivers/usb/typec/mux/gpio-switch.c | 105 ++++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+)
drivers/usb/typec/mux/Kconfig +7 -0
index 01ed0d5..27120e6 100644
@@ -9,4 +9,11 @@ config TYPEC_MUX_PI3USB30532
          Say Y or M if your system has a Pericom PI3USB30532 Type-C cross
          switch / mux chip found on some devices with a Type-C port.
 
+config TYPEC_SWITCH_GPIO
+       tristate "Simple Super Speed Active Switch via GPIO"
+       depends on GPIOLIB
+       help
+         Say Y or M if your system has a typec super speed channel
+         switch via a simple GPIO control.
+
 endmenu
drivers/usb/typec/mux/Makefile +1 -0
index 1332e46..e29377c 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_TYPEC_MUX_PI3USB30532)    += pi3usb30532.o
+obj-$(CONFIG_TYPEC_SWITCH_GPIO)                += gpio-switch.o
drivers/usb/typec/mux/gpio-switch.c new file +0 -0
new file mode 100644
index 0000000..b01844c

drivers/usb/typec/mux/gpio-switch.c line 3

Quoted 4 lines
drivers/usb/typec/mux/gpio-switch.c new file +3 -0
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0
+/**
 
+ * gpio-switch.c - typec switch via a simple GPIO control.

If under any circumstances file will be renamed this become outdated. So, better not to include file name in the file.

Quoted 105 lines

+ *
+ * Copyright 2019 NXP
+ * Author: Jun Li <[email protected]>
+ *
+ */

drivers/usb/typec/mux/gpio-switch.c new file +97 -1
+
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/mod_devicetable.h>
+#include <linux/usb/typec_mux.h>
+
+struct gpio_typec_switch {
+       struct typec_switch sw;
+       struct mutex lock;
+       struct gpio_desc *ss_sel;
+};
+
+static int switch_gpio_set(struct typec_switch *sw,
+                          enum typec_orientation orientation)
+{
+       struct gpio_typec_switch *gpio_sw = container_of(sw,
+                               struct gpio_typec_switch, sw);
+
+       mutex_lock(&gpio_sw->lock);
+
+       switch (orientation) {
+       case TYPEC_ORIENTATION_NORMAL:
+               gpiod_set_value_cansleep(gpio_sw->ss_sel, 1);
+               break;
+       case TYPEC_ORIENTATION_REVERSE:
+               gpiod_set_value_cansleep(gpio_sw->ss_sel, 0);
+               break;
+       case TYPEC_ORIENTATION_NONE:
+               break;
+       }
+
+       mutex_unlock(&gpio_sw->lock);
+
+       return 0;
+}
+
+static int typec_switch_gpio_probe(struct platform_device *pdev)
+{
+       struct gpio_typec_switch        *gpio_sw;
+       struct device                   *dev = &pdev->dev;
+       int                             ret;
+
+       gpio_sw = devm_kzalloc(dev, sizeof(*gpio_sw), GFP_KERNEL);
+       if (!gpio_sw)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, gpio_sw);
+
+       gpio_sw->sw.dev = dev;
+       gpio_sw->sw.set = switch_gpio_set;
+       mutex_init(&gpio_sw->lock);
+
+       /* Get the super speed active channel selection GPIO */
+       gpio_sw->ss_sel = devm_gpiod_get(dev, NULL, GPIOD_OUT_LOW);
+       if (IS_ERR(gpio_sw->ss_sel))
+               return PTR_ERR(gpio_sw->ss_sel);
+
+       ret = typec_switch_register(&gpio_sw->sw);
+       if (ret) {
+               dev_err(dev, "Error registering typec switch: %d\n", ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int typec_switch_gpio_remove(struct platform_device *pdev)
+{
+       struct gpio_typec_switch *gpio_sw = platform_get_drvdata(pdev);
+
+       typec_switch_unregister(&gpio_sw->sw);
+
+       return 0;
+}
+
+static const struct of_device_id of_typec_switch_gpio_match[] = {
+       { .compatible = "nxp,ptn36043" },
+       { /* Sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, of_typec_switch_gpio_match);
+
+static struct platform_driver typec_switch_gpio_driver = {
+       .probe          = typec_switch_gpio_probe,
+       .remove         = typec_switch_gpio_remove,
+       .driver         = {
+               .name   = "typec-switch-gpio",
+               .of_match_table = of_typec_switch_gpio_match,
+       },
+};
+
+module_platform_driver(typec_switch_gpio_driver);
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("TypeC Super Speed Switch GPIO driver");
+MODULE_AUTHOR("Jun Li <[email protected]>");
--

2.7.4

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#3 lore raw

RE: [PATCH v2 2/2] usb: typec: add typec switch via GPIO control

Hi Andy,

Quoted 71 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: 2019年3月3日 0:27
To: Jun Li <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH v2 2/2] usb: typec: add typec switch via GPIO control

Quoted 4 lines · Jun Li

This patch adds a simple typec switch driver which only needs a GPIO to switch the super speed active channel according to typec orientation.

FWIW,

One minor below.

Quoted 50 lines

---

Changes for v2:
- Use the correct head files for gpio api and of_device_id:
#include <linux/gpio/consumer.h>
#include <linux/mod_devicetable.h>
- Add driver dependency on GPIOLIB

 drivers/usb/typec/mux/Kconfig       |   7 +++
 drivers/usb/typec/mux/Makefile      |   1 +
 drivers/usb/typec/mux/gpio-switch.c | 105
++++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+)
(quoted diff) +0 -0

b/drivers/usb/typec/mux/Kconfig index 01ed0d5..27120e6 100644

drivers/usb/typec/mux/Kconfig +7 -0
@@ -9,4 +9,11 @@ config TYPEC_MUX_PI3USB30532
          Say Y or M if your system has a Pericom PI3USB30532 Type-C cross
          switch / mux chip found on some devices with a Type-C port.
 
+config TYPEC_SWITCH_GPIO
+       tristate "Simple Super Speed Active Switch via GPIO"
+       depends on GPIOLIB
+       help
+         Say Y or M if your system has a typec super speed channel
+         switch via a simple GPIO control.
+
 endmenu
(quoted diff) +0 -0

b/drivers/usb/typec/mux/Makefile index 1332e46..e29377c 100644

drivers/usb/typec/mux/Makefile +1 -0
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_TYPEC_MUX_PI3USB30532)    += pi3usb30532.o
+obj-$(CONFIG_TYPEC_SWITCH_GPIO)                += gpio-switch.o
drivers/usb/typec/mux/gpio-switch.c new file +2 -0
new file mode 100644
index 0000000..b01844c
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0
+/**
Quoted 4 lines

drivers/usb/typec/mux/gpio-switch.c line 3

Quoted 1 line
drivers/usb/typec/mux/gpio-switch.c new file +1 -0
+ * gpio-switch.c - typec switch via a simple GPIO control.

If under any circumstances file will be renamed this become outdated. So, better not to include file name in the file.

OK, I will remove this.

Thanks
Li Jun

Quoted 109 lines
Quoted 102 lines
drivers/usb/typec/mux/gpio-switch.c new file +100 -1
+ *
+ * Copyright 2019 NXP
+ * Author: Jun Li <[email protected]>
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/mod_devicetable.h>
+#include <linux/usb/typec_mux.h>
+
+struct gpio_typec_switch {
+       struct typec_switch sw;
+       struct mutex lock;
+       struct gpio_desc *ss_sel;
+};
+
+static int switch_gpio_set(struct typec_switch *sw,
+                          enum typec_orientation orientation) {
+       struct gpio_typec_switch *gpio_sw = container_of(sw,
+                               struct gpio_typec_switch, sw);
+
+       mutex_lock(&gpio_sw->lock);
+
+       switch (orientation) {
+       case TYPEC_ORIENTATION_NORMAL:
+               gpiod_set_value_cansleep(gpio_sw->ss_sel, 1);
+               break;
+       case TYPEC_ORIENTATION_REVERSE:
+               gpiod_set_value_cansleep(gpio_sw->ss_sel, 0);
+               break;
+       case TYPEC_ORIENTATION_NONE:
+               break;
+       }
+
+       mutex_unlock(&gpio_sw->lock);
+
+       return 0;
+}
+
+static int typec_switch_gpio_probe(struct platform_device *pdev) {
+       struct gpio_typec_switch        *gpio_sw;
+       struct device                   *dev = &pdev->dev;
+       int                             ret;
+
+       gpio_sw = devm_kzalloc(dev, sizeof(*gpio_sw), GFP_KERNEL);
+       if (!gpio_sw)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, gpio_sw);
+
+       gpio_sw->sw.dev = dev;
+       gpio_sw->sw.set = switch_gpio_set;
+       mutex_init(&gpio_sw->lock);
+
+       /* Get the super speed active channel selection GPIO */
+       gpio_sw->ss_sel = devm_gpiod_get(dev, NULL, GPIOD_OUT_LOW);
+       if (IS_ERR(gpio_sw->ss_sel))
+               return PTR_ERR(gpio_sw->ss_sel);
+
+       ret = typec_switch_register(&gpio_sw->sw);
+       if (ret) {
+               dev_err(dev, "Error registering typec switch: %d\n", ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int typec_switch_gpio_remove(struct platform_device *pdev) {
+       struct gpio_typec_switch *gpio_sw =
+platform_get_drvdata(pdev);
+
+       typec_switch_unregister(&gpio_sw->sw);
+
+       return 0;
+}
+
+static const struct of_device_id of_typec_switch_gpio_match[] = {
+       { .compatible = "nxp,ptn36043" },
+       { /* Sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, of_typec_switch_gpio_match);
+
+static struct platform_driver typec_switch_gpio_driver = {
+       .probe          = typec_switch_gpio_probe,
+       .remove         = typec_switch_gpio_remove,
+       .driver         = {
+               .name   = "typec-switch-gpio",
+               .of_match_table = of_typec_switch_gpio_match,
+       },
+};
+
+module_platform_driver(typec_switch_gpio_driver);
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("TypeC Super Speed Switch GPIO driver");
+MODULE_AUTHOR("Jun Li <[email protected]>");
--
Quoted 2 lines

2.7.4

--
With Best Regards,
Andy Shevchenko