diff options
Diffstat (limited to 'drivers/usb/gadget')
29 files changed, 4433 insertions, 451 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index acc95b2ac6f8..dd4cd5a51370 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -45,7 +45,7 @@ if USB_GADGET | |||
45 | 45 | ||
46 | config USB_GADGET_DEBUG | 46 | config USB_GADGET_DEBUG |
47 | boolean "Debugging messages (DEVELOPMENT)" | 47 | boolean "Debugging messages (DEVELOPMENT)" |
48 | depends on USB_GADGET && DEBUG_KERNEL | 48 | depends on DEBUG_KERNEL |
49 | help | 49 | help |
50 | Many controller and gadget drivers will print some debugging | 50 | Many controller and gadget drivers will print some debugging |
51 | messages if you use this option to ask for those messages. | 51 | messages if you use this option to ask for those messages. |
@@ -59,7 +59,7 @@ config USB_GADGET_DEBUG | |||
59 | 59 | ||
60 | config USB_GADGET_DEBUG_FILES | 60 | config USB_GADGET_DEBUG_FILES |
61 | boolean "Debugging information files (DEVELOPMENT)" | 61 | boolean "Debugging information files (DEVELOPMENT)" |
62 | depends on USB_GADGET && PROC_FS | 62 | depends on PROC_FS |
63 | help | 63 | help |
64 | Some of the drivers in the "gadget" framework can expose | 64 | Some of the drivers in the "gadget" framework can expose |
65 | debugging information in files such as /proc/driver/udc | 65 | debugging information in files such as /proc/driver/udc |
@@ -70,7 +70,7 @@ config USB_GADGET_DEBUG_FILES | |||
70 | 70 | ||
71 | config USB_GADGET_DEBUG_FS | 71 | config USB_GADGET_DEBUG_FS |
72 | boolean "Debugging information files in debugfs (DEVELOPMENT)" | 72 | boolean "Debugging information files in debugfs (DEVELOPMENT)" |
73 | depends on USB_GADGET && DEBUG_FS | 73 | depends on DEBUG_FS |
74 | help | 74 | help |
75 | Some of the drivers in the "gadget" framework can expose | 75 | Some of the drivers in the "gadget" framework can expose |
76 | debugging information in files under /sys/kernel/debug/. | 76 | debugging information in files under /sys/kernel/debug/. |
@@ -79,12 +79,36 @@ config USB_GADGET_DEBUG_FS | |||
79 | Enable these files by choosing "Y" here. If in doubt, or | 79 | Enable these files by choosing "Y" here. If in doubt, or |
80 | to conserve kernel memory, say "N". | 80 | to conserve kernel memory, say "N". |
81 | 81 | ||
82 | config USB_GADGET_VBUS_DRAW | ||
83 | int "Maximum VBUS Power usage (2-500 mA)" | ||
84 | range 2 500 | ||
85 | default 2 | ||
86 | help | ||
87 | Some devices need to draw power from USB when they are | ||
88 | configured, perhaps to operate circuitry or to recharge | ||
89 | batteries. This is in addition to any local power supply, | ||
90 | such as an AC adapter or batteries. | ||
91 | |||
92 | Enter the maximum power your device draws through USB, in | ||
93 | milliAmperes. The permitted range of values is 2 - 500 mA; | ||
94 | 0 mA would be legal, but can make some hosts misbehave. | ||
95 | |||
96 | This value will be used except for system-specific gadget | ||
97 | drivers that have more specific information. | ||
98 | |||
82 | config USB_GADGET_SELECTED | 99 | config USB_GADGET_SELECTED |
83 | boolean | 100 | boolean |
84 | 101 | ||
85 | # | 102 | # |
86 | # USB Peripheral Controller Support | 103 | # USB Peripheral Controller Support |
87 | # | 104 | # |
105 | # The order here is alphabetical, except that integrated controllers go | ||
106 | # before discrete ones so they will be the initial/default value: | ||
107 | # - integrated/SOC controllers first | ||
108 | # - licensed IP used in both SOC and discrete versions | ||
109 | # - discrete ones (including all PCI-only controllers) | ||
110 | # - debug/dummy gadget+hcd is last. | ||
111 | # | ||
88 | choice | 112 | choice |
89 | prompt "USB Peripheral Controller" | 113 | prompt "USB Peripheral Controller" |
90 | depends on USB_GADGET | 114 | depends on USB_GADGET |
@@ -94,26 +118,27 @@ choice | |||
94 | Many controller drivers are platform-specific; these | 118 | Many controller drivers are platform-specific; these |
95 | often need board-specific hooks. | 119 | often need board-specific hooks. |
96 | 120 | ||
97 | config USB_GADGET_AMD5536UDC | 121 | # |
98 | boolean "AMD5536 UDC" | 122 | # Integrated controllers |
99 | depends on PCI | 123 | # |
100 | select USB_GADGET_DUALSPEED | 124 | |
125 | config USB_GADGET_AT91 | ||
126 | boolean "Atmel AT91 USB Device Port" | ||
127 | depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 | ||
128 | select USB_GADGET_SELECTED | ||
101 | help | 129 | help |
102 | The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge. | 130 | Many Atmel AT91 processors (such as the AT91RM2000) have a |
103 | It is a USB Highspeed DMA capable USB device controller. Beside ep0 | 131 | full speed USB Device Port with support for five configurable |
104 | it provides 4 IN and 4 OUT endpoints (bulk or interrupt type). | 132 | endpoints (plus endpoint zero). |
105 | The UDC port supports OTG operation, and may be used as a host port | ||
106 | if it's not being used to implement peripheral or OTG roles. | ||
107 | 133 | ||
108 | Say "y" to link the driver statically, or "m" to build a | 134 | Say "y" to link the driver statically, or "m" to build a |
109 | dynamically linked module called "amd5536udc" and force all | 135 | dynamically linked module called "at91_udc" and force all |
110 | gadget drivers to also be dynamically linked. | 136 | gadget drivers to also be dynamically linked. |
111 | 137 | ||
112 | config USB_AMD5536UDC | 138 | config USB_AT91 |
113 | tristate | 139 | tristate |
114 | depends on USB_GADGET_AMD5536UDC | 140 | depends on USB_GADGET_AT91 |
115 | default USB_GADGET | 141 | default USB_GADGET |
116 | select USB_GADGET_SELECTED | ||
117 | 142 | ||
118 | config USB_GADGET_ATMEL_USBA | 143 | config USB_GADGET_ATMEL_USBA |
119 | boolean "Atmel USBA" | 144 | boolean "Atmel USBA" |
@@ -150,28 +175,50 @@ config USB_FSL_USB2 | |||
150 | default USB_GADGET | 175 | default USB_GADGET |
151 | select USB_GADGET_SELECTED | 176 | select USB_GADGET_SELECTED |
152 | 177 | ||
153 | config USB_GADGET_NET2280 | 178 | config USB_GADGET_LH7A40X |
154 | boolean "NetChip 228x" | 179 | boolean "LH7A40X" |
155 | depends on PCI | 180 | depends on ARCH_LH7A40X |
156 | select USB_GADGET_DUALSPEED | ||
157 | help | 181 | help |
158 | NetChip 2280 / 2282 is a PCI based USB peripheral controller which | 182 | This driver provides USB Device Controller driver for LH7A40x |
159 | supports both full and high speed USB 2.0 data transfers. | 183 | |
160 | 184 | config USB_LH7A40X | |
161 | It has six configurable endpoints, as well as endpoint zero | 185 | tristate |
162 | (for control transfers) and several endpoints with dedicated | 186 | depends on USB_GADGET_LH7A40X |
163 | functions. | 187 | default USB_GADGET |
188 | select USB_GADGET_SELECTED | ||
189 | |||
190 | config USB_GADGET_OMAP | ||
191 | boolean "OMAP USB Device Controller" | ||
192 | depends on ARCH_OMAP | ||
193 | select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG | ||
194 | help | ||
195 | Many Texas Instruments OMAP processors have flexible full | ||
196 | speed USB device controllers, with support for up to 30 | ||
197 | endpoints (plus endpoint zero). This driver supports the | ||
198 | controller in the OMAP 1611, and should work with controllers | ||
199 | in other OMAP processors too, given minor tweaks. | ||
164 | 200 | ||
165 | Say "y" to link the driver statically, or "m" to build a | 201 | Say "y" to link the driver statically, or "m" to build a |
166 | dynamically linked module called "net2280" and force all | 202 | dynamically linked module called "omap_udc" and force all |
167 | gadget drivers to also be dynamically linked. | 203 | gadget drivers to also be dynamically linked. |
168 | 204 | ||
169 | config USB_NET2280 | 205 | config USB_OMAP |
170 | tristate | 206 | tristate |
171 | depends on USB_GADGET_NET2280 | 207 | depends on USB_GADGET_OMAP |
172 | default USB_GADGET | 208 | default USB_GADGET |
173 | select USB_GADGET_SELECTED | 209 | select USB_GADGET_SELECTED |
174 | 210 | ||
211 | config USB_OTG | ||
212 | boolean "OTG Support" | ||
213 | depends on USB_GADGET_OMAP && ARCH_OMAP_OTG && USB_OHCI_HCD | ||
214 | help | ||
215 | The most notable feature of USB OTG is support for a | ||
216 | "Dual-Role" device, which can act as either a device | ||
217 | or a host. The initial role choice can be changed | ||
218 | later, when two dual-role devices talk to each other. | ||
219 | |||
220 | Select this only if your OMAP board has a Mini-AB connector. | ||
221 | |||
175 | config USB_GADGET_PXA25X | 222 | config USB_GADGET_PXA25X |
176 | boolean "PXA 25x or IXP 4xx" | 223 | boolean "PXA 25x or IXP 4xx" |
177 | depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX | 224 | depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX |
@@ -203,34 +250,6 @@ config USB_PXA25X_SMALL | |||
203 | default y if USB_ETH | 250 | default y if USB_ETH |
204 | default y if USB_G_SERIAL | 251 | default y if USB_G_SERIAL |
205 | 252 | ||
206 | config USB_GADGET_M66592 | ||
207 | boolean "Renesas M66592 USB Peripheral Controller" | ||
208 | select USB_GADGET_DUALSPEED | ||
209 | help | ||
210 | M66592 is a discrete USB peripheral controller chip that | ||
211 | supports both full and high speed USB 2.0 data transfers. | ||
212 | It has seven configurable endpoints, and endpoint zero. | ||
213 | |||
214 | Say "y" to link the driver statically, or "m" to build a | ||
215 | dynamically linked module called "m66592_udc" and force all | ||
216 | gadget drivers to also be dynamically linked. | ||
217 | |||
218 | config USB_M66592 | ||
219 | tristate | ||
220 | depends on USB_GADGET_M66592 | ||
221 | default USB_GADGET | ||
222 | select USB_GADGET_SELECTED | ||
223 | |||
224 | config SUPERH_BUILT_IN_M66592 | ||
225 | boolean "Enable SuperH built-in USB like the M66592" | ||
226 | depends on USB_GADGET_M66592 && CPU_SUBTYPE_SH7722 | ||
227 | help | ||
228 | SH7722 has USB like the M66592. | ||
229 | |||
230 | The transfer rate is very slow when use "Ethernet Gadget". | ||
231 | However, this problem is improved if change a value of | ||
232 | NET_IP_ALIGN to 4. | ||
233 | |||
234 | config USB_GADGET_PXA27X | 253 | config USB_GADGET_PXA27X |
235 | boolean "PXA 27x" | 254 | boolean "PXA 27x" |
236 | depends on ARCH_PXA && PXA27x | 255 | depends on ARCH_PXA && PXA27x |
@@ -251,40 +270,32 @@ config USB_PXA27X | |||
251 | default USB_GADGET | 270 | default USB_GADGET |
252 | select USB_GADGET_SELECTED | 271 | select USB_GADGET_SELECTED |
253 | 272 | ||
254 | config USB_GADGET_GOKU | 273 | config USB_GADGET_S3C2410 |
255 | boolean "Toshiba TC86C001 'Goku-S'" | 274 | boolean "S3C2410 USB Device Controller" |
256 | depends on PCI | 275 | depends on ARCH_S3C2410 |
257 | help | 276 | help |
258 | The Toshiba TC86C001 is a PCI device which includes controllers | 277 | Samsung's S3C2410 is an ARM-4 processor with an integrated |
259 | for full speed USB devices, IDE, I2C, SIO, plus a USB host (OHCI). | 278 | full speed USB 1.1 device controller. It has 4 configurable |
260 | 279 | endpoints, as well as endpoint zero (for control transfers). | |
261 | The device controller has three configurable (bulk or interrupt) | ||
262 | endpoints, plus endpoint zero (for control transfers). | ||
263 | 280 | ||
264 | Say "y" to link the driver statically, or "m" to build a | 281 | This driver has been tested on the S3C2410, S3C2412, and |
265 | dynamically linked module called "goku_udc" and to force all | 282 | S3C2440 processors. |
266 | gadget drivers to also be dynamically linked. | ||
267 | 283 | ||
268 | config USB_GOKU | 284 | config USB_S3C2410 |
269 | tristate | 285 | tristate |
270 | depends on USB_GADGET_GOKU | 286 | depends on USB_GADGET_S3C2410 |
271 | default USB_GADGET | 287 | default USB_GADGET |
272 | select USB_GADGET_SELECTED | 288 | select USB_GADGET_SELECTED |
273 | 289 | ||
290 | config USB_S3C2410_DEBUG | ||
291 | boolean "S3C2410 udc debug messages" | ||
292 | depends on USB_GADGET_S3C2410 | ||
274 | 293 | ||
275 | config USB_GADGET_LH7A40X | 294 | # |
276 | boolean "LH7A40X" | 295 | # Controllers available in both integrated and discrete versions |
277 | depends on ARCH_LH7A40X | 296 | # |
278 | help | ||
279 | This driver provides USB Device Controller driver for LH7A40x | ||
280 | |||
281 | config USB_LH7A40X | ||
282 | tristate | ||
283 | depends on USB_GADGET_LH7A40X | ||
284 | default USB_GADGET | ||
285 | select USB_GADGET_SELECTED | ||
286 | 297 | ||
287 | # built in ../musb along with host support | 298 | # musb builds in ../musb along with host support |
288 | config USB_GADGET_MUSB_HDRC | 299 | config USB_GADGET_MUSB_HDRC |
289 | boolean "Inventra HDRC USB Peripheral (TI, ...)" | 300 | boolean "Inventra HDRC USB Peripheral (TI, ...)" |
290 | depends on USB_MUSB_HDRC && (USB_MUSB_PERIPHERAL || USB_MUSB_OTG) | 301 | depends on USB_MUSB_HDRC && (USB_MUSB_PERIPHERAL || USB_MUSB_OTG) |
@@ -294,76 +305,124 @@ config USB_GADGET_MUSB_HDRC | |||
294 | This OTG-capable silicon IP is used in dual designs including | 305 | This OTG-capable silicon IP is used in dual designs including |
295 | the TI DaVinci, OMAP 243x, OMAP 343x, and TUSB 6010. | 306 | the TI DaVinci, OMAP 243x, OMAP 343x, and TUSB 6010. |
296 | 307 | ||
297 | config USB_GADGET_OMAP | 308 | config USB_GADGET_M66592 |
298 | boolean "OMAP USB Device Controller" | 309 | boolean "Renesas M66592 USB Peripheral Controller" |
299 | depends on ARCH_OMAP | 310 | select USB_GADGET_DUALSPEED |
300 | select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 | ||
301 | help | 311 | help |
302 | Many Texas Instruments OMAP processors have flexible full | 312 | M66592 is a discrete USB peripheral controller chip that |
303 | speed USB device controllers, with support for up to 30 | 313 | supports both full and high speed USB 2.0 data transfers. |
304 | endpoints (plus endpoint zero). This driver supports the | 314 | It has seven configurable endpoints, and endpoint zero. |
305 | controller in the OMAP 1611, and should work with controllers | ||
306 | in other OMAP processors too, given minor tweaks. | ||
307 | 315 | ||
308 | Say "y" to link the driver statically, or "m" to build a | 316 | Say "y" to link the driver statically, or "m" to build a |
309 | dynamically linked module called "omap_udc" and force all | 317 | dynamically linked module called "m66592_udc" and force all |
310 | gadget drivers to also be dynamically linked. | 318 | gadget drivers to also be dynamically linked. |
311 | 319 | ||
312 | config USB_OMAP | 320 | config USB_M66592 |
313 | tristate | 321 | tristate |
314 | depends on USB_GADGET_OMAP | 322 | depends on USB_GADGET_M66592 |
315 | default USB_GADGET | 323 | default USB_GADGET |
316 | select USB_GADGET_SELECTED | 324 | select USB_GADGET_SELECTED |
317 | 325 | ||
318 | config USB_OTG | 326 | config SUPERH_BUILT_IN_M66592 |
319 | boolean "OTG Support" | 327 | boolean "Enable SuperH built-in USB like the M66592" |
320 | depends on USB_GADGET_OMAP && ARCH_OMAP_OTG && USB_OHCI_HCD | 328 | depends on USB_GADGET_M66592 && CPU_SUBTYPE_SH7722 |
321 | help | 329 | help |
322 | The most notable feature of USB OTG is support for a | 330 | SH7722 has USB like the M66592. |
323 | "Dual-Role" device, which can act as either a device | ||
324 | or a host. The initial role choice can be changed | ||
325 | later, when two dual-role devices talk to each other. | ||
326 | 331 | ||
327 | Select this only if your OMAP board has a Mini-AB connector. | 332 | The transfer rate is very slow when use "Ethernet Gadget". |
333 | However, this problem is improved if change a value of | ||
334 | NET_IP_ALIGN to 4. | ||
328 | 335 | ||
329 | config USB_GADGET_S3C2410 | 336 | # |
330 | boolean "S3C2410 USB Device Controller" | 337 | # Controllers available only in discrete form (and all PCI controllers) |
331 | depends on ARCH_S3C2410 | 338 | # |
339 | |||
340 | config USB_GADGET_AMD5536UDC | ||
341 | boolean "AMD5536 UDC" | ||
342 | depends on PCI | ||
343 | select USB_GADGET_DUALSPEED | ||
332 | help | 344 | help |
333 | Samsung's S3C2410 is an ARM-4 processor with an integrated | 345 | The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge. |
334 | full speed USB 1.1 device controller. It has 4 configurable | 346 | It is a USB Highspeed DMA capable USB device controller. Beside ep0 |
335 | endpoints, as well as endpoint zero (for control transfers). | 347 | it provides 4 IN and 4 OUT endpoints (bulk or interrupt type). |
348 | The UDC port supports OTG operation, and may be used as a host port | ||
349 | if it's not being used to implement peripheral or OTG roles. | ||
336 | 350 | ||
337 | This driver has been tested on the S3C2410, S3C2412, and | 351 | Say "y" to link the driver statically, or "m" to build a |
338 | S3C2440 processors. | 352 | dynamically linked module called "amd5536udc" and force all |
353 | gadget drivers to also be dynamically linked. | ||
339 | 354 | ||
340 | config USB_S3C2410 | 355 | config USB_AMD5536UDC |
341 | tristate | 356 | tristate |
342 | depends on USB_GADGET_S3C2410 | 357 | depends on USB_GADGET_AMD5536UDC |
343 | default USB_GADGET | 358 | default USB_GADGET |
344 | select USB_GADGET_SELECTED | 359 | select USB_GADGET_SELECTED |
345 | 360 | ||
346 | config USB_S3C2410_DEBUG | 361 | config USB_GADGET_FSL_QE |
347 | boolean "S3C2410 udc debug messages" | 362 | boolean "Freescale QE/CPM USB Device Controller" |
348 | depends on USB_GADGET_S3C2410 | 363 | depends on FSL_SOC && (QUICC_ENGINE || CPM) |
364 | help | ||
365 | Some of Freescale PowerPC processors have a Full Speed | ||
366 | QE/CPM2 USB controller, which support device mode with 4 | ||
367 | programmable endpoints. This driver supports the | ||
368 | controller in the MPC8360 and MPC8272, and should work with | ||
369 | controllers having QE or CPM2, given minor tweaks. | ||
349 | 370 | ||
350 | config USB_GADGET_AT91 | 371 | Set CONFIG_USB_GADGET to "m" to build this driver as a |
351 | boolean "AT91 USB Device Port" | 372 | dynmically linked module called "fsl_qe_udc". |
352 | depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 | 373 | |
374 | config USB_FSL_QE | ||
375 | tristate | ||
376 | depends on USB_GADGET_FSL_QE | ||
377 | default USB_GADGET | ||
353 | select USB_GADGET_SELECTED | 378 | select USB_GADGET_SELECTED |
379 | |||
380 | config USB_GADGET_NET2280 | ||
381 | boolean "NetChip 228x" | ||
382 | depends on PCI | ||
383 | select USB_GADGET_DUALSPEED | ||
354 | help | 384 | help |
355 | Many Atmel AT91 processors (such as the AT91RM2000) have a | 385 | NetChip 2280 / 2282 is a PCI based USB peripheral controller which |
356 | full speed USB Device Port with support for five configurable | 386 | supports both full and high speed USB 2.0 data transfers. |
357 | endpoints (plus endpoint zero). | 387 | |
388 | It has six configurable endpoints, as well as endpoint zero | ||
389 | (for control transfers) and several endpoints with dedicated | ||
390 | functions. | ||
358 | 391 | ||
359 | Say "y" to link the driver statically, or "m" to build a | 392 | Say "y" to link the driver statically, or "m" to build a |
360 | dynamically linked module called "at91_udc" and force all | 393 | dynamically linked module called "net2280" and force all |
361 | gadget drivers to also be dynamically linked. | 394 | gadget drivers to also be dynamically linked. |
362 | 395 | ||
363 | config USB_AT91 | 396 | config USB_NET2280 |
364 | tristate | 397 | tristate |
365 | depends on USB_GADGET_AT91 | 398 | depends on USB_GADGET_NET2280 |
399 | default USB_GADGET | ||
400 | select USB_GADGET_SELECTED | ||
401 | |||
402 | config USB_GADGET_GOKU | ||
403 | boolean "Toshiba TC86C001 'Goku-S'" | ||
404 | depends on PCI | ||
405 | help | ||
406 | The Toshiba TC86C001 is a PCI device which includes controllers | ||
407 | for full speed USB devices, IDE, I2C, SIO, plus a USB host (OHCI). | ||
408 | |||
409 | The device controller has three configurable (bulk or interrupt) | ||
410 | endpoints, plus endpoint zero (for control transfers). | ||
411 | |||
412 | Say "y" to link the driver statically, or "m" to build a | ||
413 | dynamically linked module called "goku_udc" and to force all | ||
414 | gadget drivers to also be dynamically linked. | ||
415 | |||
416 | config USB_GOKU | ||
417 | tristate | ||
418 | depends on USB_GADGET_GOKU | ||
366 | default USB_GADGET | 419 | default USB_GADGET |
420 | select USB_GADGET_SELECTED | ||
421 | |||
422 | |||
423 | # | ||
424 | # LAST -- dummy/emulated controller | ||
425 | # | ||
367 | 426 | ||
368 | config USB_GADGET_DUMMY_HCD | 427 | config USB_GADGET_DUMMY_HCD |
369 | boolean "Dummy HCD (DEVELOPMENT)" | 428 | boolean "Dummy HCD (DEVELOPMENT)" |
@@ -553,19 +612,23 @@ config USB_FILE_STORAGE_TEST | |||
553 | normal operation. | 612 | normal operation. |
554 | 613 | ||
555 | config USB_G_SERIAL | 614 | config USB_G_SERIAL |
556 | tristate "Serial Gadget (with CDC ACM support)" | 615 | tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" |
557 | help | 616 | help |
558 | The Serial Gadget talks to the Linux-USB generic serial driver. | 617 | The Serial Gadget talks to the Linux-USB generic serial driver. |
559 | This driver supports a CDC-ACM module option, which can be used | 618 | This driver supports a CDC-ACM module option, which can be used |
560 | to interoperate with MS-Windows hosts or with the Linux-USB | 619 | to interoperate with MS-Windows hosts or with the Linux-USB |
561 | "cdc-acm" driver. | 620 | "cdc-acm" driver. |
562 | 621 | ||
622 | This driver also supports a CDC-OBEX option. You will need a | ||
623 | user space OBEX server talking to /dev/ttyGS*, since the kernel | ||
624 | itself doesn't implement the OBEX protocol. | ||
625 | |||
563 | Say "y" to link the driver statically, or "m" to build a | 626 | Say "y" to link the driver statically, or "m" to build a |
564 | dynamically linked module called "g_serial". | 627 | dynamically linked module called "g_serial". |
565 | 628 | ||
566 | For more information, see Documentation/usb/gadget_serial.txt | 629 | For more information, see Documentation/usb/gadget_serial.txt |
567 | which includes instructions and a "driver info file" needed to | 630 | which includes instructions and a "driver info file" needed to |
568 | make MS-Windows work with this driver. | 631 | make MS-Windows work with CDC ACM. |
569 | 632 | ||
570 | config USB_MIDI_GADGET | 633 | config USB_MIDI_GADGET |
571 | tristate "MIDI Gadget (EXPERIMENTAL)" | 634 | tristate "MIDI Gadget (EXPERIMENTAL)" |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index fcb5cb9094d9..bd4041b47dce 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -18,28 +18,20 @@ obj-$(CONFIG_USB_AT91) += at91_udc.o | |||
18 | obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o | 18 | obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o |
19 | obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o | 19 | obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o |
20 | obj-$(CONFIG_USB_M66592) += m66592-udc.o | 20 | obj-$(CONFIG_USB_M66592) += m66592-udc.o |
21 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o | ||
21 | 22 | ||
22 | # | 23 | # |
23 | # USB gadget drivers | 24 | # USB gadget drivers |
24 | # | 25 | # |
25 | C_UTILS = composite.o usbstring.o config.o epautoconf.o | 26 | g_zero-objs := zero.o |
26 | 27 | g_ether-objs := ether.o | |
27 | g_zero-objs := zero.o f_sourcesink.o f_loopback.o $(C_UTILS) | 28 | g_serial-objs := serial.o |
28 | g_ether-objs := ether.o u_ether.o f_subset.o f_ecm.o $(C_UTILS) | 29 | g_midi-objs := gmidi.o |
29 | g_serial-objs := serial.o u_serial.o f_acm.o f_serial.o $(C_UTILS) | ||
30 | g_midi-objs := gmidi.o usbstring.o config.o epautoconf.o | ||
31 | gadgetfs-objs := inode.o | 30 | gadgetfs-objs := inode.o |
32 | g_file_storage-objs := file_storage.o usbstring.o config.o \ | 31 | g_file_storage-objs := file_storage.o |
33 | epautoconf.o | 32 | g_printer-objs := printer.o |
34 | g_printer-objs := printer.o usbstring.o config.o \ | 33 | g_cdc-objs := cdc2.o |
35 | epautoconf.o | ||
36 | g_cdc-objs := cdc2.o u_ether.o f_ecm.o \ | ||
37 | u_serial.o f_acm.o $(C_UTILS) | ||
38 | 34 | ||
39 | ifeq ($(CONFIG_USB_ETH_RNDIS),y) | ||
40 | g_ether-objs += f_rndis.o rndis.o | ||
41 | endif | ||
42 | |||
43 | obj-$(CONFIG_USB_ZERO) += g_zero.o | 35 | obj-$(CONFIG_USB_ZERO) += g_zero.o |
44 | obj-$(CONFIG_USB_ETH) += g_ether.o | 36 | obj-$(CONFIG_USB_ETH) += g_ether.o |
45 | obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o | 37 | obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o |
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c index a39a4b940c33..5495b171cf29 100644 --- a/drivers/usb/gadget/cdc2.c +++ b/drivers/usb/gadget/cdc2.c | |||
@@ -43,6 +43,25 @@ | |||
43 | 43 | ||
44 | /*-------------------------------------------------------------------------*/ | 44 | /*-------------------------------------------------------------------------*/ |
45 | 45 | ||
46 | /* | ||
47 | * Kbuild is not very cooperative with respect to linking separately | ||
48 | * compiled library objects into one module. So for now we won't use | ||
49 | * separate compilation ... ensuring init/exit sections work to shrink | ||
50 | * the runtime footprint, and giving us at least some parts of what | ||
51 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
52 | */ | ||
53 | |||
54 | #include "composite.c" | ||
55 | #include "usbstring.c" | ||
56 | #include "config.c" | ||
57 | #include "epautoconf.c" | ||
58 | #include "u_serial.c" | ||
59 | #include "f_acm.c" | ||
60 | #include "f_ecm.c" | ||
61 | #include "u_ether.c" | ||
62 | |||
63 | /*-------------------------------------------------------------------------*/ | ||
64 | |||
46 | static struct usb_device_descriptor device_desc = { | 65 | static struct usb_device_descriptor device_desc = { |
47 | .bLength = sizeof device_desc, | 66 | .bLength = sizeof device_desc, |
48 | .bDescriptorType = USB_DT_DEVICE, | 67 | .bDescriptorType = USB_DT_DEVICE, |
@@ -136,7 +155,6 @@ static struct usb_configuration cdc_config_driver = { | |||
136 | .bConfigurationValue = 1, | 155 | .bConfigurationValue = 1, |
137 | /* .iConfiguration = DYNAMIC */ | 156 | /* .iConfiguration = DYNAMIC */ |
138 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 157 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
139 | .bMaxPower = 1, /* 2 mA, minimal */ | ||
140 | }; | 158 | }; |
141 | 159 | ||
142 | /*-------------------------------------------------------------------------*/ | 160 | /*-------------------------------------------------------------------------*/ |
@@ -148,7 +166,8 @@ static int __init cdc_bind(struct usb_composite_dev *cdev) | |||
148 | int status; | 166 | int status; |
149 | 167 | ||
150 | if (!can_support_ecm(cdev->gadget)) { | 168 | if (!can_support_ecm(cdev->gadget)) { |
151 | ERROR(cdev, "controller '%s' not usable\n", gadget->name); | 169 | dev_err(&gadget->dev, "controller '%s' not usable\n", |
170 | gadget->name); | ||
152 | return -EINVAL; | 171 | return -EINVAL; |
153 | } | 172 | } |
154 | 173 | ||
@@ -203,7 +222,8 @@ static int __init cdc_bind(struct usb_composite_dev *cdev) | |||
203 | if (status < 0) | 222 | if (status < 0) |
204 | goto fail1; | 223 | goto fail1; |
205 | 224 | ||
206 | INFO(cdev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC); | 225 | dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", |
226 | DRIVER_DESC); | ||
207 | 227 | ||
208 | return 0; | 228 | return 0; |
209 | 229 | ||
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 85c876c1f150..f2da0269e1b1 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -128,6 +128,70 @@ done: | |||
128 | } | 128 | } |
129 | 129 | ||
130 | /** | 130 | /** |
131 | * usb_function_deactivate - prevent function and gadget enumeration | ||
132 | * @function: the function that isn't yet ready to respond | ||
133 | * | ||
134 | * Blocks response of the gadget driver to host enumeration by | ||
135 | * preventing the data line pullup from being activated. This is | ||
136 | * normally called during @bind() processing to change from the | ||
137 | * initial "ready to respond" state, or when a required resource | ||
138 | * becomes available. | ||
139 | * | ||
140 | * For example, drivers that serve as a passthrough to a userspace | ||
141 | * daemon can block enumeration unless that daemon (such as an OBEX, | ||
142 | * MTP, or print server) is ready to handle host requests. | ||
143 | * | ||
144 | * Not all systems support software control of their USB peripheral | ||
145 | * data pullups. | ||
146 | * | ||
147 | * Returns zero on success, else negative errno. | ||
148 | */ | ||
149 | int usb_function_deactivate(struct usb_function *function) | ||
150 | { | ||
151 | struct usb_composite_dev *cdev = function->config->cdev; | ||
152 | int status = 0; | ||
153 | |||
154 | spin_lock(&cdev->lock); | ||
155 | |||
156 | if (cdev->deactivations == 0) | ||
157 | status = usb_gadget_disconnect(cdev->gadget); | ||
158 | if (status == 0) | ||
159 | cdev->deactivations++; | ||
160 | |||
161 | spin_unlock(&cdev->lock); | ||
162 | return status; | ||
163 | } | ||
164 | |||
165 | /** | ||
166 | * usb_function_activate - allow function and gadget enumeration | ||
167 | * @function: function on which usb_function_activate() was called | ||
168 | * | ||
169 | * Reverses effect of usb_function_deactivate(). If no more functions | ||
170 | * are delaying their activation, the gadget driver will respond to | ||
171 | * host enumeration procedures. | ||
172 | * | ||
173 | * Returns zero on success, else negative errno. | ||
174 | */ | ||
175 | int usb_function_activate(struct usb_function *function) | ||
176 | { | ||
177 | struct usb_composite_dev *cdev = function->config->cdev; | ||
178 | int status = 0; | ||
179 | |||
180 | spin_lock(&cdev->lock); | ||
181 | |||
182 | if (WARN_ON(cdev->deactivations == 0)) | ||
183 | status = -EINVAL; | ||
184 | else { | ||
185 | cdev->deactivations--; | ||
186 | if (cdev->deactivations == 0) | ||
187 | status = usb_gadget_connect(cdev->gadget); | ||
188 | } | ||
189 | |||
190 | spin_unlock(&cdev->lock); | ||
191 | return status; | ||
192 | } | ||
193 | |||
194 | /** | ||
131 | * usb_interface_id() - allocate an unused interface ID | 195 | * usb_interface_id() - allocate an unused interface ID |
132 | * @config: configuration associated with the interface | 196 | * @config: configuration associated with the interface |
133 | * @function: function handling the interface | 197 | * @function: function handling the interface |
@@ -181,7 +245,7 @@ static int config_buf(struct usb_configuration *config, | |||
181 | c->bConfigurationValue = config->bConfigurationValue; | 245 | c->bConfigurationValue = config->bConfigurationValue; |
182 | c->iConfiguration = config->iConfiguration; | 246 | c->iConfiguration = config->iConfiguration; |
183 | c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes; | 247 | c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes; |
184 | c->bMaxPower = config->bMaxPower; | 248 | c->bMaxPower = config->bMaxPower ? : (CONFIG_USB_GADGET_VBUS_DRAW / 2); |
185 | 249 | ||
186 | /* There may be e.g. OTG descriptors */ | 250 | /* There may be e.g. OTG descriptors */ |
187 | if (config->descriptors) { | 251 | if (config->descriptors) { |
@@ -368,7 +432,7 @@ static int set_config(struct usb_composite_dev *cdev, | |||
368 | } | 432 | } |
369 | 433 | ||
370 | /* when we return, be sure our power usage is valid */ | 434 | /* when we return, be sure our power usage is valid */ |
371 | power = 2 * c->bMaxPower; | 435 | power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW; |
372 | done: | 436 | done: |
373 | usb_gadget_vbus_draw(gadget, power); | 437 | usb_gadget_vbus_draw(gadget, power); |
374 | return result; | 438 | return result; |
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 7600a0c78753..9064696636ac 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -82,6 +82,7 @@ struct dummy_ep { | |||
82 | const struct usb_endpoint_descriptor *desc; | 82 | const struct usb_endpoint_descriptor *desc; |
83 | struct usb_ep ep; | 83 | struct usb_ep ep; |
84 | unsigned halted : 1; | 84 | unsigned halted : 1; |
85 | unsigned wedged : 1; | ||
85 | unsigned already_seen : 1; | 86 | unsigned already_seen : 1; |
86 | unsigned setup_stage : 1; | 87 | unsigned setup_stage : 1; |
87 | }; | 88 | }; |
@@ -436,6 +437,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
436 | /* at this point real hardware should be NAKing transfers | 437 | /* at this point real hardware should be NAKing transfers |
437 | * to that endpoint, until a buffer is queued to it. | 438 | * to that endpoint, until a buffer is queued to it. |
438 | */ | 439 | */ |
440 | ep->halted = ep->wedged = 0; | ||
439 | retval = 0; | 441 | retval = 0; |
440 | done: | 442 | done: |
441 | return retval; | 443 | return retval; |
@@ -597,7 +599,7 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req) | |||
597 | } | 599 | } |
598 | 600 | ||
599 | static int | 601 | static int |
600 | dummy_set_halt (struct usb_ep *_ep, int value) | 602 | dummy_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged) |
601 | { | 603 | { |
602 | struct dummy_ep *ep; | 604 | struct dummy_ep *ep; |
603 | struct dummy *dum; | 605 | struct dummy *dum; |
@@ -609,16 +611,32 @@ dummy_set_halt (struct usb_ep *_ep, int value) | |||
609 | if (!dum->driver) | 611 | if (!dum->driver) |
610 | return -ESHUTDOWN; | 612 | return -ESHUTDOWN; |
611 | if (!value) | 613 | if (!value) |
612 | ep->halted = 0; | 614 | ep->halted = ep->wedged = 0; |
613 | else if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) && | 615 | else if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) && |
614 | !list_empty (&ep->queue)) | 616 | !list_empty (&ep->queue)) |
615 | return -EAGAIN; | 617 | return -EAGAIN; |
616 | else | 618 | else { |
617 | ep->halted = 1; | 619 | ep->halted = 1; |
620 | if (wedged) | ||
621 | ep->wedged = 1; | ||
622 | } | ||
618 | /* FIXME clear emulated data toggle too */ | 623 | /* FIXME clear emulated data toggle too */ |
619 | return 0; | 624 | return 0; |
620 | } | 625 | } |
621 | 626 | ||
627 | static int | ||
628 | dummy_set_halt(struct usb_ep *_ep, int value) | ||
629 | { | ||
630 | return dummy_set_halt_and_wedge(_ep, value, 0); | ||
631 | } | ||
632 | |||
633 | static int dummy_set_wedge(struct usb_ep *_ep) | ||
634 | { | ||
635 | if (!_ep || _ep->name == ep0name) | ||
636 | return -EINVAL; | ||
637 | return dummy_set_halt_and_wedge(_ep, 1, 1); | ||
638 | } | ||
639 | |||
622 | static const struct usb_ep_ops dummy_ep_ops = { | 640 | static const struct usb_ep_ops dummy_ep_ops = { |
623 | .enable = dummy_enable, | 641 | .enable = dummy_enable, |
624 | .disable = dummy_disable, | 642 | .disable = dummy_disable, |
@@ -630,6 +648,7 @@ static const struct usb_ep_ops dummy_ep_ops = { | |||
630 | .dequeue = dummy_dequeue, | 648 | .dequeue = dummy_dequeue, |
631 | 649 | ||
632 | .set_halt = dummy_set_halt, | 650 | .set_halt = dummy_set_halt, |
651 | .set_wedge = dummy_set_wedge, | ||
633 | }; | 652 | }; |
634 | 653 | ||
635 | /*-------------------------------------------------------------------------*/ | 654 | /*-------------------------------------------------------------------------*/ |
@@ -760,7 +779,8 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver) | |||
760 | ep->ep.name = ep_name [i]; | 779 | ep->ep.name = ep_name [i]; |
761 | ep->ep.ops = &dummy_ep_ops; | 780 | ep->ep.ops = &dummy_ep_ops; |
762 | list_add_tail (&ep->ep.ep_list, &dum->gadget.ep_list); | 781 | list_add_tail (&ep->ep.ep_list, &dum->gadget.ep_list); |
763 | ep->halted = ep->already_seen = ep->setup_stage = 0; | 782 | ep->halted = ep->wedged = ep->already_seen = |
783 | ep->setup_stage = 0; | ||
764 | ep->ep.maxpacket = ~0; | 784 | ep->ep.maxpacket = ~0; |
765 | ep->last_io = jiffies; | 785 | ep->last_io = jiffies; |
766 | ep->gadget = &dum->gadget; | 786 | ep->gadget = &dum->gadget; |
@@ -1351,7 +1371,7 @@ restart: | |||
1351 | } else if (setup.bRequestType == Ep_Request) { | 1371 | } else if (setup.bRequestType == Ep_Request) { |
1352 | // endpoint halt | 1372 | // endpoint halt |
1353 | ep2 = find_endpoint (dum, w_index); | 1373 | ep2 = find_endpoint (dum, w_index); |
1354 | if (!ep2) { | 1374 | if (!ep2 || ep2->ep.name == ep0name) { |
1355 | value = -EOPNOTSUPP; | 1375 | value = -EOPNOTSUPP; |
1356 | break; | 1376 | break; |
1357 | } | 1377 | } |
@@ -1380,7 +1400,8 @@ restart: | |||
1380 | value = -EOPNOTSUPP; | 1400 | value = -EOPNOTSUPP; |
1381 | break; | 1401 | break; |
1382 | } | 1402 | } |
1383 | ep2->halted = 0; | 1403 | if (!ep2->wedged) |
1404 | ep2->halted = 0; | ||
1384 | value = 0; | 1405 | value = 0; |
1385 | status = 0; | 1406 | status = 0; |
1386 | } | 1407 | } |
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index bcac2e68660d..37252d0012a7 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -96,6 +96,28 @@ static inline bool has_rndis(void) | |||
96 | 96 | ||
97 | /*-------------------------------------------------------------------------*/ | 97 | /*-------------------------------------------------------------------------*/ |
98 | 98 | ||
99 | /* | ||
100 | * Kbuild is not very cooperative with respect to linking separately | ||
101 | * compiled library objects into one module. So for now we won't use | ||
102 | * separate compilation ... ensuring init/exit sections work to shrink | ||
103 | * the runtime footprint, and giving us at least some parts of what | ||
104 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
105 | */ | ||
106 | #include "composite.c" | ||
107 | #include "usbstring.c" | ||
108 | #include "config.c" | ||
109 | #include "epautoconf.c" | ||
110 | |||
111 | #include "f_ecm.c" | ||
112 | #include "f_subset.c" | ||
113 | #ifdef CONFIG_USB_ETH_RNDIS | ||
114 | #include "f_rndis.c" | ||
115 | #include "rndis.c" | ||
116 | #endif | ||
117 | #include "u_ether.c" | ||
118 | |||
119 | /*-------------------------------------------------------------------------*/ | ||
120 | |||
99 | /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! | 121 | /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! |
100 | * Instead: allocate your own, using normal USB-IF procedures. | 122 | * Instead: allocate your own, using normal USB-IF procedures. |
101 | */ | 123 | */ |
@@ -220,7 +242,6 @@ static struct usb_configuration rndis_config_driver = { | |||
220 | .bConfigurationValue = 2, | 242 | .bConfigurationValue = 2, |
221 | /* .iConfiguration = DYNAMIC */ | 243 | /* .iConfiguration = DYNAMIC */ |
222 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 244 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
223 | .bMaxPower = 1, /* 2 mA, minimal */ | ||
224 | }; | 245 | }; |
225 | 246 | ||
226 | /*-------------------------------------------------------------------------*/ | 247 | /*-------------------------------------------------------------------------*/ |
@@ -249,7 +270,6 @@ static struct usb_configuration eth_config_driver = { | |||
249 | .bConfigurationValue = 1, | 270 | .bConfigurationValue = 1, |
250 | /* .iConfiguration = DYNAMIC */ | 271 | /* .iConfiguration = DYNAMIC */ |
251 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 272 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
252 | .bMaxPower = 1, /* 2 mA, minimal */ | ||
253 | }; | 273 | }; |
254 | 274 | ||
255 | /*-------------------------------------------------------------------------*/ | 275 | /*-------------------------------------------------------------------------*/ |
@@ -293,7 +313,8 @@ static int __init eth_bind(struct usb_composite_dev *cdev) | |||
293 | * but if the controller isn't recognized at all then | 313 | * but if the controller isn't recognized at all then |
294 | * that assumption is a bit more likely to be wrong. | 314 | * that assumption is a bit more likely to be wrong. |
295 | */ | 315 | */ |
296 | WARNING(cdev, "controller '%s' not recognized; trying %s\n", | 316 | dev_warn(&gadget->dev, |
317 | "controller '%s' not recognized; trying %s\n", | ||
297 | gadget->name, | 318 | gadget->name, |
298 | eth_config_driver.label); | 319 | eth_config_driver.label); |
299 | device_desc.bcdDevice = | 320 | device_desc.bcdDevice = |
@@ -332,7 +353,8 @@ static int __init eth_bind(struct usb_composite_dev *cdev) | |||
332 | if (status < 0) | 353 | if (status < 0) |
333 | goto fail; | 354 | goto fail; |
334 | 355 | ||
335 | INFO(cdev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC); | 356 | dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", |
357 | DRIVER_DESC); | ||
336 | 358 | ||
337 | return 0; | 359 | return 0; |
338 | 360 | ||
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c index a2b5c092bda0..4ae579948e54 100644 --- a/drivers/usb/gadget/f_ecm.c +++ b/drivers/usb/gadget/f_ecm.c | |||
@@ -83,7 +83,7 @@ static inline struct f_ecm *func_to_ecm(struct usb_function *f) | |||
83 | } | 83 | } |
84 | 84 | ||
85 | /* peak (theoretical) bulk transfer rate in bits-per-second */ | 85 | /* peak (theoretical) bulk transfer rate in bits-per-second */ |
86 | static inline unsigned bitrate(struct usb_gadget *g) | 86 | static inline unsigned ecm_bitrate(struct usb_gadget *g) |
87 | { | 87 | { |
88 | if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) | 88 | if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) |
89 | return 13 * 512 * 8 * 1000 * 8; | 89 | return 13 * 512 * 8 * 1000 * 8; |
@@ -107,7 +107,7 @@ static inline unsigned bitrate(struct usb_gadget *g) | |||
107 | */ | 107 | */ |
108 | 108 | ||
109 | #define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */ | 109 | #define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */ |
110 | #define STATUS_BYTECOUNT 16 /* 8 byte header + data */ | 110 | #define ECM_STATUS_BYTECOUNT 16 /* 8 byte header + data */ |
111 | 111 | ||
112 | 112 | ||
113 | /* interface descriptor: */ | 113 | /* interface descriptor: */ |
@@ -125,8 +125,8 @@ static struct usb_interface_descriptor ecm_control_intf __initdata = { | |||
125 | /* .iInterface = DYNAMIC */ | 125 | /* .iInterface = DYNAMIC */ |
126 | }; | 126 | }; |
127 | 127 | ||
128 | static struct usb_cdc_header_desc header_desc __initdata = { | 128 | static struct usb_cdc_header_desc ecm_header_desc __initdata = { |
129 | .bLength = sizeof header_desc, | 129 | .bLength = sizeof ecm_header_desc, |
130 | .bDescriptorType = USB_DT_CS_INTERFACE, | 130 | .bDescriptorType = USB_DT_CS_INTERFACE, |
131 | .bDescriptorSubType = USB_CDC_HEADER_TYPE, | 131 | .bDescriptorSubType = USB_CDC_HEADER_TYPE, |
132 | 132 | ||
@@ -141,8 +141,8 @@ static struct usb_cdc_union_desc ecm_union_desc __initdata = { | |||
141 | /* .bSlaveInterface0 = DYNAMIC */ | 141 | /* .bSlaveInterface0 = DYNAMIC */ |
142 | }; | 142 | }; |
143 | 143 | ||
144 | static struct usb_cdc_ether_desc ether_desc __initdata = { | 144 | static struct usb_cdc_ether_desc ecm_desc __initdata = { |
145 | .bLength = sizeof ether_desc, | 145 | .bLength = sizeof ecm_desc, |
146 | .bDescriptorType = USB_DT_CS_INTERFACE, | 146 | .bDescriptorType = USB_DT_CS_INTERFACE, |
147 | .bDescriptorSubType = USB_CDC_ETHERNET_TYPE, | 147 | .bDescriptorSubType = USB_CDC_ETHERNET_TYPE, |
148 | 148 | ||
@@ -186,17 +186,17 @@ static struct usb_interface_descriptor ecm_data_intf __initdata = { | |||
186 | 186 | ||
187 | /* full speed support: */ | 187 | /* full speed support: */ |
188 | 188 | ||
189 | static struct usb_endpoint_descriptor fs_notify_desc __initdata = { | 189 | static struct usb_endpoint_descriptor fs_ecm_notify_desc __initdata = { |
190 | .bLength = USB_DT_ENDPOINT_SIZE, | 190 | .bLength = USB_DT_ENDPOINT_SIZE, |
191 | .bDescriptorType = USB_DT_ENDPOINT, | 191 | .bDescriptorType = USB_DT_ENDPOINT, |
192 | 192 | ||
193 | .bEndpointAddress = USB_DIR_IN, | 193 | .bEndpointAddress = USB_DIR_IN, |
194 | .bmAttributes = USB_ENDPOINT_XFER_INT, | 194 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
195 | .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), | 195 | .wMaxPacketSize = __constant_cpu_to_le16(ECM_STATUS_BYTECOUNT), |
196 | .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, | 196 | .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, |
197 | }; | 197 | }; |
198 | 198 | ||
199 | static struct usb_endpoint_descriptor fs_in_desc __initdata = { | 199 | static struct usb_endpoint_descriptor fs_ecm_in_desc __initdata = { |
200 | .bLength = USB_DT_ENDPOINT_SIZE, | 200 | .bLength = USB_DT_ENDPOINT_SIZE, |
201 | .bDescriptorType = USB_DT_ENDPOINT, | 201 | .bDescriptorType = USB_DT_ENDPOINT, |
202 | 202 | ||
@@ -204,7 +204,7 @@ static struct usb_endpoint_descriptor fs_in_desc __initdata = { | |||
204 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 204 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
205 | }; | 205 | }; |
206 | 206 | ||
207 | static struct usb_endpoint_descriptor fs_out_desc __initdata = { | 207 | static struct usb_endpoint_descriptor fs_ecm_out_desc __initdata = { |
208 | .bLength = USB_DT_ENDPOINT_SIZE, | 208 | .bLength = USB_DT_ENDPOINT_SIZE, |
209 | .bDescriptorType = USB_DT_ENDPOINT, | 209 | .bDescriptorType = USB_DT_ENDPOINT, |
210 | 210 | ||
@@ -212,34 +212,34 @@ static struct usb_endpoint_descriptor fs_out_desc __initdata = { | |||
212 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 212 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
213 | }; | 213 | }; |
214 | 214 | ||
215 | static struct usb_descriptor_header *eth_fs_function[] __initdata = { | 215 | static struct usb_descriptor_header *ecm_fs_function[] __initdata = { |
216 | /* CDC ECM control descriptors */ | 216 | /* CDC ECM control descriptors */ |
217 | (struct usb_descriptor_header *) &ecm_control_intf, | 217 | (struct usb_descriptor_header *) &ecm_control_intf, |
218 | (struct usb_descriptor_header *) &header_desc, | 218 | (struct usb_descriptor_header *) &ecm_header_desc, |
219 | (struct usb_descriptor_header *) &ecm_union_desc, | 219 | (struct usb_descriptor_header *) &ecm_union_desc, |
220 | (struct usb_descriptor_header *) ðer_desc, | 220 | (struct usb_descriptor_header *) &ecm_desc, |
221 | /* NOTE: status endpoint might need to be removed */ | 221 | /* NOTE: status endpoint might need to be removed */ |
222 | (struct usb_descriptor_header *) &fs_notify_desc, | 222 | (struct usb_descriptor_header *) &fs_ecm_notify_desc, |
223 | /* data interface, altsettings 0 and 1 */ | 223 | /* data interface, altsettings 0 and 1 */ |
224 | (struct usb_descriptor_header *) &ecm_data_nop_intf, | 224 | (struct usb_descriptor_header *) &ecm_data_nop_intf, |
225 | (struct usb_descriptor_header *) &ecm_data_intf, | 225 | (struct usb_descriptor_header *) &ecm_data_intf, |
226 | (struct usb_descriptor_header *) &fs_in_desc, | 226 | (struct usb_descriptor_header *) &fs_ecm_in_desc, |
227 | (struct usb_descriptor_header *) &fs_out_desc, | 227 | (struct usb_descriptor_header *) &fs_ecm_out_desc, |
228 | NULL, | 228 | NULL, |
229 | }; | 229 | }; |
230 | 230 | ||
231 | /* high speed support: */ | 231 | /* high speed support: */ |
232 | 232 | ||
233 | static struct usb_endpoint_descriptor hs_notify_desc __initdata = { | 233 | static struct usb_endpoint_descriptor hs_ecm_notify_desc __initdata = { |
234 | .bLength = USB_DT_ENDPOINT_SIZE, | 234 | .bLength = USB_DT_ENDPOINT_SIZE, |
235 | .bDescriptorType = USB_DT_ENDPOINT, | 235 | .bDescriptorType = USB_DT_ENDPOINT, |
236 | 236 | ||
237 | .bEndpointAddress = USB_DIR_IN, | 237 | .bEndpointAddress = USB_DIR_IN, |
238 | .bmAttributes = USB_ENDPOINT_XFER_INT, | 238 | .bmAttributes = USB_ENDPOINT_XFER_INT, |
239 | .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), | 239 | .wMaxPacketSize = __constant_cpu_to_le16(ECM_STATUS_BYTECOUNT), |
240 | .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, | 240 | .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, |
241 | }; | 241 | }; |
242 | static struct usb_endpoint_descriptor hs_in_desc __initdata = { | 242 | static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = { |
243 | .bLength = USB_DT_ENDPOINT_SIZE, | 243 | .bLength = USB_DT_ENDPOINT_SIZE, |
244 | .bDescriptorType = USB_DT_ENDPOINT, | 244 | .bDescriptorType = USB_DT_ENDPOINT, |
245 | 245 | ||
@@ -248,7 +248,7 @@ static struct usb_endpoint_descriptor hs_in_desc __initdata = { | |||
248 | .wMaxPacketSize = __constant_cpu_to_le16(512), | 248 | .wMaxPacketSize = __constant_cpu_to_le16(512), |
249 | }; | 249 | }; |
250 | 250 | ||
251 | static struct usb_endpoint_descriptor hs_out_desc __initdata = { | 251 | static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = { |
252 | .bLength = USB_DT_ENDPOINT_SIZE, | 252 | .bLength = USB_DT_ENDPOINT_SIZE, |
253 | .bDescriptorType = USB_DT_ENDPOINT, | 253 | .bDescriptorType = USB_DT_ENDPOINT, |
254 | 254 | ||
@@ -257,19 +257,19 @@ static struct usb_endpoint_descriptor hs_out_desc __initdata = { | |||
257 | .wMaxPacketSize = __constant_cpu_to_le16(512), | 257 | .wMaxPacketSize = __constant_cpu_to_le16(512), |
258 | }; | 258 | }; |
259 | 259 | ||
260 | static struct usb_descriptor_header *eth_hs_function[] __initdata = { | 260 | static struct usb_descriptor_header *ecm_hs_function[] __initdata = { |
261 | /* CDC ECM control descriptors */ | 261 | /* CDC ECM control descriptors */ |
262 | (struct usb_descriptor_header *) &ecm_control_intf, | 262 | (struct usb_descriptor_header *) &ecm_control_intf, |
263 | (struct usb_descriptor_header *) &header_desc, | 263 | (struct usb_descriptor_header *) &ecm_header_desc, |
264 | (struct usb_descriptor_header *) &ecm_union_desc, | 264 | (struct usb_descriptor_header *) &ecm_union_desc, |
265 | (struct usb_descriptor_header *) ðer_desc, | 265 | (struct usb_descriptor_header *) &ecm_desc, |
266 | /* NOTE: status endpoint might need to be removed */ | 266 | /* NOTE: status endpoint might need to be removed */ |
267 | (struct usb_descriptor_header *) &hs_notify_desc, | 267 | (struct usb_descriptor_header *) &hs_ecm_notify_desc, |
268 | /* data interface, altsettings 0 and 1 */ | 268 | /* data interface, altsettings 0 and 1 */ |
269 | (struct usb_descriptor_header *) &ecm_data_nop_intf, | 269 | (struct usb_descriptor_header *) &ecm_data_nop_intf, |
270 | (struct usb_descriptor_header *) &ecm_data_intf, | 270 | (struct usb_descriptor_header *) &ecm_data_intf, |
271 | (struct usb_descriptor_header *) &hs_in_desc, | 271 | (struct usb_descriptor_header *) &hs_ecm_in_desc, |
272 | (struct usb_descriptor_header *) &hs_out_desc, | 272 | (struct usb_descriptor_header *) &hs_ecm_out_desc, |
273 | NULL, | 273 | NULL, |
274 | }; | 274 | }; |
275 | 275 | ||
@@ -329,14 +329,14 @@ static void ecm_do_notify(struct f_ecm *ecm) | |||
329 | event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE; | 329 | event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE; |
330 | event->wValue = cpu_to_le16(0); | 330 | event->wValue = cpu_to_le16(0); |
331 | event->wLength = cpu_to_le16(8); | 331 | event->wLength = cpu_to_le16(8); |
332 | req->length = STATUS_BYTECOUNT; | 332 | req->length = ECM_STATUS_BYTECOUNT; |
333 | 333 | ||
334 | /* SPEED_CHANGE data is up/down speeds in bits/sec */ | 334 | /* SPEED_CHANGE data is up/down speeds in bits/sec */ |
335 | data = req->buf + sizeof *event; | 335 | data = req->buf + sizeof *event; |
336 | data[0] = cpu_to_le32(bitrate(cdev->gadget)); | 336 | data[0] = cpu_to_le32(ecm_bitrate(cdev->gadget)); |
337 | data[1] = data[0]; | 337 | data[1] = data[0]; |
338 | 338 | ||
339 | DBG(cdev, "notify speed %d\n", bitrate(cdev->gadget)); | 339 | DBG(cdev, "notify speed %d\n", ecm_bitrate(cdev->gadget)); |
340 | ecm->notify_state = ECM_NOTIFY_NONE; | 340 | ecm->notify_state = ECM_NOTIFY_NONE; |
341 | break; | 341 | break; |
342 | } | 342 | } |
@@ -628,13 +628,13 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
628 | status = -ENODEV; | 628 | status = -ENODEV; |
629 | 629 | ||
630 | /* allocate instance-specific endpoints */ | 630 | /* allocate instance-specific endpoints */ |
631 | ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc); | 631 | ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_in_desc); |
632 | if (!ep) | 632 | if (!ep) |
633 | goto fail; | 633 | goto fail; |
634 | ecm->port.in_ep = ep; | 634 | ecm->port.in_ep = ep; |
635 | ep->driver_data = cdev; /* claim */ | 635 | ep->driver_data = cdev; /* claim */ |
636 | 636 | ||
637 | ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc); | 637 | ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_out_desc); |
638 | if (!ep) | 638 | if (!ep) |
639 | goto fail; | 639 | goto fail; |
640 | ecm->port.out_ep = ep; | 640 | ecm->port.out_ep = ep; |
@@ -644,7 +644,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
644 | * don't treat it that way. It's simpler, and some newer CDC | 644 | * don't treat it that way. It's simpler, and some newer CDC |
645 | * profiles (wireless handsets) no longer treat it as optional. | 645 | * profiles (wireless handsets) no longer treat it as optional. |
646 | */ | 646 | */ |
647 | ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc); | 647 | ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_notify_desc); |
648 | if (!ep) | 648 | if (!ep) |
649 | goto fail; | 649 | goto fail; |
650 | ecm->notify = ep; | 650 | ecm->notify = ep; |
@@ -656,47 +656,47 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) | |||
656 | ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); | 656 | ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); |
657 | if (!ecm->notify_req) | 657 | if (!ecm->notify_req) |
658 | goto fail; | 658 | goto fail; |
659 | ecm->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL); | 659 | ecm->notify_req->buf = kmalloc(ECM_STATUS_BYTECOUNT, GFP_KERNEL); |
660 | if (!ecm->notify_req->buf) | 660 | if (!ecm->notify_req->buf) |
661 | goto fail; | 661 | goto fail; |
662 | ecm->notify_req->context = ecm; | 662 | ecm->notify_req->context = ecm; |
663 | ecm->notify_req->complete = ecm_notify_complete; | 663 | ecm->notify_req->complete = ecm_notify_complete; |
664 | 664 | ||
665 | /* copy descriptors, and track endpoint copies */ | 665 | /* copy descriptors, and track endpoint copies */ |
666 | f->descriptors = usb_copy_descriptors(eth_fs_function); | 666 | f->descriptors = usb_copy_descriptors(ecm_fs_function); |
667 | if (!f->descriptors) | 667 | if (!f->descriptors) |
668 | goto fail; | 668 | goto fail; |
669 | 669 | ||
670 | ecm->fs.in = usb_find_endpoint(eth_fs_function, | 670 | ecm->fs.in = usb_find_endpoint(ecm_fs_function, |
671 | f->descriptors, &fs_in_desc); | 671 | f->descriptors, &fs_ecm_in_desc); |
672 | ecm->fs.out = usb_find_endpoint(eth_fs_function, | 672 | ecm->fs.out = usb_find_endpoint(ecm_fs_function, |
673 | f->descriptors, &fs_out_desc); | 673 | f->descriptors, &fs_ecm_out_desc); |
674 | ecm->fs.notify = usb_find_endpoint(eth_fs_function, | 674 | ecm->fs.notify = usb_find_endpoint(ecm_fs_function, |
675 | f->descriptors, &fs_notify_desc); | 675 | f->descriptors, &fs_ecm_notify_desc); |
676 | 676 | ||
677 | /* support all relevant hardware speeds... we expect that when | 677 | /* support all relevant hardware speeds... we expect that when |
678 | * hardware is dual speed, all bulk-capable endpoints work at | 678 | * hardware is dual speed, all bulk-capable endpoints work at |
679 | * both speeds | 679 | * both speeds |
680 | */ | 680 | */ |
681 | if (gadget_is_dualspeed(c->cdev->gadget)) { | 681 | if (gadget_is_dualspeed(c->cdev->gadget)) { |
682 | hs_in_desc.bEndpointAddress = | 682 | hs_ecm_in_desc.bEndpointAddress = |
683 | fs_in_desc.bEndpointAddress; | 683 | fs_ecm_in_desc.bEndpointAddress; |
684 | hs_out_desc.bEndpointAddress = | 684 | hs_ecm_out_desc.bEndpointAddress = |
685 | fs_out_desc.bEndpointAddress; | 685 | fs_ecm_out_desc.bEndpointAddress; |
686 | hs_notify_desc.bEndpointAddress = | 686 | hs_ecm_notify_desc.bEndpointAddress = |
687 | fs_notify_desc.bEndpointAddress; | 687 | fs_ecm_notify_desc.bEndpointAddress; |
688 | 688 | ||
689 | /* copy descriptors, and track endpoint copies */ | 689 | /* copy descriptors, and track endpoint copies */ |
690 | f->hs_descriptors = usb_copy_descriptors(eth_hs_function); | 690 | f->hs_descriptors = usb_copy_descriptors(ecm_hs_function); |
691 | if (!f->hs_descriptors) | 691 | if (!f->hs_descriptors) |
692 | goto fail; | 692 | goto fail; |
693 | 693 | ||
694 | ecm->hs.in = usb_find_endpoint(eth_hs_function, | 694 | ecm->hs.in = usb_find_endpoint(ecm_hs_function, |
695 | f->hs_descriptors, &hs_in_desc); | 695 | f->hs_descriptors, &hs_ecm_in_desc); |
696 | ecm->hs.out = usb_find_endpoint(eth_hs_function, | 696 | ecm->hs.out = usb_find_endpoint(ecm_hs_function, |
697 | f->hs_descriptors, &hs_out_desc); | 697 | f->hs_descriptors, &hs_ecm_out_desc); |
698 | ecm->hs.notify = usb_find_endpoint(eth_hs_function, | 698 | ecm->hs.notify = usb_find_endpoint(ecm_hs_function, |
699 | f->hs_descriptors, &hs_notify_desc); | 699 | f->hs_descriptors, &hs_ecm_notify_desc); |
700 | } | 700 | } |
701 | 701 | ||
702 | /* NOTE: all that is done without knowing or caring about | 702 | /* NOTE: all that is done without knowing or caring about |
@@ -795,7 +795,7 @@ int __init ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | |||
795 | if (status < 0) | 795 | if (status < 0) |
796 | return status; | 796 | return status; |
797 | ecm_string_defs[1].id = status; | 797 | ecm_string_defs[1].id = status; |
798 | ether_desc.iMACAddress = status; | 798 | ecm_desc.iMACAddress = status; |
799 | } | 799 | } |
800 | 800 | ||
801 | /* allocate and initialize one new instance */ | 801 | /* allocate and initialize one new instance */ |
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index eda4cde72c82..8affe1dfc2c1 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c | |||
@@ -70,7 +70,7 @@ static struct usb_interface_descriptor loopback_intf = { | |||
70 | 70 | ||
71 | /* full speed support: */ | 71 | /* full speed support: */ |
72 | 72 | ||
73 | static struct usb_endpoint_descriptor fs_source_desc = { | 73 | static struct usb_endpoint_descriptor fs_loop_source_desc = { |
74 | .bLength = USB_DT_ENDPOINT_SIZE, | 74 | .bLength = USB_DT_ENDPOINT_SIZE, |
75 | .bDescriptorType = USB_DT_ENDPOINT, | 75 | .bDescriptorType = USB_DT_ENDPOINT, |
76 | 76 | ||
@@ -78,7 +78,7 @@ static struct usb_endpoint_descriptor fs_source_desc = { | |||
78 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 78 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
79 | }; | 79 | }; |
80 | 80 | ||
81 | static struct usb_endpoint_descriptor fs_sink_desc = { | 81 | static struct usb_endpoint_descriptor fs_loop_sink_desc = { |
82 | .bLength = USB_DT_ENDPOINT_SIZE, | 82 | .bLength = USB_DT_ENDPOINT_SIZE, |
83 | .bDescriptorType = USB_DT_ENDPOINT, | 83 | .bDescriptorType = USB_DT_ENDPOINT, |
84 | 84 | ||
@@ -88,14 +88,14 @@ static struct usb_endpoint_descriptor fs_sink_desc = { | |||
88 | 88 | ||
89 | static struct usb_descriptor_header *fs_loopback_descs[] = { | 89 | static struct usb_descriptor_header *fs_loopback_descs[] = { |
90 | (struct usb_descriptor_header *) &loopback_intf, | 90 | (struct usb_descriptor_header *) &loopback_intf, |
91 | (struct usb_descriptor_header *) &fs_sink_desc, | 91 | (struct usb_descriptor_header *) &fs_loop_sink_desc, |
92 | (struct usb_descriptor_header *) &fs_source_desc, | 92 | (struct usb_descriptor_header *) &fs_loop_source_desc, |
93 | NULL, | 93 | NULL, |
94 | }; | 94 | }; |
95 | 95 | ||
96 | /* high speed support: */ | 96 | /* high speed support: */ |
97 | 97 | ||
98 | static struct usb_endpoint_descriptor hs_source_desc = { | 98 | static struct usb_endpoint_descriptor hs_loop_source_desc = { |
99 | .bLength = USB_DT_ENDPOINT_SIZE, | 99 | .bLength = USB_DT_ENDPOINT_SIZE, |
100 | .bDescriptorType = USB_DT_ENDPOINT, | 100 | .bDescriptorType = USB_DT_ENDPOINT, |
101 | 101 | ||
@@ -103,7 +103,7 @@ static struct usb_endpoint_descriptor hs_source_desc = { | |||
103 | .wMaxPacketSize = __constant_cpu_to_le16(512), | 103 | .wMaxPacketSize = __constant_cpu_to_le16(512), |
104 | }; | 104 | }; |
105 | 105 | ||
106 | static struct usb_endpoint_descriptor hs_sink_desc = { | 106 | static struct usb_endpoint_descriptor hs_loop_sink_desc = { |
107 | .bLength = USB_DT_ENDPOINT_SIZE, | 107 | .bLength = USB_DT_ENDPOINT_SIZE, |
108 | .bDescriptorType = USB_DT_ENDPOINT, | 108 | .bDescriptorType = USB_DT_ENDPOINT, |
109 | 109 | ||
@@ -113,8 +113,8 @@ static struct usb_endpoint_descriptor hs_sink_desc = { | |||
113 | 113 | ||
114 | static struct usb_descriptor_header *hs_loopback_descs[] = { | 114 | static struct usb_descriptor_header *hs_loopback_descs[] = { |
115 | (struct usb_descriptor_header *) &loopback_intf, | 115 | (struct usb_descriptor_header *) &loopback_intf, |
116 | (struct usb_descriptor_header *) &hs_source_desc, | 116 | (struct usb_descriptor_header *) &hs_loop_source_desc, |
117 | (struct usb_descriptor_header *) &hs_sink_desc, | 117 | (struct usb_descriptor_header *) &hs_loop_sink_desc, |
118 | NULL, | 118 | NULL, |
119 | }; | 119 | }; |
120 | 120 | ||
@@ -152,7 +152,7 @@ loopback_bind(struct usb_configuration *c, struct usb_function *f) | |||
152 | 152 | ||
153 | /* allocate endpoints */ | 153 | /* allocate endpoints */ |
154 | 154 | ||
155 | loop->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc); | 155 | loop->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_loop_source_desc); |
156 | if (!loop->in_ep) { | 156 | if (!loop->in_ep) { |
157 | autoconf_fail: | 157 | autoconf_fail: |
158 | ERROR(cdev, "%s: can't autoconfigure on %s\n", | 158 | ERROR(cdev, "%s: can't autoconfigure on %s\n", |
@@ -161,17 +161,17 @@ autoconf_fail: | |||
161 | } | 161 | } |
162 | loop->in_ep->driver_data = cdev; /* claim */ | 162 | loop->in_ep->driver_data = cdev; /* claim */ |
163 | 163 | ||
164 | loop->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_sink_desc); | 164 | loop->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_loop_sink_desc); |
165 | if (!loop->out_ep) | 165 | if (!loop->out_ep) |
166 | goto autoconf_fail; | 166 | goto autoconf_fail; |
167 | loop->out_ep->driver_data = cdev; /* claim */ | 167 | loop->out_ep->driver_data = cdev; /* claim */ |
168 | 168 | ||
169 | /* support high speed hardware */ | 169 | /* support high speed hardware */ |
170 | if (gadget_is_dualspeed(c->cdev->gadget)) { | 170 | if (gadget_is_dualspeed(c->cdev->gadget)) { |
171 | hs_source_desc.bEndpointAddress = | 171 | hs_loop_source_desc.bEndpointAddress = |
172 | fs_source_desc.bEndpointAddress; | 172 | fs_loop_source_desc.bEndpointAddress; |
173 | hs_sink_desc.bEndpointAddress = | 173 | hs_loop_sink_desc.bEndpointAddress = |
174 | fs_sink_desc.bEndpointAddress; | 174 | fs_loop_sink_desc.bEndpointAddress; |
175 | f->hs_descriptors = hs_loopback_descs; | 175 | f->hs_descriptors = hs_loopback_descs; |
176 | } | 176 | } |
177 | 177 | ||
@@ -255,8 +255,10 @@ enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop) | |||
255 | struct usb_request *req; | 255 | struct usb_request *req; |
256 | unsigned i; | 256 | unsigned i; |
257 | 257 | ||
258 | src = ep_choose(cdev->gadget, &hs_source_desc, &fs_source_desc); | 258 | src = ep_choose(cdev->gadget, |
259 | sink = ep_choose(cdev->gadget, &hs_sink_desc, &fs_sink_desc); | 259 | &hs_loop_source_desc, &fs_loop_source_desc); |
260 | sink = ep_choose(cdev->gadget, | ||
261 | &hs_loop_sink_desc, &fs_loop_sink_desc); | ||
260 | 262 | ||
261 | /* one endpoint writes data back IN to the host */ | 263 | /* one endpoint writes data back IN to the host */ |
262 | ep = loop->in_ep; | 264 | ep = loop->in_ep; |
@@ -350,7 +352,6 @@ static struct usb_configuration loopback_driver = { | |||
350 | .bind = loopback_bind_config, | 352 | .bind = loopback_bind_config, |
351 | .bConfigurationValue = 2, | 353 | .bConfigurationValue = 2, |
352 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 354 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
353 | .bMaxPower = 1, /* 2 mA, minimal */ | ||
354 | /* .iConfiguration = DYNAMIC */ | 355 | /* .iConfiguration = DYNAMIC */ |
355 | }; | 356 | }; |
356 | 357 | ||
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c new file mode 100644 index 000000000000..80c2e7e9622f --- /dev/null +++ b/drivers/usb/gadget/f_obex.c | |||
@@ -0,0 +1,493 @@ | |||
1 | /* | ||
2 | * f_obex.c -- USB CDC OBEX function driver | ||
3 | * | ||
4 | * Copyright (C) 2008 Nokia Corporation | ||
5 | * Contact: Felipe Balbi <felipe.balbi@nokia.com> | ||
6 | * | ||
7 | * Based on f_acm.c by Al Borchers and David Brownell. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | */ | ||
23 | |||
24 | /* #define VERBOSE_DEBUG */ | ||
25 | |||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/utsname.h> | ||
28 | #include <linux/device.h> | ||
29 | |||
30 | #include "u_serial.h" | ||
31 | #include "gadget_chips.h" | ||
32 | |||
33 | |||
34 | /* | ||
35 | * This CDC OBEX function support just packages a TTY-ish byte stream. | ||
36 | * A user mode server will put it into "raw" mode and handle all the | ||
37 | * relevant protocol details ... this is just a kernel passthrough. | ||
38 | * When possible, we prevent gadget enumeration until that server is | ||
39 | * ready to handle the commands. | ||
40 | */ | ||
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 { | ||
48 | struct gserial port; | ||
49 | u8 ctrl_id; | ||
50 | u8 data_id; | ||
51 | u8 port_num; | ||
52 | u8 can_activate; | ||
53 | |||
54 | struct obex_ep_descs fs; | ||
55 | struct obex_ep_descs hs; | ||
56 | }; | ||
57 | |||
58 | static inline struct f_obex *func_to_obex(struct usb_function *f) | ||
59 | { | ||
60 | return container_of(f, struct f_obex, port.func); | ||
61 | } | ||
62 | |||
63 | static inline struct f_obex *port_to_obex(struct gserial *p) | ||
64 | { | ||
65 | return container_of(p, struct f_obex, port); | ||
66 | } | ||
67 | |||
68 | /*-------------------------------------------------------------------------*/ | ||
69 | |||
70 | #define OBEX_CTRL_IDX 0 | ||
71 | #define OBEX_DATA_IDX 1 | ||
72 | |||
73 | static struct usb_string obex_string_defs[] = { | ||
74 | [OBEX_CTRL_IDX].s = "CDC Object Exchange (OBEX)", | ||
75 | [OBEX_DATA_IDX].s = "CDC OBEX Data", | ||
76 | { }, /* end of list */ | ||
77 | }; | ||
78 | |||
79 | static struct usb_gadget_strings obex_string_table = { | ||
80 | .language = 0x0409, /* en-US */ | ||
81 | .strings = obex_string_defs, | ||
82 | }; | ||
83 | |||
84 | static struct usb_gadget_strings *obex_strings[] = { | ||
85 | &obex_string_table, | ||
86 | NULL, | ||
87 | }; | ||
88 | |||
89 | /*-------------------------------------------------------------------------*/ | ||
90 | |||
91 | static struct usb_interface_descriptor obex_control_intf __initdata = { | ||
92 | .bLength = sizeof(obex_control_intf), | ||
93 | .bDescriptorType = USB_DT_INTERFACE, | ||
94 | .bInterfaceNumber = 0, | ||
95 | |||
96 | .bAlternateSetting = 0, | ||
97 | .bNumEndpoints = 0, | ||
98 | .bInterfaceClass = USB_CLASS_COMM, | ||
99 | .bInterfaceSubClass = USB_CDC_SUBCLASS_OBEX, | ||
100 | }; | ||
101 | |||
102 | static struct usb_interface_descriptor obex_data_nop_intf __initdata = { | ||
103 | .bLength = sizeof(obex_data_nop_intf), | ||
104 | .bDescriptorType = USB_DT_INTERFACE, | ||
105 | .bInterfaceNumber = 1, | ||
106 | |||
107 | .bAlternateSetting = 0, | ||
108 | .bNumEndpoints = 0, | ||
109 | .bInterfaceClass = USB_CLASS_CDC_DATA, | ||
110 | }; | ||
111 | |||
112 | static struct usb_interface_descriptor obex_data_intf __initdata = { | ||
113 | .bLength = sizeof(obex_data_intf), | ||
114 | .bDescriptorType = USB_DT_INTERFACE, | ||
115 | .bInterfaceNumber = 2, | ||
116 | |||
117 | .bAlternateSetting = 1, | ||
118 | .bNumEndpoints = 2, | ||
119 | .bInterfaceClass = USB_CLASS_CDC_DATA, | ||
120 | }; | ||
121 | |||
122 | static struct usb_cdc_header_desc obex_cdc_header_desc __initdata = { | ||
123 | .bLength = sizeof(obex_cdc_header_desc), | ||
124 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
125 | .bDescriptorSubType = USB_CDC_HEADER_TYPE, | ||
126 | .bcdCDC = __constant_cpu_to_le16(0x0120), | ||
127 | }; | ||
128 | |||
129 | static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = { | ||
130 | .bLength = sizeof(obex_cdc_union_desc), | ||
131 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
132 | .bDescriptorSubType = USB_CDC_UNION_TYPE, | ||
133 | .bMasterInterface0 = 1, | ||
134 | .bSlaveInterface0 = 2, | ||
135 | }; | ||
136 | |||
137 | static struct usb_cdc_obex_desc obex_desc __initdata = { | ||
138 | .bLength = sizeof(obex_desc), | ||
139 | .bDescriptorType = USB_DT_CS_INTERFACE, | ||
140 | .bDescriptorSubType = USB_CDC_OBEX_TYPE, | ||
141 | .bcdVersion = __constant_cpu_to_le16(0x0100), | ||
142 | }; | ||
143 | |||
144 | /* High-Speed Support */ | ||
145 | |||
146 | static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = { | ||
147 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
148 | .bDescriptorType = USB_DT_ENDPOINT, | ||
149 | |||
150 | .bEndpointAddress = USB_DIR_OUT, | ||
151 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
152 | .wMaxPacketSize = __constant_cpu_to_le16(512), | ||
153 | }; | ||
154 | |||
155 | static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = { | ||
156 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
157 | .bDescriptorType = USB_DT_ENDPOINT, | ||
158 | |||
159 | .bEndpointAddress = USB_DIR_IN, | ||
160 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
161 | .wMaxPacketSize = __constant_cpu_to_le16(512), | ||
162 | }; | ||
163 | |||
164 | static struct usb_descriptor_header *hs_function[] __initdata = { | ||
165 | (struct usb_descriptor_header *) &obex_control_intf, | ||
166 | (struct usb_descriptor_header *) &obex_cdc_header_desc, | ||
167 | (struct usb_descriptor_header *) &obex_desc, | ||
168 | (struct usb_descriptor_header *) &obex_cdc_union_desc, | ||
169 | |||
170 | (struct usb_descriptor_header *) &obex_data_nop_intf, | ||
171 | (struct usb_descriptor_header *) &obex_data_intf, | ||
172 | (struct usb_descriptor_header *) &obex_hs_ep_in_desc, | ||
173 | (struct usb_descriptor_header *) &obex_hs_ep_out_desc, | ||
174 | NULL, | ||
175 | }; | ||
176 | |||
177 | /* Full-Speed Support */ | ||
178 | |||
179 | static struct usb_endpoint_descriptor obex_fs_ep_in_desc __initdata = { | ||
180 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
181 | .bDescriptorType = USB_DT_ENDPOINT, | ||
182 | |||
183 | .bEndpointAddress = USB_DIR_IN, | ||
184 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
185 | }; | ||
186 | |||
187 | static struct usb_endpoint_descriptor obex_fs_ep_out_desc __initdata = { | ||
188 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
189 | .bDescriptorType = USB_DT_ENDPOINT, | ||
190 | |||
191 | .bEndpointAddress = USB_DIR_OUT, | ||
192 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
193 | }; | ||
194 | |||
195 | static struct usb_descriptor_header *fs_function[] __initdata = { | ||
196 | (struct usb_descriptor_header *) &obex_control_intf, | ||
197 | (struct usb_descriptor_header *) &obex_cdc_header_desc, | ||
198 | (struct usb_descriptor_header *) &obex_desc, | ||
199 | (struct usb_descriptor_header *) &obex_cdc_union_desc, | ||
200 | |||
201 | (struct usb_descriptor_header *) &obex_data_nop_intf, | ||
202 | (struct usb_descriptor_header *) &obex_data_intf, | ||
203 | (struct usb_descriptor_header *) &obex_fs_ep_in_desc, | ||
204 | (struct usb_descriptor_header *) &obex_fs_ep_out_desc, | ||
205 | NULL, | ||
206 | }; | ||
207 | |||
208 | /*-------------------------------------------------------------------------*/ | ||
209 | |||
210 | static int obex_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | ||
211 | { | ||
212 | struct f_obex *obex = func_to_obex(f); | ||
213 | struct usb_composite_dev *cdev = f->config->cdev; | ||
214 | |||
215 | if (intf == obex->ctrl_id) { | ||
216 | if (alt != 0) | ||
217 | goto fail; | ||
218 | /* NOP */ | ||
219 | DBG(cdev, "reset obex ttyGS%d control\n", obex->port_num); | ||
220 | |||
221 | } else if (intf == obex->data_id) { | ||
222 | if (alt > 1) | ||
223 | goto fail; | ||
224 | |||
225 | if (obex->port.in->driver_data) { | ||
226 | DBG(cdev, "reset obex ttyGS%d\n", obex->port_num); | ||
227 | gserial_disconnect(&obex->port); | ||
228 | } | ||
229 | |||
230 | if (!obex->port.in_desc) { | ||
231 | DBG(cdev, "init obex ttyGS%d\n", obex->port_num); | ||
232 | obex->port.in_desc = ep_choose(cdev->gadget, | ||
233 | obex->hs.obex_in, obex->fs.obex_in); | ||
234 | obex->port.out_desc = ep_choose(cdev->gadget, | ||
235 | obex->hs.obex_out, obex->fs.obex_out); | ||
236 | } | ||
237 | |||
238 | if (alt == 1) { | ||
239 | DBG(cdev, "activate obex ttyGS%d\n", obex->port_num); | ||
240 | gserial_connect(&obex->port, obex->port_num); | ||
241 | } | ||
242 | |||
243 | } else | ||
244 | goto fail; | ||
245 | |||
246 | return 0; | ||
247 | |||
248 | fail: | ||
249 | return -EINVAL; | ||
250 | } | ||
251 | |||
252 | static int obex_get_alt(struct usb_function *f, unsigned intf) | ||
253 | { | ||
254 | struct f_obex *obex = func_to_obex(f); | ||
255 | |||
256 | if (intf == obex->ctrl_id) | ||
257 | return 0; | ||
258 | |||
259 | return obex->port.in->driver_data ? 1 : 0; | ||
260 | } | ||
261 | |||
262 | static void obex_disable(struct usb_function *f) | ||
263 | { | ||
264 | struct f_obex *obex = func_to_obex(f); | ||
265 | struct usb_composite_dev *cdev = f->config->cdev; | ||
266 | |||
267 | DBG(cdev, "obex ttyGS%d disable\n", obex->port_num); | ||
268 | gserial_disconnect(&obex->port); | ||
269 | } | ||
270 | |||
271 | /*-------------------------------------------------------------------------*/ | ||
272 | |||
273 | static void obex_connect(struct gserial *g) | ||
274 | { | ||
275 | struct f_obex *obex = port_to_obex(g); | ||
276 | struct usb_composite_dev *cdev = g->func.config->cdev; | ||
277 | int status; | ||
278 | |||
279 | if (!obex->can_activate) | ||
280 | return; | ||
281 | |||
282 | status = usb_function_activate(&g->func); | ||
283 | if (status) | ||
284 | DBG(cdev, "obex ttyGS%d function activate --> %d\n", | ||
285 | obex->port_num, status); | ||
286 | } | ||
287 | |||
288 | static void obex_disconnect(struct gserial *g) | ||
289 | { | ||
290 | struct f_obex *obex = port_to_obex(g); | ||
291 | struct usb_composite_dev *cdev = g->func.config->cdev; | ||
292 | int status; | ||
293 | |||
294 | if (!obex->can_activate) | ||
295 | return; | ||
296 | |||
297 | status = usb_function_deactivate(&g->func); | ||
298 | if (status) | ||
299 | DBG(cdev, "obex ttyGS%d function deactivate --> %d\n", | ||
300 | obex->port_num, status); | ||
301 | } | ||
302 | |||
303 | /*-------------------------------------------------------------------------*/ | ||
304 | |||
305 | static int __init | ||
306 | obex_bind(struct usb_configuration *c, struct usb_function *f) | ||
307 | { | ||
308 | struct usb_composite_dev *cdev = c->cdev; | ||
309 | struct f_obex *obex = func_to_obex(f); | ||
310 | int status; | ||
311 | struct usb_ep *ep; | ||
312 | |||
313 | /* allocate instance-specific interface IDs, and patch descriptors */ | ||
314 | |||
315 | status = usb_interface_id(c, f); | ||
316 | if (status < 0) | ||
317 | goto fail; | ||
318 | obex->ctrl_id = status; | ||
319 | |||
320 | obex_control_intf.bInterfaceNumber = status; | ||
321 | obex_cdc_union_desc.bMasterInterface0 = status; | ||
322 | |||
323 | status = usb_interface_id(c, f); | ||
324 | if (status < 0) | ||
325 | goto fail; | ||
326 | obex->data_id = status; | ||
327 | |||
328 | obex_data_nop_intf.bInterfaceNumber = status; | ||
329 | obex_data_intf.bInterfaceNumber = status; | ||
330 | obex_cdc_union_desc.bSlaveInterface0 = status; | ||
331 | |||
332 | /* allocate instance-specific endpoints */ | ||
333 | |||
334 | ep = usb_ep_autoconfig(cdev->gadget, &obex_fs_ep_in_desc); | ||
335 | if (!ep) | ||
336 | goto fail; | ||
337 | obex->port.in = ep; | ||
338 | ep->driver_data = cdev; /* claim */ | ||
339 | |||
340 | ep = usb_ep_autoconfig(cdev->gadget, &obex_fs_ep_out_desc); | ||
341 | if (!ep) | ||
342 | goto fail; | ||
343 | obex->port.out = ep; | ||
344 | ep->driver_data = cdev; /* claim */ | ||
345 | |||
346 | /* copy descriptors, and track endpoint copies */ | ||
347 | f->descriptors = usb_copy_descriptors(fs_function); | ||
348 | |||
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 | ||
355 | * hardware is dual speed, all bulk-capable endpoints work at | ||
356 | * both speeds | ||
357 | */ | ||
358 | if (gadget_is_dualspeed(c->cdev->gadget)) { | ||
359 | |||
360 | obex_hs_ep_in_desc.bEndpointAddress = | ||
361 | obex_fs_ep_in_desc.bEndpointAddress; | ||
362 | obex_hs_ep_out_desc.bEndpointAddress = | ||
363 | obex_fs_ep_out_desc.bEndpointAddress; | ||
364 | |||
365 | /* copy descriptors, and track endpoint copies */ | ||
366 | f->hs_descriptors = usb_copy_descriptors(hs_function); | ||
367 | |||
368 | obex->hs.obex_in = usb_find_endpoint(hs_function, | ||
369 | f->descriptors, &obex_hs_ep_in_desc); | ||
370 | obex->hs.obex_out = usb_find_endpoint(hs_function, | ||
371 | f->descriptors, &obex_hs_ep_out_desc); | ||
372 | } | ||
373 | |||
374 | /* Avoid letting this gadget enumerate until the userspace | ||
375 | * OBEX server is active. | ||
376 | */ | ||
377 | status = usb_function_deactivate(f); | ||
378 | if (status < 0) | ||
379 | WARNING(cdev, "obex ttyGS%d: can't prevent enumeration, %d\n", | ||
380 | obex->port_num, status); | ||
381 | else | ||
382 | obex->can_activate = true; | ||
383 | |||
384 | |||
385 | DBG(cdev, "obex ttyGS%d: %s speed IN/%s OUT/%s\n", | ||
386 | obex->port_num, | ||
387 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | ||
388 | obex->port.in->name, obex->port.out->name); | ||
389 | |||
390 | return 0; | ||
391 | |||
392 | fail: | ||
393 | /* we might as well release our claims on endpoints */ | ||
394 | if (obex->port.out) | ||
395 | obex->port.out->driver_data = NULL; | ||
396 | if (obex->port.in) | ||
397 | obex->port.in->driver_data = NULL; | ||
398 | |||
399 | ERROR(cdev, "%s/%p: can't bind, err %d\n", f->name, f, status); | ||
400 | |||
401 | return status; | ||
402 | } | ||
403 | |||
404 | static void | ||
405 | obex_unbind(struct usb_configuration *c, struct usb_function *f) | ||
406 | { | ||
407 | if (gadget_is_dualspeed(c->cdev->gadget)) | ||
408 | usb_free_descriptors(f->hs_descriptors); | ||
409 | usb_free_descriptors(f->descriptors); | ||
410 | kfree(func_to_obex(f)); | ||
411 | } | ||
412 | |||
413 | /* Some controllers can't support CDC OBEX ... */ | ||
414 | static inline bool can_support_obex(struct usb_configuration *c) | ||
415 | { | ||
416 | /* Since the first interface is a NOP, we can ignore the | ||
417 | * issue of multi-interface support on most controllers. | ||
418 | * | ||
419 | * Altsettings are mandatory, however... | ||
420 | */ | ||
421 | if (!gadget_supports_altsettings(c->cdev->gadget)) | ||
422 | return false; | ||
423 | |||
424 | /* everything else is *probably* fine ... */ | ||
425 | return true; | ||
426 | } | ||
427 | |||
428 | /** | ||
429 | * obex_bind_config - add a CDC OBEX function to a configuration | ||
430 | * @c: the configuration to support the CDC OBEX instance | ||
431 | * @port_num: /dev/ttyGS* port this interface will use | ||
432 | * Context: single threaded during gadget setup | ||
433 | * | ||
434 | * Returns zero on success, else negative errno. | ||
435 | * | ||
436 | * Caller must have called @gserial_setup() with enough ports to | ||
437 | * handle all the ones it binds. Caller is also responsible | ||
438 | * for calling @gserial_cleanup() before module unload. | ||
439 | */ | ||
440 | int __init obex_bind_config(struct usb_configuration *c, u8 port_num) | ||
441 | { | ||
442 | struct f_obex *obex; | ||
443 | int status; | ||
444 | |||
445 | if (!can_support_obex(c)) | ||
446 | return -EINVAL; | ||
447 | |||
448 | /* maybe allocate device-global string IDs, and patch descriptors */ | ||
449 | if (obex_string_defs[OBEX_CTRL_IDX].id == 0) { | ||
450 | status = usb_string_id(c->cdev); | ||
451 | if (status < 0) | ||
452 | return status; | ||
453 | obex_string_defs[OBEX_CTRL_IDX].id = status; | ||
454 | |||
455 | obex_control_intf.iInterface = status; | ||
456 | |||
457 | status = usb_string_id(c->cdev); | ||
458 | if (status < 0) | ||
459 | return status; | ||
460 | obex_string_defs[OBEX_DATA_IDX].id = status; | ||
461 | |||
462 | obex_data_nop_intf.iInterface = | ||
463 | obex_data_intf.iInterface = status; | ||
464 | } | ||
465 | |||
466 | /* allocate and initialize one new instance */ | ||
467 | obex = kzalloc(sizeof *obex, GFP_KERNEL); | ||
468 | if (!obex) | ||
469 | return -ENOMEM; | ||
470 | |||
471 | obex->port_num = port_num; | ||
472 | |||
473 | obex->port.connect = obex_connect; | ||
474 | obex->port.disconnect = obex_disconnect; | ||
475 | |||
476 | obex->port.func.name = "obex"; | ||
477 | obex->port.func.strings = obex_strings; | ||
478 | /* descriptors are per-instance copies */ | ||
479 | obex->port.func.bind = obex_bind; | ||
480 | obex->port.func.unbind = obex_unbind; | ||
481 | obex->port.func.set_alt = obex_set_alt; | ||
482 | obex->port.func.get_alt = obex_get_alt; | ||
483 | obex->port.func.disable = obex_disable; | ||
484 | |||
485 | status = usb_add_function(c, &obex->port.func); | ||
486 | if (status) | ||
487 | kfree(obex); | ||
488 | |||
489 | return status; | ||
490 | } | ||
491 | |||
492 | MODULE_AUTHOR("Felipe Balbi"); | ||
493 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index f18c3a14d72a..dc84d26d2835 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c | |||
@@ -552,7 +552,6 @@ static struct usb_configuration sourcesink_driver = { | |||
552 | .setup = sourcesink_setup, | 552 | .setup = sourcesink_setup, |
553 | .bConfigurationValue = 3, | 553 | .bConfigurationValue = 3, |
554 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 554 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
555 | .bMaxPower = 1, /* 2 mA, minimal */ | ||
556 | /* .iConfiguration = DYNAMIC */ | 555 | /* .iConfiguration = DYNAMIC */ |
557 | }; | 556 | }; |
558 | 557 | ||
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c index acb8d233aa1d..fe1832875771 100644 --- a/drivers/usb/gadget/f_subset.c +++ b/drivers/usb/gadget/f_subset.c | |||
@@ -103,8 +103,8 @@ static struct usb_interface_descriptor subset_data_intf __initdata = { | |||
103 | /* .iInterface = DYNAMIC */ | 103 | /* .iInterface = DYNAMIC */ |
104 | }; | 104 | }; |
105 | 105 | ||
106 | static struct usb_cdc_header_desc header_desc __initdata = { | 106 | static struct usb_cdc_header_desc mdlm_header_desc __initdata = { |
107 | .bLength = sizeof header_desc, | 107 | .bLength = sizeof mdlm_header_desc, |
108 | .bDescriptorType = USB_DT_CS_INTERFACE, | 108 | .bDescriptorType = USB_DT_CS_INTERFACE, |
109 | .bDescriptorSubType = USB_CDC_HEADER_TYPE, | 109 | .bDescriptorSubType = USB_CDC_HEADER_TYPE, |
110 | 110 | ||
@@ -152,7 +152,7 @@ static struct usb_cdc_ether_desc ether_desc __initdata = { | |||
152 | 152 | ||
153 | /* full speed support: */ | 153 | /* full speed support: */ |
154 | 154 | ||
155 | static struct usb_endpoint_descriptor fs_in_desc __initdata = { | 155 | static struct usb_endpoint_descriptor fs_subset_in_desc __initdata = { |
156 | .bLength = USB_DT_ENDPOINT_SIZE, | 156 | .bLength = USB_DT_ENDPOINT_SIZE, |
157 | .bDescriptorType = USB_DT_ENDPOINT, | 157 | .bDescriptorType = USB_DT_ENDPOINT, |
158 | 158 | ||
@@ -160,7 +160,7 @@ static struct usb_endpoint_descriptor fs_in_desc __initdata = { | |||
160 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 160 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
161 | }; | 161 | }; |
162 | 162 | ||
163 | static struct usb_endpoint_descriptor fs_out_desc __initdata = { | 163 | static struct usb_endpoint_descriptor fs_subset_out_desc __initdata = { |
164 | .bLength = USB_DT_ENDPOINT_SIZE, | 164 | .bLength = USB_DT_ENDPOINT_SIZE, |
165 | .bDescriptorType = USB_DT_ENDPOINT, | 165 | .bDescriptorType = USB_DT_ENDPOINT, |
166 | 166 | ||
@@ -170,18 +170,18 @@ static struct usb_endpoint_descriptor fs_out_desc __initdata = { | |||
170 | 170 | ||
171 | static struct usb_descriptor_header *fs_eth_function[] __initdata = { | 171 | static struct usb_descriptor_header *fs_eth_function[] __initdata = { |
172 | (struct usb_descriptor_header *) &subset_data_intf, | 172 | (struct usb_descriptor_header *) &subset_data_intf, |
173 | (struct usb_descriptor_header *) &header_desc, | 173 | (struct usb_descriptor_header *) &mdlm_header_desc, |
174 | (struct usb_descriptor_header *) &mdlm_desc, | 174 | (struct usb_descriptor_header *) &mdlm_desc, |
175 | (struct usb_descriptor_header *) &mdlm_detail_desc, | 175 | (struct usb_descriptor_header *) &mdlm_detail_desc, |
176 | (struct usb_descriptor_header *) ðer_desc, | 176 | (struct usb_descriptor_header *) ðer_desc, |
177 | (struct usb_descriptor_header *) &fs_in_desc, | 177 | (struct usb_descriptor_header *) &fs_subset_in_desc, |
178 | (struct usb_descriptor_header *) &fs_out_desc, | 178 | (struct usb_descriptor_header *) &fs_subset_out_desc, |
179 | NULL, | 179 | NULL, |
180 | }; | 180 | }; |
181 | 181 | ||
182 | /* high speed support: */ | 182 | /* high speed support: */ |
183 | 183 | ||
184 | static struct usb_endpoint_descriptor hs_in_desc __initdata = { | 184 | static struct usb_endpoint_descriptor hs_subset_in_desc __initdata = { |
185 | .bLength = USB_DT_ENDPOINT_SIZE, | 185 | .bLength = USB_DT_ENDPOINT_SIZE, |
186 | .bDescriptorType = USB_DT_ENDPOINT, | 186 | .bDescriptorType = USB_DT_ENDPOINT, |
187 | 187 | ||
@@ -189,7 +189,7 @@ static struct usb_endpoint_descriptor hs_in_desc __initdata = { | |||
189 | .wMaxPacketSize = __constant_cpu_to_le16(512), | 189 | .wMaxPacketSize = __constant_cpu_to_le16(512), |
190 | }; | 190 | }; |
191 | 191 | ||
192 | static struct usb_endpoint_descriptor hs_out_desc __initdata = { | 192 | static struct usb_endpoint_descriptor hs_subset_out_desc __initdata = { |
193 | .bLength = USB_DT_ENDPOINT_SIZE, | 193 | .bLength = USB_DT_ENDPOINT_SIZE, |
194 | .bDescriptorType = USB_DT_ENDPOINT, | 194 | .bDescriptorType = USB_DT_ENDPOINT, |
195 | 195 | ||
@@ -199,12 +199,12 @@ static struct usb_endpoint_descriptor hs_out_desc __initdata = { | |||
199 | 199 | ||
200 | static struct usb_descriptor_header *hs_eth_function[] __initdata = { | 200 | static struct usb_descriptor_header *hs_eth_function[] __initdata = { |
201 | (struct usb_descriptor_header *) &subset_data_intf, | 201 | (struct usb_descriptor_header *) &subset_data_intf, |
202 | (struct usb_descriptor_header *) &header_desc, | 202 | (struct usb_descriptor_header *) &mdlm_header_desc, |
203 | (struct usb_descriptor_header *) &mdlm_desc, | 203 | (struct usb_descriptor_header *) &mdlm_desc, |
204 | (struct usb_descriptor_header *) &mdlm_detail_desc, | 204 | (struct usb_descriptor_header *) &mdlm_detail_desc, |
205 | (struct usb_descriptor_header *) ðer_desc, | 205 | (struct usb_descriptor_header *) ðer_desc, |
206 | (struct usb_descriptor_header *) &hs_in_desc, | 206 | (struct usb_descriptor_header *) &hs_subset_in_desc, |
207 | (struct usb_descriptor_header *) &hs_out_desc, | 207 | (struct usb_descriptor_header *) &hs_subset_out_desc, |
208 | NULL, | 208 | NULL, |
209 | }; | 209 | }; |
210 | 210 | ||
@@ -281,13 +281,13 @@ geth_bind(struct usb_configuration *c, struct usb_function *f) | |||
281 | status = -ENODEV; | 281 | status = -ENODEV; |
282 | 282 | ||
283 | /* allocate instance-specific endpoints */ | 283 | /* allocate instance-specific endpoints */ |
284 | ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc); | 284 | ep = usb_ep_autoconfig(cdev->gadget, &fs_subset_in_desc); |
285 | if (!ep) | 285 | if (!ep) |
286 | goto fail; | 286 | goto fail; |
287 | geth->port.in_ep = ep; | 287 | geth->port.in_ep = ep; |
288 | ep->driver_data = cdev; /* claim */ | 288 | ep->driver_data = cdev; /* claim */ |
289 | 289 | ||
290 | ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc); | 290 | ep = usb_ep_autoconfig(cdev->gadget, &fs_subset_out_desc); |
291 | if (!ep) | 291 | if (!ep) |
292 | goto fail; | 292 | goto fail; |
293 | geth->port.out_ep = ep; | 293 | geth->port.out_ep = ep; |
@@ -297,9 +297,9 @@ geth_bind(struct usb_configuration *c, struct usb_function *f) | |||
297 | f->descriptors = usb_copy_descriptors(fs_eth_function); | 297 | f->descriptors = usb_copy_descriptors(fs_eth_function); |
298 | 298 | ||
299 | geth->fs.in = usb_find_endpoint(fs_eth_function, | 299 | geth->fs.in = usb_find_endpoint(fs_eth_function, |
300 | f->descriptors, &fs_in_desc); | 300 | f->descriptors, &fs_subset_in_desc); |
301 | geth->fs.out = usb_find_endpoint(fs_eth_function, | 301 | geth->fs.out = usb_find_endpoint(fs_eth_function, |
302 | f->descriptors, &fs_out_desc); | 302 | f->descriptors, &fs_subset_out_desc); |
303 | 303 | ||
304 | 304 | ||
305 | /* support all relevant hardware speeds... we expect that when | 305 | /* support all relevant hardware speeds... we expect that when |
@@ -307,18 +307,18 @@ geth_bind(struct usb_configuration *c, struct usb_function *f) | |||
307 | * both speeds | 307 | * both speeds |
308 | */ | 308 | */ |
309 | if (gadget_is_dualspeed(c->cdev->gadget)) { | 309 | if (gadget_is_dualspeed(c->cdev->gadget)) { |
310 | hs_in_desc.bEndpointAddress = | 310 | hs_subset_in_desc.bEndpointAddress = |
311 | fs_in_desc.bEndpointAddress; | 311 | fs_subset_in_desc.bEndpointAddress; |
312 | hs_out_desc.bEndpointAddress = | 312 | hs_subset_out_desc.bEndpointAddress = |
313 | fs_out_desc.bEndpointAddress; | 313 | fs_subset_out_desc.bEndpointAddress; |
314 | 314 | ||
315 | /* copy descriptors, and track endpoint copies */ | 315 | /* copy descriptors, and track endpoint copies */ |
316 | f->hs_descriptors = usb_copy_descriptors(hs_eth_function); | 316 | f->hs_descriptors = usb_copy_descriptors(hs_eth_function); |
317 | 317 | ||
318 | geth->hs.in = usb_find_endpoint(hs_eth_function, | 318 | geth->hs.in = usb_find_endpoint(hs_eth_function, |
319 | f->hs_descriptors, &hs_in_desc); | 319 | f->hs_descriptors, &hs_subset_in_desc); |
320 | geth->hs.out = usb_find_endpoint(hs_eth_function, | 320 | geth->hs.out = usb_find_endpoint(hs_eth_function, |
321 | f->hs_descriptors, &hs_out_desc); | 321 | f->hs_descriptors, &hs_subset_out_desc); |
322 | } | 322 | } |
323 | 323 | ||
324 | /* NOTE: all that is done without knowing or caring about | 324 | /* NOTE: all that is done without knowing or caring about |
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index ea2c31d18080..c4e62a6297d7 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
@@ -245,6 +245,18 @@ | |||
245 | #include "gadget_chips.h" | 245 | #include "gadget_chips.h" |
246 | 246 | ||
247 | 247 | ||
248 | |||
249 | /* | ||
250 | * Kbuild is not very cooperative with respect to linking separately | ||
251 | * compiled library objects into one module. So for now we won't use | ||
252 | * separate compilation ... ensuring init/exit sections work to shrink | ||
253 | * the runtime footprint, and giving us at least some parts of what | ||
254 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
255 | */ | ||
256 | #include "usbstring.c" | ||
257 | #include "config.c" | ||
258 | #include "epautoconf.c" | ||
259 | |||
248 | /*-------------------------------------------------------------------------*/ | 260 | /*-------------------------------------------------------------------------*/ |
249 | 261 | ||
250 | #define DRIVER_DESC "File-backed Storage Gadget" | 262 | #define DRIVER_DESC "File-backed Storage Gadget" |
@@ -839,7 +851,7 @@ config_desc = { | |||
839 | .bConfigurationValue = CONFIG_VALUE, | 851 | .bConfigurationValue = CONFIG_VALUE, |
840 | .iConfiguration = STRING_CONFIG, | 852 | .iConfiguration = STRING_CONFIG, |
841 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, | 853 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, |
842 | .bMaxPower = 1, // self-powered | 854 | .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, |
843 | }; | 855 | }; |
844 | 856 | ||
845 | static struct usb_otg_descriptor | 857 | static struct usb_otg_descriptor |
@@ -2664,11 +2676,24 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size, | |||
2664 | /* Verify the length of the command itself */ | 2676 | /* Verify the length of the command itself */ |
2665 | if (cmnd_size != fsg->cmnd_size) { | 2677 | if (cmnd_size != fsg->cmnd_size) { |
2666 | 2678 | ||
2667 | /* Special case workaround: MS-Windows issues REQUEST SENSE | 2679 | /* Special case workaround: There are plenty of buggy SCSI |
2668 | * with cbw->Length == 12 (it should be 6). */ | 2680 | * implementations. Many have issues with cbw->Length |
2669 | if (fsg->cmnd[0] == SC_REQUEST_SENSE && fsg->cmnd_size == 12) | 2681 | * field passing a wrong command size. For those cases we |
2682 | * always try to work around the problem by using the length | ||
2683 | * sent by the host side provided it is at least as large | ||
2684 | * as the correct command length. | ||
2685 | * Examples of such cases would be MS-Windows, which issues | ||
2686 | * REQUEST SENSE with cbw->Length == 12 where it should | ||
2687 | * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and | ||
2688 | * REQUEST SENSE with cbw->Length == 10 where it should | ||
2689 | * be 6 as well. | ||
2690 | */ | ||
2691 | if (cmnd_size <= fsg->cmnd_size) { | ||
2692 | DBG(fsg, "%s is buggy! Expected length %d " | ||
2693 | "but we got %d\n", name, | ||
2694 | cmnd_size, fsg->cmnd_size); | ||
2670 | cmnd_size = fsg->cmnd_size; | 2695 | cmnd_size = fsg->cmnd_size; |
2671 | else { | 2696 | } else { |
2672 | fsg->phase_error = 1; | 2697 | fsg->phase_error = 1; |
2673 | return -EINVAL; | 2698 | return -EINVAL; |
2674 | } | 2699 | } |
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c new file mode 100644 index 000000000000..1fe8b44787b3 --- /dev/null +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -0,0 +1,2760 @@ | |||
1 | /* | ||
2 | * driver/usb/gadget/fsl_qe_udc.c | ||
3 | * | ||
4 | * Copyright (c) 2006-2008 Freescale Semiconductor, Inc. All rights reserved. | ||
5 | * | ||
6 | * Xie Xiaobo <X.Xie@freescale.com> | ||
7 | * Li Yang <leoli@freescale.com> | ||
8 | * Based on bareboard code from Shlomi Gridish. | ||
9 | * | ||
10 | * Description: | ||
11 | * Freescle QE/CPM USB Pheripheral Controller Driver | ||
12 | * The controller can be found on MPC8360, MPC8272, and etc. | ||
13 | * MPC8360 Rev 1.1 may need QE mircocode update | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or modify it | ||
16 | * under the terms of the GNU General Public License as published by the | ||
17 | * Free Software Foundation; either version 2 of the License, or (at your | ||
18 | * option) any later version. | ||
19 | */ | ||
20 | |||
21 | #undef USB_TRACE | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/ioport.h> | ||
27 | #include <linux/types.h> | ||
28 | #include <linux/errno.h> | ||
29 | #include <linux/slab.h> | ||
30 | #include <linux/list.h> | ||
31 | #include <linux/interrupt.h> | ||
32 | #include <linux/io.h> | ||
33 | #include <linux/moduleparam.h> | ||
34 | #include <linux/of_platform.h> | ||
35 | #include <linux/dma-mapping.h> | ||
36 | #include <linux/usb/ch9.h> | ||
37 | #include <linux/usb/gadget.h> | ||
38 | #include <linux/usb/otg.h> | ||
39 | #include <asm/qe.h> | ||
40 | #include <asm/cpm.h> | ||
41 | #include <asm/dma.h> | ||
42 | #include <asm/reg.h> | ||
43 | #include "fsl_qe_udc.h" | ||
44 | |||
45 | #define DRIVER_DESC "Freescale QE/CPM USB Device Controller driver" | ||
46 | #define DRIVER_AUTHOR "Xie XiaoBo" | ||
47 | #define DRIVER_VERSION "1.0" | ||
48 | |||
49 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
50 | |||
51 | static const char driver_name[] = "fsl_qe_udc"; | ||
52 | static const char driver_desc[] = DRIVER_DESC; | ||
53 | |||
54 | /*ep name is important in gadget, it should obey the convention of ep_match()*/ | ||
55 | static const char *const ep_name[] = { | ||
56 | "ep0-control", /* everyone has ep0 */ | ||
57 | /* 3 configurable endpoints */ | ||
58 | "ep1", | ||
59 | "ep2", | ||
60 | "ep3", | ||
61 | }; | ||
62 | |||
63 | static struct usb_endpoint_descriptor qe_ep0_desc = { | ||
64 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
65 | .bDescriptorType = USB_DT_ENDPOINT, | ||
66 | |||
67 | .bEndpointAddress = 0, | ||
68 | .bmAttributes = USB_ENDPOINT_XFER_CONTROL, | ||
69 | .wMaxPacketSize = USB_MAX_CTRL_PAYLOAD, | ||
70 | }; | ||
71 | |||
72 | /* it is initialized in probe() */ | ||
73 | static struct qe_udc *udc_controller; | ||
74 | |||
75 | /******************************************************************** | ||
76 | * Internal Used Function Start | ||
77 | ********************************************************************/ | ||
78 | /*----------------------------------------------------------------- | ||
79 | * done() - retire a request; caller blocked irqs | ||
80 | *--------------------------------------------------------------*/ | ||
81 | static void done(struct qe_ep *ep, struct qe_req *req, int status) | ||
82 | { | ||
83 | struct qe_udc *udc = ep->udc; | ||
84 | unsigned char stopped = ep->stopped; | ||
85 | |||
86 | /* the req->queue pointer is used by ep_queue() func, in which | ||
87 | * the request will be added into a udc_ep->queue 'd tail | ||
88 | * so here the req will be dropped from the ep->queue | ||
89 | */ | ||
90 | list_del_init(&req->queue); | ||
91 | |||
92 | /* req.status should be set as -EINPROGRESS in ep_queue() */ | ||
93 | if (req->req.status == -EINPROGRESS) | ||
94 | req->req.status = status; | ||
95 | else | ||
96 | status = req->req.status; | ||
97 | |||
98 | if (req->mapped) { | ||
99 | dma_unmap_single(udc->gadget.dev.parent, | ||
100 | req->req.dma, req->req.length, | ||
101 | ep_is_in(ep) | ||
102 | ? DMA_TO_DEVICE | ||
103 | : DMA_FROM_DEVICE); | ||
104 | req->req.dma = DMA_ADDR_INVALID; | ||
105 | req->mapped = 0; | ||
106 | } else | ||
107 | dma_sync_single_for_cpu(udc->gadget.dev.parent, | ||
108 | req->req.dma, req->req.length, | ||
109 | ep_is_in(ep) | ||
110 | ? DMA_TO_DEVICE | ||
111 | : DMA_FROM_DEVICE); | ||
112 | |||
113 | if (status && (status != -ESHUTDOWN)) | ||
114 | dev_vdbg(udc->dev, "complete %s req %p stat %d len %u/%u\n", | ||
115 | ep->ep.name, &req->req, status, | ||
116 | req->req.actual, req->req.length); | ||
117 | |||
118 | /* don't modify queue heads during completion callback */ | ||
119 | ep->stopped = 1; | ||
120 | spin_unlock(&udc->lock); | ||
121 | |||
122 | /* this complete() should a func implemented by gadget layer, | ||
123 | * eg fsg->bulk_in_complete() */ | ||
124 | if (req->req.complete) | ||
125 | req->req.complete(&ep->ep, &req->req); | ||
126 | |||
127 | spin_lock(&udc->lock); | ||
128 | |||
129 | ep->stopped = stopped; | ||
130 | } | ||
131 | |||
132 | /*----------------------------------------------------------------- | ||
133 | * nuke(): delete all requests related to this ep | ||
134 | *--------------------------------------------------------------*/ | ||
135 | static void nuke(struct qe_ep *ep, int status) | ||
136 | { | ||
137 | /* Whether this eq has request linked */ | ||
138 | while (!list_empty(&ep->queue)) { | ||
139 | struct qe_req *req = NULL; | ||
140 | req = list_entry(ep->queue.next, struct qe_req, queue); | ||
141 | |||
142 | done(ep, req, status); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | /*---------------------------------------------------------------------------* | ||
147 | * USB and Endpoint manipulate process, include parameter and register * | ||
148 | *---------------------------------------------------------------------------*/ | ||
149 | /* @value: 1--set stall 0--clean stall */ | ||
150 | static int qe_eprx_stall_change(struct qe_ep *ep, int value) | ||
151 | { | ||
152 | u16 tem_usep; | ||
153 | u8 epnum = ep->epnum; | ||
154 | struct qe_udc *udc = ep->udc; | ||
155 | |||
156 | tem_usep = in_be16(&udc->usb_regs->usb_usep[epnum]); | ||
157 | tem_usep = tem_usep & ~USB_RHS_MASK; | ||
158 | if (value == 1) | ||
159 | tem_usep |= USB_RHS_STALL; | ||
160 | else if (ep->dir == USB_DIR_IN) | ||
161 | tem_usep |= USB_RHS_IGNORE_OUT; | ||
162 | |||
163 | out_be16(&udc->usb_regs->usb_usep[epnum], tem_usep); | ||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | static int qe_eptx_stall_change(struct qe_ep *ep, int value) | ||
168 | { | ||
169 | u16 tem_usep; | ||
170 | u8 epnum = ep->epnum; | ||
171 | struct qe_udc *udc = ep->udc; | ||
172 | |||
173 | tem_usep = in_be16(&udc->usb_regs->usb_usep[epnum]); | ||
174 | tem_usep = tem_usep & ~USB_THS_MASK; | ||
175 | if (value == 1) | ||
176 | tem_usep |= USB_THS_STALL; | ||
177 | else if (ep->dir == USB_DIR_OUT) | ||
178 | tem_usep |= USB_THS_IGNORE_IN; | ||
179 | |||
180 | out_be16(&udc->usb_regs->usb_usep[epnum], tem_usep); | ||
181 | |||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | static int qe_ep0_stall(struct qe_udc *udc) | ||
186 | { | ||
187 | qe_eptx_stall_change(&udc->eps[0], 1); | ||
188 | qe_eprx_stall_change(&udc->eps[0], 1); | ||
189 | udc_controller->ep0_state = WAIT_FOR_SETUP; | ||
190 | udc_controller->ep0_dir = 0; | ||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static int qe_eprx_nack(struct qe_ep *ep) | ||
195 | { | ||
196 | u8 epnum = ep->epnum; | ||
197 | struct qe_udc *udc = ep->udc; | ||
198 | |||
199 | if (ep->state == EP_STATE_IDLE) { | ||
200 | /* Set the ep's nack */ | ||
201 | clrsetbits_be16(&udc->usb_regs->usb_usep[epnum], | ||
202 | USB_RHS_MASK, USB_RHS_NACK); | ||
203 | |||
204 | /* Mask Rx and Busy interrupts */ | ||
205 | clrbits16(&udc->usb_regs->usb_usbmr, | ||
206 | (USB_E_RXB_MASK | USB_E_BSY_MASK)); | ||
207 | |||
208 | ep->state = EP_STATE_NACK; | ||
209 | } | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | static int qe_eprx_normal(struct qe_ep *ep) | ||
214 | { | ||
215 | struct qe_udc *udc = ep->udc; | ||
216 | |||
217 | if (ep->state == EP_STATE_NACK) { | ||
218 | clrsetbits_be16(&udc->usb_regs->usb_usep[ep->epnum], | ||
219 | USB_RTHS_MASK, USB_THS_IGNORE_IN); | ||
220 | |||
221 | /* Unmask RX interrupts */ | ||
222 | out_be16(&udc->usb_regs->usb_usber, | ||
223 | USB_E_BSY_MASK | USB_E_RXB_MASK); | ||
224 | setbits16(&udc->usb_regs->usb_usbmr, | ||
225 | (USB_E_RXB_MASK | USB_E_BSY_MASK)); | ||
226 | |||
227 | ep->state = EP_STATE_IDLE; | ||
228 | ep->has_data = 0; | ||
229 | } | ||
230 | |||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | static int qe_ep_cmd_stoptx(struct qe_ep *ep) | ||
235 | { | ||
236 | if (ep->udc->soc_type == PORT_CPM) | ||
237 | cpm_command(CPM_USB_STOP_TX | (ep->epnum << CPM_USB_EP_SHIFT), | ||
238 | CPM_USB_STOP_TX_OPCODE); | ||
239 | else | ||
240 | qe_issue_cmd(QE_USB_STOP_TX, QE_CR_SUBBLOCK_USB, | ||
241 | ep->epnum, 0); | ||
242 | |||
243 | return 0; | ||
244 | } | ||
245 | |||
246 | static int qe_ep_cmd_restarttx(struct qe_ep *ep) | ||
247 | { | ||
248 | if (ep->udc->soc_type == PORT_CPM) | ||
249 | cpm_command(CPM_USB_RESTART_TX | (ep->epnum << | ||
250 | CPM_USB_EP_SHIFT), CPM_USB_RESTART_TX_OPCODE); | ||
251 | else | ||
252 | qe_issue_cmd(QE_USB_RESTART_TX, QE_CR_SUBBLOCK_USB, | ||
253 | ep->epnum, 0); | ||
254 | |||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | static int qe_ep_flushtxfifo(struct qe_ep *ep) | ||
259 | { | ||
260 | struct qe_udc *udc = ep->udc; | ||
261 | int i; | ||
262 | |||
263 | i = (int)ep->epnum; | ||
264 | |||
265 | qe_ep_cmd_stoptx(ep); | ||
266 | out_8(&udc->usb_regs->usb_uscom, | ||
267 | USB_CMD_FLUSH_FIFO | (USB_CMD_EP_MASK & (ep->epnum))); | ||
268 | out_be16(&udc->ep_param[i]->tbptr, in_be16(&udc->ep_param[i]->tbase)); | ||
269 | out_be32(&udc->ep_param[i]->tstate, 0); | ||
270 | out_be16(&udc->ep_param[i]->tbcnt, 0); | ||
271 | |||
272 | ep->c_txbd = ep->txbase; | ||
273 | ep->n_txbd = ep->txbase; | ||
274 | qe_ep_cmd_restarttx(ep); | ||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static int qe_ep_filltxfifo(struct qe_ep *ep) | ||
279 | { | ||
280 | struct qe_udc *udc = ep->udc; | ||
281 | |||
282 | out_8(&udc->usb_regs->usb_uscom, | ||
283 | USB_CMD_STR_FIFO | (USB_CMD_EP_MASK & (ep->epnum))); | ||
284 | return 0; | ||
285 | } | ||
286 | |||
287 | static int qe_epbds_reset(struct qe_udc *udc, int pipe_num) | ||
288 | { | ||
289 | struct qe_ep *ep; | ||
290 | u32 bdring_len; | ||
291 | struct qe_bd __iomem *bd; | ||
292 | int i; | ||
293 | |||
294 | ep = &udc->eps[pipe_num]; | ||
295 | |||
296 | if (ep->dir == USB_DIR_OUT) | ||
297 | bdring_len = USB_BDRING_LEN_RX; | ||
298 | else | ||
299 | bdring_len = USB_BDRING_LEN; | ||
300 | |||
301 | bd = ep->rxbase; | ||
302 | for (i = 0; i < (bdring_len - 1); i++) { | ||
303 | out_be32((u32 __iomem *)bd, R_E | R_I); | ||
304 | bd++; | ||
305 | } | ||
306 | out_be32((u32 __iomem *)bd, R_E | R_I | R_W); | ||
307 | |||
308 | bd = ep->txbase; | ||
309 | for (i = 0; i < USB_BDRING_LEN_TX - 1; i++) { | ||
310 | out_be32(&bd->buf, 0); | ||
311 | out_be32((u32 __iomem *)bd, 0); | ||
312 | bd++; | ||
313 | } | ||
314 | out_be32((u32 __iomem *)bd, T_W); | ||
315 | |||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | static int qe_ep_reset(struct qe_udc *udc, int pipe_num) | ||
320 | { | ||
321 | struct qe_ep *ep; | ||
322 | u16 tmpusep; | ||
323 | |||
324 | ep = &udc->eps[pipe_num]; | ||
325 | tmpusep = in_be16(&udc->usb_regs->usb_usep[pipe_num]); | ||
326 | tmpusep &= ~USB_RTHS_MASK; | ||
327 | |||
328 | switch (ep->dir) { | ||
329 | case USB_DIR_BOTH: | ||
330 | qe_ep_flushtxfifo(ep); | ||
331 | break; | ||
332 | case USB_DIR_OUT: | ||
333 | tmpusep |= USB_THS_IGNORE_IN; | ||
334 | break; | ||
335 | case USB_DIR_IN: | ||
336 | qe_ep_flushtxfifo(ep); | ||
337 | tmpusep |= USB_RHS_IGNORE_OUT; | ||
338 | break; | ||
339 | default: | ||
340 | break; | ||
341 | } | ||
342 | out_be16(&udc->usb_regs->usb_usep[pipe_num], tmpusep); | ||
343 | |||
344 | qe_epbds_reset(udc, pipe_num); | ||
345 | |||
346 | return 0; | ||
347 | } | ||
348 | |||
349 | static int qe_ep_toggledata01(struct qe_ep *ep) | ||
350 | { | ||
351 | ep->data01 ^= 0x1; | ||
352 | return 0; | ||
353 | } | ||
354 | |||
355 | static int qe_ep_bd_init(struct qe_udc *udc, unsigned char pipe_num) | ||
356 | { | ||
357 | struct qe_ep *ep = &udc->eps[pipe_num]; | ||
358 | unsigned long tmp_addr = 0; | ||
359 | struct usb_ep_para __iomem *epparam; | ||
360 | int i; | ||
361 | struct qe_bd __iomem *bd; | ||
362 | int bdring_len; | ||
363 | |||
364 | if (ep->dir == USB_DIR_OUT) | ||
365 | bdring_len = USB_BDRING_LEN_RX; | ||
366 | else | ||
367 | bdring_len = USB_BDRING_LEN; | ||
368 | |||
369 | epparam = udc->ep_param[pipe_num]; | ||
370 | /* alloc multi-ram for BD rings and set the ep parameters */ | ||
371 | tmp_addr = cpm_muram_alloc(sizeof(struct qe_bd) * (bdring_len + | ||
372 | USB_BDRING_LEN_TX), QE_ALIGNMENT_OF_BD); | ||
373 | out_be16(&epparam->rbase, (u16)tmp_addr); | ||
374 | out_be16(&epparam->tbase, (u16)(tmp_addr + | ||
375 | (sizeof(struct qe_bd) * bdring_len))); | ||
376 | |||
377 | out_be16(&epparam->rbptr, in_be16(&epparam->rbase)); | ||
378 | out_be16(&epparam->tbptr, in_be16(&epparam->tbase)); | ||
379 | |||
380 | ep->rxbase = cpm_muram_addr(tmp_addr); | ||
381 | ep->txbase = cpm_muram_addr(tmp_addr + (sizeof(struct qe_bd) | ||
382 | * bdring_len)); | ||
383 | ep->n_rxbd = ep->rxbase; | ||
384 | ep->e_rxbd = ep->rxbase; | ||
385 | ep->n_txbd = ep->txbase; | ||
386 | ep->c_txbd = ep->txbase; | ||
387 | ep->data01 = 0; /* data0 */ | ||
388 | |||
389 | /* Init TX and RX bds */ | ||
390 | bd = ep->rxbase; | ||
391 | for (i = 0; i < bdring_len - 1; i++) { | ||
392 | out_be32(&bd->buf, 0); | ||
393 | out_be32((u32 __iomem *)bd, 0); | ||
394 | bd++; | ||
395 | } | ||
396 | out_be32(&bd->buf, 0); | ||
397 | out_be32((u32 __iomem *)bd, R_W); | ||
398 | |||
399 | bd = ep->txbase; | ||
400 | for (i = 0; i < USB_BDRING_LEN_TX - 1; i++) { | ||
401 | out_be32(&bd->buf, 0); | ||
402 | out_be32((u32 __iomem *)bd, 0); | ||
403 | bd++; | ||
404 | } | ||
405 | out_be32(&bd->buf, 0); | ||
406 | out_be32((u32 __iomem *)bd, T_W); | ||
407 | |||
408 | return 0; | ||
409 | } | ||
410 | |||
411 | static int qe_ep_rxbd_update(struct qe_ep *ep) | ||
412 | { | ||
413 | unsigned int size; | ||
414 | int i; | ||
415 | unsigned int tmp; | ||
416 | struct qe_bd __iomem *bd; | ||
417 | unsigned int bdring_len; | ||
418 | |||
419 | if (ep->rxbase == NULL) | ||
420 | return -EINVAL; | ||
421 | |||
422 | bd = ep->rxbase; | ||
423 | |||
424 | ep->rxframe = kmalloc(sizeof(*ep->rxframe), GFP_ATOMIC); | ||
425 | if (ep->rxframe == NULL) { | ||
426 | dev_err(ep->udc->dev, "malloc rxframe failed\n"); | ||
427 | return -ENOMEM; | ||
428 | } | ||
429 | |||
430 | qe_frame_init(ep->rxframe); | ||
431 | |||
432 | if (ep->dir == USB_DIR_OUT) | ||
433 | bdring_len = USB_BDRING_LEN_RX; | ||
434 | else | ||
435 | bdring_len = USB_BDRING_LEN; | ||
436 | |||
437 | size = (ep->ep.maxpacket + USB_CRC_SIZE + 2) * (bdring_len + 1); | ||
438 | ep->rxbuffer = kzalloc(size, GFP_ATOMIC); | ||
439 | if (ep->rxbuffer == NULL) { | ||
440 | dev_err(ep->udc->dev, "malloc rxbuffer failed,size=%d\n", | ||
441 | size); | ||
442 | kfree(ep->rxframe); | ||
443 | return -ENOMEM; | ||
444 | } | ||
445 | |||
446 | ep->rxbuf_d = virt_to_phys((void *)ep->rxbuffer); | ||
447 | if (ep->rxbuf_d == DMA_ADDR_INVALID) { | ||
448 | ep->rxbuf_d = dma_map_single(udc_controller->gadget.dev.parent, | ||
449 | ep->rxbuffer, | ||
450 | size, | ||
451 | DMA_FROM_DEVICE); | ||
452 | ep->rxbufmap = 1; | ||
453 | } else { | ||
454 | dma_sync_single_for_device(udc_controller->gadget.dev.parent, | ||
455 | ep->rxbuf_d, size, | ||
456 | DMA_FROM_DEVICE); | ||
457 | ep->rxbufmap = 0; | ||
458 | } | ||
459 | |||
460 | size = ep->ep.maxpacket + USB_CRC_SIZE + 2; | ||
461 | tmp = ep->rxbuf_d; | ||
462 | tmp = (u32)(((tmp >> 2) << 2) + 4); | ||
463 | |||
464 | for (i = 0; i < bdring_len - 1; i++) { | ||
465 | out_be32(&bd->buf, tmp); | ||
466 | out_be32((u32 __iomem *)bd, (R_E | R_I)); | ||
467 | tmp = tmp + size; | ||
468 | bd++; | ||
469 | } | ||
470 | out_be32(&bd->buf, tmp); | ||
471 | out_be32((u32 __iomem *)bd, (R_E | R_I | R_W)); | ||
472 | |||
473 | return 0; | ||
474 | } | ||
475 | |||
476 | static int qe_ep_register_init(struct qe_udc *udc, unsigned char pipe_num) | ||
477 | { | ||
478 | struct qe_ep *ep = &udc->eps[pipe_num]; | ||
479 | struct usb_ep_para __iomem *epparam; | ||
480 | u16 usep, logepnum; | ||
481 | u16 tmp; | ||
482 | u8 rtfcr = 0; | ||
483 | |||
484 | epparam = udc->ep_param[pipe_num]; | ||
485 | |||
486 | usep = 0; | ||
487 | logepnum = (ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); | ||
488 | usep |= (logepnum << USB_EPNUM_SHIFT); | ||
489 | |||
490 | switch (ep->desc->bmAttributes & 0x03) { | ||
491 | case USB_ENDPOINT_XFER_BULK: | ||
492 | usep |= USB_TRANS_BULK; | ||
493 | break; | ||
494 | case USB_ENDPOINT_XFER_ISOC: | ||
495 | usep |= USB_TRANS_ISO; | ||
496 | break; | ||
497 | case USB_ENDPOINT_XFER_INT: | ||
498 | usep |= USB_TRANS_INT; | ||
499 | break; | ||
500 | default: | ||
501 | usep |= USB_TRANS_CTR; | ||
502 | break; | ||
503 | } | ||
504 | |||
505 | switch (ep->dir) { | ||
506 | case USB_DIR_OUT: | ||
507 | usep |= USB_THS_IGNORE_IN; | ||
508 | break; | ||
509 | case USB_DIR_IN: | ||
510 | usep |= USB_RHS_IGNORE_OUT; | ||
511 | break; | ||
512 | default: | ||
513 | break; | ||
514 | } | ||
515 | out_be16(&udc->usb_regs->usb_usep[pipe_num], usep); | ||
516 | |||
517 | rtfcr = 0x30; | ||
518 | out_8(&epparam->rbmr, rtfcr); | ||
519 | out_8(&epparam->tbmr, rtfcr); | ||
520 | |||
521 | tmp = (u16)(ep->ep.maxpacket + USB_CRC_SIZE); | ||
522 | /* MRBLR must be divisble by 4 */ | ||
523 | tmp = (u16)(((tmp >> 2) << 2) + 4); | ||
524 | out_be16(&epparam->mrblr, tmp); | ||
525 | |||
526 | return 0; | ||
527 | } | ||
528 | |||
529 | static int qe_ep_init(struct qe_udc *udc, | ||
530 | unsigned char pipe_num, | ||
531 | const struct usb_endpoint_descriptor *desc) | ||
532 | { | ||
533 | struct qe_ep *ep = &udc->eps[pipe_num]; | ||
534 | unsigned long flags; | ||
535 | int reval = 0; | ||
536 | u16 max = 0; | ||
537 | |||
538 | max = le16_to_cpu(desc->wMaxPacketSize); | ||
539 | |||
540 | /* check the max package size validate for this endpoint */ | ||
541 | /* Refer to USB2.0 spec table 9-13, | ||
542 | */ | ||
543 | if (pipe_num != 0) { | ||
544 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | ||
545 | case USB_ENDPOINT_XFER_BULK: | ||
546 | if (strstr(ep->ep.name, "-iso") | ||
547 | || strstr(ep->ep.name, "-int")) | ||
548 | goto en_done; | ||
549 | switch (udc->gadget.speed) { | ||
550 | case USB_SPEED_HIGH: | ||
551 | if ((max == 128) || (max == 256) || (max == 512)) | ||
552 | break; | ||
553 | default: | ||
554 | switch (max) { | ||
555 | case 4: | ||
556 | case 8: | ||
557 | case 16: | ||
558 | case 32: | ||
559 | case 64: | ||
560 | break; | ||
561 | default: | ||
562 | case USB_SPEED_LOW: | ||
563 | goto en_done; | ||
564 | } | ||
565 | } | ||
566 | break; | ||
567 | case USB_ENDPOINT_XFER_INT: | ||
568 | if (strstr(ep->ep.name, "-iso")) /* bulk is ok */ | ||
569 | goto en_done; | ||
570 | switch (udc->gadget.speed) { | ||
571 | case USB_SPEED_HIGH: | ||
572 | if (max <= 1024) | ||
573 | break; | ||
574 | case USB_SPEED_FULL: | ||
575 | if (max <= 64) | ||
576 | break; | ||
577 | default: | ||
578 | if (max <= 8) | ||
579 | break; | ||
580 | goto en_done; | ||
581 | } | ||
582 | break; | ||
583 | case USB_ENDPOINT_XFER_ISOC: | ||
584 | if (strstr(ep->ep.name, "-bulk") | ||
585 | || strstr(ep->ep.name, "-int")) | ||
586 | goto en_done; | ||
587 | switch (udc->gadget.speed) { | ||
588 | case USB_SPEED_HIGH: | ||
589 | if (max <= 1024) | ||
590 | break; | ||
591 | case USB_SPEED_FULL: | ||
592 | if (max <= 1023) | ||
593 | break; | ||
594 | default: | ||
595 | goto en_done; | ||
596 | } | ||
597 | break; | ||
598 | case USB_ENDPOINT_XFER_CONTROL: | ||
599 | if (strstr(ep->ep.name, "-iso") | ||
600 | || strstr(ep->ep.name, "-int")) | ||
601 | goto en_done; | ||
602 | switch (udc->gadget.speed) { | ||
603 | case USB_SPEED_HIGH: | ||
604 | case USB_SPEED_FULL: | ||
605 | switch (max) { | ||
606 | case 1: | ||
607 | case 2: | ||
608 | case 4: | ||
609 | case 8: | ||
610 | case 16: | ||
611 | case 32: | ||
612 | case 64: | ||
613 | break; | ||
614 | default: | ||
615 | goto en_done; | ||
616 | } | ||
617 | case USB_SPEED_LOW: | ||
618 | switch (max) { | ||
619 | case 1: | ||
620 | case 2: | ||
621 | case 4: | ||
622 | case 8: | ||
623 | break; | ||
624 | default: | ||
625 | goto en_done; | ||
626 | } | ||
627 | default: | ||
628 | goto en_done; | ||
629 | } | ||
630 | break; | ||
631 | |||
632 | default: | ||
633 | goto en_done; | ||
634 | } | ||
635 | } /* if ep0*/ | ||
636 | |||
637 | spin_lock_irqsave(&udc->lock, flags); | ||
638 | |||
639 | /* initialize ep structure */ | ||
640 | ep->ep.maxpacket = max; | ||
641 | ep->tm = (u8)(desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); | ||
642 | ep->desc = desc; | ||
643 | ep->stopped = 0; | ||
644 | ep->init = 1; | ||
645 | |||
646 | if (pipe_num == 0) { | ||
647 | ep->dir = USB_DIR_BOTH; | ||
648 | udc->ep0_dir = USB_DIR_OUT; | ||
649 | udc->ep0_state = WAIT_FOR_SETUP; | ||
650 | } else { | ||
651 | switch (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) { | ||
652 | case USB_DIR_OUT: | ||
653 | ep->dir = USB_DIR_OUT; | ||
654 | break; | ||
655 | case USB_DIR_IN: | ||
656 | ep->dir = USB_DIR_IN; | ||
657 | default: | ||
658 | break; | ||
659 | } | ||
660 | } | ||
661 | |||
662 | /* hardware special operation */ | ||
663 | qe_ep_bd_init(udc, pipe_num); | ||
664 | if ((ep->tm == USBP_TM_CTL) || (ep->dir == USB_DIR_OUT)) { | ||
665 | reval = qe_ep_rxbd_update(ep); | ||
666 | if (reval) | ||
667 | goto en_done1; | ||
668 | } | ||
669 | |||
670 | if ((ep->tm == USBP_TM_CTL) || (ep->dir == USB_DIR_IN)) { | ||
671 | ep->txframe = kmalloc(sizeof(*ep->txframe), GFP_ATOMIC); | ||
672 | if (ep->txframe == NULL) { | ||
673 | dev_err(udc->dev, "malloc txframe failed\n"); | ||
674 | goto en_done2; | ||
675 | } | ||
676 | qe_frame_init(ep->txframe); | ||
677 | } | ||
678 | |||
679 | qe_ep_register_init(udc, pipe_num); | ||
680 | |||
681 | /* Now HW will be NAKing transfers to that EP, | ||
682 | * until a buffer is queued to it. */ | ||
683 | spin_unlock_irqrestore(&udc->lock, flags); | ||
684 | |||
685 | return 0; | ||
686 | en_done2: | ||
687 | kfree(ep->rxbuffer); | ||
688 | kfree(ep->rxframe); | ||
689 | en_done1: | ||
690 | spin_unlock_irqrestore(&udc->lock, flags); | ||
691 | en_done: | ||
692 | dev_dbg(udc->dev, "failed to initialize %s\n", ep->ep.name); | ||
693 | return -ENODEV; | ||
694 | } | ||
695 | |||
696 | static inline void qe_usb_enable(void) | ||
697 | { | ||
698 | setbits8(&udc_controller->usb_regs->usb_usmod, USB_MODE_EN); | ||
699 | } | ||
700 | |||
701 | static inline void qe_usb_disable(void) | ||
702 | { | ||
703 | clrbits8(&udc_controller->usb_regs->usb_usmod, USB_MODE_EN); | ||
704 | } | ||
705 | |||
706 | /*----------------------------------------------------------------------------* | ||
707 | * USB and EP basic manipulate function end * | ||
708 | *----------------------------------------------------------------------------*/ | ||
709 | |||
710 | |||
711 | /****************************************************************************** | ||
712 | UDC transmit and receive process | ||
713 | ******************************************************************************/ | ||
714 | static void recycle_one_rxbd(struct qe_ep *ep) | ||
715 | { | ||
716 | u32 bdstatus; | ||
717 | |||
718 | bdstatus = in_be32((u32 __iomem *)ep->e_rxbd); | ||
719 | bdstatus = R_I | R_E | (bdstatus & R_W); | ||
720 | out_be32((u32 __iomem *)ep->e_rxbd, bdstatus); | ||
721 | |||
722 | if (bdstatus & R_W) | ||
723 | ep->e_rxbd = ep->rxbase; | ||
724 | else | ||
725 | ep->e_rxbd++; | ||
726 | } | ||
727 | |||
728 | static void recycle_rxbds(struct qe_ep *ep, unsigned char stopatnext) | ||
729 | { | ||
730 | u32 bdstatus; | ||
731 | struct qe_bd __iomem *bd, *nextbd; | ||
732 | unsigned char stop = 0; | ||
733 | |||
734 | nextbd = ep->n_rxbd; | ||
735 | bd = ep->e_rxbd; | ||
736 | bdstatus = in_be32((u32 __iomem *)bd); | ||
737 | |||
738 | while (!(bdstatus & R_E) && !(bdstatus & BD_LENGTH_MASK) && !stop) { | ||
739 | bdstatus = R_E | R_I | (bdstatus & R_W); | ||
740 | out_be32((u32 __iomem *)bd, bdstatus); | ||
741 | |||
742 | if (bdstatus & R_W) | ||
743 | bd = ep->rxbase; | ||
744 | else | ||
745 | bd++; | ||
746 | |||
747 | bdstatus = in_be32((u32 __iomem *)bd); | ||
748 | if (stopatnext && (bd == nextbd)) | ||
749 | stop = 1; | ||
750 | } | ||
751 | |||
752 | ep->e_rxbd = bd; | ||
753 | } | ||
754 | |||
755 | static void ep_recycle_rxbds(struct qe_ep *ep) | ||
756 | { | ||
757 | struct qe_bd __iomem *bd = ep->n_rxbd; | ||
758 | u32 bdstatus; | ||
759 | u8 epnum = ep->epnum; | ||
760 | struct qe_udc *udc = ep->udc; | ||
761 | |||
762 | bdstatus = in_be32((u32 __iomem *)bd); | ||
763 | if (!(bdstatus & R_E) && !(bdstatus & BD_LENGTH_MASK)) { | ||
764 | bd = ep->rxbase + | ||
765 | ((in_be16(&udc->ep_param[epnum]->rbptr) - | ||
766 | in_be16(&udc->ep_param[epnum]->rbase)) | ||
767 | >> 3); | ||
768 | bdstatus = in_be32((u32 __iomem *)bd); | ||
769 | |||
770 | if (bdstatus & R_W) | ||
771 | bd = ep->rxbase; | ||
772 | else | ||
773 | bd++; | ||
774 | |||
775 | ep->e_rxbd = bd; | ||
776 | recycle_rxbds(ep, 0); | ||
777 | ep->e_rxbd = ep->n_rxbd; | ||
778 | } else | ||
779 | recycle_rxbds(ep, 1); | ||
780 | |||
781 | if (in_be16(&udc->usb_regs->usb_usber) & USB_E_BSY_MASK) | ||
782 | out_be16(&udc->usb_regs->usb_usber, USB_E_BSY_MASK); | ||
783 | |||
784 | if (ep->has_data <= 0 && (!list_empty(&ep->queue))) | ||
785 | qe_eprx_normal(ep); | ||
786 | |||
787 | ep->localnack = 0; | ||
788 | } | ||
789 | |||
790 | static void setup_received_handle(struct qe_udc *udc, | ||
791 | struct usb_ctrlrequest *setup); | ||
792 | static int qe_ep_rxframe_handle(struct qe_ep *ep); | ||
793 | static void ep0_req_complete(struct qe_udc *udc, struct qe_req *req); | ||
794 | /* when BD PID is setup, handle the packet */ | ||
795 | static int ep0_setup_handle(struct qe_udc *udc) | ||
796 | { | ||
797 | struct qe_ep *ep = &udc->eps[0]; | ||
798 | struct qe_frame *pframe; | ||
799 | unsigned int fsize; | ||
800 | u8 *cp; | ||
801 | |||
802 | pframe = ep->rxframe; | ||
803 | if ((frame_get_info(pframe) & PID_SETUP) | ||
804 | && (udc->ep0_state == WAIT_FOR_SETUP)) { | ||
805 | fsize = frame_get_length(pframe); | ||
806 | if (unlikely(fsize != 8)) | ||
807 | return -EINVAL; | ||
808 | cp = (u8 *)&udc->local_setup_buff; | ||
809 | memcpy(cp, pframe->data, fsize); | ||
810 | ep->data01 = 1; | ||
811 | |||
812 | /* handle the usb command base on the usb_ctrlrequest */ | ||
813 | setup_received_handle(udc, &udc->local_setup_buff); | ||
814 | return 0; | ||
815 | } | ||
816 | return -EINVAL; | ||
817 | } | ||
818 | |||
819 | static int qe_ep0_rx(struct qe_udc *udc) | ||
820 | { | ||
821 | struct qe_ep *ep = &udc->eps[0]; | ||
822 | struct qe_frame *pframe; | ||
823 | struct qe_bd __iomem *bd; | ||
824 | u32 bdstatus, length; | ||
825 | u32 vaddr; | ||
826 | |||
827 | pframe = ep->rxframe; | ||
828 | |||
829 | if (ep->dir == USB_DIR_IN) { | ||
830 | dev_err(udc->dev, "ep0 not a control endpoint\n"); | ||
831 | return -EINVAL; | ||
832 | } | ||
833 | |||
834 | bd = ep->n_rxbd; | ||
835 | bdstatus = in_be32((u32 __iomem *)bd); | ||
836 | length = bdstatus & BD_LENGTH_MASK; | ||
837 | |||
838 | while (!(bdstatus & R_E) && length) { | ||
839 | if ((bdstatus & R_F) && (bdstatus & R_L) | ||
840 | && !(bdstatus & R_ERROR)) { | ||
841 | if (length == USB_CRC_SIZE) { | ||
842 | udc->ep0_state = WAIT_FOR_SETUP; | ||
843 | dev_vdbg(udc->dev, | ||
844 | "receive a ZLP in status phase\n"); | ||
845 | } else { | ||
846 | qe_frame_clean(pframe); | ||
847 | vaddr = (u32)phys_to_virt(in_be32(&bd->buf)); | ||
848 | frame_set_data(pframe, (u8 *)vaddr); | ||
849 | frame_set_length(pframe, | ||
850 | (length - USB_CRC_SIZE)); | ||
851 | frame_set_status(pframe, FRAME_OK); | ||
852 | switch (bdstatus & R_PID) { | ||
853 | case R_PID_SETUP: | ||
854 | frame_set_info(pframe, PID_SETUP); | ||
855 | break; | ||
856 | case R_PID_DATA1: | ||
857 | frame_set_info(pframe, PID_DATA1); | ||
858 | break; | ||
859 | default: | ||
860 | frame_set_info(pframe, PID_DATA0); | ||
861 | break; | ||
862 | } | ||
863 | |||
864 | if ((bdstatus & R_PID) == R_PID_SETUP) | ||
865 | ep0_setup_handle(udc); | ||
866 | else | ||
867 | qe_ep_rxframe_handle(ep); | ||
868 | } | ||
869 | } else { | ||
870 | dev_err(udc->dev, "The receive frame with error!\n"); | ||
871 | } | ||
872 | |||
873 | /* note: don't clear the rxbd's buffer address */ | ||
874 | recycle_one_rxbd(ep); | ||
875 | |||
876 | /* Get next BD */ | ||
877 | if (bdstatus & R_W) | ||
878 | bd = ep->rxbase; | ||
879 | else | ||
880 | bd++; | ||
881 | |||
882 | bdstatus = in_be32((u32 __iomem *)bd); | ||
883 | length = bdstatus & BD_LENGTH_MASK; | ||
884 | |||
885 | } | ||
886 | |||
887 | ep->n_rxbd = bd; | ||
888 | |||
889 | return 0; | ||
890 | } | ||
891 | |||
892 | static int qe_ep_rxframe_handle(struct qe_ep *ep) | ||
893 | { | ||
894 | struct qe_frame *pframe; | ||
895 | u8 framepid = 0; | ||
896 | unsigned int fsize; | ||
897 | u8 *cp; | ||
898 | struct qe_req *req; | ||
899 | |||
900 | pframe = ep->rxframe; | ||
901 | |||
902 | if (frame_get_info(pframe) & PID_DATA1) | ||
903 | framepid = 0x1; | ||
904 | |||
905 | if (framepid != ep->data01) { | ||
906 | dev_err(ep->udc->dev, "the data01 error!\n"); | ||
907 | return -EIO; | ||
908 | } | ||
909 | |||
910 | fsize = frame_get_length(pframe); | ||
911 | if (list_empty(&ep->queue)) { | ||
912 | dev_err(ep->udc->dev, "the %s have no requeue!\n", ep->name); | ||
913 | } else { | ||
914 | req = list_entry(ep->queue.next, struct qe_req, queue); | ||
915 | |||
916 | cp = (u8 *)(req->req.buf) + req->req.actual; | ||
917 | if (cp) { | ||
918 | memcpy(cp, pframe->data, fsize); | ||
919 | req->req.actual += fsize; | ||
920 | if ((fsize < ep->ep.maxpacket) || | ||
921 | (req->req.actual >= req->req.length)) { | ||
922 | if (ep->epnum == 0) | ||
923 | ep0_req_complete(ep->udc, req); | ||
924 | else | ||
925 | done(ep, req, 0); | ||
926 | if (list_empty(&ep->queue) && ep->epnum != 0) | ||
927 | qe_eprx_nack(ep); | ||
928 | } | ||
929 | } | ||
930 | } | ||
931 | |||
932 | qe_ep_toggledata01(ep); | ||
933 | |||
934 | return 0; | ||
935 | } | ||
936 | |||
937 | static void ep_rx_tasklet(unsigned long data) | ||
938 | { | ||
939 | struct qe_udc *udc = (struct qe_udc *)data; | ||
940 | struct qe_ep *ep; | ||
941 | struct qe_frame *pframe; | ||
942 | struct qe_bd __iomem *bd; | ||
943 | unsigned long flags; | ||
944 | u32 bdstatus, length; | ||
945 | u32 vaddr, i; | ||
946 | |||
947 | spin_lock_irqsave(&udc->lock, flags); | ||
948 | |||
949 | for (i = 1; i < USB_MAX_ENDPOINTS; i++) { | ||
950 | ep = &udc->eps[i]; | ||
951 | |||
952 | if (ep->dir == USB_DIR_IN || ep->enable_tasklet == 0) { | ||
953 | dev_dbg(udc->dev, | ||
954 | "This is a transmit ep or disable tasklet!\n"); | ||
955 | continue; | ||
956 | } | ||
957 | |||
958 | pframe = ep->rxframe; | ||
959 | bd = ep->n_rxbd; | ||
960 | bdstatus = in_be32((u32 __iomem *)bd); | ||
961 | length = bdstatus & BD_LENGTH_MASK; | ||
962 | |||
963 | while (!(bdstatus & R_E) && length) { | ||
964 | if (list_empty(&ep->queue)) { | ||
965 | qe_eprx_nack(ep); | ||
966 | dev_dbg(udc->dev, | ||
967 | "The rxep have noreq %d\n", | ||
968 | ep->has_data); | ||
969 | break; | ||
970 | } | ||
971 | |||
972 | if ((bdstatus & R_F) && (bdstatus & R_L) | ||
973 | && !(bdstatus & R_ERROR)) { | ||
974 | qe_frame_clean(pframe); | ||
975 | vaddr = (u32)phys_to_virt(in_be32(&bd->buf)); | ||
976 | frame_set_data(pframe, (u8 *)vaddr); | ||
977 | frame_set_length(pframe, | ||
978 | (length - USB_CRC_SIZE)); | ||
979 | frame_set_status(pframe, FRAME_OK); | ||
980 | switch (bdstatus & R_PID) { | ||
981 | case R_PID_DATA1: | ||
982 | frame_set_info(pframe, PID_DATA1); | ||
983 | break; | ||
984 | case R_PID_SETUP: | ||
985 | frame_set_info(pframe, PID_SETUP); | ||
986 | break; | ||
987 | default: | ||
988 | frame_set_info(pframe, PID_DATA0); | ||
989 | break; | ||
990 | } | ||
991 | /* handle the rx frame */ | ||
992 | qe_ep_rxframe_handle(ep); | ||
993 | } else { | ||
994 | dev_err(udc->dev, | ||
995 | "error in received frame\n"); | ||
996 | } | ||
997 | /* note: don't clear the rxbd's buffer address */ | ||
998 | /*clear the length */ | ||
999 | out_be32((u32 __iomem *)bd, bdstatus & BD_STATUS_MASK); | ||
1000 | ep->has_data--; | ||
1001 | if (!(ep->localnack)) | ||
1002 | recycle_one_rxbd(ep); | ||
1003 | |||
1004 | /* Get next BD */ | ||
1005 | if (bdstatus & R_W) | ||
1006 | bd = ep->rxbase; | ||
1007 | else | ||
1008 | bd++; | ||
1009 | |||
1010 | bdstatus = in_be32((u32 __iomem *)bd); | ||
1011 | length = bdstatus & BD_LENGTH_MASK; | ||
1012 | } | ||
1013 | |||
1014 | ep->n_rxbd = bd; | ||
1015 | |||
1016 | if (ep->localnack) | ||
1017 | ep_recycle_rxbds(ep); | ||
1018 | |||
1019 | ep->enable_tasklet = 0; | ||
1020 | } /* for i=1 */ | ||
1021 | |||
1022 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1023 | } | ||
1024 | |||
1025 | static int qe_ep_rx(struct qe_ep *ep) | ||
1026 | { | ||
1027 | struct qe_udc *udc; | ||
1028 | struct qe_frame *pframe; | ||
1029 | struct qe_bd __iomem *bd; | ||
1030 | u16 swoffs, ucoffs, emptybds; | ||
1031 | |||
1032 | udc = ep->udc; | ||
1033 | pframe = ep->rxframe; | ||
1034 | |||
1035 | if (ep->dir == USB_DIR_IN) { | ||
1036 | dev_err(udc->dev, "transmit ep in rx function\n"); | ||
1037 | return -EINVAL; | ||
1038 | } | ||
1039 | |||
1040 | bd = ep->n_rxbd; | ||
1041 | |||
1042 | swoffs = (u16)(bd - ep->rxbase); | ||
1043 | ucoffs = (u16)((in_be16(&udc->ep_param[ep->epnum]->rbptr) - | ||
1044 | in_be16(&udc->ep_param[ep->epnum]->rbase)) >> 3); | ||
1045 | if (swoffs < ucoffs) | ||
1046 | emptybds = USB_BDRING_LEN_RX - ucoffs + swoffs; | ||
1047 | else | ||
1048 | emptybds = swoffs - ucoffs; | ||
1049 | |||
1050 | if (emptybds < MIN_EMPTY_BDS) { | ||
1051 | qe_eprx_nack(ep); | ||
1052 | ep->localnack = 1; | ||
1053 | dev_vdbg(udc->dev, "%d empty bds, send NACK\n", emptybds); | ||
1054 | } | ||
1055 | ep->has_data = USB_BDRING_LEN_RX - emptybds; | ||
1056 | |||
1057 | if (list_empty(&ep->queue)) { | ||
1058 | qe_eprx_nack(ep); | ||
1059 | dev_vdbg(udc->dev, "The rxep have no req queued with %d BDs\n", | ||
1060 | ep->has_data); | ||
1061 | return 0; | ||
1062 | } | ||
1063 | |||
1064 | tasklet_schedule(&udc->rx_tasklet); | ||
1065 | ep->enable_tasklet = 1; | ||
1066 | |||
1067 | return 0; | ||
1068 | } | ||
1069 | |||
1070 | /* send data from a frame, no matter what tx_req */ | ||
1071 | static int qe_ep_tx(struct qe_ep *ep, struct qe_frame *frame) | ||
1072 | { | ||
1073 | struct qe_udc *udc = ep->udc; | ||
1074 | struct qe_bd __iomem *bd; | ||
1075 | u16 saveusbmr; | ||
1076 | u32 bdstatus, pidmask; | ||
1077 | u32 paddr; | ||
1078 | |||
1079 | if (ep->dir == USB_DIR_OUT) { | ||
1080 | dev_err(udc->dev, "receive ep passed to tx function\n"); | ||
1081 | return -EINVAL; | ||
1082 | } | ||
1083 | |||
1084 | /* Disable the Tx interrupt */ | ||
1085 | saveusbmr = in_be16(&udc->usb_regs->usb_usbmr); | ||
1086 | out_be16(&udc->usb_regs->usb_usbmr, | ||
1087 | saveusbmr & ~(USB_E_TXB_MASK | USB_E_TXE_MASK)); | ||
1088 | |||
1089 | bd = ep->n_txbd; | ||
1090 | bdstatus = in_be32((u32 __iomem *)bd); | ||
1091 | |||
1092 | if (!(bdstatus & (T_R | BD_LENGTH_MASK))) { | ||
1093 | if (frame_get_length(frame) == 0) { | ||
1094 | frame_set_data(frame, udc->nullbuf); | ||
1095 | frame_set_length(frame, 2); | ||
1096 | frame->info |= (ZLP | NO_CRC); | ||
1097 | dev_vdbg(udc->dev, "the frame size = 0\n"); | ||
1098 | } | ||
1099 | paddr = virt_to_phys((void *)frame->data); | ||
1100 | out_be32(&bd->buf, paddr); | ||
1101 | bdstatus = (bdstatus&T_W); | ||
1102 | if (!(frame_get_info(frame) & NO_CRC)) | ||
1103 | bdstatus |= T_R | T_I | T_L | T_TC | ||
1104 | | frame_get_length(frame); | ||
1105 | else | ||
1106 | bdstatus |= T_R | T_I | T_L | frame_get_length(frame); | ||
1107 | |||
1108 | /* if the packet is a ZLP in status phase */ | ||
1109 | if ((ep->epnum == 0) && (udc->ep0_state == DATA_STATE_NEED_ZLP)) | ||
1110 | ep->data01 = 0x1; | ||
1111 | |||
1112 | if (ep->data01) { | ||
1113 | pidmask = T_PID_DATA1; | ||
1114 | frame->info |= PID_DATA1; | ||
1115 | } else { | ||
1116 | pidmask = T_PID_DATA0; | ||
1117 | frame->info |= PID_DATA0; | ||
1118 | } | ||
1119 | bdstatus |= T_CNF; | ||
1120 | bdstatus |= pidmask; | ||
1121 | out_be32((u32 __iomem *)bd, bdstatus); | ||
1122 | qe_ep_filltxfifo(ep); | ||
1123 | |||
1124 | /* enable the TX interrupt */ | ||
1125 | out_be16(&udc->usb_regs->usb_usbmr, saveusbmr); | ||
1126 | |||
1127 | qe_ep_toggledata01(ep); | ||
1128 | if (bdstatus & T_W) | ||
1129 | ep->n_txbd = ep->txbase; | ||
1130 | else | ||
1131 | ep->n_txbd++; | ||
1132 | |||
1133 | return 0; | ||
1134 | } else { | ||
1135 | out_be16(&udc->usb_regs->usb_usbmr, saveusbmr); | ||
1136 | dev_vdbg(udc->dev, "The tx bd is not ready!\n"); | ||
1137 | return -EBUSY; | ||
1138 | } | ||
1139 | } | ||
1140 | |||
1141 | /* when a bd was transmitted, the function can | ||
1142 | * handle the tx_req, not include ep0 */ | ||
1143 | static int txcomplete(struct qe_ep *ep, unsigned char restart) | ||
1144 | { | ||
1145 | if (ep->tx_req != NULL) { | ||
1146 | if (!restart) { | ||
1147 | int asent = ep->last; | ||
1148 | ep->sent += asent; | ||
1149 | ep->last -= asent; | ||
1150 | } else { | ||
1151 | ep->last = 0; | ||
1152 | } | ||
1153 | |||
1154 | /* a request already were transmitted completely */ | ||
1155 | if ((ep->tx_req->req.length - ep->sent) <= 0) { | ||
1156 | ep->tx_req->req.actual = (unsigned int)ep->sent; | ||
1157 | done(ep, ep->tx_req, 0); | ||
1158 | ep->tx_req = NULL; | ||
1159 | ep->last = 0; | ||
1160 | ep->sent = 0; | ||
1161 | } | ||
1162 | } | ||
1163 | |||
1164 | /* we should gain a new tx_req fot this endpoint */ | ||
1165 | if (ep->tx_req == NULL) { | ||
1166 | if (!list_empty(&ep->queue)) { | ||
1167 | ep->tx_req = list_entry(ep->queue.next, struct qe_req, | ||
1168 | queue); | ||
1169 | ep->last = 0; | ||
1170 | ep->sent = 0; | ||
1171 | } | ||
1172 | } | ||
1173 | |||
1174 | return 0; | ||
1175 | } | ||
1176 | |||
1177 | /* give a frame and a tx_req, send some data */ | ||
1178 | static int qe_usb_senddata(struct qe_ep *ep, struct qe_frame *frame) | ||
1179 | { | ||
1180 | unsigned int size; | ||
1181 | u8 *buf; | ||
1182 | |||
1183 | qe_frame_clean(frame); | ||
1184 | size = min_t(u32, (ep->tx_req->req.length - ep->sent), | ||
1185 | ep->ep.maxpacket); | ||
1186 | buf = (u8 *)ep->tx_req->req.buf + ep->sent; | ||
1187 | if (buf && size) { | ||
1188 | ep->last = size; | ||
1189 | frame_set_data(frame, buf); | ||
1190 | frame_set_length(frame, size); | ||
1191 | frame_set_status(frame, FRAME_OK); | ||
1192 | frame_set_info(frame, 0); | ||
1193 | return qe_ep_tx(ep, frame); | ||
1194 | } | ||
1195 | return -EIO; | ||
1196 | } | ||
1197 | |||
1198 | /* give a frame struct,send a ZLP */ | ||
1199 | static int sendnulldata(struct qe_ep *ep, struct qe_frame *frame, uint infor) | ||
1200 | { | ||
1201 | struct qe_udc *udc = ep->udc; | ||
1202 | |||
1203 | if (frame == NULL) | ||
1204 | return -ENODEV; | ||
1205 | |||
1206 | qe_frame_clean(frame); | ||
1207 | frame_set_data(frame, (u8 *)udc->nullbuf); | ||
1208 | frame_set_length(frame, 2); | ||
1209 | frame_set_status(frame, FRAME_OK); | ||
1210 | frame_set_info(frame, (ZLP | NO_CRC | infor)); | ||
1211 | |||
1212 | return qe_ep_tx(ep, frame); | ||
1213 | } | ||
1214 | |||
1215 | static int frame_create_tx(struct qe_ep *ep, struct qe_frame *frame) | ||
1216 | { | ||
1217 | struct qe_req *req = ep->tx_req; | ||
1218 | int reval; | ||
1219 | |||
1220 | if (req == NULL) | ||
1221 | return -ENODEV; | ||
1222 | |||
1223 | if ((req->req.length - ep->sent) > 0) | ||
1224 | reval = qe_usb_senddata(ep, frame); | ||
1225 | else | ||
1226 | reval = sendnulldata(ep, frame, 0); | ||
1227 | |||
1228 | return reval; | ||
1229 | } | ||
1230 | |||
1231 | /* if direction is DIR_IN, the status is Device->Host | ||
1232 | * if direction is DIR_OUT, the status transaction is Device<-Host | ||
1233 | * in status phase, udc create a request and gain status */ | ||
1234 | static int ep0_prime_status(struct qe_udc *udc, int direction) | ||
1235 | { | ||
1236 | |||
1237 | struct qe_ep *ep = &udc->eps[0]; | ||
1238 | |||
1239 | if (direction == USB_DIR_IN) { | ||
1240 | udc->ep0_state = DATA_STATE_NEED_ZLP; | ||
1241 | udc->ep0_dir = USB_DIR_IN; | ||
1242 | sendnulldata(ep, ep->txframe, SETUP_STATUS | NO_REQ); | ||
1243 | } else { | ||
1244 | udc->ep0_dir = USB_DIR_OUT; | ||
1245 | udc->ep0_state = WAIT_FOR_OUT_STATUS; | ||
1246 | } | ||
1247 | |||
1248 | return 0; | ||
1249 | } | ||
1250 | |||
1251 | /* a request complete in ep0, whether gadget request or udc request */ | ||
1252 | static void ep0_req_complete(struct qe_udc *udc, struct qe_req *req) | ||
1253 | { | ||
1254 | struct qe_ep *ep = &udc->eps[0]; | ||
1255 | /* because usb and ep's status already been set in ch9setaddress() */ | ||
1256 | |||
1257 | switch (udc->ep0_state) { | ||
1258 | case DATA_STATE_XMIT: | ||
1259 | done(ep, req, 0); | ||
1260 | /* receive status phase */ | ||
1261 | if (ep0_prime_status(udc, USB_DIR_OUT)) | ||
1262 | qe_ep0_stall(udc); | ||
1263 | break; | ||
1264 | |||
1265 | case DATA_STATE_NEED_ZLP: | ||
1266 | done(ep, req, 0); | ||
1267 | udc->ep0_state = WAIT_FOR_SETUP; | ||
1268 | break; | ||
1269 | |||
1270 | case DATA_STATE_RECV: | ||
1271 | done(ep, req, 0); | ||
1272 | /* send status phase */ | ||
1273 | if (ep0_prime_status(udc, USB_DIR_IN)) | ||
1274 | qe_ep0_stall(udc); | ||
1275 | break; | ||
1276 | |||
1277 | case WAIT_FOR_OUT_STATUS: | ||
1278 | done(ep, req, 0); | ||
1279 | udc->ep0_state = WAIT_FOR_SETUP; | ||
1280 | break; | ||
1281 | |||
1282 | case WAIT_FOR_SETUP: | ||
1283 | dev_vdbg(udc->dev, "Unexpected interrupt\n"); | ||
1284 | break; | ||
1285 | |||
1286 | default: | ||
1287 | qe_ep0_stall(udc); | ||
1288 | break; | ||
1289 | } | ||
1290 | } | ||
1291 | |||
1292 | static int ep0_txcomplete(struct qe_ep *ep, unsigned char restart) | ||
1293 | { | ||
1294 | struct qe_req *tx_req = NULL; | ||
1295 | struct qe_frame *frame = ep->txframe; | ||
1296 | |||
1297 | if ((frame_get_info(frame) & (ZLP | NO_REQ)) == (ZLP | NO_REQ)) { | ||
1298 | if (!restart) | ||
1299 | ep->udc->ep0_state = WAIT_FOR_SETUP; | ||
1300 | else | ||
1301 | sendnulldata(ep, ep->txframe, SETUP_STATUS | NO_REQ); | ||
1302 | return 0; | ||
1303 | } | ||
1304 | |||
1305 | tx_req = ep->tx_req; | ||
1306 | if (tx_req != NULL) { | ||
1307 | if (!restart) { | ||
1308 | int asent = ep->last; | ||
1309 | ep->sent += asent; | ||
1310 | ep->last -= asent; | ||
1311 | } else { | ||
1312 | ep->last = 0; | ||
1313 | } | ||
1314 | |||
1315 | /* a request already were transmitted completely */ | ||
1316 | if ((ep->tx_req->req.length - ep->sent) <= 0) { | ||
1317 | ep->tx_req->req.actual = (unsigned int)ep->sent; | ||
1318 | ep0_req_complete(ep->udc, ep->tx_req); | ||
1319 | ep->tx_req = NULL; | ||
1320 | ep->last = 0; | ||
1321 | ep->sent = 0; | ||
1322 | } | ||
1323 | } else { | ||
1324 | dev_vdbg(ep->udc->dev, "the ep0_controller have no req\n"); | ||
1325 | } | ||
1326 | |||
1327 | return 0; | ||
1328 | } | ||
1329 | |||
1330 | static int ep0_txframe_handle(struct qe_ep *ep) | ||
1331 | { | ||
1332 | /* if have error, transmit again */ | ||
1333 | if (frame_get_status(ep->txframe) & FRAME_ERROR) { | ||
1334 | qe_ep_flushtxfifo(ep); | ||
1335 | dev_vdbg(ep->udc->dev, "The EP0 transmit data have error!\n"); | ||
1336 | if (frame_get_info(ep->txframe) & PID_DATA0) | ||
1337 | ep->data01 = 0; | ||
1338 | else | ||
1339 | ep->data01 = 1; | ||
1340 | |||
1341 | ep0_txcomplete(ep, 1); | ||
1342 | } else | ||
1343 | ep0_txcomplete(ep, 0); | ||
1344 | |||
1345 | frame_create_tx(ep, ep->txframe); | ||
1346 | return 0; | ||
1347 | } | ||
1348 | |||
1349 | static int qe_ep0_txconf(struct qe_ep *ep) | ||
1350 | { | ||
1351 | struct qe_bd __iomem *bd; | ||
1352 | struct qe_frame *pframe; | ||
1353 | u32 bdstatus; | ||
1354 | |||
1355 | bd = ep->c_txbd; | ||
1356 | bdstatus = in_be32((u32 __iomem *)bd); | ||
1357 | while (!(bdstatus & T_R) && (bdstatus & ~T_W)) { | ||
1358 | pframe = ep->txframe; | ||
1359 | |||
1360 | /* clear and recycle the BD */ | ||
1361 | out_be32((u32 __iomem *)bd, bdstatus & T_W); | ||
1362 | out_be32(&bd->buf, 0); | ||
1363 | if (bdstatus & T_W) | ||
1364 | ep->c_txbd = ep->txbase; | ||
1365 | else | ||
1366 | ep->c_txbd++; | ||
1367 | |||
1368 | if (ep->c_txbd == ep->n_txbd) { | ||
1369 | if (bdstatus & DEVICE_T_ERROR) { | ||
1370 | frame_set_status(pframe, FRAME_ERROR); | ||
1371 | if (bdstatus & T_TO) | ||
1372 | pframe->status |= TX_ER_TIMEOUT; | ||
1373 | if (bdstatus & T_UN) | ||
1374 | pframe->status |= TX_ER_UNDERUN; | ||
1375 | } | ||
1376 | ep0_txframe_handle(ep); | ||
1377 | } | ||
1378 | |||
1379 | bd = ep->c_txbd; | ||
1380 | bdstatus = in_be32((u32 __iomem *)bd); | ||
1381 | } | ||
1382 | |||
1383 | return 0; | ||
1384 | } | ||
1385 | |||
1386 | static int ep_txframe_handle(struct qe_ep *ep) | ||
1387 | { | ||
1388 | if (frame_get_status(ep->txframe) & FRAME_ERROR) { | ||
1389 | qe_ep_flushtxfifo(ep); | ||
1390 | dev_vdbg(ep->udc->dev, "The EP0 transmit data have error!\n"); | ||
1391 | if (frame_get_info(ep->txframe) & PID_DATA0) | ||
1392 | ep->data01 = 0; | ||
1393 | else | ||
1394 | ep->data01 = 1; | ||
1395 | |||
1396 | txcomplete(ep, 1); | ||
1397 | } else | ||
1398 | txcomplete(ep, 0); | ||
1399 | |||
1400 | frame_create_tx(ep, ep->txframe); /* send the data */ | ||
1401 | return 0; | ||
1402 | } | ||
1403 | |||
1404 | /* confirm the already trainsmited bd */ | ||
1405 | static int qe_ep_txconf(struct qe_ep *ep) | ||
1406 | { | ||
1407 | struct qe_bd __iomem *bd; | ||
1408 | struct qe_frame *pframe = NULL; | ||
1409 | u32 bdstatus; | ||
1410 | unsigned char breakonrxinterrupt = 0; | ||
1411 | |||
1412 | bd = ep->c_txbd; | ||
1413 | bdstatus = in_be32((u32 __iomem *)bd); | ||
1414 | while (!(bdstatus & T_R) && (bdstatus & ~T_W)) { | ||
1415 | pframe = ep->txframe; | ||
1416 | if (bdstatus & DEVICE_T_ERROR) { | ||
1417 | frame_set_status(pframe, FRAME_ERROR); | ||
1418 | if (bdstatus & T_TO) | ||
1419 | pframe->status |= TX_ER_TIMEOUT; | ||
1420 | if (bdstatus & T_UN) | ||
1421 | pframe->status |= TX_ER_UNDERUN; | ||
1422 | } | ||
1423 | |||
1424 | /* clear and recycle the BD */ | ||
1425 | out_be32((u32 __iomem *)bd, bdstatus & T_W); | ||
1426 | out_be32(&bd->buf, 0); | ||
1427 | if (bdstatus & T_W) | ||
1428 | ep->c_txbd = ep->txbase; | ||
1429 | else | ||
1430 | ep->c_txbd++; | ||
1431 | |||
1432 | /* handle the tx frame */ | ||
1433 | ep_txframe_handle(ep); | ||
1434 | bd = ep->c_txbd; | ||
1435 | bdstatus = in_be32((u32 __iomem *)bd); | ||
1436 | } | ||
1437 | if (breakonrxinterrupt) | ||
1438 | return -EIO; | ||
1439 | else | ||
1440 | return 0; | ||
1441 | } | ||
1442 | |||
1443 | /* Add a request in queue, and try to transmit a packet */ | ||
1444 | static int ep_req_send(struct qe_ep *ep, struct qe_req *req) | ||
1445 | { | ||
1446 | int reval = 0; | ||
1447 | |||
1448 | if (ep->tx_req == NULL) { | ||
1449 | ep->sent = 0; | ||
1450 | ep->last = 0; | ||
1451 | txcomplete(ep, 0); /* can gain a new tx_req */ | ||
1452 | reval = frame_create_tx(ep, ep->txframe); | ||
1453 | } | ||
1454 | return reval; | ||
1455 | } | ||
1456 | |||
1457 | /* Maybe this is a good ideal */ | ||
1458 | static int ep_req_rx(struct qe_ep *ep, struct qe_req *req) | ||
1459 | { | ||
1460 | struct qe_udc *udc = ep->udc; | ||
1461 | struct qe_frame *pframe = NULL; | ||
1462 | struct qe_bd __iomem *bd; | ||
1463 | u32 bdstatus, length; | ||
1464 | u32 vaddr, fsize; | ||
1465 | u8 *cp; | ||
1466 | u8 finish_req = 0; | ||
1467 | u8 framepid; | ||
1468 | |||
1469 | if (list_empty(&ep->queue)) { | ||
1470 | dev_vdbg(udc->dev, "the req already finish!\n"); | ||
1471 | return 0; | ||
1472 | } | ||
1473 | pframe = ep->rxframe; | ||
1474 | |||
1475 | bd = ep->n_rxbd; | ||
1476 | bdstatus = in_be32((u32 __iomem *)bd); | ||
1477 | length = bdstatus & BD_LENGTH_MASK; | ||
1478 | |||
1479 | while (!(bdstatus & R_E) && length) { | ||
1480 | if (finish_req) | ||
1481 | break; | ||
1482 | if ((bdstatus & R_F) && (bdstatus & R_L) | ||
1483 | && !(bdstatus & R_ERROR)) { | ||
1484 | qe_frame_clean(pframe); | ||
1485 | vaddr = (u32)phys_to_virt(in_be32(&bd->buf)); | ||
1486 | frame_set_data(pframe, (u8 *)vaddr); | ||
1487 | frame_set_length(pframe, (length - USB_CRC_SIZE)); | ||
1488 | frame_set_status(pframe, FRAME_OK); | ||
1489 | switch (bdstatus & R_PID) { | ||
1490 | case R_PID_DATA1: | ||
1491 | frame_set_info(pframe, PID_DATA1); break; | ||
1492 | default: | ||
1493 | frame_set_info(pframe, PID_DATA0); break; | ||
1494 | } | ||
1495 | /* handle the rx frame */ | ||
1496 | |||
1497 | if (frame_get_info(pframe) & PID_DATA1) | ||
1498 | framepid = 0x1; | ||
1499 | else | ||
1500 | framepid = 0; | ||
1501 | |||
1502 | if (framepid != ep->data01) { | ||
1503 | dev_vdbg(udc->dev, "the data01 error!\n"); | ||
1504 | } else { | ||
1505 | fsize = frame_get_length(pframe); | ||
1506 | |||
1507 | cp = (u8 *)(req->req.buf) + req->req.actual; | ||
1508 | if (cp) { | ||
1509 | memcpy(cp, pframe->data, fsize); | ||
1510 | req->req.actual += fsize; | ||
1511 | if ((fsize < ep->ep.maxpacket) | ||
1512 | || (req->req.actual >= | ||
1513 | req->req.length)) { | ||
1514 | finish_req = 1; | ||
1515 | done(ep, req, 0); | ||
1516 | if (list_empty(&ep->queue)) | ||
1517 | qe_eprx_nack(ep); | ||
1518 | } | ||
1519 | } | ||
1520 | qe_ep_toggledata01(ep); | ||
1521 | } | ||
1522 | } else { | ||
1523 | dev_err(udc->dev, "The receive frame with error!\n"); | ||
1524 | } | ||
1525 | |||
1526 | /* note: don't clear the rxbd's buffer address * | ||
1527 | * only Clear the length */ | ||
1528 | out_be32((u32 __iomem *)bd, (bdstatus & BD_STATUS_MASK)); | ||
1529 | ep->has_data--; | ||
1530 | |||
1531 | /* Get next BD */ | ||
1532 | if (bdstatus & R_W) | ||
1533 | bd = ep->rxbase; | ||
1534 | else | ||
1535 | bd++; | ||
1536 | |||
1537 | bdstatus = in_be32((u32 __iomem *)bd); | ||
1538 | length = bdstatus & BD_LENGTH_MASK; | ||
1539 | } | ||
1540 | |||
1541 | ep->n_rxbd = bd; | ||
1542 | ep_recycle_rxbds(ep); | ||
1543 | |||
1544 | return 0; | ||
1545 | } | ||
1546 | |||
1547 | /* only add the request in queue */ | ||
1548 | static int ep_req_receive(struct qe_ep *ep, struct qe_req *req) | ||
1549 | { | ||
1550 | if (ep->state == EP_STATE_NACK) { | ||
1551 | if (ep->has_data <= 0) { | ||
1552 | /* Enable rx and unmask rx interrupt */ | ||
1553 | qe_eprx_normal(ep); | ||
1554 | } else { | ||
1555 | /* Copy the exist BD data */ | ||
1556 | ep_req_rx(ep, req); | ||
1557 | } | ||
1558 | } | ||
1559 | |||
1560 | return 0; | ||
1561 | } | ||
1562 | |||
1563 | /******************************************************************** | ||
1564 | Internal Used Function End | ||
1565 | ********************************************************************/ | ||
1566 | |||
1567 | /*----------------------------------------------------------------------- | ||
1568 | Endpoint Management Functions For Gadget | ||
1569 | -----------------------------------------------------------------------*/ | ||
1570 | static int qe_ep_enable(struct usb_ep *_ep, | ||
1571 | const struct usb_endpoint_descriptor *desc) | ||
1572 | { | ||
1573 | struct qe_udc *udc; | ||
1574 | struct qe_ep *ep; | ||
1575 | int retval = 0; | ||
1576 | unsigned char epnum; | ||
1577 | |||
1578 | ep = container_of(_ep, struct qe_ep, ep); | ||
1579 | |||
1580 | /* catch various bogus parameters */ | ||
1581 | if (!_ep || !desc || ep->desc || _ep->name == ep_name[0] || | ||
1582 | (desc->bDescriptorType != USB_DT_ENDPOINT)) | ||
1583 | return -EINVAL; | ||
1584 | |||
1585 | udc = ep->udc; | ||
1586 | if (!udc->driver || (udc->gadget.speed == USB_SPEED_UNKNOWN)) | ||
1587 | return -ESHUTDOWN; | ||
1588 | |||
1589 | epnum = (u8)desc->bEndpointAddress & 0xF; | ||
1590 | |||
1591 | retval = qe_ep_init(udc, epnum, desc); | ||
1592 | if (retval != 0) { | ||
1593 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); | ||
1594 | dev_dbg(udc->dev, "enable ep%d failed\n", ep->epnum); | ||
1595 | return -EINVAL; | ||
1596 | } | ||
1597 | dev_dbg(udc->dev, "enable ep%d successful\n", ep->epnum); | ||
1598 | return 0; | ||
1599 | } | ||
1600 | |||
1601 | static int qe_ep_disable(struct usb_ep *_ep) | ||
1602 | { | ||
1603 | struct qe_udc *udc; | ||
1604 | struct qe_ep *ep; | ||
1605 | unsigned long flags; | ||
1606 | unsigned int size; | ||
1607 | |||
1608 | ep = container_of(_ep, struct qe_ep, ep); | ||
1609 | udc = ep->udc; | ||
1610 | |||
1611 | if (!_ep || !ep->desc) { | ||
1612 | dev_dbg(udc->dev, "%s not enabled\n", _ep ? ep->ep.name : NULL); | ||
1613 | return -EINVAL; | ||
1614 | } | ||
1615 | |||
1616 | spin_lock_irqsave(&udc->lock, flags); | ||
1617 | /* Nuke all pending requests (does flush) */ | ||
1618 | nuke(ep, -ESHUTDOWN); | ||
1619 | ep->desc = NULL; | ||
1620 | ep->stopped = 1; | ||
1621 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1622 | |||
1623 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); | ||
1624 | |||
1625 | if (ep->dir == USB_DIR_OUT) | ||
1626 | size = (ep->ep.maxpacket + USB_CRC_SIZE + 2) * | ||
1627 | (USB_BDRING_LEN_RX + 1); | ||
1628 | else | ||
1629 | size = (ep->ep.maxpacket + USB_CRC_SIZE + 2) * | ||
1630 | (USB_BDRING_LEN + 1); | ||
1631 | |||
1632 | if (ep->dir != USB_DIR_IN) { | ||
1633 | kfree(ep->rxframe); | ||
1634 | if (ep->rxbufmap) { | ||
1635 | dma_unmap_single(udc_controller->gadget.dev.parent, | ||
1636 | ep->rxbuf_d, size, | ||
1637 | DMA_FROM_DEVICE); | ||
1638 | ep->rxbuf_d = DMA_ADDR_INVALID; | ||
1639 | } else { | ||
1640 | dma_sync_single_for_cpu( | ||
1641 | udc_controller->gadget.dev.parent, | ||
1642 | ep->rxbuf_d, size, | ||
1643 | DMA_FROM_DEVICE); | ||
1644 | } | ||
1645 | kfree(ep->rxbuffer); | ||
1646 | } | ||
1647 | |||
1648 | if (ep->dir != USB_DIR_OUT) | ||
1649 | kfree(ep->txframe); | ||
1650 | |||
1651 | dev_dbg(udc->dev, "disabled %s OK\n", _ep->name); | ||
1652 | return 0; | ||
1653 | } | ||
1654 | |||
1655 | static struct usb_request *qe_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) | ||
1656 | { | ||
1657 | struct qe_req *req; | ||
1658 | |||
1659 | req = kzalloc(sizeof(*req), gfp_flags); | ||
1660 | if (!req) | ||
1661 | return NULL; | ||
1662 | |||
1663 | req->req.dma = DMA_ADDR_INVALID; | ||
1664 | |||
1665 | INIT_LIST_HEAD(&req->queue); | ||
1666 | |||
1667 | return &req->req; | ||
1668 | } | ||
1669 | |||
1670 | static void qe_free_request(struct usb_ep *_ep, struct usb_request *_req) | ||
1671 | { | ||
1672 | struct qe_req *req; | ||
1673 | |||
1674 | req = container_of(_req, struct qe_req, req); | ||
1675 | |||
1676 | if (_req) | ||
1677 | kfree(req); | ||
1678 | } | ||
1679 | |||
1680 | /* queues (submits) an I/O request to an endpoint */ | ||
1681 | static int qe_ep_queue(struct usb_ep *_ep, struct usb_request *_req, | ||
1682 | gfp_t gfp_flags) | ||
1683 | { | ||
1684 | struct qe_ep *ep = container_of(_ep, struct qe_ep, ep); | ||
1685 | struct qe_req *req = container_of(_req, struct qe_req, req); | ||
1686 | struct qe_udc *udc; | ||
1687 | unsigned long flags; | ||
1688 | int reval; | ||
1689 | |||
1690 | udc = ep->udc; | ||
1691 | /* catch various bogus parameters */ | ||
1692 | if (!_req || !req->req.complete || !req->req.buf | ||
1693 | || !list_empty(&req->queue)) { | ||
1694 | dev_dbg(udc->dev, "bad params\n"); | ||
1695 | return -EINVAL; | ||
1696 | } | ||
1697 | if (!_ep || (!ep->desc && ep_index(ep))) { | ||
1698 | dev_dbg(udc->dev, "bad ep\n"); | ||
1699 | return -EINVAL; | ||
1700 | } | ||
1701 | |||
1702 | if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) | ||
1703 | return -ESHUTDOWN; | ||
1704 | |||
1705 | req->ep = ep; | ||
1706 | |||
1707 | /* map virtual address to hardware */ | ||
1708 | if (req->req.dma == DMA_ADDR_INVALID) { | ||
1709 | req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, | ||
1710 | req->req.buf, | ||
1711 | req->req.length, | ||
1712 | ep_is_in(ep) | ||
1713 | ? DMA_TO_DEVICE : | ||
1714 | DMA_FROM_DEVICE); | ||
1715 | req->mapped = 1; | ||
1716 | } else { | ||
1717 | dma_sync_single_for_device(ep->udc->gadget.dev.parent, | ||
1718 | req->req.dma, req->req.length, | ||
1719 | ep_is_in(ep) | ||
1720 | ? DMA_TO_DEVICE : | ||
1721 | DMA_FROM_DEVICE); | ||
1722 | req->mapped = 0; | ||
1723 | } | ||
1724 | |||
1725 | req->req.status = -EINPROGRESS; | ||
1726 | req->req.actual = 0; | ||
1727 | |||
1728 | list_add_tail(&req->queue, &ep->queue); | ||
1729 | dev_vdbg(udc->dev, "gadget have request in %s! %d\n", | ||
1730 | ep->name, req->req.length); | ||
1731 | spin_lock_irqsave(&udc->lock, flags); | ||
1732 | /* push the request to device */ | ||
1733 | if (ep_is_in(ep)) | ||
1734 | reval = ep_req_send(ep, req); | ||
1735 | |||
1736 | /* EP0 */ | ||
1737 | if (ep_index(ep) == 0 && req->req.length > 0) { | ||
1738 | if (ep_is_in(ep)) | ||
1739 | udc->ep0_state = DATA_STATE_XMIT; | ||
1740 | else | ||
1741 | udc->ep0_state = DATA_STATE_RECV; | ||
1742 | } | ||
1743 | |||
1744 | if (ep->dir == USB_DIR_OUT) | ||
1745 | reval = ep_req_receive(ep, req); | ||
1746 | |||
1747 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1748 | |||
1749 | return 0; | ||
1750 | } | ||
1751 | |||
1752 | /* dequeues (cancels, unlinks) an I/O request from an endpoint */ | ||
1753 | static int qe_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
1754 | { | ||
1755 | struct qe_ep *ep = container_of(_ep, struct qe_ep, ep); | ||
1756 | struct qe_req *req; | ||
1757 | unsigned long flags; | ||
1758 | |||
1759 | if (!_ep || !_req) | ||
1760 | return -EINVAL; | ||
1761 | |||
1762 | spin_lock_irqsave(&ep->udc->lock, flags); | ||
1763 | |||
1764 | /* make sure it's actually queued on this endpoint */ | ||
1765 | list_for_each_entry(req, &ep->queue, queue) { | ||
1766 | if (&req->req == _req) | ||
1767 | break; | ||
1768 | } | ||
1769 | |||
1770 | if (&req->req != _req) { | ||
1771 | spin_unlock_irqrestore(&ep->udc->lock, flags); | ||
1772 | return -EINVAL; | ||
1773 | } | ||
1774 | |||
1775 | done(ep, req, -ECONNRESET); | ||
1776 | |||
1777 | spin_unlock_irqrestore(&ep->udc->lock, flags); | ||
1778 | return 0; | ||
1779 | } | ||
1780 | |||
1781 | /*----------------------------------------------------------------- | ||
1782 | * modify the endpoint halt feature | ||
1783 | * @ep: the non-isochronous endpoint being stalled | ||
1784 | * @value: 1--set halt 0--clear halt | ||
1785 | * Returns zero, or a negative error code. | ||
1786 | *----------------------------------------------------------------*/ | ||
1787 | static int qe_ep_set_halt(struct usb_ep *_ep, int value) | ||
1788 | { | ||
1789 | struct qe_ep *ep; | ||
1790 | unsigned long flags; | ||
1791 | int status = -EOPNOTSUPP; | ||
1792 | struct qe_udc *udc; | ||
1793 | |||
1794 | ep = container_of(_ep, struct qe_ep, ep); | ||
1795 | if (!_ep || !ep->desc) { | ||
1796 | status = -EINVAL; | ||
1797 | goto out; | ||
1798 | } | ||
1799 | |||
1800 | udc = ep->udc; | ||
1801 | /* Attempt to halt IN ep will fail if any transfer requests | ||
1802 | * are still queue */ | ||
1803 | if (value && ep_is_in(ep) && !list_empty(&ep->queue)) { | ||
1804 | status = -EAGAIN; | ||
1805 | goto out; | ||
1806 | } | ||
1807 | |||
1808 | status = 0; | ||
1809 | spin_lock_irqsave(&ep->udc->lock, flags); | ||
1810 | qe_eptx_stall_change(ep, value); | ||
1811 | qe_eprx_stall_change(ep, value); | ||
1812 | spin_unlock_irqrestore(&ep->udc->lock, flags); | ||
1813 | |||
1814 | if (ep->epnum == 0) { | ||
1815 | udc->ep0_state = WAIT_FOR_SETUP; | ||
1816 | udc->ep0_dir = 0; | ||
1817 | } | ||
1818 | |||
1819 | /* set data toggle to DATA0 on clear halt */ | ||
1820 | if (value == 0) | ||
1821 | ep->data01 = 0; | ||
1822 | out: | ||
1823 | dev_vdbg(udc->dev, "%s %s halt stat %d\n", ep->ep.name, | ||
1824 | value ? "set" : "clear", status); | ||
1825 | |||
1826 | return status; | ||
1827 | } | ||
1828 | |||
1829 | static struct usb_ep_ops qe_ep_ops = { | ||
1830 | .enable = qe_ep_enable, | ||
1831 | .disable = qe_ep_disable, | ||
1832 | |||
1833 | .alloc_request = qe_alloc_request, | ||
1834 | .free_request = qe_free_request, | ||
1835 | |||
1836 | .queue = qe_ep_queue, | ||
1837 | .dequeue = qe_ep_dequeue, | ||
1838 | |||
1839 | .set_halt = qe_ep_set_halt, | ||
1840 | }; | ||
1841 | |||
1842 | /*------------------------------------------------------------------------ | ||
1843 | Gadget Driver Layer Operations | ||
1844 | ------------------------------------------------------------------------*/ | ||
1845 | |||
1846 | /* Get the current frame number */ | ||
1847 | static int qe_get_frame(struct usb_gadget *gadget) | ||
1848 | { | ||
1849 | u16 tmp; | ||
1850 | |||
1851 | tmp = in_be16(&udc_controller->usb_param->frame_n); | ||
1852 | if (tmp & 0x8000) | ||
1853 | tmp = tmp & 0x07ff; | ||
1854 | else | ||
1855 | tmp = -EINVAL; | ||
1856 | |||
1857 | return (int)tmp; | ||
1858 | } | ||
1859 | |||
1860 | /* Tries to wake up the host connected to this gadget | ||
1861 | * | ||
1862 | * Return : 0-success | ||
1863 | * Negative-this feature not enabled by host or not supported by device hw | ||
1864 | */ | ||
1865 | static int qe_wakeup(struct usb_gadget *gadget) | ||
1866 | { | ||
1867 | return -ENOTSUPP; | ||
1868 | } | ||
1869 | |||
1870 | /* Notify controller that VBUS is powered, Called by whatever | ||
1871 | detects VBUS sessions */ | ||
1872 | static int qe_vbus_session(struct usb_gadget *gadget, int is_active) | ||
1873 | { | ||
1874 | return -ENOTSUPP; | ||
1875 | } | ||
1876 | |||
1877 | /* constrain controller's VBUS power usage | ||
1878 | * This call is used by gadget drivers during SET_CONFIGURATION calls, | ||
1879 | * reporting how much power the device may consume. For example, this | ||
1880 | * could affect how quickly batteries are recharged. | ||
1881 | * | ||
1882 | * Returns zero on success, else negative errno. | ||
1883 | */ | ||
1884 | static int qe_vbus_draw(struct usb_gadget *gadget, unsigned mA) | ||
1885 | { | ||
1886 | return -ENOTSUPP; | ||
1887 | } | ||
1888 | |||
1889 | /* Change Data+ pullup status | ||
1890 | * this func is used by usb_gadget_connect/disconnect | ||
1891 | */ | ||
1892 | static int qe_pullup(struct usb_gadget *gadget, int is_on) | ||
1893 | { | ||
1894 | return -ENOTSUPP; | ||
1895 | } | ||
1896 | |||
1897 | /* defined in usb_gadget.h */ | ||
1898 | static struct usb_gadget_ops qe_gadget_ops = { | ||
1899 | .get_frame = qe_get_frame, | ||
1900 | .wakeup = qe_wakeup, | ||
1901 | /* .set_selfpowered = qe_set_selfpowered,*/ /* always selfpowered */ | ||
1902 | .vbus_session = qe_vbus_session, | ||
1903 | .vbus_draw = qe_vbus_draw, | ||
1904 | .pullup = qe_pullup, | ||
1905 | }; | ||
1906 | |||
1907 | /*------------------------------------------------------------------------- | ||
1908 | USB ep0 Setup process in BUS Enumeration | ||
1909 | -------------------------------------------------------------------------*/ | ||
1910 | static int udc_reset_ep_queue(struct qe_udc *udc, u8 pipe) | ||
1911 | { | ||
1912 | struct qe_ep *ep = &udc->eps[pipe]; | ||
1913 | |||
1914 | nuke(ep, -ECONNRESET); | ||
1915 | ep->tx_req = NULL; | ||
1916 | return 0; | ||
1917 | } | ||
1918 | |||
1919 | static int reset_queues(struct qe_udc *udc) | ||
1920 | { | ||
1921 | u8 pipe; | ||
1922 | |||
1923 | for (pipe = 0; pipe < USB_MAX_ENDPOINTS; pipe++) | ||
1924 | udc_reset_ep_queue(udc, pipe); | ||
1925 | |||
1926 | /* report disconnect; the driver is already quiesced */ | ||
1927 | spin_unlock(&udc->lock); | ||
1928 | udc->driver->disconnect(&udc->gadget); | ||
1929 | spin_lock(&udc->lock); | ||
1930 | |||
1931 | return 0; | ||
1932 | } | ||
1933 | |||
1934 | static void ch9setaddress(struct qe_udc *udc, u16 value, u16 index, | ||
1935 | u16 length) | ||
1936 | { | ||
1937 | /* Save the new address to device struct */ | ||
1938 | udc->device_address = (u8) value; | ||
1939 | /* Update usb state */ | ||
1940 | udc->usb_state = USB_STATE_ADDRESS; | ||
1941 | |||
1942 | /* Status phase , send a ZLP */ | ||
1943 | if (ep0_prime_status(udc, USB_DIR_IN)) | ||
1944 | qe_ep0_stall(udc); | ||
1945 | } | ||
1946 | |||
1947 | static void ownercomplete(struct usb_ep *_ep, struct usb_request *_req) | ||
1948 | { | ||
1949 | struct qe_req *req = container_of(_req, struct qe_req, req); | ||
1950 | |||
1951 | req->req.buf = NULL; | ||
1952 | kfree(req); | ||
1953 | } | ||
1954 | |||
1955 | static void ch9getstatus(struct qe_udc *udc, u8 request_type, u16 value, | ||
1956 | u16 index, u16 length) | ||
1957 | { | ||
1958 | u16 usb_status = 0; | ||
1959 | struct qe_req *req; | ||
1960 | struct qe_ep *ep; | ||
1961 | int status = 0; | ||
1962 | |||
1963 | ep = &udc->eps[0]; | ||
1964 | if ((request_type & USB_RECIP_MASK) == USB_RECIP_DEVICE) { | ||
1965 | /* Get device status */ | ||
1966 | usb_status = 1 << USB_DEVICE_SELF_POWERED; | ||
1967 | } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_INTERFACE) { | ||
1968 | /* Get interface status */ | ||
1969 | /* We don't have interface information in udc driver */ | ||
1970 | usb_status = 0; | ||
1971 | } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_ENDPOINT) { | ||
1972 | /* Get endpoint status */ | ||
1973 | int pipe = index & USB_ENDPOINT_NUMBER_MASK; | ||
1974 | struct qe_ep *target_ep = &udc->eps[pipe]; | ||
1975 | u16 usep; | ||
1976 | |||
1977 | /* stall if endpoint doesn't exist */ | ||
1978 | if (!target_ep->desc) | ||
1979 | goto stall; | ||
1980 | |||
1981 | usep = in_be16(&udc->usb_regs->usb_usep[pipe]); | ||
1982 | if (index & USB_DIR_IN) { | ||
1983 | if (target_ep->dir != USB_DIR_IN) | ||
1984 | goto stall; | ||
1985 | if ((usep & USB_THS_MASK) == USB_THS_STALL) | ||
1986 | usb_status = 1 << USB_ENDPOINT_HALT; | ||
1987 | } else { | ||
1988 | if (target_ep->dir != USB_DIR_OUT) | ||
1989 | goto stall; | ||
1990 | if ((usep & USB_RHS_MASK) == USB_RHS_STALL) | ||
1991 | usb_status = 1 << USB_ENDPOINT_HALT; | ||
1992 | } | ||
1993 | } | ||
1994 | |||
1995 | req = container_of(qe_alloc_request(&ep->ep, GFP_KERNEL), | ||
1996 | struct qe_req, req); | ||
1997 | req->req.length = 2; | ||
1998 | req->req.buf = udc->statusbuf; | ||
1999 | *(u16 *)req->req.buf = cpu_to_le16(usb_status); | ||
2000 | req->req.status = -EINPROGRESS; | ||
2001 | req->req.actual = 0; | ||
2002 | req->req.complete = ownercomplete; | ||
2003 | |||
2004 | udc->ep0_dir = USB_DIR_IN; | ||
2005 | |||
2006 | /* data phase */ | ||
2007 | status = qe_ep_queue(&ep->ep, &req->req, GFP_ATOMIC); | ||
2008 | |||
2009 | if (status == 0) | ||
2010 | return; | ||
2011 | stall: | ||
2012 | dev_err(udc->dev, "Can't respond to getstatus request \n"); | ||
2013 | qe_ep0_stall(udc); | ||
2014 | } | ||
2015 | |||
2016 | /* only handle the setup request, suppose the device in normal status */ | ||
2017 | static void setup_received_handle(struct qe_udc *udc, | ||
2018 | struct usb_ctrlrequest *setup) | ||
2019 | { | ||
2020 | /* Fix Endian (udc->local_setup_buff is cpu Endian now)*/ | ||
2021 | u16 wValue = le16_to_cpu(setup->wValue); | ||
2022 | u16 wIndex = le16_to_cpu(setup->wIndex); | ||
2023 | u16 wLength = le16_to_cpu(setup->wLength); | ||
2024 | |||
2025 | /* clear the previous request in the ep0 */ | ||
2026 | udc_reset_ep_queue(udc, 0); | ||
2027 | |||
2028 | if (setup->bRequestType & USB_DIR_IN) | ||
2029 | udc->ep0_dir = USB_DIR_IN; | ||
2030 | else | ||
2031 | udc->ep0_dir = USB_DIR_OUT; | ||
2032 | |||
2033 | switch (setup->bRequest) { | ||
2034 | case USB_REQ_GET_STATUS: | ||
2035 | /* Data+Status phase form udc */ | ||
2036 | if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK)) | ||
2037 | != (USB_DIR_IN | USB_TYPE_STANDARD)) | ||
2038 | break; | ||
2039 | ch9getstatus(udc, setup->bRequestType, wValue, wIndex, | ||
2040 | wLength); | ||
2041 | return; | ||
2042 | |||
2043 | case USB_REQ_SET_ADDRESS: | ||
2044 | /* Status phase from udc */ | ||
2045 | if (setup->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD | | ||
2046 | USB_RECIP_DEVICE)) | ||
2047 | break; | ||
2048 | ch9setaddress(udc, wValue, wIndex, wLength); | ||
2049 | return; | ||
2050 | |||
2051 | case USB_REQ_CLEAR_FEATURE: | ||
2052 | case USB_REQ_SET_FEATURE: | ||
2053 | /* Requests with no data phase, status phase from udc */ | ||
2054 | if ((setup->bRequestType & USB_TYPE_MASK) | ||
2055 | != USB_TYPE_STANDARD) | ||
2056 | break; | ||
2057 | |||
2058 | if ((setup->bRequestType & USB_RECIP_MASK) | ||
2059 | == USB_RECIP_ENDPOINT) { | ||
2060 | int pipe = wIndex & USB_ENDPOINT_NUMBER_MASK; | ||
2061 | struct qe_ep *ep; | ||
2062 | |||
2063 | if (wValue != 0 || wLength != 0 | ||
2064 | || pipe > USB_MAX_ENDPOINTS) | ||
2065 | break; | ||
2066 | ep = &udc->eps[pipe]; | ||
2067 | |||
2068 | spin_unlock(&udc->lock); | ||
2069 | qe_ep_set_halt(&ep->ep, | ||
2070 | (setup->bRequest == USB_REQ_SET_FEATURE) | ||
2071 | ? 1 : 0); | ||
2072 | spin_lock(&udc->lock); | ||
2073 | } | ||
2074 | |||
2075 | ep0_prime_status(udc, USB_DIR_IN); | ||
2076 | |||
2077 | return; | ||
2078 | |||
2079 | default: | ||
2080 | break; | ||
2081 | } | ||
2082 | |||
2083 | if (wLength) { | ||
2084 | /* Data phase from gadget, status phase from udc */ | ||
2085 | if (setup->bRequestType & USB_DIR_IN) { | ||
2086 | udc->ep0_state = DATA_STATE_XMIT; | ||
2087 | udc->ep0_dir = USB_DIR_IN; | ||
2088 | } else { | ||
2089 | udc->ep0_state = DATA_STATE_RECV; | ||
2090 | udc->ep0_dir = USB_DIR_OUT; | ||
2091 | } | ||
2092 | spin_unlock(&udc->lock); | ||
2093 | if (udc->driver->setup(&udc->gadget, | ||
2094 | &udc->local_setup_buff) < 0) | ||
2095 | qe_ep0_stall(udc); | ||
2096 | spin_lock(&udc->lock); | ||
2097 | } else { | ||
2098 | /* No data phase, IN status from gadget */ | ||
2099 | udc->ep0_dir = USB_DIR_IN; | ||
2100 | spin_unlock(&udc->lock); | ||
2101 | if (udc->driver->setup(&udc->gadget, | ||
2102 | &udc->local_setup_buff) < 0) | ||
2103 | qe_ep0_stall(udc); | ||
2104 | spin_lock(&udc->lock); | ||
2105 | udc->ep0_state = DATA_STATE_NEED_ZLP; | ||
2106 | } | ||
2107 | } | ||
2108 | |||
2109 | /*------------------------------------------------------------------------- | ||
2110 | USB Interrupt handlers | ||
2111 | -------------------------------------------------------------------------*/ | ||
2112 | static void suspend_irq(struct qe_udc *udc) | ||
2113 | { | ||
2114 | udc->resume_state = udc->usb_state; | ||
2115 | udc->usb_state = USB_STATE_SUSPENDED; | ||
2116 | |||
2117 | /* report suspend to the driver ,serial.c not support this*/ | ||
2118 | if (udc->driver->suspend) | ||
2119 | udc->driver->suspend(&udc->gadget); | ||
2120 | } | ||
2121 | |||
2122 | static void resume_irq(struct qe_udc *udc) | ||
2123 | { | ||
2124 | udc->usb_state = udc->resume_state; | ||
2125 | udc->resume_state = 0; | ||
2126 | |||
2127 | /* report resume to the driver , serial.c not support this*/ | ||
2128 | if (udc->driver->resume) | ||
2129 | udc->driver->resume(&udc->gadget); | ||
2130 | } | ||
2131 | |||
2132 | static void idle_irq(struct qe_udc *udc) | ||
2133 | { | ||
2134 | u8 usbs; | ||
2135 | |||
2136 | usbs = in_8(&udc->usb_regs->usb_usbs); | ||
2137 | if (usbs & USB_IDLE_STATUS_MASK) { | ||
2138 | if ((udc->usb_state) != USB_STATE_SUSPENDED) | ||
2139 | suspend_irq(udc); | ||
2140 | } else { | ||
2141 | if (udc->usb_state == USB_STATE_SUSPENDED) | ||
2142 | resume_irq(udc); | ||
2143 | } | ||
2144 | } | ||
2145 | |||
2146 | static int reset_irq(struct qe_udc *udc) | ||
2147 | { | ||
2148 | unsigned char i; | ||
2149 | |||
2150 | qe_usb_disable(); | ||
2151 | out_8(&udc->usb_regs->usb_usadr, 0); | ||
2152 | |||
2153 | for (i = 0; i < USB_MAX_ENDPOINTS; i++) { | ||
2154 | if (udc->eps[i].init) | ||
2155 | qe_ep_reset(udc, i); | ||
2156 | } | ||
2157 | |||
2158 | reset_queues(udc); | ||
2159 | udc->usb_state = USB_STATE_DEFAULT; | ||
2160 | udc->ep0_state = WAIT_FOR_SETUP; | ||
2161 | udc->ep0_dir = USB_DIR_OUT; | ||
2162 | qe_usb_enable(); | ||
2163 | return 0; | ||
2164 | } | ||
2165 | |||
2166 | static int bsy_irq(struct qe_udc *udc) | ||
2167 | { | ||
2168 | return 0; | ||
2169 | } | ||
2170 | |||
2171 | static int txe_irq(struct qe_udc *udc) | ||
2172 | { | ||
2173 | return 0; | ||
2174 | } | ||
2175 | |||
2176 | /* ep0 tx interrupt also in here */ | ||
2177 | static int tx_irq(struct qe_udc *udc) | ||
2178 | { | ||
2179 | struct qe_ep *ep; | ||
2180 | struct qe_bd __iomem *bd; | ||
2181 | int i, res = 0; | ||
2182 | |||
2183 | if ((udc->usb_state == USB_STATE_ADDRESS) | ||
2184 | && (in_8(&udc->usb_regs->usb_usadr) == 0)) | ||
2185 | out_8(&udc->usb_regs->usb_usadr, udc->device_address); | ||
2186 | |||
2187 | for (i = (USB_MAX_ENDPOINTS-1); ((i >= 0) && (res == 0)); i--) { | ||
2188 | ep = &udc->eps[i]; | ||
2189 | if (ep && ep->init && (ep->dir != USB_DIR_OUT)) { | ||
2190 | bd = ep->c_txbd; | ||
2191 | if (!(in_be32((u32 __iomem *)bd) & T_R) | ||
2192 | && (in_be32(&bd->buf))) { | ||
2193 | /* confirm the transmitted bd */ | ||
2194 | if (ep->epnum == 0) | ||
2195 | res = qe_ep0_txconf(ep); | ||
2196 | else | ||
2197 | res = qe_ep_txconf(ep); | ||
2198 | } | ||
2199 | } | ||
2200 | } | ||
2201 | return res; | ||
2202 | } | ||
2203 | |||
2204 | |||
2205 | /* setup packect's rx is handle in the function too */ | ||
2206 | static void rx_irq(struct qe_udc *udc) | ||
2207 | { | ||
2208 | struct qe_ep *ep; | ||
2209 | struct qe_bd __iomem *bd; | ||
2210 | int i; | ||
2211 | |||
2212 | for (i = 0; i < USB_MAX_ENDPOINTS; i++) { | ||
2213 | ep = &udc->eps[i]; | ||
2214 | if (ep && ep->init && (ep->dir != USB_DIR_IN)) { | ||
2215 | bd = ep->n_rxbd; | ||
2216 | if (!(in_be32((u32 __iomem *)bd) & R_E) | ||
2217 | && (in_be32(&bd->buf))) { | ||
2218 | if (ep->epnum == 0) { | ||
2219 | qe_ep0_rx(udc); | ||
2220 | } else { | ||
2221 | /*non-setup package receive*/ | ||
2222 | qe_ep_rx(ep); | ||
2223 | } | ||
2224 | } | ||
2225 | } | ||
2226 | } | ||
2227 | } | ||
2228 | |||
2229 | static irqreturn_t qe_udc_irq(int irq, void *_udc) | ||
2230 | { | ||
2231 | struct qe_udc *udc = (struct qe_udc *)_udc; | ||
2232 | u16 irq_src; | ||
2233 | irqreturn_t status = IRQ_NONE; | ||
2234 | unsigned long flags; | ||
2235 | |||
2236 | spin_lock_irqsave(&udc->lock, flags); | ||
2237 | |||
2238 | irq_src = in_be16(&udc->usb_regs->usb_usber) & | ||
2239 | in_be16(&udc->usb_regs->usb_usbmr); | ||
2240 | /* Clear notification bits */ | ||
2241 | out_be16(&udc->usb_regs->usb_usber, irq_src); | ||
2242 | /* USB Interrupt */ | ||
2243 | if (irq_src & USB_E_IDLE_MASK) { | ||
2244 | idle_irq(udc); | ||
2245 | irq_src &= ~USB_E_IDLE_MASK; | ||
2246 | status = IRQ_HANDLED; | ||
2247 | } | ||
2248 | |||
2249 | if (irq_src & USB_E_TXB_MASK) { | ||
2250 | tx_irq(udc); | ||
2251 | irq_src &= ~USB_E_TXB_MASK; | ||
2252 | status = IRQ_HANDLED; | ||
2253 | } | ||
2254 | |||
2255 | if (irq_src & USB_E_RXB_MASK) { | ||
2256 | rx_irq(udc); | ||
2257 | irq_src &= ~USB_E_RXB_MASK; | ||
2258 | status = IRQ_HANDLED; | ||
2259 | } | ||
2260 | |||
2261 | if (irq_src & USB_E_RESET_MASK) { | ||
2262 | reset_irq(udc); | ||
2263 | irq_src &= ~USB_E_RESET_MASK; | ||
2264 | status = IRQ_HANDLED; | ||
2265 | } | ||
2266 | |||
2267 | if (irq_src & USB_E_BSY_MASK) { | ||
2268 | bsy_irq(udc); | ||
2269 | irq_src &= ~USB_E_BSY_MASK; | ||
2270 | status = IRQ_HANDLED; | ||
2271 | } | ||
2272 | |||
2273 | if (irq_src & USB_E_TXE_MASK) { | ||
2274 | txe_irq(udc); | ||
2275 | irq_src &= ~USB_E_TXE_MASK; | ||
2276 | status = IRQ_HANDLED; | ||
2277 | } | ||
2278 | |||
2279 | spin_unlock_irqrestore(&udc->lock, flags); | ||
2280 | |||
2281 | return status; | ||
2282 | } | ||
2283 | |||
2284 | /*------------------------------------------------------------------------- | ||
2285 | Gadget driver register and unregister. | ||
2286 | --------------------------------------------------------------------------*/ | ||
2287 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) | ||
2288 | { | ||
2289 | int retval; | ||
2290 | unsigned long flags = 0; | ||
2291 | |||
2292 | /* standard operations */ | ||
2293 | if (!udc_controller) | ||
2294 | return -ENODEV; | ||
2295 | |||
2296 | if (!driver || (driver->speed != USB_SPEED_FULL | ||
2297 | && driver->speed != USB_SPEED_HIGH) | ||
2298 | || !driver->bind || !driver->disconnect | ||
2299 | || !driver->setup) | ||
2300 | return -EINVAL; | ||
2301 | |||
2302 | if (udc_controller->driver) | ||
2303 | return -EBUSY; | ||
2304 | |||
2305 | /* lock is needed but whether should use this lock or another */ | ||
2306 | spin_lock_irqsave(&udc_controller->lock, flags); | ||
2307 | |||
2308 | driver->driver.bus = NULL; | ||
2309 | /* hook up the driver */ | ||
2310 | udc_controller->driver = driver; | ||
2311 | udc_controller->gadget.dev.driver = &driver->driver; | ||
2312 | udc_controller->gadget.speed = (enum usb_device_speed)(driver->speed); | ||
2313 | spin_unlock_irqrestore(&udc_controller->lock, flags); | ||
2314 | |||
2315 | retval = driver->bind(&udc_controller->gadget); | ||
2316 | if (retval) { | ||
2317 | dev_err(udc_controller->dev, "bind to %s --> %d", | ||
2318 | driver->driver.name, retval); | ||
2319 | udc_controller->gadget.dev.driver = NULL; | ||
2320 | udc_controller->driver = NULL; | ||
2321 | return retval; | ||
2322 | } | ||
2323 | |||
2324 | /* Enable IRQ reg and Set usbcmd reg EN bit */ | ||
2325 | qe_usb_enable(); | ||
2326 | |||
2327 | out_be16(&udc_controller->usb_regs->usb_usber, 0xffff); | ||
2328 | out_be16(&udc_controller->usb_regs->usb_usbmr, USB_E_DEFAULT_DEVICE); | ||
2329 | udc_controller->usb_state = USB_STATE_ATTACHED; | ||
2330 | udc_controller->ep0_state = WAIT_FOR_SETUP; | ||
2331 | udc_controller->ep0_dir = USB_DIR_OUT; | ||
2332 | dev_info(udc_controller->dev, "%s bind to driver %s \n", | ||
2333 | udc_controller->gadget.name, driver->driver.name); | ||
2334 | return 0; | ||
2335 | } | ||
2336 | EXPORT_SYMBOL(usb_gadget_register_driver); | ||
2337 | |||
2338 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | ||
2339 | { | ||
2340 | struct qe_ep *loop_ep; | ||
2341 | unsigned long flags; | ||
2342 | |||
2343 | if (!udc_controller) | ||
2344 | return -ENODEV; | ||
2345 | |||
2346 | if (!driver || driver != udc_controller->driver) | ||
2347 | return -EINVAL; | ||
2348 | |||
2349 | /* stop usb controller, disable intr */ | ||
2350 | qe_usb_disable(); | ||
2351 | |||
2352 | /* in fact, no needed */ | ||
2353 | udc_controller->usb_state = USB_STATE_ATTACHED; | ||
2354 | udc_controller->ep0_state = WAIT_FOR_SETUP; | ||
2355 | udc_controller->ep0_dir = 0; | ||
2356 | |||
2357 | /* stand operation */ | ||
2358 | spin_lock_irqsave(&udc_controller->lock, flags); | ||
2359 | udc_controller->gadget.speed = USB_SPEED_UNKNOWN; | ||
2360 | nuke(&udc_controller->eps[0], -ESHUTDOWN); | ||
2361 | list_for_each_entry(loop_ep, &udc_controller->gadget.ep_list, | ||
2362 | ep.ep_list) | ||
2363 | nuke(loop_ep, -ESHUTDOWN); | ||
2364 | spin_unlock_irqrestore(&udc_controller->lock, flags); | ||
2365 | |||
2366 | /* unbind gadget and unhook driver. */ | ||
2367 | driver->unbind(&udc_controller->gadget); | ||
2368 | udc_controller->gadget.dev.driver = NULL; | ||
2369 | udc_controller->driver = NULL; | ||
2370 | |||
2371 | dev_info(udc_controller->dev, "unregistered gadget driver '%s'\r\n", | ||
2372 | driver->driver.name); | ||
2373 | return 0; | ||
2374 | } | ||
2375 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2376 | |||
2377 | /* udc structure's alloc and setup, include ep-param alloc */ | ||
2378 | static struct qe_udc __devinit *qe_udc_config(struct of_device *ofdev) | ||
2379 | { | ||
2380 | struct qe_udc *udc; | ||
2381 | struct device_node *np = ofdev->node; | ||
2382 | unsigned int tmp_addr = 0; | ||
2383 | struct usb_device_para __iomem *usbpram; | ||
2384 | unsigned int i; | ||
2385 | u64 size; | ||
2386 | u32 offset; | ||
2387 | |||
2388 | udc = kzalloc(sizeof(*udc), GFP_KERNEL); | ||
2389 | if (udc == NULL) { | ||
2390 | dev_err(&ofdev->dev, "malloc udc failed\n"); | ||
2391 | goto cleanup; | ||
2392 | } | ||
2393 | |||
2394 | udc->dev = &ofdev->dev; | ||
2395 | |||
2396 | /* get default address of usb parameter in MURAM from device tree */ | ||
2397 | offset = *of_get_address(np, 1, &size, NULL); | ||
2398 | udc->usb_param = cpm_muram_addr(offset); | ||
2399 | memset_io(udc->usb_param, 0, size); | ||
2400 | |||
2401 | usbpram = udc->usb_param; | ||
2402 | out_be16(&usbpram->frame_n, 0); | ||
2403 | out_be32(&usbpram->rstate, 0); | ||
2404 | |||
2405 | tmp_addr = cpm_muram_alloc((USB_MAX_ENDPOINTS * | ||
2406 | sizeof(struct usb_ep_para)), | ||
2407 | USB_EP_PARA_ALIGNMENT); | ||
2408 | |||
2409 | for (i = 0; i < USB_MAX_ENDPOINTS; i++) { | ||
2410 | out_be16(&usbpram->epptr[i], (u16)tmp_addr); | ||
2411 | udc->ep_param[i] = cpm_muram_addr(tmp_addr); | ||
2412 | tmp_addr += 32; | ||
2413 | } | ||
2414 | |||
2415 | memset_io(udc->ep_param[0], 0, | ||
2416 | USB_MAX_ENDPOINTS * sizeof(struct usb_ep_para)); | ||
2417 | |||
2418 | udc->resume_state = USB_STATE_NOTATTACHED; | ||
2419 | udc->usb_state = USB_STATE_POWERED; | ||
2420 | udc->ep0_dir = 0; | ||
2421 | |||
2422 | spin_lock_init(&udc->lock); | ||
2423 | return udc; | ||
2424 | |||
2425 | cleanup: | ||
2426 | kfree(udc); | ||
2427 | return NULL; | ||
2428 | } | ||
2429 | |||
2430 | /* USB Controller register init */ | ||
2431 | static int __devinit qe_udc_reg_init(struct qe_udc *udc) | ||
2432 | { | ||
2433 | struct usb_ctlr __iomem *qe_usbregs; | ||
2434 | qe_usbregs = udc->usb_regs; | ||
2435 | |||
2436 | /* Init the usb register */ | ||
2437 | out_8(&qe_usbregs->usb_usmod, 0x01); | ||
2438 | out_be16(&qe_usbregs->usb_usbmr, 0); | ||
2439 | out_8(&qe_usbregs->usb_uscom, 0); | ||
2440 | out_be16(&qe_usbregs->usb_usber, USBER_ALL_CLEAR); | ||
2441 | |||
2442 | return 0; | ||
2443 | } | ||
2444 | |||
2445 | static int __devinit qe_ep_config(struct qe_udc *udc, unsigned char pipe_num) | ||
2446 | { | ||
2447 | struct qe_ep *ep = &udc->eps[pipe_num]; | ||
2448 | |||
2449 | ep->udc = udc; | ||
2450 | strcpy(ep->name, ep_name[pipe_num]); | ||
2451 | ep->ep.name = ep_name[pipe_num]; | ||
2452 | |||
2453 | ep->ep.ops = &qe_ep_ops; | ||
2454 | ep->stopped = 1; | ||
2455 | ep->ep.maxpacket = (unsigned short) ~0; | ||
2456 | ep->desc = NULL; | ||
2457 | ep->dir = 0xff; | ||
2458 | ep->epnum = (u8)pipe_num; | ||
2459 | ep->sent = 0; | ||
2460 | ep->last = 0; | ||
2461 | ep->init = 0; | ||
2462 | ep->rxframe = NULL; | ||
2463 | ep->txframe = NULL; | ||
2464 | ep->tx_req = NULL; | ||
2465 | ep->state = EP_STATE_IDLE; | ||
2466 | ep->has_data = 0; | ||
2467 | |||
2468 | /* the queue lists any req for this ep */ | ||
2469 | INIT_LIST_HEAD(&ep->queue); | ||
2470 | |||
2471 | /* gagdet.ep_list used for ep_autoconfig so no ep0*/ | ||
2472 | if (pipe_num != 0) | ||
2473 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); | ||
2474 | |||
2475 | ep->gadget = &udc->gadget; | ||
2476 | |||
2477 | return 0; | ||
2478 | } | ||
2479 | |||
2480 | /*----------------------------------------------------------------------- | ||
2481 | * UDC device Driver operation functions * | ||
2482 | *----------------------------------------------------------------------*/ | ||
2483 | static void qe_udc_release(struct device *dev) | ||
2484 | { | ||
2485 | int i = 0; | ||
2486 | |||
2487 | complete(udc_controller->done); | ||
2488 | cpm_muram_free(cpm_muram_offset(udc_controller->ep_param[0])); | ||
2489 | for (i = 0; i < USB_MAX_ENDPOINTS; i++) | ||
2490 | udc_controller->ep_param[i] = NULL; | ||
2491 | |||
2492 | kfree(udc_controller); | ||
2493 | udc_controller = NULL; | ||
2494 | } | ||
2495 | |||
2496 | /* Driver probe functions */ | ||
2497 | static int __devinit qe_udc_probe(struct of_device *ofdev, | ||
2498 | const struct of_device_id *match) | ||
2499 | { | ||
2500 | struct device_node *np = ofdev->node; | ||
2501 | struct qe_ep *ep; | ||
2502 | unsigned int ret = 0; | ||
2503 | unsigned int i; | ||
2504 | const void *prop; | ||
2505 | |||
2506 | prop = of_get_property(np, "mode", NULL); | ||
2507 | if (!prop || strcmp(prop, "peripheral")) | ||
2508 | return -ENODEV; | ||
2509 | |||
2510 | /* Initialize the udc structure including QH member and other member */ | ||
2511 | udc_controller = qe_udc_config(ofdev); | ||
2512 | if (!udc_controller) { | ||
2513 | dev_dbg(&ofdev->dev, "udc_controll is NULL\n"); | ||
2514 | return -ENOMEM; | ||
2515 | } | ||
2516 | |||
2517 | udc_controller->soc_type = (unsigned long)match->data; | ||
2518 | udc_controller->usb_regs = of_iomap(np, 0); | ||
2519 | if (!udc_controller->usb_regs) { | ||
2520 | ret = -ENOMEM; | ||
2521 | goto err1; | ||
2522 | } | ||
2523 | |||
2524 | /* initialize usb hw reg except for regs for EP, | ||
2525 | * leave usbintr reg untouched*/ | ||
2526 | qe_udc_reg_init(udc_controller); | ||
2527 | |||
2528 | /* here comes the stand operations for probe | ||
2529 | * set the qe_udc->gadget.xxx */ | ||
2530 | udc_controller->gadget.ops = &qe_gadget_ops; | ||
2531 | |||
2532 | /* gadget.ep0 is a pointer */ | ||
2533 | udc_controller->gadget.ep0 = &udc_controller->eps[0].ep; | ||
2534 | |||
2535 | INIT_LIST_HEAD(&udc_controller->gadget.ep_list); | ||
2536 | |||
2537 | /* modify in register gadget process */ | ||
2538 | udc_controller->gadget.speed = USB_SPEED_UNKNOWN; | ||
2539 | |||
2540 | /* name: Identifies the controller hardware type. */ | ||
2541 | udc_controller->gadget.name = driver_name; | ||
2542 | |||
2543 | device_initialize(&udc_controller->gadget.dev); | ||
2544 | |||
2545 | strcpy(udc_controller->gadget.dev.bus_id, "gadget"); | ||
2546 | |||
2547 | udc_controller->gadget.dev.release = qe_udc_release; | ||
2548 | udc_controller->gadget.dev.parent = &ofdev->dev; | ||
2549 | |||
2550 | /* initialize qe_ep struct */ | ||
2551 | for (i = 0; i < USB_MAX_ENDPOINTS ; i++) { | ||
2552 | /* because the ep type isn't decide here so | ||
2553 | * qe_ep_init() should be called in ep_enable() */ | ||
2554 | |||
2555 | /* setup the qe_ep struct and link ep.ep.list | ||
2556 | * into gadget.ep_list */ | ||
2557 | qe_ep_config(udc_controller, (unsigned char)i); | ||
2558 | } | ||
2559 | |||
2560 | /* ep0 initialization in here */ | ||
2561 | ret = qe_ep_init(udc_controller, 0, &qe_ep0_desc); | ||
2562 | if (ret) | ||
2563 | goto err2; | ||
2564 | |||
2565 | /* create a buf for ZLP send, need to remain zeroed */ | ||
2566 | udc_controller->nullbuf = kzalloc(256, GFP_KERNEL); | ||
2567 | if (udc_controller->nullbuf == NULL) { | ||
2568 | dev_dbg(udc_controller->dev, "cannot alloc nullbuf\n"); | ||
2569 | ret = -ENOMEM; | ||
2570 | goto err3; | ||
2571 | } | ||
2572 | |||
2573 | /* buffer for data of get_status request */ | ||
2574 | udc_controller->statusbuf = kzalloc(2, GFP_KERNEL); | ||
2575 | if (udc_controller->statusbuf == NULL) { | ||
2576 | ret = -ENOMEM; | ||
2577 | goto err4; | ||
2578 | } | ||
2579 | |||
2580 | udc_controller->nullp = virt_to_phys((void *)udc_controller->nullbuf); | ||
2581 | if (udc_controller->nullp == DMA_ADDR_INVALID) { | ||
2582 | udc_controller->nullp = dma_map_single( | ||
2583 | udc_controller->gadget.dev.parent, | ||
2584 | udc_controller->nullbuf, | ||
2585 | 256, | ||
2586 | DMA_TO_DEVICE); | ||
2587 | udc_controller->nullmap = 1; | ||
2588 | } else { | ||
2589 | dma_sync_single_for_device(udc_controller->gadget.dev.parent, | ||
2590 | udc_controller->nullp, 256, | ||
2591 | DMA_TO_DEVICE); | ||
2592 | } | ||
2593 | |||
2594 | tasklet_init(&udc_controller->rx_tasklet, ep_rx_tasklet, | ||
2595 | (unsigned long)udc_controller); | ||
2596 | /* request irq and disable DR */ | ||
2597 | udc_controller->usb_irq = irq_of_parse_and_map(np, 0); | ||
2598 | |||
2599 | ret = request_irq(udc_controller->usb_irq, qe_udc_irq, 0, | ||
2600 | driver_name, udc_controller); | ||
2601 | if (ret) { | ||
2602 | dev_err(udc_controller->dev, "cannot request irq %d err %d \n", | ||
2603 | udc_controller->usb_irq, ret); | ||
2604 | goto err5; | ||
2605 | } | ||
2606 | |||
2607 | ret = device_add(&udc_controller->gadget.dev); | ||
2608 | if (ret) | ||
2609 | goto err6; | ||
2610 | |||
2611 | dev_info(udc_controller->dev, | ||
2612 | "%s USB controller initialized as device\n", | ||
2613 | (udc_controller->soc_type == PORT_QE) ? "QE" : "CPM"); | ||
2614 | return 0; | ||
2615 | |||
2616 | err6: | ||
2617 | free_irq(udc_controller->usb_irq, udc_controller); | ||
2618 | err5: | ||
2619 | if (udc_controller->nullmap) { | ||
2620 | dma_unmap_single(udc_controller->gadget.dev.parent, | ||
2621 | udc_controller->nullp, 256, | ||
2622 | DMA_TO_DEVICE); | ||
2623 | udc_controller->nullp = DMA_ADDR_INVALID; | ||
2624 | } else { | ||
2625 | dma_sync_single_for_cpu(udc_controller->gadget.dev.parent, | ||
2626 | udc_controller->nullp, 256, | ||
2627 | DMA_TO_DEVICE); | ||
2628 | } | ||
2629 | kfree(udc_controller->statusbuf); | ||
2630 | err4: | ||
2631 | kfree(udc_controller->nullbuf); | ||
2632 | err3: | ||
2633 | ep = &udc_controller->eps[0]; | ||
2634 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); | ||
2635 | kfree(ep->rxframe); | ||
2636 | kfree(ep->rxbuffer); | ||
2637 | kfree(ep->txframe); | ||
2638 | err2: | ||
2639 | iounmap(udc_controller->usb_regs); | ||
2640 | err1: | ||
2641 | kfree(udc_controller); | ||
2642 | |||
2643 | return ret; | ||
2644 | } | ||
2645 | |||
2646 | #ifdef CONFIG_PM | ||
2647 | static int qe_udc_suspend(struct of_device *dev, pm_message_t state) | ||
2648 | { | ||
2649 | return -ENOTSUPP; | ||
2650 | } | ||
2651 | |||
2652 | static int qe_udc_resume(struct of_device *dev) | ||
2653 | { | ||
2654 | return -ENOTSUPP; | ||
2655 | } | ||
2656 | #endif | ||
2657 | |||
2658 | static int __devexit qe_udc_remove(struct of_device *ofdev) | ||
2659 | { | ||
2660 | struct qe_ep *ep; | ||
2661 | unsigned int size; | ||
2662 | |||
2663 | DECLARE_COMPLETION(done); | ||
2664 | |||
2665 | if (!udc_controller) | ||
2666 | return -ENODEV; | ||
2667 | |||
2668 | udc_controller->done = &done; | ||
2669 | tasklet_disable(&udc_controller->rx_tasklet); | ||
2670 | |||
2671 | if (udc_controller->nullmap) { | ||
2672 | dma_unmap_single(udc_controller->gadget.dev.parent, | ||
2673 | udc_controller->nullp, 256, | ||
2674 | DMA_TO_DEVICE); | ||
2675 | udc_controller->nullp = DMA_ADDR_INVALID; | ||
2676 | } else { | ||
2677 | dma_sync_single_for_cpu(udc_controller->gadget.dev.parent, | ||
2678 | udc_controller->nullp, 256, | ||
2679 | DMA_TO_DEVICE); | ||
2680 | } | ||
2681 | kfree(udc_controller->statusbuf); | ||
2682 | kfree(udc_controller->nullbuf); | ||
2683 | |||
2684 | ep = &udc_controller->eps[0]; | ||
2685 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); | ||
2686 | size = (ep->ep.maxpacket + USB_CRC_SIZE + 2) * (USB_BDRING_LEN + 1); | ||
2687 | |||
2688 | kfree(ep->rxframe); | ||
2689 | if (ep->rxbufmap) { | ||
2690 | dma_unmap_single(udc_controller->gadget.dev.parent, | ||
2691 | ep->rxbuf_d, size, | ||
2692 | DMA_FROM_DEVICE); | ||
2693 | ep->rxbuf_d = DMA_ADDR_INVALID; | ||
2694 | } else { | ||
2695 | dma_sync_single_for_cpu(udc_controller->gadget.dev.parent, | ||
2696 | ep->rxbuf_d, size, | ||
2697 | DMA_FROM_DEVICE); | ||
2698 | } | ||
2699 | |||
2700 | kfree(ep->rxbuffer); | ||
2701 | kfree(ep->txframe); | ||
2702 | |||
2703 | free_irq(udc_controller->usb_irq, udc_controller); | ||
2704 | |||
2705 | tasklet_kill(&udc_controller->rx_tasklet); | ||
2706 | |||
2707 | iounmap(udc_controller->usb_regs); | ||
2708 | |||
2709 | device_unregister(&udc_controller->gadget.dev); | ||
2710 | /* wait for release() of gadget.dev to free udc */ | ||
2711 | wait_for_completion(&done); | ||
2712 | |||
2713 | return 0; | ||
2714 | } | ||
2715 | |||
2716 | /*-------------------------------------------------------------------------*/ | ||
2717 | static struct of_device_id __devinitdata qe_udc_match[] = { | ||
2718 | { | ||
2719 | .compatible = "fsl,mpc8360-qe-usb", | ||
2720 | .data = (void *)PORT_QE, | ||
2721 | }, | ||
2722 | { | ||
2723 | .compatible = "fsl,mpc8272-cpm-usb", | ||
2724 | .data = (void *)PORT_CPM, | ||
2725 | }, | ||
2726 | {}, | ||
2727 | }; | ||
2728 | |||
2729 | MODULE_DEVICE_TABLE(of, qe_udc_match); | ||
2730 | |||
2731 | static struct of_platform_driver udc_driver = { | ||
2732 | .name = (char *)driver_name, | ||
2733 | .match_table = qe_udc_match, | ||
2734 | .probe = qe_udc_probe, | ||
2735 | .remove = __devexit_p(qe_udc_remove), | ||
2736 | #ifdef CONFIG_PM | ||
2737 | .suspend = qe_udc_suspend, | ||
2738 | .resume = qe_udc_resume, | ||
2739 | #endif | ||
2740 | }; | ||
2741 | |||
2742 | static int __init qe_udc_init(void) | ||
2743 | { | ||
2744 | printk(KERN_INFO "%s: %s, %s\n", driver_name, driver_desc, | ||
2745 | DRIVER_VERSION); | ||
2746 | return of_register_platform_driver(&udc_driver); | ||
2747 | } | ||
2748 | |||
2749 | static void __exit qe_udc_exit(void) | ||
2750 | { | ||
2751 | of_unregister_platform_driver(&udc_driver); | ||
2752 | } | ||
2753 | |||
2754 | module_init(qe_udc_init); | ||
2755 | module_exit(qe_udc_exit); | ||
2756 | |||
2757 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
2758 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
2759 | MODULE_LICENSE("GPL"); | ||
2760 | |||
diff --git a/drivers/usb/gadget/fsl_qe_udc.h b/drivers/usb/gadget/fsl_qe_udc.h new file mode 100644 index 000000000000..31b2710882e4 --- /dev/null +++ b/drivers/usb/gadget/fsl_qe_udc.h | |||
@@ -0,0 +1,437 @@ | |||
1 | /* | ||
2 | * drivers/usb/gadget/qe_udc.h | ||
3 | * | ||
4 | * Copyright (C) 2006-2008 Freescale Semiconductor, Inc. All rights reserved. | ||
5 | * | ||
6 | * Xiaobo Xie <X.Xie@freescale.com> | ||
7 | * Li Yang <leoli@freescale.com> | ||
8 | * | ||
9 | * Description: | ||
10 | * Freescale USB device/endpoint management registers | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or (at | ||
15 | * your option) any later version. | ||
16 | */ | ||
17 | |||
18 | #ifndef __FSL_QE_UDC_H | ||
19 | #define __FSL_QE_UDC_H | ||
20 | |||
21 | /* SoC type */ | ||
22 | #define PORT_CPM 0 | ||
23 | #define PORT_QE 1 | ||
24 | |||
25 | #define USB_MAX_ENDPOINTS 4 | ||
26 | #define USB_MAX_PIPES USB_MAX_ENDPOINTS | ||
27 | #define USB_EP0_MAX_SIZE 64 | ||
28 | #define USB_MAX_CTRL_PAYLOAD 0x4000 | ||
29 | #define USB_BDRING_LEN 16 | ||
30 | #define USB_BDRING_LEN_RX 256 | ||
31 | #define USB_BDRING_LEN_TX 16 | ||
32 | #define MIN_EMPTY_BDS 128 | ||
33 | #define MAX_DATA_BDS 8 | ||
34 | #define USB_CRC_SIZE 2 | ||
35 | #define USB_DIR_BOTH 0x88 | ||
36 | #define R_BUF_MAXSIZE 0x800 | ||
37 | #define USB_EP_PARA_ALIGNMENT 32 | ||
38 | |||
39 | /* USB Mode Register bit define */ | ||
40 | #define USB_MODE_EN 0x01 | ||
41 | #define USB_MODE_HOST 0x02 | ||
42 | #define USB_MODE_TEST 0x04 | ||
43 | #define USB_MODE_SFTE 0x08 | ||
44 | #define USB_MODE_RESUME 0x40 | ||
45 | #define USB_MODE_LSS 0x80 | ||
46 | |||
47 | /* USB Slave Address Register Mask */ | ||
48 | #define USB_SLVADDR_MASK 0x7F | ||
49 | |||
50 | /* USB Endpoint register define */ | ||
51 | #define USB_EPNUM_MASK 0xF000 | ||
52 | #define USB_EPNUM_SHIFT 12 | ||
53 | |||
54 | #define USB_TRANS_MODE_SHIFT 8 | ||
55 | #define USB_TRANS_CTR 0x0000 | ||
56 | #define USB_TRANS_INT 0x0100 | ||
57 | #define USB_TRANS_BULK 0x0200 | ||
58 | #define USB_TRANS_ISO 0x0300 | ||
59 | |||
60 | #define USB_EP_MF 0x0020 | ||
61 | #define USB_EP_RTE 0x0010 | ||
62 | |||
63 | #define USB_THS_SHIFT 2 | ||
64 | #define USB_THS_MASK 0x000c | ||
65 | #define USB_THS_NORMAL 0x0 | ||
66 | #define USB_THS_IGNORE_IN 0x0004 | ||
67 | #define USB_THS_NACK 0x0008 | ||
68 | #define USB_THS_STALL 0x000c | ||
69 | |||
70 | #define USB_RHS_SHIFT 0 | ||
71 | #define USB_RHS_MASK 0x0003 | ||
72 | #define USB_RHS_NORMAL 0x0 | ||
73 | #define USB_RHS_IGNORE_OUT 0x0001 | ||
74 | #define USB_RHS_NACK 0x0002 | ||
75 | #define USB_RHS_STALL 0x0003 | ||
76 | |||
77 | #define USB_RTHS_MASK 0x000f | ||
78 | |||
79 | /* USB Command Register define */ | ||
80 | #define USB_CMD_STR_FIFO 0x80 | ||
81 | #define USB_CMD_FLUSH_FIFO 0x40 | ||
82 | #define USB_CMD_ISFT 0x20 | ||
83 | #define USB_CMD_DSFT 0x10 | ||
84 | #define USB_CMD_EP_MASK 0x03 | ||
85 | |||
86 | /* USB Event and Mask Register define */ | ||
87 | #define USB_E_MSF_MASK 0x0800 | ||
88 | #define USB_E_SFT_MASK 0x0400 | ||
89 | #define USB_E_RESET_MASK 0x0200 | ||
90 | #define USB_E_IDLE_MASK 0x0100 | ||
91 | #define USB_E_TXE4_MASK 0x0080 | ||
92 | #define USB_E_TXE3_MASK 0x0040 | ||
93 | #define USB_E_TXE2_MASK 0x0020 | ||
94 | #define USB_E_TXE1_MASK 0x0010 | ||
95 | #define USB_E_SOF_MASK 0x0008 | ||
96 | #define USB_E_BSY_MASK 0x0004 | ||
97 | #define USB_E_TXB_MASK 0x0002 | ||
98 | #define USB_E_RXB_MASK 0x0001 | ||
99 | #define USBER_ALL_CLEAR 0x0fff | ||
100 | |||
101 | #define USB_E_DEFAULT_DEVICE (USB_E_RESET_MASK | USB_E_TXE4_MASK | \ | ||
102 | USB_E_TXE3_MASK | USB_E_TXE2_MASK | \ | ||
103 | USB_E_TXE1_MASK | USB_E_BSY_MASK | \ | ||
104 | USB_E_TXB_MASK | USB_E_RXB_MASK) | ||
105 | |||
106 | #define USB_E_TXE_MASK (USB_E_TXE4_MASK | USB_E_TXE3_MASK|\ | ||
107 | USB_E_TXE2_MASK | USB_E_TXE1_MASK) | ||
108 | /* USB Status Register define */ | ||
109 | #define USB_IDLE_STATUS_MASK 0x01 | ||
110 | |||
111 | /* USB Start of Frame Timer */ | ||
112 | #define USB_USSFT_MASK 0x3FFF | ||
113 | |||
114 | /* USB Frame Number Register */ | ||
115 | #define USB_USFRN_MASK 0xFFFF | ||
116 | |||
117 | struct usb_device_para{ | ||
118 | u16 epptr[4]; | ||
119 | u32 rstate; | ||
120 | u32 rptr; | ||
121 | u16 frame_n; | ||
122 | u16 rbcnt; | ||
123 | u32 rtemp; | ||
124 | u32 rxusb_data; | ||
125 | u16 rxuptr; | ||
126 | u8 reso[2]; | ||
127 | u32 softbl; | ||
128 | u8 sofucrctemp; | ||
129 | }; | ||
130 | |||
131 | struct usb_ep_para{ | ||
132 | u16 rbase; | ||
133 | u16 tbase; | ||
134 | u8 rbmr; | ||
135 | u8 tbmr; | ||
136 | u16 mrblr; | ||
137 | u16 rbptr; | ||
138 | u16 tbptr; | ||
139 | u32 tstate; | ||
140 | u32 tptr; | ||
141 | u16 tcrc; | ||
142 | u16 tbcnt; | ||
143 | u32 ttemp; | ||
144 | u16 txusbu_ptr; | ||
145 | u8 reserve[2]; | ||
146 | }; | ||
147 | |||
148 | #define USB_BUSMODE_GBL 0x20 | ||
149 | #define USB_BUSMODE_BO_MASK 0x18 | ||
150 | #define USB_BUSMODE_BO_SHIFT 0x3 | ||
151 | #define USB_BUSMODE_BE 0x2 | ||
152 | #define USB_BUSMODE_CETM 0x04 | ||
153 | #define USB_BUSMODE_DTB 0x02 | ||
154 | |||
155 | /* Endpoint basic handle */ | ||
156 | #define ep_index(EP) ((EP)->desc->bEndpointAddress & 0xF) | ||
157 | #define ep_maxpacket(EP) ((EP)->ep.maxpacket) | ||
158 | #define ep_is_in(EP) ((ep_index(EP) == 0) ? (EP->udc->ep0_dir == \ | ||
159 | USB_DIR_IN) : ((EP)->desc->bEndpointAddress \ | ||
160 | & USB_DIR_IN) == USB_DIR_IN) | ||
161 | |||
162 | /* ep0 transfer state */ | ||
163 | #define WAIT_FOR_SETUP 0 | ||
164 | #define DATA_STATE_XMIT 1 | ||
165 | #define DATA_STATE_NEED_ZLP 2 | ||
166 | #define WAIT_FOR_OUT_STATUS 3 | ||
167 | #define DATA_STATE_RECV 4 | ||
168 | |||
169 | /* ep tramsfer mode */ | ||
170 | #define USBP_TM_CTL 0 | ||
171 | #define USBP_TM_ISO 1 | ||
172 | #define USBP_TM_BULK 2 | ||
173 | #define USBP_TM_INT 3 | ||
174 | |||
175 | /*----------------------------------------------------------------------------- | ||
176 | USB RX And TX DATA Frame | ||
177 | -----------------------------------------------------------------------------*/ | ||
178 | struct qe_frame{ | ||
179 | u8 *data; | ||
180 | u32 len; | ||
181 | u32 status; | ||
182 | u32 info; | ||
183 | |||
184 | void *privdata; | ||
185 | struct list_head node; | ||
186 | }; | ||
187 | |||
188 | /* Frame structure, info field. */ | ||
189 | #define PID_DATA0 0x80000000 /* Data toggle zero */ | ||
190 | #define PID_DATA1 0x40000000 /* Data toggle one */ | ||
191 | #define PID_SETUP 0x20000000 /* setup bit */ | ||
192 | #define SETUP_STATUS 0x10000000 /* setup status bit */ | ||
193 | #define SETADDR_STATUS 0x08000000 /* setupup address status bit */ | ||
194 | #define NO_REQ 0x04000000 /* Frame without request */ | ||
195 | #define HOST_DATA 0x02000000 /* Host data frame */ | ||
196 | #define FIRST_PACKET_IN_FRAME 0x01000000 /* first packet in the frame */ | ||
197 | #define TOKEN_FRAME 0x00800000 /* Host token frame */ | ||
198 | #define ZLP 0x00400000 /* Zero length packet */ | ||
199 | #define IN_TOKEN_FRAME 0x00200000 /* In token package */ | ||
200 | #define OUT_TOKEN_FRAME 0x00100000 /* Out token package */ | ||
201 | #define SETUP_TOKEN_FRAME 0x00080000 /* Setup token package */ | ||
202 | #define STALL_FRAME 0x00040000 /* Stall handshake */ | ||
203 | #define NACK_FRAME 0x00020000 /* Nack handshake */ | ||
204 | #define NO_PID 0x00010000 /* No send PID */ | ||
205 | #define NO_CRC 0x00008000 /* No send CRC */ | ||
206 | #define HOST_COMMAND 0x00004000 /* Host command frame */ | ||
207 | |||
208 | /* Frame status field */ | ||
209 | /* Receive side */ | ||
210 | #define FRAME_OK 0x00000000 /* Frame tranmitted or received OK */ | ||
211 | #define FRAME_ERROR 0x80000000 /* Error occured on frame */ | ||
212 | #define START_FRAME_LOST 0x40000000 /* START_FRAME_LOST */ | ||
213 | #define END_FRAME_LOST 0x20000000 /* END_FRAME_LOST */ | ||
214 | #define RX_ER_NONOCT 0x10000000 /* Rx Non Octet Aligned Packet */ | ||
215 | #define RX_ER_BITSTUFF 0x08000000 /* Frame Aborted --Received packet | ||
216 | with bit stuff error */ | ||
217 | #define RX_ER_CRC 0x04000000 /* Received packet with CRC error */ | ||
218 | #define RX_ER_OVERUN 0x02000000 /* Over-run occured on reception */ | ||
219 | #define RX_ER_PID 0x01000000 /* Wrong PID received */ | ||
220 | /* Tranmit side */ | ||
221 | #define TX_ER_NAK 0x00800000 /* Received NAK handshake */ | ||
222 | #define TX_ER_STALL 0x00400000 /* Received STALL handshake */ | ||
223 | #define TX_ER_TIMEOUT 0x00200000 /* Transmit time out */ | ||
224 | #define TX_ER_UNDERUN 0x00100000 /* Transmit underrun */ | ||
225 | #define FRAME_INPROGRESS 0x00080000 /* Frame is being transmitted */ | ||
226 | #define ER_DATA_UNDERUN 0x00040000 /* Frame is shorter then expected */ | ||
227 | #define ER_DATA_OVERUN 0x00020000 /* Frame is longer then expected */ | ||
228 | |||
229 | /* QE USB frame operation functions */ | ||
230 | #define frame_get_length(frm) (frm->len) | ||
231 | #define frame_set_length(frm, leng) (frm->len = leng) | ||
232 | #define frame_get_data(frm) (frm->data) | ||
233 | #define frame_set_data(frm, dat) (frm->data = dat) | ||
234 | #define frame_get_info(frm) (frm->info) | ||
235 | #define frame_set_info(frm, inf) (frm->info = inf) | ||
236 | #define frame_get_status(frm) (frm->status) | ||
237 | #define frame_set_status(frm, stat) (frm->status = stat) | ||
238 | #define frame_get_privdata(frm) (frm->privdata) | ||
239 | #define frame_set_privdata(frm, dat) (frm->privdata = dat) | ||
240 | |||
241 | static inline void qe_frame_clean(struct qe_frame *frm) | ||
242 | { | ||
243 | frame_set_data(frm, NULL); | ||
244 | frame_set_length(frm, 0); | ||
245 | frame_set_status(frm, FRAME_OK); | ||
246 | frame_set_info(frm, 0); | ||
247 | frame_set_privdata(frm, NULL); | ||
248 | } | ||
249 | |||
250 | static inline void qe_frame_init(struct qe_frame *frm) | ||
251 | { | ||
252 | qe_frame_clean(frm); | ||
253 | INIT_LIST_HEAD(&(frm->node)); | ||
254 | } | ||
255 | |||
256 | struct qe_req { | ||
257 | struct usb_request req; | ||
258 | struct list_head queue; | ||
259 | /* ep_queue() func will add | ||
260 | a request->queue into a udc_ep->queue 'd tail */ | ||
261 | struct qe_ep *ep; | ||
262 | unsigned mapped:1; | ||
263 | }; | ||
264 | |||
265 | struct qe_ep { | ||
266 | struct usb_ep ep; | ||
267 | struct list_head queue; | ||
268 | struct qe_udc *udc; | ||
269 | const struct usb_endpoint_descriptor *desc; | ||
270 | struct usb_gadget *gadget; | ||
271 | |||
272 | u8 state; | ||
273 | |||
274 | struct qe_bd __iomem *rxbase; | ||
275 | struct qe_bd __iomem *n_rxbd; | ||
276 | struct qe_bd __iomem *e_rxbd; | ||
277 | |||
278 | struct qe_bd __iomem *txbase; | ||
279 | struct qe_bd __iomem *n_txbd; | ||
280 | struct qe_bd __iomem *c_txbd; | ||
281 | |||
282 | struct qe_frame *rxframe; | ||
283 | u8 *rxbuffer; | ||
284 | dma_addr_t rxbuf_d; | ||
285 | u8 rxbufmap; | ||
286 | unsigned char localnack; | ||
287 | int has_data; | ||
288 | |||
289 | struct qe_frame *txframe; | ||
290 | struct qe_req *tx_req; | ||
291 | int sent; /*data already sent */ | ||
292 | int last; /*data sent in the last time*/ | ||
293 | |||
294 | u8 dir; | ||
295 | u8 epnum; | ||
296 | u8 tm; /* transfer mode */ | ||
297 | u8 data01; | ||
298 | u8 init; | ||
299 | |||
300 | u8 already_seen; | ||
301 | u8 enable_tasklet; | ||
302 | u8 setup_stage; | ||
303 | u32 last_io; /* timestamp */ | ||
304 | |||
305 | char name[14]; | ||
306 | |||
307 | unsigned double_buf:1; | ||
308 | unsigned stopped:1; | ||
309 | unsigned fnf:1; | ||
310 | unsigned has_dma:1; | ||
311 | |||
312 | u8 ackwait; | ||
313 | u8 dma_channel; | ||
314 | u16 dma_counter; | ||
315 | int lch; | ||
316 | |||
317 | struct timer_list timer; | ||
318 | }; | ||
319 | |||
320 | struct qe_udc { | ||
321 | struct usb_gadget gadget; | ||
322 | struct usb_gadget_driver *driver; | ||
323 | struct device *dev; | ||
324 | struct qe_ep eps[USB_MAX_ENDPOINTS]; | ||
325 | struct usb_ctrlrequest local_setup_buff; | ||
326 | spinlock_t lock; /* lock for set/config qe_udc */ | ||
327 | unsigned long soc_type; /* QE or CPM soc */ | ||
328 | |||
329 | struct qe_req *status_req; /* ep0 status request */ | ||
330 | |||
331 | /* USB and EP Parameter Block pointer */ | ||
332 | struct usb_device_para __iomem *usb_param; | ||
333 | struct usb_ep_para __iomem *ep_param[4]; | ||
334 | |||
335 | u32 max_pipes; /* Device max pipes */ | ||
336 | u32 max_use_endpts; /* Max endpointes to be used */ | ||
337 | u32 bus_reset; /* Device is bus reseting */ | ||
338 | u32 resume_state; /* USB state to resume*/ | ||
339 | u32 usb_state; /* USB current state */ | ||
340 | u32 usb_next_state; /* USB next state */ | ||
341 | u32 ep0_state; /* Enpoint zero state */ | ||
342 | u32 ep0_dir; /* Enpoint zero direction: can be | ||
343 | USB_DIR_IN or USB_DIR_OUT*/ | ||
344 | u32 usb_sof_count; /* SOF count */ | ||
345 | u32 errors; /* USB ERRORs count */ | ||
346 | |||
347 | u8 *tmpbuf; | ||
348 | u32 c_start; | ||
349 | u32 c_end; | ||
350 | |||
351 | u8 *nullbuf; | ||
352 | u8 *statusbuf; | ||
353 | dma_addr_t nullp; | ||
354 | u8 nullmap; | ||
355 | u8 device_address; /* Device USB address */ | ||
356 | |||
357 | unsigned int usb_clock; | ||
358 | unsigned int usb_irq; | ||
359 | struct usb_ctlr __iomem *usb_regs; | ||
360 | |||
361 | struct tasklet_struct rx_tasklet; | ||
362 | |||
363 | struct completion *done; /* to make sure release() is done */ | ||
364 | }; | ||
365 | |||
366 | #define EP_STATE_IDLE 0 | ||
367 | #define EP_STATE_NACK 1 | ||
368 | #define EP_STATE_STALL 2 | ||
369 | |||
370 | /* | ||
371 | * transmit BD's status | ||
372 | */ | ||
373 | #define T_R 0x80000000 /* ready bit */ | ||
374 | #define T_W 0x20000000 /* wrap bit */ | ||
375 | #define T_I 0x10000000 /* interrupt on completion */ | ||
376 | #define T_L 0x08000000 /* last */ | ||
377 | #define T_TC 0x04000000 /* transmit CRC */ | ||
378 | #define T_CNF 0x02000000 /* wait for transmit confirm */ | ||
379 | #define T_LSP 0x01000000 /* Low-speed transaction */ | ||
380 | #define T_PID 0x00c00000 /* packet id */ | ||
381 | #define T_NAK 0x00100000 /* No ack. */ | ||
382 | #define T_STAL 0x00080000 /* Stall recieved */ | ||
383 | #define T_TO 0x00040000 /* time out */ | ||
384 | #define T_UN 0x00020000 /* underrun */ | ||
385 | |||
386 | #define DEVICE_T_ERROR (T_UN | T_TO) | ||
387 | #define HOST_T_ERROR (T_UN | T_TO | T_NAK | T_STAL) | ||
388 | #define DEVICE_T_BD_MASK DEVICE_T_ERROR | ||
389 | #define HOST_T_BD_MASK HOST_T_ERROR | ||
390 | |||
391 | #define T_PID_SHIFT 6 | ||
392 | #define T_PID_DATA0 0x00800000 /* Data 0 toggle */ | ||
393 | #define T_PID_DATA1 0x00c00000 /* Data 1 toggle */ | ||
394 | |||
395 | /* | ||
396 | * receive BD's status | ||
397 | */ | ||
398 | #define R_E 0x80000000 /* buffer empty */ | ||
399 | #define R_W 0x20000000 /* wrap bit */ | ||
400 | #define R_I 0x10000000 /* interrupt on reception */ | ||
401 | #define R_L 0x08000000 /* last */ | ||
402 | #define R_F 0x04000000 /* first */ | ||
403 | #define R_PID 0x00c00000 /* packet id */ | ||
404 | #define R_NO 0x00100000 /* Rx Non Octet Aligned Packet */ | ||
405 | #define R_AB 0x00080000 /* Frame Aborted */ | ||
406 | #define R_CR 0x00040000 /* CRC Error */ | ||
407 | #define R_OV 0x00020000 /* Overrun */ | ||
408 | |||
409 | #define R_ERROR (R_NO | R_AB | R_CR | R_OV) | ||
410 | #define R_BD_MASK R_ERROR | ||
411 | |||
412 | #define R_PID_DATA0 0x00000000 | ||
413 | #define R_PID_DATA1 0x00400000 | ||
414 | #define R_PID_SETUP 0x00800000 | ||
415 | |||
416 | #define CPM_USB_STOP_TX 0x2e600000 | ||
417 | #define CPM_USB_RESTART_TX 0x2e600000 | ||
418 | #define CPM_USB_STOP_TX_OPCODE 0x0a | ||
419 | #define CPM_USB_RESTART_TX_OPCODE 0x0b | ||
420 | #define CPM_USB_EP_SHIFT 5 | ||
421 | |||
422 | #ifndef CONFIG_CPM | ||
423 | inline int cpm_command(u32 command, u8 opcode) | ||
424 | { | ||
425 | return -EOPNOTSUPP; | ||
426 | } | ||
427 | #endif | ||
428 | |||
429 | #ifndef CONFIG_QUICC_ENGINE | ||
430 | inline int qe_issue_cmd(u32 cmd, u32 device, u8 mcn_protocol, | ||
431 | u32 cmd_input) | ||
432 | { | ||
433 | return -EOPNOTSUPP; | ||
434 | } | ||
435 | #endif | ||
436 | |||
437 | #endif /* __FSL_QE_UDC_H */ | ||
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c index 45ad556169f1..091bb55c9aa7 100644 --- a/drivers/usb/gadget/fsl_usb2_udc.c +++ b/drivers/usb/gadget/fsl_usb2_udc.c | |||
@@ -23,11 +23,8 @@ | |||
23 | #include <linux/ioport.h> | 23 | #include <linux/ioport.h> |
24 | #include <linux/types.h> | 24 | #include <linux/types.h> |
25 | #include <linux/errno.h> | 25 | #include <linux/errno.h> |
26 | #include <linux/delay.h> | ||
27 | #include <linux/sched.h> | ||
28 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
29 | #include <linux/init.h> | 27 | #include <linux/init.h> |
30 | #include <linux/timer.h> | ||
31 | #include <linux/list.h> | 28 | #include <linux/list.h> |
32 | #include <linux/interrupt.h> | 29 | #include <linux/interrupt.h> |
33 | #include <linux/proc_fs.h> | 30 | #include <linux/proc_fs.h> |
@@ -44,11 +41,9 @@ | |||
44 | 41 | ||
45 | #include <asm/byteorder.h> | 42 | #include <asm/byteorder.h> |
46 | #include <asm/io.h> | 43 | #include <asm/io.h> |
47 | #include <asm/irq.h> | ||
48 | #include <asm/system.h> | 44 | #include <asm/system.h> |
49 | #include <asm/unaligned.h> | 45 | #include <asm/unaligned.h> |
50 | #include <asm/dma.h> | 46 | #include <asm/dma.h> |
51 | #include <asm/cacheflush.h> | ||
52 | 47 | ||
53 | #include "fsl_usb2_udc.h" | 48 | #include "fsl_usb2_udc.h" |
54 | 49 | ||
@@ -61,8 +56,8 @@ | |||
61 | static const char driver_name[] = "fsl-usb2-udc"; | 56 | static const char driver_name[] = "fsl-usb2-udc"; |
62 | static const char driver_desc[] = DRIVER_DESC; | 57 | static const char driver_desc[] = DRIVER_DESC; |
63 | 58 | ||
64 | volatile static struct usb_dr_device *dr_regs = NULL; | 59 | static struct usb_dr_device *dr_regs; |
65 | volatile static struct usb_sys_interface *usb_sys_regs = NULL; | 60 | static struct usb_sys_interface *usb_sys_regs; |
66 | 61 | ||
67 | /* it is initialized in probe() */ | 62 | /* it is initialized in probe() */ |
68 | static struct fsl_udc *udc_controller = NULL; | 63 | static struct fsl_udc *udc_controller = NULL; |
@@ -76,16 +71,14 @@ fsl_ep0_desc = { | |||
76 | .wMaxPacketSize = USB_MAX_CTRL_PAYLOAD, | 71 | .wMaxPacketSize = USB_MAX_CTRL_PAYLOAD, |
77 | }; | 72 | }; |
78 | 73 | ||
79 | static int fsl_udc_suspend(struct platform_device *pdev, pm_message_t state); | ||
80 | static int fsl_udc_resume(struct platform_device *pdev); | ||
81 | static void fsl_ep_fifo_flush(struct usb_ep *_ep); | 74 | static void fsl_ep_fifo_flush(struct usb_ep *_ep); |
82 | 75 | ||
83 | #ifdef CONFIG_PPC32 | 76 | #ifdef CONFIG_PPC32 |
84 | #define fsl_readl(addr) in_le32(addr) | 77 | #define fsl_readl(addr) in_le32(addr) |
85 | #define fsl_writel(addr, val32) out_le32(val32, addr) | 78 | #define fsl_writel(val32, addr) out_le32(addr, val32) |
86 | #else | 79 | #else |
87 | #define fsl_readl(addr) readl(addr) | 80 | #define fsl_readl(addr) readl(addr) |
88 | #define fsl_writel(addr, val32) writel(addr, val32) | 81 | #define fsl_writel(val32, addr) writel(val32, addr) |
89 | #endif | 82 | #endif |
90 | 83 | ||
91 | /******************************************************************** | 84 | /******************************************************************** |
@@ -185,10 +178,6 @@ static int dr_controller_setup(struct fsl_udc *udc) | |||
185 | unsigned long timeout; | 178 | unsigned long timeout; |
186 | #define FSL_UDC_RESET_TIMEOUT 1000 | 179 | #define FSL_UDC_RESET_TIMEOUT 1000 |
187 | 180 | ||
188 | /* before here, make sure dr_regs has been initialized */ | ||
189 | if (!udc) | ||
190 | return -EINVAL; | ||
191 | |||
192 | /* Stop and reset the usb controller */ | 181 | /* Stop and reset the usb controller */ |
193 | tmp = fsl_readl(&dr_regs->usbcmd); | 182 | tmp = fsl_readl(&dr_regs->usbcmd); |
194 | tmp &= ~USB_CMD_RUN_STOP; | 183 | tmp &= ~USB_CMD_RUN_STOP; |
@@ -202,7 +191,7 @@ static int dr_controller_setup(struct fsl_udc *udc) | |||
202 | timeout = jiffies + FSL_UDC_RESET_TIMEOUT; | 191 | timeout = jiffies + FSL_UDC_RESET_TIMEOUT; |
203 | while (fsl_readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) { | 192 | while (fsl_readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) { |
204 | if (time_after(jiffies, timeout)) { | 193 | if (time_after(jiffies, timeout)) { |
205 | ERR("udc reset timeout! \n"); | 194 | ERR("udc reset timeout!\n"); |
206 | return -ETIMEDOUT; | 195 | return -ETIMEDOUT; |
207 | } | 196 | } |
208 | cpu_relax(); | 197 | cpu_relax(); |
@@ -315,7 +304,8 @@ static void dr_controller_stop(struct fsl_udc *udc) | |||
315 | return; | 304 | return; |
316 | } | 305 | } |
317 | 306 | ||
318 | void dr_ep_setup(unsigned char ep_num, unsigned char dir, unsigned char ep_type) | 307 | static void dr_ep_setup(unsigned char ep_num, unsigned char dir, |
308 | unsigned char ep_type) | ||
319 | { | 309 | { |
320 | unsigned int tmp_epctrl = 0; | 310 | unsigned int tmp_epctrl = 0; |
321 | 311 | ||
@@ -563,7 +553,7 @@ static int fsl_ep_disable(struct usb_ep *_ep) | |||
563 | /* nuke all pending requests (does flush) */ | 553 | /* nuke all pending requests (does flush) */ |
564 | nuke(ep, -ESHUTDOWN); | 554 | nuke(ep, -ESHUTDOWN); |
565 | 555 | ||
566 | ep->desc = 0; | 556 | ep->desc = NULL; |
567 | ep->stopped = 1; | 557 | ep->stopped = 1; |
568 | spin_unlock_irqrestore(&udc->lock, flags); | 558 | spin_unlock_irqrestore(&udc->lock, flags); |
569 | 559 | ||
@@ -602,7 +592,7 @@ static void fsl_free_request(struct usb_ep *_ep, struct usb_request *_req) | |||
602 | } | 592 | } |
603 | 593 | ||
604 | /*-------------------------------------------------------------------------*/ | 594 | /*-------------------------------------------------------------------------*/ |
605 | static int fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req) | 595 | static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req) |
606 | { | 596 | { |
607 | int i = ep_index(ep) * 2 + ep_is_in(ep); | 597 | int i = ep_index(ep) * 2 + ep_is_in(ep); |
608 | u32 temp, bitmask, tmp_stat; | 598 | u32 temp, bitmask, tmp_stat; |
@@ -653,13 +643,16 @@ static int fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req) | |||
653 | | EP_QUEUE_HEAD_STATUS_HALT)); | 643 | | EP_QUEUE_HEAD_STATUS_HALT)); |
654 | dQH->size_ioc_int_sts &= temp; | 644 | dQH->size_ioc_int_sts &= temp; |
655 | 645 | ||
646 | /* Ensure that updates to the QH will occure before priming. */ | ||
647 | wmb(); | ||
648 | |||
656 | /* Prime endpoint by writing 1 to ENDPTPRIME */ | 649 | /* Prime endpoint by writing 1 to ENDPTPRIME */ |
657 | temp = ep_is_in(ep) | 650 | temp = ep_is_in(ep) |
658 | ? (1 << (ep_index(ep) + 16)) | 651 | ? (1 << (ep_index(ep) + 16)) |
659 | : (1 << (ep_index(ep))); | 652 | : (1 << (ep_index(ep))); |
660 | fsl_writel(temp, &dr_regs->endpointprime); | 653 | fsl_writel(temp, &dr_regs->endpointprime); |
661 | out: | 654 | out: |
662 | return 0; | 655 | return; |
663 | } | 656 | } |
664 | 657 | ||
665 | /* Fill in the dTD structure | 658 | /* Fill in the dTD structure |
@@ -710,7 +703,7 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length, | |||
710 | *is_last = 0; | 703 | *is_last = 0; |
711 | 704 | ||
712 | if ((*is_last) == 0) | 705 | if ((*is_last) == 0) |
713 | VDBG("multi-dtd request!\n"); | 706 | VDBG("multi-dtd request!"); |
714 | /* Fill in the transfer size; set active bit */ | 707 | /* Fill in the transfer size; set active bit */ |
715 | swap_temp = ((*length << DTD_LENGTH_BIT_POS) | DTD_STATUS_ACTIVE); | 708 | swap_temp = ((*length << DTD_LENGTH_BIT_POS) | DTD_STATUS_ACTIVE); |
716 | 709 | ||
@@ -773,11 +766,11 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
773 | /* catch various bogus parameters */ | 766 | /* catch various bogus parameters */ |
774 | if (!_req || !req->req.complete || !req->req.buf | 767 | if (!_req || !req->req.complete || !req->req.buf |
775 | || !list_empty(&req->queue)) { | 768 | || !list_empty(&req->queue)) { |
776 | VDBG("%s, bad params\n", __func__); | 769 | VDBG("%s, bad params", __func__); |
777 | return -EINVAL; | 770 | return -EINVAL; |
778 | } | 771 | } |
779 | if (unlikely(!_ep || !ep->desc)) { | 772 | if (unlikely(!_ep || !ep->desc)) { |
780 | VDBG("%s, bad ep\n", __func__); | 773 | VDBG("%s, bad ep", __func__); |
781 | return -EINVAL; | 774 | return -EINVAL; |
782 | } | 775 | } |
783 | if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { | 776 | if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { |
@@ -1069,7 +1062,7 @@ static int fsl_vbus_session(struct usb_gadget *gadget, int is_active) | |||
1069 | 1062 | ||
1070 | udc = container_of(gadget, struct fsl_udc, gadget); | 1063 | udc = container_of(gadget, struct fsl_udc, gadget); |
1071 | spin_lock_irqsave(&udc->lock, flags); | 1064 | spin_lock_irqsave(&udc->lock, flags); |
1072 | VDBG("VBUS %s\n", is_active ? "on" : "off"); | 1065 | VDBG("VBUS %s", is_active ? "on" : "off"); |
1073 | udc->vbus_active = (is_active != 0); | 1066 | udc->vbus_active = (is_active != 0); |
1074 | if (can_pullup(udc)) | 1067 | if (can_pullup(udc)) |
1075 | fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP), | 1068 | fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP), |
@@ -1146,7 +1139,6 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction) | |||
1146 | { | 1139 | { |
1147 | struct fsl_req *req = udc->status_req; | 1140 | struct fsl_req *req = udc->status_req; |
1148 | struct fsl_ep *ep; | 1141 | struct fsl_ep *ep; |
1149 | int status = 0; | ||
1150 | 1142 | ||
1151 | if (direction == EP_DIR_IN) | 1143 | if (direction == EP_DIR_IN) |
1152 | udc->ep0_dir = USB_DIR_IN; | 1144 | udc->ep0_dir = USB_DIR_IN; |
@@ -1164,27 +1156,21 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction) | |||
1164 | req->dtd_count = 0; | 1156 | req->dtd_count = 0; |
1165 | 1157 | ||
1166 | if (fsl_req_to_dtd(req) == 0) | 1158 | if (fsl_req_to_dtd(req) == 0) |
1167 | status = fsl_queue_td(ep, req); | 1159 | fsl_queue_td(ep, req); |
1168 | else | 1160 | else |
1169 | return -ENOMEM; | 1161 | return -ENOMEM; |
1170 | 1162 | ||
1171 | if (status) | ||
1172 | ERR("Can't queue ep0 status request \n"); | ||
1173 | list_add_tail(&req->queue, &ep->queue); | 1163 | list_add_tail(&req->queue, &ep->queue); |
1174 | 1164 | ||
1175 | return status; | 1165 | return 0; |
1176 | } | 1166 | } |
1177 | 1167 | ||
1178 | static inline int udc_reset_ep_queue(struct fsl_udc *udc, u8 pipe) | 1168 | static void udc_reset_ep_queue(struct fsl_udc *udc, u8 pipe) |
1179 | { | 1169 | { |
1180 | struct fsl_ep *ep = get_ep_by_pipe(udc, pipe); | 1170 | struct fsl_ep *ep = get_ep_by_pipe(udc, pipe); |
1181 | 1171 | ||
1182 | if (!ep->name) | 1172 | if (ep->name) |
1183 | return 0; | 1173 | nuke(ep, -ESHUTDOWN); |
1184 | |||
1185 | nuke(ep, -ESHUTDOWN); | ||
1186 | |||
1187 | return 0; | ||
1188 | } | 1174 | } |
1189 | 1175 | ||
1190 | /* | 1176 | /* |
@@ -1208,10 +1194,8 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value, | |||
1208 | u16 index, u16 length) | 1194 | u16 index, u16 length) |
1209 | { | 1195 | { |
1210 | u16 tmp = 0; /* Status, cpu endian */ | 1196 | u16 tmp = 0; /* Status, cpu endian */ |
1211 | |||
1212 | struct fsl_req *req; | 1197 | struct fsl_req *req; |
1213 | struct fsl_ep *ep; | 1198 | struct fsl_ep *ep; |
1214 | int status = 0; | ||
1215 | 1199 | ||
1216 | ep = &udc->eps[0]; | 1200 | ep = &udc->eps[0]; |
1217 | 1201 | ||
@@ -1250,14 +1234,10 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value, | |||
1250 | 1234 | ||
1251 | /* prime the data phase */ | 1235 | /* prime the data phase */ |
1252 | if ((fsl_req_to_dtd(req) == 0)) | 1236 | if ((fsl_req_to_dtd(req) == 0)) |
1253 | status = fsl_queue_td(ep, req); | 1237 | fsl_queue_td(ep, req); |
1254 | else /* no mem */ | 1238 | else /* no mem */ |
1255 | goto stall; | 1239 | goto stall; |
1256 | 1240 | ||
1257 | if (status) { | ||
1258 | ERR("Can't respond to getstatus request \n"); | ||
1259 | goto stall; | ||
1260 | } | ||
1261 | list_add_tail(&req->queue, &ep->queue); | 1241 | list_add_tail(&req->queue, &ep->queue); |
1262 | udc->ep0_state = DATA_STATE_XMIT; | 1242 | udc->ep0_state = DATA_STATE_XMIT; |
1263 | return; | 1243 | return; |
@@ -1397,7 +1377,7 @@ static void ep0_req_complete(struct fsl_udc *udc, struct fsl_ep *ep0, | |||
1397 | udc->ep0_state = WAIT_FOR_SETUP; | 1377 | udc->ep0_state = WAIT_FOR_SETUP; |
1398 | break; | 1378 | break; |
1399 | case WAIT_FOR_SETUP: | 1379 | case WAIT_FOR_SETUP: |
1400 | ERR("Unexpect ep0 packets \n"); | 1380 | ERR("Unexpect ep0 packets\n"); |
1401 | break; | 1381 | break; |
1402 | default: | 1382 | default: |
1403 | ep0stall(udc); | 1383 | ep0stall(udc); |
@@ -1476,7 +1456,7 @@ static int process_ep_req(struct fsl_udc *udc, int pipe, | |||
1476 | status = -EILSEQ; | 1456 | status = -EILSEQ; |
1477 | break; | 1457 | break; |
1478 | } else | 1458 | } else |
1479 | ERR("Unknown error has occured (0x%x)!\r\n", | 1459 | ERR("Unknown error has occured (0x%x)!\n", |
1480 | errors); | 1460 | errors); |
1481 | 1461 | ||
1482 | } else if (le32_to_cpu(curr_td->size_ioc_sts) | 1462 | } else if (le32_to_cpu(curr_td->size_ioc_sts) |
@@ -1495,7 +1475,7 @@ static int process_ep_req(struct fsl_udc *udc, int pipe, | |||
1495 | } | 1475 | } |
1496 | } else { | 1476 | } else { |
1497 | td_complete++; | 1477 | td_complete++; |
1498 | VDBG("dTD transmitted successful "); | 1478 | VDBG("dTD transmitted successful"); |
1499 | } | 1479 | } |
1500 | 1480 | ||
1501 | if (j != curr_req->dtd_count - 1) | 1481 | if (j != curr_req->dtd_count - 1) |
@@ -1568,9 +1548,6 @@ static void port_change_irq(struct fsl_udc *udc) | |||
1568 | { | 1548 | { |
1569 | u32 speed; | 1549 | u32 speed; |
1570 | 1550 | ||
1571 | if (udc->bus_reset) | ||
1572 | udc->bus_reset = 0; | ||
1573 | |||
1574 | /* Bus resetting is finished */ | 1551 | /* Bus resetting is finished */ |
1575 | if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET)) { | 1552 | if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET)) { |
1576 | /* Get the speed */ | 1553 | /* Get the speed */ |
@@ -1678,8 +1655,6 @@ static void reset_irq(struct fsl_udc *udc) | |||
1678 | 1655 | ||
1679 | if (fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) { | 1656 | if (fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) { |
1680 | VDBG("Bus reset"); | 1657 | VDBG("Bus reset"); |
1681 | /* Bus is reseting */ | ||
1682 | udc->bus_reset = 1; | ||
1683 | /* Reset all the queues, include XD, dTD, EP queue | 1658 | /* Reset all the queues, include XD, dTD, EP queue |
1684 | * head and TR Queue */ | 1659 | * head and TR Queue */ |
1685 | reset_queues(udc); | 1660 | reset_queues(udc); |
@@ -1768,7 +1743,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc) | |||
1768 | } | 1743 | } |
1769 | 1744 | ||
1770 | if (irq_src & (USB_STS_ERR | USB_STS_SYS_ERR)) { | 1745 | if (irq_src & (USB_STS_ERR | USB_STS_SYS_ERR)) { |
1771 | VDBG("Error IRQ %x ", irq_src); | 1746 | VDBG("Error IRQ %x", irq_src); |
1772 | } | 1747 | } |
1773 | 1748 | ||
1774 | spin_unlock_irqrestore(&udc->lock, flags); | 1749 | spin_unlock_irqrestore(&udc->lock, flags); |
@@ -1799,7 +1774,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
1799 | /* lock is needed but whether should use this lock or another */ | 1774 | /* lock is needed but whether should use this lock or another */ |
1800 | spin_lock_irqsave(&udc_controller->lock, flags); | 1775 | spin_lock_irqsave(&udc_controller->lock, flags); |
1801 | 1776 | ||
1802 | driver->driver.bus = 0; | 1777 | driver->driver.bus = NULL; |
1803 | /* hook up the driver */ | 1778 | /* hook up the driver */ |
1804 | udc_controller->driver = driver; | 1779 | udc_controller->driver = driver; |
1805 | udc_controller->gadget.dev.driver = &driver->driver; | 1780 | udc_controller->gadget.dev.driver = &driver->driver; |
@@ -1809,8 +1784,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
1809 | retval = driver->bind(&udc_controller->gadget); | 1784 | retval = driver->bind(&udc_controller->gadget); |
1810 | if (retval) { | 1785 | if (retval) { |
1811 | VDBG("bind to %s --> %d", driver->driver.name, retval); | 1786 | VDBG("bind to %s --> %d", driver->driver.name, retval); |
1812 | udc_controller->gadget.dev.driver = 0; | 1787 | udc_controller->gadget.dev.driver = NULL; |
1813 | udc_controller->driver = 0; | 1788 | udc_controller->driver = NULL; |
1814 | goto out; | 1789 | goto out; |
1815 | } | 1790 | } |
1816 | 1791 | ||
@@ -1819,12 +1794,12 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
1819 | udc_controller->usb_state = USB_STATE_ATTACHED; | 1794 | udc_controller->usb_state = USB_STATE_ATTACHED; |
1820 | udc_controller->ep0_state = WAIT_FOR_SETUP; | 1795 | udc_controller->ep0_state = WAIT_FOR_SETUP; |
1821 | udc_controller->ep0_dir = 0; | 1796 | udc_controller->ep0_dir = 0; |
1822 | printk(KERN_INFO "%s: bind to driver %s \n", | 1797 | printk(KERN_INFO "%s: bind to driver %s\n", |
1823 | udc_controller->gadget.name, driver->driver.name); | 1798 | udc_controller->gadget.name, driver->driver.name); |
1824 | 1799 | ||
1825 | out: | 1800 | out: |
1826 | if (retval) | 1801 | if (retval) |
1827 | printk("retval %d \n", retval); | 1802 | printk("gadget driver register failed %d\n", retval); |
1828 | return retval; | 1803 | return retval; |
1829 | } | 1804 | } |
1830 | EXPORT_SYMBOL(usb_gadget_register_driver); | 1805 | EXPORT_SYMBOL(usb_gadget_register_driver); |
@@ -1842,7 +1817,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1842 | return -EINVAL; | 1817 | return -EINVAL; |
1843 | 1818 | ||
1844 | if (udc_controller->transceiver) | 1819 | if (udc_controller->transceiver) |
1845 | (void)otg_set_peripheral(udc_controller->transceiver, 0); | 1820 | otg_set_peripheral(udc_controller->transceiver, NULL); |
1846 | 1821 | ||
1847 | /* stop DR, disable intr */ | 1822 | /* stop DR, disable intr */ |
1848 | dr_controller_stop(udc_controller); | 1823 | dr_controller_stop(udc_controller); |
@@ -1863,10 +1838,10 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1863 | 1838 | ||
1864 | /* unbind gadget and unhook driver. */ | 1839 | /* unbind gadget and unhook driver. */ |
1865 | driver->unbind(&udc_controller->gadget); | 1840 | driver->unbind(&udc_controller->gadget); |
1866 | udc_controller->gadget.dev.driver = 0; | 1841 | udc_controller->gadget.dev.driver = NULL; |
1867 | udc_controller->driver = 0; | 1842 | udc_controller->driver = NULL; |
1868 | 1843 | ||
1869 | printk("unregistered gadget driver '%s'\r\n", driver->driver.name); | 1844 | printk("unregistered gadget driver '%s'\n", driver->driver.name); |
1870 | return 0; | 1845 | return 0; |
1871 | } | 1846 | } |
1872 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | 1847 | EXPORT_SYMBOL(usb_gadget_unregister_driver); |
@@ -1922,7 +1897,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
1922 | tmp_reg = fsl_readl(&dr_regs->usbsts); | 1897 | tmp_reg = fsl_readl(&dr_regs->usbsts); |
1923 | t = scnprintf(next, size, | 1898 | t = scnprintf(next, size, |
1924 | "USB Status Reg:\n" | 1899 | "USB Status Reg:\n" |
1925 | "Dr Suspend: %d" "Reset Received: %d" "System Error: %s" | 1900 | "Dr Suspend: %d Reset Received: %d System Error: %s " |
1926 | "USB Error Interrupt: %s\n\n", | 1901 | "USB Error Interrupt: %s\n\n", |
1927 | (tmp_reg & USB_STS_SUSPEND) ? 1 : 0, | 1902 | (tmp_reg & USB_STS_SUSPEND) ? 1 : 0, |
1928 | (tmp_reg & USB_STS_RESET) ? 1 : 0, | 1903 | (tmp_reg & USB_STS_RESET) ? 1 : 0, |
@@ -1934,11 +1909,11 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
1934 | tmp_reg = fsl_readl(&dr_regs->usbintr); | 1909 | tmp_reg = fsl_readl(&dr_regs->usbintr); |
1935 | t = scnprintf(next, size, | 1910 | t = scnprintf(next, size, |
1936 | "USB Intrrupt Enable Reg:\n" | 1911 | "USB Intrrupt Enable Reg:\n" |
1937 | "Sleep Enable: %d" "SOF Received Enable: %d" | 1912 | "Sleep Enable: %d SOF Received Enable: %d " |
1938 | "Reset Enable: %d\n" | 1913 | "Reset Enable: %d\n" |
1939 | "System Error Enable: %d" | 1914 | "System Error Enable: %d " |
1940 | "Port Change Dectected Enable: %d\n" | 1915 | "Port Change Dectected Enable: %d\n" |
1941 | "USB Error Intr Enable: %d" "USB Intr Enable: %d\n\n", | 1916 | "USB Error Intr Enable: %d USB Intr Enable: %d\n\n", |
1942 | (tmp_reg & USB_INTR_DEVICE_SUSPEND) ? 1 : 0, | 1917 | (tmp_reg & USB_INTR_DEVICE_SUSPEND) ? 1 : 0, |
1943 | (tmp_reg & USB_INTR_SOF_EN) ? 1 : 0, | 1918 | (tmp_reg & USB_INTR_SOF_EN) ? 1 : 0, |
1944 | (tmp_reg & USB_INTR_RESET_EN) ? 1 : 0, | 1919 | (tmp_reg & USB_INTR_RESET_EN) ? 1 : 0, |
@@ -1951,21 +1926,21 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
1951 | 1926 | ||
1952 | tmp_reg = fsl_readl(&dr_regs->frindex); | 1927 | tmp_reg = fsl_readl(&dr_regs->frindex); |
1953 | t = scnprintf(next, size, | 1928 | t = scnprintf(next, size, |
1954 | "USB Frame Index Reg:" "Frame Number is 0x%x\n\n", | 1929 | "USB Frame Index Reg: Frame Number is 0x%x\n\n", |
1955 | (tmp_reg & USB_FRINDEX_MASKS)); | 1930 | (tmp_reg & USB_FRINDEX_MASKS)); |
1956 | size -= t; | 1931 | size -= t; |
1957 | next += t; | 1932 | next += t; |
1958 | 1933 | ||
1959 | tmp_reg = fsl_readl(&dr_regs->deviceaddr); | 1934 | tmp_reg = fsl_readl(&dr_regs->deviceaddr); |
1960 | t = scnprintf(next, size, | 1935 | t = scnprintf(next, size, |
1961 | "USB Device Address Reg:" "Device Addr is 0x%x\n\n", | 1936 | "USB Device Address Reg: Device Addr is 0x%x\n\n", |
1962 | (tmp_reg & USB_DEVICE_ADDRESS_MASK)); | 1937 | (tmp_reg & USB_DEVICE_ADDRESS_MASK)); |
1963 | size -= t; | 1938 | size -= t; |
1964 | next += t; | 1939 | next += t; |
1965 | 1940 | ||
1966 | tmp_reg = fsl_readl(&dr_regs->endpointlistaddr); | 1941 | tmp_reg = fsl_readl(&dr_regs->endpointlistaddr); |
1967 | t = scnprintf(next, size, | 1942 | t = scnprintf(next, size, |
1968 | "USB Endpoint List Address Reg:" | 1943 | "USB Endpoint List Address Reg: " |
1969 | "Device Addr is 0x%x\n\n", | 1944 | "Device Addr is 0x%x\n\n", |
1970 | (tmp_reg & USB_EP_LIST_ADDRESS_MASK)); | 1945 | (tmp_reg & USB_EP_LIST_ADDRESS_MASK)); |
1971 | size -= t; | 1946 | size -= t; |
@@ -1974,11 +1949,12 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
1974 | tmp_reg = fsl_readl(&dr_regs->portsc1); | 1949 | tmp_reg = fsl_readl(&dr_regs->portsc1); |
1975 | t = scnprintf(next, size, | 1950 | t = scnprintf(next, size, |
1976 | "USB Port Status&Control Reg:\n" | 1951 | "USB Port Status&Control Reg:\n" |
1977 | "Port Transceiver Type : %s" "Port Speed: %s \n" | 1952 | "Port Transceiver Type : %s Port Speed: %s\n" |
1978 | "PHY Low Power Suspend: %s" "Port Reset: %s" | 1953 | "PHY Low Power Suspend: %s Port Reset: %s " |
1979 | "Port Suspend Mode: %s \n" "Over-current Change: %s" | 1954 | "Port Suspend Mode: %s\n" |
1955 | "Over-current Change: %s " | ||
1980 | "Port Enable/Disable Change: %s\n" | 1956 | "Port Enable/Disable Change: %s\n" |
1981 | "Port Enabled/Disabled: %s" | 1957 | "Port Enabled/Disabled: %s " |
1982 | "Current Connect Status: %s\n\n", ( { | 1958 | "Current Connect Status: %s\n\n", ( { |
1983 | char *s; | 1959 | char *s; |
1984 | switch (tmp_reg & PORTSCX_PTS_FSLS) { | 1960 | switch (tmp_reg & PORTSCX_PTS_FSLS) { |
@@ -2023,7 +1999,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
2023 | 1999 | ||
2024 | tmp_reg = fsl_readl(&dr_regs->usbmode); | 2000 | tmp_reg = fsl_readl(&dr_regs->usbmode); |
2025 | t = scnprintf(next, size, | 2001 | t = scnprintf(next, size, |
2026 | "USB Mode Reg:" "Controller Mode is : %s\n\n", ( { | 2002 | "USB Mode Reg: Controller Mode is: %s\n\n", ( { |
2027 | char *s; | 2003 | char *s; |
2028 | switch (tmp_reg & USB_MODE_CTRL_MODE_HOST) { | 2004 | switch (tmp_reg & USB_MODE_CTRL_MODE_HOST) { |
2029 | case USB_MODE_CTRL_MODE_IDLE: | 2005 | case USB_MODE_CTRL_MODE_IDLE: |
@@ -2042,7 +2018,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
2042 | 2018 | ||
2043 | tmp_reg = fsl_readl(&dr_regs->endptsetupstat); | 2019 | tmp_reg = fsl_readl(&dr_regs->endptsetupstat); |
2044 | t = scnprintf(next, size, | 2020 | t = scnprintf(next, size, |
2045 | "Endpoint Setup Status Reg:" "SETUP on ep 0x%x\n\n", | 2021 | "Endpoint Setup Status Reg: SETUP on ep 0x%x\n\n", |
2046 | (tmp_reg & EP_SETUP_STATUS_MASK)); | 2022 | (tmp_reg & EP_SETUP_STATUS_MASK)); |
2047 | size -= t; | 2023 | size -= t; |
2048 | next += t; | 2024 | next += t; |
@@ -2055,12 +2031,12 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
2055 | next += t; | 2031 | next += t; |
2056 | } | 2032 | } |
2057 | tmp_reg = fsl_readl(&dr_regs->endpointprime); | 2033 | tmp_reg = fsl_readl(&dr_regs->endpointprime); |
2058 | t = scnprintf(next, size, "EP Prime Reg = [0x%x]\n", tmp_reg); | 2034 | t = scnprintf(next, size, "EP Prime Reg = [0x%x]\n\n", tmp_reg); |
2059 | size -= t; | 2035 | size -= t; |
2060 | next += t; | 2036 | next += t; |
2061 | 2037 | ||
2062 | tmp_reg = usb_sys_regs->snoop1; | 2038 | tmp_reg = usb_sys_regs->snoop1; |
2063 | t = scnprintf(next, size, "\nSnoop1 Reg : = [0x%x]\n\n", tmp_reg); | 2039 | t = scnprintf(next, size, "Snoop1 Reg : = [0x%x]\n\n", tmp_reg); |
2064 | size -= t; | 2040 | size -= t; |
2065 | next += t; | 2041 | next += t; |
2066 | 2042 | ||
@@ -2084,7 +2060,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
2084 | } else { | 2060 | } else { |
2085 | list_for_each_entry(req, &ep->queue, queue) { | 2061 | list_for_each_entry(req, &ep->queue, queue) { |
2086 | t = scnprintf(next, size, | 2062 | t = scnprintf(next, size, |
2087 | "req %p actual 0x%x length 0x%x buf %p\n", | 2063 | "req %p actual 0x%x length 0x%x buf %p\n", |
2088 | &req->req, req->req.actual, | 2064 | &req->req, req->req.actual, |
2089 | req->req.length, req->req.buf); | 2065 | req->req.length, req->req.buf); |
2090 | size -= t; | 2066 | size -= t; |
@@ -2110,7 +2086,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
2110 | } else { | 2086 | } else { |
2111 | list_for_each_entry(req, &ep->queue, queue) { | 2087 | list_for_each_entry(req, &ep->queue, queue) { |
2112 | t = scnprintf(next, size, | 2088 | t = scnprintf(next, size, |
2113 | "req %p actual 0x%x length" | 2089 | "req %p actual 0x%x length " |
2114 | "0x%x buf %p\n", | 2090 | "0x%x buf %p\n", |
2115 | &req->req, req->req.actual, | 2091 | &req->req, req->req.actual, |
2116 | req->req.length, req->req.buf); | 2092 | req->req.length, req->req.buf); |
@@ -2202,7 +2178,6 @@ static int __init struct_udc_setup(struct fsl_udc *udc, | |||
2202 | udc->usb_state = USB_STATE_POWERED; | 2178 | udc->usb_state = USB_STATE_POWERED; |
2203 | udc->ep0_dir = 0; | 2179 | udc->ep0_dir = 0; |
2204 | udc->remote_wakeup = 0; /* default to 0 on reset */ | 2180 | udc->remote_wakeup = 0; /* default to 0 on reset */ |
2205 | spin_lock_init(&udc->lock); | ||
2206 | 2181 | ||
2207 | return 0; | 2182 | return 0; |
2208 | } | 2183 | } |
@@ -2254,7 +2229,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2254 | u32 dccparams; | 2229 | u32 dccparams; |
2255 | 2230 | ||
2256 | if (strcmp(pdev->name, driver_name)) { | 2231 | if (strcmp(pdev->name, driver_name)) { |
2257 | VDBG("Wrong device\n"); | 2232 | VDBG("Wrong device"); |
2258 | return -ENODEV; | 2233 | return -ENODEV; |
2259 | } | 2234 | } |
2260 | 2235 | ||
@@ -2264,23 +2239,26 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2264 | return -ENOMEM; | 2239 | return -ENOMEM; |
2265 | } | 2240 | } |
2266 | 2241 | ||
2242 | spin_lock_init(&udc_controller->lock); | ||
2243 | udc_controller->stopped = 1; | ||
2244 | |||
2267 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 2245 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
2268 | if (!res) { | 2246 | if (!res) { |
2269 | kfree(udc_controller); | 2247 | ret = -ENXIO; |
2270 | return -ENXIO; | 2248 | goto err_kfree; |
2271 | } | 2249 | } |
2272 | 2250 | ||
2273 | if (!request_mem_region(res->start, res->end - res->start + 1, | 2251 | if (!request_mem_region(res->start, res->end - res->start + 1, |
2274 | driver_name)) { | 2252 | driver_name)) { |
2275 | ERR("request mem region for %s failed \n", pdev->name); | 2253 | ERR("request mem region for %s failed\n", pdev->name); |
2276 | kfree(udc_controller); | 2254 | ret = -EBUSY; |
2277 | return -EBUSY; | 2255 | goto err_kfree; |
2278 | } | 2256 | } |
2279 | 2257 | ||
2280 | dr_regs = ioremap(res->start, res->end - res->start + 1); | 2258 | dr_regs = ioremap(res->start, res->end - res->start + 1); |
2281 | if (!dr_regs) { | 2259 | if (!dr_regs) { |
2282 | ret = -ENOMEM; | 2260 | ret = -ENOMEM; |
2283 | goto err1; | 2261 | goto err_release_mem_region; |
2284 | } | 2262 | } |
2285 | 2263 | ||
2286 | usb_sys_regs = (struct usb_sys_interface *) | 2264 | usb_sys_regs = (struct usb_sys_interface *) |
@@ -2291,7 +2269,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2291 | if (!(dccparams & DCCPARAMS_DC)) { | 2269 | if (!(dccparams & DCCPARAMS_DC)) { |
2292 | ERR("This SOC doesn't support device role\n"); | 2270 | ERR("This SOC doesn't support device role\n"); |
2293 | ret = -ENODEV; | 2271 | ret = -ENODEV; |
2294 | goto err2; | 2272 | goto err_iounmap; |
2295 | } | 2273 | } |
2296 | /* Get max device endpoints */ | 2274 | /* Get max device endpoints */ |
2297 | /* DEN is bidirectional ep number, max_ep doubles the number */ | 2275 | /* DEN is bidirectional ep number, max_ep doubles the number */ |
@@ -2300,22 +2278,22 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2300 | udc_controller->irq = platform_get_irq(pdev, 0); | 2278 | udc_controller->irq = platform_get_irq(pdev, 0); |
2301 | if (!udc_controller->irq) { | 2279 | if (!udc_controller->irq) { |
2302 | ret = -ENODEV; | 2280 | ret = -ENODEV; |
2303 | goto err2; | 2281 | goto err_iounmap; |
2304 | } | 2282 | } |
2305 | 2283 | ||
2306 | ret = request_irq(udc_controller->irq, fsl_udc_irq, IRQF_SHARED, | 2284 | ret = request_irq(udc_controller->irq, fsl_udc_irq, IRQF_SHARED, |
2307 | driver_name, udc_controller); | 2285 | driver_name, udc_controller); |
2308 | if (ret != 0) { | 2286 | if (ret != 0) { |
2309 | ERR("cannot request irq %d err %d \n", | 2287 | ERR("cannot request irq %d err %d\n", |
2310 | udc_controller->irq, ret); | 2288 | udc_controller->irq, ret); |
2311 | goto err2; | 2289 | goto err_iounmap; |
2312 | } | 2290 | } |
2313 | 2291 | ||
2314 | /* Initialize the udc structure including QH member and other member */ | 2292 | /* Initialize the udc structure including QH member and other member */ |
2315 | if (struct_udc_setup(udc_controller, pdev)) { | 2293 | if (struct_udc_setup(udc_controller, pdev)) { |
2316 | ERR("Can't initialize udc data structure\n"); | 2294 | ERR("Can't initialize udc data structure\n"); |
2317 | ret = -ENOMEM; | 2295 | ret = -ENOMEM; |
2318 | goto err3; | 2296 | goto err_free_irq; |
2319 | } | 2297 | } |
2320 | 2298 | ||
2321 | /* initialize usb hw reg except for regs for EP, | 2299 | /* initialize usb hw reg except for regs for EP, |
@@ -2336,7 +2314,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2336 | udc_controller->gadget.dev.parent = &pdev->dev; | 2314 | udc_controller->gadget.dev.parent = &pdev->dev; |
2337 | ret = device_register(&udc_controller->gadget.dev); | 2315 | ret = device_register(&udc_controller->gadget.dev); |
2338 | if (ret < 0) | 2316 | if (ret < 0) |
2339 | goto err3; | 2317 | goto err_free_irq; |
2340 | 2318 | ||
2341 | /* setup QH and epctrl for ep0 */ | 2319 | /* setup QH and epctrl for ep0 */ |
2342 | ep0_setup(udc_controller); | 2320 | ep0_setup(udc_controller); |
@@ -2366,20 +2344,22 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2366 | DTD_ALIGNMENT, UDC_DMA_BOUNDARY); | 2344 | DTD_ALIGNMENT, UDC_DMA_BOUNDARY); |
2367 | if (udc_controller->td_pool == NULL) { | 2345 | if (udc_controller->td_pool == NULL) { |
2368 | ret = -ENOMEM; | 2346 | ret = -ENOMEM; |
2369 | goto err4; | 2347 | goto err_unregister; |
2370 | } | 2348 | } |
2371 | create_proc_file(); | 2349 | create_proc_file(); |
2372 | return 0; | 2350 | return 0; |
2373 | 2351 | ||
2374 | err4: | 2352 | err_unregister: |
2375 | device_unregister(&udc_controller->gadget.dev); | 2353 | device_unregister(&udc_controller->gadget.dev); |
2376 | err3: | 2354 | err_free_irq: |
2377 | free_irq(udc_controller->irq, udc_controller); | 2355 | free_irq(udc_controller->irq, udc_controller); |
2378 | err2: | 2356 | err_iounmap: |
2379 | iounmap(dr_regs); | 2357 | iounmap(dr_regs); |
2380 | err1: | 2358 | err_release_mem_region: |
2381 | release_mem_region(res->start, res->end - res->start + 1); | 2359 | release_mem_region(res->start, res->end - res->start + 1); |
2360 | err_kfree: | ||
2382 | kfree(udc_controller); | 2361 | kfree(udc_controller); |
2362 | udc_controller = NULL; | ||
2383 | return ret; | 2363 | return ret; |
2384 | } | 2364 | } |
2385 | 2365 | ||
@@ -2469,7 +2449,7 @@ module_init(udc_init); | |||
2469 | static void __exit udc_exit(void) | 2449 | static void __exit udc_exit(void) |
2470 | { | 2450 | { |
2471 | platform_driver_unregister(&udc_driver); | 2451 | platform_driver_unregister(&udc_driver); |
2472 | printk("%s unregistered \n", driver_desc); | 2452 | printk("%s unregistered\n", driver_desc); |
2473 | } | 2453 | } |
2474 | 2454 | ||
2475 | module_exit(udc_exit); | 2455 | module_exit(udc_exit); |
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h index 6131752a38bc..e63ef12645f5 100644 --- a/drivers/usb/gadget/fsl_usb2_udc.h +++ b/drivers/usb/gadget/fsl_usb2_udc.h | |||
@@ -424,16 +424,6 @@ struct ep_td_struct { | |||
424 | /* Controller dma boundary */ | 424 | /* Controller dma boundary */ |
425 | #define UDC_DMA_BOUNDARY 0x1000 | 425 | #define UDC_DMA_BOUNDARY 0x1000 |
426 | 426 | ||
427 | /* -----------------------------------------------------------------------*/ | ||
428 | /* ##### enum data | ||
429 | */ | ||
430 | typedef enum { | ||
431 | e_ULPI, | ||
432 | e_UTMI_8BIT, | ||
433 | e_UTMI_16BIT, | ||
434 | e_SERIAL | ||
435 | } e_PhyInterface; | ||
436 | |||
437 | /*-------------------------------------------------------------------------*/ | 427 | /*-------------------------------------------------------------------------*/ |
438 | 428 | ||
439 | /* ### driver private data | 429 | /* ### driver private data |
@@ -469,9 +459,9 @@ struct fsl_ep { | |||
469 | #define EP_DIR_OUT 0 | 459 | #define EP_DIR_OUT 0 |
470 | 460 | ||
471 | struct fsl_udc { | 461 | struct fsl_udc { |
472 | |||
473 | struct usb_gadget gadget; | 462 | struct usb_gadget gadget; |
474 | struct usb_gadget_driver *driver; | 463 | struct usb_gadget_driver *driver; |
464 | struct completion *done; /* to make sure release() is done */ | ||
475 | struct fsl_ep *eps; | 465 | struct fsl_ep *eps; |
476 | unsigned int max_ep; | 466 | unsigned int max_ep; |
477 | unsigned int irq; | 467 | unsigned int irq; |
@@ -492,20 +482,13 @@ struct fsl_udc { | |||
492 | size_t ep_qh_size; /* size after alignment adjustment*/ | 482 | size_t ep_qh_size; /* size after alignment adjustment*/ |
493 | dma_addr_t ep_qh_dma; /* dma address of QH */ | 483 | dma_addr_t ep_qh_dma; /* dma address of QH */ |
494 | 484 | ||
495 | u32 max_pipes; /* Device max pipes */ | 485 | u32 max_pipes; /* Device max pipes */ |
496 | u32 max_use_endpts; /* Max endpointes to be used */ | ||
497 | u32 bus_reset; /* Device is bus reseting */ | ||
498 | u32 resume_state; /* USB state to resume */ | 486 | u32 resume_state; /* USB state to resume */ |
499 | u32 usb_state; /* USB current state */ | 487 | u32 usb_state; /* USB current state */ |
500 | u32 usb_next_state; /* USB next state */ | ||
501 | u32 ep0_state; /* Endpoint zero state */ | 488 | u32 ep0_state; /* Endpoint zero state */ |
502 | u32 ep0_dir; /* Endpoint zero direction: can be | 489 | u32 ep0_dir; /* Endpoint zero direction: can be |
503 | USB_DIR_IN or USB_DIR_OUT */ | 490 | USB_DIR_IN or USB_DIR_OUT */ |
504 | u32 usb_sof_count; /* SOF count */ | ||
505 | u32 errors; /* USB ERRORs count */ | ||
506 | u8 device_address; /* Device USB address */ | 491 | u8 device_address; /* Device USB address */ |
507 | |||
508 | struct completion *done; /* to make sure release() is done */ | ||
509 | }; | 492 | }; |
510 | 493 | ||
511 | /*-------------------------------------------------------------------------*/ | 494 | /*-------------------------------------------------------------------------*/ |
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index 17d9905101b7..4e3107dd2f34 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h | |||
@@ -151,6 +151,13 @@ | |||
151 | #define gadget_is_m66592(g) 0 | 151 | #define gadget_is_m66592(g) 0 |
152 | #endif | 152 | #endif |
153 | 153 | ||
154 | /* Freescale CPM/QE UDC SUPPORT */ | ||
155 | #ifdef CONFIG_USB_GADGET_FSL_QE | ||
156 | #define gadget_is_fsl_qe(g) !strcmp("fsl_qe_udc", (g)->name) | ||
157 | #else | ||
158 | #define gadget_is_fsl_qe(g) 0 | ||
159 | #endif | ||
160 | |||
154 | 161 | ||
155 | // CONFIG_USB_GADGET_SX2 | 162 | // CONFIG_USB_GADGET_SX2 |
156 | // CONFIG_USB_GADGET_AU1X00 | 163 | // CONFIG_USB_GADGET_AU1X00 |
@@ -216,6 +223,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
216 | return 0x20; | 223 | return 0x20; |
217 | else if (gadget_is_m66592(gadget)) | 224 | else if (gadget_is_m66592(gadget)) |
218 | return 0x21; | 225 | return 0x21; |
226 | else if (gadget_is_fsl_qe(gadget)) | ||
227 | return 0x22; | ||
219 | return -ENOENT; | 228 | return -ENOENT; |
220 | } | 229 | } |
221 | 230 | ||
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c index ea8651e3da1a..60d3f9e9b51f 100644 --- a/drivers/usb/gadget/gmidi.c +++ b/drivers/usb/gadget/gmidi.c | |||
@@ -35,6 +35,21 @@ | |||
35 | 35 | ||
36 | #include "gadget_chips.h" | 36 | #include "gadget_chips.h" |
37 | 37 | ||
38 | |||
39 | /* | ||
40 | * Kbuild is not very cooperative with respect to linking separately | ||
41 | * compiled library objects into one module. So for now we won't use | ||
42 | * separate compilation ... ensuring init/exit sections work to shrink | ||
43 | * the runtime footprint, and giving us at least some parts of what | ||
44 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
45 | */ | ||
46 | #include "usbstring.c" | ||
47 | #include "config.c" | ||
48 | #include "epautoconf.c" | ||
49 | |||
50 | /*-------------------------------------------------------------------------*/ | ||
51 | |||
52 | |||
38 | MODULE_AUTHOR("Ben Williamson"); | 53 | MODULE_AUTHOR("Ben Williamson"); |
39 | MODULE_LICENSE("GPL v2"); | 54 | MODULE_LICENSE("GPL v2"); |
40 | 55 | ||
@@ -207,7 +222,7 @@ static struct usb_config_descriptor config_desc = { | |||
207 | * power properties of the device. Is it selfpowered? | 222 | * power properties of the device. Is it selfpowered? |
208 | */ | 223 | */ |
209 | .bmAttributes = USB_CONFIG_ATT_ONE, | 224 | .bmAttributes = USB_CONFIG_ATT_ONE, |
210 | .bMaxPower = 1, | 225 | .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, |
211 | }; | 226 | }; |
212 | 227 | ||
213 | /* B.3.1 Standard AC Interface Descriptor */ | 228 | /* B.3.1 Standard AC Interface Descriptor */ |
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c index 5cfb5ebf3881..8ae70de2c37d 100644 --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c | |||
@@ -178,6 +178,7 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
178 | 178 | ||
179 | /* ep_reset() has already been called */ | 179 | /* ep_reset() has already been called */ |
180 | ep->stopped = 0; | 180 | ep->stopped = 0; |
181 | ep->wedged = 0; | ||
181 | ep->out_overflow = 0; | 182 | ep->out_overflow = 0; |
182 | 183 | ||
183 | /* set speed-dependent max packet; may kick in high bandwidth */ | 184 | /* set speed-dependent max packet; may kick in high bandwidth */ |
@@ -1218,7 +1219,7 @@ static int net2280_dequeue (struct usb_ep *_ep, struct usb_request *_req) | |||
1218 | static int net2280_fifo_status (struct usb_ep *_ep); | 1219 | static int net2280_fifo_status (struct usb_ep *_ep); |
1219 | 1220 | ||
1220 | static int | 1221 | static int |
1221 | net2280_set_halt (struct usb_ep *_ep, int value) | 1222 | net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged) |
1222 | { | 1223 | { |
1223 | struct net2280_ep *ep; | 1224 | struct net2280_ep *ep; |
1224 | unsigned long flags; | 1225 | unsigned long flags; |
@@ -1239,16 +1240,21 @@ net2280_set_halt (struct usb_ep *_ep, int value) | |||
1239 | else if (ep->is_in && value && net2280_fifo_status (_ep) != 0) | 1240 | else if (ep->is_in && value && net2280_fifo_status (_ep) != 0) |
1240 | retval = -EAGAIN; | 1241 | retval = -EAGAIN; |
1241 | else { | 1242 | else { |
1242 | VDEBUG (ep->dev, "%s %s halt\n", _ep->name, | 1243 | VDEBUG (ep->dev, "%s %s %s\n", _ep->name, |
1243 | value ? "set" : "clear"); | 1244 | value ? "set" : "clear", |
1245 | wedged ? "wedge" : "halt"); | ||
1244 | /* set/clear, then synch memory views with the device */ | 1246 | /* set/clear, then synch memory views with the device */ |
1245 | if (value) { | 1247 | if (value) { |
1246 | if (ep->num == 0) | 1248 | if (ep->num == 0) |
1247 | ep->dev->protocol_stall = 1; | 1249 | ep->dev->protocol_stall = 1; |
1248 | else | 1250 | else |
1249 | set_halt (ep); | 1251 | set_halt (ep); |
1250 | } else | 1252 | if (wedged) |
1253 | ep->wedged = 1; | ||
1254 | } else { | ||
1251 | clear_halt (ep); | 1255 | clear_halt (ep); |
1256 | ep->wedged = 0; | ||
1257 | } | ||
1252 | (void) readl (&ep->regs->ep_rsp); | 1258 | (void) readl (&ep->regs->ep_rsp); |
1253 | } | 1259 | } |
1254 | spin_unlock_irqrestore (&ep->dev->lock, flags); | 1260 | spin_unlock_irqrestore (&ep->dev->lock, flags); |
@@ -1257,6 +1263,20 @@ net2280_set_halt (struct usb_ep *_ep, int value) | |||
1257 | } | 1263 | } |
1258 | 1264 | ||
1259 | static int | 1265 | static int |
1266 | net2280_set_halt(struct usb_ep *_ep, int value) | ||
1267 | { | ||
1268 | return net2280_set_halt_and_wedge(_ep, value, 0); | ||
1269 | } | ||
1270 | |||
1271 | static int | ||
1272 | net2280_set_wedge(struct usb_ep *_ep) | ||
1273 | { | ||
1274 | if (!_ep || _ep->name == ep0name) | ||
1275 | return -EINVAL; | ||
1276 | return net2280_set_halt_and_wedge(_ep, 1, 1); | ||
1277 | } | ||
1278 | |||
1279 | static int | ||
1260 | net2280_fifo_status (struct usb_ep *_ep) | 1280 | net2280_fifo_status (struct usb_ep *_ep) |
1261 | { | 1281 | { |
1262 | struct net2280_ep *ep; | 1282 | struct net2280_ep *ep; |
@@ -1302,6 +1322,7 @@ static const struct usb_ep_ops net2280_ep_ops = { | |||
1302 | .dequeue = net2280_dequeue, | 1322 | .dequeue = net2280_dequeue, |
1303 | 1323 | ||
1304 | .set_halt = net2280_set_halt, | 1324 | .set_halt = net2280_set_halt, |
1325 | .set_wedge = net2280_set_wedge, | ||
1305 | .fifo_status = net2280_fifo_status, | 1326 | .fifo_status = net2280_fifo_status, |
1306 | .fifo_flush = net2280_fifo_flush, | 1327 | .fifo_flush = net2280_fifo_flush, |
1307 | }; | 1328 | }; |
@@ -2410,9 +2431,14 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) | |||
2410 | goto do_stall; | 2431 | goto do_stall; |
2411 | if ((e = get_ep_by_addr (dev, w_index)) == 0) | 2432 | if ((e = get_ep_by_addr (dev, w_index)) == 0) |
2412 | goto do_stall; | 2433 | goto do_stall; |
2413 | clear_halt (e); | 2434 | if (e->wedged) { |
2435 | VDEBUG(dev, "%s wedged, halt not cleared\n", | ||
2436 | ep->ep.name); | ||
2437 | } else { | ||
2438 | VDEBUG(dev, "%s clear halt\n", ep->ep.name); | ||
2439 | clear_halt(e); | ||
2440 | } | ||
2414 | allow_status (ep); | 2441 | allow_status (ep); |
2415 | VDEBUG (dev, "%s clear halt\n", ep->ep.name); | ||
2416 | goto next_endpoints; | 2442 | goto next_endpoints; |
2417 | } | 2443 | } |
2418 | break; | 2444 | break; |
@@ -2427,6 +2453,8 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat) | |||
2427 | goto do_stall; | 2453 | goto do_stall; |
2428 | if ((e = get_ep_by_addr (dev, w_index)) == 0) | 2454 | if ((e = get_ep_by_addr (dev, w_index)) == 0) |
2429 | goto do_stall; | 2455 | goto do_stall; |
2456 | if (e->ep.name == ep0name) | ||
2457 | goto do_stall; | ||
2430 | set_halt (e); | 2458 | set_halt (e); |
2431 | allow_status (ep); | 2459 | allow_status (ep); |
2432 | VDEBUG (dev, "%s set halt\n", ep->ep.name); | 2460 | VDEBUG (dev, "%s set halt\n", ep->ep.name); |
diff --git a/drivers/usb/gadget/net2280.h b/drivers/usb/gadget/net2280.h index 81a71dbdc2c6..c36852263d93 100644 --- a/drivers/usb/gadget/net2280.h +++ b/drivers/usb/gadget/net2280.h | |||
@@ -109,6 +109,7 @@ struct net2280_ep { | |||
109 | in_fifo_validate : 1, | 109 | in_fifo_validate : 1, |
110 | out_overflow : 1, | 110 | out_overflow : 1, |
111 | stopped : 1, | 111 | stopped : 1, |
112 | wedged : 1, | ||
112 | is_in : 1, | 113 | is_in : 1, |
113 | is_iso : 1, | 114 | is_iso : 1, |
114 | responded : 1; | 115 | responded : 1; |
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index bb54cca4c543..34e9e393f929 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c | |||
@@ -2313,6 +2313,13 @@ static int proc_otg_show(struct seq_file *s) | |||
2313 | 2313 | ||
2314 | tmp = omap_readl(OTG_REV); | 2314 | tmp = omap_readl(OTG_REV); |
2315 | if (cpu_is_omap24xx()) { | 2315 | if (cpu_is_omap24xx()) { |
2316 | /* | ||
2317 | * REVISIT: Not clear how this works on OMAP2. trans | ||
2318 | * is ANDed to produce bits 7 and 8, which might make | ||
2319 | * sense for USB_TRANSCEIVER_CTRL on OMAP1, | ||
2320 | * but with CONTROL_DEVCONF, these bits have something to | ||
2321 | * do with the frame adjustment counter and McBSP2. | ||
2322 | */ | ||
2316 | ctrl_name = "control_devconf"; | 2323 | ctrl_name = "control_devconf"; |
2317 | trans = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); | 2324 | trans = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); |
2318 | } else { | 2325 | } else { |
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index e0090085b78e..5a3034fdfe47 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c | |||
@@ -53,6 +53,20 @@ | |||
53 | 53 | ||
54 | #include "gadget_chips.h" | 54 | #include "gadget_chips.h" |
55 | 55 | ||
56 | |||
57 | /* | ||
58 | * Kbuild is not very cooperative with respect to linking separately | ||
59 | * compiled library objects into one module. So for now we won't use | ||
60 | * separate compilation ... ensuring init/exit sections work to shrink | ||
61 | * the runtime footprint, and giving us at least some parts of what | ||
62 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
63 | */ | ||
64 | #include "usbstring.c" | ||
65 | #include "config.c" | ||
66 | #include "epautoconf.c" | ||
67 | |||
68 | /*-------------------------------------------------------------------------*/ | ||
69 | |||
56 | #define DRIVER_DESC "Printer Gadget" | 70 | #define DRIVER_DESC "Printer Gadget" |
57 | #define DRIVER_VERSION "2007 OCT 06" | 71 | #define DRIVER_VERSION "2007 OCT 06" |
58 | 72 | ||
@@ -238,7 +252,7 @@ static struct usb_config_descriptor config_desc = { | |||
238 | .bConfigurationValue = DEV_CONFIG_VALUE, | 252 | .bConfigurationValue = DEV_CONFIG_VALUE, |
239 | .iConfiguration = 0, | 253 | .iConfiguration = 0, |
240 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, | 254 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, |
241 | .bMaxPower = 1 /* Self-Powered */ | 255 | .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, |
242 | }; | 256 | }; |
243 | 257 | ||
244 | static struct usb_interface_descriptor intf_desc = { | 258 | static struct usb_interface_descriptor intf_desc = { |
@@ -1264,8 +1278,7 @@ unknown: | |||
1264 | /* respond with data transfer before status phase? */ | 1278 | /* respond with data transfer before status phase? */ |
1265 | if (value >= 0) { | 1279 | if (value >= 0) { |
1266 | req->length = value; | 1280 | req->length = value; |
1267 | req->zero = value < wLength | 1281 | req->zero = value < wLength; |
1268 | && (value % gadget->ep0->maxpacket) == 0; | ||
1269 | value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); | 1282 | value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); |
1270 | if (value < 0) { | 1283 | if (value < 0) { |
1271 | DBG(dev, "ep_queue --> %d\n", value); | 1284 | DBG(dev, "ep_queue --> %d\n", value); |
@@ -1360,8 +1373,8 @@ printer_bind(struct usb_gadget *gadget) | |||
1360 | 1373 | ||
1361 | 1374 | ||
1362 | /* Setup the sysfs files for the printer gadget. */ | 1375 | /* Setup the sysfs files for the printer gadget. */ |
1363 | dev->pdev = device_create_drvdata(usb_gadget_class, NULL, | 1376 | dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno, |
1364 | g_printer_devno, NULL, "g_printer"); | 1377 | NULL, "g_printer"); |
1365 | if (IS_ERR(dev->pdev)) { | 1378 | if (IS_ERR(dev->pdev)) { |
1366 | ERROR(dev, "Failed to create device: g_printer\n"); | 1379 | ERROR(dev, "Failed to create device: g_printer\n"); |
1367 | goto fail; | 1380 | goto fail; |
@@ -1463,7 +1476,6 @@ autoconf_fail: | |||
1463 | if (gadget->is_otg) { | 1476 | if (gadget->is_otg) { |
1464 | otg_desc.bmAttributes |= USB_OTG_HNP, | 1477 | otg_desc.bmAttributes |= USB_OTG_HNP, |
1465 | config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 1478 | config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
1466 | config_desc.bMaxPower = 4; | ||
1467 | } | 1479 | } |
1468 | 1480 | ||
1469 | spin_lock_init(&dev->lock); | 1481 | spin_lock_init(&dev->lock); |
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 7cbc78a6853d..bcf375ca3d72 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c | |||
@@ -22,7 +22,6 @@ | |||
22 | #include <linux/module.h> | 22 | #include <linux/module.h> |
23 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
24 | #include <linux/types.h> | 24 | #include <linux/types.h> |
25 | #include <linux/version.h> | ||
26 | #include <linux/errno.h> | 25 | #include <linux/errno.h> |
27 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
28 | #include <linux/delay.h> | 27 | #include <linux/delay.h> |
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index 7228e8562236..8c26f5ea2b83 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c | |||
@@ -57,11 +57,6 @@ MODULE_PARM_DESC (rndis_debug, "enable debugging"); | |||
57 | #define rndis_debug 0 | 57 | #define rndis_debug 0 |
58 | #endif | 58 | #endif |
59 | 59 | ||
60 | #define DBG(str,args...) do { \ | ||
61 | if (rndis_debug) \ | ||
62 | pr_debug(str , ## args); \ | ||
63 | } while (0) | ||
64 | |||
65 | #define RNDIS_MAX_CONFIGS 1 | 60 | #define RNDIS_MAX_CONFIGS 1 |
66 | 61 | ||
67 | 62 | ||
@@ -183,9 +178,9 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
183 | if (!resp) return -ENOMEM; | 178 | if (!resp) return -ENOMEM; |
184 | 179 | ||
185 | if (buf_len && rndis_debug > 1) { | 180 | if (buf_len && rndis_debug > 1) { |
186 | DBG("query OID %08x value, len %d:\n", OID, buf_len); | 181 | pr_debug("query OID %08x value, len %d:\n", OID, buf_len); |
187 | for (i = 0; i < buf_len; i += 16) { | 182 | for (i = 0; i < buf_len; i += 16) { |
188 | DBG("%03d: %08x %08x %08x %08x\n", i, | 183 | pr_debug("%03d: %08x %08x %08x %08x\n", i, |
189 | get_unaligned_le32(&buf[i]), | 184 | get_unaligned_le32(&buf[i]), |
190 | get_unaligned_le32(&buf[i + 4]), | 185 | get_unaligned_le32(&buf[i + 4]), |
191 | get_unaligned_le32(&buf[i + 8]), | 186 | get_unaligned_le32(&buf[i + 8]), |
@@ -209,7 +204,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
209 | 204 | ||
210 | /* mandatory */ | 205 | /* mandatory */ |
211 | case OID_GEN_SUPPORTED_LIST: | 206 | case OID_GEN_SUPPORTED_LIST: |
212 | DBG("%s: OID_GEN_SUPPORTED_LIST\n", __func__); | 207 | pr_debug("%s: OID_GEN_SUPPORTED_LIST\n", __func__); |
213 | length = sizeof (oid_supported_list); | 208 | length = sizeof (oid_supported_list); |
214 | count = length / sizeof (u32); | 209 | count = length / sizeof (u32); |
215 | for (i = 0; i < count; i++) | 210 | for (i = 0; i < count; i++) |
@@ -219,7 +214,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
219 | 214 | ||
220 | /* mandatory */ | 215 | /* mandatory */ |
221 | case OID_GEN_HARDWARE_STATUS: | 216 | case OID_GEN_HARDWARE_STATUS: |
222 | DBG("%s: OID_GEN_HARDWARE_STATUS\n", __func__); | 217 | pr_debug("%s: OID_GEN_HARDWARE_STATUS\n", __func__); |
223 | /* Bogus question! | 218 | /* Bogus question! |
224 | * Hardware must be ready to receive high level protocols. | 219 | * Hardware must be ready to receive high level protocols. |
225 | * BTW: | 220 | * BTW: |
@@ -232,14 +227,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
232 | 227 | ||
233 | /* mandatory */ | 228 | /* mandatory */ |
234 | case OID_GEN_MEDIA_SUPPORTED: | 229 | case OID_GEN_MEDIA_SUPPORTED: |
235 | DBG("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__); | 230 | pr_debug("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__); |
236 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); | 231 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); |
237 | retval = 0; | 232 | retval = 0; |
238 | break; | 233 | break; |
239 | 234 | ||
240 | /* mandatory */ | 235 | /* mandatory */ |
241 | case OID_GEN_MEDIA_IN_USE: | 236 | case OID_GEN_MEDIA_IN_USE: |
242 | DBG("%s: OID_GEN_MEDIA_IN_USE\n", __func__); | 237 | pr_debug("%s: OID_GEN_MEDIA_IN_USE\n", __func__); |
243 | /* one medium, one transport... (maybe you do it better) */ | 238 | /* one medium, one transport... (maybe you do it better) */ |
244 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); | 239 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); |
245 | retval = 0; | 240 | retval = 0; |
@@ -247,7 +242,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
247 | 242 | ||
248 | /* mandatory */ | 243 | /* mandatory */ |
249 | case OID_GEN_MAXIMUM_FRAME_SIZE: | 244 | case OID_GEN_MAXIMUM_FRAME_SIZE: |
250 | DBG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__); | 245 | pr_debug("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__); |
251 | if (rndis_per_dev_params [configNr].dev) { | 246 | if (rndis_per_dev_params [configNr].dev) { |
252 | *outbuf = cpu_to_le32 ( | 247 | *outbuf = cpu_to_le32 ( |
253 | rndis_per_dev_params [configNr].dev->mtu); | 248 | rndis_per_dev_params [configNr].dev->mtu); |
@@ -258,7 +253,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
258 | /* mandatory */ | 253 | /* mandatory */ |
259 | case OID_GEN_LINK_SPEED: | 254 | case OID_GEN_LINK_SPEED: |
260 | if (rndis_debug > 1) | 255 | if (rndis_debug > 1) |
261 | DBG("%s: OID_GEN_LINK_SPEED\n", __func__); | 256 | pr_debug("%s: OID_GEN_LINK_SPEED\n", __func__); |
262 | if (rndis_per_dev_params [configNr].media_state | 257 | if (rndis_per_dev_params [configNr].media_state |
263 | == NDIS_MEDIA_STATE_DISCONNECTED) | 258 | == NDIS_MEDIA_STATE_DISCONNECTED) |
264 | *outbuf = __constant_cpu_to_le32 (0); | 259 | *outbuf = __constant_cpu_to_le32 (0); |
@@ -270,7 +265,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
270 | 265 | ||
271 | /* mandatory */ | 266 | /* mandatory */ |
272 | case OID_GEN_TRANSMIT_BLOCK_SIZE: | 267 | case OID_GEN_TRANSMIT_BLOCK_SIZE: |
273 | DBG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__); | 268 | pr_debug("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__); |
274 | if (rndis_per_dev_params [configNr].dev) { | 269 | if (rndis_per_dev_params [configNr].dev) { |
275 | *outbuf = cpu_to_le32 ( | 270 | *outbuf = cpu_to_le32 ( |
276 | rndis_per_dev_params [configNr].dev->mtu); | 271 | rndis_per_dev_params [configNr].dev->mtu); |
@@ -280,7 +275,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
280 | 275 | ||
281 | /* mandatory */ | 276 | /* mandatory */ |
282 | case OID_GEN_RECEIVE_BLOCK_SIZE: | 277 | case OID_GEN_RECEIVE_BLOCK_SIZE: |
283 | DBG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__); | 278 | pr_debug("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__); |
284 | if (rndis_per_dev_params [configNr].dev) { | 279 | if (rndis_per_dev_params [configNr].dev) { |
285 | *outbuf = cpu_to_le32 ( | 280 | *outbuf = cpu_to_le32 ( |
286 | rndis_per_dev_params [configNr].dev->mtu); | 281 | rndis_per_dev_params [configNr].dev->mtu); |
@@ -290,7 +285,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
290 | 285 | ||
291 | /* mandatory */ | 286 | /* mandatory */ |
292 | case OID_GEN_VENDOR_ID: | 287 | case OID_GEN_VENDOR_ID: |
293 | DBG("%s: OID_GEN_VENDOR_ID\n", __func__); | 288 | pr_debug("%s: OID_GEN_VENDOR_ID\n", __func__); |
294 | *outbuf = cpu_to_le32 ( | 289 | *outbuf = cpu_to_le32 ( |
295 | rndis_per_dev_params [configNr].vendorID); | 290 | rndis_per_dev_params [configNr].vendorID); |
296 | retval = 0; | 291 | retval = 0; |
@@ -298,7 +293,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
298 | 293 | ||
299 | /* mandatory */ | 294 | /* mandatory */ |
300 | case OID_GEN_VENDOR_DESCRIPTION: | 295 | case OID_GEN_VENDOR_DESCRIPTION: |
301 | DBG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__); | 296 | pr_debug("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__); |
302 | length = strlen (rndis_per_dev_params [configNr].vendorDescr); | 297 | length = strlen (rndis_per_dev_params [configNr].vendorDescr); |
303 | memcpy (outbuf, | 298 | memcpy (outbuf, |
304 | rndis_per_dev_params [configNr].vendorDescr, length); | 299 | rndis_per_dev_params [configNr].vendorDescr, length); |
@@ -306,7 +301,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
306 | break; | 301 | break; |
307 | 302 | ||
308 | case OID_GEN_VENDOR_DRIVER_VERSION: | 303 | case OID_GEN_VENDOR_DRIVER_VERSION: |
309 | DBG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__); | 304 | pr_debug("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__); |
310 | /* Created as LE */ | 305 | /* Created as LE */ |
311 | *outbuf = rndis_driver_version; | 306 | *outbuf = rndis_driver_version; |
312 | retval = 0; | 307 | retval = 0; |
@@ -314,14 +309,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
314 | 309 | ||
315 | /* mandatory */ | 310 | /* mandatory */ |
316 | case OID_GEN_CURRENT_PACKET_FILTER: | 311 | case OID_GEN_CURRENT_PACKET_FILTER: |
317 | DBG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__); | 312 | pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__); |
318 | *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); | 313 | *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); |
319 | retval = 0; | 314 | retval = 0; |
320 | break; | 315 | break; |
321 | 316 | ||
322 | /* mandatory */ | 317 | /* mandatory */ |
323 | case OID_GEN_MAXIMUM_TOTAL_SIZE: | 318 | case OID_GEN_MAXIMUM_TOTAL_SIZE: |
324 | DBG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__); | 319 | pr_debug("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__); |
325 | *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); | 320 | *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); |
326 | retval = 0; | 321 | retval = 0; |
327 | break; | 322 | break; |
@@ -329,14 +324,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
329 | /* mandatory */ | 324 | /* mandatory */ |
330 | case OID_GEN_MEDIA_CONNECT_STATUS: | 325 | case OID_GEN_MEDIA_CONNECT_STATUS: |
331 | if (rndis_debug > 1) | 326 | if (rndis_debug > 1) |
332 | DBG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__); | 327 | pr_debug("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__); |
333 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] | 328 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
334 | .media_state); | 329 | .media_state); |
335 | retval = 0; | 330 | retval = 0; |
336 | break; | 331 | break; |
337 | 332 | ||
338 | case OID_GEN_PHYSICAL_MEDIUM: | 333 | case OID_GEN_PHYSICAL_MEDIUM: |
339 | DBG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__); | 334 | pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__); |
340 | *outbuf = __constant_cpu_to_le32 (0); | 335 | *outbuf = __constant_cpu_to_le32 (0); |
341 | retval = 0; | 336 | retval = 0; |
342 | break; | 337 | break; |
@@ -346,7 +341,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
346 | * versions emit undefined RNDIS messages. DOCUMENT ALL THESE! | 341 | * versions emit undefined RNDIS messages. DOCUMENT ALL THESE! |
347 | */ | 342 | */ |
348 | case OID_GEN_MAC_OPTIONS: /* from WinME */ | 343 | case OID_GEN_MAC_OPTIONS: /* from WinME */ |
349 | DBG("%s: OID_GEN_MAC_OPTIONS\n", __func__); | 344 | pr_debug("%s: OID_GEN_MAC_OPTIONS\n", __func__); |
350 | *outbuf = __constant_cpu_to_le32( | 345 | *outbuf = __constant_cpu_to_le32( |
351 | NDIS_MAC_OPTION_RECEIVE_SERIALIZED | 346 | NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
352 | | NDIS_MAC_OPTION_FULL_DUPLEX); | 347 | | NDIS_MAC_OPTION_FULL_DUPLEX); |
@@ -358,7 +353,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
358 | /* mandatory */ | 353 | /* mandatory */ |
359 | case OID_GEN_XMIT_OK: | 354 | case OID_GEN_XMIT_OK: |
360 | if (rndis_debug > 1) | 355 | if (rndis_debug > 1) |
361 | DBG("%s: OID_GEN_XMIT_OK\n", __func__); | 356 | pr_debug("%s: OID_GEN_XMIT_OK\n", __func__); |
362 | if (stats) { | 357 | if (stats) { |
363 | *outbuf = cpu_to_le32(stats->tx_packets | 358 | *outbuf = cpu_to_le32(stats->tx_packets |
364 | - stats->tx_errors - stats->tx_dropped); | 359 | - stats->tx_errors - stats->tx_dropped); |
@@ -369,7 +364,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
369 | /* mandatory */ | 364 | /* mandatory */ |
370 | case OID_GEN_RCV_OK: | 365 | case OID_GEN_RCV_OK: |
371 | if (rndis_debug > 1) | 366 | if (rndis_debug > 1) |
372 | DBG("%s: OID_GEN_RCV_OK\n", __func__); | 367 | pr_debug("%s: OID_GEN_RCV_OK\n", __func__); |
373 | if (stats) { | 368 | if (stats) { |
374 | *outbuf = cpu_to_le32(stats->rx_packets | 369 | *outbuf = cpu_to_le32(stats->rx_packets |
375 | - stats->rx_errors - stats->rx_dropped); | 370 | - stats->rx_errors - stats->rx_dropped); |
@@ -380,7 +375,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
380 | /* mandatory */ | 375 | /* mandatory */ |
381 | case OID_GEN_XMIT_ERROR: | 376 | case OID_GEN_XMIT_ERROR: |
382 | if (rndis_debug > 1) | 377 | if (rndis_debug > 1) |
383 | DBG("%s: OID_GEN_XMIT_ERROR\n", __func__); | 378 | pr_debug("%s: OID_GEN_XMIT_ERROR\n", __func__); |
384 | if (stats) { | 379 | if (stats) { |
385 | *outbuf = cpu_to_le32(stats->tx_errors); | 380 | *outbuf = cpu_to_le32(stats->tx_errors); |
386 | retval = 0; | 381 | retval = 0; |
@@ -390,7 +385,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
390 | /* mandatory */ | 385 | /* mandatory */ |
391 | case OID_GEN_RCV_ERROR: | 386 | case OID_GEN_RCV_ERROR: |
392 | if (rndis_debug > 1) | 387 | if (rndis_debug > 1) |
393 | DBG("%s: OID_GEN_RCV_ERROR\n", __func__); | 388 | pr_debug("%s: OID_GEN_RCV_ERROR\n", __func__); |
394 | if (stats) { | 389 | if (stats) { |
395 | *outbuf = cpu_to_le32(stats->rx_errors); | 390 | *outbuf = cpu_to_le32(stats->rx_errors); |
396 | retval = 0; | 391 | retval = 0; |
@@ -399,7 +394,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
399 | 394 | ||
400 | /* mandatory */ | 395 | /* mandatory */ |
401 | case OID_GEN_RCV_NO_BUFFER: | 396 | case OID_GEN_RCV_NO_BUFFER: |
402 | DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __func__); | 397 | pr_debug("%s: OID_GEN_RCV_NO_BUFFER\n", __func__); |
403 | if (stats) { | 398 | if (stats) { |
404 | *outbuf = cpu_to_le32(stats->rx_dropped); | 399 | *outbuf = cpu_to_le32(stats->rx_dropped); |
405 | retval = 0; | 400 | retval = 0; |
@@ -410,7 +405,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
410 | 405 | ||
411 | /* mandatory */ | 406 | /* mandatory */ |
412 | case OID_802_3_PERMANENT_ADDRESS: | 407 | case OID_802_3_PERMANENT_ADDRESS: |
413 | DBG("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__); | 408 | pr_debug("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__); |
414 | if (rndis_per_dev_params [configNr].dev) { | 409 | if (rndis_per_dev_params [configNr].dev) { |
415 | length = ETH_ALEN; | 410 | length = ETH_ALEN; |
416 | memcpy (outbuf, | 411 | memcpy (outbuf, |
@@ -422,7 +417,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
422 | 417 | ||
423 | /* mandatory */ | 418 | /* mandatory */ |
424 | case OID_802_3_CURRENT_ADDRESS: | 419 | case OID_802_3_CURRENT_ADDRESS: |
425 | DBG("%s: OID_802_3_CURRENT_ADDRESS\n", __func__); | 420 | pr_debug("%s: OID_802_3_CURRENT_ADDRESS\n", __func__); |
426 | if (rndis_per_dev_params [configNr].dev) { | 421 | if (rndis_per_dev_params [configNr].dev) { |
427 | length = ETH_ALEN; | 422 | length = ETH_ALEN; |
428 | memcpy (outbuf, | 423 | memcpy (outbuf, |
@@ -434,7 +429,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
434 | 429 | ||
435 | /* mandatory */ | 430 | /* mandatory */ |
436 | case OID_802_3_MULTICAST_LIST: | 431 | case OID_802_3_MULTICAST_LIST: |
437 | DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__); | 432 | pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__); |
438 | /* Multicast base address only */ | 433 | /* Multicast base address only */ |
439 | *outbuf = __constant_cpu_to_le32 (0xE0000000); | 434 | *outbuf = __constant_cpu_to_le32 (0xE0000000); |
440 | retval = 0; | 435 | retval = 0; |
@@ -442,21 +437,21 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
442 | 437 | ||
443 | /* mandatory */ | 438 | /* mandatory */ |
444 | case OID_802_3_MAXIMUM_LIST_SIZE: | 439 | case OID_802_3_MAXIMUM_LIST_SIZE: |
445 | DBG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__); | 440 | pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__); |
446 | /* Multicast base address only */ | 441 | /* Multicast base address only */ |
447 | *outbuf = __constant_cpu_to_le32 (1); | 442 | *outbuf = __constant_cpu_to_le32 (1); |
448 | retval = 0; | 443 | retval = 0; |
449 | break; | 444 | break; |
450 | 445 | ||
451 | case OID_802_3_MAC_OPTIONS: | 446 | case OID_802_3_MAC_OPTIONS: |
452 | DBG("%s: OID_802_3_MAC_OPTIONS\n", __func__); | 447 | pr_debug("%s: OID_802_3_MAC_OPTIONS\n", __func__); |
453 | break; | 448 | break; |
454 | 449 | ||
455 | /* ieee802.3 statistics OIDs (table 4-4) */ | 450 | /* ieee802.3 statistics OIDs (table 4-4) */ |
456 | 451 | ||
457 | /* mandatory */ | 452 | /* mandatory */ |
458 | case OID_802_3_RCV_ERROR_ALIGNMENT: | 453 | case OID_802_3_RCV_ERROR_ALIGNMENT: |
459 | DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__); | 454 | pr_debug("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__); |
460 | if (stats) { | 455 | if (stats) { |
461 | *outbuf = cpu_to_le32(stats->rx_frame_errors); | 456 | *outbuf = cpu_to_le32(stats->rx_frame_errors); |
462 | retval = 0; | 457 | retval = 0; |
@@ -465,14 +460,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | |||
465 | 460 | ||
466 | /* mandatory */ | 461 | /* mandatory */ |
467 | case OID_802_3_XMIT_ONE_COLLISION: | 462 | case OID_802_3_XMIT_ONE_COLLISION: |
468 | DBG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__); | 463 | pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__); |
469 | *outbuf = __constant_cpu_to_le32 (0); | 464 | *outbuf = __constant_cpu_to_le32 (0); |
470 | retval = 0; | 465 | retval = 0; |
471 | break; | 466 | break; |
472 | 467 | ||
473 | /* mandatory */ | 468 | /* mandatory */ |
474 | case OID_802_3_XMIT_MORE_COLLISIONS: | 469 | case OID_802_3_XMIT_MORE_COLLISIONS: |
475 | DBG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__); | 470 | pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__); |
476 | *outbuf = __constant_cpu_to_le32 (0); | 471 | *outbuf = __constant_cpu_to_le32 (0); |
477 | retval = 0; | 472 | retval = 0; |
478 | break; | 473 | break; |
@@ -504,9 +499,9 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len, | |||
504 | return -ENOMEM; | 499 | return -ENOMEM; |
505 | 500 | ||
506 | if (buf_len && rndis_debug > 1) { | 501 | if (buf_len && rndis_debug > 1) { |
507 | DBG("set OID %08x value, len %d:\n", OID, buf_len); | 502 | pr_debug("set OID %08x value, len %d:\n", OID, buf_len); |
508 | for (i = 0; i < buf_len; i += 16) { | 503 | for (i = 0; i < buf_len; i += 16) { |
509 | DBG("%03d: %08x %08x %08x %08x\n", i, | 504 | pr_debug("%03d: %08x %08x %08x %08x\n", i, |
510 | get_unaligned_le32(&buf[i]), | 505 | get_unaligned_le32(&buf[i]), |
511 | get_unaligned_le32(&buf[i + 4]), | 506 | get_unaligned_le32(&buf[i + 4]), |
512 | get_unaligned_le32(&buf[i + 8]), | 507 | get_unaligned_le32(&buf[i + 8]), |
@@ -525,7 +520,7 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len, | |||
525 | * MULTICAST, ALL_MULTICAST, BROADCAST | 520 | * MULTICAST, ALL_MULTICAST, BROADCAST |
526 | */ | 521 | */ |
527 | *params->filter = (u16)get_unaligned_le32(buf); | 522 | *params->filter = (u16)get_unaligned_le32(buf); |
528 | DBG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", | 523 | pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", |
529 | __func__, *params->filter); | 524 | __func__, *params->filter); |
530 | 525 | ||
531 | /* this call has a significant side effect: it's | 526 | /* this call has a significant side effect: it's |
@@ -547,7 +542,7 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len, | |||
547 | 542 | ||
548 | case OID_802_3_MULTICAST_LIST: | 543 | case OID_802_3_MULTICAST_LIST: |
549 | /* I think we can ignore this */ | 544 | /* I think we can ignore this */ |
550 | DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__); | 545 | pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__); |
551 | retval = 0; | 546 | retval = 0; |
552 | break; | 547 | break; |
553 | 548 | ||
@@ -606,7 +601,7 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf) | |||
606 | rndis_resp_t *r; | 601 | rndis_resp_t *r; |
607 | struct rndis_params *params = rndis_per_dev_params + configNr; | 602 | struct rndis_params *params = rndis_per_dev_params + configNr; |
608 | 603 | ||
609 | // DBG("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); | 604 | /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */ |
610 | if (!params->dev) | 605 | if (!params->dev) |
611 | return -ENOTSUPP; | 606 | return -ENOTSUPP; |
612 | 607 | ||
@@ -659,15 +654,15 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf) | |||
659 | BufOffset = le32_to_cpu (buf->InformationBufferOffset); | 654 | BufOffset = le32_to_cpu (buf->InformationBufferOffset); |
660 | 655 | ||
661 | #ifdef VERBOSE_DEBUG | 656 | #ifdef VERBOSE_DEBUG |
662 | DBG("%s: Length: %d\n", __func__, BufLength); | 657 | pr_debug("%s: Length: %d\n", __func__, BufLength); |
663 | DBG("%s: Offset: %d\n", __func__, BufOffset); | 658 | pr_debug("%s: Offset: %d\n", __func__, BufOffset); |
664 | DBG("%s: InfoBuffer: ", __func__); | 659 | pr_debug("%s: InfoBuffer: ", __func__); |
665 | 660 | ||
666 | for (i = 0; i < BufLength; i++) { | 661 | for (i = 0; i < BufLength; i++) { |
667 | DBG("%02x ", *(((u8 *) buf) + i + 8 + BufOffset)); | 662 | pr_debug("%02x ", *(((u8 *) buf) + i + 8 + BufOffset)); |
668 | } | 663 | } |
669 | 664 | ||
670 | DBG("\n"); | 665 | pr_debug("\n"); |
671 | #endif | 666 | #endif |
672 | 667 | ||
673 | resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_SET_CMPLT); | 668 | resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_SET_CMPLT); |
@@ -821,14 +816,14 @@ int rndis_msg_parser (u8 configNr, u8 *buf) | |||
821 | /* For USB: responses may take up to 10 seconds */ | 816 | /* For USB: responses may take up to 10 seconds */ |
822 | switch (MsgType) { | 817 | switch (MsgType) { |
823 | case REMOTE_NDIS_INITIALIZE_MSG: | 818 | case REMOTE_NDIS_INITIALIZE_MSG: |
824 | DBG("%s: REMOTE_NDIS_INITIALIZE_MSG\n", | 819 | pr_debug("%s: REMOTE_NDIS_INITIALIZE_MSG\n", |
825 | __func__ ); | 820 | __func__ ); |
826 | params->state = RNDIS_INITIALIZED; | 821 | params->state = RNDIS_INITIALIZED; |
827 | return rndis_init_response (configNr, | 822 | return rndis_init_response (configNr, |
828 | (rndis_init_msg_type *) buf); | 823 | (rndis_init_msg_type *) buf); |
829 | 824 | ||
830 | case REMOTE_NDIS_HALT_MSG: | 825 | case REMOTE_NDIS_HALT_MSG: |
831 | DBG("%s: REMOTE_NDIS_HALT_MSG\n", | 826 | pr_debug("%s: REMOTE_NDIS_HALT_MSG\n", |
832 | __func__ ); | 827 | __func__ ); |
833 | params->state = RNDIS_UNINITIALIZED; | 828 | params->state = RNDIS_UNINITIALIZED; |
834 | if (params->dev) { | 829 | if (params->dev) { |
@@ -846,7 +841,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf) | |||
846 | (rndis_set_msg_type *) buf); | 841 | (rndis_set_msg_type *) buf); |
847 | 842 | ||
848 | case REMOTE_NDIS_RESET_MSG: | 843 | case REMOTE_NDIS_RESET_MSG: |
849 | DBG("%s: REMOTE_NDIS_RESET_MSG\n", | 844 | pr_debug("%s: REMOTE_NDIS_RESET_MSG\n", |
850 | __func__ ); | 845 | __func__ ); |
851 | return rndis_reset_response (configNr, | 846 | return rndis_reset_response (configNr, |
852 | (rndis_reset_msg_type *) buf); | 847 | (rndis_reset_msg_type *) buf); |
@@ -854,7 +849,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf) | |||
854 | case REMOTE_NDIS_KEEPALIVE_MSG: | 849 | case REMOTE_NDIS_KEEPALIVE_MSG: |
855 | /* For USB: host does this every 5 seconds */ | 850 | /* For USB: host does this every 5 seconds */ |
856 | if (rndis_debug > 1) | 851 | if (rndis_debug > 1) |
857 | DBG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", | 852 | pr_debug("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", |
858 | __func__ ); | 853 | __func__ ); |
859 | return rndis_keepalive_response (configNr, | 854 | return rndis_keepalive_response (configNr, |
860 | (rndis_keepalive_msg_type *) | 855 | (rndis_keepalive_msg_type *) |
@@ -870,7 +865,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf) | |||
870 | { | 865 | { |
871 | unsigned i; | 866 | unsigned i; |
872 | for (i = 0; i < MsgLength; i += 16) { | 867 | for (i = 0; i < MsgLength; i += 16) { |
873 | DBG("%03d: " | 868 | pr_debug("%03d: " |
874 | " %02x %02x %02x %02x" | 869 | " %02x %02x %02x %02x" |
875 | " %02x %02x %02x %02x" | 870 | " %02x %02x %02x %02x" |
876 | " %02x %02x %02x %02x" | 871 | " %02x %02x %02x %02x" |
@@ -905,18 +900,18 @@ int rndis_register(void (*resp_avail)(void *v), void *v) | |||
905 | rndis_per_dev_params [i].used = 1; | 900 | rndis_per_dev_params [i].used = 1; |
906 | rndis_per_dev_params [i].resp_avail = resp_avail; | 901 | rndis_per_dev_params [i].resp_avail = resp_avail; |
907 | rndis_per_dev_params [i].v = v; | 902 | rndis_per_dev_params [i].v = v; |
908 | DBG("%s: configNr = %d\n", __func__, i); | 903 | pr_debug("%s: configNr = %d\n", __func__, i); |
909 | return i; | 904 | return i; |
910 | } | 905 | } |
911 | } | 906 | } |
912 | DBG("failed\n"); | 907 | pr_debug("failed\n"); |
913 | 908 | ||
914 | return -ENODEV; | 909 | return -ENODEV; |
915 | } | 910 | } |
916 | 911 | ||
917 | void rndis_deregister (int configNr) | 912 | void rndis_deregister (int configNr) |
918 | { | 913 | { |
919 | DBG("%s: \n", __func__ ); | 914 | pr_debug("%s: \n", __func__); |
920 | 915 | ||
921 | if (configNr >= RNDIS_MAX_CONFIGS) return; | 916 | if (configNr >= RNDIS_MAX_CONFIGS) return; |
922 | rndis_per_dev_params [configNr].used = 0; | 917 | rndis_per_dev_params [configNr].used = 0; |
@@ -926,7 +921,7 @@ void rndis_deregister (int configNr) | |||
926 | 921 | ||
927 | int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) | 922 | int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) |
928 | { | 923 | { |
929 | DBG("%s:\n", __func__ ); | 924 | pr_debug("%s:\n", __func__); |
930 | if (!dev) | 925 | if (!dev) |
931 | return -EINVAL; | 926 | return -EINVAL; |
932 | if (configNr >= RNDIS_MAX_CONFIGS) return -1; | 927 | if (configNr >= RNDIS_MAX_CONFIGS) return -1; |
@@ -939,7 +934,7 @@ int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) | |||
939 | 934 | ||
940 | int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr) | 935 | int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr) |
941 | { | 936 | { |
942 | DBG("%s:\n", __func__ ); | 937 | pr_debug("%s:\n", __func__); |
943 | if (!vendorDescr) return -1; | 938 | if (!vendorDescr) return -1; |
944 | if (configNr >= RNDIS_MAX_CONFIGS) return -1; | 939 | if (configNr >= RNDIS_MAX_CONFIGS) return -1; |
945 | 940 | ||
@@ -951,7 +946,7 @@ int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr) | |||
951 | 946 | ||
952 | int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) | 947 | int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) |
953 | { | 948 | { |
954 | DBG("%s: %u %u\n", __func__, medium, speed); | 949 | pr_debug("%s: %u %u\n", __func__, medium, speed); |
955 | if (configNr >= RNDIS_MAX_CONFIGS) return -1; | 950 | if (configNr >= RNDIS_MAX_CONFIGS) return -1; |
956 | 951 | ||
957 | rndis_per_dev_params [configNr].medium = medium; | 952 | rndis_per_dev_params [configNr].medium = medium; |
@@ -1114,7 +1109,7 @@ static ssize_t rndis_proc_write(struct file *file, const char __user *buffer, | |||
1114 | break; | 1109 | break; |
1115 | default: | 1110 | default: |
1116 | if (fl_speed) p->speed = speed; | 1111 | if (fl_speed) p->speed = speed; |
1117 | else DBG("%c is not valid\n", c); | 1112 | else pr_debug("%c is not valid\n", c); |
1118 | break; | 1113 | break; |
1119 | } | 1114 | } |
1120 | 1115 | ||
@@ -1159,12 +1154,12 @@ int __init rndis_init (void) | |||
1159 | &rndis_proc_fops, | 1154 | &rndis_proc_fops, |
1160 | (void *)(rndis_per_dev_params + i)))) | 1155 | (void *)(rndis_per_dev_params + i)))) |
1161 | { | 1156 | { |
1162 | DBG("%s :remove entries", __func__); | 1157 | pr_debug("%s :remove entries", __func__); |
1163 | while (i) { | 1158 | while (i) { |
1164 | sprintf (name, NAME_TEMPLATE, --i); | 1159 | sprintf (name, NAME_TEMPLATE, --i); |
1165 | remove_proc_entry (name, NULL); | 1160 | remove_proc_entry (name, NULL); |
1166 | } | 1161 | } |
1167 | DBG("\n"); | 1162 | pr_debug("\n"); |
1168 | return -EIO; | 1163 | return -EIO; |
1169 | } | 1164 | } |
1170 | #endif | 1165 | #endif |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index 29d13ebe7500..48f51b12d2e2 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -1651,7 +1651,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
1651 | return -EBUSY; | 1651 | return -EBUSY; |
1652 | 1652 | ||
1653 | if (!driver->bind || !driver->setup | 1653 | if (!driver->bind || !driver->setup |
1654 | || driver->speed != USB_SPEED_FULL) { | 1654 | || driver->speed < USB_SPEED_FULL) { |
1655 | printk(KERN_ERR "Invalid driver: bind %p setup %p speed %d\n", | 1655 | printk(KERN_ERR "Invalid driver: bind %p setup %p speed %d\n", |
1656 | driver->bind, driver->setup, driver->speed); | 1656 | driver->bind, driver->setup, driver->speed); |
1657 | return -EINVAL; | 1657 | return -EINVAL; |
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index b3699afff002..37879af1c433 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c | |||
@@ -30,6 +30,25 @@ | |||
30 | 30 | ||
31 | /*-------------------------------------------------------------------------*/ | 31 | /*-------------------------------------------------------------------------*/ |
32 | 32 | ||
33 | /* | ||
34 | * Kbuild is not very cooperative with respect to linking separately | ||
35 | * compiled library objects into one module. So for now we won't use | ||
36 | * separate compilation ... ensuring init/exit sections work to shrink | ||
37 | * the runtime footprint, and giving us at least some parts of what | ||
38 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
39 | */ | ||
40 | #include "composite.c" | ||
41 | #include "usbstring.c" | ||
42 | #include "config.c" | ||
43 | #include "epautoconf.c" | ||
44 | |||
45 | #include "f_acm.c" | ||
46 | #include "f_obex.c" | ||
47 | #include "f_serial.c" | ||
48 | #include "u_serial.c" | ||
49 | |||
50 | /*-------------------------------------------------------------------------*/ | ||
51 | |||
33 | /* Thanks to NetChip Technologies for donating this product ID. | 52 | /* Thanks to NetChip Technologies for donating this product ID. |
34 | * | 53 | * |
35 | * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! | 54 | * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! |
@@ -38,6 +57,7 @@ | |||
38 | #define GS_VENDOR_ID 0x0525 /* NetChip */ | 57 | #define GS_VENDOR_ID 0x0525 /* NetChip */ |
39 | #define GS_PRODUCT_ID 0xa4a6 /* Linux-USB Serial Gadget */ | 58 | #define GS_PRODUCT_ID 0xa4a6 /* Linux-USB Serial Gadget */ |
40 | #define GS_CDC_PRODUCT_ID 0xa4a7 /* ... as CDC-ACM */ | 59 | #define GS_CDC_PRODUCT_ID 0xa4a7 /* ... as CDC-ACM */ |
60 | #define GS_CDC_OBEX_PRODUCT_ID 0xa4a9 /* ... as CDC-OBEX */ | ||
41 | 61 | ||
42 | /* string IDs are assigned dynamically */ | 62 | /* string IDs are assigned dynamically */ |
43 | 63 | ||
@@ -107,6 +127,10 @@ static int use_acm = true; | |||
107 | module_param(use_acm, bool, 0); | 127 | module_param(use_acm, bool, 0); |
108 | MODULE_PARM_DESC(use_acm, "Use CDC ACM, default=yes"); | 128 | MODULE_PARM_DESC(use_acm, "Use CDC ACM, default=yes"); |
109 | 129 | ||
130 | static int use_obex = false; | ||
131 | module_param(use_obex, bool, 0); | ||
132 | MODULE_PARM_DESC(use_obex, "Use CDC OBEX, default=no"); | ||
133 | |||
110 | static unsigned n_ports = 1; | 134 | static unsigned n_ports = 1; |
111 | module_param(n_ports, uint, 0); | 135 | module_param(n_ports, uint, 0); |
112 | MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); | 136 | MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); |
@@ -121,6 +145,8 @@ static int __init serial_bind_config(struct usb_configuration *c) | |||
121 | for (i = 0; i < n_ports && status == 0; i++) { | 145 | for (i = 0; i < n_ports && status == 0; i++) { |
122 | if (use_acm) | 146 | if (use_acm) |
123 | status = acm_bind_config(c, i); | 147 | status = acm_bind_config(c, i); |
148 | else if (use_obex) | ||
149 | status = obex_bind_config(c, i); | ||
124 | else | 150 | else |
125 | status = gser_bind_config(c, i); | 151 | status = gser_bind_config(c, i); |
126 | } | 152 | } |
@@ -133,7 +159,6 @@ static struct usb_configuration serial_config_driver = { | |||
133 | /* .bConfigurationValue = f(use_acm) */ | 159 | /* .bConfigurationValue = f(use_acm) */ |
134 | /* .iConfiguration = DYNAMIC */ | 160 | /* .iConfiguration = DYNAMIC */ |
135 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 161 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
136 | .bMaxPower = 1, /* 2 mA, minimal */ | ||
137 | }; | 162 | }; |
138 | 163 | ||
139 | static int __init gs_bind(struct usb_composite_dev *cdev) | 164 | static int __init gs_bind(struct usb_composite_dev *cdev) |
@@ -231,6 +256,12 @@ static int __init init(void) | |||
231 | device_desc.bDeviceClass = USB_CLASS_COMM; | 256 | device_desc.bDeviceClass = USB_CLASS_COMM; |
232 | device_desc.idProduct = | 257 | device_desc.idProduct = |
233 | __constant_cpu_to_le16(GS_CDC_PRODUCT_ID); | 258 | __constant_cpu_to_le16(GS_CDC_PRODUCT_ID); |
259 | } else if (use_obex) { | ||
260 | serial_config_driver.label = "CDC OBEX config"; | ||
261 | serial_config_driver.bConfigurationValue = 3; | ||
262 | device_desc.bDeviceClass = USB_CLASS_COMM; | ||
263 | device_desc.idProduct = | ||
264 | __constant_cpu_to_le16(GS_CDC_OBEX_PRODUCT_ID); | ||
234 | } else { | 265 | } else { |
235 | serial_config_driver.label = "Generic Serial config"; | 266 | serial_config_driver.label = "Generic Serial config"; |
236 | serial_config_driver.bConfigurationValue = 1; | 267 | serial_config_driver.bConfigurationValue = 1; |
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index 3791e6271903..66948b72bb9b 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -52,7 +52,7 @@ | |||
52 | * this single "physical" link to be used by multiple virtual links.) | 52 | * this single "physical" link to be used by multiple virtual links.) |
53 | */ | 53 | */ |
54 | 54 | ||
55 | #define DRIVER_VERSION "29-May-2008" | 55 | #define UETH__VERSION "29-May-2008" |
56 | 56 | ||
57 | struct eth_dev { | 57 | struct eth_dev { |
58 | /* lock is held while accessing port_usb | 58 | /* lock is held while accessing port_usb |
@@ -170,7 +170,7 @@ static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p) | |||
170 | struct eth_dev *dev = netdev_priv(net); | 170 | struct eth_dev *dev = netdev_priv(net); |
171 | 171 | ||
172 | strlcpy(p->driver, "g_ether", sizeof p->driver); | 172 | strlcpy(p->driver, "g_ether", sizeof p->driver); |
173 | strlcpy(p->version, DRIVER_VERSION, sizeof p->version); | 173 | strlcpy(p->version, UETH__VERSION, sizeof p->version); |
174 | strlcpy(p->fw_version, dev->gadget->name, sizeof p->fw_version); | 174 | strlcpy(p->fw_version, dev->gadget->name, sizeof p->fw_version); |
175 | strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof p->bus_info); | 175 | strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof p->bus_info); |
176 | } | 176 | } |
@@ -873,6 +873,13 @@ struct net_device *gether_connect(struct gether *link) | |||
873 | spin_lock(&dev->lock); | 873 | spin_lock(&dev->lock); |
874 | dev->port_usb = link; | 874 | dev->port_usb = link; |
875 | link->ioport = dev; | 875 | link->ioport = dev; |
876 | if (netif_running(dev->net)) { | ||
877 | if (link->open) | ||
878 | link->open(link); | ||
879 | } else { | ||
880 | if (link->close) | ||
881 | link->close(link); | ||
882 | } | ||
876 | spin_unlock(&dev->lock); | 883 | spin_unlock(&dev->lock); |
877 | 884 | ||
878 | netif_carrier_on(dev->net); | 885 | netif_carrier_on(dev->net); |
diff --git a/drivers/usb/gadget/u_serial.h b/drivers/usb/gadget/u_serial.h index af3910d01aea..300f0ed9475d 100644 --- a/drivers/usb/gadget/u_serial.h +++ b/drivers/usb/gadget/u_serial.h | |||
@@ -62,5 +62,6 @@ void gserial_disconnect(struct gserial *); | |||
62 | /* functions are bound to configurations by a config or gadget driver */ | 62 | /* functions are bound to configurations by a config or gadget driver */ |
63 | int acm_bind_config(struct usb_configuration *c, u8 port_num); | 63 | int acm_bind_config(struct usb_configuration *c, u8 port_num); |
64 | int gser_bind_config(struct usb_configuration *c, u8 port_num); | 64 | int gser_bind_config(struct usb_configuration *c, u8 port_num); |
65 | int obex_bind_config(struct usb_configuration *c, u8 port_num); | ||
65 | 66 | ||
66 | #endif /* __U_SERIAL_H */ | 67 | #endif /* __U_SERIAL_H */ |
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index aa0bd4f126a1..361d9659ac48 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c | |||
@@ -59,6 +59,23 @@ | |||
59 | 59 | ||
60 | /*-------------------------------------------------------------------------*/ | 60 | /*-------------------------------------------------------------------------*/ |
61 | 61 | ||
62 | /* | ||
63 | * Kbuild is not very cooperative with respect to linking separately | ||
64 | * compiled library objects into one module. So for now we won't use | ||
65 | * separate compilation ... ensuring init/exit sections work to shrink | ||
66 | * the runtime footprint, and giving us at least some parts of what | ||
67 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
68 | */ | ||
69 | #include "composite.c" | ||
70 | #include "usbstring.c" | ||
71 | #include "config.c" | ||
72 | #include "epautoconf.c" | ||
73 | |||
74 | #include "f_sourcesink.c" | ||
75 | #include "f_loopback.c" | ||
76 | |||
77 | /*-------------------------------------------------------------------------*/ | ||
78 | |||
62 | #define DRIVER_VERSION "Cinco de Mayo 2008" | 79 | #define DRIVER_VERSION "Cinco de Mayo 2008" |
63 | 80 | ||
64 | static const char longname[] = "Gadget Zero"; | 81 | static const char longname[] = "Gadget Zero"; |