summaryrefslogtreecommitdiff
path: root/drivers/phy/allwinner/phy-sun4i-usb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/phy/allwinner/phy-sun4i-usb.c')
-rw-r--r--drivers/phy/allwinner/phy-sun4i-usb.c96
1 files changed, 32 insertions, 64 deletions
diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index b9306c9a827..3acffb40b0b 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -85,41 +85,14 @@ struct sun4i_usb_phy_cfg {
int missing_phys;
};
-struct sun4i_usb_phy_info {
- const char *gpio_vbus;
- const char *gpio_vbus_det;
- const char *gpio_id_det;
-} phy_info[] = {
- {
- .gpio_vbus = CONFIG_USB0_VBUS_PIN,
- .gpio_vbus_det = CONFIG_USB0_VBUS_DET,
- .gpio_id_det = CONFIG_USB0_ID_DET,
- },
- {
- .gpio_vbus = CONFIG_USB1_VBUS_PIN,
- .gpio_vbus_det = NULL,
- .gpio_id_det = NULL,
- },
- {
- .gpio_vbus = CONFIG_USB2_VBUS_PIN,
- .gpio_vbus_det = NULL,
- .gpio_id_det = NULL,
- },
- {
- .gpio_vbus = CONFIG_USB3_VBUS_PIN,
- .gpio_vbus_det = NULL,
- .gpio_id_det = NULL,
- },
-};
-
struct sun4i_usb_phy_plat {
void __iomem *pmu;
- struct gpio_desc gpio_vbus;
struct gpio_desc gpio_vbus_det;
struct gpio_desc gpio_id_det;
struct clk clocks;
struct clk clk2;
struct reset_ctl resets;
+ struct udevice *vbus;
int id;
};
@@ -208,6 +181,7 @@ static int sun4i_usb_phy_power_on(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];
+ int ret;
if (initial_usb_scan_delay) {
mdelay(initial_usb_scan_delay);
@@ -220,8 +194,9 @@ static int sun4i_usb_phy_power_on(struct phy *phy)
return 0;
}
- if (dm_gpio_is_valid(&usb_phy->gpio_vbus))
- dm_gpio_set_value(&usb_phy->gpio_vbus, 1);
+ ret = regulator_set_enable_if_allowed(usb_phy->vbus, true);
+ if (ret)
+ return ret;
return 0;
}
@@ -230,9 +205,11 @@ 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];
+ int ret;
- if (dm_gpio_is_valid(&usb_phy->gpio_vbus))
- dm_gpio_set_value(&usb_phy->gpio_vbus, 0);
+ ret = regulator_set_enable_if_allowed(usb_phy->vbus, false);
+ if (ret)
+ return ret;
return 0;
}
@@ -481,48 +458,39 @@ static int sun4i_usb_phy_probe(struct udevice *dev)
data->usb_phy = plat;
for (i = 0; i < data->cfg->num_phys; i++) {
struct sun4i_usb_phy_plat *phy = &plat[i];
- struct sun4i_usb_phy_info *info = &phy_info[i];
- char name[16];
+ char name[32];
if (data->cfg->missing_phys & BIT(i))
continue;
- 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 = 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;
- }
-
- 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 = dm_gpio_set_dir_flags(&phy->gpio_vbus_det,
- GPIOD_IS_IN);
+ snprintf(name, sizeof(name), "usb%d_vbus-supply", i);
+ ret = device_get_supply_regulator(dev, name, &phy->vbus);
+ if (phy->vbus) {
+ ret = regulator_set_enable_if_allowed(phy->vbus, false);
if (ret)
return ret;
}
- 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)
+ if (i == 0) {
+ ret = gpio_request_by_name(dev, "usb0_vbus_det-gpios",
+ 0, &phy->gpio_vbus_det,
+ GPIOD_IS_IN);
+ if (ret && ret != -ENOENT) {
+ dev_err(dev,
+ "failed to get VBUS detect GPIO: %d\n",
+ ret);
return ret;
- ret = dm_gpio_set_dir_flags(&phy->gpio_id_det,
- GPIOD_IS_IN | GPIOD_PULL_UP);
- if (ret)
+ }
+
+ ret = gpio_request_by_name(dev, "usb0_id_det-gpios", 0,
+ &phy->gpio_id_det,
+ GPIOD_IS_IN | GPIOD_PULL_UP);
+ if (ret && ret != -ENOENT) {
+ dev_err(dev,
+ "failed to get ID detect GPIO: %d\n",
+ ret);
return ret;
+ }
}
if (data->cfg->dedicated_clocks)