On 10/16/26 9:25 AM, Mehmet Fide wrote:

[...]

@@ -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 */
-};

Please split this into two patches:
- First - only the macro replacements
- Second - any additional clean ups

The current combined state makes this hard to review, and also the second part is currently missing error checking (please see below)

[...]

@@ -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);

This has to check return value, gpio_request_by_name() can return negative error.

+               if (dm_gpio_is_valid(&priv->cdet_gpio) &&
+                   !dm_gpio_get_value(&priv->cdet_gpio))

This has to check return value, dm_gpio_get_value() can return negative error.

                        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;

Thus far, USB_DR_MODE_UNKNOWN or equivalent undecodable dr_mode made this function return -EINVAL ...

-               }
-       } else {
-               priv->dr_mode = DR_MODE_HOST;
+               break;
+       default:

... Now it seems to be handled as host ?

                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;
  }

Reply via email to