1 /*
2  * USB device controllers have lots of quirks.  Use these macros in
3  * gadget drivers or other code that needs to deal with them, and which
4  * autoconfigures instead of using early binding to the hardware.
5  *
6  * This SHOULD eventually work like the ARM mach_is_*() stuff, driven by
7  * some config file that gets updated as new hardware is supported.
8  * (And avoiding all runtime comparisons in typical one-choice configs!)
9  *
10  * NOTE:  some of these controller drivers may not be available yet.
11  * Some are available on 2.4 kernels; several are available, but not
12  * yet pushed in the 2.6 mainline tree.
13  *
14  * Ported to U-Boot by: Thomas Smits <ts.smits@gmail.com> and
15  *                      Remy Bohmer <linux@bohmer.net>
16  */
17 #ifdef CONFIG_USB_GADGET_NET2280
18 #define	gadget_is_net2280(g)	(!strcmp("net2280", (g)->name))
19 #else
20 #define	gadget_is_net2280(g)	0
21 #endif
22 
23 #ifdef CONFIG_USB_GADGET_AMD5536UDC
24 #define	gadget_is_amd5536udc(g)	(!strcmp("amd5536udc", (g)->name))
25 #else
26 #define	gadget_is_amd5536udc(g)	0
27 #endif
28 
29 #ifdef CONFIG_USB_GADGET_DUMMY_HCD
30 #define	gadget_is_dummy(g)	(!strcmp("dummy_udc", (g)->name))
31 #else
32 #define	gadget_is_dummy(g)	0
33 #endif
34 
35 #ifdef CONFIG_USB_GADGET_PXA2XX
36 #define	gadget_is_pxa(g)	(!strcmp("pxa2xx_udc", (g)->name))
37 #else
38 #define	gadget_is_pxa(g)	0
39 #endif
40 
41 #ifdef CONFIG_USB_GADGET_GOKU
42 #define	gadget_is_goku(g)	(!strcmp("goku_udc", (g)->name))
43 #else
44 #define	gadget_is_goku(g)	0
45 #endif
46 
47 /* SH3 UDC -- not yet ported 2.4 --> 2.6 */
48 #ifdef CONFIG_USB_GADGET_SUPERH
49 #define	gadget_is_sh(g)		(!strcmp("sh_udc", (g)->name))
50 #else
51 #define	gadget_is_sh(g)		0
52 #endif
53 
54 /* not yet stable on 2.6 (would help "original Zaurus") */
55 #ifdef CONFIG_USB_GADGET_SA1100
56 #define	gadget_is_sa1100(g)	(!strcmp("sa1100_udc", (g)->name))
57 #else
58 #define	gadget_is_sa1100(g)	0
59 #endif
60 
61 /* handhelds.org tree (?) */
62 #ifdef CONFIG_USB_GADGET_MQ11XX
63 #define	gadget_is_mq11xx(g)	(!strcmp("mq11xx_udc", (g)->name))
64 #else
65 #define	gadget_is_mq11xx(g)	0
66 #endif
67 
68 #ifdef CONFIG_USB_GADGET_OMAP
69 #define	gadget_is_omap(g)	(!strcmp("omap_udc", (g)->name))
70 #else
71 #define	gadget_is_omap(g)	0
72 #endif
73 
74 /* not yet ported 2.4 --> 2.6 */
75 #ifdef CONFIG_USB_GADGET_N9604
76 #define	gadget_is_n9604(g)	(!strcmp("n9604_udc", (g)->name))
77 #else
78 #define	gadget_is_n9604(g)	0
79 #endif
80 
81 /* various unstable versions available */
82 #ifdef CONFIG_USB_GADGET_PXA27X
83 #define	gadget_is_pxa27x(g)	(!strcmp("pxa27x_udc", (g)->name))
84 #else
85 #define	gadget_is_pxa27x(g)	0
86 #endif
87 
88 #ifdef CONFIG_USB_GADGET_ATMEL_USBA
89 #define gadget_is_atmel_usba(g)	(!strcmp("atmel_usba_udc", (g)->name))
90 #else
91 #define gadget_is_atmel_usba(g)	0
92 #endif
93 
94 #ifdef CONFIG_USB_GADGET_AT91
95 #define gadget_is_at91(g)	(!strcmp("at91_udc", (g)->name))
96 #else
97 #define gadget_is_at91(g)	0
98 #endif
99 
100 /* status unclear */
101 #ifdef CONFIG_USB_GADGET_IMX
102 #define gadget_is_imx(g)	(!strcmp("imx_udc", (g)->name))
103 #else
104 #define gadget_is_imx(g)	0
105 #endif
106 
107 #ifdef CONFIG_USB_GADGET_FSL_USB2
108 #define gadget_is_fsl_usb2(g)	(!strcmp("fsl-usb2-udc", (g)->name))
109 #else
110 #define gadget_is_fsl_usb2(g)	0
111 #endif
112 
113 /* Mentor high speed function controller */
114 /* from Montavista kernel (?) */
115 #ifdef CONFIG_USB_GADGET_MUSBHSFC
116 #define gadget_is_musbhsfc(g)	(!strcmp("musbhsfc_udc", (g)->name))
117 #else
118 #define gadget_is_musbhsfc(g)	0
119 #endif
120 
121 /* Mentor high speed "dual role" controller, in peripheral role */
122 #ifdef CONFIG_USB_MUSB_GADGET
123 #define gadget_is_musbhdrc(g)	(!strcmp("musb-hdrc", (g)->name))
124 #else
125 #define gadget_is_musbhdrc(g)	0
126 #endif
127 
128 #ifdef CONFIG_USB_GADGET_M66592
129 #define	gadget_is_m66592(g)	(!strcmp("m66592_udc", (g)->name))
130 #else
131 #define	gadget_is_m66592(g)	0
132 #endif
133 
134 #ifdef CONFIG_CI_UDC
135 #define gadget_is_ci(g)        (!strcmp("ci_udc", (g)->name))
136 #else
137 #define gadget_is_ci(g)        0
138 #endif
139 
140 #ifdef CONFIG_USB_GADGET_FOTG210
141 #define gadget_is_fotg210(g)        (!strcmp("fotg210_udc", (g)->name))
142 #else
143 #define gadget_is_fotg210(g)        0
144 #endif
145 
146 #ifdef CONFIG_USB_DWC3_GADGET
147 #define gadget_is_dwc3(g)        (!strcmp("dwc3-gadget", (g)->name))
148 #else
149 #define gadget_is_dwc3(g)        0
150 #endif
151 
152 #ifdef CONFIG_USB_CDNS3_GADGET
153 #define gadget_is_cdns3(g)        (!strcmp("cdns3-gadget", (g)->name))
154 #else
155 #define gadget_is_cdns3(g)        0
156 #endif
157 
158 #ifdef CONFIG_USB_GADGET_MAX3420
159 #define gadget_is_max3420(g)        (!strcmp("max3420-udc", (g)->name))
160 #else
161 #define gadget_is_max3420(g)        0
162 #endif
163 
164 #ifdef CONFIG_USB_MTU3_GADGET
165 #define gadget_is_mtu3(g)        (!strcmp("mtu3-gadget", (g)->name))
166 #else
167 #define gadget_is_mtu3(g)        0
168 #endif
169 
170 /**
171  * usb_gadget_controller_number - support bcdDevice id convention
172  * @gadget: the controller being driven
173  *
174  * Return a 2-digit BCD value associated with the peripheral controller,
175  * suitable for use as part of a bcdDevice value, or a negative error code.
176  *
177  * NOTE:  this convention is purely optional, and has no meaning in terms of
178  * any USB specification.  If you want to use a different convention in your
179  * gadget driver firmware -- maybe a more formal revision ID -- feel free.
180  *
181  * Hosts see these bcdDevice numbers, and are allowed (but not encouraged!)
182  * to change their behavior accordingly.  For example it might help avoiding
183  * some chip bug.
184  */
usb_gadget_controller_number(struct usb_gadget * gadget)185 static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
186 {
187 	if (gadget_is_net2280(gadget))
188 		return 0x01;
189 	else if (gadget_is_dummy(gadget))
190 		return 0x02;
191 	else if (gadget_is_pxa(gadget))
192 		return 0x03;
193 	else if (gadget_is_sh(gadget))
194 		return 0x04;
195 	else if (gadget_is_sa1100(gadget))
196 		return 0x05;
197 	else if (gadget_is_goku(gadget))
198 		return 0x06;
199 	else if (gadget_is_mq11xx(gadget))
200 		return 0x07;
201 	else if (gadget_is_omap(gadget))
202 		return 0x08;
203 	else if (gadget_is_n9604(gadget))
204 		return 0x09;
205 	else if (gadget_is_pxa27x(gadget))
206 		return 0x10;
207 	else if (gadget_is_at91(gadget))
208 		return 0x12;
209 	else if (gadget_is_imx(gadget))
210 		return 0x13;
211 	else if (gadget_is_musbhsfc(gadget))
212 		return 0x14;
213 	else if (gadget_is_musbhdrc(gadget))
214 		return 0x15;
215 	else if (gadget_is_atmel_usba(gadget))
216 		return 0x17;
217 	else if (gadget_is_fsl_usb2(gadget))
218 		return 0x18;
219 	else if (gadget_is_amd5536udc(gadget))
220 		return 0x19;
221 	else if (gadget_is_m66592(gadget))
222 		return 0x20;
223 	else if (gadget_is_ci(gadget))
224 		return 0x21;
225 	else if (gadget_is_fotg210(gadget))
226 		return 0x22;
227 	else if (gadget_is_dwc3(gadget))
228 		return 0x23;
229 	else if (gadget_is_cdns3(gadget))
230 		return 0x24;
231 	else if (gadget_is_max3420(gadget))
232 		return 0x25;
233 	else if (gadget_is_mtu3(gadget))
234 		return 0x26;
235 	return -ENOENT;
236 }
237