1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2009, 2011 Freescale Semiconductor, Inc.
5 * (C) Copyright 2008, Excito Elektronik i Sk=E5ne AB
7 * Author: Tor Krill tor@excito.com
15 #include <fsl_errata.h>
17 #include <fdt_support.h>
20 #define FSL_USB2_MPH "fsl-usb2-mph"
21 #define FSL_USB2_DR "fsl-usb2-dr"
22 #define CHIPIDEA_USB2 "chipidea,usb2"
23 #define SNPS_DWC3 "snps,dwc3"
25 static const char * const compat_usb_fsl[] = {
32 static int fdt_usb_get_node_type(void *blob, int start_offset,
33 int *node_offset, const char **node_type)
38 for (i = 0; compat_usb_fsl[i]; i++) {
39 *node_offset = fdt_node_offset_by_compatible
42 if (*node_offset >= 0) {
43 *node_type = compat_usb_fsl[i];
52 static int fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
53 const char *phy_type, int start_offset)
55 const char *prop_mode = "dr_mode";
56 const char *prop_type = "phy_type";
57 const char *node_type = NULL;
61 err = fdt_usb_get_node_type(blob, start_offset,
62 &node_offset, &node_type);
67 err = fdt_setprop(blob, node_offset, prop_mode, mode,
70 printf("WARNING: could not set %s for %s: %s.\n",
71 prop_mode, node_type, fdt_strerror(err));
75 err = fdt_setprop(blob, node_offset, prop_type, phy_type,
76 strlen(phy_type) + 1);
78 printf("WARNING: could not set %s for %s: %s.\n",
79 prop_type, node_type, fdt_strerror(err));
85 static int fsl_fdt_fixup_usb_erratum(void *blob, const char *prop_erratum,
86 const char *controller_type,
90 const char *node_type = NULL;
91 const char *node_name = NULL;
93 err = fdt_usb_get_node_type(blob, start_offset,
94 &node_offset, &node_type);
98 if (!strcmp(node_type, FSL_USB2_MPH) || !strcmp(node_type, FSL_USB2_DR))
99 node_name = CHIPIDEA_USB2;
101 node_name = node_type;
102 if (strcmp(node_name, controller_type))
105 err = fdt_setprop(blob, node_offset, prop_erratum, NULL, 0);
107 printf("ERROR: could not set %s for %s: %s.\n",
108 prop_erratum, node_type, fdt_strerror(err));
114 static int fsl_fdt_fixup_erratum(int *usb_erratum_off, void *blob,
115 const char *controller_type, char *str,
116 bool (*has_erratum)(void))
120 snprintf(buf, sizeof(buf), "fsl,usb-erratum-%s", str);
123 *usb_erratum_off = fsl_fdt_fixup_usb_erratum(blob, buf, controller_type,
125 if (*usb_erratum_off < 0)
127 debug("Adding USB erratum %s\n", str);
131 void fsl_fdt_fixup_dr_usb(void *blob, struct bd_info *bd)
133 static const char * const modes[] = { "host", "peripheral", "otg" };
134 static const char * const phys[] = { "ulpi", "utmi", "utmi_dual" };
135 int usb_erratum_a006261_off = -1;
136 int usb_erratum_a007075_off = -1;
137 int usb_erratum_a007792_off = -1;
138 int usb_erratum_a005697_off = -1;
139 int usb_erratum_a008751_off = -1;
140 int usb_mode_off = -1;
141 int usb_phy_off = -1;
146 for (i = 1; i <= CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
147 const char *dr_mode_type = NULL;
148 const char *dr_phy_type = NULL;
149 int mode_idx = -1, phy_idx = -1;
151 snprintf(str, 5, "%s%d", "usb", i);
153 for (j = 0; j < ARRAY_SIZE(modes); j++) {
154 if (hwconfig_subarg_cmp(str, "dr_mode",
161 for (j = 0; j < ARRAY_SIZE(phys); j++) {
162 if (hwconfig_subarg_cmp(str, "phy_type",
169 if (mode_idx < 0 && phy_idx < 0) {
170 printf("WARNING: invalid phy or mode\n");
175 dr_mode_type = modes[mode_idx];
178 dr_phy_type = phys[phy_idx];
182 dr_phy_type = phys[2];
184 usb_mode_off = fdt_fixup_usb_mode_phy_type(blob,
188 if (usb_mode_off < 0)
191 usb_phy_off = fdt_fixup_usb_mode_phy_type(blob,
198 ret = fsl_fdt_fixup_erratum(&usb_erratum_a006261_off, blob,
199 CHIPIDEA_USB2, "a006261",
200 has_erratum_a006261);
203 ret = fsl_fdt_fixup_erratum(&usb_erratum_a007075_off, blob,
204 CHIPIDEA_USB2, "a007075",
205 has_erratum_a007075);
208 ret = fsl_fdt_fixup_erratum(&usb_erratum_a007792_off, blob,
209 CHIPIDEA_USB2, "a007792",
210 has_erratum_a007792);
213 ret = fsl_fdt_fixup_erratum(&usb_erratum_a005697_off, blob,
214 CHIPIDEA_USB2, "a005697",
215 has_erratum_a005697);
218 ret = fsl_fdt_fixup_erratum(&usb_erratum_a008751_off, blob,
219 SNPS_DWC3, "a008751",
220 has_erratum_a008751);