phy-sun4i-usb: Simplify missing dr_mode handling
If we cannot get dr_mode or no id gpio is specified simply assume peripheral mode, as this is always safe. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
This commit is contained in:
parent
36f9159ba9
commit
5f90d31cab
|
@ -124,7 +124,6 @@ struct sun4i_usb_phy_data {
|
||||||
bool regulator_on;
|
bool regulator_on;
|
||||||
int index;
|
int index;
|
||||||
} phys[MAX_PHYS];
|
} phys[MAX_PHYS];
|
||||||
int first_phy;
|
|
||||||
/* phy0 / otg related variables */
|
/* phy0 / otg related variables */
|
||||||
struct extcon_dev *extcon;
|
struct extcon_dev *extcon;
|
||||||
bool phy0_init;
|
bool phy0_init;
|
||||||
|
@ -326,7 +325,10 @@ static int sun4i_usb_phy0_get_id_det(struct sun4i_usb_phy_data *data)
|
||||||
{
|
{
|
||||||
switch (data->dr_mode) {
|
switch (data->dr_mode) {
|
||||||
case USB_DR_MODE_OTG:
|
case USB_DR_MODE_OTG:
|
||||||
return gpiod_get_value_cansleep(data->id_det_gpio);
|
if (data->id_det_gpio)
|
||||||
|
return gpiod_get_value_cansleep(data->id_det_gpio);
|
||||||
|
else
|
||||||
|
return 1; /* Fallback to peripheral mode */
|
||||||
case USB_DR_MODE_HOST:
|
case USB_DR_MODE_HOST:
|
||||||
return 0;
|
return 0;
|
||||||
case USB_DR_MODE_PERIPHERAL:
|
case USB_DR_MODE_PERIPHERAL:
|
||||||
|
@ -539,8 +541,7 @@ static struct phy *sun4i_usb_phy_xlate(struct device *dev,
|
||||||
{
|
{
|
||||||
struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
|
struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
|
||||||
|
|
||||||
if (args->args[0] < data->first_phy ||
|
if (args->args[0] >= data->cfg->num_phys)
|
||||||
args->args[0] >= data->cfg->num_phys)
|
|
||||||
return ERR_PTR(-ENODEV);
|
return ERR_PTR(-ENODEV);
|
||||||
|
|
||||||
return data->phys[args->args[0]].phy;
|
return data->phys[args->args[0]].phy;
|
||||||
|
@ -615,33 +616,18 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0);
|
data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0);
|
||||||
switch (data->dr_mode) {
|
|
||||||
case USB_DR_MODE_OTG:
|
|
||||||
/* otg without id_det makes no sense, and is not supported */
|
|
||||||
if (!data->id_det_gpio) {
|
|
||||||
dev_err(dev, "usb0_id_det missing or invalid\n");
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
/* fall through */
|
|
||||||
case USB_DR_MODE_HOST:
|
|
||||||
case USB_DR_MODE_PERIPHERAL:
|
|
||||||
data->extcon = devm_extcon_dev_allocate(dev,
|
|
||||||
sun4i_usb_phy0_cable);
|
|
||||||
if (IS_ERR(data->extcon))
|
|
||||||
return PTR_ERR(data->extcon);
|
|
||||||
|
|
||||||
ret = devm_extcon_dev_register(dev, data->extcon);
|
data->extcon = devm_extcon_dev_allocate(dev, sun4i_usb_phy0_cable);
|
||||||
if (ret) {
|
if (IS_ERR(data->extcon))
|
||||||
dev_err(dev, "failed to register extcon: %d\n", ret);
|
return PTR_ERR(data->extcon);
|
||||||
return ret;
|
|
||||||
}
|
ret = devm_extcon_dev_register(dev, data->extcon);
|
||||||
break;
|
if (ret) {
|
||||||
default:
|
dev_err(dev, "failed to register extcon: %d\n", ret);
|
||||||
dev_info(dev, "dr_mode unknown, not registering usb phy0\n");
|
return ret;
|
||||||
data->first_phy = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = data->first_phy; i < data->cfg->num_phys; i++) {
|
for (i = 0; i < data->cfg->num_phys; i++) {
|
||||||
struct sun4i_usb_phy *phy = data->phys + i;
|
struct sun4i_usb_phy *phy = data->phys + i;
|
||||||
char name[16];
|
char name[16];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue