+ if (otg_mode && (strcasecmp(otg_mode, "device") == 0 ||
+ strcasecmp(otg_mode, "gadget") == 0)) {
+ debug("Setting dr_mode to 'peripheral'\n");
+ ret = fdt_setprop_string(blob, off, "dr_mode", "peripheral");
+ disable_phy_pins = 1;
+ } else if (otg_mode && strcasecmp(otg_mode, "host") == 0) {
+ debug("Setting dr_mode to 'host'\n");
+ ret = fdt_setprop_string(blob, off, "dr_mode", "host");
+ } else if (otg_mode && strcasecmp(otg_mode, "otg") == 0) {
+ debug("Setting dr_mode to 'otg'\n");
+ ret = fdt_setprop_string(blob, off, "dr_mode", "otg");
+ } else {
+ if (otg_mode && strcasecmp(otg_mode, "none") != 0)
+ printf("Invalid 'otg_mode' setting '%s'; disabling usbotg port\n",
+ otg_mode);
+ disable_otg = 1;
+ ret = 0;
+ }
+
+ if ((!disable_phy_pins && !disable_otg) || ret)
+ goto out;
+
+ ret = karo_fdt_disable_node_phandle(blob, node, phy_supply);
+ if (ret && ret == -FDT_ERR_NOTFOUND) {
+ const uint32_t *ph;
+
+ ph = fdt_getprop(blob, off, phy, NULL);
+ if (ph == NULL) {
+ printf("Failed to find '%s' phandle in node '%s'\n",
+ phy, node);
+ ret = -FDT_ERR_NOTFOUND;
+ goto out;
+ }
+ off = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*ph));
+ if (off < 0) {
+ printf("Failed to find '%s' node via phandle %04x\n",
+ phy, fdt32_to_cpu(*ph));
+ ret = off;
+ goto out;
+ }
+ ph = fdt_getprop(blob, off, phy_supply, NULL);
+ if (ph == NULL) {
+ debug("Failed to find '%s' phandle in node '%s'\n",
+ phy_supply, fdt_get_name(blob, off, NULL));
+ ret = -FDT_ERR_NOTFOUND;
+ goto disable_otg;
+ }
+ ret = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*ph));
+ if (ret > 0) {
+ debug("Disabling node %s via phandle %s:%s\n",
+ fdt_get_name(blob, ret, NULL),
+ fdt_get_name(blob, off, NULL), phy_supply);
+ ret = fdt_set_node_status(blob, ret,
+ FDT_STATUS_DISABLED, 0);
+ }