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/pci_ids.h>
44 #include <linux/sched.h>
45 #include <linux/slab.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 <linux/mutex.h>
58 #include <asm/system.h>
59 #include <asm/byteorder.h>
60 #include "../core/hcd.h"
62 /* FIXME ohci.h is ONLY for internal use by the OHCI driver.
63 * If you're going to try stuff like this, you need to split
64 * out shareable stuff (register declarations?) into its own
65 * file, maybe name <linux/usb/ohci.h>
69 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
70 #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
72 MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
73 MODULE_DESCRIPTION("U132 USB Host Controller Driver");
74 MODULE_LICENSE("GPL");
75 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
76 INT_MODULE_PARM(testing, 0);
77 /* Some boards misreport power switching/overcurrent*/
78 static int distrust_firmware = 1;
79 module_param(distrust_firmware, bool, 0);
80 MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
82 static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
84 * u132_module_lock exists to protect access to global variables
87 static struct mutex u132_module_lock;
88 static int u132_exiting = 0;
89 static int u132_instances = 0;
90 static struct list_head u132_static_list;
92 * end of the global variables protected by u132_module_lock
94 static struct workqueue_struct *workqueue;
95 #define MAX_U132_PORTS 7
96 #define MAX_U132_ADDRS 128
97 #define MAX_U132_UDEVS 4
98 #define MAX_U132_ENDPS 100
99 #define MAX_U132_RINGS 4
100 static const char *cc_to_text[16] = {
130 struct usb_device *usb_device;
135 u8 endp_number_in[16];
136 u8 endp_number_out[16];
138 #define ENDP_QUEUE_SHIFT 3
139 #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
140 #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
142 struct list_head urb_more;
155 struct list_head endp_ring;
156 struct u132_ring *ring;
157 unsigned toggle_bits:2;
163 unsigned dequeueing:1;
164 unsigned edset_flush:1;
165 unsigned spare_bits:14;
166 unsigned long jiffies;
167 struct usb_host_endpoint *hep;
168 struct u132_spin queue_lock;
172 struct urb *urb_list[ENDP_QUEUE_SIZE];
173 struct list_head urb_more;
174 struct delayed_work scheduler;
181 struct u132_endp *curr_endp;
182 struct delayed_work scheduler;
186 struct list_head u132_list;
187 struct semaphore sw_lock;
188 struct semaphore scheduler_lock;
189 struct u132_platform_data *board;
190 struct platform_device *platform_dev;
191 struct u132_ring ring[MAX_U132_RINGS];
199 u32 hc_roothub_status;
201 u32 hc_roothub_portstatus[MAX_ROOT_PORTS];
203 unsigned long next_statechange;
204 struct delayed_work monitor;
206 struct u132_addr addr[MAX_U132_ADDRS];
207 struct u132_udev udev[MAX_U132_UDEVS];
208 struct u132_port port[MAX_U132_PORTS];
209 struct u132_endp *endp[MAX_U132_ENDPS];
213 * these cannot be inlines because we need the structure offset!!
214 * Does anyone have a better way?????
216 #define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
217 offsetof(struct ohci_regs, member), 0, data);
218 #define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
219 offsetof(struct ohci_regs, member), 0, data);
220 #define u132_read_pcimem(u132, member, data) \
221 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
222 ohci_regs, member), 0, data);
223 #define u132_write_pcimem(u132, member, data) \
224 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
225 ohci_regs, member), 0, data);
226 static inline struct u132 *udev_to_u132(struct u132_udev *udev)
228 u8 udev_number = udev->udev_number;
229 return container_of(udev, struct u132, udev[udev_number]);
232 static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd)
234 return (struct u132 *)(hcd->hcd_priv);
237 static inline struct usb_hcd *u132_to_hcd(struct u132 *u132)
239 return container_of((void *)u132, struct usb_hcd, hcd_priv);
242 static inline void u132_disable(struct u132 *u132)
244 u132_to_hcd(u132)->state = HC_STATE_HALT;
248 #define kref_to_u132(d) container_of(d, struct u132, kref)
249 #define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref)
250 #define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref)
251 #include "../misc/usb_u132.h"
252 static const char hcd_name[] = "u132_hcd";
253 #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
254 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
255 USB_PORT_STAT_C_RESET) << 16)
256 static void u132_hcd_delete(struct kref *kref)
258 struct u132 *u132 = kref_to_u132(kref);
259 struct platform_device *pdev = u132->platform_dev;
260 struct usb_hcd *hcd = u132_to_hcd(u132);
262 mutex_lock(&u132_module_lock);
263 list_del_init(&u132->u132_list);
265 mutex_unlock(&u132_module_lock);
266 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
267 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
271 static inline void u132_u132_put_kref(struct u132 *u132)
273 kref_put(&u132->kref, u132_hcd_delete);
276 static inline void u132_u132_init_kref(struct u132 *u132)
278 kref_init(&u132->kref);
281 static void u132_udev_delete(struct kref *kref)
283 struct u132_udev *udev = kref_to_u132_udev(kref);
284 udev->udev_number = 0;
285 udev->usb_device = NULL;
287 udev->enumeration = 0;
290 static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev)
292 kref_put(&udev->kref, u132_udev_delete);
295 static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev)
297 kref_get(&udev->kref);
300 static inline void u132_udev_init_kref(struct u132 *u132,
301 struct u132_udev *udev)
303 kref_init(&udev->kref);
306 static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring)
308 kref_put(&u132->kref, u132_hcd_delete);
311 static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring,
315 if (queue_delayed_work(workqueue, &ring->scheduler, delta))
317 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0))
319 kref_put(&u132->kref, u132_hcd_delete);
323 static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
326 kref_get(&u132->kref);
327 u132_ring_requeue_work(u132, ring, delta);
331 static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
333 if (cancel_delayed_work(&ring->scheduler)) {
334 kref_put(&u132->kref, u132_hcd_delete);
338 static void u132_endp_delete(struct kref *kref)
340 struct u132_endp *endp = kref_to_u132_endp(kref);
341 struct u132 *u132 = endp->u132;
342 u8 usb_addr = endp->usb_addr;
343 u8 usb_endp = endp->usb_endp;
344 u8 address = u132->addr[usb_addr].address;
345 struct u132_udev *udev = &u132->udev[address];
346 u8 endp_number = endp->endp_number;
347 struct usb_host_endpoint *hep = endp->hep;
348 struct u132_ring *ring = endp->ring;
349 struct list_head *head = &endp->endp_ring;
351 if (endp == ring->curr_endp) {
352 if (list_empty(head)) {
353 ring->curr_endp = NULL;
356 struct u132_endp *next_endp = list_entry(head->next,
357 struct u132_endp, endp_ring);
358 ring->curr_endp = next_endp;
363 udev->endp_number_in[usb_endp] = 0;
364 u132_udev_put_kref(u132, udev);
367 udev->endp_number_out[usb_endp] = 0;
368 u132_udev_put_kref(u132, udev);
370 u132->endp[endp_number - 1] = NULL;
373 u132_u132_put_kref(u132);
376 static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp)
378 kref_put(&endp->kref, u132_endp_delete);
381 static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp)
383 kref_get(&endp->kref);
386 static inline void u132_endp_init_kref(struct u132 *u132,
387 struct u132_endp *endp)
389 kref_init(&endp->kref);
390 kref_get(&u132->kref);
393 static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
396 if (queue_delayed_work(workqueue, &endp->scheduler, delta))
397 kref_get(&endp->kref);
400 static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp)
402 if (cancel_delayed_work(&endp->scheduler))
403 kref_put(&endp->kref, u132_endp_delete);
406 static inline void u132_monitor_put_kref(struct u132 *u132)
408 kref_put(&u132->kref, u132_hcd_delete);
411 static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta)
413 if (queue_delayed_work(workqueue, &u132->monitor, delta))
414 kref_get(&u132->kref);
417 static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta)
419 if (!queue_delayed_work(workqueue, &u132->monitor, delta))
420 kref_put(&u132->kref, u132_hcd_delete);
423 static void u132_monitor_cancel_work(struct u132 *u132)
425 if (cancel_delayed_work(&u132->monitor))
426 kref_put(&u132->kref, u132_hcd_delete);
429 static int read_roothub_info(struct u132 *u132)
433 retval = u132_read_pcimem(u132, revision, &revision);
435 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
438 } else if ((revision & 0xFF) == 0x10) {
439 } else if ((revision & 0xFF) == 0x11) {
441 dev_err(&u132->platform_dev->dev, "device revision is not valid"
442 " %08X\n", revision);
445 retval = u132_read_pcimem(u132, control, &u132->hc_control);
447 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
451 retval = u132_read_pcimem(u132, roothub.status,
452 &u132->hc_roothub_status);
454 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
455 "g roothub.status\n", retval);
458 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a);
460 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
461 "g roothub.a\n", retval);
465 int I = u132->num_ports;
468 retval = u132_read_pcimem(u132, roothub.portstatus[i],
469 &u132->hc_roothub_portstatus[i]);
471 dev_err(&u132->platform_dev->dev, "error %d acc"
472 "essing device roothub.portstatus[%d]\n"
482 static void u132_hcd_monitor_work(struct work_struct *work)
484 struct u132 *u132 = container_of(work, struct u132, monitor.work);
485 if (u132->going > 1) {
486 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
488 u132_monitor_put_kref(u132);
490 } else if (u132->going > 0) {
491 dev_err(&u132->platform_dev->dev, "device is being removed\n");
492 u132_monitor_put_kref(u132);
496 down(&u132->sw_lock);
497 retval = read_roothub_info(u132);
499 struct usb_hcd *hcd = u132_to_hcd(u132);
504 ftdi_elan_gone_away(u132->platform_dev);
505 u132_monitor_put_kref(u132);
508 u132_monitor_requeue_work(u132, 500);
515 static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
516 struct urb *urb, int status)
518 struct u132_ring *ring;
520 struct usb_hcd *hcd = u132_to_hcd(u132);
521 urb->error_count = 0;
522 urb->status = status;
524 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
525 endp->queue_next += 1;
526 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
528 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
530 struct list_head *next = endp->urb_more.next;
531 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
534 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
537 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
539 } down(&u132->scheduler_lock);
542 u132_ring_cancel_work(u132, ring);
543 u132_ring_queue_work(u132, ring, 0);
544 up(&u132->scheduler_lock);
545 u132_endp_put_kref(u132, endp);
546 usb_hcd_giveback_urb(hcd, urb);
550 static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp,
551 struct urb *urb, int status)
553 u132_endp_put_kref(u132, endp);
556 static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
557 struct urb *urb, int status)
560 struct usb_hcd *hcd = u132_to_hcd(u132);
561 urb->error_count = 0;
562 urb->status = status;
564 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
565 endp->queue_next += 1;
566 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
568 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
570 struct list_head *next = endp->urb_more.next;
571 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
574 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
577 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
579 } usb_hcd_giveback_urb(hcd, urb);
583 static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
584 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
585 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
586 int toggle_bits, int error_count, int condition_code, int repeat_number,
587 int halted, int skipped, int actual, int non_null))
589 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
590 urb, address, endp->usb_endp, toggle_bits, callback);
593 static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
594 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
595 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
596 int toggle_bits, int error_count, int condition_code, int repeat_number,
597 int halted, int skipped, int actual, int non_null))
599 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
600 urb, address, endp->usb_endp, toggle_bits, callback);
603 static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
604 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
605 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
606 int toggle_bits, int error_count, int condition_code, int repeat_number,
607 int halted, int skipped, int actual, int non_null))
609 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
610 endp, urb, address, endp->usb_endp, toggle_bits, callback);
613 static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
614 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
615 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
616 int toggle_bits, int error_count, int condition_code, int repeat_number,
617 int halted, int skipped, int actual, int non_null))
619 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
620 endp, urb, address, endp->usb_endp, toggle_bits, callback);
625 * must not LOCK sw_lock
628 static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
629 int len, int toggle_bits, int error_count, int condition_code,
630 int repeat_number, int halted, int skipped, int actual, int non_null)
632 struct u132_endp *endp = data;
633 struct u132 *u132 = endp->u132;
634 u8 address = u132->addr[endp->usb_addr].address;
635 struct u132_udev *udev = &u132->udev[address];
636 down(&u132->scheduler_lock);
637 if (u132->going > 1) {
638 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
640 up(&u132->scheduler_lock);
641 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
643 } else if (endp->dequeueing) {
644 endp->dequeueing = 0;
645 up(&u132->scheduler_lock);
646 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
648 } else if (u132->going > 0) {
649 dev_err(&u132->platform_dev->dev, "device is being removed urb="
650 "%p status=%d\n", urb, urb->status);
651 up(&u132->scheduler_lock);
652 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
654 } else if (urb->status == -EINPROGRESS) {
655 struct u132_ring *ring = endp->ring;
656 u8 *u = urb->transfer_buffer + urb->actual_length;
662 urb->actual_length += len;
663 if ((condition_code == TD_CC_NOERROR) &&
664 (urb->transfer_buffer_length > urb->actual_length)) {
665 endp->toggle_bits = toggle_bits;
666 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
668 if (urb->actual_length > 0) {
670 up(&u132->scheduler_lock);
671 retval = edset_single(u132, ring, endp, urb,
672 address, endp->toggle_bits,
673 u132_hcd_interrupt_recv);
676 u132_hcd_giveback_urb(u132, endp, urb,
681 endp->jiffies = jiffies +
682 msecs_to_jiffies(urb->interval);
683 u132_ring_cancel_work(u132, ring);
684 u132_ring_queue_work(u132, ring, 0);
685 up(&u132->scheduler_lock);
686 u132_endp_put_kref(u132, endp);
689 } else if ((condition_code == TD_DATAUNDERRUN) &&
690 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
691 endp->toggle_bits = toggle_bits;
692 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
694 up(&u132->scheduler_lock);
695 u132_hcd_giveback_urb(u132, endp, urb, 0);
698 if (condition_code == TD_CC_NOERROR) {
699 endp->toggle_bits = toggle_bits;
700 usb_settoggle(udev->usb_device, endp->usb_endp,
702 } else if (condition_code == TD_CC_STALL) {
703 endp->toggle_bits = 0x2;
704 usb_settoggle(udev->usb_device, endp->usb_endp,
707 endp->toggle_bits = 0x2;
708 usb_settoggle(udev->usb_device, endp->usb_endp,
710 dev_err(&u132->platform_dev->dev, "urb=%p givin"
711 "g back INTERRUPT %s\n", urb,
712 cc_to_text[condition_code]);
714 up(&u132->scheduler_lock);
715 u132_hcd_giveback_urb(u132, endp, urb,
716 cc_to_error[condition_code]);
720 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
721 "s=%d\n", urb, urb->status);
722 up(&u132->scheduler_lock);
723 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
728 static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
729 int len, int toggle_bits, int error_count, int condition_code,
730 int repeat_number, int halted, int skipped, int actual, int non_null)
732 struct u132_endp *endp = data;
733 struct u132 *u132 = endp->u132;
734 u8 address = u132->addr[endp->usb_addr].address;
735 down(&u132->scheduler_lock);
736 if (u132->going > 1) {
737 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
739 up(&u132->scheduler_lock);
740 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
742 } else if (endp->dequeueing) {
743 endp->dequeueing = 0;
744 up(&u132->scheduler_lock);
745 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
747 } else if (u132->going > 0) {
748 dev_err(&u132->platform_dev->dev, "device is being removed urb="
749 "%p status=%d\n", urb, urb->status);
750 up(&u132->scheduler_lock);
751 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
753 } else if (urb->status == -EINPROGRESS) {
754 struct u132_ring *ring = endp->ring;
755 urb->actual_length += len;
756 endp->toggle_bits = toggle_bits;
757 if (urb->transfer_buffer_length > urb->actual_length) {
759 up(&u132->scheduler_lock);
760 retval = edset_output(u132, ring, endp, urb, address,
761 endp->toggle_bits, u132_hcd_bulk_output_sent);
764 u132_hcd_giveback_urb(u132, endp, urb, retval);
767 up(&u132->scheduler_lock);
768 u132_hcd_giveback_urb(u132, endp, urb, 0);
772 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
773 "s=%d\n", urb, urb->status);
774 up(&u132->scheduler_lock);
775 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
780 static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
781 int len, int toggle_bits, int error_count, int condition_code,
782 int repeat_number, int halted, int skipped, int actual, int non_null)
784 struct u132_endp *endp = data;
785 struct u132 *u132 = endp->u132;
786 u8 address = u132->addr[endp->usb_addr].address;
787 struct u132_udev *udev = &u132->udev[address];
788 down(&u132->scheduler_lock);
789 if (u132->going > 1) {
790 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
792 up(&u132->scheduler_lock);
793 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
795 } else if (endp->dequeueing) {
796 endp->dequeueing = 0;
797 up(&u132->scheduler_lock);
798 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
800 } else if (u132->going > 0) {
801 dev_err(&u132->platform_dev->dev, "device is being removed urb="
802 "%p status=%d\n", urb, urb->status);
803 up(&u132->scheduler_lock);
804 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
806 } else if (urb->status == -EINPROGRESS) {
807 struct u132_ring *ring = endp->ring;
808 u8 *u = urb->transfer_buffer + urb->actual_length;
814 urb->actual_length += len;
815 if ((condition_code == TD_CC_NOERROR) &&
816 (urb->transfer_buffer_length > urb->actual_length)) {
818 endp->toggle_bits = toggle_bits;
819 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
821 up(&u132->scheduler_lock);
822 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
823 ring->number, endp, urb, address,
824 endp->usb_endp, endp->toggle_bits,
825 u132_hcd_bulk_input_recv);
828 u132_hcd_giveback_urb(u132, endp, urb, retval);
830 } else if (condition_code == TD_CC_NOERROR) {
831 endp->toggle_bits = toggle_bits;
832 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
834 up(&u132->scheduler_lock);
835 u132_hcd_giveback_urb(u132, endp, urb,
836 cc_to_error[condition_code]);
838 } else if ((condition_code == TD_DATAUNDERRUN) &&
839 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
840 endp->toggle_bits = toggle_bits;
841 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
843 up(&u132->scheduler_lock);
844 u132_hcd_giveback_urb(u132, endp, urb, 0);
846 } else if (condition_code == TD_DATAUNDERRUN) {
847 endp->toggle_bits = toggle_bits;
848 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
850 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
851 ") giving back BULK IN %s\n", urb,
852 cc_to_text[condition_code]);
853 up(&u132->scheduler_lock);
854 u132_hcd_giveback_urb(u132, endp, urb, 0);
856 } else if (condition_code == TD_CC_STALL) {
857 endp->toggle_bits = 0x2;
858 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
859 up(&u132->scheduler_lock);
860 u132_hcd_giveback_urb(u132, endp, urb,
861 cc_to_error[condition_code]);
864 endp->toggle_bits = 0x2;
865 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
866 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
867 "ULK IN code=%d %s\n", urb, condition_code,
868 cc_to_text[condition_code]);
869 up(&u132->scheduler_lock);
870 u132_hcd_giveback_urb(u132, endp, urb,
871 cc_to_error[condition_code]);
875 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
876 "s=%d\n", urb, urb->status);
877 up(&u132->scheduler_lock);
878 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
883 static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
884 int len, int toggle_bits, int error_count, int condition_code,
885 int repeat_number, int halted, int skipped, int actual, int non_null)
887 struct u132_endp *endp = data;
888 struct u132 *u132 = endp->u132;
889 down(&u132->scheduler_lock);
890 if (u132->going > 1) {
891 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
893 up(&u132->scheduler_lock);
894 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
896 } else if (endp->dequeueing) {
897 endp->dequeueing = 0;
898 up(&u132->scheduler_lock);
899 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
901 } else if (u132->going > 0) {
902 dev_err(&u132->platform_dev->dev, "device is being removed urb="
903 "%p status=%d\n", urb, urb->status);
904 up(&u132->scheduler_lock);
905 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
907 } else if (urb->status == -EINPROGRESS) {
908 up(&u132->scheduler_lock);
909 u132_hcd_giveback_urb(u132, endp, urb, 0);
912 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
913 "s=%d\n", urb, urb->status);
914 up(&u132->scheduler_lock);
915 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
920 static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
921 int len, int toggle_bits, int error_count, int condition_code,
922 int repeat_number, int halted, int skipped, int actual, int non_null)
924 struct u132_endp *endp = data;
925 struct u132 *u132 = endp->u132;
926 u8 address = u132->addr[endp->usb_addr].address;
927 down(&u132->scheduler_lock);
928 if (u132->going > 1) {
929 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
931 up(&u132->scheduler_lock);
932 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
934 } else if (endp->dequeueing) {
935 endp->dequeueing = 0;
936 up(&u132->scheduler_lock);
937 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
939 } else if (u132->going > 0) {
940 dev_err(&u132->platform_dev->dev, "device is being removed urb="
941 "%p status=%d\n", urb, urb->status);
942 up(&u132->scheduler_lock);
943 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
945 } else if (urb->status == -EINPROGRESS) {
946 struct u132_ring *ring = endp->ring;
947 u8 *u = urb->transfer_buffer;
953 urb->actual_length = len;
954 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
955 TD_DATAUNDERRUN) && ((urb->transfer_flags &
956 URB_SHORT_NOT_OK) == 0))) {
958 up(&u132->scheduler_lock);
959 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
960 ring->number, endp, urb, address,
962 u132_hcd_configure_empty_sent);
965 u132_hcd_giveback_urb(u132, endp, urb, retval);
967 } else if (condition_code == TD_CC_STALL) {
968 up(&u132->scheduler_lock);
969 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
970 "NPUT STALL urb %p\n", urb);
971 u132_hcd_giveback_urb(u132, endp, urb,
972 cc_to_error[condition_code]);
975 up(&u132->scheduler_lock);
976 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
977 "PUT %s urb %p\n", cc_to_text[condition_code],
979 u132_hcd_giveback_urb(u132, endp, urb,
980 cc_to_error[condition_code]);
984 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
985 "s=%d\n", urb, urb->status);
986 up(&u132->scheduler_lock);
987 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
992 static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
993 int len, int toggle_bits, int error_count, int condition_code,
994 int repeat_number, int halted, int skipped, int actual, int non_null)
996 struct u132_endp *endp = data;
997 struct u132 *u132 = endp->u132;
998 down(&u132->scheduler_lock);
999 if (u132->going > 1) {
1000 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1002 up(&u132->scheduler_lock);
1003 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1005 } else if (endp->dequeueing) {
1006 endp->dequeueing = 0;
1007 up(&u132->scheduler_lock);
1008 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1010 } else if (u132->going > 0) {
1011 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1012 "%p status=%d\n", urb, urb->status);
1013 up(&u132->scheduler_lock);
1014 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1016 } else if (urb->status == -EINPROGRESS) {
1017 up(&u132->scheduler_lock);
1018 u132_hcd_giveback_urb(u132, endp, urb, 0);
1021 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1022 "s=%d\n", urb, urb->status);
1023 up(&u132->scheduler_lock);
1024 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1029 static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1030 int len, int toggle_bits, int error_count, int condition_code,
1031 int repeat_number, int halted, int skipped, int actual, int non_null)
1033 struct u132_endp *endp = data;
1034 struct u132 *u132 = endp->u132;
1035 u8 address = u132->addr[endp->usb_addr].address;
1036 down(&u132->scheduler_lock);
1037 if (u132->going > 1) {
1038 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1040 up(&u132->scheduler_lock);
1041 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1043 } else if (endp->dequeueing) {
1044 endp->dequeueing = 0;
1045 up(&u132->scheduler_lock);
1046 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1048 } else if (u132->going > 0) {
1049 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1050 "%p status=%d\n", urb, urb->status);
1051 up(&u132->scheduler_lock);
1052 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1054 } else if (urb->status == -EINPROGRESS) {
1055 if (usb_pipein(urb->pipe)) {
1057 struct u132_ring *ring = endp->ring;
1058 up(&u132->scheduler_lock);
1059 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1060 ring->number, endp, urb, address,
1062 u132_hcd_configure_input_recv);
1065 u132_hcd_giveback_urb(u132, endp, urb, retval);
1069 struct u132_ring *ring = endp->ring;
1070 up(&u132->scheduler_lock);
1071 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1072 ring->number, endp, urb, address,
1074 u132_hcd_configure_empty_recv);
1077 u132_hcd_giveback_urb(u132, endp, urb, retval);
1081 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1082 "s=%d\n", urb, urb->status);
1083 up(&u132->scheduler_lock);
1084 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1089 static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1090 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1091 int repeat_number, int halted, int skipped, int actual, int non_null)
1093 struct u132_endp *endp = data;
1094 struct u132 *u132 = endp->u132;
1095 u8 address = u132->addr[endp->usb_addr].address;
1096 struct u132_udev *udev = &u132->udev[address];
1097 down(&u132->scheduler_lock);
1098 if (u132->going > 1) {
1099 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1101 up(&u132->scheduler_lock);
1102 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1104 } else if (endp->dequeueing) {
1105 endp->dequeueing = 0;
1106 up(&u132->scheduler_lock);
1107 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1109 } else if (u132->going > 0) {
1110 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1111 "%p status=%d\n", urb, urb->status);
1112 up(&u132->scheduler_lock);
1113 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1115 } else if (urb->status == -EINPROGRESS) {
1116 u132->addr[0].address = 0;
1117 endp->usb_addr = udev->usb_addr;
1118 up(&u132->scheduler_lock);
1119 u132_hcd_giveback_urb(u132, endp, urb, 0);
1122 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1123 "s=%d\n", urb, urb->status);
1124 up(&u132->scheduler_lock);
1125 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1130 static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1131 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1132 int repeat_number, int halted, int skipped, int actual, int non_null)
1134 struct u132_endp *endp = data;
1135 struct u132 *u132 = endp->u132;
1136 down(&u132->scheduler_lock);
1137 if (u132->going > 1) {
1138 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1140 up(&u132->scheduler_lock);
1141 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1143 } else if (endp->dequeueing) {
1144 endp->dequeueing = 0;
1145 up(&u132->scheduler_lock);
1146 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1148 } else if (u132->going > 0) {
1149 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1150 "%p status=%d\n", urb, urb->status);
1151 up(&u132->scheduler_lock);
1152 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1154 } else if (urb->status == -EINPROGRESS) {
1156 struct u132_ring *ring = endp->ring;
1157 up(&u132->scheduler_lock);
1158 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1159 ring->number, endp, urb, 0, endp->usb_endp, 0,
1160 u132_hcd_enumeration_empty_recv);
1163 u132_hcd_giveback_urb(u132, endp, urb, retval);
1166 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1167 "s=%d\n", urb, urb->status);
1168 up(&u132->scheduler_lock);
1169 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1174 static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1175 int len, int toggle_bits, int error_count, int condition_code,
1176 int repeat_number, int halted, int skipped, int actual, int non_null)
1178 struct u132_endp *endp = data;
1179 struct u132 *u132 = endp->u132;
1180 down(&u132->scheduler_lock);
1181 if (u132->going > 1) {
1182 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1184 up(&u132->scheduler_lock);
1185 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1187 } else if (endp->dequeueing) {
1188 endp->dequeueing = 0;
1189 up(&u132->scheduler_lock);
1190 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1192 } else if (u132->going > 0) {
1193 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1194 "%p status=%d\n", urb, urb->status);
1195 up(&u132->scheduler_lock);
1196 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1198 } else if (urb->status == -EINPROGRESS) {
1199 up(&u132->scheduler_lock);
1200 u132_hcd_giveback_urb(u132, endp, urb, 0);
1203 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1204 "s=%d\n", urb, urb->status);
1205 up(&u132->scheduler_lock);
1206 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1211 static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1212 int len, int toggle_bits, int error_count, int condition_code,
1213 int repeat_number, int halted, int skipped, int actual, int non_null)
1215 struct u132_endp *endp = data;
1216 struct u132 *u132 = endp->u132;
1217 u8 address = u132->addr[endp->usb_addr].address;
1218 down(&u132->scheduler_lock);
1219 if (u132->going > 1) {
1220 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1222 up(&u132->scheduler_lock);
1223 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1225 } else if (endp->dequeueing) {
1226 endp->dequeueing = 0;
1227 up(&u132->scheduler_lock);
1228 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1230 } else if (u132->going > 0) {
1231 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1232 "%p status=%d\n", urb, urb->status);
1233 up(&u132->scheduler_lock);
1234 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1236 } else if (urb->status == -EINPROGRESS) {
1238 struct u132_ring *ring = endp->ring;
1239 u8 *u = urb->transfer_buffer;
1245 urb->actual_length = len;
1246 up(&u132->scheduler_lock);
1247 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1248 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1249 u132_hcd_initial_empty_sent);
1252 u132_hcd_giveback_urb(u132, endp, urb, retval);
1255 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1256 "s=%d\n", urb, urb->status);
1257 up(&u132->scheduler_lock);
1258 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1263 static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1264 int len, int toggle_bits, int error_count, int condition_code,
1265 int repeat_number, int halted, int skipped, int actual, int non_null)
1267 struct u132_endp *endp = data;
1268 struct u132 *u132 = endp->u132;
1269 u8 address = u132->addr[endp->usb_addr].address;
1270 down(&u132->scheduler_lock);
1271 if (u132->going > 1) {
1272 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1274 up(&u132->scheduler_lock);
1275 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1277 } else if (endp->dequeueing) {
1278 endp->dequeueing = 0;
1279 up(&u132->scheduler_lock);
1280 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1282 } else if (u132->going > 0) {
1283 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1284 "%p status=%d\n", urb, urb->status);
1285 up(&u132->scheduler_lock);
1286 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1288 } else if (urb->status == -EINPROGRESS) {
1290 struct u132_ring *ring = endp->ring;
1291 up(&u132->scheduler_lock);
1292 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1293 ring->number, endp, urb, address, endp->usb_endp, 0,
1294 u132_hcd_initial_input_recv);
1297 u132_hcd_giveback_urb(u132, endp, urb, retval);
1300 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1301 "s=%d\n", urb, urb->status);
1302 up(&u132->scheduler_lock);
1303 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1309 * this work function is only executed from the work queue
1312 static void u132_hcd_ring_work_scheduler(struct work_struct *work)
1314 struct u132_ring *ring =
1315 container_of(work, struct u132_ring, scheduler.work);
1316 struct u132 *u132 = ring->u132;
1317 down(&u132->scheduler_lock);
1319 up(&u132->scheduler_lock);
1320 u132_ring_put_kref(u132, ring);
1322 } else if (ring->curr_endp) {
1323 struct u132_endp *last_endp = ring->curr_endp;
1324 struct list_head *scan;
1325 struct list_head *head = &last_endp->endp_ring;
1326 unsigned long wakeup = 0;
1327 list_for_each(scan, head) {
1328 struct u132_endp *endp = list_entry(scan,
1329 struct u132_endp, endp_ring);
1330 if (endp->queue_next == endp->queue_last) {
1331 } else if ((endp->delayed == 0)
1332 || time_after_eq(jiffies, endp->jiffies)) {
1333 ring->curr_endp = endp;
1334 u132_endp_cancel_work(u132, last_endp);
1335 u132_endp_queue_work(u132, last_endp, 0);
1336 up(&u132->scheduler_lock);
1337 u132_ring_put_kref(u132, ring);
1340 unsigned long delta = endp->jiffies - jiffies;
1345 if (last_endp->queue_next == last_endp->queue_last) {
1346 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1347 last_endp->jiffies)) {
1348 u132_endp_cancel_work(u132, last_endp);
1349 u132_endp_queue_work(u132, last_endp, 0);
1350 up(&u132->scheduler_lock);
1351 u132_ring_put_kref(u132, ring);
1354 unsigned long delta = last_endp->jiffies - jiffies;
1359 u132_ring_requeue_work(u132, ring, wakeup);
1360 up(&u132->scheduler_lock);
1363 up(&u132->scheduler_lock);
1364 u132_ring_put_kref(u132, ring);
1368 up(&u132->scheduler_lock);
1369 u132_ring_put_kref(u132, ring);
1374 static void u132_hcd_endp_work_scheduler(struct work_struct *work)
1376 struct u132_ring *ring;
1377 struct u132_endp *endp =
1378 container_of(work, struct u132_endp, scheduler.work);
1379 struct u132 *u132 = endp->u132;
1380 down(&u132->scheduler_lock);
1382 if (endp->edset_flush) {
1383 endp->edset_flush = 0;
1384 if (endp->dequeueing)
1385 usb_ftdi_elan_edset_flush(u132->platform_dev,
1386 ring->number, endp);
1387 up(&u132->scheduler_lock);
1388 u132_endp_put_kref(u132, endp);
1390 } else if (endp->active) {
1391 up(&u132->scheduler_lock);
1392 u132_endp_put_kref(u132, endp);
1394 } else if (ring->in_use) {
1395 up(&u132->scheduler_lock);
1396 u132_endp_put_kref(u132, endp);
1398 } else if (endp->queue_next == endp->queue_last) {
1399 up(&u132->scheduler_lock);
1400 u132_endp_put_kref(u132, endp);
1402 } else if (endp->pipetype == PIPE_INTERRUPT) {
1403 u8 address = u132->addr[endp->usb_addr].address;
1405 up(&u132->scheduler_lock);
1406 u132_endp_put_kref(u132, endp);
1410 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1413 ring->curr_endp = endp;
1415 up(&u132->scheduler_lock);
1416 retval = edset_single(u132, ring, endp, urb, address,
1417 endp->toggle_bits, u132_hcd_interrupt_recv);
1420 u132_hcd_giveback_urb(u132, endp, urb, retval);
1423 } else if (endp->pipetype == PIPE_CONTROL) {
1424 u8 address = u132->addr[endp->usb_addr].address;
1426 up(&u132->scheduler_lock);
1427 u132_endp_put_kref(u132, endp);
1429 } else if (address == 0) {
1431 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1434 ring->curr_endp = endp;
1436 up(&u132->scheduler_lock);
1437 retval = edset_setup(u132, ring, endp, urb, address,
1438 0x2, u132_hcd_initial_setup_sent);
1441 u132_hcd_giveback_urb(u132, endp, urb, retval);
1443 } else if (endp->usb_addr == 0) {
1445 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1448 ring->curr_endp = endp;
1450 up(&u132->scheduler_lock);
1451 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1452 u132_hcd_enumeration_address_sent);
1455 u132_hcd_giveback_urb(u132, endp, urb, retval);
1459 u8 address = u132->addr[endp->usb_addr].address;
1460 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1463 ring->curr_endp = endp;
1465 up(&u132->scheduler_lock);
1466 retval = edset_setup(u132, ring, endp, urb, address,
1467 0x2, u132_hcd_configure_setup_sent);
1470 u132_hcd_giveback_urb(u132, endp, urb, retval);
1475 u8 address = u132->addr[endp->usb_addr].address;
1477 up(&u132->scheduler_lock);
1478 u132_endp_put_kref(u132, endp);
1482 struct urb *urb = endp->urb_list[
1483 ENDP_QUEUE_MASK & endp->queue_next];
1485 ring->curr_endp = endp;
1487 up(&u132->scheduler_lock);
1488 retval = edset_input(u132, ring, endp, urb,
1489 address, endp->toggle_bits,
1490 u132_hcd_bulk_input_recv);
1493 u132_hcd_giveback_urb(u132, endp, urb,
1497 } else { /* output pipe */
1498 u8 address = u132->addr[endp->usb_addr].address;
1500 up(&u132->scheduler_lock);
1501 u132_endp_put_kref(u132, endp);
1505 struct urb *urb = endp->urb_list[
1506 ENDP_QUEUE_MASK & endp->queue_next];
1508 ring->curr_endp = endp;
1510 up(&u132->scheduler_lock);
1511 retval = edset_output(u132, ring, endp, urb,
1512 address, endp->toggle_bits,
1513 u132_hcd_bulk_output_sent);
1516 u132_hcd_giveback_urb(u132, endp, urb,
1524 static void port_power(struct u132 *u132, int pn, int is_on)
1526 u132->port[pn].power = is_on;
1529 static void u132_power(struct u132 *u132, int is_on)
1531 struct usb_hcd *hcd = u132_to_hcd(u132)
1532 ; /* hub is inactive unless the port is powered */
1537 hcd->self.controller->power.power_state = PMSG_ON;
1540 hcd->state = HC_STATE_HALT;
1541 hcd->self.controller->power.power_state = PMSG_SUSPEND;
1545 static int u132_periodic_reinit(struct u132 *u132)
1548 u32 fi = u132->hc_fminterval & 0x03fff;
1551 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1554 fit = fminterval & FIT;
1555 retval = u132_write_pcimem(u132, fminterval,
1556 (fit ^ FIT) | u132->hc_fminterval);
1559 retval = u132_write_pcimem(u132, periodicstart,
1560 ((9 *fi) / 10) & 0x3fff);
1566 static char *hcfs2string(int state)
1569 case OHCI_USB_RESET:
1571 case OHCI_USB_RESUME:
1574 return "operational";
1575 case OHCI_USB_SUSPEND:
1581 static int u132_init(struct u132 *u132)
1586 u132->next_statechange = jiffies;
1587 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1590 retval = u132_read_pcimem(u132, control, &control);
1593 if (u132->num_ports == 0) {
1595 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1598 u132->num_ports = rh_a & RH_A_NDP;
1599 retval = read_roothub_info(u132);
1603 if (u132->num_ports > MAX_U132_PORTS) {
1610 /* Start an OHCI controller, set the BUS operational
1611 * resets USB and controller
1614 static int u132_run(struct u132 *u132)
1623 int mask = OHCI_INTR_INIT;
1624 int first = u132->hc_fminterval == 0;
1626 int reset_timeout = 30; /* ... allow extra time */
1630 retval = u132_read_pcimem(u132, fminterval, &temp);
1633 u132->hc_fminterval = temp & 0x3fff;
1634 if (u132->hc_fminterval != FI) {
1636 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1638 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1641 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1642 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1644 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1648 case OHCI_USB_SUSPEND:
1649 case OHCI_USB_RESUME:
1650 u132->hc_control &= OHCI_CTRL_RWC;
1651 u132->hc_control |= OHCI_USB_RESUME;
1655 u132->hc_control &= OHCI_CTRL_RWC;
1656 u132->hc_control |= OHCI_USB_RESET;
1660 retval = u132_write_pcimem(u132, control, u132->hc_control);
1663 retval = u132_read_pcimem(u132, control, &control);
1667 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1670 if (!(roothub_a & RH_A_NPS)) {
1671 int temp; /* power down each port */
1672 for (temp = 0; temp < u132->num_ports; temp++) {
1673 retval = u132_write_pcimem(u132,
1674 roothub.portstatus[temp], RH_PS_LSDA);
1679 retval = u132_read_pcimem(u132, control, &control);
1682 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1685 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1689 retval = u132_read_pcimem(u132, cmdstatus, &status);
1692 if (0 != (status & OHCI_HCR)) {
1693 if (--reset_timeout == 0) {
1694 dev_err(&u132->platform_dev->dev, "USB HC reset"
1703 if (u132->flags & OHCI_QUIRK_INITRESET) {
1704 retval = u132_write_pcimem(u132, control, u132->hc_control);
1707 retval = u132_read_pcimem(u132, control, &control);
1711 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1714 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1717 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1720 retval = u132_periodic_reinit(u132);
1723 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1726 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1729 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1730 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1731 u132->flags |= OHCI_QUIRK_INITRESET;
1734 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1735 "\n", fminterval, periodicstart);
1736 } /* start controller operations */
1737 u132->hc_control &= OHCI_CTRL_RWC;
1738 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1739 retval = u132_write_pcimem(u132, control, u132->hc_control);
1742 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1745 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1748 retval = u132_read_pcimem(u132, control, &control);
1751 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1752 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1755 retval = u132_write_pcimem(u132, intrstatus, mask);
1758 retval = u132_write_pcimem(u132, intrdisable,
1759 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1760 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1763 return retval; /* handle root hub init quirks ... */
1764 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1767 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1768 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1769 roothub_a |= RH_A_NOCP;
1770 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1771 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1774 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1775 roothub_a |= RH_A_NPS;
1776 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1780 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1783 retval = u132_write_pcimem(u132, roothub.b,
1784 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1787 retval = u132_read_pcimem(u132, control, &control);
1790 mdelay((roothub_a >> 23) & 0x1fe);
1791 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1795 static void u132_hcd_stop(struct usb_hcd *hcd)
1797 struct u132 *u132 = hcd_to_u132(hcd);
1798 if (u132->going > 1) {
1799 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1800 "een removed %d\n", u132, hcd, u132->going);
1801 } else if (u132->going > 0) {
1802 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1805 down(&u132->sw_lock);
1807 u132_power(u132, 0);
1812 static int u132_hcd_start(struct usb_hcd *hcd)
1814 struct u132 *u132 = hcd_to_u132(hcd);
1815 if (u132->going > 1) {
1816 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1819 } else if (u132->going > 0) {
1820 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1822 } else if (hcd->self.controller) {
1824 struct platform_device *pdev =
1825 to_platform_device(hcd->self.controller);
1826 u16 vendor = ((struct u132_platform_data *)
1827 (pdev->dev.platform_data))->vendor;
1828 u16 device = ((struct u132_platform_data *)
1829 (pdev->dev.platform_data))->device;
1830 down(&u132->sw_lock);
1832 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1833 u132->flags = OHCI_QUIRK_AMD756;
1834 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1835 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1836 "ounds unavailable\n");
1837 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1838 u132->flags |= OHCI_QUIRK_ZFMICRO;
1839 retval = u132_run(u132);
1848 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1853 static int u132_hcd_reset(struct usb_hcd *hcd)
1855 struct u132 *u132 = hcd_to_u132(hcd);
1856 if (u132->going > 1) {
1857 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1860 } else if (u132->going > 0) {
1861 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1865 down(&u132->sw_lock);
1866 retval = u132_init(u132);
1876 static int create_endpoint_and_queue_int(struct u132 *u132,
1877 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1878 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1881 struct u132_ring *ring;
1883 u8 endp_number = ++u132->num_endpoints;
1884 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1885 kmalloc(sizeof(struct u132_endp), mem_flags);
1889 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1890 spin_lock_init(&endp->queue_lock.slock);
1891 INIT_LIST_HEAD(&endp->urb_more);
1892 ring = endp->ring = &u132->ring[0];
1893 if (ring->curr_endp) {
1894 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1896 INIT_LIST_HEAD(&endp->endp_ring);
1897 ring->curr_endp = endp;
1900 endp->dequeueing = 0;
1901 endp->edset_flush = 0;
1904 endp->endp_number = endp_number;
1907 endp->pipetype = usb_pipetype(urb->pipe);
1908 u132_endp_init_kref(u132, endp);
1909 if (usb_pipein(urb->pipe)) {
1910 endp->toggle_bits = 0x2;
1911 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1914 udev->endp_number_in[usb_endp] = endp_number;
1915 u132_udev_get_kref(u132, udev);
1917 endp->toggle_bits = 0x2;
1918 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1921 udev->endp_number_out[usb_endp] = endp_number;
1922 u132_udev_get_kref(u132, udev);
1925 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1927 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1928 endp->udev_number = address;
1929 endp->usb_addr = usb_addr;
1930 endp->usb_endp = usb_endp;
1931 endp->queue_size = 1;
1932 endp->queue_last = 0;
1933 endp->queue_next = 0;
1934 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1935 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1936 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1940 static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
1941 struct usb_host_endpoint *hep, struct urb *urb,
1942 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1943 u8 usb_endp, u8 address)
1947 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1948 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1949 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1951 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1954 endp->queue_size -= 1;
1957 list_add_tail(&urbq->urb_more, &endp->urb_more);
1964 static int create_endpoint_and_queue_bulk(struct u132 *u132,
1965 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1966 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1970 struct u132_ring *ring;
1972 u8 endp_number = ++u132->num_endpoints;
1973 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1974 kmalloc(sizeof(struct u132_endp), mem_flags);
1978 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1979 spin_lock_init(&endp->queue_lock.slock);
1980 INIT_LIST_HEAD(&endp->urb_more);
1981 endp->dequeueing = 0;
1982 endp->edset_flush = 0;
1985 endp->endp_number = endp_number;
1988 endp->pipetype = usb_pipetype(urb->pipe);
1989 u132_endp_init_kref(u132, endp);
1990 if (usb_pipein(urb->pipe)) {
1991 endp->toggle_bits = 0x2;
1992 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1996 udev->endp_number_in[usb_endp] = endp_number;
1997 u132_udev_get_kref(u132, udev);
1999 endp->toggle_bits = 0x2;
2000 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2004 udev->endp_number_out[usb_endp] = endp_number;
2005 u132_udev_get_kref(u132, udev);
2007 ring = endp->ring = &u132->ring[ring_number - 1];
2008 if (ring->curr_endp) {
2009 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2011 INIT_LIST_HEAD(&endp->endp_ring);
2012 ring->curr_endp = endp;
2016 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2017 endp->udev_number = address;
2018 endp->usb_addr = usb_addr;
2019 endp->usb_endp = usb_endp;
2020 endp->queue_size = 1;
2021 endp->queue_last = 0;
2022 endp->queue_next = 0;
2023 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2024 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2025 u132_endp_queue_work(u132, endp, 0);
2029 static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2030 struct usb_host_endpoint *hep, struct urb *urb,
2031 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2032 u8 usb_endp, u8 address)
2035 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2036 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2038 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2041 endp->queue_size -= 1;
2044 list_add_tail(&urbq->urb_more, &endp->urb_more);
2051 static int create_endpoint_and_queue_control(struct u132 *u132,
2052 struct usb_host_endpoint *hep, struct urb *urb,
2053 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2056 struct u132_ring *ring;
2057 u8 endp_number = ++u132->num_endpoints;
2058 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
2059 kmalloc(sizeof(struct u132_endp), mem_flags);
2063 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2064 spin_lock_init(&endp->queue_lock.slock);
2065 INIT_LIST_HEAD(&endp->urb_more);
2066 ring = endp->ring = &u132->ring[0];
2067 if (ring->curr_endp) {
2068 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2070 INIT_LIST_HEAD(&endp->endp_ring);
2071 ring->curr_endp = endp;
2074 endp->dequeueing = 0;
2075 endp->edset_flush = 0;
2078 endp->endp_number = endp_number;
2081 u132_endp_init_kref(u132, endp);
2082 u132_endp_get_kref(u132, endp);
2083 if (usb_addr == 0) {
2085 u8 address = u132->addr[usb_addr].address;
2086 struct u132_udev *udev = &u132->udev[address];
2087 endp->udev_number = address;
2088 endp->usb_addr = usb_addr;
2089 endp->usb_endp = usb_endp;
2092 endp->pipetype = usb_pipetype(urb->pipe);
2093 u132_udev_init_kref(u132, udev);
2094 u132_udev_get_kref(u132, udev);
2095 udev->endp_number_in[usb_endp] = endp_number;
2096 udev->endp_number_out[usb_endp] = endp_number;
2098 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2099 endp->queue_size = 1;
2100 endp->queue_last = 0;
2101 endp->queue_next = 0;
2102 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2103 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2104 u132_endp_queue_work(u132, endp, 0);
2106 } else { /*(usb_addr > 0) */
2108 u8 address = u132->addr[usb_addr].address;
2109 struct u132_udev *udev = &u132->udev[address];
2110 endp->udev_number = address;
2111 endp->usb_addr = usb_addr;
2112 endp->usb_endp = usb_endp;
2115 endp->pipetype = usb_pipetype(urb->pipe);
2116 u132_udev_get_kref(u132, udev);
2117 udev->enumeration = 2;
2118 udev->endp_number_in[usb_endp] = endp_number;
2119 udev->endp_number_out[usb_endp] = endp_number;
2121 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2122 endp->queue_size = 1;
2123 endp->queue_last = 0;
2124 endp->queue_next = 0;
2125 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2126 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2127 u132_endp_queue_work(u132, endp, 0);
2132 static int queue_control_on_old_endpoint(struct u132 *u132,
2133 struct usb_host_endpoint *hep, struct urb *urb,
2134 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2137 if (usb_addr == 0) {
2138 if (usb_pipein(urb->pipe)) {
2140 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2141 endp->urb_list[ENDP_QUEUE_MASK &
2142 endp->queue_last++] = urb;
2144 struct u132_urbq *urbq =
2145 kmalloc(sizeof(struct u132_urbq),
2148 endp->queue_size -= 1;
2151 list_add_tail(&urbq->urb_more,
2157 } else { /* usb_pipeout(urb->pipe) */
2158 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2159 int I = MAX_U132_UDEVS;
2162 struct u132_udev *udev = &u132->udev[++i];
2163 if (udev->usb_device) {
2166 udev->enumeration = 1;
2167 u132->addr[0].address = i;
2168 endp->udev_number = i;
2169 udev->udev_number = i;
2170 udev->usb_addr = usb_dev->devnum;
2171 u132_udev_init_kref(u132, udev);
2172 udev->endp_number_in[usb_endp] =
2174 u132_udev_get_kref(u132, udev);
2175 udev->endp_number_out[usb_endp] =
2177 udev->usb_device = usb_dev;
2178 ((u8 *) (urb->setup_packet))[2] =
2180 u132_udev_get_kref(u132, udev);
2185 dev_err(&u132->platform_dev->dev, "run out of d"
2190 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2191 endp->urb_list[ENDP_QUEUE_MASK &
2192 endp->queue_last++] = urb;
2194 struct u132_urbq *urbq =
2195 kmalloc(sizeof(struct u132_urbq),
2198 endp->queue_size -= 1;
2201 list_add_tail(&urbq->urb_more,
2208 } else { /*(usb_addr > 0) */
2209 u8 address = u132->addr[usb_addr].address;
2210 struct u132_udev *udev = &u132->udev[address];
2212 if (udev->enumeration == 2) {
2214 udev->enumeration = 2;
2215 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2216 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2219 struct u132_urbq *urbq =
2220 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2222 endp->queue_size -= 1;
2225 list_add_tail(&urbq->urb_more, &endp->urb_more);
2233 static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2234 struct urb *urb, gfp_t mem_flags)
2236 struct u132 *u132 = hcd_to_u132(hcd);
2237 if (irqs_disabled()) {
2238 if (__GFP_WAIT & mem_flags) {
2239 printk(KERN_ERR "invalid context for function that migh"
2244 if (u132->going > 1) {
2245 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2248 } else if (u132->going > 0) {
2249 dev_err(&u132->platform_dev->dev, "device is being removed urb="
2250 "%p status=%d\n", urb, urb->status);
2253 u8 usb_addr = usb_pipedevice(urb->pipe);
2254 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2255 struct usb_device *usb_dev = urb->dev;
2256 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2257 u8 address = u132->addr[usb_addr].address;
2258 struct u132_udev *udev = &u132->udev[address];
2259 struct u132_endp *endp = hep->hcpriv;
2260 urb->actual_length = 0;
2264 spin_lock_irqsave(&endp->queue_lock.slock,
2266 retval = queue_int_on_old_endpoint(u132, udev,
2267 hep, urb, usb_dev, endp, usb_addr,
2269 spin_unlock_irqrestore(&endp->queue_lock.slock,
2274 u132_endp_queue_work(u132, endp,
2275 msecs_to_jiffies(urb->interval))
2279 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2281 } else { /*(endp == NULL) */
2282 return create_endpoint_and_queue_int(u132, udev,
2283 hep, urb, usb_dev, usb_addr, usb_endp,
2284 address, mem_flags);
2286 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2287 dev_err(&u132->platform_dev->dev, "the hardware does no"
2288 "t support PIPE_ISOCHRONOUS\n");
2290 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2291 u8 address = u132->addr[usb_addr].address;
2292 struct u132_udev *udev = &u132->udev[address];
2293 struct u132_endp *endp = hep->hcpriv;
2294 urb->actual_length = 0;
2298 spin_lock_irqsave(&endp->queue_lock.slock,
2300 retval = queue_bulk_on_old_endpoint(u132, udev,
2301 hep, urb, usb_dev, endp, usb_addr,
2303 spin_unlock_irqrestore(&endp->queue_lock.slock,
2308 u132_endp_queue_work(u132, endp, 0);
2311 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2314 return create_endpoint_and_queue_bulk(u132,
2315 udev, hep, urb, usb_dev, usb_addr,
2316 usb_endp, address, mem_flags);
2318 struct u132_endp *endp = hep->hcpriv;
2320 u8 *b = urb->setup_packet;
2322 char data[30 *3 + 4];
2324 int m = (sizeof(data) - 1) / 3;
2327 while (urb_size-- > 0) {
2329 } else if (i++ < m) {
2330 int w = sprintf(d, " %02X", *b++);
2334 d += sprintf(d, " ..");
2339 spin_lock_irqsave(&endp->queue_lock.slock,
2341 retval = queue_control_on_old_endpoint(u132,
2342 hep, urb, usb_dev, endp, usb_addr,
2344 spin_unlock_irqrestore(&endp->queue_lock.slock,
2349 u132_endp_queue_work(u132, endp, 0);
2352 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2355 return create_endpoint_and_queue_control(u132,
2356 hep, urb, usb_dev, usb_addr, usb_endp,
2362 static int dequeue_from_overflow_chain(struct u132 *u132,
2363 struct u132_endp *endp, struct urb *urb)
2365 struct list_head *scan;
2366 struct list_head *head = &endp->urb_more;
2367 list_for_each(scan, head) {
2368 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2370 if (urbq->urb == urb) {
2371 struct usb_hcd *hcd = u132_to_hcd(u132);
2373 endp->queue_size -= 1;
2374 urb->error_count = 0;
2376 usb_hcd_giveback_urb(hcd, urb);
2381 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2382 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2383 "\n", urb, endp->endp_number, endp, endp->ring->number,
2384 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2385 endp->usb_endp, endp->usb_addr, endp->queue_size,
2386 endp->queue_next, endp->queue_last);
2390 static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2394 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2395 if (endp->queue_size == 0) {
2396 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2397 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2398 endp->endp_number, endp, endp->ring->number,
2399 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2400 endp->usb_endp, endp->usb_addr);
2401 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2404 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2406 endp->dequeueing = 1;
2407 endp->edset_flush = 1;
2408 u132_endp_queue_work(u132, endp, 0);
2409 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2413 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2414 u132_hcd_abandon_urb(u132, endp, urb, urb->status);
2419 u16 queue_size = endp->queue_size;
2420 u16 queue_scan = endp->queue_next;
2421 struct urb **urb_slot = NULL;
2422 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2423 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2425 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2431 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2432 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2434 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2438 struct usb_hcd *hcd = u132_to_hcd(u132);
2439 endp->queue_size -= 1;
2440 if (list_empty(&endp->urb_more)) {
2441 spin_unlock_irqrestore(&endp->queue_lock.slock,
2444 struct list_head *next = endp->urb_more.next;
2445 struct u132_urbq *urbq = list_entry(next,
2446 struct u132_urbq, urb_more);
2448 *urb_slot = urbq->urb;
2449 spin_unlock_irqrestore(&endp->queue_lock.slock,
2452 } urb->error_count = 0;
2454 usb_hcd_giveback_urb(hcd, urb);
2456 } else if (list_empty(&endp->urb_more)) {
2457 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2458 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2459 "=%d size=%d next=%04X last=%04X\n", urb,
2460 endp->endp_number, endp, endp->ring->number,
2461 endp->input ? 'I' : ' ',
2462 endp->output ? 'O' : ' ', endp->usb_endp,
2463 endp->usb_addr, endp->queue_size,
2464 endp->queue_next, endp->queue_last);
2465 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2468 int retval = dequeue_from_overflow_chain(u132, endp,
2470 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2476 static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
2478 struct u132 *u132 = hcd_to_u132(hcd);
2479 if (u132->going > 2) {
2480 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2484 u8 usb_addr = usb_pipedevice(urb->pipe);
2485 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2486 u8 address = u132->addr[usb_addr].address;
2487 struct u132_udev *udev = &u132->udev[address];
2488 if (usb_pipein(urb->pipe)) {
2489 u8 endp_number = udev->endp_number_in[usb_endp];
2490 struct u132_endp *endp = u132->endp[endp_number - 1];
2491 return u132_endp_urb_dequeue(u132, endp, urb);
2493 u8 endp_number = udev->endp_number_out[usb_endp];
2494 struct u132_endp *endp = u132->endp[endp_number - 1];
2495 return u132_endp_urb_dequeue(u132, endp, urb);
2500 static void u132_endpoint_disable(struct usb_hcd *hcd,
2501 struct usb_host_endpoint *hep)
2503 struct u132 *u132 = hcd_to_u132(hcd);
2504 if (u132->going > 2) {
2505 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2506 ") has been removed %d\n", u132, hcd, hep,
2509 struct u132_endp *endp = hep->hcpriv;
2511 u132_endp_put_kref(u132, endp);
2515 static int u132_get_frame(struct usb_hcd *hcd)
2517 struct u132 *u132 = hcd_to_u132(hcd);
2518 if (u132->going > 1) {
2519 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2522 } else if (u132->going > 0) {
2523 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2527 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2533 static int u132_roothub_descriptor(struct u132 *u132,
2534 struct usb_hub_descriptor *desc)
2540 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2543 desc->bDescriptorType = 0x29;
2544 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2545 desc->bHubContrCurrent = 0;
2546 desc->bNbrPorts = u132->num_ports;
2547 temp = 1 + (u132->num_ports / 8);
2548 desc->bDescLength = 7 + 2 *temp;
2550 if (rh_a & RH_A_NPS)
2552 if (rh_a & RH_A_PSM)
2554 if (rh_a & RH_A_NOCP) {
2556 } else if (rh_a & RH_A_OCPM)
2558 desc->wHubCharacteristics = cpu_to_le16(temp);
2559 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2562 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2563 desc->bitmap[0] = rh_b & RH_B_DR;
2564 if (u132->num_ports > 7) {
2565 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2566 desc->bitmap[2] = 0xff;
2568 desc->bitmap[1] = 0xff;
2572 static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2575 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2576 *desc = cpu_to_le32(rh_status);
2580 static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2582 if (wIndex == 0 || wIndex > u132->num_ports) {
2585 int port = wIndex - 1;
2586 u32 rh_portstatus = -1;
2587 int ret_portstatus = u132_read_pcimem(u132,
2588 roothub.portstatus[port], &rh_portstatus);
2589 *desc = cpu_to_le32(rh_portstatus);
2590 if (*(u16 *) (desc + 2)) {
2591 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2592 "ge = %08X\n", port, *desc);
2594 return ret_portstatus;
2599 /* this timer value might be vendor-specific ... */
2600 #define PORT_RESET_HW_MSEC 10
2601 #define PORT_RESET_MSEC 10
2602 /* wrap-aware logic morphed from <linux/jiffies.h> */
2603 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2604 static int u132_roothub_portreset(struct u132 *u132, int port_index)
2610 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2614 reset_done = now + PORT_RESET_MSEC;
2618 retval = u132_read_pcimem(u132,
2619 roothub.portstatus[port_index], &portstat);
2622 if (RH_PS_PRS & portstat) {
2626 } while (tick_before(now, reset_done));
2627 if (RH_PS_PRS & portstat)
2629 if (RH_PS_CCS & portstat) {
2630 if (RH_PS_PRSC & portstat) {
2631 retval = u132_write_pcimem(u132,
2632 roothub.portstatus[port_index],
2638 break; /* start the next reset,
2639 sleep till it's probably done */
2640 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2644 msleep(PORT_RESET_HW_MSEC);
2645 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2649 } while (tick_before(now, reset_done));
2653 static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2656 if (wIndex == 0 || wIndex > u132->num_ports) {
2660 int port_index = wIndex - 1;
2661 struct u132_port *port = &u132->port[port_index];
2662 port->Status &= ~(1 << wValue);
2664 case USB_PORT_FEAT_SUSPEND:
2665 retval = u132_write_pcimem(u132,
2666 roothub.portstatus[port_index], RH_PS_PSS);
2670 case USB_PORT_FEAT_POWER:
2671 retval = u132_write_pcimem(u132,
2672 roothub.portstatus[port_index], RH_PS_PPS);
2676 case USB_PORT_FEAT_RESET:
2677 retval = u132_roothub_portreset(u132, port_index);
2687 static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2690 if (wIndex == 0 || wIndex > u132->num_ports) {
2693 int port_index = wIndex - 1;
2696 struct u132_port *port = &u132->port[port_index];
2697 port->Status &= ~(1 << wValue);
2699 case USB_PORT_FEAT_ENABLE:
2702 case USB_PORT_FEAT_C_ENABLE:
2705 case USB_PORT_FEAT_SUSPEND:
2707 if ((u132->hc_control & OHCI_CTRL_HCFS)
2709 dev_err(&u132->platform_dev->dev, "TODO resume_"
2713 case USB_PORT_FEAT_C_SUSPEND:
2716 case USB_PORT_FEAT_POWER:
2719 case USB_PORT_FEAT_C_CONNECTION:
2722 case USB_PORT_FEAT_C_OVER_CURRENT:
2725 case USB_PORT_FEAT_C_RESET:
2731 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2740 /* the virtual root hub timer IRQ checks for hub status*/
2741 static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2743 struct u132 *u132 = hcd_to_u132(hcd);
2744 if (u132->going > 1) {
2745 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2746 "ed %d\n", hcd, u132->going);
2748 } else if (u132->going > 0) {
2749 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2753 int i, changed = 0, length = 1;
2754 if (u132->flags & OHCI_QUIRK_AMD756) {
2755 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2756 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2757 "ereads as NDP=%d\n",
2758 u132->hc_roothub_a & RH_A_NDP);
2762 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) {
2763 buf[0] = changed = 1;
2766 if (u132->num_ports > 7) {
2770 for (i = 0; i < u132->num_ports; i++) {
2771 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2772 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2776 buf[0] |= 1 << (i + 1);
2778 buf[1] |= 1 << (i - 7);
2781 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) {
2784 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) {
2788 done:return changed ? length : 0;
2792 static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2793 u16 wIndex, char *buf, u16 wLength)
2795 struct u132 *u132 = hcd_to_u132(hcd);
2796 if (u132->going > 1) {
2797 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2800 } else if (u132->going > 0) {
2801 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2805 down(&u132->sw_lock);
2807 case ClearHubFeature:
2809 case C_HUB_OVER_CURRENT:
2810 case C_HUB_LOCAL_POWER:
2818 case C_HUB_OVER_CURRENT:
2819 case C_HUB_LOCAL_POWER:
2825 case ClearPortFeature:{
2826 retval = u132_roothub_clearportfeature(u132,
2832 case GetHubDescriptor:{
2833 retval = u132_roothub_descriptor(u132,
2834 (struct usb_hub_descriptor *)buf);
2840 retval = u132_roothub_status(u132,
2846 case GetPortStatus:{
2847 retval = u132_roothub_portstatus(u132,
2848 (__le32 *) buf, wIndex);
2853 case SetPortFeature:{
2854 retval = u132_roothub_setportfeature(u132,
2862 error:u132_disable(u132);
2865 stall:retval = -EPIPE;
2873 static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2875 struct u132 *u132 = hcd_to_u132(hcd);
2876 if (u132->going > 1) {
2877 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2880 } else if (u132->going > 0) {
2881 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2887 static void u132_hub_irq_enable(struct usb_hcd *hcd)
2889 struct u132 *u132 = hcd_to_u132(hcd);
2890 if (u132->going > 1) {
2891 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2893 } else if (u132->going > 0)
2894 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2899 static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2901 struct u132 *u132 = hcd_to_u132(hcd);
2902 if (u132->going > 1) {
2903 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2906 } else if (u132->going > 0) {
2907 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2913 static int u132_hcd_resume(struct usb_hcd *hcd)
2915 struct u132 *u132 = hcd_to_u132(hcd);
2916 if (u132->going > 1) {
2917 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2920 } else if (u132->going > 0) {
2921 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2927 static int u132_bus_suspend(struct usb_hcd *hcd)
2929 struct u132 *u132 = hcd_to_u132(hcd);
2930 if (u132->going > 1) {
2931 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2934 } else if (u132->going > 0) {
2935 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2941 static int u132_bus_resume(struct usb_hcd *hcd)
2943 struct u132 *u132 = hcd_to_u132(hcd);
2944 if (u132->going > 1) {
2945 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2948 } else if (u132->going > 0) {
2949 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2956 #define u132_hcd_suspend NULL
2957 #define u132_hcd_resume NULL
2958 #define u132_bus_suspend NULL
2959 #define u132_bus_resume NULL
2961 static struct hc_driver u132_hc_driver = {
2962 .description = hcd_name,
2963 .hcd_priv_size = sizeof(struct u132),
2965 .flags = HCD_USB11 | HCD_MEMORY,
2966 .reset = u132_hcd_reset,
2967 .start = u132_hcd_start,
2968 .suspend = u132_hcd_suspend,
2969 .resume = u132_hcd_resume,
2970 .stop = u132_hcd_stop,
2971 .urb_enqueue = u132_urb_enqueue,
2972 .urb_dequeue = u132_urb_dequeue,
2973 .endpoint_disable = u132_endpoint_disable,
2974 .get_frame_number = u132_get_frame,
2975 .hub_status_data = u132_hub_status_data,
2976 .hub_control = u132_hub_control,
2977 .bus_suspend = u132_bus_suspend,
2978 .bus_resume = u132_bus_resume,
2979 .start_port_reset = u132_start_port_reset,
2980 .hub_irq_enable = u132_hub_irq_enable,
2984 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
2985 * is held for writing, thus this module must not call usb_remove_hcd()
2986 * synchronously - but instead should immediately stop activity to the
2987 * device and asynchronously call usb_remove_hcd()
2989 static int __devexit u132_remove(struct platform_device *pdev)
2991 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2993 struct u132 *u132 = hcd_to_u132(hcd);
2994 if (u132->going++ > 1) {
2995 dev_err(&u132->platform_dev->dev, "already being remove"
2999 int rings = MAX_U132_RINGS;
3000 int endps = MAX_U132_ENDPS;
3001 dev_err(&u132->platform_dev->dev, "removing device u132"
3002 ".%d\n", u132->sequence_num);
3004 down(&u132->sw_lock);
3005 u132_monitor_cancel_work(u132);
3006 while (rings-- > 0) {
3007 struct u132_ring *ring = &u132->ring[rings];
3008 u132_ring_cancel_work(u132, ring);
3009 } while (endps-- > 0) {
3010 struct u132_endp *endp = u132->endp[endps];
3012 u132_endp_cancel_work(u132, endp);
3015 printk(KERN_INFO "removing device u132.%d\n",
3016 u132->sequence_num);
3018 usb_remove_hcd(hcd);
3019 u132_u132_put_kref(u132);
3026 static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3028 int rings = MAX_U132_RINGS;
3029 int ports = MAX_U132_PORTS;
3030 int addrs = MAX_U132_ADDRS;
3031 int udevs = MAX_U132_UDEVS;
3032 int endps = MAX_U132_ENDPS;
3033 u132->board = pdev->dev.platform_data;
3034 u132->platform_dev = pdev;
3037 init_MUTEX(&u132->sw_lock);
3038 init_MUTEX(&u132->scheduler_lock);
3039 while (rings-- > 0) {
3040 struct u132_ring *ring = &u132->ring[rings];
3042 ring->number = rings + 1;
3044 ring->curr_endp = NULL;
3045 INIT_DELAYED_WORK(&ring->scheduler,
3046 u132_hcd_ring_work_scheduler);
3047 } down(&u132->sw_lock);
3048 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3049 while (ports-- > 0) {
3050 struct u132_port *port = &u132->port[ports];
3056 } while (addrs-- > 0) {
3057 struct u132_addr *addr = &u132->addr[addrs];
3059 } while (udevs-- > 0) {
3060 struct u132_udev *udev = &u132->udev[udevs];
3061 int i = ARRAY_SIZE(udev->endp_number_in);
3062 int o = ARRAY_SIZE(udev->endp_number_out);
3063 udev->usb_device = NULL;
3064 udev->udev_number = 0;
3066 udev->portnumber = 0;
3068 udev->endp_number_in[i] = 0;
3071 udev->endp_number_out[o] = 0;
3074 while (endps-- > 0) {
3075 u132->endp[endps] = NULL;
3081 static int __devinit u132_probe(struct platform_device *pdev)
3083 struct usb_hcd *hcd;
3089 if (u132_exiting > 0) {
3092 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3095 retval = ftdi_read_pcimem(pdev, control, &control);
3098 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3101 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3102 if (pdev->dev.dma_mask) {
3105 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3107 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3109 ftdi_elan_gone_away(pdev);
3113 struct u132 *u132 = hcd_to_u132(hcd);
3114 hcd->rsrc_start = 0;
3115 mutex_lock(&u132_module_lock);
3116 list_add_tail(&u132->u132_list, &u132_static_list);
3117 u132->sequence_num = ++u132_instances;
3118 mutex_unlock(&u132_module_lock);
3119 u132_u132_init_kref(u132);
3120 u132_initialise(u132, pdev);
3121 hcd->product_desc = "ELAN U132 Host Controller";
3122 retval = usb_add_hcd(hcd, 0, 0);
3124 dev_err(&u132->platform_dev->dev, "init error %d\n",
3126 u132_u132_put_kref(u132);
3129 u132_monitor_queue_work(u132, 100);
3137 /* for this device there's no useful distinction between the controller
3138 * and its root hub, except that the root hub only gets direct PM calls
3139 * when CONFIG_USB_SUSPEND is enabled.
3141 static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3143 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3144 struct u132 *u132 = hcd_to_u132(hcd);
3145 if (u132->going > 1) {
3146 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3149 } else if (u132->going > 0) {
3150 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3154 if (state.event == PM_EVENT_FREEZE) {
3155 retval = u132_bus_suspend(hcd);
3156 } else if (state.event == PM_EVENT_SUSPEND) {
3157 int ports = MAX_U132_PORTS;
3158 while (ports-- > 0) {
3159 port_power(u132, ports, 0);
3163 pdev->dev.power.power_state = state;
3168 static int u132_resume(struct platform_device *pdev)
3170 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3171 struct u132 *u132 = hcd_to_u132(hcd);
3172 if (u132->going > 1) {
3173 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3176 } else if (u132->going > 0) {
3177 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3181 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
3182 int ports = MAX_U132_PORTS;
3183 while (ports-- > 0) {
3184 port_power(u132, ports, 1);
3188 pdev->dev.power.power_state = PMSG_ON;
3189 retval = u132_bus_resume(hcd);
3196 #define u132_suspend NULL
3197 #define u132_resume NULL
3200 * this driver is loaded explicitly by ftdi_u132
3202 * the platform_driver struct is static because it is per type of module
3204 static struct platform_driver u132_platform_driver = {
3205 .probe = u132_probe,
3206 .remove = __devexit_p(u132_remove),
3207 .suspend = u132_suspend,
3208 .resume = u132_resume,
3210 .name = (char *)hcd_name,
3211 .owner = THIS_MODULE,
3214 static int __init u132_hcd_init(void)
3217 INIT_LIST_HEAD(&u132_static_list);
3220 mutex_init(&u132_module_lock);
3223 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3225 workqueue = create_singlethread_workqueue("u132");
3226 retval = platform_driver_register(&u132_platform_driver);
3231 module_init(u132_hcd_init);
3232 static void __exit u132_hcd_exit(void)
3236 mutex_lock(&u132_module_lock);
3238 mutex_unlock(&u132_module_lock);
3239 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3240 platform_device_unregister(u132->platform_dev);
3241 } platform_driver_unregister(&u132_platform_driver);
3242 printk(KERN_INFO "u132-hcd driver deregistered\n");
3243 wait_event(u132_hcd_wait, u132_instances == 0);
3244 flush_workqueue(workqueue);
3245 destroy_workqueue(workqueue);
3249 module_exit(u132_hcd_exit);
3250 MODULE_LICENSE("GPL");