MLK-16298-1 usb: typec: make super speed signal mux select configurable
authorLi Jun <jun.li@nxp.com>
Wed, 9 Jan 2019 07:34:03 +0000 (13:04 +0530)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
Instead of fixed pull up super speed mux selection gpio for cc1, use
GPIO_ACTIVE_HIGH/LOW to map the CC1/CC2 orientation via gpiod api, So
for ss-sel-gpios:
GPIO_ACTIVE_HIGH: CC1 <--> GPIO high
GPIO_ACTIVE_LOW : CC1 <--> GPIO low

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
drivers/usb/typec/tcpci.c

index 86972c8..ce7cd48 100644 (file)
@@ -32,7 +32,7 @@ struct tcpci {
        struct regmap *regmap;
 
        bool controls_vbus;
-       int ss_sel_gpio;
+       struct gpio_desc *ss_sel_gpio;
 
        struct tcpc_dev tcpc;
        unsigned int irq_mask;
@@ -288,10 +288,13 @@ static int tcpci_set_ss_mux(struct tcpc_dev *tcpc,
 {
        struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
 
+       if (!tcpci->ss_sel_gpio)
+               return 0;
+
        if (polarity == TYPEC_POLARITY_CC1)
-               gpio_set_value(tcpci->ss_sel_gpio, 1);
+               gpiod_set_value_cansleep(tcpci->ss_sel_gpio, 1);
        else
-               gpio_set_value(tcpci->ss_sel_gpio, 0);
+               gpiod_set_value_cansleep(tcpci->ss_sel_gpio, 0);
 
        return 0;
 }
@@ -656,22 +659,15 @@ static int tcpci_parse_config(struct tcpci *tcpci)
 static int tcpci_ss_mux_control_init(struct tcpci *tcpci)
 {
        struct device *dev = tcpci->dev;
-       int retval = 0;
 
-       tcpci->ss_sel_gpio = of_get_named_gpio(dev->of_node,
-                                              "ss-sel-gpios", 0);
-       if (!gpio_is_valid(tcpci->ss_sel_gpio)) {
-               /* Super speed signal mux conrol gpio is optional */
-               dev_dbg(dev, "no Super Speed mux gpio pin available");
-       } else {
-               retval = devm_gpio_request_one(dev, tcpci->ss_sel_gpio,
-                                       GPIOF_OUT_INIT_LOW, "typec_ss_sel");
-               if (retval < 0)
-                       dev_err(dev, "Unable to request super speed mux gpio %d\n",
-                               retval);
+       tcpci->ss_sel_gpio = devm_gpiod_get_optional(dev, "ss-sel",
+                                                    GPIOD_OUT_HIGH);
+       if (IS_ERR(tcpci->ss_sel_gpio)) {
+               dev_err(dev, "Failed to request super speed mux sel gpio.");
+               return PTR_ERR(tcpci->ss_sel_gpio);
        }
 
-       return retval;
+       return 0;
 }
 
 struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)