Skip to content

Commit fceecf9

Browse files
committed
usb: chipidea: core: modernize ulpi reset gpio handling
The ulpi reset gpio code (which is a patch owned by us) was still using the legacy gpio API which brings some pain from times to times whem merging to a new kernel version (ex: this merge a macro was dropped from upstream). Hence, use the proper GPIO consumer API. On top of that, correctly handle the pin polarity. The pins is active low so this means we want to request the GPIO asserted to reset the phy (hence GPIOD_OUT_HIGH) and then bring the device out of reset by deaserting the pin (hence passing 0 in gpiod_set_value_cansleep(). Things worked because we "cheated" in DT by saying the pin is active high and then requesting it in the deasserted state (setting the pin to 0 and effectively assert/reset it), Then asserting it by passing 1 to gpiod_set_value_cansleep() which in fact was deasserting the pin. While at it, remove the #ifdef and use fsleep() instead of msleep(). Signed-off-by: Nuno Sá <nuno.sa@analog.com>
1 parent 5eefac7 commit fceecf9

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

drivers/usb/chipidea/core.c

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <linux/device.h>
1919
#include <linux/dma-mapping.h>
2020
#include <linux/extcon.h>
21-
#include <linux/gpio.h>
21+
#include <linux/gpio/consumer.h>
2222
#include <linux/phy/phy.h>
2323
#include <linux/platform_device.h>
2424
#include <linux/module.h>
@@ -36,7 +36,6 @@
3636
#include <linux/usb/of.h>
3737
#include <linux/usb/ulpi.h>
3838
#include <linux/of.h>
39-
#include <linux/of_gpio.h>
4039
#include <linux/phy.h>
4140
#include <linux/regulator/consumer.h>
4241
#include <linux/usb/ehci_def.h>
@@ -988,25 +987,28 @@ static void ci_get_otg_capable(struct ci_hdrc *ci)
988987
}
989988
}
990989

991-
#ifdef CONFIG_USB_ULPI
992-
993990
static int ci_hdrc_create_ulpi_phy(struct device *dev, struct ci_hdrc *ci)
994991
{
995992
struct usb_phy *ulpi;
996-
int reset_gpio;
997-
int ret;
993+
struct gpio_desc *reset_gpio;
998994

999-
reset_gpio = of_get_named_gpio(dev->parent->of_node, "xlnx,phy-reset-gpio", 0);
1000-
if (gpio_is_valid(reset_gpio)) {
1001-
ret = devm_gpio_request_one(dev, reset_gpio,
1002-
GPIOF_OUT_INIT_LOW, "ulpi resetb");
1003-
if (ret) {
1004-
dev_err(dev, "Failed to request ULPI reset gpio: %d\n", ret);
995+
if (!IS_ENABLED(CONFIG_USB_ULPI))
996+
return 0;
997+
998+
reset_gpio = devm_gpiod_get_optional(dev->parent, "xlnx,phy-reset-gpio",
999+
GPIOD_OUT_HIGH);
1000+
if (IS_ERR(reset_gpio))
1001+
return dev_err_probe(dev, PTR_ERR(reset_gpio), "Failed to get ULPI reset gpio\n");
1002+
if (reset_gpio) {
1003+
int ret;
1004+
1005+
ret = gpiod_set_consumer_name(reset_gpio, "ulpi resetb");
1006+
if (ret)
10051007
return ret;
1006-
}
1007-
msleep(5);
1008-
gpio_set_value_cansleep(reset_gpio, 1);
1009-
msleep(1);
1008+
1009+
fsleep(5);
1010+
gpiod_set_value_cansleep(reset_gpio, 0);
1011+
fsleep(1);
10101012
}
10111013

10121014
ulpi = otg_ulpi_create(&ulpi_viewport_access_ops,
@@ -1019,15 +1021,6 @@ static int ci_hdrc_create_ulpi_phy(struct device *dev, struct ci_hdrc *ci)
10191021
return 0;
10201022
}
10211023

1022-
#else
1023-
1024-
static int ci_hdrc_create_ulpi_phy(struct device *dev, struct ci_hdrc *ci)
1025-
{
1026-
return 0;
1027-
}
1028-
1029-
#endif
1030-
10311024
static ssize_t role_show(struct device *dev, struct device_attribute *attr,
10321025
char *buf)
10331026
{

0 commit comments

Comments
 (0)