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/mutex.h>
57 #include <asm/system.h>
58 #include <asm/byteorder.h>
59 #include "../core/hcd.h"
61 /* FIXME ohci.h is ONLY for internal use by the OHCI driver.
62 * If you're going to try stuff like this, you need to split
63 * out shareable stuff (register declarations?) into its own
64 * file, maybe name <linux/usb/ohci.h>
68 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
69 #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
71 MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
72 MODULE_DESCRIPTION("U132 USB Host Controller Driver");
73 MODULE_LICENSE("GPL");
74 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
75 INT_MODULE_PARM(testing, 0);
76 /* Some boards misreport power switching/overcurrent*/
77 static int distrust_firmware = 1;
78 module_param(distrust_firmware, bool, 0);
79 MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
81 static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
83 * u132_module_lock exists to protect access to global variables
86 static struct mutex u132_module_lock;
87 static int u132_exiting = 0;
88 static int u132_instances = 0;
89 static struct list_head u132_static_list;
91 * end of the global variables protected by u132_module_lock
93 static struct workqueue_struct *workqueue;
94 #define MAX_U132_PORTS 7
95 #define MAX_U132_ADDRS 128
96 #define MAX_U132_UDEVS 4
97 #define MAX_U132_ENDPS 100
98 #define MAX_U132_RINGS 4
99 static const char *cc_to_text[16] = {
129 struct usb_device *usb_device;
134 u8 endp_number_in[16];
135 u8 endp_number_out[16];
137 #define ENDP_QUEUE_SHIFT 3
138 #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
139 #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
141 struct list_head urb_more;
154 struct list_head endp_ring;
155 struct u132_ring *ring;
156 unsigned toggle_bits:2;
162 unsigned dequeueing:1;
163 unsigned edset_flush:1;
164 unsigned spare_bits:14;
165 unsigned long jiffies;
166 struct usb_host_endpoint *hep;
167 struct u132_spin queue_lock;
171 struct urb *urb_list[ENDP_QUEUE_SIZE];
172 struct list_head urb_more;
173 struct delayed_work scheduler;
180 struct u132_endp *curr_endp;
181 struct delayed_work scheduler;
185 struct list_head u132_list;
186 struct semaphore sw_lock;
187 struct semaphore scheduler_lock;
188 struct u132_platform_data *board;
189 struct platform_device *platform_dev;
190 struct u132_ring ring[MAX_U132_RINGS];
198 u32 hc_roothub_status;
200 u32 hc_roothub_portstatus[MAX_ROOT_PORTS];
202 unsigned long next_statechange;
203 struct delayed_work monitor;
205 struct u132_addr addr[MAX_U132_ADDRS];
206 struct u132_udev udev[MAX_U132_UDEVS];
207 struct u132_port port[MAX_U132_PORTS];
208 struct u132_endp *endp[MAX_U132_ENDPS];
212 * these cannot be inlines because we need the structure offset!!
213 * Does anyone have a better way?????
215 #define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
216 offsetof(struct ohci_regs, member), 0, data);
217 #define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
218 offsetof(struct ohci_regs, member), 0, data);
219 #define u132_read_pcimem(u132, member, data) \
220 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
221 ohci_regs, member), 0, data);
222 #define u132_write_pcimem(u132, member, data) \
223 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
224 ohci_regs, member), 0, data);
225 static inline struct u132 *udev_to_u132(struct u132_udev *udev)
227 u8 udev_number = udev->udev_number;
228 return container_of(udev, struct u132, udev[udev_number]);
231 static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd)
233 return (struct u132 *)(hcd->hcd_priv);
236 static inline struct usb_hcd *u132_to_hcd(struct u132 *u132)
238 return container_of((void *)u132, struct usb_hcd, hcd_priv);
241 static inline void u132_disable(struct u132 *u132)
243 u132_to_hcd(u132)->state = HC_STATE_HALT;
247 #define kref_to_u132(d) container_of(d, struct u132, kref)
248 #define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref)
249 #define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref)
250 #include "../misc/usb_u132.h"
251 static const char hcd_name[] = "u132_hcd";
252 #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
253 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
254 USB_PORT_STAT_C_RESET) << 16)
255 static void u132_hcd_delete(struct kref *kref)
257 struct u132 *u132 = kref_to_u132(kref);
258 struct platform_device *pdev = u132->platform_dev;
259 struct usb_hcd *hcd = u132_to_hcd(u132);
261 mutex_lock(&u132_module_lock);
262 list_del_init(&u132->u132_list);
264 mutex_unlock(&u132_module_lock);
265 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
266 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
270 static inline void u132_u132_put_kref(struct u132 *u132)
272 kref_put(&u132->kref, u132_hcd_delete);
275 static inline void u132_u132_init_kref(struct u132 *u132)
277 kref_init(&u132->kref);
280 static void u132_udev_delete(struct kref *kref)
282 struct u132_udev *udev = kref_to_u132_udev(kref);
283 udev->udev_number = 0;
284 udev->usb_device = NULL;
286 udev->enumeration = 0;
289 static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev)
291 kref_put(&udev->kref, u132_udev_delete);
294 static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev)
296 kref_get(&udev->kref);
299 static inline void u132_udev_init_kref(struct u132 *u132,
300 struct u132_udev *udev)
302 kref_init(&udev->kref);
305 static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring)
307 kref_put(&u132->kref, u132_hcd_delete);
310 static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring,
314 if (queue_delayed_work(workqueue, &ring->scheduler, delta))
316 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0))
318 kref_put(&u132->kref, u132_hcd_delete);
322 static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
325 kref_get(&u132->kref);
326 u132_ring_requeue_work(u132, ring, delta);
330 static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
332 if (cancel_delayed_work(&ring->scheduler)) {
333 kref_put(&u132->kref, u132_hcd_delete);
337 static void u132_endp_delete(struct kref *kref)
339 struct u132_endp *endp = kref_to_u132_endp(kref);
340 struct u132 *u132 = endp->u132;
341 u8 usb_addr = endp->usb_addr;
342 u8 usb_endp = endp->usb_endp;
343 u8 address = u132->addr[usb_addr].address;
344 struct u132_udev *udev = &u132->udev[address];
345 u8 endp_number = endp->endp_number;
346 struct usb_host_endpoint *hep = endp->hep;
347 struct u132_ring *ring = endp->ring;
348 struct list_head *head = &endp->endp_ring;
350 if (endp == ring->curr_endp) {
351 if (list_empty(head)) {
352 ring->curr_endp = NULL;
355 struct u132_endp *next_endp = list_entry(head->next,
356 struct u132_endp, endp_ring);
357 ring->curr_endp = next_endp;
362 udev->endp_number_in[usb_endp] = 0;
363 u132_udev_put_kref(u132, udev);
366 udev->endp_number_out[usb_endp] = 0;
367 u132_udev_put_kref(u132, udev);
369 u132->endp[endp_number - 1] = NULL;
372 u132_u132_put_kref(u132);
375 static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp)
377 kref_put(&endp->kref, u132_endp_delete);
380 static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp)
382 kref_get(&endp->kref);
385 static inline void u132_endp_init_kref(struct u132 *u132,
386 struct u132_endp *endp)
388 kref_init(&endp->kref);
389 kref_get(&u132->kref);
392 static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
395 if (queue_delayed_work(workqueue, &endp->scheduler, delta))
396 kref_get(&endp->kref);
399 static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp)
401 if (cancel_delayed_work(&endp->scheduler))
402 kref_put(&endp->kref, u132_endp_delete);
405 static inline void u132_monitor_put_kref(struct u132 *u132)
407 kref_put(&u132->kref, u132_hcd_delete);
410 static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta)
412 if (queue_delayed_work(workqueue, &u132->monitor, delta))
413 kref_get(&u132->kref);
416 static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta)
418 if (!queue_delayed_work(workqueue, &u132->monitor, delta))
419 kref_put(&u132->kref, u132_hcd_delete);
422 static void u132_monitor_cancel_work(struct u132 *u132)
424 if (cancel_delayed_work(&u132->monitor))
425 kref_put(&u132->kref, u132_hcd_delete);
428 static int read_roothub_info(struct u132 *u132)
432 retval = u132_read_pcimem(u132, revision, &revision);
434 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
437 } else if ((revision & 0xFF) == 0x10) {
438 } else if ((revision & 0xFF) == 0x11) {
440 dev_err(&u132->platform_dev->dev, "device revision is not valid"
441 " %08X\n", revision);
444 retval = u132_read_pcimem(u132, control, &u132->hc_control);
446 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
450 retval = u132_read_pcimem(u132, roothub.status,
451 &u132->hc_roothub_status);
453 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
454 "g roothub.status\n", retval);
457 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a);
459 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
460 "g roothub.a\n", retval);
464 int I = u132->num_ports;
467 retval = u132_read_pcimem(u132, roothub.portstatus[i],
468 &u132->hc_roothub_portstatus[i]);
470 dev_err(&u132->platform_dev->dev, "error %d acc"
471 "essing device roothub.portstatus[%d]\n"
481 static void u132_hcd_monitor_work(struct work_struct *work)
483 struct u132 *u132 = container_of(work, struct u132, monitor.work);
484 if (u132->going > 1) {
485 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
487 u132_monitor_put_kref(u132);
489 } else if (u132->going > 0) {
490 dev_err(&u132->platform_dev->dev, "device is being removed\n");
491 u132_monitor_put_kref(u132);
495 down(&u132->sw_lock);
496 retval = read_roothub_info(u132);
498 struct usb_hcd *hcd = u132_to_hcd(u132);
503 ftdi_elan_gone_away(u132->platform_dev);
504 u132_monitor_put_kref(u132);
507 u132_monitor_requeue_work(u132, 500);
514 static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
515 struct urb *urb, int status)
517 struct u132_ring *ring;
519 struct usb_hcd *hcd = u132_to_hcd(u132);
520 urb->error_count = 0;
521 urb->status = status;
523 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
524 usb_hcd_unlink_urb_from_ep(hcd, urb);
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 usb_hcd_unlink_urb_from_ep(hcd, urb);
566 endp->queue_next += 1;
567 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
569 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
571 struct list_head *next = endp->urb_more.next;
572 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
575 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
578 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
580 } usb_hcd_giveback_urb(hcd, urb);
584 static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
585 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
586 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
587 int toggle_bits, int error_count, int condition_code, int repeat_number,
588 int halted, int skipped, int actual, int non_null))
590 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
591 urb, address, endp->usb_endp, toggle_bits, callback);
594 static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
595 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
596 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
597 int toggle_bits, int error_count, int condition_code, int repeat_number,
598 int halted, int skipped, int actual, int non_null))
600 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
601 urb, address, endp->usb_endp, toggle_bits, callback);
604 static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
605 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
606 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
607 int toggle_bits, int error_count, int condition_code, int repeat_number,
608 int halted, int skipped, int actual, int non_null))
610 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
611 endp, urb, address, endp->usb_endp, toggle_bits, callback);
614 static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
615 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
616 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
617 int toggle_bits, int error_count, int condition_code, int repeat_number,
618 int halted, int skipped, int actual, int non_null))
620 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
621 endp, urb, address, endp->usb_endp, toggle_bits, callback);
626 * must not LOCK sw_lock
629 static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
630 int len, int toggle_bits, int error_count, int condition_code,
631 int repeat_number, int halted, int skipped, int actual, int non_null)
633 struct u132_endp *endp = data;
634 struct u132 *u132 = endp->u132;
635 u8 address = u132->addr[endp->usb_addr].address;
636 struct u132_udev *udev = &u132->udev[address];
637 down(&u132->scheduler_lock);
638 if (u132->going > 1) {
639 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
641 up(&u132->scheduler_lock);
642 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
644 } else if (endp->dequeueing) {
645 endp->dequeueing = 0;
646 up(&u132->scheduler_lock);
647 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
649 } else if (u132->going > 0) {
650 dev_err(&u132->platform_dev->dev, "device is being removed urb="
651 "%p status=%d\n", urb, urb->status);
652 up(&u132->scheduler_lock);
653 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
655 } else if (urb->status == -EINPROGRESS) {
656 struct u132_ring *ring = endp->ring;
657 u8 *u = urb->transfer_buffer + urb->actual_length;
663 urb->actual_length += len;
664 if ((condition_code == TD_CC_NOERROR) &&
665 (urb->transfer_buffer_length > urb->actual_length)) {
666 endp->toggle_bits = toggle_bits;
667 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
669 if (urb->actual_length > 0) {
671 up(&u132->scheduler_lock);
672 retval = edset_single(u132, ring, endp, urb,
673 address, endp->toggle_bits,
674 u132_hcd_interrupt_recv);
677 u132_hcd_giveback_urb(u132, endp, urb,
682 endp->jiffies = jiffies +
683 msecs_to_jiffies(urb->interval);
684 u132_ring_cancel_work(u132, ring);
685 u132_ring_queue_work(u132, ring, 0);
686 up(&u132->scheduler_lock);
687 u132_endp_put_kref(u132, endp);
690 } else if ((condition_code == TD_DATAUNDERRUN) &&
691 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
692 endp->toggle_bits = toggle_bits;
693 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
695 up(&u132->scheduler_lock);
696 u132_hcd_giveback_urb(u132, endp, urb, 0);
699 if (condition_code == TD_CC_NOERROR) {
700 endp->toggle_bits = toggle_bits;
701 usb_settoggle(udev->usb_device, endp->usb_endp,
703 } else if (condition_code == TD_CC_STALL) {
704 endp->toggle_bits = 0x2;
705 usb_settoggle(udev->usb_device, endp->usb_endp,
708 endp->toggle_bits = 0x2;
709 usb_settoggle(udev->usb_device, endp->usb_endp,
711 dev_err(&u132->platform_dev->dev, "urb=%p givin"
712 "g back INTERRUPT %s\n", urb,
713 cc_to_text[condition_code]);
715 up(&u132->scheduler_lock);
716 u132_hcd_giveback_urb(u132, endp, urb,
717 cc_to_error[condition_code]);
721 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
722 "s=%d\n", urb, urb->status);
723 up(&u132->scheduler_lock);
724 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
729 static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
730 int len, int toggle_bits, int error_count, int condition_code,
731 int repeat_number, int halted, int skipped, int actual, int non_null)
733 struct u132_endp *endp = data;
734 struct u132 *u132 = endp->u132;
735 u8 address = u132->addr[endp->usb_addr].address;
736 down(&u132->scheduler_lock);
737 if (u132->going > 1) {
738 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
740 up(&u132->scheduler_lock);
741 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
743 } else if (endp->dequeueing) {
744 endp->dequeueing = 0;
745 up(&u132->scheduler_lock);
746 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
748 } else if (u132->going > 0) {
749 dev_err(&u132->platform_dev->dev, "device is being removed urb="
750 "%p status=%d\n", urb, urb->status);
751 up(&u132->scheduler_lock);
752 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
754 } else if (urb->status == -EINPROGRESS) {
755 struct u132_ring *ring = endp->ring;
756 urb->actual_length += len;
757 endp->toggle_bits = toggle_bits;
758 if (urb->transfer_buffer_length > urb->actual_length) {
760 up(&u132->scheduler_lock);
761 retval = edset_output(u132, ring, endp, urb, address,
762 endp->toggle_bits, u132_hcd_bulk_output_sent);
765 u132_hcd_giveback_urb(u132, endp, urb, retval);
768 up(&u132->scheduler_lock);
769 u132_hcd_giveback_urb(u132, endp, urb, 0);
773 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
774 "s=%d\n", urb, urb->status);
775 up(&u132->scheduler_lock);
776 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
781 static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
782 int len, int toggle_bits, int error_count, int condition_code,
783 int repeat_number, int halted, int skipped, int actual, int non_null)
785 struct u132_endp *endp = data;
786 struct u132 *u132 = endp->u132;
787 u8 address = u132->addr[endp->usb_addr].address;
788 struct u132_udev *udev = &u132->udev[address];
789 down(&u132->scheduler_lock);
790 if (u132->going > 1) {
791 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
793 up(&u132->scheduler_lock);
794 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
796 } else if (endp->dequeueing) {
797 endp->dequeueing = 0;
798 up(&u132->scheduler_lock);
799 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
801 } else if (u132->going > 0) {
802 dev_err(&u132->platform_dev->dev, "device is being removed urb="
803 "%p status=%d\n", urb, urb->status);
804 up(&u132->scheduler_lock);
805 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
807 } else if (urb->status == -EINPROGRESS) {
808 struct u132_ring *ring = endp->ring;
809 u8 *u = urb->transfer_buffer + urb->actual_length;
815 urb->actual_length += len;
816 if ((condition_code == TD_CC_NOERROR) &&
817 (urb->transfer_buffer_length > urb->actual_length)) {
819 endp->toggle_bits = toggle_bits;
820 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
822 up(&u132->scheduler_lock);
823 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
824 ring->number, endp, urb, address,
825 endp->usb_endp, endp->toggle_bits,
826 u132_hcd_bulk_input_recv);
829 u132_hcd_giveback_urb(u132, endp, urb, retval);
831 } else if (condition_code == TD_CC_NOERROR) {
832 endp->toggle_bits = toggle_bits;
833 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
835 up(&u132->scheduler_lock);
836 u132_hcd_giveback_urb(u132, endp, urb,
837 cc_to_error[condition_code]);
839 } else if ((condition_code == TD_DATAUNDERRUN) &&
840 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
841 endp->toggle_bits = toggle_bits;
842 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
844 up(&u132->scheduler_lock);
845 u132_hcd_giveback_urb(u132, endp, urb, 0);
847 } else if (condition_code == TD_DATAUNDERRUN) {
848 endp->toggle_bits = toggle_bits;
849 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
851 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
852 ") giving back BULK IN %s\n", urb,
853 cc_to_text[condition_code]);
854 up(&u132->scheduler_lock);
855 u132_hcd_giveback_urb(u132, endp, urb, 0);
857 } else if (condition_code == TD_CC_STALL) {
858 endp->toggle_bits = 0x2;
859 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
860 up(&u132->scheduler_lock);
861 u132_hcd_giveback_urb(u132, endp, urb,
862 cc_to_error[condition_code]);
865 endp->toggle_bits = 0x2;
866 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
867 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
868 "ULK IN code=%d %s\n", urb, condition_code,
869 cc_to_text[condition_code]);
870 up(&u132->scheduler_lock);
871 u132_hcd_giveback_urb(u132, endp, urb,
872 cc_to_error[condition_code]);
876 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
877 "s=%d\n", urb, urb->status);
878 up(&u132->scheduler_lock);
879 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
884 static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
885 int len, int toggle_bits, int error_count, int condition_code,
886 int repeat_number, int halted, int skipped, int actual, int non_null)
888 struct u132_endp *endp = data;
889 struct u132 *u132 = endp->u132;
890 down(&u132->scheduler_lock);
891 if (u132->going > 1) {
892 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
894 up(&u132->scheduler_lock);
895 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
897 } else if (endp->dequeueing) {
898 endp->dequeueing = 0;
899 up(&u132->scheduler_lock);
900 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
902 } else if (u132->going > 0) {
903 dev_err(&u132->platform_dev->dev, "device is being removed urb="
904 "%p status=%d\n", urb, urb->status);
905 up(&u132->scheduler_lock);
906 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
908 } else if (urb->status == -EINPROGRESS) {
909 up(&u132->scheduler_lock);
910 u132_hcd_giveback_urb(u132, endp, urb, 0);
913 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
914 "s=%d\n", urb, urb->status);
915 up(&u132->scheduler_lock);
916 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
921 static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
922 int len, int toggle_bits, int error_count, int condition_code,
923 int repeat_number, int halted, int skipped, int actual, int non_null)
925 struct u132_endp *endp = data;
926 struct u132 *u132 = endp->u132;
927 u8 address = u132->addr[endp->usb_addr].address;
928 down(&u132->scheduler_lock);
929 if (u132->going > 1) {
930 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
932 up(&u132->scheduler_lock);
933 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
935 } else if (endp->dequeueing) {
936 endp->dequeueing = 0;
937 up(&u132->scheduler_lock);
938 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
940 } else if (u132->going > 0) {
941 dev_err(&u132->platform_dev->dev, "device is being removed urb="
942 "%p status=%d\n", urb, urb->status);
943 up(&u132->scheduler_lock);
944 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
946 } else if (urb->status == -EINPROGRESS) {
947 struct u132_ring *ring = endp->ring;
948 u8 *u = urb->transfer_buffer;
954 urb->actual_length = len;
955 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
956 TD_DATAUNDERRUN) && ((urb->transfer_flags &
957 URB_SHORT_NOT_OK) == 0))) {
959 up(&u132->scheduler_lock);
960 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
961 ring->number, endp, urb, address,
963 u132_hcd_configure_empty_sent);
966 u132_hcd_giveback_urb(u132, endp, urb, retval);
968 } else if (condition_code == TD_CC_STALL) {
969 up(&u132->scheduler_lock);
970 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
971 "NPUT STALL urb %p\n", urb);
972 u132_hcd_giveback_urb(u132, endp, urb,
973 cc_to_error[condition_code]);
976 up(&u132->scheduler_lock);
977 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
978 "PUT %s urb %p\n", cc_to_text[condition_code],
980 u132_hcd_giveback_urb(u132, endp, urb,
981 cc_to_error[condition_code]);
985 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
986 "s=%d\n", urb, urb->status);
987 up(&u132->scheduler_lock);
988 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
993 static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
994 int len, int toggle_bits, int error_count, int condition_code,
995 int repeat_number, int halted, int skipped, int actual, int non_null)
997 struct u132_endp *endp = data;
998 struct u132 *u132 = endp->u132;
999 down(&u132->scheduler_lock);
1000 if (u132->going > 1) {
1001 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1003 up(&u132->scheduler_lock);
1004 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1006 } else if (endp->dequeueing) {
1007 endp->dequeueing = 0;
1008 up(&u132->scheduler_lock);
1009 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1011 } else if (u132->going > 0) {
1012 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1013 "%p status=%d\n", urb, urb->status);
1014 up(&u132->scheduler_lock);
1015 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1017 } else if (urb->status == -EINPROGRESS) {
1018 up(&u132->scheduler_lock);
1019 u132_hcd_giveback_urb(u132, endp, urb, 0);
1022 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1023 "s=%d\n", urb, urb->status);
1024 up(&u132->scheduler_lock);
1025 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1030 static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1031 int len, int toggle_bits, int error_count, int condition_code,
1032 int repeat_number, int halted, int skipped, int actual, int non_null)
1034 struct u132_endp *endp = data;
1035 struct u132 *u132 = endp->u132;
1036 u8 address = u132->addr[endp->usb_addr].address;
1037 down(&u132->scheduler_lock);
1038 if (u132->going > 1) {
1039 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1041 up(&u132->scheduler_lock);
1042 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1044 } else if (endp->dequeueing) {
1045 endp->dequeueing = 0;
1046 up(&u132->scheduler_lock);
1047 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1049 } else if (u132->going > 0) {
1050 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1051 "%p status=%d\n", urb, urb->status);
1052 up(&u132->scheduler_lock);
1053 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1055 } else if (urb->status == -EINPROGRESS) {
1056 if (usb_pipein(urb->pipe)) {
1058 struct u132_ring *ring = endp->ring;
1059 up(&u132->scheduler_lock);
1060 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1061 ring->number, endp, urb, address,
1063 u132_hcd_configure_input_recv);
1066 u132_hcd_giveback_urb(u132, endp, urb, retval);
1070 struct u132_ring *ring = endp->ring;
1071 up(&u132->scheduler_lock);
1072 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1073 ring->number, endp, urb, address,
1075 u132_hcd_configure_empty_recv);
1078 u132_hcd_giveback_urb(u132, endp, urb, retval);
1082 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1083 "s=%d\n", urb, urb->status);
1084 up(&u132->scheduler_lock);
1085 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1090 static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1091 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1092 int repeat_number, int halted, int skipped, int actual, int non_null)
1094 struct u132_endp *endp = data;
1095 struct u132 *u132 = endp->u132;
1096 u8 address = u132->addr[endp->usb_addr].address;
1097 struct u132_udev *udev = &u132->udev[address];
1098 down(&u132->scheduler_lock);
1099 if (u132->going > 1) {
1100 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1102 up(&u132->scheduler_lock);
1103 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1105 } else if (endp->dequeueing) {
1106 endp->dequeueing = 0;
1107 up(&u132->scheduler_lock);
1108 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1110 } else if (u132->going > 0) {
1111 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1112 "%p status=%d\n", urb, urb->status);
1113 up(&u132->scheduler_lock);
1114 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1116 } else if (urb->status == -EINPROGRESS) {
1117 u132->addr[0].address = 0;
1118 endp->usb_addr = udev->usb_addr;
1119 up(&u132->scheduler_lock);
1120 u132_hcd_giveback_urb(u132, endp, urb, 0);
1123 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1124 "s=%d\n", urb, urb->status);
1125 up(&u132->scheduler_lock);
1126 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1131 static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1132 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1133 int repeat_number, int halted, int skipped, int actual, int non_null)
1135 struct u132_endp *endp = data;
1136 struct u132 *u132 = endp->u132;
1137 down(&u132->scheduler_lock);
1138 if (u132->going > 1) {
1139 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1141 up(&u132->scheduler_lock);
1142 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1144 } else if (endp->dequeueing) {
1145 endp->dequeueing = 0;
1146 up(&u132->scheduler_lock);
1147 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1149 } else if (u132->going > 0) {
1150 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1151 "%p status=%d\n", urb, urb->status);
1152 up(&u132->scheduler_lock);
1153 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1155 } else if (urb->status == -EINPROGRESS) {
1157 struct u132_ring *ring = endp->ring;
1158 up(&u132->scheduler_lock);
1159 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1160 ring->number, endp, urb, 0, endp->usb_endp, 0,
1161 u132_hcd_enumeration_empty_recv);
1164 u132_hcd_giveback_urb(u132, endp, urb, retval);
1167 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1168 "s=%d\n", urb, urb->status);
1169 up(&u132->scheduler_lock);
1170 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1175 static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1176 int len, int toggle_bits, int error_count, int condition_code,
1177 int repeat_number, int halted, int skipped, int actual, int non_null)
1179 struct u132_endp *endp = data;
1180 struct u132 *u132 = endp->u132;
1181 down(&u132->scheduler_lock);
1182 if (u132->going > 1) {
1183 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1185 up(&u132->scheduler_lock);
1186 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1188 } else if (endp->dequeueing) {
1189 endp->dequeueing = 0;
1190 up(&u132->scheduler_lock);
1191 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1193 } else if (u132->going > 0) {
1194 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1195 "%p status=%d\n", urb, urb->status);
1196 up(&u132->scheduler_lock);
1197 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1199 } else if (urb->status == -EINPROGRESS) {
1200 up(&u132->scheduler_lock);
1201 u132_hcd_giveback_urb(u132, endp, urb, 0);
1204 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1205 "s=%d\n", urb, urb->status);
1206 up(&u132->scheduler_lock);
1207 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1212 static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1213 int len, int toggle_bits, int error_count, int condition_code,
1214 int repeat_number, int halted, int skipped, int actual, int non_null)
1216 struct u132_endp *endp = data;
1217 struct u132 *u132 = endp->u132;
1218 u8 address = u132->addr[endp->usb_addr].address;
1219 down(&u132->scheduler_lock);
1220 if (u132->going > 1) {
1221 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1223 up(&u132->scheduler_lock);
1224 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1226 } else if (endp->dequeueing) {
1227 endp->dequeueing = 0;
1228 up(&u132->scheduler_lock);
1229 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1231 } else if (u132->going > 0) {
1232 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1233 "%p status=%d\n", urb, urb->status);
1234 up(&u132->scheduler_lock);
1235 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1237 } else if (urb->status == -EINPROGRESS) {
1239 struct u132_ring *ring = endp->ring;
1240 u8 *u = urb->transfer_buffer;
1246 urb->actual_length = len;
1247 up(&u132->scheduler_lock);
1248 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1249 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1250 u132_hcd_initial_empty_sent);
1253 u132_hcd_giveback_urb(u132, endp, urb, retval);
1256 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1257 "s=%d\n", urb, urb->status);
1258 up(&u132->scheduler_lock);
1259 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1264 static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1265 int len, int toggle_bits, int error_count, int condition_code,
1266 int repeat_number, int halted, int skipped, int actual, int non_null)
1268 struct u132_endp *endp = data;
1269 struct u132 *u132 = endp->u132;
1270 u8 address = u132->addr[endp->usb_addr].address;
1271 down(&u132->scheduler_lock);
1272 if (u132->going > 1) {
1273 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1275 up(&u132->scheduler_lock);
1276 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1278 } else if (endp->dequeueing) {
1279 endp->dequeueing = 0;
1280 up(&u132->scheduler_lock);
1281 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1283 } else if (u132->going > 0) {
1284 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1285 "%p status=%d\n", urb, urb->status);
1286 up(&u132->scheduler_lock);
1287 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1289 } else if (urb->status == -EINPROGRESS) {
1291 struct u132_ring *ring = endp->ring;
1292 up(&u132->scheduler_lock);
1293 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1294 ring->number, endp, urb, address, endp->usb_endp, 0,
1295 u132_hcd_initial_input_recv);
1298 u132_hcd_giveback_urb(u132, endp, urb, retval);
1301 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1302 "s=%d\n", urb, urb->status);
1303 up(&u132->scheduler_lock);
1304 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1310 * this work function is only executed from the work queue
1313 static void u132_hcd_ring_work_scheduler(struct work_struct *work)
1315 struct u132_ring *ring =
1316 container_of(work, struct u132_ring, scheduler.work);
1317 struct u132 *u132 = ring->u132;
1318 down(&u132->scheduler_lock);
1320 up(&u132->scheduler_lock);
1321 u132_ring_put_kref(u132, ring);
1323 } else if (ring->curr_endp) {
1324 struct u132_endp *last_endp = ring->curr_endp;
1325 struct list_head *scan;
1326 struct list_head *head = &last_endp->endp_ring;
1327 unsigned long wakeup = 0;
1328 list_for_each(scan, head) {
1329 struct u132_endp *endp = list_entry(scan,
1330 struct u132_endp, endp_ring);
1331 if (endp->queue_next == endp->queue_last) {
1332 } else if ((endp->delayed == 0)
1333 || time_after_eq(jiffies, endp->jiffies)) {
1334 ring->curr_endp = endp;
1335 u132_endp_cancel_work(u132, last_endp);
1336 u132_endp_queue_work(u132, last_endp, 0);
1337 up(&u132->scheduler_lock);
1338 u132_ring_put_kref(u132, ring);
1341 unsigned long delta = endp->jiffies - jiffies;
1346 if (last_endp->queue_next == last_endp->queue_last) {
1347 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1348 last_endp->jiffies)) {
1349 u132_endp_cancel_work(u132, last_endp);
1350 u132_endp_queue_work(u132, last_endp, 0);
1351 up(&u132->scheduler_lock);
1352 u132_ring_put_kref(u132, ring);
1355 unsigned long delta = last_endp->jiffies - jiffies;
1360 u132_ring_requeue_work(u132, ring, wakeup);
1361 up(&u132->scheduler_lock);
1364 up(&u132->scheduler_lock);
1365 u132_ring_put_kref(u132, ring);
1369 up(&u132->scheduler_lock);
1370 u132_ring_put_kref(u132, ring);
1375 static void u132_hcd_endp_work_scheduler(struct work_struct *work)
1377 struct u132_ring *ring;
1378 struct u132_endp *endp =
1379 container_of(work, struct u132_endp, scheduler.work);
1380 struct u132 *u132 = endp->u132;
1381 down(&u132->scheduler_lock);
1383 if (endp->edset_flush) {
1384 endp->edset_flush = 0;
1385 if (endp->dequeueing)
1386 usb_ftdi_elan_edset_flush(u132->platform_dev,
1387 ring->number, endp);
1388 up(&u132->scheduler_lock);
1389 u132_endp_put_kref(u132, endp);
1391 } else if (endp->active) {
1392 up(&u132->scheduler_lock);
1393 u132_endp_put_kref(u132, endp);
1395 } else if (ring->in_use) {
1396 up(&u132->scheduler_lock);
1397 u132_endp_put_kref(u132, endp);
1399 } else if (endp->queue_next == endp->queue_last) {
1400 up(&u132->scheduler_lock);
1401 u132_endp_put_kref(u132, endp);
1403 } else if (endp->pipetype == PIPE_INTERRUPT) {
1404 u8 address = u132->addr[endp->usb_addr].address;
1406 up(&u132->scheduler_lock);
1407 u132_endp_put_kref(u132, endp);
1411 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1414 ring->curr_endp = endp;
1416 up(&u132->scheduler_lock);
1417 retval = edset_single(u132, ring, endp, urb, address,
1418 endp->toggle_bits, u132_hcd_interrupt_recv);
1421 u132_hcd_giveback_urb(u132, endp, urb, retval);
1424 } else if (endp->pipetype == PIPE_CONTROL) {
1425 u8 address = u132->addr[endp->usb_addr].address;
1427 up(&u132->scheduler_lock);
1428 u132_endp_put_kref(u132, endp);
1430 } else if (address == 0) {
1432 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1435 ring->curr_endp = endp;
1437 up(&u132->scheduler_lock);
1438 retval = edset_setup(u132, ring, endp, urb, address,
1439 0x2, u132_hcd_initial_setup_sent);
1442 u132_hcd_giveback_urb(u132, endp, urb, retval);
1444 } else if (endp->usb_addr == 0) {
1446 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1449 ring->curr_endp = endp;
1451 up(&u132->scheduler_lock);
1452 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1453 u132_hcd_enumeration_address_sent);
1456 u132_hcd_giveback_urb(u132, endp, urb, retval);
1460 u8 address = u132->addr[endp->usb_addr].address;
1461 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1464 ring->curr_endp = endp;
1466 up(&u132->scheduler_lock);
1467 retval = edset_setup(u132, ring, endp, urb, address,
1468 0x2, u132_hcd_configure_setup_sent);
1471 u132_hcd_giveback_urb(u132, endp, urb, retval);
1476 u8 address = u132->addr[endp->usb_addr].address;
1478 up(&u132->scheduler_lock);
1479 u132_endp_put_kref(u132, endp);
1483 struct urb *urb = endp->urb_list[
1484 ENDP_QUEUE_MASK & endp->queue_next];
1486 ring->curr_endp = endp;
1488 up(&u132->scheduler_lock);
1489 retval = edset_input(u132, ring, endp, urb,
1490 address, endp->toggle_bits,
1491 u132_hcd_bulk_input_recv);
1494 u132_hcd_giveback_urb(u132, endp, urb,
1498 } else { /* output pipe */
1499 u8 address = u132->addr[endp->usb_addr].address;
1501 up(&u132->scheduler_lock);
1502 u132_endp_put_kref(u132, endp);
1506 struct urb *urb = endp->urb_list[
1507 ENDP_QUEUE_MASK & endp->queue_next];
1509 ring->curr_endp = endp;
1511 up(&u132->scheduler_lock);
1512 retval = edset_output(u132, ring, endp, urb,
1513 address, endp->toggle_bits,
1514 u132_hcd_bulk_output_sent);
1517 u132_hcd_giveback_urb(u132, endp, urb,
1526 static void port_power(struct u132 *u132, int pn, int is_on)
1528 u132->port[pn].power = is_on;
1533 static void u132_power(struct u132 *u132, int is_on)
1535 struct usb_hcd *hcd = u132_to_hcd(u132)
1536 ; /* hub is inactive unless the port is powered */
1541 hcd->self.controller->power.power_state = PMSG_ON;
1544 hcd->state = HC_STATE_HALT;
1545 hcd->self.controller->power.power_state = PMSG_SUSPEND;
1549 static int u132_periodic_reinit(struct u132 *u132)
1552 u32 fi = u132->hc_fminterval & 0x03fff;
1555 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1558 fit = fminterval & FIT;
1559 retval = u132_write_pcimem(u132, fminterval,
1560 (fit ^ FIT) | u132->hc_fminterval);
1563 retval = u132_write_pcimem(u132, periodicstart,
1564 ((9 *fi) / 10) & 0x3fff);
1570 static char *hcfs2string(int state)
1573 case OHCI_USB_RESET:
1575 case OHCI_USB_RESUME:
1578 return "operational";
1579 case OHCI_USB_SUSPEND:
1585 static int u132_init(struct u132 *u132)
1590 u132->next_statechange = jiffies;
1591 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1594 retval = u132_read_pcimem(u132, control, &control);
1597 if (u132->num_ports == 0) {
1599 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1602 u132->num_ports = rh_a & RH_A_NDP;
1603 retval = read_roothub_info(u132);
1607 if (u132->num_ports > MAX_U132_PORTS) {
1614 /* Start an OHCI controller, set the BUS operational
1615 * resets USB and controller
1618 static int u132_run(struct u132 *u132)
1627 int mask = OHCI_INTR_INIT;
1628 int first = u132->hc_fminterval == 0;
1630 int reset_timeout = 30; /* ... allow extra time */
1634 retval = u132_read_pcimem(u132, fminterval, &temp);
1637 u132->hc_fminterval = temp & 0x3fff;
1638 if (u132->hc_fminterval != FI) {
1640 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1642 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1645 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1646 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1648 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1652 case OHCI_USB_SUSPEND:
1653 case OHCI_USB_RESUME:
1654 u132->hc_control &= OHCI_CTRL_RWC;
1655 u132->hc_control |= OHCI_USB_RESUME;
1659 u132->hc_control &= OHCI_CTRL_RWC;
1660 u132->hc_control |= OHCI_USB_RESET;
1664 retval = u132_write_pcimem(u132, control, u132->hc_control);
1667 retval = u132_read_pcimem(u132, control, &control);
1671 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1674 if (!(roothub_a & RH_A_NPS)) {
1675 int temp; /* power down each port */
1676 for (temp = 0; temp < u132->num_ports; temp++) {
1677 retval = u132_write_pcimem(u132,
1678 roothub.portstatus[temp], RH_PS_LSDA);
1683 retval = u132_read_pcimem(u132, control, &control);
1686 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1689 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1693 retval = u132_read_pcimem(u132, cmdstatus, &status);
1696 if (0 != (status & OHCI_HCR)) {
1697 if (--reset_timeout == 0) {
1698 dev_err(&u132->platform_dev->dev, "USB HC reset"
1707 if (u132->flags & OHCI_QUIRK_INITRESET) {
1708 retval = u132_write_pcimem(u132, control, u132->hc_control);
1711 retval = u132_read_pcimem(u132, control, &control);
1715 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1718 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1721 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1724 retval = u132_periodic_reinit(u132);
1727 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1730 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1733 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1734 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1735 u132->flags |= OHCI_QUIRK_INITRESET;
1738 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1739 "\n", fminterval, periodicstart);
1740 } /* start controller operations */
1741 u132->hc_control &= OHCI_CTRL_RWC;
1742 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1743 retval = u132_write_pcimem(u132, control, u132->hc_control);
1746 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1749 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1752 retval = u132_read_pcimem(u132, control, &control);
1755 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1756 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1759 retval = u132_write_pcimem(u132, intrstatus, mask);
1762 retval = u132_write_pcimem(u132, intrdisable,
1763 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1764 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1767 return retval; /* handle root hub init quirks ... */
1768 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1771 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1772 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1773 roothub_a |= RH_A_NOCP;
1774 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1775 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1778 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1779 roothub_a |= RH_A_NPS;
1780 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1784 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1787 retval = u132_write_pcimem(u132, roothub.b,
1788 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1791 retval = u132_read_pcimem(u132, control, &control);
1794 mdelay((roothub_a >> 23) & 0x1fe);
1795 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1799 static void u132_hcd_stop(struct usb_hcd *hcd)
1801 struct u132 *u132 = hcd_to_u132(hcd);
1802 if (u132->going > 1) {
1803 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1804 "een removed %d\n", u132, hcd, u132->going);
1805 } else if (u132->going > 0) {
1806 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1809 down(&u132->sw_lock);
1811 u132_power(u132, 0);
1816 static int u132_hcd_start(struct usb_hcd *hcd)
1818 struct u132 *u132 = hcd_to_u132(hcd);
1819 if (u132->going > 1) {
1820 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1823 } else if (u132->going > 0) {
1824 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1826 } else if (hcd->self.controller) {
1828 struct platform_device *pdev =
1829 to_platform_device(hcd->self.controller);
1830 u16 vendor = ((struct u132_platform_data *)
1831 (pdev->dev.platform_data))->vendor;
1832 u16 device = ((struct u132_platform_data *)
1833 (pdev->dev.platform_data))->device;
1834 down(&u132->sw_lock);
1836 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1837 u132->flags = OHCI_QUIRK_AMD756;
1838 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1839 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1840 "ounds unavailable\n");
1841 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1842 u132->flags |= OHCI_QUIRK_ZFMICRO;
1843 retval = u132_run(u132);
1852 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1857 static int u132_hcd_reset(struct usb_hcd *hcd)
1859 struct u132 *u132 = hcd_to_u132(hcd);
1860 if (u132->going > 1) {
1861 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1864 } else if (u132->going > 0) {
1865 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1869 down(&u132->sw_lock);
1870 retval = u132_init(u132);
1880 static int create_endpoint_and_queue_int(struct u132 *u132,
1881 struct u132_udev *udev, struct urb *urb,
1882 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1885 struct u132_ring *ring;
1889 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1895 spin_lock_init(&endp->queue_lock.slock);
1896 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1897 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1899 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1904 endp_number = ++u132->num_endpoints;
1905 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1906 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1907 INIT_LIST_HEAD(&endp->urb_more);
1908 ring = endp->ring = &u132->ring[0];
1909 if (ring->curr_endp) {
1910 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1912 INIT_LIST_HEAD(&endp->endp_ring);
1913 ring->curr_endp = endp;
1916 endp->dequeueing = 0;
1917 endp->edset_flush = 0;
1920 endp->endp_number = endp_number;
1922 endp->hep = urb->ep;
1923 endp->pipetype = usb_pipetype(urb->pipe);
1924 u132_endp_init_kref(u132, endp);
1925 if (usb_pipein(urb->pipe)) {
1926 endp->toggle_bits = 0x2;
1927 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1930 udev->endp_number_in[usb_endp] = endp_number;
1931 u132_udev_get_kref(u132, udev);
1933 endp->toggle_bits = 0x2;
1934 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1937 udev->endp_number_out[usb_endp] = endp_number;
1938 u132_udev_get_kref(u132, udev);
1942 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1943 endp->udev_number = address;
1944 endp->usb_addr = usb_addr;
1945 endp->usb_endp = usb_endp;
1946 endp->queue_size = 1;
1947 endp->queue_last = 0;
1948 endp->queue_next = 0;
1949 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1950 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1951 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1955 static int queue_int_on_old_endpoint(struct u132 *u132,
1956 struct u132_udev *udev, struct urb *urb,
1957 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1958 u8 usb_endp, u8 address)
1962 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1963 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1964 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1966 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1969 endp->queue_size -= 1;
1972 list_add_tail(&urbq->urb_more, &endp->urb_more);
1979 static int create_endpoint_and_queue_bulk(struct u132 *u132,
1980 struct u132_udev *udev, struct urb *urb,
1981 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1985 struct u132_ring *ring;
1989 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1995 spin_lock_init(&endp->queue_lock.slock);
1996 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1997 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1999 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2004 endp_number = ++u132->num_endpoints;
2005 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2006 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2007 INIT_LIST_HEAD(&endp->urb_more);
2008 endp->dequeueing = 0;
2009 endp->edset_flush = 0;
2012 endp->endp_number = endp_number;
2014 endp->hep = urb->ep;
2015 endp->pipetype = usb_pipetype(urb->pipe);
2016 u132_endp_init_kref(u132, endp);
2017 if (usb_pipein(urb->pipe)) {
2018 endp->toggle_bits = 0x2;
2019 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
2023 udev->endp_number_in[usb_endp] = endp_number;
2024 u132_udev_get_kref(u132, udev);
2026 endp->toggle_bits = 0x2;
2027 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2031 udev->endp_number_out[usb_endp] = endp_number;
2032 u132_udev_get_kref(u132, udev);
2034 ring = endp->ring = &u132->ring[ring_number - 1];
2035 if (ring->curr_endp) {
2036 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2038 INIT_LIST_HEAD(&endp->endp_ring);
2039 ring->curr_endp = endp;
2043 endp->udev_number = address;
2044 endp->usb_addr = usb_addr;
2045 endp->usb_endp = usb_endp;
2046 endp->queue_size = 1;
2047 endp->queue_last = 0;
2048 endp->queue_next = 0;
2049 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2050 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2051 u132_endp_queue_work(u132, endp, 0);
2055 static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2057 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2058 u8 usb_endp, u8 address)
2061 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2062 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2064 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2067 endp->queue_size -= 1;
2070 list_add_tail(&urbq->urb_more, &endp->urb_more);
2077 static int create_endpoint_and_queue_control(struct u132 *u132,
2079 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2082 struct u132_ring *ring;
2086 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
2092 spin_lock_init(&endp->queue_lock.slock);
2093 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2094 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
2096 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2101 endp_number = ++u132->num_endpoints;
2102 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2103 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2104 INIT_LIST_HEAD(&endp->urb_more);
2105 ring = endp->ring = &u132->ring[0];
2106 if (ring->curr_endp) {
2107 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2109 INIT_LIST_HEAD(&endp->endp_ring);
2110 ring->curr_endp = endp;
2113 endp->dequeueing = 0;
2114 endp->edset_flush = 0;
2117 endp->endp_number = endp_number;
2119 endp->hep = urb->ep;
2120 u132_endp_init_kref(u132, endp);
2121 u132_endp_get_kref(u132, endp);
2122 if (usb_addr == 0) {
2123 u8 address = u132->addr[usb_addr].address;
2124 struct u132_udev *udev = &u132->udev[address];
2125 endp->udev_number = address;
2126 endp->usb_addr = usb_addr;
2127 endp->usb_endp = usb_endp;
2130 endp->pipetype = usb_pipetype(urb->pipe);
2131 u132_udev_init_kref(u132, udev);
2132 u132_udev_get_kref(u132, udev);
2133 udev->endp_number_in[usb_endp] = endp_number;
2134 udev->endp_number_out[usb_endp] = endp_number;
2136 endp->queue_size = 1;
2137 endp->queue_last = 0;
2138 endp->queue_next = 0;
2139 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2140 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2141 u132_endp_queue_work(u132, endp, 0);
2143 } else { /*(usb_addr > 0) */
2144 u8 address = u132->addr[usb_addr].address;
2145 struct u132_udev *udev = &u132->udev[address];
2146 endp->udev_number = address;
2147 endp->usb_addr = usb_addr;
2148 endp->usb_endp = usb_endp;
2151 endp->pipetype = usb_pipetype(urb->pipe);
2152 u132_udev_get_kref(u132, udev);
2153 udev->enumeration = 2;
2154 udev->endp_number_in[usb_endp] = endp_number;
2155 udev->endp_number_out[usb_endp] = endp_number;
2157 endp->queue_size = 1;
2158 endp->queue_last = 0;
2159 endp->queue_next = 0;
2160 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2161 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2162 u132_endp_queue_work(u132, endp, 0);
2167 static int queue_control_on_old_endpoint(struct u132 *u132,
2169 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2172 if (usb_addr == 0) {
2173 if (usb_pipein(urb->pipe)) {
2175 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2176 endp->urb_list[ENDP_QUEUE_MASK &
2177 endp->queue_last++] = urb;
2179 struct u132_urbq *urbq =
2180 kmalloc(sizeof(struct u132_urbq),
2183 endp->queue_size -= 1;
2186 list_add_tail(&urbq->urb_more,
2192 } else { /* usb_pipeout(urb->pipe) */
2193 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2194 int I = MAX_U132_UDEVS;
2197 struct u132_udev *udev = &u132->udev[++i];
2198 if (udev->usb_device) {
2201 udev->enumeration = 1;
2202 u132->addr[0].address = i;
2203 endp->udev_number = i;
2204 udev->udev_number = i;
2205 udev->usb_addr = usb_dev->devnum;
2206 u132_udev_init_kref(u132, udev);
2207 udev->endp_number_in[usb_endp] =
2209 u132_udev_get_kref(u132, udev);
2210 udev->endp_number_out[usb_endp] =
2212 udev->usb_device = usb_dev;
2213 ((u8 *) (urb->setup_packet))[2] =
2215 u132_udev_get_kref(u132, udev);
2220 dev_err(&u132->platform_dev->dev, "run out of d"
2225 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2226 endp->urb_list[ENDP_QUEUE_MASK &
2227 endp->queue_last++] = urb;
2229 struct u132_urbq *urbq =
2230 kmalloc(sizeof(struct u132_urbq),
2233 endp->queue_size -= 1;
2236 list_add_tail(&urbq->urb_more,
2243 } else { /*(usb_addr > 0) */
2244 u8 address = u132->addr[usb_addr].address;
2245 struct u132_udev *udev = &u132->udev[address];
2247 if (udev->enumeration == 2) {
2249 udev->enumeration = 2;
2250 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2251 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2254 struct u132_urbq *urbq =
2255 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2257 endp->queue_size -= 1;
2260 list_add_tail(&urbq->urb_more, &endp->urb_more);
2268 static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2271 struct u132 *u132 = hcd_to_u132(hcd);
2272 if (irqs_disabled()) {
2273 if (__GFP_WAIT & mem_flags) {
2274 printk(KERN_ERR "invalid context for function that migh"
2279 if (u132->going > 1) {
2280 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2283 } else if (u132->going > 0) {
2284 dev_err(&u132->platform_dev->dev, "device is being removed urb="
2285 "%p status=%d\n", urb, urb->status);
2288 u8 usb_addr = usb_pipedevice(urb->pipe);
2289 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2290 struct usb_device *usb_dev = urb->dev;
2291 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2292 u8 address = u132->addr[usb_addr].address;
2293 struct u132_udev *udev = &u132->udev[address];
2294 struct u132_endp *endp = urb->ep->hcpriv;
2295 urb->actual_length = 0;
2299 spin_lock_irqsave(&endp->queue_lock.slock,
2301 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2303 retval = queue_int_on_old_endpoint(
2309 usb_hcd_unlink_urb_from_ep(
2312 spin_unlock_irqrestore(&endp->queue_lock.slock,
2317 u132_endp_queue_work(u132, endp,
2318 msecs_to_jiffies(urb->interval))
2322 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2324 } else { /*(endp == NULL) */
2325 return create_endpoint_and_queue_int(u132, udev,
2326 urb, usb_dev, usb_addr,
2327 usb_endp, address, mem_flags);
2329 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2330 dev_err(&u132->platform_dev->dev, "the hardware does no"
2331 "t support PIPE_ISOCHRONOUS\n");
2333 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2334 u8 address = u132->addr[usb_addr].address;
2335 struct u132_udev *udev = &u132->udev[address];
2336 struct u132_endp *endp = urb->ep->hcpriv;
2337 urb->actual_length = 0;
2341 spin_lock_irqsave(&endp->queue_lock.slock,
2343 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2345 retval = queue_bulk_on_old_endpoint(
2351 usb_hcd_unlink_urb_from_ep(
2354 spin_unlock_irqrestore(&endp->queue_lock.slock,
2359 u132_endp_queue_work(u132, endp, 0);
2362 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2365 return create_endpoint_and_queue_bulk(u132,
2366 udev, urb, usb_dev, usb_addr,
2367 usb_endp, address, mem_flags);
2369 struct u132_endp *endp = urb->ep->hcpriv;
2371 u8 *b = urb->setup_packet;
2373 char data[30 *3 + 4];
2375 int m = (sizeof(data) - 1) / 3;
2378 while (urb_size-- > 0) {
2380 } else if (i++ < m) {
2381 int w = sprintf(d, " %02X", *b++);
2385 d += sprintf(d, " ..");
2390 spin_lock_irqsave(&endp->queue_lock.slock,
2392 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2394 retval = queue_control_on_old_endpoint(
2399 usb_hcd_unlink_urb_from_ep(
2402 spin_unlock_irqrestore(&endp->queue_lock.slock,
2407 u132_endp_queue_work(u132, endp, 0);
2410 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2413 return create_endpoint_and_queue_control(u132,
2414 urb, usb_dev, usb_addr, usb_endp,
2420 static int dequeue_from_overflow_chain(struct u132 *u132,
2421 struct u132_endp *endp, struct urb *urb)
2423 struct list_head *scan;
2424 struct list_head *head = &endp->urb_more;
2425 list_for_each(scan, head) {
2426 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2428 if (urbq->urb == urb) {
2429 struct usb_hcd *hcd = u132_to_hcd(u132);
2431 endp->queue_size -= 1;
2432 urb->error_count = 0;
2434 usb_hcd_giveback_urb(hcd, urb);
2439 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2440 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2441 "\n", urb, endp->endp_number, endp, endp->ring->number,
2442 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2443 endp->usb_endp, endp->usb_addr, endp->queue_size,
2444 endp->queue_next, endp->queue_last);
2448 static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2449 struct urb *urb, int status)
2454 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2455 rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status);
2457 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2460 if (endp->queue_size == 0) {
2461 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2462 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2463 endp->endp_number, endp, endp->ring->number,
2464 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2465 endp->usb_endp, endp->usb_addr);
2466 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2469 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2471 endp->dequeueing = 1;
2472 endp->edset_flush = 1;
2473 u132_endp_queue_work(u132, endp, 0);
2474 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2478 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2479 u132_hcd_abandon_urb(u132, endp, urb, urb->status);
2484 u16 queue_size = endp->queue_size;
2485 u16 queue_scan = endp->queue_next;
2486 struct urb **urb_slot = NULL;
2487 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2488 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2490 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2496 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2497 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2499 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2503 struct usb_hcd *hcd = u132_to_hcd(u132);
2505 usb_hcd_unlink_urb_from_ep(hcd, urb);
2506 endp->queue_size -= 1;
2507 if (list_empty(&endp->urb_more)) {
2508 spin_unlock_irqrestore(&endp->queue_lock.slock,
2511 struct list_head *next = endp->urb_more.next;
2512 struct u132_urbq *urbq = list_entry(next,
2513 struct u132_urbq, urb_more);
2515 *urb_slot = urbq->urb;
2516 spin_unlock_irqrestore(&endp->queue_lock.slock,
2519 } urb->error_count = 0;
2521 usb_hcd_giveback_urb(hcd, urb);
2523 } else if (list_empty(&endp->urb_more)) {
2524 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2525 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2526 "=%d size=%d next=%04X last=%04X\n", urb,
2527 endp->endp_number, endp, endp->ring->number,
2528 endp->input ? 'I' : ' ',
2529 endp->output ? 'O' : ' ', endp->usb_endp,
2530 endp->usb_addr, endp->queue_size,
2531 endp->queue_next, endp->queue_last);
2532 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2537 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb);
2538 retval = dequeue_from_overflow_chain(u132, endp,
2540 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2546 static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2548 struct u132 *u132 = hcd_to_u132(hcd);
2549 if (u132->going > 2) {
2550 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2554 u8 usb_addr = usb_pipedevice(urb->pipe);
2555 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2556 u8 address = u132->addr[usb_addr].address;
2557 struct u132_udev *udev = &u132->udev[address];
2558 if (usb_pipein(urb->pipe)) {
2559 u8 endp_number = udev->endp_number_in[usb_endp];
2560 struct u132_endp *endp = u132->endp[endp_number - 1];
2561 return u132_endp_urb_dequeue(u132, endp, urb, status);
2563 u8 endp_number = udev->endp_number_out[usb_endp];
2564 struct u132_endp *endp = u132->endp[endp_number - 1];
2565 return u132_endp_urb_dequeue(u132, endp, urb, status);
2570 static void u132_endpoint_disable(struct usb_hcd *hcd,
2571 struct usb_host_endpoint *hep)
2573 struct u132 *u132 = hcd_to_u132(hcd);
2574 if (u132->going > 2) {
2575 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2576 ") has been removed %d\n", u132, hcd, hep,
2579 struct u132_endp *endp = hep->hcpriv;
2581 u132_endp_put_kref(u132, endp);
2585 static int u132_get_frame(struct usb_hcd *hcd)
2587 struct u132 *u132 = hcd_to_u132(hcd);
2588 if (u132->going > 1) {
2589 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2592 } else if (u132->going > 0) {
2593 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2597 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2603 static int u132_roothub_descriptor(struct u132 *u132,
2604 struct usb_hub_descriptor *desc)
2610 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2613 desc->bDescriptorType = 0x29;
2614 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2615 desc->bHubContrCurrent = 0;
2616 desc->bNbrPorts = u132->num_ports;
2617 temp = 1 + (u132->num_ports / 8);
2618 desc->bDescLength = 7 + 2 *temp;
2620 if (rh_a & RH_A_NPS)
2622 if (rh_a & RH_A_PSM)
2624 if (rh_a & RH_A_NOCP) {
2626 } else if (rh_a & RH_A_OCPM)
2628 desc->wHubCharacteristics = cpu_to_le16(temp);
2629 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2632 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2633 desc->bitmap[0] = rh_b & RH_B_DR;
2634 if (u132->num_ports > 7) {
2635 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2636 desc->bitmap[2] = 0xff;
2638 desc->bitmap[1] = 0xff;
2642 static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2645 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2646 *desc = cpu_to_le32(rh_status);
2650 static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2652 if (wIndex == 0 || wIndex > u132->num_ports) {
2655 int port = wIndex - 1;
2656 u32 rh_portstatus = -1;
2657 int ret_portstatus = u132_read_pcimem(u132,
2658 roothub.portstatus[port], &rh_portstatus);
2659 *desc = cpu_to_le32(rh_portstatus);
2660 if (*(u16 *) (desc + 2)) {
2661 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2662 "ge = %08X\n", port, *desc);
2664 return ret_portstatus;
2669 /* this timer value might be vendor-specific ... */
2670 #define PORT_RESET_HW_MSEC 10
2671 #define PORT_RESET_MSEC 10
2672 /* wrap-aware logic morphed from <linux/jiffies.h> */
2673 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2674 static int u132_roothub_portreset(struct u132 *u132, int port_index)
2680 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2684 reset_done = now + PORT_RESET_MSEC;
2688 retval = u132_read_pcimem(u132,
2689 roothub.portstatus[port_index], &portstat);
2692 if (RH_PS_PRS & portstat) {
2696 } while (tick_before(now, reset_done));
2697 if (RH_PS_PRS & portstat)
2699 if (RH_PS_CCS & portstat) {
2700 if (RH_PS_PRSC & portstat) {
2701 retval = u132_write_pcimem(u132,
2702 roothub.portstatus[port_index],
2708 break; /* start the next reset,
2709 sleep till it's probably done */
2710 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2714 msleep(PORT_RESET_HW_MSEC);
2715 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2719 } while (tick_before(now, reset_done));
2723 static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2726 if (wIndex == 0 || wIndex > u132->num_ports) {
2730 int port_index = wIndex - 1;
2731 struct u132_port *port = &u132->port[port_index];
2732 port->Status &= ~(1 << wValue);
2734 case USB_PORT_FEAT_SUSPEND:
2735 retval = u132_write_pcimem(u132,
2736 roothub.portstatus[port_index], RH_PS_PSS);
2740 case USB_PORT_FEAT_POWER:
2741 retval = u132_write_pcimem(u132,
2742 roothub.portstatus[port_index], RH_PS_PPS);
2746 case USB_PORT_FEAT_RESET:
2747 retval = u132_roothub_portreset(u132, port_index);
2757 static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2760 if (wIndex == 0 || wIndex > u132->num_ports) {
2763 int port_index = wIndex - 1;
2766 struct u132_port *port = &u132->port[port_index];
2767 port->Status &= ~(1 << wValue);
2769 case USB_PORT_FEAT_ENABLE:
2772 case USB_PORT_FEAT_C_ENABLE:
2775 case USB_PORT_FEAT_SUSPEND:
2777 if ((u132->hc_control & OHCI_CTRL_HCFS)
2779 dev_err(&u132->platform_dev->dev, "TODO resume_"
2783 case USB_PORT_FEAT_C_SUSPEND:
2786 case USB_PORT_FEAT_POWER:
2789 case USB_PORT_FEAT_C_CONNECTION:
2792 case USB_PORT_FEAT_C_OVER_CURRENT:
2795 case USB_PORT_FEAT_C_RESET:
2801 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2810 /* the virtual root hub timer IRQ checks for hub status*/
2811 static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2813 struct u132 *u132 = hcd_to_u132(hcd);
2814 if (u132->going > 1) {
2815 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2816 "ed %d\n", hcd, u132->going);
2818 } else if (u132->going > 0) {
2819 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2823 int i, changed = 0, length = 1;
2824 if (u132->flags & OHCI_QUIRK_AMD756) {
2825 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2826 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2827 "ereads as NDP=%d\n",
2828 u132->hc_roothub_a & RH_A_NDP);
2832 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) {
2833 buf[0] = changed = 1;
2836 if (u132->num_ports > 7) {
2840 for (i = 0; i < u132->num_ports; i++) {
2841 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2842 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2846 buf[0] |= 1 << (i + 1);
2848 buf[1] |= 1 << (i - 7);
2851 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) {
2854 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) {
2858 done:return changed ? length : 0;
2862 static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2863 u16 wIndex, char *buf, u16 wLength)
2865 struct u132 *u132 = hcd_to_u132(hcd);
2866 if (u132->going > 1) {
2867 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2870 } else if (u132->going > 0) {
2871 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2875 down(&u132->sw_lock);
2877 case ClearHubFeature:
2879 case C_HUB_OVER_CURRENT:
2880 case C_HUB_LOCAL_POWER:
2888 case C_HUB_OVER_CURRENT:
2889 case C_HUB_LOCAL_POWER:
2895 case ClearPortFeature:{
2896 retval = u132_roothub_clearportfeature(u132,
2902 case GetHubDescriptor:{
2903 retval = u132_roothub_descriptor(u132,
2904 (struct usb_hub_descriptor *)buf);
2910 retval = u132_roothub_status(u132,
2916 case GetPortStatus:{
2917 retval = u132_roothub_portstatus(u132,
2918 (__le32 *) buf, wIndex);
2923 case SetPortFeature:{
2924 retval = u132_roothub_setportfeature(u132,
2932 error:u132_disable(u132);
2935 stall:retval = -EPIPE;
2943 static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2945 struct u132 *u132 = hcd_to_u132(hcd);
2946 if (u132->going > 1) {
2947 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2950 } else if (u132->going > 0) {
2951 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2957 static void u132_hub_irq_enable(struct usb_hcd *hcd)
2959 struct u132 *u132 = hcd_to_u132(hcd);
2960 if (u132->going > 1) {
2961 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2963 } else if (u132->going > 0)
2964 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2969 static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2971 struct u132 *u132 = hcd_to_u132(hcd);
2972 if (u132->going > 1) {
2973 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2976 } else if (u132->going > 0) {
2977 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2983 static int u132_hcd_resume(struct usb_hcd *hcd)
2985 struct u132 *u132 = hcd_to_u132(hcd);
2986 if (u132->going > 1) {
2987 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2990 } else if (u132->going > 0) {
2991 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2997 static int u132_bus_suspend(struct usb_hcd *hcd)
2999 struct u132 *u132 = hcd_to_u132(hcd);
3000 if (u132->going > 1) {
3001 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3004 } else if (u132->going > 0) {
3005 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3011 static int u132_bus_resume(struct usb_hcd *hcd)
3013 struct u132 *u132 = hcd_to_u132(hcd);
3014 if (u132->going > 1) {
3015 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3018 } else if (u132->going > 0) {
3019 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3026 #define u132_hcd_suspend NULL
3027 #define u132_hcd_resume NULL
3028 #define u132_bus_suspend NULL
3029 #define u132_bus_resume NULL
3031 static struct hc_driver u132_hc_driver = {
3032 .description = hcd_name,
3033 .hcd_priv_size = sizeof(struct u132),
3035 .flags = HCD_USB11 | HCD_MEMORY,
3036 .reset = u132_hcd_reset,
3037 .start = u132_hcd_start,
3038 .suspend = u132_hcd_suspend,
3039 .resume = u132_hcd_resume,
3040 .stop = u132_hcd_stop,
3041 .urb_enqueue = u132_urb_enqueue,
3042 .urb_dequeue = u132_urb_dequeue,
3043 .endpoint_disable = u132_endpoint_disable,
3044 .get_frame_number = u132_get_frame,
3045 .hub_status_data = u132_hub_status_data,
3046 .hub_control = u132_hub_control,
3047 .bus_suspend = u132_bus_suspend,
3048 .bus_resume = u132_bus_resume,
3049 .start_port_reset = u132_start_port_reset,
3050 .hub_irq_enable = u132_hub_irq_enable,
3054 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
3055 * is held for writing, thus this module must not call usb_remove_hcd()
3056 * synchronously - but instead should immediately stop activity to the
3057 * device and asynchronously call usb_remove_hcd()
3059 static int __devexit u132_remove(struct platform_device *pdev)
3061 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3063 struct u132 *u132 = hcd_to_u132(hcd);
3064 if (u132->going++ > 1) {
3065 dev_err(&u132->platform_dev->dev, "already being remove"
3069 int rings = MAX_U132_RINGS;
3070 int endps = MAX_U132_ENDPS;
3071 dev_err(&u132->platform_dev->dev, "removing device u132"
3072 ".%d\n", u132->sequence_num);
3074 down(&u132->sw_lock);
3075 u132_monitor_cancel_work(u132);
3076 while (rings-- > 0) {
3077 struct u132_ring *ring = &u132->ring[rings];
3078 u132_ring_cancel_work(u132, ring);
3079 } while (endps-- > 0) {
3080 struct u132_endp *endp = u132->endp[endps];
3082 u132_endp_cancel_work(u132, endp);
3085 printk(KERN_INFO "removing device u132.%d\n",
3086 u132->sequence_num);
3088 usb_remove_hcd(hcd);
3089 u132_u132_put_kref(u132);
3096 static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3098 int rings = MAX_U132_RINGS;
3099 int ports = MAX_U132_PORTS;
3100 int addrs = MAX_U132_ADDRS;
3101 int udevs = MAX_U132_UDEVS;
3102 int endps = MAX_U132_ENDPS;
3103 u132->board = pdev->dev.platform_data;
3104 u132->platform_dev = pdev;
3107 init_MUTEX(&u132->sw_lock);
3108 init_MUTEX(&u132->scheduler_lock);
3109 while (rings-- > 0) {
3110 struct u132_ring *ring = &u132->ring[rings];
3112 ring->number = rings + 1;
3114 ring->curr_endp = NULL;
3115 INIT_DELAYED_WORK(&ring->scheduler,
3116 u132_hcd_ring_work_scheduler);
3117 } down(&u132->sw_lock);
3118 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3119 while (ports-- > 0) {
3120 struct u132_port *port = &u132->port[ports];
3126 } while (addrs-- > 0) {
3127 struct u132_addr *addr = &u132->addr[addrs];
3129 } while (udevs-- > 0) {
3130 struct u132_udev *udev = &u132->udev[udevs];
3131 int i = ARRAY_SIZE(udev->endp_number_in);
3132 int o = ARRAY_SIZE(udev->endp_number_out);
3133 udev->usb_device = NULL;
3134 udev->udev_number = 0;
3136 udev->portnumber = 0;
3138 udev->endp_number_in[i] = 0;
3141 udev->endp_number_out[o] = 0;
3144 while (endps-- > 0) {
3145 u132->endp[endps] = NULL;
3151 static int __devinit u132_probe(struct platform_device *pdev)
3153 struct usb_hcd *hcd;
3159 if (u132_exiting > 0) {
3162 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3165 retval = ftdi_read_pcimem(pdev, control, &control);
3168 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3171 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3172 if (pdev->dev.dma_mask) {
3175 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3177 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3179 ftdi_elan_gone_away(pdev);
3183 struct u132 *u132 = hcd_to_u132(hcd);
3184 hcd->rsrc_start = 0;
3185 mutex_lock(&u132_module_lock);
3186 list_add_tail(&u132->u132_list, &u132_static_list);
3187 u132->sequence_num = ++u132_instances;
3188 mutex_unlock(&u132_module_lock);
3189 u132_u132_init_kref(u132);
3190 u132_initialise(u132, pdev);
3191 hcd->product_desc = "ELAN U132 Host Controller";
3192 retval = usb_add_hcd(hcd, 0, 0);
3194 dev_err(&u132->platform_dev->dev, "init error %d\n",
3196 u132_u132_put_kref(u132);
3199 u132_monitor_queue_work(u132, 100);
3207 /* for this device there's no useful distinction between the controller
3208 * and its root hub, except that the root hub only gets direct PM calls
3209 * when CONFIG_USB_SUSPEND is enabled.
3211 static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3213 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3214 struct u132 *u132 = hcd_to_u132(hcd);
3215 if (u132->going > 1) {
3216 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3219 } else if (u132->going > 0) {
3220 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3224 if (state.event == PM_EVENT_FREEZE) {
3225 retval = u132_bus_suspend(hcd);
3226 } else if (state.event == PM_EVENT_SUSPEND) {
3227 int ports = MAX_U132_PORTS;
3228 while (ports-- > 0) {
3229 port_power(u132, ports, 0);
3233 pdev->dev.power.power_state = state;
3238 static int u132_resume(struct platform_device *pdev)
3240 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3241 struct u132 *u132 = hcd_to_u132(hcd);
3242 if (u132->going > 1) {
3243 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3246 } else if (u132->going > 0) {
3247 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3251 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
3252 int ports = MAX_U132_PORTS;
3253 while (ports-- > 0) {
3254 port_power(u132, ports, 1);
3258 pdev->dev.power.power_state = PMSG_ON;
3259 retval = u132_bus_resume(hcd);
3266 #define u132_suspend NULL
3267 #define u132_resume NULL
3270 * this driver is loaded explicitly by ftdi_u132
3272 * the platform_driver struct is static because it is per type of module
3274 static struct platform_driver u132_platform_driver = {
3275 .probe = u132_probe,
3276 .remove = __devexit_p(u132_remove),
3277 .suspend = u132_suspend,
3278 .resume = u132_resume,
3280 .name = (char *)hcd_name,
3281 .owner = THIS_MODULE,
3284 static int __init u132_hcd_init(void)
3287 INIT_LIST_HEAD(&u132_static_list);
3290 mutex_init(&u132_module_lock);
3293 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3295 workqueue = create_singlethread_workqueue("u132");
3296 retval = platform_driver_register(&u132_platform_driver);
3301 module_init(u132_hcd_init);
3302 static void __exit u132_hcd_exit(void)
3306 mutex_lock(&u132_module_lock);
3308 mutex_unlock(&u132_module_lock);
3309 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3310 platform_device_unregister(u132->platform_dev);
3311 } platform_driver_unregister(&u132_platform_driver);
3312 printk(KERN_INFO "u132-hcd driver deregistered\n");
3313 wait_event(u132_hcd_wait, u132_instances == 0);
3314 flush_workqueue(workqueue);
3315 destroy_workqueue(workqueue);
3319 module_exit(u132_hcd_exit);
3320 MODULE_LICENSE("GPL");