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+
15 #include <fsl_errata.h>
17 #include <fdt_support.h>
19 #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
20 #define CONFIG_USB_MAX_CONTROLLER_COUNT 1
24 #define FSL_USB2_MPH "fsl-usb2-mph"
25 #define FSL_USB2_DR "fsl-usb2-dr"
26 #define CHIPIDEA_USB2 "chipidea,usb2"
27 #define SNPS_DWC3 "snps,dwc3"
29 static const char * const compat_usb_fsl[] = {
36 static int fdt_usb_get_node_type(void *blob, int start_offset,
37 int *node_offset, const char **node_type)
42 for (i = 0; compat_usb_fsl[i]; i++) {
43 *node_offset = fdt_node_offset_by_compatible
46 if (*node_offset >= 0) {
47 *node_type = compat_usb_fsl[i];
56 static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
57 const char *phy_type, int start_offset)
59 const char *prop_mode = "dr_mode";
60 const char *prop_type = "phy_type";
61 const char *node_type = NULL;
65 err = fdt_usb_get_node_type(blob, start_offset,
66 &node_offset, &node_type);
71 err = fdt_setprop(blob, node_offset, prop_mode, mode,
74 printf("WARNING: could not set %s for %s: %s.\n",
75 prop_mode, node_type, fdt_strerror(err));
79 err = fdt_setprop(blob, node_offset, prop_type, phy_type,
80 strlen(phy_type) + 1);
82 printf("WARNING: could not set %s for %s: %s.\n",
83 prop_type, node_type, fdt_strerror(err));
89 static int fsl_fdt_fixup_usb_erratum(void *blob, const char *prop_erratum,
90 const char *controller_type,
94 const char *node_type = NULL;
95 const char *node_name = NULL;
97 err = fdt_usb_get_node_type(blob, start_offset,
98 &node_offset, &node_type);
102 if (!strcmp(node_type, FSL_USB2_MPH) || !strcmp(node_type, FSL_USB2_DR))
103 node_name = CHIPIDEA_USB2;
105 node_name = node_type;
106 if (strcmp(node_name, controller_type))
109 err = fdt_setprop(blob, node_offset, prop_erratum, NULL, 0);
111 printf("ERROR: could not set %s for %s: %s.\n",
112 prop_erratum, node_type, fdt_strerror(err));
118 static int fsl_fdt_fixup_erratum(int *usb_erratum_off, void *blob,
119 const char *controller_type, char *str,
120 bool (*has_erratum)(void))
124 snprintf(buf, sizeof(buf), "fsl,usb-erratum-%s", str);
127 *usb_erratum_off = fsl_fdt_fixup_usb_erratum(blob, buf, controller_type,
129 if (*usb_erratum_off < 0)
131 debug("Adding USB erratum %s\n", str);
135 void fsl_fdt_fixup_dr_usb(void *blob, bd_t *bd)
137 static const char * const modes[] = { "host", "peripheral", "otg" };
138 static const char * const phys[] = { "ulpi", "utmi", "utmi_dual" };
139 int usb_erratum_a006261_off = -1;
140 int usb_erratum_a007075_off = -1;
141 int usb_erratum_a007792_off = -1;
142 int usb_erratum_a005697_off = -1;
143 int usb_erratum_a008751_off = -1;
144 int usb_mode_off = -1;
145 int usb_phy_off = -1;
150 for (i = 1; i <= CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
151 const char *dr_mode_type = NULL;
152 const char *dr_phy_type = NULL;
153 int mode_idx = -1, phy_idx = -1;
155 snprintf(str, 5, "%s%d", "usb", i);
157 for (j = 0; j < ARRAY_SIZE(modes); j++) {
158 if (hwconfig_subarg_cmp(str, "dr_mode",
165 for (j = 0; j < ARRAY_SIZE(phys); j++) {
166 if (hwconfig_subarg_cmp(str, "phy_type",
173 if (mode_idx < 0 && phy_idx < 0) {
174 printf("WARNING: invalid phy or mode\n");
179 dr_mode_type = modes[mode_idx];
182 dr_phy_type = phys[phy_idx];
186 dr_phy_type = phys[2];
188 usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
192 if (usb_mode_off < 0)
195 usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
202 ret = fsl_fdt_fixup_erratum(&usb_erratum_a006261_off, blob,
203 CHIPIDEA_USB2, "a006261",
204 has_erratum_a006261);
207 ret = fsl_fdt_fixup_erratum(&usb_erratum_a007075_off, blob,
208 CHIPIDEA_USB2, "a007075",
209 has_erratum_a007075);
212 ret = fsl_fdt_fixup_erratum(&usb_erratum_a007792_off, blob,
213 CHIPIDEA_USB2, "a007792",
214 has_erratum_a007792);
217 ret = fsl_fdt_fixup_erratum(&usb_erratum_a005697_off, blob,
218 CHIPIDEA_USB2, "a005697",
219 has_erratum_a005697);
222 ret = fsl_fdt_fixup_erratum(&usb_erratum_a008751_off, blob,
223 SNPS_DWC3, "a008751",
224 has_erratum_a008751);