UPSTREAM: USB: Fix of_usb_get_dr_mode_by_phy with a shared phy block
authorHans de Goede <hdegoede@redhat.com>
Fri, 10 Jun 2016 09:46:25 +0000 (11:46 +0200)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 12 Sep 2016 03:18:54 +0000 (11:18 +0800)
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.

Conflicts:
drivers/usb/phy/phy-am335x.c

Change-Id: I0b999a7445399cb2c86060bdf662db8aab96d1cc
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Wu Liang feng <wulf@rock-chips.com>
(cherry picked from commit ce15ed4c5dfb3f7757e6611902aed5db253af977)

drivers/usb/common/common.c
include/linux/usb/of.h

index e6ec125e4485096276b685fd12932aae44dccc87..86449fb3f5bfde822f6aa183b86e375d3d064c45 100644 (file)
@@ -136,15 +136,17 @@ EXPORT_SYMBOL_GPL(usb_get_dr_mode);
  * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device
  * which is associated with 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
  * the string from property 'dr_mode' of the controller associated with the
  * 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 *phy;
+       struct of_phandle_args args;
        const char *dr_mode;
        int index;
        int err;
@@ -153,12 +155,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");
                index = 0;
                do {
-                       phy = of_parse_phandle(controller, "phys", index);
-                       of_node_put(phy);
-                       if (phy == phy_np)
+                       if (arg0 == -1) {
+                               args.np = of_parse_phandle(controller, "phys",
+                                                       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;
                        index++;
-               } while (phy);
+               } while (args.np);
        } while (controller);
 
 finish:
index 974bce93aa28910918efa0127a40852223c4fcae..cd5be413b26581d43d2c46a2c3f6635770ede88c 100644 (file)
 #include <linux/usb/phy.h>
 
 #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);
 int of_usb_update_otg_caps(struct device_node *np,
                        struct usb_otg_caps *otg_caps);
 #else
 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;
 }