From: Mehmet Fide <[email protected]>

The driver parses the dr_mode property itself, through the flat tree,
into an enum of its own that mirrors enum usb_dr_mode. Use
usb_get_dr_mode() and USB_DR_MODE_* instead, as ehci-mx6 does, and take
the ID detect GPIO through the device rather than its flat node. A
dr_mode value the driver does not know now means host, as a missing
property already did.

Signed-off-by: Mehmet Fide <[email protected]>
---

Notes:
    Changes in v6:
    - new patch, from the review of the register base patch in v5: the
      private enum duplicated USB_DR_MODE_*

 drivers/usb/host/ehci-vf.c | 65 ++++++++------------------------------
 1 file changed, 14 insertions(+), 51 deletions(-)

diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index e5f9ec0fdbb..4009eaef6a1 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -10,7 +10,6 @@
 #include <log.h>
 #include <usb.h>
 #include <errno.h>
-#include <asm/global_data.h>
 #include <linux/compiler.h>
 #include <asm/io.h>
 #include <asm-generic/gpio.h>
@@ -21,8 +20,8 @@
 #include <asm/mach-imx/regs-usbphy.h>
 #include <linux/delay.h>
 #include <usb/ehci-ci.h>
-#include <linux/libfdt.h>
 #include <fdtdec.h>
+#include <linux/usb/otg.h>
 
 #include "ehci.h"
 
@@ -37,8 +36,6 @@
 #define UCMD_RUN_STOP          (1 << 0) /* controller run/stop */
 #define UCMD_RESET                     (1 << 1) /* controller reset */
 
-DECLARE_GLOBAL_DATA_PTR;
-
 static const unsigned phy_bases[] = {
        USB_PHY0_BASE_ADDR,
        USB_PHY1_BASE_ADDR,
@@ -150,29 +147,17 @@ int ehci_vf_common_init(struct usb_ehci *ehci, int index)
        return 0;
 }
 
-/* Possible port types (dual role mode) */
-enum dr_mode {
-       DR_MODE_NONE = 0,
-       DR_MODE_HOST,           /* supports host operation */
-       DR_MODE_DEVICE,         /* supports device operation */
-       DR_MODE_OTG,            /* supports both */
-};
-
 struct ehci_vf_priv_data {
        struct ehci_ctrl ctrl;
        struct usb_ehci *ehci;
        struct gpio_desc cdet_gpio;
        enum usb_init_type init_type;
-       enum dr_mode dr_mode;
        u32 portnr;
 };
 
 static int vf_usb_of_to_plat(struct udevice *dev)
 {
        struct ehci_vf_priv_data *priv = dev_get_priv(dev);
-       const void *dt_blob = gd->fdt_blob;
-       int node = dev_of_offset(dev);
-       const char *mode;
        fdt_addr_t phy_addr;
        ofnode phy_node;
        int i;
@@ -192,45 +177,23 @@ static int vf_usb_of_to_plat(struct udevice *dev)
        priv->portnr = i;
 
        priv->ehci = dev_read_addr_ptr(dev);
-       mode = fdt_getprop(dt_blob, node, "dr_mode", NULL);
-       if (mode) {
-               if (0 == strcmp(mode, "host")) {
-                       priv->dr_mode = DR_MODE_HOST;
+
+       switch (usb_get_dr_mode(dev_ofnode(dev))) {
+       case USB_DR_MODE_PERIPHERAL:
+               priv->init_type = USB_INIT_DEVICE;
+               break;
+       case USB_DR_MODE_OTG:
+               priv->init_type = USB_INIT_DEVICE;
+               gpio_request_by_name(dev, "fsl,cdet-gpio", 0,
+                                    &priv->cdet_gpio, GPIOD_IS_IN);
+               if (dm_gpio_is_valid(&priv->cdet_gpio) &&
+                   !dm_gpio_get_value(&priv->cdet_gpio))
                        priv->init_type = USB_INIT_HOST;
-               } else if (0 == strcmp(mode, "peripheral")) {
-                       priv->dr_mode = DR_MODE_DEVICE;
-                       priv->init_type = USB_INIT_DEVICE;
-               } else if (0 == strcmp(mode, "otg")) {
-                       priv->dr_mode = DR_MODE_OTG;
-                       /*
-                        * We set init_type to device by default when OTG
-                        * mode is requested. If a valid gpio is provided
-                        * we will switch the init_type based on the state
-                        * of the gpio pin.
-                        */
-                       priv->init_type = USB_INIT_DEVICE;
-               } else {
-                       debug("%s: Cannot decode dr_mode '%s'\n",
-                             __func__, mode);
-                       return -EINVAL;
-               }
-       } else {
-               priv->dr_mode = DR_MODE_HOST;
+               break;
+       default:
                priv->init_type = USB_INIT_HOST;
        }
 
-       if (priv->dr_mode == DR_MODE_OTG) {
-               gpio_request_by_name_nodev(offset_to_ofnode(node),
-                                          "fsl,cdet-gpio", 0, &priv->cdet_gpio,
-                                          GPIOD_IS_IN);
-               if (dm_gpio_is_valid(&priv->cdet_gpio)) {
-                       if (dm_gpio_get_value(&priv->cdet_gpio))
-                               priv->init_type = USB_INIT_DEVICE;
-                       else
-                               priv->init_type = USB_INIT_HOST;
-               }
-       }
-
        return 0;
 }
 
-- 
2.55.0

Reply via email to