From 6e24826d2c51a0e005ecf3ed74ea48688fca0306 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 15 Apr 2020 21:24:48 +0200 Subject: usb: fusb302: Convert to use GPIO descriptors This converts the FUSB302 driver to use GPIO descriptors. The conversion to descriptors per se is pretty straight-forward. In the process I discovered that: 1. The driver uses a completely undocumented device tree binding for the interrupt GPIO line, "fcs,int_n". Ooops. 2. The undocumented binding, presumably since it has not seen review, is just "fcs,int_n", lacking the compulsory "-gpios" suffix and also something that is not a good name because the "_n" implies the line is inverted which is something we handle with flags in the device tree. Ooops. 3. Possibly the driver should not be requesting the line as a GPIO and request the corresponding interrupt line by open coding, the GPIO chip is very likely doubleing as an IRQ controller and can probably provide an interrupt directly for this line with interrupts-extended = <&gpio0 ...>; 4. Possibly the IRQ should just be tagged on the I2C client node in the device tree like apparently ACPI does, as it overrides this IRQ with client->irq if that exists. But now it is too late to do much about that and as I can see this is used like this in the Pinebook which is a shipping product so let'a just contain the mess and move on. The property currently appears in: arch/arm64/boot/dts/rockchip/rk3399-pinebook-pro.dts Create a quirk in the GPIO OF library to allow this property specifically to be specified without the "-gpios" suffix, we have other such bindings already. Cc: Tobias Schramm Cc: Heikki Krogerus Cc: Yueyao Zhu Cc: Guenter Roeck Cc: devicetree@vger.kernel.org Signed-off-by: Linus Walleij Link: https://lore.kernel.org/r/20200415192448.305257-1-linus.walleij@linaro.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpiolib-of.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'drivers/gpio/gpiolib-of.c') diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index ccc449df3792..20c2c428168e 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -460,6 +460,24 @@ static struct gpio_desc *of_find_arizona_gpio(struct device *dev, return of_get_named_gpiod_flags(dev->of_node, con_id, 0, of_flags); } +static struct gpio_desc *of_find_usb_gpio(struct device *dev, + const char *con_id, + enum of_gpio_flags *of_flags) +{ + /* + * Currently this USB quirk is only for the Fairchild FUSB302 host which is using + * an undocumented DT GPIO line named "fcs,int_n" without the compulsory "-gpios" + * suffix. + */ + if (!IS_ENABLED(CONFIG_TYPEC_FUSB302)) + return ERR_PTR(-ENOENT); + + if (!con_id || strcmp(con_id, "fcs,int_n")) + return ERR_PTR(-ENOENT); + + return of_get_named_gpiod_flags(dev->of_node, con_id, 0, of_flags); +} + struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, unsigned int idx, unsigned long *flags) { @@ -504,6 +522,9 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, if (PTR_ERR(desc) == -ENOENT) desc = of_find_arizona_gpio(dev, con_id, &of_flags); + if (PTR_ERR(desc) == -ENOENT) + desc = of_find_usb_gpio(dev, con_id, &of_flags); + if (IS_ERR(desc)) return desc; -- cgit v1.2.3-59-g8ed1b