Commit | Line | Data |
---|---|---|
d774efea TO |
1 | /* |
2 | * Host Controller Driver for the Elan Digital Systems U132 adapter | |
3 | * | |
4 | * Copyright(C) 2006 Elan Digital Systems Limited | |
5 | * http://www.elandigitalsystems.com | |
6 | * | |
7 | * Author and Maintainer - Tony Olech - Elan Digital Systems | |
8 | * tony.olech@elandigitalsystems.com | |
9 | * | |
10 | * This program is free software;you can redistribute it and/or | |
11 | * modify it under the terms of the GNU General Public License as | |
12 | * published by the Free Software Foundation, version 2. | |
13 | * | |
14 | * | |
15 | * This driver was written by Tony Olech(tony.olech@elandigitalsystems.com) | |
16 | * based on various USB host drivers in the 2.6.15 linux kernel | |
17 | * with constant reference to the 3rd Edition of Linux Device Drivers | |
18 | * published by O'Reilly | |
19 | * | |
20 | * The U132 adapter is a USB to CardBus adapter specifically designed | |
21 | * for PC cards that contain an OHCI host controller. Typical PC cards | |
22 | * are the Orange Mobile 3G Option GlobeTrotter Fusion card. | |
23 | * | |
24 | * The U132 adapter will *NOT *work with PC cards that do not contain | |
25 | * an OHCI controller. A simple way to test whether a PC card has an | |
26 | * OHCI controller as an interface is to insert the PC card directly | |
27 | * into a laptop(or desktop) with a CardBus slot and if "lspci" shows | |
28 | * a new USB controller and "lsusb -v" shows a new OHCI Host Controller | |
29 | * then there is a good chance that the U132 adapter will support the | |
30 | * PC card.(you also need the specific client driver for the PC card) | |
31 | * | |
32 | * Please inform the Author and Maintainer about any PC cards that | |
33 | * contain OHCI Host Controller and work when directly connected to | |
34 | * an embedded CardBus slot but do not work when they are connected | |
35 | * via an ELAN U132 adapter. | |
36 | * | |
37 | */ | |
d774efea TO |
38 | #include <linux/kernel.h> |
39 | #include <linux/module.h> | |
40 | #include <linux/moduleparam.h> | |
41 | #include <linux/delay.h> | |
42 | #include <linux/ioport.h> | |
43 | #include <linux/sched.h> | |
44 | #include <linux/slab.h> | |
45 | #include <linux/smp_lock.h> | |
46 | #include <linux/errno.h> | |
47 | #include <linux/init.h> | |
48 | #include <linux/timer.h> | |
49 | #include <linux/list.h> | |
50 | #include <linux/interrupt.h> | |
51 | #include <linux/usb.h> | |
52 | #include <linux/workqueue.h> | |
53 | #include <linux/platform_device.h> | |
54 | #include <linux/pci_ids.h> | |
55 | #include <asm/io.h> | |
56 | #include <asm/irq.h> | |
57 | #include <asm/system.h> | |
58 | #include <asm/byteorder.h> | |
59 | #include "../core/hcd.h" | |
60 | #include "ohci.h" | |
61 | #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR | |
62 | #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \ | |
63 | OHCI_INTR_WDH) | |
64 | MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited"); | |
65 | MODULE_DESCRIPTION("U132 USB Host Controller Driver"); | |
66 | MODULE_LICENSE("GPL"); | |
67 | #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444) | |
68 | INT_MODULE_PARM(testing, 0); | |
69 | /* Some boards misreport power switching/overcurrent*/ | |
70 | static int distrust_firmware = 1; | |
71 | module_param(distrust_firmware, bool, 0); | |
72 | MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren" | |
73 | "t setup"); | |
27a3de4c | 74 | static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait); |
d774efea TO |
75 | /* |
76 | * u132_module_lock exists to protect access to global variables | |
77 | * | |
78 | */ | |
79 | static struct semaphore u132_module_lock; | |
80 | static int u132_exiting = 0; | |
81 | static int u132_instances = 0; | |
82 | static struct list_head u132_static_list; | |
83 | /* | |
84 | * end of the global variables protected by u132_module_lock | |
85 | */ | |
86 | static struct workqueue_struct *workqueue; | |
87 | #define MAX_U132_PORTS 7 | |
88 | #define MAX_U132_ADDRS 128 | |
89 | #define MAX_U132_UDEVS 4 | |
90 | #define MAX_U132_ENDPS 100 | |
91 | #define MAX_U132_RINGS 4 | |
92 | static const char *cc_to_text[16] = { | |
93 | "No Error ", | |
94 | "CRC Error ", | |
95 | "Bit Stuff ", | |
96 | "Data Togg ", | |
97 | "Stall ", | |
98 | "DevNotResp ", | |
99 | "PIDCheck ", | |
100 | "UnExpPID ", | |
101 | "DataOver ", | |
102 | "DataUnder ", | |
103 | "(for hw) ", | |
104 | "(for hw) ", | |
105 | "BufferOver ", | |
106 | "BuffUnder ", | |
107 | "(for HCD) ", | |
108 | "(for HCD) " | |
109 | }; | |
110 | struct u132_port { | |
111 | struct u132 *u132; | |
112 | int reset; | |
113 | int enable; | |
114 | int power; | |
115 | int Status; | |
116 | }; | |
117 | struct u132_addr { | |
118 | u8 address; | |
119 | }; | |
120 | struct u132_udev { | |
121 | struct kref kref; | |
122 | struct usb_device *usb_device; | |
123 | u8 enumeration; | |
124 | u8 udev_number; | |
125 | u8 usb_addr; | |
126 | u8 portnumber; | |
127 | u8 endp_number_in[16]; | |
128 | u8 endp_number_out[16]; | |
129 | }; | |
130 | #define ENDP_QUEUE_SHIFT 3 | |
131 | #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT) | |
132 | #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1) | |
133 | struct u132_urbq { | |
134 | struct list_head urb_more; | |
135 | struct urb *urb; | |
136 | }; | |
137 | struct u132_spin { | |
138 | spinlock_t slock; | |
139 | }; | |
140 | struct u132_endp { | |
141 | struct kref kref; | |
142 | u8 udev_number; | |
143 | u8 endp_number; | |
144 | u8 usb_addr; | |
145 | u8 usb_endp; | |
146 | struct u132 *u132; | |
147 | struct list_head endp_ring; | |
148 | struct u132_ring *ring; | |
149 | unsigned toggle_bits:2; | |
150 | unsigned active:1; | |
151 | unsigned delayed:1; | |
152 | unsigned input:1; | |
153 | unsigned output:1; | |
154 | unsigned pipetype:2; | |
155 | unsigned dequeueing:1; | |
156 | unsigned edset_flush:1; | |
157 | unsigned spare_bits:14; | |
158 | unsigned long jiffies; | |
159 | struct usb_host_endpoint *hep; | |
160 | struct u132_spin queue_lock; | |
161 | u16 queue_size; | |
162 | u16 queue_last; | |
163 | u16 queue_next; | |
164 | struct urb *urb_list[ENDP_QUEUE_SIZE]; | |
165 | struct list_head urb_more; | |
c4028958 | 166 | struct delayed_work scheduler; |
d774efea TO |
167 | }; |
168 | struct u132_ring { | |
169 | unsigned in_use:1; | |
170 | unsigned length:7; | |
171 | u8 number; | |
172 | struct u132 *u132; | |
173 | struct u132_endp *curr_endp; | |
c4028958 | 174 | struct delayed_work scheduler; |
d774efea TO |
175 | }; |
176 | #define OHCI_QUIRK_AMD756 0x01 | |
177 | #define OHCI_QUIRK_SUPERIO 0x02 | |
178 | #define OHCI_QUIRK_INITRESET 0x04 | |
179 | #define OHCI_BIG_ENDIAN 0x08 | |
180 | #define OHCI_QUIRK_ZFMICRO 0x10 | |
181 | struct u132 { | |
182 | struct kref kref; | |
183 | struct list_head u132_list; | |
184 | struct semaphore sw_lock; | |
185 | struct semaphore scheduler_lock; | |
186 | struct u132_platform_data *board; | |
187 | struct platform_device *platform_dev; | |
188 | struct u132_ring ring[MAX_U132_RINGS]; | |
189 | int sequence_num; | |
190 | int going; | |
191 | int power; | |
192 | int reset; | |
193 | int num_ports; | |
194 | u32 hc_control; | |
195 | u32 hc_fminterval; | |
196 | u32 hc_roothub_status; | |
197 | u32 hc_roothub_a; | |
198 | u32 hc_roothub_portstatus[MAX_ROOT_PORTS]; | |
199 | int flags; | |
200 | unsigned long next_statechange; | |
c4028958 | 201 | struct delayed_work monitor; |
d774efea TO |
202 | int num_endpoints; |
203 | struct u132_addr addr[MAX_U132_ADDRS]; | |
204 | struct u132_udev udev[MAX_U132_UDEVS]; | |
205 | struct u132_port port[MAX_U132_PORTS]; | |
206 | struct u132_endp *endp[MAX_U132_ENDPS]; | |
207 | }; | |
9ce8540c | 208 | |
d774efea | 209 | /* |
0779bf2d | 210 | * these cannot be inlines because we need the structure offset!! |
d774efea TO |
211 | * Does anyone have a better way????? |
212 | */ | |
213 | #define u132_read_pcimem(u132, member, data) \ | |
214 | usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \ | |
215 | ohci_regs, member), 0, data); | |
216 | #define u132_write_pcimem(u132, member, data) \ | |
217 | usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \ | |
218 | ohci_regs, member), 0, data); | |
219 | #define u132_write_pcimem_byte(u132, member, data) \ | |
220 | usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \ | |
221 | ohci_regs, member), 0x0e, data); | |
222 | static inline struct u132 *udev_to_u132(struct u132_udev *udev) | |
223 | { | |
224 | u8 udev_number = udev->udev_number; | |
225 | return container_of(udev, struct u132, udev[udev_number]); | |
226 | } | |
227 | ||
228 | static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd) | |
229 | { | |
230 | return (struct u132 *)(hcd->hcd_priv); | |
231 | } | |
232 | ||
233 | static inline struct usb_hcd *u132_to_hcd(struct u132 *u132) | |
234 | { | |
235 | return container_of((void *)u132, struct usb_hcd, hcd_priv); | |
236 | } | |
237 | ||
238 | static inline void u132_disable(struct u132 *u132) | |
239 | { | |
240 | u132_to_hcd(u132)->state = HC_STATE_HALT; | |
241 | } | |
242 | ||
243 | ||
244 | #define kref_to_u132(d) container_of(d, struct u132, kref) | |
245 | #define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref) | |
246 | #define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref) | |
247 | #include "../misc/usb_u132.h" | |
248 | static const char hcd_name[] = "u132_hcd"; | |
249 | #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \ | |
250 | USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \ | |
251 | USB_PORT_STAT_C_RESET) << 16) | |
252 | static void u132_hcd_delete(struct kref *kref) | |
253 | { | |
254 | struct u132 *u132 = kref_to_u132(kref); | |
255 | struct platform_device *pdev = u132->platform_dev; | |
256 | struct usb_hcd *hcd = u132_to_hcd(u132); | |
257 | u132->going += 1; | |
258 | down(&u132_module_lock); | |
259 | list_del_init(&u132->u132_list); | |
260 | u132_instances -= 1; | |
261 | up(&u132_module_lock); | |
262 | dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13" | |
263 | "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev); | |
264 | usb_put_hcd(hcd); | |
265 | } | |
266 | ||
267 | static inline void u132_u132_put_kref(struct u132 *u132) | |
268 | { | |
269 | kref_put(&u132->kref, u132_hcd_delete); | |
270 | } | |
271 | ||
272 | static inline void u132_u132_init_kref(struct u132 *u132) | |
273 | { | |
274 | kref_init(&u132->kref); | |
275 | } | |
276 | ||
277 | static void u132_udev_delete(struct kref *kref) | |
278 | { | |
279 | struct u132_udev *udev = kref_to_u132_udev(kref); | |
280 | udev->udev_number = 0; | |
281 | udev->usb_device = NULL; | |
282 | udev->usb_addr = 0; | |
283 | udev->enumeration = 0; | |
284 | } | |
285 | ||
286 | static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev) | |
287 | { | |
288 | kref_put(&udev->kref, u132_udev_delete); | |
289 | } | |
290 | ||
291 | static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev) | |
292 | { | |
293 | kref_get(&udev->kref); | |
294 | } | |
295 | ||
296 | static inline void u132_udev_init_kref(struct u132 *u132, | |
297 | struct u132_udev *udev) | |
298 | { | |
299 | kref_init(&udev->kref); | |
300 | } | |
301 | ||
302 | static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring) | |
303 | { | |
304 | kref_put(&u132->kref, u132_hcd_delete); | |
305 | } | |
306 | ||
307 | static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring, | |
308 | unsigned int delta) | |
309 | { | |
310 | if (delta > 0) { | |
311 | if (queue_delayed_work(workqueue, &ring->scheduler, delta)) | |
312 | return; | |
c4028958 | 313 | } else if (queue_delayed_work(workqueue, &ring->scheduler, 0)) |
d774efea TO |
314 | return; |
315 | kref_put(&u132->kref, u132_hcd_delete); | |
316 | return; | |
317 | } | |
318 | ||
319 | static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring, | |
320 | unsigned int delta) | |
321 | { | |
322 | kref_get(&u132->kref); | |
323 | u132_ring_requeue_work(u132, ring, delta); | |
324 | return; | |
325 | } | |
326 | ||
327 | static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring) | |
328 | { | |
329 | if (cancel_delayed_work(&ring->scheduler)) { | |
330 | kref_put(&u132->kref, u132_hcd_delete); | |
331 | } | |
332 | } | |
333 | ||
334 | static void u132_endp_delete(struct kref *kref) | |
335 | { | |
336 | struct u132_endp *endp = kref_to_u132_endp(kref); | |
337 | struct u132 *u132 = endp->u132; | |
338 | u8 usb_addr = endp->usb_addr; | |
339 | u8 usb_endp = endp->usb_endp; | |
340 | u8 address = u132->addr[usb_addr].address; | |
341 | struct u132_udev *udev = &u132->udev[address]; | |
342 | u8 endp_number = endp->endp_number; | |
343 | struct usb_host_endpoint *hep = endp->hep; | |
344 | struct u132_ring *ring = endp->ring; | |
345 | struct list_head *head = &endp->endp_ring; | |
346 | ring->length -= 1; | |
347 | if (endp == ring->curr_endp) { | |
348 | if (list_empty(head)) { | |
349 | ring->curr_endp = NULL; | |
350 | list_del(head); | |
351 | } else { | |
352 | struct u132_endp *next_endp = list_entry(head->next, | |
353 | struct u132_endp, endp_ring); | |
354 | ring->curr_endp = next_endp; | |
355 | list_del(head); | |
356 | }} else | |
357 | list_del(head); | |
358 | if (endp->input) { | |
359 | udev->endp_number_in[usb_endp] = 0; | |
360 | u132_udev_put_kref(u132, udev); | |
361 | } | |
362 | if (endp->output) { | |
363 | udev->endp_number_out[usb_endp] = 0; | |
364 | u132_udev_put_kref(u132, udev); | |
365 | } | |
366 | u132->endp[endp_number - 1] = NULL; | |
367 | hep->hcpriv = NULL; | |
368 | kfree(endp); | |
369 | u132_u132_put_kref(u132); | |
370 | } | |
371 | ||
372 | static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp) | |
373 | { | |
374 | kref_put(&endp->kref, u132_endp_delete); | |
375 | } | |
376 | ||
377 | static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp) | |
378 | { | |
379 | kref_get(&endp->kref); | |
380 | } | |
381 | ||
382 | static inline void u132_endp_init_kref(struct u132 *u132, | |
383 | struct u132_endp *endp) | |
384 | { | |
385 | kref_init(&endp->kref); | |
386 | kref_get(&u132->kref); | |
387 | } | |
388 | ||
389 | static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp, | |
390 | unsigned int delta) | |
391 | { | |
c4028958 DH |
392 | if (queue_delayed_work(workqueue, &endp->scheduler, delta)) |
393 | kref_get(&endp->kref); | |
d774efea TO |
394 | } |
395 | ||
396 | static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp) | |
397 | { | |
398 | if (cancel_delayed_work(&endp->scheduler)) | |
399 | kref_put(&endp->kref, u132_endp_delete); | |
400 | } | |
401 | ||
402 | static inline void u132_monitor_put_kref(struct u132 *u132) | |
403 | { | |
404 | kref_put(&u132->kref, u132_hcd_delete); | |
405 | } | |
406 | ||
407 | static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta) | |
408 | { | |
c4028958 DH |
409 | if (queue_delayed_work(workqueue, &u132->monitor, delta)) |
410 | kref_get(&u132->kref); | |
d774efea TO |
411 | } |
412 | ||
413 | static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta) | |
414 | { | |
c4028958 DH |
415 | if (!queue_delayed_work(workqueue, &u132->monitor, delta)) |
416 | kref_put(&u132->kref, u132_hcd_delete); | |
d774efea TO |
417 | } |
418 | ||
419 | static void u132_monitor_cancel_work(struct u132 *u132) | |
420 | { | |
421 | if (cancel_delayed_work(&u132->monitor)) | |
422 | kref_put(&u132->kref, u132_hcd_delete); | |
423 | } | |
424 | ||
425 | static int read_roothub_info(struct u132 *u132) | |
426 | { | |
427 | u32 revision; | |
428 | int retval; | |
429 | retval = u132_read_pcimem(u132, revision, &revision); | |
430 | if (retval) { | |
431 | dev_err(&u132->platform_dev->dev, "error %d accessing device co" | |
432 | "ntrol\n", retval); | |
433 | return retval; | |
434 | } else if ((revision & 0xFF) == 0x10) { | |
435 | } else if ((revision & 0xFF) == 0x11) { | |
436 | } else { | |
437 | dev_err(&u132->platform_dev->dev, "device revision is not valid" | |
438 | " %08X\n", revision); | |
439 | return -ENODEV; | |
440 | } | |
441 | retval = u132_read_pcimem(u132, control, &u132->hc_control); | |
442 | if (retval) { | |
443 | dev_err(&u132->platform_dev->dev, "error %d accessing device co" | |
444 | "ntrol\n", retval); | |
445 | return retval; | |
446 | } | |
447 | retval = u132_read_pcimem(u132, roothub.status, | |
448 | &u132->hc_roothub_status); | |
449 | if (retval) { | |
450 | dev_err(&u132->platform_dev->dev, "error %d accessing device re" | |
451 | "g roothub.status\n", retval); | |
452 | return retval; | |
453 | } | |
454 | retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a); | |
455 | if (retval) { | |
456 | dev_err(&u132->platform_dev->dev, "error %d accessing device re" | |
457 | "g roothub.a\n", retval); | |
458 | return retval; | |
459 | } | |
460 | { | |
461 | int I = u132->num_ports; | |
462 | int i = 0; | |
463 | while (I-- > 0) { | |
464 | retval = u132_read_pcimem(u132, roothub.portstatus[i], | |
465 | &u132->hc_roothub_portstatus[i]); | |
466 | if (retval) { | |
467 | dev_err(&u132->platform_dev->dev, "error %d acc" | |
468 | "essing device roothub.portstatus[%d]\n" | |
469 | , retval, i); | |
470 | return retval; | |
471 | } else | |
472 | i += 1; | |
473 | } | |
474 | } | |
475 | return 0; | |
476 | } | |
477 | ||
c4028958 | 478 | static void u132_hcd_monitor_work(struct work_struct *work) |
d774efea | 479 | { |
c4028958 | 480 | struct u132 *u132 = container_of(work, struct u132, monitor.work); |
d774efea TO |
481 | if (u132->going > 1) { |
482 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
483 | , u132->going); | |
484 | u132_monitor_put_kref(u132); | |
485 | return; | |
486 | } else if (u132->going > 0) { | |
487 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
488 | u132_monitor_put_kref(u132); | |
489 | return; | |
490 | } else { | |
491 | int retval; | |
492 | down(&u132->sw_lock); | |
493 | retval = read_roothub_info(u132); | |
494 | if (retval) { | |
495 | struct usb_hcd *hcd = u132_to_hcd(u132); | |
496 | u132_disable(u132); | |
497 | u132->going = 1; | |
498 | up(&u132->sw_lock); | |
499 | usb_hc_died(hcd); | |
500 | ftdi_elan_gone_away(u132->platform_dev); | |
501 | u132_monitor_put_kref(u132); | |
502 | return; | |
503 | } else { | |
504 | u132_monitor_requeue_work(u132, 500); | |
505 | up(&u132->sw_lock); | |
506 | return; | |
507 | } | |
508 | } | |
509 | } | |
510 | ||
511 | static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp, | |
512 | struct urb *urb, int status) | |
513 | { | |
514 | struct u132_ring *ring; | |
515 | unsigned long irqs; | |
516 | struct usb_hcd *hcd = u132_to_hcd(u132); | |
517 | urb->error_count = 0; | |
518 | urb->status = status; | |
519 | urb->hcpriv = NULL; | |
520 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); | |
521 | endp->queue_next += 1; | |
522 | if (ENDP_QUEUE_SIZE > --endp->queue_size) { | |
523 | endp->active = 0; | |
524 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
525 | } else { | |
526 | struct list_head *next = endp->urb_more.next; | |
527 | struct u132_urbq *urbq = list_entry(next, struct u132_urbq, | |
528 | urb_more); | |
529 | list_del(next); | |
530 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = | |
531 | urbq->urb; | |
532 | endp->active = 0; | |
533 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
534 | kfree(urbq); | |
535 | } down(&u132->scheduler_lock); | |
536 | ring = endp->ring; | |
537 | ring->in_use = 0; | |
538 | u132_ring_cancel_work(u132, ring); | |
539 | u132_ring_queue_work(u132, ring, 0); | |
540 | up(&u132->scheduler_lock); | |
541 | u132_endp_put_kref(u132, endp); | |
7d12e780 | 542 | usb_hcd_giveback_urb(hcd, urb); |
d774efea TO |
543 | return; |
544 | } | |
545 | ||
546 | static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp, | |
547 | struct urb *urb, int status) | |
548 | { | |
549 | u132_endp_put_kref(u132, endp); | |
550 | } | |
551 | ||
552 | static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp, | |
553 | struct urb *urb, int status) | |
554 | { | |
555 | unsigned long irqs; | |
556 | struct usb_hcd *hcd = u132_to_hcd(u132); | |
557 | urb->error_count = 0; | |
558 | urb->status = status; | |
559 | urb->hcpriv = NULL; | |
560 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); | |
561 | endp->queue_next += 1; | |
562 | if (ENDP_QUEUE_SIZE > --endp->queue_size) { | |
563 | endp->active = 0; | |
564 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
565 | } else { | |
566 | struct list_head *next = endp->urb_more.next; | |
567 | struct u132_urbq *urbq = list_entry(next, struct u132_urbq, | |
568 | urb_more); | |
569 | list_del(next); | |
570 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = | |
571 | urbq->urb; | |
572 | endp->active = 0; | |
573 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
574 | kfree(urbq); | |
7d12e780 | 575 | } usb_hcd_giveback_urb(hcd, urb); |
d774efea TO |
576 | return; |
577 | } | |
578 | ||
579 | static inline int edset_input(struct u132 *u132, struct u132_ring *ring, | |
580 | struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, | |
581 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | |
582 | int toggle_bits, int error_count, int condition_code, int repeat_number, | |
583 | int halted, int skipped, int actual, int non_null)) | |
584 | { | |
585 | return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp, | |
586 | urb, address, endp->usb_endp, toggle_bits, callback); | |
587 | } | |
588 | ||
589 | static inline int edset_setup(struct u132 *u132, struct u132_ring *ring, | |
590 | struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, | |
591 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | |
592 | int toggle_bits, int error_count, int condition_code, int repeat_number, | |
593 | int halted, int skipped, int actual, int non_null)) | |
594 | { | |
595 | return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp, | |
596 | urb, address, endp->usb_endp, toggle_bits, callback); | |
597 | } | |
598 | ||
599 | static inline int edset_single(struct u132 *u132, struct u132_ring *ring, | |
600 | struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, | |
601 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | |
602 | int toggle_bits, int error_count, int condition_code, int repeat_number, | |
603 | int halted, int skipped, int actual, int non_null)) | |
604 | { | |
605 | return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number, | |
606 | endp, urb, address, endp->usb_endp, toggle_bits, callback); | |
607 | } | |
608 | ||
609 | static inline int edset_output(struct u132 *u132, struct u132_ring *ring, | |
610 | struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, | |
611 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | |
612 | int toggle_bits, int error_count, int condition_code, int repeat_number, | |
613 | int halted, int skipped, int actual, int non_null)) | |
614 | { | |
615 | return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number, | |
616 | endp, urb, address, endp->usb_endp, toggle_bits, callback); | |
617 | } | |
618 | ||
619 | ||
620 | /* | |
621 | * must not LOCK sw_lock | |
622 | * | |
623 | */ | |
624 | static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf, | |
625 | int len, int toggle_bits, int error_count, int condition_code, | |
626 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
627 | { | |
628 | struct u132_endp *endp = data; | |
629 | struct u132 *u132 = endp->u132; | |
630 | u8 address = u132->addr[endp->usb_addr].address; | |
631 | struct u132_udev *udev = &u132->udev[address]; | |
632 | down(&u132->scheduler_lock); | |
633 | if (u132->going > 1) { | |
634 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
635 | , u132->going); | |
636 | up(&u132->scheduler_lock); | |
637 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
638 | return; | |
639 | } else if (endp->dequeueing) { | |
640 | endp->dequeueing = 0; | |
641 | up(&u132->scheduler_lock); | |
642 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
643 | return; | |
644 | } else if (u132->going > 0) { | |
645 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
646 | "%p status=%d\n", urb, urb->status); | |
647 | up(&u132->scheduler_lock); | |
648 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
649 | return; | |
650 | } else if (urb->status == -EINPROGRESS) { | |
651 | struct u132_ring *ring = endp->ring; | |
652 | u8 *u = urb->transfer_buffer + urb->actual_length; | |
653 | u8 *b = buf; | |
654 | int L = len; | |
655 | while (L-- > 0) { | |
656 | *u++ = *b++; | |
657 | } | |
658 | urb->actual_length += len; | |
659 | if ((condition_code == TD_CC_NOERROR) && | |
660 | (urb->transfer_buffer_length > urb->actual_length)) { | |
661 | endp->toggle_bits = toggle_bits; | |
662 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, | |
663 | 1 & toggle_bits); | |
664 | if (urb->actual_length > 0) { | |
665 | int retval; | |
666 | up(&u132->scheduler_lock); | |
667 | retval = edset_single(u132, ring, endp, urb, | |
668 | address, endp->toggle_bits, | |
669 | u132_hcd_interrupt_recv); | |
670 | if (retval == 0) { | |
671 | } else | |
672 | u132_hcd_giveback_urb(u132, endp, urb, | |
673 | retval); | |
674 | } else { | |
675 | ring->in_use = 0; | |
676 | endp->active = 0; | |
677 | endp->jiffies = jiffies + | |
678 | msecs_to_jiffies(urb->interval); | |
679 | u132_ring_cancel_work(u132, ring); | |
680 | u132_ring_queue_work(u132, ring, 0); | |
681 | up(&u132->scheduler_lock); | |
682 | u132_endp_put_kref(u132, endp); | |
683 | } | |
684 | return; | |
685 | } else if ((condition_code == TD_DATAUNDERRUN) && | |
686 | ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) { | |
687 | endp->toggle_bits = toggle_bits; | |
688 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, | |
689 | 1 & toggle_bits); | |
690 | up(&u132->scheduler_lock); | |
691 | u132_hcd_giveback_urb(u132, endp, urb, 0); | |
692 | return; | |
693 | } else { | |
694 | if (condition_code == TD_CC_NOERROR) { | |
695 | endp->toggle_bits = toggle_bits; | |
696 | usb_settoggle(udev->usb_device, endp->usb_endp, | |
697 | 0, 1 & toggle_bits); | |
698 | } else if (condition_code == TD_CC_STALL) { | |
699 | endp->toggle_bits = 0x2; | |
700 | usb_settoggle(udev->usb_device, endp->usb_endp, | |
701 | 0, 0); | |
702 | } else { | |
703 | endp->toggle_bits = 0x2; | |
704 | usb_settoggle(udev->usb_device, endp->usb_endp, | |
705 | 0, 0); | |
706 | dev_err(&u132->platform_dev->dev, "urb=%p givin" | |
707 | "g back INTERRUPT %s\n", urb, | |
708 | cc_to_text[condition_code]); | |
709 | } | |
710 | up(&u132->scheduler_lock); | |
711 | u132_hcd_giveback_urb(u132, endp, urb, | |
712 | cc_to_error[condition_code]); | |
713 | return; | |
714 | } | |
715 | } else { | |
716 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
717 | "s=%d\n", urb, urb->status); | |
718 | up(&u132->scheduler_lock); | |
719 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
720 | return; | |
721 | } | |
722 | } | |
723 | ||
724 | static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf, | |
725 | int len, int toggle_bits, int error_count, int condition_code, | |
726 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
727 | { | |
728 | struct u132_endp *endp = data; | |
729 | struct u132 *u132 = endp->u132; | |
730 | u8 address = u132->addr[endp->usb_addr].address; | |
731 | down(&u132->scheduler_lock); | |
732 | if (u132->going > 1) { | |
733 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
734 | , u132->going); | |
735 | up(&u132->scheduler_lock); | |
736 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
737 | return; | |
738 | } else if (endp->dequeueing) { | |
739 | endp->dequeueing = 0; | |
740 | up(&u132->scheduler_lock); | |
741 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
742 | return; | |
743 | } else if (u132->going > 0) { | |
744 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
745 | "%p status=%d\n", urb, urb->status); | |
746 | up(&u132->scheduler_lock); | |
747 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
748 | return; | |
749 | } else if (urb->status == -EINPROGRESS) { | |
750 | struct u132_ring *ring = endp->ring; | |
751 | urb->actual_length += len; | |
752 | endp->toggle_bits = toggle_bits; | |
753 | if (urb->transfer_buffer_length > urb->actual_length) { | |
754 | int retval; | |
755 | up(&u132->scheduler_lock); | |
756 | retval = edset_output(u132, ring, endp, urb, address, | |
757 | endp->toggle_bits, u132_hcd_bulk_output_sent); | |
758 | if (retval == 0) { | |
759 | } else | |
760 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
761 | return; | |
762 | } else { | |
763 | up(&u132->scheduler_lock); | |
764 | u132_hcd_giveback_urb(u132, endp, urb, 0); | |
765 | return; | |
766 | } | |
767 | } else { | |
768 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
769 | "s=%d\n", urb, urb->status); | |
770 | up(&u132->scheduler_lock); | |
771 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
772 | return; | |
773 | } | |
774 | } | |
775 | ||
776 | static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf, | |
777 | int len, int toggle_bits, int error_count, int condition_code, | |
778 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
779 | { | |
780 | struct u132_endp *endp = data; | |
781 | struct u132 *u132 = endp->u132; | |
782 | u8 address = u132->addr[endp->usb_addr].address; | |
783 | struct u132_udev *udev = &u132->udev[address]; | |
784 | down(&u132->scheduler_lock); | |
785 | if (u132->going > 1) { | |
786 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
787 | , u132->going); | |
788 | up(&u132->scheduler_lock); | |
789 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
790 | return; | |
791 | } else if (endp->dequeueing) { | |
792 | endp->dequeueing = 0; | |
793 | up(&u132->scheduler_lock); | |
794 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
795 | return; | |
796 | } else if (u132->going > 0) { | |
797 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
798 | "%p status=%d\n", urb, urb->status); | |
799 | up(&u132->scheduler_lock); | |
800 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
801 | return; | |
802 | } else if (urb->status == -EINPROGRESS) { | |
803 | struct u132_ring *ring = endp->ring; | |
804 | u8 *u = urb->transfer_buffer + urb->actual_length; | |
805 | u8 *b = buf; | |
806 | int L = len; | |
807 | while (L-- > 0) { | |
808 | *u++ = *b++; | |
809 | } | |
810 | urb->actual_length += len; | |
811 | if ((condition_code == TD_CC_NOERROR) && | |
812 | (urb->transfer_buffer_length > urb->actual_length)) { | |
813 | int retval; | |
814 | endp->toggle_bits = toggle_bits; | |
815 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, | |
816 | 1 & toggle_bits); | |
817 | up(&u132->scheduler_lock); | |
818 | retval = usb_ftdi_elan_edset_input(u132->platform_dev, | |
819 | ring->number, endp, urb, address, | |
820 | endp->usb_endp, endp->toggle_bits, | |
821 | u132_hcd_bulk_input_recv); | |
822 | if (retval == 0) { | |
823 | } else | |
824 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
825 | return; | |
826 | } else if (condition_code == TD_CC_NOERROR) { | |
827 | endp->toggle_bits = toggle_bits; | |
828 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, | |
829 | 1 & toggle_bits); | |
830 | up(&u132->scheduler_lock); | |
831 | u132_hcd_giveback_urb(u132, endp, urb, | |
832 | cc_to_error[condition_code]); | |
833 | return; | |
834 | } else if ((condition_code == TD_DATAUNDERRUN) && | |
835 | ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) { | |
836 | endp->toggle_bits = toggle_bits; | |
837 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, | |
838 | 1 & toggle_bits); | |
839 | up(&u132->scheduler_lock); | |
840 | u132_hcd_giveback_urb(u132, endp, urb, 0); | |
841 | return; | |
842 | } else if (condition_code == TD_DATAUNDERRUN) { | |
843 | endp->toggle_bits = toggle_bits; | |
844 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, | |
845 | 1 & toggle_bits); | |
846 | dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK" | |
847 | ") giving back BULK IN %s\n", urb, | |
848 | cc_to_text[condition_code]); | |
849 | up(&u132->scheduler_lock); | |
850 | u132_hcd_giveback_urb(u132, endp, urb, 0); | |
851 | return; | |
852 | } else if (condition_code == TD_CC_STALL) { | |
853 | endp->toggle_bits = 0x2; | |
854 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0); | |
855 | up(&u132->scheduler_lock); | |
856 | u132_hcd_giveback_urb(u132, endp, urb, | |
857 | cc_to_error[condition_code]); | |
858 | return; | |
859 | } else { | |
860 | endp->toggle_bits = 0x2; | |
861 | usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0); | |
862 | dev_err(&u132->platform_dev->dev, "urb=%p giving back B" | |
863 | "ULK IN code=%d %s\n", urb, condition_code, | |
864 | cc_to_text[condition_code]); | |
865 | up(&u132->scheduler_lock); | |
866 | u132_hcd_giveback_urb(u132, endp, urb, | |
867 | cc_to_error[condition_code]); | |
868 | return; | |
869 | } | |
870 | } else { | |
871 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
872 | "s=%d\n", urb, urb->status); | |
873 | up(&u132->scheduler_lock); | |
874 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
875 | return; | |
876 | } | |
877 | } | |
878 | ||
879 | static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf, | |
880 | int len, int toggle_bits, int error_count, int condition_code, | |
881 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
882 | { | |
883 | struct u132_endp *endp = data; | |
884 | struct u132 *u132 = endp->u132; | |
885 | down(&u132->scheduler_lock); | |
886 | if (u132->going > 1) { | |
887 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
888 | , u132->going); | |
889 | up(&u132->scheduler_lock); | |
890 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
891 | return; | |
892 | } else if (endp->dequeueing) { | |
893 | endp->dequeueing = 0; | |
894 | up(&u132->scheduler_lock); | |
895 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
896 | return; | |
897 | } else if (u132->going > 0) { | |
898 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
899 | "%p status=%d\n", urb, urb->status); | |
900 | up(&u132->scheduler_lock); | |
901 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
902 | return; | |
903 | } else if (urb->status == -EINPROGRESS) { | |
904 | up(&u132->scheduler_lock); | |
905 | u132_hcd_giveback_urb(u132, endp, urb, 0); | |
906 | return; | |
907 | } else { | |
908 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
909 | "s=%d\n", urb, urb->status); | |
910 | up(&u132->scheduler_lock); | |
911 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
912 | return; | |
913 | } | |
914 | } | |
915 | ||
916 | static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf, | |
917 | int len, int toggle_bits, int error_count, int condition_code, | |
918 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
919 | { | |
920 | struct u132_endp *endp = data; | |
921 | struct u132 *u132 = endp->u132; | |
922 | u8 address = u132->addr[endp->usb_addr].address; | |
923 | down(&u132->scheduler_lock); | |
924 | if (u132->going > 1) { | |
925 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
926 | , u132->going); | |
927 | up(&u132->scheduler_lock); | |
928 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
929 | return; | |
930 | } else if (endp->dequeueing) { | |
931 | endp->dequeueing = 0; | |
932 | up(&u132->scheduler_lock); | |
933 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
934 | return; | |
935 | } else if (u132->going > 0) { | |
936 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
937 | "%p status=%d\n", urb, urb->status); | |
938 | up(&u132->scheduler_lock); | |
939 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
940 | return; | |
941 | } else if (urb->status == -EINPROGRESS) { | |
942 | struct u132_ring *ring = endp->ring; | |
943 | u8 *u = urb->transfer_buffer; | |
944 | u8 *b = buf; | |
945 | int L = len; | |
946 | while (L-- > 0) { | |
947 | *u++ = *b++; | |
948 | } | |
949 | urb->actual_length = len; | |
950 | if ((condition_code == TD_CC_NOERROR) || ((condition_code == | |
951 | TD_DATAUNDERRUN) && ((urb->transfer_flags & | |
952 | URB_SHORT_NOT_OK) == 0))) { | |
953 | int retval; | |
954 | up(&u132->scheduler_lock); | |
955 | retval = usb_ftdi_elan_edset_empty(u132->platform_dev, | |
956 | ring->number, endp, urb, address, | |
957 | endp->usb_endp, 0x3, | |
958 | u132_hcd_configure_empty_sent); | |
959 | if (retval == 0) { | |
960 | } else | |
961 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
962 | return; | |
963 | } else if (condition_code == TD_CC_STALL) { | |
964 | up(&u132->scheduler_lock); | |
965 | dev_warn(&u132->platform_dev->dev, "giving back SETUP I" | |
966 | "NPUT STALL urb %p\n", urb); | |
967 | u132_hcd_giveback_urb(u132, endp, urb, | |
968 | cc_to_error[condition_code]); | |
969 | return; | |
970 | } else { | |
971 | up(&u132->scheduler_lock); | |
972 | dev_err(&u132->platform_dev->dev, "giving back SETUP IN" | |
973 | "PUT %s urb %p\n", cc_to_text[condition_code], | |
974 | urb); | |
975 | u132_hcd_giveback_urb(u132, endp, urb, | |
976 | cc_to_error[condition_code]); | |
977 | return; | |
978 | } | |
979 | } else { | |
980 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
981 | "s=%d\n", urb, urb->status); | |
982 | up(&u132->scheduler_lock); | |
983 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
984 | return; | |
985 | } | |
986 | } | |
987 | ||
988 | static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf, | |
989 | int len, int toggle_bits, int error_count, int condition_code, | |
990 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
991 | { | |
992 | struct u132_endp *endp = data; | |
993 | struct u132 *u132 = endp->u132; | |
994 | down(&u132->scheduler_lock); | |
995 | if (u132->going > 1) { | |
996 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
997 | , u132->going); | |
998 | up(&u132->scheduler_lock); | |
999 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
1000 | return; | |
1001 | } else if (endp->dequeueing) { | |
1002 | endp->dequeueing = 0; | |
1003 | up(&u132->scheduler_lock); | |
1004 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
1005 | return; | |
1006 | } else if (u132->going > 0) { | |
1007 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
1008 | "%p status=%d\n", urb, urb->status); | |
1009 | up(&u132->scheduler_lock); | |
1010 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
1011 | return; | |
1012 | } else if (urb->status == -EINPROGRESS) { | |
1013 | up(&u132->scheduler_lock); | |
1014 | u132_hcd_giveback_urb(u132, endp, urb, 0); | |
1015 | return; | |
1016 | } else { | |
1017 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
1018 | "s=%d\n", urb, urb->status); | |
1019 | up(&u132->scheduler_lock); | |
1020 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
1021 | return; | |
1022 | } | |
1023 | } | |
1024 | ||
1025 | static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf, | |
1026 | int len, int toggle_bits, int error_count, int condition_code, | |
1027 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
1028 | { | |
1029 | struct u132_endp *endp = data; | |
1030 | struct u132 *u132 = endp->u132; | |
1031 | u8 address = u132->addr[endp->usb_addr].address; | |
1032 | down(&u132->scheduler_lock); | |
1033 | if (u132->going > 1) { | |
1034 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
1035 | , u132->going); | |
1036 | up(&u132->scheduler_lock); | |
1037 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
1038 | return; | |
1039 | } else if (endp->dequeueing) { | |
1040 | endp->dequeueing = 0; | |
1041 | up(&u132->scheduler_lock); | |
1042 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
1043 | return; | |
1044 | } else if (u132->going > 0) { | |
1045 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
1046 | "%p status=%d\n", urb, urb->status); | |
1047 | up(&u132->scheduler_lock); | |
1048 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
1049 | return; | |
1050 | } else if (urb->status == -EINPROGRESS) { | |
1051 | if (usb_pipein(urb->pipe)) { | |
1052 | int retval; | |
1053 | struct u132_ring *ring = endp->ring; | |
1054 | up(&u132->scheduler_lock); | |
1055 | retval = usb_ftdi_elan_edset_input(u132->platform_dev, | |
1056 | ring->number, endp, urb, address, | |
1057 | endp->usb_endp, 0, | |
1058 | u132_hcd_configure_input_recv); | |
1059 | if (retval == 0) { | |
1060 | } else | |
1061 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
1062 | return; | |
1063 | } else { | |
1064 | int retval; | |
1065 | struct u132_ring *ring = endp->ring; | |
1066 | up(&u132->scheduler_lock); | |
1067 | retval = usb_ftdi_elan_edset_input(u132->platform_dev, | |
1068 | ring->number, endp, urb, address, | |
1069 | endp->usb_endp, 0, | |
1070 | u132_hcd_configure_empty_recv); | |
1071 | if (retval == 0) { | |
1072 | } else | |
1073 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
1074 | return; | |
1075 | } | |
1076 | } else { | |
1077 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
1078 | "s=%d\n", urb, urb->status); | |
1079 | up(&u132->scheduler_lock); | |
1080 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
1081 | return; | |
1082 | } | |
1083 | } | |
1084 | ||
1085 | static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb, | |
1086 | u8 *buf, int len, int toggle_bits, int error_count, int condition_code, | |
1087 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
1088 | { | |
1089 | struct u132_endp *endp = data; | |
1090 | struct u132 *u132 = endp->u132; | |
1091 | u8 address = u132->addr[endp->usb_addr].address; | |
1092 | struct u132_udev *udev = &u132->udev[address]; | |
1093 | down(&u132->scheduler_lock); | |
1094 | if (u132->going > 1) { | |
1095 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
1096 | , u132->going); | |
1097 | up(&u132->scheduler_lock); | |
1098 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
1099 | return; | |
1100 | } else if (endp->dequeueing) { | |
1101 | endp->dequeueing = 0; | |
1102 | up(&u132->scheduler_lock); | |
1103 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
1104 | return; | |
1105 | } else if (u132->going > 0) { | |
1106 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
1107 | "%p status=%d\n", urb, urb->status); | |
1108 | up(&u132->scheduler_lock); | |
1109 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
1110 | return; | |
1111 | } else if (urb->status == -EINPROGRESS) { | |
1112 | u132->addr[0].address = 0; | |
1113 | endp->usb_addr = udev->usb_addr; | |
1114 | up(&u132->scheduler_lock); | |
1115 | u132_hcd_giveback_urb(u132, endp, urb, 0); | |
1116 | return; | |
1117 | } else { | |
1118 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
1119 | "s=%d\n", urb, urb->status); | |
1120 | up(&u132->scheduler_lock); | |
1121 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
1122 | return; | |
1123 | } | |
1124 | } | |
1125 | ||
1126 | static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb, | |
1127 | u8 *buf, int len, int toggle_bits, int error_count, int condition_code, | |
1128 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
1129 | { | |
1130 | struct u132_endp *endp = data; | |
1131 | struct u132 *u132 = endp->u132; | |
1132 | down(&u132->scheduler_lock); | |
1133 | if (u132->going > 1) { | |
1134 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
1135 | , u132->going); | |
1136 | up(&u132->scheduler_lock); | |
1137 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
1138 | return; | |
1139 | } else if (endp->dequeueing) { | |
1140 | endp->dequeueing = 0; | |
1141 | up(&u132->scheduler_lock); | |
1142 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
1143 | return; | |
1144 | } else if (u132->going > 0) { | |
1145 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
1146 | "%p status=%d\n", urb, urb->status); | |
1147 | up(&u132->scheduler_lock); | |
1148 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
1149 | return; | |
1150 | } else if (urb->status == -EINPROGRESS) { | |
1151 | int retval; | |
1152 | struct u132_ring *ring = endp->ring; | |
1153 | up(&u132->scheduler_lock); | |
1154 | retval = usb_ftdi_elan_edset_input(u132->platform_dev, | |
1155 | ring->number, endp, urb, 0, endp->usb_endp, 0, | |
1156 | u132_hcd_enumeration_empty_recv); | |
1157 | if (retval == 0) { | |
1158 | } else | |
1159 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
1160 | return; | |
1161 | } else { | |
1162 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
1163 | "s=%d\n", urb, urb->status); | |
1164 | up(&u132->scheduler_lock); | |
1165 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
1166 | return; | |
1167 | } | |
1168 | } | |
1169 | ||
1170 | static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf, | |
1171 | int len, int toggle_bits, int error_count, int condition_code, | |
1172 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
1173 | { | |
1174 | struct u132_endp *endp = data; | |
1175 | struct u132 *u132 = endp->u132; | |
1176 | down(&u132->scheduler_lock); | |
1177 | if (u132->going > 1) { | |
1178 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
1179 | , u132->going); | |
1180 | up(&u132->scheduler_lock); | |
1181 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
1182 | return; | |
1183 | } else if (endp->dequeueing) { | |
1184 | endp->dequeueing = 0; | |
1185 | up(&u132->scheduler_lock); | |
1186 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
1187 | return; | |
1188 | } else if (u132->going > 0) { | |
1189 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
1190 | "%p status=%d\n", urb, urb->status); | |
1191 | up(&u132->scheduler_lock); | |
1192 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
1193 | return; | |
1194 | } else if (urb->status == -EINPROGRESS) { | |
1195 | up(&u132->scheduler_lock); | |
1196 | u132_hcd_giveback_urb(u132, endp, urb, 0); | |
1197 | return; | |
1198 | } else { | |
1199 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
1200 | "s=%d\n", urb, urb->status); | |
1201 | up(&u132->scheduler_lock); | |
1202 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
1203 | return; | |
1204 | } | |
1205 | } | |
1206 | ||
1207 | static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf, | |
1208 | int len, int toggle_bits, int error_count, int condition_code, | |
1209 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
1210 | { | |
1211 | struct u132_endp *endp = data; | |
1212 | struct u132 *u132 = endp->u132; | |
1213 | u8 address = u132->addr[endp->usb_addr].address; | |
1214 | down(&u132->scheduler_lock); | |
1215 | if (u132->going > 1) { | |
1216 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
1217 | , u132->going); | |
1218 | up(&u132->scheduler_lock); | |
1219 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
1220 | return; | |
1221 | } else if (endp->dequeueing) { | |
1222 | endp->dequeueing = 0; | |
1223 | up(&u132->scheduler_lock); | |
1224 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
1225 | return; | |
1226 | } else if (u132->going > 0) { | |
1227 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
1228 | "%p status=%d\n", urb, urb->status); | |
1229 | up(&u132->scheduler_lock); | |
1230 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
1231 | return; | |
1232 | } else if (urb->status == -EINPROGRESS) { | |
1233 | int retval; | |
1234 | struct u132_ring *ring = endp->ring; | |
1235 | u8 *u = urb->transfer_buffer; | |
1236 | u8 *b = buf; | |
1237 | int L = len; | |
1238 | while (L-- > 0) { | |
1239 | *u++ = *b++; | |
1240 | } | |
1241 | urb->actual_length = len; | |
1242 | up(&u132->scheduler_lock); | |
1243 | retval = usb_ftdi_elan_edset_empty(u132->platform_dev, | |
1244 | ring->number, endp, urb, address, endp->usb_endp, 0x3, | |
1245 | u132_hcd_initial_empty_sent); | |
1246 | if (retval == 0) { | |
1247 | } else | |
1248 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
1249 | return; | |
1250 | } else { | |
1251 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
1252 | "s=%d\n", urb, urb->status); | |
1253 | up(&u132->scheduler_lock); | |
1254 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
1255 | return; | |
1256 | } | |
1257 | } | |
1258 | ||
1259 | static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf, | |
1260 | int len, int toggle_bits, int error_count, int condition_code, | |
1261 | int repeat_number, int halted, int skipped, int actual, int non_null) | |
1262 | { | |
1263 | struct u132_endp *endp = data; | |
1264 | struct u132 *u132 = endp->u132; | |
1265 | u8 address = u132->addr[endp->usb_addr].address; | |
1266 | down(&u132->scheduler_lock); | |
1267 | if (u132->going > 1) { | |
1268 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
1269 | , u132->going); | |
1270 | up(&u132->scheduler_lock); | |
1271 | u132_hcd_forget_urb(u132, endp, urb, -ENODEV); | |
1272 | return; | |
1273 | } else if (endp->dequeueing) { | |
1274 | endp->dequeueing = 0; | |
1275 | up(&u132->scheduler_lock); | |
1276 | u132_hcd_giveback_urb(u132, endp, urb, -EINTR); | |
1277 | return; | |
1278 | } else if (u132->going > 0) { | |
1279 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
1280 | "%p status=%d\n", urb, urb->status); | |
1281 | up(&u132->scheduler_lock); | |
1282 | u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); | |
1283 | return; | |
1284 | } else if (urb->status == -EINPROGRESS) { | |
1285 | int retval; | |
1286 | struct u132_ring *ring = endp->ring; | |
1287 | up(&u132->scheduler_lock); | |
1288 | retval = usb_ftdi_elan_edset_input(u132->platform_dev, | |
1289 | ring->number, endp, urb, address, endp->usb_endp, 0, | |
1290 | u132_hcd_initial_input_recv); | |
1291 | if (retval == 0) { | |
1292 | } else | |
1293 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
1294 | return; | |
1295 | } else { | |
1296 | dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu" | |
1297 | "s=%d\n", urb, urb->status); | |
1298 | up(&u132->scheduler_lock); | |
1299 | u132_hcd_giveback_urb(u132, endp, urb, urb->status); | |
1300 | return; | |
1301 | } | |
1302 | } | |
1303 | ||
d774efea TO |
1304 | /* |
1305 | * this work function is only executed from the work queue | |
1306 | * | |
1307 | */ | |
c4028958 | 1308 | static void u132_hcd_ring_work_scheduler(struct work_struct *work) |
d774efea | 1309 | { |
c4028958 DH |
1310 | struct u132_ring *ring = |
1311 | container_of(work, struct u132_ring, scheduler.work); | |
d774efea TO |
1312 | struct u132 *u132 = ring->u132; |
1313 | down(&u132->scheduler_lock); | |
1314 | if (ring->in_use) { | |
1315 | up(&u132->scheduler_lock); | |
1316 | u132_ring_put_kref(u132, ring); | |
1317 | return; | |
1318 | } else if (ring->curr_endp) { | |
1319 | struct u132_endp *last_endp = ring->curr_endp; | |
1320 | struct list_head *scan; | |
1321 | struct list_head *head = &last_endp->endp_ring; | |
1322 | unsigned long wakeup = 0; | |
1323 | list_for_each(scan, head) { | |
1324 | struct u132_endp *endp = list_entry(scan, | |
1325 | struct u132_endp, endp_ring); | |
1326 | if (endp->queue_next == endp->queue_last) { | |
1327 | } else if ((endp->delayed == 0) | |
1328 | || time_after_eq(jiffies, endp->jiffies)) { | |
1329 | ring->curr_endp = endp; | |
1330 | u132_endp_cancel_work(u132, last_endp); | |
1331 | u132_endp_queue_work(u132, last_endp, 0); | |
1332 | up(&u132->scheduler_lock); | |
1333 | u132_ring_put_kref(u132, ring); | |
1334 | return; | |
1335 | } else { | |
1336 | unsigned long delta = endp->jiffies - jiffies; | |
1337 | if (delta > wakeup) | |
1338 | wakeup = delta; | |
1339 | } | |
1340 | } | |
1341 | if (last_endp->queue_next == last_endp->queue_last) { | |
1342 | } else if ((last_endp->delayed == 0) || time_after_eq(jiffies, | |
1343 | last_endp->jiffies)) { | |
1344 | u132_endp_cancel_work(u132, last_endp); | |
1345 | u132_endp_queue_work(u132, last_endp, 0); | |
1346 | up(&u132->scheduler_lock); | |
1347 | u132_ring_put_kref(u132, ring); | |
1348 | return; | |
1349 | } else { | |
1350 | unsigned long delta = last_endp->jiffies - jiffies; | |
1351 | if (delta > wakeup) | |
1352 | wakeup = delta; | |
1353 | } | |
1354 | if (wakeup > 0) { | |
1355 | u132_ring_requeue_work(u132, ring, wakeup); | |
1356 | up(&u132->scheduler_lock); | |
1357 | return; | |
1358 | } else { | |
1359 | up(&u132->scheduler_lock); | |
1360 | u132_ring_put_kref(u132, ring); | |
1361 | return; | |
1362 | } | |
1363 | } else { | |
1364 | up(&u132->scheduler_lock); | |
1365 | u132_ring_put_kref(u132, ring); | |
1366 | return; | |
1367 | } | |
1368 | } | |
1369 | ||
c4028958 | 1370 | static void u132_hcd_endp_work_scheduler(struct work_struct *work) |
d774efea TO |
1371 | { |
1372 | struct u132_ring *ring; | |
c4028958 DH |
1373 | struct u132_endp *endp = |
1374 | container_of(work, struct u132_endp, scheduler.work); | |
d774efea TO |
1375 | struct u132 *u132 = endp->u132; |
1376 | down(&u132->scheduler_lock); | |
1377 | ring = endp->ring; | |
1378 | if (endp->edset_flush) { | |
1379 | endp->edset_flush = 0; | |
1380 | if (endp->dequeueing) | |
1381 | usb_ftdi_elan_edset_flush(u132->platform_dev, | |
1382 | ring->number, endp); | |
1383 | up(&u132->scheduler_lock); | |
1384 | u132_endp_put_kref(u132, endp); | |
1385 | return; | |
1386 | } else if (endp->active) { | |
1387 | up(&u132->scheduler_lock); | |
1388 | u132_endp_put_kref(u132, endp); | |
1389 | return; | |
1390 | } else if (ring->in_use) { | |
1391 | up(&u132->scheduler_lock); | |
1392 | u132_endp_put_kref(u132, endp); | |
1393 | return; | |
1394 | } else if (endp->queue_next == endp->queue_last) { | |
1395 | up(&u132->scheduler_lock); | |
1396 | u132_endp_put_kref(u132, endp); | |
1397 | return; | |
1398 | } else if (endp->pipetype == PIPE_INTERRUPT) { | |
1399 | u8 address = u132->addr[endp->usb_addr].address; | |
1400 | if (ring->in_use) { | |
1401 | up(&u132->scheduler_lock); | |
1402 | u132_endp_put_kref(u132, endp); | |
1403 | return; | |
1404 | } else { | |
1405 | int retval; | |
1406 | struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & | |
1407 | endp->queue_next]; | |
1408 | endp->active = 1; | |
1409 | ring->curr_endp = endp; | |
1410 | ring->in_use = 1; | |
1411 | up(&u132->scheduler_lock); | |
1412 | retval = edset_single(u132, ring, endp, urb, address, | |
1413 | endp->toggle_bits, u132_hcd_interrupt_recv); | |
1414 | if (retval == 0) { | |
1415 | } else | |
1416 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
1417 | return; | |
1418 | } | |
1419 | } else if (endp->pipetype == PIPE_CONTROL) { | |
1420 | u8 address = u132->addr[endp->usb_addr].address; | |
1421 | if (ring->in_use) { | |
1422 | up(&u132->scheduler_lock); | |
1423 | u132_endp_put_kref(u132, endp); | |
1424 | return; | |
1425 | } else if (address == 0) { | |
1426 | int retval; | |
1427 | struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & | |
1428 | endp->queue_next]; | |
1429 | endp->active = 1; | |
1430 | ring->curr_endp = endp; | |
1431 | ring->in_use = 1; | |
1432 | up(&u132->scheduler_lock); | |
1433 | retval = edset_setup(u132, ring, endp, urb, address, | |
1434 | 0x2, u132_hcd_initial_setup_sent); | |
1435 | if (retval == 0) { | |
1436 | } else | |
1437 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
1438 | return; | |
1439 | } else if (endp->usb_addr == 0) { | |
1440 | int retval; | |
1441 | struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & | |
1442 | endp->queue_next]; | |
1443 | endp->active = 1; | |
1444 | ring->curr_endp = endp; | |
1445 | ring->in_use = 1; | |
1446 | up(&u132->scheduler_lock); | |
1447 | retval = edset_setup(u132, ring, endp, urb, 0, 0x2, | |
1448 | u132_hcd_enumeration_address_sent); | |
1449 | if (retval == 0) { | |
1450 | } else | |
1451 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
1452 | return; | |
1453 | } else { | |
1454 | int retval; | |
1455 | u8 address = u132->addr[endp->usb_addr].address; | |
1456 | struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & | |
1457 | endp->queue_next]; | |
1458 | endp->active = 1; | |
1459 | ring->curr_endp = endp; | |
1460 | ring->in_use = 1; | |
1461 | up(&u132->scheduler_lock); | |
1462 | retval = edset_setup(u132, ring, endp, urb, address, | |
1463 | 0x2, u132_hcd_configure_setup_sent); | |
1464 | if (retval == 0) { | |
1465 | } else | |
1466 | u132_hcd_giveback_urb(u132, endp, urb, retval); | |
1467 | return; | |
1468 | } | |
1469 | } else { | |
1470 | if (endp->input) { | |
1471 | u8 address = u132->addr[endp->usb_addr].address; | |
1472 | if (ring->in_use) { | |
1473 | up(&u132->scheduler_lock); | |
1474 | u132_endp_put_kref(u132, endp); | |
1475 | return; | |
1476 | } else { | |
1477 | int retval; | |
1478 | struct urb *urb = endp->urb_list[ | |
1479 | ENDP_QUEUE_MASK & endp->queue_next]; | |
1480 | endp->active = 1; | |
1481 | ring->curr_endp = endp; | |
1482 | ring->in_use = 1; | |
1483 | up(&u132->scheduler_lock); | |
1484 | retval = edset_input(u132, ring, endp, urb, | |
1485 | address, endp->toggle_bits, | |
1486 | u132_hcd_bulk_input_recv); | |
1487 | if (retval == 0) { | |
1488 | } else | |
1489 | u132_hcd_giveback_urb(u132, endp, urb, | |
1490 | retval); | |
1491 | return; | |
1492 | } | |
1493 | } else { /* output pipe */ | |
1494 | u8 address = u132->addr[endp->usb_addr].address; | |
1495 | if (ring->in_use) { | |
1496 | up(&u132->scheduler_lock); | |
1497 | u132_endp_put_kref(u132, endp); | |
1498 | return; | |
1499 | } else { | |
1500 | int retval; | |
1501 | struct urb *urb = endp->urb_list[ | |
1502 | ENDP_QUEUE_MASK & endp->queue_next]; | |
1503 | endp->active = 1; | |
1504 | ring->curr_endp = endp; | |
1505 | ring->in_use = 1; | |
1506 | up(&u132->scheduler_lock); | |
1507 | retval = edset_output(u132, ring, endp, urb, | |
1508 | address, endp->toggle_bits, | |
1509 | u132_hcd_bulk_output_sent); | |
1510 | if (retval == 0) { | |
1511 | } else | |
1512 | u132_hcd_giveback_urb(u132, endp, urb, | |
1513 | retval); | |
1514 | return; | |
1515 | } | |
1516 | } | |
1517 | } | |
1518 | } | |
1519 | ||
1520 | static void port_power(struct u132 *u132, int pn, int is_on) | |
1521 | { | |
1522 | u132->port[pn].power = is_on; | |
1523 | } | |
1524 | ||
1525 | static void u132_power(struct u132 *u132, int is_on) | |
1526 | { | |
1527 | struct usb_hcd *hcd = u132_to_hcd(u132) | |
1528 | ; /* hub is inactive unless the port is powered */ | |
1529 | if (is_on) { | |
1530 | if (u132->power) | |
1531 | return; | |
1532 | u132->power = 1; | |
1533 | hcd->self.controller->power.power_state = PMSG_ON; | |
1534 | } else { | |
1535 | u132->power = 0; | |
1536 | hcd->state = HC_STATE_HALT; | |
1537 | hcd->self.controller->power.power_state = PMSG_SUSPEND; | |
1538 | } | |
1539 | } | |
1540 | ||
1541 | static int u132_periodic_reinit(struct u132 *u132) | |
1542 | { | |
1543 | int retval; | |
1544 | u32 fi = u132->hc_fminterval & 0x03fff; | |
1545 | u32 fit; | |
1546 | u32 fminterval; | |
1547 | retval = u132_read_pcimem(u132, fminterval, &fminterval); | |
1548 | if (retval) | |
1549 | return retval; | |
1550 | fit = fminterval & FIT; | |
1551 | retval = u132_write_pcimem(u132, fminterval, | |
1552 | (fit ^ FIT) | u132->hc_fminterval); | |
1553 | if (retval) | |
1554 | return retval; | |
1555 | retval = u132_write_pcimem(u132, periodicstart, | |
1556 | ((9 *fi) / 10) & 0x3fff); | |
1557 | if (retval) | |
1558 | return retval; | |
1559 | return 0; | |
1560 | } | |
1561 | ||
1562 | static char *hcfs2string(int state) | |
1563 | { | |
1564 | switch (state) { | |
1565 | case OHCI_USB_RESET: | |
1566 | return "reset"; | |
1567 | case OHCI_USB_RESUME: | |
1568 | return "resume"; | |
1569 | case OHCI_USB_OPER: | |
1570 | return "operational"; | |
1571 | case OHCI_USB_SUSPEND: | |
1572 | return "suspend"; | |
1573 | } | |
1574 | return "?"; | |
1575 | } | |
1576 | ||
1577 | static int u132_usb_reset(struct u132 *u132) | |
1578 | { | |
1579 | int retval; | |
1580 | retval = u132_read_pcimem(u132, control, &u132->hc_control); | |
1581 | if (retval) | |
1582 | return retval; | |
1583 | u132->hc_control &= OHCI_CTRL_RWC; | |
1584 | retval = u132_write_pcimem(u132, control, u132->hc_control); | |
1585 | if (retval) | |
1586 | return retval; | |
1587 | return 0; | |
1588 | } | |
1589 | ||
1590 | static int u132_init(struct u132 *u132) | |
1591 | { | |
1592 | int retval; | |
1593 | u32 control; | |
1594 | u132_disable(u132); | |
1595 | u132->next_statechange = | |
1596 | jiffies; /* SMM owns the HC? not for long! */ { | |
1597 | u32 control; | |
1598 | retval = u132_read_pcimem(u132, control, &control); | |
1599 | if (retval) | |
1600 | return retval; | |
1601 | if (control & OHCI_CTRL_IR) { | |
1602 | u32 temp = 50; | |
1603 | retval = u132_write_pcimem(u132, intrenable, | |
1604 | OHCI_INTR_OC); | |
1605 | if (retval) | |
1606 | return retval; | |
1607 | retval = u132_write_pcimem_byte(u132, cmdstatus, | |
1608 | OHCI_OCR); | |
1609 | if (retval) | |
1610 | return retval; | |
1611 | check:{ | |
1612 | retval = u132_read_pcimem(u132, control, | |
1613 | &control); | |
1614 | if (retval) | |
1615 | return retval; | |
1616 | } | |
1617 | if (control & OHCI_CTRL_IR) { | |
1618 | msleep(10); | |
1619 | if (--temp == 0) { | |
1620 | dev_err(&u132->platform_dev->dev, "USB " | |
1621 | "HC takeover failed!(BIOS/SMM b" | |
1622 | "ug) control=%08X\n", control); | |
1623 | return -EBUSY; | |
1624 | } | |
1625 | goto check; | |
1626 | } | |
1627 | u132_usb_reset(u132); | |
1628 | } | |
1629 | } | |
1630 | retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE); | |
1631 | if (retval) | |
1632 | return retval; | |
1633 | retval = u132_read_pcimem(u132, control, &control); | |
1634 | if (retval) | |
1635 | return retval; | |
1636 | if (u132->num_ports == 0) { | |
1637 | u32 rh_a = -1; | |
1638 | retval = u132_read_pcimem(u132, roothub.a, &rh_a); | |
1639 | if (retval) | |
1640 | return retval; | |
1641 | u132->num_ports = rh_a & RH_A_NDP; | |
1642 | retval = read_roothub_info(u132); | |
1643 | if (retval) | |
1644 | return retval; | |
1645 | } | |
1646 | if (u132->num_ports > MAX_U132_PORTS) { | |
1647 | return -EINVAL; | |
1648 | } | |
1649 | return 0; | |
1650 | } | |
1651 | ||
1652 | ||
1653 | /* Start an OHCI controller, set the BUS operational | |
1654 | * resets USB and controller | |
1655 | * enable interrupts | |
1656 | */ | |
1657 | static int u132_run(struct u132 *u132) | |
1658 | { | |
1659 | int retval; | |
1660 | u32 control; | |
1661 | u32 status; | |
1662 | u32 fminterval; | |
1663 | u32 periodicstart; | |
1664 | u32 cmdstatus; | |
1665 | u32 roothub_a; | |
1666 | int mask = OHCI_INTR_INIT; | |
1667 | int first = u132->hc_fminterval == 0; | |
1668 | int sleep_time = 0; | |
1669 | int reset_timeout = 30; /* ... allow extra time */ | |
1670 | u132_disable(u132); | |
1671 | if (first) { | |
1672 | u32 temp; | |
1673 | retval = u132_read_pcimem(u132, fminterval, &temp); | |
1674 | if (retval) | |
1675 | return retval; | |
1676 | u132->hc_fminterval = temp & 0x3fff; | |
1677 | if (u132->hc_fminterval != FI) { | |
1678 | } | |
1679 | u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16; | |
1680 | } | |
1681 | retval = u132_read_pcimem(u132, control, &u132->hc_control); | |
1682 | if (retval) | |
1683 | return retval; | |
1684 | dev_info(&u132->platform_dev->dev, "resetting from state '%s', control " | |
1685 | "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS), | |
1686 | u132->hc_control); | |
1687 | switch (u132->hc_control & OHCI_CTRL_HCFS) { | |
1688 | case OHCI_USB_OPER: | |
1689 | sleep_time = 0; | |
1690 | break; | |
1691 | case OHCI_USB_SUSPEND: | |
1692 | case OHCI_USB_RESUME: | |
1693 | u132->hc_control &= OHCI_CTRL_RWC; | |
1694 | u132->hc_control |= OHCI_USB_RESUME; | |
1695 | sleep_time = 10; | |
1696 | break; | |
1697 | default: | |
1698 | u132->hc_control &= OHCI_CTRL_RWC; | |
1699 | u132->hc_control |= OHCI_USB_RESET; | |
1700 | sleep_time = 50; | |
1701 | break; | |
1702 | } | |
1703 | retval = u132_write_pcimem(u132, control, u132->hc_control); | |
1704 | if (retval) | |
1705 | return retval; | |
1706 | retval = u132_read_pcimem(u132, control, &control); | |
1707 | if (retval) | |
1708 | return retval; | |
1709 | msleep(sleep_time); | |
1710 | retval = u132_read_pcimem(u132, roothub.a, &roothub_a); | |
1711 | if (retval) | |
1712 | return retval; | |
1713 | if (!(roothub_a & RH_A_NPS)) { | |
1714 | int temp; /* power down each port */ | |
1715 | for (temp = 0; temp < u132->num_ports; temp++) { | |
1716 | retval = u132_write_pcimem(u132, | |
1717 | roothub.portstatus[temp], RH_PS_LSDA); | |
1718 | if (retval) | |
1719 | return retval; | |
1720 | } | |
1721 | } | |
1722 | retval = u132_read_pcimem(u132, control, &control); | |
1723 | if (retval) | |
1724 | return retval; | |
1725 | retry:retval = u132_read_pcimem(u132, cmdstatus, &status); | |
1726 | if (retval) | |
1727 | return retval; | |
1728 | retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_HCR); | |
1729 | if (retval) | |
1730 | return retval; | |
1731 | extra:{ | |
1732 | retval = u132_read_pcimem(u132, cmdstatus, &status); | |
1733 | if (retval) | |
1734 | return retval; | |
1735 | if (0 != (status & OHCI_HCR)) { | |
1736 | if (--reset_timeout == 0) { | |
1737 | dev_err(&u132->platform_dev->dev, "USB HC reset" | |
1738 | " timed out!\n"); | |
1739 | return -ENODEV; | |
1740 | } else { | |
1741 | msleep(5); | |
1742 | goto extra; | |
1743 | } | |
1744 | } | |
1745 | } | |
1746 | if (u132->flags & OHCI_QUIRK_INITRESET) { | |
1747 | retval = u132_write_pcimem(u132, control, u132->hc_control); | |
1748 | if (retval) | |
1749 | return retval; | |
1750 | retval = u132_read_pcimem(u132, control, &control); | |
1751 | if (retval) | |
1752 | return retval; | |
1753 | } | |
1754 | retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000); | |
1755 | if (retval) | |
1756 | return retval; | |
1757 | retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000); | |
1758 | if (retval) | |
1759 | return retval; | |
1760 | retval = u132_write_pcimem(u132, hcca, 0x00000000); | |
1761 | if (retval) | |
1762 | return retval; | |
1763 | retval = u132_periodic_reinit(u132); | |
1764 | if (retval) | |
1765 | return retval; | |
1766 | retval = u132_read_pcimem(u132, fminterval, &fminterval); | |
1767 | if (retval) | |
1768 | return retval; | |
1769 | retval = u132_read_pcimem(u132, periodicstart, &periodicstart); | |
1770 | if (retval) | |
1771 | return retval; | |
1772 | if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) { | |
1773 | if (!(u132->flags & OHCI_QUIRK_INITRESET)) { | |
1774 | u132->flags |= OHCI_QUIRK_INITRESET; | |
1775 | goto retry; | |
1776 | } else | |
1777 | dev_err(&u132->platform_dev->dev, "init err(%08x %04x)" | |
1778 | "\n", fminterval, periodicstart); | |
1779 | } /* start controller operations */ | |
1780 | u132->hc_control &= OHCI_CTRL_RWC; | |
1781 | u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER; | |
1782 | retval = u132_write_pcimem(u132, control, u132->hc_control); | |
1783 | if (retval) | |
1784 | return retval; | |
1785 | retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_BLF); | |
1786 | if (retval) | |
1787 | return retval; | |
1788 | retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus); | |
1789 | if (retval) | |
1790 | return retval; | |
1791 | retval = u132_read_pcimem(u132, control, &control); | |
1792 | if (retval) | |
1793 | return retval; | |
1794 | u132_to_hcd(u132)->state = HC_STATE_RUNNING; | |
1795 | retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE); | |
1796 | if (retval) | |
1797 | return retval; | |
1798 | retval = u132_write_pcimem(u132, intrstatus, mask); | |
1799 | if (retval) | |
1800 | return retval; | |
1801 | retval = u132_write_pcimem(u132, intrdisable, | |
1802 | OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO | | |
1803 | OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH | | |
1804 | OHCI_INTR_SO); | |
1805 | if (retval) | |
1806 | return retval; /* handle root hub init quirks ... */ | |
1807 | retval = u132_read_pcimem(u132, roothub.a, &roothub_a); | |
1808 | if (retval) | |
1809 | return retval; | |
1810 | roothub_a &= ~(RH_A_PSM | RH_A_OCPM); | |
1811 | if (u132->flags & OHCI_QUIRK_SUPERIO) { | |
1812 | roothub_a |= RH_A_NOCP; | |
1813 | roothub_a &= ~(RH_A_POTPGT | RH_A_NPS); | |
1814 | retval = u132_write_pcimem(u132, roothub.a, roothub_a); | |
1815 | if (retval) | |
1816 | return retval; | |
1817 | } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) { | |
1818 | roothub_a |= RH_A_NPS; | |
1819 | retval = u132_write_pcimem(u132, roothub.a, roothub_a); | |
1820 | if (retval) | |
1821 | return retval; | |
1822 | } | |
1823 | retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC); | |
1824 | if (retval) | |
1825 | return retval; | |
1826 | retval = u132_write_pcimem(u132, roothub.b, | |
1827 | (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM); | |
1828 | if (retval) | |
1829 | return retval; | |
1830 | retval = u132_read_pcimem(u132, control, &control); | |
1831 | if (retval) | |
1832 | return retval; | |
1833 | mdelay((roothub_a >> 23) & 0x1fe); | |
1834 | u132_to_hcd(u132)->state = HC_STATE_RUNNING; | |
1835 | return 0; | |
1836 | } | |
1837 | ||
1838 | static void u132_hcd_stop(struct usb_hcd *hcd) | |
1839 | { | |
1840 | struct u132 *u132 = hcd_to_u132(hcd); | |
1841 | if (u132->going > 1) { | |
1842 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
1843 | , u132->going); | |
1844 | } else if (u132->going > 0) { | |
1845 | dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" | |
1846 | "ed\n", hcd); | |
1847 | } else { | |
1848 | down(&u132->sw_lock); | |
1849 | msleep(100); | |
1850 | u132_power(u132, 0); | |
1851 | up(&u132->sw_lock); | |
1852 | } | |
1853 | } | |
1854 | ||
1855 | static int u132_hcd_start(struct usb_hcd *hcd) | |
1856 | { | |
1857 | struct u132 *u132 = hcd_to_u132(hcd); | |
1858 | if (u132->going > 1) { | |
1859 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
1860 | , u132->going); | |
1861 | return -ENODEV; | |
1862 | } else if (u132->going > 0) { | |
1863 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
1864 | return -ESHUTDOWN; | |
1865 | } else if (hcd->self.controller) { | |
1866 | int retval; | |
1867 | struct platform_device *pdev = | |
1868 | to_platform_device(hcd->self.controller); | |
1869 | u16 vendor = ((struct u132_platform_data *) | |
1870 | (pdev->dev.platform_data))->vendor; | |
1871 | u16 device = ((struct u132_platform_data *) | |
1872 | (pdev->dev.platform_data))->device; | |
1873 | down(&u132->sw_lock); | |
1874 | msleep(10); | |
1875 | if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) { | |
1876 | u132->flags = OHCI_QUIRK_AMD756; | |
1877 | } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) { | |
1878 | dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar" | |
1879 | "ounds unavailable\n"); | |
1880 | } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8) | |
1881 | u132->flags |= OHCI_QUIRK_ZFMICRO; | |
1882 | retval = u132_run(u132); | |
1883 | if (retval) { | |
1884 | u132_disable(u132); | |
1885 | u132->going = 1; | |
1886 | } | |
1887 | msleep(100); | |
1888 | up(&u132->sw_lock); | |
1889 | return retval; | |
1890 | } else { | |
1891 | dev_err(&u132->platform_dev->dev, "platform_device missing\n"); | |
1892 | return -ENODEV; | |
1893 | } | |
1894 | } | |
1895 | ||
1896 | static int u132_hcd_reset(struct usb_hcd *hcd) | |
1897 | { | |
1898 | struct u132 *u132 = hcd_to_u132(hcd); | |
1899 | if (u132->going > 1) { | |
1900 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
1901 | , u132->going); | |
1902 | return -ENODEV; | |
1903 | } else if (u132->going > 0) { | |
1904 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
1905 | return -ESHUTDOWN; | |
1906 | } else { | |
1907 | int retval; | |
1908 | down(&u132->sw_lock); | |
1909 | retval = u132_init(u132); | |
1910 | if (retval) { | |
1911 | u132_disable(u132); | |
1912 | u132->going = 1; | |
1913 | } | |
1914 | up(&u132->sw_lock); | |
1915 | return retval; | |
1916 | } | |
1917 | } | |
1918 | ||
1919 | static int create_endpoint_and_queue_int(struct u132 *u132, | |
1920 | struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb, | |
1921 | struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, | |
1922 | gfp_t mem_flags) | |
1923 | { | |
1924 | struct u132_ring *ring; | |
1925 | unsigned long irqs; | |
1926 | u8 endp_number = ++u132->num_endpoints; | |
1927 | struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] = | |
1928 | kmalloc(sizeof(struct u132_endp), mem_flags); | |
1929 | if (!endp) { | |
1930 | return -ENOMEM; | |
1931 | } | |
c4028958 | 1932 | INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); |
d774efea TO |
1933 | spin_lock_init(&endp->queue_lock.slock); |
1934 | INIT_LIST_HEAD(&endp->urb_more); | |
1935 | ring = endp->ring = &u132->ring[0]; | |
1936 | if (ring->curr_endp) { | |
1937 | list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); | |
1938 | } else { | |
1939 | INIT_LIST_HEAD(&endp->endp_ring); | |
1940 | ring->curr_endp = endp; | |
1941 | } | |
1942 | ring->length += 1; | |
1943 | endp->dequeueing = 0; | |
1944 | endp->edset_flush = 0; | |
1945 | endp->active = 0; | |
1946 | endp->delayed = 0; | |
1947 | endp->endp_number = endp_number; | |
1948 | endp->u132 = u132; | |
1949 | endp->hep = hep; | |
1950 | endp->pipetype = usb_pipetype(urb->pipe); | |
1951 | u132_endp_init_kref(u132, endp); | |
1952 | if (usb_pipein(urb->pipe)) { | |
1953 | endp->toggle_bits = 0x2; | |
1954 | usb_settoggle(udev->usb_device, usb_endp, 0, 0); | |
1955 | endp->input = 1; | |
1956 | endp->output = 0; | |
1957 | udev->endp_number_in[usb_endp] = endp_number; | |
1958 | u132_udev_get_kref(u132, udev); | |
1959 | } else { | |
1960 | endp->toggle_bits = 0x2; | |
1961 | usb_settoggle(udev->usb_device, usb_endp, 1, 0); | |
1962 | endp->input = 0; | |
1963 | endp->output = 1; | |
1964 | udev->endp_number_out[usb_endp] = endp_number; | |
1965 | u132_udev_get_kref(u132, udev); | |
1966 | } | |
1967 | urb->hcpriv = u132; | |
1968 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); | |
1969 | endp->delayed = 1; | |
1970 | endp->jiffies = jiffies + msecs_to_jiffies(urb->interval); | |
1971 | endp->udev_number = address; | |
1972 | endp->usb_addr = usb_addr; | |
1973 | endp->usb_endp = usb_endp; | |
1974 | endp->queue_size = 1; | |
1975 | endp->queue_last = 0; | |
1976 | endp->queue_next = 0; | |
1977 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; | |
1978 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
1979 | u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval)); | |
1980 | return 0; | |
1981 | } | |
1982 | ||
1983 | static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev, | |
1984 | struct usb_host_endpoint *hep, struct urb *urb, | |
1985 | struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, | |
1986 | u8 usb_endp, u8 address) | |
1987 | { | |
1988 | urb->hcpriv = u132; | |
1989 | endp->delayed = 1; | |
1990 | endp->jiffies = jiffies + msecs_to_jiffies(urb->interval); | |
1991 | if (endp->queue_size++ < ENDP_QUEUE_SIZE) { | |
1992 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; | |
1993 | } else { | |
1994 | struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq), | |
1995 | GFP_ATOMIC); | |
1996 | if (urbq == NULL) { | |
1997 | endp->queue_size -= 1; | |
1998 | return -ENOMEM; | |
1999 | } else { | |
2000 | list_add_tail(&urbq->urb_more, &endp->urb_more); | |
2001 | urbq->urb = urb; | |
2002 | } | |
2003 | } | |
2004 | return 0; | |
2005 | } | |
2006 | ||
2007 | static int create_endpoint_and_queue_bulk(struct u132 *u132, | |
2008 | struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb, | |
2009 | struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, | |
2010 | gfp_t mem_flags) | |
2011 | { | |
2012 | int ring_number; | |
2013 | struct u132_ring *ring; | |
2014 | unsigned long irqs; | |
2015 | u8 endp_number = ++u132->num_endpoints; | |
2016 | struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] = | |
2017 | kmalloc(sizeof(struct u132_endp), mem_flags); | |
2018 | if (!endp) { | |
2019 | return -ENOMEM; | |
2020 | } | |
c4028958 | 2021 | INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); |
d774efea TO |
2022 | spin_lock_init(&endp->queue_lock.slock); |
2023 | INIT_LIST_HEAD(&endp->urb_more); | |
2024 | endp->dequeueing = 0; | |
2025 | endp->edset_flush = 0; | |
2026 | endp->active = 0; | |
2027 | endp->delayed = 0; | |
2028 | endp->endp_number = endp_number; | |
2029 | endp->u132 = u132; | |
2030 | endp->hep = hep; | |
2031 | endp->pipetype = usb_pipetype(urb->pipe); | |
2032 | u132_endp_init_kref(u132, endp); | |
2033 | if (usb_pipein(urb->pipe)) { | |
2034 | endp->toggle_bits = 0x2; | |
2035 | usb_settoggle(udev->usb_device, usb_endp, 0, 0); | |
2036 | ring_number = 3; | |
2037 | endp->input = 1; | |
2038 | endp->output = 0; | |
2039 | udev->endp_number_in[usb_endp] = endp_number; | |
2040 | u132_udev_get_kref(u132, udev); | |
2041 | } else { | |
2042 | endp->toggle_bits = 0x2; | |
2043 | usb_settoggle(udev->usb_device, usb_endp, 1, 0); | |
2044 | ring_number = 2; | |
2045 | endp->input = 0; | |
2046 | endp->output = 1; | |
2047 | udev->endp_number_out[usb_endp] = endp_number; | |
2048 | u132_udev_get_kref(u132, udev); | |
2049 | } | |
2050 | ring = endp->ring = &u132->ring[ring_number - 1]; | |
2051 | if (ring->curr_endp) { | |
2052 | list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); | |
2053 | } else { | |
2054 | INIT_LIST_HEAD(&endp->endp_ring); | |
2055 | ring->curr_endp = endp; | |
2056 | } | |
2057 | ring->length += 1; | |
2058 | urb->hcpriv = u132; | |
2059 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); | |
2060 | endp->udev_number = address; | |
2061 | endp->usb_addr = usb_addr; | |
2062 | endp->usb_endp = usb_endp; | |
2063 | endp->queue_size = 1; | |
2064 | endp->queue_last = 0; | |
2065 | endp->queue_next = 0; | |
2066 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; | |
2067 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
2068 | u132_endp_queue_work(u132, endp, 0); | |
2069 | return 0; | |
2070 | } | |
2071 | ||
2072 | static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev, | |
2073 | struct usb_host_endpoint *hep, struct urb *urb, | |
2074 | struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, | |
2075 | u8 usb_endp, u8 address) | |
2076 | { | |
2077 | urb->hcpriv = u132; | |
2078 | if (endp->queue_size++ < ENDP_QUEUE_SIZE) { | |
2079 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; | |
2080 | } else { | |
2081 | struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq), | |
2082 | GFP_ATOMIC); | |
2083 | if (urbq == NULL) { | |
2084 | endp->queue_size -= 1; | |
2085 | return -ENOMEM; | |
2086 | } else { | |
2087 | list_add_tail(&urbq->urb_more, &endp->urb_more); | |
2088 | urbq->urb = urb; | |
2089 | } | |
2090 | } | |
2091 | return 0; | |
2092 | } | |
2093 | ||
2094 | static int create_endpoint_and_queue_control(struct u132 *u132, | |
2095 | struct usb_host_endpoint *hep, struct urb *urb, | |
2096 | struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, | |
2097 | gfp_t mem_flags) | |
2098 | { | |
2099 | struct u132_ring *ring; | |
2100 | u8 endp_number = ++u132->num_endpoints; | |
2101 | struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] = | |
2102 | kmalloc(sizeof(struct u132_endp), mem_flags); | |
2103 | if (!endp) { | |
2104 | return -ENOMEM; | |
2105 | } | |
c4028958 | 2106 | INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); |
d774efea TO |
2107 | spin_lock_init(&endp->queue_lock.slock); |
2108 | INIT_LIST_HEAD(&endp->urb_more); | |
2109 | ring = endp->ring = &u132->ring[0]; | |
2110 | if (ring->curr_endp) { | |
2111 | list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); | |
2112 | } else { | |
2113 | INIT_LIST_HEAD(&endp->endp_ring); | |
2114 | ring->curr_endp = endp; | |
2115 | } | |
2116 | ring->length += 1; | |
2117 | endp->dequeueing = 0; | |
2118 | endp->edset_flush = 0; | |
2119 | endp->active = 0; | |
2120 | endp->delayed = 0; | |
2121 | endp->endp_number = endp_number; | |
2122 | endp->u132 = u132; | |
2123 | endp->hep = hep; | |
2124 | u132_endp_init_kref(u132, endp); | |
2125 | u132_endp_get_kref(u132, endp); | |
2126 | if (usb_addr == 0) { | |
2127 | unsigned long irqs; | |
2128 | u8 address = u132->addr[usb_addr].address; | |
2129 | struct u132_udev *udev = &u132->udev[address]; | |
2130 | endp->udev_number = address; | |
2131 | endp->usb_addr = usb_addr; | |
2132 | endp->usb_endp = usb_endp; | |
2133 | endp->input = 1; | |
2134 | endp->output = 1; | |
2135 | endp->pipetype = usb_pipetype(urb->pipe); | |
2136 | u132_udev_init_kref(u132, udev); | |
2137 | u132_udev_get_kref(u132, udev); | |
2138 | udev->endp_number_in[usb_endp] = endp_number; | |
2139 | udev->endp_number_out[usb_endp] = endp_number; | |
2140 | urb->hcpriv = u132; | |
2141 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); | |
2142 | endp->queue_size = 1; | |
2143 | endp->queue_last = 0; | |
2144 | endp->queue_next = 0; | |
2145 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; | |
2146 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
2147 | u132_endp_queue_work(u132, endp, 0); | |
2148 | return 0; | |
2149 | } else { /*(usb_addr > 0) */ | |
2150 | unsigned long irqs; | |
2151 | u8 address = u132->addr[usb_addr].address; | |
2152 | struct u132_udev *udev = &u132->udev[address]; | |
2153 | endp->udev_number = address; | |
2154 | endp->usb_addr = usb_addr; | |
2155 | endp->usb_endp = usb_endp; | |
2156 | endp->input = 1; | |
2157 | endp->output = 1; | |
2158 | endp->pipetype = usb_pipetype(urb->pipe); | |
2159 | u132_udev_get_kref(u132, udev); | |
2160 | udev->enumeration = 2; | |
2161 | udev->endp_number_in[usb_endp] = endp_number; | |
2162 | udev->endp_number_out[usb_endp] = endp_number; | |
2163 | urb->hcpriv = u132; | |
2164 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); | |
2165 | endp->queue_size = 1; | |
2166 | endp->queue_last = 0; | |
2167 | endp->queue_next = 0; | |
2168 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; | |
2169 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
2170 | u132_endp_queue_work(u132, endp, 0); | |
2171 | return 0; | |
2172 | } | |
2173 | } | |
2174 | ||
2175 | static int queue_control_on_old_endpoint(struct u132 *u132, | |
2176 | struct usb_host_endpoint *hep, struct urb *urb, | |
2177 | struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, | |
2178 | u8 usb_endp) | |
2179 | { | |
2180 | if (usb_addr == 0) { | |
2181 | if (usb_pipein(urb->pipe)) { | |
2182 | urb->hcpriv = u132; | |
2183 | if (endp->queue_size++ < ENDP_QUEUE_SIZE) { | |
2184 | endp->urb_list[ENDP_QUEUE_MASK & | |
2185 | endp->queue_last++] = urb; | |
2186 | } else { | |
2187 | struct u132_urbq *urbq = | |
2188 | kmalloc(sizeof(struct u132_urbq), | |
2189 | GFP_ATOMIC); | |
2190 | if (urbq == NULL) { | |
2191 | endp->queue_size -= 1; | |
2192 | return -ENOMEM; | |
2193 | } else { | |
2194 | list_add_tail(&urbq->urb_more, | |
2195 | &endp->urb_more); | |
2196 | urbq->urb = urb; | |
2197 | } | |
2198 | } | |
2199 | return 0; | |
2200 | } else { /* usb_pipeout(urb->pipe) */ | |
2201 | struct u132_addr *addr = &u132->addr[usb_dev->devnum]; | |
2202 | int I = MAX_U132_UDEVS; | |
2203 | int i = 0; | |
2204 | while (--I > 0) { | |
2205 | struct u132_udev *udev = &u132->udev[++i]; | |
2206 | if (udev->usb_device) { | |
2207 | continue; | |
2208 | } else { | |
2209 | udev->enumeration = 1; | |
2210 | u132->addr[0].address = i; | |
2211 | endp->udev_number = i; | |
2212 | udev->udev_number = i; | |
2213 | udev->usb_addr = usb_dev->devnum; | |
2214 | u132_udev_init_kref(u132, udev); | |
2215 | udev->endp_number_in[usb_endp] = | |
2216 | endp->endp_number; | |
2217 | u132_udev_get_kref(u132, udev); | |
2218 | udev->endp_number_out[usb_endp] = | |
2219 | endp->endp_number; | |
2220 | udev->usb_device = usb_dev; | |
2221 | ((u8 *) (urb->setup_packet))[2] = | |
2222 | addr->address = i; | |
2223 | u132_udev_get_kref(u132, udev); | |
2224 | break; | |
2225 | } | |
2226 | } | |
2227 | if (I == 0) { | |
2228 | dev_err(&u132->platform_dev->dev, "run out of d" | |
2229 | "evice space\n"); | |
2230 | return -EINVAL; | |
2231 | } | |
2232 | urb->hcpriv = u132; | |
2233 | if (endp->queue_size++ < ENDP_QUEUE_SIZE) { | |
2234 | endp->urb_list[ENDP_QUEUE_MASK & | |
2235 | endp->queue_last++] = urb; | |
2236 | } else { | |
2237 | struct u132_urbq *urbq = | |
2238 | kmalloc(sizeof(struct u132_urbq), | |
2239 | GFP_ATOMIC); | |
2240 | if (urbq == NULL) { | |
2241 | endp->queue_size -= 1; | |
2242 | return -ENOMEM; | |
2243 | } else { | |
2244 | list_add_tail(&urbq->urb_more, | |
2245 | &endp->urb_more); | |
2246 | urbq->urb = urb; | |
2247 | } | |
2248 | } | |
2249 | return 0; | |
2250 | } | |
2251 | } else { /*(usb_addr > 0) */ | |
2252 | u8 address = u132->addr[usb_addr].address; | |
2253 | struct u132_udev *udev = &u132->udev[address]; | |
2254 | urb->hcpriv = u132; | |
2255 | if (udev->enumeration == 2) { | |
2256 | } else | |
2257 | udev->enumeration = 2; | |
2258 | if (endp->queue_size++ < ENDP_QUEUE_SIZE) { | |
2259 | endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = | |
2260 | urb; | |
2261 | } else { | |
2262 | struct u132_urbq *urbq = | |
2263 | kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC); | |
2264 | if (urbq == NULL) { | |
2265 | endp->queue_size -= 1; | |
2266 | return -ENOMEM; | |
2267 | } else { | |
2268 | list_add_tail(&urbq->urb_more, &endp->urb_more); | |
2269 | urbq->urb = urb; | |
2270 | } | |
2271 | } | |
2272 | return 0; | |
2273 | } | |
2274 | } | |
2275 | ||
2276 | static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep, | |
2277 | struct urb *urb, gfp_t mem_flags) | |
2278 | { | |
2279 | struct u132 *u132 = hcd_to_u132(hcd); | |
2280 | if (irqs_disabled()) { | |
2281 | if (__GFP_WAIT & mem_flags) { | |
2282 | printk(KERN_ERR "invalid context for function that migh" | |
2283 | "t sleep\n"); | |
2284 | return -EINVAL; | |
2285 | } | |
2286 | } | |
2287 | if (u132->going > 1) { | |
2288 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2289 | , u132->going); | |
2290 | return -ENODEV; | |
2291 | } else if (u132->going > 0) { | |
2292 | dev_err(&u132->platform_dev->dev, "device is being removed urb=" | |
2293 | "%p status=%d\n", urb, urb->status); | |
2294 | return -ESHUTDOWN; | |
2295 | } else { | |
2296 | u8 usb_addr = usb_pipedevice(urb->pipe); | |
2297 | u8 usb_endp = usb_pipeendpoint(urb->pipe); | |
2298 | struct usb_device *usb_dev = urb->dev; | |
2299 | if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { | |
2300 | u8 address = u132->addr[usb_addr].address; | |
2301 | struct u132_udev *udev = &u132->udev[address]; | |
2302 | struct u132_endp *endp = hep->hcpriv; | |
2303 | urb->actual_length = 0; | |
2304 | if (endp) { | |
2305 | unsigned long irqs; | |
2306 | int retval; | |
2307 | spin_lock_irqsave(&endp->queue_lock.slock, | |
2308 | irqs); | |
2309 | retval = queue_int_on_old_endpoint(u132, udev, | |
2310 | hep, urb, usb_dev, endp, usb_addr, | |
2311 | usb_endp, address); | |
2312 | spin_unlock_irqrestore(&endp->queue_lock.slock, | |
2313 | irqs); | |
2314 | if (retval) { | |
2315 | return retval; | |
2316 | } else { | |
2317 | u132_endp_queue_work(u132, endp, | |
2318 | msecs_to_jiffies(urb->interval)) | |
2319 | ; | |
2320 | return 0; | |
2321 | } | |
2322 | } else if (u132->num_endpoints == MAX_U132_ENDPS) { | |
2323 | return -EINVAL; | |
2324 | } else { /*(endp == NULL) */ | |
2325 | return create_endpoint_and_queue_int(u132, udev, | |
2326 | hep, urb, usb_dev, usb_addr, usb_endp, | |
2327 | address, mem_flags); | |
2328 | } | |
2329 | } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { | |
2330 | dev_err(&u132->platform_dev->dev, "the hardware does no" | |
2331 | "t support PIPE_ISOCHRONOUS\n"); | |
2332 | return -EINVAL; | |
2333 | } else if (usb_pipetype(urb->pipe) == PIPE_BULK) { | |
2334 | u8 address = u132->addr[usb_addr].address; | |
2335 | struct u132_udev *udev = &u132->udev[address]; | |
2336 | struct u132_endp *endp = hep->hcpriv; | |
2337 | urb->actual_length = 0; | |
2338 | if (endp) { | |
2339 | unsigned long irqs; | |
2340 | int retval; | |
2341 | spin_lock_irqsave(&endp->queue_lock.slock, | |
2342 | irqs); | |
2343 | retval = queue_bulk_on_old_endpoint(u132, udev, | |
2344 | hep, urb, usb_dev, endp, usb_addr, | |
2345 | usb_endp, address); | |
2346 | spin_unlock_irqrestore(&endp->queue_lock.slock, | |
2347 | irqs); | |
2348 | if (retval) { | |
2349 | return retval; | |
2350 | } else { | |
2351 | u132_endp_queue_work(u132, endp, 0); | |
2352 | return 0; | |
2353 | } | |
2354 | } else if (u132->num_endpoints == MAX_U132_ENDPS) { | |
2355 | return -EINVAL; | |
2356 | } else | |
2357 | return create_endpoint_and_queue_bulk(u132, | |
2358 | udev, hep, urb, usb_dev, usb_addr, | |
2359 | usb_endp, address, mem_flags); | |
2360 | } else { | |
2361 | struct u132_endp *endp = hep->hcpriv; | |
2362 | u16 urb_size = 8; | |
2363 | u8 *b = urb->setup_packet; | |
2364 | int i = 0; | |
2365 | char data[30 *3 + 4]; | |
2366 | char *d = data; | |
2367 | int m = (sizeof(data) - 1) / 3; | |
2368 | int l = 0; | |
2369 | data[0] = 0; | |
2370 | while (urb_size-- > 0) { | |
2371 | if (i > m) { | |
2372 | } else if (i++ < m) { | |
2373 | int w = sprintf(d, " %02X", *b++); | |
2374 | d += w; | |
2375 | l += w; | |
2376 | } else | |
2377 | d += sprintf(d, " .."); | |
2378 | } | |
2379 | if (endp) { | |
2380 | unsigned long irqs; | |
2381 | int retval; | |
2382 | spin_lock_irqsave(&endp->queue_lock.slock, | |
2383 | irqs); | |
2384 | retval = queue_control_on_old_endpoint(u132, | |
2385 | hep, urb, usb_dev, endp, usb_addr, | |
2386 | usb_endp); | |
2387 | spin_unlock_irqrestore(&endp->queue_lock.slock, | |
2388 | irqs); | |
2389 | if (retval) { | |
2390 | return retval; | |
2391 | } else { | |
2392 | u132_endp_queue_work(u132, endp, 0); | |
2393 | return 0; | |
2394 | } | |
2395 | } else if (u132->num_endpoints == MAX_U132_ENDPS) { | |
2396 | return -EINVAL; | |
2397 | } else | |
2398 | return create_endpoint_and_queue_control(u132, | |
2399 | hep, urb, usb_dev, usb_addr, usb_endp, | |
2400 | mem_flags); | |
2401 | } | |
2402 | } | |
2403 | } | |
2404 | ||
2405 | static int dequeue_from_overflow_chain(struct u132 *u132, | |
2406 | struct u132_endp *endp, struct urb *urb) | |
2407 | { | |
2408 | struct list_head *scan; | |
2409 | struct list_head *head = &endp->urb_more; | |
2410 | list_for_each(scan, head) { | |
2411 | struct u132_urbq *urbq = list_entry(scan, struct u132_urbq, | |
2412 | urb_more); | |
2413 | if (urbq->urb == urb) { | |
2414 | struct usb_hcd *hcd = u132_to_hcd(u132); | |
2415 | list_del(scan); | |
2416 | endp->queue_size -= 1; | |
2417 | urb->error_count = 0; | |
2418 | urb->hcpriv = NULL; | |
7d12e780 | 2419 | usb_hcd_giveback_urb(hcd, urb); |
d774efea TO |
2420 | return 0; |
2421 | } else | |
2422 | continue; | |
2423 | } | |
2424 | dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring" | |
2425 | "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X" | |
2426 | "\n", urb, endp->endp_number, endp, endp->ring->number, | |
2427 | endp->input ? 'I' : ' ', endp->output ? 'O' : ' ', | |
2428 | endp->usb_endp, endp->usb_addr, endp->queue_size, | |
2429 | endp->queue_next, endp->queue_last); | |
2430 | return -EINVAL; | |
2431 | } | |
2432 | ||
2433 | static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp, | |
2434 | struct urb *urb) | |
2435 | { | |
2436 | unsigned long irqs; | |
2437 | spin_lock_irqsave(&endp->queue_lock.slock, irqs); | |
2438 | if (endp->queue_size == 0) { | |
2439 | dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]" | |
2440 | "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb, | |
2441 | endp->endp_number, endp, endp->ring->number, | |
2442 | endp->input ? 'I' : ' ', endp->output ? 'O' : ' ', | |
2443 | endp->usb_endp, endp->usb_addr); | |
2444 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
2445 | return -EINVAL; | |
2446 | } | |
2447 | if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) { | |
2448 | if (endp->active) { | |
2449 | endp->dequeueing = 1; | |
2450 | endp->edset_flush = 1; | |
2451 | u132_endp_queue_work(u132, endp, 0); | |
2452 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
2453 | urb->hcpriv = NULL; | |
2454 | return 0; | |
2455 | } else { | |
2456 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
2457 | u132_hcd_abandon_urb(u132, endp, urb, urb->status); | |
2458 | return 0; | |
2459 | } | |
2460 | } else { | |
2461 | u16 queue_list = 0; | |
2462 | u16 queue_size = endp->queue_size; | |
2463 | u16 queue_scan = endp->queue_next; | |
2464 | struct urb **urb_slot = NULL; | |
2465 | while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) { | |
2466 | if (urb == endp->urb_list[ENDP_QUEUE_MASK & | |
2467 | ++queue_scan]) { | |
2468 | urb_slot = &endp->urb_list[ENDP_QUEUE_MASK & | |
2469 | queue_scan]; | |
2470 | break; | |
2471 | } else | |
2472 | continue; | |
2473 | } | |
2474 | while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) { | |
2475 | *urb_slot = endp->urb_list[ENDP_QUEUE_MASK & | |
2476 | ++queue_scan]; | |
2477 | urb_slot = &endp->urb_list[ENDP_QUEUE_MASK & | |
2478 | queue_scan]; | |
2479 | } | |
2480 | if (urb_slot) { | |
2481 | struct usb_hcd *hcd = u132_to_hcd(u132); | |
2482 | endp->queue_size -= 1; | |
2483 | if (list_empty(&endp->urb_more)) { | |
2484 | spin_unlock_irqrestore(&endp->queue_lock.slock, | |
2485 | irqs); | |
2486 | } else { | |
2487 | struct list_head *next = endp->urb_more.next; | |
2488 | struct u132_urbq *urbq = list_entry(next, | |
2489 | struct u132_urbq, urb_more); | |
2490 | list_del(next); | |
2491 | *urb_slot = urbq->urb; | |
2492 | spin_unlock_irqrestore(&endp->queue_lock.slock, | |
2493 | irqs); | |
2494 | kfree(urbq); | |
2495 | } urb->error_count = 0; | |
2496 | urb->hcpriv = NULL; | |
7d12e780 | 2497 | usb_hcd_giveback_urb(hcd, urb); |
d774efea TO |
2498 | return 0; |
2499 | } else if (list_empty(&endp->urb_more)) { | |
2500 | dev_err(&u132->platform_dev->dev, "urb=%p not found in " | |
2501 | "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr" | |
2502 | "=%d size=%d next=%04X last=%04X\n", urb, | |
2503 | endp->endp_number, endp, endp->ring->number, | |
2504 | endp->input ? 'I' : ' ', | |
2505 | endp->output ? 'O' : ' ', endp->usb_endp, | |
2506 | endp->usb_addr, endp->queue_size, | |
2507 | endp->queue_next, endp->queue_last); | |
2508 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
2509 | return -EINVAL; | |
2510 | } else { | |
2511 | int retval = dequeue_from_overflow_chain(u132, endp, | |
2512 | urb); | |
2513 | spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); | |
2514 | return retval; | |
2515 | } | |
2516 | } | |
2517 | } | |
2518 | ||
2519 | static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) | |
2520 | { | |
2521 | struct u132 *u132 = hcd_to_u132(hcd); | |
2522 | if (u132->going > 2) { | |
2523 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2524 | , u132->going); | |
2525 | return -ENODEV; | |
2526 | } else { | |
2527 | u8 usb_addr = usb_pipedevice(urb->pipe); | |
2528 | u8 usb_endp = usb_pipeendpoint(urb->pipe); | |
2529 | u8 address = u132->addr[usb_addr].address; | |
2530 | struct u132_udev *udev = &u132->udev[address]; | |
2531 | if (usb_pipein(urb->pipe)) { | |
2532 | u8 endp_number = udev->endp_number_in[usb_endp]; | |
2533 | struct u132_endp *endp = u132->endp[endp_number - 1]; | |
2534 | return u132_endp_urb_dequeue(u132, endp, urb); | |
2535 | } else { | |
2536 | u8 endp_number = udev->endp_number_out[usb_endp]; | |
2537 | struct u132_endp *endp = u132->endp[endp_number - 1]; | |
2538 | return u132_endp_urb_dequeue(u132, endp, urb); | |
2539 | } | |
2540 | } | |
2541 | } | |
2542 | ||
2543 | static void u132_endpoint_disable(struct usb_hcd *hcd, | |
2544 | struct usb_host_endpoint *hep) | |
2545 | { | |
2546 | struct u132 *u132 = hcd_to_u132(hcd); | |
2547 | if (u132->going > 2) { | |
2548 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2549 | , u132->going); | |
2550 | } else { | |
2551 | struct u132_endp *endp = hep->hcpriv; | |
2552 | if (endp) | |
2553 | u132_endp_put_kref(u132, endp); | |
2554 | } | |
2555 | } | |
2556 | ||
2557 | static int u132_get_frame(struct usb_hcd *hcd) | |
2558 | { | |
2559 | struct u132 *u132 = hcd_to_u132(hcd); | |
2560 | if (u132->going > 1) { | |
2561 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2562 | , u132->going); | |
2563 | return -ENODEV; | |
2564 | } else if (u132->going > 0) { | |
2565 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
2566 | return -ESHUTDOWN; | |
2567 | } else { | |
2568 | int frame = 0; | |
2569 | dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n"); | |
2570 | msleep(100); | |
2571 | return frame; | |
2572 | } | |
2573 | } | |
2574 | ||
2575 | static int u132_roothub_descriptor(struct u132 *u132, | |
2576 | struct usb_hub_descriptor *desc) | |
2577 | { | |
2578 | int retval; | |
2579 | u16 temp; | |
2580 | u32 rh_a = -1; | |
2581 | u32 rh_b = -1; | |
2582 | retval = u132_read_pcimem(u132, roothub.a, &rh_a); | |
2583 | if (retval) | |
2584 | return retval; | |
2585 | desc->bDescriptorType = 0x29; | |
2586 | desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24; | |
2587 | desc->bHubContrCurrent = 0; | |
2588 | desc->bNbrPorts = u132->num_ports; | |
2589 | temp = 1 + (u132->num_ports / 8); | |
2590 | desc->bDescLength = 7 + 2 *temp; | |
2591 | temp = 0; | |
2592 | if (rh_a & RH_A_NPS) | |
2593 | temp |= 0x0002; | |
2594 | if (rh_a & RH_A_PSM) | |
2595 | temp |= 0x0001; | |
2596 | if (rh_a & RH_A_NOCP) { | |
2597 | temp |= 0x0010; | |
2598 | } else if (rh_a & RH_A_OCPM) | |
2599 | temp |= 0x0008; | |
2600 | desc->wHubCharacteristics = cpu_to_le16(temp); | |
2601 | retval = u132_read_pcimem(u132, roothub.b, &rh_b); | |
2602 | if (retval) | |
2603 | return retval; | |
2604 | memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); | |
2605 | desc->bitmap[0] = rh_b & RH_B_DR; | |
2606 | if (u132->num_ports > 7) { | |
2607 | desc->bitmap[1] = (rh_b & RH_B_DR) >> 8; | |
2608 | desc->bitmap[2] = 0xff; | |
2609 | } else | |
2610 | desc->bitmap[1] = 0xff; | |
2611 | return 0; | |
2612 | } | |
2613 | ||
2614 | static int u132_roothub_status(struct u132 *u132, __le32 *desc) | |
2615 | { | |
2616 | u32 rh_status = -1; | |
2617 | int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status); | |
2618 | *desc = cpu_to_le32(rh_status); | |
2619 | return ret_status; | |
2620 | } | |
2621 | ||
2622 | static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex) | |
2623 | { | |
2624 | if (wIndex == 0 || wIndex > u132->num_ports) { | |
2625 | return -EINVAL; | |
2626 | } else { | |
2627 | int port = wIndex - 1; | |
2628 | u32 rh_portstatus = -1; | |
2629 | int ret_portstatus = u132_read_pcimem(u132, | |
2630 | roothub.portstatus[port], &rh_portstatus); | |
2631 | *desc = cpu_to_le32(rh_portstatus); | |
2632 | if (*(u16 *) (desc + 2)) { | |
2633 | dev_info(&u132->platform_dev->dev, "Port %d Status Chan" | |
2634 | "ge = %08X\n", port, *desc); | |
2635 | } | |
2636 | return ret_portstatus; | |
2637 | } | |
2638 | } | |
2639 | ||
2640 | ||
2641 | /* this timer value might be vendor-specific ... */ | |
2642 | #define PORT_RESET_HW_MSEC 10 | |
2643 | #define PORT_RESET_MSEC 10 | |
2644 | /* wrap-aware logic morphed from <linux/jiffies.h> */ | |
2645 | #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) | |
2646 | static int u132_roothub_portreset(struct u132 *u132, int port_index) | |
2647 | { | |
2648 | int retval; | |
2649 | u32 fmnumber; | |
2650 | u16 now; | |
2651 | u16 reset_done; | |
2652 | retval = u132_read_pcimem(u132, fmnumber, &fmnumber); | |
2653 | if (retval) | |
2654 | return retval; | |
2655 | now = fmnumber; | |
2656 | reset_done = now + PORT_RESET_MSEC; | |
2657 | do { | |
2658 | u32 portstat; | |
2659 | do { | |
2660 | retval = u132_read_pcimem(u132, | |
2661 | roothub.portstatus[port_index], &portstat); | |
2662 | if (retval) | |
2663 | return retval; | |
2664 | if (RH_PS_PRS & portstat) { | |
2665 | continue; | |
2666 | } else | |
2667 | break; | |
2668 | } while (tick_before(now, reset_done)); | |
2669 | if (RH_PS_PRS & portstat) | |
2670 | return -ENODEV; | |
2671 | if (RH_PS_CCS & portstat) { | |
2672 | if (RH_PS_PRSC & portstat) { | |
2673 | retval = u132_write_pcimem(u132, | |
2674 | roothub.portstatus[port_index], | |
2675 | RH_PS_PRSC); | |
2676 | if (retval) | |
2677 | return retval; | |
2678 | } | |
2679 | } else | |
2680 | break; /* start the next reset, | |
2681 | sleep till it's probably done */ | |
2682 | retval = u132_write_pcimem(u132, roothub.portstatus[port_index], | |
2683 | RH_PS_PRS); | |
2684 | if (retval) | |
2685 | return retval; | |
2686 | msleep(PORT_RESET_HW_MSEC); | |
2687 | retval = u132_read_pcimem(u132, fmnumber, &fmnumber); | |
2688 | if (retval) | |
2689 | return retval; | |
2690 | now = fmnumber; | |
2691 | } while (tick_before(now, reset_done)); | |
2692 | return 0; | |
2693 | } | |
2694 | ||
2695 | static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue, | |
2696 | u16 wIndex) | |
2697 | { | |
2698 | if (wIndex == 0 || wIndex > u132->num_ports) { | |
2699 | return -EINVAL; | |
2700 | } else { | |
2701 | int retval; | |
2702 | int port_index = wIndex - 1; | |
2703 | struct u132_port *port = &u132->port[port_index]; | |
2704 | port->Status &= ~(1 << wValue); | |
2705 | switch (wValue) { | |
2706 | case USB_PORT_FEAT_SUSPEND: | |
2707 | retval = u132_write_pcimem(u132, | |
2708 | roothub.portstatus[port_index], RH_PS_PSS); | |
2709 | if (retval) | |
2710 | return retval; | |
2711 | return 0; | |
2712 | case USB_PORT_FEAT_POWER: | |
2713 | retval = u132_write_pcimem(u132, | |
2714 | roothub.portstatus[port_index], RH_PS_PPS); | |
2715 | if (retval) | |
2716 | return retval; | |
2717 | return 0; | |
2718 | case USB_PORT_FEAT_RESET: | |
2719 | retval = u132_roothub_portreset(u132, port_index); | |
2720 | if (retval) | |
2721 | return retval; | |
2722 | return 0; | |
2723 | default: | |
2724 | return -EPIPE; | |
2725 | } | |
2726 | } | |
2727 | } | |
2728 | ||
2729 | static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue, | |
2730 | u16 wIndex) | |
2731 | { | |
2732 | if (wIndex == 0 || wIndex > u132->num_ports) { | |
2733 | return -EINVAL; | |
2734 | } else { | |
2735 | int port_index = wIndex - 1; | |
2736 | u32 temp; | |
2737 | int retval; | |
2738 | struct u132_port *port = &u132->port[port_index]; | |
2739 | port->Status &= ~(1 << wValue); | |
2740 | switch (wValue) { | |
2741 | case USB_PORT_FEAT_ENABLE: | |
2742 | temp = RH_PS_CCS; | |
2743 | break; | |
2744 | case USB_PORT_FEAT_C_ENABLE: | |
2745 | temp = RH_PS_PESC; | |
2746 | break; | |
2747 | case USB_PORT_FEAT_SUSPEND: | |
2748 | temp = RH_PS_POCI; | |
2749 | if ((u132->hc_control & OHCI_CTRL_HCFS) | |
2750 | != OHCI_USB_OPER) { | |
2751 | dev_err(&u132->platform_dev->dev, "TODO resume_" | |
2752 | "root_hub\n"); | |
2753 | } | |
2754 | break; | |
2755 | case USB_PORT_FEAT_C_SUSPEND: | |
2756 | temp = RH_PS_PSSC; | |
2757 | break; | |
2758 | case USB_PORT_FEAT_POWER: | |
2759 | temp = RH_PS_LSDA; | |
2760 | break; | |
2761 | case USB_PORT_FEAT_C_CONNECTION: | |
2762 | temp = RH_PS_CSC; | |
2763 | break; | |
2764 | case USB_PORT_FEAT_C_OVER_CURRENT: | |
2765 | temp = RH_PS_OCIC; | |
2766 | break; | |
2767 | case USB_PORT_FEAT_C_RESET: | |
2768 | temp = RH_PS_PRSC; | |
2769 | break; | |
2770 | default: | |
2771 | return -EPIPE; | |
2772 | } | |
2773 | retval = u132_write_pcimem(u132, roothub.portstatus[port_index], | |
2774 | temp); | |
2775 | if (retval) | |
2776 | return retval; | |
2777 | return 0; | |
2778 | } | |
2779 | } | |
2780 | ||
2781 | ||
2782 | /* the virtual root hub timer IRQ checks for hub status*/ | |
2783 | static int u132_hub_status_data(struct usb_hcd *hcd, char *buf) | |
2784 | { | |
2785 | struct u132 *u132 = hcd_to_u132(hcd); | |
2786 | if (u132->going > 1) { | |
2787 | dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov" | |
2788 | "ed %d\n", hcd, u132->going); | |
2789 | return -ENODEV; | |
2790 | } else if (u132->going > 0) { | |
2791 | dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" | |
2792 | "ed\n", hcd); | |
2793 | dump_stack(); | |
2794 | return -ESHUTDOWN; | |
2795 | } else { | |
2796 | int i, changed = 0, length = 1; | |
2797 | if (u132->flags & OHCI_QUIRK_AMD756) { | |
2798 | if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) { | |
2799 | dev_err(&u132->platform_dev->dev, "bogus NDP, r" | |
2800 | "ereads as NDP=%d\n", | |
2801 | u132->hc_roothub_a & RH_A_NDP); | |
2802 | goto done; | |
2803 | } | |
2804 | } | |
2805 | if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) { | |
2806 | buf[0] = changed = 1; | |
2807 | } else | |
2808 | buf[0] = 0; | |
2809 | if (u132->num_ports > 7) { | |
2810 | buf[1] = 0; | |
2811 | length++; | |
2812 | } | |
2813 | for (i = 0; i < u132->num_ports; i++) { | |
2814 | if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC | | |
2815 | RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC | | |
2816 | RH_PS_PRSC)) { | |
2817 | changed = 1; | |
2818 | if (i < 7) { | |
2819 | buf[0] |= 1 << (i + 1); | |
2820 | } else | |
2821 | buf[1] |= 1 << (i - 7); | |
2822 | continue; | |
2823 | } | |
2824 | if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) { | |
2825 | continue; | |
2826 | } | |
2827 | if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) { | |
2828 | continue; | |
2829 | } | |
2830 | } | |
2831 | done:return changed ? length : 0; | |
2832 | } | |
2833 | } | |
2834 | ||
2835 | static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |
2836 | u16 wIndex, char *buf, u16 wLength) | |
2837 | { | |
2838 | struct u132 *u132 = hcd_to_u132(hcd); | |
2839 | if (u132->going > 1) { | |
2840 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2841 | , u132->going); | |
2842 | return -ENODEV; | |
2843 | } else if (u132->going > 0) { | |
2844 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
2845 | return -ESHUTDOWN; | |
2846 | } else { | |
2847 | int retval = 0; | |
2848 | down(&u132->sw_lock); | |
2849 | switch (typeReq) { | |
2850 | case ClearHubFeature: | |
2851 | switch (wValue) { | |
2852 | case C_HUB_OVER_CURRENT: | |
2853 | case C_HUB_LOCAL_POWER: | |
2854 | break; | |
2855 | default: | |
2856 | goto stall; | |
2857 | } | |
2858 | break; | |
2859 | case SetHubFeature: | |
2860 | switch (wValue) { | |
2861 | case C_HUB_OVER_CURRENT: | |
2862 | case C_HUB_LOCAL_POWER: | |
2863 | break; | |
2864 | default: | |
2865 | goto stall; | |
2866 | } | |
2867 | break; | |
2868 | case ClearPortFeature:{ | |
2869 | retval = u132_roothub_clearportfeature(u132, | |
2870 | wValue, wIndex); | |
2871 | if (retval) | |
2872 | goto error; | |
2873 | break; | |
2874 | } | |
2875 | case GetHubDescriptor:{ | |
2876 | retval = u132_roothub_descriptor(u132, | |
2877 | (struct usb_hub_descriptor *)buf); | |
2878 | if (retval) | |
2879 | goto error; | |
2880 | break; | |
2881 | } | |
2882 | case GetHubStatus:{ | |
2883 | retval = u132_roothub_status(u132, | |
2884 | (__le32 *) buf); | |
2885 | if (retval) | |
2886 | goto error; | |
2887 | break; | |
2888 | } | |
2889 | case GetPortStatus:{ | |
2890 | retval = u132_roothub_portstatus(u132, | |
2891 | (__le32 *) buf, wIndex); | |
2892 | if (retval) | |
2893 | goto error; | |
2894 | break; | |
2895 | } | |
2896 | case SetPortFeature:{ | |
2897 | retval = u132_roothub_setportfeature(u132, | |
2898 | wValue, wIndex); | |
2899 | if (retval) | |
2900 | goto error; | |
2901 | break; | |
2902 | } | |
2903 | default: | |
2904 | goto stall; | |
2905 | error:u132_disable(u132); | |
2906 | u132->going = 1; | |
2907 | break; | |
2908 | stall:retval = -EPIPE; | |
2909 | break; | |
2910 | } | |
2911 | up(&u132->sw_lock); | |
2912 | return retval; | |
2913 | } | |
2914 | } | |
2915 | ||
2916 | static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num) | |
2917 | { | |
2918 | struct u132 *u132 = hcd_to_u132(hcd); | |
2919 | if (u132->going > 1) { | |
2920 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2921 | , u132->going); | |
2922 | return -ENODEV; | |
2923 | } else if (u132->going > 0) { | |
2924 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
2925 | return -ESHUTDOWN; | |
2926 | } else | |
2927 | return 0; | |
2928 | } | |
2929 | ||
2930 | static void u132_hub_irq_enable(struct usb_hcd *hcd) | |
2931 | { | |
2932 | struct u132 *u132 = hcd_to_u132(hcd); | |
2933 | if (u132->going > 1) { | |
2934 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2935 | , u132->going); | |
2936 | } else if (u132->going > 0) | |
2937 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
2938 | } | |
2939 | ||
2940 | ||
2941 | #ifdef CONFIG_PM | |
2942 | static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message) | |
2943 | { | |
2944 | struct u132 *u132 = hcd_to_u132(hcd); | |
2945 | if (u132->going > 1) { | |
2946 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2947 | , u132->going); | |
2948 | return -ENODEV; | |
2949 | } else if (u132->going > 0) { | |
2950 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
2951 | return -ESHUTDOWN; | |
2952 | } else | |
2953 | return 0; | |
2954 | } | |
2955 | ||
2956 | static int u132_hcd_resume(struct usb_hcd *hcd) | |
2957 | { | |
2958 | struct u132 *u132 = hcd_to_u132(hcd); | |
2959 | if (u132->going > 1) { | |
2960 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2961 | , u132->going); | |
2962 | return -ENODEV; | |
2963 | } else if (u132->going > 0) { | |
2964 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
2965 | return -ESHUTDOWN; | |
2966 | } else | |
2967 | return 0; | |
2968 | } | |
2969 | ||
2970 | static int u132_bus_suspend(struct usb_hcd *hcd) | |
2971 | { | |
2972 | struct u132 *u132 = hcd_to_u132(hcd); | |
2973 | if (u132->going > 1) { | |
2974 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2975 | , u132->going); | |
2976 | return -ENODEV; | |
2977 | } else if (u132->going > 0) { | |
2978 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
2979 | return -ESHUTDOWN; | |
2980 | } else | |
2981 | return 0; | |
2982 | } | |
2983 | ||
2984 | static int u132_bus_resume(struct usb_hcd *hcd) | |
2985 | { | |
2986 | struct u132 *u132 = hcd_to_u132(hcd); | |
2987 | if (u132->going > 1) { | |
2988 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
2989 | , u132->going); | |
2990 | return -ENODEV; | |
2991 | } else if (u132->going > 0) { | |
2992 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
2993 | return -ESHUTDOWN; | |
2994 | } else | |
2995 | return 0; | |
2996 | } | |
2997 | ||
2998 | #else | |
2999 | #define u132_hcd_suspend NULL | |
3000 | #define u132_hcd_resume NULL | |
3001 | #define u132_bus_suspend NULL | |
3002 | #define u132_bus_resume NULL | |
3003 | #endif | |
3004 | static struct hc_driver u132_hc_driver = { | |
3005 | .description = hcd_name, | |
3006 | .hcd_priv_size = sizeof(struct u132), | |
3007 | .irq = NULL, | |
3008 | .flags = HCD_USB11 | HCD_MEMORY, | |
3009 | .reset = u132_hcd_reset, | |
3010 | .start = u132_hcd_start, | |
3011 | .suspend = u132_hcd_suspend, | |
3012 | .resume = u132_hcd_resume, | |
3013 | .stop = u132_hcd_stop, | |
3014 | .urb_enqueue = u132_urb_enqueue, | |
3015 | .urb_dequeue = u132_urb_dequeue, | |
3016 | .endpoint_disable = u132_endpoint_disable, | |
3017 | .get_frame_number = u132_get_frame, | |
3018 | .hub_status_data = u132_hub_status_data, | |
3019 | .hub_control = u132_hub_control, | |
3020 | .bus_suspend = u132_bus_suspend, | |
3021 | .bus_resume = u132_bus_resume, | |
3022 | .start_port_reset = u132_start_port_reset, | |
3023 | .hub_irq_enable = u132_hub_irq_enable, | |
3024 | }; | |
3025 | ||
3026 | /* | |
3027 | * This function may be called by the USB core whilst the "usb_all_devices_rwsem" | |
3028 | * is held for writing, thus this module must not call usb_remove_hcd() | |
3029 | * synchronously - but instead should immediately stop activity to the | |
0779bf2d | 3030 | * device and asynchronously call usb_remove_hcd() |
d774efea TO |
3031 | */ |
3032 | static int __devexit u132_remove(struct platform_device *pdev) | |
3033 | { | |
3034 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | |
3035 | if (hcd) { | |
3036 | struct u132 *u132 = hcd_to_u132(hcd); | |
3037 | dump_stack(); | |
3038 | if (u132->going++ > 1) { | |
3039 | return -ENODEV; | |
3040 | } else { | |
3041 | int rings = MAX_U132_RINGS; | |
3042 | int endps = MAX_U132_ENDPS; | |
3043 | msleep(100); | |
3044 | down(&u132->sw_lock); | |
3045 | u132_monitor_cancel_work(u132); | |
3046 | while (rings-- > 0) { | |
3047 | struct u132_ring *ring = &u132->ring[rings]; | |
3048 | u132_ring_cancel_work(u132, ring); | |
3049 | } while (endps-- > 0) { | |
3050 | struct u132_endp *endp = u132->endp[endps]; | |
3051 | if (endp) | |
3052 | u132_endp_cancel_work(u132, endp); | |
3053 | } | |
3054 | u132->going += 1; | |
3055 | printk(KERN_INFO "removing device u132.%d\n", | |
3056 | u132->sequence_num); | |
3057 | up(&u132->sw_lock); | |
3058 | usb_remove_hcd(hcd); | |
3059 | u132_u132_put_kref(u132); | |
3060 | return 0; | |
3061 | } | |
3062 | } else | |
3063 | return 0; | |
3064 | } | |
3065 | ||
3066 | static void u132_initialise(struct u132 *u132, struct platform_device *pdev) | |
3067 | { | |
3068 | int rings = MAX_U132_RINGS; | |
3069 | int ports = MAX_U132_PORTS; | |
3070 | int addrs = MAX_U132_ADDRS; | |
3071 | int udevs = MAX_U132_UDEVS; | |
3072 | int endps = MAX_U132_ENDPS; | |
3073 | u132->board = pdev->dev.platform_data; | |
3074 | u132->platform_dev = pdev; | |
3075 | u132->power = 0; | |
3076 | u132->reset = 0; | |
3077 | init_MUTEX(&u132->sw_lock); | |
3078 | init_MUTEX(&u132->scheduler_lock); | |
3079 | while (rings-- > 0) { | |
3080 | struct u132_ring *ring = &u132->ring[rings]; | |
3081 | ring->u132 = u132; | |
3082 | ring->number = rings + 1; | |
3083 | ring->length = 0; | |
3084 | ring->curr_endp = NULL; | |
c4028958 DH |
3085 | INIT_DELAYED_WORK(&ring->scheduler, |
3086 | u132_hcd_ring_work_scheduler); | |
d774efea | 3087 | } down(&u132->sw_lock); |
c4028958 | 3088 | INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work); |
d774efea TO |
3089 | while (ports-- > 0) { |
3090 | struct u132_port *port = &u132->port[ports]; | |
3091 | port->u132 = u132; | |
3092 | port->reset = 0; | |
3093 | port->enable = 0; | |
3094 | port->power = 0; | |
3095 | port->Status = 0; | |
3096 | } while (addrs-- > 0) { | |
3097 | struct u132_addr *addr = &u132->addr[addrs]; | |
3098 | addr->address = 0; | |
3099 | } while (udevs-- > 0) { | |
3100 | struct u132_udev *udev = &u132->udev[udevs]; | |
3101 | int i = ARRAY_SIZE(udev->endp_number_in); | |
3102 | int o = ARRAY_SIZE(udev->endp_number_out); | |
3103 | udev->usb_device = NULL; | |
3104 | udev->udev_number = 0; | |
3105 | udev->usb_addr = 0; | |
3106 | udev->portnumber = 0; | |
3107 | while (i-- > 0) { | |
3108 | udev->endp_number_in[i] = 0; | |
3109 | } | |
3110 | while (o-- > 0) { | |
3111 | udev->endp_number_out[o] = 0; | |
3112 | } | |
3113 | } | |
3114 | while (endps-- > 0) { | |
3115 | u132->endp[endps] = NULL; | |
3116 | } | |
3117 | up(&u132->sw_lock); | |
3118 | return; | |
3119 | } | |
3120 | ||
3121 | static int __devinit u132_probe(struct platform_device *pdev) | |
3122 | { | |
3123 | struct usb_hcd *hcd; | |
3124 | msleep(100); | |
3125 | if (u132_exiting > 0) { | |
3126 | return -ENODEV; | |
3127 | } /* refuse to confuse usbcore */ | |
3128 | if (pdev->dev.dma_mask) { | |
3129 | return -EINVAL; | |
3130 | } | |
3131 | hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id); | |
3132 | if (!hcd) { | |
3133 | printk(KERN_ERR "failed to create the usb hcd struct for U132\n" | |
3134 | ); | |
3135 | ftdi_elan_gone_away(pdev); | |
3136 | return -ENOMEM; | |
3137 | } else { | |
3138 | int retval = 0; | |
3139 | struct u132 *u132 = hcd_to_u132(hcd); | |
3140 | hcd->rsrc_start = 0; | |
3141 | down(&u132_module_lock); | |
3142 | list_add_tail(&u132->u132_list, &u132_static_list); | |
3143 | u132->sequence_num = ++u132_instances; | |
3144 | up(&u132_module_lock); | |
3145 | u132_u132_init_kref(u132); | |
3146 | u132_initialise(u132, pdev); | |
3147 | hcd->product_desc = "ELAN U132 Host Controller"; | |
3148 | retval = usb_add_hcd(hcd, 0, 0); | |
3149 | if (retval != 0) { | |
3150 | dev_err(&u132->platform_dev->dev, "init error %d\n", | |
3151 | retval); | |
3152 | u132_u132_put_kref(u132); | |
3153 | return retval; | |
3154 | } else { | |
3155 | u132_monitor_queue_work(u132, 100); | |
3156 | return 0; | |
3157 | } | |
3158 | } | |
3159 | } | |
3160 | ||
3161 | ||
3162 | #ifdef CONFIG_PM | |
3163 | /* for this device there's no useful distinction between the controller | |
3164 | * and its root hub, except that the root hub only gets direct PM calls | |
3165 | * when CONFIG_USB_SUSPEND is enabled. | |
3166 | */ | |
3167 | static int u132_suspend(struct platform_device *pdev, pm_message_t state) | |
3168 | { | |
3169 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | |
3170 | struct u132 *u132 = hcd_to_u132(hcd); | |
3171 | if (u132->going > 1) { | |
3172 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
3173 | , u132->going); | |
3174 | return -ENODEV; | |
3175 | } else if (u132->going > 0) { | |
3176 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
3177 | return -ESHUTDOWN; | |
3178 | } else { | |
3179 | int retval = 0; | |
3180 | if (state.event == PM_EVENT_FREEZE) { | |
3181 | retval = u132_bus_suspend(hcd); | |
3182 | } else if (state.event == PM_EVENT_SUSPEND) { | |
3183 | int ports = MAX_U132_PORTS; | |
3184 | while (ports-- > 0) { | |
3185 | port_power(u132, ports, 0); | |
3186 | } | |
3187 | } | |
3188 | if (retval == 0) | |
3189 | pdev->dev.power.power_state = state; | |
3190 | return retval; | |
3191 | } | |
3192 | } | |
3193 | ||
3194 | static int u132_resume(struct platform_device *pdev) | |
3195 | { | |
3196 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | |
3197 | struct u132 *u132 = hcd_to_u132(hcd); | |
3198 | if (u132->going > 1) { | |
3199 | dev_err(&u132->platform_dev->dev, "device has been removed %d\n" | |
3200 | , u132->going); | |
3201 | return -ENODEV; | |
3202 | } else if (u132->going > 0) { | |
3203 | dev_err(&u132->platform_dev->dev, "device is being removed\n"); | |
3204 | return -ESHUTDOWN; | |
3205 | } else { | |
3206 | int retval = 0; | |
3207 | if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { | |
3208 | int ports = MAX_U132_PORTS; | |
3209 | while (ports-- > 0) { | |
3210 | port_power(u132, ports, 1); | |
3211 | } | |
3212 | retval = 0; | |
3213 | } else { | |
3214 | pdev->dev.power.power_state = PMSG_ON; | |
3215 | retval = u132_bus_resume(hcd); | |
3216 | } | |
3217 | return retval; | |
3218 | } | |
3219 | } | |
3220 | ||
3221 | #else | |
3222 | #define u132_suspend NULL | |
3223 | #define u132_resume NULL | |
3224 | #endif | |
3225 | /* | |
0779bf2d | 3226 | * this driver is loaded explicitly by ftdi_u132 |
d774efea TO |
3227 | * |
3228 | * the platform_driver struct is static because it is per type of module | |
3229 | */ | |
3230 | static struct platform_driver u132_platform_driver = { | |
3231 | .probe = u132_probe, | |
3232 | .remove = __devexit_p(u132_remove), | |
3233 | .suspend = u132_suspend, | |
3234 | .resume = u132_resume, | |
3235 | .driver = { | |
3236 | .name = (char *)hcd_name, | |
3237 | .owner = THIS_MODULE, | |
3238 | }, | |
3239 | }; | |
3240 | static int __init u132_hcd_init(void) | |
3241 | { | |
3242 | int retval; | |
3243 | INIT_LIST_HEAD(&u132_static_list); | |
3244 | u132_instances = 0; | |
3245 | u132_exiting = 0; | |
3246 | init_MUTEX(&u132_module_lock); | |
3247 | if (usb_disabled()) | |
3248 | return -ENODEV; | |
3249 | printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__, | |
3250 | __DATE__); | |
3251 | workqueue = create_singlethread_workqueue("u132"); | |
3252 | retval = platform_driver_register(&u132_platform_driver); | |
3253 | return retval; | |
3254 | } | |
3255 | ||
3256 | ||
3257 | module_init(u132_hcd_init); | |
3258 | static void __exit u132_hcd_exit(void) | |
3259 | { | |
3260 | struct u132 *u132; | |
3261 | struct u132 *temp; | |
3262 | down(&u132_module_lock); | |
3263 | u132_exiting += 1; | |
3264 | up(&u132_module_lock); | |
3265 | list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) { | |
3266 | platform_device_unregister(u132->platform_dev); | |
3267 | } platform_driver_unregister(&u132_platform_driver); | |
3268 | printk(KERN_INFO "u132-hcd driver deregistered\n"); | |
3269 | wait_event(u132_hcd_wait, u132_instances == 0); | |
3270 | flush_workqueue(workqueue); | |
3271 | destroy_workqueue(workqueue); | |
3272 | } | |
3273 | ||
3274 | ||
3275 | module_exit(u132_hcd_exit); | |
3276 | MODULE_LICENSE("GPL"); |