2 * (C) Copyright 2009, 2011 Freescale Semiconductor, Inc.
4 * (C) Copyright 2008, Excito Elektronik i Sk=E5ne AB
6 * Author: Tor Krill tor@excito.com
8 * SPDX-License-Identifier: GPL-2.0+
16 #include <fdt_support.h>
18 #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
19 #define CONFIG_USB_MAX_CONTROLLER_COUNT 1
22 static const char *fdt_usb_get_node_type(void *blob, int start_offset,
25 const char *compat_dr = "fsl-usb2-dr";
26 const char *compat_mph = "fsl-usb2-mph";
27 const char *node_type = NULL;
29 *node_offset = fdt_node_offset_by_compatible(blob, start_offset,
31 if (*node_offset < 0) {
32 *node_offset = fdt_node_offset_by_compatible(blob,
35 if (*node_offset < 0) {
36 printf("ERROR: could not find compatible node: %s\n",
37 fdt_strerror(*node_offset));
39 node_type = compat_dr;
42 node_type = compat_mph;
48 static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
49 const char *phy_type, int start_offset)
51 const char *prop_mode = "dr_mode";
52 const char *prop_type = "phy_type";
53 const char *node_type = NULL;
57 node_type = fdt_usb_get_node_type(blob, start_offset, &node_offset);
62 err = fdt_setprop(blob, node_offset, prop_mode, mode,
65 printf("WARNING: could not set %s for %s: %s.\n",
66 prop_mode, node_type, fdt_strerror(err));
70 err = fdt_setprop(blob, node_offset, prop_type, phy_type,
71 strlen(phy_type) + 1);
73 printf("WARNING: could not set %s for %s: %s.\n",
74 prop_type, node_type, fdt_strerror(err));
80 static int fdt_fixup_usb_erratum(void *blob, const char *prop_erratum,
84 const char *node_type = NULL;
86 node_type = fdt_usb_get_node_type(blob, start_offset, &node_offset);
90 err = fdt_setprop(blob, node_offset, prop_erratum, NULL, 0);
92 printf("ERROR: could not set %s for %s: %s.\n",
93 prop_erratum, node_type, fdt_strerror(err));
99 void fdt_fixup_dr_usb(void *blob, bd_t *bd)
101 static const char * const modes[] = { "host", "peripheral", "otg" };
102 static const char * const phys[] = { "ulpi", "utmi", "utmi_dual" };
103 int usb_erratum_a006261_off = -1;
104 int usb_erratum_a007075_off = -1;
105 int usb_erratum_a007792_off = -1;
106 int usb_erratum_a005697_off = -1;
107 int usb_mode_off = -1;
108 int usb_phy_off = -1;
112 for (i = 1; i <= CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
113 const char *dr_mode_type = NULL;
114 const char *dr_phy_type = NULL;
115 int mode_idx = -1, phy_idx = -1;
117 snprintf(str, 5, "%s%d", "usb", i);
119 for (j = 0; j < ARRAY_SIZE(modes); j++) {
120 if (hwconfig_subarg_cmp(str, "dr_mode",
127 for (j = 0; j < ARRAY_SIZE(phys); j++) {
128 if (hwconfig_subarg_cmp(str, "phy_type",
135 if (mode_idx < 0 && phy_idx < 0) {
136 printf("WARNING: invalid phy or mode\n");
141 dr_mode_type = modes[mode_idx];
144 dr_phy_type = phys[phy_idx];
148 dr_phy_type = phys[2];
150 usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
154 if (usb_mode_off < 0)
157 usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
164 if (has_erratum_a006261()) {
165 usb_erratum_a006261_off = fdt_fixup_usb_erratum
167 "fsl,usb-erratum-a006261",
168 usb_erratum_a006261_off);
169 if (usb_erratum_a006261_off < 0)
173 if (has_erratum_a007075()) {
174 usb_erratum_a007075_off = fdt_fixup_usb_erratum
176 "fsl,usb-erratum-a007075",
177 usb_erratum_a007075_off);
178 if (usb_erratum_a007075_off < 0)
182 if (has_erratum_a007792()) {
183 usb_erratum_a007792_off = fdt_fixup_usb_erratum
185 "fsl,usb-erratum-a007792",
186 usb_erratum_a007792_off);
187 if (usb_erratum_a007792_off < 0)
190 if (has_erratum_a005697()) {
191 usb_erratum_a005697_off = fdt_fixup_usb_erratum
193 "fsl,usb-erratum-a005697",
194 usb_erratum_a005697_off);
195 if (usb_erratum_a005697_off < 0)