Skip to contentSkip to conversation

sunxi: usb: convert PHY GPIO functions to DM

PATCH Applied Andre Przywara 3 participants 7 messages Jun 8, 2022 – Jun 27, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sunxi: usb: convert PHY GPIO functions to DM

The Allwinner USB PHY driver is still using the legacy GPIO interface, which is now implemented by the DM_GPIO compat functions. Those seem to have some design flaws, as setting the direction, then later setting the value will not work, if the DM_GPIO driver is implementing set_flags.

Fix this by using the dm_ version of the direct GPIO interface, which uses struct gpio_desc structs to handle requested GPIOs, and actually keeps the flags we set earlier.

This fixes USB operation on boards which need to toggle the VBUS supply via a GPIO, like the Teres-I laptop or the BananaPi M2 Berry board.

---
 drivers/phy/allwinner/phy-sun4i-usb.c | 59 +++++++++++++++------------
 1 file changed, 33 insertions(+), 26 deletions(-)
drivers/phy/allwinner/phy-sun4i-usb.c +33 -26
index 86c589a65fd..aef2cb8f6f8 100644
@@ -125,9 +125,9 @@ struct sun4i_usb_phy_info {
 
 struct sun4i_usb_phy_plat {
 	void __iomem *pmu;
-	int gpio_vbus;
-	int gpio_vbus_det;
-	int gpio_id_det;
+	struct gpio_desc gpio_vbus;
+	struct gpio_desc gpio_vbus_det;
+	struct gpio_desc gpio_id_det;
 	struct clk clocks;
 	struct reset_ctl resets;
 	int id;
@@ -224,8 +224,8 @@ static int sun4i_usb_phy_power_on(struct phy *phy)
 		initial_usb_scan_delay = 0;
 	}
 
-	if (usb_phy->gpio_vbus >= 0)
-		gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_UP);
+	if (dm_gpio_is_valid(&usb_phy->gpio_vbus))
+		dm_gpio_set_value(&usb_phy->gpio_vbus, 1);
 
 	return 0;
 }
@@ -235,8 +235,8 @@ static int sun4i_usb_phy_power_off(struct phy *phy)
 	struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
 	struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
 
-	if (usb_phy->gpio_vbus >= 0)
-		gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_DISABLE);
+	if (dm_gpio_is_valid(&usb_phy->gpio_vbus))
+		dm_gpio_set_value(&usb_phy->gpio_vbus, 0);
 
 	return 0;
 }
@@ -386,8 +386,8 @@ int sun4i_usb_phy_vbus_detect(struct phy *phy)
 	struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
 	int err = 1, retries = 3;
 
-	if (usb_phy->gpio_vbus_det >= 0) {
-		err = gpio_get_value(usb_phy->gpio_vbus_det);
+	if (dm_gpio_is_valid(&usb_phy->gpio_vbus_det)) {
+		err = dm_gpio_get_value(&usb_phy->gpio_vbus_det);
 		/*
 		 * Vbus may have been provided by the board and just turned off
 		 * some milliseconds ago on reset. What we're measuring then is
@@ -395,7 +395,7 @@ int sun4i_usb_phy_vbus_detect(struct phy *phy)
 		 */
 		while (err > 0 && retries--) {
 			mdelay(100);
-			err = gpio_get_value(usb_phy->gpio_vbus_det);
+			err = dm_gpio_get_value(&usb_phy->gpio_vbus_det);
 		}
 	} else if (data->vbus_power_supply) {
 		err = regulator_get_enable(data->vbus_power_supply);
@@ -409,10 +409,10 @@ int sun4i_usb_phy_id_detect(struct phy *phy)
 	struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
 	struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
 
-	if (usb_phy->gpio_id_det < 0)
-		return usb_phy->gpio_id_det;
+	if (!dm_gpio_is_valid(&usb_phy->gpio_id_det))
+		return -1;
 
-	return gpio_get_value(usb_phy->gpio_id_det);
+	return dm_gpio_get_value(&usb_phy->gpio_id_det);
 }
 
 void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled)
@@ -454,35 +454,42 @@ static int sun4i_usb_phy_probe(struct udevice *dev)
 		if (data->cfg->missing_phys & BIT(i))
 			continue;
 
-		phy->gpio_vbus = sunxi_name_to_gpio(info->gpio_vbus);
-		if (phy->gpio_vbus >= 0) {
-			ret = gpio_request(phy->gpio_vbus, "usb_vbus");
+		ret = dm_gpio_lookup_name(info->gpio_vbus, &phy->gpio_vbus);
+		if (ret == 0) {
+			ret = dm_gpio_request(&phy->gpio_vbus, "usb_vbus");
 			if (ret)
 				return ret;
-			ret = gpio_direction_output(phy->gpio_vbus, 0);
+			ret = dm_gpio_set_dir_flags(&phy->gpio_vbus,
+						    GPIOD_IS_OUT);
+			if (ret)
+				return ret;
+			ret = dm_gpio_set_value(&phy->gpio_vbus, 0);
 			if (ret)
 				return ret;
 		}
 
-		phy->gpio_vbus_det = sunxi_name_to_gpio(info->gpio_vbus_det);
-		if (phy->gpio_vbus_det >= 0) {
-			ret = gpio_request(phy->gpio_vbus_det, "usb_vbus_det");
+		ret = dm_gpio_lookup_name(info->gpio_vbus_det,
+					  &phy->gpio_vbus_det);
+		if (ret == 0) {
+			ret = dm_gpio_request(&phy->gpio_vbus_det,
+					      "usb_vbus_det");
 			if (ret)
 				return ret;
-			ret = gpio_direction_input(phy->gpio_vbus_det);
+			ret = dm_gpio_set_dir_flags(&phy->gpio_vbus_det,
+						    GPIOD_IS_IN);
 			if (ret)
 				return ret;
 		}
 
-		phy->gpio_id_det = sunxi_name_to_gpio(info->gpio_id_det);
-		if (phy->gpio_id_det >= 0) {
-			ret = gpio_request(phy->gpio_id_det, "usb_id_det");
+		ret = dm_gpio_lookup_name(info->gpio_id_det, &phy->gpio_id_det);
+		if (ret == 0) {
+			ret = dm_gpio_request(&phy->gpio_id_det, "usb_id_det");
 			if (ret)
 				return ret;
-			ret = gpio_direction_input(phy->gpio_id_det);
+			ret = dm_gpio_set_dir_flags(&phy->gpio_id_det,
+						GPIOD_IS_IN | GPIOD_PULL_UP);
 			if (ret)
 				return ret;
-			sunxi_gpio_set_pull(phy->gpio_id_det, SUNXI_GPIO_PULL_UP);
 		}
 
 		if (data->cfg->dedicated_clocks)
Signature · 1 line
2.35.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Andre Przywara

The Allwinner USB PHY driver is still using the legacy GPIO interface, which is now implemented by the DM_GPIO compat functions. Those seem to have some design flaws, as setting the direction, then later setting the value will not work, if the DM_GPIO driver is implementing set_flags.

Fix this by using the dm_ version of the direct GPIO interface, which uses struct gpio_desc structs to handle requested GPIOs, and actually keeps the flags we set earlier.

Quoted 5 lines

This fixes USB operation on boards which need to toggle the VBUS supply via a GPIO, like the Teres-I laptop or the BananaPi M2 Berry board.

It looks like the other users of sunxi_name_to_gpio are unaffected because they call only gpio_direction_output (sometimes repeatedly), never gpio_set_value.

Regards,
Samuel

#2 lore raw

On Tue, 7 Jun 2022 21:07:59 -0500
Samuel Holland <[email protected]> wrote:

Hi,

Quoted 11 lines · Andre Przywara
Quoted 10 lines

The Allwinner USB PHY driver is still using the legacy GPIO interface, which is now implemented by the DM_GPIO compat functions. Those seem to have some design flaws, as setting the direction, then later setting the value will not work, if the DM_GPIO driver is implementing set_flags.

Fix this by using the dm_ version of the direct GPIO interface, which uses struct gpio_desc structs to handle requested GPIOs, and actually keeps the flags we set earlier.

Quoted 7 lines
Quoted 5 lines

This fixes USB operation on boards which need to toggle the VBUS supply via a GPIO, like the Teres-I laptop or the BananaPi M2 Berry board.

Thanks!

Quoted 3 lines

It looks like the other users of sunxi_name_to_gpio are unaffected because they call only gpio_direction_output (sometimes repeatedly), never gpio_set_value.

Yeah, that's right, I was concerned about SATAPWR and MACPWR too, but they work, for the very reason you mentioned.
But we should eventually eliminate their usage, together with CONFIG_USB?_VBUS_PIN, as they are only used in U-Boot proper, where we can rely on proper DT information now.

Cheers,
Andre

P.S.: I just picked the lowest hanging fruit, and removed CONFIG_MMC?_CD_PIN, since we can ignore card detect in the same way the BROM does.

maintainer
#3 lore raw
Quoted 27 lines · Andre Przywara

On Tue, 7 Jun 2022 21:07:59 -0500
Samuel Holland <[email protected]> wrote:

Hi,

Quoted 11 lines · Andre Przywara
Quoted 10 lines

The Allwinner USB PHY driver is still using the legacy GPIO interface, which is now implemented by the DM_GPIO compat functions. Those seem to have some design flaws, as setting the direction, then later setting the value will not work, if the DM_GPIO driver is implementing set_flags.

Fix this by using the dm_ version of the direct GPIO interface, which uses struct gpio_desc structs to handle requested GPIOs, and actually keeps the flags we set earlier.

Quoted 7 lines
Quoted 5 lines

This fixes USB operation on boards which need to toggle the VBUS supply via a GPIO, like the Teres-I laptop or the BananaPi M2 Berry board.

Thanks!

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

It looks like the other users of sunxi_name_to_gpio are unaffected because they call only gpio_direction_output (sometimes repeatedly), never gpio_set_value.

Yeah, that's right, I was concerned about SATAPWR and MACPWR too, but they work, for the very reason you mentioned.
But we should eventually eliminate their usage, together with CONFIG_USB?_VBUS_PIN, as they are only used in U-Boot proper, where we can rely on proper DT information now.

I have a series for converting the USB PHY driver to devicetree already, but it has been blocked on the devicetree update renaming "usb0_*_det-gpio" to "usb0_*_det-gpios". In fact it is still blocked on that, because the sun4i devicetree patch was only partially applied.

I will rebase the series on top of your patch and send it soon.

Regards,
Samuel

#4 lore raw

On Wed, 8 Jun 2022 08:14:27 -0500
Samuel Holland <[email protected]> wrote:

Hi,

Quoted 31 lines · Andre Przywara
Quoted 30 lines

On Tue, 7 Jun 2022 21:07:59 -0500
Samuel Holland <[email protected]> wrote:

Hi,

Quoted 11 lines · Andre Przywara
Quoted 10 lines

The Allwinner USB PHY driver is still using the legacy GPIO interface, which is now implemented by the DM_GPIO compat functions. Those seem to have some design flaws, as setting the direction, then later setting the value will not work, if the DM_GPIO driver is implementing set_flags.

Fix this by using the dm_ version of the direct GPIO interface, which uses struct gpio_desc structs to handle requested GPIOs, and actually keeps the flags we set earlier.

Quoted 7 lines
Quoted 5 lines

This fixes USB operation on boards which need to toggle the VBUS supply via a GPIO, like the Teres-I laptop or the BananaPi M2 Berry board.

Thanks!

Quoted 3 lines

It looks like the other users of sunxi_name_to_gpio are unaffected because they call only gpio_direction_output (sometimes repeatedly), never gpio_set_value.

Quoted 7 lines
Quoted 5 lines

Yeah, that's right, I was concerned about SATAPWR and MACPWR too, but they work, for the very reason you mentioned.
But we should eventually eliminate their usage, together with CONFIG_USB?_VBUS_PIN, as they are only used in U-Boot proper, where we can rely on proper DT information now.

I have a series for converting the USB PHY driver to devicetree already, but it

So I remembered correctly ...

Quoted 3 lines

has been blocked on the devicetree update renaming "usb0_*_det-gpio" to "usb0_*_det-gpios". In fact it is still blocked on that, because the sun4i devicetree patch was only partially applied.

Yeah, I saw that, sorry for the mixup. That patch didn't make it to patchwork, so I applied it manually on one tree, but fixed it up wrongly on the other machine. It is in my (mental) fixes queue, together with that H616 FEL issue (once I find the actual culprit), and that NAND environment fix.
Once that's in, I will try to update the -next branch with stuff for the next merge window (in July), so you can then work on that branch.

Quoted 1 line

I will rebase the series on top of your patch and send it soon.

Cool, many thanks. And no rush, I just wanted to check to avoid double work.
I think I figured nice and easy solutions for SATAPWR and MACPWR, will test them later tonight.

Cheers,
Andre

Tested-by on v1 1/1
#5 lore raw
In reply to Andre Przywara

Hi,

it works fine. Thank you.

Quoted 10 lines · Andre Przywara

The Allwinner USB PHY driver is still using the legacy GPIO interface, which is now implemented by the DM_GPIO compat functions. Those seem to have some design flaws, as setting the direction, then later setting the value will not work, if the DM_GPIO driver is implementing set_flags.

Fix this by using the dm_ version of the direct GPIO interface, which uses struct gpio_desc structs to handle requested GPIOs, and actually keeps the flags we set earlier.

Quoted 5 lines

This fixes USB operation on boards which need to toggle the VBUS supply via a GPIO, like the Teres-I laptop or the BananaPi M2 Berry board.

Quoted 136 lines
---
 drivers/phy/allwinner/phy-sun4i-usb.c | 59 +++++++++++++++------------
 1 file changed, 33 insertions(+), 26 deletions(-)
drivers/phy/allwinner/phy-sun4i-usb.c +33 -26
index 86c589a65fd..aef2cb8f6f8 100644
@@ -125,9 +125,9 @@ struct sun4i_usb_phy_info {
 
 struct sun4i_usb_phy_plat {
 	void __iomem *pmu;
-	int gpio_vbus;
-	int gpio_vbus_det;
-	int gpio_id_det;
+	struct gpio_desc gpio_vbus;
+	struct gpio_desc gpio_vbus_det;
+	struct gpio_desc gpio_id_det;
 	struct clk clocks;
 	struct reset_ctl resets;
 	int id;
@@ -224,8 +224,8 @@ static int sun4i_usb_phy_power_on(struct phy *phy)
 		initial_usb_scan_delay = 0;
 	}
 
-	if (usb_phy->gpio_vbus >= 0)
-		gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_UP);
+	if (dm_gpio_is_valid(&usb_phy->gpio_vbus))
+		dm_gpio_set_value(&usb_phy->gpio_vbus, 1);
 
 	return 0;
 }
@@ -235,8 +235,8 @@ static int sun4i_usb_phy_power_off(struct phy *phy)
 	struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
 	struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
 
-	if (usb_phy->gpio_vbus >= 0)
-		gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_DISABLE);
+	if (dm_gpio_is_valid(&usb_phy->gpio_vbus))
+		dm_gpio_set_value(&usb_phy->gpio_vbus, 0);
 
 	return 0;
 }
@@ -386,8 +386,8 @@ int sun4i_usb_phy_vbus_detect(struct phy *phy)
 	struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
 	int err = 1, retries = 3;
 
-	if (usb_phy->gpio_vbus_det >= 0) {
-		err = gpio_get_value(usb_phy->gpio_vbus_det);
+	if (dm_gpio_is_valid(&usb_phy->gpio_vbus_det)) {
+		err = dm_gpio_get_value(&usb_phy->gpio_vbus_det);
 		/*
 		 * Vbus may have been provided by the board and just turned off
 		 * some milliseconds ago on reset. What we're measuring then is
@@ -395,7 +395,7 @@ int sun4i_usb_phy_vbus_detect(struct phy *phy)
 		 */
 		while (err > 0 && retries--) {
 			mdelay(100);
-			err = gpio_get_value(usb_phy->gpio_vbus_det);
+			err = dm_gpio_get_value(&usb_phy->gpio_vbus_det);
 		}
 	} else if (data->vbus_power_supply) {
 		err = regulator_get_enable(data->vbus_power_supply);
@@ -409,10 +409,10 @@ int sun4i_usb_phy_id_detect(struct phy *phy)
 	struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
 	struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
 
-	if (usb_phy->gpio_id_det < 0)
-		return usb_phy->gpio_id_det;
+	if (!dm_gpio_is_valid(&usb_phy->gpio_id_det))
+		return -1;
 
-	return gpio_get_value(usb_phy->gpio_id_det);
+	return dm_gpio_get_value(&usb_phy->gpio_id_det);
 }
 
 void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled)
@@ -454,35 +454,42 @@ static int sun4i_usb_phy_probe(struct udevice *dev)
 		if (data->cfg->missing_phys & BIT(i))
 			continue;
 
-		phy->gpio_vbus = sunxi_name_to_gpio(info->gpio_vbus);
-		if (phy->gpio_vbus >= 0) {
-			ret = gpio_request(phy->gpio_vbus, "usb_vbus");
+		ret = dm_gpio_lookup_name(info->gpio_vbus, &phy->gpio_vbus);
+		if (ret == 0) {
+			ret = dm_gpio_request(&phy->gpio_vbus, "usb_vbus");
 			if (ret)
 				return ret;
-			ret = gpio_direction_output(phy->gpio_vbus, 0);
+			ret = dm_gpio_set_dir_flags(&phy->gpio_vbus,
+						    GPIOD_IS_OUT);
+			if (ret)
+				return ret;
+			ret = dm_gpio_set_value(&phy->gpio_vbus, 0);
 			if (ret)
 				return ret;
 		}
 
-		phy->gpio_vbus_det = sunxi_name_to_gpio(info->gpio_vbus_det);
-		if (phy->gpio_vbus_det >= 0) {
-			ret = gpio_request(phy->gpio_vbus_det, "usb_vbus_det");
+		ret = dm_gpio_lookup_name(info->gpio_vbus_det,
+					  &phy->gpio_vbus_det);
+		if (ret == 0) {
+			ret = dm_gpio_request(&phy->gpio_vbus_det,
+					      "usb_vbus_det");
 			if (ret)
 				return ret;
-			ret = gpio_direction_input(phy->gpio_vbus_det);
+			ret = dm_gpio_set_dir_flags(&phy->gpio_vbus_det,
+						    GPIOD_IS_IN);
 			if (ret)
 				return ret;
 		}
 
-		phy->gpio_id_det = sunxi_name_to_gpio(info->gpio_id_det);
-		if (phy->gpio_id_det >= 0) {
-			ret = gpio_request(phy->gpio_id_det, "usb_id_det");
+		ret = dm_gpio_lookup_name(info->gpio_id_det, &phy->gpio_id_det);
+		if (ret == 0) {
+			ret = dm_gpio_request(&phy->gpio_id_det, "usb_id_det");
 			if (ret)
 				return ret;
-			ret = gpio_direction_input(phy->gpio_id_det);
+			ret = dm_gpio_set_dir_flags(&phy->gpio_id_det,
+						GPIOD_IS_IN | GPIOD_PULL_UP);
 			if (ret)
 				return ret;
-			sunxi_gpio_set_pull(phy->gpio_id_det, SUNXI_GPIO_PULL_UP);
 		}
 
 		if (data->cfg->dedicated_clocks)
Signature · 1 line
2.35.3
author Applied
#6 lore raw
In reply to Andre Przywara
Quoted 10 lines · On Wed, 8 Jun 2022 01:06:04 +0100 Andre Przywara <[email protected]>…

The Allwinner USB PHY driver is still using the legacy GPIO interface, which is now implemented by the DM_GPIO compat functions. Those seem to have some design flaws, as setting the direction, then later setting the value will not work, if the DM_GPIO driver is implementing set_flags.

Fix this by using the dm_ version of the direct GPIO interface, which uses struct gpio_desc structs to handle requested GPIOs, and actually keeps the flags we set earlier.

Quoted 5 lines

This fixes USB operation on boards which need to toggle the VBUS supply via a GPIO, like the Teres-I laptop or the BananaPi M2 Berry board.

Applied to sunxi/master, for v2022.07.

Cheers,
Andre

Quoted 133 lines
---
 drivers/phy/allwinner/phy-sun4i-usb.c | 59 +++++++++++++++------------
 1 file changed, 33 insertions(+), 26 deletions(-)
drivers/phy/allwinner/phy-sun4i-usb.c +33 -26
index 86c589a65fd..aef2cb8f6f8 100644
@@ -125,9 +125,9 @@ struct sun4i_usb_phy_info {
 
 struct sun4i_usb_phy_plat {
 	void __iomem *pmu;
-	int gpio_vbus;
-	int gpio_vbus_det;
-	int gpio_id_det;
+	struct gpio_desc gpio_vbus;
+	struct gpio_desc gpio_vbus_det;
+	struct gpio_desc gpio_id_det;
 	struct clk clocks;
 	struct reset_ctl resets;
 	int id;
@@ -224,8 +224,8 @@ static int sun4i_usb_phy_power_on(struct phy *phy)
 		initial_usb_scan_delay = 0;
 	}
 
-	if (usb_phy->gpio_vbus >= 0)
-		gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_UP);
+	if (dm_gpio_is_valid(&usb_phy->gpio_vbus))
+		dm_gpio_set_value(&usb_phy->gpio_vbus, 1);
 
 	return 0;
 }
@@ -235,8 +235,8 @@ static int sun4i_usb_phy_power_off(struct phy *phy)
 	struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
 	struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
 
-	if (usb_phy->gpio_vbus >= 0)
-		gpio_set_value(usb_phy->gpio_vbus, SUNXI_GPIO_PULL_DISABLE);
+	if (dm_gpio_is_valid(&usb_phy->gpio_vbus))
+		dm_gpio_set_value(&usb_phy->gpio_vbus, 0);
 
 	return 0;
 }
@@ -386,8 +386,8 @@ int sun4i_usb_phy_vbus_detect(struct phy *phy)
 	struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
 	int err = 1, retries = 3;
 
-	if (usb_phy->gpio_vbus_det >= 0) {
-		err = gpio_get_value(usb_phy->gpio_vbus_det);
+	if (dm_gpio_is_valid(&usb_phy->gpio_vbus_det)) {
+		err = dm_gpio_get_value(&usb_phy->gpio_vbus_det);
 		/*
 		 * Vbus may have been provided by the board and just turned off
 		 * some milliseconds ago on reset. What we're measuring then is
@@ -395,7 +395,7 @@ int sun4i_usb_phy_vbus_detect(struct phy *phy)
 		 */
 		while (err > 0 && retries--) {
 			mdelay(100);
-			err = gpio_get_value(usb_phy->gpio_vbus_det);
+			err = dm_gpio_get_value(&usb_phy->gpio_vbus_det);
 		}
 	} else if (data->vbus_power_supply) {
 		err = regulator_get_enable(data->vbus_power_supply);
@@ -409,10 +409,10 @@ int sun4i_usb_phy_id_detect(struct phy *phy)
 	struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
 	struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
 
-	if (usb_phy->gpio_id_det < 0)
-		return usb_phy->gpio_id_det;
+	if (!dm_gpio_is_valid(&usb_phy->gpio_id_det))
+		return -1;
 
-	return gpio_get_value(usb_phy->gpio_id_det);
+	return dm_gpio_get_value(&usb_phy->gpio_id_det);
 }
 
 void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled)
@@ -454,35 +454,42 @@ static int sun4i_usb_phy_probe(struct udevice *dev)
 		if (data->cfg->missing_phys & BIT(i))
 			continue;
 
-		phy->gpio_vbus = sunxi_name_to_gpio(info->gpio_vbus);
-		if (phy->gpio_vbus >= 0) {
-			ret = gpio_request(phy->gpio_vbus, "usb_vbus");
+		ret = dm_gpio_lookup_name(info->gpio_vbus, &phy->gpio_vbus);
+		if (ret == 0) {
+			ret = dm_gpio_request(&phy->gpio_vbus, "usb_vbus");
 			if (ret)
 				return ret;
-			ret = gpio_direction_output(phy->gpio_vbus, 0);
+			ret = dm_gpio_set_dir_flags(&phy->gpio_vbus,
+						    GPIOD_IS_OUT);
+			if (ret)
+				return ret;
+			ret = dm_gpio_set_value(&phy->gpio_vbus, 0);
 			if (ret)
 				return ret;
 		}
 
-		phy->gpio_vbus_det = sunxi_name_to_gpio(info->gpio_vbus_det);
-		if (phy->gpio_vbus_det >= 0) {
-			ret = gpio_request(phy->gpio_vbus_det, "usb_vbus_det");
+		ret = dm_gpio_lookup_name(info->gpio_vbus_det,
+					  &phy->gpio_vbus_det);
+		if (ret == 0) {
+			ret = dm_gpio_request(&phy->gpio_vbus_det,
+					      "usb_vbus_det");
 			if (ret)
 				return ret;
-			ret = gpio_direction_input(phy->gpio_vbus_det);
+			ret = dm_gpio_set_dir_flags(&phy->gpio_vbus_det,
+						    GPIOD_IS_IN);
 			if (ret)
 				return ret;
 		}
 
-		phy->gpio_id_det = sunxi_name_to_gpio(info->gpio_id_det);
-		if (phy->gpio_id_det >= 0) {
-			ret = gpio_request(phy->gpio_id_det, "usb_id_det");
+		ret = dm_gpio_lookup_name(info->gpio_id_det, &phy->gpio_id_det);
+		if (ret == 0) {
+			ret = dm_gpio_request(&phy->gpio_id_det, "usb_id_det");
 			if (ret)
 				return ret;
-			ret = gpio_direction_input(phy->gpio_id_det);
+			ret = dm_gpio_set_dir_flags(&phy->gpio_id_det,
+						GPIOD_IS_IN | GPIOD_PULL_UP);
 			if (ret)
 				return ret;
-			sunxi_gpio_set_pull(phy->gpio_id_det, SUNXI_GPIO_PULL_UP);
 		}
 
 		if (data->cfg->dedicated_clocks)