Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: phy: generic: migrate to gpio_desc

Change internal gpio handling from integer gpios into gpio
descriptors. This change only addresses the internal API and
device-tree/ACPI, while the legacy platform data remains integer space
based.

This change is only build compile tested, and very prone to error. I
leave this comment for now in the commit message so that this patch gets
some testing as I'm pretty sure it's buggy.

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>

authored by

Robert Jarzmik and committed by
Felipe Balbi
e9f2cefb e3a912a1

+21 -44
+19 -42
drivers/usb/phy/phy-generic.c
··· 59 59 60 60 static void nop_reset_set(struct usb_phy_generic *nop, int asserted) 61 61 { 62 - int value; 63 - 64 - if (!gpio_is_valid(nop->gpio_reset)) 65 - return; 66 - 67 - value = asserted; 68 - if (nop->reset_active_low) 69 - value = !value; 70 - 71 - gpio_set_value_cansleep(nop->gpio_reset, value); 62 + if (nop->gpiod_reset) 63 + gpiod_set_value(nop->gpiod_reset, asserted); 72 64 73 65 if (!asserted) 74 66 usleep_range(10000, 20000); ··· 135 143 struct usb_phy_generic_platform_data *pdata) 136 144 { 137 145 enum usb_phy_type type = USB_PHY_TYPE_USB2; 138 - int err; 146 + int err = 0; 139 147 140 148 u32 clk_rate = 0; 141 149 bool needs_vcc = false; 142 150 143 - nop->reset_active_low = true; /* default behaviour */ 144 - 145 151 if (dev->of_node) { 146 152 struct device_node *node = dev->of_node; 147 - enum of_gpio_flags flags = 0; 148 153 149 154 if (of_property_read_u32(node, "clock-frequency", &clk_rate)) 150 155 clk_rate = 0; 151 156 152 157 needs_vcc = of_property_read_bool(node, "vcc-supply"); 153 - nop->gpio_reset = of_get_named_gpio_flags(node, "reset-gpios", 154 - 0, &flags); 155 - if (nop->gpio_reset == -EPROBE_DEFER) 156 - return -EPROBE_DEFER; 157 - 158 - nop->reset_active_low = flags & OF_GPIO_ACTIVE_LOW; 159 - 158 + nop->gpiod_reset = devm_gpiod_get(dev, "reset-gpios"); 159 + err = PTR_ERR(nop->gpiod_reset); 160 160 } else if (pdata) { 161 161 type = pdata->type; 162 162 clk_rate = pdata->clk_rate; 163 163 needs_vcc = pdata->needs_vcc; 164 - nop->gpio_reset = pdata->gpio_reset; 165 - } else { 166 - nop->gpio_reset = -1; 164 + if (gpio_is_valid(gpio->gpio_reset)) { 165 + err = devm_gpio_request_one(dev, pdata->gpio_reset, 0, 166 + dev_name(dev)); 167 + if (!err) 168 + nop->gpiod_reset = 169 + gpio_to_desc(pdata->gpio_reset); 170 + } 171 + } 172 + 173 + if (err == -EPROBE_DEFER) 174 + return -EPROBE_DEFER; 175 + if (err) { 176 + dev_err(dev, "Error requesting RESET GPIO\n"); 177 + return err; 167 178 } 168 179 169 180 nop->phy.otg = devm_kzalloc(dev, sizeof(*nop->phy.otg), ··· 194 199 PTR_ERR(nop->vcc)); 195 200 if (needs_vcc) 196 201 return -EPROBE_DEFER; 197 - } 198 - 199 - if (gpio_is_valid(nop->gpio_reset)) { 200 - unsigned long gpio_flags; 201 - 202 - /* Assert RESET */ 203 - if (nop->reset_active_low) 204 - gpio_flags = GPIOF_OUT_INIT_LOW; 205 - else 206 - gpio_flags = GPIOF_OUT_INIT_HIGH; 207 - 208 - err = devm_gpio_request_one(dev, nop->gpio_reset, 209 - gpio_flags, dev_name(dev)); 210 - if (err) { 211 - dev_err(dev, "Error requesting RESET GPIO %d\n", 212 - nop->gpio_reset); 213 - return err; 214 - } 215 202 } 216 203 217 204 nop->dev = dev;
+2 -2
drivers/usb/phy/phy-generic.h
··· 2 2 #define _PHY_GENERIC_H_ 3 3 4 4 #include <linux/usb/usb_phy_generic.h> 5 + #include <linux/gpio/consumer.h> 5 6 6 7 struct usb_phy_generic { 7 8 struct usb_phy phy; 8 9 struct device *dev; 9 10 struct clk *clk; 10 11 struct regulator *vcc; 11 - int gpio_reset; 12 - bool reset_active_low; 12 + struct gpio_desc *gpiod_reset; 13 13 }; 14 14 15 15 int usb_gen_phy_init(struct usb_phy *phy);