Commit ce15ed4c authored by Hans de Goede's avatar Hans de Goede Committed by Felipe Balbi

USB: Fix of_usb_get_dr_mode_by_phy with a shared phy block

Some SoCs have a single phy-hw-block with multiple phys, this is
modelled by a single phy dts node, so we end up with multiple
controller nodes with a phys property pointing to the phy-node
of the otg-phy.

Only one of these controllers typically is an otg controller, yet we
were checking the first controller who uses a phy from the block and
then end up looking for a dr_mode property in e.g. the ehci controller.

This commit fixes this by adding an arg0 parameter to
of_usb_get_dr_mode_by_phy and make of_usb_get_dr_mode_by_phy
check that this matches the phandle args[0] value when looking for
the otg controller.
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 882bd9fc
...@@ -131,15 +131,17 @@ EXPORT_SYMBOL_GPL(usb_get_dr_mode); ...@@ -131,15 +131,17 @@ EXPORT_SYMBOL_GPL(usb_get_dr_mode);
* of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device
* which is associated with the given phy device_node * which is associated with the given phy device_node
* @np: Pointer to the given phy device_node * @np: Pointer to the given phy device_node
* @arg0: phandle args[0] for phy's with #phy-cells >= 1, or -1 for
* phys which do not have phy-cells
* *
* In dts a usb controller associates with phy devices. The function gets * In dts a usb controller associates with phy devices. The function gets
* the string from property 'dr_mode' of the controller associated with the * the string from property 'dr_mode' of the controller associated with the
* given phy device node, and returns the correspondig enum usb_dr_mode. * given phy device node, and returns the correspondig enum usb_dr_mode.
*/ */
enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np) enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0)
{ {
struct device_node *controller = NULL; struct device_node *controller = NULL;
struct device_node *phy; struct of_phandle_args args;
const char *dr_mode; const char *dr_mode;
int index; int index;
int err; int err;
...@@ -148,12 +150,24 @@ enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np) ...@@ -148,12 +150,24 @@ enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np)
controller = of_find_node_with_property(controller, "phys"); controller = of_find_node_with_property(controller, "phys");
index = 0; index = 0;
do { do {
phy = of_parse_phandle(controller, "phys", index); if (arg0 == -1) {
of_node_put(phy); args.np = of_parse_phandle(controller, "phys",
if (phy == phy_np) index);
args.args_count = 0;
} else {
err = of_parse_phandle_with_args(controller,
"phys", "#phy-cells",
index, &args);
if (err)
break;
}
of_node_put(args.np);
if (args.np == np && (args.args_count == 0 ||
args.args[0] == arg0))
goto finish; goto finish;
index++; index++;
} while (phy); } while (args.np);
} while (controller); } while (controller);
finish: finish:
......
...@@ -54,7 +54,7 @@ static int am335x_phy_probe(struct platform_device *pdev) ...@@ -54,7 +54,7 @@ static int am335x_phy_probe(struct platform_device *pdev)
return am_phy->id; return am_phy->id;
} }
am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node); am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node, -1);
ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, NULL); ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, NULL);
if (ret) if (ret)
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <linux/usb/phy.h> #include <linux/usb/phy.h>
#if IS_ENABLED(CONFIG_OF) #if IS_ENABLED(CONFIG_OF)
enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np); enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0);
bool of_usb_host_tpl_support(struct device_node *np); bool of_usb_host_tpl_support(struct device_node *np);
int of_usb_update_otg_caps(struct device_node *np, int of_usb_update_otg_caps(struct device_node *np,
struct usb_otg_caps *otg_caps); struct usb_otg_caps *otg_caps);
...@@ -20,7 +20,7 @@ struct device_node *usb_of_get_child_node(struct device_node *parent, ...@@ -20,7 +20,7 @@ struct device_node *usb_of_get_child_node(struct device_node *parent,
int portnum); int portnum);
#else #else
static inline enum usb_dr_mode static inline enum usb_dr_mode
of_usb_get_dr_mode_by_phy(struct device_node *phy_np) of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0)
{ {
return USB_DR_MODE_UNKNOWN; return USB_DR_MODE_UNKNOWN;
} }
......
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