diff options
Diffstat (limited to 'drivers/usb/gadget')
72 files changed, 6338 insertions, 1493 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 029e288805b6..44b6b40aafb4 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -96,9 +96,6 @@ config USB_GADGET_VBUS_DRAW | |||
96 | This value will be used except for system-specific gadget | 96 | This value will be used except for system-specific gadget |
97 | drivers that have more specific information. | 97 | drivers that have more specific information. |
98 | 98 | ||
99 | config USB_GADGET_SELECTED | ||
100 | boolean | ||
101 | |||
102 | # | 99 | # |
103 | # USB Peripheral Controller Support | 100 | # USB Peripheral Controller Support |
104 | # | 101 | # |
@@ -122,10 +119,9 @@ choice | |||
122 | # Integrated controllers | 119 | # Integrated controllers |
123 | # | 120 | # |
124 | 121 | ||
125 | config USB_GADGET_AT91 | 122 | config USB_AT91 |
126 | boolean "Atmel AT91 USB Device Port" | 123 | tristate "Atmel AT91 USB Device Port" |
127 | depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 && !ARCH_AT91SAM9G45 | 124 | depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 && !ARCH_AT91SAM9G45 |
128 | select USB_GADGET_SELECTED | ||
129 | help | 125 | help |
130 | Many Atmel AT91 processors (such as the AT91RM2000) have a | 126 | Many Atmel AT91 processors (such as the AT91RM2000) have a |
131 | full speed USB Device Port with support for five configurable | 127 | full speed USB Device Port with support for five configurable |
@@ -135,27 +131,16 @@ config USB_GADGET_AT91 | |||
135 | dynamically linked module called "at91_udc" and force all | 131 | dynamically linked module called "at91_udc" and force all |
136 | gadget drivers to also be dynamically linked. | 132 | gadget drivers to also be dynamically linked. |
137 | 133 | ||
138 | config USB_AT91 | 134 | config USB_ATMEL_USBA |
139 | tristate | 135 | tristate "Atmel USBA" |
140 | depends on USB_GADGET_AT91 | ||
141 | default USB_GADGET | ||
142 | |||
143 | config USB_GADGET_ATMEL_USBA | ||
144 | boolean "Atmel USBA" | ||
145 | select USB_GADGET_DUALSPEED | 136 | select USB_GADGET_DUALSPEED |
146 | depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45 | 137 | depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45 |
147 | help | 138 | help |
148 | USBA is the integrated high-speed USB Device controller on | 139 | USBA is the integrated high-speed USB Device controller on |
149 | the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. | 140 | the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. |
150 | 141 | ||
151 | config USB_ATMEL_USBA | 142 | config USB_FSL_USB2 |
152 | tristate | 143 | tristate "Freescale Highspeed USB DR Peripheral Controller" |
153 | depends on USB_GADGET_ATMEL_USBA | ||
154 | default USB_GADGET | ||
155 | select USB_GADGET_SELECTED | ||
156 | |||
157 | config USB_GADGET_FSL_USB2 | ||
158 | boolean "Freescale Highspeed USB DR Peripheral Controller" | ||
159 | depends on FSL_SOC || ARCH_MXC | 144 | depends on FSL_SOC || ARCH_MXC |
160 | select USB_GADGET_DUALSPEED | 145 | select USB_GADGET_DUALSPEED |
161 | select USB_FSL_MPH_DR_OF if OF | 146 | select USB_FSL_MPH_DR_OF if OF |
@@ -170,26 +155,15 @@ config USB_GADGET_FSL_USB2 | |||
170 | dynamically linked module called "fsl_usb2_udc" and force | 155 | dynamically linked module called "fsl_usb2_udc" and force |
171 | all gadget drivers to also be dynamically linked. | 156 | all gadget drivers to also be dynamically linked. |
172 | 157 | ||
173 | config USB_FSL_USB2 | 158 | config USB_FUSB300 |
174 | tristate | 159 | tristate "Faraday FUSB300 USB Peripheral Controller" |
175 | depends on USB_GADGET_FSL_USB2 | 160 | depends on !PHYS_ADDR_T_64BIT |
176 | default USB_GADGET | ||
177 | select USB_GADGET_SELECTED | ||
178 | |||
179 | config USB_GADGET_FUSB300 | ||
180 | boolean "Faraday FUSB300 USB Peripheral Controller" | ||
181 | select USB_GADGET_DUALSPEED | 161 | select USB_GADGET_DUALSPEED |
182 | help | 162 | help |
183 | Faraday usb device controller FUSB300 driver | 163 | Faraday usb device controller FUSB300 driver |
184 | 164 | ||
185 | config USB_FUSB300 | 165 | config USB_OMAP |
186 | tristate | 166 | tristate "OMAP USB Device Controller" |
187 | depends on USB_GADGET_FUSB300 | ||
188 | default USB_GADGET | ||
189 | select USB_GADGET_SELECTED | ||
190 | |||
191 | config USB_GADGET_OMAP | ||
192 | boolean "OMAP USB Device Controller" | ||
193 | depends on ARCH_OMAP | 167 | depends on ARCH_OMAP |
194 | select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG | 168 | select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG |
195 | select USB_OTG_UTILS if ARCH_OMAP | 169 | select USB_OTG_UTILS if ARCH_OMAP |
@@ -204,14 +178,8 @@ config USB_GADGET_OMAP | |||
204 | dynamically linked module called "omap_udc" and force all | 178 | dynamically linked module called "omap_udc" and force all |
205 | gadget drivers to also be dynamically linked. | 179 | gadget drivers to also be dynamically linked. |
206 | 180 | ||
207 | config USB_OMAP | 181 | config USB_PXA25X |
208 | tristate | 182 | tristate "PXA 25x or IXP 4xx" |
209 | depends on USB_GADGET_OMAP | ||
210 | default USB_GADGET | ||
211 | select USB_GADGET_SELECTED | ||
212 | |||
213 | config USB_GADGET_PXA25X | ||
214 | boolean "PXA 25x or IXP 4xx" | ||
215 | depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX | 183 | depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX |
216 | select USB_OTG_UTILS | 184 | select USB_OTG_UTILS |
217 | help | 185 | help |
@@ -226,24 +194,18 @@ config USB_GADGET_PXA25X | |||
226 | dynamically linked module called "pxa25x_udc" and force all | 194 | dynamically linked module called "pxa25x_udc" and force all |
227 | gadget drivers to also be dynamically linked. | 195 | gadget drivers to also be dynamically linked. |
228 | 196 | ||
229 | config USB_PXA25X | ||
230 | tristate | ||
231 | depends on USB_GADGET_PXA25X | ||
232 | default USB_GADGET | ||
233 | select USB_GADGET_SELECTED | ||
234 | |||
235 | # if there's only one gadget driver, using only two bulk endpoints, | 197 | # if there's only one gadget driver, using only two bulk endpoints, |
236 | # don't waste memory for the other endpoints | 198 | # don't waste memory for the other endpoints |
237 | config USB_PXA25X_SMALL | 199 | config USB_PXA25X_SMALL |
238 | depends on USB_GADGET_PXA25X | 200 | depends on USB_PXA25X |
239 | bool | 201 | bool |
240 | default n if USB_ETH_RNDIS | 202 | default n if USB_ETH_RNDIS |
241 | default y if USB_ZERO | 203 | default y if USB_ZERO |
242 | default y if USB_ETH | 204 | default y if USB_ETH |
243 | default y if USB_G_SERIAL | 205 | default y if USB_G_SERIAL |
244 | 206 | ||
245 | config USB_GADGET_R8A66597 | 207 | config USB_R8A66597 |
246 | boolean "Renesas R8A66597 USB Peripheral Controller" | 208 | tristate "Renesas R8A66597 USB Peripheral Controller" |
247 | select USB_GADGET_DUALSPEED | 209 | select USB_GADGET_DUALSPEED |
248 | help | 210 | help |
249 | R8A66597 is a discrete USB host and peripheral controller chip that | 211 | R8A66597 is a discrete USB host and peripheral controller chip that |
@@ -254,32 +216,22 @@ config USB_GADGET_R8A66597 | |||
254 | dynamically linked module called "r8a66597_udc" and force all | 216 | dynamically linked module called "r8a66597_udc" and force all |
255 | gadget drivers to also be dynamically linked. | 217 | gadget drivers to also be dynamically linked. |
256 | 218 | ||
257 | config USB_R8A66597 | 219 | config USB_RENESAS_USBHS_UDC |
258 | tristate | 220 | tristate 'Renesas USBHS controller' |
259 | depends on USB_GADGET_R8A66597 | 221 | depends on SUPERH || ARCH_SHMOBILE |
260 | default USB_GADGET | ||
261 | select USB_GADGET_SELECTED | ||
262 | |||
263 | config USB_GADGET_RENESAS_USBHS | ||
264 | boolean "Renesas USBHS" | ||
265 | depends on USB_RENESAS_USBHS | 222 | depends on USB_RENESAS_USBHS |
266 | select USB_GADGET_DUALSPEED | 223 | select USB_GADGET_DUALSPEED |
267 | help | 224 | help |
268 | Renesas USBHS is a discrete USB host and peripheral controller | 225 | Renesas USBHS is a discrete USB host and peripheral controller chip |
269 | chip that supports both full and high speed USB 2.0 data transfers. | 226 | that supports both full and high speed USB 2.0 data transfers. |
270 | platform is able to configure endpoint (pipe) style | 227 | It has nine or more configurable endpoints, and endpoint zero. |
271 | 228 | ||
272 | Say "y" to enable the gadget specific portion of the USBHS driver. | 229 | Say "y" to link the driver statically, or "m" to build a |
273 | 230 | dynamically linked module called "renesas_usbhs" and force all | |
274 | 231 | gadget drivers to also be dynamically linked. | |
275 | config USB_RENESAS_USBHS_UDC | ||
276 | tristate | ||
277 | depends on USB_GADGET_RENESAS_USBHS | ||
278 | default USB_GADGET | ||
279 | select USB_GADGET_SELECTED | ||
280 | 232 | ||
281 | config USB_GADGET_PXA27X | 233 | config USB_PXA27X |
282 | boolean "PXA 27x" | 234 | tristate "PXA 27x" |
283 | depends on ARCH_PXA && (PXA27x || PXA3xx) | 235 | depends on ARCH_PXA && (PXA27x || PXA3xx) |
284 | select USB_OTG_UTILS | 236 | select USB_OTG_UTILS |
285 | help | 237 | help |
@@ -293,14 +245,8 @@ config USB_GADGET_PXA27X | |||
293 | dynamically linked module called "pxa27x_udc" and force all | 245 | dynamically linked module called "pxa27x_udc" and force all |
294 | gadget drivers to also be dynamically linked. | 246 | gadget drivers to also be dynamically linked. |
295 | 247 | ||
296 | config USB_PXA27X | 248 | config USB_S3C_HSOTG |
297 | tristate | 249 | tristate "S3C HS/OtG USB Device controller" |
298 | depends on USB_GADGET_PXA27X | ||
299 | default USB_GADGET | ||
300 | select USB_GADGET_SELECTED | ||
301 | |||
302 | config USB_GADGET_S3C_HSOTG | ||
303 | boolean "S3C HS/OtG USB Device controller" | ||
304 | depends on S3C_DEV_USB_HSOTG | 250 | depends on S3C_DEV_USB_HSOTG |
305 | select USB_GADGET_S3C_HSOTG_PIO | 251 | select USB_GADGET_S3C_HSOTG_PIO |
306 | select USB_GADGET_DUALSPEED | 252 | select USB_GADGET_DUALSPEED |
@@ -308,14 +254,8 @@ config USB_GADGET_S3C_HSOTG | |||
308 | The Samsung S3C64XX USB2.0 high-speed gadget controller | 254 | The Samsung S3C64XX USB2.0 high-speed gadget controller |
309 | integrated into the S3C64XX series SoC. | 255 | integrated into the S3C64XX series SoC. |
310 | 256 | ||
311 | config USB_S3C_HSOTG | 257 | config USB_IMX |
312 | tristate | 258 | tristate "Freescale IMX USB Peripheral Controller" |
313 | depends on USB_GADGET_S3C_HSOTG | ||
314 | default USB_GADGET | ||
315 | select USB_GADGET_SELECTED | ||
316 | |||
317 | config USB_GADGET_IMX | ||
318 | boolean "Freescale IMX USB Peripheral Controller" | ||
319 | depends on ARCH_MX1 | 259 | depends on ARCH_MX1 |
320 | help | 260 | help |
321 | Freescale's IMX series include an integrated full speed | 261 | Freescale's IMX series include an integrated full speed |
@@ -329,14 +269,8 @@ config USB_GADGET_IMX | |||
329 | dynamically linked module called "imx_udc" and force all | 269 | dynamically linked module called "imx_udc" and force all |
330 | gadget drivers to also be dynamically linked. | 270 | gadget drivers to also be dynamically linked. |
331 | 271 | ||
332 | config USB_IMX | 272 | config USB_S3C2410 |
333 | tristate | 273 | tristate "S3C2410 USB Device Controller" |
334 | depends on USB_GADGET_IMX | ||
335 | default USB_GADGET | ||
336 | select USB_GADGET_SELECTED | ||
337 | |||
338 | config USB_GADGET_S3C2410 | ||
339 | boolean "S3C2410 USB Device Controller" | ||
340 | depends on ARCH_S3C2410 | 274 | depends on ARCH_S3C2410 |
341 | help | 275 | help |
342 | Samsung's S3C2410 is an ARM-4 processor with an integrated | 276 | Samsung's S3C2410 is an ARM-4 processor with an integrated |
@@ -346,18 +280,12 @@ config USB_GADGET_S3C2410 | |||
346 | This driver has been tested on the S3C2410, S3C2412, and | 280 | This driver has been tested on the S3C2410, S3C2412, and |
347 | S3C2440 processors. | 281 | S3C2440 processors. |
348 | 282 | ||
349 | config USB_S3C2410 | ||
350 | tristate | ||
351 | depends on USB_GADGET_S3C2410 | ||
352 | default USB_GADGET | ||
353 | select USB_GADGET_SELECTED | ||
354 | |||
355 | config USB_S3C2410_DEBUG | 283 | config USB_S3C2410_DEBUG |
356 | boolean "S3C2410 udc debug messages" | 284 | boolean "S3C2410 udc debug messages" |
357 | depends on USB_GADGET_S3C2410 | 285 | depends on USB_S3C2410 |
358 | 286 | ||
359 | config USB_GADGET_S3C_HSUDC | 287 | config USB_S3C_HSUDC |
360 | boolean "S3C2416, S3C2443 and S3C2450 USB Device Controller" | 288 | tristate "S3C2416, S3C2443 and S3C2450 USB Device Controller" |
361 | depends on ARCH_S3C2410 | 289 | depends on ARCH_S3C2410 |
362 | select USB_GADGET_DUALSPEED | 290 | select USB_GADGET_DUALSPEED |
363 | help | 291 | help |
@@ -367,41 +295,29 @@ config USB_GADGET_S3C_HSUDC | |||
367 | 295 | ||
368 | This driver has been tested on S3C2416 and S3C2450 processors. | 296 | This driver has been tested on S3C2416 and S3C2450 processors. |
369 | 297 | ||
370 | config USB_S3C_HSUDC | 298 | config USB_PXA_U2O |
371 | tristate | 299 | tristate "PXA9xx Processor USB2.0 controller" |
372 | depends on USB_GADGET_S3C_HSUDC | 300 | depends on ARCH_MMP |
373 | default USB_GADGET | ||
374 | select USB_GADGET_SELECTED | ||
375 | |||
376 | config USB_GADGET_PXA_U2O | ||
377 | boolean "PXA9xx Processor USB2.0 controller" | ||
378 | select USB_GADGET_DUALSPEED | 301 | select USB_GADGET_DUALSPEED |
379 | help | 302 | help |
380 | PXA9xx Processor series include a high speed USB2.0 device | 303 | PXA9xx Processor series include a high speed USB2.0 device |
381 | controller, which support high speed and full speed USB peripheral. | 304 | controller, which support high speed and full speed USB peripheral. |
382 | 305 | ||
383 | config USB_PXA_U2O | ||
384 | tristate | ||
385 | depends on USB_GADGET_PXA_U2O | ||
386 | default USB_GADGET | ||
387 | select USB_GADGET_SELECTED | ||
388 | |||
389 | # | 306 | # |
390 | # Controllers available in both integrated and discrete versions | 307 | # Controllers available in both integrated and discrete versions |
391 | # | 308 | # |
392 | 309 | ||
393 | # musb builds in ../musb along with host support | 310 | # musb builds in ../musb along with host support |
394 | config USB_GADGET_MUSB_HDRC | 311 | config USB_GADGET_MUSB_HDRC |
395 | boolean "Inventra HDRC USB Peripheral (TI, ADI, ...)" | 312 | tristate "Inventra HDRC USB Peripheral (TI, ADI, ...)" |
396 | depends on USB_MUSB_HDRC && (USB_MUSB_PERIPHERAL || USB_MUSB_OTG) | 313 | depends on USB_MUSB_HDRC && (USB_MUSB_PERIPHERAL || USB_MUSB_OTG) |
397 | select USB_GADGET_DUALSPEED | 314 | select USB_GADGET_DUALSPEED |
398 | select USB_GADGET_SELECTED | ||
399 | help | 315 | help |
400 | This OTG-capable silicon IP is used in dual designs including | 316 | This OTG-capable silicon IP is used in dual designs including |
401 | the TI DaVinci, OMAP 243x, OMAP 343x, TUSB 6010, and ADI Blackfin | 317 | the TI DaVinci, OMAP 243x, OMAP 343x, TUSB 6010, and ADI Blackfin |
402 | 318 | ||
403 | config USB_GADGET_M66592 | 319 | config USB_M66592 |
404 | boolean "Renesas M66592 USB Peripheral Controller" | 320 | tristate "Renesas M66592 USB Peripheral Controller" |
405 | select USB_GADGET_DUALSPEED | 321 | select USB_GADGET_DUALSPEED |
406 | help | 322 | help |
407 | M66592 is a discrete USB peripheral controller chip that | 323 | M66592 is a discrete USB peripheral controller chip that |
@@ -412,18 +328,12 @@ config USB_GADGET_M66592 | |||
412 | dynamically linked module called "m66592_udc" and force all | 328 | dynamically linked module called "m66592_udc" and force all |
413 | gadget drivers to also be dynamically linked. | 329 | gadget drivers to also be dynamically linked. |
414 | 330 | ||
415 | config USB_M66592 | ||
416 | tristate | ||
417 | depends on USB_GADGET_M66592 | ||
418 | default USB_GADGET | ||
419 | select USB_GADGET_SELECTED | ||
420 | |||
421 | # | 331 | # |
422 | # Controllers available only in discrete form (and all PCI controllers) | 332 | # Controllers available only in discrete form (and all PCI controllers) |
423 | # | 333 | # |
424 | 334 | ||
425 | config USB_GADGET_AMD5536UDC | 335 | config USB_AMD5536UDC |
426 | boolean "AMD5536 UDC" | 336 | tristate "AMD5536 UDC" |
427 | depends on PCI | 337 | depends on PCI |
428 | select USB_GADGET_DUALSPEED | 338 | select USB_GADGET_DUALSPEED |
429 | help | 339 | help |
@@ -437,14 +347,8 @@ config USB_GADGET_AMD5536UDC | |||
437 | dynamically linked module called "amd5536udc" and force all | 347 | dynamically linked module called "amd5536udc" and force all |
438 | gadget drivers to also be dynamically linked. | 348 | gadget drivers to also be dynamically linked. |
439 | 349 | ||
440 | config USB_AMD5536UDC | 350 | config USB_FSL_QE |
441 | tristate | 351 | tristate "Freescale QE/CPM USB Device Controller" |
442 | depends on USB_GADGET_AMD5536UDC | ||
443 | default USB_GADGET | ||
444 | select USB_GADGET_SELECTED | ||
445 | |||
446 | config USB_GADGET_FSL_QE | ||
447 | boolean "Freescale QE/CPM USB Device Controller" | ||
448 | depends on FSL_SOC && (QUICC_ENGINE || CPM) | 352 | depends on FSL_SOC && (QUICC_ENGINE || CPM) |
449 | help | 353 | help |
450 | Some of Freescale PowerPC processors have a Full Speed | 354 | Some of Freescale PowerPC processors have a Full Speed |
@@ -456,14 +360,8 @@ config USB_GADGET_FSL_QE | |||
456 | Set CONFIG_USB_GADGET to "m" to build this driver as a | 360 | Set CONFIG_USB_GADGET to "m" to build this driver as a |
457 | dynamically linked module called "fsl_qe_udc". | 361 | dynamically linked module called "fsl_qe_udc". |
458 | 362 | ||
459 | config USB_FSL_QE | 363 | config USB_CI13XXX_PCI |
460 | tristate | 364 | tristate "MIPS USB CI13xxx PCI UDC" |
461 | depends on USB_GADGET_FSL_QE | ||
462 | default USB_GADGET | ||
463 | select USB_GADGET_SELECTED | ||
464 | |||
465 | config USB_GADGET_CI13XXX_PCI | ||
466 | boolean "MIPS USB CI13xxx PCI UDC" | ||
467 | depends on PCI | 365 | depends on PCI |
468 | select USB_GADGET_DUALSPEED | 366 | select USB_GADGET_DUALSPEED |
469 | help | 367 | help |
@@ -474,14 +372,31 @@ config USB_GADGET_CI13XXX_PCI | |||
474 | dynamically linked module called "ci13xxx_udc" and force all | 372 | dynamically linked module called "ci13xxx_udc" and force all |
475 | gadget drivers to also be dynamically linked. | 373 | gadget drivers to also be dynamically linked. |
476 | 374 | ||
477 | config USB_CI13XXX_PCI | 375 | config USB_NET2272 |
478 | tristate | 376 | tristate "PLX NET2272" |
479 | depends on USB_GADGET_CI13XXX_PCI | 377 | select USB_GADGET_DUALSPEED |
480 | default USB_GADGET | 378 | help |
481 | select USB_GADGET_SELECTED | 379 | PLX NET2272 is a USB peripheral controller which supports |
380 | both full and high speed USB 2.0 data transfers. | ||
381 | |||
382 | It has three configurable endpoints, as well as endpoint zero | ||
383 | (for control transfer). | ||
384 | Say "y" to link the driver statically, or "m" to build a | ||
385 | dynamically linked module called "net2272" and force all | ||
386 | gadget drivers to also be dynamically linked. | ||
387 | |||
388 | config USB_NET2272_DMA | ||
389 | boolean "Support external DMA controller" | ||
390 | depends on USB_NET2272 | ||
391 | help | ||
392 | The NET2272 part can optionally support an external DMA | ||
393 | controller, but your board has to have support in the | ||
394 | driver itself. | ||
482 | 395 | ||
483 | config USB_GADGET_NET2280 | 396 | If unsure, say "N" here. The driver works fine in PIO mode. |
484 | boolean "NetChip 228x" | 397 | |
398 | config USB_NET2280 | ||
399 | tristate "NetChip 228x" | ||
485 | depends on PCI | 400 | depends on PCI |
486 | select USB_GADGET_DUALSPEED | 401 | select USB_GADGET_DUALSPEED |
487 | help | 402 | help |
@@ -496,14 +411,8 @@ config USB_GADGET_NET2280 | |||
496 | dynamically linked module called "net2280" and force all | 411 | dynamically linked module called "net2280" and force all |
497 | gadget drivers to also be dynamically linked. | 412 | gadget drivers to also be dynamically linked. |
498 | 413 | ||
499 | config USB_NET2280 | 414 | config USB_GOKU |
500 | tristate | 415 | tristate "Toshiba TC86C001 'Goku-S'" |
501 | depends on USB_GADGET_NET2280 | ||
502 | default USB_GADGET | ||
503 | select USB_GADGET_SELECTED | ||
504 | |||
505 | config USB_GADGET_GOKU | ||
506 | boolean "Toshiba TC86C001 'Goku-S'" | ||
507 | depends on PCI | 416 | depends on PCI |
508 | help | 417 | help |
509 | The Toshiba TC86C001 is a PCI device which includes controllers | 418 | The Toshiba TC86C001 is a PCI device which includes controllers |
@@ -516,15 +425,10 @@ config USB_GADGET_GOKU | |||
516 | dynamically linked module called "goku_udc" and to force all | 425 | dynamically linked module called "goku_udc" and to force all |
517 | gadget drivers to also be dynamically linked. | 426 | gadget drivers to also be dynamically linked. |
518 | 427 | ||
519 | config USB_GOKU | 428 | config USB_LANGWELL |
520 | tristate | 429 | tristate "Intel Langwell USB Device Controller" |
521 | depends on USB_GADGET_GOKU | ||
522 | default USB_GADGET | ||
523 | select USB_GADGET_SELECTED | ||
524 | |||
525 | config USB_GADGET_LANGWELL | ||
526 | boolean "Intel Langwell USB Device Controller" | ||
527 | depends on PCI | 430 | depends on PCI |
431 | depends on !PHYS_ADDR_T_64BIT | ||
528 | select USB_GADGET_DUALSPEED | 432 | select USB_GADGET_DUALSPEED |
529 | help | 433 | help |
530 | Intel Langwell USB Device Controller is a High-Speed USB | 434 | Intel Langwell USB Device Controller is a High-Speed USB |
@@ -537,14 +441,8 @@ config USB_GADGET_LANGWELL | |||
537 | dynamically linked module called "langwell_udc" and force all | 441 | dynamically linked module called "langwell_udc" and force all |
538 | gadget drivers to also be dynamically linked. | 442 | gadget drivers to also be dynamically linked. |
539 | 443 | ||
540 | config USB_LANGWELL | 444 | config USB_EG20T |
541 | tristate | 445 | tristate "Intel EG20T PCH/OKI SEMICONDUCTOR ML7213 IOH UDC" |
542 | depends on USB_GADGET_LANGWELL | ||
543 | default USB_GADGET | ||
544 | select USB_GADGET_SELECTED | ||
545 | |||
546 | config USB_GADGET_EG20T | ||
547 | boolean "Intel EG20T PCH/OKI SEMICONDUCTOR ML7213 IOH UDC" | ||
548 | depends on PCI | 446 | depends on PCI |
549 | select USB_GADGET_DUALSPEED | 447 | select USB_GADGET_DUALSPEED |
550 | help | 448 | help |
@@ -565,14 +463,8 @@ config USB_GADGET_EG20T | |||
565 | ML7213 is companion chip for Intel Atom E6xx series. | 463 | ML7213 is companion chip for Intel Atom E6xx series. |
566 | ML7213 is completely compatible for Intel EG20T PCH. | 464 | ML7213 is completely compatible for Intel EG20T PCH. |
567 | 465 | ||
568 | config USB_EG20T | 466 | config USB_CI13XXX_MSM |
569 | tristate | 467 | tristate "MIPS USB CI13xxx for MSM" |
570 | depends on USB_GADGET_EG20T | ||
571 | default USB_GADGET | ||
572 | select USB_GADGET_SELECTED | ||
573 | |||
574 | config USB_GADGET_CI13XXX_MSM | ||
575 | boolean "MIPS USB CI13xxx for MSM" | ||
576 | depends on ARCH_MSM | 468 | depends on ARCH_MSM |
577 | select USB_GADGET_DUALSPEED | 469 | select USB_GADGET_DUALSPEED |
578 | select USB_MSM_OTG | 470 | select USB_MSM_OTG |
@@ -588,31 +480,26 @@ config USB_GADGET_CI13XXX_MSM | |||
588 | dynamically linked module called "ci13xxx_msm" and force all | 480 | dynamically linked module called "ci13xxx_msm" and force all |
589 | gadget drivers to also be dynamically linked. | 481 | gadget drivers to also be dynamically linked. |
590 | 482 | ||
591 | config USB_CI13XXX_MSM | ||
592 | tristate | ||
593 | depends on USB_GADGET_CI13XXX_MSM | ||
594 | default USB_GADGET | ||
595 | select USB_GADGET_SELECTED | ||
596 | |||
597 | # | 483 | # |
598 | # LAST -- dummy/emulated controller | 484 | # LAST -- dummy/emulated controller |
599 | # | 485 | # |
600 | 486 | ||
601 | config USB_GADGET_DUMMY_HCD | 487 | config USB_DUMMY_HCD |
602 | boolean "Dummy HCD (DEVELOPMENT)" | 488 | tristate "Dummy HCD (DEVELOPMENT)" |
603 | depends on USB=y || (USB=m && USB_GADGET=m) | 489 | depends on USB=y || (USB=m && USB_GADGET=m) |
604 | select USB_GADGET_DUALSPEED | 490 | select USB_GADGET_DUALSPEED |
491 | select USB_GADGET_SUPERSPEED | ||
605 | help | 492 | help |
606 | This host controller driver emulates USB, looping all data transfer | 493 | This host controller driver emulates USB, looping all data transfer |
607 | requests back to a USB "gadget driver" in the same host. The host | 494 | requests back to a USB "gadget driver" in the same host. The host |
608 | side is the master; the gadget side is the slave. Gadget drivers | 495 | side is the master; the gadget side is the slave. Gadget drivers |
609 | can be high, full, or low speed; and they have access to endpoints | 496 | can be high, full, or low speed; and they have access to endpoints |
610 | like those from NET2280, PXA2xx, or SA1100 hardware. | 497 | like those from NET2280, PXA2xx, or SA1100 hardware. |
611 | 498 | ||
612 | This may help in some stages of creating a driver to embed in a | 499 | This may help in some stages of creating a driver to embed in a |
613 | Linux device, since it lets you debug several parts of the gadget | 500 | Linux device, since it lets you debug several parts of the gadget |
614 | driver without its hardware or drivers being involved. | 501 | driver without its hardware or drivers being involved. |
615 | 502 | ||
616 | Since such a gadget side driver needs to interoperate with a host | 503 | Since such a gadget side driver needs to interoperate with a host |
617 | side Linux-USB device driver, this may help to debug both sides | 504 | side Linux-USB device driver, this may help to debug both sides |
618 | of a USB protocol stack. | 505 | of a USB protocol stack. |
@@ -621,12 +508,6 @@ config USB_GADGET_DUMMY_HCD | |||
621 | dynamically linked module called "dummy_hcd" and force all | 508 | dynamically linked module called "dummy_hcd" and force all |
622 | gadget drivers to also be dynamically linked. | 509 | gadget drivers to also be dynamically linked. |
623 | 510 | ||
624 | config USB_DUMMY_HCD | ||
625 | tristate | ||
626 | depends on USB_GADGET_DUMMY_HCD | ||
627 | default USB_GADGET | ||
628 | select USB_GADGET_SELECTED | ||
629 | |||
630 | # NOTE: Please keep dummy_hcd LAST so that "real hardware" appears | 511 | # NOTE: Please keep dummy_hcd LAST so that "real hardware" appears |
631 | # first and will be selected by default. | 512 | # first and will be selected by default. |
632 | 513 | ||
@@ -637,12 +518,18 @@ config USB_GADGET_DUALSPEED | |||
637 | bool | 518 | bool |
638 | depends on USB_GADGET | 519 | depends on USB_GADGET |
639 | 520 | ||
521 | # Selected by UDC drivers that support super-speed opperation | ||
522 | config USB_GADGET_SUPERSPEED | ||
523 | bool | ||
524 | depends on USB_GADGET | ||
525 | depends on USB_GADGET_DUALSPEED | ||
526 | |||
640 | # | 527 | # |
641 | # USB Gadget Drivers | 528 | # USB Gadget Drivers |
642 | # | 529 | # |
643 | choice | 530 | choice |
644 | tristate "USB Gadget Drivers" | 531 | tristate "USB Gadget Drivers" |
645 | depends on USB_GADGET && USB_GADGET_SELECTED | 532 | depends on USB_GADGET |
646 | default USB_ETH | 533 | default USB_ETH |
647 | help | 534 | help |
648 | A Linux "Gadget Driver" talks to the USB Peripheral Controller | 535 | A Linux "Gadget Driver" talks to the USB Peripheral Controller |
@@ -848,7 +735,7 @@ config USB_FUNCTIONFS_GENERIC | |||
848 | no Ethernet interface. | 735 | no Ethernet interface. |
849 | 736 | ||
850 | config USB_FILE_STORAGE | 737 | config USB_FILE_STORAGE |
851 | tristate "File-backed Storage Gadget" | 738 | tristate "File-backed Storage Gadget (DEPRECATED)" |
852 | depends on BLOCK | 739 | depends on BLOCK |
853 | help | 740 | help |
854 | The File-backed Storage Gadget acts as a USB Mass Storage | 741 | The File-backed Storage Gadget acts as a USB Mass Storage |
@@ -859,6 +746,9 @@ config USB_FILE_STORAGE | |||
859 | Say "y" to link the driver statically, or "m" to build a | 746 | Say "y" to link the driver statically, or "m" to build a |
860 | dynamically linked module called "g_file_storage". | 747 | dynamically linked module called "g_file_storage". |
861 | 748 | ||
749 | NOTE: This driver is deprecated. Its replacement is the | ||
750 | Mass Storage Gadget. | ||
751 | |||
862 | config USB_FILE_STORAGE_TEST | 752 | config USB_FILE_STORAGE_TEST |
863 | bool "File-backed Storage Gadget testing version" | 753 | bool "File-backed Storage Gadget testing version" |
864 | depends on USB_FILE_STORAGE | 754 | depends on USB_FILE_STORAGE |
@@ -878,14 +768,11 @@ config USB_MASS_STORAGE | |||
878 | device (in much the same way as the "loop" device driver), | 768 | device (in much the same way as the "loop" device driver), |
879 | specified as a module parameter or sysfs option. | 769 | specified as a module parameter or sysfs option. |
880 | 770 | ||
881 | This is heavily based on File-backed Storage Gadget and in most | 771 | This driver is an updated replacement for the deprecated |
882 | cases you will want to use FSG instead. This gadget is mostly | 772 | File-backed Storage Gadget (g_file_storage). |
883 | here to test the functionality of the Mass Storage Function | ||
884 | which may be used with composite framework. | ||
885 | 773 | ||
886 | Say "y" to link the driver statically, or "m" to build | 774 | Say "y" to link the driver statically, or "m" to build |
887 | a dynamically linked module called "g_mass_storage". If unsure, | 775 | a dynamically linked module called "g_mass_storage". |
888 | consider File-backed Storage Gadget. | ||
889 | 776 | ||
890 | config USB_G_SERIAL | 777 | config USB_G_SERIAL |
891 | tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" | 778 | tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 4fe92b18a055..9ba725af4a08 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -3,7 +3,9 @@ | |||
3 | # | 3 | # |
4 | ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG | 4 | ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG |
5 | 5 | ||
6 | obj-$(CONFIG_USB_GADGET) += udc-core.o | ||
6 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o | 7 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o |
8 | obj-$(CONFIG_USB_NET2272) += net2272.o | ||
7 | obj-$(CONFIG_USB_NET2280) += net2280.o | 9 | obj-$(CONFIG_USB_NET2280) += net2280.o |
8 | obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o | 10 | obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o |
9 | obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o | 11 | obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o |
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index 95e8138cd48f..70f2b376c86d 100644 --- a/drivers/usb/gadget/amd5536udc.c +++ b/drivers/usb/gadget/amd5536udc.c | |||
@@ -1438,10 +1438,15 @@ static int udc_wakeup(struct usb_gadget *gadget) | |||
1438 | return 0; | 1438 | return 0; |
1439 | } | 1439 | } |
1440 | 1440 | ||
1441 | static int amd5536_start(struct usb_gadget_driver *driver, | ||
1442 | int (*bind)(struct usb_gadget *)); | ||
1443 | static int amd5536_stop(struct usb_gadget_driver *driver); | ||
1441 | /* gadget operations */ | 1444 | /* gadget operations */ |
1442 | static const struct usb_gadget_ops udc_ops = { | 1445 | static const struct usb_gadget_ops udc_ops = { |
1443 | .wakeup = udc_wakeup, | 1446 | .wakeup = udc_wakeup, |
1444 | .get_frame = udc_get_frame, | 1447 | .get_frame = udc_get_frame, |
1448 | .start = amd5536_start, | ||
1449 | .stop = amd5536_stop, | ||
1445 | }; | 1450 | }; |
1446 | 1451 | ||
1447 | /* Setups endpoint parameters, adds endpoints to linked list */ | 1452 | /* Setups endpoint parameters, adds endpoints to linked list */ |
@@ -1955,7 +1960,7 @@ static int setup_ep0(struct udc *dev) | |||
1955 | } | 1960 | } |
1956 | 1961 | ||
1957 | /* Called by gadget driver to register itself */ | 1962 | /* Called by gadget driver to register itself */ |
1958 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1963 | static int amd5536_start(struct usb_gadget_driver *driver, |
1959 | int (*bind)(struct usb_gadget *)) | 1964 | int (*bind)(struct usb_gadget *)) |
1960 | { | 1965 | { |
1961 | struct udc *dev = udc; | 1966 | struct udc *dev = udc; |
@@ -2002,7 +2007,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
2002 | 2007 | ||
2003 | return 0; | 2008 | return 0; |
2004 | } | 2009 | } |
2005 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
2006 | 2010 | ||
2007 | /* shutdown requests and disconnect from gadget */ | 2011 | /* shutdown requests and disconnect from gadget */ |
2008 | static void | 2012 | static void |
@@ -2027,7 +2031,7 @@ __acquires(dev->lock) | |||
2027 | } | 2031 | } |
2028 | 2032 | ||
2029 | /* Called by gadget driver to unregister itself */ | 2033 | /* Called by gadget driver to unregister itself */ |
2030 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 2034 | static int amd5536_stop(struct usb_gadget_driver *driver) |
2031 | { | 2035 | { |
2032 | struct udc *dev = udc; | 2036 | struct udc *dev = udc; |
2033 | unsigned long flags; | 2037 | unsigned long flags; |
@@ -2057,8 +2061,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
2057 | 2061 | ||
2058 | return 0; | 2062 | return 0; |
2059 | } | 2063 | } |
2060 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2061 | |||
2062 | 2064 | ||
2063 | /* Clear pending NAK bits */ | 2065 | /* Clear pending NAK bits */ |
2064 | static void udc_process_cnak_queue(struct udc *dev) | 2066 | static void udc_process_cnak_queue(struct udc *dev) |
@@ -3134,6 +3136,7 @@ static void udc_pci_remove(struct pci_dev *pdev) | |||
3134 | 3136 | ||
3135 | dev = pci_get_drvdata(pdev); | 3137 | dev = pci_get_drvdata(pdev); |
3136 | 3138 | ||
3139 | usb_del_gadget_udc(&udc->gadget); | ||
3137 | /* gadget driver must not be registered */ | 3140 | /* gadget driver must not be registered */ |
3138 | BUG_ON(dev->driver != NULL); | 3141 | BUG_ON(dev->driver != NULL); |
3139 | 3142 | ||
@@ -3382,8 +3385,13 @@ static int udc_probe(struct udc *dev) | |||
3382 | "driver version: %s(for Geode5536 B1)\n", tmp); | 3385 | "driver version: %s(for Geode5536 B1)\n", tmp); |
3383 | udc = dev; | 3386 | udc = dev; |
3384 | 3387 | ||
3388 | retval = usb_add_gadget_udc(&udc->pdev->dev, &dev->gadget); | ||
3389 | if (retval) | ||
3390 | goto finished; | ||
3391 | |||
3385 | retval = device_register(&dev->gadget.dev); | 3392 | retval = device_register(&dev->gadget.dev); |
3386 | if (retval) { | 3393 | if (retval) { |
3394 | usb_del_gadget_udc(&dev->gadget); | ||
3387 | put_device(&dev->gadget.dev); | 3395 | put_device(&dev->gadget.dev); |
3388 | goto finished; | 3396 | goto finished; |
3389 | } | 3397 | } |
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index f4690ffcb489..98cbc06c30fd 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -985,12 +985,18 @@ static int at91_set_selfpowered(struct usb_gadget *gadget, int is_on) | |||
985 | return 0; | 985 | return 0; |
986 | } | 986 | } |
987 | 987 | ||
988 | static int at91_start(struct usb_gadget_driver *driver, | ||
989 | int (*bind)(struct usb_gadget *)); | ||
990 | static int at91_stop(struct usb_gadget_driver *driver); | ||
991 | |||
988 | static const struct usb_gadget_ops at91_udc_ops = { | 992 | static const struct usb_gadget_ops at91_udc_ops = { |
989 | .get_frame = at91_get_frame, | 993 | .get_frame = at91_get_frame, |
990 | .wakeup = at91_wakeup, | 994 | .wakeup = at91_wakeup, |
991 | .set_selfpowered = at91_set_selfpowered, | 995 | .set_selfpowered = at91_set_selfpowered, |
992 | .vbus_session = at91_vbus_session, | 996 | .vbus_session = at91_vbus_session, |
993 | .pullup = at91_pullup, | 997 | .pullup = at91_pullup, |
998 | .start = at91_start, | ||
999 | .stop = at91_stop, | ||
994 | 1000 | ||
995 | /* | 1001 | /* |
996 | * VBUS-powered devices may also also want to support bigger | 1002 | * VBUS-powered devices may also also want to support bigger |
@@ -1628,7 +1634,7 @@ static void at91_vbus_timer(unsigned long data) | |||
1628 | schedule_work(&udc->vbus_timer_work); | 1634 | schedule_work(&udc->vbus_timer_work); |
1629 | } | 1635 | } |
1630 | 1636 | ||
1631 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1637 | static int at91_start(struct usb_gadget_driver *driver, |
1632 | int (*bind)(struct usb_gadget *)) | 1638 | int (*bind)(struct usb_gadget *)) |
1633 | { | 1639 | { |
1634 | struct at91_udc *udc = &controller; | 1640 | struct at91_udc *udc = &controller; |
@@ -1672,9 +1678,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
1672 | DBG("bound to %s\n", driver->driver.name); | 1678 | DBG("bound to %s\n", driver->driver.name); |
1673 | return 0; | 1679 | return 0; |
1674 | } | 1680 | } |
1675 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1676 | 1681 | ||
1677 | int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | 1682 | static int at91_stop(struct usb_gadget_driver *driver) |
1678 | { | 1683 | { |
1679 | struct at91_udc *udc = &controller; | 1684 | struct at91_udc *udc = &controller; |
1680 | unsigned long flags; | 1685 | unsigned long flags; |
@@ -1696,7 +1701,6 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | |||
1696 | DBG("unbound from %s\n", driver->driver.name); | 1701 | DBG("unbound from %s\n", driver->driver.name); |
1697 | return 0; | 1702 | return 0; |
1698 | } | 1703 | } |
1699 | EXPORT_SYMBOL (usb_gadget_unregister_driver); | ||
1700 | 1704 | ||
1701 | /*-------------------------------------------------------------------------*/ | 1705 | /*-------------------------------------------------------------------------*/ |
1702 | 1706 | ||
@@ -1854,13 +1858,18 @@ static int __init at91udc_probe(struct platform_device *pdev) | |||
1854 | DBG("no VBUS detection, assuming always-on\n"); | 1858 | DBG("no VBUS detection, assuming always-on\n"); |
1855 | udc->vbus = 1; | 1859 | udc->vbus = 1; |
1856 | } | 1860 | } |
1861 | retval = usb_add_gadget_udc(dev, &udc->gadget); | ||
1862 | if (retval) | ||
1863 | goto fail4; | ||
1857 | dev_set_drvdata(dev, udc); | 1864 | dev_set_drvdata(dev, udc); |
1858 | device_init_wakeup(dev, 1); | 1865 | device_init_wakeup(dev, 1); |
1859 | create_debug_file(udc); | 1866 | create_debug_file(udc); |
1860 | 1867 | ||
1861 | INFO("%s version %s\n", driver_name, DRIVER_VERSION); | 1868 | INFO("%s version %s\n", driver_name, DRIVER_VERSION); |
1862 | return 0; | 1869 | return 0; |
1863 | 1870 | fail4: | |
1871 | if (udc->board.vbus_pin > 0 && !udc->board.vbus_polled) | ||
1872 | free_irq(udc->board.vbus_pin, udc); | ||
1864 | fail3: | 1873 | fail3: |
1865 | if (udc->board.vbus_pin > 0) | 1874 | if (udc->board.vbus_pin > 0) |
1866 | gpio_free(udc->board.vbus_pin); | 1875 | gpio_free(udc->board.vbus_pin); |
@@ -1887,6 +1896,7 @@ static int __exit at91udc_remove(struct platform_device *pdev) | |||
1887 | 1896 | ||
1888 | DBG("remove\n"); | 1897 | DBG("remove\n"); |
1889 | 1898 | ||
1899 | usb_del_gadget_udc(&udc->gadget); | ||
1890 | if (udc->driver) | 1900 | if (udc->driver) |
1891 | return -EBUSY; | 1901 | return -EBUSY; |
1892 | 1902 | ||
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index f045c8968a6e..5b1665eb1bef 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c | |||
@@ -1007,10 +1007,16 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered) | |||
1007 | return 0; | 1007 | return 0; |
1008 | } | 1008 | } |
1009 | 1009 | ||
1010 | static int atmel_usba_start(struct usb_gadget_driver *driver, | ||
1011 | int (*bind)(struct usb_gadget *)); | ||
1012 | static int atmel_usba_stop(struct usb_gadget_driver *driver); | ||
1013 | |||
1010 | static const struct usb_gadget_ops usba_udc_ops = { | 1014 | static const struct usb_gadget_ops usba_udc_ops = { |
1011 | .get_frame = usba_udc_get_frame, | 1015 | .get_frame = usba_udc_get_frame, |
1012 | .wakeup = usba_udc_wakeup, | 1016 | .wakeup = usba_udc_wakeup, |
1013 | .set_selfpowered = usba_udc_set_selfpowered, | 1017 | .set_selfpowered = usba_udc_set_selfpowered, |
1018 | .start = atmel_usba_start, | ||
1019 | .stop = atmel_usba_stop, | ||
1014 | }; | 1020 | }; |
1015 | 1021 | ||
1016 | static struct usb_endpoint_descriptor usba_ep0_desc = { | 1022 | static struct usb_endpoint_descriptor usba_ep0_desc = { |
@@ -1789,7 +1795,7 @@ out: | |||
1789 | return IRQ_HANDLED; | 1795 | return IRQ_HANDLED; |
1790 | } | 1796 | } |
1791 | 1797 | ||
1792 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1798 | static int atmel_usba_start(struct usb_gadget_driver *driver, |
1793 | int (*bind)(struct usb_gadget *)) | 1799 | int (*bind)(struct usb_gadget *)) |
1794 | { | 1800 | { |
1795 | struct usba_udc *udc = &the_udc; | 1801 | struct usba_udc *udc = &the_udc; |
@@ -1842,9 +1848,8 @@ err_driver_bind: | |||
1842 | udc->gadget.dev.driver = NULL; | 1848 | udc->gadget.dev.driver = NULL; |
1843 | return ret; | 1849 | return ret; |
1844 | } | 1850 | } |
1845 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1846 | 1851 | ||
1847 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1852 | static int atmel_usba_stop(struct usb_gadget_driver *driver) |
1848 | { | 1853 | { |
1849 | struct usba_udc *udc = &the_udc; | 1854 | struct usba_udc *udc = &the_udc; |
1850 | unsigned long flags; | 1855 | unsigned long flags; |
@@ -1880,7 +1885,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1880 | 1885 | ||
1881 | return 0; | 1886 | return 0; |
1882 | } | 1887 | } |
1883 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1884 | 1888 | ||
1885 | static int __init usba_udc_probe(struct platform_device *pdev) | 1889 | static int __init usba_udc_probe(struct platform_device *pdev) |
1886 | { | 1890 | { |
@@ -2021,12 +2025,24 @@ static int __init usba_udc_probe(struct platform_device *pdev) | |||
2021 | } | 2025 | } |
2022 | } | 2026 | } |
2023 | 2027 | ||
2028 | ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | ||
2029 | if (ret) | ||
2030 | goto err_add_udc; | ||
2031 | |||
2024 | usba_init_debugfs(udc); | 2032 | usba_init_debugfs(udc); |
2025 | for (i = 1; i < pdata->num_ep; i++) | 2033 | for (i = 1; i < pdata->num_ep; i++) |
2026 | usba_ep_init_debugfs(udc, &usba_ep[i]); | 2034 | usba_ep_init_debugfs(udc, &usba_ep[i]); |
2027 | 2035 | ||
2028 | return 0; | 2036 | return 0; |
2029 | 2037 | ||
2038 | err_add_udc: | ||
2039 | if (gpio_is_valid(pdata->vbus_pin)) { | ||
2040 | free_irq(gpio_to_irq(udc->vbus_pin), udc); | ||
2041 | gpio_free(udc->vbus_pin); | ||
2042 | } | ||
2043 | |||
2044 | device_unregister(&udc->gadget.dev); | ||
2045 | |||
2030 | err_device_add: | 2046 | err_device_add: |
2031 | free_irq(irq, udc); | 2047 | free_irq(irq, udc); |
2032 | err_request_irq: | 2048 | err_request_irq: |
@@ -2053,6 +2069,8 @@ static int __exit usba_udc_remove(struct platform_device *pdev) | |||
2053 | 2069 | ||
2054 | udc = platform_get_drvdata(pdev); | 2070 | udc = platform_get_drvdata(pdev); |
2055 | 2071 | ||
2072 | usb_del_gadget_udc(&udc->gadget); | ||
2073 | |||
2056 | for (i = 1; i < pdata->num_ep; i++) | 2074 | for (i = 1; i < pdata->num_ep; i++) |
2057 | usba_ep_cleanup_debugfs(&usba_ep[i]); | 2075 | usba_ep_cleanup_debugfs(&usba_ep[i]); |
2058 | usba_cleanup_debugfs(udc); | 2076 | usba_cleanup_debugfs(udc); |
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c index 93b999e49ef3..9d89ae4765a9 100644 --- a/drivers/usb/gadget/audio.c +++ b/drivers/usb/gadget/audio.c | |||
@@ -165,6 +165,7 @@ static struct usb_composite_driver audio_driver = { | |||
165 | .name = "g_audio", | 165 | .name = "g_audio", |
166 | .dev = &device_desc, | 166 | .dev = &device_desc, |
167 | .strings = audio_strings, | 167 | .strings = audio_strings, |
168 | .max_speed = USB_SPEED_HIGH, | ||
168 | .unbind = __exit_p(audio_unbind), | 169 | .unbind = __exit_p(audio_unbind), |
169 | }; | 170 | }; |
170 | 171 | ||
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c index 2720ab07ef1a..b1c1afbb8750 100644 --- a/drivers/usb/gadget/cdc2.c +++ b/drivers/usb/gadget/cdc2.c | |||
@@ -244,6 +244,7 @@ static struct usb_composite_driver cdc_driver = { | |||
244 | .name = "g_cdc", | 244 | .name = "g_cdc", |
245 | .dev = &device_desc, | 245 | .dev = &device_desc, |
246 | .strings = dev_strings, | 246 | .strings = dev_strings, |
247 | .max_speed = USB_SPEED_HIGH, | ||
247 | .unbind = __exit_p(cdc_unbind), | 248 | .unbind = __exit_p(cdc_unbind), |
248 | }; | 249 | }; |
249 | 250 | ||
diff --git a/drivers/usb/gadget/ci13xxx_msm.c b/drivers/usb/gadget/ci13xxx_msm.c index 139ac9419597..470981ad6f77 100644 --- a/drivers/usb/gadget/ci13xxx_msm.c +++ b/drivers/usb/gadget/ci13xxx_msm.c | |||
@@ -126,6 +126,7 @@ static struct platform_driver ci13xxx_msm_driver = { | |||
126 | .probe = ci13xxx_msm_probe, | 126 | .probe = ci13xxx_msm_probe, |
127 | .driver = { .name = "msm_hsusb", }, | 127 | .driver = { .name = "msm_hsusb", }, |
128 | }; | 128 | }; |
129 | MODULE_ALIAS("platform:msm_hsusb"); | ||
129 | 130 | ||
130 | static int __init ci13xxx_msm_init(void) | 131 | static int __init ci13xxx_msm_init(void) |
131 | { | 132 | { |
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c index baaf87ed7685..1265a8502ea0 100644 --- a/drivers/usb/gadget/ci13xxx_udc.c +++ b/drivers/usb/gadget/ci13xxx_udc.c | |||
@@ -857,7 +857,7 @@ static void dbg_print(u8 addr, const char *name, int status, const char *extra) | |||
857 | stamp = stamp * 1000000 + tval.tv_usec; | 857 | stamp = stamp * 1000000 + tval.tv_usec; |
858 | 858 | ||
859 | scnprintf(dbg_data.buf[dbg_data.idx], DBG_DATA_MSG, | 859 | scnprintf(dbg_data.buf[dbg_data.idx], DBG_DATA_MSG, |
860 | "%04X\t» %02X %-7.7s %4i «\t%s\n", | 860 | "%04X\t? %02X %-7.7s %4i ?\t%s\n", |
861 | stamp, addr, name, status, extra); | 861 | stamp, addr, name, status, extra); |
862 | 862 | ||
863 | dbg_inc(&dbg_data.idx); | 863 | dbg_inc(&dbg_data.idx); |
@@ -865,7 +865,7 @@ static void dbg_print(u8 addr, const char *name, int status, const char *extra) | |||
865 | write_unlock_irqrestore(&dbg_data.lck, flags); | 865 | write_unlock_irqrestore(&dbg_data.lck, flags); |
866 | 866 | ||
867 | if (dbg_data.tty != 0) | 867 | if (dbg_data.tty != 0) |
868 | pr_notice("%04X\t» %02X %-7.7s %4i «\t%s\n", | 868 | pr_notice("%04X\t? %02X %-7.7s %4i ?\t%s\n", |
869 | stamp, addr, name, status, extra); | 869 | stamp, addr, name, status, extra); |
870 | } | 870 | } |
871 | 871 | ||
@@ -1025,15 +1025,15 @@ static ssize_t show_inters(struct device *dev, struct device_attribute *attr, | |||
1025 | 1025 | ||
1026 | n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n", | 1026 | n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n", |
1027 | isr_statistics.test); | 1027 | isr_statistics.test); |
1028 | n += scnprintf(buf + n, PAGE_SIZE - n, "» ui = %d\n", | 1028 | n += scnprintf(buf + n, PAGE_SIZE - n, "? ui = %d\n", |
1029 | isr_statistics.ui); | 1029 | isr_statistics.ui); |
1030 | n += scnprintf(buf + n, PAGE_SIZE - n, "» uei = %d\n", | 1030 | n += scnprintf(buf + n, PAGE_SIZE - n, "? uei = %d\n", |
1031 | isr_statistics.uei); | 1031 | isr_statistics.uei); |
1032 | n += scnprintf(buf + n, PAGE_SIZE - n, "» pci = %d\n", | 1032 | n += scnprintf(buf + n, PAGE_SIZE - n, "? pci = %d\n", |
1033 | isr_statistics.pci); | 1033 | isr_statistics.pci); |
1034 | n += scnprintf(buf + n, PAGE_SIZE - n, "» uri = %d\n", | 1034 | n += scnprintf(buf + n, PAGE_SIZE - n, "? uri = %d\n", |
1035 | isr_statistics.uri); | 1035 | isr_statistics.uri); |
1036 | n += scnprintf(buf + n, PAGE_SIZE - n, "» sli = %d\n", | 1036 | n += scnprintf(buf + n, PAGE_SIZE - n, "? sli = %d\n", |
1037 | isr_statistics.sli); | 1037 | isr_statistics.sli); |
1038 | n += scnprintf(buf + n, PAGE_SIZE - n, "*none = %d\n", | 1038 | n += scnprintf(buf + n, PAGE_SIZE - n, "*none = %d\n", |
1039 | isr_statistics.none); | 1039 | isr_statistics.none); |
@@ -1214,12 +1214,13 @@ static DEVICE_ATTR(qheads, S_IRUSR, show_qheads, NULL); | |||
1214 | * | 1214 | * |
1215 | * Check "device.h" for details | 1215 | * Check "device.h" for details |
1216 | */ | 1216 | */ |
1217 | #define DUMP_ENTRIES 512 | ||
1217 | static ssize_t show_registers(struct device *dev, | 1218 | static ssize_t show_registers(struct device *dev, |
1218 | struct device_attribute *attr, char *buf) | 1219 | struct device_attribute *attr, char *buf) |
1219 | { | 1220 | { |
1220 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | 1221 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); |
1221 | unsigned long flags; | 1222 | unsigned long flags; |
1222 | u32 dump[512]; | 1223 | u32 *dump; |
1223 | unsigned i, k, n = 0; | 1224 | unsigned i, k, n = 0; |
1224 | 1225 | ||
1225 | dbg_trace("[%s] %p\n", __func__, buf); | 1226 | dbg_trace("[%s] %p\n", __func__, buf); |
@@ -1228,8 +1229,14 @@ static ssize_t show_registers(struct device *dev, | |||
1228 | return 0; | 1229 | return 0; |
1229 | } | 1230 | } |
1230 | 1231 | ||
1232 | dump = kmalloc(sizeof(u32) * DUMP_ENTRIES, GFP_KERNEL); | ||
1233 | if (!dump) { | ||
1234 | dev_err(dev, "%s: out of memory\n", __func__); | ||
1235 | return 0; | ||
1236 | } | ||
1237 | |||
1231 | spin_lock_irqsave(udc->lock, flags); | 1238 | spin_lock_irqsave(udc->lock, flags); |
1232 | k = hw_register_read(dump, sizeof(dump)/sizeof(u32)); | 1239 | k = hw_register_read(dump, DUMP_ENTRIES); |
1233 | spin_unlock_irqrestore(udc->lock, flags); | 1240 | spin_unlock_irqrestore(udc->lock, flags); |
1234 | 1241 | ||
1235 | for (i = 0; i < k; i++) { | 1242 | for (i = 0; i < k; i++) { |
@@ -1237,6 +1244,7 @@ static ssize_t show_registers(struct device *dev, | |||
1237 | "reg[0x%04X] = 0x%08X\n", | 1244 | "reg[0x%04X] = 0x%08X\n", |
1238 | i * (unsigned)sizeof(u32), dump[i]); | 1245 | i * (unsigned)sizeof(u32), dump[i]); |
1239 | } | 1246 | } |
1247 | kfree(dump); | ||
1240 | 1248 | ||
1241 | return n; | 1249 | return n; |
1242 | } | 1250 | } |
@@ -2515,6 +2523,9 @@ static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA) | |||
2515 | return -ENOTSUPP; | 2523 | return -ENOTSUPP; |
2516 | } | 2524 | } |
2517 | 2525 | ||
2526 | static int ci13xxx_start(struct usb_gadget_driver *driver, | ||
2527 | int (*bind)(struct usb_gadget *)); | ||
2528 | static int ci13xxx_stop(struct usb_gadget_driver *driver); | ||
2518 | /** | 2529 | /** |
2519 | * Device operations part of the API to the USB controller hardware, | 2530 | * Device operations part of the API to the USB controller hardware, |
2520 | * which don't involve endpoints (or i/o) | 2531 | * which don't involve endpoints (or i/o) |
@@ -2524,17 +2535,19 @@ static const struct usb_gadget_ops usb_gadget_ops = { | |||
2524 | .vbus_session = ci13xxx_vbus_session, | 2535 | .vbus_session = ci13xxx_vbus_session, |
2525 | .wakeup = ci13xxx_wakeup, | 2536 | .wakeup = ci13xxx_wakeup, |
2526 | .vbus_draw = ci13xxx_vbus_draw, | 2537 | .vbus_draw = ci13xxx_vbus_draw, |
2538 | .start = ci13xxx_start, | ||
2539 | .stop = ci13xxx_stop, | ||
2527 | }; | 2540 | }; |
2528 | 2541 | ||
2529 | /** | 2542 | /** |
2530 | * usb_gadget_probe_driver: register a gadget driver | 2543 | * ci13xxx_start: register a gadget driver |
2531 | * @driver: the driver being registered | 2544 | * @driver: the driver being registered |
2532 | * @bind: the driver's bind callback | 2545 | * @bind: the driver's bind callback |
2533 | * | 2546 | * |
2534 | * Check usb_gadget_probe_driver() at <linux/usb/gadget.h> for details. | 2547 | * Check ci13xxx_start() at <linux/usb/gadget.h> for details. |
2535 | * Interrupts are enabled here. | 2548 | * Interrupts are enabled here. |
2536 | */ | 2549 | */ |
2537 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 2550 | static int ci13xxx_start(struct usb_gadget_driver *driver, |
2538 | int (*bind)(struct usb_gadget *)) | 2551 | int (*bind)(struct usb_gadget *)) |
2539 | { | 2552 | { |
2540 | struct ci13xxx *udc = _udc; | 2553 | struct ci13xxx *udc = _udc; |
@@ -2615,10 +2628,13 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
2615 | if (retval) | 2628 | if (retval) |
2616 | goto done; | 2629 | goto done; |
2617 | spin_unlock_irqrestore(udc->lock, flags); | 2630 | spin_unlock_irqrestore(udc->lock, flags); |
2618 | retval = usb_ep_enable(&udc->ep0out.ep, &ctrl_endpt_out_desc); | 2631 | udc->ep0out.ep.desc = &ctrl_endpt_out_desc; |
2632 | retval = usb_ep_enable(&udc->ep0out.ep); | ||
2619 | if (retval) | 2633 | if (retval) |
2620 | return retval; | 2634 | return retval; |
2621 | retval = usb_ep_enable(&udc->ep0in.ep, &ctrl_endpt_in_desc); | 2635 | |
2636 | udc->ep0in.ep.desc = &ctrl_endpt_in_desc; | ||
2637 | retval = usb_ep_enable(&udc->ep0in.ep); | ||
2622 | if (retval) | 2638 | if (retval) |
2623 | return retval; | 2639 | return retval; |
2624 | spin_lock_irqsave(udc->lock, flags); | 2640 | spin_lock_irqsave(udc->lock, flags); |
@@ -2657,14 +2673,13 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
2657 | spin_unlock_irqrestore(udc->lock, flags); | 2673 | spin_unlock_irqrestore(udc->lock, flags); |
2658 | return retval; | 2674 | return retval; |
2659 | } | 2675 | } |
2660 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
2661 | 2676 | ||
2662 | /** | 2677 | /** |
2663 | * usb_gadget_unregister_driver: unregister a gadget driver | 2678 | * ci13xxx_stop: unregister a gadget driver |
2664 | * | 2679 | * |
2665 | * Check usb_gadget_unregister_driver() at "usb_gadget.h" for details | 2680 | * Check usb_gadget_unregister_driver() at "usb_gadget.h" for details |
2666 | */ | 2681 | */ |
2667 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 2682 | static int ci13xxx_stop(struct usb_gadget_driver *driver) |
2668 | { | 2683 | { |
2669 | struct ci13xxx *udc = _udc; | 2684 | struct ci13xxx *udc = _udc; |
2670 | unsigned long i, flags; | 2685 | unsigned long i, flags; |
@@ -2726,7 +2741,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
2726 | 2741 | ||
2727 | return 0; | 2742 | return 0; |
2728 | } | 2743 | } |
2729 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2730 | 2744 | ||
2731 | /****************************************************************************** | 2745 | /****************************************************************************** |
2732 | * BUS block | 2746 | * BUS block |
@@ -2901,12 +2915,23 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, | |||
2901 | if (retval) | 2915 | if (retval) |
2902 | goto remove_dbg; | 2916 | goto remove_dbg; |
2903 | } | 2917 | } |
2918 | |||
2919 | retval = usb_add_gadget_udc(dev, &udc->gadget); | ||
2920 | if (retval) | ||
2921 | goto remove_trans; | ||
2922 | |||
2904 | pm_runtime_no_callbacks(&udc->gadget.dev); | 2923 | pm_runtime_no_callbacks(&udc->gadget.dev); |
2905 | pm_runtime_enable(&udc->gadget.dev); | 2924 | pm_runtime_enable(&udc->gadget.dev); |
2906 | 2925 | ||
2907 | _udc = udc; | 2926 | _udc = udc; |
2908 | return retval; | 2927 | return retval; |
2909 | 2928 | ||
2929 | remove_trans: | ||
2930 | if (udc->transceiver) { | ||
2931 | otg_set_peripheral(udc->transceiver, &udc->gadget); | ||
2932 | otg_put_transceiver(udc->transceiver); | ||
2933 | } | ||
2934 | |||
2910 | err("error = %i", retval); | 2935 | err("error = %i", retval); |
2911 | remove_dbg: | 2936 | remove_dbg: |
2912 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | 2937 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
@@ -2936,6 +2961,7 @@ static void udc_remove(void) | |||
2936 | err("EINVAL"); | 2961 | err("EINVAL"); |
2937 | return; | 2962 | return; |
2938 | } | 2963 | } |
2964 | usb_del_gadget_udc(&udc->gadget); | ||
2939 | 2965 | ||
2940 | if (udc->transceiver) { | 2966 | if (udc->transceiver) { |
2941 | otg_set_peripheral(udc->transceiver, &udc->gadget); | 2967 | otg_set_peripheral(udc->transceiver, &udc->gadget); |
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 5cbb1a41c223..5ef87794fd32 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include <linux/utsname.h> | 27 | #include <linux/utsname.h> |
28 | 28 | ||
29 | #include <linux/usb/composite.h> | 29 | #include <linux/usb/composite.h> |
30 | 30 | #include <asm/unaligned.h> | |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * The code in this file is utility code, used to build a gadget driver | 33 | * The code in this file is utility code, used to build a gadget driver |
@@ -74,6 +74,130 @@ MODULE_PARM_DESC(iSerialNumber, "SerialNumber string"); | |||
74 | static char composite_manufacturer[50]; | 74 | static char composite_manufacturer[50]; |
75 | 75 | ||
76 | /*-------------------------------------------------------------------------*/ | 76 | /*-------------------------------------------------------------------------*/ |
77 | /** | ||
78 | * next_ep_desc() - advance to the next EP descriptor | ||
79 | * @t: currect pointer within descriptor array | ||
80 | * | ||
81 | * Return: next EP descriptor or NULL | ||
82 | * | ||
83 | * Iterate over @t until either EP descriptor found or | ||
84 | * NULL (that indicates end of list) encountered | ||
85 | */ | ||
86 | static struct usb_descriptor_header** | ||
87 | next_ep_desc(struct usb_descriptor_header **t) | ||
88 | { | ||
89 | for (; *t; t++) { | ||
90 | if ((*t)->bDescriptorType == USB_DT_ENDPOINT) | ||
91 | return t; | ||
92 | } | ||
93 | return NULL; | ||
94 | } | ||
95 | |||
96 | /* | ||
97 | * for_each_ep_desc()- iterate over endpoint descriptors in the | ||
98 | * descriptors list | ||
99 | * @start: pointer within descriptor array. | ||
100 | * @ep_desc: endpoint descriptor to use as the loop cursor | ||
101 | */ | ||
102 | #define for_each_ep_desc(start, ep_desc) \ | ||
103 | for (ep_desc = next_ep_desc(start); \ | ||
104 | ep_desc; ep_desc = next_ep_desc(ep_desc+1)) | ||
105 | |||
106 | /** | ||
107 | * config_ep_by_speed() - configures the given endpoint | ||
108 | * according to gadget speed. | ||
109 | * @g: pointer to the gadget | ||
110 | * @f: usb function | ||
111 | * @_ep: the endpoint to configure | ||
112 | * | ||
113 | * Return: error code, 0 on success | ||
114 | * | ||
115 | * This function chooses the right descriptors for a given | ||
116 | * endpoint according to gadget speed and saves it in the | ||
117 | * endpoint desc field. If the endpoint already has a descriptor | ||
118 | * assigned to it - overwrites it with currently corresponding | ||
119 | * descriptor. The endpoint maxpacket field is updated according | ||
120 | * to the chosen descriptor. | ||
121 | * Note: the supplied function should hold all the descriptors | ||
122 | * for supported speeds | ||
123 | */ | ||
124 | int config_ep_by_speed(struct usb_gadget *g, | ||
125 | struct usb_function *f, | ||
126 | struct usb_ep *_ep) | ||
127 | { | ||
128 | struct usb_endpoint_descriptor *chosen_desc = NULL; | ||
129 | struct usb_descriptor_header **speed_desc = NULL; | ||
130 | |||
131 | struct usb_ss_ep_comp_descriptor *comp_desc = NULL; | ||
132 | int want_comp_desc = 0; | ||
133 | |||
134 | struct usb_descriptor_header **d_spd; /* cursor for speed desc */ | ||
135 | |||
136 | if (!g || !f || !_ep) | ||
137 | return -EIO; | ||
138 | |||
139 | /* select desired speed */ | ||
140 | switch (g->speed) { | ||
141 | case USB_SPEED_SUPER: | ||
142 | if (gadget_is_superspeed(g)) { | ||
143 | speed_desc = f->ss_descriptors; | ||
144 | want_comp_desc = 1; | ||
145 | break; | ||
146 | } | ||
147 | /* else: Fall trough */ | ||
148 | case USB_SPEED_HIGH: | ||
149 | if (gadget_is_dualspeed(g)) { | ||
150 | speed_desc = f->hs_descriptors; | ||
151 | break; | ||
152 | } | ||
153 | /* else: fall through */ | ||
154 | default: | ||
155 | speed_desc = f->descriptors; | ||
156 | } | ||
157 | /* find descriptors */ | ||
158 | for_each_ep_desc(speed_desc, d_spd) { | ||
159 | chosen_desc = (struct usb_endpoint_descriptor *)*d_spd; | ||
160 | if (chosen_desc->bEndpointAddress == _ep->address) | ||
161 | goto ep_found; | ||
162 | } | ||
163 | return -EIO; | ||
164 | |||
165 | ep_found: | ||
166 | /* commit results */ | ||
167 | _ep->maxpacket = le16_to_cpu(chosen_desc->wMaxPacketSize); | ||
168 | _ep->desc = chosen_desc; | ||
169 | _ep->comp_desc = NULL; | ||
170 | _ep->maxburst = 0; | ||
171 | _ep->mult = 0; | ||
172 | if (!want_comp_desc) | ||
173 | return 0; | ||
174 | |||
175 | /* | ||
176 | * Companion descriptor should follow EP descriptor | ||
177 | * USB 3.0 spec, #9.6.7 | ||
178 | */ | ||
179 | comp_desc = (struct usb_ss_ep_comp_descriptor *)*(++d_spd); | ||
180 | if (!comp_desc || | ||
181 | (comp_desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP)) | ||
182 | return -EIO; | ||
183 | _ep->comp_desc = comp_desc; | ||
184 | if (g->speed == USB_SPEED_SUPER) { | ||
185 | switch (usb_endpoint_type(_ep->desc)) { | ||
186 | case USB_ENDPOINT_XFER_BULK: | ||
187 | case USB_ENDPOINT_XFER_INT: | ||
188 | _ep->maxburst = comp_desc->bMaxBurst; | ||
189 | break; | ||
190 | case USB_ENDPOINT_XFER_ISOC: | ||
191 | /* mult: bits 1:0 of bmAttributes */ | ||
192 | _ep->mult = comp_desc->bmAttributes & 0x3; | ||
193 | break; | ||
194 | default: | ||
195 | /* Do nothing for control endpoints */ | ||
196 | break; | ||
197 | } | ||
198 | } | ||
199 | return 0; | ||
200 | } | ||
77 | 201 | ||
78 | /** | 202 | /** |
79 | * usb_add_function() - add a function to a configuration | 203 | * usb_add_function() - add a function to a configuration |
@@ -123,6 +247,8 @@ int usb_add_function(struct usb_configuration *config, | |||
123 | config->fullspeed = true; | 247 | config->fullspeed = true; |
124 | if (!config->highspeed && function->hs_descriptors) | 248 | if (!config->highspeed && function->hs_descriptors) |
125 | config->highspeed = true; | 249 | config->highspeed = true; |
250 | if (!config->superspeed && function->ss_descriptors) | ||
251 | config->superspeed = true; | ||
126 | 252 | ||
127 | done: | 253 | done: |
128 | if (value) | 254 | if (value) |
@@ -266,10 +392,17 @@ static int config_buf(struct usb_configuration *config, | |||
266 | list_for_each_entry(f, &config->functions, list) { | 392 | list_for_each_entry(f, &config->functions, list) { |
267 | struct usb_descriptor_header **descriptors; | 393 | struct usb_descriptor_header **descriptors; |
268 | 394 | ||
269 | if (speed == USB_SPEED_HIGH) | 395 | switch (speed) { |
396 | case USB_SPEED_SUPER: | ||
397 | descriptors = f->ss_descriptors; | ||
398 | break; | ||
399 | case USB_SPEED_HIGH: | ||
270 | descriptors = f->hs_descriptors; | 400 | descriptors = f->hs_descriptors; |
271 | else | 401 | break; |
402 | default: | ||
272 | descriptors = f->descriptors; | 403 | descriptors = f->descriptors; |
404 | } | ||
405 | |||
273 | if (!descriptors) | 406 | if (!descriptors) |
274 | continue; | 407 | continue; |
275 | status = usb_descriptor_fillbuf(next, len, | 408 | status = usb_descriptor_fillbuf(next, len, |
@@ -292,9 +425,10 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value) | |||
292 | u8 type = w_value >> 8; | 425 | u8 type = w_value >> 8; |
293 | enum usb_device_speed speed = USB_SPEED_UNKNOWN; | 426 | enum usb_device_speed speed = USB_SPEED_UNKNOWN; |
294 | 427 | ||
295 | if (gadget_is_dualspeed(gadget)) { | 428 | if (gadget->speed == USB_SPEED_SUPER) |
296 | int hs = 0; | 429 | speed = gadget->speed; |
297 | 430 | else if (gadget_is_dualspeed(gadget)) { | |
431 | int hs = 0; | ||
298 | if (gadget->speed == USB_SPEED_HIGH) | 432 | if (gadget->speed == USB_SPEED_HIGH) |
299 | hs = 1; | 433 | hs = 1; |
300 | if (type == USB_DT_OTHER_SPEED_CONFIG) | 434 | if (type == USB_DT_OTHER_SPEED_CONFIG) |
@@ -308,13 +442,20 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value) | |||
308 | w_value &= 0xff; | 442 | w_value &= 0xff; |
309 | list_for_each_entry(c, &cdev->configs, list) { | 443 | list_for_each_entry(c, &cdev->configs, list) { |
310 | /* ignore configs that won't work at this speed */ | 444 | /* ignore configs that won't work at this speed */ |
311 | if (speed == USB_SPEED_HIGH) { | 445 | switch (speed) { |
446 | case USB_SPEED_SUPER: | ||
447 | if (!c->superspeed) | ||
448 | continue; | ||
449 | break; | ||
450 | case USB_SPEED_HIGH: | ||
312 | if (!c->highspeed) | 451 | if (!c->highspeed) |
313 | continue; | 452 | continue; |
314 | } else { | 453 | break; |
454 | default: | ||
315 | if (!c->fullspeed) | 455 | if (!c->fullspeed) |
316 | continue; | 456 | continue; |
317 | } | 457 | } |
458 | |||
318 | if (w_value == 0) | 459 | if (w_value == 0) |
319 | return config_buf(c, speed, cdev->req->buf, type); | 460 | return config_buf(c, speed, cdev->req->buf, type); |
320 | w_value--; | 461 | w_value--; |
@@ -328,16 +469,22 @@ static int count_configs(struct usb_composite_dev *cdev, unsigned type) | |||
328 | struct usb_configuration *c; | 469 | struct usb_configuration *c; |
329 | unsigned count = 0; | 470 | unsigned count = 0; |
330 | int hs = 0; | 471 | int hs = 0; |
472 | int ss = 0; | ||
331 | 473 | ||
332 | if (gadget_is_dualspeed(gadget)) { | 474 | if (gadget_is_dualspeed(gadget)) { |
333 | if (gadget->speed == USB_SPEED_HIGH) | 475 | if (gadget->speed == USB_SPEED_HIGH) |
334 | hs = 1; | 476 | hs = 1; |
477 | if (gadget->speed == USB_SPEED_SUPER) | ||
478 | ss = 1; | ||
335 | if (type == USB_DT_DEVICE_QUALIFIER) | 479 | if (type == USB_DT_DEVICE_QUALIFIER) |
336 | hs = !hs; | 480 | hs = !hs; |
337 | } | 481 | } |
338 | list_for_each_entry(c, &cdev->configs, list) { | 482 | list_for_each_entry(c, &cdev->configs, list) { |
339 | /* ignore configs that won't work at this speed */ | 483 | /* ignore configs that won't work at this speed */ |
340 | if (hs) { | 484 | if (ss) { |
485 | if (!c->superspeed) | ||
486 | continue; | ||
487 | } else if (hs) { | ||
341 | if (!c->highspeed) | 488 | if (!c->highspeed) |
342 | continue; | 489 | continue; |
343 | } else { | 490 | } else { |
@@ -349,6 +496,71 @@ static int count_configs(struct usb_composite_dev *cdev, unsigned type) | |||
349 | return count; | 496 | return count; |
350 | } | 497 | } |
351 | 498 | ||
499 | /** | ||
500 | * bos_desc() - prepares the BOS descriptor. | ||
501 | * @cdev: pointer to usb_composite device to generate the bos | ||
502 | * descriptor for | ||
503 | * | ||
504 | * This function generates the BOS (Binary Device Object) | ||
505 | * descriptor and its device capabilities descriptors. The BOS | ||
506 | * descriptor should be supported by a SuperSpeed device. | ||
507 | */ | ||
508 | static int bos_desc(struct usb_composite_dev *cdev) | ||
509 | { | ||
510 | struct usb_ext_cap_descriptor *usb_ext; | ||
511 | struct usb_ss_cap_descriptor *ss_cap; | ||
512 | struct usb_dcd_config_params dcd_config_params; | ||
513 | struct usb_bos_descriptor *bos = cdev->req->buf; | ||
514 | |||
515 | bos->bLength = USB_DT_BOS_SIZE; | ||
516 | bos->bDescriptorType = USB_DT_BOS; | ||
517 | |||
518 | bos->wTotalLength = cpu_to_le16(USB_DT_BOS_SIZE); | ||
519 | bos->bNumDeviceCaps = 0; | ||
520 | |||
521 | /* | ||
522 | * A SuperSpeed device shall include the USB2.0 extension descriptor | ||
523 | * and shall support LPM when operating in USB2.0 HS mode. | ||
524 | */ | ||
525 | usb_ext = cdev->req->buf + le16_to_cpu(bos->wTotalLength); | ||
526 | bos->bNumDeviceCaps++; | ||
527 | le16_add_cpu(&bos->wTotalLength, USB_DT_USB_EXT_CAP_SIZE); | ||
528 | usb_ext->bLength = USB_DT_USB_EXT_CAP_SIZE; | ||
529 | usb_ext->bDescriptorType = USB_DT_DEVICE_CAPABILITY; | ||
530 | usb_ext->bDevCapabilityType = USB_CAP_TYPE_EXT; | ||
531 | usb_ext->bmAttributes = cpu_to_le32(USB_LPM_SUPPORT); | ||
532 | |||
533 | /* | ||
534 | * The Superspeed USB Capability descriptor shall be implemented by all | ||
535 | * SuperSpeed devices. | ||
536 | */ | ||
537 | ss_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength); | ||
538 | bos->bNumDeviceCaps++; | ||
539 | le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SS_CAP_SIZE); | ||
540 | ss_cap->bLength = USB_DT_USB_SS_CAP_SIZE; | ||
541 | ss_cap->bDescriptorType = USB_DT_DEVICE_CAPABILITY; | ||
542 | ss_cap->bDevCapabilityType = USB_SS_CAP_TYPE; | ||
543 | ss_cap->bmAttributes = 0; /* LTM is not supported yet */ | ||
544 | ss_cap->wSpeedSupported = cpu_to_le16(USB_LOW_SPEED_OPERATION | | ||
545 | USB_FULL_SPEED_OPERATION | | ||
546 | USB_HIGH_SPEED_OPERATION | | ||
547 | USB_5GBPS_OPERATION); | ||
548 | ss_cap->bFunctionalitySupport = USB_LOW_SPEED_OPERATION; | ||
549 | |||
550 | /* Get Controller configuration */ | ||
551 | if (cdev->gadget->ops->get_config_params) | ||
552 | cdev->gadget->ops->get_config_params(&dcd_config_params); | ||
553 | else { | ||
554 | dcd_config_params.bU1devExitLat = USB_DEFULT_U1_DEV_EXIT_LAT; | ||
555 | dcd_config_params.bU2DevExitLat = | ||
556 | cpu_to_le16(USB_DEFULT_U2_DEV_EXIT_LAT); | ||
557 | } | ||
558 | ss_cap->bU1devExitLat = dcd_config_params.bU1devExitLat; | ||
559 | ss_cap->bU2DevExitLat = dcd_config_params.bU2DevExitLat; | ||
560 | |||
561 | return le16_to_cpu(bos->wTotalLength); | ||
562 | } | ||
563 | |||
352 | static void device_qual(struct usb_composite_dev *cdev) | 564 | static void device_qual(struct usb_composite_dev *cdev) |
353 | { | 565 | { |
354 | struct usb_qualifier_descriptor *qual = cdev->req->buf; | 566 | struct usb_qualifier_descriptor *qual = cdev->req->buf; |
@@ -361,7 +573,7 @@ static void device_qual(struct usb_composite_dev *cdev) | |||
361 | qual->bDeviceSubClass = cdev->desc.bDeviceSubClass; | 573 | qual->bDeviceSubClass = cdev->desc.bDeviceSubClass; |
362 | qual->bDeviceProtocol = cdev->desc.bDeviceProtocol; | 574 | qual->bDeviceProtocol = cdev->desc.bDeviceProtocol; |
363 | /* ASSUME same EP0 fifo size at both speeds */ | 575 | /* ASSUME same EP0 fifo size at both speeds */ |
364 | qual->bMaxPacketSize0 = cdev->desc.bMaxPacketSize0; | 576 | qual->bMaxPacketSize0 = cdev->gadget->ep0->maxpacket; |
365 | qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER); | 577 | qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER); |
366 | qual->bRESERVED = 0; | 578 | qual->bRESERVED = 0; |
367 | } | 579 | } |
@@ -392,28 +604,46 @@ static int set_config(struct usb_composite_dev *cdev, | |||
392 | unsigned power = gadget_is_otg(gadget) ? 8 : 100; | 604 | unsigned power = gadget_is_otg(gadget) ? 8 : 100; |
393 | int tmp; | 605 | int tmp; |
394 | 606 | ||
395 | if (cdev->config) | ||
396 | reset_config(cdev); | ||
397 | |||
398 | if (number) { | 607 | if (number) { |
399 | list_for_each_entry(c, &cdev->configs, list) { | 608 | list_for_each_entry(c, &cdev->configs, list) { |
400 | if (c->bConfigurationValue == number) { | 609 | if (c->bConfigurationValue == number) { |
610 | /* | ||
611 | * We disable the FDs of the previous | ||
612 | * configuration only if the new configuration | ||
613 | * is a valid one | ||
614 | */ | ||
615 | if (cdev->config) | ||
616 | reset_config(cdev); | ||
401 | result = 0; | 617 | result = 0; |
402 | break; | 618 | break; |
403 | } | 619 | } |
404 | } | 620 | } |
405 | if (result < 0) | 621 | if (result < 0) |
406 | goto done; | 622 | goto done; |
407 | } else | 623 | } else { /* Zero configuration value - need to reset the config */ |
624 | if (cdev->config) | ||
625 | reset_config(cdev); | ||
408 | result = 0; | 626 | result = 0; |
627 | } | ||
409 | 628 | ||
410 | INFO(cdev, "%s speed config #%d: %s\n", | 629 | INFO(cdev, "%s speed config #%d: %s\n", |
411 | ({ char *speed; | 630 | ({ char *speed; |
412 | switch (gadget->speed) { | 631 | switch (gadget->speed) { |
413 | case USB_SPEED_LOW: speed = "low"; break; | 632 | case USB_SPEED_LOW: |
414 | case USB_SPEED_FULL: speed = "full"; break; | 633 | speed = "low"; |
415 | case USB_SPEED_HIGH: speed = "high"; break; | 634 | break; |
416 | default: speed = "?"; break; | 635 | case USB_SPEED_FULL: |
636 | speed = "full"; | ||
637 | break; | ||
638 | case USB_SPEED_HIGH: | ||
639 | speed = "high"; | ||
640 | break; | ||
641 | case USB_SPEED_SUPER: | ||
642 | speed = "super"; | ||
643 | break; | ||
644 | default: | ||
645 | speed = "?"; | ||
646 | break; | ||
417 | } ; speed; }), number, c ? c->label : "unconfigured"); | 647 | } ; speed; }), number, c ? c->label : "unconfigured"); |
418 | 648 | ||
419 | if (!c) | 649 | if (!c) |
@@ -435,10 +665,16 @@ static int set_config(struct usb_composite_dev *cdev, | |||
435 | * function's setup callback instead of the current | 665 | * function's setup callback instead of the current |
436 | * configuration's setup callback. | 666 | * configuration's setup callback. |
437 | */ | 667 | */ |
438 | if (gadget->speed == USB_SPEED_HIGH) | 668 | switch (gadget->speed) { |
669 | case USB_SPEED_SUPER: | ||
670 | descriptors = f->ss_descriptors; | ||
671 | break; | ||
672 | case USB_SPEED_HIGH: | ||
439 | descriptors = f->hs_descriptors; | 673 | descriptors = f->hs_descriptors; |
440 | else | 674 | break; |
675 | default: | ||
441 | descriptors = f->descriptors; | 676 | descriptors = f->descriptors; |
677 | } | ||
442 | 678 | ||
443 | for (; *descriptors; ++descriptors) { | 679 | for (; *descriptors; ++descriptors) { |
444 | struct usb_endpoint_descriptor *ep; | 680 | struct usb_endpoint_descriptor *ep; |
@@ -531,8 +767,9 @@ int usb_add_config(struct usb_composite_dev *cdev, | |||
531 | } else { | 767 | } else { |
532 | unsigned i; | 768 | unsigned i; |
533 | 769 | ||
534 | DBG(cdev, "cfg %d/%p speeds:%s%s\n", | 770 | DBG(cdev, "cfg %d/%p speeds:%s%s%s\n", |
535 | config->bConfigurationValue, config, | 771 | config->bConfigurationValue, config, |
772 | config->superspeed ? " super" : "", | ||
536 | config->highspeed ? " high" : "", | 773 | config->highspeed ? " high" : "", |
537 | config->fullspeed | 774 | config->fullspeed |
538 | ? (gadget_is_dualspeed(cdev->gadget) | 775 | ? (gadget_is_dualspeed(cdev->gadget) |
@@ -811,6 +1048,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
811 | struct usb_composite_dev *cdev = get_gadget_data(gadget); | 1048 | struct usb_composite_dev *cdev = get_gadget_data(gadget); |
812 | struct usb_request *req = cdev->req; | 1049 | struct usb_request *req = cdev->req; |
813 | int value = -EOPNOTSUPP; | 1050 | int value = -EOPNOTSUPP; |
1051 | int status = 0; | ||
814 | u16 w_index = le16_to_cpu(ctrl->wIndex); | 1052 | u16 w_index = le16_to_cpu(ctrl->wIndex); |
815 | u8 intf = w_index & 0xFF; | 1053 | u8 intf = w_index & 0xFF; |
816 | u16 w_value = le16_to_cpu(ctrl->wValue); | 1054 | u16 w_value = le16_to_cpu(ctrl->wValue); |
@@ -838,18 +1076,29 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
838 | case USB_DT_DEVICE: | 1076 | case USB_DT_DEVICE: |
839 | cdev->desc.bNumConfigurations = | 1077 | cdev->desc.bNumConfigurations = |
840 | count_configs(cdev, USB_DT_DEVICE); | 1078 | count_configs(cdev, USB_DT_DEVICE); |
1079 | cdev->desc.bMaxPacketSize0 = | ||
1080 | cdev->gadget->ep0->maxpacket; | ||
1081 | if (gadget_is_superspeed(gadget)) { | ||
1082 | if (gadget->speed >= USB_SPEED_SUPER) | ||
1083 | cdev->desc.bcdUSB = cpu_to_le16(0x0300); | ||
1084 | else | ||
1085 | cdev->desc.bcdUSB = cpu_to_le16(0x0210); | ||
1086 | } | ||
1087 | |||
841 | value = min(w_length, (u16) sizeof cdev->desc); | 1088 | value = min(w_length, (u16) sizeof cdev->desc); |
842 | memcpy(req->buf, &cdev->desc, value); | 1089 | memcpy(req->buf, &cdev->desc, value); |
843 | break; | 1090 | break; |
844 | case USB_DT_DEVICE_QUALIFIER: | 1091 | case USB_DT_DEVICE_QUALIFIER: |
845 | if (!gadget_is_dualspeed(gadget)) | 1092 | if (!gadget_is_dualspeed(gadget) || |
1093 | gadget->speed >= USB_SPEED_SUPER) | ||
846 | break; | 1094 | break; |
847 | device_qual(cdev); | 1095 | device_qual(cdev); |
848 | value = min_t(int, w_length, | 1096 | value = min_t(int, w_length, |
849 | sizeof(struct usb_qualifier_descriptor)); | 1097 | sizeof(struct usb_qualifier_descriptor)); |
850 | break; | 1098 | break; |
851 | case USB_DT_OTHER_SPEED_CONFIG: | 1099 | case USB_DT_OTHER_SPEED_CONFIG: |
852 | if (!gadget_is_dualspeed(gadget)) | 1100 | if (!gadget_is_dualspeed(gadget) || |
1101 | gadget->speed >= USB_SPEED_SUPER) | ||
853 | break; | 1102 | break; |
854 | /* FALLTHROUGH */ | 1103 | /* FALLTHROUGH */ |
855 | case USB_DT_CONFIG: | 1104 | case USB_DT_CONFIG: |
@@ -863,6 +1112,12 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
863 | if (value >= 0) | 1112 | if (value >= 0) |
864 | value = min(w_length, (u16) value); | 1113 | value = min(w_length, (u16) value); |
865 | break; | 1114 | break; |
1115 | case USB_DT_BOS: | ||
1116 | if (gadget_is_superspeed(gadget)) { | ||
1117 | value = bos_desc(cdev); | ||
1118 | value = min(w_length, (u16) value); | ||
1119 | } | ||
1120 | break; | ||
866 | } | 1121 | } |
867 | break; | 1122 | break; |
868 | 1123 | ||
@@ -930,6 +1185,61 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
930 | *((u8 *)req->buf) = value; | 1185 | *((u8 *)req->buf) = value; |
931 | value = min(w_length, (u16) 1); | 1186 | value = min(w_length, (u16) 1); |
932 | break; | 1187 | break; |
1188 | |||
1189 | /* | ||
1190 | * USB 3.0 additions: | ||
1191 | * Function driver should handle get_status request. If such cb | ||
1192 | * wasn't supplied we respond with default value = 0 | ||
1193 | * Note: function driver should supply such cb only for the first | ||
1194 | * interface of the function | ||
1195 | */ | ||
1196 | case USB_REQ_GET_STATUS: | ||
1197 | if (!gadget_is_superspeed(gadget)) | ||
1198 | goto unknown; | ||
1199 | if (ctrl->bRequestType != (USB_DIR_IN | USB_RECIP_INTERFACE)) | ||
1200 | goto unknown; | ||
1201 | value = 2; /* This is the length of the get_status reply */ | ||
1202 | put_unaligned_le16(0, req->buf); | ||
1203 | if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) | ||
1204 | break; | ||
1205 | f = cdev->config->interface[intf]; | ||
1206 | if (!f) | ||
1207 | break; | ||
1208 | status = f->get_status ? f->get_status(f) : 0; | ||
1209 | if (status < 0) | ||
1210 | break; | ||
1211 | put_unaligned_le16(status & 0x0000ffff, req->buf); | ||
1212 | break; | ||
1213 | /* | ||
1214 | * Function drivers should handle SetFeature/ClearFeature | ||
1215 | * (FUNCTION_SUSPEND) request. function_suspend cb should be supplied | ||
1216 | * only for the first interface of the function | ||
1217 | */ | ||
1218 | case USB_REQ_CLEAR_FEATURE: | ||
1219 | case USB_REQ_SET_FEATURE: | ||
1220 | if (!gadget_is_superspeed(gadget)) | ||
1221 | goto unknown; | ||
1222 | if (ctrl->bRequestType != (USB_DIR_OUT | USB_RECIP_INTERFACE)) | ||
1223 | goto unknown; | ||
1224 | switch (w_value) { | ||
1225 | case USB_INTRF_FUNC_SUSPEND: | ||
1226 | if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) | ||
1227 | break; | ||
1228 | f = cdev->config->interface[intf]; | ||
1229 | if (!f) | ||
1230 | break; | ||
1231 | value = 0; | ||
1232 | if (f->func_suspend) | ||
1233 | value = f->func_suspend(f, w_index >> 8); | ||
1234 | if (value < 0) { | ||
1235 | ERROR(cdev, | ||
1236 | "func_suspend() returned error %d\n", | ||
1237 | value); | ||
1238 | value = 0; | ||
1239 | } | ||
1240 | break; | ||
1241 | } | ||
1242 | break; | ||
933 | default: | 1243 | default: |
934 | unknown: | 1244 | unknown: |
935 | VDBG(cdev, | 1245 | VDBG(cdev, |
@@ -1140,7 +1450,6 @@ static int composite_bind(struct usb_gadget *gadget) | |||
1140 | goto fail; | 1450 | goto fail; |
1141 | 1451 | ||
1142 | cdev->desc = *composite->dev; | 1452 | cdev->desc = *composite->dev; |
1143 | cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket; | ||
1144 | 1453 | ||
1145 | /* standardized runtime overrides for device ID data */ | 1454 | /* standardized runtime overrides for device ID data */ |
1146 | if (idVendor) | 1455 | if (idVendor) |
@@ -1247,7 +1556,11 @@ composite_resume(struct usb_gadget *gadget) | |||
1247 | /*-------------------------------------------------------------------------*/ | 1556 | /*-------------------------------------------------------------------------*/ |
1248 | 1557 | ||
1249 | static struct usb_gadget_driver composite_driver = { | 1558 | static struct usb_gadget_driver composite_driver = { |
1559 | #ifdef CONFIG_USB_GADGET_SUPERSPEED | ||
1560 | .speed = USB_SPEED_SUPER, | ||
1561 | #else | ||
1250 | .speed = USB_SPEED_HIGH, | 1562 | .speed = USB_SPEED_HIGH, |
1563 | #endif | ||
1251 | 1564 | ||
1252 | .unbind = composite_unbind, | 1565 | .unbind = composite_unbind, |
1253 | 1566 | ||
@@ -1293,6 +1606,8 @@ int usb_composite_probe(struct usb_composite_driver *driver, | |||
1293 | driver->iProduct = driver->name; | 1606 | driver->iProduct = driver->name; |
1294 | composite_driver.function = (char *) driver->name; | 1607 | composite_driver.function = (char *) driver->name; |
1295 | composite_driver.driver.name = driver->name; | 1608 | composite_driver.driver.name = driver->name; |
1609 | composite_driver.speed = min((u8)composite_driver.speed, | ||
1610 | (u8)driver->max_speed); | ||
1296 | composite = driver; | 1611 | composite = driver; |
1297 | composite_gadget_bind = bind; | 1612 | composite_gadget_bind = bind; |
1298 | 1613 | ||
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c index 09084fd646ab..b2c001334876 100644 --- a/drivers/usb/gadget/config.c +++ b/drivers/usb/gadget/config.c | |||
@@ -165,28 +165,3 @@ usb_copy_descriptors(struct usb_descriptor_header **src) | |||
165 | return ret; | 165 | return ret; |
166 | } | 166 | } |
167 | 167 | ||
168 | /** | ||
169 | * usb_find_endpoint - find a copy of an endpoint descriptor | ||
170 | * @src: original vector of descriptors | ||
171 | * @copy: copy of @src | ||
172 | * @match: endpoint descriptor found in @src | ||
173 | * | ||
174 | * This returns the copy of the @match descriptor made for @copy. Its | ||
175 | * intended use is to help remembering the endpoint descriptor to use | ||
176 | * when enabling a given endpoint. | ||
177 | */ | ||
178 | struct usb_endpoint_descriptor * | ||
179 | usb_find_endpoint( | ||
180 | struct usb_descriptor_header **src, | ||
181 | struct usb_descriptor_header **copy, | ||
182 | struct usb_endpoint_descriptor *match | ||
183 | ) | ||
184 | { | ||
185 | while (*src) { | ||
186 | if (*src == (void *) match) | ||
187 | return (void *)*copy; | ||
188 | src++; | ||
189 | copy++; | ||
190 | } | ||
191 | return NULL; | ||
192 | } | ||
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c index dbe92ee88477..8beefdd36787 100644 --- a/drivers/usb/gadget/dbgp.c +++ b/drivers/usb/gadget/dbgp.c | |||
@@ -173,7 +173,9 @@ fail_1: | |||
173 | 173 | ||
174 | static int __enable_ep(struct usb_ep *ep, struct usb_endpoint_descriptor *desc) | 174 | static int __enable_ep(struct usb_ep *ep, struct usb_endpoint_descriptor *desc) |
175 | { | 175 | { |
176 | int err = usb_ep_enable(ep, desc); | 176 | int err; |
177 | ep->desc = desc; | ||
178 | err = usb_ep_enable(ep); | ||
177 | ep->driver_data = dbgp.gadget; | 179 | ep->driver_data = dbgp.gadget; |
178 | return err; | 180 | return err; |
179 | } | 181 | } |
@@ -268,8 +270,8 @@ static int __init dbgp_configure_endpoints(struct usb_gadget *gadget) | |||
268 | dbgp.serial->in = dbgp.i_ep; | 270 | dbgp.serial->in = dbgp.i_ep; |
269 | dbgp.serial->out = dbgp.o_ep; | 271 | dbgp.serial->out = dbgp.o_ep; |
270 | 272 | ||
271 | dbgp.serial->in_desc = &i_desc; | 273 | dbgp.serial->in->desc = &i_desc; |
272 | dbgp.serial->out_desc = &o_desc; | 274 | dbgp.serial->out->desc = &o_desc; |
273 | 275 | ||
274 | if (gserial_setup(gadget, 1) < 0) { | 276 | if (gserial_setup(gadget, 1) < 0) { |
275 | stp = 3; | 277 | stp = 3; |
@@ -312,7 +314,6 @@ static int __init dbgp_bind(struct usb_gadget *gadget) | |||
312 | 314 | ||
313 | dbgp.req->length = DBGP_REQ_EP0_LEN; | 315 | dbgp.req->length = DBGP_REQ_EP0_LEN; |
314 | gadget->ep0->driver_data = gadget; | 316 | gadget->ep0->driver_data = gadget; |
315 | device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; | ||
316 | 317 | ||
317 | #ifdef CONFIG_USB_G_DBGP_SERIAL | 318 | #ifdef CONFIG_USB_G_DBGP_SERIAL |
318 | dbgp.serial = kzalloc(sizeof(struct gserial), GFP_KERNEL); | 319 | dbgp.serial = kzalloc(sizeof(struct gserial), GFP_KERNEL); |
@@ -363,6 +364,7 @@ static int dbgp_setup(struct usb_gadget *gadget, | |||
363 | dev_dbg(&dbgp.gadget->dev, "setup: desc device\n"); | 364 | dev_dbg(&dbgp.gadget->dev, "setup: desc device\n"); |
364 | len = sizeof device_desc; | 365 | len = sizeof device_desc; |
365 | data = &device_desc; | 366 | data = &device_desc; |
367 | device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; | ||
366 | break; | 368 | break; |
367 | case USB_DT_DEBUG: | 369 | case USB_DT_DEBUG: |
368 | dev_dbg(&dbgp.gadget->dev, "setup: desc debug\n"); | 370 | dev_dbg(&dbgp.gadget->dev, "setup: desc debug\n"); |
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index d3dcabc1a5fc..e755a9d267fc 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -70,6 +70,19 @@ MODULE_DESCRIPTION (DRIVER_DESC); | |||
70 | MODULE_AUTHOR ("David Brownell"); | 70 | MODULE_AUTHOR ("David Brownell"); |
71 | MODULE_LICENSE ("GPL"); | 71 | MODULE_LICENSE ("GPL"); |
72 | 72 | ||
73 | struct dummy_hcd_module_parameters { | ||
74 | bool is_super_speed; | ||
75 | bool is_high_speed; | ||
76 | }; | ||
77 | |||
78 | static struct dummy_hcd_module_parameters mod_data = { | ||
79 | .is_super_speed = false, | ||
80 | .is_high_speed = true, | ||
81 | }; | ||
82 | module_param_named(is_super_speed, mod_data.is_super_speed, bool, S_IRUGO); | ||
83 | MODULE_PARM_DESC(is_super_speed, "true to simulate SuperSpeed connection"); | ||
84 | module_param_named(is_high_speed, mod_data.is_high_speed, bool, S_IRUGO); | ||
85 | MODULE_PARM_DESC(is_high_speed, "true to simulate HighSpeed connection"); | ||
73 | /*-------------------------------------------------------------------------*/ | 86 | /*-------------------------------------------------------------------------*/ |
74 | 87 | ||
75 | /* gadget side driver data structres */ | 88 | /* gadget side driver data structres */ |
@@ -152,6 +165,22 @@ enum dummy_rh_state { | |||
152 | DUMMY_RH_RUNNING | 165 | DUMMY_RH_RUNNING |
153 | }; | 166 | }; |
154 | 167 | ||
168 | struct dummy_hcd { | ||
169 | struct dummy *dum; | ||
170 | enum dummy_rh_state rh_state; | ||
171 | struct timer_list timer; | ||
172 | u32 port_status; | ||
173 | u32 old_status; | ||
174 | unsigned long re_timeout; | ||
175 | |||
176 | struct usb_device *udev; | ||
177 | struct list_head urbp_list; | ||
178 | |||
179 | unsigned active:1; | ||
180 | unsigned old_active:1; | ||
181 | unsigned resuming:1; | ||
182 | }; | ||
183 | |||
155 | struct dummy { | 184 | struct dummy { |
156 | spinlock_t lock; | 185 | spinlock_t lock; |
157 | 186 | ||
@@ -167,36 +196,27 @@ struct dummy { | |||
167 | u16 devstatus; | 196 | u16 devstatus; |
168 | unsigned udc_suspended:1; | 197 | unsigned udc_suspended:1; |
169 | unsigned pullup:1; | 198 | unsigned pullup:1; |
170 | unsigned active:1; | ||
171 | unsigned old_active:1; | ||
172 | 199 | ||
173 | /* | 200 | /* |
174 | * MASTER/HOST side support | 201 | * MASTER/HOST side support |
175 | */ | 202 | */ |
176 | enum dummy_rh_state rh_state; | 203 | struct dummy_hcd *hs_hcd; |
177 | struct timer_list timer; | 204 | struct dummy_hcd *ss_hcd; |
178 | u32 port_status; | ||
179 | u32 old_status; | ||
180 | unsigned resuming:1; | ||
181 | unsigned long re_timeout; | ||
182 | |||
183 | struct usb_device *udev; | ||
184 | struct list_head urbp_list; | ||
185 | }; | 205 | }; |
186 | 206 | ||
187 | static inline struct dummy *hcd_to_dummy (struct usb_hcd *hcd) | 207 | static inline struct dummy_hcd *hcd_to_dummy_hcd(struct usb_hcd *hcd) |
188 | { | 208 | { |
189 | return (struct dummy *) (hcd->hcd_priv); | 209 | return (struct dummy_hcd *) (hcd->hcd_priv); |
190 | } | 210 | } |
191 | 211 | ||
192 | static inline struct usb_hcd *dummy_to_hcd (struct dummy *dum) | 212 | static inline struct usb_hcd *dummy_hcd_to_hcd(struct dummy_hcd *dum) |
193 | { | 213 | { |
194 | return container_of((void *) dum, struct usb_hcd, hcd_priv); | 214 | return container_of((void *) dum, struct usb_hcd, hcd_priv); |
195 | } | 215 | } |
196 | 216 | ||
197 | static inline struct device *dummy_dev (struct dummy *dum) | 217 | static inline struct device *dummy_dev(struct dummy_hcd *dum) |
198 | { | 218 | { |
199 | return dummy_to_hcd(dum)->self.controller; | 219 | return dummy_hcd_to_hcd(dum)->self.controller; |
200 | } | 220 | } |
201 | 221 | ||
202 | static inline struct device *udc_dev (struct dummy *dum) | 222 | static inline struct device *udc_dev (struct dummy *dum) |
@@ -209,9 +229,13 @@ static inline struct dummy *ep_to_dummy (struct dummy_ep *ep) | |||
209 | return container_of (ep->gadget, struct dummy, gadget); | 229 | return container_of (ep->gadget, struct dummy, gadget); |
210 | } | 230 | } |
211 | 231 | ||
212 | static inline struct dummy *gadget_to_dummy (struct usb_gadget *gadget) | 232 | static inline struct dummy_hcd *gadget_to_dummy_hcd(struct usb_gadget *gadget) |
213 | { | 233 | { |
214 | return container_of (gadget, struct dummy, gadget); | 234 | struct dummy *dum = container_of(gadget, struct dummy, gadget); |
235 | if (dum->gadget.speed == USB_SPEED_SUPER) | ||
236 | return dum->ss_hcd; | ||
237 | else | ||
238 | return dum->hs_hcd; | ||
215 | } | 239 | } |
216 | 240 | ||
217 | static inline struct dummy *gadget_dev_to_dummy (struct device *dev) | 241 | static inline struct dummy *gadget_dev_to_dummy (struct device *dev) |
@@ -219,7 +243,7 @@ static inline struct dummy *gadget_dev_to_dummy (struct device *dev) | |||
219 | return container_of (dev, struct dummy, gadget.dev); | 243 | return container_of (dev, struct dummy, gadget.dev); |
220 | } | 244 | } |
221 | 245 | ||
222 | static struct dummy *the_controller; | 246 | static struct dummy the_controller; |
223 | 247 | ||
224 | /*-------------------------------------------------------------------------*/ | 248 | /*-------------------------------------------------------------------------*/ |
225 | 249 | ||
@@ -259,61 +283,122 @@ stop_activity (struct dummy *dum) | |||
259 | /* driver now does any non-usb quiescing necessary */ | 283 | /* driver now does any non-usb quiescing necessary */ |
260 | } | 284 | } |
261 | 285 | ||
262 | /* caller must hold lock */ | 286 | /** |
263 | static void | 287 | * set_link_state_by_speed() - Sets the current state of the link according to |
264 | set_link_state (struct dummy *dum) | 288 | * the hcd speed |
265 | { | 289 | * @dum_hcd: pointer to the dummy_hcd structure to update the link state for |
266 | dum->active = 0; | 290 | * |
267 | if ((dum->port_status & USB_PORT_STAT_POWER) == 0) | 291 | * This function updates the port_status according to the link state and the |
268 | dum->port_status = 0; | 292 | * speed of the hcd. |
269 | 293 | */ | |
270 | /* UDC suspend must cause a disconnect */ | 294 | static void set_link_state_by_speed(struct dummy_hcd *dum_hcd) |
271 | else if (!dum->pullup || dum->udc_suspended) { | 295 | { |
272 | dum->port_status &= ~(USB_PORT_STAT_CONNECTION | | 296 | struct dummy *dum = dum_hcd->dum; |
273 | USB_PORT_STAT_ENABLE | | 297 | |
274 | USB_PORT_STAT_LOW_SPEED | | 298 | if (dummy_hcd_to_hcd(dum_hcd)->speed == HCD_USB3) { |
275 | USB_PORT_STAT_HIGH_SPEED | | 299 | if ((dum_hcd->port_status & USB_SS_PORT_STAT_POWER) == 0) { |
276 | USB_PORT_STAT_SUSPEND); | 300 | dum_hcd->port_status = 0; |
277 | if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0) | 301 | } else if (!dum->pullup || dum->udc_suspended) { |
278 | dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); | 302 | /* UDC suspend must cause a disconnect */ |
303 | dum_hcd->port_status &= ~(USB_PORT_STAT_CONNECTION | | ||
304 | USB_PORT_STAT_ENABLE); | ||
305 | if ((dum_hcd->old_status & | ||
306 | USB_PORT_STAT_CONNECTION) != 0) | ||
307 | dum_hcd->port_status |= | ||
308 | (USB_PORT_STAT_C_CONNECTION << 16); | ||
309 | } else { | ||
310 | /* device is connected and not suspended */ | ||
311 | dum_hcd->port_status |= (USB_PORT_STAT_CONNECTION | | ||
312 | USB_PORT_STAT_SPEED_5GBPS) ; | ||
313 | if ((dum_hcd->old_status & | ||
314 | USB_PORT_STAT_CONNECTION) == 0) | ||
315 | dum_hcd->port_status |= | ||
316 | (USB_PORT_STAT_C_CONNECTION << 16); | ||
317 | if ((dum_hcd->port_status & | ||
318 | USB_PORT_STAT_ENABLE) == 1 && | ||
319 | (dum_hcd->port_status & | ||
320 | USB_SS_PORT_LS_U0) == 1 && | ||
321 | dum_hcd->rh_state != DUMMY_RH_SUSPENDED) | ||
322 | dum_hcd->active = 1; | ||
323 | } | ||
279 | } else { | 324 | } else { |
280 | dum->port_status |= USB_PORT_STAT_CONNECTION; | 325 | if ((dum_hcd->port_status & USB_PORT_STAT_POWER) == 0) { |
281 | if ((dum->old_status & USB_PORT_STAT_CONNECTION) == 0) | 326 | dum_hcd->port_status = 0; |
282 | dum->port_status |= (USB_PORT_STAT_C_CONNECTION << 16); | 327 | } else if (!dum->pullup || dum->udc_suspended) { |
283 | if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0) | 328 | /* UDC suspend must cause a disconnect */ |
284 | dum->port_status &= ~USB_PORT_STAT_SUSPEND; | 329 | dum_hcd->port_status &= ~(USB_PORT_STAT_CONNECTION | |
285 | else if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 && | 330 | USB_PORT_STAT_ENABLE | |
286 | dum->rh_state != DUMMY_RH_SUSPENDED) | 331 | USB_PORT_STAT_LOW_SPEED | |
287 | dum->active = 1; | 332 | USB_PORT_STAT_HIGH_SPEED | |
333 | USB_PORT_STAT_SUSPEND); | ||
334 | if ((dum_hcd->old_status & | ||
335 | USB_PORT_STAT_CONNECTION) != 0) | ||
336 | dum_hcd->port_status |= | ||
337 | (USB_PORT_STAT_C_CONNECTION << 16); | ||
338 | } else { | ||
339 | dum_hcd->port_status |= USB_PORT_STAT_CONNECTION; | ||
340 | if ((dum_hcd->old_status & | ||
341 | USB_PORT_STAT_CONNECTION) == 0) | ||
342 | dum_hcd->port_status |= | ||
343 | (USB_PORT_STAT_C_CONNECTION << 16); | ||
344 | if ((dum_hcd->port_status & USB_PORT_STAT_ENABLE) == 0) | ||
345 | dum_hcd->port_status &= ~USB_PORT_STAT_SUSPEND; | ||
346 | else if ((dum_hcd->port_status & | ||
347 | USB_PORT_STAT_SUSPEND) == 0 && | ||
348 | dum_hcd->rh_state != DUMMY_RH_SUSPENDED) | ||
349 | dum_hcd->active = 1; | ||
350 | } | ||
288 | } | 351 | } |
352 | } | ||
353 | |||
354 | /* caller must hold lock */ | ||
355 | static void set_link_state(struct dummy_hcd *dum_hcd) | ||
356 | { | ||
357 | struct dummy *dum = dum_hcd->dum; | ||
289 | 358 | ||
290 | if ((dum->port_status & USB_PORT_STAT_ENABLE) == 0 || dum->active) | 359 | dum_hcd->active = 0; |
291 | dum->resuming = 0; | 360 | if (dum->pullup) |
361 | if ((dummy_hcd_to_hcd(dum_hcd)->speed == HCD_USB3 && | ||
362 | dum->gadget.speed != USB_SPEED_SUPER) || | ||
363 | (dummy_hcd_to_hcd(dum_hcd)->speed != HCD_USB3 && | ||
364 | dum->gadget.speed == USB_SPEED_SUPER)) | ||
365 | return; | ||
292 | 366 | ||
293 | if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0 || | 367 | set_link_state_by_speed(dum_hcd); |
294 | (dum->port_status & USB_PORT_STAT_RESET) != 0) { | 368 | |
295 | if ((dum->old_status & USB_PORT_STAT_CONNECTION) != 0 && | 369 | if ((dum_hcd->port_status & USB_PORT_STAT_ENABLE) == 0 || |
296 | (dum->old_status & USB_PORT_STAT_RESET) == 0 && | 370 | dum_hcd->active) |
297 | dum->driver) { | 371 | dum_hcd->resuming = 0; |
298 | stop_activity (dum); | 372 | |
299 | spin_unlock (&dum->lock); | 373 | /* if !connected or reset */ |
300 | dum->driver->disconnect (&dum->gadget); | 374 | if ((dum_hcd->port_status & USB_PORT_STAT_CONNECTION) == 0 || |
301 | spin_lock (&dum->lock); | 375 | (dum_hcd->port_status & USB_PORT_STAT_RESET) != 0) { |
376 | /* | ||
377 | * We're connected and not reset (reset occurred now), | ||
378 | * and driver attached - disconnect! | ||
379 | */ | ||
380 | if ((dum_hcd->old_status & USB_PORT_STAT_CONNECTION) != 0 && | ||
381 | (dum_hcd->old_status & USB_PORT_STAT_RESET) == 0 && | ||
382 | dum->driver) { | ||
383 | stop_activity(dum); | ||
384 | spin_unlock(&dum->lock); | ||
385 | dum->driver->disconnect(&dum->gadget); | ||
386 | spin_lock(&dum->lock); | ||
302 | } | 387 | } |
303 | } else if (dum->active != dum->old_active) { | 388 | } else if (dum_hcd->active != dum_hcd->old_active) { |
304 | if (dum->old_active && dum->driver->suspend) { | 389 | if (dum_hcd->old_active && dum->driver->suspend) { |
305 | spin_unlock (&dum->lock); | 390 | spin_unlock(&dum->lock); |
306 | dum->driver->suspend (&dum->gadget); | 391 | dum->driver->suspend(&dum->gadget); |
307 | spin_lock (&dum->lock); | 392 | spin_lock(&dum->lock); |
308 | } else if (!dum->old_active && dum->driver->resume) { | 393 | } else if (!dum_hcd->old_active && dum->driver->resume) { |
309 | spin_unlock (&dum->lock); | 394 | spin_unlock(&dum->lock); |
310 | dum->driver->resume (&dum->gadget); | 395 | dum->driver->resume(&dum->gadget); |
311 | spin_lock (&dum->lock); | 396 | spin_lock(&dum->lock); |
312 | } | 397 | } |
313 | } | 398 | } |
314 | 399 | ||
315 | dum->old_status = dum->port_status; | 400 | dum_hcd->old_status = dum_hcd->port_status; |
316 | dum->old_active = dum->active; | 401 | dum_hcd->old_active = dum_hcd->active; |
317 | } | 402 | } |
318 | 403 | ||
319 | /*-------------------------------------------------------------------------*/ | 404 | /*-------------------------------------------------------------------------*/ |
@@ -332,6 +417,7 @@ static int | |||
332 | dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | 417 | dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) |
333 | { | 418 | { |
334 | struct dummy *dum; | 419 | struct dummy *dum; |
420 | struct dummy_hcd *dum_hcd; | ||
335 | struct dummy_ep *ep; | 421 | struct dummy_ep *ep; |
336 | unsigned max; | 422 | unsigned max; |
337 | int retval; | 423 | int retval; |
@@ -341,9 +427,19 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
341 | || desc->bDescriptorType != USB_DT_ENDPOINT) | 427 | || desc->bDescriptorType != USB_DT_ENDPOINT) |
342 | return -EINVAL; | 428 | return -EINVAL; |
343 | dum = ep_to_dummy (ep); | 429 | dum = ep_to_dummy (ep); |
344 | if (!dum->driver || !is_enabled (dum)) | 430 | if (!dum->driver) |
431 | return -ESHUTDOWN; | ||
432 | |||
433 | dum_hcd = gadget_to_dummy_hcd(&dum->gadget); | ||
434 | if (!is_enabled(dum_hcd)) | ||
345 | return -ESHUTDOWN; | 435 | return -ESHUTDOWN; |
346 | max = le16_to_cpu(desc->wMaxPacketSize) & 0x3ff; | 436 | |
437 | /* | ||
438 | * For HS/FS devices only bits 0..10 of the wMaxPacketSize represent the | ||
439 | * maximum packet size. | ||
440 | * For SS devices the wMaxPacketSize is limited by 1024. | ||
441 | */ | ||
442 | max = le16_to_cpu(desc->wMaxPacketSize) & 0x7ff; | ||
347 | 443 | ||
348 | /* drivers must not request bad settings, since lower levels | 444 | /* drivers must not request bad settings, since lower levels |
349 | * (hardware or its drivers) may not check. some endpoints | 445 | * (hardware or its drivers) may not check. some endpoints |
@@ -361,6 +457,10 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
361 | goto done; | 457 | goto done; |
362 | } | 458 | } |
363 | switch (dum->gadget.speed) { | 459 | switch (dum->gadget.speed) { |
460 | case USB_SPEED_SUPER: | ||
461 | if (max == 1024) | ||
462 | break; | ||
463 | goto done; | ||
364 | case USB_SPEED_HIGH: | 464 | case USB_SPEED_HIGH: |
365 | if (max == 512) | 465 | if (max == 512) |
366 | break; | 466 | break; |
@@ -379,6 +479,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
379 | goto done; | 479 | goto done; |
380 | /* real hardware might not handle all packet sizes */ | 480 | /* real hardware might not handle all packet sizes */ |
381 | switch (dum->gadget.speed) { | 481 | switch (dum->gadget.speed) { |
482 | case USB_SPEED_SUPER: | ||
382 | case USB_SPEED_HIGH: | 483 | case USB_SPEED_HIGH: |
383 | if (max <= 1024) | 484 | if (max <= 1024) |
384 | break; | 485 | break; |
@@ -399,6 +500,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
399 | goto done; | 500 | goto done; |
400 | /* real hardware might not handle all packet sizes */ | 501 | /* real hardware might not handle all packet sizes */ |
401 | switch (dum->gadget.speed) { | 502 | switch (dum->gadget.speed) { |
503 | case USB_SPEED_SUPER: | ||
402 | case USB_SPEED_HIGH: | 504 | case USB_SPEED_HIGH: |
403 | if (max <= 1024) | 505 | if (max <= 1024) |
404 | break; | 506 | break; |
@@ -425,10 +527,18 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
425 | (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", | 527 | (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", |
426 | ({ char *val; | 528 | ({ char *val; |
427 | switch (desc->bmAttributes & 0x03) { | 529 | switch (desc->bmAttributes & 0x03) { |
428 | case USB_ENDPOINT_XFER_BULK: val = "bulk"; break; | 530 | case USB_ENDPOINT_XFER_BULK: |
429 | case USB_ENDPOINT_XFER_ISOC: val = "iso"; break; | 531 | val = "bulk"; |
430 | case USB_ENDPOINT_XFER_INT: val = "intr"; break; | 532 | break; |
431 | default: val = "ctrl"; break; | 533 | case USB_ENDPOINT_XFER_ISOC: |
534 | val = "iso"; | ||
535 | break; | ||
536 | case USB_ENDPOINT_XFER_INT: | ||
537 | val = "intr"; | ||
538 | break; | ||
539 | default: | ||
540 | val = "ctrl"; | ||
541 | break; | ||
432 | }; val; }), | 542 | }; val; }), |
433 | max); | 543 | max); |
434 | 544 | ||
@@ -507,6 +617,7 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req, | |||
507 | struct dummy_ep *ep; | 617 | struct dummy_ep *ep; |
508 | struct dummy_request *req; | 618 | struct dummy_request *req; |
509 | struct dummy *dum; | 619 | struct dummy *dum; |
620 | struct dummy_hcd *dum_hcd; | ||
510 | unsigned long flags; | 621 | unsigned long flags; |
511 | 622 | ||
512 | req = usb_request_to_dummy_request (_req); | 623 | req = usb_request_to_dummy_request (_req); |
@@ -518,7 +629,8 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req, | |||
518 | return -EINVAL; | 629 | return -EINVAL; |
519 | 630 | ||
520 | dum = ep_to_dummy (ep); | 631 | dum = ep_to_dummy (ep); |
521 | if (!dum->driver || !is_enabled (dum)) | 632 | dum_hcd = gadget_to_dummy_hcd(&dum->gadget); |
633 | if (!dum->driver || !is_enabled(dum_hcd)) | ||
522 | return -ESHUTDOWN; | 634 | return -ESHUTDOWN; |
523 | 635 | ||
524 | #if 0 | 636 | #if 0 |
@@ -662,24 +774,24 @@ static int dummy_g_get_frame (struct usb_gadget *_gadget) | |||
662 | 774 | ||
663 | static int dummy_wakeup (struct usb_gadget *_gadget) | 775 | static int dummy_wakeup (struct usb_gadget *_gadget) |
664 | { | 776 | { |
665 | struct dummy *dum; | 777 | struct dummy_hcd *dum_hcd; |
666 | 778 | ||
667 | dum = gadget_to_dummy (_gadget); | 779 | dum_hcd = gadget_to_dummy_hcd(_gadget); |
668 | if (!(dum->devstatus & ( (1 << USB_DEVICE_B_HNP_ENABLE) | 780 | if (!(dum_hcd->dum->devstatus & ((1 << USB_DEVICE_B_HNP_ENABLE) |
669 | | (1 << USB_DEVICE_REMOTE_WAKEUP)))) | 781 | | (1 << USB_DEVICE_REMOTE_WAKEUP)))) |
670 | return -EINVAL; | 782 | return -EINVAL; |
671 | if ((dum->port_status & USB_PORT_STAT_CONNECTION) == 0) | 783 | if ((dum_hcd->port_status & USB_PORT_STAT_CONNECTION) == 0) |
672 | return -ENOLINK; | 784 | return -ENOLINK; |
673 | if ((dum->port_status & USB_PORT_STAT_SUSPEND) == 0 && | 785 | if ((dum_hcd->port_status & USB_PORT_STAT_SUSPEND) == 0 && |
674 | dum->rh_state != DUMMY_RH_SUSPENDED) | 786 | dum_hcd->rh_state != DUMMY_RH_SUSPENDED) |
675 | return -EIO; | 787 | return -EIO; |
676 | 788 | ||
677 | /* FIXME: What if the root hub is suspended but the port isn't? */ | 789 | /* FIXME: What if the root hub is suspended but the port isn't? */ |
678 | 790 | ||
679 | /* hub notices our request, issues downstream resume, etc */ | 791 | /* hub notices our request, issues downstream resume, etc */ |
680 | dum->resuming = 1; | 792 | dum_hcd->resuming = 1; |
681 | dum->re_timeout = jiffies + msecs_to_jiffies(20); | 793 | dum_hcd->re_timeout = jiffies + msecs_to_jiffies(20); |
682 | mod_timer (&dummy_to_hcd (dum)->rh_timer, dum->re_timeout); | 794 | mod_timer(&dummy_hcd_to_hcd(dum_hcd)->rh_timer, dum_hcd->re_timeout); |
683 | return 0; | 795 | return 0; |
684 | } | 796 | } |
685 | 797 | ||
@@ -687,7 +799,7 @@ static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value) | |||
687 | { | 799 | { |
688 | struct dummy *dum; | 800 | struct dummy *dum; |
689 | 801 | ||
690 | dum = gadget_to_dummy (_gadget); | 802 | dum = (gadget_to_dummy_hcd(_gadget))->dum; |
691 | if (value) | 803 | if (value) |
692 | dum->devstatus |= (1 << USB_DEVICE_SELF_POWERED); | 804 | dum->devstatus |= (1 << USB_DEVICE_SELF_POWERED); |
693 | else | 805 | else |
@@ -695,26 +807,68 @@ static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value) | |||
695 | return 0; | 807 | return 0; |
696 | } | 808 | } |
697 | 809 | ||
810 | static void dummy_udc_udpate_ep0(struct dummy *dum) | ||
811 | { | ||
812 | u32 i; | ||
813 | |||
814 | if (dum->gadget.speed == USB_SPEED_SUPER) { | ||
815 | for (i = 0; i < DUMMY_ENDPOINTS; i++) | ||
816 | dum->ep[i].ep.max_streams = 0x10; | ||
817 | dum->ep[0].ep.maxpacket = 9; | ||
818 | } else { | ||
819 | for (i = 0; i < DUMMY_ENDPOINTS; i++) | ||
820 | dum->ep[i].ep.max_streams = 0; | ||
821 | dum->ep[0].ep.maxpacket = 64; | ||
822 | } | ||
823 | } | ||
824 | |||
698 | static int dummy_pullup (struct usb_gadget *_gadget, int value) | 825 | static int dummy_pullup (struct usb_gadget *_gadget, int value) |
699 | { | 826 | { |
827 | struct dummy_hcd *dum_hcd; | ||
700 | struct dummy *dum; | 828 | struct dummy *dum; |
701 | unsigned long flags; | 829 | unsigned long flags; |
702 | 830 | ||
703 | dum = gadget_to_dummy (_gadget); | 831 | dum = gadget_dev_to_dummy(&_gadget->dev); |
832 | |||
833 | if (value && dum->driver) { | ||
834 | if (mod_data.is_super_speed) | ||
835 | dum->gadget.speed = dum->driver->speed; | ||
836 | else if (mod_data.is_high_speed) | ||
837 | dum->gadget.speed = min_t(u8, USB_SPEED_HIGH, | ||
838 | dum->driver->speed); | ||
839 | else | ||
840 | dum->gadget.speed = USB_SPEED_FULL; | ||
841 | dummy_udc_udpate_ep0(dum); | ||
842 | |||
843 | if (dum->gadget.speed < dum->driver->speed) | ||
844 | dev_dbg(udc_dev(dum), "This device can perform faster" | ||
845 | " if you connect it to a %s port...\n", | ||
846 | (dum->driver->speed == USB_SPEED_SUPER ? | ||
847 | "SuperSpeed" : "HighSpeed")); | ||
848 | } | ||
849 | dum_hcd = gadget_to_dummy_hcd(_gadget); | ||
850 | |||
704 | spin_lock_irqsave (&dum->lock, flags); | 851 | spin_lock_irqsave (&dum->lock, flags); |
705 | dum->pullup = (value != 0); | 852 | dum->pullup = (value != 0); |
706 | set_link_state (dum); | 853 | set_link_state(dum_hcd); |
707 | spin_unlock_irqrestore (&dum->lock, flags); | 854 | spin_unlock_irqrestore (&dum->lock, flags); |
708 | 855 | ||
709 | usb_hcd_poll_rh_status (dummy_to_hcd (dum)); | 856 | usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd)); |
710 | return 0; | 857 | return 0; |
711 | } | 858 | } |
712 | 859 | ||
860 | static int dummy_udc_start(struct usb_gadget *g, | ||
861 | struct usb_gadget_driver *driver); | ||
862 | static int dummy_udc_stop(struct usb_gadget *g, | ||
863 | struct usb_gadget_driver *driver); | ||
864 | |||
713 | static const struct usb_gadget_ops dummy_ops = { | 865 | static const struct usb_gadget_ops dummy_ops = { |
714 | .get_frame = dummy_g_get_frame, | 866 | .get_frame = dummy_g_get_frame, |
715 | .wakeup = dummy_wakeup, | 867 | .wakeup = dummy_wakeup, |
716 | .set_selfpowered = dummy_set_selfpowered, | 868 | .set_selfpowered = dummy_set_selfpowered, |
717 | .pullup = dummy_pullup, | 869 | .pullup = dummy_pullup, |
870 | .udc_start = dummy_udc_start, | ||
871 | .udc_stop = dummy_udc_stop, | ||
718 | }; | 872 | }; |
719 | 873 | ||
720 | /*-------------------------------------------------------------------------*/ | 874 | /*-------------------------------------------------------------------------*/ |
@@ -747,18 +901,13 @@ static DEVICE_ATTR (function, S_IRUGO, show_function, NULL); | |||
747 | * for each driver that registers: just add to a big root hub. | 901 | * for each driver that registers: just add to a big root hub. |
748 | */ | 902 | */ |
749 | 903 | ||
750 | int | 904 | static int dummy_udc_start(struct usb_gadget *g, |
751 | usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 905 | struct usb_gadget_driver *driver) |
752 | int (*bind)(struct usb_gadget *)) | ||
753 | { | 906 | { |
754 | struct dummy *dum = the_controller; | 907 | struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g); |
755 | int retval, i; | 908 | struct dummy *dum = dum_hcd->dum; |
756 | 909 | ||
757 | if (!dum) | 910 | if (driver->speed == USB_SPEED_UNKNOWN) |
758 | return -EINVAL; | ||
759 | if (dum->driver) | ||
760 | return -EBUSY; | ||
761 | if (!bind || !driver->setup || driver->speed == USB_SPEED_UNKNOWN) | ||
762 | return -EINVAL; | 911 | return -EINVAL; |
763 | 912 | ||
764 | /* | 913 | /* |
@@ -768,121 +917,77 @@ usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
768 | 917 | ||
769 | dum->devstatus = 0; | 918 | dum->devstatus = 0; |
770 | 919 | ||
771 | INIT_LIST_HEAD (&dum->gadget.ep_list); | ||
772 | for (i = 0; i < DUMMY_ENDPOINTS; i++) { | ||
773 | struct dummy_ep *ep = &dum->ep [i]; | ||
774 | |||
775 | if (!ep_name [i]) | ||
776 | break; | ||
777 | ep->ep.name = ep_name [i]; | ||
778 | ep->ep.ops = &dummy_ep_ops; | ||
779 | list_add_tail (&ep->ep.ep_list, &dum->gadget.ep_list); | ||
780 | ep->halted = ep->wedged = ep->already_seen = | ||
781 | ep->setup_stage = 0; | ||
782 | ep->ep.maxpacket = ~0; | ||
783 | ep->last_io = jiffies; | ||
784 | ep->gadget = &dum->gadget; | ||
785 | ep->desc = NULL; | ||
786 | INIT_LIST_HEAD (&ep->queue); | ||
787 | } | ||
788 | |||
789 | dum->gadget.ep0 = &dum->ep [0].ep; | ||
790 | dum->ep [0].ep.maxpacket = 64; | ||
791 | list_del_init (&dum->ep [0].ep.ep_list); | ||
792 | INIT_LIST_HEAD(&dum->fifo_req.queue); | ||
793 | |||
794 | driver->driver.bus = NULL; | ||
795 | dum->driver = driver; | 920 | dum->driver = driver; |
796 | dum->gadget.dev.driver = &driver->driver; | ||
797 | dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", | 921 | dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", |
798 | driver->driver.name); | 922 | driver->driver.name); |
799 | retval = bind(&dum->gadget); | ||
800 | if (retval) { | ||
801 | dum->driver = NULL; | ||
802 | dum->gadget.dev.driver = NULL; | ||
803 | return retval; | ||
804 | } | ||
805 | |||
806 | /* khubd will enumerate this in a while */ | ||
807 | spin_lock_irq (&dum->lock); | ||
808 | dum->pullup = 1; | ||
809 | set_link_state (dum); | ||
810 | spin_unlock_irq (&dum->lock); | ||
811 | |||
812 | usb_hcd_poll_rh_status (dummy_to_hcd (dum)); | ||
813 | return 0; | 923 | return 0; |
814 | } | 924 | } |
815 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
816 | 925 | ||
817 | int | 926 | static int dummy_udc_stop(struct usb_gadget *g, |
818 | usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | 927 | struct usb_gadget_driver *driver) |
819 | { | 928 | { |
820 | struct dummy *dum = the_controller; | 929 | struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g); |
821 | unsigned long flags; | 930 | struct dummy *dum = dum_hcd->dum; |
822 | |||
823 | if (!dum) | ||
824 | return -ENODEV; | ||
825 | if (!driver || driver != dum->driver || !driver->unbind) | ||
826 | return -EINVAL; | ||
827 | 931 | ||
828 | dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n", | 932 | dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n", |
829 | driver->driver.name); | 933 | driver->driver.name); |
830 | 934 | ||
831 | spin_lock_irqsave (&dum->lock, flags); | ||
832 | dum->pullup = 0; | ||
833 | set_link_state (dum); | ||
834 | spin_unlock_irqrestore (&dum->lock, flags); | ||
835 | |||
836 | driver->unbind (&dum->gadget); | ||
837 | dum->gadget.dev.driver = NULL; | ||
838 | dum->driver = NULL; | 935 | dum->driver = NULL; |
839 | 936 | ||
840 | spin_lock_irqsave (&dum->lock, flags); | 937 | dummy_pullup(&dum->gadget, 0); |
841 | dum->pullup = 0; | ||
842 | set_link_state (dum); | ||
843 | spin_unlock_irqrestore (&dum->lock, flags); | ||
844 | |||
845 | usb_hcd_poll_rh_status (dummy_to_hcd (dum)); | ||
846 | return 0; | 938 | return 0; |
847 | } | 939 | } |
848 | EXPORT_SYMBOL (usb_gadget_unregister_driver); | ||
849 | 940 | ||
850 | #undef is_enabled | 941 | #undef is_enabled |
851 | 942 | ||
852 | /* just declare this in any driver that really need it */ | ||
853 | extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode); | ||
854 | |||
855 | int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode) | ||
856 | { | ||
857 | return -ENOSYS; | ||
858 | } | ||
859 | EXPORT_SYMBOL (net2280_set_fifo_mode); | ||
860 | |||
861 | |||
862 | /* The gadget structure is stored inside the hcd structure and will be | 943 | /* The gadget structure is stored inside the hcd structure and will be |
863 | * released along with it. */ | 944 | * released along with it. */ |
864 | static void | 945 | static void |
865 | dummy_gadget_release (struct device *dev) | 946 | dummy_gadget_release (struct device *dev) |
866 | { | 947 | { |
867 | struct dummy *dum = gadget_dev_to_dummy (dev); | 948 | return; |
949 | } | ||
950 | |||
951 | static void init_dummy_udc_hw(struct dummy *dum) | ||
952 | { | ||
953 | int i; | ||
954 | |||
955 | INIT_LIST_HEAD(&dum->gadget.ep_list); | ||
956 | for (i = 0; i < DUMMY_ENDPOINTS; i++) { | ||
957 | struct dummy_ep *ep = &dum->ep[i]; | ||
958 | |||
959 | if (!ep_name[i]) | ||
960 | break; | ||
961 | ep->ep.name = ep_name[i]; | ||
962 | ep->ep.ops = &dummy_ep_ops; | ||
963 | list_add_tail(&ep->ep.ep_list, &dum->gadget.ep_list); | ||
964 | ep->halted = ep->wedged = ep->already_seen = | ||
965 | ep->setup_stage = 0; | ||
966 | ep->ep.maxpacket = ~0; | ||
967 | ep->last_io = jiffies; | ||
968 | ep->gadget = &dum->gadget; | ||
969 | ep->desc = NULL; | ||
970 | INIT_LIST_HEAD(&ep->queue); | ||
971 | } | ||
972 | |||
973 | dum->gadget.ep0 = &dum->ep[0].ep; | ||
974 | list_del_init(&dum->ep[0].ep.ep_list); | ||
975 | INIT_LIST_HEAD(&dum->fifo_req.queue); | ||
868 | 976 | ||
869 | usb_put_hcd (dummy_to_hcd (dum)); | 977 | #ifdef CONFIG_USB_OTG |
978 | dum->gadget.is_otg = 1; | ||
979 | #endif | ||
870 | } | 980 | } |
871 | 981 | ||
872 | static int dummy_udc_probe (struct platform_device *pdev) | 982 | static int dummy_udc_probe (struct platform_device *pdev) |
873 | { | 983 | { |
874 | struct dummy *dum = the_controller; | 984 | struct dummy *dum = &the_controller; |
875 | int rc; | 985 | int rc; |
876 | 986 | ||
877 | usb_get_hcd(dummy_to_hcd(dum)); | ||
878 | |||
879 | dum->gadget.name = gadget_name; | 987 | dum->gadget.name = gadget_name; |
880 | dum->gadget.ops = &dummy_ops; | 988 | dum->gadget.ops = &dummy_ops; |
881 | dum->gadget.is_dualspeed = 1; | 989 | dum->gadget.is_dualspeed = 1; |
882 | 990 | ||
883 | /* maybe claim OTG support, though we won't complete HNP */ | ||
884 | dum->gadget.is_otg = (dummy_to_hcd(dum)->self.otg_port != 0); | ||
885 | |||
886 | dev_set_name(&dum->gadget.dev, "gadget"); | 991 | dev_set_name(&dum->gadget.dev, "gadget"); |
887 | dum->gadget.dev.parent = &pdev->dev; | 992 | dum->gadget.dev.parent = &pdev->dev; |
888 | dum->gadget.dev.release = dummy_gadget_release; | 993 | dum->gadget.dev.release = dummy_gadget_release; |
@@ -892,11 +997,22 @@ static int dummy_udc_probe (struct platform_device *pdev) | |||
892 | return rc; | 997 | return rc; |
893 | } | 998 | } |
894 | 999 | ||
1000 | init_dummy_udc_hw(dum); | ||
1001 | |||
1002 | rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget); | ||
1003 | if (rc < 0) | ||
1004 | goto err_udc; | ||
1005 | |||
895 | rc = device_create_file (&dum->gadget.dev, &dev_attr_function); | 1006 | rc = device_create_file (&dum->gadget.dev, &dev_attr_function); |
896 | if (rc < 0) | 1007 | if (rc < 0) |
897 | device_unregister (&dum->gadget.dev); | 1008 | goto err_dev; |
898 | else | 1009 | platform_set_drvdata(pdev, dum); |
899 | platform_set_drvdata(pdev, dum); | 1010 | return rc; |
1011 | |||
1012 | err_dev: | ||
1013 | usb_del_gadget_udc(&dum->gadget); | ||
1014 | err_udc: | ||
1015 | device_unregister(&dum->gadget.dev); | ||
900 | return rc; | 1016 | return rc; |
901 | } | 1017 | } |
902 | 1018 | ||
@@ -904,37 +1020,41 @@ static int dummy_udc_remove (struct platform_device *pdev) | |||
904 | { | 1020 | { |
905 | struct dummy *dum = platform_get_drvdata (pdev); | 1021 | struct dummy *dum = platform_get_drvdata (pdev); |
906 | 1022 | ||
1023 | usb_del_gadget_udc(&dum->gadget); | ||
907 | platform_set_drvdata (pdev, NULL); | 1024 | platform_set_drvdata (pdev, NULL); |
908 | device_remove_file (&dum->gadget.dev, &dev_attr_function); | 1025 | device_remove_file (&dum->gadget.dev, &dev_attr_function); |
909 | device_unregister (&dum->gadget.dev); | 1026 | device_unregister (&dum->gadget.dev); |
910 | return 0; | 1027 | return 0; |
911 | } | 1028 | } |
912 | 1029 | ||
913 | static int dummy_udc_suspend (struct platform_device *pdev, pm_message_t state) | 1030 | static void dummy_udc_pm(struct dummy *dum, struct dummy_hcd *dum_hcd, |
1031 | int suspend) | ||
914 | { | 1032 | { |
915 | struct dummy *dum = platform_get_drvdata(pdev); | 1033 | spin_lock_irq(&dum->lock); |
1034 | dum->udc_suspended = suspend; | ||
1035 | set_link_state(dum_hcd); | ||
1036 | spin_unlock_irq(&dum->lock); | ||
1037 | } | ||
916 | 1038 | ||
917 | dev_dbg (&pdev->dev, "%s\n", __func__); | 1039 | static int dummy_udc_suspend(struct platform_device *pdev, pm_message_t state) |
918 | spin_lock_irq (&dum->lock); | 1040 | { |
919 | dum->udc_suspended = 1; | 1041 | struct dummy *dum = platform_get_drvdata(pdev); |
920 | set_link_state (dum); | 1042 | struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(&dum->gadget); |
921 | spin_unlock_irq (&dum->lock); | ||
922 | 1043 | ||
923 | usb_hcd_poll_rh_status (dummy_to_hcd (dum)); | 1044 | dev_dbg(&pdev->dev, "%s\n", __func__); |
1045 | dummy_udc_pm(dum, dum_hcd, 1); | ||
1046 | usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd)); | ||
924 | return 0; | 1047 | return 0; |
925 | } | 1048 | } |
926 | 1049 | ||
927 | static int dummy_udc_resume (struct platform_device *pdev) | 1050 | static int dummy_udc_resume(struct platform_device *pdev) |
928 | { | 1051 | { |
929 | struct dummy *dum = platform_get_drvdata(pdev); | 1052 | struct dummy *dum = platform_get_drvdata(pdev); |
1053 | struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(&dum->gadget); | ||
930 | 1054 | ||
931 | dev_dbg (&pdev->dev, "%s\n", __func__); | 1055 | dev_dbg(&pdev->dev, "%s\n", __func__); |
932 | spin_lock_irq (&dum->lock); | 1056 | dummy_udc_pm(dum, dum_hcd, 0); |
933 | dum->udc_suspended = 0; | 1057 | usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd)); |
934 | set_link_state (dum); | ||
935 | spin_unlock_irq (&dum->lock); | ||
936 | |||
937 | usb_hcd_poll_rh_status (dummy_to_hcd (dum)); | ||
938 | return 0; | 1058 | return 0; |
939 | } | 1059 | } |
940 | 1060 | ||
@@ -968,7 +1088,7 @@ static int dummy_urb_enqueue ( | |||
968 | struct urb *urb, | 1088 | struct urb *urb, |
969 | gfp_t mem_flags | 1089 | gfp_t mem_flags |
970 | ) { | 1090 | ) { |
971 | struct dummy *dum; | 1091 | struct dummy_hcd *dum_hcd; |
972 | struct urbp *urbp; | 1092 | struct urbp *urbp; |
973 | unsigned long flags; | 1093 | unsigned long flags; |
974 | int rc; | 1094 | int rc; |
@@ -981,51 +1101,51 @@ static int dummy_urb_enqueue ( | |||
981 | return -ENOMEM; | 1101 | return -ENOMEM; |
982 | urbp->urb = urb; | 1102 | urbp->urb = urb; |
983 | 1103 | ||
984 | dum = hcd_to_dummy (hcd); | 1104 | dum_hcd = hcd_to_dummy_hcd(hcd); |
985 | spin_lock_irqsave (&dum->lock, flags); | 1105 | spin_lock_irqsave(&dum_hcd->dum->lock, flags); |
986 | rc = usb_hcd_link_urb_to_ep(hcd, urb); | 1106 | rc = usb_hcd_link_urb_to_ep(hcd, urb); |
987 | if (rc) { | 1107 | if (rc) { |
988 | kfree(urbp); | 1108 | kfree(urbp); |
989 | goto done; | 1109 | goto done; |
990 | } | 1110 | } |
991 | 1111 | ||
992 | if (!dum->udev) { | 1112 | if (!dum_hcd->udev) { |
993 | dum->udev = urb->dev; | 1113 | dum_hcd->udev = urb->dev; |
994 | usb_get_dev (dum->udev); | 1114 | usb_get_dev(dum_hcd->udev); |
995 | } else if (unlikely (dum->udev != urb->dev)) | 1115 | } else if (unlikely(dum_hcd->udev != urb->dev)) |
996 | dev_err (dummy_dev(dum), "usb_device address has changed!\n"); | 1116 | dev_err(dummy_dev(dum_hcd), "usb_device address has changed!\n"); |
997 | 1117 | ||
998 | list_add_tail (&urbp->urbp_list, &dum->urbp_list); | 1118 | list_add_tail(&urbp->urbp_list, &dum_hcd->urbp_list); |
999 | urb->hcpriv = urbp; | 1119 | urb->hcpriv = urbp; |
1000 | if (usb_pipetype (urb->pipe) == PIPE_CONTROL) | 1120 | if (usb_pipetype (urb->pipe) == PIPE_CONTROL) |
1001 | urb->error_count = 1; /* mark as a new urb */ | 1121 | urb->error_count = 1; /* mark as a new urb */ |
1002 | 1122 | ||
1003 | /* kick the scheduler, it'll do the rest */ | 1123 | /* kick the scheduler, it'll do the rest */ |
1004 | if (!timer_pending (&dum->timer)) | 1124 | if (!timer_pending(&dum_hcd->timer)) |
1005 | mod_timer (&dum->timer, jiffies + 1); | 1125 | mod_timer(&dum_hcd->timer, jiffies + 1); |
1006 | 1126 | ||
1007 | done: | 1127 | done: |
1008 | spin_unlock_irqrestore(&dum->lock, flags); | 1128 | spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); |
1009 | return rc; | 1129 | return rc; |
1010 | } | 1130 | } |
1011 | 1131 | ||
1012 | static int dummy_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | 1132 | static int dummy_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) |
1013 | { | 1133 | { |
1014 | struct dummy *dum; | 1134 | struct dummy_hcd *dum_hcd; |
1015 | unsigned long flags; | 1135 | unsigned long flags; |
1016 | int rc; | 1136 | int rc; |
1017 | 1137 | ||
1018 | /* giveback happens automatically in timer callback, | 1138 | /* giveback happens automatically in timer callback, |
1019 | * so make sure the callback happens */ | 1139 | * so make sure the callback happens */ |
1020 | dum = hcd_to_dummy (hcd); | 1140 | dum_hcd = hcd_to_dummy_hcd(hcd); |
1021 | spin_lock_irqsave (&dum->lock, flags); | 1141 | spin_lock_irqsave(&dum_hcd->dum->lock, flags); |
1022 | 1142 | ||
1023 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); | 1143 | rc = usb_hcd_check_unlink_urb(hcd, urb, status); |
1024 | if (!rc && dum->rh_state != DUMMY_RH_RUNNING && | 1144 | if (!rc && dum_hcd->rh_state != DUMMY_RH_RUNNING && |
1025 | !list_empty(&dum->urbp_list)) | 1145 | !list_empty(&dum_hcd->urbp_list)) |
1026 | mod_timer (&dum->timer, jiffies); | 1146 | mod_timer(&dum_hcd->timer, jiffies); |
1027 | 1147 | ||
1028 | spin_unlock_irqrestore (&dum->lock, flags); | 1148 | spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); |
1029 | return rc; | 1149 | return rc; |
1030 | } | 1150 | } |
1031 | 1151 | ||
@@ -1162,10 +1282,25 @@ static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep) | |||
1162 | tmp *= 8 /* applies to entire frame */; | 1282 | tmp *= 8 /* applies to entire frame */; |
1163 | limit += limit * tmp; | 1283 | limit += limit * tmp; |
1164 | } | 1284 | } |
1285 | if (dum->gadget.speed == USB_SPEED_SUPER) { | ||
1286 | switch (ep->desc->bmAttributes & 0x03) { | ||
1287 | case USB_ENDPOINT_XFER_ISOC: | ||
1288 | /* Sec. 4.4.8.2 USB3.0 Spec */ | ||
1289 | limit = 3 * 16 * 1024 * 8; | ||
1290 | break; | ||
1291 | case USB_ENDPOINT_XFER_INT: | ||
1292 | /* Sec. 4.4.7.2 USB3.0 Spec */ | ||
1293 | limit = 3 * 1024 * 8; | ||
1294 | break; | ||
1295 | case USB_ENDPOINT_XFER_BULK: | ||
1296 | default: | ||
1297 | break; | ||
1298 | } | ||
1299 | } | ||
1165 | return limit; | 1300 | return limit; |
1166 | } | 1301 | } |
1167 | 1302 | ||
1168 | #define is_active(dum) ((dum->port_status & \ | 1303 | #define is_active(dum_hcd) ((dum_hcd->port_status & \ |
1169 | (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | \ | 1304 | (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE | \ |
1170 | USB_PORT_STAT_SUSPEND)) \ | 1305 | USB_PORT_STAT_SUSPEND)) \ |
1171 | == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE)) | 1306 | == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE)) |
@@ -1174,7 +1309,8 @@ static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address) | |||
1174 | { | 1309 | { |
1175 | int i; | 1310 | int i; |
1176 | 1311 | ||
1177 | if (!is_active (dum)) | 1312 | if (!is_active((dum->gadget.speed == USB_SPEED_SUPER ? |
1313 | dum->ss_hcd : dum->hs_hcd))) | ||
1178 | return NULL; | 1314 | return NULL; |
1179 | if ((address & ~USB_DIR_IN) == 0) | 1315 | if ((address & ~USB_DIR_IN) == 0) |
1180 | return &dum->ep [0]; | 1316 | return &dum->ep [0]; |
@@ -1211,11 +1347,12 @@ static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address) | |||
1211 | * 1 - if the request wasn't handles | 1347 | * 1 - if the request wasn't handles |
1212 | * error code on error | 1348 | * error code on error |
1213 | */ | 1349 | */ |
1214 | static int handle_control_request(struct dummy *dum, struct urb *urb, | 1350 | static int handle_control_request(struct dummy_hcd *dum_hcd, struct urb *urb, |
1215 | struct usb_ctrlrequest *setup, | 1351 | struct usb_ctrlrequest *setup, |
1216 | int *status) | 1352 | int *status) |
1217 | { | 1353 | { |
1218 | struct dummy_ep *ep2; | 1354 | struct dummy_ep *ep2; |
1355 | struct dummy *dum = dum_hcd->dum; | ||
1219 | int ret_val = 1; | 1356 | int ret_val = 1; |
1220 | unsigned w_index; | 1357 | unsigned w_index; |
1221 | unsigned w_value; | 1358 | unsigned w_value; |
@@ -1247,6 +1384,27 @@ static int handle_control_request(struct dummy *dum, struct urb *urb, | |||
1247 | case USB_DEVICE_A_ALT_HNP_SUPPORT: | 1384 | case USB_DEVICE_A_ALT_HNP_SUPPORT: |
1248 | dum->gadget.a_alt_hnp_support = 1; | 1385 | dum->gadget.a_alt_hnp_support = 1; |
1249 | break; | 1386 | break; |
1387 | case USB_DEVICE_U1_ENABLE: | ||
1388 | if (dummy_hcd_to_hcd(dum_hcd)->speed == | ||
1389 | HCD_USB3) | ||
1390 | w_value = USB_DEV_STAT_U1_ENABLED; | ||
1391 | else | ||
1392 | ret_val = -EOPNOTSUPP; | ||
1393 | break; | ||
1394 | case USB_DEVICE_U2_ENABLE: | ||
1395 | if (dummy_hcd_to_hcd(dum_hcd)->speed == | ||
1396 | HCD_USB3) | ||
1397 | w_value = USB_DEV_STAT_U2_ENABLED; | ||
1398 | else | ||
1399 | ret_val = -EOPNOTSUPP; | ||
1400 | break; | ||
1401 | case USB_DEVICE_LTM_ENABLE: | ||
1402 | if (dummy_hcd_to_hcd(dum_hcd)->speed == | ||
1403 | HCD_USB3) | ||
1404 | w_value = USB_DEV_STAT_LTM_ENABLED; | ||
1405 | else | ||
1406 | ret_val = -EOPNOTSUPP; | ||
1407 | break; | ||
1250 | default: | 1408 | default: |
1251 | ret_val = -EOPNOTSUPP; | 1409 | ret_val = -EOPNOTSUPP; |
1252 | } | 1410 | } |
@@ -1273,6 +1431,27 @@ static int handle_control_request(struct dummy *dum, struct urb *urb, | |||
1273 | case USB_DEVICE_REMOTE_WAKEUP: | 1431 | case USB_DEVICE_REMOTE_WAKEUP: |
1274 | w_value = USB_DEVICE_REMOTE_WAKEUP; | 1432 | w_value = USB_DEVICE_REMOTE_WAKEUP; |
1275 | break; | 1433 | break; |
1434 | case USB_DEVICE_U1_ENABLE: | ||
1435 | if (dummy_hcd_to_hcd(dum_hcd)->speed == | ||
1436 | HCD_USB3) | ||
1437 | w_value = USB_DEV_STAT_U1_ENABLED; | ||
1438 | else | ||
1439 | ret_val = -EOPNOTSUPP; | ||
1440 | break; | ||
1441 | case USB_DEVICE_U2_ENABLE: | ||
1442 | if (dummy_hcd_to_hcd(dum_hcd)->speed == | ||
1443 | HCD_USB3) | ||
1444 | w_value = USB_DEV_STAT_U2_ENABLED; | ||
1445 | else | ||
1446 | ret_val = -EOPNOTSUPP; | ||
1447 | break; | ||
1448 | case USB_DEVICE_LTM_ENABLE: | ||
1449 | if (dummy_hcd_to_hcd(dum_hcd)->speed == | ||
1450 | HCD_USB3) | ||
1451 | w_value = USB_DEV_STAT_LTM_ENABLED; | ||
1452 | else | ||
1453 | ret_val = -EOPNOTSUPP; | ||
1454 | break; | ||
1276 | default: | 1455 | default: |
1277 | ret_val = -EOPNOTSUPP; | 1456 | ret_val = -EOPNOTSUPP; |
1278 | break; | 1457 | break; |
@@ -1334,9 +1513,10 @@ static int handle_control_request(struct dummy *dum, struct urb *urb, | |||
1334 | /* drive both sides of the transfers; looks like irq handlers to | 1513 | /* drive both sides of the transfers; looks like irq handlers to |
1335 | * both drivers except the callbacks aren't in_irq(). | 1514 | * both drivers except the callbacks aren't in_irq(). |
1336 | */ | 1515 | */ |
1337 | static void dummy_timer (unsigned long _dum) | 1516 | static void dummy_timer(unsigned long _dum_hcd) |
1338 | { | 1517 | { |
1339 | struct dummy *dum = (struct dummy *) _dum; | 1518 | struct dummy_hcd *dum_hcd = (struct dummy_hcd *) _dum_hcd; |
1519 | struct dummy *dum = dum_hcd->dum; | ||
1340 | struct urbp *urbp, *tmp; | 1520 | struct urbp *urbp, *tmp; |
1341 | unsigned long flags; | 1521 | unsigned long flags; |
1342 | int limit, total; | 1522 | int limit, total; |
@@ -1353,8 +1533,12 @@ static void dummy_timer (unsigned long _dum) | |||
1353 | case USB_SPEED_HIGH: | 1533 | case USB_SPEED_HIGH: |
1354 | total = 512/*bytes*/ * 13/*packets*/ * 8/*uframes*/; | 1534 | total = 512/*bytes*/ * 13/*packets*/ * 8/*uframes*/; |
1355 | break; | 1535 | break; |
1536 | case USB_SPEED_SUPER: | ||
1537 | /* Bus speed is 500000 bytes/ms, so use a little less */ | ||
1538 | total = 490000; | ||
1539 | break; | ||
1356 | default: | 1540 | default: |
1357 | dev_err (dummy_dev(dum), "bogus device speed\n"); | 1541 | dev_err(dummy_dev(dum_hcd), "bogus device speed\n"); |
1358 | return; | 1542 | return; |
1359 | } | 1543 | } |
1360 | 1544 | ||
@@ -1363,8 +1547,8 @@ static void dummy_timer (unsigned long _dum) | |||
1363 | /* look at each urb queued by the host side driver */ | 1547 | /* look at each urb queued by the host side driver */ |
1364 | spin_lock_irqsave (&dum->lock, flags); | 1548 | spin_lock_irqsave (&dum->lock, flags); |
1365 | 1549 | ||
1366 | if (!dum->udev) { | 1550 | if (!dum_hcd->udev) { |
1367 | dev_err (dummy_dev(dum), | 1551 | dev_err(dummy_dev(dum_hcd), |
1368 | "timer fired with no URBs pending?\n"); | 1552 | "timer fired with no URBs pending?\n"); |
1369 | spin_unlock_irqrestore (&dum->lock, flags); | 1553 | spin_unlock_irqrestore (&dum->lock, flags); |
1370 | return; | 1554 | return; |
@@ -1377,7 +1561,7 @@ static void dummy_timer (unsigned long _dum) | |||
1377 | } | 1561 | } |
1378 | 1562 | ||
1379 | restart: | 1563 | restart: |
1380 | list_for_each_entry_safe (urbp, tmp, &dum->urbp_list, urbp_list) { | 1564 | list_for_each_entry_safe(urbp, tmp, &dum_hcd->urbp_list, urbp_list) { |
1381 | struct urb *urb; | 1565 | struct urb *urb; |
1382 | struct dummy_request *req; | 1566 | struct dummy_request *req; |
1383 | u8 address; | 1567 | u8 address; |
@@ -1388,7 +1572,7 @@ restart: | |||
1388 | urb = urbp->urb; | 1572 | urb = urbp->urb; |
1389 | if (urb->unlinked) | 1573 | if (urb->unlinked) |
1390 | goto return_urb; | 1574 | goto return_urb; |
1391 | else if (dum->rh_state != DUMMY_RH_RUNNING) | 1575 | else if (dum_hcd->rh_state != DUMMY_RH_RUNNING) |
1392 | continue; | 1576 | continue; |
1393 | type = usb_pipetype (urb->pipe); | 1577 | type = usb_pipetype (urb->pipe); |
1394 | 1578 | ||
@@ -1406,7 +1590,7 @@ restart: | |||
1406 | ep = find_endpoint(dum, address); | 1590 | ep = find_endpoint(dum, address); |
1407 | if (!ep) { | 1591 | if (!ep) { |
1408 | /* set_configuration() disagreement */ | 1592 | /* set_configuration() disagreement */ |
1409 | dev_dbg (dummy_dev(dum), | 1593 | dev_dbg(dummy_dev(dum_hcd), |
1410 | "no ep configured for urb %p\n", | 1594 | "no ep configured for urb %p\n", |
1411 | urb); | 1595 | urb); |
1412 | status = -EPROTO; | 1596 | status = -EPROTO; |
@@ -1422,7 +1606,7 @@ restart: | |||
1422 | } | 1606 | } |
1423 | if (ep->halted && !ep->setup_stage) { | 1607 | if (ep->halted && !ep->setup_stage) { |
1424 | /* NOTE: must not be iso! */ | 1608 | /* NOTE: must not be iso! */ |
1425 | dev_dbg (dummy_dev(dum), "ep %s halted, urb %p\n", | 1609 | dev_dbg(dummy_dev(dum_hcd), "ep %s halted, urb %p\n", |
1426 | ep->ep.name, urb); | 1610 | ep->ep.name, urb); |
1427 | status = -EPIPE; | 1611 | status = -EPIPE; |
1428 | goto return_urb; | 1612 | goto return_urb; |
@@ -1457,7 +1641,7 @@ restart: | |||
1457 | ep->setup_stage = 0; | 1641 | ep->setup_stage = 0; |
1458 | ep->halted = 0; | 1642 | ep->halted = 0; |
1459 | 1643 | ||
1460 | value = handle_control_request(dum, urb, &setup, | 1644 | value = handle_control_request(dum_hcd, urb, &setup, |
1461 | &status); | 1645 | &status); |
1462 | 1646 | ||
1463 | /* gadget driver handles all other requests. block | 1647 | /* gadget driver handles all other requests. block |
@@ -1527,20 +1711,20 @@ return_urb: | |||
1527 | if (ep) | 1711 | if (ep) |
1528 | ep->already_seen = ep->setup_stage = 0; | 1712 | ep->already_seen = ep->setup_stage = 0; |
1529 | 1713 | ||
1530 | usb_hcd_unlink_urb_from_ep(dummy_to_hcd(dum), urb); | 1714 | usb_hcd_unlink_urb_from_ep(dummy_hcd_to_hcd(dum_hcd), urb); |
1531 | spin_unlock (&dum->lock); | 1715 | spin_unlock (&dum->lock); |
1532 | usb_hcd_giveback_urb(dummy_to_hcd(dum), urb, status); | 1716 | usb_hcd_giveback_urb(dummy_hcd_to_hcd(dum_hcd), urb, status); |
1533 | spin_lock (&dum->lock); | 1717 | spin_lock (&dum->lock); |
1534 | 1718 | ||
1535 | goto restart; | 1719 | goto restart; |
1536 | } | 1720 | } |
1537 | 1721 | ||
1538 | if (list_empty (&dum->urbp_list)) { | 1722 | if (list_empty(&dum_hcd->urbp_list)) { |
1539 | usb_put_dev (dum->udev); | 1723 | usb_put_dev(dum_hcd->udev); |
1540 | dum->udev = NULL; | 1724 | dum_hcd->udev = NULL; |
1541 | } else if (dum->rh_state == DUMMY_RH_RUNNING) { | 1725 | } else if (dum_hcd->rh_state == DUMMY_RH_RUNNING) { |
1542 | /* want a 1 msec delay here */ | 1726 | /* want a 1 msec delay here */ |
1543 | mod_timer (&dum->timer, jiffies + msecs_to_jiffies(1)); | 1727 | mod_timer(&dum_hcd->timer, jiffies + msecs_to_jiffies(1)); |
1544 | } | 1728 | } |
1545 | 1729 | ||
1546 | spin_unlock_irqrestore (&dum->lock, flags); | 1730 | spin_unlock_irqrestore (&dum->lock, flags); |
@@ -1557,36 +1741,48 @@ return_urb: | |||
1557 | 1741 | ||
1558 | static int dummy_hub_status (struct usb_hcd *hcd, char *buf) | 1742 | static int dummy_hub_status (struct usb_hcd *hcd, char *buf) |
1559 | { | 1743 | { |
1560 | struct dummy *dum; | 1744 | struct dummy_hcd *dum_hcd; |
1561 | unsigned long flags; | 1745 | unsigned long flags; |
1562 | int retval = 0; | 1746 | int retval = 0; |
1563 | 1747 | ||
1564 | dum = hcd_to_dummy (hcd); | 1748 | dum_hcd = hcd_to_dummy_hcd(hcd); |
1565 | 1749 | ||
1566 | spin_lock_irqsave (&dum->lock, flags); | 1750 | spin_lock_irqsave(&dum_hcd->dum->lock, flags); |
1567 | if (!HCD_HW_ACCESSIBLE(hcd)) | 1751 | if (!HCD_HW_ACCESSIBLE(hcd)) |
1568 | goto done; | 1752 | goto done; |
1569 | 1753 | ||
1570 | if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) { | 1754 | if (dum_hcd->resuming && time_after_eq(jiffies, dum_hcd->re_timeout)) { |
1571 | dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); | 1755 | dum_hcd->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); |
1572 | dum->port_status &= ~USB_PORT_STAT_SUSPEND; | 1756 | dum_hcd->port_status &= ~USB_PORT_STAT_SUSPEND; |
1573 | set_link_state (dum); | 1757 | set_link_state(dum_hcd); |
1574 | } | 1758 | } |
1575 | 1759 | ||
1576 | if ((dum->port_status & PORT_C_MASK) != 0) { | 1760 | if ((dum_hcd->port_status & PORT_C_MASK) != 0) { |
1577 | *buf = (1 << 1); | 1761 | *buf = (1 << 1); |
1578 | dev_dbg (dummy_dev(dum), "port status 0x%08x has changes\n", | 1762 | dev_dbg(dummy_dev(dum_hcd), "port status 0x%08x has changes\n", |
1579 | dum->port_status); | 1763 | dum_hcd->port_status); |
1580 | retval = 1; | 1764 | retval = 1; |
1581 | if (dum->rh_state == DUMMY_RH_SUSPENDED) | 1765 | if (dum_hcd->rh_state == DUMMY_RH_SUSPENDED) |
1582 | usb_hcd_resume_root_hub (hcd); | 1766 | usb_hcd_resume_root_hub (hcd); |
1583 | } | 1767 | } |
1584 | done: | 1768 | done: |
1585 | spin_unlock_irqrestore (&dum->lock, flags); | 1769 | spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); |
1586 | return retval; | 1770 | return retval; |
1587 | } | 1771 | } |
1588 | 1772 | ||
1589 | static inline void | 1773 | static inline void |
1774 | ss_hub_descriptor(struct usb_hub_descriptor *desc) | ||
1775 | { | ||
1776 | memset(desc, 0, sizeof *desc); | ||
1777 | desc->bDescriptorType = 0x2a; | ||
1778 | desc->bDescLength = 12; | ||
1779 | desc->wHubCharacteristics = cpu_to_le16(0x0001); | ||
1780 | desc->bNbrPorts = 1; | ||
1781 | desc->u.ss.bHubHdrDecLat = 0x04; /* Worst case: 0.4 micro sec*/ | ||
1782 | desc->u.ss.DeviceRemovable = 0xffff; | ||
1783 | } | ||
1784 | |||
1785 | static inline void | ||
1590 | hub_descriptor (struct usb_hub_descriptor *desc) | 1786 | hub_descriptor (struct usb_hub_descriptor *desc) |
1591 | { | 1787 | { |
1592 | memset (desc, 0, sizeof *desc); | 1788 | memset (desc, 0, sizeof *desc); |
@@ -1606,39 +1802,64 @@ static int dummy_hub_control ( | |||
1606 | char *buf, | 1802 | char *buf, |
1607 | u16 wLength | 1803 | u16 wLength |
1608 | ) { | 1804 | ) { |
1609 | struct dummy *dum; | 1805 | struct dummy_hcd *dum_hcd; |
1610 | int retval = 0; | 1806 | int retval = 0; |
1611 | unsigned long flags; | 1807 | unsigned long flags; |
1612 | 1808 | ||
1613 | if (!HCD_HW_ACCESSIBLE(hcd)) | 1809 | if (!HCD_HW_ACCESSIBLE(hcd)) |
1614 | return -ETIMEDOUT; | 1810 | return -ETIMEDOUT; |
1615 | 1811 | ||
1616 | dum = hcd_to_dummy (hcd); | 1812 | dum_hcd = hcd_to_dummy_hcd(hcd); |
1617 | spin_lock_irqsave (&dum->lock, flags); | 1813 | |
1814 | spin_lock_irqsave(&dum_hcd->dum->lock, flags); | ||
1618 | switch (typeReq) { | 1815 | switch (typeReq) { |
1619 | case ClearHubFeature: | 1816 | case ClearHubFeature: |
1620 | break; | 1817 | break; |
1621 | case ClearPortFeature: | 1818 | case ClearPortFeature: |
1622 | switch (wValue) { | 1819 | switch (wValue) { |
1623 | case USB_PORT_FEAT_SUSPEND: | 1820 | case USB_PORT_FEAT_SUSPEND: |
1624 | if (dum->port_status & USB_PORT_STAT_SUSPEND) { | 1821 | if (hcd->speed == HCD_USB3) { |
1822 | dev_dbg(dummy_dev(dum_hcd), | ||
1823 | "USB_PORT_FEAT_SUSPEND req not " | ||
1824 | "supported for USB 3.0 roothub\n"); | ||
1825 | goto error; | ||
1826 | } | ||
1827 | if (dum_hcd->port_status & USB_PORT_STAT_SUSPEND) { | ||
1625 | /* 20msec resume signaling */ | 1828 | /* 20msec resume signaling */ |
1626 | dum->resuming = 1; | 1829 | dum_hcd->resuming = 1; |
1627 | dum->re_timeout = jiffies + | 1830 | dum_hcd->re_timeout = jiffies + |
1628 | msecs_to_jiffies(20); | 1831 | msecs_to_jiffies(20); |
1629 | } | 1832 | } |
1630 | break; | 1833 | break; |
1631 | case USB_PORT_FEAT_POWER: | 1834 | case USB_PORT_FEAT_POWER: |
1632 | if (dum->port_status & USB_PORT_STAT_POWER) | 1835 | if (hcd->speed == HCD_USB3) { |
1633 | dev_dbg (dummy_dev(dum), "power-off\n"); | 1836 | if (dum_hcd->port_status & USB_PORT_STAT_POWER) |
1837 | dev_dbg(dummy_dev(dum_hcd), | ||
1838 | "power-off\n"); | ||
1839 | } else | ||
1840 | if (dum_hcd->port_status & | ||
1841 | USB_SS_PORT_STAT_POWER) | ||
1842 | dev_dbg(dummy_dev(dum_hcd), | ||
1843 | "power-off\n"); | ||
1634 | /* FALLS THROUGH */ | 1844 | /* FALLS THROUGH */ |
1635 | default: | 1845 | default: |
1636 | dum->port_status &= ~(1 << wValue); | 1846 | dum_hcd->port_status &= ~(1 << wValue); |
1637 | set_link_state (dum); | 1847 | set_link_state(dum_hcd); |
1638 | } | 1848 | } |
1639 | break; | 1849 | break; |
1640 | case GetHubDescriptor: | 1850 | case GetHubDescriptor: |
1641 | hub_descriptor ((struct usb_hub_descriptor *) buf); | 1851 | if (hcd->speed == HCD_USB3 && |
1852 | (wLength < USB_DT_SS_HUB_SIZE || | ||
1853 | wValue != (USB_DT_SS_HUB << 8))) { | ||
1854 | dev_dbg(dummy_dev(dum_hcd), | ||
1855 | "Wrong hub descriptor type for " | ||
1856 | "USB 3.0 roothub.\n"); | ||
1857 | goto error; | ||
1858 | } | ||
1859 | if (hcd->speed == HCD_USB3) | ||
1860 | ss_hub_descriptor((struct usb_hub_descriptor *) buf); | ||
1861 | else | ||
1862 | hub_descriptor((struct usb_hub_descriptor *) buf); | ||
1642 | break; | 1863 | break; |
1643 | case GetHubStatus: | 1864 | case GetHubStatus: |
1644 | *(__le32 *) buf = cpu_to_le32 (0); | 1865 | *(__le32 *) buf = cpu_to_le32 (0); |
@@ -1650,127 +1871,210 @@ static int dummy_hub_control ( | |||
1650 | /* whoever resets or resumes must GetPortStatus to | 1871 | /* whoever resets or resumes must GetPortStatus to |
1651 | * complete it!! | 1872 | * complete it!! |
1652 | */ | 1873 | */ |
1653 | if (dum->resuming && | 1874 | if (dum_hcd->resuming && |
1654 | time_after_eq (jiffies, dum->re_timeout)) { | 1875 | time_after_eq(jiffies, dum_hcd->re_timeout)) { |
1655 | dum->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); | 1876 | dum_hcd->port_status |= (USB_PORT_STAT_C_SUSPEND << 16); |
1656 | dum->port_status &= ~USB_PORT_STAT_SUSPEND; | 1877 | dum_hcd->port_status &= ~USB_PORT_STAT_SUSPEND; |
1657 | } | 1878 | } |
1658 | if ((dum->port_status & USB_PORT_STAT_RESET) != 0 && | 1879 | if ((dum_hcd->port_status & USB_PORT_STAT_RESET) != 0 && |
1659 | time_after_eq (jiffies, dum->re_timeout)) { | 1880 | time_after_eq(jiffies, dum_hcd->re_timeout)) { |
1660 | dum->port_status |= (USB_PORT_STAT_C_RESET << 16); | 1881 | dum_hcd->port_status |= (USB_PORT_STAT_C_RESET << 16); |
1661 | dum->port_status &= ~USB_PORT_STAT_RESET; | 1882 | dum_hcd->port_status &= ~USB_PORT_STAT_RESET; |
1662 | if (dum->pullup) { | 1883 | if (dum_hcd->dum->pullup) { |
1663 | dum->port_status |= USB_PORT_STAT_ENABLE; | 1884 | dum_hcd->port_status |= USB_PORT_STAT_ENABLE; |
1664 | /* give it the best speed we agree on */ | 1885 | |
1665 | dum->gadget.speed = dum->driver->speed; | 1886 | if (hcd->speed < HCD_USB3) { |
1666 | dum->gadget.ep0->maxpacket = 64; | 1887 | switch (dum_hcd->dum->gadget.speed) { |
1667 | switch (dum->gadget.speed) { | 1888 | case USB_SPEED_HIGH: |
1668 | case USB_SPEED_HIGH: | 1889 | dum_hcd->port_status |= |
1669 | dum->port_status |= | 1890 | USB_PORT_STAT_HIGH_SPEED; |
1670 | USB_PORT_STAT_HIGH_SPEED; | 1891 | break; |
1671 | break; | 1892 | case USB_SPEED_LOW: |
1672 | case USB_SPEED_LOW: | 1893 | dum_hcd->dum->gadget.ep0-> |
1673 | dum->gadget.ep0->maxpacket = 8; | 1894 | maxpacket = 8; |
1674 | dum->port_status |= | 1895 | dum_hcd->port_status |= |
1675 | USB_PORT_STAT_LOW_SPEED; | 1896 | USB_PORT_STAT_LOW_SPEED; |
1676 | break; | 1897 | break; |
1677 | default: | 1898 | default: |
1678 | dum->gadget.speed = USB_SPEED_FULL; | 1899 | dum_hcd->dum->gadget.speed = |
1679 | break; | 1900 | USB_SPEED_FULL; |
1901 | break; | ||
1902 | } | ||
1680 | } | 1903 | } |
1681 | } | 1904 | } |
1682 | } | 1905 | } |
1683 | set_link_state (dum); | 1906 | set_link_state(dum_hcd); |
1684 | ((__le16 *) buf)[0] = cpu_to_le16 (dum->port_status); | 1907 | ((__le16 *) buf)[0] = cpu_to_le16 (dum_hcd->port_status); |
1685 | ((__le16 *) buf)[1] = cpu_to_le16 (dum->port_status >> 16); | 1908 | ((__le16 *) buf)[1] = cpu_to_le16 (dum_hcd->port_status >> 16); |
1686 | break; | 1909 | break; |
1687 | case SetHubFeature: | 1910 | case SetHubFeature: |
1688 | retval = -EPIPE; | 1911 | retval = -EPIPE; |
1689 | break; | 1912 | break; |
1690 | case SetPortFeature: | 1913 | case SetPortFeature: |
1691 | switch (wValue) { | 1914 | switch (wValue) { |
1915 | case USB_PORT_FEAT_LINK_STATE: | ||
1916 | if (hcd->speed != HCD_USB3) { | ||
1917 | dev_dbg(dummy_dev(dum_hcd), | ||
1918 | "USB_PORT_FEAT_LINK_STATE req not " | ||
1919 | "supported for USB 2.0 roothub\n"); | ||
1920 | goto error; | ||
1921 | } | ||
1922 | /* | ||
1923 | * Since this is dummy we don't have an actual link so | ||
1924 | * there is nothing to do for the SET_LINK_STATE cmd | ||
1925 | */ | ||
1926 | break; | ||
1927 | case USB_PORT_FEAT_U1_TIMEOUT: | ||
1928 | case USB_PORT_FEAT_U2_TIMEOUT: | ||
1929 | /* TODO: add suspend/resume support! */ | ||
1930 | if (hcd->speed != HCD_USB3) { | ||
1931 | dev_dbg(dummy_dev(dum_hcd), | ||
1932 | "USB_PORT_FEAT_U1/2_TIMEOUT req not " | ||
1933 | "supported for USB 2.0 roothub\n"); | ||
1934 | goto error; | ||
1935 | } | ||
1936 | break; | ||
1692 | case USB_PORT_FEAT_SUSPEND: | 1937 | case USB_PORT_FEAT_SUSPEND: |
1693 | if (dum->active) { | 1938 | /* Applicable only for USB2.0 hub */ |
1694 | dum->port_status |= USB_PORT_STAT_SUSPEND; | 1939 | if (hcd->speed == HCD_USB3) { |
1940 | dev_dbg(dummy_dev(dum_hcd), | ||
1941 | "USB_PORT_FEAT_SUSPEND req not " | ||
1942 | "supported for USB 3.0 roothub\n"); | ||
1943 | goto error; | ||
1944 | } | ||
1945 | if (dum_hcd->active) { | ||
1946 | dum_hcd->port_status |= USB_PORT_STAT_SUSPEND; | ||
1695 | 1947 | ||
1696 | /* HNP would happen here; for now we | 1948 | /* HNP would happen here; for now we |
1697 | * assume b_bus_req is always true. | 1949 | * assume b_bus_req is always true. |
1698 | */ | 1950 | */ |
1699 | set_link_state (dum); | 1951 | set_link_state(dum_hcd); |
1700 | if (((1 << USB_DEVICE_B_HNP_ENABLE) | 1952 | if (((1 << USB_DEVICE_B_HNP_ENABLE) |
1701 | & dum->devstatus) != 0) | 1953 | & dum_hcd->dum->devstatus) != 0) |
1702 | dev_dbg (dummy_dev(dum), | 1954 | dev_dbg(dummy_dev(dum_hcd), |
1703 | "no HNP yet!\n"); | 1955 | "no HNP yet!\n"); |
1704 | } | 1956 | } |
1705 | break; | 1957 | break; |
1706 | case USB_PORT_FEAT_POWER: | 1958 | case USB_PORT_FEAT_POWER: |
1707 | dum->port_status |= USB_PORT_STAT_POWER; | 1959 | if (hcd->speed == HCD_USB3) |
1708 | set_link_state (dum); | 1960 | dum_hcd->port_status |= USB_SS_PORT_STAT_POWER; |
1961 | else | ||
1962 | dum_hcd->port_status |= USB_PORT_STAT_POWER; | ||
1963 | set_link_state(dum_hcd); | ||
1709 | break; | 1964 | break; |
1965 | case USB_PORT_FEAT_BH_PORT_RESET: | ||
1966 | /* Applicable only for USB3.0 hub */ | ||
1967 | if (hcd->speed != HCD_USB3) { | ||
1968 | dev_dbg(dummy_dev(dum_hcd), | ||
1969 | "USB_PORT_FEAT_BH_PORT_RESET req not " | ||
1970 | "supported for USB 2.0 roothub\n"); | ||
1971 | goto error; | ||
1972 | } | ||
1973 | /* FALLS THROUGH */ | ||
1710 | case USB_PORT_FEAT_RESET: | 1974 | case USB_PORT_FEAT_RESET: |
1711 | /* if it's already enabled, disable */ | 1975 | /* if it's already enabled, disable */ |
1712 | dum->port_status &= ~(USB_PORT_STAT_ENABLE | 1976 | if (hcd->speed == HCD_USB3) { |
1977 | dum_hcd->port_status = 0; | ||
1978 | dum_hcd->port_status = | ||
1979 | (USB_SS_PORT_STAT_POWER | | ||
1980 | USB_PORT_STAT_CONNECTION | | ||
1981 | USB_PORT_STAT_RESET); | ||
1982 | } else | ||
1983 | dum_hcd->port_status &= ~(USB_PORT_STAT_ENABLE | ||
1713 | | USB_PORT_STAT_LOW_SPEED | 1984 | | USB_PORT_STAT_LOW_SPEED |
1714 | | USB_PORT_STAT_HIGH_SPEED); | 1985 | | USB_PORT_STAT_HIGH_SPEED); |
1715 | dum->devstatus = 0; | 1986 | /* |
1716 | /* 50msec reset signaling */ | 1987 | * We want to reset device status. All but the |
1717 | dum->re_timeout = jiffies + msecs_to_jiffies(50); | 1988 | * Self powered feature |
1989 | */ | ||
1990 | dum_hcd->dum->devstatus &= | ||
1991 | (1 << USB_DEVICE_SELF_POWERED); | ||
1992 | /* | ||
1993 | * FIXME USB3.0: what is the correct reset signaling | ||
1994 | * interval? Is it still 50msec as for HS? | ||
1995 | */ | ||
1996 | dum_hcd->re_timeout = jiffies + msecs_to_jiffies(50); | ||
1718 | /* FALLS THROUGH */ | 1997 | /* FALLS THROUGH */ |
1719 | default: | 1998 | default: |
1720 | if ((dum->port_status & USB_PORT_STAT_POWER) != 0) { | 1999 | if (hcd->speed == HCD_USB3) { |
1721 | dum->port_status |= (1 << wValue); | 2000 | if ((dum_hcd->port_status & |
1722 | set_link_state (dum); | 2001 | USB_SS_PORT_STAT_POWER) != 0) { |
1723 | } | 2002 | dum_hcd->port_status |= (1 << wValue); |
2003 | set_link_state(dum_hcd); | ||
2004 | } | ||
2005 | } else | ||
2006 | if ((dum_hcd->port_status & | ||
2007 | USB_PORT_STAT_POWER) != 0) { | ||
2008 | dum_hcd->port_status |= (1 << wValue); | ||
2009 | set_link_state(dum_hcd); | ||
2010 | } | ||
2011 | } | ||
2012 | break; | ||
2013 | case GetPortErrorCount: | ||
2014 | if (hcd->speed != HCD_USB3) { | ||
2015 | dev_dbg(dummy_dev(dum_hcd), | ||
2016 | "GetPortErrorCount req not " | ||
2017 | "supported for USB 2.0 roothub\n"); | ||
2018 | goto error; | ||
2019 | } | ||
2020 | /* We'll always return 0 since this is a dummy hub */ | ||
2021 | *(__le32 *) buf = cpu_to_le32(0); | ||
2022 | break; | ||
2023 | case SetHubDepth: | ||
2024 | if (hcd->speed != HCD_USB3) { | ||
2025 | dev_dbg(dummy_dev(dum_hcd), | ||
2026 | "SetHubDepth req not supported for " | ||
2027 | "USB 2.0 roothub\n"); | ||
2028 | goto error; | ||
1724 | } | 2029 | } |
1725 | break; | 2030 | break; |
1726 | |||
1727 | default: | 2031 | default: |
1728 | dev_dbg (dummy_dev(dum), | 2032 | dev_dbg(dummy_dev(dum_hcd), |
1729 | "hub control req%04x v%04x i%04x l%d\n", | 2033 | "hub control req%04x v%04x i%04x l%d\n", |
1730 | typeReq, wValue, wIndex, wLength); | 2034 | typeReq, wValue, wIndex, wLength); |
1731 | 2035 | error: | |
1732 | /* "protocol stall" on error */ | 2036 | /* "protocol stall" on error */ |
1733 | retval = -EPIPE; | 2037 | retval = -EPIPE; |
1734 | } | 2038 | } |
1735 | spin_unlock_irqrestore (&dum->lock, flags); | 2039 | spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); |
1736 | 2040 | ||
1737 | if ((dum->port_status & PORT_C_MASK) != 0) | 2041 | if ((dum_hcd->port_status & PORT_C_MASK) != 0) |
1738 | usb_hcd_poll_rh_status (hcd); | 2042 | usb_hcd_poll_rh_status (hcd); |
1739 | return retval; | 2043 | return retval; |
1740 | } | 2044 | } |
1741 | 2045 | ||
1742 | static int dummy_bus_suspend (struct usb_hcd *hcd) | 2046 | static int dummy_bus_suspend (struct usb_hcd *hcd) |
1743 | { | 2047 | { |
1744 | struct dummy *dum = hcd_to_dummy (hcd); | 2048 | struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd); |
1745 | 2049 | ||
1746 | dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); | 2050 | dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); |
1747 | 2051 | ||
1748 | spin_lock_irq (&dum->lock); | 2052 | spin_lock_irq(&dum_hcd->dum->lock); |
1749 | dum->rh_state = DUMMY_RH_SUSPENDED; | 2053 | dum_hcd->rh_state = DUMMY_RH_SUSPENDED; |
1750 | set_link_state (dum); | 2054 | set_link_state(dum_hcd); |
1751 | hcd->state = HC_STATE_SUSPENDED; | 2055 | hcd->state = HC_STATE_SUSPENDED; |
1752 | spin_unlock_irq (&dum->lock); | 2056 | spin_unlock_irq(&dum_hcd->dum->lock); |
1753 | return 0; | 2057 | return 0; |
1754 | } | 2058 | } |
1755 | 2059 | ||
1756 | static int dummy_bus_resume (struct usb_hcd *hcd) | 2060 | static int dummy_bus_resume (struct usb_hcd *hcd) |
1757 | { | 2061 | { |
1758 | struct dummy *dum = hcd_to_dummy (hcd); | 2062 | struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd); |
1759 | int rc = 0; | 2063 | int rc = 0; |
1760 | 2064 | ||
1761 | dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); | 2065 | dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); |
1762 | 2066 | ||
1763 | spin_lock_irq (&dum->lock); | 2067 | spin_lock_irq(&dum_hcd->dum->lock); |
1764 | if (!HCD_HW_ACCESSIBLE(hcd)) { | 2068 | if (!HCD_HW_ACCESSIBLE(hcd)) { |
1765 | rc = -ESHUTDOWN; | 2069 | rc = -ESHUTDOWN; |
1766 | } else { | 2070 | } else { |
1767 | dum->rh_state = DUMMY_RH_RUNNING; | 2071 | dum_hcd->rh_state = DUMMY_RH_RUNNING; |
1768 | set_link_state (dum); | 2072 | set_link_state(dum_hcd); |
1769 | if (!list_empty(&dum->urbp_list)) | 2073 | if (!list_empty(&dum_hcd->urbp_list)) |
1770 | mod_timer (&dum->timer, jiffies); | 2074 | mod_timer(&dum_hcd->timer, jiffies); |
1771 | hcd->state = HC_STATE_RUNNING; | 2075 | hcd->state = HC_STATE_RUNNING; |
1772 | } | 2076 | } |
1773 | spin_unlock_irq (&dum->lock); | 2077 | spin_unlock_irq(&dum_hcd->dum->lock); |
1774 | return rc; | 2078 | return rc; |
1775 | } | 2079 | } |
1776 | 2080 | ||
@@ -1786,18 +2090,37 @@ show_urb (char *buf, size_t size, struct urb *urb) | |||
1786 | urb, | 2090 | urb, |
1787 | ({ char *s; | 2091 | ({ char *s; |
1788 | switch (urb->dev->speed) { | 2092 | switch (urb->dev->speed) { |
1789 | case USB_SPEED_LOW: s = "ls"; break; | 2093 | case USB_SPEED_LOW: |
1790 | case USB_SPEED_FULL: s = "fs"; break; | 2094 | s = "ls"; |
1791 | case USB_SPEED_HIGH: s = "hs"; break; | 2095 | break; |
1792 | default: s = "?"; break; | 2096 | case USB_SPEED_FULL: |
2097 | s = "fs"; | ||
2098 | break; | ||
2099 | case USB_SPEED_HIGH: | ||
2100 | s = "hs"; | ||
2101 | break; | ||
2102 | case USB_SPEED_SUPER: | ||
2103 | s = "ss"; | ||
2104 | break; | ||
2105 | default: | ||
2106 | s = "?"; | ||
2107 | break; | ||
1793 | }; s; }), | 2108 | }; s; }), |
1794 | ep, ep ? (usb_pipein (urb->pipe) ? "in" : "out") : "", | 2109 | ep, ep ? (usb_pipein (urb->pipe) ? "in" : "out") : "", |
1795 | ({ char *s; \ | 2110 | ({ char *s; \ |
1796 | switch (usb_pipetype (urb->pipe)) { \ | 2111 | switch (usb_pipetype (urb->pipe)) { \ |
1797 | case PIPE_CONTROL: s = ""; break; \ | 2112 | case PIPE_CONTROL: \ |
1798 | case PIPE_BULK: s = "-bulk"; break; \ | 2113 | s = ""; \ |
1799 | case PIPE_INTERRUPT: s = "-int"; break; \ | 2114 | break; \ |
1800 | default: s = "-iso"; break; \ | 2115 | case PIPE_BULK: \ |
2116 | s = "-bulk"; \ | ||
2117 | break; \ | ||
2118 | case PIPE_INTERRUPT: \ | ||
2119 | s = "-int"; \ | ||
2120 | break; \ | ||
2121 | default: \ | ||
2122 | s = "-iso"; \ | ||
2123 | break; \ | ||
1801 | }; s;}), | 2124 | }; s;}), |
1802 | urb->actual_length, urb->transfer_buffer_length); | 2125 | urb->actual_length, urb->transfer_buffer_length); |
1803 | } | 2126 | } |
@@ -1806,43 +2129,63 @@ static ssize_t | |||
1806 | show_urbs (struct device *dev, struct device_attribute *attr, char *buf) | 2129 | show_urbs (struct device *dev, struct device_attribute *attr, char *buf) |
1807 | { | 2130 | { |
1808 | struct usb_hcd *hcd = dev_get_drvdata (dev); | 2131 | struct usb_hcd *hcd = dev_get_drvdata (dev); |
1809 | struct dummy *dum = hcd_to_dummy (hcd); | 2132 | struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd); |
1810 | struct urbp *urbp; | 2133 | struct urbp *urbp; |
1811 | size_t size = 0; | 2134 | size_t size = 0; |
1812 | unsigned long flags; | 2135 | unsigned long flags; |
1813 | 2136 | ||
1814 | spin_lock_irqsave (&dum->lock, flags); | 2137 | spin_lock_irqsave(&dum_hcd->dum->lock, flags); |
1815 | list_for_each_entry (urbp, &dum->urbp_list, urbp_list) { | 2138 | list_for_each_entry(urbp, &dum_hcd->urbp_list, urbp_list) { |
1816 | size_t temp; | 2139 | size_t temp; |
1817 | 2140 | ||
1818 | temp = show_urb (buf, PAGE_SIZE - size, urbp->urb); | 2141 | temp = show_urb (buf, PAGE_SIZE - size, urbp->urb); |
1819 | buf += temp; | 2142 | buf += temp; |
1820 | size += temp; | 2143 | size += temp; |
1821 | } | 2144 | } |
1822 | spin_unlock_irqrestore (&dum->lock, flags); | 2145 | spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); |
1823 | 2146 | ||
1824 | return size; | 2147 | return size; |
1825 | } | 2148 | } |
1826 | static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL); | 2149 | static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL); |
1827 | 2150 | ||
1828 | static int dummy_start (struct usb_hcd *hcd) | 2151 | static int dummy_start_ss(struct dummy_hcd *dum_hcd) |
1829 | { | 2152 | { |
1830 | struct dummy *dum; | 2153 | init_timer(&dum_hcd->timer); |
2154 | dum_hcd->timer.function = dummy_timer; | ||
2155 | dum_hcd->timer.data = (unsigned long)dum_hcd; | ||
2156 | dum_hcd->rh_state = DUMMY_RH_RUNNING; | ||
2157 | INIT_LIST_HEAD(&dum_hcd->urbp_list); | ||
2158 | dummy_hcd_to_hcd(dum_hcd)->power_budget = POWER_BUDGET; | ||
2159 | dummy_hcd_to_hcd(dum_hcd)->state = HC_STATE_RUNNING; | ||
2160 | dummy_hcd_to_hcd(dum_hcd)->uses_new_polling = 1; | ||
2161 | #ifdef CONFIG_USB_OTG | ||
2162 | dummy_hcd_to_hcd(dum_hcd)->self.otg_port = 1; | ||
2163 | #endif | ||
2164 | return 0; | ||
2165 | |||
2166 | /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ | ||
2167 | return device_create_file(dummy_dev(dum_hcd), &dev_attr_urbs); | ||
2168 | } | ||
1831 | 2169 | ||
1832 | dum = hcd_to_dummy (hcd); | 2170 | static int dummy_start(struct usb_hcd *hcd) |
2171 | { | ||
2172 | struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd); | ||
1833 | 2173 | ||
1834 | /* | 2174 | /* |
1835 | * MASTER side init ... we emulate a root hub that'll only ever | 2175 | * MASTER side init ... we emulate a root hub that'll only ever |
1836 | * talk to one device (the slave side). Also appears in sysfs, | 2176 | * talk to one device (the slave side). Also appears in sysfs, |
1837 | * just like more familiar pci-based HCDs. | 2177 | * just like more familiar pci-based HCDs. |
1838 | */ | 2178 | */ |
1839 | spin_lock_init (&dum->lock); | 2179 | if (!usb_hcd_is_primary_hcd(hcd)) |
1840 | init_timer (&dum->timer); | 2180 | return dummy_start_ss(dum_hcd); |
1841 | dum->timer.function = dummy_timer; | ||
1842 | dum->timer.data = (unsigned long) dum; | ||
1843 | dum->rh_state = DUMMY_RH_RUNNING; | ||
1844 | 2181 | ||
1845 | INIT_LIST_HEAD (&dum->urbp_list); | 2182 | spin_lock_init(&dum_hcd->dum->lock); |
2183 | init_timer(&dum_hcd->timer); | ||
2184 | dum_hcd->timer.function = dummy_timer; | ||
2185 | dum_hcd->timer.data = (unsigned long)dum_hcd; | ||
2186 | dum_hcd->rh_state = DUMMY_RH_RUNNING; | ||
2187 | |||
2188 | INIT_LIST_HEAD(&dum_hcd->urbp_list); | ||
1846 | 2189 | ||
1847 | hcd->power_budget = POWER_BUDGET; | 2190 | hcd->power_budget = POWER_BUDGET; |
1848 | hcd->state = HC_STATE_RUNNING; | 2191 | hcd->state = HC_STATE_RUNNING; |
@@ -1853,18 +2196,17 @@ static int dummy_start (struct usb_hcd *hcd) | |||
1853 | #endif | 2196 | #endif |
1854 | 2197 | ||
1855 | /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ | 2198 | /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ |
1856 | return device_create_file (dummy_dev(dum), &dev_attr_urbs); | 2199 | return device_create_file(dummy_dev(dum_hcd), &dev_attr_urbs); |
1857 | } | 2200 | } |
1858 | 2201 | ||
1859 | static void dummy_stop (struct usb_hcd *hcd) | 2202 | static void dummy_stop (struct usb_hcd *hcd) |
1860 | { | 2203 | { |
1861 | struct dummy *dum; | 2204 | struct dummy *dum; |
1862 | 2205 | ||
1863 | dum = hcd_to_dummy (hcd); | 2206 | dum = (hcd_to_dummy_hcd(hcd))->dum; |
1864 | 2207 | device_remove_file(dummy_dev(hcd_to_dummy_hcd(hcd)), &dev_attr_urbs); | |
1865 | device_remove_file (dummy_dev(dum), &dev_attr_urbs); | 2208 | usb_gadget_unregister_driver(dum->driver); |
1866 | usb_gadget_unregister_driver (dum->driver); | 2209 | dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)), "stopped\n"); |
1867 | dev_info (dummy_dev(dum), "stopped\n"); | ||
1868 | } | 2210 | } |
1869 | 2211 | ||
1870 | /*-------------------------------------------------------------------------*/ | 2212 | /*-------------------------------------------------------------------------*/ |
@@ -1874,13 +2216,59 @@ static int dummy_h_get_frame (struct usb_hcd *hcd) | |||
1874 | return dummy_g_get_frame (NULL); | 2216 | return dummy_g_get_frame (NULL); |
1875 | } | 2217 | } |
1876 | 2218 | ||
1877 | static const struct hc_driver dummy_hcd = { | 2219 | static int dummy_setup(struct usb_hcd *hcd) |
2220 | { | ||
2221 | if (usb_hcd_is_primary_hcd(hcd)) { | ||
2222 | the_controller.hs_hcd = hcd_to_dummy_hcd(hcd); | ||
2223 | the_controller.hs_hcd->dum = &the_controller; | ||
2224 | /* | ||
2225 | * Mark the first roothub as being USB 2.0. | ||
2226 | * The USB 3.0 roothub will be registered later by | ||
2227 | * dummy_hcd_probe() | ||
2228 | */ | ||
2229 | hcd->speed = HCD_USB2; | ||
2230 | hcd->self.root_hub->speed = USB_SPEED_HIGH; | ||
2231 | } else { | ||
2232 | the_controller.ss_hcd = hcd_to_dummy_hcd(hcd); | ||
2233 | the_controller.ss_hcd->dum = &the_controller; | ||
2234 | hcd->speed = HCD_USB3; | ||
2235 | hcd->self.root_hub->speed = USB_SPEED_SUPER; | ||
2236 | } | ||
2237 | return 0; | ||
2238 | } | ||
2239 | |||
2240 | /* Change a group of bulk endpoints to support multiple stream IDs */ | ||
2241 | int dummy_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, | ||
2242 | struct usb_host_endpoint **eps, unsigned int num_eps, | ||
2243 | unsigned int num_streams, gfp_t mem_flags) | ||
2244 | { | ||
2245 | if (hcd->speed != HCD_USB3) | ||
2246 | dev_dbg(dummy_dev(hcd_to_dummy_hcd(hcd)), | ||
2247 | "%s() - ERROR! Not supported for USB2.0 roothub\n", | ||
2248 | __func__); | ||
2249 | return 0; | ||
2250 | } | ||
2251 | |||
2252 | /* Reverts a group of bulk endpoints back to not using stream IDs. */ | ||
2253 | int dummy_free_streams(struct usb_hcd *hcd, struct usb_device *udev, | ||
2254 | struct usb_host_endpoint **eps, unsigned int num_eps, | ||
2255 | gfp_t mem_flags) | ||
2256 | { | ||
2257 | if (hcd->speed != HCD_USB3) | ||
2258 | dev_dbg(dummy_dev(hcd_to_dummy_hcd(hcd)), | ||
2259 | "%s() - ERROR! Not supported for USB2.0 roothub\n", | ||
2260 | __func__); | ||
2261 | return 0; | ||
2262 | } | ||
2263 | |||
2264 | static struct hc_driver dummy_hcd = { | ||
1878 | .description = (char *) driver_name, | 2265 | .description = (char *) driver_name, |
1879 | .product_desc = "Dummy host controller", | 2266 | .product_desc = "Dummy host controller", |
1880 | .hcd_priv_size = sizeof(struct dummy), | 2267 | .hcd_priv_size = sizeof(struct dummy_hcd), |
1881 | 2268 | ||
1882 | .flags = HCD_USB2, | 2269 | .flags = HCD_USB3 | HCD_SHARED, |
1883 | 2270 | ||
2271 | .reset = dummy_setup, | ||
1884 | .start = dummy_start, | 2272 | .start = dummy_start, |
1885 | .stop = dummy_stop, | 2273 | .stop = dummy_stop, |
1886 | 2274 | ||
@@ -1893,51 +2281,85 @@ static const struct hc_driver dummy_hcd = { | |||
1893 | .hub_control = dummy_hub_control, | 2281 | .hub_control = dummy_hub_control, |
1894 | .bus_suspend = dummy_bus_suspend, | 2282 | .bus_suspend = dummy_bus_suspend, |
1895 | .bus_resume = dummy_bus_resume, | 2283 | .bus_resume = dummy_bus_resume, |
2284 | |||
2285 | .alloc_streams = dummy_alloc_streams, | ||
2286 | .free_streams = dummy_free_streams, | ||
1896 | }; | 2287 | }; |
1897 | 2288 | ||
1898 | static int dummy_hcd_probe(struct platform_device *pdev) | 2289 | static int dummy_hcd_probe(struct platform_device *pdev) |
1899 | { | 2290 | { |
1900 | struct usb_hcd *hcd; | 2291 | struct usb_hcd *hs_hcd; |
2292 | struct usb_hcd *ss_hcd; | ||
1901 | int retval; | 2293 | int retval; |
1902 | 2294 | ||
1903 | dev_info(&pdev->dev, "%s, driver " DRIVER_VERSION "\n", driver_desc); | 2295 | dev_info(&pdev->dev, "%s, driver " DRIVER_VERSION "\n", driver_desc); |
1904 | 2296 | ||
1905 | hcd = usb_create_hcd(&dummy_hcd, &pdev->dev, dev_name(&pdev->dev)); | 2297 | if (!mod_data.is_super_speed) |
1906 | if (!hcd) | 2298 | dummy_hcd.flags = HCD_USB2; |
2299 | hs_hcd = usb_create_hcd(&dummy_hcd, &pdev->dev, dev_name(&pdev->dev)); | ||
2300 | if (!hs_hcd) | ||
1907 | return -ENOMEM; | 2301 | return -ENOMEM; |
1908 | the_controller = hcd_to_dummy (hcd); | 2302 | hs_hcd->has_tt = 1; |
1909 | hcd->has_tt = 1; | ||
1910 | 2303 | ||
1911 | retval = usb_add_hcd(hcd, 0, 0); | 2304 | retval = usb_add_hcd(hs_hcd, 0, 0); |
1912 | if (retval != 0) { | 2305 | if (retval != 0) { |
1913 | usb_put_hcd (hcd); | 2306 | usb_put_hcd(hs_hcd); |
1914 | the_controller = NULL; | 2307 | return retval; |
2308 | } | ||
2309 | |||
2310 | if (mod_data.is_super_speed) { | ||
2311 | ss_hcd = usb_create_shared_hcd(&dummy_hcd, &pdev->dev, | ||
2312 | dev_name(&pdev->dev), hs_hcd); | ||
2313 | if (!ss_hcd) { | ||
2314 | retval = -ENOMEM; | ||
2315 | goto dealloc_usb2_hcd; | ||
2316 | } | ||
2317 | |||
2318 | retval = usb_add_hcd(ss_hcd, 0, 0); | ||
2319 | if (retval) | ||
2320 | goto put_usb3_hcd; | ||
1915 | } | 2321 | } |
2322 | return 0; | ||
2323 | |||
2324 | put_usb3_hcd: | ||
2325 | usb_put_hcd(ss_hcd); | ||
2326 | dealloc_usb2_hcd: | ||
2327 | usb_put_hcd(hs_hcd); | ||
2328 | the_controller.hs_hcd = the_controller.ss_hcd = NULL; | ||
1916 | return retval; | 2329 | return retval; |
1917 | } | 2330 | } |
1918 | 2331 | ||
1919 | static int dummy_hcd_remove (struct platform_device *pdev) | 2332 | static int dummy_hcd_remove(struct platform_device *pdev) |
1920 | { | 2333 | { |
1921 | struct usb_hcd *hcd; | 2334 | struct dummy *dum; |
2335 | |||
2336 | dum = (hcd_to_dummy_hcd(platform_get_drvdata(pdev)))->dum; | ||
2337 | |||
2338 | if (dum->ss_hcd) { | ||
2339 | usb_remove_hcd(dummy_hcd_to_hcd(dum->ss_hcd)); | ||
2340 | usb_put_hcd(dummy_hcd_to_hcd(dum->ss_hcd)); | ||
2341 | } | ||
2342 | |||
2343 | usb_remove_hcd(dummy_hcd_to_hcd(dum->hs_hcd)); | ||
2344 | usb_put_hcd(dummy_hcd_to_hcd(dum->hs_hcd)); | ||
2345 | |||
2346 | the_controller.hs_hcd = NULL; | ||
2347 | the_controller.ss_hcd = NULL; | ||
1922 | 2348 | ||
1923 | hcd = platform_get_drvdata (pdev); | ||
1924 | usb_remove_hcd (hcd); | ||
1925 | usb_put_hcd (hcd); | ||
1926 | the_controller = NULL; | ||
1927 | return 0; | 2349 | return 0; |
1928 | } | 2350 | } |
1929 | 2351 | ||
1930 | static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state) | 2352 | static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state) |
1931 | { | 2353 | { |
1932 | struct usb_hcd *hcd; | 2354 | struct usb_hcd *hcd; |
1933 | struct dummy *dum; | 2355 | struct dummy_hcd *dum_hcd; |
1934 | int rc = 0; | 2356 | int rc = 0; |
1935 | 2357 | ||
1936 | dev_dbg (&pdev->dev, "%s\n", __func__); | 2358 | dev_dbg (&pdev->dev, "%s\n", __func__); |
1937 | 2359 | ||
1938 | hcd = platform_get_drvdata (pdev); | 2360 | hcd = platform_get_drvdata (pdev); |
1939 | dum = hcd_to_dummy (hcd); | 2361 | dum_hcd = hcd_to_dummy_hcd(hcd); |
1940 | if (dum->rh_state == DUMMY_RH_RUNNING) { | 2362 | if (dum_hcd->rh_state == DUMMY_RH_RUNNING) { |
1941 | dev_warn(&pdev->dev, "Root hub isn't suspended!\n"); | 2363 | dev_warn(&pdev->dev, "Root hub isn't suspended!\n"); |
1942 | rc = -EBUSY; | 2364 | rc = -EBUSY; |
1943 | } else | 2365 | } else |
@@ -1980,6 +2402,9 @@ static int __init init (void) | |||
1980 | if (usb_disabled ()) | 2402 | if (usb_disabled ()) |
1981 | return -ENODEV; | 2403 | return -ENODEV; |
1982 | 2404 | ||
2405 | if (!mod_data.is_high_speed && mod_data.is_super_speed) | ||
2406 | return -EINVAL; | ||
2407 | |||
1983 | the_hcd_pdev = platform_device_alloc(driver_name, -1); | 2408 | the_hcd_pdev = platform_device_alloc(driver_name, -1); |
1984 | if (!the_hcd_pdev) | 2409 | if (!the_hcd_pdev) |
1985 | return retval; | 2410 | return retval; |
@@ -1997,7 +2422,8 @@ static int __init init (void) | |||
1997 | retval = platform_device_add(the_hcd_pdev); | 2422 | retval = platform_device_add(the_hcd_pdev); |
1998 | if (retval < 0) | 2423 | if (retval < 0) |
1999 | goto err_add_hcd; | 2424 | goto err_add_hcd; |
2000 | if (!the_controller) { | 2425 | if (!the_controller.hs_hcd || |
2426 | (!the_controller.ss_hcd && mod_data.is_super_speed)) { | ||
2001 | /* | 2427 | /* |
2002 | * The hcd was added successfully but its probe function failed | 2428 | * The hcd was added successfully but its probe function failed |
2003 | * for some reason. | 2429 | * for some reason. |
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index 9b7360ff5aa7..7a7e6b7e1fd6 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c | |||
@@ -63,13 +63,16 @@ static int | |||
63 | ep_matches ( | 63 | ep_matches ( |
64 | struct usb_gadget *gadget, | 64 | struct usb_gadget *gadget, |
65 | struct usb_ep *ep, | 65 | struct usb_ep *ep, |
66 | struct usb_endpoint_descriptor *desc | 66 | struct usb_endpoint_descriptor *desc, |
67 | struct usb_ss_ep_comp_descriptor *ep_comp | ||
67 | ) | 68 | ) |
68 | { | 69 | { |
69 | u8 type; | 70 | u8 type; |
70 | const char *tmp; | 71 | const char *tmp; |
71 | u16 max; | 72 | u16 max; |
72 | 73 | ||
74 | int num_req_streams = 0; | ||
75 | |||
73 | /* endpoint already claimed? */ | 76 | /* endpoint already claimed? */ |
74 | if (NULL != ep->driver_data) | 77 | if (NULL != ep->driver_data) |
75 | return 0; | 78 | return 0; |
@@ -129,6 +132,22 @@ ep_matches ( | |||
129 | } | 132 | } |
130 | 133 | ||
131 | /* | 134 | /* |
135 | * Get the number of required streams from the EP companion | ||
136 | * descriptor and see if the EP matches it | ||
137 | */ | ||
138 | if (usb_endpoint_xfer_bulk(desc)) { | ||
139 | if (ep_comp) { | ||
140 | num_req_streams = ep_comp->bmAttributes & 0x1f; | ||
141 | if (num_req_streams > ep->max_streams) | ||
142 | return 0; | ||
143 | /* Update the ep_comp descriptor if needed */ | ||
144 | if (num_req_streams != ep->max_streams) | ||
145 | ep_comp->bmAttributes = ep->max_streams; | ||
146 | } | ||
147 | |||
148 | } | ||
149 | |||
150 | /* | ||
132 | * If the protocol driver hasn't yet decided on wMaxPacketSize | 151 | * If the protocol driver hasn't yet decided on wMaxPacketSize |
133 | * and wants to know the maximum possible, provide the info. | 152 | * and wants to know the maximum possible, provide the info. |
134 | */ | 153 | */ |
@@ -142,13 +161,13 @@ ep_matches ( | |||
142 | max = 0x7ff & le16_to_cpu(desc->wMaxPacketSize); | 161 | max = 0x7ff & le16_to_cpu(desc->wMaxPacketSize); |
143 | switch (type) { | 162 | switch (type) { |
144 | case USB_ENDPOINT_XFER_INT: | 163 | case USB_ENDPOINT_XFER_INT: |
145 | /* INT: limit 64 bytes full speed, 1024 high speed */ | 164 | /* INT: limit 64 bytes full speed, 1024 high/super speed */ |
146 | if (!gadget->is_dualspeed && max > 64) | 165 | if (!gadget->is_dualspeed && max > 64) |
147 | return 0; | 166 | return 0; |
148 | /* FALLTHROUGH */ | 167 | /* FALLTHROUGH */ |
149 | 168 | ||
150 | case USB_ENDPOINT_XFER_ISOC: | 169 | case USB_ENDPOINT_XFER_ISOC: |
151 | /* ISO: limit 1023 bytes full speed, 1024 high speed */ | 170 | /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ |
152 | if (ep->maxpacket < max) | 171 | if (ep->maxpacket < max) |
153 | return 0; | 172 | return 0; |
154 | if (!gadget->is_dualspeed && max > 1023) | 173 | if (!gadget->is_dualspeed && max > 1023) |
@@ -183,7 +202,7 @@ ep_matches ( | |||
183 | } | 202 | } |
184 | 203 | ||
185 | /* report (variable) full speed bulk maxpacket */ | 204 | /* report (variable) full speed bulk maxpacket */ |
186 | if (USB_ENDPOINT_XFER_BULK == type) { | 205 | if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) { |
187 | int size = ep->maxpacket; | 206 | int size = ep->maxpacket; |
188 | 207 | ||
189 | /* min() doesn't work on bitfields with gcc-3.5 */ | 208 | /* min() doesn't work on bitfields with gcc-3.5 */ |
@@ -191,6 +210,7 @@ ep_matches ( | |||
191 | size = 64; | 210 | size = 64; |
192 | desc->wMaxPacketSize = cpu_to_le16(size); | 211 | desc->wMaxPacketSize = cpu_to_le16(size); |
193 | } | 212 | } |
213 | ep->address = desc->bEndpointAddress; | ||
194 | return 1; | 214 | return 1; |
195 | } | 215 | } |
196 | 216 | ||
@@ -207,38 +227,53 @@ find_ep (struct usb_gadget *gadget, const char *name) | |||
207 | } | 227 | } |
208 | 228 | ||
209 | /** | 229 | /** |
210 | * usb_ep_autoconfig - choose an endpoint matching the descriptor | 230 | * usb_ep_autoconfig_ss() - choose an endpoint matching the ep |
231 | * descriptor and ep companion descriptor | ||
211 | * @gadget: The device to which the endpoint must belong. | 232 | * @gadget: The device to which the endpoint must belong. |
212 | * @desc: Endpoint descriptor, with endpoint direction and transfer mode | 233 | * @desc: Endpoint descriptor, with endpoint direction and transfer mode |
213 | * initialized. For periodic transfers, the maximum packet | 234 | * initialized. For periodic transfers, the maximum packet |
214 | * size must also be initialized. This is modified on success. | 235 | * size must also be initialized. This is modified on |
236 | * success. | ||
237 | * @ep_comp: Endpoint companion descriptor, with the required | ||
238 | * number of streams. Will be modified when the chosen EP | ||
239 | * supports a different number of streams. | ||
215 | * | 240 | * |
216 | * By choosing an endpoint to use with the specified descriptor, this | 241 | * This routine replaces the usb_ep_autoconfig when needed |
217 | * routine simplifies writing gadget drivers that work with multiple | 242 | * superspeed enhancments. If such enhancemnets are required, |
218 | * USB device controllers. The endpoint would be passed later to | 243 | * the FD should call usb_ep_autoconfig_ss directly and provide |
219 | * usb_ep_enable(), along with some descriptor. | 244 | * the additional ep_comp parameter. |
245 | * | ||
246 | * By choosing an endpoint to use with the specified descriptor, | ||
247 | * this routine simplifies writing gadget drivers that work with | ||
248 | * multiple USB device controllers. The endpoint would be | ||
249 | * passed later to usb_ep_enable(), along with some descriptor. | ||
220 | * | 250 | * |
221 | * That second descriptor won't always be the same as the first one. | 251 | * That second descriptor won't always be the same as the first one. |
222 | * For example, isochronous endpoints can be autoconfigured for high | 252 | * For example, isochronous endpoints can be autoconfigured for high |
223 | * bandwidth, and then used in several lower bandwidth altsettings. | 253 | * bandwidth, and then used in several lower bandwidth altsettings. |
224 | * Also, high and full speed descriptors will be different. | 254 | * Also, high and full speed descriptors will be different. |
225 | * | 255 | * |
226 | * Be sure to examine and test the results of autoconfiguration on your | 256 | * Be sure to examine and test the results of autoconfiguration |
227 | * hardware. This code may not make the best choices about how to use the | 257 | * on your hardware. This code may not make the best choices |
228 | * USB controller, and it can't know all the restrictions that may apply. | 258 | * about how to use the USB controller, and it can't know all |
229 | * Some combinations of driver and hardware won't be able to autoconfigure. | 259 | * the restrictions that may apply. Some combinations of driver |
260 | * and hardware won't be able to autoconfigure. | ||
230 | * | 261 | * |
231 | * On success, this returns an un-claimed usb_ep, and modifies the endpoint | 262 | * On success, this returns an un-claimed usb_ep, and modifies the endpoint |
232 | * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value | 263 | * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value |
233 | * is initialized as if the endpoint were used at full speed. To prevent | 264 | * is initialized as if the endpoint were used at full speed and |
234 | * the endpoint from being returned by a later autoconfig call, claim it | 265 | * the bmAttribute field in the ep companion descriptor is |
235 | * by assigning ep->driver_data to some non-null value. | 266 | * updated with the assigned number of streams if it is |
267 | * different from the original value. To prevent the endpoint | ||
268 | * from being returned by a later autoconfig call, claim it by | ||
269 | * assigning ep->driver_data to some non-null value. | ||
236 | * | 270 | * |
237 | * On failure, this returns a null endpoint descriptor. | 271 | * On failure, this returns a null endpoint descriptor. |
238 | */ | 272 | */ |
239 | struct usb_ep *usb_ep_autoconfig ( | 273 | struct usb_ep *usb_ep_autoconfig_ss( |
240 | struct usb_gadget *gadget, | 274 | struct usb_gadget *gadget, |
241 | struct usb_endpoint_descriptor *desc | 275 | struct usb_endpoint_descriptor *desc, |
276 | struct usb_ss_ep_comp_descriptor *ep_comp | ||
242 | ) | 277 | ) |
243 | { | 278 | { |
244 | struct usb_ep *ep; | 279 | struct usb_ep *ep; |
@@ -252,23 +287,24 @@ struct usb_ep *usb_ep_autoconfig ( | |||
252 | if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) { | 287 | if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) { |
253 | /* ep-e, ep-f are PIO with only 64 byte fifos */ | 288 | /* ep-e, ep-f are PIO with only 64 byte fifos */ |
254 | ep = find_ep (gadget, "ep-e"); | 289 | ep = find_ep (gadget, "ep-e"); |
255 | if (ep && ep_matches (gadget, ep, desc)) | 290 | if (ep && ep_matches(gadget, ep, desc, ep_comp)) |
256 | return ep; | 291 | return ep; |
257 | ep = find_ep (gadget, "ep-f"); | 292 | ep = find_ep (gadget, "ep-f"); |
258 | if (ep && ep_matches (gadget, ep, desc)) | 293 | if (ep && ep_matches(gadget, ep, desc, ep_comp)) |
259 | return ep; | 294 | return ep; |
260 | 295 | ||
261 | } else if (gadget_is_goku (gadget)) { | 296 | } else if (gadget_is_goku (gadget)) { |
262 | if (USB_ENDPOINT_XFER_INT == type) { | 297 | if (USB_ENDPOINT_XFER_INT == type) { |
263 | /* single buffering is enough */ | 298 | /* single buffering is enough */ |
264 | ep = find_ep (gadget, "ep3-bulk"); | 299 | ep = find_ep(gadget, "ep3-bulk"); |
265 | if (ep && ep_matches (gadget, ep, desc)) | 300 | if (ep && ep_matches(gadget, ep, desc, ep_comp)) |
266 | return ep; | 301 | return ep; |
267 | } else if (USB_ENDPOINT_XFER_BULK == type | 302 | } else if (USB_ENDPOINT_XFER_BULK == type |
268 | && (USB_DIR_IN & desc->bEndpointAddress)) { | 303 | && (USB_DIR_IN & desc->bEndpointAddress)) { |
269 | /* DMA may be available */ | 304 | /* DMA may be available */ |
270 | ep = find_ep (gadget, "ep2-bulk"); | 305 | ep = find_ep(gadget, "ep2-bulk"); |
271 | if (ep && ep_matches (gadget, ep, desc)) | 306 | if (ep && ep_matches(gadget, ep, desc, |
307 | ep_comp)) | ||
272 | return ep; | 308 | return ep; |
273 | } | 309 | } |
274 | 310 | ||
@@ -287,14 +323,14 @@ struct usb_ep *usb_ep_autoconfig ( | |||
287 | ep = find_ep(gadget, "ep2out"); | 323 | ep = find_ep(gadget, "ep2out"); |
288 | } else | 324 | } else |
289 | ep = NULL; | 325 | ep = NULL; |
290 | if (ep && ep_matches (gadget, ep, desc)) | 326 | if (ep && ep_matches(gadget, ep, desc, ep_comp)) |
291 | return ep; | 327 | return ep; |
292 | #endif | 328 | #endif |
293 | } | 329 | } |
294 | 330 | ||
295 | /* Second, look at endpoints until an unclaimed one looks usable */ | 331 | /* Second, look at endpoints until an unclaimed one looks usable */ |
296 | list_for_each_entry (ep, &gadget->ep_list, ep_list) { | 332 | list_for_each_entry (ep, &gadget->ep_list, ep_list) { |
297 | if (ep_matches (gadget, ep, desc)) | 333 | if (ep_matches(gadget, ep, desc, ep_comp)) |
298 | return ep; | 334 | return ep; |
299 | } | 335 | } |
300 | 336 | ||
@@ -303,6 +339,46 @@ struct usb_ep *usb_ep_autoconfig ( | |||
303 | } | 339 | } |
304 | 340 | ||
305 | /** | 341 | /** |
342 | * usb_ep_autoconfig() - choose an endpoint matching the | ||
343 | * descriptor | ||
344 | * @gadget: The device to which the endpoint must belong. | ||
345 | * @desc: Endpoint descriptor, with endpoint direction and transfer mode | ||
346 | * initialized. For periodic transfers, the maximum packet | ||
347 | * size must also be initialized. This is modified on success. | ||
348 | * | ||
349 | * By choosing an endpoint to use with the specified descriptor, this | ||
350 | * routine simplifies writing gadget drivers that work with multiple | ||
351 | * USB device controllers. The endpoint would be passed later to | ||
352 | * usb_ep_enable(), along with some descriptor. | ||
353 | * | ||
354 | * That second descriptor won't always be the same as the first one. | ||
355 | * For example, isochronous endpoints can be autoconfigured for high | ||
356 | * bandwidth, and then used in several lower bandwidth altsettings. | ||
357 | * Also, high and full speed descriptors will be different. | ||
358 | * | ||
359 | * Be sure to examine and test the results of autoconfiguration on your | ||
360 | * hardware. This code may not make the best choices about how to use the | ||
361 | * USB controller, and it can't know all the restrictions that may apply. | ||
362 | * Some combinations of driver and hardware won't be able to autoconfigure. | ||
363 | * | ||
364 | * On success, this returns an un-claimed usb_ep, and modifies the endpoint | ||
365 | * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value | ||
366 | * is initialized as if the endpoint were used at full speed. To prevent | ||
367 | * the endpoint from being returned by a later autoconfig call, claim it | ||
368 | * by assigning ep->driver_data to some non-null value. | ||
369 | * | ||
370 | * On failure, this returns a null endpoint descriptor. | ||
371 | */ | ||
372 | struct usb_ep *usb_ep_autoconfig( | ||
373 | struct usb_gadget *gadget, | ||
374 | struct usb_endpoint_descriptor *desc | ||
375 | ) | ||
376 | { | ||
377 | return usb_ep_autoconfig_ss(gadget, desc, NULL); | ||
378 | } | ||
379 | |||
380 | |||
381 | /** | ||
306 | * usb_ep_autoconfig_reset - reset endpoint autoconfig state | 382 | * usb_ep_autoconfig_reset - reset endpoint autoconfig state |
307 | * @gadget: device for which autoconfig state will be reset | 383 | * @gadget: device for which autoconfig state will be reset |
308 | * | 384 | * |
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 1690c9d68256..aafc84f33e26 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -401,6 +401,7 @@ static struct usb_composite_driver eth_driver = { | |||
401 | .name = "g_ether", | 401 | .name = "g_ether", |
402 | .dev = &device_desc, | 402 | .dev = &device_desc, |
403 | .strings = dev_strings, | 403 | .strings = dev_strings, |
404 | .max_speed = USB_SPEED_SUPER, | ||
404 | .unbind = __exit_p(eth_unbind), | 405 | .unbind = __exit_p(eth_unbind), |
405 | }; | 406 | }; |
406 | 407 | ||
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c index bd6226cbae86..3f8849339ade 100644 --- a/drivers/usb/gadget/f_acm.c +++ b/drivers/usb/gadget/f_acm.c | |||
@@ -39,12 +39,6 @@ | |||
39 | * descriptors (roughly equivalent to CDC Unions) may sometimes help. | 39 | * descriptors (roughly equivalent to CDC Unions) may sometimes help. |
40 | */ | 40 | */ |
41 | 41 | ||
42 | struct acm_ep_descs { | ||
43 | struct usb_endpoint_descriptor *in; | ||
44 | struct usb_endpoint_descriptor *out; | ||
45 | struct usb_endpoint_descriptor *notify; | ||
46 | }; | ||
47 | |||
48 | struct f_acm { | 42 | struct f_acm { |
49 | struct gserial port; | 43 | struct gserial port; |
50 | u8 ctrl_id, data_id; | 44 | u8 ctrl_id, data_id; |
@@ -58,11 +52,7 @@ struct f_acm { | |||
58 | */ | 52 | */ |
59 | spinlock_t lock; | 53 | spinlock_t lock; |
60 | 54 | ||
61 | struct acm_ep_descs fs; | ||
62 | struct acm_ep_descs hs; | ||
63 | |||
64 | struct usb_ep *notify; | 55 | struct usb_ep *notify; |
65 | struct usb_endpoint_descriptor *notify_desc; | ||
66 | struct usb_request *notify_req; | 56 | struct usb_request *notify_req; |
67 | 57 | ||
68 | struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */ | 58 | struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */ |
@@ -405,23 +395,27 @@ static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
405 | usb_ep_disable(acm->notify); | 395 | usb_ep_disable(acm->notify); |
406 | } else { | 396 | } else { |
407 | VDBG(cdev, "init acm ctrl interface %d\n", intf); | 397 | VDBG(cdev, "init acm ctrl interface %d\n", intf); |
408 | acm->notify_desc = ep_choose(cdev->gadget, | 398 | if (config_ep_by_speed(cdev->gadget, f, acm->notify)) |
409 | acm->hs.notify, | 399 | return -EINVAL; |
410 | acm->fs.notify); | ||
411 | } | 400 | } |
412 | usb_ep_enable(acm->notify, acm->notify_desc); | 401 | usb_ep_enable(acm->notify); |
413 | acm->notify->driver_data = acm; | 402 | acm->notify->driver_data = acm; |
414 | 403 | ||
415 | } else if (intf == acm->data_id) { | 404 | } else if (intf == acm->data_id) { |
416 | if (acm->port.in->driver_data) { | 405 | if (acm->port.in->driver_data) { |
417 | DBG(cdev, "reset acm ttyGS%d\n", acm->port_num); | 406 | DBG(cdev, "reset acm ttyGS%d\n", acm->port_num); |
418 | gserial_disconnect(&acm->port); | 407 | gserial_disconnect(&acm->port); |
419 | } else { | 408 | } |
409 | if (!acm->port.in->desc || !acm->port.out->desc) { | ||
420 | DBG(cdev, "activate acm ttyGS%d\n", acm->port_num); | 410 | DBG(cdev, "activate acm ttyGS%d\n", acm->port_num); |
421 | acm->port.in_desc = ep_choose(cdev->gadget, | 411 | if (config_ep_by_speed(cdev->gadget, f, |
422 | acm->hs.in, acm->fs.in); | 412 | acm->port.in) || |
423 | acm->port.out_desc = ep_choose(cdev->gadget, | 413 | config_ep_by_speed(cdev->gadget, f, |
424 | acm->hs.out, acm->fs.out); | 414 | acm->port.out)) { |
415 | acm->port.in->desc = NULL; | ||
416 | acm->port.out->desc = NULL; | ||
417 | return -EINVAL; | ||
418 | } | ||
425 | } | 419 | } |
426 | gserial_connect(&acm->port, acm->port_num); | 420 | gserial_connect(&acm->port, acm->port_num); |
427 | 421 | ||
@@ -629,18 +623,11 @@ acm_bind(struct usb_configuration *c, struct usb_function *f) | |||
629 | acm->notify_req->complete = acm_cdc_notify_complete; | 623 | acm->notify_req->complete = acm_cdc_notify_complete; |
630 | acm->notify_req->context = acm; | 624 | acm->notify_req->context = acm; |
631 | 625 | ||
632 | /* copy descriptors, and track endpoint copies */ | 626 | /* copy descriptors */ |
633 | f->descriptors = usb_copy_descriptors(acm_fs_function); | 627 | f->descriptors = usb_copy_descriptors(acm_fs_function); |
634 | if (!f->descriptors) | 628 | if (!f->descriptors) |
635 | goto fail; | 629 | goto fail; |
636 | 630 | ||
637 | acm->fs.in = usb_find_endpoint(acm_fs_function, | ||
638 | f->descriptors, &acm_fs_in_desc); | ||
639 | acm->fs.out = usb_find_endpoint(acm_fs_function, | ||
640 | f->descriptors, &acm_fs_out_desc); | ||
641 | acm->fs.notify = usb_find_endpoint(acm_fs_function, | ||
642 | f->descriptors, &acm_fs_notify_desc); | ||
643 | |||
644 | /* support all relevant hardware speeds... we expect that when | 631 | /* support all relevant hardware speeds... we expect that when |
645 | * hardware is dual speed, all bulk-capable endpoints work at | 632 | * hardware is dual speed, all bulk-capable endpoints work at |
646 | * both speeds | 633 | * both speeds |
@@ -653,15 +640,8 @@ acm_bind(struct usb_configuration *c, struct usb_function *f) | |||
653 | acm_hs_notify_desc.bEndpointAddress = | 640 | acm_hs_notify_desc.bEndpointAddress = |
654 | acm_fs_notify_desc.bEndpointAddress; | 641 | acm_fs_notify_desc.bEndpointAddress; |
655 | 642 | ||
656 | /* copy descriptors, and track endpoint copies */ | 643 | /* copy descriptors */ |
657 | f->hs_descriptors = usb_copy_descriptors(acm_hs_function); | 644 | f->hs_descriptors = usb_copy_descriptors(acm_hs_function); |
658 | |||
659 | acm->hs.in = usb_find_endpoint(acm_hs_function, | ||
660 | f->hs_descriptors, &acm_hs_in_desc); | ||
661 | acm->hs.out = usb_find_endpoint(acm_hs_function, | ||
662 | f->hs_descriptors, &acm_hs_out_desc); | ||
663 | acm->hs.notify = usb_find_endpoint(acm_hs_function, | ||
664 | f->hs_descriptors, &acm_hs_notify_desc); | ||
665 | } | 645 | } |
666 | 646 | ||
667 | DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n", | 647 | DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n", |
diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_audio.c index 8ee330a2ab58..02a02700b51d 100644 --- a/drivers/usb/gadget/f_audio.c +++ b/drivers/usb/gadget/f_audio.c | |||
@@ -279,7 +279,6 @@ struct f_audio { | |||
279 | 279 | ||
280 | /* endpoints handle full and/or high speeds */ | 280 | /* endpoints handle full and/or high speeds */ |
281 | struct usb_ep *out_ep; | 281 | struct usb_ep *out_ep; |
282 | struct usb_endpoint_descriptor *out_desc; | ||
283 | 282 | ||
284 | spinlock_t lock; | 283 | spinlock_t lock; |
285 | struct f_audio_buf *copy_buf; | 284 | struct f_audio_buf *copy_buf; |
@@ -575,7 +574,7 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
575 | 574 | ||
576 | if (intf == 1) { | 575 | if (intf == 1) { |
577 | if (alt == 1) { | 576 | if (alt == 1) { |
578 | usb_ep_enable(out_ep, audio->out_desc); | 577 | usb_ep_enable(out_ep); |
579 | out_ep->driver_data = audio; | 578 | out_ep->driver_data = audio; |
580 | audio->copy_buf = f_audio_buffer_alloc(audio_buf_size); | 579 | audio->copy_buf = f_audio_buffer_alloc(audio_buf_size); |
581 | if (IS_ERR(audio->copy_buf)) | 580 | if (IS_ERR(audio->copy_buf)) |
@@ -677,6 +676,7 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f) | |||
677 | if (!ep) | 676 | if (!ep) |
678 | goto fail; | 677 | goto fail; |
679 | audio->out_ep = ep; | 678 | audio->out_ep = ep; |
679 | audio->out_ep->desc = &as_out_ep_desc; | ||
680 | ep->driver_data = cdev; /* claim */ | 680 | ep->driver_data = cdev; /* claim */ |
681 | 681 | ||
682 | status = -ENOMEM; | 682 | status = -ENOMEM; |
@@ -776,7 +776,6 @@ int __init audio_bind_config(struct usb_configuration *c) | |||
776 | audio->card.func.set_alt = f_audio_set_alt; | 776 | audio->card.func.set_alt = f_audio_set_alt; |
777 | audio->card.func.setup = f_audio_setup; | 777 | audio->card.func.setup = f_audio_setup; |
778 | audio->card.func.disable = f_audio_disable; | 778 | audio->card.func.disable = f_audio_disable; |
779 | audio->out_desc = &as_out_ep_desc; | ||
780 | 779 | ||
781 | control_selector_init(audio); | 780 | control_selector_init(audio); |
782 | 781 | ||
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c index 544257a89ed2..3691a0cb9465 100644 --- a/drivers/usb/gadget/f_ecm.c +++ b/drivers/usb/gadget/f_ecm.c | |||
@@ -46,11 +46,6 @@ | |||
46 | * and also means that a get_alt() method is required. | 46 | * and also means that a get_alt() method is required. |
47 | */ | 47 | */ |
48 | 48 | ||
49 | struct ecm_ep_descs { | ||
50 | struct usb_endpoint_descriptor *in; | ||
51 | struct usb_endpoint_descriptor *out; | ||
52 | struct usb_endpoint_descriptor *notify; | ||
53 | }; | ||
54 | 49 | ||
55 | enum ecm_notify_state { | 50 | enum ecm_notify_state { |
56 | ECM_NOTIFY_NONE, /* don't notify */ | 51 | ECM_NOTIFY_NONE, /* don't notify */ |
@@ -64,11 +59,7 @@ struct f_ecm { | |||
64 | 59 | ||
65 | char ethaddr[14]; | 60 | char ethaddr[14]; |
66 | 61 | ||
67 | struct ecm_ep_descs fs; | ||
68 | struct ecm_ep_descs hs; | ||
69 | |||
70 | struct usb_ep *notify; | 62 | struct usb_ep *notify; |
71 | struct usb_endpoint_descriptor *notify_desc; | ||
72 | struct usb_request *notify_req; | 63 | struct usb_request *notify_req; |
73 | u8 notify_state; | 64 | u8 notify_state; |
74 | bool is_open; | 65 | bool is_open; |
@@ -86,10 +77,12 @@ static inline struct f_ecm *func_to_ecm(struct usb_function *f) | |||
86 | /* peak (theoretical) bulk transfer rate in bits-per-second */ | 77 | /* peak (theoretical) bulk transfer rate in bits-per-second */ |
87 | static inline unsigned ecm_bitrate(struct usb_gadget *g) | 78 | static inline unsigned ecm_bitrate(struct usb_gadget *g) |
88 | { | 79 | { |
89 | if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) | 80 | if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) |
81 | return 13 * 1024 * 8 * 1000 * 8; | ||
82 | else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) | ||
90 | return 13 * 512 * 8 * 1000 * 8; | 83 | return 13 * 512 * 8 * 1000 * 8; |
91 | else | 84 | else |
92 | return 19 * 64 * 1 * 1000 * 8; | 85 | return 19 * 64 * 1 * 1000 * 8; |
93 | } | 86 | } |
94 | 87 | ||
95 | /*-------------------------------------------------------------------------*/ | 88 | /*-------------------------------------------------------------------------*/ |
@@ -219,8 +212,10 @@ static struct usb_descriptor_header *ecm_fs_function[] = { | |||
219 | (struct usb_descriptor_header *) &ecm_header_desc, | 212 | (struct usb_descriptor_header *) &ecm_header_desc, |
220 | (struct usb_descriptor_header *) &ecm_union_desc, | 213 | (struct usb_descriptor_header *) &ecm_union_desc, |
221 | (struct usb_descriptor_header *) &ecm_desc, | 214 | (struct usb_descriptor_header *) &ecm_desc, |
215 | |||
222 | /* NOTE: status endpoint might need to be removed */ | 216 | /* NOTE: status endpoint might need to be removed */ |
223 | (struct usb_descriptor_header *) &fs_ecm_notify_desc, | 217 | (struct usb_descriptor_header *) &fs_ecm_notify_desc, |
218 | |||
224 | /* data interface, altsettings 0 and 1 */ | 219 | /* data interface, altsettings 0 and 1 */ |
225 | (struct usb_descriptor_header *) &ecm_data_nop_intf, | 220 | (struct usb_descriptor_header *) &ecm_data_nop_intf, |
226 | (struct usb_descriptor_header *) &ecm_data_intf, | 221 | (struct usb_descriptor_header *) &ecm_data_intf, |
@@ -240,6 +235,7 @@ static struct usb_endpoint_descriptor hs_ecm_notify_desc = { | |||
240 | .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT), | 235 | .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT), |
241 | .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, | 236 | .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, |
242 | }; | 237 | }; |
238 | |||
243 | static struct usb_endpoint_descriptor hs_ecm_in_desc = { | 239 | static struct usb_endpoint_descriptor hs_ecm_in_desc = { |
244 | .bLength = USB_DT_ENDPOINT_SIZE, | 240 | .bLength = USB_DT_ENDPOINT_SIZE, |
245 | .bDescriptorType = USB_DT_ENDPOINT, | 241 | .bDescriptorType = USB_DT_ENDPOINT, |
@@ -264,8 +260,10 @@ static struct usb_descriptor_header *ecm_hs_function[] = { | |||
264 | (struct usb_descriptor_header *) &ecm_header_desc, | 260 | (struct usb_descriptor_header *) &ecm_header_desc, |
265 | (struct usb_descriptor_header *) &ecm_union_desc, | 261 | (struct usb_descriptor_header *) &ecm_union_desc, |
266 | (struct usb_descriptor_header *) &ecm_desc, | 262 | (struct usb_descriptor_header *) &ecm_desc, |
263 | |||
267 | /* NOTE: status endpoint might need to be removed */ | 264 | /* NOTE: status endpoint might need to be removed */ |
268 | (struct usb_descriptor_header *) &hs_ecm_notify_desc, | 265 | (struct usb_descriptor_header *) &hs_ecm_notify_desc, |
266 | |||
269 | /* data interface, altsettings 0 and 1 */ | 267 | /* data interface, altsettings 0 and 1 */ |
270 | (struct usb_descriptor_header *) &ecm_data_nop_intf, | 268 | (struct usb_descriptor_header *) &ecm_data_nop_intf, |
271 | (struct usb_descriptor_header *) &ecm_data_intf, | 269 | (struct usb_descriptor_header *) &ecm_data_intf, |
@@ -274,6 +272,76 @@ static struct usb_descriptor_header *ecm_hs_function[] = { | |||
274 | NULL, | 272 | NULL, |
275 | }; | 273 | }; |
276 | 274 | ||
275 | /* super speed support: */ | ||
276 | |||
277 | static struct usb_endpoint_descriptor ss_ecm_notify_desc = { | ||
278 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
279 | .bDescriptorType = USB_DT_ENDPOINT, | ||
280 | |||
281 | .bEndpointAddress = USB_DIR_IN, | ||
282 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
283 | .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT), | ||
284 | .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, | ||
285 | }; | ||
286 | |||
287 | static struct usb_ss_ep_comp_descriptor ss_ecm_intr_comp_desc = { | ||
288 | .bLength = sizeof ss_ecm_intr_comp_desc, | ||
289 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
290 | |||
291 | /* the following 3 values can be tweaked if necessary */ | ||
292 | /* .bMaxBurst = 0, */ | ||
293 | /* .bmAttributes = 0, */ | ||
294 | .wBytesPerInterval = cpu_to_le16(ECM_STATUS_BYTECOUNT), | ||
295 | }; | ||
296 | |||
297 | static struct usb_endpoint_descriptor ss_ecm_in_desc = { | ||
298 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
299 | .bDescriptorType = USB_DT_ENDPOINT, | ||
300 | |||
301 | .bEndpointAddress = USB_DIR_IN, | ||
302 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
303 | .wMaxPacketSize = cpu_to_le16(1024), | ||
304 | }; | ||
305 | |||
306 | static struct usb_endpoint_descriptor ss_ecm_out_desc = { | ||
307 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
308 | .bDescriptorType = USB_DT_ENDPOINT, | ||
309 | |||
310 | .bEndpointAddress = USB_DIR_OUT, | ||
311 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
312 | .wMaxPacketSize = cpu_to_le16(1024), | ||
313 | }; | ||
314 | |||
315 | static struct usb_ss_ep_comp_descriptor ss_ecm_bulk_comp_desc = { | ||
316 | .bLength = sizeof ss_ecm_bulk_comp_desc, | ||
317 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
318 | |||
319 | /* the following 2 values can be tweaked if necessary */ | ||
320 | /* .bMaxBurst = 0, */ | ||
321 | /* .bmAttributes = 0, */ | ||
322 | }; | ||
323 | |||
324 | static struct usb_descriptor_header *ecm_ss_function[] = { | ||
325 | /* CDC ECM control descriptors */ | ||
326 | (struct usb_descriptor_header *) &ecm_control_intf, | ||
327 | (struct usb_descriptor_header *) &ecm_header_desc, | ||
328 | (struct usb_descriptor_header *) &ecm_union_desc, | ||
329 | (struct usb_descriptor_header *) &ecm_desc, | ||
330 | |||
331 | /* NOTE: status endpoint might need to be removed */ | ||
332 | (struct usb_descriptor_header *) &ss_ecm_notify_desc, | ||
333 | (struct usb_descriptor_header *) &ss_ecm_intr_comp_desc, | ||
334 | |||
335 | /* data interface, altsettings 0 and 1 */ | ||
336 | (struct usb_descriptor_header *) &ecm_data_nop_intf, | ||
337 | (struct usb_descriptor_header *) &ecm_data_intf, | ||
338 | (struct usb_descriptor_header *) &ss_ecm_in_desc, | ||
339 | (struct usb_descriptor_header *) &ss_ecm_bulk_comp_desc, | ||
340 | (struct usb_descriptor_header *) &ss_ecm_out_desc, | ||
341 | (struct usb_descriptor_header *) &ss_ecm_bulk_comp_desc, | ||
342 | NULL, | ||
343 | }; | ||
344 | |||
277 | /* string descriptors: */ | 345 | /* string descriptors: */ |
278 | 346 | ||
279 | static struct usb_string ecm_string_defs[] = { | 347 | static struct usb_string ecm_string_defs[] = { |
@@ -464,13 +532,13 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
464 | if (ecm->notify->driver_data) { | 532 | if (ecm->notify->driver_data) { |
465 | VDBG(cdev, "reset ecm control %d\n", intf); | 533 | VDBG(cdev, "reset ecm control %d\n", intf); |
466 | usb_ep_disable(ecm->notify); | 534 | usb_ep_disable(ecm->notify); |
467 | } else { | 535 | } |
536 | if (!(ecm->notify->desc)) { | ||
468 | VDBG(cdev, "init ecm ctrl %d\n", intf); | 537 | VDBG(cdev, "init ecm ctrl %d\n", intf); |
469 | ecm->notify_desc = ep_choose(cdev->gadget, | 538 | if (config_ep_by_speed(cdev->gadget, f, ecm->notify)) |
470 | ecm->hs.notify, | 539 | goto fail; |
471 | ecm->fs.notify); | ||
472 | } | 540 | } |
473 | usb_ep_enable(ecm->notify, ecm->notify_desc); | 541 | usb_ep_enable(ecm->notify); |
474 | ecm->notify->driver_data = ecm; | 542 | ecm->notify->driver_data = ecm; |
475 | 543 | ||
476 | /* Data interface has two altsettings, 0 and 1 */ | 544 | /* Data interface has two altsettings, 0 and 1 */ |
@@ -483,12 +551,17 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
483 | gether_disconnect(&ecm->port); | 551 | gether_disconnect(&ecm->port); |
484 | } | 552 | } |
485 | 553 | ||
486 | if (!ecm->port.in) { | 554 | if (!ecm->port.in_ep->desc || |
555 | !ecm->port.out_ep->desc) { | ||
487 | DBG(cdev, "init ecm\n"); | 556 | DBG(cdev, "init ecm\n"); |
488 | ecm->port.in = ep_choose(cdev->gadget, | 557 | if (config_ep_by_speed(cdev->gadget, f, |
489 | ecm->hs.in, ecm->fs.in); | 558 | ecm->port.in_ep) || |
490 | ecm->port.out = ep_choose(cdev->gadget, | 559 | config_ep_by_speed(cdev->gadget, f, |
491 | ecm->hs.out, ecm->fs.out); | 560 | ecm->port.out_ep)) { |
561 | ecm->port.in_ep->desc = NULL; | ||
562 | ecm->port.out_ep->desc = NULL; | ||
563 | goto fail; | ||
564 | } | ||
492 | } | 565 | } |
493 | 566 | ||
494 | /* CDC Ethernet only sends data in non-default altsettings. | 567 | /* CDC Ethernet only sends data in non-default altsettings. |
@@ -549,7 +622,7 @@ static void ecm_disable(struct usb_function *f) | |||
549 | if (ecm->notify->driver_data) { | 622 | if (ecm->notify->driver_data) { |
550 | usb_ep_disable(ecm->notify); | 623 | usb_ep_disable(ecm->notify); |
551 | ecm->notify->driver_data = NULL; | 624 | ecm->notify->driver_data = NULL; |
552 | ecm->notify_desc = NULL; | 625 | ecm->notify->desc = NULL; |
553 | } | 626 | } |
554 | } | 627 | } |
555 | 628 | ||
@@ -665,13 +738,6 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
665 | if (!f->descriptors) | 738 | if (!f->descriptors) |
666 | goto fail; | 739 | goto fail; |
667 | 740 | ||
668 | ecm->fs.in = usb_find_endpoint(ecm_fs_function, | ||
669 | f->descriptors, &fs_ecm_in_desc); | ||
670 | ecm->fs.out = usb_find_endpoint(ecm_fs_function, | ||
671 | f->descriptors, &fs_ecm_out_desc); | ||
672 | ecm->fs.notify = usb_find_endpoint(ecm_fs_function, | ||
673 | f->descriptors, &fs_ecm_notify_desc); | ||
674 | |||
675 | /* support all relevant hardware speeds... we expect that when | 741 | /* support all relevant hardware speeds... we expect that when |
676 | * hardware is dual speed, all bulk-capable endpoints work at | 742 | * hardware is dual speed, all bulk-capable endpoints work at |
677 | * both speeds | 743 | * both speeds |
@@ -688,13 +754,20 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
688 | f->hs_descriptors = usb_copy_descriptors(ecm_hs_function); | 754 | f->hs_descriptors = usb_copy_descriptors(ecm_hs_function); |
689 | if (!f->hs_descriptors) | 755 | if (!f->hs_descriptors) |
690 | goto fail; | 756 | goto fail; |
757 | } | ||
691 | 758 | ||
692 | ecm->hs.in = usb_find_endpoint(ecm_hs_function, | 759 | if (gadget_is_superspeed(c->cdev->gadget)) { |
693 | f->hs_descriptors, &hs_ecm_in_desc); | 760 | ss_ecm_in_desc.bEndpointAddress = |
694 | ecm->hs.out = usb_find_endpoint(ecm_hs_function, | 761 | fs_ecm_in_desc.bEndpointAddress; |
695 | f->hs_descriptors, &hs_ecm_out_desc); | 762 | ss_ecm_out_desc.bEndpointAddress = |
696 | ecm->hs.notify = usb_find_endpoint(ecm_hs_function, | 763 | fs_ecm_out_desc.bEndpointAddress; |
697 | f->hs_descriptors, &hs_ecm_notify_desc); | 764 | ss_ecm_notify_desc.bEndpointAddress = |
765 | fs_ecm_notify_desc.bEndpointAddress; | ||
766 | |||
767 | /* copy descriptors, and track endpoint copies */ | ||
768 | f->ss_descriptors = usb_copy_descriptors(ecm_ss_function); | ||
769 | if (!f->ss_descriptors) | ||
770 | goto fail; | ||
698 | } | 771 | } |
699 | 772 | ||
700 | /* NOTE: all that is done without knowing or caring about | 773 | /* NOTE: all that is done without knowing or caring about |
@@ -706,6 +779,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
706 | ecm->port.close = ecm_close; | 779 | ecm->port.close = ecm_close; |
707 | 780 | ||
708 | DBG(cdev, "CDC Ethernet: %s speed IN/%s OUT/%s NOTIFY/%s\n", | 781 | DBG(cdev, "CDC Ethernet: %s speed IN/%s OUT/%s NOTIFY/%s\n", |
782 | gadget_is_superspeed(c->cdev->gadget) ? "super" : | ||
709 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | 783 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", |
710 | ecm->port.in_ep->name, ecm->port.out_ep->name, | 784 | ecm->port.in_ep->name, ecm->port.out_ep->name, |
711 | ecm->notify->name); | 785 | ecm->notify->name); |
@@ -714,6 +788,8 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
714 | fail: | 788 | fail: |
715 | if (f->descriptors) | 789 | if (f->descriptors) |
716 | usb_free_descriptors(f->descriptors); | 790 | usb_free_descriptors(f->descriptors); |
791 | if (f->hs_descriptors) | ||
792 | usb_free_descriptors(f->hs_descriptors); | ||
717 | 793 | ||
718 | if (ecm->notify_req) { | 794 | if (ecm->notify_req) { |
719 | kfree(ecm->notify_req->buf); | 795 | kfree(ecm->notify_req->buf); |
@@ -723,9 +799,9 @@ fail: | |||
723 | /* we might as well release our claims on endpoints */ | 799 | /* we might as well release our claims on endpoints */ |
724 | if (ecm->notify) | 800 | if (ecm->notify) |
725 | ecm->notify->driver_data = NULL; | 801 | ecm->notify->driver_data = NULL; |
726 | if (ecm->port.out) | 802 | if (ecm->port.out_ep->desc) |
727 | ecm->port.out_ep->driver_data = NULL; | 803 | ecm->port.out_ep->driver_data = NULL; |
728 | if (ecm->port.in) | 804 | if (ecm->port.in_ep->desc) |
729 | ecm->port.in_ep->driver_data = NULL; | 805 | ecm->port.in_ep->driver_data = NULL; |
730 | 806 | ||
731 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); | 807 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); |
@@ -740,6 +816,8 @@ ecm_unbind(struct usb_configuration *c, struct usb_function *f) | |||
740 | 816 | ||
741 | DBG(c->cdev, "ecm unbind\n"); | 817 | DBG(c->cdev, "ecm unbind\n"); |
742 | 818 | ||
819 | if (gadget_is_superspeed(c->cdev->gadget)) | ||
820 | usb_free_descriptors(f->ss_descriptors); | ||
743 | if (gadget_is_dualspeed(c->cdev->gadget)) | 821 | if (gadget_is_dualspeed(c->cdev->gadget)) |
744 | usb_free_descriptors(f->hs_descriptors); | 822 | usb_free_descriptors(f->hs_descriptors); |
745 | usb_free_descriptors(f->descriptors); | 823 | usb_free_descriptors(f->descriptors); |
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c index b3c304290150..046c6d0e6960 100644 --- a/drivers/usb/gadget/f_eem.c +++ b/drivers/usb/gadget/f_eem.c | |||
@@ -35,17 +35,9 @@ | |||
35 | * Ethernet link. | 35 | * Ethernet link. |
36 | */ | 36 | */ |
37 | 37 | ||
38 | struct eem_ep_descs { | ||
39 | struct usb_endpoint_descriptor *in; | ||
40 | struct usb_endpoint_descriptor *out; | ||
41 | }; | ||
42 | |||
43 | struct f_eem { | 38 | struct f_eem { |
44 | struct gether port; | 39 | struct gether port; |
45 | u8 ctrl_id; | 40 | u8 ctrl_id; |
46 | |||
47 | struct eem_ep_descs fs; | ||
48 | struct eem_ep_descs hs; | ||
49 | }; | 41 | }; |
50 | 42 | ||
51 | static inline struct f_eem *func_to_eem(struct usb_function *f) | 43 | static inline struct f_eem *func_to_eem(struct usb_function *f) |
@@ -123,6 +115,45 @@ static struct usb_descriptor_header *eem_hs_function[] __initdata = { | |||
123 | NULL, | 115 | NULL, |
124 | }; | 116 | }; |
125 | 117 | ||
118 | /* super speed support: */ | ||
119 | |||
120 | static struct usb_endpoint_descriptor eem_ss_in_desc __initdata = { | ||
121 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
122 | .bDescriptorType = USB_DT_ENDPOINT, | ||
123 | |||
124 | .bEndpointAddress = USB_DIR_IN, | ||
125 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
126 | .wMaxPacketSize = cpu_to_le16(1024), | ||
127 | }; | ||
128 | |||
129 | static struct usb_endpoint_descriptor eem_ss_out_desc __initdata = { | ||
130 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
131 | .bDescriptorType = USB_DT_ENDPOINT, | ||
132 | |||
133 | .bEndpointAddress = USB_DIR_OUT, | ||
134 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
135 | .wMaxPacketSize = cpu_to_le16(1024), | ||
136 | }; | ||
137 | |||
138 | static struct usb_ss_ep_comp_descriptor eem_ss_bulk_comp_desc __initdata = { | ||
139 | .bLength = sizeof eem_ss_bulk_comp_desc, | ||
140 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
141 | |||
142 | /* the following 2 values can be tweaked if necessary */ | ||
143 | /* .bMaxBurst = 0, */ | ||
144 | /* .bmAttributes = 0, */ | ||
145 | }; | ||
146 | |||
147 | static struct usb_descriptor_header *eem_ss_function[] __initdata = { | ||
148 | /* CDC EEM control descriptors */ | ||
149 | (struct usb_descriptor_header *) &eem_intf, | ||
150 | (struct usb_descriptor_header *) &eem_ss_in_desc, | ||
151 | (struct usb_descriptor_header *) &eem_ss_bulk_comp_desc, | ||
152 | (struct usb_descriptor_header *) &eem_ss_out_desc, | ||
153 | (struct usb_descriptor_header *) &eem_ss_bulk_comp_desc, | ||
154 | NULL, | ||
155 | }; | ||
156 | |||
126 | /* string descriptors: */ | 157 | /* string descriptors: */ |
127 | 158 | ||
128 | static struct usb_string eem_string_defs[] = { | 159 | static struct usb_string eem_string_defs[] = { |
@@ -176,12 +207,16 @@ static int eem_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
176 | gether_disconnect(&eem->port); | 207 | gether_disconnect(&eem->port); |
177 | } | 208 | } |
178 | 209 | ||
179 | if (!eem->port.in) { | 210 | if (!eem->port.in_ep->desc || !eem->port.out_ep->desc) { |
180 | DBG(cdev, "init eem\n"); | 211 | DBG(cdev, "init eem\n"); |
181 | eem->port.in = ep_choose(cdev->gadget, | 212 | if (config_ep_by_speed(cdev->gadget, f, |
182 | eem->hs.in, eem->fs.in); | 213 | eem->port.in_ep) || |
183 | eem->port.out = ep_choose(cdev->gadget, | 214 | config_ep_by_speed(cdev->gadget, f, |
184 | eem->hs.out, eem->fs.out); | 215 | eem->port.out_ep)) { |
216 | eem->port.in_ep->desc = NULL; | ||
217 | eem->port.out_ep->desc = NULL; | ||
218 | goto fail; | ||
219 | } | ||
185 | } | 220 | } |
186 | 221 | ||
187 | /* zlps should not occur because zero-length EEM packets | 222 | /* zlps should not occur because zero-length EEM packets |
@@ -253,11 +288,6 @@ eem_bind(struct usb_configuration *c, struct usb_function *f) | |||
253 | if (!f->descriptors) | 288 | if (!f->descriptors) |
254 | goto fail; | 289 | goto fail; |
255 | 290 | ||
256 | eem->fs.in = usb_find_endpoint(eem_fs_function, | ||
257 | f->descriptors, &eem_fs_in_desc); | ||
258 | eem->fs.out = usb_find_endpoint(eem_fs_function, | ||
259 | f->descriptors, &eem_fs_out_desc); | ||
260 | |||
261 | /* support all relevant hardware speeds... we expect that when | 291 | /* support all relevant hardware speeds... we expect that when |
262 | * hardware is dual speed, all bulk-capable endpoints work at | 292 | * hardware is dual speed, all bulk-capable endpoints work at |
263 | * both speeds | 293 | * both speeds |
@@ -272,14 +302,22 @@ eem_bind(struct usb_configuration *c, struct usb_function *f) | |||
272 | f->hs_descriptors = usb_copy_descriptors(eem_hs_function); | 302 | f->hs_descriptors = usb_copy_descriptors(eem_hs_function); |
273 | if (!f->hs_descriptors) | 303 | if (!f->hs_descriptors) |
274 | goto fail; | 304 | goto fail; |
305 | } | ||
306 | |||
307 | if (gadget_is_superspeed(c->cdev->gadget)) { | ||
308 | eem_ss_in_desc.bEndpointAddress = | ||
309 | eem_fs_in_desc.bEndpointAddress; | ||
310 | eem_ss_out_desc.bEndpointAddress = | ||
311 | eem_fs_out_desc.bEndpointAddress; | ||
275 | 312 | ||
276 | eem->hs.in = usb_find_endpoint(eem_hs_function, | 313 | /* copy descriptors, and track endpoint copies */ |
277 | f->hs_descriptors, &eem_hs_in_desc); | 314 | f->ss_descriptors = usb_copy_descriptors(eem_ss_function); |
278 | eem->hs.out = usb_find_endpoint(eem_hs_function, | 315 | if (!f->ss_descriptors) |
279 | f->hs_descriptors, &eem_hs_out_desc); | 316 | goto fail; |
280 | } | 317 | } |
281 | 318 | ||
282 | DBG(cdev, "CDC Ethernet (EEM): %s speed IN/%s OUT/%s\n", | 319 | DBG(cdev, "CDC Ethernet (EEM): %s speed IN/%s OUT/%s\n", |
320 | gadget_is_superspeed(c->cdev->gadget) ? "super" : | ||
283 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | 321 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", |
284 | eem->port.in_ep->name, eem->port.out_ep->name); | 322 | eem->port.in_ep->name, eem->port.out_ep->name); |
285 | return 0; | 323 | return 0; |
@@ -287,11 +325,13 @@ eem_bind(struct usb_configuration *c, struct usb_function *f) | |||
287 | fail: | 325 | fail: |
288 | if (f->descriptors) | 326 | if (f->descriptors) |
289 | usb_free_descriptors(f->descriptors); | 327 | usb_free_descriptors(f->descriptors); |
328 | if (f->hs_descriptors) | ||
329 | usb_free_descriptors(f->hs_descriptors); | ||
290 | 330 | ||
291 | /* we might as well release our claims on endpoints */ | 331 | /* we might as well release our claims on endpoints */ |
292 | if (eem->port.out) | 332 | if (eem->port.out_ep->desc) |
293 | eem->port.out_ep->driver_data = NULL; | 333 | eem->port.out_ep->driver_data = NULL; |
294 | if (eem->port.in) | 334 | if (eem->port.in_ep->desc) |
295 | eem->port.in_ep->driver_data = NULL; | 335 | eem->port.in_ep->driver_data = NULL; |
296 | 336 | ||
297 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); | 337 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); |
@@ -306,6 +346,8 @@ eem_unbind(struct usb_configuration *c, struct usb_function *f) | |||
306 | 346 | ||
307 | DBG(c->cdev, "eem unbind\n"); | 347 | DBG(c->cdev, "eem unbind\n"); |
308 | 348 | ||
349 | if (gadget_is_superspeed(c->cdev->gadget)) | ||
350 | usb_free_descriptors(f->ss_descriptors); | ||
309 | if (gadget_is_dualspeed(c->cdev->gadget)) | 351 | if (gadget_is_dualspeed(c->cdev->gadget)) |
310 | usb_free_descriptors(f->hs_descriptors); | 352 | usb_free_descriptors(f->hs_descriptors); |
311 | usb_free_descriptors(f->descriptors); | 353 | usb_free_descriptors(f->descriptors); |
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index 19fffccc370d..c161a9aaeb7e 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -1544,7 +1544,8 @@ static int ffs_func_eps_enable(struct ffs_function *func) | |||
1544 | ds = ep->descs[ep->descs[1] ? 1 : 0]; | 1544 | ds = ep->descs[ep->descs[1] ? 1 : 0]; |
1545 | 1545 | ||
1546 | ep->ep->driver_data = ep; | 1546 | ep->ep->driver_data = ep; |
1547 | ret = usb_ep_enable(ep->ep, ds); | 1547 | ep->ep->desc = ds; |
1548 | ret = usb_ep_enable(ep->ep); | ||
1548 | if (likely(!ret)) { | 1549 | if (likely(!ret)) { |
1549 | epfile->ep = ep; | 1550 | epfile->ep = ep; |
1550 | epfile->in = usb_endpoint_dir_in(ds); | 1551 | epfile->in = usb_endpoint_dir_in(ds); |
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c index 598e7e2ab80c..403a48bcf560 100644 --- a/drivers/usb/gadget/f_hid.c +++ b/drivers/usb/gadget/f_hid.c | |||
@@ -59,8 +59,6 @@ struct f_hidg { | |||
59 | struct cdev cdev; | 59 | struct cdev cdev; |
60 | struct usb_function func; | 60 | struct usb_function func; |
61 | struct usb_ep *in_ep; | 61 | struct usb_ep *in_ep; |
62 | struct usb_endpoint_descriptor *fs_in_ep_desc; | ||
63 | struct usb_endpoint_descriptor *hs_in_ep_desc; | ||
64 | }; | 62 | }; |
65 | 63 | ||
66 | static inline struct f_hidg *func_to_hidg(struct usb_function *f) | 64 | static inline struct f_hidg *func_to_hidg(struct usb_function *f) |
@@ -416,7 +414,6 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
416 | { | 414 | { |
417 | struct usb_composite_dev *cdev = f->config->cdev; | 415 | struct usb_composite_dev *cdev = f->config->cdev; |
418 | struct f_hidg *hidg = func_to_hidg(f); | 416 | struct f_hidg *hidg = func_to_hidg(f); |
419 | const struct usb_endpoint_descriptor *ep_desc; | ||
420 | int status = 0; | 417 | int status = 0; |
421 | 418 | ||
422 | VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt); | 419 | VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt); |
@@ -426,9 +423,13 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
426 | if (hidg->in_ep->driver_data != NULL) | 423 | if (hidg->in_ep->driver_data != NULL) |
427 | usb_ep_disable(hidg->in_ep); | 424 | usb_ep_disable(hidg->in_ep); |
428 | 425 | ||
429 | ep_desc = ep_choose(f->config->cdev->gadget, | 426 | status = config_ep_by_speed(f->config->cdev->gadget, f, |
430 | hidg->hs_in_ep_desc, hidg->fs_in_ep_desc); | 427 | hidg->in_ep); |
431 | status = usb_ep_enable(hidg->in_ep, ep_desc); | 428 | if (status) { |
429 | ERROR(cdev, "config_ep_by_speed FAILED!\n"); | ||
430 | goto fail; | ||
431 | } | ||
432 | status = usb_ep_enable(hidg->in_ep); | ||
432 | if (status < 0) { | 433 | if (status < 0) { |
433 | ERROR(cdev, "Enable endpoint FAILED!\n"); | 434 | ERROR(cdev, "Enable endpoint FAILED!\n"); |
434 | goto fail; | 435 | goto fail; |
@@ -498,21 +499,12 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f) | |||
498 | if (!f->descriptors) | 499 | if (!f->descriptors) |
499 | goto fail; | 500 | goto fail; |
500 | 501 | ||
501 | hidg->fs_in_ep_desc = usb_find_endpoint(hidg_fs_descriptors, | ||
502 | f->descriptors, | ||
503 | &hidg_fs_in_ep_desc); | ||
504 | |||
505 | if (gadget_is_dualspeed(c->cdev->gadget)) { | 502 | if (gadget_is_dualspeed(c->cdev->gadget)) { |
506 | hidg_hs_in_ep_desc.bEndpointAddress = | 503 | hidg_hs_in_ep_desc.bEndpointAddress = |
507 | hidg_fs_in_ep_desc.bEndpointAddress; | 504 | hidg_fs_in_ep_desc.bEndpointAddress; |
508 | f->hs_descriptors = usb_copy_descriptors(hidg_hs_descriptors); | 505 | f->hs_descriptors = usb_copy_descriptors(hidg_hs_descriptors); |
509 | if (!f->hs_descriptors) | 506 | if (!f->hs_descriptors) |
510 | goto fail; | 507 | goto fail; |
511 | hidg->hs_in_ep_desc = usb_find_endpoint(hidg_hs_descriptors, | ||
512 | f->hs_descriptors, | ||
513 | &hidg_hs_in_ep_desc); | ||
514 | } else { | ||
515 | hidg->hs_in_ep_desc = NULL; | ||
516 | } | 508 | } |
517 | 509 | ||
518 | mutex_init(&hidg->lock); | 510 | mutex_init(&hidg->lock); |
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index b37960f9e753..ca660d40b11a 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c | |||
@@ -118,6 +118,49 @@ static struct usb_descriptor_header *hs_loopback_descs[] = { | |||
118 | NULL, | 118 | NULL, |
119 | }; | 119 | }; |
120 | 120 | ||
121 | /* super speed support: */ | ||
122 | |||
123 | static struct usb_endpoint_descriptor ss_loop_source_desc = { | ||
124 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
125 | .bDescriptorType = USB_DT_ENDPOINT, | ||
126 | |||
127 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
128 | .wMaxPacketSize = cpu_to_le16(1024), | ||
129 | }; | ||
130 | |||
131 | struct usb_ss_ep_comp_descriptor ss_loop_source_comp_desc = { | ||
132 | .bLength = USB_DT_SS_EP_COMP_SIZE, | ||
133 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
134 | .bMaxBurst = 0, | ||
135 | .bmAttributes = 0, | ||
136 | .wBytesPerInterval = 0, | ||
137 | }; | ||
138 | |||
139 | static struct usb_endpoint_descriptor ss_loop_sink_desc = { | ||
140 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
141 | .bDescriptorType = USB_DT_ENDPOINT, | ||
142 | |||
143 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
144 | .wMaxPacketSize = cpu_to_le16(1024), | ||
145 | }; | ||
146 | |||
147 | struct usb_ss_ep_comp_descriptor ss_loop_sink_comp_desc = { | ||
148 | .bLength = USB_DT_SS_EP_COMP_SIZE, | ||
149 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
150 | .bMaxBurst = 0, | ||
151 | .bmAttributes = 0, | ||
152 | .wBytesPerInterval = 0, | ||
153 | }; | ||
154 | |||
155 | static struct usb_descriptor_header *ss_loopback_descs[] = { | ||
156 | (struct usb_descriptor_header *) &loopback_intf, | ||
157 | (struct usb_descriptor_header *) &ss_loop_source_desc, | ||
158 | (struct usb_descriptor_header *) &ss_loop_source_comp_desc, | ||
159 | (struct usb_descriptor_header *) &ss_loop_sink_desc, | ||
160 | (struct usb_descriptor_header *) &ss_loop_sink_comp_desc, | ||
161 | NULL, | ||
162 | }; | ||
163 | |||
121 | /* function-specific strings: */ | 164 | /* function-specific strings: */ |
122 | 165 | ||
123 | static struct usb_string strings_loopback[] = { | 166 | static struct usb_string strings_loopback[] = { |
@@ -175,8 +218,18 @@ autoconf_fail: | |||
175 | f->hs_descriptors = hs_loopback_descs; | 218 | f->hs_descriptors = hs_loopback_descs; |
176 | } | 219 | } |
177 | 220 | ||
221 | /* support super speed hardware */ | ||
222 | if (gadget_is_superspeed(c->cdev->gadget)) { | ||
223 | ss_loop_source_desc.bEndpointAddress = | ||
224 | fs_loop_source_desc.bEndpointAddress; | ||
225 | ss_loop_sink_desc.bEndpointAddress = | ||
226 | fs_loop_sink_desc.bEndpointAddress; | ||
227 | f->ss_descriptors = ss_loopback_descs; | ||
228 | } | ||
229 | |||
178 | DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n", | 230 | DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n", |
179 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | 231 | (gadget_is_superspeed(c->cdev->gadget) ? "super" : |
232 | (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")), | ||
180 | f->name, loop->in_ep->name, loop->out_ep->name); | 233 | f->name, loop->in_ep->name, loop->out_ep->name); |
181 | return 0; | 234 | return 0; |
182 | } | 235 | } |
@@ -250,26 +303,27 @@ static int | |||
250 | enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop) | 303 | enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop) |
251 | { | 304 | { |
252 | int result = 0; | 305 | int result = 0; |
253 | const struct usb_endpoint_descriptor *src, *sink; | ||
254 | struct usb_ep *ep; | 306 | struct usb_ep *ep; |
255 | struct usb_request *req; | 307 | struct usb_request *req; |
256 | unsigned i; | 308 | unsigned i; |
257 | 309 | ||
258 | src = ep_choose(cdev->gadget, | ||
259 | &hs_loop_source_desc, &fs_loop_source_desc); | ||
260 | sink = ep_choose(cdev->gadget, | ||
261 | &hs_loop_sink_desc, &fs_loop_sink_desc); | ||
262 | |||
263 | /* one endpoint writes data back IN to the host */ | 310 | /* one endpoint writes data back IN to the host */ |
264 | ep = loop->in_ep; | 311 | ep = loop->in_ep; |
265 | result = usb_ep_enable(ep, src); | 312 | result = config_ep_by_speed(cdev->gadget, &(loop->function), ep); |
313 | if (result) | ||
314 | return result; | ||
315 | result = usb_ep_enable(ep); | ||
266 | if (result < 0) | 316 | if (result < 0) |
267 | return result; | 317 | return result; |
268 | ep->driver_data = loop; | 318 | ep->driver_data = loop; |
269 | 319 | ||
270 | /* one endpoint just reads OUT packets */ | 320 | /* one endpoint just reads OUT packets */ |
271 | ep = loop->out_ep; | 321 | ep = loop->out_ep; |
272 | result = usb_ep_enable(ep, sink); | 322 | result = config_ep_by_speed(cdev->gadget, &(loop->function), ep); |
323 | if (result) | ||
324 | goto fail0; | ||
325 | |||
326 | result = usb_ep_enable(ep); | ||
273 | if (result < 0) { | 327 | if (result < 0) { |
274 | fail0: | 328 | fail0: |
275 | ep = loop->in_ep; | 329 | ep = loop->in_ep; |
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index efb58f9f5aa9..5b9339582007 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c | |||
@@ -2324,18 +2324,6 @@ static int get_next_command(struct fsg_common *common) | |||
2324 | 2324 | ||
2325 | /*-------------------------------------------------------------------------*/ | 2325 | /*-------------------------------------------------------------------------*/ |
2326 | 2326 | ||
2327 | static int enable_endpoint(struct fsg_common *common, struct usb_ep *ep, | ||
2328 | const struct usb_endpoint_descriptor *d) | ||
2329 | { | ||
2330 | int rc; | ||
2331 | |||
2332 | ep->driver_data = common; | ||
2333 | rc = usb_ep_enable(ep, d); | ||
2334 | if (rc) | ||
2335 | ERROR(common, "can't enable %s, result %d\n", ep->name, rc); | ||
2336 | return rc; | ||
2337 | } | ||
2338 | |||
2339 | static int alloc_request(struct fsg_common *common, struct usb_ep *ep, | 2327 | static int alloc_request(struct fsg_common *common, struct usb_ep *ep, |
2340 | struct usb_request **preq) | 2328 | struct usb_request **preq) |
2341 | { | 2329 | { |
@@ -2349,7 +2337,6 @@ static int alloc_request(struct fsg_common *common, struct usb_ep *ep, | |||
2349 | /* Reset interface setting and re-init endpoint state (toggle etc). */ | 2337 | /* Reset interface setting and re-init endpoint state (toggle etc). */ |
2350 | static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg) | 2338 | static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg) |
2351 | { | 2339 | { |
2352 | const struct usb_endpoint_descriptor *d; | ||
2353 | struct fsg_dev *fsg; | 2340 | struct fsg_dev *fsg; |
2354 | int i, rc = 0; | 2341 | int i, rc = 0; |
2355 | 2342 | ||
@@ -2396,20 +2383,26 @@ reset: | |||
2396 | fsg = common->fsg; | 2383 | fsg = common->fsg; |
2397 | 2384 | ||
2398 | /* Enable the endpoints */ | 2385 | /* Enable the endpoints */ |
2399 | d = fsg_ep_desc(common->gadget, | 2386 | rc = config_ep_by_speed(common->gadget, &(fsg->function), fsg->bulk_in); |
2400 | &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc); | 2387 | if (rc) |
2401 | rc = enable_endpoint(common, fsg->bulk_in, d); | 2388 | goto reset; |
2389 | rc = usb_ep_enable(fsg->bulk_in); | ||
2402 | if (rc) | 2390 | if (rc) |
2403 | goto reset; | 2391 | goto reset; |
2392 | fsg->bulk_in->driver_data = common; | ||
2404 | fsg->bulk_in_enabled = 1; | 2393 | fsg->bulk_in_enabled = 1; |
2405 | 2394 | ||
2406 | d = fsg_ep_desc(common->gadget, | 2395 | rc = config_ep_by_speed(common->gadget, &(fsg->function), |
2407 | &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc); | 2396 | fsg->bulk_out); |
2408 | rc = enable_endpoint(common, fsg->bulk_out, d); | 2397 | if (rc) |
2398 | goto reset; | ||
2399 | rc = usb_ep_enable(fsg->bulk_out); | ||
2409 | if (rc) | 2400 | if (rc) |
2410 | goto reset; | 2401 | goto reset; |
2402 | fsg->bulk_out->driver_data = common; | ||
2411 | fsg->bulk_out_enabled = 1; | 2403 | fsg->bulk_out_enabled = 1; |
2412 | common->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize); | 2404 | common->bulk_out_maxpacket = |
2405 | le16_to_cpu(fsg->bulk_out->desc->wMaxPacketSize); | ||
2413 | clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); | 2406 | clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); |
2414 | 2407 | ||
2415 | /* Allocate the requests */ | 2408 | /* Allocate the requests */ |
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c index 86902a60bcdb..ae69ed7e6b99 100644 --- a/drivers/usb/gadget/f_ncm.c +++ b/drivers/usb/gadget/f_ncm.c | |||
@@ -48,12 +48,6 @@ | |||
48 | #define NCM_NDP_HDR_CRC 0x01000000 | 48 | #define NCM_NDP_HDR_CRC 0x01000000 |
49 | #define NCM_NDP_HDR_NOCRC 0x00000000 | 49 | #define NCM_NDP_HDR_NOCRC 0x00000000 |
50 | 50 | ||
51 | struct ncm_ep_descs { | ||
52 | struct usb_endpoint_descriptor *in; | ||
53 | struct usb_endpoint_descriptor *out; | ||
54 | struct usb_endpoint_descriptor *notify; | ||
55 | }; | ||
56 | |||
57 | enum ncm_notify_state { | 51 | enum ncm_notify_state { |
58 | NCM_NOTIFY_NONE, /* don't notify */ | 52 | NCM_NOTIFY_NONE, /* don't notify */ |
59 | NCM_NOTIFY_CONNECT, /* issue CONNECT next */ | 53 | NCM_NOTIFY_CONNECT, /* issue CONNECT next */ |
@@ -66,11 +60,7 @@ struct f_ncm { | |||
66 | 60 | ||
67 | char ethaddr[14]; | 61 | char ethaddr[14]; |
68 | 62 | ||
69 | struct ncm_ep_descs fs; | ||
70 | struct ncm_ep_descs hs; | ||
71 | |||
72 | struct usb_ep *notify; | 63 | struct usb_ep *notify; |
73 | struct usb_endpoint_descriptor *notify_desc; | ||
74 | struct usb_request *notify_req; | 64 | struct usb_request *notify_req; |
75 | u8 notify_state; | 65 | u8 notify_state; |
76 | bool is_open; | 66 | bool is_open; |
@@ -802,13 +792,14 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
802 | if (ncm->notify->driver_data) { | 792 | if (ncm->notify->driver_data) { |
803 | DBG(cdev, "reset ncm control %d\n", intf); | 793 | DBG(cdev, "reset ncm control %d\n", intf); |
804 | usb_ep_disable(ncm->notify); | 794 | usb_ep_disable(ncm->notify); |
805 | } else { | 795 | } |
796 | |||
797 | if (!(ncm->notify->desc)) { | ||
806 | DBG(cdev, "init ncm ctrl %d\n", intf); | 798 | DBG(cdev, "init ncm ctrl %d\n", intf); |
807 | ncm->notify_desc = ep_choose(cdev->gadget, | 799 | if (config_ep_by_speed(cdev->gadget, f, ncm->notify)) |
808 | ncm->hs.notify, | 800 | goto fail; |
809 | ncm->fs.notify); | ||
810 | } | 801 | } |
811 | usb_ep_enable(ncm->notify, ncm->notify_desc); | 802 | usb_ep_enable(ncm->notify); |
812 | ncm->notify->driver_data = ncm; | 803 | ncm->notify->driver_data = ncm; |
813 | 804 | ||
814 | /* Data interface has two altsettings, 0 and 1 */ | 805 | /* Data interface has two altsettings, 0 and 1 */ |
@@ -829,14 +820,17 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
829 | if (alt == 1) { | 820 | if (alt == 1) { |
830 | struct net_device *net; | 821 | struct net_device *net; |
831 | 822 | ||
832 | if (!ncm->port.in) { | 823 | if (!ncm->port.in_ep->desc || |
824 | !ncm->port.out_ep->desc) { | ||
833 | DBG(cdev, "init ncm\n"); | 825 | DBG(cdev, "init ncm\n"); |
834 | ncm->port.in = ep_choose(cdev->gadget, | 826 | if (config_ep_by_speed(cdev->gadget, f, |
835 | ncm->hs.in, | 827 | ncm->port.in_ep) || |
836 | ncm->fs.in); | 828 | config_ep_by_speed(cdev->gadget, f, |
837 | ncm->port.out = ep_choose(cdev->gadget, | 829 | ncm->port.out_ep)) { |
838 | ncm->hs.out, | 830 | ncm->port.in_ep->desc = NULL; |
839 | ncm->fs.out); | 831 | ncm->port.out_ep->desc = NULL; |
832 | goto fail; | ||
833 | } | ||
840 | } | 834 | } |
841 | 835 | ||
842 | /* TODO */ | 836 | /* TODO */ |
@@ -1111,7 +1105,7 @@ static void ncm_disable(struct usb_function *f) | |||
1111 | if (ncm->notify->driver_data) { | 1105 | if (ncm->notify->driver_data) { |
1112 | usb_ep_disable(ncm->notify); | 1106 | usb_ep_disable(ncm->notify); |
1113 | ncm->notify->driver_data = NULL; | 1107 | ncm->notify->driver_data = NULL; |
1114 | ncm->notify_desc = NULL; | 1108 | ncm->notify->desc = NULL; |
1115 | } | 1109 | } |
1116 | } | 1110 | } |
1117 | 1111 | ||
@@ -1228,13 +1222,6 @@ ncm_bind(struct usb_configuration *c, struct usb_function *f) | |||
1228 | if (!f->descriptors) | 1222 | if (!f->descriptors) |
1229 | goto fail; | 1223 | goto fail; |
1230 | 1224 | ||
1231 | ncm->fs.in = usb_find_endpoint(ncm_fs_function, | ||
1232 | f->descriptors, &fs_ncm_in_desc); | ||
1233 | ncm->fs.out = usb_find_endpoint(ncm_fs_function, | ||
1234 | f->descriptors, &fs_ncm_out_desc); | ||
1235 | ncm->fs.notify = usb_find_endpoint(ncm_fs_function, | ||
1236 | f->descriptors, &fs_ncm_notify_desc); | ||
1237 | |||
1238 | /* | 1225 | /* |
1239 | * support all relevant hardware speeds... we expect that when | 1226 | * support all relevant hardware speeds... we expect that when |
1240 | * hardware is dual speed, all bulk-capable endpoints work at | 1227 | * hardware is dual speed, all bulk-capable endpoints work at |
@@ -1252,13 +1239,6 @@ ncm_bind(struct usb_configuration *c, struct usb_function *f) | |||
1252 | f->hs_descriptors = usb_copy_descriptors(ncm_hs_function); | 1239 | f->hs_descriptors = usb_copy_descriptors(ncm_hs_function); |
1253 | if (!f->hs_descriptors) | 1240 | if (!f->hs_descriptors) |
1254 | goto fail; | 1241 | goto fail; |
1255 | |||
1256 | ncm->hs.in = usb_find_endpoint(ncm_hs_function, | ||
1257 | f->hs_descriptors, &hs_ncm_in_desc); | ||
1258 | ncm->hs.out = usb_find_endpoint(ncm_hs_function, | ||
1259 | f->hs_descriptors, &hs_ncm_out_desc); | ||
1260 | ncm->hs.notify = usb_find_endpoint(ncm_hs_function, | ||
1261 | f->hs_descriptors, &hs_ncm_notify_desc); | ||
1262 | } | 1242 | } |
1263 | 1243 | ||
1264 | /* | 1244 | /* |
@@ -1288,9 +1268,9 @@ fail: | |||
1288 | /* we might as well release our claims on endpoints */ | 1268 | /* we might as well release our claims on endpoints */ |
1289 | if (ncm->notify) | 1269 | if (ncm->notify) |
1290 | ncm->notify->driver_data = NULL; | 1270 | ncm->notify->driver_data = NULL; |
1291 | if (ncm->port.out) | 1271 | if (ncm->port.out_ep->desc) |
1292 | ncm->port.out_ep->driver_data = NULL; | 1272 | ncm->port.out_ep->driver_data = NULL; |
1293 | if (ncm->port.in) | 1273 | if (ncm->port.in_ep->desc) |
1294 | ncm->port.in_ep->driver_data = NULL; | 1274 | ncm->port.in_ep->driver_data = NULL; |
1295 | 1275 | ||
1296 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); | 1276 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); |
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c index 8f8c64371475..394502abeb96 100644 --- a/drivers/usb/gadget/f_obex.c +++ b/drivers/usb/gadget/f_obex.c | |||
@@ -39,20 +39,12 @@ | |||
39 | * ready to handle the commands. | 39 | * ready to handle the commands. |
40 | */ | 40 | */ |
41 | 41 | ||
42 | struct obex_ep_descs { | ||
43 | struct usb_endpoint_descriptor *obex_in; | ||
44 | struct usb_endpoint_descriptor *obex_out; | ||
45 | }; | ||
46 | |||
47 | struct f_obex { | 42 | struct f_obex { |
48 | struct gserial port; | 43 | struct gserial port; |
49 | u8 ctrl_id; | 44 | u8 ctrl_id; |
50 | u8 data_id; | 45 | u8 data_id; |
51 | u8 port_num; | 46 | u8 port_num; |
52 | u8 can_activate; | 47 | u8 can_activate; |
53 | |||
54 | struct obex_ep_descs fs; | ||
55 | struct obex_ep_descs hs; | ||
56 | }; | 48 | }; |
57 | 49 | ||
58 | static inline struct f_obex *func_to_obex(struct usb_function *f) | 50 | static inline struct f_obex *func_to_obex(struct usb_function *f) |
@@ -227,12 +219,16 @@ static int obex_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
227 | gserial_disconnect(&obex->port); | 219 | gserial_disconnect(&obex->port); |
228 | } | 220 | } |
229 | 221 | ||
230 | if (!obex->port.in_desc) { | 222 | if (!obex->port.in->desc || !obex->port.out->desc) { |
231 | DBG(cdev, "init obex ttyGS%d\n", obex->port_num); | 223 | DBG(cdev, "init obex ttyGS%d\n", obex->port_num); |
232 | obex->port.in_desc = ep_choose(cdev->gadget, | 224 | if (config_ep_by_speed(cdev->gadget, f, |
233 | obex->hs.obex_in, obex->fs.obex_in); | 225 | obex->port.in) || |
234 | obex->port.out_desc = ep_choose(cdev->gadget, | 226 | config_ep_by_speed(cdev->gadget, f, |
235 | obex->hs.obex_out, obex->fs.obex_out); | 227 | obex->port.out)) { |
228 | obex->port.out->desc = NULL; | ||
229 | obex->port.in->desc = NULL; | ||
230 | goto fail; | ||
231 | } | ||
236 | } | 232 | } |
237 | 233 | ||
238 | if (alt == 1) { | 234 | if (alt == 1) { |
@@ -346,11 +342,6 @@ obex_bind(struct usb_configuration *c, struct usb_function *f) | |||
346 | /* copy descriptors, and track endpoint copies */ | 342 | /* copy descriptors, and track endpoint copies */ |
347 | f->descriptors = usb_copy_descriptors(fs_function); | 343 | f->descriptors = usb_copy_descriptors(fs_function); |
348 | 344 | ||
349 | obex->fs.obex_in = usb_find_endpoint(fs_function, | ||
350 | f->descriptors, &obex_fs_ep_in_desc); | ||
351 | obex->fs.obex_out = usb_find_endpoint(fs_function, | ||
352 | f->descriptors, &obex_fs_ep_out_desc); | ||
353 | |||
354 | /* support all relevant hardware speeds... we expect that when | 345 | /* support all relevant hardware speeds... we expect that when |
355 | * hardware is dual speed, all bulk-capable endpoints work at | 346 | * hardware is dual speed, all bulk-capable endpoints work at |
356 | * both speeds | 347 | * both speeds |
@@ -364,11 +355,6 @@ obex_bind(struct usb_configuration *c, struct usb_function *f) | |||
364 | 355 | ||
365 | /* copy descriptors, and track endpoint copies */ | 356 | /* copy descriptors, and track endpoint copies */ |
366 | f->hs_descriptors = usb_copy_descriptors(hs_function); | 357 | f->hs_descriptors = usb_copy_descriptors(hs_function); |
367 | |||
368 | obex->hs.obex_in = usb_find_endpoint(hs_function, | ||
369 | f->hs_descriptors, &obex_hs_ep_in_desc); | ||
370 | obex->hs.obex_out = usb_find_endpoint(hs_function, | ||
371 | f->hs_descriptors, &obex_hs_ep_out_desc); | ||
372 | } | 358 | } |
373 | 359 | ||
374 | /* Avoid letting this gadget enumerate until the userspace | 360 | /* Avoid letting this gadget enumerate until the userspace |
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c index f22fc685ddfd..8f8d3f6cd89e 100644 --- a/drivers/usb/gadget/f_phonet.c +++ b/drivers/usb/gadget/f_phonet.c | |||
@@ -428,17 +428,16 @@ static int pn_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
428 | spin_lock(&port->lock); | 428 | spin_lock(&port->lock); |
429 | __pn_reset(f); | 429 | __pn_reset(f); |
430 | if (alt == 1) { | 430 | if (alt == 1) { |
431 | struct usb_endpoint_descriptor *out, *in; | ||
432 | int i; | 431 | int i; |
433 | 432 | ||
434 | out = ep_choose(gadget, | 433 | if (config_ep_by_speed(gadget, f, fp->in_ep) || |
435 | &pn_hs_sink_desc, | 434 | config_ep_by_speed(gadget, f, fp->out_ep)) { |
436 | &pn_fs_sink_desc); | 435 | fp->in_ep->desc = NULL; |
437 | in = ep_choose(gadget, | 436 | fp->out_ep->desc = NULL; |
438 | &pn_hs_source_desc, | 437 | return -EINVAL; |
439 | &pn_fs_source_desc); | 438 | } |
440 | usb_ep_enable(fp->out_ep, out); | 439 | usb_ep_enable(fp->out_ep); |
441 | usb_ep_enable(fp->in_ep, in); | 440 | usb_ep_enable(fp->in_ep); |
442 | 441 | ||
443 | port->usb = fp; | 442 | port->usb = fp; |
444 | fp->out_ep->driver_data = fp; | 443 | fp->out_ep->driver_data = fp; |
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c index fa12ec8364ef..8f3eae90919f 100644 --- a/drivers/usb/gadget/f_rndis.c +++ b/drivers/usb/gadget/f_rndis.c | |||
@@ -76,23 +76,13 @@ | |||
76 | * - MS-Windows drivers sometimes emit undocumented requests. | 76 | * - MS-Windows drivers sometimes emit undocumented requests. |
77 | */ | 77 | */ |
78 | 78 | ||
79 | struct rndis_ep_descs { | ||
80 | struct usb_endpoint_descriptor *in; | ||
81 | struct usb_endpoint_descriptor *out; | ||
82 | struct usb_endpoint_descriptor *notify; | ||
83 | }; | ||
84 | |||
85 | struct f_rndis { | 79 | struct f_rndis { |
86 | struct gether port; | 80 | struct gether port; |
87 | u8 ctrl_id, data_id; | 81 | u8 ctrl_id, data_id; |
88 | u8 ethaddr[ETH_ALEN]; | 82 | u8 ethaddr[ETH_ALEN]; |
89 | int config; | 83 | int config; |
90 | 84 | ||
91 | struct rndis_ep_descs fs; | ||
92 | struct rndis_ep_descs hs; | ||
93 | |||
94 | struct usb_ep *notify; | 85 | struct usb_ep *notify; |
95 | struct usb_endpoint_descriptor *notify_desc; | ||
96 | struct usb_request *notify_req; | 86 | struct usb_request *notify_req; |
97 | atomic_t notify_count; | 87 | atomic_t notify_count; |
98 | }; | 88 | }; |
@@ -105,10 +95,12 @@ static inline struct f_rndis *func_to_rndis(struct usb_function *f) | |||
105 | /* peak (theoretical) bulk transfer rate in bits-per-second */ | 95 | /* peak (theoretical) bulk transfer rate in bits-per-second */ |
106 | static unsigned int bitrate(struct usb_gadget *g) | 96 | static unsigned int bitrate(struct usb_gadget *g) |
107 | { | 97 | { |
108 | if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) | 98 | if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) |
99 | return 13 * 1024 * 8 * 1000 * 8; | ||
100 | else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) | ||
109 | return 13 * 512 * 8 * 1000 * 8; | 101 | return 13 * 512 * 8 * 1000 * 8; |
110 | else | 102 | else |
111 | return 19 * 64 * 1 * 1000 * 8; | 103 | return 19 * 64 * 1 * 1000 * 8; |
112 | } | 104 | } |
113 | 105 | ||
114 | /*-------------------------------------------------------------------------*/ | 106 | /*-------------------------------------------------------------------------*/ |
@@ -226,6 +218,7 @@ static struct usb_endpoint_descriptor fs_out_desc = { | |||
226 | 218 | ||
227 | static struct usb_descriptor_header *eth_fs_function[] = { | 219 | static struct usb_descriptor_header *eth_fs_function[] = { |
228 | (struct usb_descriptor_header *) &rndis_iad_descriptor, | 220 | (struct usb_descriptor_header *) &rndis_iad_descriptor, |
221 | |||
229 | /* control interface matches ACM, not Ethernet */ | 222 | /* control interface matches ACM, not Ethernet */ |
230 | (struct usb_descriptor_header *) &rndis_control_intf, | 223 | (struct usb_descriptor_header *) &rndis_control_intf, |
231 | (struct usb_descriptor_header *) &header_desc, | 224 | (struct usb_descriptor_header *) &header_desc, |
@@ -233,6 +226,7 @@ static struct usb_descriptor_header *eth_fs_function[] = { | |||
233 | (struct usb_descriptor_header *) &rndis_acm_descriptor, | 226 | (struct usb_descriptor_header *) &rndis_acm_descriptor, |
234 | (struct usb_descriptor_header *) &rndis_union_desc, | 227 | (struct usb_descriptor_header *) &rndis_union_desc, |
235 | (struct usb_descriptor_header *) &fs_notify_desc, | 228 | (struct usb_descriptor_header *) &fs_notify_desc, |
229 | |||
236 | /* data interface has no altsetting */ | 230 | /* data interface has no altsetting */ |
237 | (struct usb_descriptor_header *) &rndis_data_intf, | 231 | (struct usb_descriptor_header *) &rndis_data_intf, |
238 | (struct usb_descriptor_header *) &fs_in_desc, | 232 | (struct usb_descriptor_header *) &fs_in_desc, |
@@ -251,6 +245,7 @@ static struct usb_endpoint_descriptor hs_notify_desc = { | |||
251 | .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), | 245 | .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), |
252 | .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, | 246 | .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, |
253 | }; | 247 | }; |
248 | |||
254 | static struct usb_endpoint_descriptor hs_in_desc = { | 249 | static struct usb_endpoint_descriptor hs_in_desc = { |
255 | .bLength = USB_DT_ENDPOINT_SIZE, | 250 | .bLength = USB_DT_ENDPOINT_SIZE, |
256 | .bDescriptorType = USB_DT_ENDPOINT, | 251 | .bDescriptorType = USB_DT_ENDPOINT, |
@@ -271,6 +266,7 @@ static struct usb_endpoint_descriptor hs_out_desc = { | |||
271 | 266 | ||
272 | static struct usb_descriptor_header *eth_hs_function[] = { | 267 | static struct usb_descriptor_header *eth_hs_function[] = { |
273 | (struct usb_descriptor_header *) &rndis_iad_descriptor, | 268 | (struct usb_descriptor_header *) &rndis_iad_descriptor, |
269 | |||
274 | /* control interface matches ACM, not Ethernet */ | 270 | /* control interface matches ACM, not Ethernet */ |
275 | (struct usb_descriptor_header *) &rndis_control_intf, | 271 | (struct usb_descriptor_header *) &rndis_control_intf, |
276 | (struct usb_descriptor_header *) &header_desc, | 272 | (struct usb_descriptor_header *) &header_desc, |
@@ -278,6 +274,7 @@ static struct usb_descriptor_header *eth_hs_function[] = { | |||
278 | (struct usb_descriptor_header *) &rndis_acm_descriptor, | 274 | (struct usb_descriptor_header *) &rndis_acm_descriptor, |
279 | (struct usb_descriptor_header *) &rndis_union_desc, | 275 | (struct usb_descriptor_header *) &rndis_union_desc, |
280 | (struct usb_descriptor_header *) &hs_notify_desc, | 276 | (struct usb_descriptor_header *) &hs_notify_desc, |
277 | |||
281 | /* data interface has no altsetting */ | 278 | /* data interface has no altsetting */ |
282 | (struct usb_descriptor_header *) &rndis_data_intf, | 279 | (struct usb_descriptor_header *) &rndis_data_intf, |
283 | (struct usb_descriptor_header *) &hs_in_desc, | 280 | (struct usb_descriptor_header *) &hs_in_desc, |
@@ -285,6 +282,76 @@ static struct usb_descriptor_header *eth_hs_function[] = { | |||
285 | NULL, | 282 | NULL, |
286 | }; | 283 | }; |
287 | 284 | ||
285 | /* super speed support: */ | ||
286 | |||
287 | static struct usb_endpoint_descriptor ss_notify_desc = { | ||
288 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
289 | .bDescriptorType = USB_DT_ENDPOINT, | ||
290 | |||
291 | .bEndpointAddress = USB_DIR_IN, | ||
292 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
293 | .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), | ||
294 | .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, | ||
295 | }; | ||
296 | |||
297 | static struct usb_ss_ep_comp_descriptor ss_intr_comp_desc = { | ||
298 | .bLength = sizeof ss_intr_comp_desc, | ||
299 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
300 | |||
301 | /* the following 3 values can be tweaked if necessary */ | ||
302 | /* .bMaxBurst = 0, */ | ||
303 | /* .bmAttributes = 0, */ | ||
304 | .wBytesPerInterval = cpu_to_le16(STATUS_BYTECOUNT), | ||
305 | }; | ||
306 | |||
307 | static struct usb_endpoint_descriptor ss_in_desc = { | ||
308 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
309 | .bDescriptorType = USB_DT_ENDPOINT, | ||
310 | |||
311 | .bEndpointAddress = USB_DIR_IN, | ||
312 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
313 | .wMaxPacketSize = cpu_to_le16(1024), | ||
314 | }; | ||
315 | |||
316 | static struct usb_endpoint_descriptor ss_out_desc = { | ||
317 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
318 | .bDescriptorType = USB_DT_ENDPOINT, | ||
319 | |||
320 | .bEndpointAddress = USB_DIR_OUT, | ||
321 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
322 | .wMaxPacketSize = cpu_to_le16(1024), | ||
323 | }; | ||
324 | |||
325 | static struct usb_ss_ep_comp_descriptor ss_bulk_comp_desc = { | ||
326 | .bLength = sizeof ss_bulk_comp_desc, | ||
327 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
328 | |||
329 | /* the following 2 values can be tweaked if necessary */ | ||
330 | /* .bMaxBurst = 0, */ | ||
331 | /* .bmAttributes = 0, */ | ||
332 | }; | ||
333 | |||
334 | static struct usb_descriptor_header *eth_ss_function[] = { | ||
335 | (struct usb_descriptor_header *) &rndis_iad_descriptor, | ||
336 | |||
337 | /* control interface matches ACM, not Ethernet */ | ||
338 | (struct usb_descriptor_header *) &rndis_control_intf, | ||
339 | (struct usb_descriptor_header *) &header_desc, | ||
340 | (struct usb_descriptor_header *) &call_mgmt_descriptor, | ||
341 | (struct usb_descriptor_header *) &rndis_acm_descriptor, | ||
342 | (struct usb_descriptor_header *) &rndis_union_desc, | ||
343 | (struct usb_descriptor_header *) &ss_notify_desc, | ||
344 | (struct usb_descriptor_header *) &ss_intr_comp_desc, | ||
345 | |||
346 | /* data interface has no altsetting */ | ||
347 | (struct usb_descriptor_header *) &rndis_data_intf, | ||
348 | (struct usb_descriptor_header *) &ss_in_desc, | ||
349 | (struct usb_descriptor_header *) &ss_bulk_comp_desc, | ||
350 | (struct usb_descriptor_header *) &ss_out_desc, | ||
351 | (struct usb_descriptor_header *) &ss_bulk_comp_desc, | ||
352 | NULL, | ||
353 | }; | ||
354 | |||
288 | /* string descriptors: */ | 355 | /* string descriptors: */ |
289 | 356 | ||
290 | static struct usb_string rndis_string_defs[] = { | 357 | static struct usb_string rndis_string_defs[] = { |
@@ -484,13 +551,13 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
484 | if (rndis->notify->driver_data) { | 551 | if (rndis->notify->driver_data) { |
485 | VDBG(cdev, "reset rndis control %d\n", intf); | 552 | VDBG(cdev, "reset rndis control %d\n", intf); |
486 | usb_ep_disable(rndis->notify); | 553 | usb_ep_disable(rndis->notify); |
487 | } else { | 554 | } |
555 | if (!rndis->notify->desc) { | ||
488 | VDBG(cdev, "init rndis ctrl %d\n", intf); | 556 | VDBG(cdev, "init rndis ctrl %d\n", intf); |
489 | rndis->notify_desc = ep_choose(cdev->gadget, | 557 | if (config_ep_by_speed(cdev->gadget, f, rndis->notify)) |
490 | rndis->hs.notify, | 558 | goto fail; |
491 | rndis->fs.notify); | ||
492 | } | 559 | } |
493 | usb_ep_enable(rndis->notify, rndis->notify_desc); | 560 | usb_ep_enable(rndis->notify); |
494 | rndis->notify->driver_data = rndis; | 561 | rndis->notify->driver_data = rndis; |
495 | 562 | ||
496 | } else if (intf == rndis->data_id) { | 563 | } else if (intf == rndis->data_id) { |
@@ -501,12 +568,16 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
501 | gether_disconnect(&rndis->port); | 568 | gether_disconnect(&rndis->port); |
502 | } | 569 | } |
503 | 570 | ||
504 | if (!rndis->port.in) { | 571 | if (!rndis->port.in_ep->desc || !rndis->port.out_ep->desc) { |
505 | DBG(cdev, "init rndis\n"); | 572 | DBG(cdev, "init rndis\n"); |
506 | rndis->port.in = ep_choose(cdev->gadget, | 573 | if (config_ep_by_speed(cdev->gadget, f, |
507 | rndis->hs.in, rndis->fs.in); | 574 | rndis->port.in_ep) || |
508 | rndis->port.out = ep_choose(cdev->gadget, | 575 | config_ep_by_speed(cdev->gadget, f, |
509 | rndis->hs.out, rndis->fs.out); | 576 | rndis->port.out_ep)) { |
577 | rndis->port.in_ep->desc = NULL; | ||
578 | rndis->port.out_ep->desc = NULL; | ||
579 | goto fail; | ||
580 | } | ||
510 | } | 581 | } |
511 | 582 | ||
512 | /* Avoid ZLPs; they can be troublesome. */ | 583 | /* Avoid ZLPs; they can be troublesome. */ |
@@ -662,13 +733,6 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
662 | if (!f->descriptors) | 733 | if (!f->descriptors) |
663 | goto fail; | 734 | goto fail; |
664 | 735 | ||
665 | rndis->fs.in = usb_find_endpoint(eth_fs_function, | ||
666 | f->descriptors, &fs_in_desc); | ||
667 | rndis->fs.out = usb_find_endpoint(eth_fs_function, | ||
668 | f->descriptors, &fs_out_desc); | ||
669 | rndis->fs.notify = usb_find_endpoint(eth_fs_function, | ||
670 | f->descriptors, &fs_notify_desc); | ||
671 | |||
672 | /* support all relevant hardware speeds... we expect that when | 736 | /* support all relevant hardware speeds... we expect that when |
673 | * hardware is dual speed, all bulk-capable endpoints work at | 737 | * hardware is dual speed, all bulk-capable endpoints work at |
674 | * both speeds | 738 | * both speeds |
@@ -683,16 +747,22 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
683 | 747 | ||
684 | /* copy descriptors, and track endpoint copies */ | 748 | /* copy descriptors, and track endpoint copies */ |
685 | f->hs_descriptors = usb_copy_descriptors(eth_hs_function); | 749 | f->hs_descriptors = usb_copy_descriptors(eth_hs_function); |
686 | |||
687 | if (!f->hs_descriptors) | 750 | if (!f->hs_descriptors) |
688 | goto fail; | 751 | goto fail; |
752 | } | ||
689 | 753 | ||
690 | rndis->hs.in = usb_find_endpoint(eth_hs_function, | 754 | if (gadget_is_superspeed(c->cdev->gadget)) { |
691 | f->hs_descriptors, &hs_in_desc); | 755 | ss_in_desc.bEndpointAddress = |
692 | rndis->hs.out = usb_find_endpoint(eth_hs_function, | 756 | fs_in_desc.bEndpointAddress; |
693 | f->hs_descriptors, &hs_out_desc); | 757 | ss_out_desc.bEndpointAddress = |
694 | rndis->hs.notify = usb_find_endpoint(eth_hs_function, | 758 | fs_out_desc.bEndpointAddress; |
695 | f->hs_descriptors, &hs_notify_desc); | 759 | ss_notify_desc.bEndpointAddress = |
760 | fs_notify_desc.bEndpointAddress; | ||
761 | |||
762 | /* copy descriptors, and track endpoint copies */ | ||
763 | f->ss_descriptors = usb_copy_descriptors(eth_ss_function); | ||
764 | if (!f->ss_descriptors) | ||
765 | goto fail; | ||
696 | } | 766 | } |
697 | 767 | ||
698 | rndis->port.open = rndis_open; | 768 | rndis->port.open = rndis_open; |
@@ -719,12 +789,15 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
719 | */ | 789 | */ |
720 | 790 | ||
721 | DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n", | 791 | DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n", |
792 | gadget_is_superspeed(c->cdev->gadget) ? "super" : | ||
722 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | 793 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", |
723 | rndis->port.in_ep->name, rndis->port.out_ep->name, | 794 | rndis->port.in_ep->name, rndis->port.out_ep->name, |
724 | rndis->notify->name); | 795 | rndis->notify->name); |
725 | return 0; | 796 | return 0; |
726 | 797 | ||
727 | fail: | 798 | fail: |
799 | if (gadget_is_superspeed(c->cdev->gadget) && f->ss_descriptors) | ||
800 | usb_free_descriptors(f->ss_descriptors); | ||
728 | if (gadget_is_dualspeed(c->cdev->gadget) && f->hs_descriptors) | 801 | if (gadget_is_dualspeed(c->cdev->gadget) && f->hs_descriptors) |
729 | usb_free_descriptors(f->hs_descriptors); | 802 | usb_free_descriptors(f->hs_descriptors); |
730 | if (f->descriptors) | 803 | if (f->descriptors) |
@@ -738,9 +811,9 @@ fail: | |||
738 | /* we might as well release our claims on endpoints */ | 811 | /* we might as well release our claims on endpoints */ |
739 | if (rndis->notify) | 812 | if (rndis->notify) |
740 | rndis->notify->driver_data = NULL; | 813 | rndis->notify->driver_data = NULL; |
741 | if (rndis->port.out) | 814 | if (rndis->port.out_ep->desc) |
742 | rndis->port.out_ep->driver_data = NULL; | 815 | rndis->port.out_ep->driver_data = NULL; |
743 | if (rndis->port.in) | 816 | if (rndis->port.in_ep->desc) |
744 | rndis->port.in_ep->driver_data = NULL; | 817 | rndis->port.in_ep->driver_data = NULL; |
745 | 818 | ||
746 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); | 819 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); |
@@ -756,6 +829,8 @@ rndis_unbind(struct usb_configuration *c, struct usb_function *f) | |||
756 | rndis_deregister(rndis->config); | 829 | rndis_deregister(rndis->config); |
757 | rndis_exit(); | 830 | rndis_exit(); |
758 | 831 | ||
832 | if (gadget_is_superspeed(c->cdev->gadget)) | ||
833 | usb_free_descriptors(f->ss_descriptors); | ||
759 | if (gadget_is_dualspeed(c->cdev->gadget)) | 834 | if (gadget_is_dualspeed(c->cdev->gadget)) |
760 | usb_free_descriptors(f->hs_descriptors); | 835 | usb_free_descriptors(f->hs_descriptors); |
761 | usb_free_descriptors(f->descriptors); | 836 | usb_free_descriptors(f->descriptors); |
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c index 490b00b01a7d..91fdf790ed20 100644 --- a/drivers/usb/gadget/f_serial.c +++ b/drivers/usb/gadget/f_serial.c | |||
@@ -27,18 +27,10 @@ | |||
27 | * if you can arrange appropriate host side drivers. | 27 | * if you can arrange appropriate host side drivers. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | struct gser_descs { | ||
31 | struct usb_endpoint_descriptor *in; | ||
32 | struct usb_endpoint_descriptor *out; | ||
33 | }; | ||
34 | |||
35 | struct f_gser { | 30 | struct f_gser { |
36 | struct gserial port; | 31 | struct gserial port; |
37 | u8 data_id; | 32 | u8 data_id; |
38 | u8 port_num; | 33 | u8 port_num; |
39 | |||
40 | struct gser_descs fs; | ||
41 | struct gser_descs hs; | ||
42 | }; | 34 | }; |
43 | 35 | ||
44 | static inline struct f_gser *func_to_gser(struct usb_function *f) | 36 | static inline struct f_gser *func_to_gser(struct usb_function *f) |
@@ -136,12 +128,15 @@ static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
136 | if (gser->port.in->driver_data) { | 128 | if (gser->port.in->driver_data) { |
137 | DBG(cdev, "reset generic ttyGS%d\n", gser->port_num); | 129 | DBG(cdev, "reset generic ttyGS%d\n", gser->port_num); |
138 | gserial_disconnect(&gser->port); | 130 | gserial_disconnect(&gser->port); |
139 | } else { | 131 | } |
132 | if (!gser->port.in->desc || !gser->port.out->desc) { | ||
140 | DBG(cdev, "activate generic ttyGS%d\n", gser->port_num); | 133 | DBG(cdev, "activate generic ttyGS%d\n", gser->port_num); |
141 | gser->port.in_desc = ep_choose(cdev->gadget, | 134 | if (!config_ep_by_speed(cdev->gadget, f, gser->port.in) || |
142 | gser->hs.in, gser->fs.in); | 135 | !config_ep_by_speed(cdev->gadget, f, gser->port.out)) { |
143 | gser->port.out_desc = ep_choose(cdev->gadget, | 136 | gser->port.in->desc = NULL; |
144 | gser->hs.out, gser->fs.out); | 137 | gser->port.out->desc = NULL; |
138 | return -EINVAL; | ||
139 | } | ||
145 | } | 140 | } |
146 | gserial_connect(&gser->port, gser->port_num); | 141 | gserial_connect(&gser->port, gser->port_num); |
147 | return 0; | 142 | return 0; |
@@ -193,12 +188,6 @@ gser_bind(struct usb_configuration *c, struct usb_function *f) | |||
193 | /* copy descriptors, and track endpoint copies */ | 188 | /* copy descriptors, and track endpoint copies */ |
194 | f->descriptors = usb_copy_descriptors(gser_fs_function); | 189 | f->descriptors = usb_copy_descriptors(gser_fs_function); |
195 | 190 | ||
196 | gser->fs.in = usb_find_endpoint(gser_fs_function, | ||
197 | f->descriptors, &gser_fs_in_desc); | ||
198 | gser->fs.out = usb_find_endpoint(gser_fs_function, | ||
199 | f->descriptors, &gser_fs_out_desc); | ||
200 | |||
201 | |||
202 | /* support all relevant hardware speeds... we expect that when | 191 | /* support all relevant hardware speeds... we expect that when |
203 | * hardware is dual speed, all bulk-capable endpoints work at | 192 | * hardware is dual speed, all bulk-capable endpoints work at |
204 | * both speeds | 193 | * both speeds |
@@ -211,11 +200,6 @@ gser_bind(struct usb_configuration *c, struct usb_function *f) | |||
211 | 200 | ||
212 | /* copy descriptors, and track endpoint copies */ | 201 | /* copy descriptors, and track endpoint copies */ |
213 | f->hs_descriptors = usb_copy_descriptors(gser_hs_function); | 202 | f->hs_descriptors = usb_copy_descriptors(gser_hs_function); |
214 | |||
215 | gser->hs.in = usb_find_endpoint(gser_hs_function, | ||
216 | f->hs_descriptors, &gser_hs_in_desc); | ||
217 | gser->hs.out = usb_find_endpoint(gser_hs_function, | ||
218 | f->hs_descriptors, &gser_hs_out_desc); | ||
219 | } | 203 | } |
220 | 204 | ||
221 | DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n", | 205 | DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n", |
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index e403a534dd55..e18b4f520951 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c | |||
@@ -131,6 +131,49 @@ static struct usb_descriptor_header *hs_source_sink_descs[] = { | |||
131 | NULL, | 131 | NULL, |
132 | }; | 132 | }; |
133 | 133 | ||
134 | /* super speed support: */ | ||
135 | |||
136 | static struct usb_endpoint_descriptor ss_source_desc = { | ||
137 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
138 | .bDescriptorType = USB_DT_ENDPOINT, | ||
139 | |||
140 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
141 | .wMaxPacketSize = cpu_to_le16(1024), | ||
142 | }; | ||
143 | |||
144 | struct usb_ss_ep_comp_descriptor ss_source_comp_desc = { | ||
145 | .bLength = USB_DT_SS_EP_COMP_SIZE, | ||
146 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
147 | .bMaxBurst = 0, | ||
148 | .bmAttributes = 0, | ||
149 | .wBytesPerInterval = 0, | ||
150 | }; | ||
151 | |||
152 | static struct usb_endpoint_descriptor ss_sink_desc = { | ||
153 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
154 | .bDescriptorType = USB_DT_ENDPOINT, | ||
155 | |||
156 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
157 | .wMaxPacketSize = cpu_to_le16(1024), | ||
158 | }; | ||
159 | |||
160 | struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = { | ||
161 | .bLength = USB_DT_SS_EP_COMP_SIZE, | ||
162 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
163 | .bMaxBurst = 0, | ||
164 | .bmAttributes = 0, | ||
165 | .wBytesPerInterval = 0, | ||
166 | }; | ||
167 | |||
168 | static struct usb_descriptor_header *ss_source_sink_descs[] = { | ||
169 | (struct usb_descriptor_header *) &source_sink_intf, | ||
170 | (struct usb_descriptor_header *) &ss_source_desc, | ||
171 | (struct usb_descriptor_header *) &ss_source_comp_desc, | ||
172 | (struct usb_descriptor_header *) &ss_sink_desc, | ||
173 | (struct usb_descriptor_header *) &ss_sink_comp_desc, | ||
174 | NULL, | ||
175 | }; | ||
176 | |||
134 | /* function-specific strings: */ | 177 | /* function-specific strings: */ |
135 | 178 | ||
136 | static struct usb_string strings_sourcesink[] = { | 179 | static struct usb_string strings_sourcesink[] = { |
@@ -187,8 +230,18 @@ autoconf_fail: | |||
187 | f->hs_descriptors = hs_source_sink_descs; | 230 | f->hs_descriptors = hs_source_sink_descs; |
188 | } | 231 | } |
189 | 232 | ||
233 | /* support super speed hardware */ | ||
234 | if (gadget_is_superspeed(c->cdev->gadget)) { | ||
235 | ss_source_desc.bEndpointAddress = | ||
236 | fs_source_desc.bEndpointAddress; | ||
237 | ss_sink_desc.bEndpointAddress = | ||
238 | fs_sink_desc.bEndpointAddress; | ||
239 | f->ss_descriptors = ss_source_sink_descs; | ||
240 | } | ||
241 | |||
190 | DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n", | 242 | DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n", |
191 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | 243 | (gadget_is_superspeed(c->cdev->gadget) ? "super" : |
244 | (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")), | ||
192 | f->name, ss->in_ep->name, ss->out_ep->name); | 245 | f->name, ss->in_ep->name, ss->out_ep->name); |
193 | return 0; | 246 | return 0; |
194 | } | 247 | } |
@@ -343,15 +396,14 @@ static int | |||
343 | enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss) | 396 | enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss) |
344 | { | 397 | { |
345 | int result = 0; | 398 | int result = 0; |
346 | const struct usb_endpoint_descriptor *src, *sink; | ||
347 | struct usb_ep *ep; | 399 | struct usb_ep *ep; |
348 | 400 | ||
349 | src = ep_choose(cdev->gadget, &hs_source_desc, &fs_source_desc); | ||
350 | sink = ep_choose(cdev->gadget, &hs_sink_desc, &fs_sink_desc); | ||
351 | |||
352 | /* one endpoint writes (sources) zeroes IN (to the host) */ | 401 | /* one endpoint writes (sources) zeroes IN (to the host) */ |
353 | ep = ss->in_ep; | 402 | ep = ss->in_ep; |
354 | result = usb_ep_enable(ep, src); | 403 | result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); |
404 | if (result) | ||
405 | return result; | ||
406 | result = usb_ep_enable(ep); | ||
355 | if (result < 0) | 407 | if (result < 0) |
356 | return result; | 408 | return result; |
357 | ep->driver_data = ss; | 409 | ep->driver_data = ss; |
@@ -367,7 +419,10 @@ fail: | |||
367 | 419 | ||
368 | /* one endpoint reads (sinks) anything OUT (from the host) */ | 420 | /* one endpoint reads (sinks) anything OUT (from the host) */ |
369 | ep = ss->out_ep; | 421 | ep = ss->out_ep; |
370 | result = usb_ep_enable(ep, sink); | 422 | result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); |
423 | if (result) | ||
424 | goto fail; | ||
425 | result = usb_ep_enable(ep); | ||
371 | if (result < 0) | 426 | if (result < 0) |
372 | goto fail; | 427 | goto fail; |
373 | ep->driver_data = ss; | 428 | ep->driver_data = ss; |
@@ -435,6 +490,8 @@ static int sourcesink_setup(struct usb_configuration *c, | |||
435 | u16 w_value = le16_to_cpu(ctrl->wValue); | 490 | u16 w_value = le16_to_cpu(ctrl->wValue); |
436 | u16 w_length = le16_to_cpu(ctrl->wLength); | 491 | u16 w_length = le16_to_cpu(ctrl->wLength); |
437 | 492 | ||
493 | req->length = USB_BUFSIZ; | ||
494 | |||
438 | /* composite driver infrastructure handles everything except | 495 | /* composite driver infrastructure handles everything except |
439 | * the two control test requests. | 496 | * the two control test requests. |
440 | */ | 497 | */ |
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c index 8675ca415329..3dc53754ab60 100644 --- a/drivers/usb/gadget/f_subset.c +++ b/drivers/usb/gadget/f_subset.c | |||
@@ -57,18 +57,10 @@ | |||
57 | * caring about specific product and vendor IDs. | 57 | * caring about specific product and vendor IDs. |
58 | */ | 58 | */ |
59 | 59 | ||
60 | struct geth_descs { | ||
61 | struct usb_endpoint_descriptor *in; | ||
62 | struct usb_endpoint_descriptor *out; | ||
63 | }; | ||
64 | |||
65 | struct f_gether { | 60 | struct f_gether { |
66 | struct gether port; | 61 | struct gether port; |
67 | 62 | ||
68 | char ethaddr[14]; | 63 | char ethaddr[14]; |
69 | |||
70 | struct geth_descs fs; | ||
71 | struct geth_descs hs; | ||
72 | }; | 64 | }; |
73 | 65 | ||
74 | static inline struct f_gether *func_to_geth(struct usb_function *f) | 66 | static inline struct f_gether *func_to_geth(struct usb_function *f) |
@@ -209,6 +201,46 @@ static struct usb_descriptor_header *hs_eth_function[] __initdata = { | |||
209 | NULL, | 201 | NULL, |
210 | }; | 202 | }; |
211 | 203 | ||
204 | /* super speed support: */ | ||
205 | |||
206 | static struct usb_endpoint_descriptor ss_subset_in_desc __initdata = { | ||
207 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
208 | .bDescriptorType = USB_DT_ENDPOINT, | ||
209 | |||
210 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
211 | .wMaxPacketSize = cpu_to_le16(1024), | ||
212 | }; | ||
213 | |||
214 | static struct usb_endpoint_descriptor ss_subset_out_desc __initdata = { | ||
215 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
216 | .bDescriptorType = USB_DT_ENDPOINT, | ||
217 | |||
218 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
219 | .wMaxPacketSize = cpu_to_le16(1024), | ||
220 | }; | ||
221 | |||
222 | static struct usb_ss_ep_comp_descriptor ss_subset_bulk_comp_desc __initdata = { | ||
223 | .bLength = sizeof ss_subset_bulk_comp_desc, | ||
224 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
225 | |||
226 | /* the following 2 values can be tweaked if necessary */ | ||
227 | /* .bMaxBurst = 0, */ | ||
228 | /* .bmAttributes = 0, */ | ||
229 | }; | ||
230 | |||
231 | static struct usb_descriptor_header *ss_eth_function[] __initdata = { | ||
232 | (struct usb_descriptor_header *) &subset_data_intf, | ||
233 | (struct usb_descriptor_header *) &mdlm_header_desc, | ||
234 | (struct usb_descriptor_header *) &mdlm_desc, | ||
235 | (struct usb_descriptor_header *) &mdlm_detail_desc, | ||
236 | (struct usb_descriptor_header *) ðer_desc, | ||
237 | (struct usb_descriptor_header *) &ss_subset_in_desc, | ||
238 | (struct usb_descriptor_header *) &ss_subset_bulk_comp_desc, | ||
239 | (struct usb_descriptor_header *) &ss_subset_out_desc, | ||
240 | (struct usb_descriptor_header *) &ss_subset_bulk_comp_desc, | ||
241 | NULL, | ||
242 | }; | ||
243 | |||
212 | /* string descriptors: */ | 244 | /* string descriptors: */ |
213 | 245 | ||
214 | static struct usb_string geth_string_defs[] = { | 246 | static struct usb_string geth_string_defs[] = { |
@@ -243,10 +275,12 @@ static int geth_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
243 | } | 275 | } |
244 | 276 | ||
245 | DBG(cdev, "init + activate cdc subset\n"); | 277 | DBG(cdev, "init + activate cdc subset\n"); |
246 | geth->port.in = ep_choose(cdev->gadget, | 278 | if (config_ep_by_speed(cdev->gadget, f, geth->port.in_ep) || |
247 | geth->hs.in, geth->fs.in); | 279 | config_ep_by_speed(cdev->gadget, f, geth->port.out_ep)) { |
248 | geth->port.out = ep_choose(cdev->gadget, | 280 | geth->port.in_ep->desc = NULL; |
249 | geth->hs.out, geth->fs.out); | 281 | geth->port.out_ep->desc = NULL; |
282 | return -EINVAL; | ||
283 | } | ||
250 | 284 | ||
251 | net = gether_connect(&geth->port); | 285 | net = gether_connect(&geth->port); |
252 | return IS_ERR(net) ? PTR_ERR(net) : 0; | 286 | return IS_ERR(net) ? PTR_ERR(net) : 0; |
@@ -296,12 +330,8 @@ geth_bind(struct usb_configuration *c, struct usb_function *f) | |||
296 | 330 | ||
297 | /* copy descriptors, and track endpoint copies */ | 331 | /* copy descriptors, and track endpoint copies */ |
298 | f->descriptors = usb_copy_descriptors(fs_eth_function); | 332 | f->descriptors = usb_copy_descriptors(fs_eth_function); |
299 | 333 | if (!f->descriptors) | |
300 | geth->fs.in = usb_find_endpoint(fs_eth_function, | 334 | goto fail; |
301 | f->descriptors, &fs_subset_in_desc); | ||
302 | geth->fs.out = usb_find_endpoint(fs_eth_function, | ||
303 | f->descriptors, &fs_subset_out_desc); | ||
304 | |||
305 | 335 | ||
306 | /* support all relevant hardware speeds... we expect that when | 336 | /* support all relevant hardware speeds... we expect that when |
307 | * hardware is dual speed, all bulk-capable endpoints work at | 337 | * hardware is dual speed, all bulk-capable endpoints work at |
@@ -315,11 +345,20 @@ geth_bind(struct usb_configuration *c, struct usb_function *f) | |||
315 | 345 | ||
316 | /* copy descriptors, and track endpoint copies */ | 346 | /* copy descriptors, and track endpoint copies */ |
317 | f->hs_descriptors = usb_copy_descriptors(hs_eth_function); | 347 | f->hs_descriptors = usb_copy_descriptors(hs_eth_function); |
348 | if (!f->hs_descriptors) | ||
349 | goto fail; | ||
350 | } | ||
318 | 351 | ||
319 | geth->hs.in = usb_find_endpoint(hs_eth_function, | 352 | if (gadget_is_superspeed(c->cdev->gadget)) { |
320 | f->hs_descriptors, &hs_subset_in_desc); | 353 | ss_subset_in_desc.bEndpointAddress = |
321 | geth->hs.out = usb_find_endpoint(hs_eth_function, | 354 | fs_subset_in_desc.bEndpointAddress; |
322 | f->hs_descriptors, &hs_subset_out_desc); | 355 | ss_subset_out_desc.bEndpointAddress = |
356 | fs_subset_out_desc.bEndpointAddress; | ||
357 | |||
358 | /* copy descriptors, and track endpoint copies */ | ||
359 | f->ss_descriptors = usb_copy_descriptors(ss_eth_function); | ||
360 | if (!f->ss_descriptors) | ||
361 | goto fail; | ||
323 | } | 362 | } |
324 | 363 | ||
325 | /* NOTE: all that is done without knowing or caring about | 364 | /* NOTE: all that is done without knowing or caring about |
@@ -328,15 +367,21 @@ geth_bind(struct usb_configuration *c, struct usb_function *f) | |||
328 | */ | 367 | */ |
329 | 368 | ||
330 | DBG(cdev, "CDC Subset: %s speed IN/%s OUT/%s\n", | 369 | DBG(cdev, "CDC Subset: %s speed IN/%s OUT/%s\n", |
370 | gadget_is_superspeed(c->cdev->gadget) ? "super" : | ||
331 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | 371 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", |
332 | geth->port.in_ep->name, geth->port.out_ep->name); | 372 | geth->port.in_ep->name, geth->port.out_ep->name); |
333 | return 0; | 373 | return 0; |
334 | 374 | ||
335 | fail: | 375 | fail: |
376 | if (f->descriptors) | ||
377 | usb_free_descriptors(f->descriptors); | ||
378 | if (f->hs_descriptors) | ||
379 | usb_free_descriptors(f->hs_descriptors); | ||
380 | |||
336 | /* we might as well release our claims on endpoints */ | 381 | /* we might as well release our claims on endpoints */ |
337 | if (geth->port.out) | 382 | if (geth->port.out_ep->desc) |
338 | geth->port.out_ep->driver_data = NULL; | 383 | geth->port.out_ep->driver_data = NULL; |
339 | if (geth->port.in) | 384 | if (geth->port.in_ep->desc) |
340 | geth->port.in_ep->driver_data = NULL; | 385 | geth->port.in_ep->driver_data = NULL; |
341 | 386 | ||
342 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); | 387 | ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); |
@@ -347,6 +392,8 @@ fail: | |||
347 | static void | 392 | static void |
348 | geth_unbind(struct usb_configuration *c, struct usb_function *f) | 393 | geth_unbind(struct usb_configuration *c, struct usb_function *f) |
349 | { | 394 | { |
395 | if (gadget_is_superspeed(c->cdev->gadget)) | ||
396 | usb_free_descriptors(f->ss_descriptors); | ||
350 | if (gadget_is_dualspeed(c->cdev->gadget)) | 397 | if (gadget_is_dualspeed(c->cdev->gadget)) |
351 | usb_free_descriptors(f->hs_descriptors); | 398 | usb_free_descriptors(f->hs_descriptors); |
352 | usb_free_descriptors(f->descriptors); | 399 | usb_free_descriptors(f->descriptors); |
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c index be446b7e7eaa..7a8b9aa4aea5 100644 --- a/drivers/usb/gadget/f_uvc.c +++ b/drivers/usb/gadget/f_uvc.c | |||
@@ -262,8 +262,10 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) | |||
262 | if (uvc->state != UVC_STATE_CONNECTED) | 262 | if (uvc->state != UVC_STATE_CONNECTED) |
263 | return 0; | 263 | return 0; |
264 | 264 | ||
265 | if (uvc->video.ep) | 265 | if (uvc->video.ep) { |
266 | usb_ep_enable(uvc->video.ep, &uvc_streaming_ep); | 266 | uvc->video.ep->desc = &uvc_streaming_ep; |
267 | usb_ep_enable(uvc->video.ep); | ||
268 | } | ||
267 | 269 | ||
268 | memset(&v4l2_event, 0, sizeof(v4l2_event)); | 270 | memset(&v4l2_event, 0, sizeof(v4l2_event)); |
269 | v4l2_event.type = UVC_EVENT_STREAMON; | 271 | v4l2_event.type = UVC_EVENT_STREAMON; |
@@ -649,7 +651,7 @@ uvc_bind_config(struct usb_configuration *c, | |||
649 | if (ret) | 651 | if (ret) |
650 | kfree(uvc); | 652 | kfree(uvc); |
651 | 653 | ||
652 | return 0; | 654 | return ret; |
653 | 655 | ||
654 | error: | 656 | error: |
655 | kfree(uvc); | 657 | kfree(uvc); |
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index 0360f56221ea..639e14a2fd15 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
@@ -929,6 +929,7 @@ static int standard_setup_req(struct fsg_dev *fsg, | |||
929 | 929 | ||
930 | case USB_DT_DEVICE: | 930 | case USB_DT_DEVICE: |
931 | VDBG(fsg, "get device descriptor\n"); | 931 | VDBG(fsg, "get device descriptor\n"); |
932 | device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket; | ||
932 | value = sizeof device_desc; | 933 | value = sizeof device_desc; |
933 | memcpy(req->buf, &device_desc, value); | 934 | memcpy(req->buf, &device_desc, value); |
934 | break; | 935 | break; |
@@ -936,6 +937,11 @@ static int standard_setup_req(struct fsg_dev *fsg, | |||
936 | VDBG(fsg, "get device qualifier\n"); | 937 | VDBG(fsg, "get device qualifier\n"); |
937 | if (!gadget_is_dualspeed(fsg->gadget)) | 938 | if (!gadget_is_dualspeed(fsg->gadget)) |
938 | break; | 939 | break; |
940 | /* | ||
941 | * Assume ep0 uses the same maxpacket value for both | ||
942 | * speeds | ||
943 | */ | ||
944 | dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket; | ||
939 | value = sizeof dev_qualifier; | 945 | value = sizeof dev_qualifier; |
940 | memcpy(req->buf, &dev_qualifier, value); | 946 | memcpy(req->buf, &dev_qualifier, value); |
941 | break; | 947 | break; |
@@ -2713,7 +2719,8 @@ static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep, | |||
2713 | int rc; | 2719 | int rc; |
2714 | 2720 | ||
2715 | ep->driver_data = fsg; | 2721 | ep->driver_data = fsg; |
2716 | rc = usb_ep_enable(ep, d); | 2722 | ep->desc = d; |
2723 | rc = usb_ep_enable(ep); | ||
2717 | if (rc) | 2724 | if (rc) |
2718 | ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc); | 2725 | ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc); |
2719 | return rc; | 2726 | return rc; |
@@ -3416,7 +3423,6 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3416 | } | 3423 | } |
3417 | 3424 | ||
3418 | /* Fix up the descriptors */ | 3425 | /* Fix up the descriptors */ |
3419 | device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket; | ||
3420 | device_desc.idVendor = cpu_to_le16(mod_data.vendor); | 3426 | device_desc.idVendor = cpu_to_le16(mod_data.vendor); |
3421 | device_desc.idProduct = cpu_to_le16(mod_data.product); | 3427 | device_desc.idProduct = cpu_to_le16(mod_data.product); |
3422 | device_desc.bcdDevice = cpu_to_le16(mod_data.release); | 3428 | device_desc.bcdDevice = cpu_to_le16(mod_data.release); |
@@ -3430,9 +3436,6 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3430 | if (gadget_is_dualspeed(gadget)) { | 3436 | if (gadget_is_dualspeed(gadget)) { |
3431 | fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL; | 3437 | fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL; |
3432 | 3438 | ||
3433 | /* Assume ep0 uses the same maxpacket value for both speeds */ | ||
3434 | dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket; | ||
3435 | |||
3436 | /* Assume endpoint addresses are the same for both speeds */ | 3439 | /* Assume endpoint addresses are the same for both speeds */ |
3437 | fsg_hs_bulk_in_desc.bEndpointAddress = | 3440 | fsg_hs_bulk_in_desc.bEndpointAddress = |
3438 | fsg_fs_bulk_in_desc.bEndpointAddress; | 3441 | fsg_fs_bulk_in_desc.bEndpointAddress; |
@@ -3486,6 +3489,8 @@ static int __init fsg_bind(struct usb_gadget *gadget) | |||
3486 | } | 3489 | } |
3487 | 3490 | ||
3488 | INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); | 3491 | INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); |
3492 | INFO(fsg, "NOTE: This driver is deprecated. " | ||
3493 | "Consider using g_mass_storage instead.\n"); | ||
3489 | INFO(fsg, "Number of LUNs=%d\n", fsg->nluns); | 3494 | INFO(fsg, "Number of LUNs=%d\n", fsg->nluns); |
3490 | 3495 | ||
3491 | pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); | 3496 | pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); |
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c index 3a68e09309f7..3bf872e1ad39 100644 --- a/drivers/usb/gadget/fsl_qe_udc.c +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -1927,6 +1927,10 @@ static int qe_pullup(struct usb_gadget *gadget, int is_on) | |||
1927 | return -ENOTSUPP; | 1927 | return -ENOTSUPP; |
1928 | } | 1928 | } |
1929 | 1929 | ||
1930 | static int fsl_qe_start(struct usb_gadget_driver *driver, | ||
1931 | int (*bind)(struct usb_gadget *)); | ||
1932 | static int fsl_qe_stop(struct usb_gadget_driver *driver); | ||
1933 | |||
1930 | /* defined in usb_gadget.h */ | 1934 | /* defined in usb_gadget.h */ |
1931 | static struct usb_gadget_ops qe_gadget_ops = { | 1935 | static struct usb_gadget_ops qe_gadget_ops = { |
1932 | .get_frame = qe_get_frame, | 1936 | .get_frame = qe_get_frame, |
@@ -1935,6 +1939,8 @@ static struct usb_gadget_ops qe_gadget_ops = { | |||
1935 | .vbus_session = qe_vbus_session, | 1939 | .vbus_session = qe_vbus_session, |
1936 | .vbus_draw = qe_vbus_draw, | 1940 | .vbus_draw = qe_vbus_draw, |
1937 | .pullup = qe_pullup, | 1941 | .pullup = qe_pullup, |
1942 | .start = fsl_qe_start, | ||
1943 | .stop = fsl_qe_stop, | ||
1938 | }; | 1944 | }; |
1939 | 1945 | ||
1940 | /*------------------------------------------------------------------------- | 1946 | /*------------------------------------------------------------------------- |
@@ -2320,7 +2326,7 @@ static irqreturn_t qe_udc_irq(int irq, void *_udc) | |||
2320 | /*------------------------------------------------------------------------- | 2326 | /*------------------------------------------------------------------------- |
2321 | Gadget driver probe and unregister. | 2327 | Gadget driver probe and unregister. |
2322 | --------------------------------------------------------------------------*/ | 2328 | --------------------------------------------------------------------------*/ |
2323 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 2329 | static int fsl_qe_start(struct usb_gadget_driver *driver, |
2324 | int (*bind)(struct usb_gadget *)) | 2330 | int (*bind)(struct usb_gadget *)) |
2325 | { | 2331 | { |
2326 | int retval; | 2332 | int retval; |
@@ -2369,9 +2375,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
2369 | udc_controller->gadget.name, driver->driver.name); | 2375 | udc_controller->gadget.name, driver->driver.name); |
2370 | return 0; | 2376 | return 0; |
2371 | } | 2377 | } |
2372 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
2373 | 2378 | ||
2374 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 2379 | static int fsl_qe_stop(struct usb_gadget_driver *driver) |
2375 | { | 2380 | { |
2376 | struct qe_ep *loop_ep; | 2381 | struct qe_ep *loop_ep; |
2377 | unsigned long flags; | 2382 | unsigned long flags; |
@@ -2411,7 +2416,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
2411 | driver->driver.name); | 2416 | driver->driver.name); |
2412 | return 0; | 2417 | return 0; |
2413 | } | 2418 | } |
2414 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2415 | 2419 | ||
2416 | /* udc structure's alloc and setup, include ep-param alloc */ | 2420 | /* udc structure's alloc and setup, include ep-param alloc */ |
2417 | static struct qe_udc __devinit *qe_udc_config(struct platform_device *ofdev) | 2421 | static struct qe_udc __devinit *qe_udc_config(struct platform_device *ofdev) |
@@ -2662,11 +2666,17 @@ static int __devinit qe_udc_probe(struct platform_device *ofdev) | |||
2662 | if (ret) | 2666 | if (ret) |
2663 | goto err6; | 2667 | goto err6; |
2664 | 2668 | ||
2669 | ret = usb_add_gadget_udc(&ofdev->dev, &udc_controller->gadget); | ||
2670 | if (ret) | ||
2671 | goto err7; | ||
2672 | |||
2665 | dev_info(udc_controller->dev, | 2673 | dev_info(udc_controller->dev, |
2666 | "%s USB controller initialized as device\n", | 2674 | "%s USB controller initialized as device\n", |
2667 | (udc_controller->soc_type == PORT_QE) ? "QE" : "CPM"); | 2675 | (udc_controller->soc_type == PORT_QE) ? "QE" : "CPM"); |
2668 | return 0; | 2676 | return 0; |
2669 | 2677 | ||
2678 | err7: | ||
2679 | device_unregister(&udc_controller->gadget.dev); | ||
2670 | err6: | 2680 | err6: |
2671 | free_irq(udc_controller->usb_irq, udc_controller); | 2681 | free_irq(udc_controller->usb_irq, udc_controller); |
2672 | err5: | 2682 | err5: |
@@ -2721,6 +2731,8 @@ static int __devexit qe_udc_remove(struct platform_device *ofdev) | |||
2721 | if (!udc_controller) | 2731 | if (!udc_controller) |
2722 | return -ENODEV; | 2732 | return -ENODEV; |
2723 | 2733 | ||
2734 | usb_del_gadget_udc(&udc_controller->gadget); | ||
2735 | |||
2724 | udc_controller->done = &done; | 2736 | udc_controller->done = &done; |
2725 | tasklet_disable(&udc_controller->rx_tasklet); | 2737 | tasklet_disable(&udc_controller->rx_tasklet); |
2726 | 2738 | ||
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c index 3e59035e6de8..de24a4233c25 100644 --- a/drivers/usb/gadget/fsl_udc_core.c +++ b/drivers/usb/gadget/fsl_udc_core.c | |||
@@ -1244,6 +1244,9 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on) | |||
1244 | return 0; | 1244 | return 0; |
1245 | } | 1245 | } |
1246 | 1246 | ||
1247 | static int fsl_start(struct usb_gadget_driver *driver, | ||
1248 | int (*bind)(struct usb_gadget *)); | ||
1249 | static int fsl_stop(struct usb_gadget_driver *driver); | ||
1247 | /* defined in gadget.h */ | 1250 | /* defined in gadget.h */ |
1248 | static struct usb_gadget_ops fsl_gadget_ops = { | 1251 | static struct usb_gadget_ops fsl_gadget_ops = { |
1249 | .get_frame = fsl_get_frame, | 1252 | .get_frame = fsl_get_frame, |
@@ -1252,6 +1255,8 @@ static struct usb_gadget_ops fsl_gadget_ops = { | |||
1252 | .vbus_session = fsl_vbus_session, | 1255 | .vbus_session = fsl_vbus_session, |
1253 | .vbus_draw = fsl_vbus_draw, | 1256 | .vbus_draw = fsl_vbus_draw, |
1254 | .pullup = fsl_pullup, | 1257 | .pullup = fsl_pullup, |
1258 | .start = fsl_start, | ||
1259 | .stop = fsl_stop, | ||
1255 | }; | 1260 | }; |
1256 | 1261 | ||
1257 | /* Set protocol stall on ep0, protocol stall will automatically be cleared | 1262 | /* Set protocol stall on ep0, protocol stall will automatically be cleared |
@@ -1927,7 +1932,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc) | |||
1927 | * Hook to gadget drivers | 1932 | * Hook to gadget drivers |
1928 | * Called by initialization code of gadget drivers | 1933 | * Called by initialization code of gadget drivers |
1929 | *----------------------------------------------------------------*/ | 1934 | *----------------------------------------------------------------*/ |
1930 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1935 | static int fsl_start(struct usb_gadget_driver *driver, |
1931 | int (*bind)(struct usb_gadget *)) | 1936 | int (*bind)(struct usb_gadget *)) |
1932 | { | 1937 | { |
1933 | int retval = -ENODEV; | 1938 | int retval = -ENODEV; |
@@ -1995,10 +2000,9 @@ out: | |||
1995 | retval); | 2000 | retval); |
1996 | return retval; | 2001 | return retval; |
1997 | } | 2002 | } |
1998 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1999 | 2003 | ||
2000 | /* Disconnect from gadget driver */ | 2004 | /* Disconnect from gadget driver */ |
2001 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 2005 | static int fsl_stop(struct usb_gadget_driver *driver) |
2002 | { | 2006 | { |
2003 | struct fsl_ep *loop_ep; | 2007 | struct fsl_ep *loop_ep; |
2004 | unsigned long flags; | 2008 | unsigned long flags; |
@@ -2041,7 +2045,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
2041 | driver->driver.name); | 2045 | driver->driver.name); |
2042 | return 0; | 2046 | return 0; |
2043 | } | 2047 | } |
2044 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2045 | 2048 | ||
2046 | /*------------------------------------------------------------------------- | 2049 | /*------------------------------------------------------------------------- |
2047 | PROC File System Support | 2050 | PROC File System Support |
@@ -2590,9 +2593,16 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2590 | ret = -ENOMEM; | 2593 | ret = -ENOMEM; |
2591 | goto err_unregister; | 2594 | goto err_unregister; |
2592 | } | 2595 | } |
2596 | |||
2597 | ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget); | ||
2598 | if (ret) | ||
2599 | goto err_del_udc; | ||
2600 | |||
2593 | create_proc_file(); | 2601 | create_proc_file(); |
2594 | return 0; | 2602 | return 0; |
2595 | 2603 | ||
2604 | err_del_udc: | ||
2605 | dma_pool_destroy(udc_controller->td_pool); | ||
2596 | err_unregister: | 2606 | err_unregister: |
2597 | device_unregister(&udc_controller->gadget.dev); | 2607 | device_unregister(&udc_controller->gadget.dev); |
2598 | err_free_irq: | 2608 | err_free_irq: |
@@ -2624,6 +2634,8 @@ static int __exit fsl_udc_remove(struct platform_device *pdev) | |||
2624 | 2634 | ||
2625 | if (!udc_controller) | 2635 | if (!udc_controller) |
2626 | return -ENODEV; | 2636 | return -ENODEV; |
2637 | |||
2638 | usb_del_gadget_udc(&udc_controller->gadget); | ||
2627 | udc_controller->done = &done; | 2639 | udc_controller->done = &done; |
2628 | 2640 | ||
2629 | fsl_udc_clk_release(); | 2641 | fsl_udc_clk_release(); |
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c index 763d462454b9..24a924330c81 100644 --- a/drivers/usb/gadget/fusb300_udc.c +++ b/drivers/usb/gadget/fusb300_udc.c | |||
@@ -767,56 +767,6 @@ static void fusb300_rdfifo(struct fusb300_ep *ep, | |||
767 | } while (!reg); | 767 | } while (!reg); |
768 | } | 768 | } |
769 | 769 | ||
770 | /* write data to fifo */ | ||
771 | static void fusb300_wrfifo(struct fusb300_ep *ep, | ||
772 | struct fusb300_request *req) | ||
773 | { | ||
774 | int i = 0; | ||
775 | u8 *tmp; | ||
776 | u32 data, reg; | ||
777 | struct fusb300 *fusb300 = ep->fusb300; | ||
778 | |||
779 | tmp = req->req.buf; | ||
780 | req->req.actual = req->req.length; | ||
781 | |||
782 | for (i = (req->req.length >> 2); i > 0; i--) { | ||
783 | data = *tmp | *(tmp + 1) << 8 | | ||
784 | *(tmp + 2) << 16 | *(tmp + 3) << 24; | ||
785 | |||
786 | iowrite32(data, fusb300->reg + | ||
787 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
788 | tmp += 4; | ||
789 | } | ||
790 | |||
791 | switch (req->req.length % 4) { | ||
792 | case 1: | ||
793 | data = *tmp; | ||
794 | iowrite32(data, fusb300->reg + | ||
795 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
796 | break; | ||
797 | case 2: | ||
798 | data = *tmp | *(tmp + 1) << 8; | ||
799 | iowrite32(data, fusb300->reg + | ||
800 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
801 | break; | ||
802 | case 3: | ||
803 | data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16; | ||
804 | iowrite32(data, fusb300->reg + | ||
805 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
806 | break; | ||
807 | default: | ||
808 | break; | ||
809 | } | ||
810 | |||
811 | do { | ||
812 | reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1); | ||
813 | reg &= FUSB300_IGR1_SYNF0_EMPTY_INT; | ||
814 | if (i) | ||
815 | printk(KERN_INFO"sync fifo is not empty!\n"); | ||
816 | i++; | ||
817 | } while (!reg); | ||
818 | } | ||
819 | |||
820 | static u8 fusb300_get_epnstall(struct fusb300 *fusb300, u8 ep) | 770 | static u8 fusb300_get_epnstall(struct fusb300 *fusb300, u8 ep) |
821 | { | 771 | { |
822 | u8 value; | 772 | u8 value; |
@@ -980,11 +930,6 @@ static void set_address(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl) | |||
980 | } \ | 930 | } \ |
981 | } while (0) | 931 | } while (0) |
982 | 932 | ||
983 | static void fusb300_ep0_complete(struct usb_ep *ep, | ||
984 | struct usb_request *req) | ||
985 | { | ||
986 | } | ||
987 | |||
988 | static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl) | 933 | static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl) |
989 | { | 934 | { |
990 | u8 *p = (u8 *)ctrl; | 935 | u8 *p = (u8 *)ctrl; |
@@ -1029,17 +974,6 @@ static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl) | |||
1029 | return ret; | 974 | return ret; |
1030 | } | 975 | } |
1031 | 976 | ||
1032 | static void fusb300_set_ep_bycnt(struct fusb300_ep *ep, u32 bycnt) | ||
1033 | { | ||
1034 | struct fusb300 *fusb300 = ep->fusb300; | ||
1035 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum)); | ||
1036 | |||
1037 | reg &= ~FUSB300_FFR_BYCNT; | ||
1038 | reg |= bycnt & FUSB300_FFR_BYCNT; | ||
1039 | |||
1040 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum)); | ||
1041 | } | ||
1042 | |||
1043 | static void done(struct fusb300_ep *ep, struct fusb300_request *req, | 977 | static void done(struct fusb300_ep *ep, struct fusb300_request *req, |
1044 | int status) | 978 | int status) |
1045 | { | 979 | { |
@@ -1063,8 +997,8 @@ static void done(struct fusb300_ep *ep, struct fusb300_request *req, | |||
1063 | fusb300_set_cxdone(ep->fusb300); | 997 | fusb300_set_cxdone(ep->fusb300); |
1064 | } | 998 | } |
1065 | 999 | ||
1066 | void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep, | 1000 | static void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep, dma_addr_t d, |
1067 | struct fusb300_request *req) | 1001 | u32 len) |
1068 | { | 1002 | { |
1069 | u32 value; | 1003 | u32 value; |
1070 | u32 reg; | 1004 | u32 reg; |
@@ -1076,10 +1010,9 @@ void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep, | |||
1076 | reg &= FUSB300_EPPRD0_H; | 1010 | reg &= FUSB300_EPPRD0_H; |
1077 | } while (reg); | 1011 | } while (reg); |
1078 | 1012 | ||
1079 | iowrite32((u32) req->req.buf, ep->fusb300->reg + | 1013 | iowrite32(d, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W1(ep->epnum)); |
1080 | FUSB300_OFFSET_EPPRD_W1(ep->epnum)); | ||
1081 | 1014 | ||
1082 | value = FUSB300_EPPRD0_BTC(req->req.length) | FUSB300_EPPRD0_H | | 1015 | value = FUSB300_EPPRD0_BTC(len) | FUSB300_EPPRD0_H | |
1083 | FUSB300_EPPRD0_F | FUSB300_EPPRD0_L | FUSB300_EPPRD0_I; | 1016 | FUSB300_EPPRD0_F | FUSB300_EPPRD0_L | FUSB300_EPPRD0_I; |
1084 | iowrite32(value, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W0(ep->epnum)); | 1017 | iowrite32(value, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W0(ep->epnum)); |
1085 | 1018 | ||
@@ -1116,13 +1049,12 @@ static void fusb300_set_idma(struct fusb300_ep *ep, | |||
1116 | struct fusb300_request *req) | 1049 | struct fusb300_request *req) |
1117 | { | 1050 | { |
1118 | dma_addr_t d; | 1051 | dma_addr_t d; |
1119 | u8 *tmp = NULL; | ||
1120 | 1052 | ||
1121 | d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE); | 1053 | d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE); |
1122 | 1054 | ||
1123 | if (dma_mapping_error(NULL, d)) { | 1055 | if (dma_mapping_error(NULL, d)) { |
1124 | kfree(req->req.buf); | ||
1125 | printk(KERN_DEBUG "dma_mapping_error\n"); | 1056 | printk(KERN_DEBUG "dma_mapping_error\n"); |
1057 | return; | ||
1126 | } | 1058 | } |
1127 | 1059 | ||
1128 | dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE); | 1060 | dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE); |
@@ -1130,17 +1062,11 @@ static void fusb300_set_idma(struct fusb300_ep *ep, | |||
1130 | fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0, | 1062 | fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0, |
1131 | FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); | 1063 | FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); |
1132 | 1064 | ||
1133 | tmp = req->req.buf; | 1065 | fusb300_fill_idma_prdtbl(ep, d, req->req.length); |
1134 | req->req.buf = (u8 *)d; | ||
1135 | |||
1136 | fusb300_fill_idma_prdtbl(ep, req); | ||
1137 | /* check idma is done */ | 1066 | /* check idma is done */ |
1138 | fusb300_wait_idma_finished(ep); | 1067 | fusb300_wait_idma_finished(ep); |
1139 | 1068 | ||
1140 | req->req.buf = tmp; | 1069 | dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE); |
1141 | |||
1142 | if (d) | ||
1143 | dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE); | ||
1144 | } | 1070 | } |
1145 | 1071 | ||
1146 | static void in_ep_fifo_handler(struct fusb300_ep *ep) | 1072 | static void in_ep_fifo_handler(struct fusb300_ep *ep) |
@@ -1148,14 +1074,8 @@ static void in_ep_fifo_handler(struct fusb300_ep *ep) | |||
1148 | struct fusb300_request *req = list_entry(ep->queue.next, | 1074 | struct fusb300_request *req = list_entry(ep->queue.next, |
1149 | struct fusb300_request, queue); | 1075 | struct fusb300_request, queue); |
1150 | 1076 | ||
1151 | if (req->req.length) { | 1077 | if (req->req.length) |
1152 | #if 0 | ||
1153 | fusb300_set_ep_bycnt(ep, req->req.length); | ||
1154 | fusb300_wrfifo(ep, req); | ||
1155 | #else | ||
1156 | fusb300_set_idma(ep, req); | 1078 | fusb300_set_idma(ep, req); |
1157 | #endif | ||
1158 | } | ||
1159 | done(ep, req, 0); | 1079 | done(ep, req, 0); |
1160 | } | 1080 | } |
1161 | 1081 | ||
@@ -1500,7 +1420,7 @@ static void init_controller(struct fusb300 *fusb300) | |||
1500 | /*------------------------------------------------------------------------*/ | 1420 | /*------------------------------------------------------------------------*/ |
1501 | static struct fusb300 *the_controller; | 1421 | static struct fusb300 *the_controller; |
1502 | 1422 | ||
1503 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1423 | static int fusb300_udc_start(struct usb_gadget_driver *driver, |
1504 | int (*bind)(struct usb_gadget *)) | 1424 | int (*bind)(struct usb_gadget *)) |
1505 | { | 1425 | { |
1506 | struct fusb300 *fusb300 = the_controller; | 1426 | struct fusb300 *fusb300 = the_controller; |
@@ -1544,9 +1464,8 @@ error: | |||
1544 | 1464 | ||
1545 | return retval; | 1465 | return retval; |
1546 | } | 1466 | } |
1547 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1548 | 1467 | ||
1549 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1468 | static int fusb300_udc_stop(struct usb_gadget_driver *driver) |
1550 | { | 1469 | { |
1551 | struct fusb300 *fusb300 = the_controller; | 1470 | struct fusb300 *fusb300 = the_controller; |
1552 | 1471 | ||
@@ -1562,7 +1481,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1562 | 1481 | ||
1563 | return 0; | 1482 | return 0; |
1564 | } | 1483 | } |
1565 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1566 | /*--------------------------------------------------------------------------*/ | 1484 | /*--------------------------------------------------------------------------*/ |
1567 | 1485 | ||
1568 | static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active) | 1486 | static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active) |
@@ -1572,12 +1490,15 @@ static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active) | |||
1572 | 1490 | ||
1573 | static struct usb_gadget_ops fusb300_gadget_ops = { | 1491 | static struct usb_gadget_ops fusb300_gadget_ops = { |
1574 | .pullup = fusb300_udc_pullup, | 1492 | .pullup = fusb300_udc_pullup, |
1493 | .start = fusb300_udc_start, | ||
1494 | .stop = fusb300_udc_stop, | ||
1575 | }; | 1495 | }; |
1576 | 1496 | ||
1577 | static int __exit fusb300_remove(struct platform_device *pdev) | 1497 | static int __exit fusb300_remove(struct platform_device *pdev) |
1578 | { | 1498 | { |
1579 | struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev); | 1499 | struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev); |
1580 | 1500 | ||
1501 | usb_del_gadget_udc(&fusb300->gadget); | ||
1581 | iounmap(fusb300->reg); | 1502 | iounmap(fusb300->reg); |
1582 | free_irq(platform_get_irq(pdev, 0), fusb300); | 1503 | free_irq(platform_get_irq(pdev, 0), fusb300); |
1583 | 1504 | ||
@@ -1702,9 +1623,15 @@ static int __init fusb300_probe(struct platform_device *pdev) | |||
1702 | goto clean_up3; | 1623 | goto clean_up3; |
1703 | 1624 | ||
1704 | init_controller(fusb300); | 1625 | init_controller(fusb300); |
1626 | ret = usb_add_gadget_udc(&pdev->dev, &fusb300->gadget); | ||
1627 | if (ret) | ||
1628 | goto err_add_udc; | ||
1629 | |||
1705 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); | 1630 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); |
1706 | 1631 | ||
1707 | return 0; | 1632 | return 0; |
1633 | err_add_udc: | ||
1634 | fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req); | ||
1708 | 1635 | ||
1709 | clean_up3: | 1636 | clean_up3: |
1710 | free_irq(ires->start, fusb300); | 1637 | free_irq(ires->start, fusb300); |
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index ebf6970a10bf..704c2800ac00 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c | |||
@@ -162,6 +162,7 @@ static struct usb_composite_driver gfs_driver = { | |||
162 | .name = DRIVER_NAME, | 162 | .name = DRIVER_NAME, |
163 | .dev = &gfs_dev_desc, | 163 | .dev = &gfs_dev_desc, |
164 | .strings = gfs_dev_strings, | 164 | .strings = gfs_dev_strings, |
165 | .max_speed = USB_SPEED_HIGH, | ||
165 | .unbind = gfs_unbind, | 166 | .unbind = gfs_unbind, |
166 | .iProduct = DRIVER_DESC, | 167 | .iProduct = DRIVER_DESC, |
167 | }; | 168 | }; |
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index bcdac7c73e89..f3a83cd0ef50 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h | |||
@@ -15,150 +15,40 @@ | |||
15 | #ifndef __GADGET_CHIPS_H | 15 | #ifndef __GADGET_CHIPS_H |
16 | #define __GADGET_CHIPS_H | 16 | #define __GADGET_CHIPS_H |
17 | 17 | ||
18 | #ifdef CONFIG_USB_GADGET_NET2280 | 18 | /* |
19 | #define gadget_is_net2280(g) !strcmp("net2280", (g)->name) | 19 | * NOTICE: the entries below are alphabetical and should be kept |
20 | #else | 20 | * that way. |
21 | #define gadget_is_net2280(g) 0 | 21 | * |
22 | #endif | 22 | * Always be sure to add new entries to the correct position or |
23 | 23 | * accept the bashing later. | |
24 | #ifdef CONFIG_USB_GADGET_AMD5536UDC | 24 | * |
25 | #define gadget_is_amd5536udc(g) !strcmp("amd5536udc", (g)->name) | 25 | * If you have forgotten the alphabetical order let VIM/EMACS |
26 | #else | 26 | * do that for you. |
27 | #define gadget_is_amd5536udc(g) 0 | 27 | */ |
28 | #endif | 28 | #define gadget_is_amd5536udc(g) (!strcmp("amd5536udc", (g)->name)) |
29 | 29 | #define gadget_is_at91(g) (!strcmp("at91_udc", (g)->name)) | |
30 | #ifdef CONFIG_USB_GADGET_DUMMY_HCD | 30 | #define gadget_is_atmel_usba(g) (!strcmp("atmel_usba_udc", (g)->name)) |
31 | #define gadget_is_dummy(g) !strcmp("dummy_udc", (g)->name) | ||
32 | #else | ||
33 | #define gadget_is_dummy(g) 0 | ||
34 | #endif | ||
35 | |||
36 | #ifdef CONFIG_USB_GADGET_PXA25X | ||
37 | #define gadget_is_pxa(g) !strcmp("pxa25x_udc", (g)->name) | ||
38 | #else | ||
39 | #define gadget_is_pxa(g) 0 | ||
40 | #endif | ||
41 | |||
42 | #ifdef CONFIG_USB_GADGET_GOKU | ||
43 | #define gadget_is_goku(g) !strcmp("goku_udc", (g)->name) | ||
44 | #else | ||
45 | #define gadget_is_goku(g) 0 | ||
46 | #endif | ||
47 | |||
48 | #ifdef CONFIG_USB_GADGET_OMAP | ||
49 | #define gadget_is_omap(g) !strcmp("omap_udc", (g)->name) | ||
50 | #else | ||
51 | #define gadget_is_omap(g) 0 | ||
52 | #endif | ||
53 | |||
54 | /* various unstable versions available */ | ||
55 | #ifdef CONFIG_USB_GADGET_PXA27X | ||
56 | #define gadget_is_pxa27x(g) !strcmp("pxa27x_udc", (g)->name) | ||
57 | #else | ||
58 | #define gadget_is_pxa27x(g) 0 | ||
59 | #endif | ||
60 | |||
61 | #ifdef CONFIG_USB_GADGET_ATMEL_USBA | ||
62 | #define gadget_is_atmel_usba(g) !strcmp("atmel_usba_udc", (g)->name) | ||
63 | #else | ||
64 | #define gadget_is_atmel_usba(g) 0 | ||
65 | #endif | ||
66 | |||
67 | #ifdef CONFIG_USB_GADGET_S3C2410 | ||
68 | #define gadget_is_s3c2410(g) !strcmp("s3c2410_udc", (g)->name) | ||
69 | #else | ||
70 | #define gadget_is_s3c2410(g) 0 | ||
71 | #endif | ||
72 | |||
73 | #ifdef CONFIG_USB_GADGET_AT91 | ||
74 | #define gadget_is_at91(g) !strcmp("at91_udc", (g)->name) | ||
75 | #else | ||
76 | #define gadget_is_at91(g) 0 | ||
77 | #endif | ||
78 | |||
79 | #ifdef CONFIG_USB_GADGET_IMX | ||
80 | #define gadget_is_imx(g) !strcmp("imx_udc", (g)->name) | ||
81 | #else | ||
82 | #define gadget_is_imx(g) 0 | ||
83 | #endif | ||
84 | |||
85 | #ifdef CONFIG_USB_GADGET_FSL_USB2 | ||
86 | #define gadget_is_fsl_usb2(g) !strcmp("fsl-usb2-udc", (g)->name) | ||
87 | #else | ||
88 | #define gadget_is_fsl_usb2(g) 0 | ||
89 | #endif | ||
90 | |||
91 | /* Mentor high speed "dual role" controller, in peripheral role */ | ||
92 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC | ||
93 | #define gadget_is_musbhdrc(g) !strcmp("musb-hdrc", (g)->name) | ||
94 | #else | ||
95 | #define gadget_is_musbhdrc(g) 0 | ||
96 | #endif | ||
97 | |||
98 | #ifdef CONFIG_USB_GADGET_LANGWELL | ||
99 | #define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name)) | ||
100 | #else | ||
101 | #define gadget_is_langwell(g) 0 | ||
102 | #endif | ||
103 | |||
104 | #ifdef CONFIG_USB_GADGET_M66592 | ||
105 | #define gadget_is_m66592(g) !strcmp("m66592_udc", (g)->name) | ||
106 | #else | ||
107 | #define gadget_is_m66592(g) 0 | ||
108 | #endif | ||
109 | |||
110 | /* Freescale CPM/QE UDC SUPPORT */ | ||
111 | #ifdef CONFIG_USB_GADGET_FSL_QE | ||
112 | #define gadget_is_fsl_qe(g) !strcmp("fsl_qe_udc", (g)->name) | ||
113 | #else | ||
114 | #define gadget_is_fsl_qe(g) 0 | ||
115 | #endif | ||
116 | |||
117 | #ifdef CONFIG_USB_GADGET_CI13XXX_PCI | ||
118 | #define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name)) | ||
119 | #else | ||
120 | #define gadget_is_ci13xxx_pci(g) 0 | ||
121 | #endif | ||
122 | |||
123 | // CONFIG_USB_GADGET_SX2 | ||
124 | // CONFIG_USB_GADGET_AU1X00 | ||
125 | // ... | ||
126 | |||
127 | #ifdef CONFIG_USB_GADGET_R8A66597 | ||
128 | #define gadget_is_r8a66597(g) !strcmp("r8a66597_udc", (g)->name) | ||
129 | #else | ||
130 | #define gadget_is_r8a66597(g) 0 | ||
131 | #endif | ||
132 | |||
133 | #ifdef CONFIG_USB_S3C_HSOTG | ||
134 | #define gadget_is_s3c_hsotg(g) (!strcmp("s3c-hsotg", (g)->name)) | ||
135 | #else | ||
136 | #define gadget_is_s3c_hsotg(g) 0 | ||
137 | #endif | ||
138 | |||
139 | #ifdef CONFIG_USB_S3C_HSUDC | ||
140 | #define gadget_is_s3c_hsudc(g) (!strcmp("s3c-hsudc", (g)->name)) | ||
141 | #else | ||
142 | #define gadget_is_s3c_hsudc(g) 0 | ||
143 | #endif | ||
144 | |||
145 | #ifdef CONFIG_USB_GADGET_EG20T | ||
146 | #define gadget_is_pch(g) (!strcmp("pch_udc", (g)->name)) | ||
147 | #else | ||
148 | #define gadget_is_pch(g) 0 | ||
149 | #endif | ||
150 | |||
151 | #ifdef CONFIG_USB_GADGET_CI13XXX_MSM | ||
152 | #define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name)) | 31 | #define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name)) |
153 | #else | 32 | #define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name)) |
154 | #define gadget_is_ci13xxx_msm(g) 0 | 33 | #define gadget_is_dummy(g) (!strcmp("dummy_udc", (g)->name)) |
155 | #endif | 34 | #define gadget_is_fsl_qe(g) (!strcmp("fsl_qe_udc", (g)->name)) |
156 | 35 | #define gadget_is_fsl_usb2(g) (!strcmp("fsl-usb2-udc", (g)->name)) | |
157 | #ifdef CONFIG_USB_GADGET_RENESAS_USBHS | 36 | #define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name)) |
158 | #define gadget_is_renesas_usbhs(g) (!strcmp("renesas_usbhs_udc", (g)->name)) | 37 | #define gadget_is_imx(g) (!strcmp("imx_udc", (g)->name)) |
159 | #else | 38 | #define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name)) |
160 | #define gadget_is_renesas_usbhs(g) 0 | 39 | #define gadget_is_m66592(g) (!strcmp("m66592_udc", (g)->name)) |
161 | #endif | 40 | #define gadget_is_musbhdrc(g) (!strcmp("musb-hdrc", (g)->name)) |
41 | #define gadget_is_net2272(g) (!strcmp("net2272", (g)->name)) | ||
42 | #define gadget_is_net2280(g) (!strcmp("net2280", (g)->name)) | ||
43 | #define gadget_is_omap(g) (!strcmp("omap_udc", (g)->name)) | ||
44 | #define gadget_is_pch(g) (!strcmp("pch_udc", (g)->name)) | ||
45 | #define gadget_is_pxa(g) (!strcmp("pxa25x_udc", (g)->name)) | ||
46 | #define gadget_is_pxa27x(g) (!strcmp("pxa27x_udc", (g)->name)) | ||
47 | #define gadget_is_r8a66597(g) (!strcmp("r8a66597_udc", (g)->name)) | ||
48 | #define gadget_is_renesas_usbhs(g) (!strcmp("renesas_usbhs_udc", (g)->name)) | ||
49 | #define gadget_is_s3c2410(g) (!strcmp("s3c2410_udc", (g)->name)) | ||
50 | #define gadget_is_s3c_hsotg(g) (!strcmp("s3c-hsotg", (g)->name)) | ||
51 | #define gadget_is_s3c_hsudc(g) (!strcmp("s3c-hsudc", (g)->name)) | ||
162 | 52 | ||
163 | /** | 53 | /** |
164 | * usb_gadget_controller_number - support bcdDevice id convention | 54 | * usb_gadget_controller_number - support bcdDevice id convention |
@@ -223,6 +113,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
223 | return 0x29; | 113 | return 0x29; |
224 | else if (gadget_is_s3c_hsudc(gadget)) | 114 | else if (gadget_is_s3c_hsudc(gadget)) |
225 | return 0x30; | 115 | return 0x30; |
116 | else if (gadget_is_net2272(gadget)) | ||
117 | return 0x31; | ||
226 | 118 | ||
227 | return -ENOENT; | 119 | return -ENOENT; |
228 | } | 120 | } |
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index 47b86b99d449..8b9220e128a7 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c | |||
@@ -537,14 +537,16 @@ static int set_gmidi_config(struct gmidi_device *dev, gfp_t gfp_flags) | |||
537 | struct usb_ep *ep; | 537 | struct usb_ep *ep; |
538 | unsigned i; | 538 | unsigned i; |
539 | 539 | ||
540 | err = usb_ep_enable(dev->in_ep, &bulk_in_desc); | 540 | dev->in_ep->desc = &bulk_in_desc; |
541 | err = usb_ep_enable(dev->in_ep); | ||
541 | if (err) { | 542 | if (err) { |
542 | ERROR(dev, "can't start %s: %d\n", dev->in_ep->name, err); | 543 | ERROR(dev, "can't start %s: %d\n", dev->in_ep->name, err); |
543 | goto fail; | 544 | goto fail; |
544 | } | 545 | } |
545 | dev->in_ep->driver_data = dev; | 546 | dev->in_ep->driver_data = dev; |
546 | 547 | ||
547 | err = usb_ep_enable(dev->out_ep, &bulk_out_desc); | 548 | dev->out_ep->desc = &bulk_out_desc; |
549 | err = usb_ep_enable(dev->out_ep); | ||
548 | if (err) { | 550 | if (err) { |
549 | ERROR(dev, "can't start %s: %d\n", dev->out_ep->name, err); | 551 | ERROR(dev, "can't start %s: %d\n", dev->out_ep->name, err); |
550 | goto fail; | 552 | goto fail; |
@@ -693,6 +695,7 @@ static int gmidi_setup(struct usb_gadget *gadget, | |||
693 | switch (w_value >> 8) { | 695 | switch (w_value >> 8) { |
694 | 696 | ||
695 | case USB_DT_DEVICE: | 697 | case USB_DT_DEVICE: |
698 | device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; | ||
696 | value = min(w_length, (u16) sizeof(device_desc)); | 699 | value = min(w_length, (u16) sizeof(device_desc)); |
697 | memcpy(req->buf, &device_desc, value); | 700 | memcpy(req->buf, &device_desc, value); |
698 | break; | 701 | break; |
@@ -1247,8 +1250,6 @@ autoconf_fail: | |||
1247 | 1250 | ||
1248 | dev->req->complete = gmidi_setup_complete; | 1251 | dev->req->complete = gmidi_setup_complete; |
1249 | 1252 | ||
1250 | device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; | ||
1251 | |||
1252 | gadget->ep0->driver_data = dev; | 1253 | gadget->ep0->driver_data = dev; |
1253 | 1254 | ||
1254 | INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname); | 1255 | INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname); |
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c index bf6e11c758d5..7f87805cddc4 100644 --- a/drivers/usb/gadget/goku_udc.c +++ b/drivers/usb/gadget/goku_udc.c | |||
@@ -996,8 +996,14 @@ static int goku_get_frame(struct usb_gadget *_gadget) | |||
996 | return -EOPNOTSUPP; | 996 | return -EOPNOTSUPP; |
997 | } | 997 | } |
998 | 998 | ||
999 | static int goku_start(struct usb_gadget_driver *driver, | ||
1000 | int (*bind)(struct usb_gadget *)); | ||
1001 | static int goku_stop(struct usb_gadget_driver *driver); | ||
1002 | |||
999 | static const struct usb_gadget_ops goku_ops = { | 1003 | static const struct usb_gadget_ops goku_ops = { |
1000 | .get_frame = goku_get_frame, | 1004 | .get_frame = goku_get_frame, |
1005 | .start = goku_start, | ||
1006 | .stop = goku_stop, | ||
1001 | // no remote wakeup | 1007 | // no remote wakeup |
1002 | // not selfpowered | 1008 | // not selfpowered |
1003 | }; | 1009 | }; |
@@ -1344,7 +1350,7 @@ static struct goku_udc *the_controller; | |||
1344 | * disconnect is reported. then a host may connect again, or | 1350 | * disconnect is reported. then a host may connect again, or |
1345 | * the driver might get unbound. | 1351 | * the driver might get unbound. |
1346 | */ | 1352 | */ |
1347 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1353 | static int goku_start(struct usb_gadget_driver *driver, |
1348 | int (*bind)(struct usb_gadget *)) | 1354 | int (*bind)(struct usb_gadget *)) |
1349 | { | 1355 | { |
1350 | struct goku_udc *dev = the_controller; | 1356 | struct goku_udc *dev = the_controller; |
@@ -1382,7 +1388,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
1382 | DBG(dev, "registered gadget driver '%s'\n", driver->driver.name); | 1388 | DBG(dev, "registered gadget driver '%s'\n", driver->driver.name); |
1383 | return 0; | 1389 | return 0; |
1384 | } | 1390 | } |
1385 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1386 | 1391 | ||
1387 | static void | 1392 | static void |
1388 | stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver) | 1393 | stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver) |
@@ -1408,7 +1413,7 @@ stop_activity(struct goku_udc *dev, struct usb_gadget_driver *driver) | |||
1408 | udc_enable(dev); | 1413 | udc_enable(dev); |
1409 | } | 1414 | } |
1410 | 1415 | ||
1411 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1416 | static int goku_stop(struct usb_gadget_driver *driver) |
1412 | { | 1417 | { |
1413 | struct goku_udc *dev = the_controller; | 1418 | struct goku_udc *dev = the_controller; |
1414 | unsigned long flags; | 1419 | unsigned long flags; |
@@ -1429,8 +1434,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1429 | DBG(dev, "unregistered driver '%s'\n", driver->driver.name); | 1434 | DBG(dev, "unregistered driver '%s'\n", driver->driver.name); |
1430 | return 0; | 1435 | return 0; |
1431 | } | 1436 | } |
1432 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1433 | |||
1434 | 1437 | ||
1435 | /*-------------------------------------------------------------------------*/ | 1438 | /*-------------------------------------------------------------------------*/ |
1436 | 1439 | ||
@@ -1730,6 +1733,8 @@ static void goku_remove(struct pci_dev *pdev) | |||
1730 | 1733 | ||
1731 | DBG(dev, "%s\n", __func__); | 1734 | DBG(dev, "%s\n", __func__); |
1732 | 1735 | ||
1736 | usb_del_gadget_udc(&dev->gadget); | ||
1737 | |||
1733 | BUG_ON(dev->driver); | 1738 | BUG_ON(dev->driver); |
1734 | 1739 | ||
1735 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | 1740 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
@@ -1854,6 +1859,10 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |||
1854 | goto err; | 1859 | goto err; |
1855 | } | 1860 | } |
1856 | dev->registered = 1; | 1861 | dev->registered = 1; |
1862 | retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); | ||
1863 | if (retval) | ||
1864 | goto err; | ||
1865 | |||
1857 | return 0; | 1866 | return 0; |
1858 | 1867 | ||
1859 | err: | 1868 | err: |
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c index 2523e54097bd..9fb575034a0e 100644 --- a/drivers/usb/gadget/hid.c +++ b/drivers/usb/gadget/hid.c | |||
@@ -255,6 +255,7 @@ static struct usb_composite_driver hidg_driver = { | |||
255 | .name = "g_hid", | 255 | .name = "g_hid", |
256 | .dev = &device_desc, | 256 | .dev = &device_desc, |
257 | .strings = dev_strings, | 257 | .strings = dev_strings, |
258 | .max_speed = USB_SPEED_HIGH, | ||
258 | .unbind = __exit_p(hid_unbind), | 259 | .unbind = __exit_p(hid_unbind), |
259 | }; | 260 | }; |
260 | 261 | ||
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c index ade40066decf..692fd9b2248b 100644 --- a/drivers/usb/gadget/imx_udc.c +++ b/drivers/usb/gadget/imx_udc.c | |||
@@ -1237,9 +1237,14 @@ irq_handler_t intr_handler(int i) | |||
1237 | ******************************************************************************* | 1237 | ******************************************************************************* |
1238 | */ | 1238 | */ |
1239 | 1239 | ||
1240 | static int imx_udc_start(struct usb_gadget_driver *driver, | ||
1241 | int (*bind)(struct usb_gadget *)); | ||
1242 | static int imx_udc_stop(struct usb_gadget_driver *driver); | ||
1240 | static const struct usb_gadget_ops imx_udc_ops = { | 1243 | static const struct usb_gadget_ops imx_udc_ops = { |
1241 | .get_frame = imx_udc_get_frame, | 1244 | .get_frame = imx_udc_get_frame, |
1242 | .wakeup = imx_udc_wakeup, | 1245 | .wakeup = imx_udc_wakeup, |
1246 | .start = imx_udc_start, | ||
1247 | .stop = imx_udc_stop, | ||
1243 | }; | 1248 | }; |
1244 | 1249 | ||
1245 | static struct imx_udc_struct controller = { | 1250 | static struct imx_udc_struct controller = { |
@@ -1324,7 +1329,7 @@ static struct imx_udc_struct controller = { | |||
1324 | * USB gadget driver functions | 1329 | * USB gadget driver functions |
1325 | ******************************************************************************* | 1330 | ******************************************************************************* |
1326 | */ | 1331 | */ |
1327 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1332 | static int imx_udc_start(struct usb_gadget_driver *driver, |
1328 | int (*bind)(struct usb_gadget *)) | 1333 | int (*bind)(struct usb_gadget *)) |
1329 | { | 1334 | { |
1330 | struct imx_udc_struct *imx_usb = &controller; | 1335 | struct imx_udc_struct *imx_usb = &controller; |
@@ -1368,9 +1373,8 @@ fail: | |||
1368 | imx_usb->gadget.dev.driver = NULL; | 1373 | imx_usb->gadget.dev.driver = NULL; |
1369 | return retval; | 1374 | return retval; |
1370 | } | 1375 | } |
1371 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1372 | 1376 | ||
1373 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1377 | static int imx_udc_stop(struct usb_gadget_driver *driver) |
1374 | { | 1378 | { |
1375 | struct imx_udc_struct *imx_usb = &controller; | 1379 | struct imx_udc_struct *imx_usb = &controller; |
1376 | 1380 | ||
@@ -1394,7 +1398,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1394 | 1398 | ||
1395 | return 0; | 1399 | return 0; |
1396 | } | 1400 | } |
1397 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1398 | 1401 | ||
1399 | /******************************************************************************* | 1402 | /******************************************************************************* |
1400 | * Module functions | 1403 | * Module functions |
@@ -1504,8 +1507,14 @@ static int __init imx_udc_probe(struct platform_device *pdev) | |||
1504 | imx_usb->timer.function = handle_config; | 1507 | imx_usb->timer.function = handle_config; |
1505 | imx_usb->timer.data = (unsigned long)imx_usb; | 1508 | imx_usb->timer.data = (unsigned long)imx_usb; |
1506 | 1509 | ||
1507 | return 0; | 1510 | ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget); |
1511 | if (ret) | ||
1512 | goto fail4; | ||
1508 | 1513 | ||
1514 | return 0; | ||
1515 | fail4: | ||
1516 | for (i = 0; i < IMX_USB_NB_EP + 1; i++) | ||
1517 | free_irq(imx_usb->usbd_int[i], imx_usb); | ||
1509 | fail3: | 1518 | fail3: |
1510 | clk_put(clk); | 1519 | clk_put(clk); |
1511 | clk_disable(clk); | 1520 | clk_disable(clk); |
@@ -1525,6 +1534,7 @@ static int __exit imx_udc_remove(struct platform_device *pdev) | |||
1525 | struct imxusb_platform_data *pdata = pdev->dev.platform_data; | 1534 | struct imxusb_platform_data *pdata = pdev->dev.platform_data; |
1526 | int i; | 1535 | int i; |
1527 | 1536 | ||
1537 | usb_del_gadget_udc(&imx_usb->gadget); | ||
1528 | imx_udc_disable(imx_usb); | 1538 | imx_udc_disable(imx_usb); |
1529 | del_timer(&imx_usb->timer); | 1539 | del_timer(&imx_usb->timer); |
1530 | 1540 | ||
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index a56876aaf76c..1b240990448f 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c | |||
@@ -832,14 +832,16 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) | |||
832 | switch (data->dev->gadget->speed) { | 832 | switch (data->dev->gadget->speed) { |
833 | case USB_SPEED_LOW: | 833 | case USB_SPEED_LOW: |
834 | case USB_SPEED_FULL: | 834 | case USB_SPEED_FULL: |
835 | value = usb_ep_enable (ep, &data->desc); | 835 | ep->desc = &data->desc; |
836 | value = usb_ep_enable(ep); | ||
836 | if (value == 0) | 837 | if (value == 0) |
837 | data->state = STATE_EP_ENABLED; | 838 | data->state = STATE_EP_ENABLED; |
838 | break; | 839 | break; |
839 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 840 | #ifdef CONFIG_USB_GADGET_DUALSPEED |
840 | case USB_SPEED_HIGH: | 841 | case USB_SPEED_HIGH: |
841 | /* fails if caller didn't provide that descriptor... */ | 842 | /* fails if caller didn't provide that descriptor... */ |
842 | value = usb_ep_enable (ep, &data->hs_desc); | 843 | ep->desc = &data->hs_desc; |
844 | value = usb_ep_enable(ep); | ||
843 | if (value == 0) | 845 | if (value == 0) |
844 | data->state = STATE_EP_ENABLED; | 846 | data->state = STATE_EP_ENABLED; |
845 | break; | 847 | break; |
@@ -1345,7 +1347,7 @@ static void make_qualifier (struct dev_data *dev) | |||
1345 | qual.bDeviceProtocol = desc->bDeviceProtocol; | 1347 | qual.bDeviceProtocol = desc->bDeviceProtocol; |
1346 | 1348 | ||
1347 | /* assumes ep0 uses the same value for both speeds ... */ | 1349 | /* assumes ep0 uses the same value for both speeds ... */ |
1348 | qual.bMaxPacketSize0 = desc->bMaxPacketSize0; | 1350 | qual.bMaxPacketSize0 = dev->gadget->ep0->maxpacket; |
1349 | 1351 | ||
1350 | qual.bNumConfigurations = 1; | 1352 | qual.bNumConfigurations = 1; |
1351 | qual.bRESERVED = 0; | 1353 | qual.bRESERVED = 0; |
@@ -1402,7 +1404,6 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1402 | } | 1404 | } |
1403 | 1405 | ||
1404 | dev->state = STATE_DEV_CONNECTED; | 1406 | dev->state = STATE_DEV_CONNECTED; |
1405 | dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket; | ||
1406 | 1407 | ||
1407 | INFO (dev, "connected\n"); | 1408 | INFO (dev, "connected\n"); |
1408 | event = next_event (dev, GADGETFS_CONNECT); | 1409 | event = next_event (dev, GADGETFS_CONNECT); |
@@ -1430,6 +1431,7 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1430 | 1431 | ||
1431 | case USB_DT_DEVICE: | 1432 | case USB_DT_DEVICE: |
1432 | value = min (w_length, (u16) sizeof *dev->dev); | 1433 | value = min (w_length, (u16) sizeof *dev->dev); |
1434 | dev->dev->bMaxPacketSize0 = dev->gadget->ep0->maxpacket; | ||
1433 | req->buf = dev->dev; | 1435 | req->buf = dev->dev; |
1434 | break; | 1436 | break; |
1435 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 1437 | #ifdef CONFIG_USB_GADGET_DUALSPEED |
@@ -1710,7 +1712,6 @@ gadgetfs_bind (struct usb_gadget *gadget) | |||
1710 | set_gadget_data (gadget, dev); | 1712 | set_gadget_data (gadget, dev); |
1711 | dev->gadget = gadget; | 1713 | dev->gadget = gadget; |
1712 | gadget->ep0->driver_data = dev; | 1714 | gadget->ep0->driver_data = dev; |
1713 | dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket; | ||
1714 | 1715 | ||
1715 | /* preallocate control response and buffer */ | 1716 | /* preallocate control response and buffer */ |
1716 | dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL); | 1717 | dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL); |
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c index 9cee88a43a73..a06e2c27b435 100644 --- a/drivers/usb/gadget/langwell_udc.c +++ b/drivers/usb/gadget/langwell_udc.c | |||
@@ -593,8 +593,8 @@ static int queue_dtd(struct langwell_ep *ep, struct langwell_request *req) | |||
593 | /* ep0 */ | 593 | /* ep0 */ |
594 | dev_vdbg(&dev->pdev->dev, "%s-%s\n", ep->name, DIR_STRING(ep)); | 594 | dev_vdbg(&dev->pdev->dev, "%s-%s\n", ep->name, DIR_STRING(ep)); |
595 | 595 | ||
596 | dev_vdbg(&dev->pdev->dev, "ep_dqh[%d] addr: 0x%08x\n", | 596 | dev_vdbg(&dev->pdev->dev, "ep_dqh[%d] addr: 0x%p\n", |
597 | i, (u32)&(dev->ep_dqh[i])); | 597 | i, &(dev->ep_dqh[i])); |
598 | 598 | ||
599 | bit_mask = is_in(ep) ? | 599 | bit_mask = is_in(ep) ? |
600 | (1 << (ep->ep_num + 16)) : (1 << (ep->ep_num)); | 600 | (1 << (ep->ep_num + 16)) : (1 << (ep->ep_num)); |
@@ -1321,7 +1321,9 @@ static int langwell_pullup(struct usb_gadget *_gadget, int is_on) | |||
1321 | return 0; | 1321 | return 0; |
1322 | } | 1322 | } |
1323 | 1323 | ||
1324 | 1324 | static int langwell_start(struct usb_gadget_driver *driver, | |
1325 | int (*bind)(struct usb_gadget *)); | ||
1326 | static int langwell_stop(struct usb_gadget_driver *driver); | ||
1325 | /* device controller usb_gadget_ops structure */ | 1327 | /* device controller usb_gadget_ops structure */ |
1326 | static const struct usb_gadget_ops langwell_ops = { | 1328 | static const struct usb_gadget_ops langwell_ops = { |
1327 | 1329 | ||
@@ -1342,6 +1344,9 @@ static const struct usb_gadget_ops langwell_ops = { | |||
1342 | 1344 | ||
1343 | /* D+ pullup, software-controlled connect/disconnect to USB host */ | 1345 | /* D+ pullup, software-controlled connect/disconnect to USB host */ |
1344 | .pullup = langwell_pullup, | 1346 | .pullup = langwell_pullup, |
1347 | |||
1348 | .start = langwell_start, | ||
1349 | .stop = langwell_stop, | ||
1345 | }; | 1350 | }; |
1346 | 1351 | ||
1347 | 1352 | ||
@@ -1852,7 +1857,7 @@ static DEVICE_ATTR(remote_wakeup, S_IWUSR, NULL, store_remote_wakeup); | |||
1852 | * the driver might get unbound. | 1857 | * the driver might get unbound. |
1853 | */ | 1858 | */ |
1854 | 1859 | ||
1855 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1860 | static int langwell_start(struct usb_gadget_driver *driver, |
1856 | int (*bind)(struct usb_gadget *)) | 1861 | int (*bind)(struct usb_gadget *)) |
1857 | { | 1862 | { |
1858 | struct langwell_udc *dev = the_controller; | 1863 | struct langwell_udc *dev = the_controller; |
@@ -1914,11 +1919,9 @@ err_unbind: | |||
1914 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | 1919 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); |
1915 | return retval; | 1920 | return retval; |
1916 | } | 1921 | } |
1917 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1918 | |||
1919 | 1922 | ||
1920 | /* unregister gadget driver */ | 1923 | /* unregister gadget driver */ |
1921 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1924 | static int langwell_stop(struct usb_gadget_driver *driver) |
1922 | { | 1925 | { |
1923 | struct langwell_udc *dev = the_controller; | 1926 | struct langwell_udc *dev = the_controller; |
1924 | unsigned long flags; | 1927 | unsigned long flags; |
@@ -1965,8 +1968,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1965 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | 1968 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); |
1966 | return 0; | 1969 | return 0; |
1967 | } | 1970 | } |
1968 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1969 | |||
1970 | 1971 | ||
1971 | /*-------------------------------------------------------------------------*/ | 1972 | /*-------------------------------------------------------------------------*/ |
1972 | 1973 | ||
@@ -3270,7 +3271,7 @@ static int langwell_udc_probe(struct pci_dev *pdev, | |||
3270 | 3271 | ||
3271 | /* allocate device dQH memory */ | 3272 | /* allocate device dQH memory */ |
3272 | size = dev->ep_max * sizeof(struct langwell_dqh); | 3273 | size = dev->ep_max * sizeof(struct langwell_dqh); |
3273 | dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size); | 3274 | dev_vdbg(&dev->pdev->dev, "orig size = %zd\n", size); |
3274 | if (size < DQH_ALIGNMENT) | 3275 | if (size < DQH_ALIGNMENT) |
3275 | size = DQH_ALIGNMENT; | 3276 | size = DQH_ALIGNMENT; |
3276 | else if ((size % DQH_ALIGNMENT) != 0) { | 3277 | else if ((size % DQH_ALIGNMENT) != 0) { |
@@ -3285,7 +3286,7 @@ static int langwell_udc_probe(struct pci_dev *pdev, | |||
3285 | goto error; | 3286 | goto error; |
3286 | } | 3287 | } |
3287 | dev->ep_dqh_size = size; | 3288 | dev->ep_dqh_size = size; |
3288 | dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size); | 3289 | dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %zd\n", dev->ep_dqh_size); |
3289 | 3290 | ||
3290 | /* initialize ep0 status request structure */ | 3291 | /* initialize ep0 status request structure */ |
3291 | dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL); | 3292 | dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL); |
@@ -3373,6 +3374,10 @@ static int langwell_udc_probe(struct pci_dev *pdev, | |||
3373 | if (retval) | 3374 | if (retval) |
3374 | goto error; | 3375 | goto error; |
3375 | 3376 | ||
3377 | retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); | ||
3378 | if (retval) | ||
3379 | goto error; | ||
3380 | |||
3376 | retval = device_create_file(&pdev->dev, &dev_attr_langwell_udc); | 3381 | retval = device_create_file(&pdev->dev, &dev_attr_langwell_udc); |
3377 | if (retval) | 3382 | if (retval) |
3378 | goto error; | 3383 | goto error; |
@@ -3403,6 +3408,7 @@ static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state) | |||
3403 | 3408 | ||
3404 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | 3409 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); |
3405 | 3410 | ||
3411 | usb_del_gadget_udc(&dev->gadget); | ||
3406 | /* disable interrupt and set controller to stop state */ | 3412 | /* disable interrupt and set controller to stop state */ |
3407 | langwell_udc_stop(dev); | 3413 | langwell_udc_stop(dev); |
3408 | 3414 | ||
@@ -3464,7 +3470,7 @@ static int langwell_udc_resume(struct pci_dev *pdev) | |||
3464 | 3470 | ||
3465 | /* allocate device dQH memory */ | 3471 | /* allocate device dQH memory */ |
3466 | size = dev->ep_max * sizeof(struct langwell_dqh); | 3472 | size = dev->ep_max * sizeof(struct langwell_dqh); |
3467 | dev_vdbg(&dev->pdev->dev, "orig size = %d\n", size); | 3473 | dev_vdbg(&dev->pdev->dev, "orig size = %zd\n", size); |
3468 | if (size < DQH_ALIGNMENT) | 3474 | if (size < DQH_ALIGNMENT) |
3469 | size = DQH_ALIGNMENT; | 3475 | size = DQH_ALIGNMENT; |
3470 | else if ((size % DQH_ALIGNMENT) != 0) { | 3476 | else if ((size % DQH_ALIGNMENT) != 0) { |
@@ -3478,7 +3484,7 @@ static int langwell_udc_resume(struct pci_dev *pdev) | |||
3478 | return -ENOMEM; | 3484 | return -ENOMEM; |
3479 | } | 3485 | } |
3480 | dev->ep_dqh_size = size; | 3486 | dev->ep_dqh_size = size; |
3481 | dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %d\n", dev->ep_dqh_size); | 3487 | dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %zd\n", dev->ep_dqh_size); |
3482 | 3488 | ||
3483 | /* create dTD dma_pool resource */ | 3489 | /* create dTD dma_pool resource */ |
3484 | dev->dtd_pool = dma_pool_create("langwell_dtd", | 3490 | dev->dtd_pool = dma_pool_create("langwell_dtd", |
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 084aa080a2d5..491f825ed5c9 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) 2006-2007 Renesas Solutions Corp. | 4 | * Copyright (C) 2006-2007 Renesas Solutions Corp. |
5 | * | 5 | * |
6 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> | 6 | * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
@@ -691,6 +691,7 @@ static void init_controller(struct m66592 *m66592) | |||
691 | 691 | ||
692 | static void disable_controller(struct m66592 *m66592) | 692 | static void disable_controller(struct m66592 *m66592) |
693 | { | 693 | { |
694 | m66592_bclr(m66592, M66592_UTST, M66592_TESTMODE); | ||
694 | if (!m66592->pdata->on_chip) { | 695 | if (!m66592->pdata->on_chip) { |
695 | m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG); | 696 | m66592_bclr(m66592, M66592_SCKE, M66592_SYSCFG); |
696 | udelay(1); | 697 | udelay(1); |
@@ -780,7 +781,7 @@ static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req) | |||
780 | /* write fifo */ | 781 | /* write fifo */ |
781 | if (req->req.buf) { | 782 | if (req->req.buf) { |
782 | if (size > 0) | 783 | if (size > 0) |
783 | m66592_write_fifo(m66592, ep->fifoaddr, buf, size); | 784 | m66592_write_fifo(m66592, ep, buf, size); |
784 | if ((size == 0) || ((size % ep->ep.maxpacket) != 0)) | 785 | if ((size == 0) || ((size % ep->ep.maxpacket) != 0)) |
785 | m66592_bset(m66592, M66592_BVAL, ep->fifoctr); | 786 | m66592_bset(m66592, M66592_BVAL, ep->fifoctr); |
786 | } | 787 | } |
@@ -826,7 +827,7 @@ static void irq_packet_write(struct m66592_ep *ep, struct m66592_request *req) | |||
826 | 827 | ||
827 | /* write fifo */ | 828 | /* write fifo */ |
828 | if (req->req.buf) { | 829 | if (req->req.buf) { |
829 | m66592_write_fifo(m66592, ep->fifoaddr, buf, size); | 830 | m66592_write_fifo(m66592, ep, buf, size); |
830 | if ((size == 0) | 831 | if ((size == 0) |
831 | || ((size % ep->ep.maxpacket) != 0) | 832 | || ((size % ep->ep.maxpacket) != 0) |
832 | || ((bufsize != ep->ep.maxpacket) | 833 | || ((bufsize != ep->ep.maxpacket) |
@@ -1048,10 +1049,30 @@ static void clear_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) | |||
1048 | 1049 | ||
1049 | static void set_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) | 1050 | static void set_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) |
1050 | { | 1051 | { |
1052 | u16 tmp; | ||
1053 | int timeout = 3000; | ||
1051 | 1054 | ||
1052 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | 1055 | switch (ctrl->bRequestType & USB_RECIP_MASK) { |
1053 | case USB_RECIP_DEVICE: | 1056 | case USB_RECIP_DEVICE: |
1054 | control_end(m66592, 1); | 1057 | switch (le16_to_cpu(ctrl->wValue)) { |
1058 | case USB_DEVICE_TEST_MODE: | ||
1059 | control_end(m66592, 1); | ||
1060 | /* Wait for the completion of status stage */ | ||
1061 | do { | ||
1062 | tmp = m66592_read(m66592, M66592_INTSTS0) & | ||
1063 | M66592_CTSQ; | ||
1064 | udelay(1); | ||
1065 | } while (tmp != M66592_CS_IDST || timeout-- > 0); | ||
1066 | |||
1067 | if (tmp == M66592_CS_IDST) | ||
1068 | m66592_bset(m66592, | ||
1069 | le16_to_cpu(ctrl->wIndex >> 8), | ||
1070 | M66592_TESTMODE); | ||
1071 | break; | ||
1072 | default: | ||
1073 | pipe_stall(m66592, 0); | ||
1074 | break; | ||
1075 | } | ||
1055 | break; | 1076 | break; |
1056 | case USB_RECIP_INTERFACE: | 1077 | case USB_RECIP_INTERFACE: |
1057 | control_end(m66592, 1); | 1078 | control_end(m66592, 1); |
@@ -1454,7 +1475,7 @@ static struct usb_ep_ops m66592_ep_ops = { | |||
1454 | /*-------------------------------------------------------------------------*/ | 1475 | /*-------------------------------------------------------------------------*/ |
1455 | static struct m66592 *the_controller; | 1476 | static struct m66592 *the_controller; |
1456 | 1477 | ||
1457 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1478 | static int m66592_start(struct usb_gadget_driver *driver, |
1458 | int (*bind)(struct usb_gadget *)) | 1479 | int (*bind)(struct usb_gadget *)) |
1459 | { | 1480 | { |
1460 | struct m66592 *m66592 = the_controller; | 1481 | struct m66592 *m66592 = the_controller; |
@@ -1506,9 +1527,8 @@ error: | |||
1506 | 1527 | ||
1507 | return retval; | 1528 | return retval; |
1508 | } | 1529 | } |
1509 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1510 | 1530 | ||
1511 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1531 | static int m66592_stop(struct usb_gadget_driver *driver) |
1512 | { | 1532 | { |
1513 | struct m66592 *m66592 = the_controller; | 1533 | struct m66592 *m66592 = the_controller; |
1514 | unsigned long flags; | 1534 | unsigned long flags; |
@@ -1533,7 +1553,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1533 | m66592->driver = NULL; | 1553 | m66592->driver = NULL; |
1534 | return 0; | 1554 | return 0; |
1535 | } | 1555 | } |
1536 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1537 | 1556 | ||
1538 | /*-------------------------------------------------------------------------*/ | 1557 | /*-------------------------------------------------------------------------*/ |
1539 | static int m66592_get_frame(struct usb_gadget *_gadget) | 1558 | static int m66592_get_frame(struct usb_gadget *_gadget) |
@@ -1542,14 +1561,34 @@ static int m66592_get_frame(struct usb_gadget *_gadget) | |||
1542 | return m66592_read(m66592, M66592_FRMNUM) & 0x03FF; | 1561 | return m66592_read(m66592, M66592_FRMNUM) & 0x03FF; |
1543 | } | 1562 | } |
1544 | 1563 | ||
1564 | static int m66592_pullup(struct usb_gadget *gadget, int is_on) | ||
1565 | { | ||
1566 | struct m66592 *m66592 = gadget_to_m66592(gadget); | ||
1567 | unsigned long flags; | ||
1568 | |||
1569 | spin_lock_irqsave(&m66592->lock, flags); | ||
1570 | if (is_on) | ||
1571 | m66592_bset(m66592, M66592_DPRPU, M66592_SYSCFG); | ||
1572 | else | ||
1573 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); | ||
1574 | spin_unlock_irqrestore(&m66592->lock, flags); | ||
1575 | |||
1576 | return 0; | ||
1577 | } | ||
1578 | |||
1545 | static struct usb_gadget_ops m66592_gadget_ops = { | 1579 | static struct usb_gadget_ops m66592_gadget_ops = { |
1546 | .get_frame = m66592_get_frame, | 1580 | .get_frame = m66592_get_frame, |
1581 | .start = m66592_start, | ||
1582 | .stop = m66592_stop, | ||
1583 | .pullup = m66592_pullup, | ||
1547 | }; | 1584 | }; |
1548 | 1585 | ||
1549 | static int __exit m66592_remove(struct platform_device *pdev) | 1586 | static int __exit m66592_remove(struct platform_device *pdev) |
1550 | { | 1587 | { |
1551 | struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); | 1588 | struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); |
1552 | 1589 | ||
1590 | usb_del_gadget_udc(&m66592->gadget); | ||
1591 | |||
1553 | del_timer_sync(&m66592->timer); | 1592 | del_timer_sync(&m66592->timer); |
1554 | iounmap(m66592->reg); | 1593 | iounmap(m66592->reg); |
1555 | free_irq(platform_get_irq(pdev, 0), m66592); | 1594 | free_irq(platform_get_irq(pdev, 0), m66592); |
@@ -1691,9 +1730,16 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1691 | 1730 | ||
1692 | init_controller(m66592); | 1731 | init_controller(m66592); |
1693 | 1732 | ||
1733 | ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget); | ||
1734 | if (ret) | ||
1735 | goto err_add_udc; | ||
1736 | |||
1694 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); | 1737 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); |
1695 | return 0; | 1738 | return 0; |
1696 | 1739 | ||
1740 | err_add_udc: | ||
1741 | m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); | ||
1742 | |||
1697 | clean_up3: | 1743 | clean_up3: |
1698 | #ifdef CONFIG_HAVE_CLK | 1744 | #ifdef CONFIG_HAVE_CLK |
1699 | if (m66592->pdata->on_chip) { | 1745 | if (m66592->pdata->on_chip) { |
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h index c3caf1ac73ce..7b93d579af37 100644 --- a/drivers/usb/gadget/m66592-udc.h +++ b/drivers/usb/gadget/m66592-udc.h | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) 2006-2007 Renesas Solutions Corp. | 4 | * Copyright (C) 2006-2007 Renesas Solutions Corp. |
5 | * | 5 | * |
6 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> | 6 | * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
@@ -561,11 +561,26 @@ static inline void m66592_write(struct m66592 *m66592, u16 val, | |||
561 | iowrite16(val, m66592->reg + offset); | 561 | iowrite16(val, m66592->reg + offset); |
562 | } | 562 | } |
563 | 563 | ||
564 | static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat, | ||
565 | unsigned long offset) | ||
566 | { | ||
567 | u16 tmp; | ||
568 | tmp = m66592_read(m66592, offset); | ||
569 | tmp = tmp & (~pat); | ||
570 | tmp = tmp | val; | ||
571 | m66592_write(m66592, tmp, offset); | ||
572 | } | ||
573 | |||
574 | #define m66592_bclr(m66592, val, offset) \ | ||
575 | m66592_mdfy(m66592, 0, val, offset) | ||
576 | #define m66592_bset(m66592, val, offset) \ | ||
577 | m66592_mdfy(m66592, val, 0, offset) | ||
578 | |||
564 | static inline void m66592_write_fifo(struct m66592 *m66592, | 579 | static inline void m66592_write_fifo(struct m66592 *m66592, |
565 | unsigned long offset, | 580 | struct m66592_ep *ep, |
566 | void *buf, unsigned long len) | 581 | void *buf, unsigned long len) |
567 | { | 582 | { |
568 | void __iomem *fifoaddr = m66592->reg + offset; | 583 | void __iomem *fifoaddr = m66592->reg + ep->fifoaddr; |
569 | 584 | ||
570 | if (m66592->pdata->on_chip) { | 585 | if (m66592->pdata->on_chip) { |
571 | unsigned long count; | 586 | unsigned long count; |
@@ -591,26 +606,15 @@ static inline void m66592_write_fifo(struct m66592 *m66592, | |||
591 | iowrite16_rep(fifoaddr, buf, len); | 606 | iowrite16_rep(fifoaddr, buf, len); |
592 | if (odd) { | 607 | if (odd) { |
593 | unsigned char *p = buf + len*2; | 608 | unsigned char *p = buf + len*2; |
609 | if (m66592->pdata->wr0_shorted_to_wr1) | ||
610 | m66592_bclr(m66592, M66592_MBW_16, ep->fifosel); | ||
594 | iowrite8(*p, fifoaddr); | 611 | iowrite8(*p, fifoaddr); |
612 | if (m66592->pdata->wr0_shorted_to_wr1) | ||
613 | m66592_bset(m66592, M66592_MBW_16, ep->fifosel); | ||
595 | } | 614 | } |
596 | } | 615 | } |
597 | } | 616 | } |
598 | 617 | ||
599 | static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat, | ||
600 | unsigned long offset) | ||
601 | { | ||
602 | u16 tmp; | ||
603 | tmp = m66592_read(m66592, offset); | ||
604 | tmp = tmp & (~pat); | ||
605 | tmp = tmp | val; | ||
606 | m66592_write(m66592, tmp, offset); | ||
607 | } | ||
608 | |||
609 | #define m66592_bclr(m66592, val, offset) \ | ||
610 | m66592_mdfy(m66592, 0, val, offset) | ||
611 | #define m66592_bset(m66592, val, offset) \ | ||
612 | m66592_mdfy(m66592, val, 0, offset) | ||
613 | |||
614 | #endif /* ifndef __M66592_UDC_H__ */ | 618 | #endif /* ifndef __M66592_UDC_H__ */ |
615 | 619 | ||
616 | 620 | ||
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c index 01822422c3e8..d3eb27427c58 100644 --- a/drivers/usb/gadget/mass_storage.c +++ b/drivers/usb/gadget/mass_storage.c | |||
@@ -169,6 +169,7 @@ static struct usb_composite_driver msg_driver = { | |||
169 | .name = "g_mass_storage", | 169 | .name = "g_mass_storage", |
170 | .dev = &msg_device_desc, | 170 | .dev = &msg_device_desc, |
171 | .iProduct = DRIVER_DESC, | 171 | .iProduct = DRIVER_DESC, |
172 | .max_speed = USB_SPEED_HIGH, | ||
172 | .needs_serial = 1, | 173 | .needs_serial = 1, |
173 | }; | 174 | }; |
174 | 175 | ||
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index d9feced348e3..8c7b74717d85 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c | |||
@@ -351,6 +351,7 @@ static struct usb_composite_driver multi_driver = { | |||
351 | .name = "g_multi", | 351 | .name = "g_multi", |
352 | .dev = &device_desc, | 352 | .dev = &device_desc, |
353 | .strings = dev_strings, | 353 | .strings = dev_strings, |
354 | .max_speed = USB_SPEED_HIGH, | ||
354 | .unbind = __exit_p(multi_unbind), | 355 | .unbind = __exit_p(multi_unbind), |
355 | .iProduct = DRIVER_DESC, | 356 | .iProduct = DRIVER_DESC, |
356 | .needs_serial = 1, | 357 | .needs_serial = 1, |
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c index b1a8146b9d50..ce1ac2bcb314 100644 --- a/drivers/usb/gadget/mv_udc_core.c +++ b/drivers/usb/gadget/mv_udc_core.c | |||
@@ -1128,6 +1128,9 @@ static int mv_udc_pullup(struct usb_gadget *gadget, int is_on) | |||
1128 | return 0; | 1128 | return 0; |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | static int mv_udc_start(struct usb_gadget_driver *driver, | ||
1132 | int (*bind)(struct usb_gadget *)); | ||
1133 | static int mv_udc_stop(struct usb_gadget_driver *driver); | ||
1131 | /* device controller usb_gadget_ops structure */ | 1134 | /* device controller usb_gadget_ops structure */ |
1132 | static const struct usb_gadget_ops mv_ops = { | 1135 | static const struct usb_gadget_ops mv_ops = { |
1133 | 1136 | ||
@@ -1139,6 +1142,8 @@ static const struct usb_gadget_ops mv_ops = { | |||
1139 | 1142 | ||
1140 | /* D+ pullup, software-controlled connect/disconnect to USB host */ | 1143 | /* D+ pullup, software-controlled connect/disconnect to USB host */ |
1141 | .pullup = mv_udc_pullup, | 1144 | .pullup = mv_udc_pullup, |
1145 | .start = mv_udc_start, | ||
1146 | .stop = mv_udc_stop, | ||
1142 | }; | 1147 | }; |
1143 | 1148 | ||
1144 | static void mv_udc_testmode(struct mv_udc *udc, u16 index, bool enter) | 1149 | static void mv_udc_testmode(struct mv_udc *udc, u16 index, bool enter) |
@@ -1230,7 +1235,7 @@ static void stop_activity(struct mv_udc *udc, struct usb_gadget_driver *driver) | |||
1230 | } | 1235 | } |
1231 | } | 1236 | } |
1232 | 1237 | ||
1233 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1238 | static int mv_udc_start(struct usb_gadget_driver *driver, |
1234 | int (*bind)(struct usb_gadget *)) | 1239 | int (*bind)(struct usb_gadget *)) |
1235 | { | 1240 | { |
1236 | struct mv_udc *udc = the_controller; | 1241 | struct mv_udc *udc = the_controller; |
@@ -1270,9 +1275,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
1270 | 1275 | ||
1271 | return 0; | 1276 | return 0; |
1272 | } | 1277 | } |
1273 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1274 | 1278 | ||
1275 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1279 | static int mv_udc_stop(struct usb_gadget_driver *driver) |
1276 | { | 1280 | { |
1277 | struct mv_udc *udc = the_controller; | 1281 | struct mv_udc *udc = the_controller; |
1278 | unsigned long flags; | 1282 | unsigned long flags; |
@@ -1296,7 +1300,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1296 | 1300 | ||
1297 | return 0; | 1301 | return 0; |
1298 | } | 1302 | } |
1299 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1300 | 1303 | ||
1301 | static int | 1304 | static int |
1302 | udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty) | 1305 | udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty) |
@@ -1880,9 +1883,10 @@ static void gadget_release(struct device *_dev) | |||
1880 | static int mv_udc_remove(struct platform_device *dev) | 1883 | static int mv_udc_remove(struct platform_device *dev) |
1881 | { | 1884 | { |
1882 | struct mv_udc *udc = the_controller; | 1885 | struct mv_udc *udc = the_controller; |
1883 | |||
1884 | DECLARE_COMPLETION(done); | 1886 | DECLARE_COMPLETION(done); |
1885 | 1887 | ||
1888 | usb_del_gadget_udc(&udc->gadget); | ||
1889 | |||
1886 | udc->done = &done; | 1890 | udc->done = &done; |
1887 | 1891 | ||
1888 | /* free memory allocated in probe */ | 1892 | /* free memory allocated in probe */ |
@@ -2074,11 +2078,12 @@ int mv_udc_probe(struct platform_device *dev) | |||
2074 | 2078 | ||
2075 | the_controller = udc; | 2079 | the_controller = udc; |
2076 | 2080 | ||
2077 | goto out; | 2081 | retval = usb_add_gadget_udc(&dev->dev, &udc->gadget); |
2082 | if (!retval) | ||
2083 | return retval; | ||
2078 | error: | 2084 | error: |
2079 | if (udc) | 2085 | if (udc) |
2080 | mv_udc_remove(udc->dev); | 2086 | mv_udc_remove(udc->dev); |
2081 | out: | ||
2082 | return retval; | 2087 | return retval; |
2083 | } | 2088 | } |
2084 | 2089 | ||
@@ -2126,7 +2131,7 @@ static struct platform_driver udc_driver = { | |||
2126 | #endif | 2131 | #endif |
2127 | }, | 2132 | }, |
2128 | }; | 2133 | }; |
2129 | 2134 | MODULE_ALIAS("platform:pxa-u2o"); | |
2130 | 2135 | ||
2131 | MODULE_DESCRIPTION(DRIVER_DESC); | 2136 | MODULE_DESCRIPTION(DRIVER_DESC); |
2132 | MODULE_AUTHOR("Chao Xie <chao.xie@marvell.com>"); | 2137 | MODULE_AUTHOR("Chao Xie <chao.xie@marvell.com>"); |
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c index 99c179ad729d..62ee5087dcac 100644 --- a/drivers/usb/gadget/ncm.c +++ b/drivers/usb/gadget/ncm.c | |||
@@ -228,6 +228,7 @@ static struct usb_composite_driver ncm_driver = { | |||
228 | .name = "g_ncm", | 228 | .name = "g_ncm", |
229 | .dev = &device_desc, | 229 | .dev = &device_desc, |
230 | .strings = dev_strings, | 230 | .strings = dev_strings, |
231 | .max_speed = USB_SPEED_HIGH, | ||
231 | .unbind = __exit_p(gncm_unbind), | 232 | .unbind = __exit_p(gncm_unbind), |
232 | }; | 233 | }; |
233 | 234 | ||
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c new file mode 100644 index 000000000000..7c7b0e120d88 --- /dev/null +++ b/drivers/usb/gadget/net2272.c | |||
@@ -0,0 +1,2752 @@ | |||
1 | /* | ||
2 | * Driver for PLX NET2272 USB device controller | ||
3 | * | ||
4 | * Copyright (C) 2005-2006 PLX Technology, Inc. | ||
5 | * Copyright (C) 2006-2011 Analog Devices, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #include <linux/delay.h> | ||
23 | #include <linux/device.h> | ||
24 | #include <linux/errno.h> | ||
25 | #include <linux/gpio.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/io.h> | ||
29 | #include <linux/ioport.h> | ||
30 | #include <linux/irq.h> | ||
31 | #include <linux/kernel.h> | ||
32 | #include <linux/list.h> | ||
33 | #include <linux/module.h> | ||
34 | #include <linux/moduleparam.h> | ||
35 | #include <linux/pci.h> | ||
36 | #include <linux/platform_device.h> | ||
37 | #include <linux/sched.h> | ||
38 | #include <linux/slab.h> | ||
39 | #include <linux/timer.h> | ||
40 | #include <linux/usb.h> | ||
41 | #include <linux/usb/ch9.h> | ||
42 | #include <linux/usb/gadget.h> | ||
43 | |||
44 | #include <asm/byteorder.h> | ||
45 | #include <asm/system.h> | ||
46 | #include <asm/unaligned.h> | ||
47 | |||
48 | #include "net2272.h" | ||
49 | |||
50 | #define DRIVER_DESC "PLX NET2272 USB Peripheral Controller" | ||
51 | |||
52 | static const char driver_name[] = "net2272"; | ||
53 | static const char driver_vers[] = "2006 October 17/mainline"; | ||
54 | static const char driver_desc[] = DRIVER_DESC; | ||
55 | |||
56 | static const char ep0name[] = "ep0"; | ||
57 | static const char * const ep_name[] = { | ||
58 | ep0name, | ||
59 | "ep-a", "ep-b", "ep-c", | ||
60 | }; | ||
61 | |||
62 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
63 | #ifdef CONFIG_USB_GADGET_NET2272_DMA | ||
64 | /* | ||
65 | * use_dma: the NET2272 can use an external DMA controller. | ||
66 | * Note that since there is no generic DMA api, some functions, | ||
67 | * notably request_dma, start_dma, and cancel_dma will need to be | ||
68 | * modified for your platform's particular dma controller. | ||
69 | * | ||
70 | * If use_dma is disabled, pio will be used instead. | ||
71 | */ | ||
72 | static int use_dma = 0; | ||
73 | module_param(use_dma, bool, 0644); | ||
74 | |||
75 | /* | ||
76 | * dma_ep: selects the endpoint for use with dma (1=ep-a, 2=ep-b) | ||
77 | * The NET2272 can only use dma for a single endpoint at a time. | ||
78 | * At some point this could be modified to allow either endpoint | ||
79 | * to take control of dma as it becomes available. | ||
80 | * | ||
81 | * Note that DMA should not be used on OUT endpoints unless it can | ||
82 | * be guaranteed that no short packets will arrive on an IN endpoint | ||
83 | * while the DMA operation is pending. Otherwise the OUT DMA will | ||
84 | * terminate prematurely (See NET2272 Errata 630-0213-0101) | ||
85 | */ | ||
86 | static ushort dma_ep = 1; | ||
87 | module_param(dma_ep, ushort, 0644); | ||
88 | |||
89 | /* | ||
90 | * dma_mode: net2272 dma mode setting (see LOCCTL1 definiton): | ||
91 | * mode 0 == Slow DREQ mode | ||
92 | * mode 1 == Fast DREQ mode | ||
93 | * mode 2 == Burst mode | ||
94 | */ | ||
95 | static ushort dma_mode = 2; | ||
96 | module_param(dma_mode, ushort, 0644); | ||
97 | #else | ||
98 | #define use_dma 0 | ||
99 | #define dma_ep 1 | ||
100 | #define dma_mode 2 | ||
101 | #endif | ||
102 | |||
103 | /* | ||
104 | * fifo_mode: net2272 buffer configuration: | ||
105 | * mode 0 == ep-{a,b,c} 512db each | ||
106 | * mode 1 == ep-a 1k, ep-{b,c} 512db | ||
107 | * mode 2 == ep-a 1k, ep-b 1k, ep-c 512db | ||
108 | * mode 3 == ep-a 1k, ep-b disabled, ep-c 512db | ||
109 | */ | ||
110 | static ushort fifo_mode = 0; | ||
111 | module_param(fifo_mode, ushort, 0644); | ||
112 | |||
113 | /* | ||
114 | * enable_suspend: When enabled, the driver will respond to | ||
115 | * USB suspend requests by powering down the NET2272. Otherwise, | ||
116 | * USB suspend requests will be ignored. This is acceptible for | ||
117 | * self-powered devices. For bus powered devices set this to 1. | ||
118 | */ | ||
119 | static ushort enable_suspend = 0; | ||
120 | module_param(enable_suspend, ushort, 0644); | ||
121 | |||
122 | static void assert_out_naking(struct net2272_ep *ep, const char *where) | ||
123 | { | ||
124 | u8 tmp; | ||
125 | |||
126 | #ifndef DEBUG | ||
127 | return; | ||
128 | #endif | ||
129 | |||
130 | tmp = net2272_ep_read(ep, EP_STAT0); | ||
131 | if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) { | ||
132 | dev_dbg(ep->dev->dev, "%s %s %02x !NAK\n", | ||
133 | ep->ep.name, where, tmp); | ||
134 | net2272_ep_write(ep, EP_RSPSET, 1 << ALT_NAK_OUT_PACKETS); | ||
135 | } | ||
136 | } | ||
137 | #define ASSERT_OUT_NAKING(ep) assert_out_naking(ep, __func__) | ||
138 | |||
139 | static void stop_out_naking(struct net2272_ep *ep) | ||
140 | { | ||
141 | u8 tmp = net2272_ep_read(ep, EP_STAT0); | ||
142 | |||
143 | if ((tmp & (1 << NAK_OUT_PACKETS)) != 0) | ||
144 | net2272_ep_write(ep, EP_RSPCLR, 1 << ALT_NAK_OUT_PACKETS); | ||
145 | } | ||
146 | |||
147 | #define PIPEDIR(bAddress) (usb_pipein(bAddress) ? "in" : "out") | ||
148 | |||
149 | static char *type_string(u8 bmAttributes) | ||
150 | { | ||
151 | switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) { | ||
152 | case USB_ENDPOINT_XFER_BULK: return "bulk"; | ||
153 | case USB_ENDPOINT_XFER_ISOC: return "iso"; | ||
154 | case USB_ENDPOINT_XFER_INT: return "intr"; | ||
155 | default: return "control"; | ||
156 | } | ||
157 | } | ||
158 | |||
159 | static char *buf_state_string(unsigned state) | ||
160 | { | ||
161 | switch (state) { | ||
162 | case BUFF_FREE: return "free"; | ||
163 | case BUFF_VALID: return "valid"; | ||
164 | case BUFF_LCL: return "local"; | ||
165 | case BUFF_USB: return "usb"; | ||
166 | default: return "unknown"; | ||
167 | } | ||
168 | } | ||
169 | |||
170 | static char *dma_mode_string(void) | ||
171 | { | ||
172 | if (!use_dma) | ||
173 | return "PIO"; | ||
174 | switch (dma_mode) { | ||
175 | case 0: return "SLOW DREQ"; | ||
176 | case 1: return "FAST DREQ"; | ||
177 | case 2: return "BURST"; | ||
178 | default: return "invalid"; | ||
179 | } | ||
180 | } | ||
181 | |||
182 | static void net2272_dequeue_all(struct net2272_ep *); | ||
183 | static int net2272_kick_dma(struct net2272_ep *, struct net2272_request *); | ||
184 | static int net2272_fifo_status(struct usb_ep *); | ||
185 | |||
186 | static struct usb_ep_ops net2272_ep_ops; | ||
187 | |||
188 | /*---------------------------------------------------------------------------*/ | ||
189 | |||
190 | static int | ||
191 | net2272_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | ||
192 | { | ||
193 | struct net2272 *dev; | ||
194 | struct net2272_ep *ep; | ||
195 | u32 max; | ||
196 | u8 tmp; | ||
197 | unsigned long flags; | ||
198 | |||
199 | ep = container_of(_ep, struct net2272_ep, ep); | ||
200 | if (!_ep || !desc || ep->desc || _ep->name == ep0name | ||
201 | || desc->bDescriptorType != USB_DT_ENDPOINT) | ||
202 | return -EINVAL; | ||
203 | dev = ep->dev; | ||
204 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
205 | return -ESHUTDOWN; | ||
206 | |||
207 | max = le16_to_cpu(desc->wMaxPacketSize) & 0x1fff; | ||
208 | |||
209 | spin_lock_irqsave(&dev->lock, flags); | ||
210 | _ep->maxpacket = max & 0x7fff; | ||
211 | ep->desc = desc; | ||
212 | |||
213 | /* net2272_ep_reset() has already been called */ | ||
214 | ep->stopped = 0; | ||
215 | ep->wedged = 0; | ||
216 | |||
217 | /* set speed-dependent max packet */ | ||
218 | net2272_ep_write(ep, EP_MAXPKT0, max & 0xff); | ||
219 | net2272_ep_write(ep, EP_MAXPKT1, (max & 0xff00) >> 8); | ||
220 | |||
221 | /* set type, direction, address; reset fifo counters */ | ||
222 | net2272_ep_write(ep, EP_STAT1, 1 << BUFFER_FLUSH); | ||
223 | tmp = usb_endpoint_type(desc); | ||
224 | if (usb_endpoint_xfer_bulk(desc)) { | ||
225 | /* catch some particularly blatant driver bugs */ | ||
226 | if ((dev->gadget.speed == USB_SPEED_HIGH && max != 512) || | ||
227 | (dev->gadget.speed == USB_SPEED_FULL && max > 64)) { | ||
228 | spin_unlock_irqrestore(&dev->lock, flags); | ||
229 | return -ERANGE; | ||
230 | } | ||
231 | } | ||
232 | ep->is_iso = usb_endpoint_xfer_isoc(desc) ? 1 : 0; | ||
233 | tmp <<= ENDPOINT_TYPE; | ||
234 | tmp |= ((desc->bEndpointAddress & 0x0f) << ENDPOINT_NUMBER); | ||
235 | tmp |= usb_endpoint_dir_in(desc) << ENDPOINT_DIRECTION; | ||
236 | tmp |= (1 << ENDPOINT_ENABLE); | ||
237 | |||
238 | /* for OUT transfers, block the rx fifo until a read is posted */ | ||
239 | ep->is_in = usb_endpoint_dir_in(desc); | ||
240 | if (!ep->is_in) | ||
241 | net2272_ep_write(ep, EP_RSPSET, 1 << ALT_NAK_OUT_PACKETS); | ||
242 | |||
243 | net2272_ep_write(ep, EP_CFG, tmp); | ||
244 | |||
245 | /* enable irqs */ | ||
246 | tmp = (1 << ep->num) | net2272_read(dev, IRQENB0); | ||
247 | net2272_write(dev, IRQENB0, tmp); | ||
248 | |||
249 | tmp = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) | ||
250 | | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE) | ||
251 | | net2272_ep_read(ep, EP_IRQENB); | ||
252 | net2272_ep_write(ep, EP_IRQENB, tmp); | ||
253 | |||
254 | tmp = desc->bEndpointAddress; | ||
255 | dev_dbg(dev->dev, "enabled %s (ep%d%s-%s) max %04x cfg %02x\n", | ||
256 | _ep->name, tmp & 0x0f, PIPEDIR(tmp), | ||
257 | type_string(desc->bmAttributes), max, | ||
258 | net2272_ep_read(ep, EP_CFG)); | ||
259 | |||
260 | spin_unlock_irqrestore(&dev->lock, flags); | ||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | static void net2272_ep_reset(struct net2272_ep *ep) | ||
265 | { | ||
266 | u8 tmp; | ||
267 | |||
268 | ep->desc = NULL; | ||
269 | INIT_LIST_HEAD(&ep->queue); | ||
270 | |||
271 | ep->ep.maxpacket = ~0; | ||
272 | ep->ep.ops = &net2272_ep_ops; | ||
273 | |||
274 | /* disable irqs, endpoint */ | ||
275 | net2272_ep_write(ep, EP_IRQENB, 0); | ||
276 | |||
277 | /* init to our chosen defaults, notably so that we NAK OUT | ||
278 | * packets until the driver queues a read. | ||
279 | */ | ||
280 | tmp = (1 << NAK_OUT_PACKETS_MODE) | (1 << ALT_NAK_OUT_PACKETS); | ||
281 | net2272_ep_write(ep, EP_RSPSET, tmp); | ||
282 | |||
283 | tmp = (1 << INTERRUPT_MODE) | (1 << HIDE_STATUS_PHASE); | ||
284 | if (ep->num != 0) | ||
285 | tmp |= (1 << ENDPOINT_TOGGLE) | (1 << ENDPOINT_HALT); | ||
286 | |||
287 | net2272_ep_write(ep, EP_RSPCLR, tmp); | ||
288 | |||
289 | /* scrub most status bits, and flush any fifo state */ | ||
290 | net2272_ep_write(ep, EP_STAT0, | ||
291 | (1 << DATA_IN_TOKEN_INTERRUPT) | ||
292 | | (1 << DATA_OUT_TOKEN_INTERRUPT) | ||
293 | | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT) | ||
294 | | (1 << DATA_PACKET_RECEIVED_INTERRUPT) | ||
295 | | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)); | ||
296 | |||
297 | net2272_ep_write(ep, EP_STAT1, | ||
298 | (1 << TIMEOUT) | ||
299 | | (1 << USB_OUT_ACK_SENT) | ||
300 | | (1 << USB_OUT_NAK_SENT) | ||
301 | | (1 << USB_IN_ACK_RCVD) | ||
302 | | (1 << USB_IN_NAK_SENT) | ||
303 | | (1 << USB_STALL_SENT) | ||
304 | | (1 << LOCAL_OUT_ZLP) | ||
305 | | (1 << BUFFER_FLUSH)); | ||
306 | |||
307 | /* fifo size is handled seperately */ | ||
308 | } | ||
309 | |||
310 | static int net2272_disable(struct usb_ep *_ep) | ||
311 | { | ||
312 | struct net2272_ep *ep; | ||
313 | unsigned long flags; | ||
314 | |||
315 | ep = container_of(_ep, struct net2272_ep, ep); | ||
316 | if (!_ep || !ep->desc || _ep->name == ep0name) | ||
317 | return -EINVAL; | ||
318 | |||
319 | spin_lock_irqsave(&ep->dev->lock, flags); | ||
320 | net2272_dequeue_all(ep); | ||
321 | net2272_ep_reset(ep); | ||
322 | |||
323 | dev_vdbg(ep->dev->dev, "disabled %s\n", _ep->name); | ||
324 | |||
325 | spin_unlock_irqrestore(&ep->dev->lock, flags); | ||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | /*---------------------------------------------------------------------------*/ | ||
330 | |||
331 | static struct usb_request * | ||
332 | net2272_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) | ||
333 | { | ||
334 | struct net2272_ep *ep; | ||
335 | struct net2272_request *req; | ||
336 | |||
337 | if (!_ep) | ||
338 | return NULL; | ||
339 | ep = container_of(_ep, struct net2272_ep, ep); | ||
340 | |||
341 | req = kzalloc(sizeof(*req), gfp_flags); | ||
342 | if (!req) | ||
343 | return NULL; | ||
344 | |||
345 | req->req.dma = DMA_ADDR_INVALID; | ||
346 | INIT_LIST_HEAD(&req->queue); | ||
347 | |||
348 | return &req->req; | ||
349 | } | ||
350 | |||
351 | static void | ||
352 | net2272_free_request(struct usb_ep *_ep, struct usb_request *_req) | ||
353 | { | ||
354 | struct net2272_ep *ep; | ||
355 | struct net2272_request *req; | ||
356 | |||
357 | ep = container_of(_ep, struct net2272_ep, ep); | ||
358 | if (!_ep || !_req) | ||
359 | return; | ||
360 | |||
361 | req = container_of(_req, struct net2272_request, req); | ||
362 | WARN_ON(!list_empty(&req->queue)); | ||
363 | kfree(req); | ||
364 | } | ||
365 | |||
366 | static void | ||
367 | net2272_done(struct net2272_ep *ep, struct net2272_request *req, int status) | ||
368 | { | ||
369 | struct net2272 *dev; | ||
370 | unsigned stopped = ep->stopped; | ||
371 | |||
372 | if (ep->num == 0) { | ||
373 | if (ep->dev->protocol_stall) { | ||
374 | ep->stopped = 1; | ||
375 | set_halt(ep); | ||
376 | } | ||
377 | allow_status(ep); | ||
378 | } | ||
379 | |||
380 | list_del_init(&req->queue); | ||
381 | |||
382 | if (req->req.status == -EINPROGRESS) | ||
383 | req->req.status = status; | ||
384 | else | ||
385 | status = req->req.status; | ||
386 | |||
387 | dev = ep->dev; | ||
388 | if (use_dma && req->mapped) { | ||
389 | dma_unmap_single(dev->dev, req->req.dma, req->req.length, | ||
390 | ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
391 | req->req.dma = DMA_ADDR_INVALID; | ||
392 | req->mapped = 0; | ||
393 | } | ||
394 | |||
395 | if (status && status != -ESHUTDOWN) | ||
396 | dev_vdbg(dev->dev, "complete %s req %p stat %d len %u/%u buf %p\n", | ||
397 | ep->ep.name, &req->req, status, | ||
398 | req->req.actual, req->req.length, req->req.buf); | ||
399 | |||
400 | /* don't modify queue heads during completion callback */ | ||
401 | ep->stopped = 1; | ||
402 | spin_unlock(&dev->lock); | ||
403 | req->req.complete(&ep->ep, &req->req); | ||
404 | spin_lock(&dev->lock); | ||
405 | ep->stopped = stopped; | ||
406 | } | ||
407 | |||
408 | static int | ||
409 | net2272_write_packet(struct net2272_ep *ep, u8 *buf, | ||
410 | struct net2272_request *req, unsigned max) | ||
411 | { | ||
412 | u16 __iomem *ep_data = net2272_reg_addr(ep->dev, EP_DATA); | ||
413 | u16 *bufp; | ||
414 | unsigned length, count; | ||
415 | u8 tmp; | ||
416 | |||
417 | length = min(req->req.length - req->req.actual, max); | ||
418 | req->req.actual += length; | ||
419 | |||
420 | dev_vdbg(ep->dev->dev, "write packet %s req %p max %u len %u avail %u\n", | ||
421 | ep->ep.name, req, max, length, | ||
422 | (net2272_ep_read(ep, EP_AVAIL1) << 8) | net2272_ep_read(ep, EP_AVAIL0)); | ||
423 | |||
424 | count = length; | ||
425 | bufp = (u16 *)buf; | ||
426 | |||
427 | while (likely(count >= 2)) { | ||
428 | /* no byte-swap required; chip endian set during init */ | ||
429 | writew(*bufp++, ep_data); | ||
430 | count -= 2; | ||
431 | } | ||
432 | buf = (u8 *)bufp; | ||
433 | |||
434 | /* write final byte by placing the NET2272 into 8-bit mode */ | ||
435 | if (unlikely(count)) { | ||
436 | tmp = net2272_read(ep->dev, LOCCTL); | ||
437 | net2272_write(ep->dev, LOCCTL, tmp & ~(1 << DATA_WIDTH)); | ||
438 | writeb(*buf, ep_data); | ||
439 | net2272_write(ep->dev, LOCCTL, tmp); | ||
440 | } | ||
441 | return length; | ||
442 | } | ||
443 | |||
444 | /* returns: 0: still running, 1: completed, negative: errno */ | ||
445 | static int | ||
446 | net2272_write_fifo(struct net2272_ep *ep, struct net2272_request *req) | ||
447 | { | ||
448 | u8 *buf; | ||
449 | unsigned count, max; | ||
450 | int status; | ||
451 | |||
452 | dev_vdbg(ep->dev->dev, "write_fifo %s actual %d len %d\n", | ||
453 | ep->ep.name, req->req.actual, req->req.length); | ||
454 | |||
455 | /* | ||
456 | * Keep loading the endpoint until the final packet is loaded, | ||
457 | * or the endpoint buffer is full. | ||
458 | */ | ||
459 | top: | ||
460 | /* | ||
461 | * Clear interrupt status | ||
462 | * - Packet Transmitted interrupt will become set again when the | ||
463 | * host successfully takes another packet | ||
464 | */ | ||
465 | net2272_ep_write(ep, EP_STAT0, (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)); | ||
466 | while (!(net2272_ep_read(ep, EP_STAT0) & (1 << BUFFER_FULL))) { | ||
467 | buf = req->req.buf + req->req.actual; | ||
468 | prefetch(buf); | ||
469 | |||
470 | /* force pagesel */ | ||
471 | net2272_ep_read(ep, EP_STAT0); | ||
472 | |||
473 | max = (net2272_ep_read(ep, EP_AVAIL1) << 8) | | ||
474 | (net2272_ep_read(ep, EP_AVAIL0)); | ||
475 | |||
476 | if (max < ep->ep.maxpacket) | ||
477 | max = (net2272_ep_read(ep, EP_AVAIL1) << 8) | ||
478 | | (net2272_ep_read(ep, EP_AVAIL0)); | ||
479 | |||
480 | count = net2272_write_packet(ep, buf, req, max); | ||
481 | /* see if we are done */ | ||
482 | if (req->req.length == req->req.actual) { | ||
483 | /* validate short or zlp packet */ | ||
484 | if (count < ep->ep.maxpacket) | ||
485 | set_fifo_bytecount(ep, 0); | ||
486 | net2272_done(ep, req, 0); | ||
487 | |||
488 | if (!list_empty(&ep->queue)) { | ||
489 | req = list_entry(ep->queue.next, | ||
490 | struct net2272_request, | ||
491 | queue); | ||
492 | status = net2272_kick_dma(ep, req); | ||
493 | |||
494 | if (status < 0) | ||
495 | if ((net2272_ep_read(ep, EP_STAT0) | ||
496 | & (1 << BUFFER_EMPTY))) | ||
497 | goto top; | ||
498 | } | ||
499 | return 1; | ||
500 | } | ||
501 | net2272_ep_write(ep, EP_STAT0, (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)); | ||
502 | } | ||
503 | return 0; | ||
504 | } | ||
505 | |||
506 | static void | ||
507 | net2272_out_flush(struct net2272_ep *ep) | ||
508 | { | ||
509 | ASSERT_OUT_NAKING(ep); | ||
510 | |||
511 | net2272_ep_write(ep, EP_STAT0, (1 << DATA_OUT_TOKEN_INTERRUPT) | ||
512 | | (1 << DATA_PACKET_RECEIVED_INTERRUPT)); | ||
513 | net2272_ep_write(ep, EP_STAT1, 1 << BUFFER_FLUSH); | ||
514 | } | ||
515 | |||
516 | static int | ||
517 | net2272_read_packet(struct net2272_ep *ep, u8 *buf, | ||
518 | struct net2272_request *req, unsigned avail) | ||
519 | { | ||
520 | u16 __iomem *ep_data = net2272_reg_addr(ep->dev, EP_DATA); | ||
521 | unsigned is_short; | ||
522 | u16 *bufp; | ||
523 | |||
524 | req->req.actual += avail; | ||
525 | |||
526 | dev_vdbg(ep->dev->dev, "read packet %s req %p len %u avail %u\n", | ||
527 | ep->ep.name, req, avail, | ||
528 | (net2272_ep_read(ep, EP_AVAIL1) << 8) | net2272_ep_read(ep, EP_AVAIL0)); | ||
529 | |||
530 | is_short = (avail < ep->ep.maxpacket); | ||
531 | |||
532 | if (unlikely(avail == 0)) { | ||
533 | /* remove any zlp from the buffer */ | ||
534 | (void)readw(ep_data); | ||
535 | return is_short; | ||
536 | } | ||
537 | |||
538 | /* Ensure we get the final byte */ | ||
539 | if (unlikely(avail % 2)) | ||
540 | avail++; | ||
541 | bufp = (u16 *)buf; | ||
542 | |||
543 | do { | ||
544 | *bufp++ = readw(ep_data); | ||
545 | avail -= 2; | ||
546 | } while (avail); | ||
547 | |||
548 | /* | ||
549 | * To avoid false endpoint available race condition must read | ||
550 | * ep stat0 twice in the case of a short transfer | ||
551 | */ | ||
552 | if (net2272_ep_read(ep, EP_STAT0) & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) | ||
553 | net2272_ep_read(ep, EP_STAT0); | ||
554 | |||
555 | return is_short; | ||
556 | } | ||
557 | |||
558 | static int | ||
559 | net2272_read_fifo(struct net2272_ep *ep, struct net2272_request *req) | ||
560 | { | ||
561 | u8 *buf; | ||
562 | unsigned is_short; | ||
563 | int count; | ||
564 | int tmp; | ||
565 | int cleanup = 0; | ||
566 | int status = -1; | ||
567 | |||
568 | dev_vdbg(ep->dev->dev, "read_fifo %s actual %d len %d\n", | ||
569 | ep->ep.name, req->req.actual, req->req.length); | ||
570 | |||
571 | top: | ||
572 | do { | ||
573 | buf = req->req.buf + req->req.actual; | ||
574 | prefetchw(buf); | ||
575 | |||
576 | count = (net2272_ep_read(ep, EP_AVAIL1) << 8) | ||
577 | | net2272_ep_read(ep, EP_AVAIL0); | ||
578 | |||
579 | net2272_ep_write(ep, EP_STAT0, | ||
580 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT) | | ||
581 | (1 << DATA_PACKET_RECEIVED_INTERRUPT)); | ||
582 | |||
583 | tmp = req->req.length - req->req.actual; | ||
584 | |||
585 | if (count > tmp) { | ||
586 | if ((tmp % ep->ep.maxpacket) != 0) { | ||
587 | dev_err(ep->dev->dev, | ||
588 | "%s out fifo %d bytes, expected %d\n", | ||
589 | ep->ep.name, count, tmp); | ||
590 | cleanup = 1; | ||
591 | } | ||
592 | count = (tmp > 0) ? tmp : 0; | ||
593 | } | ||
594 | |||
595 | is_short = net2272_read_packet(ep, buf, req, count); | ||
596 | |||
597 | /* completion */ | ||
598 | if (unlikely(cleanup || is_short || | ||
599 | ((req->req.actual == req->req.length) | ||
600 | && !req->req.zero))) { | ||
601 | |||
602 | if (cleanup) { | ||
603 | net2272_out_flush(ep); | ||
604 | net2272_done(ep, req, -EOVERFLOW); | ||
605 | } else | ||
606 | net2272_done(ep, req, 0); | ||
607 | |||
608 | /* re-initialize endpoint transfer registers | ||
609 | * otherwise they may result in erroneous pre-validation | ||
610 | * for subsequent control reads | ||
611 | */ | ||
612 | if (unlikely(ep->num == 0)) { | ||
613 | net2272_ep_write(ep, EP_TRANSFER2, 0); | ||
614 | net2272_ep_write(ep, EP_TRANSFER1, 0); | ||
615 | net2272_ep_write(ep, EP_TRANSFER0, 0); | ||
616 | } | ||
617 | |||
618 | if (!list_empty(&ep->queue)) { | ||
619 | req = list_entry(ep->queue.next, | ||
620 | struct net2272_request, queue); | ||
621 | status = net2272_kick_dma(ep, req); | ||
622 | if ((status < 0) && | ||
623 | !(net2272_ep_read(ep, EP_STAT0) & (1 << BUFFER_EMPTY))) | ||
624 | goto top; | ||
625 | } | ||
626 | return 1; | ||
627 | } | ||
628 | } while (!(net2272_ep_read(ep, EP_STAT0) & (1 << BUFFER_EMPTY))); | ||
629 | |||
630 | return 0; | ||
631 | } | ||
632 | |||
633 | static void | ||
634 | net2272_pio_advance(struct net2272_ep *ep) | ||
635 | { | ||
636 | struct net2272_request *req; | ||
637 | |||
638 | if (unlikely(list_empty(&ep->queue))) | ||
639 | return; | ||
640 | |||
641 | req = list_entry(ep->queue.next, struct net2272_request, queue); | ||
642 | (ep->is_in ? net2272_write_fifo : net2272_read_fifo)(ep, req); | ||
643 | } | ||
644 | |||
645 | /* returns 0 on success, else negative errno */ | ||
646 | static int | ||
647 | net2272_request_dma(struct net2272 *dev, unsigned ep, u32 buf, | ||
648 | unsigned len, unsigned dir) | ||
649 | { | ||
650 | dev_vdbg(dev->dev, "request_dma ep %d buf %08x len %d dir %d\n", | ||
651 | ep, buf, len, dir); | ||
652 | |||
653 | /* The NET2272 only supports a single dma channel */ | ||
654 | if (dev->dma_busy) | ||
655 | return -EBUSY; | ||
656 | /* | ||
657 | * EP_TRANSFER (used to determine the number of bytes received | ||
658 | * in an OUT transfer) is 24 bits wide; don't ask for more than that. | ||
659 | */ | ||
660 | if ((dir == 1) && (len > 0x1000000)) | ||
661 | return -EINVAL; | ||
662 | |||
663 | dev->dma_busy = 1; | ||
664 | |||
665 | /* initialize platform's dma */ | ||
666 | #ifdef CONFIG_PCI | ||
667 | /* NET2272 addr, buffer addr, length, etc. */ | ||
668 | switch (dev->dev_id) { | ||
669 | case PCI_DEVICE_ID_RDK1: | ||
670 | /* Setup PLX 9054 DMA mode */ | ||
671 | writel((1 << LOCAL_BUS_WIDTH) | | ||
672 | (1 << TA_READY_INPUT_ENABLE) | | ||
673 | (0 << LOCAL_BURST_ENABLE) | | ||
674 | (1 << DONE_INTERRUPT_ENABLE) | | ||
675 | (1 << LOCAL_ADDRESSING_MODE) | | ||
676 | (1 << DEMAND_MODE) | | ||
677 | (1 << DMA_EOT_ENABLE) | | ||
678 | (1 << FAST_SLOW_TERMINATE_MODE_SELECT) | | ||
679 | (1 << DMA_CHANNEL_INTERRUPT_SELECT), | ||
680 | dev->rdk1.plx9054_base_addr + DMAMODE0); | ||
681 | |||
682 | writel(0x100000, dev->rdk1.plx9054_base_addr + DMALADR0); | ||
683 | writel(buf, dev->rdk1.plx9054_base_addr + DMAPADR0); | ||
684 | writel(len, dev->rdk1.plx9054_base_addr + DMASIZ0); | ||
685 | writel((dir << DIRECTION_OF_TRANSFER) | | ||
686 | (1 << INTERRUPT_AFTER_TERMINAL_COUNT), | ||
687 | dev->rdk1.plx9054_base_addr + DMADPR0); | ||
688 | writel((1 << LOCAL_DMA_CHANNEL_0_INTERRUPT_ENABLE) | | ||
689 | readl(dev->rdk1.plx9054_base_addr + INTCSR), | ||
690 | dev->rdk1.plx9054_base_addr + INTCSR); | ||
691 | |||
692 | break; | ||
693 | } | ||
694 | #endif | ||
695 | |||
696 | net2272_write(dev, DMAREQ, | ||
697 | (0 << DMA_BUFFER_VALID) | | ||
698 | (1 << DMA_REQUEST_ENABLE) | | ||
699 | (1 << DMA_CONTROL_DACK) | | ||
700 | (dev->dma_eot_polarity << EOT_POLARITY) | | ||
701 | (dev->dma_dack_polarity << DACK_POLARITY) | | ||
702 | (dev->dma_dreq_polarity << DREQ_POLARITY) | | ||
703 | ((ep >> 1) << DMA_ENDPOINT_SELECT)); | ||
704 | |||
705 | (void) net2272_read(dev, SCRATCH); | ||
706 | |||
707 | return 0; | ||
708 | } | ||
709 | |||
710 | static void | ||
711 | net2272_start_dma(struct net2272 *dev) | ||
712 | { | ||
713 | /* start platform's dma controller */ | ||
714 | #ifdef CONFIG_PCI | ||
715 | switch (dev->dev_id) { | ||
716 | case PCI_DEVICE_ID_RDK1: | ||
717 | writeb((1 << CHANNEL_ENABLE) | (1 << CHANNEL_START), | ||
718 | dev->rdk1.plx9054_base_addr + DMACSR0); | ||
719 | break; | ||
720 | } | ||
721 | #endif | ||
722 | } | ||
723 | |||
724 | /* returns 0 on success, else negative errno */ | ||
725 | static int | ||
726 | net2272_kick_dma(struct net2272_ep *ep, struct net2272_request *req) | ||
727 | { | ||
728 | unsigned size; | ||
729 | u8 tmp; | ||
730 | |||
731 | if (!use_dma || (ep->num < 1) || (ep->num > 2) || !ep->dma) | ||
732 | return -EINVAL; | ||
733 | |||
734 | /* don't use dma for odd-length transfers | ||
735 | * otherwise, we'd need to deal with the last byte with pio | ||
736 | */ | ||
737 | if (req->req.length & 1) | ||
738 | return -EINVAL; | ||
739 | |||
740 | dev_vdbg(ep->dev->dev, "kick_dma %s req %p dma %08llx\n", | ||
741 | ep->ep.name, req, (unsigned long long) req->req.dma); | ||
742 | |||
743 | net2272_ep_write(ep, EP_RSPSET, 1 << ALT_NAK_OUT_PACKETS); | ||
744 | |||
745 | /* The NET2272 can only use DMA on one endpoint at a time */ | ||
746 | if (ep->dev->dma_busy) | ||
747 | return -EBUSY; | ||
748 | |||
749 | /* Make sure we only DMA an even number of bytes (we'll use | ||
750 | * pio to complete the transfer) | ||
751 | */ | ||
752 | size = req->req.length; | ||
753 | size &= ~1; | ||
754 | |||
755 | /* device-to-host transfer */ | ||
756 | if (ep->is_in) { | ||
757 | /* initialize platform's dma controller */ | ||
758 | if (net2272_request_dma(ep->dev, ep->num, req->req.dma, size, 0)) | ||
759 | /* unable to obtain DMA channel; return error and use pio mode */ | ||
760 | return -EBUSY; | ||
761 | req->req.actual += size; | ||
762 | |||
763 | /* host-to-device transfer */ | ||
764 | } else { | ||
765 | tmp = net2272_ep_read(ep, EP_STAT0); | ||
766 | |||
767 | /* initialize platform's dma controller */ | ||
768 | if (net2272_request_dma(ep->dev, ep->num, req->req.dma, size, 1)) | ||
769 | /* unable to obtain DMA channel; return error and use pio mode */ | ||
770 | return -EBUSY; | ||
771 | |||
772 | if (!(tmp & (1 << BUFFER_EMPTY))) | ||
773 | ep->not_empty = 1; | ||
774 | else | ||
775 | ep->not_empty = 0; | ||
776 | |||
777 | |||
778 | /* allow the endpoint's buffer to fill */ | ||
779 | net2272_ep_write(ep, EP_RSPCLR, 1 << ALT_NAK_OUT_PACKETS); | ||
780 | |||
781 | /* this transfer completed and data's already in the fifo | ||
782 | * return error so pio gets used. | ||
783 | */ | ||
784 | if (tmp & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) { | ||
785 | |||
786 | /* deassert dreq */ | ||
787 | net2272_write(ep->dev, DMAREQ, | ||
788 | (0 << DMA_BUFFER_VALID) | | ||
789 | (0 << DMA_REQUEST_ENABLE) | | ||
790 | (1 << DMA_CONTROL_DACK) | | ||
791 | (ep->dev->dma_eot_polarity << EOT_POLARITY) | | ||
792 | (ep->dev->dma_dack_polarity << DACK_POLARITY) | | ||
793 | (ep->dev->dma_dreq_polarity << DREQ_POLARITY) | | ||
794 | ((ep->num >> 1) << DMA_ENDPOINT_SELECT)); | ||
795 | |||
796 | return -EBUSY; | ||
797 | } | ||
798 | } | ||
799 | |||
800 | /* Don't use per-packet interrupts: use dma interrupts only */ | ||
801 | net2272_ep_write(ep, EP_IRQENB, 0); | ||
802 | |||
803 | net2272_start_dma(ep->dev); | ||
804 | |||
805 | return 0; | ||
806 | } | ||
807 | |||
808 | static void net2272_cancel_dma(struct net2272 *dev) | ||
809 | { | ||
810 | #ifdef CONFIG_PCI | ||
811 | switch (dev->dev_id) { | ||
812 | case PCI_DEVICE_ID_RDK1: | ||
813 | writeb(0, dev->rdk1.plx9054_base_addr + DMACSR0); | ||
814 | writeb(1 << CHANNEL_ABORT, dev->rdk1.plx9054_base_addr + DMACSR0); | ||
815 | while (!(readb(dev->rdk1.plx9054_base_addr + DMACSR0) & | ||
816 | (1 << CHANNEL_DONE))) | ||
817 | continue; /* wait for dma to stabalize */ | ||
818 | |||
819 | /* dma abort generates an interrupt */ | ||
820 | writeb(1 << CHANNEL_CLEAR_INTERRUPT, | ||
821 | dev->rdk1.plx9054_base_addr + DMACSR0); | ||
822 | break; | ||
823 | } | ||
824 | #endif | ||
825 | |||
826 | dev->dma_busy = 0; | ||
827 | } | ||
828 | |||
829 | /*---------------------------------------------------------------------------*/ | ||
830 | |||
831 | static int | ||
832 | net2272_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | ||
833 | { | ||
834 | struct net2272_request *req; | ||
835 | struct net2272_ep *ep; | ||
836 | struct net2272 *dev; | ||
837 | unsigned long flags; | ||
838 | int status = -1; | ||
839 | u8 s; | ||
840 | |||
841 | req = container_of(_req, struct net2272_request, req); | ||
842 | if (!_req || !_req->complete || !_req->buf | ||
843 | || !list_empty(&req->queue)) | ||
844 | return -EINVAL; | ||
845 | ep = container_of(_ep, struct net2272_ep, ep); | ||
846 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
847 | return -EINVAL; | ||
848 | dev = ep->dev; | ||
849 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
850 | return -ESHUTDOWN; | ||
851 | |||
852 | /* set up dma mapping in case the caller didn't */ | ||
853 | if (use_dma && ep->dma && _req->dma == DMA_ADDR_INVALID) { | ||
854 | _req->dma = dma_map_single(dev->dev, _req->buf, _req->length, | ||
855 | ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
856 | req->mapped = 1; | ||
857 | } | ||
858 | |||
859 | dev_vdbg(dev->dev, "%s queue req %p, len %d buf %p dma %08llx %s\n", | ||
860 | _ep->name, _req, _req->length, _req->buf, | ||
861 | (unsigned long long) _req->dma, _req->zero ? "zero" : "!zero"); | ||
862 | |||
863 | spin_lock_irqsave(&dev->lock, flags); | ||
864 | |||
865 | _req->status = -EINPROGRESS; | ||
866 | _req->actual = 0; | ||
867 | |||
868 | /* kickstart this i/o queue? */ | ||
869 | if (list_empty(&ep->queue) && !ep->stopped) { | ||
870 | /* maybe there's no control data, just status ack */ | ||
871 | if (ep->num == 0 && _req->length == 0) { | ||
872 | net2272_done(ep, req, 0); | ||
873 | dev_vdbg(dev->dev, "%s status ack\n", ep->ep.name); | ||
874 | goto done; | ||
875 | } | ||
876 | |||
877 | /* Return zlp, don't let it block subsequent packets */ | ||
878 | s = net2272_ep_read(ep, EP_STAT0); | ||
879 | if (s & (1 << BUFFER_EMPTY)) { | ||
880 | /* Buffer is empty check for a blocking zlp, handle it */ | ||
881 | if ((s & (1 << NAK_OUT_PACKETS)) && | ||
882 | net2272_ep_read(ep, EP_STAT1) & (1 << LOCAL_OUT_ZLP)) { | ||
883 | dev_dbg(dev->dev, "WARNING: returning ZLP short packet termination!\n"); | ||
884 | /* | ||
885 | * Request is going to terminate with a short packet ... | ||
886 | * hope the client is ready for it! | ||
887 | */ | ||
888 | status = net2272_read_fifo(ep, req); | ||
889 | /* clear short packet naking */ | ||
890 | net2272_ep_write(ep, EP_STAT0, (1 << NAK_OUT_PACKETS)); | ||
891 | goto done; | ||
892 | } | ||
893 | } | ||
894 | |||
895 | /* try dma first */ | ||
896 | status = net2272_kick_dma(ep, req); | ||
897 | |||
898 | if (status < 0) { | ||
899 | /* dma failed (most likely in use by another endpoint) | ||
900 | * fallback to pio | ||
901 | */ | ||
902 | status = 0; | ||
903 | |||
904 | if (ep->is_in) | ||
905 | status = net2272_write_fifo(ep, req); | ||
906 | else { | ||
907 | s = net2272_ep_read(ep, EP_STAT0); | ||
908 | if ((s & (1 << BUFFER_EMPTY)) == 0) | ||
909 | status = net2272_read_fifo(ep, req); | ||
910 | } | ||
911 | |||
912 | if (unlikely(status != 0)) { | ||
913 | if (status > 0) | ||
914 | status = 0; | ||
915 | req = NULL; | ||
916 | } | ||
917 | } | ||
918 | } | ||
919 | if (likely(req != 0)) | ||
920 | list_add_tail(&req->queue, &ep->queue); | ||
921 | |||
922 | if (likely(!list_empty(&ep->queue))) | ||
923 | net2272_ep_write(ep, EP_RSPCLR, 1 << ALT_NAK_OUT_PACKETS); | ||
924 | done: | ||
925 | spin_unlock_irqrestore(&dev->lock, flags); | ||
926 | |||
927 | return 0; | ||
928 | } | ||
929 | |||
930 | /* dequeue ALL requests */ | ||
931 | static void | ||
932 | net2272_dequeue_all(struct net2272_ep *ep) | ||
933 | { | ||
934 | struct net2272_request *req; | ||
935 | |||
936 | /* called with spinlock held */ | ||
937 | ep->stopped = 1; | ||
938 | |||
939 | while (!list_empty(&ep->queue)) { | ||
940 | req = list_entry(ep->queue.next, | ||
941 | struct net2272_request, | ||
942 | queue); | ||
943 | net2272_done(ep, req, -ESHUTDOWN); | ||
944 | } | ||
945 | } | ||
946 | |||
947 | /* dequeue JUST ONE request */ | ||
948 | static int | ||
949 | net2272_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
950 | { | ||
951 | struct net2272_ep *ep; | ||
952 | struct net2272_request *req; | ||
953 | unsigned long flags; | ||
954 | int stopped; | ||
955 | |||
956 | ep = container_of(_ep, struct net2272_ep, ep); | ||
957 | if (!_ep || (!ep->desc && ep->num != 0) || !_req) | ||
958 | return -EINVAL; | ||
959 | |||
960 | spin_lock_irqsave(&ep->dev->lock, flags); | ||
961 | stopped = ep->stopped; | ||
962 | ep->stopped = 1; | ||
963 | |||
964 | /* make sure it's still queued on this endpoint */ | ||
965 | list_for_each_entry(req, &ep->queue, queue) { | ||
966 | if (&req->req == _req) | ||
967 | break; | ||
968 | } | ||
969 | if (&req->req != _req) { | ||
970 | spin_unlock_irqrestore(&ep->dev->lock, flags); | ||
971 | return -EINVAL; | ||
972 | } | ||
973 | |||
974 | /* queue head may be partially complete */ | ||
975 | if (ep->queue.next == &req->queue) { | ||
976 | dev_dbg(ep->dev->dev, "unlink (%s) pio\n", _ep->name); | ||
977 | net2272_done(ep, req, -ECONNRESET); | ||
978 | } | ||
979 | req = NULL; | ||
980 | ep->stopped = stopped; | ||
981 | |||
982 | spin_unlock_irqrestore(&ep->dev->lock, flags); | ||
983 | return 0; | ||
984 | } | ||
985 | |||
986 | /*---------------------------------------------------------------------------*/ | ||
987 | |||
988 | static int | ||
989 | net2272_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged) | ||
990 | { | ||
991 | struct net2272_ep *ep; | ||
992 | unsigned long flags; | ||
993 | int ret = 0; | ||
994 | |||
995 | ep = container_of(_ep, struct net2272_ep, ep); | ||
996 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
997 | return -EINVAL; | ||
998 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
999 | return -ESHUTDOWN; | ||
1000 | if (ep->desc /* not ep0 */ && usb_endpoint_xfer_isoc(ep->desc)) | ||
1001 | return -EINVAL; | ||
1002 | |||
1003 | spin_lock_irqsave(&ep->dev->lock, flags); | ||
1004 | if (!list_empty(&ep->queue)) | ||
1005 | ret = -EAGAIN; | ||
1006 | else if (ep->is_in && value && net2272_fifo_status(_ep) != 0) | ||
1007 | ret = -EAGAIN; | ||
1008 | else { | ||
1009 | dev_vdbg(ep->dev->dev, "%s %s %s\n", _ep->name, | ||
1010 | value ? "set" : "clear", | ||
1011 | wedged ? "wedge" : "halt"); | ||
1012 | /* set/clear */ | ||
1013 | if (value) { | ||
1014 | if (ep->num == 0) | ||
1015 | ep->dev->protocol_stall = 1; | ||
1016 | else | ||
1017 | set_halt(ep); | ||
1018 | if (wedged) | ||
1019 | ep->wedged = 1; | ||
1020 | } else { | ||
1021 | clear_halt(ep); | ||
1022 | ep->wedged = 0; | ||
1023 | } | ||
1024 | } | ||
1025 | spin_unlock_irqrestore(&ep->dev->lock, flags); | ||
1026 | |||
1027 | return ret; | ||
1028 | } | ||
1029 | |||
1030 | static int | ||
1031 | net2272_set_halt(struct usb_ep *_ep, int value) | ||
1032 | { | ||
1033 | return net2272_set_halt_and_wedge(_ep, value, 0); | ||
1034 | } | ||
1035 | |||
1036 | static int | ||
1037 | net2272_set_wedge(struct usb_ep *_ep) | ||
1038 | { | ||
1039 | if (!_ep || _ep->name == ep0name) | ||
1040 | return -EINVAL; | ||
1041 | return net2272_set_halt_and_wedge(_ep, 1, 1); | ||
1042 | } | ||
1043 | |||
1044 | static int | ||
1045 | net2272_fifo_status(struct usb_ep *_ep) | ||
1046 | { | ||
1047 | struct net2272_ep *ep; | ||
1048 | u16 avail; | ||
1049 | |||
1050 | ep = container_of(_ep, struct net2272_ep, ep); | ||
1051 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
1052 | return -ENODEV; | ||
1053 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1054 | return -ESHUTDOWN; | ||
1055 | |||
1056 | avail = net2272_ep_read(ep, EP_AVAIL1) << 8; | ||
1057 | avail |= net2272_ep_read(ep, EP_AVAIL0); | ||
1058 | if (avail > ep->fifo_size) | ||
1059 | return -EOVERFLOW; | ||
1060 | if (ep->is_in) | ||
1061 | avail = ep->fifo_size - avail; | ||
1062 | return avail; | ||
1063 | } | ||
1064 | |||
1065 | static void | ||
1066 | net2272_fifo_flush(struct usb_ep *_ep) | ||
1067 | { | ||
1068 | struct net2272_ep *ep; | ||
1069 | |||
1070 | ep = container_of(_ep, struct net2272_ep, ep); | ||
1071 | if (!_ep || (!ep->desc && ep->num != 0)) | ||
1072 | return; | ||
1073 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1074 | return; | ||
1075 | |||
1076 | net2272_ep_write(ep, EP_STAT1, 1 << BUFFER_FLUSH); | ||
1077 | } | ||
1078 | |||
1079 | static struct usb_ep_ops net2272_ep_ops = { | ||
1080 | .enable = net2272_enable, | ||
1081 | .disable = net2272_disable, | ||
1082 | |||
1083 | .alloc_request = net2272_alloc_request, | ||
1084 | .free_request = net2272_free_request, | ||
1085 | |||
1086 | .queue = net2272_queue, | ||
1087 | .dequeue = net2272_dequeue, | ||
1088 | |||
1089 | .set_halt = net2272_set_halt, | ||
1090 | .set_wedge = net2272_set_wedge, | ||
1091 | .fifo_status = net2272_fifo_status, | ||
1092 | .fifo_flush = net2272_fifo_flush, | ||
1093 | }; | ||
1094 | |||
1095 | /*---------------------------------------------------------------------------*/ | ||
1096 | |||
1097 | static int | ||
1098 | net2272_get_frame(struct usb_gadget *_gadget) | ||
1099 | { | ||
1100 | struct net2272 *dev; | ||
1101 | unsigned long flags; | ||
1102 | u16 ret; | ||
1103 | |||
1104 | if (!_gadget) | ||
1105 | return -ENODEV; | ||
1106 | dev = container_of(_gadget, struct net2272, gadget); | ||
1107 | spin_lock_irqsave(&dev->lock, flags); | ||
1108 | |||
1109 | ret = net2272_read(dev, FRAME1) << 8; | ||
1110 | ret |= net2272_read(dev, FRAME0); | ||
1111 | |||
1112 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1113 | return ret; | ||
1114 | } | ||
1115 | |||
1116 | static int | ||
1117 | net2272_wakeup(struct usb_gadget *_gadget) | ||
1118 | { | ||
1119 | struct net2272 *dev; | ||
1120 | u8 tmp; | ||
1121 | unsigned long flags; | ||
1122 | |||
1123 | if (!_gadget) | ||
1124 | return 0; | ||
1125 | dev = container_of(_gadget, struct net2272, gadget); | ||
1126 | |||
1127 | spin_lock_irqsave(&dev->lock, flags); | ||
1128 | tmp = net2272_read(dev, USBCTL0); | ||
1129 | if (tmp & (1 << IO_WAKEUP_ENABLE)) | ||
1130 | net2272_write(dev, USBCTL1, (1 << GENERATE_RESUME)); | ||
1131 | |||
1132 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1133 | |||
1134 | return 0; | ||
1135 | } | ||
1136 | |||
1137 | static int | ||
1138 | net2272_set_selfpowered(struct usb_gadget *_gadget, int value) | ||
1139 | { | ||
1140 | struct net2272 *dev; | ||
1141 | |||
1142 | if (!_gadget) | ||
1143 | return -ENODEV; | ||
1144 | dev = container_of(_gadget, struct net2272, gadget); | ||
1145 | |||
1146 | dev->is_selfpowered = value; | ||
1147 | |||
1148 | return 0; | ||
1149 | } | ||
1150 | |||
1151 | static int | ||
1152 | net2272_pullup(struct usb_gadget *_gadget, int is_on) | ||
1153 | { | ||
1154 | struct net2272 *dev; | ||
1155 | u8 tmp; | ||
1156 | unsigned long flags; | ||
1157 | |||
1158 | if (!_gadget) | ||
1159 | return -ENODEV; | ||
1160 | dev = container_of(_gadget, struct net2272, gadget); | ||
1161 | |||
1162 | spin_lock_irqsave(&dev->lock, flags); | ||
1163 | tmp = net2272_read(dev, USBCTL0); | ||
1164 | dev->softconnect = (is_on != 0); | ||
1165 | if (is_on) | ||
1166 | tmp |= (1 << USB_DETECT_ENABLE); | ||
1167 | else | ||
1168 | tmp &= ~(1 << USB_DETECT_ENABLE); | ||
1169 | net2272_write(dev, USBCTL0, tmp); | ||
1170 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1171 | |||
1172 | return 0; | ||
1173 | } | ||
1174 | |||
1175 | static int net2272_start(struct usb_gadget_driver *driver, | ||
1176 | int (*bind)(struct usb_gadget *)); | ||
1177 | static int net2272_stop(struct usb_gadget_driver *driver); | ||
1178 | |||
1179 | static const struct usb_gadget_ops net2272_ops = { | ||
1180 | .get_frame = net2272_get_frame, | ||
1181 | .wakeup = net2272_wakeup, | ||
1182 | .set_selfpowered = net2272_set_selfpowered, | ||
1183 | .pullup = net2272_pullup, | ||
1184 | .start = net2272_start, | ||
1185 | .stop = net2272_stop, | ||
1186 | }; | ||
1187 | |||
1188 | /*---------------------------------------------------------------------------*/ | ||
1189 | |||
1190 | static ssize_t | ||
1191 | net2272_show_registers(struct device *_dev, struct device_attribute *attr, char *buf) | ||
1192 | { | ||
1193 | struct net2272 *dev; | ||
1194 | char *next; | ||
1195 | unsigned size, t; | ||
1196 | unsigned long flags; | ||
1197 | u8 t1, t2; | ||
1198 | int i; | ||
1199 | const char *s; | ||
1200 | |||
1201 | dev = dev_get_drvdata(_dev); | ||
1202 | next = buf; | ||
1203 | size = PAGE_SIZE; | ||
1204 | spin_lock_irqsave(&dev->lock, flags); | ||
1205 | |||
1206 | if (dev->driver) | ||
1207 | s = dev->driver->driver.name; | ||
1208 | else | ||
1209 | s = "(none)"; | ||
1210 | |||
1211 | /* Main Control Registers */ | ||
1212 | t = scnprintf(next, size, "%s version %s," | ||
1213 | "chiprev %02x, locctl %02x\n" | ||
1214 | "irqenb0 %02x irqenb1 %02x " | ||
1215 | "irqstat0 %02x irqstat1 %02x\n", | ||
1216 | driver_name, driver_vers, dev->chiprev, | ||
1217 | net2272_read(dev, LOCCTL), | ||
1218 | net2272_read(dev, IRQENB0), | ||
1219 | net2272_read(dev, IRQENB1), | ||
1220 | net2272_read(dev, IRQSTAT0), | ||
1221 | net2272_read(dev, IRQSTAT1)); | ||
1222 | size -= t; | ||
1223 | next += t; | ||
1224 | |||
1225 | /* DMA */ | ||
1226 | t1 = net2272_read(dev, DMAREQ); | ||
1227 | t = scnprintf(next, size, "\ndmareq %02x: %s %s%s%s%s\n", | ||
1228 | t1, ep_name[(t1 & 0x01) + 1], | ||
1229 | t1 & (1 << DMA_CONTROL_DACK) ? "dack " : "", | ||
1230 | t1 & (1 << DMA_REQUEST_ENABLE) ? "reqenb " : "", | ||
1231 | t1 & (1 << DMA_REQUEST) ? "req " : "", | ||
1232 | t1 & (1 << DMA_BUFFER_VALID) ? "valid " : ""); | ||
1233 | size -= t; | ||
1234 | next += t; | ||
1235 | |||
1236 | /* USB Control Registers */ | ||
1237 | t1 = net2272_read(dev, USBCTL1); | ||
1238 | if (t1 & (1 << VBUS_PIN)) { | ||
1239 | if (t1 & (1 << USB_HIGH_SPEED)) | ||
1240 | s = "high speed"; | ||
1241 | else if (dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1242 | s = "powered"; | ||
1243 | else | ||
1244 | s = "full speed"; | ||
1245 | } else | ||
1246 | s = "not attached"; | ||
1247 | t = scnprintf(next, size, | ||
1248 | "usbctl0 %02x usbctl1 %02x addr 0x%02x (%s)\n", | ||
1249 | net2272_read(dev, USBCTL0), t1, | ||
1250 | net2272_read(dev, OURADDR), s); | ||
1251 | size -= t; | ||
1252 | next += t; | ||
1253 | |||
1254 | /* Endpoint Registers */ | ||
1255 | for (i = 0; i < 4; ++i) { | ||
1256 | struct net2272_ep *ep; | ||
1257 | |||
1258 | ep = &dev->ep[i]; | ||
1259 | if (i && !ep->desc) | ||
1260 | continue; | ||
1261 | |||
1262 | t1 = net2272_ep_read(ep, EP_CFG); | ||
1263 | t2 = net2272_ep_read(ep, EP_RSPSET); | ||
1264 | t = scnprintf(next, size, | ||
1265 | "\n%s\tcfg %02x rsp (%02x) %s%s%s%s%s%s%s%s" | ||
1266 | "irqenb %02x\n", | ||
1267 | ep->ep.name, t1, t2, | ||
1268 | (t2 & (1 << ALT_NAK_OUT_PACKETS)) ? "NAK " : "", | ||
1269 | (t2 & (1 << HIDE_STATUS_PHASE)) ? "hide " : "", | ||
1270 | (t2 & (1 << AUTOVALIDATE)) ? "auto " : "", | ||
1271 | (t2 & (1 << INTERRUPT_MODE)) ? "interrupt " : "", | ||
1272 | (t2 & (1 << CONTROL_STATUS_PHASE_HANDSHAKE)) ? "status " : "", | ||
1273 | (t2 & (1 << NAK_OUT_PACKETS_MODE)) ? "NAKmode " : "", | ||
1274 | (t2 & (1 << ENDPOINT_TOGGLE)) ? "DATA1 " : "DATA0 ", | ||
1275 | (t2 & (1 << ENDPOINT_HALT)) ? "HALT " : "", | ||
1276 | net2272_ep_read(ep, EP_IRQENB)); | ||
1277 | size -= t; | ||
1278 | next += t; | ||
1279 | |||
1280 | t = scnprintf(next, size, | ||
1281 | "\tstat0 %02x stat1 %02x avail %04x " | ||
1282 | "(ep%d%s-%s)%s\n", | ||
1283 | net2272_ep_read(ep, EP_STAT0), | ||
1284 | net2272_ep_read(ep, EP_STAT1), | ||
1285 | (net2272_ep_read(ep, EP_AVAIL1) << 8) | net2272_ep_read(ep, EP_AVAIL0), | ||
1286 | t1 & 0x0f, | ||
1287 | ep->is_in ? "in" : "out", | ||
1288 | type_string(t1 >> 5), | ||
1289 | ep->stopped ? "*" : ""); | ||
1290 | size -= t; | ||
1291 | next += t; | ||
1292 | |||
1293 | t = scnprintf(next, size, | ||
1294 | "\tep_transfer %06x\n", | ||
1295 | ((net2272_ep_read(ep, EP_TRANSFER2) & 0xff) << 16) | | ||
1296 | ((net2272_ep_read(ep, EP_TRANSFER1) & 0xff) << 8) | | ||
1297 | ((net2272_ep_read(ep, EP_TRANSFER0) & 0xff))); | ||
1298 | size -= t; | ||
1299 | next += t; | ||
1300 | |||
1301 | t1 = net2272_ep_read(ep, EP_BUFF_STATES) & 0x03; | ||
1302 | t2 = (net2272_ep_read(ep, EP_BUFF_STATES) >> 2) & 0x03; | ||
1303 | t = scnprintf(next, size, | ||
1304 | "\tbuf-a %s buf-b %s\n", | ||
1305 | buf_state_string(t1), | ||
1306 | buf_state_string(t2)); | ||
1307 | size -= t; | ||
1308 | next += t; | ||
1309 | } | ||
1310 | |||
1311 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1312 | |||
1313 | return PAGE_SIZE - size; | ||
1314 | } | ||
1315 | static DEVICE_ATTR(registers, S_IRUGO, net2272_show_registers, NULL); | ||
1316 | |||
1317 | /*---------------------------------------------------------------------------*/ | ||
1318 | |||
1319 | static void | ||
1320 | net2272_set_fifo_mode(struct net2272 *dev, int mode) | ||
1321 | { | ||
1322 | u8 tmp; | ||
1323 | |||
1324 | tmp = net2272_read(dev, LOCCTL) & 0x3f; | ||
1325 | tmp |= (mode << 6); | ||
1326 | net2272_write(dev, LOCCTL, tmp); | ||
1327 | |||
1328 | INIT_LIST_HEAD(&dev->gadget.ep_list); | ||
1329 | |||
1330 | /* always ep-a, ep-c ... maybe not ep-b */ | ||
1331 | list_add_tail(&dev->ep[1].ep.ep_list, &dev->gadget.ep_list); | ||
1332 | |||
1333 | switch (mode) { | ||
1334 | case 0: | ||
1335 | list_add_tail(&dev->ep[2].ep.ep_list, &dev->gadget.ep_list); | ||
1336 | dev->ep[1].fifo_size = dev->ep[2].fifo_size = 512; | ||
1337 | break; | ||
1338 | case 1: | ||
1339 | list_add_tail(&dev->ep[2].ep.ep_list, &dev->gadget.ep_list); | ||
1340 | dev->ep[1].fifo_size = 1024; | ||
1341 | dev->ep[2].fifo_size = 512; | ||
1342 | break; | ||
1343 | case 2: | ||
1344 | list_add_tail(&dev->ep[2].ep.ep_list, &dev->gadget.ep_list); | ||
1345 | dev->ep[1].fifo_size = dev->ep[2].fifo_size = 1024; | ||
1346 | break; | ||
1347 | case 3: | ||
1348 | dev->ep[1].fifo_size = 1024; | ||
1349 | break; | ||
1350 | } | ||
1351 | |||
1352 | /* ep-c is always 2 512 byte buffers */ | ||
1353 | list_add_tail(&dev->ep[3].ep.ep_list, &dev->gadget.ep_list); | ||
1354 | dev->ep[3].fifo_size = 512; | ||
1355 | } | ||
1356 | |||
1357 | /*---------------------------------------------------------------------------*/ | ||
1358 | |||
1359 | static struct net2272 *the_controller; | ||
1360 | |||
1361 | static void | ||
1362 | net2272_usb_reset(struct net2272 *dev) | ||
1363 | { | ||
1364 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
1365 | |||
1366 | net2272_cancel_dma(dev); | ||
1367 | |||
1368 | net2272_write(dev, IRQENB0, 0); | ||
1369 | net2272_write(dev, IRQENB1, 0); | ||
1370 | |||
1371 | /* clear irq state */ | ||
1372 | net2272_write(dev, IRQSTAT0, 0xff); | ||
1373 | net2272_write(dev, IRQSTAT1, ~(1 << SUSPEND_REQUEST_INTERRUPT)); | ||
1374 | |||
1375 | net2272_write(dev, DMAREQ, | ||
1376 | (0 << DMA_BUFFER_VALID) | | ||
1377 | (0 << DMA_REQUEST_ENABLE) | | ||
1378 | (1 << DMA_CONTROL_DACK) | | ||
1379 | (dev->dma_eot_polarity << EOT_POLARITY) | | ||
1380 | (dev->dma_dack_polarity << DACK_POLARITY) | | ||
1381 | (dev->dma_dreq_polarity << DREQ_POLARITY) | | ||
1382 | ((dma_ep >> 1) << DMA_ENDPOINT_SELECT)); | ||
1383 | |||
1384 | net2272_cancel_dma(dev); | ||
1385 | net2272_set_fifo_mode(dev, (fifo_mode <= 3) ? fifo_mode : 0); | ||
1386 | |||
1387 | /* Set the NET2272 ep fifo data width to 16-bit mode and for correct byte swapping | ||
1388 | * note that the higher level gadget drivers are expected to convert data to little endian. | ||
1389 | * Enable byte swap for your local bus/cpu if needed by setting BYTE_SWAP in LOCCTL here | ||
1390 | */ | ||
1391 | net2272_write(dev, LOCCTL, net2272_read(dev, LOCCTL) | (1 << DATA_WIDTH)); | ||
1392 | net2272_write(dev, LOCCTL1, (dma_mode << DMA_MODE)); | ||
1393 | } | ||
1394 | |||
1395 | static void | ||
1396 | net2272_usb_reinit(struct net2272 *dev) | ||
1397 | { | ||
1398 | int i; | ||
1399 | |||
1400 | /* basic endpoint init */ | ||
1401 | for (i = 0; i < 4; ++i) { | ||
1402 | struct net2272_ep *ep = &dev->ep[i]; | ||
1403 | |||
1404 | ep->ep.name = ep_name[i]; | ||
1405 | ep->dev = dev; | ||
1406 | ep->num = i; | ||
1407 | ep->not_empty = 0; | ||
1408 | |||
1409 | if (use_dma && ep->num == dma_ep) | ||
1410 | ep->dma = 1; | ||
1411 | |||
1412 | if (i > 0 && i <= 3) | ||
1413 | ep->fifo_size = 512; | ||
1414 | else | ||
1415 | ep->fifo_size = 64; | ||
1416 | net2272_ep_reset(ep); | ||
1417 | } | ||
1418 | dev->ep[0].ep.maxpacket = 64; | ||
1419 | |||
1420 | dev->gadget.ep0 = &dev->ep[0].ep; | ||
1421 | dev->ep[0].stopped = 0; | ||
1422 | INIT_LIST_HEAD(&dev->gadget.ep0->ep_list); | ||
1423 | } | ||
1424 | |||
1425 | static void | ||
1426 | net2272_ep0_start(struct net2272 *dev) | ||
1427 | { | ||
1428 | struct net2272_ep *ep0 = &dev->ep[0]; | ||
1429 | |||
1430 | net2272_ep_write(ep0, EP_RSPSET, | ||
1431 | (1 << NAK_OUT_PACKETS_MODE) | | ||
1432 | (1 << ALT_NAK_OUT_PACKETS)); | ||
1433 | net2272_ep_write(ep0, EP_RSPCLR, | ||
1434 | (1 << HIDE_STATUS_PHASE) | | ||
1435 | (1 << CONTROL_STATUS_PHASE_HANDSHAKE)); | ||
1436 | net2272_write(dev, USBCTL0, | ||
1437 | (dev->softconnect << USB_DETECT_ENABLE) | | ||
1438 | (1 << USB_ROOT_PORT_WAKEUP_ENABLE) | | ||
1439 | (1 << IO_WAKEUP_ENABLE)); | ||
1440 | net2272_write(dev, IRQENB0, | ||
1441 | (1 << SETUP_PACKET_INTERRUPT_ENABLE) | | ||
1442 | (1 << ENDPOINT_0_INTERRUPT_ENABLE) | | ||
1443 | (1 << DMA_DONE_INTERRUPT_ENABLE)); | ||
1444 | net2272_write(dev, IRQENB1, | ||
1445 | (1 << VBUS_INTERRUPT_ENABLE) | | ||
1446 | (1 << ROOT_PORT_RESET_INTERRUPT_ENABLE) | | ||
1447 | (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE)); | ||
1448 | } | ||
1449 | |||
1450 | /* when a driver is successfully registered, it will receive | ||
1451 | * control requests including set_configuration(), which enables | ||
1452 | * non-control requests. then usb traffic follows until a | ||
1453 | * disconnect is reported. then a host may connect again, or | ||
1454 | * the driver might get unbound. | ||
1455 | */ | ||
1456 | static int net2272_start(struct usb_gadget_driver *driver, | ||
1457 | int (*bind)(struct usb_gadget *)) | ||
1458 | { | ||
1459 | struct net2272 *dev = the_controller; | ||
1460 | int ret; | ||
1461 | unsigned i; | ||
1462 | |||
1463 | if (!driver || !bind || !driver->unbind || !driver->setup || | ||
1464 | driver->speed != USB_SPEED_HIGH) | ||
1465 | return -EINVAL; | ||
1466 | if (!dev) | ||
1467 | return -ENODEV; | ||
1468 | if (dev->driver) | ||
1469 | return -EBUSY; | ||
1470 | |||
1471 | for (i = 0; i < 4; ++i) | ||
1472 | dev->ep[i].irqs = 0; | ||
1473 | /* hook up the driver ... */ | ||
1474 | dev->softconnect = 1; | ||
1475 | driver->driver.bus = NULL; | ||
1476 | dev->driver = driver; | ||
1477 | dev->gadget.dev.driver = &driver->driver; | ||
1478 | ret = bind(&dev->gadget); | ||
1479 | if (ret) { | ||
1480 | dev_dbg(dev->dev, "bind to driver %s --> %d\n", | ||
1481 | driver->driver.name, ret); | ||
1482 | dev->driver = NULL; | ||
1483 | dev->gadget.dev.driver = NULL; | ||
1484 | return ret; | ||
1485 | } | ||
1486 | |||
1487 | /* ... then enable host detection and ep0; and we're ready | ||
1488 | * for set_configuration as well as eventual disconnect. | ||
1489 | */ | ||
1490 | net2272_ep0_start(dev); | ||
1491 | |||
1492 | dev_dbg(dev->dev, "%s ready\n", driver->driver.name); | ||
1493 | |||
1494 | return 0; | ||
1495 | } | ||
1496 | |||
1497 | static void | ||
1498 | stop_activity(struct net2272 *dev, struct usb_gadget_driver *driver) | ||
1499 | { | ||
1500 | int i; | ||
1501 | |||
1502 | /* don't disconnect if it's not connected */ | ||
1503 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1504 | driver = NULL; | ||
1505 | |||
1506 | /* stop hardware; prevent new request submissions; | ||
1507 | * and kill any outstanding requests. | ||
1508 | */ | ||
1509 | net2272_usb_reset(dev); | ||
1510 | for (i = 0; i < 4; ++i) | ||
1511 | net2272_dequeue_all(&dev->ep[i]); | ||
1512 | |||
1513 | /* report disconnect; the driver is already quiesced */ | ||
1514 | if (driver) { | ||
1515 | spin_unlock(&dev->lock); | ||
1516 | driver->disconnect(&dev->gadget); | ||
1517 | spin_lock(&dev->lock); | ||
1518 | |||
1519 | } | ||
1520 | net2272_usb_reinit(dev); | ||
1521 | } | ||
1522 | |||
1523 | static int net2272_stop(struct usb_gadget_driver *driver) | ||
1524 | { | ||
1525 | struct net2272 *dev = the_controller; | ||
1526 | unsigned long flags; | ||
1527 | |||
1528 | if (!dev) | ||
1529 | return -ENODEV; | ||
1530 | if (!driver || driver != dev->driver) | ||
1531 | return -EINVAL; | ||
1532 | |||
1533 | spin_lock_irqsave(&dev->lock, flags); | ||
1534 | stop_activity(dev, driver); | ||
1535 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1536 | |||
1537 | net2272_pullup(&dev->gadget, 0); | ||
1538 | |||
1539 | driver->unbind(&dev->gadget); | ||
1540 | dev->gadget.dev.driver = NULL; | ||
1541 | dev->driver = NULL; | ||
1542 | |||
1543 | dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name); | ||
1544 | return 0; | ||
1545 | } | ||
1546 | |||
1547 | /*---------------------------------------------------------------------------*/ | ||
1548 | /* handle ep-a/ep-b dma completions */ | ||
1549 | static void | ||
1550 | net2272_handle_dma(struct net2272_ep *ep) | ||
1551 | { | ||
1552 | struct net2272_request *req; | ||
1553 | unsigned len; | ||
1554 | int status; | ||
1555 | |||
1556 | if (!list_empty(&ep->queue)) | ||
1557 | req = list_entry(ep->queue.next, | ||
1558 | struct net2272_request, queue); | ||
1559 | else | ||
1560 | req = NULL; | ||
1561 | |||
1562 | dev_vdbg(ep->dev->dev, "handle_dma %s req %p\n", ep->ep.name, req); | ||
1563 | |||
1564 | /* Ensure DREQ is de-asserted */ | ||
1565 | net2272_write(ep->dev, DMAREQ, | ||
1566 | (0 << DMA_BUFFER_VALID) | ||
1567 | | (0 << DMA_REQUEST_ENABLE) | ||
1568 | | (1 << DMA_CONTROL_DACK) | ||
1569 | | (ep->dev->dma_eot_polarity << EOT_POLARITY) | ||
1570 | | (ep->dev->dma_dack_polarity << DACK_POLARITY) | ||
1571 | | (ep->dev->dma_dreq_polarity << DREQ_POLARITY) | ||
1572 | | ((ep->dma >> 1) << DMA_ENDPOINT_SELECT)); | ||
1573 | |||
1574 | ep->dev->dma_busy = 0; | ||
1575 | |||
1576 | net2272_ep_write(ep, EP_IRQENB, | ||
1577 | (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) | ||
1578 | | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE) | ||
1579 | | net2272_ep_read(ep, EP_IRQENB)); | ||
1580 | |||
1581 | /* device-to-host transfer completed */ | ||
1582 | if (ep->is_in) { | ||
1583 | /* validate a short packet or zlp if necessary */ | ||
1584 | if ((req->req.length % ep->ep.maxpacket != 0) || | ||
1585 | req->req.zero) | ||
1586 | set_fifo_bytecount(ep, 0); | ||
1587 | |||
1588 | net2272_done(ep, req, 0); | ||
1589 | if (!list_empty(&ep->queue)) { | ||
1590 | req = list_entry(ep->queue.next, | ||
1591 | struct net2272_request, queue); | ||
1592 | status = net2272_kick_dma(ep, req); | ||
1593 | if (status < 0) | ||
1594 | net2272_pio_advance(ep); | ||
1595 | } | ||
1596 | |||
1597 | /* host-to-device transfer completed */ | ||
1598 | } else { | ||
1599 | /* terminated with a short packet? */ | ||
1600 | if (net2272_read(ep->dev, IRQSTAT0) & | ||
1601 | (1 << DMA_DONE_INTERRUPT)) { | ||
1602 | /* abort system dma */ | ||
1603 | net2272_cancel_dma(ep->dev); | ||
1604 | } | ||
1605 | |||
1606 | /* EP_TRANSFER will contain the number of bytes | ||
1607 | * actually received. | ||
1608 | * NOTE: There is no overflow detection on EP_TRANSFER: | ||
1609 | * We can't deal with transfers larger than 2^24 bytes! | ||
1610 | */ | ||
1611 | len = (net2272_ep_read(ep, EP_TRANSFER2) << 16) | ||
1612 | | (net2272_ep_read(ep, EP_TRANSFER1) << 8) | ||
1613 | | (net2272_ep_read(ep, EP_TRANSFER0)); | ||
1614 | |||
1615 | if (ep->not_empty) | ||
1616 | len += 4; | ||
1617 | |||
1618 | req->req.actual += len; | ||
1619 | |||
1620 | /* get any remaining data */ | ||
1621 | net2272_pio_advance(ep); | ||
1622 | } | ||
1623 | } | ||
1624 | |||
1625 | /*---------------------------------------------------------------------------*/ | ||
1626 | |||
1627 | static void | ||
1628 | net2272_handle_ep(struct net2272_ep *ep) | ||
1629 | { | ||
1630 | struct net2272_request *req; | ||
1631 | u8 stat0, stat1; | ||
1632 | |||
1633 | if (!list_empty(&ep->queue)) | ||
1634 | req = list_entry(ep->queue.next, | ||
1635 | struct net2272_request, queue); | ||
1636 | else | ||
1637 | req = NULL; | ||
1638 | |||
1639 | /* ack all, and handle what we care about */ | ||
1640 | stat0 = net2272_ep_read(ep, EP_STAT0); | ||
1641 | stat1 = net2272_ep_read(ep, EP_STAT1); | ||
1642 | ep->irqs++; | ||
1643 | |||
1644 | dev_vdbg(ep->dev->dev, "%s ack ep_stat0 %02x, ep_stat1 %02x, req %p\n", | ||
1645 | ep->ep.name, stat0, stat1, req ? &req->req : 0); | ||
1646 | |||
1647 | net2272_ep_write(ep, EP_STAT0, stat0 & | ||
1648 | ~((1 << NAK_OUT_PACKETS) | ||
1649 | | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT))); | ||
1650 | net2272_ep_write(ep, EP_STAT1, stat1); | ||
1651 | |||
1652 | /* data packet(s) received (in the fifo, OUT) | ||
1653 | * direction must be validated, otherwise control read status phase | ||
1654 | * could be interpreted as a valid packet | ||
1655 | */ | ||
1656 | if (!ep->is_in && (stat0 & (1 << DATA_PACKET_RECEIVED_INTERRUPT))) | ||
1657 | net2272_pio_advance(ep); | ||
1658 | /* data packet(s) transmitted (IN) */ | ||
1659 | else if (stat0 & (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)) | ||
1660 | net2272_pio_advance(ep); | ||
1661 | } | ||
1662 | |||
1663 | static struct net2272_ep * | ||
1664 | net2272_get_ep_by_addr(struct net2272 *dev, u16 wIndex) | ||
1665 | { | ||
1666 | struct net2272_ep *ep; | ||
1667 | |||
1668 | if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0) | ||
1669 | return &dev->ep[0]; | ||
1670 | |||
1671 | list_for_each_entry(ep, &dev->gadget.ep_list, ep.ep_list) { | ||
1672 | u8 bEndpointAddress; | ||
1673 | |||
1674 | if (!ep->desc) | ||
1675 | continue; | ||
1676 | bEndpointAddress = ep->desc->bEndpointAddress; | ||
1677 | if ((wIndex ^ bEndpointAddress) & USB_DIR_IN) | ||
1678 | continue; | ||
1679 | if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f)) | ||
1680 | return ep; | ||
1681 | } | ||
1682 | return NULL; | ||
1683 | } | ||
1684 | |||
1685 | /* | ||
1686 | * USB Test Packet: | ||
1687 | * JKJKJKJK * 9 | ||
1688 | * JJKKJJKK * 8 | ||
1689 | * JJJJKKKK * 8 | ||
1690 | * JJJJJJJKKKKKKK * 8 | ||
1691 | * JJJJJJJK * 8 | ||
1692 | * {JKKKKKKK * 10}, JK | ||
1693 | */ | ||
1694 | static const u8 net2272_test_packet[] = { | ||
1695 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
1696 | 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, | ||
1697 | 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, | ||
1698 | 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
1699 | 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, | ||
1700 | 0xFC, 0x7E, 0xBF, 0xDF, 0xEF, 0xF7, 0xFD, 0x7E | ||
1701 | }; | ||
1702 | |||
1703 | static void | ||
1704 | net2272_set_test_mode(struct net2272 *dev, int mode) | ||
1705 | { | ||
1706 | int i; | ||
1707 | |||
1708 | /* Disable all net2272 interrupts: | ||
1709 | * Nothing but a power cycle should stop the test. | ||
1710 | */ | ||
1711 | net2272_write(dev, IRQENB0, 0x00); | ||
1712 | net2272_write(dev, IRQENB1, 0x00); | ||
1713 | |||
1714 | /* Force tranceiver to high-speed */ | ||
1715 | net2272_write(dev, XCVRDIAG, 1 << FORCE_HIGH_SPEED); | ||
1716 | |||
1717 | net2272_write(dev, PAGESEL, 0); | ||
1718 | net2272_write(dev, EP_STAT0, 1 << DATA_PACKET_TRANSMITTED_INTERRUPT); | ||
1719 | net2272_write(dev, EP_RSPCLR, | ||
1720 | (1 << CONTROL_STATUS_PHASE_HANDSHAKE) | ||
1721 | | (1 << HIDE_STATUS_PHASE)); | ||
1722 | net2272_write(dev, EP_CFG, 1 << ENDPOINT_DIRECTION); | ||
1723 | net2272_write(dev, EP_STAT1, 1 << BUFFER_FLUSH); | ||
1724 | |||
1725 | /* wait for status phase to complete */ | ||
1726 | while (!(net2272_read(dev, EP_STAT0) & | ||
1727 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT))) | ||
1728 | ; | ||
1729 | |||
1730 | /* Enable test mode */ | ||
1731 | net2272_write(dev, USBTEST, mode); | ||
1732 | |||
1733 | /* load test packet */ | ||
1734 | if (mode == TEST_PACKET) { | ||
1735 | /* switch to 8 bit mode */ | ||
1736 | net2272_write(dev, LOCCTL, net2272_read(dev, LOCCTL) & | ||
1737 | ~(1 << DATA_WIDTH)); | ||
1738 | |||
1739 | for (i = 0; i < sizeof(net2272_test_packet); ++i) | ||
1740 | net2272_write(dev, EP_DATA, net2272_test_packet[i]); | ||
1741 | |||
1742 | /* Validate test packet */ | ||
1743 | net2272_write(dev, EP_TRANSFER0, 0); | ||
1744 | } | ||
1745 | } | ||
1746 | |||
1747 | static void | ||
1748 | net2272_handle_stat0_irqs(struct net2272 *dev, u8 stat) | ||
1749 | { | ||
1750 | struct net2272_ep *ep; | ||
1751 | u8 num, scratch; | ||
1752 | |||
1753 | /* starting a control request? */ | ||
1754 | if (unlikely(stat & (1 << SETUP_PACKET_INTERRUPT))) { | ||
1755 | union { | ||
1756 | u8 raw[8]; | ||
1757 | struct usb_ctrlrequest r; | ||
1758 | } u; | ||
1759 | int tmp = 0; | ||
1760 | struct net2272_request *req; | ||
1761 | |||
1762 | if (dev->gadget.speed == USB_SPEED_UNKNOWN) { | ||
1763 | if (net2272_read(dev, USBCTL1) & (1 << USB_HIGH_SPEED)) | ||
1764 | dev->gadget.speed = USB_SPEED_HIGH; | ||
1765 | else | ||
1766 | dev->gadget.speed = USB_SPEED_FULL; | ||
1767 | dev_dbg(dev->dev, "%s speed\n", | ||
1768 | (dev->gadget.speed == USB_SPEED_HIGH) ? "high" : "full"); | ||
1769 | } | ||
1770 | |||
1771 | ep = &dev->ep[0]; | ||
1772 | ep->irqs++; | ||
1773 | |||
1774 | /* make sure any leftover interrupt state is cleared */ | ||
1775 | stat &= ~(1 << ENDPOINT_0_INTERRUPT); | ||
1776 | while (!list_empty(&ep->queue)) { | ||
1777 | req = list_entry(ep->queue.next, | ||
1778 | struct net2272_request, queue); | ||
1779 | net2272_done(ep, req, | ||
1780 | (req->req.actual == req->req.length) ? 0 : -EPROTO); | ||
1781 | } | ||
1782 | ep->stopped = 0; | ||
1783 | dev->protocol_stall = 0; | ||
1784 | net2272_ep_write(ep, EP_STAT0, | ||
1785 | (1 << DATA_IN_TOKEN_INTERRUPT) | ||
1786 | | (1 << DATA_OUT_TOKEN_INTERRUPT) | ||
1787 | | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT) | ||
1788 | | (1 << DATA_PACKET_RECEIVED_INTERRUPT) | ||
1789 | | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)); | ||
1790 | net2272_ep_write(ep, EP_STAT1, | ||
1791 | (1 << TIMEOUT) | ||
1792 | | (1 << USB_OUT_ACK_SENT) | ||
1793 | | (1 << USB_OUT_NAK_SENT) | ||
1794 | | (1 << USB_IN_ACK_RCVD) | ||
1795 | | (1 << USB_IN_NAK_SENT) | ||
1796 | | (1 << USB_STALL_SENT) | ||
1797 | | (1 << LOCAL_OUT_ZLP)); | ||
1798 | |||
1799 | /* | ||
1800 | * Ensure Control Read pre-validation setting is beyond maximum size | ||
1801 | * - Control Writes can leave non-zero values in EP_TRANSFER. If | ||
1802 | * an EP0 transfer following the Control Write is a Control Read, | ||
1803 | * the NET2272 sees the non-zero EP_TRANSFER as an unexpected | ||
1804 | * pre-validation count. | ||
1805 | * - Setting EP_TRANSFER beyond the maximum EP0 transfer size ensures | ||
1806 | * the pre-validation count cannot cause an unexpected validatation | ||
1807 | */ | ||
1808 | net2272_write(dev, PAGESEL, 0); | ||
1809 | net2272_write(dev, EP_TRANSFER2, 0xff); | ||
1810 | net2272_write(dev, EP_TRANSFER1, 0xff); | ||
1811 | net2272_write(dev, EP_TRANSFER0, 0xff); | ||
1812 | |||
1813 | u.raw[0] = net2272_read(dev, SETUP0); | ||
1814 | u.raw[1] = net2272_read(dev, SETUP1); | ||
1815 | u.raw[2] = net2272_read(dev, SETUP2); | ||
1816 | u.raw[3] = net2272_read(dev, SETUP3); | ||
1817 | u.raw[4] = net2272_read(dev, SETUP4); | ||
1818 | u.raw[5] = net2272_read(dev, SETUP5); | ||
1819 | u.raw[6] = net2272_read(dev, SETUP6); | ||
1820 | u.raw[7] = net2272_read(dev, SETUP7); | ||
1821 | /* | ||
1822 | * If you have a big endian cpu make sure le16_to_cpus | ||
1823 | * performs the proper byte swapping here... | ||
1824 | */ | ||
1825 | le16_to_cpus(&u.r.wValue); | ||
1826 | le16_to_cpus(&u.r.wIndex); | ||
1827 | le16_to_cpus(&u.r.wLength); | ||
1828 | |||
1829 | /* ack the irq */ | ||
1830 | net2272_write(dev, IRQSTAT0, 1 << SETUP_PACKET_INTERRUPT); | ||
1831 | stat ^= (1 << SETUP_PACKET_INTERRUPT); | ||
1832 | |||
1833 | /* watch control traffic at the token level, and force | ||
1834 | * synchronization before letting the status phase happen. | ||
1835 | */ | ||
1836 | ep->is_in = (u.r.bRequestType & USB_DIR_IN) != 0; | ||
1837 | if (ep->is_in) { | ||
1838 | scratch = (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE) | ||
1839 | | (1 << DATA_OUT_TOKEN_INTERRUPT_ENABLE) | ||
1840 | | (1 << DATA_IN_TOKEN_INTERRUPT_ENABLE); | ||
1841 | stop_out_naking(ep); | ||
1842 | } else | ||
1843 | scratch = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) | ||
1844 | | (1 << DATA_OUT_TOKEN_INTERRUPT_ENABLE) | ||
1845 | | (1 << DATA_IN_TOKEN_INTERRUPT_ENABLE); | ||
1846 | net2272_ep_write(ep, EP_IRQENB, scratch); | ||
1847 | |||
1848 | if ((u.r.bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD) | ||
1849 | goto delegate; | ||
1850 | switch (u.r.bRequest) { | ||
1851 | case USB_REQ_GET_STATUS: { | ||
1852 | struct net2272_ep *e; | ||
1853 | u16 status = 0; | ||
1854 | |||
1855 | switch (u.r.bRequestType & USB_RECIP_MASK) { | ||
1856 | case USB_RECIP_ENDPOINT: | ||
1857 | e = net2272_get_ep_by_addr(dev, u.r.wIndex); | ||
1858 | if (!e || u.r.wLength > 2) | ||
1859 | goto do_stall; | ||
1860 | if (net2272_ep_read(e, EP_RSPSET) & (1 << ENDPOINT_HALT)) | ||
1861 | status = __constant_cpu_to_le16(1); | ||
1862 | else | ||
1863 | status = __constant_cpu_to_le16(0); | ||
1864 | |||
1865 | /* don't bother with a request object! */ | ||
1866 | net2272_ep_write(&dev->ep[0], EP_IRQENB, 0); | ||
1867 | writew(status, net2272_reg_addr(dev, EP_DATA)); | ||
1868 | set_fifo_bytecount(&dev->ep[0], 0); | ||
1869 | allow_status(ep); | ||
1870 | dev_vdbg(dev->dev, "%s stat %02x\n", | ||
1871 | ep->ep.name, status); | ||
1872 | goto next_endpoints; | ||
1873 | case USB_RECIP_DEVICE: | ||
1874 | if (u.r.wLength > 2) | ||
1875 | goto do_stall; | ||
1876 | if (dev->is_selfpowered) | ||
1877 | status = (1 << USB_DEVICE_SELF_POWERED); | ||
1878 | |||
1879 | /* don't bother with a request object! */ | ||
1880 | net2272_ep_write(&dev->ep[0], EP_IRQENB, 0); | ||
1881 | writew(status, net2272_reg_addr(dev, EP_DATA)); | ||
1882 | set_fifo_bytecount(&dev->ep[0], 0); | ||
1883 | allow_status(ep); | ||
1884 | dev_vdbg(dev->dev, "device stat %02x\n", status); | ||
1885 | goto next_endpoints; | ||
1886 | case USB_RECIP_INTERFACE: | ||
1887 | if (u.r.wLength > 2) | ||
1888 | goto do_stall; | ||
1889 | |||
1890 | /* don't bother with a request object! */ | ||
1891 | net2272_ep_write(&dev->ep[0], EP_IRQENB, 0); | ||
1892 | writew(status, net2272_reg_addr(dev, EP_DATA)); | ||
1893 | set_fifo_bytecount(&dev->ep[0], 0); | ||
1894 | allow_status(ep); | ||
1895 | dev_vdbg(dev->dev, "interface status %02x\n", status); | ||
1896 | goto next_endpoints; | ||
1897 | } | ||
1898 | |||
1899 | break; | ||
1900 | } | ||
1901 | case USB_REQ_CLEAR_FEATURE: { | ||
1902 | struct net2272_ep *e; | ||
1903 | |||
1904 | if (u.r.bRequestType != USB_RECIP_ENDPOINT) | ||
1905 | goto delegate; | ||
1906 | if (u.r.wValue != USB_ENDPOINT_HALT || | ||
1907 | u.r.wLength != 0) | ||
1908 | goto do_stall; | ||
1909 | e = net2272_get_ep_by_addr(dev, u.r.wIndex); | ||
1910 | if (!e) | ||
1911 | goto do_stall; | ||
1912 | if (e->wedged) { | ||
1913 | dev_vdbg(dev->dev, "%s wedged, halt not cleared\n", | ||
1914 | ep->ep.name); | ||
1915 | } else { | ||
1916 | dev_vdbg(dev->dev, "%s clear halt\n", ep->ep.name); | ||
1917 | clear_halt(e); | ||
1918 | } | ||
1919 | allow_status(ep); | ||
1920 | goto next_endpoints; | ||
1921 | } | ||
1922 | case USB_REQ_SET_FEATURE: { | ||
1923 | struct net2272_ep *e; | ||
1924 | |||
1925 | if (u.r.bRequestType == USB_RECIP_DEVICE) { | ||
1926 | if (u.r.wIndex != NORMAL_OPERATION) | ||
1927 | net2272_set_test_mode(dev, (u.r.wIndex >> 8)); | ||
1928 | allow_status(ep); | ||
1929 | dev_vdbg(dev->dev, "test mode: %d\n", u.r.wIndex); | ||
1930 | goto next_endpoints; | ||
1931 | } else if (u.r.bRequestType != USB_RECIP_ENDPOINT) | ||
1932 | goto delegate; | ||
1933 | if (u.r.wValue != USB_ENDPOINT_HALT || | ||
1934 | u.r.wLength != 0) | ||
1935 | goto do_stall; | ||
1936 | e = net2272_get_ep_by_addr(dev, u.r.wIndex); | ||
1937 | if (!e) | ||
1938 | goto do_stall; | ||
1939 | set_halt(e); | ||
1940 | allow_status(ep); | ||
1941 | dev_vdbg(dev->dev, "%s set halt\n", ep->ep.name); | ||
1942 | goto next_endpoints; | ||
1943 | } | ||
1944 | case USB_REQ_SET_ADDRESS: { | ||
1945 | net2272_write(dev, OURADDR, u.r.wValue & 0xff); | ||
1946 | allow_status(ep); | ||
1947 | break; | ||
1948 | } | ||
1949 | default: | ||
1950 | delegate: | ||
1951 | dev_vdbg(dev->dev, "setup %02x.%02x v%04x i%04x " | ||
1952 | "ep_cfg %08x\n", | ||
1953 | u.r.bRequestType, u.r.bRequest, | ||
1954 | u.r.wValue, u.r.wIndex, | ||
1955 | net2272_ep_read(ep, EP_CFG)); | ||
1956 | spin_unlock(&dev->lock); | ||
1957 | tmp = dev->driver->setup(&dev->gadget, &u.r); | ||
1958 | spin_lock(&dev->lock); | ||
1959 | } | ||
1960 | |||
1961 | /* stall ep0 on error */ | ||
1962 | if (tmp < 0) { | ||
1963 | do_stall: | ||
1964 | dev_vdbg(dev->dev, "req %02x.%02x protocol STALL; stat %d\n", | ||
1965 | u.r.bRequestType, u.r.bRequest, tmp); | ||
1966 | dev->protocol_stall = 1; | ||
1967 | } | ||
1968 | /* endpoint dma irq? */ | ||
1969 | } else if (stat & (1 << DMA_DONE_INTERRUPT)) { | ||
1970 | net2272_cancel_dma(dev); | ||
1971 | net2272_write(dev, IRQSTAT0, 1 << DMA_DONE_INTERRUPT); | ||
1972 | stat &= ~(1 << DMA_DONE_INTERRUPT); | ||
1973 | num = (net2272_read(dev, DMAREQ) & (1 << DMA_ENDPOINT_SELECT)) | ||
1974 | ? 2 : 1; | ||
1975 | |||
1976 | ep = &dev->ep[num]; | ||
1977 | net2272_handle_dma(ep); | ||
1978 | } | ||
1979 | |||
1980 | next_endpoints: | ||
1981 | /* endpoint data irq? */ | ||
1982 | scratch = stat & 0x0f; | ||
1983 | stat &= ~0x0f; | ||
1984 | for (num = 0; scratch; num++) { | ||
1985 | u8 t; | ||
1986 | |||
1987 | /* does this endpoint's FIFO and queue need tending? */ | ||
1988 | t = 1 << num; | ||
1989 | if ((scratch & t) == 0) | ||
1990 | continue; | ||
1991 | scratch ^= t; | ||
1992 | |||
1993 | ep = &dev->ep[num]; | ||
1994 | net2272_handle_ep(ep); | ||
1995 | } | ||
1996 | |||
1997 | /* some interrupts we can just ignore */ | ||
1998 | stat &= ~(1 << SOF_INTERRUPT); | ||
1999 | |||
2000 | if (stat) | ||
2001 | dev_dbg(dev->dev, "unhandled irqstat0 %02x\n", stat); | ||
2002 | } | ||
2003 | |||
2004 | static void | ||
2005 | net2272_handle_stat1_irqs(struct net2272 *dev, u8 stat) | ||
2006 | { | ||
2007 | u8 tmp, mask; | ||
2008 | |||
2009 | /* after disconnect there's nothing else to do! */ | ||
2010 | tmp = (1 << VBUS_INTERRUPT) | (1 << ROOT_PORT_RESET_INTERRUPT); | ||
2011 | mask = (1 << USB_HIGH_SPEED) | (1 << USB_FULL_SPEED); | ||
2012 | |||
2013 | if (stat & tmp) { | ||
2014 | net2272_write(dev, IRQSTAT1, tmp); | ||
2015 | if ((((stat & (1 << ROOT_PORT_RESET_INTERRUPT)) && | ||
2016 | ((net2272_read(dev, USBCTL1) & mask) == 0)) | ||
2017 | || ((net2272_read(dev, USBCTL1) & (1 << VBUS_PIN)) | ||
2018 | == 0)) | ||
2019 | && (dev->gadget.speed != USB_SPEED_UNKNOWN)) { | ||
2020 | dev_dbg(dev->dev, "disconnect %s\n", | ||
2021 | dev->driver->driver.name); | ||
2022 | stop_activity(dev, dev->driver); | ||
2023 | net2272_ep0_start(dev); | ||
2024 | return; | ||
2025 | } | ||
2026 | stat &= ~tmp; | ||
2027 | |||
2028 | if (!stat) | ||
2029 | return; | ||
2030 | } | ||
2031 | |||
2032 | tmp = (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT); | ||
2033 | if (stat & tmp) { | ||
2034 | net2272_write(dev, IRQSTAT1, tmp); | ||
2035 | if (stat & (1 << SUSPEND_REQUEST_INTERRUPT)) { | ||
2036 | if (dev->driver->suspend) | ||
2037 | dev->driver->suspend(&dev->gadget); | ||
2038 | if (!enable_suspend) { | ||
2039 | stat &= ~(1 << SUSPEND_REQUEST_INTERRUPT); | ||
2040 | dev_dbg(dev->dev, "Suspend disabled, ignoring\n"); | ||
2041 | } | ||
2042 | } else { | ||
2043 | if (dev->driver->resume) | ||
2044 | dev->driver->resume(&dev->gadget); | ||
2045 | } | ||
2046 | stat &= ~tmp; | ||
2047 | } | ||
2048 | |||
2049 | /* clear any other status/irqs */ | ||
2050 | if (stat) | ||
2051 | net2272_write(dev, IRQSTAT1, stat); | ||
2052 | |||
2053 | /* some status we can just ignore */ | ||
2054 | stat &= ~((1 << CONTROL_STATUS_INTERRUPT) | ||
2055 | | (1 << SUSPEND_REQUEST_INTERRUPT) | ||
2056 | | (1 << RESUME_INTERRUPT)); | ||
2057 | if (!stat) | ||
2058 | return; | ||
2059 | else | ||
2060 | dev_dbg(dev->dev, "unhandled irqstat1 %02x\n", stat); | ||
2061 | } | ||
2062 | |||
2063 | static irqreturn_t net2272_irq(int irq, void *_dev) | ||
2064 | { | ||
2065 | struct net2272 *dev = _dev; | ||
2066 | #if defined(PLX_PCI_RDK) || defined(PLX_PCI_RDK2) | ||
2067 | u32 intcsr; | ||
2068 | #endif | ||
2069 | #if defined(PLX_PCI_RDK) | ||
2070 | u8 dmareq; | ||
2071 | #endif | ||
2072 | spin_lock(&dev->lock); | ||
2073 | #if defined(PLX_PCI_RDK) | ||
2074 | intcsr = readl(dev->rdk1.plx9054_base_addr + INTCSR); | ||
2075 | |||
2076 | if ((intcsr & LOCAL_INTERRUPT_TEST) == LOCAL_INTERRUPT_TEST) { | ||
2077 | writel(intcsr & ~(1 << PCI_INTERRUPT_ENABLE), | ||
2078 | dev->rdk1.plx9054_base_addr + INTCSR); | ||
2079 | net2272_handle_stat1_irqs(dev, net2272_read(dev, IRQSTAT1)); | ||
2080 | net2272_handle_stat0_irqs(dev, net2272_read(dev, IRQSTAT0)); | ||
2081 | intcsr = readl(dev->rdk1.plx9054_base_addr + INTCSR); | ||
2082 | writel(intcsr | (1 << PCI_INTERRUPT_ENABLE), | ||
2083 | dev->rdk1.plx9054_base_addr + INTCSR); | ||
2084 | } | ||
2085 | if ((intcsr & DMA_CHANNEL_0_TEST) == DMA_CHANNEL_0_TEST) { | ||
2086 | writeb((1 << CHANNEL_CLEAR_INTERRUPT | (0 << CHANNEL_ENABLE)), | ||
2087 | dev->rdk1.plx9054_base_addr + DMACSR0); | ||
2088 | |||
2089 | dmareq = net2272_read(dev, DMAREQ); | ||
2090 | if (dmareq & 0x01) | ||
2091 | net2272_handle_dma(&dev->ep[2]); | ||
2092 | else | ||
2093 | net2272_handle_dma(&dev->ep[1]); | ||
2094 | } | ||
2095 | #endif | ||
2096 | #if defined(PLX_PCI_RDK2) | ||
2097 | /* see if PCI int for us by checking irqstat */ | ||
2098 | intcsr = readl(dev->rdk2.fpga_base_addr + RDK2_IRQSTAT); | ||
2099 | if (!intcsr & (1 << NET2272_PCI_IRQ)) | ||
2100 | return IRQ_NONE; | ||
2101 | /* check dma interrupts */ | ||
2102 | #endif | ||
2103 | /* Platform/devcice interrupt handler */ | ||
2104 | #if !defined(PLX_PCI_RDK) | ||
2105 | net2272_handle_stat1_irqs(dev, net2272_read(dev, IRQSTAT1)); | ||
2106 | net2272_handle_stat0_irqs(dev, net2272_read(dev, IRQSTAT0)); | ||
2107 | #endif | ||
2108 | spin_unlock(&dev->lock); | ||
2109 | |||
2110 | return IRQ_HANDLED; | ||
2111 | } | ||
2112 | |||
2113 | static int net2272_present(struct net2272 *dev) | ||
2114 | { | ||
2115 | /* | ||
2116 | * Quick test to see if CPU can communicate properly with the NET2272. | ||
2117 | * Verifies connection using writes and reads to write/read and | ||
2118 | * read-only registers. | ||
2119 | * | ||
2120 | * This routine is strongly recommended especially during early bring-up | ||
2121 | * of new hardware, however for designs that do not apply Power On System | ||
2122 | * Tests (POST) it may discarded (or perhaps minimized). | ||
2123 | */ | ||
2124 | unsigned int ii; | ||
2125 | u8 val, refval; | ||
2126 | |||
2127 | /* Verify NET2272 write/read SCRATCH register can write and read */ | ||
2128 | refval = net2272_read(dev, SCRATCH); | ||
2129 | for (ii = 0; ii < 0x100; ii += 7) { | ||
2130 | net2272_write(dev, SCRATCH, ii); | ||
2131 | val = net2272_read(dev, SCRATCH); | ||
2132 | if (val != ii) { | ||
2133 | dev_dbg(dev->dev, | ||
2134 | "%s: write/read SCRATCH register test failed: " | ||
2135 | "wrote:0x%2.2x, read:0x%2.2x\n", | ||
2136 | __func__, ii, val); | ||
2137 | return -EINVAL; | ||
2138 | } | ||
2139 | } | ||
2140 | /* To be nice, we write the original SCRATCH value back: */ | ||
2141 | net2272_write(dev, SCRATCH, refval); | ||
2142 | |||
2143 | /* Verify NET2272 CHIPREV register is read-only: */ | ||
2144 | refval = net2272_read(dev, CHIPREV_2272); | ||
2145 | for (ii = 0; ii < 0x100; ii += 7) { | ||
2146 | net2272_write(dev, CHIPREV_2272, ii); | ||
2147 | val = net2272_read(dev, CHIPREV_2272); | ||
2148 | if (val != refval) { | ||
2149 | dev_dbg(dev->dev, | ||
2150 | "%s: write/read CHIPREV register test failed: " | ||
2151 | "wrote 0x%2.2x, read:0x%2.2x expected:0x%2.2x\n", | ||
2152 | __func__, ii, val, refval); | ||
2153 | return -EINVAL; | ||
2154 | } | ||
2155 | } | ||
2156 | |||
2157 | /* | ||
2158 | * Verify NET2272's "NET2270 legacy revision" register | ||
2159 | * - NET2272 has two revision registers. The NET2270 legacy revision | ||
2160 | * register should read the same value, regardless of the NET2272 | ||
2161 | * silicon revision. The legacy register applies to NET2270 | ||
2162 | * firmware being applied to the NET2272. | ||
2163 | */ | ||
2164 | val = net2272_read(dev, CHIPREV_LEGACY); | ||
2165 | if (val != NET2270_LEGACY_REV) { | ||
2166 | /* | ||
2167 | * Unexpected legacy revision value | ||
2168 | * - Perhaps the chip is a NET2270? | ||
2169 | */ | ||
2170 | dev_dbg(dev->dev, | ||
2171 | "%s: WARNING: UNEXPECTED NET2272 LEGACY REGISTER VALUE:\n" | ||
2172 | " - CHIPREV_LEGACY: expected 0x%2.2x, got:0x%2.2x. (Not NET2272?)\n", | ||
2173 | __func__, NET2270_LEGACY_REV, val); | ||
2174 | return -EINVAL; | ||
2175 | } | ||
2176 | |||
2177 | /* | ||
2178 | * Verify NET2272 silicon revision | ||
2179 | * - This revision register is appropriate for the silicon version | ||
2180 | * of the NET2272 | ||
2181 | */ | ||
2182 | val = net2272_read(dev, CHIPREV_2272); | ||
2183 | switch (val) { | ||
2184 | case CHIPREV_NET2272_R1: | ||
2185 | /* | ||
2186 | * NET2272 Rev 1 has DMA related errata: | ||
2187 | * - Newer silicon (Rev 1A or better) required | ||
2188 | */ | ||
2189 | dev_dbg(dev->dev, | ||
2190 | "%s: Rev 1 detected: newer silicon recommended for DMA support\n", | ||
2191 | __func__); | ||
2192 | break; | ||
2193 | case CHIPREV_NET2272_R1A: | ||
2194 | break; | ||
2195 | default: | ||
2196 | /* NET2272 silicon version *may* not work with this firmware */ | ||
2197 | dev_dbg(dev->dev, | ||
2198 | "%s: unexpected silicon revision register value: " | ||
2199 | " CHIPREV_2272: 0x%2.2x\n", | ||
2200 | __func__, val); | ||
2201 | /* | ||
2202 | * Return Success, even though the chip rev is not an expected value | ||
2203 | * - Older, pre-built firmware can attempt to operate on newer silicon | ||
2204 | * - Often, new silicon is perfectly compatible | ||
2205 | */ | ||
2206 | } | ||
2207 | |||
2208 | /* Success: NET2272 checks out OK */ | ||
2209 | return 0; | ||
2210 | } | ||
2211 | |||
2212 | static void | ||
2213 | net2272_gadget_release(struct device *_dev) | ||
2214 | { | ||
2215 | struct net2272 *dev = dev_get_drvdata(_dev); | ||
2216 | kfree(dev); | ||
2217 | } | ||
2218 | |||
2219 | /*---------------------------------------------------------------------------*/ | ||
2220 | |||
2221 | static void __devexit | ||
2222 | net2272_remove(struct net2272 *dev) | ||
2223 | { | ||
2224 | usb_del_gadget_udc(&dev->gadget); | ||
2225 | |||
2226 | /* start with the driver above us */ | ||
2227 | if (dev->driver) { | ||
2228 | /* should have been done already by driver model core */ | ||
2229 | dev_warn(dev->dev, "pci remove, driver '%s' is still registered\n", | ||
2230 | dev->driver->driver.name); | ||
2231 | usb_gadget_unregister_driver(dev->driver); | ||
2232 | } | ||
2233 | |||
2234 | free_irq(dev->irq, dev); | ||
2235 | iounmap(dev->base_addr); | ||
2236 | |||
2237 | device_unregister(&dev->gadget.dev); | ||
2238 | device_remove_file(dev->dev, &dev_attr_registers); | ||
2239 | |||
2240 | dev_info(dev->dev, "unbind\n"); | ||
2241 | the_controller = NULL; | ||
2242 | } | ||
2243 | |||
2244 | static struct net2272 * __devinit | ||
2245 | net2272_probe_init(struct device *dev, unsigned int irq) | ||
2246 | { | ||
2247 | struct net2272 *ret; | ||
2248 | |||
2249 | if (the_controller) { | ||
2250 | dev_warn(dev, "ignoring\n"); | ||
2251 | return ERR_PTR(-EBUSY); | ||
2252 | } | ||
2253 | |||
2254 | if (!irq) { | ||
2255 | dev_dbg(dev, "No IRQ!\n"); | ||
2256 | return ERR_PTR(-ENODEV); | ||
2257 | } | ||
2258 | |||
2259 | /* alloc, and start init */ | ||
2260 | ret = kzalloc(sizeof(*ret), GFP_KERNEL); | ||
2261 | if (!ret) | ||
2262 | return ERR_PTR(-ENOMEM); | ||
2263 | |||
2264 | spin_lock_init(&ret->lock); | ||
2265 | ret->irq = irq; | ||
2266 | ret->dev = dev; | ||
2267 | ret->gadget.ops = &net2272_ops; | ||
2268 | ret->gadget.is_dualspeed = 1; | ||
2269 | |||
2270 | /* the "gadget" abstracts/virtualizes the controller */ | ||
2271 | dev_set_name(&ret->gadget.dev, "gadget"); | ||
2272 | ret->gadget.dev.parent = dev; | ||
2273 | ret->gadget.dev.dma_mask = dev->dma_mask; | ||
2274 | ret->gadget.dev.release = net2272_gadget_release; | ||
2275 | ret->gadget.name = driver_name; | ||
2276 | |||
2277 | return ret; | ||
2278 | } | ||
2279 | |||
2280 | static int __devinit | ||
2281 | net2272_probe_fin(struct net2272 *dev, unsigned int irqflags) | ||
2282 | { | ||
2283 | int ret; | ||
2284 | |||
2285 | /* See if there... */ | ||
2286 | if (net2272_present(dev)) { | ||
2287 | dev_warn(dev->dev, "2272 not found!\n"); | ||
2288 | ret = -ENODEV; | ||
2289 | goto err; | ||
2290 | } | ||
2291 | |||
2292 | net2272_usb_reset(dev); | ||
2293 | net2272_usb_reinit(dev); | ||
2294 | |||
2295 | ret = request_irq(dev->irq, net2272_irq, irqflags, driver_name, dev); | ||
2296 | if (ret) { | ||
2297 | dev_err(dev->dev, "request interrupt %i failed\n", dev->irq); | ||
2298 | goto err; | ||
2299 | } | ||
2300 | |||
2301 | dev->chiprev = net2272_read(dev, CHIPREV_2272); | ||
2302 | |||
2303 | /* done */ | ||
2304 | dev_info(dev->dev, "%s\n", driver_desc); | ||
2305 | dev_info(dev->dev, "irq %i, mem %p, chip rev %04x, dma %s\n", | ||
2306 | dev->irq, dev->base_addr, dev->chiprev, | ||
2307 | dma_mode_string()); | ||
2308 | dev_info(dev->dev, "version: %s\n", driver_vers); | ||
2309 | |||
2310 | the_controller = dev; | ||
2311 | |||
2312 | ret = device_register(&dev->gadget.dev); | ||
2313 | if (ret) | ||
2314 | goto err_irq; | ||
2315 | ret = device_create_file(dev->dev, &dev_attr_registers); | ||
2316 | if (ret) | ||
2317 | goto err_dev_reg; | ||
2318 | |||
2319 | ret = usb_add_gadget_udc(dev->dev, &dev->gadget); | ||
2320 | if (ret) | ||
2321 | goto err_add_udc; | ||
2322 | |||
2323 | return 0; | ||
2324 | |||
2325 | err_add_udc: | ||
2326 | device_remove_file(dev->dev, &dev_attr_registers); | ||
2327 | err_dev_reg: | ||
2328 | device_unregister(&dev->gadget.dev); | ||
2329 | err_irq: | ||
2330 | free_irq(dev->irq, dev); | ||
2331 | err: | ||
2332 | return ret; | ||
2333 | } | ||
2334 | |||
2335 | #ifdef CONFIG_PCI | ||
2336 | |||
2337 | /* | ||
2338 | * wrap this driver around the specified device, but | ||
2339 | * don't respond over USB until a gadget driver binds to us | ||
2340 | */ | ||
2341 | |||
2342 | static int __devinit | ||
2343 | net2272_rdk1_probe(struct pci_dev *pdev, struct net2272 *dev) | ||
2344 | { | ||
2345 | unsigned long resource, len, tmp; | ||
2346 | void __iomem *mem_mapped_addr[4]; | ||
2347 | int ret, i; | ||
2348 | |||
2349 | /* | ||
2350 | * BAR 0 holds PLX 9054 config registers | ||
2351 | * BAR 1 is i/o memory; unused here | ||
2352 | * BAR 2 holds EPLD config registers | ||
2353 | * BAR 3 holds NET2272 registers | ||
2354 | */ | ||
2355 | |||
2356 | /* Find and map all address spaces */ | ||
2357 | for (i = 0; i < 4; ++i) { | ||
2358 | if (i == 1) | ||
2359 | continue; /* BAR1 unused */ | ||
2360 | |||
2361 | resource = pci_resource_start(pdev, i); | ||
2362 | len = pci_resource_len(pdev, i); | ||
2363 | |||
2364 | if (!request_mem_region(resource, len, driver_name)) { | ||
2365 | dev_dbg(dev->dev, "controller already in use\n"); | ||
2366 | ret = -EBUSY; | ||
2367 | goto err; | ||
2368 | } | ||
2369 | |||
2370 | mem_mapped_addr[i] = ioremap_nocache(resource, len); | ||
2371 | if (mem_mapped_addr[i] == NULL) { | ||
2372 | release_mem_region(resource, len); | ||
2373 | dev_dbg(dev->dev, "can't map memory\n"); | ||
2374 | ret = -EFAULT; | ||
2375 | goto err; | ||
2376 | } | ||
2377 | } | ||
2378 | |||
2379 | dev->rdk1.plx9054_base_addr = mem_mapped_addr[0]; | ||
2380 | dev->rdk1.epld_base_addr = mem_mapped_addr[2]; | ||
2381 | dev->base_addr = mem_mapped_addr[3]; | ||
2382 | |||
2383 | /* Set PLX 9054 bus width (16 bits) */ | ||
2384 | tmp = readl(dev->rdk1.plx9054_base_addr + LBRD1); | ||
2385 | writel((tmp & ~(3 << MEMORY_SPACE_LOCAL_BUS_WIDTH)) | W16_BIT, | ||
2386 | dev->rdk1.plx9054_base_addr + LBRD1); | ||
2387 | |||
2388 | /* Enable PLX 9054 Interrupts */ | ||
2389 | writel(readl(dev->rdk1.plx9054_base_addr + INTCSR) | | ||
2390 | (1 << PCI_INTERRUPT_ENABLE) | | ||
2391 | (1 << LOCAL_INTERRUPT_INPUT_ENABLE), | ||
2392 | dev->rdk1.plx9054_base_addr + INTCSR); | ||
2393 | |||
2394 | writeb((1 << CHANNEL_CLEAR_INTERRUPT | (0 << CHANNEL_ENABLE)), | ||
2395 | dev->rdk1.plx9054_base_addr + DMACSR0); | ||
2396 | |||
2397 | /* reset */ | ||
2398 | writeb((1 << EPLD_DMA_ENABLE) | | ||
2399 | (1 << DMA_CTL_DACK) | | ||
2400 | (1 << DMA_TIMEOUT_ENABLE) | | ||
2401 | (1 << USER) | | ||
2402 | (0 << MPX_MODE) | | ||
2403 | (1 << BUSWIDTH) | | ||
2404 | (1 << NET2272_RESET), | ||
2405 | dev->base_addr + EPLD_IO_CONTROL_REGISTER); | ||
2406 | |||
2407 | mb(); | ||
2408 | writeb(readb(dev->base_addr + EPLD_IO_CONTROL_REGISTER) & | ||
2409 | ~(1 << NET2272_RESET), | ||
2410 | dev->base_addr + EPLD_IO_CONTROL_REGISTER); | ||
2411 | udelay(200); | ||
2412 | |||
2413 | return 0; | ||
2414 | |||
2415 | err: | ||
2416 | while (--i >= 0) { | ||
2417 | iounmap(mem_mapped_addr[i]); | ||
2418 | release_mem_region(pci_resource_start(pdev, i), | ||
2419 | pci_resource_len(pdev, i)); | ||
2420 | } | ||
2421 | |||
2422 | return ret; | ||
2423 | } | ||
2424 | |||
2425 | static int __devinit | ||
2426 | net2272_rdk2_probe(struct pci_dev *pdev, struct net2272 *dev) | ||
2427 | { | ||
2428 | unsigned long resource, len; | ||
2429 | void __iomem *mem_mapped_addr[2]; | ||
2430 | int ret, i; | ||
2431 | |||
2432 | /* | ||
2433 | * BAR 0 holds FGPA config registers | ||
2434 | * BAR 1 holds NET2272 registers | ||
2435 | */ | ||
2436 | |||
2437 | /* Find and map all address spaces, bar2-3 unused in rdk 2 */ | ||
2438 | for (i = 0; i < 2; ++i) { | ||
2439 | resource = pci_resource_start(pdev, i); | ||
2440 | len = pci_resource_len(pdev, i); | ||
2441 | |||
2442 | if (!request_mem_region(resource, len, driver_name)) { | ||
2443 | dev_dbg(dev->dev, "controller already in use\n"); | ||
2444 | ret = -EBUSY; | ||
2445 | goto err; | ||
2446 | } | ||
2447 | |||
2448 | mem_mapped_addr[i] = ioremap_nocache(resource, len); | ||
2449 | if (mem_mapped_addr[i] == NULL) { | ||
2450 | release_mem_region(resource, len); | ||
2451 | dev_dbg(dev->dev, "can't map memory\n"); | ||
2452 | ret = -EFAULT; | ||
2453 | goto err; | ||
2454 | } | ||
2455 | } | ||
2456 | |||
2457 | dev->rdk2.fpga_base_addr = mem_mapped_addr[0]; | ||
2458 | dev->base_addr = mem_mapped_addr[1]; | ||
2459 | |||
2460 | mb(); | ||
2461 | /* Set 2272 bus width (16 bits) and reset */ | ||
2462 | writel((1 << CHIP_RESET), dev->rdk2.fpga_base_addr + RDK2_LOCCTLRDK); | ||
2463 | udelay(200); | ||
2464 | writel((1 << BUS_WIDTH), dev->rdk2.fpga_base_addr + RDK2_LOCCTLRDK); | ||
2465 | /* Print fpga version number */ | ||
2466 | dev_info(dev->dev, "RDK2 FPGA version %08x\n", | ||
2467 | readl(dev->rdk2.fpga_base_addr + RDK2_FPGAREV)); | ||
2468 | /* Enable FPGA Interrupts */ | ||
2469 | writel((1 << NET2272_PCI_IRQ), dev->rdk2.fpga_base_addr + RDK2_IRQENB); | ||
2470 | |||
2471 | return 0; | ||
2472 | |||
2473 | err: | ||
2474 | while (--i >= 0) { | ||
2475 | iounmap(mem_mapped_addr[i]); | ||
2476 | release_mem_region(pci_resource_start(pdev, i), | ||
2477 | pci_resource_len(pdev, i)); | ||
2478 | } | ||
2479 | |||
2480 | return ret; | ||
2481 | } | ||
2482 | |||
2483 | static int __devinit | ||
2484 | net2272_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) | ||
2485 | { | ||
2486 | struct net2272 *dev; | ||
2487 | int ret; | ||
2488 | |||
2489 | dev = net2272_probe_init(&pdev->dev, pdev->irq); | ||
2490 | if (IS_ERR(dev)) | ||
2491 | return PTR_ERR(dev); | ||
2492 | dev->dev_id = pdev->device; | ||
2493 | |||
2494 | if (pci_enable_device(pdev) < 0) { | ||
2495 | ret = -ENODEV; | ||
2496 | goto err_free; | ||
2497 | } | ||
2498 | |||
2499 | pci_set_master(pdev); | ||
2500 | |||
2501 | switch (pdev->device) { | ||
2502 | case PCI_DEVICE_ID_RDK1: ret = net2272_rdk1_probe(pdev, dev); break; | ||
2503 | case PCI_DEVICE_ID_RDK2: ret = net2272_rdk2_probe(pdev, dev); break; | ||
2504 | default: BUG(); | ||
2505 | } | ||
2506 | if (ret) | ||
2507 | goto err_pci; | ||
2508 | |||
2509 | ret = net2272_probe_fin(dev, 0); | ||
2510 | if (ret) | ||
2511 | goto err_pci; | ||
2512 | |||
2513 | pci_set_drvdata(pdev, dev); | ||
2514 | |||
2515 | return 0; | ||
2516 | |||
2517 | err_pci: | ||
2518 | pci_disable_device(pdev); | ||
2519 | err_free: | ||
2520 | kfree(dev); | ||
2521 | |||
2522 | return ret; | ||
2523 | } | ||
2524 | |||
2525 | static void __devexit | ||
2526 | net2272_rdk1_remove(struct pci_dev *pdev, struct net2272 *dev) | ||
2527 | { | ||
2528 | int i; | ||
2529 | |||
2530 | /* disable PLX 9054 interrupts */ | ||
2531 | writel(readl(dev->rdk1.plx9054_base_addr + INTCSR) & | ||
2532 | ~(1 << PCI_INTERRUPT_ENABLE), | ||
2533 | dev->rdk1.plx9054_base_addr + INTCSR); | ||
2534 | |||
2535 | /* clean up resources allocated during probe() */ | ||
2536 | iounmap(dev->rdk1.plx9054_base_addr); | ||
2537 | iounmap(dev->rdk1.epld_base_addr); | ||
2538 | |||
2539 | for (i = 0; i < 4; ++i) { | ||
2540 | if (i == 1) | ||
2541 | continue; /* BAR1 unused */ | ||
2542 | release_mem_region(pci_resource_start(pdev, i), | ||
2543 | pci_resource_len(pdev, i)); | ||
2544 | } | ||
2545 | } | ||
2546 | |||
2547 | static void __devexit | ||
2548 | net2272_rdk2_remove(struct pci_dev *pdev, struct net2272 *dev) | ||
2549 | { | ||
2550 | int i; | ||
2551 | |||
2552 | /* disable fpga interrupts | ||
2553 | writel(readl(dev->rdk1.plx9054_base_addr + INTCSR) & | ||
2554 | ~(1 << PCI_INTERRUPT_ENABLE), | ||
2555 | dev->rdk1.plx9054_base_addr + INTCSR); | ||
2556 | */ | ||
2557 | |||
2558 | /* clean up resources allocated during probe() */ | ||
2559 | iounmap(dev->rdk2.fpga_base_addr); | ||
2560 | |||
2561 | for (i = 0; i < 2; ++i) | ||
2562 | release_mem_region(pci_resource_start(pdev, i), | ||
2563 | pci_resource_len(pdev, i)); | ||
2564 | } | ||
2565 | |||
2566 | static void __devexit | ||
2567 | net2272_pci_remove(struct pci_dev *pdev) | ||
2568 | { | ||
2569 | struct net2272 *dev = pci_get_drvdata(pdev); | ||
2570 | |||
2571 | net2272_remove(dev); | ||
2572 | |||
2573 | switch (pdev->device) { | ||
2574 | case PCI_DEVICE_ID_RDK1: net2272_rdk1_remove(pdev, dev); break; | ||
2575 | case PCI_DEVICE_ID_RDK2: net2272_rdk2_remove(pdev, dev); break; | ||
2576 | default: BUG(); | ||
2577 | } | ||
2578 | |||
2579 | pci_disable_device(pdev); | ||
2580 | |||
2581 | kfree(dev); | ||
2582 | } | ||
2583 | |||
2584 | /* Table of matching PCI IDs */ | ||
2585 | static struct pci_device_id __devinitdata pci_ids[] = { | ||
2586 | { /* RDK 1 card */ | ||
2587 | .class = ((PCI_CLASS_BRIDGE_OTHER << 8) | 0xfe), | ||
2588 | .class_mask = 0, | ||
2589 | .vendor = PCI_VENDOR_ID_PLX, | ||
2590 | .device = PCI_DEVICE_ID_RDK1, | ||
2591 | .subvendor = PCI_ANY_ID, | ||
2592 | .subdevice = PCI_ANY_ID, | ||
2593 | }, | ||
2594 | { /* RDK 2 card */ | ||
2595 | .class = ((PCI_CLASS_BRIDGE_OTHER << 8) | 0xfe), | ||
2596 | .class_mask = 0, | ||
2597 | .vendor = PCI_VENDOR_ID_PLX, | ||
2598 | .device = PCI_DEVICE_ID_RDK2, | ||
2599 | .subvendor = PCI_ANY_ID, | ||
2600 | .subdevice = PCI_ANY_ID, | ||
2601 | }, | ||
2602 | { } | ||
2603 | }; | ||
2604 | MODULE_DEVICE_TABLE(pci, pci_ids); | ||
2605 | |||
2606 | static struct pci_driver net2272_pci_driver = { | ||
2607 | .name = driver_name, | ||
2608 | .id_table = pci_ids, | ||
2609 | |||
2610 | .probe = net2272_pci_probe, | ||
2611 | .remove = __devexit_p(net2272_pci_remove), | ||
2612 | }; | ||
2613 | |||
2614 | static int net2272_pci_register(void) | ||
2615 | { | ||
2616 | return pci_register_driver(&net2272_pci_driver); | ||
2617 | } | ||
2618 | |||
2619 | static void net2272_pci_unregister(void) | ||
2620 | { | ||
2621 | pci_unregister_driver(&net2272_pci_driver); | ||
2622 | } | ||
2623 | |||
2624 | #else | ||
2625 | static inline int net2272_pci_register(void) { return 0; } | ||
2626 | static inline void net2272_pci_unregister(void) { } | ||
2627 | #endif | ||
2628 | |||
2629 | /*---------------------------------------------------------------------------*/ | ||
2630 | |||
2631 | static int __devinit | ||
2632 | net2272_plat_probe(struct platform_device *pdev) | ||
2633 | { | ||
2634 | struct net2272 *dev; | ||
2635 | int ret; | ||
2636 | unsigned int irqflags; | ||
2637 | resource_size_t base, len; | ||
2638 | struct resource *iomem, *iomem_bus, *irq_res; | ||
2639 | |||
2640 | irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
2641 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
2642 | iomem_bus = platform_get_resource(pdev, IORESOURCE_BUS, 0); | ||
2643 | if (!irq_res || !iomem) { | ||
2644 | dev_err(&pdev->dev, "must provide irq/base addr"); | ||
2645 | return -EINVAL; | ||
2646 | } | ||
2647 | |||
2648 | dev = net2272_probe_init(&pdev->dev, irq_res->start); | ||
2649 | if (IS_ERR(dev)) | ||
2650 | return PTR_ERR(dev); | ||
2651 | |||
2652 | irqflags = 0; | ||
2653 | if (irq_res->flags & IORESOURCE_IRQ_HIGHEDGE) | ||
2654 | irqflags |= IRQF_TRIGGER_RISING; | ||
2655 | if (irq_res->flags & IORESOURCE_IRQ_LOWEDGE) | ||
2656 | irqflags |= IRQF_TRIGGER_FALLING; | ||
2657 | if (irq_res->flags & IORESOURCE_IRQ_HIGHLEVEL) | ||
2658 | irqflags |= IRQF_TRIGGER_HIGH; | ||
2659 | if (irq_res->flags & IORESOURCE_IRQ_LOWLEVEL) | ||
2660 | irqflags |= IRQF_TRIGGER_LOW; | ||
2661 | |||
2662 | base = iomem->start; | ||
2663 | len = resource_size(iomem); | ||
2664 | if (iomem_bus) | ||
2665 | dev->base_shift = iomem_bus->start; | ||
2666 | |||
2667 | if (!request_mem_region(base, len, driver_name)) { | ||
2668 | dev_dbg(dev->dev, "get request memory region!\n"); | ||
2669 | ret = -EBUSY; | ||
2670 | goto err; | ||
2671 | } | ||
2672 | dev->base_addr = ioremap_nocache(base, len); | ||
2673 | if (!dev->base_addr) { | ||
2674 | dev_dbg(dev->dev, "can't map memory\n"); | ||
2675 | ret = -EFAULT; | ||
2676 | goto err_req; | ||
2677 | } | ||
2678 | |||
2679 | ret = net2272_probe_fin(dev, IRQF_TRIGGER_LOW); | ||
2680 | if (ret) | ||
2681 | goto err_io; | ||
2682 | |||
2683 | platform_set_drvdata(pdev, dev); | ||
2684 | dev_info(&pdev->dev, "running in 16-bit, %sbyte swap local bus mode\n", | ||
2685 | (net2272_read(dev, LOCCTL) & (1 << BYTE_SWAP)) ? "" : "no "); | ||
2686 | |||
2687 | the_controller = dev; | ||
2688 | |||
2689 | return 0; | ||
2690 | |||
2691 | err_io: | ||
2692 | iounmap(dev->base_addr); | ||
2693 | err_req: | ||
2694 | release_mem_region(base, len); | ||
2695 | err: | ||
2696 | return ret; | ||
2697 | } | ||
2698 | |||
2699 | static int __devexit | ||
2700 | net2272_plat_remove(struct platform_device *pdev) | ||
2701 | { | ||
2702 | struct net2272 *dev = platform_get_drvdata(pdev); | ||
2703 | |||
2704 | net2272_remove(dev); | ||
2705 | |||
2706 | release_mem_region(pdev->resource[0].start, | ||
2707 | resource_size(&pdev->resource[0])); | ||
2708 | |||
2709 | kfree(dev); | ||
2710 | |||
2711 | return 0; | ||
2712 | } | ||
2713 | |||
2714 | static struct platform_driver net2272_plat_driver = { | ||
2715 | .probe = net2272_plat_probe, | ||
2716 | .remove = __devexit_p(net2272_plat_remove), | ||
2717 | .driver = { | ||
2718 | .name = driver_name, | ||
2719 | .owner = THIS_MODULE, | ||
2720 | }, | ||
2721 | /* FIXME .suspend, .resume */ | ||
2722 | }; | ||
2723 | MODULE_ALIAS("platform:net2272"); | ||
2724 | |||
2725 | static int __init net2272_init(void) | ||
2726 | { | ||
2727 | int ret; | ||
2728 | |||
2729 | ret = net2272_pci_register(); | ||
2730 | if (ret) | ||
2731 | return ret; | ||
2732 | ret = platform_driver_register(&net2272_plat_driver); | ||
2733 | if (ret) | ||
2734 | goto err_pci; | ||
2735 | return ret; | ||
2736 | |||
2737 | err_pci: | ||
2738 | net2272_pci_unregister(); | ||
2739 | return ret; | ||
2740 | } | ||
2741 | module_init(net2272_init); | ||
2742 | |||
2743 | static void __exit net2272_cleanup(void) | ||
2744 | { | ||
2745 | net2272_pci_unregister(); | ||
2746 | platform_driver_unregister(&net2272_plat_driver); | ||
2747 | } | ||
2748 | module_exit(net2272_cleanup); | ||
2749 | |||
2750 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
2751 | MODULE_AUTHOR("PLX Technology, Inc."); | ||
2752 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/gadget/net2272.h b/drivers/usb/gadget/net2272.h new file mode 100644 index 000000000000..e59505789359 --- /dev/null +++ b/drivers/usb/gadget/net2272.h | |||
@@ -0,0 +1,601 @@ | |||
1 | /* | ||
2 | * PLX NET2272 high/full speed USB device controller | ||
3 | * | ||
4 | * Copyright (C) 2005-2006 PLX Technology, Inc. | ||
5 | * Copyright (C) 2006-2011 Analog Devices, Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #ifndef __NET2272_H__ | ||
23 | #define __NET2272_H__ | ||
24 | |||
25 | /* Main Registers */ | ||
26 | #define REGADDRPTR 0x00 | ||
27 | #define REGDATA 0x01 | ||
28 | #define IRQSTAT0 0x02 | ||
29 | #define ENDPOINT_0_INTERRUPT 0 | ||
30 | #define ENDPOINT_A_INTERRUPT 1 | ||
31 | #define ENDPOINT_B_INTERRUPT 2 | ||
32 | #define ENDPOINT_C_INTERRUPT 3 | ||
33 | #define VIRTUALIZED_ENDPOINT_INTERRUPT 4 | ||
34 | #define SETUP_PACKET_INTERRUPT 5 | ||
35 | #define DMA_DONE_INTERRUPT 6 | ||
36 | #define SOF_INTERRUPT 7 | ||
37 | #define IRQSTAT1 0x03 | ||
38 | #define CONTROL_STATUS_INTERRUPT 1 | ||
39 | #define VBUS_INTERRUPT 2 | ||
40 | #define SUSPEND_REQUEST_INTERRUPT 3 | ||
41 | #define SUSPEND_REQUEST_CHANGE_INTERRUPT 4 | ||
42 | #define RESUME_INTERRUPT 5 | ||
43 | #define ROOT_PORT_RESET_INTERRUPT 6 | ||
44 | #define RESET_STATUS 7 | ||
45 | #define PAGESEL 0x04 | ||
46 | #define DMAREQ 0x1c | ||
47 | #define DMA_ENDPOINT_SELECT 0 | ||
48 | #define DREQ_POLARITY 1 | ||
49 | #define DACK_POLARITY 2 | ||
50 | #define EOT_POLARITY 3 | ||
51 | #define DMA_CONTROL_DACK 4 | ||
52 | #define DMA_REQUEST_ENABLE 5 | ||
53 | #define DMA_REQUEST 6 | ||
54 | #define DMA_BUFFER_VALID 7 | ||
55 | #define SCRATCH 0x1d | ||
56 | #define IRQENB0 0x20 | ||
57 | #define ENDPOINT_0_INTERRUPT_ENABLE 0 | ||
58 | #define ENDPOINT_A_INTERRUPT_ENABLE 1 | ||
59 | #define ENDPOINT_B_INTERRUPT_ENABLE 2 | ||
60 | #define ENDPOINT_C_INTERRUPT_ENABLE 3 | ||
61 | #define VIRTUALIZED_ENDPOINT_INTERRUPT_ENABLE 4 | ||
62 | #define SETUP_PACKET_INTERRUPT_ENABLE 5 | ||
63 | #define DMA_DONE_INTERRUPT_ENABLE 6 | ||
64 | #define SOF_INTERRUPT_ENABLE 7 | ||
65 | #define IRQENB1 0x21 | ||
66 | #define VBUS_INTERRUPT_ENABLE 2 | ||
67 | #define SUSPEND_REQUEST_INTERRUPT_ENABLE 3 | ||
68 | #define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE 4 | ||
69 | #define RESUME_INTERRUPT_ENABLE 5 | ||
70 | #define ROOT_PORT_RESET_INTERRUPT_ENABLE 6 | ||
71 | #define LOCCTL 0x22 | ||
72 | #define DATA_WIDTH 0 | ||
73 | #define LOCAL_CLOCK_OUTPUT 1 | ||
74 | #define LOCAL_CLOCK_OUTPUT_OFF 0 | ||
75 | #define LOCAL_CLOCK_OUTPUT_3_75MHZ 1 | ||
76 | #define LOCAL_CLOCK_OUTPUT_7_5MHZ 2 | ||
77 | #define LOCAL_CLOCK_OUTPUT_15MHZ 3 | ||
78 | #define LOCAL_CLOCK_OUTPUT_30MHZ 4 | ||
79 | #define LOCAL_CLOCK_OUTPUT_60MHZ 5 | ||
80 | #define DMA_SPLIT_BUS_MODE 4 | ||
81 | #define BYTE_SWAP 5 | ||
82 | #define BUFFER_CONFIGURATION 6 | ||
83 | #define BUFFER_CONFIGURATION_EPA512_EPB512 0 | ||
84 | #define BUFFER_CONFIGURATION_EPA1024_EPB512 1 | ||
85 | #define BUFFER_CONFIGURATION_EPA1024_EPB1024 2 | ||
86 | #define BUFFER_CONFIGURATION_EPA1024DB 3 | ||
87 | #define CHIPREV_LEGACY 0x23 | ||
88 | #define NET2270_LEGACY_REV 0x40 | ||
89 | #define LOCCTL1 0x24 | ||
90 | #define DMA_MODE 0 | ||
91 | #define SLOW_DREQ 0 | ||
92 | #define FAST_DREQ 1 | ||
93 | #define BURST_MODE 2 | ||
94 | #define DMA_DACK_ENABLE 2 | ||
95 | #define CHIPREV_2272 0x25 | ||
96 | #define CHIPREV_NET2272_R1 0x10 | ||
97 | #define CHIPREV_NET2272_R1A 0x11 | ||
98 | /* USB Registers */ | ||
99 | #define USBCTL0 0x18 | ||
100 | #define IO_WAKEUP_ENABLE 1 | ||
101 | #define USB_DETECT_ENABLE 3 | ||
102 | #define USB_ROOT_PORT_WAKEUP_ENABLE 5 | ||
103 | #define USBCTL1 0x19 | ||
104 | #define VBUS_PIN 0 | ||
105 | #define USB_FULL_SPEED 1 | ||
106 | #define USB_HIGH_SPEED 2 | ||
107 | #define GENERATE_RESUME 3 | ||
108 | #define VIRTUAL_ENDPOINT_ENABLE 4 | ||
109 | #define FRAME0 0x1a | ||
110 | #define FRAME1 0x1b | ||
111 | #define OURADDR 0x30 | ||
112 | #define FORCE_IMMEDIATE 7 | ||
113 | #define USBDIAG 0x31 | ||
114 | #define FORCE_TRANSMIT_CRC_ERROR 0 | ||
115 | #define PREVENT_TRANSMIT_BIT_STUFF 1 | ||
116 | #define FORCE_RECEIVE_ERROR 2 | ||
117 | #define FAST_TIMES 4 | ||
118 | #define USBTEST 0x32 | ||
119 | #define TEST_MODE_SELECT 0 | ||
120 | #define NORMAL_OPERATION 0 | ||
121 | #define TEST_J 1 | ||
122 | #define TEST_K 2 | ||
123 | #define TEST_SE0_NAK 3 | ||
124 | #define TEST_PACKET 4 | ||
125 | #define TEST_FORCE_ENABLE 5 | ||
126 | #define XCVRDIAG 0x33 | ||
127 | #define FORCE_FULL_SPEED 2 | ||
128 | #define FORCE_HIGH_SPEED 3 | ||
129 | #define OPMODE 4 | ||
130 | #define NORMAL_OPERATION 0 | ||
131 | #define NON_DRIVING 1 | ||
132 | #define DISABLE_BITSTUFF_AND_NRZI_ENCODE 2 | ||
133 | #define LINESTATE 6 | ||
134 | #define SE0_STATE 0 | ||
135 | #define J_STATE 1 | ||
136 | #define K_STATE 2 | ||
137 | #define SE1_STATE 3 | ||
138 | #define VIRTOUT0 0x34 | ||
139 | #define VIRTOUT1 0x35 | ||
140 | #define VIRTIN0 0x36 | ||
141 | #define VIRTIN1 0x37 | ||
142 | #define SETUP0 0x40 | ||
143 | #define SETUP1 0x41 | ||
144 | #define SETUP2 0x42 | ||
145 | #define SETUP3 0x43 | ||
146 | #define SETUP4 0x44 | ||
147 | #define SETUP5 0x45 | ||
148 | #define SETUP6 0x46 | ||
149 | #define SETUP7 0x47 | ||
150 | /* Endpoint Registers (Paged via PAGESEL) */ | ||
151 | #define EP_DATA 0x05 | ||
152 | #define EP_STAT0 0x06 | ||
153 | #define DATA_IN_TOKEN_INTERRUPT 0 | ||
154 | #define DATA_OUT_TOKEN_INTERRUPT 1 | ||
155 | #define DATA_PACKET_TRANSMITTED_INTERRUPT 2 | ||
156 | #define DATA_PACKET_RECEIVED_INTERRUPT 3 | ||
157 | #define SHORT_PACKET_TRANSFERRED_INTERRUPT 4 | ||
158 | #define NAK_OUT_PACKETS 5 | ||
159 | #define BUFFER_EMPTY 6 | ||
160 | #define BUFFER_FULL 7 | ||
161 | #define EP_STAT1 0x07 | ||
162 | #define TIMEOUT 0 | ||
163 | #define USB_OUT_ACK_SENT 1 | ||
164 | #define USB_OUT_NAK_SENT 2 | ||
165 | #define USB_IN_ACK_RCVD 3 | ||
166 | #define USB_IN_NAK_SENT 4 | ||
167 | #define USB_STALL_SENT 5 | ||
168 | #define LOCAL_OUT_ZLP 6 | ||
169 | #define BUFFER_FLUSH 7 | ||
170 | #define EP_TRANSFER0 0x08 | ||
171 | #define EP_TRANSFER1 0x09 | ||
172 | #define EP_TRANSFER2 0x0a | ||
173 | #define EP_IRQENB 0x0b | ||
174 | #define DATA_IN_TOKEN_INTERRUPT_ENABLE 0 | ||
175 | #define DATA_OUT_TOKEN_INTERRUPT_ENABLE 1 | ||
176 | #define DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE 2 | ||
177 | #define DATA_PACKET_RECEIVED_INTERRUPT_ENABLE 3 | ||
178 | #define SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE 4 | ||
179 | #define EP_AVAIL0 0x0c | ||
180 | #define EP_AVAIL1 0x0d | ||
181 | #define EP_RSPCLR 0x0e | ||
182 | #define EP_RSPSET 0x0f | ||
183 | #define ENDPOINT_HALT 0 | ||
184 | #define ENDPOINT_TOGGLE 1 | ||
185 | #define NAK_OUT_PACKETS_MODE 2 | ||
186 | #define CONTROL_STATUS_PHASE_HANDSHAKE 3 | ||
187 | #define INTERRUPT_MODE 4 | ||
188 | #define AUTOVALIDATE 5 | ||
189 | #define HIDE_STATUS_PHASE 6 | ||
190 | #define ALT_NAK_OUT_PACKETS 7 | ||
191 | #define EP_MAXPKT0 0x28 | ||
192 | #define EP_MAXPKT1 0x29 | ||
193 | #define ADDITIONAL_TRANSACTION_OPPORTUNITIES 3 | ||
194 | #define NONE_ADDITIONAL_TRANSACTION 0 | ||
195 | #define ONE_ADDITIONAL_TRANSACTION 1 | ||
196 | #define TWO_ADDITIONAL_TRANSACTION 2 | ||
197 | #define EP_CFG 0x2a | ||
198 | #define ENDPOINT_NUMBER 0 | ||
199 | #define ENDPOINT_DIRECTION 4 | ||
200 | #define ENDPOINT_TYPE 5 | ||
201 | #define ENDPOINT_ENABLE 7 | ||
202 | #define EP_HBW 0x2b | ||
203 | #define HIGH_BANDWIDTH_OUT_TRANSACTION_PID 0 | ||
204 | #define DATA0_PID 0 | ||
205 | #define DATA1_PID 1 | ||
206 | #define DATA2_PID 2 | ||
207 | #define MDATA_PID 3 | ||
208 | #define EP_BUFF_STATES 0x2c | ||
209 | #define BUFFER_A_STATE 0 | ||
210 | #define BUFFER_B_STATE 2 | ||
211 | #define BUFF_FREE 0 | ||
212 | #define BUFF_VALID 1 | ||
213 | #define BUFF_LCL 2 | ||
214 | #define BUFF_USB 3 | ||
215 | |||
216 | /*---------------------------------------------------------------------------*/ | ||
217 | |||
218 | #define PCI_DEVICE_ID_RDK1 0x9054 | ||
219 | |||
220 | /* PCI-RDK EPLD Registers */ | ||
221 | #define RDK_EPLD_IO_REGISTER1 0x00000000 | ||
222 | #define RDK_EPLD_USB_RESET 0 | ||
223 | #define RDK_EPLD_USB_POWERDOWN 1 | ||
224 | #define RDK_EPLD_USB_WAKEUP 2 | ||
225 | #define RDK_EPLD_USB_EOT 3 | ||
226 | #define RDK_EPLD_DPPULL 4 | ||
227 | #define RDK_EPLD_IO_REGISTER2 0x00000004 | ||
228 | #define RDK_EPLD_BUSWIDTH 0 | ||
229 | #define RDK_EPLD_USER 2 | ||
230 | #define RDK_EPLD_RESET_INTERRUPT_ENABLE 3 | ||
231 | #define RDK_EPLD_DMA_TIMEOUT_ENABLE 4 | ||
232 | #define RDK_EPLD_STATUS_REGISTER 0x00000008 | ||
233 | #define RDK_EPLD_USB_LRESET 0 | ||
234 | #define RDK_EPLD_REVISION_REGISTER 0x0000000c | ||
235 | |||
236 | /* PCI-RDK PLX 9054 Registers */ | ||
237 | #define INTCSR 0x68 | ||
238 | #define PCI_INTERRUPT_ENABLE 8 | ||
239 | #define LOCAL_INTERRUPT_INPUT_ENABLE 11 | ||
240 | #define LOCAL_INPUT_INTERRUPT_ACTIVE 15 | ||
241 | #define LOCAL_DMA_CHANNEL_0_INTERRUPT_ENABLE 18 | ||
242 | #define LOCAL_DMA_CHANNEL_1_INTERRUPT_ENABLE 19 | ||
243 | #define DMA_CHANNEL_0_INTERRUPT_ACTIVE 21 | ||
244 | #define DMA_CHANNEL_1_INTERRUPT_ACTIVE 22 | ||
245 | #define CNTRL 0x6C | ||
246 | #define RELOAD_CONFIGURATION_REGISTERS 29 | ||
247 | #define PCI_ADAPTER_SOFTWARE_RESET 30 | ||
248 | #define DMAMODE0 0x80 | ||
249 | #define LOCAL_BUS_WIDTH 0 | ||
250 | #define INTERNAL_WAIT_STATES 2 | ||
251 | #define TA_READY_INPUT_ENABLE 6 | ||
252 | #define LOCAL_BURST_ENABLE 8 | ||
253 | #define SCATTER_GATHER_MODE 9 | ||
254 | #define DONE_INTERRUPT_ENABLE 10 | ||
255 | #define LOCAL_ADDRESSING_MODE 11 | ||
256 | #define DEMAND_MODE 12 | ||
257 | #define DMA_EOT_ENABLE 14 | ||
258 | #define FAST_SLOW_TERMINATE_MODE_SELECT 15 | ||
259 | #define DMA_CHANNEL_INTERRUPT_SELECT 17 | ||
260 | #define DMAPADR0 0x84 | ||
261 | #define DMALADR0 0x88 | ||
262 | #define DMASIZ0 0x8c | ||
263 | #define DMADPR0 0x90 | ||
264 | #define DESCRIPTOR_LOCATION 0 | ||
265 | #define END_OF_CHAIN 1 | ||
266 | #define INTERRUPT_AFTER_TERMINAL_COUNT 2 | ||
267 | #define DIRECTION_OF_TRANSFER 3 | ||
268 | #define DMACSR0 0xa8 | ||
269 | #define CHANNEL_ENABLE 0 | ||
270 | #define CHANNEL_START 1 | ||
271 | #define CHANNEL_ABORT 2 | ||
272 | #define CHANNEL_CLEAR_INTERRUPT 3 | ||
273 | #define CHANNEL_DONE 4 | ||
274 | #define DMATHR 0xb0 | ||
275 | #define LBRD1 0xf8 | ||
276 | #define MEMORY_SPACE_LOCAL_BUS_WIDTH 0 | ||
277 | #define W8_BIT 0 | ||
278 | #define W16_BIT 1 | ||
279 | |||
280 | /* Special OR'ing of INTCSR bits */ | ||
281 | #define LOCAL_INTERRUPT_TEST \ | ||
282 | ((1 << LOCAL_INPUT_INTERRUPT_ACTIVE) | \ | ||
283 | (1 << LOCAL_INTERRUPT_INPUT_ENABLE)) | ||
284 | |||
285 | #define DMA_CHANNEL_0_TEST \ | ||
286 | ((1 << DMA_CHANNEL_0_INTERRUPT_ACTIVE) | \ | ||
287 | (1 << LOCAL_DMA_CHANNEL_0_INTERRUPT_ENABLE)) | ||
288 | |||
289 | #define DMA_CHANNEL_1_TEST \ | ||
290 | ((1 << DMA_CHANNEL_1_INTERRUPT_ACTIVE) | \ | ||
291 | (1 << LOCAL_DMA_CHANNEL_1_INTERRUPT_ENABLE)) | ||
292 | |||
293 | /* EPLD Registers */ | ||
294 | #define RDK_EPLD_IO_REGISTER1 0x00000000 | ||
295 | #define RDK_EPLD_USB_RESET 0 | ||
296 | #define RDK_EPLD_USB_POWERDOWN 1 | ||
297 | #define RDK_EPLD_USB_WAKEUP 2 | ||
298 | #define RDK_EPLD_USB_EOT 3 | ||
299 | #define RDK_EPLD_DPPULL 4 | ||
300 | #define RDK_EPLD_IO_REGISTER2 0x00000004 | ||
301 | #define RDK_EPLD_BUSWIDTH 0 | ||
302 | #define RDK_EPLD_USER 2 | ||
303 | #define RDK_EPLD_RESET_INTERRUPT_ENABLE 3 | ||
304 | #define RDK_EPLD_DMA_TIMEOUT_ENABLE 4 | ||
305 | #define RDK_EPLD_STATUS_REGISTER 0x00000008 | ||
306 | #define RDK_EPLD_USB_LRESET 0 | ||
307 | #define RDK_EPLD_REVISION_REGISTER 0x0000000c | ||
308 | |||
309 | #define EPLD_IO_CONTROL_REGISTER 0x400 | ||
310 | #define NET2272_RESET 0 | ||
311 | #define BUSWIDTH 1 | ||
312 | #define MPX_MODE 3 | ||
313 | #define USER 4 | ||
314 | #define DMA_TIMEOUT_ENABLE 5 | ||
315 | #define DMA_CTL_DACK 6 | ||
316 | #define EPLD_DMA_ENABLE 7 | ||
317 | #define EPLD_DMA_CONTROL_REGISTER 0x800 | ||
318 | #define SPLIT_DMA_MODE 0 | ||
319 | #define SPLIT_DMA_DIRECTION 1 | ||
320 | #define SPLIT_DMA_ENABLE 2 | ||
321 | #define SPLIT_DMA_INTERRUPT_ENABLE 3 | ||
322 | #define SPLIT_DMA_INTERRUPT 4 | ||
323 | #define EPLD_DMA_MODE 5 | ||
324 | #define EPLD_DMA_CONTROLLER_ENABLE 7 | ||
325 | #define SPLIT_DMA_ADDRESS_LOW 0xc00 | ||
326 | #define SPLIT_DMA_ADDRESS_HIGH 0x1000 | ||
327 | #define SPLIT_DMA_BYTE_COUNT_LOW 0x1400 | ||
328 | #define SPLIT_DMA_BYTE_COUNT_HIGH 0x1800 | ||
329 | #define EPLD_REVISION_REGISTER 0x1c00 | ||
330 | #define SPLIT_DMA_RAM 0x4000 | ||
331 | #define DMA_RAM_SIZE 0x1000 | ||
332 | |||
333 | /*---------------------------------------------------------------------------*/ | ||
334 | |||
335 | #define PCI_DEVICE_ID_RDK2 0x3272 | ||
336 | |||
337 | /* PCI-RDK version 2 registers */ | ||
338 | |||
339 | /* Main Control Registers */ | ||
340 | |||
341 | #define RDK2_IRQENB 0x00 | ||
342 | #define RDK2_IRQSTAT 0x04 | ||
343 | #define PB7 23 | ||
344 | #define PB6 22 | ||
345 | #define PB5 21 | ||
346 | #define PB4 20 | ||
347 | #define PB3 19 | ||
348 | #define PB2 18 | ||
349 | #define PB1 17 | ||
350 | #define PB0 16 | ||
351 | #define GP3 23 | ||
352 | #define GP2 23 | ||
353 | #define GP1 23 | ||
354 | #define GP0 23 | ||
355 | #define DMA_RETRY_ABORT 6 | ||
356 | #define DMA_PAUSE_DONE 5 | ||
357 | #define DMA_ABORT_DONE 4 | ||
358 | #define DMA_OUT_FIFO_TRANSFER_DONE 3 | ||
359 | #define DMA_LOCAL_DONE 2 | ||
360 | #define DMA_PCI_DONE 1 | ||
361 | #define NET2272_PCI_IRQ 0 | ||
362 | |||
363 | #define RDK2_LOCCTLRDK 0x08 | ||
364 | #define CHIP_RESET 3 | ||
365 | #define SPLIT_DMA 2 | ||
366 | #define MULTIPLEX_MODE 1 | ||
367 | #define BUS_WIDTH 0 | ||
368 | |||
369 | #define RDK2_GPIOCTL 0x10 | ||
370 | #define GP3_OUT_ENABLE 7 | ||
371 | #define GP2_OUT_ENABLE 6 | ||
372 | #define GP1_OUT_ENABLE 5 | ||
373 | #define GP0_OUT_ENABLE 4 | ||
374 | #define GP3_DATA 3 | ||
375 | #define GP2_DATA 2 | ||
376 | #define GP1_DATA 1 | ||
377 | #define GP0_DATA 0 | ||
378 | |||
379 | #define RDK2_LEDSW 0x14 | ||
380 | #define LED3 27 | ||
381 | #define LED2 26 | ||
382 | #define LED1 25 | ||
383 | #define LED0 24 | ||
384 | #define PBUTTON 16 | ||
385 | #define DIPSW 0 | ||
386 | |||
387 | #define RDK2_DIAG 0x18 | ||
388 | #define RDK2_FAST_TIMES 2 | ||
389 | #define FORCE_PCI_SERR 1 | ||
390 | #define FORCE_PCI_INT 0 | ||
391 | #define RDK2_FPGAREV 0x1C | ||
392 | |||
393 | /* Dma Control registers */ | ||
394 | #define RDK2_DMACTL 0x80 | ||
395 | #define ADDR_HOLD 24 | ||
396 | #define RETRY_COUNT 16 /* 23:16 */ | ||
397 | #define FIFO_THRESHOLD 11 /* 15:11 */ | ||
398 | #define MEM_WRITE_INVALIDATE 10 | ||
399 | #define READ_MULTIPLE 9 | ||
400 | #define READ_LINE 8 | ||
401 | #define RDK2_DMA_MODE 6 /* 7:6 */ | ||
402 | #define CONTROL_DACK 5 | ||
403 | #define EOT_ENABLE 4 | ||
404 | #define EOT_POLARITY 3 | ||
405 | #define DACK_POLARITY 2 | ||
406 | #define DREQ_POLARITY 1 | ||
407 | #define DMA_ENABLE 0 | ||
408 | |||
409 | #define RDK2_DMASTAT 0x84 | ||
410 | #define GATHER_COUNT 12 /* 14:12 */ | ||
411 | #define FIFO_COUNT 6 /* 11:6 */ | ||
412 | #define FIFO_FLUSH 5 | ||
413 | #define FIFO_TRANSFER 4 | ||
414 | #define PAUSE_DONE 3 | ||
415 | #define ABORT_DONE 2 | ||
416 | #define DMA_ABORT 1 | ||
417 | #define DMA_START 0 | ||
418 | |||
419 | #define RDK2_DMAPCICOUNT 0x88 | ||
420 | #define DMA_DIRECTION 31 | ||
421 | #define DMA_PCI_BYTE_COUNT 0 /* 0:23 */ | ||
422 | |||
423 | #define RDK2_DMALOCCOUNT 0x8C /* 0:23 dma local byte count */ | ||
424 | |||
425 | #define RDK2_DMAADDR 0x90 /* 2:31 PCI bus starting address */ | ||
426 | |||
427 | /*---------------------------------------------------------------------------*/ | ||
428 | |||
429 | #define REG_INDEXED_THRESHOLD (1 << 5) | ||
430 | |||
431 | /* DRIVER DATA STRUCTURES and UTILITIES */ | ||
432 | struct net2272_ep { | ||
433 | struct usb_ep ep; | ||
434 | struct net2272 *dev; | ||
435 | unsigned long irqs; | ||
436 | |||
437 | /* analogous to a host-side qh */ | ||
438 | struct list_head queue; | ||
439 | const struct usb_endpoint_descriptor *desc; | ||
440 | unsigned num:8, | ||
441 | fifo_size:12, | ||
442 | stopped:1, | ||
443 | wedged:1, | ||
444 | is_in:1, | ||
445 | is_iso:1, | ||
446 | dma:1, | ||
447 | not_empty:1; | ||
448 | }; | ||
449 | |||
450 | struct net2272 { | ||
451 | /* each device provides one gadget, several endpoints */ | ||
452 | struct usb_gadget gadget; | ||
453 | struct device *dev; | ||
454 | unsigned short dev_id; | ||
455 | |||
456 | spinlock_t lock; | ||
457 | struct net2272_ep ep[4]; | ||
458 | struct usb_gadget_driver *driver; | ||
459 | unsigned protocol_stall:1, | ||
460 | softconnect:1, | ||
461 | is_selfpowered:1, | ||
462 | wakeup:1, | ||
463 | dma_eot_polarity:1, | ||
464 | dma_dack_polarity:1, | ||
465 | dma_dreq_polarity:1, | ||
466 | dma_busy:1; | ||
467 | u16 chiprev; | ||
468 | u8 pagesel; | ||
469 | |||
470 | unsigned int irq; | ||
471 | unsigned short fifo_mode; | ||
472 | |||
473 | unsigned int base_shift; | ||
474 | u16 __iomem *base_addr; | ||
475 | union { | ||
476 | #ifdef CONFIG_PCI | ||
477 | struct { | ||
478 | void __iomem *plx9054_base_addr; | ||
479 | void __iomem *epld_base_addr; | ||
480 | } rdk1; | ||
481 | struct { | ||
482 | /* Bar0, Bar1 is base_addr both mem-mapped */ | ||
483 | void __iomem *fpga_base_addr; | ||
484 | } rdk2; | ||
485 | #endif | ||
486 | }; | ||
487 | }; | ||
488 | |||
489 | static void __iomem * | ||
490 | net2272_reg_addr(struct net2272 *dev, unsigned int reg) | ||
491 | { | ||
492 | return dev->base_addr + (reg << dev->base_shift); | ||
493 | } | ||
494 | |||
495 | static void | ||
496 | net2272_write(struct net2272 *dev, unsigned int reg, u8 value) | ||
497 | { | ||
498 | if (reg >= REG_INDEXED_THRESHOLD) { | ||
499 | /* | ||
500 | * Indexed register; use REGADDRPTR/REGDATA | ||
501 | * - Save and restore REGADDRPTR. This prevents REGADDRPTR from | ||
502 | * changes between other code sections, but it is time consuming. | ||
503 | * - Performance tips: either do not save and restore REGADDRPTR (if it | ||
504 | * is safe) or do save/restore operations only in critical sections. | ||
505 | u8 tmp = readb(dev->base_addr + REGADDRPTR); | ||
506 | */ | ||
507 | writeb((u8)reg, net2272_reg_addr(dev, REGADDRPTR)); | ||
508 | writeb(value, net2272_reg_addr(dev, REGDATA)); | ||
509 | /* writeb(tmp, net2272_reg_addr(dev, REGADDRPTR)); */ | ||
510 | } else | ||
511 | writeb(value, net2272_reg_addr(dev, reg)); | ||
512 | } | ||
513 | |||
514 | static u8 | ||
515 | net2272_read(struct net2272 *dev, unsigned int reg) | ||
516 | { | ||
517 | u8 ret; | ||
518 | |||
519 | if (reg >= REG_INDEXED_THRESHOLD) { | ||
520 | /* | ||
521 | * Indexed register; use REGADDRPTR/REGDATA | ||
522 | * - Save and restore REGADDRPTR. This prevents REGADDRPTR from | ||
523 | * changes between other code sections, but it is time consuming. | ||
524 | * - Performance tips: either do not save and restore REGADDRPTR (if it | ||
525 | * is safe) or do save/restore operations only in critical sections. | ||
526 | u8 tmp = readb(dev->base_addr + REGADDRPTR); | ||
527 | */ | ||
528 | writeb((u8)reg, net2272_reg_addr(dev, REGADDRPTR)); | ||
529 | ret = readb(net2272_reg_addr(dev, REGDATA)); | ||
530 | /* writeb(tmp, net2272_reg_addr(dev, REGADDRPTR)); */ | ||
531 | } else | ||
532 | ret = readb(net2272_reg_addr(dev, reg)); | ||
533 | |||
534 | return ret; | ||
535 | } | ||
536 | |||
537 | static void | ||
538 | net2272_ep_write(struct net2272_ep *ep, unsigned int reg, u8 value) | ||
539 | { | ||
540 | struct net2272 *dev = ep->dev; | ||
541 | |||
542 | if (dev->pagesel != ep->num) { | ||
543 | net2272_write(dev, PAGESEL, ep->num); | ||
544 | dev->pagesel = ep->num; | ||
545 | } | ||
546 | net2272_write(dev, reg, value); | ||
547 | } | ||
548 | |||
549 | static u8 | ||
550 | net2272_ep_read(struct net2272_ep *ep, unsigned int reg) | ||
551 | { | ||
552 | struct net2272 *dev = ep->dev; | ||
553 | |||
554 | if (dev->pagesel != ep->num) { | ||
555 | net2272_write(dev, PAGESEL, ep->num); | ||
556 | dev->pagesel = ep->num; | ||
557 | } | ||
558 | return net2272_read(dev, reg); | ||
559 | } | ||
560 | |||
561 | static void allow_status(struct net2272_ep *ep) | ||
562 | { | ||
563 | /* ep0 only */ | ||
564 | net2272_ep_write(ep, EP_RSPCLR, | ||
565 | (1 << CONTROL_STATUS_PHASE_HANDSHAKE) | | ||
566 | (1 << ALT_NAK_OUT_PACKETS) | | ||
567 | (1 << NAK_OUT_PACKETS_MODE)); | ||
568 | ep->stopped = 1; | ||
569 | } | ||
570 | |||
571 | static void set_halt(struct net2272_ep *ep) | ||
572 | { | ||
573 | /* ep0 and bulk/intr endpoints */ | ||
574 | net2272_ep_write(ep, EP_RSPCLR, 1 << CONTROL_STATUS_PHASE_HANDSHAKE); | ||
575 | net2272_ep_write(ep, EP_RSPSET, 1 << ENDPOINT_HALT); | ||
576 | } | ||
577 | |||
578 | static void clear_halt(struct net2272_ep *ep) | ||
579 | { | ||
580 | /* ep0 and bulk/intr endpoints */ | ||
581 | net2272_ep_write(ep, EP_RSPCLR, | ||
582 | (1 << ENDPOINT_HALT) | (1 << ENDPOINT_TOGGLE)); | ||
583 | } | ||
584 | |||
585 | /* count (<= 4) bytes in the next fifo write will be valid */ | ||
586 | static void set_fifo_bytecount(struct net2272_ep *ep, unsigned count) | ||
587 | { | ||
588 | /* net2272_ep_write will truncate to u8 for us */ | ||
589 | net2272_ep_write(ep, EP_TRANSFER2, count >> 16); | ||
590 | net2272_ep_write(ep, EP_TRANSFER1, count >> 8); | ||
591 | net2272_ep_write(ep, EP_TRANSFER0, count); | ||
592 | } | ||
593 | |||
594 | struct net2272_request { | ||
595 | struct usb_request req; | ||
596 | struct list_head queue; | ||
597 | unsigned mapped:1, | ||
598 | valid:1; | ||
599 | }; | ||
600 | |||
601 | #endif | ||
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c index 476d88e1ae97..3dd40b4e675c 100644 --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c | |||
@@ -1410,11 +1410,17 @@ static int net2280_pullup(struct usb_gadget *_gadget, int is_on) | |||
1410 | return 0; | 1410 | return 0; |
1411 | } | 1411 | } |
1412 | 1412 | ||
1413 | static int net2280_start(struct usb_gadget_driver *driver, | ||
1414 | int (*bind)(struct usb_gadget *)); | ||
1415 | static int net2280_stop(struct usb_gadget_driver *driver); | ||
1416 | |||
1413 | static const struct usb_gadget_ops net2280_ops = { | 1417 | static const struct usb_gadget_ops net2280_ops = { |
1414 | .get_frame = net2280_get_frame, | 1418 | .get_frame = net2280_get_frame, |
1415 | .wakeup = net2280_wakeup, | 1419 | .wakeup = net2280_wakeup, |
1416 | .set_selfpowered = net2280_set_selfpowered, | 1420 | .set_selfpowered = net2280_set_selfpowered, |
1417 | .pullup = net2280_pullup, | 1421 | .pullup = net2280_pullup, |
1422 | .start = net2280_start, | ||
1423 | .stop = net2280_stop, | ||
1418 | }; | 1424 | }; |
1419 | 1425 | ||
1420 | /*-------------------------------------------------------------------------*/ | 1426 | /*-------------------------------------------------------------------------*/ |
@@ -1738,62 +1744,6 @@ static void set_fifo_mode (struct net2280 *dev, int mode) | |||
1738 | list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list); | 1744 | list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list); |
1739 | } | 1745 | } |
1740 | 1746 | ||
1741 | /* just declare this in any driver that really need it */ | ||
1742 | extern int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode); | ||
1743 | |||
1744 | /** | ||
1745 | * net2280_set_fifo_mode - change allocation of fifo buffers | ||
1746 | * @gadget: access to the net2280 device that will be updated | ||
1747 | * @mode: 0 for default, four 1kB buffers (ep-a through ep-d); | ||
1748 | * 1 for two 2kB buffers (ep-a and ep-b only); | ||
1749 | * 2 for one 2kB buffer (ep-a) and two 1kB ones (ep-b, ep-c). | ||
1750 | * | ||
1751 | * returns zero on success, else negative errno. when this succeeds, | ||
1752 | * the contents of gadget->ep_list may have changed. | ||
1753 | * | ||
1754 | * you may only call this function when endpoints a-d are all disabled. | ||
1755 | * use it whenever extra hardware buffering can help performance, such | ||
1756 | * as before enabling "high bandwidth" interrupt endpoints that use | ||
1757 | * maxpacket bigger than 512 (when double buffering would otherwise | ||
1758 | * be unavailable). | ||
1759 | */ | ||
1760 | int net2280_set_fifo_mode (struct usb_gadget *gadget, int mode) | ||
1761 | { | ||
1762 | int i; | ||
1763 | struct net2280 *dev; | ||
1764 | int status = 0; | ||
1765 | unsigned long flags; | ||
1766 | |||
1767 | if (!gadget) | ||
1768 | return -ENODEV; | ||
1769 | dev = container_of (gadget, struct net2280, gadget); | ||
1770 | |||
1771 | spin_lock_irqsave (&dev->lock, flags); | ||
1772 | |||
1773 | for (i = 1; i <= 4; i++) | ||
1774 | if (dev->ep [i].desc) { | ||
1775 | status = -EINVAL; | ||
1776 | break; | ||
1777 | } | ||
1778 | if (mode < 0 || mode > 2) | ||
1779 | status = -EINVAL; | ||
1780 | if (status == 0) | ||
1781 | set_fifo_mode (dev, mode); | ||
1782 | spin_unlock_irqrestore (&dev->lock, flags); | ||
1783 | |||
1784 | if (status == 0) { | ||
1785 | if (mode == 1) | ||
1786 | DEBUG (dev, "fifo: ep-a 2K, ep-b 2K\n"); | ||
1787 | else if (mode == 2) | ||
1788 | DEBUG (dev, "fifo: ep-a 2K, ep-b 1K, ep-c 1K\n"); | ||
1789 | /* else all are 1K */ | ||
1790 | } | ||
1791 | return status; | ||
1792 | } | ||
1793 | EXPORT_SYMBOL (net2280_set_fifo_mode); | ||
1794 | |||
1795 | /*-------------------------------------------------------------------------*/ | ||
1796 | |||
1797 | /* keeping it simple: | 1747 | /* keeping it simple: |
1798 | * - one bus driver, initted first; | 1748 | * - one bus driver, initted first; |
1799 | * - one function driver, initted second | 1749 | * - one function driver, initted second |
@@ -1930,7 +1880,7 @@ static void ep0_start (struct net2280 *dev) | |||
1930 | * disconnect is reported. then a host may connect again, or | 1880 | * disconnect is reported. then a host may connect again, or |
1931 | * the driver might get unbound. | 1881 | * the driver might get unbound. |
1932 | */ | 1882 | */ |
1933 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1883 | static int net2280_start(struct usb_gadget_driver *driver, |
1934 | int (*bind)(struct usb_gadget *)) | 1884 | int (*bind)(struct usb_gadget *)) |
1935 | { | 1885 | { |
1936 | struct net2280 *dev = the_controller; | 1886 | struct net2280 *dev = the_controller; |
@@ -1994,7 +1944,6 @@ err_unbind: | |||
1994 | dev->driver = NULL; | 1944 | dev->driver = NULL; |
1995 | return retval; | 1945 | return retval; |
1996 | } | 1946 | } |
1997 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1998 | 1947 | ||
1999 | static void | 1948 | static void |
2000 | stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver) | 1949 | stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver) |
@@ -2022,7 +1971,7 @@ stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver) | |||
2022 | usb_reinit (dev); | 1971 | usb_reinit (dev); |
2023 | } | 1972 | } |
2024 | 1973 | ||
2025 | int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | 1974 | static int net2280_stop(struct usb_gadget_driver *driver) |
2026 | { | 1975 | { |
2027 | struct net2280 *dev = the_controller; | 1976 | struct net2280 *dev = the_controller; |
2028 | unsigned long flags; | 1977 | unsigned long flags; |
@@ -2049,8 +1998,6 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | |||
2049 | DEBUG (dev, "unregistered driver '%s'\n", driver->driver.name); | 1998 | DEBUG (dev, "unregistered driver '%s'\n", driver->driver.name); |
2050 | return 0; | 1999 | return 0; |
2051 | } | 2000 | } |
2052 | EXPORT_SYMBOL (usb_gadget_unregister_driver); | ||
2053 | |||
2054 | 2001 | ||
2055 | /*-------------------------------------------------------------------------*/ | 2002 | /*-------------------------------------------------------------------------*/ |
2056 | 2003 | ||
@@ -2732,6 +2679,8 @@ static void net2280_remove (struct pci_dev *pdev) | |||
2732 | { | 2679 | { |
2733 | struct net2280 *dev = pci_get_drvdata (pdev); | 2680 | struct net2280 *dev = pci_get_drvdata (pdev); |
2734 | 2681 | ||
2682 | usb_del_gadget_udc(&dev->gadget); | ||
2683 | |||
2735 | BUG_ON(dev->driver); | 2684 | BUG_ON(dev->driver); |
2736 | 2685 | ||
2737 | /* then clean up the resources we allocated during probe() */ | 2686 | /* then clean up the resources we allocated during probe() */ |
@@ -2916,6 +2865,9 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) | |||
2916 | retval = device_create_file (&pdev->dev, &dev_attr_registers); | 2865 | retval = device_create_file (&pdev->dev, &dev_attr_registers); |
2917 | if (retval) goto done; | 2866 | if (retval) goto done; |
2918 | 2867 | ||
2868 | retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); | ||
2869 | if (retval) | ||
2870 | goto done; | ||
2919 | return 0; | 2871 | return 0; |
2920 | 2872 | ||
2921 | done: | 2873 | done: |
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c index 55ca63ad3506..c7fb7723c014 100644 --- a/drivers/usb/gadget/nokia.c +++ b/drivers/usb/gadget/nokia.c | |||
@@ -241,6 +241,7 @@ static struct usb_composite_driver nokia_driver = { | |||
241 | .name = "g_nokia", | 241 | .name = "g_nokia", |
242 | .dev = &device_desc, | 242 | .dev = &device_desc, |
243 | .strings = dev_strings, | 243 | .strings = dev_strings, |
244 | .max_speed = USB_SPEED_HIGH, | ||
244 | .unbind = __exit_p(nokia_unbind), | 245 | .unbind = __exit_p(nokia_unbind), |
245 | }; | 246 | }; |
246 | 247 | ||
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index 82fd24935332..740c7daed279 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c | |||
@@ -1375,6 +1375,10 @@ static int omap_pullup(struct usb_gadget *gadget, int is_on) | |||
1375 | return 0; | 1375 | return 0; |
1376 | } | 1376 | } |
1377 | 1377 | ||
1378 | static int omap_udc_start(struct usb_gadget_driver *driver, | ||
1379 | int (*bind)(struct usb_gadget *)); | ||
1380 | static int omap_udc_stop(struct usb_gadget_driver *driver); | ||
1381 | |||
1378 | static struct usb_gadget_ops omap_gadget_ops = { | 1382 | static struct usb_gadget_ops omap_gadget_ops = { |
1379 | .get_frame = omap_get_frame, | 1383 | .get_frame = omap_get_frame, |
1380 | .wakeup = omap_wakeup, | 1384 | .wakeup = omap_wakeup, |
@@ -1382,6 +1386,8 @@ static struct usb_gadget_ops omap_gadget_ops = { | |||
1382 | .vbus_session = omap_vbus_session, | 1386 | .vbus_session = omap_vbus_session, |
1383 | .vbus_draw = omap_vbus_draw, | 1387 | .vbus_draw = omap_vbus_draw, |
1384 | .pullup = omap_pullup, | 1388 | .pullup = omap_pullup, |
1389 | .start = omap_udc_start, | ||
1390 | .stop = omap_udc_stop, | ||
1385 | }; | 1391 | }; |
1386 | 1392 | ||
1387 | /*-------------------------------------------------------------------------*/ | 1393 | /*-------------------------------------------------------------------------*/ |
@@ -2102,7 +2108,7 @@ static inline int machine_without_vbus_sense(void) | |||
2102 | ); | 2108 | ); |
2103 | } | 2109 | } |
2104 | 2110 | ||
2105 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 2111 | static int omap_udc_start(struct usb_gadget_driver *driver, |
2106 | int (*bind)(struct usb_gadget *)) | 2112 | int (*bind)(struct usb_gadget *)) |
2107 | { | 2113 | { |
2108 | int status = -ENODEV; | 2114 | int status = -ENODEV; |
@@ -2186,9 +2192,8 @@ done: | |||
2186 | omap_udc_enable_clock(0); | 2192 | omap_udc_enable_clock(0); |
2187 | return status; | 2193 | return status; |
2188 | } | 2194 | } |
2189 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
2190 | 2195 | ||
2191 | int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | 2196 | static int omap_udc_stop(struct usb_gadget_driver *driver) |
2192 | { | 2197 | { |
2193 | unsigned long flags; | 2198 | unsigned long flags; |
2194 | int status = -ENODEV; | 2199 | int status = -ENODEV; |
@@ -2222,8 +2227,6 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | |||
2222 | DBG("unregistered driver '%s'\n", driver->driver.name); | 2227 | DBG("unregistered driver '%s'\n", driver->driver.name); |
2223 | return status; | 2228 | return status; |
2224 | } | 2229 | } |
2225 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2226 | |||
2227 | 2230 | ||
2228 | /*-------------------------------------------------------------------------*/ | 2231 | /*-------------------------------------------------------------------------*/ |
2229 | 2232 | ||
@@ -2991,9 +2994,16 @@ known: | |||
2991 | 2994 | ||
2992 | create_proc_file(); | 2995 | create_proc_file(); |
2993 | status = device_add(&udc->gadget.dev); | 2996 | status = device_add(&udc->gadget.dev); |
2997 | if (status) | ||
2998 | goto cleanup4; | ||
2999 | |||
3000 | status = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | ||
2994 | if (!status) | 3001 | if (!status) |
2995 | return status; | 3002 | return status; |
2996 | /* If fail, fall through */ | 3003 | /* If fail, fall through */ |
3004 | cleanup4: | ||
3005 | remove_proc_file(); | ||
3006 | |||
2997 | #ifdef USE_ISO | 3007 | #ifdef USE_ISO |
2998 | cleanup3: | 3008 | cleanup3: |
2999 | free_irq(pdev->resource[2].start, udc); | 3009 | free_irq(pdev->resource[2].start, udc); |
@@ -3029,6 +3039,8 @@ static int __exit omap_udc_remove(struct platform_device *pdev) | |||
3029 | 3039 | ||
3030 | if (!udc) | 3040 | if (!udc) |
3031 | return -ENODEV; | 3041 | return -ENODEV; |
3042 | |||
3043 | usb_del_gadget_udc(&udc->gadget); | ||
3032 | if (udc->driver) | 3044 | if (udc->driver) |
3033 | return -EBUSY; | 3045 | return -EBUSY; |
3034 | 3046 | ||
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c index 68dbcc3e4cc2..f96615ab6b77 100644 --- a/drivers/usb/gadget/pch_udc.c +++ b/drivers/usb/gadget/pch_udc.c | |||
@@ -1176,6 +1176,9 @@ static int pch_udc_pcd_vbus_draw(struct usb_gadget *gadget, unsigned int mA) | |||
1176 | return -EOPNOTSUPP; | 1176 | return -EOPNOTSUPP; |
1177 | } | 1177 | } |
1178 | 1178 | ||
1179 | static int pch_udc_start(struct usb_gadget_driver *driver, | ||
1180 | int (*bind)(struct usb_gadget *)); | ||
1181 | static int pch_udc_stop(struct usb_gadget_driver *driver); | ||
1179 | static const struct usb_gadget_ops pch_udc_ops = { | 1182 | static const struct usb_gadget_ops pch_udc_ops = { |
1180 | .get_frame = pch_udc_pcd_get_frame, | 1183 | .get_frame = pch_udc_pcd_get_frame, |
1181 | .wakeup = pch_udc_pcd_wakeup, | 1184 | .wakeup = pch_udc_pcd_wakeup, |
@@ -1183,6 +1186,8 @@ static const struct usb_gadget_ops pch_udc_ops = { | |||
1183 | .pullup = pch_udc_pcd_pullup, | 1186 | .pullup = pch_udc_pcd_pullup, |
1184 | .vbus_session = pch_udc_pcd_vbus_session, | 1187 | .vbus_session = pch_udc_pcd_vbus_session, |
1185 | .vbus_draw = pch_udc_pcd_vbus_draw, | 1188 | .vbus_draw = pch_udc_pcd_vbus_draw, |
1189 | .start = pch_udc_start, | ||
1190 | .stop = pch_udc_stop, | ||
1186 | }; | 1191 | }; |
1187 | 1192 | ||
1188 | /** | 1193 | /** |
@@ -2690,7 +2695,7 @@ static int init_dma_pools(struct pch_udc_dev *dev) | |||
2690 | return 0; | 2695 | return 0; |
2691 | } | 2696 | } |
2692 | 2697 | ||
2693 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 2698 | static int pch_udc_start(struct usb_gadget_driver *driver, |
2694 | int (*bind)(struct usb_gadget *)) | 2699 | int (*bind)(struct usb_gadget *)) |
2695 | { | 2700 | { |
2696 | struct pch_udc_dev *dev = pch_udc; | 2701 | struct pch_udc_dev *dev = pch_udc; |
@@ -2733,9 +2738,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
2733 | dev->connected = 1; | 2738 | dev->connected = 1; |
2734 | return 0; | 2739 | return 0; |
2735 | } | 2740 | } |
2736 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
2737 | 2741 | ||
2738 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 2742 | static int pch_udc_stop(struct usb_gadget_driver *driver) |
2739 | { | 2743 | { |
2740 | struct pch_udc_dev *dev = pch_udc; | 2744 | struct pch_udc_dev *dev = pch_udc; |
2741 | 2745 | ||
@@ -2761,7 +2765,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
2761 | pch_udc_set_disconnect(dev); | 2765 | pch_udc_set_disconnect(dev); |
2762 | return 0; | 2766 | return 0; |
2763 | } | 2767 | } |
2764 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2765 | 2768 | ||
2766 | static void pch_udc_shutdown(struct pci_dev *pdev) | 2769 | static void pch_udc_shutdown(struct pci_dev *pdev) |
2767 | { | 2770 | { |
@@ -2778,6 +2781,8 @@ static void pch_udc_remove(struct pci_dev *pdev) | |||
2778 | { | 2781 | { |
2779 | struct pch_udc_dev *dev = pci_get_drvdata(pdev); | 2782 | struct pch_udc_dev *dev = pci_get_drvdata(pdev); |
2780 | 2783 | ||
2784 | usb_del_gadget_udc(&dev->gadget); | ||
2785 | |||
2781 | /* gadget driver must not be registered */ | 2786 | /* gadget driver must not be registered */ |
2782 | if (dev->driver) | 2787 | if (dev->driver) |
2783 | dev_err(&pdev->dev, | 2788 | dev_err(&pdev->dev, |
@@ -2953,6 +2958,9 @@ static int pch_udc_probe(struct pci_dev *pdev, | |||
2953 | 2958 | ||
2954 | /* Put the device in disconnected state till a driver is bound */ | 2959 | /* Put the device in disconnected state till a driver is bound */ |
2955 | pch_udc_set_disconnect(dev); | 2960 | pch_udc_set_disconnect(dev); |
2961 | retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); | ||
2962 | if (retval) | ||
2963 | goto finished; | ||
2956 | return 0; | 2964 | return 0; |
2957 | 2965 | ||
2958 | finished: | 2966 | finished: |
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index 978e6a101bf2..a341dde6f9c3 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c | |||
@@ -89,8 +89,7 @@ struct printer_dev { | |||
89 | u8 config; | 89 | u8 config; |
90 | s8 interface; | 90 | s8 interface; |
91 | struct usb_ep *in_ep, *out_ep; | 91 | struct usb_ep *in_ep, *out_ep; |
92 | const struct usb_endpoint_descriptor | 92 | |
93 | *in, *out; | ||
94 | struct list_head rx_reqs; /* List of free RX structs */ | 93 | struct list_head rx_reqs; /* List of free RX structs */ |
95 | struct list_head rx_reqs_active; /* List of Active RX xfers */ | 94 | struct list_head rx_reqs_active; /* List of Active RX xfers */ |
96 | struct list_head rx_buffers; /* List of completed xfers */ | 95 | struct list_head rx_buffers; /* List of completed xfers */ |
@@ -898,19 +897,20 @@ set_printer_interface(struct printer_dev *dev) | |||
898 | { | 897 | { |
899 | int result = 0; | 898 | int result = 0; |
900 | 899 | ||
901 | dev->in = ep_desc(dev->gadget, &hs_ep_in_desc, &fs_ep_in_desc); | 900 | dev->in_ep->desc = ep_desc(dev->gadget, &hs_ep_in_desc, &fs_ep_in_desc); |
902 | dev->in_ep->driver_data = dev; | 901 | dev->in_ep->driver_data = dev; |
903 | 902 | ||
904 | dev->out = ep_desc(dev->gadget, &hs_ep_out_desc, &fs_ep_out_desc); | 903 | dev->out_ep->desc = ep_desc(dev->gadget, &hs_ep_out_desc, |
904 | &fs_ep_out_desc); | ||
905 | dev->out_ep->driver_data = dev; | 905 | dev->out_ep->driver_data = dev; |
906 | 906 | ||
907 | result = usb_ep_enable(dev->in_ep, dev->in); | 907 | result = usb_ep_enable(dev->in_ep); |
908 | if (result != 0) { | 908 | if (result != 0) { |
909 | DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); | 909 | DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); |
910 | goto done; | 910 | goto done; |
911 | } | 911 | } |
912 | 912 | ||
913 | result = usb_ep_enable(dev->out_ep, dev->out); | 913 | result = usb_ep_enable(dev->out_ep); |
914 | if (result != 0) { | 914 | if (result != 0) { |
915 | DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); | 915 | DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result); |
916 | goto done; | 916 | goto done; |
@@ -921,8 +921,8 @@ done: | |||
921 | if (result != 0) { | 921 | if (result != 0) { |
922 | (void) usb_ep_disable(dev->in_ep); | 922 | (void) usb_ep_disable(dev->in_ep); |
923 | (void) usb_ep_disable(dev->out_ep); | 923 | (void) usb_ep_disable(dev->out_ep); |
924 | dev->in = NULL; | 924 | dev->in_ep->desc = NULL; |
925 | dev->out = NULL; | 925 | dev->out_ep->desc = NULL; |
926 | } | 926 | } |
927 | 927 | ||
928 | /* caller is responsible for cleanup on error */ | 928 | /* caller is responsible for cleanup on error */ |
@@ -936,12 +936,14 @@ static void printer_reset_interface(struct printer_dev *dev) | |||
936 | 936 | ||
937 | DBG(dev, "%s\n", __func__); | 937 | DBG(dev, "%s\n", __func__); |
938 | 938 | ||
939 | if (dev->in) | 939 | if (dev->in_ep->desc) |
940 | usb_ep_disable(dev->in_ep); | 940 | usb_ep_disable(dev->in_ep); |
941 | 941 | ||
942 | if (dev->out) | 942 | if (dev->out_ep->desc) |
943 | usb_ep_disable(dev->out_ep); | 943 | usb_ep_disable(dev->out_ep); |
944 | 944 | ||
945 | dev->in_ep->desc = NULL; | ||
946 | dev->out_ep->desc = NULL; | ||
945 | dev->interface = -1; | 947 | dev->interface = -1; |
946 | } | 948 | } |
947 | 949 | ||
@@ -1107,9 +1109,9 @@ static void printer_soft_reset(struct printer_dev *dev) | |||
1107 | list_add(&req->list, &dev->tx_reqs); | 1109 | list_add(&req->list, &dev->tx_reqs); |
1108 | } | 1110 | } |
1109 | 1111 | ||
1110 | if (usb_ep_enable(dev->in_ep, dev->in)) | 1112 | if (usb_ep_enable(dev->in_ep)) |
1111 | DBG(dev, "Failed to enable USB in_ep\n"); | 1113 | DBG(dev, "Failed to enable USB in_ep\n"); |
1112 | if (usb_ep_enable(dev->out_ep, dev->out)) | 1114 | if (usb_ep_enable(dev->out_ep)) |
1113 | DBG(dev, "Failed to enable USB out_ep\n"); | 1115 | DBG(dev, "Failed to enable USB out_ep\n"); |
1114 | 1116 | ||
1115 | wake_up_interruptible(&dev->rx_wait); | 1117 | wake_up_interruptible(&dev->rx_wait); |
@@ -1149,6 +1151,8 @@ printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1149 | switch (wValue >> 8) { | 1151 | switch (wValue >> 8) { |
1150 | 1152 | ||
1151 | case USB_DT_DEVICE: | 1153 | case USB_DT_DEVICE: |
1154 | device_desc.bMaxPacketSize0 = | ||
1155 | gadget->ep0->maxpacket; | ||
1152 | value = min(wLength, (u16) sizeof device_desc); | 1156 | value = min(wLength, (u16) sizeof device_desc); |
1153 | memcpy(req->buf, &device_desc, value); | 1157 | memcpy(req->buf, &device_desc, value); |
1154 | break; | 1158 | break; |
@@ -1156,6 +1160,12 @@ printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1156 | case USB_DT_DEVICE_QUALIFIER: | 1160 | case USB_DT_DEVICE_QUALIFIER: |
1157 | if (!gadget->is_dualspeed) | 1161 | if (!gadget->is_dualspeed) |
1158 | break; | 1162 | break; |
1163 | /* | ||
1164 | * assumes ep0 uses the same value for both | ||
1165 | * speeds | ||
1166 | */ | ||
1167 | dev_qualifier.bMaxPacketSize0 = | ||
1168 | gadget->ep0->maxpacket; | ||
1159 | value = min(wLength, | 1169 | value = min(wLength, |
1160 | (u16) sizeof dev_qualifier); | 1170 | (u16) sizeof dev_qualifier); |
1161 | memcpy(req->buf, &dev_qualifier, value); | 1171 | memcpy(req->buf, &dev_qualifier, value); |
@@ -1451,15 +1461,11 @@ autoconf_fail: | |||
1451 | out_ep->driver_data = out_ep; /* claim */ | 1461 | out_ep->driver_data = out_ep; /* claim */ |
1452 | 1462 | ||
1453 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 1463 | #ifdef CONFIG_USB_GADGET_DUALSPEED |
1454 | /* assumes ep0 uses the same value for both speeds ... */ | 1464 | /* assumes that all endpoints are dual-speed */ |
1455 | dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0; | ||
1456 | |||
1457 | /* and that all endpoints are dual-speed */ | ||
1458 | hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; | 1465 | hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; |
1459 | hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; | 1466 | hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; |
1460 | #endif /* DUALSPEED */ | 1467 | #endif /* DUALSPEED */ |
1461 | 1468 | ||
1462 | device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; | ||
1463 | usb_gadget_set_selfpowered(gadget); | 1469 | usb_gadget_set_selfpowered(gadget); |
1464 | 1470 | ||
1465 | if (gadget->is_otg) { | 1471 | if (gadget->is_otg) { |
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c index 774545494cf2..e4e59b4de25d 100644 --- a/drivers/usb/gadget/pxa25x_udc.c +++ b/drivers/usb/gadget/pxa25x_udc.c | |||
@@ -1011,12 +1011,18 @@ static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA) | |||
1011 | return -EOPNOTSUPP; | 1011 | return -EOPNOTSUPP; |
1012 | } | 1012 | } |
1013 | 1013 | ||
1014 | static int pxa25x_start(struct usb_gadget_driver *driver, | ||
1015 | int (*bind)(struct usb_gadget *)); | ||
1016 | static int pxa25x_stop(struct usb_gadget_driver *driver); | ||
1017 | |||
1014 | static const struct usb_gadget_ops pxa25x_udc_ops = { | 1018 | static const struct usb_gadget_ops pxa25x_udc_ops = { |
1015 | .get_frame = pxa25x_udc_get_frame, | 1019 | .get_frame = pxa25x_udc_get_frame, |
1016 | .wakeup = pxa25x_udc_wakeup, | 1020 | .wakeup = pxa25x_udc_wakeup, |
1017 | .vbus_session = pxa25x_udc_vbus_session, | 1021 | .vbus_session = pxa25x_udc_vbus_session, |
1018 | .pullup = pxa25x_udc_pullup, | 1022 | .pullup = pxa25x_udc_pullup, |
1019 | .vbus_draw = pxa25x_udc_vbus_draw, | 1023 | .vbus_draw = pxa25x_udc_vbus_draw, |
1024 | .start = pxa25x_start, | ||
1025 | .stop = pxa25x_stop, | ||
1020 | }; | 1026 | }; |
1021 | 1027 | ||
1022 | /*-------------------------------------------------------------------------*/ | 1028 | /*-------------------------------------------------------------------------*/ |
@@ -1263,7 +1269,7 @@ static void udc_enable (struct pxa25x_udc *dev) | |||
1263 | * disconnect is reported. then a host may connect again, or | 1269 | * disconnect is reported. then a host may connect again, or |
1264 | * the driver might get unbound. | 1270 | * the driver might get unbound. |
1265 | */ | 1271 | */ |
1266 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1272 | static int pxa25x_start(struct usb_gadget_driver *driver, |
1267 | int (*bind)(struct usb_gadget *)) | 1273 | int (*bind)(struct usb_gadget *)) |
1268 | { | 1274 | { |
1269 | struct pxa25x_udc *dev = the_controller; | 1275 | struct pxa25x_udc *dev = the_controller; |
@@ -1322,7 +1328,6 @@ fail: | |||
1322 | bind_fail: | 1328 | bind_fail: |
1323 | return retval; | 1329 | return retval; |
1324 | } | 1330 | } |
1325 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1326 | 1331 | ||
1327 | static void | 1332 | static void |
1328 | stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) | 1333 | stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) |
@@ -1351,7 +1356,7 @@ stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver) | |||
1351 | udc_reinit(dev); | 1356 | udc_reinit(dev); |
1352 | } | 1357 | } |
1353 | 1358 | ||
1354 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1359 | static int pxa25x_stop(struct usb_gadget_driver *driver) |
1355 | { | 1360 | { |
1356 | struct pxa25x_udc *dev = the_controller; | 1361 | struct pxa25x_udc *dev = the_controller; |
1357 | 1362 | ||
@@ -1379,8 +1384,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1379 | dump_state(dev); | 1384 | dump_state(dev); |
1380 | return 0; | 1385 | return 0; |
1381 | } | 1386 | } |
1382 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1383 | |||
1384 | 1387 | ||
1385 | /*-------------------------------------------------------------------------*/ | 1388 | /*-------------------------------------------------------------------------*/ |
1386 | 1389 | ||
@@ -2231,8 +2234,11 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev) | |||
2231 | #endif | 2234 | #endif |
2232 | create_debug_files(dev); | 2235 | create_debug_files(dev); |
2233 | 2236 | ||
2234 | return 0; | 2237 | retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); |
2238 | if (!retval) | ||
2239 | return retval; | ||
2235 | 2240 | ||
2241 | remove_debug_files(dev); | ||
2236 | #ifdef CONFIG_ARCH_LUBBOCK | 2242 | #ifdef CONFIG_ARCH_LUBBOCK |
2237 | lubbock_fail0: | 2243 | lubbock_fail0: |
2238 | free_irq(LUBBOCK_USB_DISC_IRQ, dev); | 2244 | free_irq(LUBBOCK_USB_DISC_IRQ, dev); |
@@ -2261,6 +2267,7 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev) | |||
2261 | { | 2267 | { |
2262 | struct pxa25x_udc *dev = platform_get_drvdata(pdev); | 2268 | struct pxa25x_udc *dev = platform_get_drvdata(pdev); |
2263 | 2269 | ||
2270 | usb_del_gadget_udc(&dev->gadget); | ||
2264 | if (dev->driver) | 2271 | if (dev->driver) |
2265 | return -EBUSY; | 2272 | return -EBUSY; |
2266 | 2273 | ||
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 57607696735c..85b68c75dc9d 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c | |||
@@ -1680,12 +1680,18 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA) | |||
1680 | return -EOPNOTSUPP; | 1680 | return -EOPNOTSUPP; |
1681 | } | 1681 | } |
1682 | 1682 | ||
1683 | static int pxa27x_udc_start(struct usb_gadget_driver *driver, | ||
1684 | int (*bind)(struct usb_gadget *)); | ||
1685 | static int pxa27x_udc_stop(struct usb_gadget_driver *driver); | ||
1686 | |||
1683 | static const struct usb_gadget_ops pxa_udc_ops = { | 1687 | static const struct usb_gadget_ops pxa_udc_ops = { |
1684 | .get_frame = pxa_udc_get_frame, | 1688 | .get_frame = pxa_udc_get_frame, |
1685 | .wakeup = pxa_udc_wakeup, | 1689 | .wakeup = pxa_udc_wakeup, |
1686 | .pullup = pxa_udc_pullup, | 1690 | .pullup = pxa_udc_pullup, |
1687 | .vbus_session = pxa_udc_vbus_session, | 1691 | .vbus_session = pxa_udc_vbus_session, |
1688 | .vbus_draw = pxa_udc_vbus_draw, | 1692 | .vbus_draw = pxa_udc_vbus_draw, |
1693 | .start = pxa27x_udc_start, | ||
1694 | .stop = pxa27x_udc_stop, | ||
1689 | }; | 1695 | }; |
1690 | 1696 | ||
1691 | /** | 1697 | /** |
@@ -1791,7 +1797,7 @@ static void udc_enable(struct pxa_udc *udc) | |||
1791 | } | 1797 | } |
1792 | 1798 | ||
1793 | /** | 1799 | /** |
1794 | * usb_gadget_probe_driver - Register gadget driver | 1800 | * pxa27x_start - Register gadget driver |
1795 | * @driver: gadget driver | 1801 | * @driver: gadget driver |
1796 | * @bind: bind function | 1802 | * @bind: bind function |
1797 | * | 1803 | * |
@@ -1805,7 +1811,7 @@ static void udc_enable(struct pxa_udc *udc) | |||
1805 | * | 1811 | * |
1806 | * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise | 1812 | * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise |
1807 | */ | 1813 | */ |
1808 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1814 | static int pxa27x_udc_start(struct usb_gadget_driver *driver, |
1809 | int (*bind)(struct usb_gadget *)) | 1815 | int (*bind)(struct usb_gadget *)) |
1810 | { | 1816 | { |
1811 | struct pxa_udc *udc = the_controller; | 1817 | struct pxa_udc *udc = the_controller; |
@@ -1860,8 +1866,6 @@ add_fail: | |||
1860 | udc->gadget.dev.driver = NULL; | 1866 | udc->gadget.dev.driver = NULL; |
1861 | return retval; | 1867 | return retval; |
1862 | } | 1868 | } |
1863 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1864 | |||
1865 | 1869 | ||
1866 | /** | 1870 | /** |
1867 | * stop_activity - Stops udc endpoints | 1871 | * stop_activity - Stops udc endpoints |
@@ -1888,12 +1892,12 @@ static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver) | |||
1888 | } | 1892 | } |
1889 | 1893 | ||
1890 | /** | 1894 | /** |
1891 | * usb_gadget_unregister_driver - Unregister the gadget driver | 1895 | * pxa27x_udc_stop - Unregister the gadget driver |
1892 | * @driver: gadget driver | 1896 | * @driver: gadget driver |
1893 | * | 1897 | * |
1894 | * Returns 0 if no error, -ENODEV, -EINVAL otherwise | 1898 | * Returns 0 if no error, -ENODEV, -EINVAL otherwise |
1895 | */ | 1899 | */ |
1896 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1900 | static int pxa27x_udc_stop(struct usb_gadget_driver *driver) |
1897 | { | 1901 | { |
1898 | struct pxa_udc *udc = the_controller; | 1902 | struct pxa_udc *udc = the_controller; |
1899 | 1903 | ||
@@ -1917,7 +1921,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1917 | return otg_set_peripheral(udc->transceiver, NULL); | 1921 | return otg_set_peripheral(udc->transceiver, NULL); |
1918 | return 0; | 1922 | return 0; |
1919 | } | 1923 | } |
1920 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1921 | 1924 | ||
1922 | /** | 1925 | /** |
1923 | * handle_ep0_ctrl_req - handle control endpoint control request | 1926 | * handle_ep0_ctrl_req - handle control endpoint control request |
@@ -2516,9 +2519,14 @@ static int __init pxa_udc_probe(struct platform_device *pdev) | |||
2516 | driver_name, IRQ_USB, retval); | 2519 | driver_name, IRQ_USB, retval); |
2517 | goto err_irq; | 2520 | goto err_irq; |
2518 | } | 2521 | } |
2522 | retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | ||
2523 | if (retval) | ||
2524 | goto err_add_udc; | ||
2519 | 2525 | ||
2520 | pxa_init_debugfs(udc); | 2526 | pxa_init_debugfs(udc); |
2521 | return 0; | 2527 | return 0; |
2528 | err_add_udc: | ||
2529 | free_irq(udc->irq, udc); | ||
2522 | err_irq: | 2530 | err_irq: |
2523 | iounmap(udc->regs); | 2531 | iounmap(udc->regs); |
2524 | err_map: | 2532 | err_map: |
@@ -2537,6 +2545,7 @@ static int __exit pxa_udc_remove(struct platform_device *_dev) | |||
2537 | struct pxa_udc *udc = platform_get_drvdata(_dev); | 2545 | struct pxa_udc *udc = platform_get_drvdata(_dev); |
2538 | int gpio = udc->mach->gpio_pullup; | 2546 | int gpio = udc->mach->gpio_pullup; |
2539 | 2547 | ||
2548 | usb_del_gadget_udc(&udc->gadget); | ||
2540 | usb_gadget_unregister_driver(udc->driver); | 2549 | usb_gadget_unregister_driver(udc->driver); |
2541 | free_irq(udc->irq, udc); | 2550 | free_irq(udc->irq, udc); |
2542 | pxa_cleanup_debugfs(udc); | 2551 | pxa_cleanup_debugfs(udc); |
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c index 6dcc1f68fa60..50991e5bd5e8 100644 --- a/drivers/usb/gadget/r8a66597-udc.c +++ b/drivers/usb/gadget/r8a66597-udc.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) 2006-2009 Renesas Solutions Corp. | 4 | * Copyright (C) 2006-2009 Renesas Solutions Corp. |
5 | * | 5 | * |
6 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> | 6 | * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
@@ -576,7 +576,11 @@ static void init_controller(struct r8a66597 *r8a66597) | |||
576 | u16 endian = r8a66597->pdata->endian ? BIGEND : 0; | 576 | u16 endian = r8a66597->pdata->endian ? BIGEND : 0; |
577 | 577 | ||
578 | if (r8a66597->pdata->on_chip) { | 578 | if (r8a66597->pdata->on_chip) { |
579 | r8a66597_bset(r8a66597, 0x04, SYSCFG1); | 579 | if (r8a66597->pdata->buswait) |
580 | r8a66597_write(r8a66597, r8a66597->pdata->buswait, | ||
581 | SYSCFG1); | ||
582 | else | ||
583 | r8a66597_write(r8a66597, 0x0f, SYSCFG1); | ||
580 | r8a66597_bset(r8a66597, HSE, SYSCFG0); | 584 | r8a66597_bset(r8a66597, HSE, SYSCFG0); |
581 | 585 | ||
582 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); | 586 | r8a66597_bclr(r8a66597, USBE, SYSCFG0); |
@@ -618,6 +622,7 @@ static void disable_controller(struct r8a66597 *r8a66597) | |||
618 | { | 622 | { |
619 | if (r8a66597->pdata->on_chip) { | 623 | if (r8a66597->pdata->on_chip) { |
620 | r8a66597_bset(r8a66597, SCKE, SYSCFG0); | 624 | r8a66597_bset(r8a66597, SCKE, SYSCFG0); |
625 | r8a66597_bclr(r8a66597, UTST, TESTMODE); | ||
621 | 626 | ||
622 | /* disable interrupts */ | 627 | /* disable interrupts */ |
623 | r8a66597_write(r8a66597, 0, INTENB0); | 628 | r8a66597_write(r8a66597, 0, INTENB0); |
@@ -635,6 +640,7 @@ static void disable_controller(struct r8a66597 *r8a66597) | |||
635 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); | 640 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); |
636 | 641 | ||
637 | } else { | 642 | } else { |
643 | r8a66597_bclr(r8a66597, UTST, TESTMODE); | ||
638 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); | 644 | r8a66597_bclr(r8a66597, SCKE, SYSCFG0); |
639 | udelay(1); | 645 | udelay(1); |
640 | r8a66597_bclr(r8a66597, PLLC, SYSCFG0); | 646 | r8a66597_bclr(r8a66597, PLLC, SYSCFG0); |
@@ -999,10 +1005,29 @@ static void clear_feature(struct r8a66597 *r8a66597, | |||
999 | 1005 | ||
1000 | static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl) | 1006 | static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl) |
1001 | { | 1007 | { |
1008 | u16 tmp; | ||
1009 | int timeout = 3000; | ||
1002 | 1010 | ||
1003 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | 1011 | switch (ctrl->bRequestType & USB_RECIP_MASK) { |
1004 | case USB_RECIP_DEVICE: | 1012 | case USB_RECIP_DEVICE: |
1005 | control_end(r8a66597, 1); | 1013 | switch (le16_to_cpu(ctrl->wValue)) { |
1014 | case USB_DEVICE_TEST_MODE: | ||
1015 | control_end(r8a66597, 1); | ||
1016 | /* Wait for the completion of status stage */ | ||
1017 | do { | ||
1018 | tmp = r8a66597_read(r8a66597, INTSTS0) & CTSQ; | ||
1019 | udelay(1); | ||
1020 | } while (tmp != CS_IDST || timeout-- > 0); | ||
1021 | |||
1022 | if (tmp == CS_IDST) | ||
1023 | r8a66597_bset(r8a66597, | ||
1024 | le16_to_cpu(ctrl->wIndex >> 8), | ||
1025 | TESTMODE); | ||
1026 | break; | ||
1027 | default: | ||
1028 | pipe_stall(r8a66597, 0); | ||
1029 | break; | ||
1030 | } | ||
1006 | break; | 1031 | break; |
1007 | case USB_RECIP_INTERFACE: | 1032 | case USB_RECIP_INTERFACE: |
1008 | control_end(r8a66597, 1); | 1033 | control_end(r8a66597, 1); |
@@ -1410,7 +1435,7 @@ static struct usb_ep_ops r8a66597_ep_ops = { | |||
1410 | /*-------------------------------------------------------------------------*/ | 1435 | /*-------------------------------------------------------------------------*/ |
1411 | static struct r8a66597 *the_controller; | 1436 | static struct r8a66597 *the_controller; |
1412 | 1437 | ||
1413 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1438 | static int r8a66597_start(struct usb_gadget_driver *driver, |
1414 | int (*bind)(struct usb_gadget *)) | 1439 | int (*bind)(struct usb_gadget *)) |
1415 | { | 1440 | { |
1416 | struct r8a66597 *r8a66597 = the_controller; | 1441 | struct r8a66597 *r8a66597 = the_controller; |
@@ -1444,6 +1469,7 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
1444 | goto error; | 1469 | goto error; |
1445 | } | 1470 | } |
1446 | 1471 | ||
1472 | init_controller(r8a66597); | ||
1447 | r8a66597_bset(r8a66597, VBSE, INTENB0); | 1473 | r8a66597_bset(r8a66597, VBSE, INTENB0); |
1448 | if (r8a66597_read(r8a66597, INTSTS0) & VBSTS) { | 1474 | if (r8a66597_read(r8a66597, INTSTS0) & VBSTS) { |
1449 | r8a66597_start_xclock(r8a66597); | 1475 | r8a66597_start_xclock(r8a66597); |
@@ -1462,9 +1488,8 @@ error: | |||
1462 | 1488 | ||
1463 | return retval; | 1489 | return retval; |
1464 | } | 1490 | } |
1465 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1466 | 1491 | ||
1467 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1492 | static int r8a66597_stop(struct usb_gadget_driver *driver) |
1468 | { | 1493 | { |
1469 | struct r8a66597 *r8a66597 = the_controller; | 1494 | struct r8a66597 *r8a66597 = the_controller; |
1470 | unsigned long flags; | 1495 | unsigned long flags; |
@@ -1475,20 +1500,16 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1475 | spin_lock_irqsave(&r8a66597->lock, flags); | 1500 | spin_lock_irqsave(&r8a66597->lock, flags); |
1476 | if (r8a66597->gadget.speed != USB_SPEED_UNKNOWN) | 1501 | if (r8a66597->gadget.speed != USB_SPEED_UNKNOWN) |
1477 | r8a66597_usb_disconnect(r8a66597); | 1502 | r8a66597_usb_disconnect(r8a66597); |
1478 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1479 | |||
1480 | r8a66597_bclr(r8a66597, VBSE, INTENB0); | 1503 | r8a66597_bclr(r8a66597, VBSE, INTENB0); |
1504 | disable_controller(r8a66597); | ||
1505 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1481 | 1506 | ||
1482 | driver->unbind(&r8a66597->gadget); | 1507 | driver->unbind(&r8a66597->gadget); |
1483 | 1508 | ||
1484 | init_controller(r8a66597); | ||
1485 | disable_controller(r8a66597); | ||
1486 | |||
1487 | device_del(&r8a66597->gadget.dev); | 1509 | device_del(&r8a66597->gadget.dev); |
1488 | r8a66597->driver = NULL; | 1510 | r8a66597->driver = NULL; |
1489 | return 0; | 1511 | return 0; |
1490 | } | 1512 | } |
1491 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1492 | 1513 | ||
1493 | /*-------------------------------------------------------------------------*/ | 1514 | /*-------------------------------------------------------------------------*/ |
1494 | static int r8a66597_get_frame(struct usb_gadget *_gadget) | 1515 | static int r8a66597_get_frame(struct usb_gadget *_gadget) |
@@ -1497,14 +1518,33 @@ static int r8a66597_get_frame(struct usb_gadget *_gadget) | |||
1497 | return r8a66597_read(r8a66597, FRMNUM) & 0x03FF; | 1518 | return r8a66597_read(r8a66597, FRMNUM) & 0x03FF; |
1498 | } | 1519 | } |
1499 | 1520 | ||
1521 | static int r8a66597_pullup(struct usb_gadget *gadget, int is_on) | ||
1522 | { | ||
1523 | struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget); | ||
1524 | unsigned long flags; | ||
1525 | |||
1526 | spin_lock_irqsave(&r8a66597->lock, flags); | ||
1527 | if (is_on) | ||
1528 | r8a66597_bset(r8a66597, DPRPU, SYSCFG0); | ||
1529 | else | ||
1530 | r8a66597_bclr(r8a66597, DPRPU, SYSCFG0); | ||
1531 | spin_unlock_irqrestore(&r8a66597->lock, flags); | ||
1532 | |||
1533 | return 0; | ||
1534 | } | ||
1535 | |||
1500 | static struct usb_gadget_ops r8a66597_gadget_ops = { | 1536 | static struct usb_gadget_ops r8a66597_gadget_ops = { |
1501 | .get_frame = r8a66597_get_frame, | 1537 | .get_frame = r8a66597_get_frame, |
1538 | .start = r8a66597_start, | ||
1539 | .stop = r8a66597_stop, | ||
1540 | .pullup = r8a66597_pullup, | ||
1502 | }; | 1541 | }; |
1503 | 1542 | ||
1504 | static int __exit r8a66597_remove(struct platform_device *pdev) | 1543 | static int __exit r8a66597_remove(struct platform_device *pdev) |
1505 | { | 1544 | { |
1506 | struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); | 1545 | struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev); |
1507 | 1546 | ||
1547 | usb_del_gadget_udc(&r8a66597->gadget); | ||
1508 | del_timer_sync(&r8a66597->timer); | 1548 | del_timer_sync(&r8a66597->timer); |
1509 | iounmap(r8a66597->reg); | 1549 | iounmap(r8a66597->reg); |
1510 | free_irq(platform_get_irq(pdev, 0), r8a66597); | 1550 | free_irq(platform_get_irq(pdev, 0), r8a66597); |
@@ -1645,11 +1685,15 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1645 | goto clean_up3; | 1685 | goto clean_up3; |
1646 | r8a66597->ep0_req->complete = nop_completion; | 1686 | r8a66597->ep0_req->complete = nop_completion; |
1647 | 1687 | ||
1648 | init_controller(r8a66597); | 1688 | ret = usb_add_gadget_udc(&pdev->dev, &r8a66597->gadget); |
1689 | if (ret) | ||
1690 | goto err_add_udc; | ||
1649 | 1691 | ||
1650 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); | 1692 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); |
1651 | return 0; | 1693 | return 0; |
1652 | 1694 | ||
1695 | err_add_udc: | ||
1696 | r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req); | ||
1653 | clean_up3: | 1697 | clean_up3: |
1654 | free_irq(irq, r8a66597); | 1698 | free_irq(irq, r8a66597); |
1655 | clean_up2: | 1699 | clean_up2: |
@@ -1679,6 +1723,7 @@ static struct platform_driver r8a66597_driver = { | |||
1679 | .name = (char *) udc_name, | 1723 | .name = (char *) udc_name, |
1680 | }, | 1724 | }, |
1681 | }; | 1725 | }; |
1726 | MODULE_ALIAS("platform:r8a66597_udc"); | ||
1682 | 1727 | ||
1683 | static int __init r8a66597_udc_init(void) | 1728 | static int __init r8a66597_udc_init(void) |
1684 | { | 1729 | { |
diff --git a/drivers/usb/gadget/r8a66597-udc.h b/drivers/usb/gadget/r8a66597-udc.h index 5fc22e09a0f1..503f766c23a7 100644 --- a/drivers/usb/gadget/r8a66597-udc.h +++ b/drivers/usb/gadget/r8a66597-udc.h | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) 2007-2009 Renesas Solutions Corp. | 4 | * Copyright (C) 2007-2009 Renesas Solutions Corp. |
5 | * | 5 | * |
6 | * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> | 6 | * Author : Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index 0dfee282878a..8bdee67ce09a 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c | |||
@@ -2574,7 +2574,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | |||
2574 | return 0; | 2574 | return 0; |
2575 | } | 2575 | } |
2576 | 2576 | ||
2577 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 2577 | static int s3c_hsotg_start(struct usb_gadget_driver *driver, |
2578 | int (*bind)(struct usb_gadget *)) | 2578 | int (*bind)(struct usb_gadget *)) |
2579 | { | 2579 | { |
2580 | struct s3c_hsotg *hsotg = our_hsotg; | 2580 | struct s3c_hsotg *hsotg = our_hsotg; |
@@ -2745,9 +2745,8 @@ err: | |||
2745 | hsotg->gadget.dev.driver = NULL; | 2745 | hsotg->gadget.dev.driver = NULL; |
2746 | return ret; | 2746 | return ret; |
2747 | } | 2747 | } |
2748 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
2749 | 2748 | ||
2750 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 2749 | static int s3c_hsotg_stop(struct usb_gadget_driver *driver) |
2751 | { | 2750 | { |
2752 | struct s3c_hsotg *hsotg = our_hsotg; | 2751 | struct s3c_hsotg *hsotg = our_hsotg; |
2753 | int ep; | 2752 | int ep; |
@@ -2775,7 +2774,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
2775 | 2774 | ||
2776 | return 0; | 2775 | return 0; |
2777 | } | 2776 | } |
2778 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2779 | 2777 | ||
2780 | static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) | 2778 | static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) |
2781 | { | 2779 | { |
@@ -2784,6 +2782,8 @@ static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) | |||
2784 | 2782 | ||
2785 | static struct usb_gadget_ops s3c_hsotg_gadget_ops = { | 2783 | static struct usb_gadget_ops s3c_hsotg_gadget_ops = { |
2786 | .get_frame = s3c_hsotg_gadget_getframe, | 2784 | .get_frame = s3c_hsotg_gadget_getframe, |
2785 | .start = s3c_hsotg_start, | ||
2786 | .stop = s3c_hsotg_stop, | ||
2787 | }; | 2787 | }; |
2788 | 2788 | ||
2789 | /** | 2789 | /** |
@@ -3403,6 +3403,10 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev) | |||
3403 | for (epnum = 0; epnum < S3C_HSOTG_EPS; epnum++) | 3403 | for (epnum = 0; epnum < S3C_HSOTG_EPS; epnum++) |
3404 | s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum); | 3404 | s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum); |
3405 | 3405 | ||
3406 | ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget); | ||
3407 | if (ret) | ||
3408 | goto err_add_udc; | ||
3409 | |||
3406 | s3c_hsotg_create_debug(hsotg); | 3410 | s3c_hsotg_create_debug(hsotg); |
3407 | 3411 | ||
3408 | s3c_hsotg_dump(hsotg); | 3412 | s3c_hsotg_dump(hsotg); |
@@ -3410,6 +3414,11 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev) | |||
3410 | our_hsotg = hsotg; | 3414 | our_hsotg = hsotg; |
3411 | return 0; | 3415 | return 0; |
3412 | 3416 | ||
3417 | err_add_udc: | ||
3418 | s3c_hsotg_gate(pdev, false); | ||
3419 | clk_disable(hsotg->clk); | ||
3420 | clk_put(hsotg->clk); | ||
3421 | |||
3413 | err_regs: | 3422 | err_regs: |
3414 | iounmap(hsotg->regs); | 3423 | iounmap(hsotg->regs); |
3415 | 3424 | ||
@@ -3427,6 +3436,8 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev) | |||
3427 | { | 3436 | { |
3428 | struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); | 3437 | struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); |
3429 | 3438 | ||
3439 | usb_del_gadget_udc(&hsotg->gadget); | ||
3440 | |||
3430 | s3c_hsotg_delete_debug(hsotg); | 3441 | s3c_hsotg_delete_debug(hsotg); |
3431 | 3442 | ||
3432 | usb_gadget_unregister_driver(hsotg->driver); | 3443 | usb_gadget_unregister_driver(hsotg->driver); |
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c index d5e3e1e58626..3fa717c5f4bc 100644 --- a/drivers/usb/gadget/s3c-hsudc.c +++ b/drivers/usb/gadget/s3c-hsudc.c | |||
@@ -1133,7 +1133,7 @@ static irqreturn_t s3c_hsudc_irq(int irq, void *_dev) | |||
1133 | return IRQ_HANDLED; | 1133 | return IRQ_HANDLED; |
1134 | } | 1134 | } |
1135 | 1135 | ||
1136 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1136 | static int s3c_hsudc_start(struct usb_gadget_driver *driver, |
1137 | int (*bind)(struct usb_gadget *)) | 1137 | int (*bind)(struct usb_gadget *)) |
1138 | { | 1138 | { |
1139 | struct s3c_hsudc *hsudc = the_controller; | 1139 | struct s3c_hsudc *hsudc = the_controller; |
@@ -1181,9 +1181,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | |||
1181 | 1181 | ||
1182 | return 0; | 1182 | return 0; |
1183 | } | 1183 | } |
1184 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1185 | 1184 | ||
1186 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1185 | static int s3c_hsudc_stop(struct usb_gadget_driver *driver) |
1187 | { | 1186 | { |
1188 | struct s3c_hsudc *hsudc = the_controller; | 1187 | struct s3c_hsudc *hsudc = the_controller; |
1189 | unsigned long flags; | 1188 | unsigned long flags; |
@@ -1210,7 +1209,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1210 | driver->driver.name); | 1209 | driver->driver.name); |
1211 | return 0; | 1210 | return 0; |
1212 | } | 1211 | } |
1213 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1214 | 1212 | ||
1215 | static inline u32 s3c_hsudc_read_frameno(struct s3c_hsudc *hsudc) | 1213 | static inline u32 s3c_hsudc_read_frameno(struct s3c_hsudc *hsudc) |
1216 | { | 1214 | { |
@@ -1224,6 +1222,8 @@ static int s3c_hsudc_gadget_getframe(struct usb_gadget *gadget) | |||
1224 | 1222 | ||
1225 | static struct usb_gadget_ops s3c_hsudc_gadget_ops = { | 1223 | static struct usb_gadget_ops s3c_hsudc_gadget_ops = { |
1226 | .get_frame = s3c_hsudc_gadget_getframe, | 1224 | .get_frame = s3c_hsudc_gadget_getframe, |
1225 | .start = s3c_hsudc_start, | ||
1226 | .stop = s3c_hsudc_stop, | ||
1227 | }; | 1227 | }; |
1228 | 1228 | ||
1229 | static int s3c_hsudc_probe(struct platform_device *pdev) | 1229 | static int s3c_hsudc_probe(struct platform_device *pdev) |
@@ -1311,7 +1311,15 @@ static int s3c_hsudc_probe(struct platform_device *pdev) | |||
1311 | 1311 | ||
1312 | disable_irq(hsudc->irq); | 1312 | disable_irq(hsudc->irq); |
1313 | local_irq_enable(); | 1313 | local_irq_enable(); |
1314 | |||
1315 | ret = usb_add_gadget_udc(&pdev->dev, &hsudc->gadget); | ||
1316 | if (ret) | ||
1317 | goto err_add_udc; | ||
1318 | |||
1314 | return 0; | 1319 | return 0; |
1320 | err_add_udc: | ||
1321 | clk_disable(hsudc->uclk); | ||
1322 | clk_put(hsudc->uclk); | ||
1315 | err_clk: | 1323 | err_clk: |
1316 | free_irq(hsudc->irq, hsudc); | 1324 | free_irq(hsudc->irq, hsudc); |
1317 | err_irq: | 1325 | err_irq: |
@@ -1333,6 +1341,7 @@ static struct platform_driver s3c_hsudc_driver = { | |||
1333 | }, | 1341 | }, |
1334 | .probe = s3c_hsudc_probe, | 1342 | .probe = s3c_hsudc_probe, |
1335 | }; | 1343 | }; |
1344 | MODULE_ALIAS("platform:s3c-hsudc"); | ||
1336 | 1345 | ||
1337 | static int __init s3c_hsudc_modinit(void) | 1346 | static int __init s3c_hsudc_modinit(void) |
1338 | { | 1347 | { |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index 100f2635cf0a..85c1b0d66293 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -1552,6 +1552,10 @@ static int s3c2410_vbus_draw(struct usb_gadget *_gadget, unsigned ma) | |||
1552 | return -ENOTSUPP; | 1552 | return -ENOTSUPP; |
1553 | } | 1553 | } |
1554 | 1554 | ||
1555 | static int s3c2410_udc_start(struct usb_gadget_driver *driver, | ||
1556 | int (*bind)(struct usb_gadget *)); | ||
1557 | static int s3c2410_udc_stop(struct usb_gadget_driver *driver); | ||
1558 | |||
1555 | static const struct usb_gadget_ops s3c2410_ops = { | 1559 | static const struct usb_gadget_ops s3c2410_ops = { |
1556 | .get_frame = s3c2410_udc_get_frame, | 1560 | .get_frame = s3c2410_udc_get_frame, |
1557 | .wakeup = s3c2410_udc_wakeup, | 1561 | .wakeup = s3c2410_udc_wakeup, |
@@ -1559,6 +1563,8 @@ static const struct usb_gadget_ops s3c2410_ops = { | |||
1559 | .pullup = s3c2410_udc_pullup, | 1563 | .pullup = s3c2410_udc_pullup, |
1560 | .vbus_session = s3c2410_udc_vbus_session, | 1564 | .vbus_session = s3c2410_udc_vbus_session, |
1561 | .vbus_draw = s3c2410_vbus_draw, | 1565 | .vbus_draw = s3c2410_vbus_draw, |
1566 | .start = s3c2410_udc_start, | ||
1567 | .stop = s3c2410_udc_stop, | ||
1562 | }; | 1568 | }; |
1563 | 1569 | ||
1564 | static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd) | 1570 | static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd) |
@@ -1567,7 +1573,7 @@ static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd) | |||
1567 | return; | 1573 | return; |
1568 | 1574 | ||
1569 | if (udc_info->udc_command) { | 1575 | if (udc_info->udc_command) { |
1570 | udc_info->udc_command(S3C2410_UDC_P_DISABLE); | 1576 | udc_info->udc_command(cmd); |
1571 | } else if (gpio_is_valid(udc_info->pullup_pin)) { | 1577 | } else if (gpio_is_valid(udc_info->pullup_pin)) { |
1572 | int value; | 1578 | int value; |
1573 | 1579 | ||
@@ -1672,10 +1678,7 @@ static void s3c2410_udc_enable(struct s3c2410_udc *dev) | |||
1672 | s3c2410_udc_command(S3C2410_UDC_P_ENABLE); | 1678 | s3c2410_udc_command(S3C2410_UDC_P_ENABLE); |
1673 | } | 1679 | } |
1674 | 1680 | ||
1675 | /* | 1681 | static int s3c2410_udc_start(struct usb_gadget_driver *driver, |
1676 | * usb_gadget_probe_driver | ||
1677 | */ | ||
1678 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | ||
1679 | int (*bind)(struct usb_gadget *)) | 1682 | int (*bind)(struct usb_gadget *)) |
1680 | { | 1683 | { |
1681 | struct s3c2410_udc *udc = the_controller; | 1684 | struct s3c2410_udc *udc = the_controller; |
@@ -1730,12 +1733,8 @@ register_error: | |||
1730 | udc->gadget.dev.driver = NULL; | 1733 | udc->gadget.dev.driver = NULL; |
1731 | return retval; | 1734 | return retval; |
1732 | } | 1735 | } |
1733 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1734 | 1736 | ||
1735 | /* | 1737 | static int s3c2410_udc_stop(struct usb_gadget_driver *driver) |
1736 | * usb_gadget_unregister_driver | ||
1737 | */ | ||
1738 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | ||
1739 | { | 1738 | { |
1740 | struct s3c2410_udc *udc = the_controller; | 1739 | struct s3c2410_udc *udc = the_controller; |
1741 | 1740 | ||
@@ -1955,6 +1954,10 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1955 | goto err_vbus_irq; | 1954 | goto err_vbus_irq; |
1956 | } | 1955 | } |
1957 | 1956 | ||
1957 | retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | ||
1958 | if (retval) | ||
1959 | goto err_add_udc; | ||
1960 | |||
1958 | if (s3c2410_udc_debugfs_root) { | 1961 | if (s3c2410_udc_debugfs_root) { |
1959 | udc->regs_info = debugfs_create_file("registers", S_IRUGO, | 1962 | udc->regs_info = debugfs_create_file("registers", S_IRUGO, |
1960 | s3c2410_udc_debugfs_root, | 1963 | s3c2410_udc_debugfs_root, |
@@ -1967,6 +1970,10 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1967 | 1970 | ||
1968 | return 0; | 1971 | return 0; |
1969 | 1972 | ||
1973 | err_add_udc: | ||
1974 | if (udc_info && !udc_info->udc_command && | ||
1975 | gpio_is_valid(udc_info->pullup_pin)) | ||
1976 | gpio_free(udc_info->pullup_pin); | ||
1970 | err_vbus_irq: | 1977 | err_vbus_irq: |
1971 | if (udc_info && udc_info->vbus_pin > 0) | 1978 | if (udc_info && udc_info->vbus_pin > 0) |
1972 | free_irq(gpio_to_irq(udc_info->vbus_pin), udc); | 1979 | free_irq(gpio_to_irq(udc_info->vbus_pin), udc); |
@@ -1992,6 +1999,8 @@ static int s3c2410_udc_remove(struct platform_device *pdev) | |||
1992 | unsigned int irq; | 1999 | unsigned int irq; |
1993 | 2000 | ||
1994 | dev_dbg(&pdev->dev, "%s()\n", __func__); | 2001 | dev_dbg(&pdev->dev, "%s()\n", __func__); |
2002 | |||
2003 | usb_del_gadget_udc(&udc->gadget); | ||
1995 | if (udc->driver) | 2004 | if (udc->driver) |
1996 | return -EBUSY; | 2005 | return -EBUSY; |
1997 | 2006 | ||
@@ -2048,26 +2057,22 @@ static int s3c2410_udc_resume(struct platform_device *pdev) | |||
2048 | #define s3c2410_udc_resume NULL | 2057 | #define s3c2410_udc_resume NULL |
2049 | #endif | 2058 | #endif |
2050 | 2059 | ||
2051 | static struct platform_driver udc_driver_2410 = { | 2060 | static const struct platform_device_id s3c_udc_ids[] = { |
2052 | .driver = { | 2061 | { "s3c2410-usbgadget", }, |
2053 | .name = "s3c2410-usbgadget", | 2062 | { "s3c2440-usbgadget", }, |
2054 | .owner = THIS_MODULE, | ||
2055 | }, | ||
2056 | .probe = s3c2410_udc_probe, | ||
2057 | .remove = s3c2410_udc_remove, | ||
2058 | .suspend = s3c2410_udc_suspend, | ||
2059 | .resume = s3c2410_udc_resume, | ||
2060 | }; | 2063 | }; |
2064 | MODULE_DEVICE_TABLE(platform, s3c_udc_ids); | ||
2061 | 2065 | ||
2062 | static struct platform_driver udc_driver_2440 = { | 2066 | static struct platform_driver udc_driver_24x0 = { |
2063 | .driver = { | 2067 | .driver = { |
2064 | .name = "s3c2440-usbgadget", | 2068 | .name = "s3c24x0-usbgadget", |
2065 | .owner = THIS_MODULE, | 2069 | .owner = THIS_MODULE, |
2066 | }, | 2070 | }, |
2067 | .probe = s3c2410_udc_probe, | 2071 | .probe = s3c2410_udc_probe, |
2068 | .remove = s3c2410_udc_remove, | 2072 | .remove = s3c2410_udc_remove, |
2069 | .suspend = s3c2410_udc_suspend, | 2073 | .suspend = s3c2410_udc_suspend, |
2070 | .resume = s3c2410_udc_resume, | 2074 | .resume = s3c2410_udc_resume, |
2075 | .id_table = s3c_udc_ids, | ||
2071 | }; | 2076 | }; |
2072 | 2077 | ||
2073 | static int __init udc_init(void) | 2078 | static int __init udc_init(void) |
@@ -2083,11 +2088,7 @@ static int __init udc_init(void) | |||
2083 | s3c2410_udc_debugfs_root = NULL; | 2088 | s3c2410_udc_debugfs_root = NULL; |
2084 | } | 2089 | } |
2085 | 2090 | ||
2086 | retval = platform_driver_register(&udc_driver_2410); | 2091 | retval = platform_driver_register(&udc_driver_24x0); |
2087 | if (retval) | ||
2088 | goto err; | ||
2089 | |||
2090 | retval = platform_driver_register(&udc_driver_2440); | ||
2091 | if (retval) | 2092 | if (retval) |
2092 | goto err; | 2093 | goto err; |
2093 | 2094 | ||
@@ -2100,13 +2101,10 @@ err: | |||
2100 | 2101 | ||
2101 | static void __exit udc_exit(void) | 2102 | static void __exit udc_exit(void) |
2102 | { | 2103 | { |
2103 | platform_driver_unregister(&udc_driver_2410); | 2104 | platform_driver_unregister(&udc_driver_24x0); |
2104 | platform_driver_unregister(&udc_driver_2440); | ||
2105 | debugfs_remove(s3c2410_udc_debugfs_root); | 2105 | debugfs_remove(s3c2410_udc_debugfs_root); |
2106 | } | 2106 | } |
2107 | 2107 | ||
2108 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2109 | |||
2110 | module_init(udc_init); | 2108 | module_init(udc_init); |
2111 | module_exit(udc_exit); | 2109 | module_exit(udc_exit); |
2112 | 2110 | ||
@@ -2114,5 +2112,3 @@ MODULE_AUTHOR(DRIVER_AUTHOR); | |||
2114 | MODULE_DESCRIPTION(DRIVER_DESC); | 2112 | MODULE_DESCRIPTION(DRIVER_DESC); |
2115 | MODULE_VERSION(DRIVER_VERSION); | 2113 | MODULE_VERSION(DRIVER_VERSION); |
2116 | MODULE_LICENSE("GPL"); | 2114 | MODULE_LICENSE("GPL"); |
2117 | MODULE_ALIAS("platform:s3c2410-usbgadget"); | ||
2118 | MODULE_ALIAS("platform:s3c2440-usbgadget"); | ||
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index 1ac57a973aa9..ed1b816e58d8 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c | |||
@@ -242,6 +242,7 @@ static struct usb_composite_driver gserial_driver = { | |||
242 | .name = "g_serial", | 242 | .name = "g_serial", |
243 | .dev = &device_desc, | 243 | .dev = &device_desc, |
244 | .strings = dev_strings, | 244 | .strings = dev_strings, |
245 | .max_speed = USB_SPEED_HIGH, | ||
245 | }; | 246 | }; |
246 | 247 | ||
247 | static int __init init(void) | 248 | static int __init init(void) |
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 1fa4f705b0b4..d3dd227a2bfc 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c | |||
@@ -494,7 +494,7 @@ static struct usb_descriptor_header *fsg_hs_function[] = { | |||
494 | }; | 494 | }; |
495 | 495 | ||
496 | /* Maxpacket and other transfer characteristics vary by speed. */ | 496 | /* Maxpacket and other transfer characteristics vary by speed. */ |
497 | static struct usb_endpoint_descriptor * | 497 | static __maybe_unused struct usb_endpoint_descriptor * |
498 | fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, | 498 | fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, |
499 | struct usb_endpoint_descriptor *hs) | 499 | struct usb_endpoint_descriptor *hs) |
500 | { | 500 | { |
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index 2ac1d2147325..dfed4c1d96c0 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -97,16 +97,17 @@ struct eth_dev { | |||
97 | 97 | ||
98 | static unsigned qmult = 5; | 98 | static unsigned qmult = 5; |
99 | module_param(qmult, uint, S_IRUGO|S_IWUSR); | 99 | module_param(qmult, uint, S_IRUGO|S_IWUSR); |
100 | MODULE_PARM_DESC(qmult, "queue length multiplier at high speed"); | 100 | MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed"); |
101 | 101 | ||
102 | #else /* full speed (low speed doesn't do bulk) */ | 102 | #else /* full speed (low speed doesn't do bulk) */ |
103 | #define qmult 1 | 103 | #define qmult 1 |
104 | #endif | 104 | #endif |
105 | 105 | ||
106 | /* for dual-speed hardware, use deeper queues at highspeed */ | 106 | /* for dual-speed hardware, use deeper queues at high/super speed */ |
107 | static inline int qlen(struct usb_gadget *gadget) | 107 | static inline int qlen(struct usb_gadget *gadget) |
108 | { | 108 | { |
109 | if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH) | 109 | if (gadget_is_dualspeed(gadget) && (gadget->speed == USB_SPEED_HIGH || |
110 | gadget->speed == USB_SPEED_SUPER)) | ||
110 | return qmult * DEFAULT_QLEN; | 111 | return qmult * DEFAULT_QLEN; |
111 | else | 112 | else |
112 | return DEFAULT_QLEN; | 113 | return DEFAULT_QLEN; |
@@ -598,9 +599,10 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, | |||
598 | 599 | ||
599 | req->length = length; | 600 | req->length = length; |
600 | 601 | ||
601 | /* throttle highspeed IRQ rate back slightly */ | 602 | /* throttle high/super speed IRQ rate back slightly */ |
602 | if (gadget_is_dualspeed(dev->gadget)) | 603 | if (gadget_is_dualspeed(dev->gadget)) |
603 | req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH) | 604 | req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH || |
605 | dev->gadget->speed == USB_SPEED_SUPER) | ||
604 | ? ((atomic_read(&dev->tx_qlen) % qmult) != 0) | 606 | ? ((atomic_read(&dev->tx_qlen) % qmult) != 0) |
605 | : 0; | 607 | : 0; |
606 | 608 | ||
@@ -693,8 +695,8 @@ static int eth_stop(struct net_device *net) | |||
693 | usb_ep_disable(link->out_ep); | 695 | usb_ep_disable(link->out_ep); |
694 | if (netif_carrier_ok(net)) { | 696 | if (netif_carrier_ok(net)) { |
695 | DBG(dev, "host still using in/out endpoints\n"); | 697 | DBG(dev, "host still using in/out endpoints\n"); |
696 | usb_ep_enable(link->in_ep, link->in); | 698 | usb_ep_enable(link->in_ep); |
697 | usb_ep_enable(link->out_ep, link->out); | 699 | usb_ep_enable(link->out_ep); |
698 | } | 700 | } |
699 | } | 701 | } |
700 | spin_unlock_irqrestore(&dev->lock, flags); | 702 | spin_unlock_irqrestore(&dev->lock, flags); |
@@ -871,7 +873,7 @@ struct net_device *gether_connect(struct gether *link) | |||
871 | return ERR_PTR(-EINVAL); | 873 | return ERR_PTR(-EINVAL); |
872 | 874 | ||
873 | link->in_ep->driver_data = dev; | 875 | link->in_ep->driver_data = dev; |
874 | result = usb_ep_enable(link->in_ep, link->in); | 876 | result = usb_ep_enable(link->in_ep); |
875 | if (result != 0) { | 877 | if (result != 0) { |
876 | DBG(dev, "enable %s --> %d\n", | 878 | DBG(dev, "enable %s --> %d\n", |
877 | link->in_ep->name, result); | 879 | link->in_ep->name, result); |
@@ -879,7 +881,7 @@ struct net_device *gether_connect(struct gether *link) | |||
879 | } | 881 | } |
880 | 882 | ||
881 | link->out_ep->driver_data = dev; | 883 | link->out_ep->driver_data = dev; |
882 | result = usb_ep_enable(link->out_ep, link->out); | 884 | result = usb_ep_enable(link->out_ep); |
883 | if (result != 0) { | 885 | if (result != 0) { |
884 | DBG(dev, "enable %s --> %d\n", | 886 | DBG(dev, "enable %s --> %d\n", |
885 | link->out_ep->name, result); | 887 | link->out_ep->name, result); |
@@ -969,7 +971,7 @@ void gether_disconnect(struct gether *link) | |||
969 | } | 971 | } |
970 | spin_unlock(&dev->req_lock); | 972 | spin_unlock(&dev->req_lock); |
971 | link->in_ep->driver_data = NULL; | 973 | link->in_ep->driver_data = NULL; |
972 | link->in = NULL; | 974 | link->in_ep->desc = NULL; |
973 | 975 | ||
974 | usb_ep_disable(link->out_ep); | 976 | usb_ep_disable(link->out_ep); |
975 | spin_lock(&dev->req_lock); | 977 | spin_lock(&dev->req_lock); |
@@ -984,7 +986,7 @@ void gether_disconnect(struct gether *link) | |||
984 | } | 986 | } |
985 | spin_unlock(&dev->req_lock); | 987 | spin_unlock(&dev->req_lock); |
986 | link->out_ep->driver_data = NULL; | 988 | link->out_ep->driver_data = NULL; |
987 | link->out = NULL; | 989 | link->out_ep->desc = NULL; |
988 | 990 | ||
989 | /* finish forgetting about this USB link episode */ | 991 | /* finish forgetting about this USB link episode */ |
990 | dev->header_len = 0; | 992 | dev->header_len = 0; |
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index b56e1e7d423c..c966440ddd70 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h | |||
@@ -52,10 +52,6 @@ struct gether { | |||
52 | struct usb_ep *in_ep; | 52 | struct usb_ep *in_ep; |
53 | struct usb_ep *out_ep; | 53 | struct usb_ep *out_ep; |
54 | 54 | ||
55 | /* descriptors match device speed at gether_connect() time */ | ||
56 | struct usb_endpoint_descriptor *in; | ||
57 | struct usb_endpoint_descriptor *out; | ||
58 | |||
59 | bool is_zlp_ok; | 55 | bool is_zlp_ok; |
60 | 56 | ||
61 | u16 cdc_filter; | 57 | u16 cdc_filter; |
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c index 40f7716b31fc..a8aa46962d81 100644 --- a/drivers/usb/gadget/u_serial.c +++ b/drivers/usb/gadget/u_serial.c | |||
@@ -1247,12 +1247,12 @@ int gserial_connect(struct gserial *gser, u8 port_num) | |||
1247 | port = ports[port_num].port; | 1247 | port = ports[port_num].port; |
1248 | 1248 | ||
1249 | /* activate the endpoints */ | 1249 | /* activate the endpoints */ |
1250 | status = usb_ep_enable(gser->in, gser->in_desc); | 1250 | status = usb_ep_enable(gser->in); |
1251 | if (status < 0) | 1251 | if (status < 0) |
1252 | return status; | 1252 | return status; |
1253 | gser->in->driver_data = port; | 1253 | gser->in->driver_data = port; |
1254 | 1254 | ||
1255 | status = usb_ep_enable(gser->out, gser->out_desc); | 1255 | status = usb_ep_enable(gser->out); |
1256 | if (status < 0) | 1256 | if (status < 0) |
1257 | goto fail_out; | 1257 | goto fail_out; |
1258 | gser->out->driver_data = port; | 1258 | gser->out->driver_data = port; |
diff --git a/drivers/usb/gadget/u_serial.h b/drivers/usb/gadget/u_serial.h index 300f0ed9475d..9b0fe6450fbf 100644 --- a/drivers/usb/gadget/u_serial.h +++ b/drivers/usb/gadget/u_serial.h | |||
@@ -35,8 +35,6 @@ struct gserial { | |||
35 | 35 | ||
36 | struct usb_ep *in; | 36 | struct usb_ep *in; |
37 | struct usb_ep *out; | 37 | struct usb_ep *out; |
38 | struct usb_endpoint_descriptor *in_desc; | ||
39 | struct usb_endpoint_descriptor *out_desc; | ||
40 | 38 | ||
41 | /* REVISIT avoid this CDC-ACM support harder ... */ | 39 | /* REVISIT avoid this CDC-ACM support harder ... */ |
42 | struct usb_cdc_line_coding port_line_coding; /* 9600-8-N-1 etc */ | 40 | struct usb_cdc_line_coding port_line_coding; /* 9600-8-N-1 etc */ |
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c new file mode 100644 index 000000000000..05ba47214361 --- /dev/null +++ b/drivers/usb/gadget/udc-core.c | |||
@@ -0,0 +1,484 @@ | |||
1 | /** | ||
2 | * udc.c - Core UDC Framework | ||
3 | * | ||
4 | * Copyright (C) 2010 Texas Instruments | ||
5 | * Author: Felipe Balbi <balbi@ti.com> | ||
6 | * | ||
7 | * This program is free software: you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 of | ||
9 | * the License as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/device.h> | ||
23 | #include <linux/list.h> | ||
24 | #include <linux/err.h> | ||
25 | |||
26 | #include <linux/usb/ch9.h> | ||
27 | #include <linux/usb/gadget.h> | ||
28 | |||
29 | /** | ||
30 | * struct usb_udc - describes one usb device controller | ||
31 | * @driver - the gadget driver pointer. For use by the class code | ||
32 | * @dev - the child device to the actual controller | ||
33 | * @gadget - the gadget. For use by the class code | ||
34 | * @list - for use by the udc class driver | ||
35 | * | ||
36 | * This represents the internal data structure which is used by the UDC-class | ||
37 | * to hold information about udc driver and gadget together. | ||
38 | */ | ||
39 | struct usb_udc { | ||
40 | struct usb_gadget_driver *driver; | ||
41 | struct usb_gadget *gadget; | ||
42 | struct device dev; | ||
43 | struct list_head list; | ||
44 | }; | ||
45 | |||
46 | static struct class *udc_class; | ||
47 | static LIST_HEAD(udc_list); | ||
48 | static DEFINE_MUTEX(udc_lock); | ||
49 | |||
50 | /* ------------------------------------------------------------------------- */ | ||
51 | |||
52 | /** | ||
53 | * usb_gadget_start - tells usb device controller to start up | ||
54 | * @gadget: The gadget we want to get started | ||
55 | * @driver: The driver we want to bind to @gadget | ||
56 | * @bind: The bind function for @driver | ||
57 | * | ||
58 | * This call is issued by the UDC Class driver when it's about | ||
59 | * to register a gadget driver to the device controller, before | ||
60 | * calling gadget driver's bind() method. | ||
61 | * | ||
62 | * It allows the controller to be powered off until strictly | ||
63 | * necessary to have it powered on. | ||
64 | * | ||
65 | * Returns zero on success, else negative errno. | ||
66 | */ | ||
67 | static inline int usb_gadget_start(struct usb_gadget *gadget, | ||
68 | struct usb_gadget_driver *driver, | ||
69 | int (*bind)(struct usb_gadget *)) | ||
70 | { | ||
71 | return gadget->ops->start(driver, bind); | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * usb_gadget_udc_start - tells usb device controller to start up | ||
76 | * @gadget: The gadget we want to get started | ||
77 | * @driver: The driver we want to bind to @gadget | ||
78 | * | ||
79 | * This call is issued by the UDC Class driver when it's about | ||
80 | * to register a gadget driver to the device controller, before | ||
81 | * calling gadget driver's bind() method. | ||
82 | * | ||
83 | * It allows the controller to be powered off until strictly | ||
84 | * necessary to have it powered on. | ||
85 | * | ||
86 | * Returns zero on success, else negative errno. | ||
87 | */ | ||
88 | static inline int usb_gadget_udc_start(struct usb_gadget *gadget, | ||
89 | struct usb_gadget_driver *driver) | ||
90 | { | ||
91 | return gadget->ops->udc_start(gadget, driver); | ||
92 | } | ||
93 | |||
94 | /** | ||
95 | * usb_gadget_stop - tells usb device controller we don't need it anymore | ||
96 | * @gadget: The device we want to stop activity | ||
97 | * @driver: The driver to unbind from @gadget | ||
98 | * | ||
99 | * This call is issued by the UDC Class driver after calling | ||
100 | * gadget driver's unbind() method. | ||
101 | * | ||
102 | * The details are implementation specific, but it can go as | ||
103 | * far as powering off UDC completely and disable its data | ||
104 | * line pullups. | ||
105 | */ | ||
106 | static inline void usb_gadget_stop(struct usb_gadget *gadget, | ||
107 | struct usb_gadget_driver *driver) | ||
108 | { | ||
109 | gadget->ops->stop(driver); | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * usb_gadget_udc_stop - tells usb device controller we don't need it anymore | ||
114 | * @gadget: The device we want to stop activity | ||
115 | * @driver: The driver to unbind from @gadget | ||
116 | * | ||
117 | * This call is issued by the UDC Class driver after calling | ||
118 | * gadget driver's unbind() method. | ||
119 | * | ||
120 | * The details are implementation specific, but it can go as | ||
121 | * far as powering off UDC completely and disable its data | ||
122 | * line pullups. | ||
123 | */ | ||
124 | static inline void usb_gadget_udc_stop(struct usb_gadget *gadget, | ||
125 | struct usb_gadget_driver *driver) | ||
126 | { | ||
127 | gadget->ops->udc_stop(gadget, driver); | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * usb_udc_release - release the usb_udc struct | ||
132 | * @dev: the dev member within usb_udc | ||
133 | * | ||
134 | * This is called by driver's core in order to free memory once the last | ||
135 | * reference is released. | ||
136 | */ | ||
137 | static void usb_udc_release(struct device *dev) | ||
138 | { | ||
139 | struct usb_udc *udc; | ||
140 | |||
141 | udc = container_of(dev, struct usb_udc, dev); | ||
142 | dev_dbg(dev, "releasing '%s'\n", dev_name(dev)); | ||
143 | kfree(udc); | ||
144 | } | ||
145 | |||
146 | static const struct attribute_group *usb_udc_attr_groups[]; | ||
147 | /** | ||
148 | * usb_add_gadget_udc - adds a new gadget to the udc class driver list | ||
149 | * @parent: the parent device to this udc. Usually the controller | ||
150 | * driver's device. | ||
151 | * @gadget: the gadget to be added to the list | ||
152 | * | ||
153 | * Returns zero on success, negative errno otherwise. | ||
154 | */ | ||
155 | int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) | ||
156 | { | ||
157 | struct usb_udc *udc; | ||
158 | int ret = -ENOMEM; | ||
159 | |||
160 | udc = kzalloc(sizeof(*udc), GFP_KERNEL); | ||
161 | if (!udc) | ||
162 | goto err1; | ||
163 | |||
164 | device_initialize(&udc->dev); | ||
165 | udc->dev.release = usb_udc_release; | ||
166 | udc->dev.class = udc_class; | ||
167 | udc->dev.groups = usb_udc_attr_groups; | ||
168 | udc->dev.parent = parent; | ||
169 | ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); | ||
170 | if (ret) | ||
171 | goto err2; | ||
172 | |||
173 | udc->gadget = gadget; | ||
174 | |||
175 | mutex_lock(&udc_lock); | ||
176 | list_add_tail(&udc->list, &udc_list); | ||
177 | |||
178 | ret = device_add(&udc->dev); | ||
179 | if (ret) | ||
180 | goto err3; | ||
181 | |||
182 | mutex_unlock(&udc_lock); | ||
183 | |||
184 | return 0; | ||
185 | err3: | ||
186 | list_del(&udc->list); | ||
187 | mutex_unlock(&udc_lock); | ||
188 | |||
189 | err2: | ||
190 | put_device(&udc->dev); | ||
191 | |||
192 | err1: | ||
193 | return ret; | ||
194 | } | ||
195 | EXPORT_SYMBOL_GPL(usb_add_gadget_udc); | ||
196 | |||
197 | static int udc_is_newstyle(struct usb_udc *udc) | ||
198 | { | ||
199 | if (udc->gadget->ops->udc_start && udc->gadget->ops->udc_stop) | ||
200 | return 1; | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | |||
205 | static void usb_gadget_remove_driver(struct usb_udc *udc) | ||
206 | { | ||
207 | dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n", | ||
208 | udc->gadget->name); | ||
209 | |||
210 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); | ||
211 | |||
212 | if (udc_is_newstyle(udc)) { | ||
213 | usb_gadget_disconnect(udc->gadget); | ||
214 | udc->driver->unbind(udc->gadget); | ||
215 | usb_gadget_udc_stop(udc->gadget, udc->driver); | ||
216 | |||
217 | } else { | ||
218 | usb_gadget_stop(udc->gadget, udc->driver); | ||
219 | } | ||
220 | |||
221 | udc->driver = NULL; | ||
222 | udc->dev.driver = NULL; | ||
223 | } | ||
224 | |||
225 | /** | ||
226 | * usb_del_gadget_udc - deletes @udc from udc_list | ||
227 | * @gadget: the gadget to be removed. | ||
228 | * | ||
229 | * This, will call usb_gadget_unregister_driver() if | ||
230 | * the @udc is still busy. | ||
231 | */ | ||
232 | void usb_del_gadget_udc(struct usb_gadget *gadget) | ||
233 | { | ||
234 | struct usb_udc *udc = NULL; | ||
235 | |||
236 | mutex_lock(&udc_lock); | ||
237 | list_for_each_entry(udc, &udc_list, list) | ||
238 | if (udc->gadget == gadget) | ||
239 | goto found; | ||
240 | |||
241 | dev_err(gadget->dev.parent, "gadget not registered.\n"); | ||
242 | mutex_unlock(&udc_lock); | ||
243 | |||
244 | return; | ||
245 | |||
246 | found: | ||
247 | dev_vdbg(gadget->dev.parent, "unregistering gadget\n"); | ||
248 | |||
249 | list_del(&udc->list); | ||
250 | mutex_unlock(&udc_lock); | ||
251 | |||
252 | if (udc->driver) | ||
253 | usb_gadget_remove_driver(udc); | ||
254 | |||
255 | kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); | ||
256 | device_unregister(&udc->dev); | ||
257 | } | ||
258 | EXPORT_SYMBOL_GPL(usb_del_gadget_udc); | ||
259 | |||
260 | /* ------------------------------------------------------------------------- */ | ||
261 | |||
262 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | ||
263 | int (*bind)(struct usb_gadget *)) | ||
264 | { | ||
265 | struct usb_udc *udc = NULL; | ||
266 | int ret; | ||
267 | |||
268 | if (!driver || !bind || !driver->setup) | ||
269 | return -EINVAL; | ||
270 | |||
271 | mutex_lock(&udc_lock); | ||
272 | list_for_each_entry(udc, &udc_list, list) { | ||
273 | /* For now we take the first one */ | ||
274 | if (!udc->driver) | ||
275 | goto found; | ||
276 | } | ||
277 | |||
278 | pr_debug("couldn't find an available UDC\n"); | ||
279 | mutex_unlock(&udc_lock); | ||
280 | return -ENODEV; | ||
281 | |||
282 | found: | ||
283 | dev_dbg(&udc->dev, "registering UDC driver [%s]\n", | ||
284 | driver->function); | ||
285 | |||
286 | udc->driver = driver; | ||
287 | udc->dev.driver = &driver->driver; | ||
288 | |||
289 | if (udc_is_newstyle(udc)) { | ||
290 | ret = bind(udc->gadget); | ||
291 | if (ret) | ||
292 | goto err1; | ||
293 | ret = usb_gadget_udc_start(udc->gadget, driver); | ||
294 | if (ret) { | ||
295 | driver->unbind(udc->gadget); | ||
296 | goto err1; | ||
297 | } | ||
298 | usb_gadget_connect(udc->gadget); | ||
299 | } else { | ||
300 | |||
301 | ret = usb_gadget_start(udc->gadget, driver, bind); | ||
302 | if (ret) | ||
303 | goto err1; | ||
304 | |||
305 | } | ||
306 | |||
307 | kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); | ||
308 | mutex_unlock(&udc_lock); | ||
309 | return 0; | ||
310 | |||
311 | err1: | ||
312 | dev_err(&udc->dev, "failed to start %s: %d\n", | ||
313 | udc->driver->function, ret); | ||
314 | udc->driver = NULL; | ||
315 | udc->dev.driver = NULL; | ||
316 | mutex_unlock(&udc_lock); | ||
317 | return ret; | ||
318 | } | ||
319 | EXPORT_SYMBOL_GPL(usb_gadget_probe_driver); | ||
320 | |||
321 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | ||
322 | { | ||
323 | struct usb_udc *udc = NULL; | ||
324 | int ret = -ENODEV; | ||
325 | |||
326 | if (!driver || !driver->unbind) | ||
327 | return -EINVAL; | ||
328 | |||
329 | mutex_lock(&udc_lock); | ||
330 | list_for_each_entry(udc, &udc_list, list) | ||
331 | if (udc->driver == driver) { | ||
332 | usb_gadget_remove_driver(udc); | ||
333 | ret = 0; | ||
334 | break; | ||
335 | } | ||
336 | |||
337 | mutex_unlock(&udc_lock); | ||
338 | return ret; | ||
339 | } | ||
340 | EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver); | ||
341 | |||
342 | /* ------------------------------------------------------------------------- */ | ||
343 | |||
344 | static ssize_t usb_udc_srp_store(struct device *dev, | ||
345 | struct device_attribute *attr, const char *buf, size_t n) | ||
346 | { | ||
347 | struct usb_udc *udc = dev_get_drvdata(dev); | ||
348 | |||
349 | if (sysfs_streq(buf, "1")) | ||
350 | usb_gadget_wakeup(udc->gadget); | ||
351 | |||
352 | return n; | ||
353 | } | ||
354 | static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store); | ||
355 | |||
356 | static ssize_t usb_udc_softconn_store(struct device *dev, | ||
357 | struct device_attribute *attr, const char *buf, size_t n) | ||
358 | { | ||
359 | struct usb_udc *udc = dev_get_drvdata(dev); | ||
360 | |||
361 | if (sysfs_streq(buf, "connect")) { | ||
362 | usb_gadget_connect(udc->gadget); | ||
363 | } else if (sysfs_streq(buf, "disconnect")) { | ||
364 | usb_gadget_disconnect(udc->gadget); | ||
365 | } else { | ||
366 | dev_err(dev, "unsupported command '%s'\n", buf); | ||
367 | return -EINVAL; | ||
368 | } | ||
369 | |||
370 | return n; | ||
371 | } | ||
372 | static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); | ||
373 | |||
374 | static ssize_t usb_udc_speed_show(struct device *dev, | ||
375 | struct device_attribute *attr, char *buf) | ||
376 | { | ||
377 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); | ||
378 | struct usb_gadget *gadget = udc->gadget; | ||
379 | |||
380 | switch (gadget->speed) { | ||
381 | case USB_SPEED_LOW: | ||
382 | return snprintf(buf, PAGE_SIZE, "low-speed\n"); | ||
383 | case USB_SPEED_FULL: | ||
384 | return snprintf(buf, PAGE_SIZE, "full-speed\n"); | ||
385 | case USB_SPEED_HIGH: | ||
386 | return snprintf(buf, PAGE_SIZE, "high-speed\n"); | ||
387 | case USB_SPEED_WIRELESS: | ||
388 | return snprintf(buf, PAGE_SIZE, "wireless\n"); | ||
389 | case USB_SPEED_SUPER: | ||
390 | return snprintf(buf, PAGE_SIZE, "super-speed\n"); | ||
391 | case USB_SPEED_UNKNOWN: /* FALLTHROUGH */ | ||
392 | default: | ||
393 | return snprintf(buf, PAGE_SIZE, "UNKNOWN\n"); | ||
394 | } | ||
395 | } | ||
396 | static DEVICE_ATTR(speed, S_IRUSR, usb_udc_speed_show, NULL); | ||
397 | |||
398 | #define USB_UDC_ATTR(name) \ | ||
399 | ssize_t usb_udc_##name##_show(struct device *dev, \ | ||
400 | struct device_attribute *attr, char *buf) \ | ||
401 | { \ | ||
402 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ | ||
403 | struct usb_gadget *gadget = udc->gadget; \ | ||
404 | \ | ||
405 | return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \ | ||
406 | } \ | ||
407 | static DEVICE_ATTR(name, S_IRUSR, usb_udc_##name##_show, NULL) | ||
408 | |||
409 | static USB_UDC_ATTR(is_dualspeed); | ||
410 | static USB_UDC_ATTR(is_otg); | ||
411 | static USB_UDC_ATTR(is_a_peripheral); | ||
412 | static USB_UDC_ATTR(b_hnp_enable); | ||
413 | static USB_UDC_ATTR(a_hnp_support); | ||
414 | static USB_UDC_ATTR(a_alt_hnp_support); | ||
415 | |||
416 | static struct attribute *usb_udc_attrs[] = { | ||
417 | &dev_attr_srp.attr, | ||
418 | &dev_attr_soft_connect.attr, | ||
419 | &dev_attr_speed.attr, | ||
420 | |||
421 | &dev_attr_is_dualspeed.attr, | ||
422 | &dev_attr_is_otg.attr, | ||
423 | &dev_attr_is_a_peripheral.attr, | ||
424 | &dev_attr_b_hnp_enable.attr, | ||
425 | &dev_attr_a_hnp_support.attr, | ||
426 | &dev_attr_a_alt_hnp_support.attr, | ||
427 | NULL, | ||
428 | }; | ||
429 | |||
430 | static const struct attribute_group usb_udc_attr_group = { | ||
431 | .attrs = usb_udc_attrs, | ||
432 | }; | ||
433 | |||
434 | static const struct attribute_group *usb_udc_attr_groups[] = { | ||
435 | &usb_udc_attr_group, | ||
436 | NULL, | ||
437 | }; | ||
438 | |||
439 | static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env) | ||
440 | { | ||
441 | struct usb_udc *udc = container_of(dev, struct usb_udc, dev); | ||
442 | int ret; | ||
443 | |||
444 | ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name); | ||
445 | if (ret) { | ||
446 | dev_err(dev, "failed to add uevent USB_UDC_NAME\n"); | ||
447 | return ret; | ||
448 | } | ||
449 | |||
450 | if (udc->driver) { | ||
451 | ret = add_uevent_var(env, "USB_UDC_DRIVER=%s", | ||
452 | udc->driver->function); | ||
453 | if (ret) { | ||
454 | dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n"); | ||
455 | return ret; | ||
456 | } | ||
457 | } | ||
458 | |||
459 | return 0; | ||
460 | } | ||
461 | |||
462 | static int __init usb_udc_init(void) | ||
463 | { | ||
464 | udc_class = class_create(THIS_MODULE, "udc"); | ||
465 | if (IS_ERR(udc_class)) { | ||
466 | pr_err("failed to create udc class --> %ld\n", | ||
467 | PTR_ERR(udc_class)); | ||
468 | return PTR_ERR(udc_class); | ||
469 | } | ||
470 | |||
471 | udc_class->dev_uevent = usb_udc_uevent; | ||
472 | return 0; | ||
473 | } | ||
474 | subsys_initcall(usb_udc_init); | ||
475 | |||
476 | static void __exit usb_udc_exit(void) | ||
477 | { | ||
478 | class_destroy(udc_class); | ||
479 | } | ||
480 | module_exit(usb_udc_exit); | ||
481 | |||
482 | MODULE_DESCRIPTION("UDC Framework"); | ||
483 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); | ||
484 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c index a5a0fdb808c7..df6882de50bf 100644 --- a/drivers/usb/gadget/webcam.c +++ b/drivers/usb/gadget/webcam.c | |||
@@ -373,6 +373,7 @@ static struct usb_composite_driver webcam_driver = { | |||
373 | .name = "g_webcam", | 373 | .name = "g_webcam", |
374 | .dev = &webcam_device_descriptor, | 374 | .dev = &webcam_device_descriptor, |
375 | .strings = webcam_device_strings, | 375 | .strings = webcam_device_strings, |
376 | .max_speed = USB_SPEED_HIGH, | ||
376 | .unbind = webcam_unbind, | 377 | .unbind = webcam_unbind, |
377 | }; | 378 | }; |
378 | 379 | ||
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index 6d16db9d9d2d..00e2fd2d4791 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c | |||
@@ -340,6 +340,7 @@ static struct usb_composite_driver zero_driver = { | |||
340 | .name = "zero", | 340 | .name = "zero", |
341 | .dev = &device_desc, | 341 | .dev = &device_desc, |
342 | .strings = dev_strings, | 342 | .strings = dev_strings, |
343 | .max_speed = USB_SPEED_SUPER, | ||
343 | .unbind = zero_unbind, | 344 | .unbind = zero_unbind, |
344 | .suspend = zero_suspend, | 345 | .suspend = zero_suspend, |
345 | .resume = zero_resume, | 346 | .resume = zero_resume, |