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,
1525 static void port_power(struct u132 *u132, int pn, int is_on)
1527 u132->port[pn].power = is_on;
1532 static void u132_power(struct u132 *u132, int is_on)
1534 struct usb_hcd *hcd = u132_to_hcd(u132)
1535 ; /* hub is inactive unless the port is powered */
1540 hcd->self.controller->power.power_state = PMSG_ON;
1543 hcd->state = HC_STATE_HALT;
1544 hcd->self.controller->power.power_state = PMSG_SUSPEND;
1548 static int u132_periodic_reinit(struct u132 *u132)
1551 u32 fi = u132->hc_fminterval & 0x03fff;
1554 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1557 fit = fminterval & FIT;
1558 retval = u132_write_pcimem(u132, fminterval,
1559 (fit ^ FIT) | u132->hc_fminterval);
1562 retval = u132_write_pcimem(u132, periodicstart,
1563 ((9 *fi) / 10) & 0x3fff);
1569 static char *hcfs2string(int state)
1572 case OHCI_USB_RESET:
1574 case OHCI_USB_RESUME:
1577 return "operational";
1578 case OHCI_USB_SUSPEND:
1584 static int u132_init(struct u132 *u132)
1589 u132->next_statechange = jiffies;
1590 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1593 retval = u132_read_pcimem(u132, control, &control);
1596 if (u132->num_ports == 0) {
1598 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1601 u132->num_ports = rh_a & RH_A_NDP;
1602 retval = read_roothub_info(u132);
1606 if (u132->num_ports > MAX_U132_PORTS) {
1613 /* Start an OHCI controller, set the BUS operational
1614 * resets USB and controller
1617 static int u132_run(struct u132 *u132)
1626 int mask = OHCI_INTR_INIT;
1627 int first = u132->hc_fminterval == 0;
1629 int reset_timeout = 30; /* ... allow extra time */
1633 retval = u132_read_pcimem(u132, fminterval, &temp);
1636 u132->hc_fminterval = temp & 0x3fff;
1637 if (u132->hc_fminterval != FI) {
1639 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1641 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1644 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1645 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1647 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1651 case OHCI_USB_SUSPEND:
1652 case OHCI_USB_RESUME:
1653 u132->hc_control &= OHCI_CTRL_RWC;
1654 u132->hc_control |= OHCI_USB_RESUME;
1658 u132->hc_control &= OHCI_CTRL_RWC;
1659 u132->hc_control |= OHCI_USB_RESET;
1663 retval = u132_write_pcimem(u132, control, u132->hc_control);
1666 retval = u132_read_pcimem(u132, control, &control);
1670 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1673 if (!(roothub_a & RH_A_NPS)) {
1674 int temp; /* power down each port */
1675 for (temp = 0; temp < u132->num_ports; temp++) {
1676 retval = u132_write_pcimem(u132,
1677 roothub.portstatus[temp], RH_PS_LSDA);
1682 retval = u132_read_pcimem(u132, control, &control);
1685 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1688 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1692 retval = u132_read_pcimem(u132, cmdstatus, &status);
1695 if (0 != (status & OHCI_HCR)) {
1696 if (--reset_timeout == 0) {
1697 dev_err(&u132->platform_dev->dev, "USB HC reset"
1706 if (u132->flags & OHCI_QUIRK_INITRESET) {
1707 retval = u132_write_pcimem(u132, control, u132->hc_control);
1710 retval = u132_read_pcimem(u132, control, &control);
1714 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1717 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1720 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1723 retval = u132_periodic_reinit(u132);
1726 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1729 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1732 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1733 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1734 u132->flags |= OHCI_QUIRK_INITRESET;
1737 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1738 "\n", fminterval, periodicstart);
1739 } /* start controller operations */
1740 u132->hc_control &= OHCI_CTRL_RWC;
1741 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1742 retval = u132_write_pcimem(u132, control, u132->hc_control);
1745 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1748 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1751 retval = u132_read_pcimem(u132, control, &control);
1754 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1755 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1758 retval = u132_write_pcimem(u132, intrstatus, mask);
1761 retval = u132_write_pcimem(u132, intrdisable,
1762 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1763 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1766 return retval; /* handle root hub init quirks ... */
1767 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1770 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1771 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1772 roothub_a |= RH_A_NOCP;
1773 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1774 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1777 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1778 roothub_a |= RH_A_NPS;
1779 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1783 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1786 retval = u132_write_pcimem(u132, roothub.b,
1787 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1790 retval = u132_read_pcimem(u132, control, &control);
1793 mdelay((roothub_a >> 23) & 0x1fe);
1794 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1798 static void u132_hcd_stop(struct usb_hcd *hcd)
1800 struct u132 *u132 = hcd_to_u132(hcd);
1801 if (u132->going > 1) {
1802 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1803 "een removed %d\n", u132, hcd, u132->going);
1804 } else if (u132->going > 0) {
1805 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1808 down(&u132->sw_lock);
1810 u132_power(u132, 0);
1815 static int u132_hcd_start(struct usb_hcd *hcd)
1817 struct u132 *u132 = hcd_to_u132(hcd);
1818 if (u132->going > 1) {
1819 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1822 } else if (u132->going > 0) {
1823 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1825 } else if (hcd->self.controller) {
1827 struct platform_device *pdev =
1828 to_platform_device(hcd->self.controller);
1829 u16 vendor = ((struct u132_platform_data *)
1830 (pdev->dev.platform_data))->vendor;
1831 u16 device = ((struct u132_platform_data *)
1832 (pdev->dev.platform_data))->device;
1833 down(&u132->sw_lock);
1835 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1836 u132->flags = OHCI_QUIRK_AMD756;
1837 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1838 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1839 "ounds unavailable\n");
1840 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1841 u132->flags |= OHCI_QUIRK_ZFMICRO;
1842 retval = u132_run(u132);
1851 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1856 static int u132_hcd_reset(struct usb_hcd *hcd)
1858 struct u132 *u132 = hcd_to_u132(hcd);
1859 if (u132->going > 1) {
1860 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1863 } else if (u132->going > 0) {
1864 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1868 down(&u132->sw_lock);
1869 retval = u132_init(u132);
1879 static int create_endpoint_and_queue_int(struct u132 *u132,
1880 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1881 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1884 struct u132_ring *ring;
1886 u8 endp_number = ++u132->num_endpoints;
1887 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1888 kmalloc(sizeof(struct u132_endp), mem_flags);
1892 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1893 spin_lock_init(&endp->queue_lock.slock);
1894 INIT_LIST_HEAD(&endp->urb_more);
1895 ring = endp->ring = &u132->ring[0];
1896 if (ring->curr_endp) {
1897 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1899 INIT_LIST_HEAD(&endp->endp_ring);
1900 ring->curr_endp = endp;
1903 endp->dequeueing = 0;
1904 endp->edset_flush = 0;
1907 endp->endp_number = endp_number;
1910 endp->pipetype = usb_pipetype(urb->pipe);
1911 u132_endp_init_kref(u132, endp);
1912 if (usb_pipein(urb->pipe)) {
1913 endp->toggle_bits = 0x2;
1914 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1917 udev->endp_number_in[usb_endp] = endp_number;
1918 u132_udev_get_kref(u132, udev);
1920 endp->toggle_bits = 0x2;
1921 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1924 udev->endp_number_out[usb_endp] = endp_number;
1925 u132_udev_get_kref(u132, udev);
1928 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1930 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1931 endp->udev_number = address;
1932 endp->usb_addr = usb_addr;
1933 endp->usb_endp = usb_endp;
1934 endp->queue_size = 1;
1935 endp->queue_last = 0;
1936 endp->queue_next = 0;
1937 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1938 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1939 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1943 static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
1944 struct usb_host_endpoint *hep, struct urb *urb,
1945 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1946 u8 usb_endp, u8 address)
1950 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1951 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1952 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1954 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1957 endp->queue_size -= 1;
1960 list_add_tail(&urbq->urb_more, &endp->urb_more);
1967 static int create_endpoint_and_queue_bulk(struct u132 *u132,
1968 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1969 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1973 struct u132_ring *ring;
1975 u8 endp_number = ++u132->num_endpoints;
1976 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1977 kmalloc(sizeof(struct u132_endp), mem_flags);
1981 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1982 spin_lock_init(&endp->queue_lock.slock);
1983 INIT_LIST_HEAD(&endp->urb_more);
1984 endp->dequeueing = 0;
1985 endp->edset_flush = 0;
1988 endp->endp_number = endp_number;
1991 endp->pipetype = usb_pipetype(urb->pipe);
1992 u132_endp_init_kref(u132, endp);
1993 if (usb_pipein(urb->pipe)) {
1994 endp->toggle_bits = 0x2;
1995 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1999 udev->endp_number_in[usb_endp] = endp_number;
2000 u132_udev_get_kref(u132, udev);
2002 endp->toggle_bits = 0x2;
2003 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2007 udev->endp_number_out[usb_endp] = endp_number;
2008 u132_udev_get_kref(u132, udev);
2010 ring = endp->ring = &u132->ring[ring_number - 1];
2011 if (ring->curr_endp) {
2012 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2014 INIT_LIST_HEAD(&endp->endp_ring);
2015 ring->curr_endp = endp;
2019 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2020 endp->udev_number = address;
2021 endp->usb_addr = usb_addr;
2022 endp->usb_endp = usb_endp;
2023 endp->queue_size = 1;
2024 endp->queue_last = 0;
2025 endp->queue_next = 0;
2026 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2027 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2028 u132_endp_queue_work(u132, endp, 0);
2032 static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2033 struct usb_host_endpoint *hep, struct urb *urb,
2034 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2035 u8 usb_endp, u8 address)
2038 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2039 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2041 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2044 endp->queue_size -= 1;
2047 list_add_tail(&urbq->urb_more, &endp->urb_more);
2054 static int create_endpoint_and_queue_control(struct u132 *u132,
2055 struct usb_host_endpoint *hep, struct urb *urb,
2056 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2059 struct u132_ring *ring;
2060 u8 endp_number = ++u132->num_endpoints;
2061 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
2062 kmalloc(sizeof(struct u132_endp), mem_flags);
2066 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2067 spin_lock_init(&endp->queue_lock.slock);
2068 INIT_LIST_HEAD(&endp->urb_more);
2069 ring = endp->ring = &u132->ring[0];
2070 if (ring->curr_endp) {
2071 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2073 INIT_LIST_HEAD(&endp->endp_ring);
2074 ring->curr_endp = endp;
2077 endp->dequeueing = 0;
2078 endp->edset_flush = 0;
2081 endp->endp_number = endp_number;
2084 u132_endp_init_kref(u132, endp);
2085 u132_endp_get_kref(u132, endp);
2086 if (usb_addr == 0) {
2088 u8 address = u132->addr[usb_addr].address;
2089 struct u132_udev *udev = &u132->udev[address];
2090 endp->udev_number = address;
2091 endp->usb_addr = usb_addr;
2092 endp->usb_endp = usb_endp;
2095 endp->pipetype = usb_pipetype(urb->pipe);
2096 u132_udev_init_kref(u132, udev);
2097 u132_udev_get_kref(u132, udev);
2098 udev->endp_number_in[usb_endp] = endp_number;
2099 udev->endp_number_out[usb_endp] = endp_number;
2101 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2102 endp->queue_size = 1;
2103 endp->queue_last = 0;
2104 endp->queue_next = 0;
2105 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2106 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2107 u132_endp_queue_work(u132, endp, 0);
2109 } else { /*(usb_addr > 0) */
2111 u8 address = u132->addr[usb_addr].address;
2112 struct u132_udev *udev = &u132->udev[address];
2113 endp->udev_number = address;
2114 endp->usb_addr = usb_addr;
2115 endp->usb_endp = usb_endp;
2118 endp->pipetype = usb_pipetype(urb->pipe);
2119 u132_udev_get_kref(u132, udev);
2120 udev->enumeration = 2;
2121 udev->endp_number_in[usb_endp] = endp_number;
2122 udev->endp_number_out[usb_endp] = endp_number;
2124 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2125 endp->queue_size = 1;
2126 endp->queue_last = 0;
2127 endp->queue_next = 0;
2128 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2129 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2130 u132_endp_queue_work(u132, endp, 0);
2135 static int queue_control_on_old_endpoint(struct u132 *u132,
2136 struct usb_host_endpoint *hep, struct urb *urb,
2137 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2140 if (usb_addr == 0) {
2141 if (usb_pipein(urb->pipe)) {
2143 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2144 endp->urb_list[ENDP_QUEUE_MASK &
2145 endp->queue_last++] = urb;
2147 struct u132_urbq *urbq =
2148 kmalloc(sizeof(struct u132_urbq),
2151 endp->queue_size -= 1;
2154 list_add_tail(&urbq->urb_more,
2160 } else { /* usb_pipeout(urb->pipe) */
2161 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2162 int I = MAX_U132_UDEVS;
2165 struct u132_udev *udev = &u132->udev[++i];
2166 if (udev->usb_device) {
2169 udev->enumeration = 1;
2170 u132->addr[0].address = i;
2171 endp->udev_number = i;
2172 udev->udev_number = i;
2173 udev->usb_addr = usb_dev->devnum;
2174 u132_udev_init_kref(u132, udev);
2175 udev->endp_number_in[usb_endp] =
2177 u132_udev_get_kref(u132, udev);
2178 udev->endp_number_out[usb_endp] =
2180 udev->usb_device = usb_dev;
2181 ((u8 *) (urb->setup_packet))[2] =
2183 u132_udev_get_kref(u132, udev);
2188 dev_err(&u132->platform_dev->dev, "run out of d"
2193 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2194 endp->urb_list[ENDP_QUEUE_MASK &
2195 endp->queue_last++] = urb;
2197 struct u132_urbq *urbq =
2198 kmalloc(sizeof(struct u132_urbq),
2201 endp->queue_size -= 1;
2204 list_add_tail(&urbq->urb_more,
2211 } else { /*(usb_addr > 0) */
2212 u8 address = u132->addr[usb_addr].address;
2213 struct u132_udev *udev = &u132->udev[address];
2215 if (udev->enumeration == 2) {
2217 udev->enumeration = 2;
2218 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2219 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2222 struct u132_urbq *urbq =
2223 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2225 endp->queue_size -= 1;
2228 list_add_tail(&urbq->urb_more, &endp->urb_more);
2236 static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2237 struct urb *urb, gfp_t mem_flags)
2239 struct u132 *u132 = hcd_to_u132(hcd);
2240 if (irqs_disabled()) {
2241 if (__GFP_WAIT & mem_flags) {
2242 printk(KERN_ERR "invalid context for function that migh"
2247 if (u132->going > 1) {
2248 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2251 } else if (u132->going > 0) {
2252 dev_err(&u132->platform_dev->dev, "device is being removed urb="
2253 "%p status=%d\n", urb, urb->status);
2256 u8 usb_addr = usb_pipedevice(urb->pipe);
2257 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2258 struct usb_device *usb_dev = urb->dev;
2259 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2260 u8 address = u132->addr[usb_addr].address;
2261 struct u132_udev *udev = &u132->udev[address];
2262 struct u132_endp *endp = hep->hcpriv;
2263 urb->actual_length = 0;
2267 spin_lock_irqsave(&endp->queue_lock.slock,
2269 retval = queue_int_on_old_endpoint(u132, udev,
2270 hep, urb, usb_dev, endp, usb_addr,
2272 spin_unlock_irqrestore(&endp->queue_lock.slock,
2277 u132_endp_queue_work(u132, endp,
2278 msecs_to_jiffies(urb->interval))
2282 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2284 } else { /*(endp == NULL) */
2285 return create_endpoint_and_queue_int(u132, udev,
2286 hep, urb, usb_dev, usb_addr, usb_endp,
2287 address, mem_flags);
2289 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2290 dev_err(&u132->platform_dev->dev, "the hardware does no"
2291 "t support PIPE_ISOCHRONOUS\n");
2293 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2294 u8 address = u132->addr[usb_addr].address;
2295 struct u132_udev *udev = &u132->udev[address];
2296 struct u132_endp *endp = hep->hcpriv;
2297 urb->actual_length = 0;
2301 spin_lock_irqsave(&endp->queue_lock.slock,
2303 retval = queue_bulk_on_old_endpoint(u132, udev,
2304 hep, urb, usb_dev, endp, usb_addr,
2306 spin_unlock_irqrestore(&endp->queue_lock.slock,
2311 u132_endp_queue_work(u132, endp, 0);
2314 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2317 return create_endpoint_and_queue_bulk(u132,
2318 udev, hep, urb, usb_dev, usb_addr,
2319 usb_endp, address, mem_flags);
2321 struct u132_endp *endp = hep->hcpriv;
2323 u8 *b = urb->setup_packet;
2325 char data[30 *3 + 4];
2327 int m = (sizeof(data) - 1) / 3;
2330 while (urb_size-- > 0) {
2332 } else if (i++ < m) {
2333 int w = sprintf(d, " %02X", *b++);
2337 d += sprintf(d, " ..");
2342 spin_lock_irqsave(&endp->queue_lock.slock,
2344 retval = queue_control_on_old_endpoint(u132,
2345 hep, urb, usb_dev, endp, usb_addr,
2347 spin_unlock_irqrestore(&endp->queue_lock.slock,
2352 u132_endp_queue_work(u132, endp, 0);
2355 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2358 return create_endpoint_and_queue_control(u132,
2359 hep, urb, usb_dev, usb_addr, usb_endp,
2365 static int dequeue_from_overflow_chain(struct u132 *u132,
2366 struct u132_endp *endp, struct urb *urb)
2368 struct list_head *scan;
2369 struct list_head *head = &endp->urb_more;
2370 list_for_each(scan, head) {
2371 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2373 if (urbq->urb == urb) {
2374 struct usb_hcd *hcd = u132_to_hcd(u132);
2376 endp->queue_size -= 1;
2377 urb->error_count = 0;
2379 usb_hcd_giveback_urb(hcd, urb);
2384 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2385 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2386 "\n", urb, endp->endp_number, endp, endp->ring->number,
2387 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2388 endp->usb_endp, endp->usb_addr, endp->queue_size,
2389 endp->queue_next, endp->queue_last);
2393 static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2397 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2398 if (endp->queue_size == 0) {
2399 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2400 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2401 endp->endp_number, endp, endp->ring->number,
2402 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2403 endp->usb_endp, endp->usb_addr);
2404 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2407 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2409 endp->dequeueing = 1;
2410 endp->edset_flush = 1;
2411 u132_endp_queue_work(u132, endp, 0);
2412 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2416 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2417 u132_hcd_abandon_urb(u132, endp, urb, urb->status);
2422 u16 queue_size = endp->queue_size;
2423 u16 queue_scan = endp->queue_next;
2424 struct urb **urb_slot = NULL;
2425 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2426 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2428 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2434 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2435 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2437 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2441 struct usb_hcd *hcd = u132_to_hcd(u132);
2442 endp->queue_size -= 1;
2443 if (list_empty(&endp->urb_more)) {
2444 spin_unlock_irqrestore(&endp->queue_lock.slock,
2447 struct list_head *next = endp->urb_more.next;
2448 struct u132_urbq *urbq = list_entry(next,
2449 struct u132_urbq, urb_more);
2451 *urb_slot = urbq->urb;
2452 spin_unlock_irqrestore(&endp->queue_lock.slock,
2455 } urb->error_count = 0;
2457 usb_hcd_giveback_urb(hcd, urb);
2459 } else if (list_empty(&endp->urb_more)) {
2460 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2461 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2462 "=%d size=%d next=%04X last=%04X\n", urb,
2463 endp->endp_number, endp, endp->ring->number,
2464 endp->input ? 'I' : ' ',
2465 endp->output ? 'O' : ' ', endp->usb_endp,
2466 endp->usb_addr, endp->queue_size,
2467 endp->queue_next, endp->queue_last);
2468 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2471 int retval = dequeue_from_overflow_chain(u132, endp,
2473 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2479 static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
2481 struct u132 *u132 = hcd_to_u132(hcd);
2482 if (u132->going > 2) {
2483 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2487 u8 usb_addr = usb_pipedevice(urb->pipe);
2488 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2489 u8 address = u132->addr[usb_addr].address;
2490 struct u132_udev *udev = &u132->udev[address];
2491 if (usb_pipein(urb->pipe)) {
2492 u8 endp_number = udev->endp_number_in[usb_endp];
2493 struct u132_endp *endp = u132->endp[endp_number - 1];
2494 return u132_endp_urb_dequeue(u132, endp, urb);
2496 u8 endp_number = udev->endp_number_out[usb_endp];
2497 struct u132_endp *endp = u132->endp[endp_number - 1];
2498 return u132_endp_urb_dequeue(u132, endp, urb);
2503 static void u132_endpoint_disable(struct usb_hcd *hcd,
2504 struct usb_host_endpoint *hep)
2506 struct u132 *u132 = hcd_to_u132(hcd);
2507 if (u132->going > 2) {
2508 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2509 ") has been removed %d\n", u132, hcd, hep,
2512 struct u132_endp *endp = hep->hcpriv;
2514 u132_endp_put_kref(u132, endp);
2518 static int u132_get_frame(struct usb_hcd *hcd)
2520 struct u132 *u132 = hcd_to_u132(hcd);
2521 if (u132->going > 1) {
2522 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2525 } else if (u132->going > 0) {
2526 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2530 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2536 static int u132_roothub_descriptor(struct u132 *u132,
2537 struct usb_hub_descriptor *desc)
2543 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2546 desc->bDescriptorType = 0x29;
2547 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2548 desc->bHubContrCurrent = 0;
2549 desc->bNbrPorts = u132->num_ports;
2550 temp = 1 + (u132->num_ports / 8);
2551 desc->bDescLength = 7 + 2 *temp;
2553 if (rh_a & RH_A_NPS)
2555 if (rh_a & RH_A_PSM)
2557 if (rh_a & RH_A_NOCP) {
2559 } else if (rh_a & RH_A_OCPM)
2561 desc->wHubCharacteristics = cpu_to_le16(temp);
2562 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2565 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2566 desc->bitmap[0] = rh_b & RH_B_DR;
2567 if (u132->num_ports > 7) {
2568 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2569 desc->bitmap[2] = 0xff;
2571 desc->bitmap[1] = 0xff;
2575 static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2578 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2579 *desc = cpu_to_le32(rh_status);
2583 static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2585 if (wIndex == 0 || wIndex > u132->num_ports) {
2588 int port = wIndex - 1;
2589 u32 rh_portstatus = -1;
2590 int ret_portstatus = u132_read_pcimem(u132,
2591 roothub.portstatus[port], &rh_portstatus);
2592 *desc = cpu_to_le32(rh_portstatus);
2593 if (*(u16 *) (desc + 2)) {
2594 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2595 "ge = %08X\n", port, *desc);
2597 return ret_portstatus;
2602 /* this timer value might be vendor-specific ... */
2603 #define PORT_RESET_HW_MSEC 10
2604 #define PORT_RESET_MSEC 10
2605 /* wrap-aware logic morphed from <linux/jiffies.h> */
2606 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2607 static int u132_roothub_portreset(struct u132 *u132, int port_index)
2613 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2617 reset_done = now + PORT_RESET_MSEC;
2621 retval = u132_read_pcimem(u132,
2622 roothub.portstatus[port_index], &portstat);
2625 if (RH_PS_PRS & portstat) {
2629 } while (tick_before(now, reset_done));
2630 if (RH_PS_PRS & portstat)
2632 if (RH_PS_CCS & portstat) {
2633 if (RH_PS_PRSC & portstat) {
2634 retval = u132_write_pcimem(u132,
2635 roothub.portstatus[port_index],
2641 break; /* start the next reset,
2642 sleep till it's probably done */
2643 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2647 msleep(PORT_RESET_HW_MSEC);
2648 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2652 } while (tick_before(now, reset_done));
2656 static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2659 if (wIndex == 0 || wIndex > u132->num_ports) {
2663 int port_index = wIndex - 1;
2664 struct u132_port *port = &u132->port[port_index];
2665 port->Status &= ~(1 << wValue);
2667 case USB_PORT_FEAT_SUSPEND:
2668 retval = u132_write_pcimem(u132,
2669 roothub.portstatus[port_index], RH_PS_PSS);
2673 case USB_PORT_FEAT_POWER:
2674 retval = u132_write_pcimem(u132,
2675 roothub.portstatus[port_index], RH_PS_PPS);
2679 case USB_PORT_FEAT_RESET:
2680 retval = u132_roothub_portreset(u132, port_index);
2690 static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2693 if (wIndex == 0 || wIndex > u132->num_ports) {
2696 int port_index = wIndex - 1;
2699 struct u132_port *port = &u132->port[port_index];
2700 port->Status &= ~(1 << wValue);
2702 case USB_PORT_FEAT_ENABLE:
2705 case USB_PORT_FEAT_C_ENABLE:
2708 case USB_PORT_FEAT_SUSPEND:
2710 if ((u132->hc_control & OHCI_CTRL_HCFS)
2712 dev_err(&u132->platform_dev->dev, "TODO resume_"
2716 case USB_PORT_FEAT_C_SUSPEND:
2719 case USB_PORT_FEAT_POWER:
2722 case USB_PORT_FEAT_C_CONNECTION:
2725 case USB_PORT_FEAT_C_OVER_CURRENT:
2728 case USB_PORT_FEAT_C_RESET:
2734 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2743 /* the virtual root hub timer IRQ checks for hub status*/
2744 static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2746 struct u132 *u132 = hcd_to_u132(hcd);
2747 if (u132->going > 1) {
2748 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2749 "ed %d\n", hcd, u132->going);
2751 } else if (u132->going > 0) {
2752 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2756 int i, changed = 0, length = 1;
2757 if (u132->flags & OHCI_QUIRK_AMD756) {
2758 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2759 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2760 "ereads as NDP=%d\n",
2761 u132->hc_roothub_a & RH_A_NDP);
2765 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) {
2766 buf[0] = changed = 1;
2769 if (u132->num_ports > 7) {
2773 for (i = 0; i < u132->num_ports; i++) {
2774 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2775 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2779 buf[0] |= 1 << (i + 1);
2781 buf[1] |= 1 << (i - 7);
2784 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) {
2787 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) {
2791 done:return changed ? length : 0;
2795 static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2796 u16 wIndex, char *buf, u16 wLength)
2798 struct u132 *u132 = hcd_to_u132(hcd);
2799 if (u132->going > 1) {
2800 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2803 } else if (u132->going > 0) {
2804 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2808 down(&u132->sw_lock);
2810 case ClearHubFeature:
2812 case C_HUB_OVER_CURRENT:
2813 case C_HUB_LOCAL_POWER:
2821 case C_HUB_OVER_CURRENT:
2822 case C_HUB_LOCAL_POWER:
2828 case ClearPortFeature:{
2829 retval = u132_roothub_clearportfeature(u132,
2835 case GetHubDescriptor:{
2836 retval = u132_roothub_descriptor(u132,
2837 (struct usb_hub_descriptor *)buf);
2843 retval = u132_roothub_status(u132,
2849 case GetPortStatus:{
2850 retval = u132_roothub_portstatus(u132,
2851 (__le32 *) buf, wIndex);
2856 case SetPortFeature:{
2857 retval = u132_roothub_setportfeature(u132,
2865 error:u132_disable(u132);
2868 stall:retval = -EPIPE;
2876 static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2878 struct u132 *u132 = hcd_to_u132(hcd);
2879 if (u132->going > 1) {
2880 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2883 } else if (u132->going > 0) {
2884 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2890 static void u132_hub_irq_enable(struct usb_hcd *hcd)
2892 struct u132 *u132 = hcd_to_u132(hcd);
2893 if (u132->going > 1) {
2894 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2896 } else if (u132->going > 0)
2897 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2902 static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2904 struct u132 *u132 = hcd_to_u132(hcd);
2905 if (u132->going > 1) {
2906 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2909 } else if (u132->going > 0) {
2910 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2916 static int u132_hcd_resume(struct usb_hcd *hcd)
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 int u132_bus_suspend(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"
2937 } else if (u132->going > 0) {
2938 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2944 static int u132_bus_resume(struct usb_hcd *hcd)
2946 struct u132 *u132 = hcd_to_u132(hcd);
2947 if (u132->going > 1) {
2948 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2951 } else if (u132->going > 0) {
2952 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2959 #define u132_hcd_suspend NULL
2960 #define u132_hcd_resume NULL
2961 #define u132_bus_suspend NULL
2962 #define u132_bus_resume NULL
2964 static struct hc_driver u132_hc_driver = {
2965 .description = hcd_name,
2966 .hcd_priv_size = sizeof(struct u132),
2968 .flags = HCD_USB11 | HCD_MEMORY,
2969 .reset = u132_hcd_reset,
2970 .start = u132_hcd_start,
2971 .suspend = u132_hcd_suspend,
2972 .resume = u132_hcd_resume,
2973 .stop = u132_hcd_stop,
2974 .urb_enqueue = u132_urb_enqueue,
2975 .urb_dequeue = u132_urb_dequeue,
2976 .endpoint_disable = u132_endpoint_disable,
2977 .get_frame_number = u132_get_frame,
2978 .hub_status_data = u132_hub_status_data,
2979 .hub_control = u132_hub_control,
2980 .bus_suspend = u132_bus_suspend,
2981 .bus_resume = u132_bus_resume,
2982 .start_port_reset = u132_start_port_reset,
2983 .hub_irq_enable = u132_hub_irq_enable,
2987 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
2988 * is held for writing, thus this module must not call usb_remove_hcd()
2989 * synchronously - but instead should immediately stop activity to the
2990 * device and asynchronously call usb_remove_hcd()
2992 static int __devexit u132_remove(struct platform_device *pdev)
2994 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2996 struct u132 *u132 = hcd_to_u132(hcd);
2997 if (u132->going++ > 1) {
2998 dev_err(&u132->platform_dev->dev, "already being remove"
3002 int rings = MAX_U132_RINGS;
3003 int endps = MAX_U132_ENDPS;
3004 dev_err(&u132->platform_dev->dev, "removing device u132"
3005 ".%d\n", u132->sequence_num);
3007 down(&u132->sw_lock);
3008 u132_monitor_cancel_work(u132);
3009 while (rings-- > 0) {
3010 struct u132_ring *ring = &u132->ring[rings];
3011 u132_ring_cancel_work(u132, ring);
3012 } while (endps-- > 0) {
3013 struct u132_endp *endp = u132->endp[endps];
3015 u132_endp_cancel_work(u132, endp);
3018 printk(KERN_INFO "removing device u132.%d\n",
3019 u132->sequence_num);
3021 usb_remove_hcd(hcd);
3022 u132_u132_put_kref(u132);
3029 static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3031 int rings = MAX_U132_RINGS;
3032 int ports = MAX_U132_PORTS;
3033 int addrs = MAX_U132_ADDRS;
3034 int udevs = MAX_U132_UDEVS;
3035 int endps = MAX_U132_ENDPS;
3036 u132->board = pdev->dev.platform_data;
3037 u132->platform_dev = pdev;
3040 init_MUTEX(&u132->sw_lock);
3041 init_MUTEX(&u132->scheduler_lock);
3042 while (rings-- > 0) {
3043 struct u132_ring *ring = &u132->ring[rings];
3045 ring->number = rings + 1;
3047 ring->curr_endp = NULL;
3048 INIT_DELAYED_WORK(&ring->scheduler,
3049 u132_hcd_ring_work_scheduler);
3050 } down(&u132->sw_lock);
3051 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3052 while (ports-- > 0) {
3053 struct u132_port *port = &u132->port[ports];
3059 } while (addrs-- > 0) {
3060 struct u132_addr *addr = &u132->addr[addrs];
3062 } while (udevs-- > 0) {
3063 struct u132_udev *udev = &u132->udev[udevs];
3064 int i = ARRAY_SIZE(udev->endp_number_in);
3065 int o = ARRAY_SIZE(udev->endp_number_out);
3066 udev->usb_device = NULL;
3067 udev->udev_number = 0;
3069 udev->portnumber = 0;
3071 udev->endp_number_in[i] = 0;
3074 udev->endp_number_out[o] = 0;
3077 while (endps-- > 0) {
3078 u132->endp[endps] = NULL;
3084 static int __devinit u132_probe(struct platform_device *pdev)
3086 struct usb_hcd *hcd;
3092 if (u132_exiting > 0) {
3095 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3098 retval = ftdi_read_pcimem(pdev, control, &control);
3101 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3104 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3105 if (pdev->dev.dma_mask) {
3108 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3110 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3112 ftdi_elan_gone_away(pdev);
3116 struct u132 *u132 = hcd_to_u132(hcd);
3117 hcd->rsrc_start = 0;
3118 mutex_lock(&u132_module_lock);
3119 list_add_tail(&u132->u132_list, &u132_static_list);
3120 u132->sequence_num = ++u132_instances;
3121 mutex_unlock(&u132_module_lock);
3122 u132_u132_init_kref(u132);
3123 u132_initialise(u132, pdev);
3124 hcd->product_desc = "ELAN U132 Host Controller";
3125 retval = usb_add_hcd(hcd, 0, 0);
3127 dev_err(&u132->platform_dev->dev, "init error %d\n",
3129 u132_u132_put_kref(u132);
3132 u132_monitor_queue_work(u132, 100);
3140 /* for this device there's no useful distinction between the controller
3141 * and its root hub, except that the root hub only gets direct PM calls
3142 * when CONFIG_USB_SUSPEND is enabled.
3144 static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3146 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3147 struct u132 *u132 = hcd_to_u132(hcd);
3148 if (u132->going > 1) {
3149 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3152 } else if (u132->going > 0) {
3153 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3157 if (state.event == PM_EVENT_FREEZE) {
3158 retval = u132_bus_suspend(hcd);
3159 } else if (state.event == PM_EVENT_SUSPEND) {
3160 int ports = MAX_U132_PORTS;
3161 while (ports-- > 0) {
3162 port_power(u132, ports, 0);
3166 pdev->dev.power.power_state = state;
3171 static int u132_resume(struct platform_device *pdev)
3173 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3174 struct u132 *u132 = hcd_to_u132(hcd);
3175 if (u132->going > 1) {
3176 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3179 } else if (u132->going > 0) {
3180 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3184 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
3185 int ports = MAX_U132_PORTS;
3186 while (ports-- > 0) {
3187 port_power(u132, ports, 1);
3191 pdev->dev.power.power_state = PMSG_ON;
3192 retval = u132_bus_resume(hcd);
3199 #define u132_suspend NULL
3200 #define u132_resume NULL
3203 * this driver is loaded explicitly by ftdi_u132
3205 * the platform_driver struct is static because it is per type of module
3207 static struct platform_driver u132_platform_driver = {
3208 .probe = u132_probe,
3209 .remove = __devexit_p(u132_remove),
3210 .suspend = u132_suspend,
3211 .resume = u132_resume,
3213 .name = (char *)hcd_name,
3214 .owner = THIS_MODULE,
3217 static int __init u132_hcd_init(void)
3220 INIT_LIST_HEAD(&u132_static_list);
3223 mutex_init(&u132_module_lock);
3226 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3228 workqueue = create_singlethread_workqueue("u132");
3229 retval = platform_driver_register(&u132_platform_driver);
3234 module_init(u132_hcd_init);
3235 static void __exit u132_hcd_exit(void)
3239 mutex_lock(&u132_module_lock);
3241 mutex_unlock(&u132_module_lock);
3242 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3243 platform_device_unregister(u132->platform_dev);
3244 } platform_driver_unregister(&u132_platform_driver);
3245 printk(KERN_INFO "u132-hcd driver deregistered\n");
3246 wait_event(u132_hcd_wait, u132_instances == 0);
3247 flush_workqueue(workqueue);
3248 destroy_workqueue(workqueue);
3252 module_exit(u132_hcd_exit);
3253 MODULE_LICENSE("GPL");