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 * const compat_usb_fsl[] = {
29 static int fdt_usb_get_node_type(void *blob, int start_offset,
30 int *node_offset, const char **node_type)
35 for (i = 0; compat_usb_fsl[i]; i++) {
36 *node_offset = fdt_node_offset_by_compatible
39 if (*node_offset >= 0) {
40 *node_type = compat_usb_fsl[i];
49 static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
50 const char *phy_type, int start_offset)
52 const char *prop_mode = "dr_mode";
53 const char *prop_type = "phy_type";
54 const char *node_type = NULL;
58 err = fdt_usb_get_node_type(blob, start_offset,
59 &node_offset, &node_type);
64 err = fdt_setprop(blob, node_offset, prop_mode, mode,
67 printf("WARNING: could not set %s for %s: %s.\n",
68 prop_mode, node_type, fdt_strerror(err));
72 err = fdt_setprop(blob, node_offset, prop_type, phy_type,
73 strlen(phy_type) + 1);
75 printf("WARNING: could not set %s for %s: %s.\n",
76 prop_type, node_type, fdt_strerror(err));
82 static int fdt_fixup_usb_erratum(void *blob, const char *prop_erratum,
86 const char *node_type = NULL;
88 err = fdt_usb_get_node_type(blob, start_offset,
89 &node_offset, &node_type);
93 err = fdt_setprop(blob, node_offset, prop_erratum, NULL, 0);
95 printf("ERROR: could not set %s for %s: %s.\n",
96 prop_erratum, node_type, fdt_strerror(err));
102 void fdt_fixup_dr_usb(void *blob, bd_t *bd)
104 static const char * const modes[] = { "host", "peripheral", "otg" };
105 static const char * const phys[] = { "ulpi", "utmi", "utmi_dual" };
106 int usb_erratum_a006261_off = -1;
107 int usb_erratum_a007075_off = -1;
108 int usb_erratum_a007792_off = -1;
109 int usb_erratum_a005697_off = -1;
110 int usb_mode_off = -1;
111 int usb_phy_off = -1;
115 for (i = 1; i <= CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
116 const char *dr_mode_type = NULL;
117 const char *dr_phy_type = NULL;
118 int mode_idx = -1, phy_idx = -1;
120 snprintf(str, 5, "%s%d", "usb", i);
122 for (j = 0; j < ARRAY_SIZE(modes); j++) {
123 if (hwconfig_subarg_cmp(str, "dr_mode",
130 for (j = 0; j < ARRAY_SIZE(phys); j++) {
131 if (hwconfig_subarg_cmp(str, "phy_type",
138 if (mode_idx < 0 && phy_idx < 0) {
139 printf("WARNING: invalid phy or mode\n");
144 dr_mode_type = modes[mode_idx];
147 dr_phy_type = phys[phy_idx];
151 dr_phy_type = phys[2];
153 usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
157 if (usb_mode_off < 0)
160 usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
167 if (has_erratum_a006261()) {
168 usb_erratum_a006261_off = fdt_fixup_usb_erratum
170 "fsl,usb-erratum-a006261",
171 usb_erratum_a006261_off);
172 if (usb_erratum_a006261_off < 0)
176 if (has_erratum_a007075()) {
177 usb_erratum_a007075_off = fdt_fixup_usb_erratum
179 "fsl,usb-erratum-a007075",
180 usb_erratum_a007075_off);
181 if (usb_erratum_a007075_off < 0)
185 if (has_erratum_a007792()) {
186 usb_erratum_a007792_off = fdt_fixup_usb_erratum
188 "fsl,usb-erratum-a007792",
189 usb_erratum_a007792_off);
190 if (usb_erratum_a007792_off < 0)
193 if (has_erratum_a005697()) {
194 usb_erratum_a005697_off = fdt_fixup_usb_erratum
196 "fsl,usb-erratum-a005697",
197 usb_erratum_a005697_off);
198 if (usb_erratum_a005697_off < 0)