Commit 5311a7b8 authored by Thierry Reding's avatar Thierry Reding Committed by Kishon Vijay Abraham I

phy: tegra: xusb: Parse dual-role mode property

The device tree bindings document the "mode" property of "ports"
subnodes, but the driver was not parsing the property. In preparation
for adding role switching, parse the property at probe time.

Based on work by JC Kuo <jckuo@nvidia.com>.
Reviewed-by: default avatarJC Kuo <jckuo@nvidia.com>
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
parent 3cffa081
...@@ -546,13 +546,34 @@ static void tegra_xusb_port_unregister(struct tegra_xusb_port *port) ...@@ -546,13 +546,34 @@ static void tegra_xusb_port_unregister(struct tegra_xusb_port *port)
device_unregister(&port->dev); device_unregister(&port->dev);
} }
static const char *const modes[] = {
[USB_DR_MODE_UNKNOWN] = "",
[USB_DR_MODE_HOST] = "host",
[USB_DR_MODE_PERIPHERAL] = "peripheral",
[USB_DR_MODE_OTG] = "otg",
};
static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2) static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2)
{ {
struct tegra_xusb_port *port = &usb2->base; struct tegra_xusb_port *port = &usb2->base;
struct device_node *np = port->dev.of_node; struct device_node *np = port->dev.of_node;
const char *mode;
usb2->internal = of_property_read_bool(np, "nvidia,internal"); usb2->internal = of_property_read_bool(np, "nvidia,internal");
if (!of_property_read_string(np, "mode", &mode)) {
int err = match_string(modes, ARRAY_SIZE(modes), mode);
if (err < 0) {
dev_err(&port->dev, "invalid value %s for \"mode\"\n",
mode);
usb2->mode = USB_DR_MODE_UNKNOWN;
} else {
usb2->mode = err;
}
} else {
usb2->mode = USB_DR_MODE_HOST;
}
usb2->supply = devm_regulator_get(&port->dev, "vbus"); usb2->supply = devm_regulator_get(&port->dev, "vbus");
return PTR_ERR_OR_ZERO(usb2->supply); return PTR_ERR_OR_ZERO(usb2->supply);
} }
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/usb/otg.h>
/* legacy entry points for backwards-compatibility */ /* legacy entry points for backwards-compatibility */
int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev); int tegra_xusb_padctl_legacy_probe(struct platform_device *pdev);
int tegra_xusb_padctl_legacy_remove(struct platform_device *pdev); int tegra_xusb_padctl_legacy_remove(struct platform_device *pdev);
...@@ -271,6 +273,7 @@ struct tegra_xusb_usb2_port { ...@@ -271,6 +273,7 @@ struct tegra_xusb_usb2_port {
struct tegra_xusb_port base; struct tegra_xusb_port base;
struct regulator *supply; struct regulator *supply;
enum usb_dr_mode mode;
bool internal; bool internal;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment