2 * Host Controller Driver for the Elan Digital Systems U132 adapter
4 * Copyright(C) 2006 Elan Digital Systems Limited
5 * http://www.elandigitalsystems.com
7 * Author and Maintainer - Tony Olech - Elan Digital Systems
8 * tony.olech@elandigitalsystems.com
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.
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
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.
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)
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.
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>
57 #include <asm/system.h>
58 #include <asm/byteorder.h>
59 #include "../core/hcd.h"
61 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
62 #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
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"
74 static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait
);
76 * u132_module_lock exists to protect access to global variables
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
;
84 * end of the global variables protected by u132_module_lock
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] = {
122 struct usb_device
*usb_device
;
127 u8 endp_number_in
[16];
128 u8 endp_number_out
[16];
130 #define ENDP_QUEUE_SHIFT 3
131 #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
132 #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
134 struct list_head urb_more
;
147 struct list_head endp_ring
;
148 struct u132_ring
*ring
;
149 unsigned toggle_bits
: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
;
164 struct urb
*urb_list
[ENDP_QUEUE_SIZE
];
165 struct list_head urb_more
;
166 struct delayed_work scheduler
;
173 struct u132_endp
*curr_endp
;
174 struct delayed_work scheduler
;
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
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
];
196 u32 hc_roothub_status
;
198 u32 hc_roothub_portstatus
[MAX_ROOT_PORTS
];
200 unsigned long next_statechange
;
201 struct delayed_work monitor
;
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
];
210 * these cannot be inlines because we need the structure offset!!
211 * Does anyone have a better way?????
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
)
224 u8 udev_number
= udev
->udev_number
;
225 return container_of(udev
, struct u132
, udev
[udev_number
]);
228 static inline struct u132
*hcd_to_u132(struct usb_hcd
*hcd
)
230 return (struct u132
*)(hcd
->hcd_priv
);
233 static inline struct usb_hcd
*u132_to_hcd(struct u132
*u132
)
235 return container_of((void *)u132
, struct usb_hcd
, hcd_priv
);
238 static inline void u132_disable(struct u132
*u132
)
240 u132_to_hcd(u132
)->state
= HC_STATE_HALT
;
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
)
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
);
258 down(&u132_module_lock
);
259 list_del_init(&u132
->u132_list
);
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
);
267 static inline void u132_u132_put_kref(struct u132
*u132
)
269 kref_put(&u132
->kref
, u132_hcd_delete
);
272 static inline void u132_u132_init_kref(struct u132
*u132
)
274 kref_init(&u132
->kref
);
277 static void u132_udev_delete(struct kref
*kref
)
279 struct u132_udev
*udev
= kref_to_u132_udev(kref
);
280 udev
->udev_number
= 0;
281 udev
->usb_device
= NULL
;
283 udev
->enumeration
= 0;
286 static inline void u132_udev_put_kref(struct u132
*u132
, struct u132_udev
*udev
)
288 kref_put(&udev
->kref
, u132_udev_delete
);
291 static inline void u132_udev_get_kref(struct u132
*u132
, struct u132_udev
*udev
)
293 kref_get(&udev
->kref
);
296 static inline void u132_udev_init_kref(struct u132
*u132
,
297 struct u132_udev
*udev
)
299 kref_init(&udev
->kref
);
302 static inline void u132_ring_put_kref(struct u132
*u132
, struct u132_ring
*ring
)
304 kref_put(&u132
->kref
, u132_hcd_delete
);
307 static void u132_ring_requeue_work(struct u132
*u132
, struct u132_ring
*ring
,
311 if (queue_delayed_work(workqueue
, &ring
->scheduler
, delta
))
313 } else if (queue_delayed_work(workqueue
, &ring
->scheduler
, 0))
315 kref_put(&u132
->kref
, u132_hcd_delete
);
319 static void u132_ring_queue_work(struct u132
*u132
, struct u132_ring
*ring
,
322 kref_get(&u132
->kref
);
323 u132_ring_requeue_work(u132
, ring
, delta
);
327 static void u132_ring_cancel_work(struct u132
*u132
, struct u132_ring
*ring
)
329 if (cancel_delayed_work(&ring
->scheduler
)) {
330 kref_put(&u132
->kref
, u132_hcd_delete
);
334 static void u132_endp_delete(struct kref
*kref
)
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
;
347 if (endp
== ring
->curr_endp
) {
348 if (list_empty(head
)) {
349 ring
->curr_endp
= NULL
;
352 struct u132_endp
*next_endp
= list_entry(head
->next
,
353 struct u132_endp
, endp_ring
);
354 ring
->curr_endp
= next_endp
;
359 udev
->endp_number_in
[usb_endp
] = 0;
360 u132_udev_put_kref(u132
, udev
);
363 udev
->endp_number_out
[usb_endp
] = 0;
364 u132_udev_put_kref(u132
, udev
);
366 u132
->endp
[endp_number
- 1] = NULL
;
369 u132_u132_put_kref(u132
);
372 static inline void u132_endp_put_kref(struct u132
*u132
, struct u132_endp
*endp
)
374 kref_put(&endp
->kref
, u132_endp_delete
);
377 static inline void u132_endp_get_kref(struct u132
*u132
, struct u132_endp
*endp
)
379 kref_get(&endp
->kref
);
382 static inline void u132_endp_init_kref(struct u132
*u132
,
383 struct u132_endp
*endp
)
385 kref_init(&endp
->kref
);
386 kref_get(&u132
->kref
);
389 static void u132_endp_queue_work(struct u132
*u132
, struct u132_endp
*endp
,
392 if (queue_delayed_work(workqueue
, &endp
->scheduler
, delta
))
393 kref_get(&endp
->kref
);
396 static void u132_endp_cancel_work(struct u132
*u132
, struct u132_endp
*endp
)
398 if (cancel_delayed_work(&endp
->scheduler
))
399 kref_put(&endp
->kref
, u132_endp_delete
);
402 static inline void u132_monitor_put_kref(struct u132
*u132
)
404 kref_put(&u132
->kref
, u132_hcd_delete
);
407 static void u132_monitor_queue_work(struct u132
*u132
, unsigned int delta
)
409 if (queue_delayed_work(workqueue
, &u132
->monitor
, delta
))
410 kref_get(&u132
->kref
);
413 static void u132_monitor_requeue_work(struct u132
*u132
, unsigned int delta
)
415 if (!queue_delayed_work(workqueue
, &u132
->monitor
, delta
))
416 kref_put(&u132
->kref
, u132_hcd_delete
);
419 static void u132_monitor_cancel_work(struct u132
*u132
)
421 if (cancel_delayed_work(&u132
->monitor
))
422 kref_put(&u132
->kref
, u132_hcd_delete
);
425 static int read_roothub_info(struct u132
*u132
)
429 retval
= u132_read_pcimem(u132
, revision
, &revision
);
431 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device co"
434 } else if ((revision
& 0xFF) == 0x10) {
435 } else if ((revision
& 0xFF) == 0x11) {
437 dev_err(&u132
->platform_dev
->dev
, "device revision is not valid"
438 " %08X\n", revision
);
441 retval
= u132_read_pcimem(u132
, control
, &u132
->hc_control
);
443 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device co"
447 retval
= u132_read_pcimem(u132
, roothub
.status
,
448 &u132
->hc_roothub_status
);
450 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device re"
451 "g roothub.status\n", retval
);
454 retval
= u132_read_pcimem(u132
, roothub
.a
, &u132
->hc_roothub_a
);
456 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device re"
457 "g roothub.a\n", retval
);
461 int I
= u132
->num_ports
;
464 retval
= u132_read_pcimem(u132
, roothub
.portstatus
[i
],
465 &u132
->hc_roothub_portstatus
[i
]);
467 dev_err(&u132
->platform_dev
->dev
, "error %d acc"
468 "essing device roothub.portstatus[%d]\n"
478 static void u132_hcd_monitor_work(struct work_struct
*work
)
480 struct u132
*u132
= container_of(work
, struct u132
, monitor
.work
);
481 if (u132
->going
> 1) {
482 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
484 u132_monitor_put_kref(u132
);
486 } else if (u132
->going
> 0) {
487 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
488 u132_monitor_put_kref(u132
);
492 down(&u132
->sw_lock
);
493 retval
= read_roothub_info(u132
);
495 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
500 ftdi_elan_gone_away(u132
->platform_dev
);
501 u132_monitor_put_kref(u132
);
504 u132_monitor_requeue_work(u132
, 500);
511 static void u132_hcd_giveback_urb(struct u132
*u132
, struct u132_endp
*endp
,
512 struct urb
*urb
, int status
)
514 struct u132_ring
*ring
;
516 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
517 urb
->error_count
= 0;
518 urb
->status
= status
;
520 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
521 endp
->queue_next
+= 1;
522 if (ENDP_QUEUE_SIZE
> --endp
->queue_size
) {
524 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
526 struct list_head
*next
= endp
->urb_more
.next
;
527 struct u132_urbq
*urbq
= list_entry(next
, struct u132_urbq
,
530 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] =
533 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
535 } down(&u132
->scheduler_lock
);
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
);
542 usb_hcd_giveback_urb(hcd
, urb
);
546 static void u132_hcd_forget_urb(struct u132
*u132
, struct u132_endp
*endp
,
547 struct urb
*urb
, int status
)
549 u132_endp_put_kref(u132
, endp
);
552 static void u132_hcd_abandon_urb(struct u132
*u132
, struct u132_endp
*endp
,
553 struct urb
*urb
, int status
)
556 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
557 urb
->error_count
= 0;
558 urb
->status
= status
;
560 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
561 endp
->queue_next
+= 1;
562 if (ENDP_QUEUE_SIZE
> --endp
->queue_size
) {
564 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
566 struct list_head
*next
= endp
->urb_more
.next
;
567 struct u132_urbq
*urbq
= list_entry(next
, struct u132_urbq
,
570 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] =
573 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
575 } usb_hcd_giveback_urb(hcd
, urb
);
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
))
585 return usb_ftdi_elan_edset_input(u132
->platform_dev
, ring
->number
, endp
,
586 urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
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
))
595 return usb_ftdi_elan_edset_setup(u132
->platform_dev
, ring
->number
, endp
,
596 urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
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
))
605 return usb_ftdi_elan_edset_single(u132
->platform_dev
, ring
->number
,
606 endp
, urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
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
))
615 return usb_ftdi_elan_edset_output(u132
->platform_dev
, ring
->number
,
616 endp
, urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
621 * must not LOCK sw_lock
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
)
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"
636 up(&u132
->scheduler_lock
);
637 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
639 } else if (endp
->dequeueing
) {
640 endp
->dequeueing
= 0;
641 up(&u132
->scheduler_lock
);
642 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
650 } else if (urb
->status
== -EINPROGRESS
) {
651 struct u132_ring
*ring
= endp
->ring
;
652 u8
*u
= urb
->transfer_buffer
+ urb
->actual_length
;
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,
664 if (urb
->actual_length
> 0) {
666 up(&u132
->scheduler_lock
);
667 retval
= edset_single(u132
, ring
, endp
, urb
,
668 address
, endp
->toggle_bits
,
669 u132_hcd_interrupt_recv
);
672 u132_hcd_giveback_urb(u132
, endp
, urb
,
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
);
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,
690 up(&u132
->scheduler_lock
);
691 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
694 if (condition_code
== TD_CC_NOERROR
) {
695 endp
->toggle_bits
= toggle_bits
;
696 usb_settoggle(udev
->usb_device
, endp
->usb_endp
,
698 } else if (condition_code
== TD_CC_STALL
) {
699 endp
->toggle_bits
= 0x2;
700 usb_settoggle(udev
->usb_device
, endp
->usb_endp
,
703 endp
->toggle_bits
= 0x2;
704 usb_settoggle(udev
->usb_device
, endp
->usb_endp
,
706 dev_err(&u132
->platform_dev
->dev
, "urb=%p givin"
707 "g back INTERRUPT %s\n", urb
,
708 cc_to_text
[condition_code
]);
710 up(&u132
->scheduler_lock
);
711 u132_hcd_giveback_urb(u132
, endp
, urb
,
712 cc_to_error
[condition_code
]);
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
);
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
)
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"
735 up(&u132
->scheduler_lock
);
736 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
738 } else if (endp
->dequeueing
) {
739 endp
->dequeueing
= 0;
740 up(&u132
->scheduler_lock
);
741 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
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
) {
755 up(&u132
->scheduler_lock
);
756 retval
= edset_output(u132
, ring
, endp
, urb
, address
,
757 endp
->toggle_bits
, u132_hcd_bulk_output_sent
);
760 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
763 up(&u132
->scheduler_lock
);
764 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
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
);
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
)
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"
788 up(&u132
->scheduler_lock
);
789 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
791 } else if (endp
->dequeueing
) {
792 endp
->dequeueing
= 0;
793 up(&u132
->scheduler_lock
);
794 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
802 } else if (urb
->status
== -EINPROGRESS
) {
803 struct u132_ring
*ring
= endp
->ring
;
804 u8
*u
= urb
->transfer_buffer
+ urb
->actual_length
;
810 urb
->actual_length
+= len
;
811 if ((condition_code
== TD_CC_NOERROR
) &&
812 (urb
->transfer_buffer_length
> urb
->actual_length
)) {
814 endp
->toggle_bits
= toggle_bits
;
815 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
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
);
824 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
826 } else if (condition_code
== TD_CC_NOERROR
) {
827 endp
->toggle_bits
= toggle_bits
;
828 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
830 up(&u132
->scheduler_lock
);
831 u132_hcd_giveback_urb(u132
, endp
, urb
,
832 cc_to_error
[condition_code
]);
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,
839 up(&u132
->scheduler_lock
);
840 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
842 } else if (condition_code
== TD_DATAUNDERRUN
) {
843 endp
->toggle_bits
= toggle_bits
;
844 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
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);
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
]);
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
]);
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
);
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
)
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"
889 up(&u132
->scheduler_lock
);
890 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
892 } else if (endp
->dequeueing
) {
893 endp
->dequeueing
= 0;
894 up(&u132
->scheduler_lock
);
895 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
903 } else if (urb
->status
== -EINPROGRESS
) {
904 up(&u132
->scheduler_lock
);
905 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
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
);
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
)
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"
927 up(&u132
->scheduler_lock
);
928 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
930 } else if (endp
->dequeueing
) {
931 endp
->dequeueing
= 0;
932 up(&u132
->scheduler_lock
);
933 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
941 } else if (urb
->status
== -EINPROGRESS
) {
942 struct u132_ring
*ring
= endp
->ring
;
943 u8
*u
= urb
->transfer_buffer
;
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))) {
954 up(&u132
->scheduler_lock
);
955 retval
= usb_ftdi_elan_edset_empty(u132
->platform_dev
,
956 ring
->number
, endp
, urb
, address
,
958 u132_hcd_configure_empty_sent
);
961 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
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
]);
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
],
975 u132_hcd_giveback_urb(u132
, endp
, urb
,
976 cc_to_error
[condition_code
]);
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
);
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
)
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"
998 up(&u132
->scheduler_lock
);
999 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1001 } else if (endp
->dequeueing
) {
1002 endp
->dequeueing
= 0;
1003 up(&u132
->scheduler_lock
);
1004 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
1012 } else if (urb
->status
== -EINPROGRESS
) {
1013 up(&u132
->scheduler_lock
);
1014 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
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
);
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
)
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"
1036 up(&u132
->scheduler_lock
);
1037 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1039 } else if (endp
->dequeueing
) {
1040 endp
->dequeueing
= 0;
1041 up(&u132
->scheduler_lock
);
1042 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
1050 } else if (urb
->status
== -EINPROGRESS
) {
1051 if (usb_pipein(urb
->pipe
)) {
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
,
1058 u132_hcd_configure_input_recv
);
1061 u132_hcd_giveback_urb(u132
, endp
, urb
, 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
,
1070 u132_hcd_configure_empty_recv
);
1073 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
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
);
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
)
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"
1097 up(&u132
->scheduler_lock
);
1098 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1100 } else if (endp
->dequeueing
) {
1101 endp
->dequeueing
= 0;
1102 up(&u132
->scheduler_lock
);
1103 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
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);
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
);
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
)
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"
1136 up(&u132
->scheduler_lock
);
1137 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1139 } else if (endp
->dequeueing
) {
1140 endp
->dequeueing
= 0;
1141 up(&u132
->scheduler_lock
);
1142 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
1150 } else if (urb
->status
== -EINPROGRESS
) {
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
);
1159 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
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
);
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
)
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"
1180 up(&u132
->scheduler_lock
);
1181 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1183 } else if (endp
->dequeueing
) {
1184 endp
->dequeueing
= 0;
1185 up(&u132
->scheduler_lock
);
1186 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
1194 } else if (urb
->status
== -EINPROGRESS
) {
1195 up(&u132
->scheduler_lock
);
1196 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
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
);
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
)
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"
1218 up(&u132
->scheduler_lock
);
1219 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1221 } else if (endp
->dequeueing
) {
1222 endp
->dequeueing
= 0;
1223 up(&u132
->scheduler_lock
);
1224 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
1232 } else if (urb
->status
== -EINPROGRESS
) {
1234 struct u132_ring
*ring
= endp
->ring
;
1235 u8
*u
= urb
->transfer_buffer
;
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
);
1248 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
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
);
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
)
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"
1270 up(&u132
->scheduler_lock
);
1271 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1273 } else if (endp
->dequeueing
) {
1274 endp
->dequeueing
= 0;
1275 up(&u132
->scheduler_lock
);
1276 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
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
);
1284 } else if (urb
->status
== -EINPROGRESS
) {
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
);
1293 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
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
);
1305 * this work function is only executed from the work queue
1308 static void u132_hcd_ring_work_scheduler(struct work_struct
*work
)
1310 struct u132_ring
*ring
=
1311 container_of(work
, struct u132_ring
, scheduler
.work
);
1312 struct u132
*u132
= ring
->u132
;
1313 down(&u132
->scheduler_lock
);
1315 up(&u132
->scheduler_lock
);
1316 u132_ring_put_kref(u132
, ring
);
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
);
1336 unsigned long delta
= endp
->jiffies
- jiffies
;
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
);
1350 unsigned long delta
= last_endp
->jiffies
- jiffies
;
1355 u132_ring_requeue_work(u132
, ring
, wakeup
);
1356 up(&u132
->scheduler_lock
);
1359 up(&u132
->scheduler_lock
);
1360 u132_ring_put_kref(u132
, ring
);
1364 up(&u132
->scheduler_lock
);
1365 u132_ring_put_kref(u132
, ring
);
1370 static void u132_hcd_endp_work_scheduler(struct work_struct
*work
)
1372 struct u132_ring
*ring
;
1373 struct u132_endp
*endp
=
1374 container_of(work
, struct u132_endp
, scheduler
.work
);
1375 struct u132
*u132
= endp
->u132
;
1376 down(&u132
->scheduler_lock
);
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
);
1386 } else if (endp
->active
) {
1387 up(&u132
->scheduler_lock
);
1388 u132_endp_put_kref(u132
, endp
);
1390 } else if (ring
->in_use
) {
1391 up(&u132
->scheduler_lock
);
1392 u132_endp_put_kref(u132
, endp
);
1394 } else if (endp
->queue_next
== endp
->queue_last
) {
1395 up(&u132
->scheduler_lock
);
1396 u132_endp_put_kref(u132
, endp
);
1398 } else if (endp
->pipetype
== PIPE_INTERRUPT
) {
1399 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1401 up(&u132
->scheduler_lock
);
1402 u132_endp_put_kref(u132
, endp
);
1406 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1409 ring
->curr_endp
= endp
;
1411 up(&u132
->scheduler_lock
);
1412 retval
= edset_single(u132
, ring
, endp
, urb
, address
,
1413 endp
->toggle_bits
, u132_hcd_interrupt_recv
);
1416 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1419 } else if (endp
->pipetype
== PIPE_CONTROL
) {
1420 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1422 up(&u132
->scheduler_lock
);
1423 u132_endp_put_kref(u132
, endp
);
1425 } else if (address
== 0) {
1427 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1430 ring
->curr_endp
= endp
;
1432 up(&u132
->scheduler_lock
);
1433 retval
= edset_setup(u132
, ring
, endp
, urb
, address
,
1434 0x2, u132_hcd_initial_setup_sent
);
1437 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1439 } else if (endp
->usb_addr
== 0) {
1441 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1444 ring
->curr_endp
= endp
;
1446 up(&u132
->scheduler_lock
);
1447 retval
= edset_setup(u132
, ring
, endp
, urb
, 0, 0x2,
1448 u132_hcd_enumeration_address_sent
);
1451 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1455 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1456 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1459 ring
->curr_endp
= endp
;
1461 up(&u132
->scheduler_lock
);
1462 retval
= edset_setup(u132
, ring
, endp
, urb
, address
,
1463 0x2, u132_hcd_configure_setup_sent
);
1466 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1471 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1473 up(&u132
->scheduler_lock
);
1474 u132_endp_put_kref(u132
, endp
);
1478 struct urb
*urb
= endp
->urb_list
[
1479 ENDP_QUEUE_MASK
& endp
->queue_next
];
1481 ring
->curr_endp
= endp
;
1483 up(&u132
->scheduler_lock
);
1484 retval
= edset_input(u132
, ring
, endp
, urb
,
1485 address
, endp
->toggle_bits
,
1486 u132_hcd_bulk_input_recv
);
1489 u132_hcd_giveback_urb(u132
, endp
, urb
,
1493 } else { /* output pipe */
1494 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1496 up(&u132
->scheduler_lock
);
1497 u132_endp_put_kref(u132
, endp
);
1501 struct urb
*urb
= endp
->urb_list
[
1502 ENDP_QUEUE_MASK
& endp
->queue_next
];
1504 ring
->curr_endp
= endp
;
1506 up(&u132
->scheduler_lock
);
1507 retval
= edset_output(u132
, ring
, endp
, urb
,
1508 address
, endp
->toggle_bits
,
1509 u132_hcd_bulk_output_sent
);
1512 u132_hcd_giveback_urb(u132
, endp
, urb
,
1520 static void port_power(struct u132
*u132
, int pn
, int is_on
)
1522 u132
->port
[pn
].power
= is_on
;
1525 static void u132_power(struct u132
*u132
, int is_on
)
1527 struct usb_hcd
*hcd
= u132_to_hcd(u132
)
1528 ; /* hub is inactive unless the port is powered */
1533 hcd
->self
.controller
->power
.power_state
= PMSG_ON
;
1536 hcd
->state
= HC_STATE_HALT
;
1537 hcd
->self
.controller
->power
.power_state
= PMSG_SUSPEND
;
1541 static int u132_periodic_reinit(struct u132
*u132
)
1544 u32 fi
= u132
->hc_fminterval
& 0x03fff;
1547 retval
= u132_read_pcimem(u132
, fminterval
, &fminterval
);
1550 fit
= fminterval
& FIT
;
1551 retval
= u132_write_pcimem(u132
, fminterval
,
1552 (fit
^ FIT
) | u132
->hc_fminterval
);
1555 retval
= u132_write_pcimem(u132
, periodicstart
,
1556 ((9 *fi
) / 10) & 0x3fff);
1562 static char *hcfs2string(int state
)
1565 case OHCI_USB_RESET
:
1567 case OHCI_USB_RESUME
:
1570 return "operational";
1571 case OHCI_USB_SUSPEND
:
1577 static int u132_usb_reset(struct u132
*u132
)
1580 retval
= u132_read_pcimem(u132
, control
, &u132
->hc_control
);
1583 u132
->hc_control
&= OHCI_CTRL_RWC
;
1584 retval
= u132_write_pcimem(u132
, control
, u132
->hc_control
);
1590 static int u132_init(struct u132
*u132
)
1595 u132
->next_statechange
=
1596 jiffies
; /* SMM owns the HC? not for long! */ {
1598 retval
= u132_read_pcimem(u132
, control
, &control
);
1601 if (control
& OHCI_CTRL_IR
) {
1603 retval
= u132_write_pcimem(u132
, intrenable
,
1607 retval
= u132_write_pcimem_byte(u132
, cmdstatus
,
1612 retval
= u132_read_pcimem(u132
, control
,
1617 if (control
& OHCI_CTRL_IR
) {
1620 dev_err(&u132
->platform_dev
->dev
, "USB "
1621 "HC takeover failed!(BIOS/SMM b"
1622 "ug) control=%08X\n", control
);
1627 u132_usb_reset(u132
);
1630 retval
= u132_write_pcimem(u132
, intrdisable
, OHCI_INTR_MIE
);
1633 retval
= u132_read_pcimem(u132
, control
, &control
);
1636 if (u132
->num_ports
== 0) {
1638 retval
= u132_read_pcimem(u132
, roothub
.a
, &rh_a
);
1641 u132
->num_ports
= rh_a
& RH_A_NDP
;
1642 retval
= read_roothub_info(u132
);
1646 if (u132
->num_ports
> MAX_U132_PORTS
) {
1653 /* Start an OHCI controller, set the BUS operational
1654 * resets USB and controller
1657 static int u132_run(struct u132
*u132
)
1666 int mask
= OHCI_INTR_INIT
;
1667 int first
= u132
->hc_fminterval
== 0;
1669 int reset_timeout
= 30; /* ... allow extra time */
1673 retval
= u132_read_pcimem(u132
, fminterval
, &temp
);
1676 u132
->hc_fminterval
= temp
& 0x3fff;
1677 if (u132
->hc_fminterval
!= FI
) {
1679 u132
->hc_fminterval
|= FSMP(u132
->hc_fminterval
) << 16;
1681 retval
= u132_read_pcimem(u132
, control
, &u132
->hc_control
);
1684 dev_info(&u132
->platform_dev
->dev
, "resetting from state '%s', control "
1685 "= %08X\n", hcfs2string(u132
->hc_control
& OHCI_CTRL_HCFS
),
1687 switch (u132
->hc_control
& OHCI_CTRL_HCFS
) {
1691 case OHCI_USB_SUSPEND
:
1692 case OHCI_USB_RESUME
:
1693 u132
->hc_control
&= OHCI_CTRL_RWC
;
1694 u132
->hc_control
|= OHCI_USB_RESUME
;
1698 u132
->hc_control
&= OHCI_CTRL_RWC
;
1699 u132
->hc_control
|= OHCI_USB_RESET
;
1703 retval
= u132_write_pcimem(u132
, control
, u132
->hc_control
);
1706 retval
= u132_read_pcimem(u132
, control
, &control
);
1710 retval
= u132_read_pcimem(u132
, roothub
.a
, &roothub_a
);
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
);
1722 retval
= u132_read_pcimem(u132
, control
, &control
);
1725 retry
:retval
= u132_read_pcimem(u132
, cmdstatus
, &status
);
1728 retval
= u132_write_pcimem_byte(u132
, cmdstatus
, OHCI_HCR
);
1732 retval
= u132_read_pcimem(u132
, cmdstatus
, &status
);
1735 if (0 != (status
& OHCI_HCR
)) {
1736 if (--reset_timeout
== 0) {
1737 dev_err(&u132
->platform_dev
->dev
, "USB HC reset"
1746 if (u132
->flags
& OHCI_QUIRK_INITRESET
) {
1747 retval
= u132_write_pcimem(u132
, control
, u132
->hc_control
);
1750 retval
= u132_read_pcimem(u132
, control
, &control
);
1754 retval
= u132_write_pcimem(u132
, ed_controlhead
, 0x00000000);
1757 retval
= u132_write_pcimem(u132
, ed_bulkhead
, 0x11000000);
1760 retval
= u132_write_pcimem(u132
, hcca
, 0x00000000);
1763 retval
= u132_periodic_reinit(u132
);
1766 retval
= u132_read_pcimem(u132
, fminterval
, &fminterval
);
1769 retval
= u132_read_pcimem(u132
, periodicstart
, &periodicstart
);
1772 if (0 == (fminterval
& 0x3fff0000) || 0 == periodicstart
) {
1773 if (!(u132
->flags
& OHCI_QUIRK_INITRESET
)) {
1774 u132
->flags
|= OHCI_QUIRK_INITRESET
;
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
);
1785 retval
= u132_write_pcimem_byte(u132
, cmdstatus
, OHCI_BLF
);
1788 retval
= u132_read_pcimem(u132
, cmdstatus
, &cmdstatus
);
1791 retval
= u132_read_pcimem(u132
, control
, &control
);
1794 u132_to_hcd(u132
)->state
= HC_STATE_RUNNING
;
1795 retval
= u132_write_pcimem(u132
, roothub
.status
, RH_HS_DRWE
);
1798 retval
= u132_write_pcimem(u132
, intrstatus
, mask
);
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
|
1806 return retval
; /* handle root hub init quirks ... */
1807 retval
= u132_read_pcimem(u132
, roothub
.a
, &roothub_a
);
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
);
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
);
1823 retval
= u132_write_pcimem(u132
, roothub
.status
, RH_HS_LPSC
);
1826 retval
= u132_write_pcimem(u132
, roothub
.b
,
1827 (roothub_a
& RH_A_NPS
) ? 0 : RH_B_PPCM
);
1830 retval
= u132_read_pcimem(u132
, control
, &control
);
1833 mdelay((roothub_a
>> 23) & 0x1fe);
1834 u132_to_hcd(u132
)->state
= HC_STATE_RUNNING
;
1838 static void u132_hcd_stop(struct usb_hcd
*hcd
)
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"
1844 } else if (u132
->going
> 0) {
1845 dev_err(&u132
->platform_dev
->dev
, "device hcd=%p is being remov"
1848 down(&u132
->sw_lock
);
1850 u132_power(u132
, 0);
1855 static int u132_hcd_start(struct usb_hcd
*hcd
)
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"
1862 } else if (u132
->going
> 0) {
1863 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
1865 } else if (hcd
->self
.controller
) {
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
);
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
);
1891 dev_err(&u132
->platform_dev
->dev
, "platform_device missing\n");
1896 static int u132_hcd_reset(struct usb_hcd
*hcd
)
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"
1903 } else if (u132
->going
> 0) {
1904 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
1908 down(&u132
->sw_lock
);
1909 retval
= u132_init(u132
);
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
,
1924 struct u132_ring
*ring
;
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
);
1932 INIT_DELAYED_WORK(&endp
->scheduler
, u132_hcd_endp_work_scheduler
);
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
);
1939 INIT_LIST_HEAD(&endp
->endp_ring
);
1940 ring
->curr_endp
= endp
;
1943 endp
->dequeueing
= 0;
1944 endp
->edset_flush
= 0;
1947 endp
->endp_number
= endp_number
;
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);
1957 udev
->endp_number_in
[usb_endp
] = endp_number
;
1958 u132_udev_get_kref(u132
, udev
);
1960 endp
->toggle_bits
= 0x2;
1961 usb_settoggle(udev
->usb_device
, usb_endp
, 1, 0);
1964 udev
->endp_number_out
[usb_endp
] = endp_number
;
1965 u132_udev_get_kref(u132
, udev
);
1968 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
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
));
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
)
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
;
1994 struct u132_urbq
*urbq
= kmalloc(sizeof(struct u132_urbq
),
1997 endp
->queue_size
-= 1;
2000 list_add_tail(&urbq
->urb_more
, &endp
->urb_more
);
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
,
2013 struct u132_ring
*ring
;
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
);
2021 INIT_DELAYED_WORK(&endp
->scheduler
, u132_hcd_endp_work_scheduler
);
2022 spin_lock_init(&endp
->queue_lock
.slock
);
2023 INIT_LIST_HEAD(&endp
->urb_more
);
2024 endp
->dequeueing
= 0;
2025 endp
->edset_flush
= 0;
2028 endp
->endp_number
= endp_number
;
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);
2039 udev
->endp_number_in
[usb_endp
] = endp_number
;
2040 u132_udev_get_kref(u132
, udev
);
2042 endp
->toggle_bits
= 0x2;
2043 usb_settoggle(udev
->usb_device
, usb_endp
, 1, 0);
2047 udev
->endp_number_out
[usb_endp
] = endp_number
;
2048 u132_udev_get_kref(u132
, udev
);
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
);
2054 INIT_LIST_HEAD(&endp
->endp_ring
);
2055 ring
->curr_endp
= endp
;
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);
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
)
2078 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2079 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
2081 struct u132_urbq
*urbq
= kmalloc(sizeof(struct u132_urbq
),
2084 endp
->queue_size
-= 1;
2087 list_add_tail(&urbq
->urb_more
, &endp
->urb_more
);
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
,
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
);
2106 INIT_DELAYED_WORK(&endp
->scheduler
, u132_hcd_endp_work_scheduler
);
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
);
2113 INIT_LIST_HEAD(&endp
->endp_ring
);
2114 ring
->curr_endp
= endp
;
2117 endp
->dequeueing
= 0;
2118 endp
->edset_flush
= 0;
2121 endp
->endp_number
= endp_number
;
2124 u132_endp_init_kref(u132
, endp
);
2125 u132_endp_get_kref(u132
, endp
);
2126 if (usb_addr
== 0) {
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
;
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
;
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);
2149 } else { /*(usb_addr > 0) */
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
;
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
;
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);
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
,
2180 if (usb_addr
== 0) {
2181 if (usb_pipein(urb
->pipe
)) {
2183 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2184 endp
->urb_list
[ENDP_QUEUE_MASK
&
2185 endp
->queue_last
++] = urb
;
2187 struct u132_urbq
*urbq
=
2188 kmalloc(sizeof(struct u132_urbq
),
2191 endp
->queue_size
-= 1;
2194 list_add_tail(&urbq
->urb_more
,
2200 } else { /* usb_pipeout(urb->pipe) */
2201 struct u132_addr
*addr
= &u132
->addr
[usb_dev
->devnum
];
2202 int I
= MAX_U132_UDEVS
;
2205 struct u132_udev
*udev
= &u132
->udev
[++i
];
2206 if (udev
->usb_device
) {
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
] =
2217 u132_udev_get_kref(u132
, udev
);
2218 udev
->endp_number_out
[usb_endp
] =
2220 udev
->usb_device
= usb_dev
;
2221 ((u8
*) (urb
->setup_packet
))[2] =
2223 u132_udev_get_kref(u132
, udev
);
2228 dev_err(&u132
->platform_dev
->dev
, "run out of d"
2233 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2234 endp
->urb_list
[ENDP_QUEUE_MASK
&
2235 endp
->queue_last
++] = urb
;
2237 struct u132_urbq
*urbq
=
2238 kmalloc(sizeof(struct u132_urbq
),
2241 endp
->queue_size
-= 1;
2244 list_add_tail(&urbq
->urb_more
,
2251 } else { /*(usb_addr > 0) */
2252 u8 address
= u132
->addr
[usb_addr
].address
;
2253 struct u132_udev
*udev
= &u132
->udev
[address
];
2255 if (udev
->enumeration
== 2) {
2257 udev
->enumeration
= 2;
2258 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2259 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] =
2262 struct u132_urbq
*urbq
=
2263 kmalloc(sizeof(struct u132_urbq
), GFP_ATOMIC
);
2265 endp
->queue_size
-= 1;
2268 list_add_tail(&urbq
->urb_more
, &endp
->urb_more
);
2276 static int u132_urb_enqueue(struct usb_hcd
*hcd
, struct usb_host_endpoint
*hep
,
2277 struct urb
*urb
, gfp_t mem_flags
)
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"
2287 if (u132
->going
> 1) {
2288 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
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
);
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;
2307 spin_lock_irqsave(&endp
->queue_lock
.slock
,
2309 retval
= queue_int_on_old_endpoint(u132
, udev
,
2310 hep
, urb
, usb_dev
, endp
, usb_addr
,
2312 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2317 u132_endp_queue_work(u132
, endp
,
2318 msecs_to_jiffies(urb
->interval
))
2322 } else if (u132
->num_endpoints
== MAX_U132_ENDPS
) {
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
);
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");
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;
2341 spin_lock_irqsave(&endp
->queue_lock
.slock
,
2343 retval
= queue_bulk_on_old_endpoint(u132
, udev
,
2344 hep
, urb
, usb_dev
, endp
, usb_addr
,
2346 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2351 u132_endp_queue_work(u132
, endp
, 0);
2354 } else if (u132
->num_endpoints
== MAX_U132_ENDPS
) {
2357 return create_endpoint_and_queue_bulk(u132
,
2358 udev
, hep
, urb
, usb_dev
, usb_addr
,
2359 usb_endp
, address
, mem_flags
);
2361 struct u132_endp
*endp
= hep
->hcpriv
;
2363 u8
*b
= urb
->setup_packet
;
2365 char data
[30 *3 + 4];
2367 int m
= (sizeof(data
) - 1) / 3;
2370 while (urb_size
-- > 0) {
2372 } else if (i
++ < m
) {
2373 int w
= sprintf(d
, " %02X", *b
++);
2377 d
+= sprintf(d
, " ..");
2382 spin_lock_irqsave(&endp
->queue_lock
.slock
,
2384 retval
= queue_control_on_old_endpoint(u132
,
2385 hep
, urb
, usb_dev
, endp
, usb_addr
,
2387 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2392 u132_endp_queue_work(u132
, endp
, 0);
2395 } else if (u132
->num_endpoints
== MAX_U132_ENDPS
) {
2398 return create_endpoint_and_queue_control(u132
,
2399 hep
, urb
, usb_dev
, usb_addr
, usb_endp
,
2405 static int dequeue_from_overflow_chain(struct u132
*u132
,
2406 struct u132_endp
*endp
, struct urb
*urb
)
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
,
2413 if (urbq
->urb
== urb
) {
2414 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
2416 endp
->queue_size
-= 1;
2417 urb
->error_count
= 0;
2419 usb_hcd_giveback_urb(hcd
, urb
);
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
);
2433 static int u132_endp_urb_dequeue(struct u132
*u132
, struct u132_endp
*endp
,
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
);
2447 if (urb
== endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_next
]) {
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
);
2456 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2457 u132_hcd_abandon_urb(u132
, endp
, urb
, urb
->status
);
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
&
2468 urb_slot
= &endp
->urb_list
[ENDP_QUEUE_MASK
&
2474 while (++queue_list
< ENDP_QUEUE_SIZE
&& --queue_size
> 0) {
2475 *urb_slot
= endp
->urb_list
[ENDP_QUEUE_MASK
&
2477 urb_slot
= &endp
->urb_list
[ENDP_QUEUE_MASK
&
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
,
2487 struct list_head
*next
= endp
->urb_more
.next
;
2488 struct u132_urbq
*urbq
= list_entry(next
,
2489 struct u132_urbq
, urb_more
);
2491 *urb_slot
= urbq
->urb
;
2492 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2495 } urb
->error_count
= 0;
2497 usb_hcd_giveback_urb(hcd
, urb
);
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
);
2511 int retval
= dequeue_from_overflow_chain(u132
, endp
,
2513 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2519 static int u132_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
)
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"
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
);
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
);
2543 static void u132_endpoint_disable(struct usb_hcd
*hcd
,
2544 struct usb_host_endpoint
*hep
)
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"
2551 struct u132_endp
*endp
= hep
->hcpriv
;
2553 u132_endp_put_kref(u132
, endp
);
2557 static int u132_get_frame(struct usb_hcd
*hcd
)
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"
2564 } else if (u132
->going
> 0) {
2565 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2569 dev_err(&u132
->platform_dev
->dev
, "TODO: u132_get_frame\n");
2575 static int u132_roothub_descriptor(struct u132
*u132
,
2576 struct usb_hub_descriptor
*desc
)
2582 retval
= u132_read_pcimem(u132
, roothub
.a
, &rh_a
);
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
;
2592 if (rh_a
& RH_A_NPS
)
2594 if (rh_a
& RH_A_PSM
)
2596 if (rh_a
& RH_A_NOCP
) {
2598 } else if (rh_a
& RH_A_OCPM
)
2600 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
2601 retval
= u132_read_pcimem(u132
, roothub
.b
, &rh_b
);
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;
2610 desc
->bitmap
[1] = 0xff;
2614 static int u132_roothub_status(struct u132
*u132
, __le32
*desc
)
2617 int ret_status
= u132_read_pcimem(u132
, roothub
.status
, &rh_status
);
2618 *desc
= cpu_to_le32(rh_status
);
2622 static int u132_roothub_portstatus(struct u132
*u132
, __le32
*desc
, u16 wIndex
)
2624 if (wIndex
== 0 || wIndex
> u132
->num_ports
) {
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
);
2636 return ret_portstatus
;
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
)
2652 retval
= u132_read_pcimem(u132
, fmnumber
, &fmnumber
);
2656 reset_done
= now
+ PORT_RESET_MSEC
;
2660 retval
= u132_read_pcimem(u132
,
2661 roothub
.portstatus
[port_index
], &portstat
);
2664 if (RH_PS_PRS
& portstat
) {
2668 } while (tick_before(now
, reset_done
));
2669 if (RH_PS_PRS
& portstat
)
2671 if (RH_PS_CCS
& portstat
) {
2672 if (RH_PS_PRSC
& portstat
) {
2673 retval
= u132_write_pcimem(u132
,
2674 roothub
.portstatus
[port_index
],
2680 break; /* start the next reset,
2681 sleep till it's probably done */
2682 retval
= u132_write_pcimem(u132
, roothub
.portstatus
[port_index
],
2686 msleep(PORT_RESET_HW_MSEC
);
2687 retval
= u132_read_pcimem(u132
, fmnumber
, &fmnumber
);
2691 } while (tick_before(now
, reset_done
));
2695 static int u132_roothub_setportfeature(struct u132
*u132
, u16 wValue
,
2698 if (wIndex
== 0 || wIndex
> u132
->num_ports
) {
2702 int port_index
= wIndex
- 1;
2703 struct u132_port
*port
= &u132
->port
[port_index
];
2704 port
->Status
&= ~(1 << wValue
);
2706 case USB_PORT_FEAT_SUSPEND
:
2707 retval
= u132_write_pcimem(u132
,
2708 roothub
.portstatus
[port_index
], RH_PS_PSS
);
2712 case USB_PORT_FEAT_POWER
:
2713 retval
= u132_write_pcimem(u132
,
2714 roothub
.portstatus
[port_index
], RH_PS_PPS
);
2718 case USB_PORT_FEAT_RESET
:
2719 retval
= u132_roothub_portreset(u132
, port_index
);
2729 static int u132_roothub_clearportfeature(struct u132
*u132
, u16 wValue
,
2732 if (wIndex
== 0 || wIndex
> u132
->num_ports
) {
2735 int port_index
= wIndex
- 1;
2738 struct u132_port
*port
= &u132
->port
[port_index
];
2739 port
->Status
&= ~(1 << wValue
);
2741 case USB_PORT_FEAT_ENABLE
:
2744 case USB_PORT_FEAT_C_ENABLE
:
2747 case USB_PORT_FEAT_SUSPEND
:
2749 if ((u132
->hc_control
& OHCI_CTRL_HCFS
)
2751 dev_err(&u132
->platform_dev
->dev
, "TODO resume_"
2755 case USB_PORT_FEAT_C_SUSPEND
:
2758 case USB_PORT_FEAT_POWER
:
2761 case USB_PORT_FEAT_C_CONNECTION
:
2764 case USB_PORT_FEAT_C_OVER_CURRENT
:
2767 case USB_PORT_FEAT_C_RESET
:
2773 retval
= u132_write_pcimem(u132
, roothub
.portstatus
[port_index
],
2782 /* the virtual root hub timer IRQ checks for hub status*/
2783 static int u132_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
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
);
2790 } else if (u132
->going
> 0) {
2791 dev_err(&u132
->platform_dev
->dev
, "device hcd=%p is being remov"
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
);
2805 if (u132
->hc_roothub_status
& (RH_HS_LPSC
| RH_HS_OCIC
)) {
2806 buf
[0] = changed
= 1;
2809 if (u132
->num_ports
> 7) {
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
|
2819 buf
[0] |= 1 << (i
+ 1);
2821 buf
[1] |= 1 << (i
- 7);
2824 if (!(u132
->hc_roothub_portstatus
[i
] & RH_PS_CCS
)) {
2827 if ((u132
->hc_roothub_portstatus
[i
] & RH_PS_PSS
)) {
2831 done
:return changed
? length
: 0;
2835 static int u132_hub_control(struct usb_hcd
*hcd
, u16 typeReq
, u16 wValue
,
2836 u16 wIndex
, char *buf
, u16 wLength
)
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"
2843 } else if (u132
->going
> 0) {
2844 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2848 down(&u132
->sw_lock
);
2850 case ClearHubFeature
:
2852 case C_HUB_OVER_CURRENT
:
2853 case C_HUB_LOCAL_POWER
:
2861 case C_HUB_OVER_CURRENT
:
2862 case C_HUB_LOCAL_POWER
:
2868 case ClearPortFeature
:{
2869 retval
= u132_roothub_clearportfeature(u132
,
2875 case GetHubDescriptor
:{
2876 retval
= u132_roothub_descriptor(u132
,
2877 (struct usb_hub_descriptor
*)buf
);
2883 retval
= u132_roothub_status(u132
,
2889 case GetPortStatus
:{
2890 retval
= u132_roothub_portstatus(u132
,
2891 (__le32
*) buf
, wIndex
);
2896 case SetPortFeature
:{
2897 retval
= u132_roothub_setportfeature(u132
,
2905 error
:u132_disable(u132
);
2908 stall
:retval
= -EPIPE
;
2916 static int u132_start_port_reset(struct usb_hcd
*hcd
, unsigned port_num
)
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"
2923 } else if (u132
->going
> 0) {
2924 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2930 static void u132_hub_irq_enable(struct usb_hcd
*hcd
)
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"
2936 } else if (u132
->going
> 0)
2937 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2942 static int u132_hcd_suspend(struct usb_hcd
*hcd
, pm_message_t message
)
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"
2949 } else if (u132
->going
> 0) {
2950 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2956 static int u132_hcd_resume(struct usb_hcd
*hcd
)
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"
2963 } else if (u132
->going
> 0) {
2964 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2970 static int u132_bus_suspend(struct usb_hcd
*hcd
)
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"
2977 } else if (u132
->going
> 0) {
2978 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2984 static int u132_bus_resume(struct usb_hcd
*hcd
)
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"
2991 } else if (u132
->going
> 0) {
2992 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2999 #define u132_hcd_suspend NULL
3000 #define u132_hcd_resume NULL
3001 #define u132_bus_suspend NULL
3002 #define u132_bus_resume NULL
3004 static struct hc_driver u132_hc_driver
= {
3005 .description
= hcd_name
,
3006 .hcd_priv_size
= sizeof(struct u132
),
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
,
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
3030 * device and asynchronously call usb_remove_hcd()
3032 static int __devexit
u132_remove(struct platform_device
*pdev
)
3034 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
3036 struct u132
*u132
= hcd_to_u132(hcd
);
3038 if (u132
->going
++ > 1) {
3041 int rings
= MAX_U132_RINGS
;
3042 int endps
= MAX_U132_ENDPS
;
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
];
3052 u132_endp_cancel_work(u132
, endp
);
3055 printk(KERN_INFO
"removing device u132.%d\n",
3056 u132
->sequence_num
);
3058 usb_remove_hcd(hcd
);
3059 u132_u132_put_kref(u132
);
3066 static void u132_initialise(struct u132
*u132
, struct platform_device
*pdev
)
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
;
3077 init_MUTEX(&u132
->sw_lock
);
3078 init_MUTEX(&u132
->scheduler_lock
);
3079 while (rings
-- > 0) {
3080 struct u132_ring
*ring
= &u132
->ring
[rings
];
3082 ring
->number
= rings
+ 1;
3084 ring
->curr_endp
= NULL
;
3085 INIT_DELAYED_WORK(&ring
->scheduler
,
3086 u132_hcd_ring_work_scheduler
);
3087 } down(&u132
->sw_lock
);
3088 INIT_DELAYED_WORK(&u132
->monitor
, u132_hcd_monitor_work
);
3089 while (ports
-- > 0) {
3090 struct u132_port
*port
= &u132
->port
[ports
];
3096 } while (addrs
-- > 0) {
3097 struct u132_addr
*addr
= &u132
->addr
[addrs
];
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;
3106 udev
->portnumber
= 0;
3108 udev
->endp_number_in
[i
] = 0;
3111 udev
->endp_number_out
[o
] = 0;
3114 while (endps
-- > 0) {
3115 u132
->endp
[endps
] = NULL
;
3121 static int __devinit
u132_probe(struct platform_device
*pdev
)
3123 struct usb_hcd
*hcd
;
3125 if (u132_exiting
> 0) {
3127 } /* refuse to confuse usbcore */
3128 if (pdev
->dev
.dma_mask
) {
3131 hcd
= usb_create_hcd(&u132_hc_driver
, &pdev
->dev
, pdev
->dev
.bus_id
);
3133 printk(KERN_ERR
"failed to create the usb hcd struct for U132\n"
3135 ftdi_elan_gone_away(pdev
);
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);
3150 dev_err(&u132
->platform_dev
->dev
, "init error %d\n",
3152 u132_u132_put_kref(u132
);
3155 u132_monitor_queue_work(u132
, 100);
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.
3167 static int u132_suspend(struct platform_device
*pdev
, pm_message_t state
)
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"
3175 } else if (u132
->going
> 0) {
3176 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
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);
3189 pdev
->dev
.power
.power_state
= state
;
3194 static int u132_resume(struct platform_device
*pdev
)
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"
3202 } else if (u132
->going
> 0) {
3203 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
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);
3214 pdev
->dev
.power
.power_state
= PMSG_ON
;
3215 retval
= u132_bus_resume(hcd
);
3222 #define u132_suspend NULL
3223 #define u132_resume NULL
3226 * this driver is loaded explicitly by ftdi_u132
3228 * the platform_driver struct is static because it is per type of module
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
,
3236 .name
= (char *)hcd_name
,
3237 .owner
= THIS_MODULE
,
3240 static int __init
u132_hcd_init(void)
3243 INIT_LIST_HEAD(&u132_static_list
);
3246 init_MUTEX(&u132_module_lock
);
3249 printk(KERN_INFO
"driver %s built at %s on %s\n", hcd_name
, __TIME__
,
3251 workqueue
= create_singlethread_workqueue("u132");
3252 retval
= platform_driver_register(&u132_platform_driver
);
3257 module_init(u132_hcd_init
);
3258 static void __exit
u132_hcd_exit(void)
3262 down(&u132_module_lock
);
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
);
3275 module_exit(u132_hcd_exit
);
3276 MODULE_LICENSE("GPL");