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;
522 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
523 usb_hcd_unlink_urb_from_ep(hcd, urb);
524 endp->queue_next += 1;
525 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
527 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
529 struct list_head *next = endp->urb_more.next;
530 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
533 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
536 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
538 } down(&u132->scheduler_lock);
541 u132_ring_cancel_work(u132, ring);
542 u132_ring_queue_work(u132, ring, 0);
543 up(&u132->scheduler_lock);
544 u132_endp_put_kref(u132, endp);
545 usb_hcd_giveback_urb(hcd, urb);
549 static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp,
550 struct urb *urb, int status)
552 u132_endp_put_kref(u132, endp);
555 static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
556 struct urb *urb, int status)
559 struct usb_hcd *hcd = u132_to_hcd(u132);
560 urb->error_count = 0;
561 urb->status = status;
562 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
563 usb_hcd_unlink_urb_from_ep(hcd, urb);
564 endp->queue_next += 1;
565 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
567 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
569 struct list_head *next = endp->urb_more.next;
570 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
573 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
576 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
578 } usb_hcd_giveback_urb(hcd, urb);
582 static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
583 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
584 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
585 int toggle_bits, int error_count, int condition_code, int repeat_number,
586 int halted, int skipped, int actual, int non_null))
588 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
589 urb, address, endp->usb_endp, toggle_bits, callback);
592 static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
593 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
594 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
595 int toggle_bits, int error_count, int condition_code, int repeat_number,
596 int halted, int skipped, int actual, int non_null))
598 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
599 urb, address, endp->usb_endp, toggle_bits, callback);
602 static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
603 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
604 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
605 int toggle_bits, int error_count, int condition_code, int repeat_number,
606 int halted, int skipped, int actual, int non_null))
608 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
609 endp, urb, address, endp->usb_endp, toggle_bits, callback);
612 static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
613 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
614 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
615 int toggle_bits, int error_count, int condition_code, int repeat_number,
616 int halted, int skipped, int actual, int non_null))
618 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
619 endp, urb, address, endp->usb_endp, toggle_bits, callback);
624 * must not LOCK sw_lock
627 static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
628 int len, int toggle_bits, int error_count, int condition_code,
629 int repeat_number, int halted, int skipped, int actual, int non_null)
631 struct u132_endp *endp = data;
632 struct u132 *u132 = endp->u132;
633 u8 address = u132->addr[endp->usb_addr].address;
634 struct u132_udev *udev = &u132->udev[address];
635 down(&u132->scheduler_lock);
636 if (u132->going > 1) {
637 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
639 up(&u132->scheduler_lock);
640 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
642 } else if (endp->dequeueing) {
643 endp->dequeueing = 0;
644 up(&u132->scheduler_lock);
645 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
647 } else if (u132->going > 0) {
648 dev_err(&u132->platform_dev->dev, "device is being removed urb="
649 "%p status=%d\n", urb, urb->status);
650 up(&u132->scheduler_lock);
651 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
653 } else if (urb->status == -EINPROGRESS) {
654 struct u132_ring *ring = endp->ring;
655 u8 *u = urb->transfer_buffer + urb->actual_length;
661 urb->actual_length += len;
662 if ((condition_code == TD_CC_NOERROR) &&
663 (urb->transfer_buffer_length > urb->actual_length)) {
664 endp->toggle_bits = toggle_bits;
665 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
667 if (urb->actual_length > 0) {
669 up(&u132->scheduler_lock);
670 retval = edset_single(u132, ring, endp, urb,
671 address, endp->toggle_bits,
672 u132_hcd_interrupt_recv);
675 u132_hcd_giveback_urb(u132, endp, urb,
680 endp->jiffies = jiffies +
681 msecs_to_jiffies(urb->interval);
682 u132_ring_cancel_work(u132, ring);
683 u132_ring_queue_work(u132, ring, 0);
684 up(&u132->scheduler_lock);
685 u132_endp_put_kref(u132, endp);
688 } else if ((condition_code == TD_DATAUNDERRUN) &&
689 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
690 endp->toggle_bits = toggle_bits;
691 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
693 up(&u132->scheduler_lock);
694 u132_hcd_giveback_urb(u132, endp, urb, 0);
697 if (condition_code == TD_CC_NOERROR) {
698 endp->toggle_bits = toggle_bits;
699 usb_settoggle(udev->usb_device, endp->usb_endp,
701 } else if (condition_code == TD_CC_STALL) {
702 endp->toggle_bits = 0x2;
703 usb_settoggle(udev->usb_device, endp->usb_endp,
706 endp->toggle_bits = 0x2;
707 usb_settoggle(udev->usb_device, endp->usb_endp,
709 dev_err(&u132->platform_dev->dev, "urb=%p givin"
710 "g back INTERRUPT %s\n", urb,
711 cc_to_text[condition_code]);
713 up(&u132->scheduler_lock);
714 u132_hcd_giveback_urb(u132, endp, urb,
715 cc_to_error[condition_code]);
719 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
720 "s=%d\n", urb, urb->status);
721 up(&u132->scheduler_lock);
722 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
727 static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
728 int len, int toggle_bits, int error_count, int condition_code,
729 int repeat_number, int halted, int skipped, int actual, int non_null)
731 struct u132_endp *endp = data;
732 struct u132 *u132 = endp->u132;
733 u8 address = u132->addr[endp->usb_addr].address;
734 down(&u132->scheduler_lock);
735 if (u132->going > 1) {
736 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
738 up(&u132->scheduler_lock);
739 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
741 } else if (endp->dequeueing) {
742 endp->dequeueing = 0;
743 up(&u132->scheduler_lock);
744 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
746 } else if (u132->going > 0) {
747 dev_err(&u132->platform_dev->dev, "device is being removed urb="
748 "%p status=%d\n", urb, urb->status);
749 up(&u132->scheduler_lock);
750 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
752 } else if (urb->status == -EINPROGRESS) {
753 struct u132_ring *ring = endp->ring;
754 urb->actual_length += len;
755 endp->toggle_bits = toggle_bits;
756 if (urb->transfer_buffer_length > urb->actual_length) {
758 up(&u132->scheduler_lock);
759 retval = edset_output(u132, ring, endp, urb, address,
760 endp->toggle_bits, u132_hcd_bulk_output_sent);
763 u132_hcd_giveback_urb(u132, endp, urb, retval);
766 up(&u132->scheduler_lock);
767 u132_hcd_giveback_urb(u132, endp, urb, 0);
771 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
772 "s=%d\n", urb, urb->status);
773 up(&u132->scheduler_lock);
774 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
779 static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
780 int len, int toggle_bits, int error_count, int condition_code,
781 int repeat_number, int halted, int skipped, int actual, int non_null)
783 struct u132_endp *endp = data;
784 struct u132 *u132 = endp->u132;
785 u8 address = u132->addr[endp->usb_addr].address;
786 struct u132_udev *udev = &u132->udev[address];
787 down(&u132->scheduler_lock);
788 if (u132->going > 1) {
789 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
791 up(&u132->scheduler_lock);
792 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
794 } else if (endp->dequeueing) {
795 endp->dequeueing = 0;
796 up(&u132->scheduler_lock);
797 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
799 } else if (u132->going > 0) {
800 dev_err(&u132->platform_dev->dev, "device is being removed urb="
801 "%p status=%d\n", urb, urb->status);
802 up(&u132->scheduler_lock);
803 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
805 } else if (urb->status == -EINPROGRESS) {
806 struct u132_ring *ring = endp->ring;
807 u8 *u = urb->transfer_buffer + urb->actual_length;
813 urb->actual_length += len;
814 if ((condition_code == TD_CC_NOERROR) &&
815 (urb->transfer_buffer_length > urb->actual_length)) {
817 endp->toggle_bits = toggle_bits;
818 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
820 up(&u132->scheduler_lock);
821 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
822 ring->number, endp, urb, address,
823 endp->usb_endp, endp->toggle_bits,
824 u132_hcd_bulk_input_recv);
827 u132_hcd_giveback_urb(u132, endp, urb, retval);
829 } else if (condition_code == TD_CC_NOERROR) {
830 endp->toggle_bits = toggle_bits;
831 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
833 up(&u132->scheduler_lock);
834 u132_hcd_giveback_urb(u132, endp, urb,
835 cc_to_error[condition_code]);
837 } else if ((condition_code == TD_DATAUNDERRUN) &&
838 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
839 endp->toggle_bits = toggle_bits;
840 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
842 up(&u132->scheduler_lock);
843 u132_hcd_giveback_urb(u132, endp, urb, 0);
845 } else if (condition_code == TD_DATAUNDERRUN) {
846 endp->toggle_bits = toggle_bits;
847 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
849 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
850 ") giving back BULK IN %s\n", urb,
851 cc_to_text[condition_code]);
852 up(&u132->scheduler_lock);
853 u132_hcd_giveback_urb(u132, endp, urb, 0);
855 } else if (condition_code == TD_CC_STALL) {
856 endp->toggle_bits = 0x2;
857 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
858 up(&u132->scheduler_lock);
859 u132_hcd_giveback_urb(u132, endp, urb,
860 cc_to_error[condition_code]);
863 endp->toggle_bits = 0x2;
864 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
865 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
866 "ULK IN code=%d %s\n", urb, condition_code,
867 cc_to_text[condition_code]);
868 up(&u132->scheduler_lock);
869 u132_hcd_giveback_urb(u132, endp, urb,
870 cc_to_error[condition_code]);
874 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
875 "s=%d\n", urb, urb->status);
876 up(&u132->scheduler_lock);
877 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
882 static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
883 int len, int toggle_bits, int error_count, int condition_code,
884 int repeat_number, int halted, int skipped, int actual, int non_null)
886 struct u132_endp *endp = data;
887 struct u132 *u132 = endp->u132;
888 down(&u132->scheduler_lock);
889 if (u132->going > 1) {
890 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
892 up(&u132->scheduler_lock);
893 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
895 } else if (endp->dequeueing) {
896 endp->dequeueing = 0;
897 up(&u132->scheduler_lock);
898 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
900 } else if (u132->going > 0) {
901 dev_err(&u132->platform_dev->dev, "device is being removed urb="
902 "%p status=%d\n", urb, urb->status);
903 up(&u132->scheduler_lock);
904 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
906 } else if (urb->status == -EINPROGRESS) {
907 up(&u132->scheduler_lock);
908 u132_hcd_giveback_urb(u132, endp, urb, 0);
911 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
912 "s=%d\n", urb, urb->status);
913 up(&u132->scheduler_lock);
914 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
919 static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
920 int len, int toggle_bits, int error_count, int condition_code,
921 int repeat_number, int halted, int skipped, int actual, int non_null)
923 struct u132_endp *endp = data;
924 struct u132 *u132 = endp->u132;
925 u8 address = u132->addr[endp->usb_addr].address;
926 down(&u132->scheduler_lock);
927 if (u132->going > 1) {
928 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
930 up(&u132->scheduler_lock);
931 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
933 } else if (endp->dequeueing) {
934 endp->dequeueing = 0;
935 up(&u132->scheduler_lock);
936 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
938 } else if (u132->going > 0) {
939 dev_err(&u132->platform_dev->dev, "device is being removed urb="
940 "%p status=%d\n", urb, urb->status);
941 up(&u132->scheduler_lock);
942 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
944 } else if (urb->status == -EINPROGRESS) {
945 struct u132_ring *ring = endp->ring;
946 u8 *u = urb->transfer_buffer;
952 urb->actual_length = len;
953 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
954 TD_DATAUNDERRUN) && ((urb->transfer_flags &
955 URB_SHORT_NOT_OK) == 0))) {
957 up(&u132->scheduler_lock);
958 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
959 ring->number, endp, urb, address,
961 u132_hcd_configure_empty_sent);
964 u132_hcd_giveback_urb(u132, endp, urb, retval);
966 } else if (condition_code == TD_CC_STALL) {
967 up(&u132->scheduler_lock);
968 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
969 "NPUT STALL urb %p\n", urb);
970 u132_hcd_giveback_urb(u132, endp, urb,
971 cc_to_error[condition_code]);
974 up(&u132->scheduler_lock);
975 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
976 "PUT %s urb %p\n", cc_to_text[condition_code],
978 u132_hcd_giveback_urb(u132, endp, urb,
979 cc_to_error[condition_code]);
983 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
984 "s=%d\n", urb, urb->status);
985 up(&u132->scheduler_lock);
986 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
991 static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
992 int len, int toggle_bits, int error_count, int condition_code,
993 int repeat_number, int halted, int skipped, int actual, int non_null)
995 struct u132_endp *endp = data;
996 struct u132 *u132 = endp->u132;
997 down(&u132->scheduler_lock);
998 if (u132->going > 1) {
999 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1001 up(&u132->scheduler_lock);
1002 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1004 } else if (endp->dequeueing) {
1005 endp->dequeueing = 0;
1006 up(&u132->scheduler_lock);
1007 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1009 } else if (u132->going > 0) {
1010 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1011 "%p status=%d\n", urb, urb->status);
1012 up(&u132->scheduler_lock);
1013 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1015 } else if (urb->status == -EINPROGRESS) {
1016 up(&u132->scheduler_lock);
1017 u132_hcd_giveback_urb(u132, endp, urb, 0);
1020 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1021 "s=%d\n", urb, urb->status);
1022 up(&u132->scheduler_lock);
1023 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1028 static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1029 int len, int toggle_bits, int error_count, int condition_code,
1030 int repeat_number, int halted, int skipped, int actual, int non_null)
1032 struct u132_endp *endp = data;
1033 struct u132 *u132 = endp->u132;
1034 u8 address = u132->addr[endp->usb_addr].address;
1035 down(&u132->scheduler_lock);
1036 if (u132->going > 1) {
1037 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1039 up(&u132->scheduler_lock);
1040 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1042 } else if (endp->dequeueing) {
1043 endp->dequeueing = 0;
1044 up(&u132->scheduler_lock);
1045 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1047 } else if (u132->going > 0) {
1048 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1049 "%p status=%d\n", urb, urb->status);
1050 up(&u132->scheduler_lock);
1051 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1053 } else if (urb->status == -EINPROGRESS) {
1054 if (usb_pipein(urb->pipe)) {
1056 struct u132_ring *ring = endp->ring;
1057 up(&u132->scheduler_lock);
1058 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1059 ring->number, endp, urb, address,
1061 u132_hcd_configure_input_recv);
1064 u132_hcd_giveback_urb(u132, endp, urb, retval);
1068 struct u132_ring *ring = endp->ring;
1069 up(&u132->scheduler_lock);
1070 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1071 ring->number, endp, urb, address,
1073 u132_hcd_configure_empty_recv);
1076 u132_hcd_giveback_urb(u132, endp, urb, retval);
1080 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1081 "s=%d\n", urb, urb->status);
1082 up(&u132->scheduler_lock);
1083 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1088 static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1089 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1090 int repeat_number, int halted, int skipped, int actual, int non_null)
1092 struct u132_endp *endp = data;
1093 struct u132 *u132 = endp->u132;
1094 u8 address = u132->addr[endp->usb_addr].address;
1095 struct u132_udev *udev = &u132->udev[address];
1096 down(&u132->scheduler_lock);
1097 if (u132->going > 1) {
1098 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1100 up(&u132->scheduler_lock);
1101 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1103 } else if (endp->dequeueing) {
1104 endp->dequeueing = 0;
1105 up(&u132->scheduler_lock);
1106 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1108 } else if (u132->going > 0) {
1109 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1110 "%p status=%d\n", urb, urb->status);
1111 up(&u132->scheduler_lock);
1112 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1114 } else if (urb->status == -EINPROGRESS) {
1115 u132->addr[0].address = 0;
1116 endp->usb_addr = udev->usb_addr;
1117 up(&u132->scheduler_lock);
1118 u132_hcd_giveback_urb(u132, endp, urb, 0);
1121 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1122 "s=%d\n", urb, urb->status);
1123 up(&u132->scheduler_lock);
1124 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1129 static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1130 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1131 int repeat_number, int halted, int skipped, int actual, int non_null)
1133 struct u132_endp *endp = data;
1134 struct u132 *u132 = endp->u132;
1135 down(&u132->scheduler_lock);
1136 if (u132->going > 1) {
1137 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1139 up(&u132->scheduler_lock);
1140 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1142 } else if (endp->dequeueing) {
1143 endp->dequeueing = 0;
1144 up(&u132->scheduler_lock);
1145 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1147 } else if (u132->going > 0) {
1148 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1149 "%p status=%d\n", urb, urb->status);
1150 up(&u132->scheduler_lock);
1151 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1153 } else if (urb->status == -EINPROGRESS) {
1155 struct u132_ring *ring = endp->ring;
1156 up(&u132->scheduler_lock);
1157 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1158 ring->number, endp, urb, 0, endp->usb_endp, 0,
1159 u132_hcd_enumeration_empty_recv);
1162 u132_hcd_giveback_urb(u132, endp, urb, retval);
1165 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1166 "s=%d\n", urb, urb->status);
1167 up(&u132->scheduler_lock);
1168 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1173 static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1174 int len, int toggle_bits, int error_count, int condition_code,
1175 int repeat_number, int halted, int skipped, int actual, int non_null)
1177 struct u132_endp *endp = data;
1178 struct u132 *u132 = endp->u132;
1179 down(&u132->scheduler_lock);
1180 if (u132->going > 1) {
1181 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1183 up(&u132->scheduler_lock);
1184 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1186 } else if (endp->dequeueing) {
1187 endp->dequeueing = 0;
1188 up(&u132->scheduler_lock);
1189 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1191 } else if (u132->going > 0) {
1192 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1193 "%p status=%d\n", urb, urb->status);
1194 up(&u132->scheduler_lock);
1195 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1197 } else if (urb->status == -EINPROGRESS) {
1198 up(&u132->scheduler_lock);
1199 u132_hcd_giveback_urb(u132, endp, urb, 0);
1202 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1203 "s=%d\n", urb, urb->status);
1204 up(&u132->scheduler_lock);
1205 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1210 static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1211 int len, int toggle_bits, int error_count, int condition_code,
1212 int repeat_number, int halted, int skipped, int actual, int non_null)
1214 struct u132_endp *endp = data;
1215 struct u132 *u132 = endp->u132;
1216 u8 address = u132->addr[endp->usb_addr].address;
1217 down(&u132->scheduler_lock);
1218 if (u132->going > 1) {
1219 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1221 up(&u132->scheduler_lock);
1222 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1224 } else if (endp->dequeueing) {
1225 endp->dequeueing = 0;
1226 up(&u132->scheduler_lock);
1227 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1229 } else if (u132->going > 0) {
1230 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1231 "%p status=%d\n", urb, urb->status);
1232 up(&u132->scheduler_lock);
1233 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1235 } else if (urb->status == -EINPROGRESS) {
1237 struct u132_ring *ring = endp->ring;
1238 u8 *u = urb->transfer_buffer;
1244 urb->actual_length = len;
1245 up(&u132->scheduler_lock);
1246 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1247 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1248 u132_hcd_initial_empty_sent);
1251 u132_hcd_giveback_urb(u132, endp, urb, retval);
1254 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1255 "s=%d\n", urb, urb->status);
1256 up(&u132->scheduler_lock);
1257 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1262 static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1263 int len, int toggle_bits, int error_count, int condition_code,
1264 int repeat_number, int halted, int skipped, int actual, int non_null)
1266 struct u132_endp *endp = data;
1267 struct u132 *u132 = endp->u132;
1268 u8 address = u132->addr[endp->usb_addr].address;
1269 down(&u132->scheduler_lock);
1270 if (u132->going > 1) {
1271 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1273 up(&u132->scheduler_lock);
1274 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1276 } else if (endp->dequeueing) {
1277 endp->dequeueing = 0;
1278 up(&u132->scheduler_lock);
1279 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1281 } else if (u132->going > 0) {
1282 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1283 "%p status=%d\n", urb, urb->status);
1284 up(&u132->scheduler_lock);
1285 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1287 } else if (urb->status == -EINPROGRESS) {
1289 struct u132_ring *ring = endp->ring;
1290 up(&u132->scheduler_lock);
1291 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1292 ring->number, endp, urb, address, endp->usb_endp, 0,
1293 u132_hcd_initial_input_recv);
1296 u132_hcd_giveback_urb(u132, endp, urb, retval);
1299 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1300 "s=%d\n", urb, urb->status);
1301 up(&u132->scheduler_lock);
1302 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1308 * this work function is only executed from the work queue
1311 static void u132_hcd_ring_work_scheduler(struct work_struct *work)
1313 struct u132_ring *ring =
1314 container_of(work, struct u132_ring, scheduler.work);
1315 struct u132 *u132 = ring->u132;
1316 down(&u132->scheduler_lock);
1318 up(&u132->scheduler_lock);
1319 u132_ring_put_kref(u132, ring);
1321 } else if (ring->curr_endp) {
1322 struct u132_endp *last_endp = ring->curr_endp;
1323 struct list_head *scan;
1324 struct list_head *head = &last_endp->endp_ring;
1325 unsigned long wakeup = 0;
1326 list_for_each(scan, head) {
1327 struct u132_endp *endp = list_entry(scan,
1328 struct u132_endp, endp_ring);
1329 if (endp->queue_next == endp->queue_last) {
1330 } else if ((endp->delayed == 0)
1331 || time_after_eq(jiffies, endp->jiffies)) {
1332 ring->curr_endp = endp;
1333 u132_endp_cancel_work(u132, last_endp);
1334 u132_endp_queue_work(u132, last_endp, 0);
1335 up(&u132->scheduler_lock);
1336 u132_ring_put_kref(u132, ring);
1339 unsigned long delta = endp->jiffies - jiffies;
1344 if (last_endp->queue_next == last_endp->queue_last) {
1345 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1346 last_endp->jiffies)) {
1347 u132_endp_cancel_work(u132, last_endp);
1348 u132_endp_queue_work(u132, last_endp, 0);
1349 up(&u132->scheduler_lock);
1350 u132_ring_put_kref(u132, ring);
1353 unsigned long delta = last_endp->jiffies - jiffies;
1358 u132_ring_requeue_work(u132, ring, wakeup);
1359 up(&u132->scheduler_lock);
1362 up(&u132->scheduler_lock);
1363 u132_ring_put_kref(u132, ring);
1367 up(&u132->scheduler_lock);
1368 u132_ring_put_kref(u132, ring);
1373 static void u132_hcd_endp_work_scheduler(struct work_struct *work)
1375 struct u132_ring *ring;
1376 struct u132_endp *endp =
1377 container_of(work, struct u132_endp, scheduler.work);
1378 struct u132 *u132 = endp->u132;
1379 down(&u132->scheduler_lock);
1381 if (endp->edset_flush) {
1382 endp->edset_flush = 0;
1383 if (endp->dequeueing)
1384 usb_ftdi_elan_edset_flush(u132->platform_dev,
1385 ring->number, endp);
1386 up(&u132->scheduler_lock);
1387 u132_endp_put_kref(u132, endp);
1389 } else if (endp->active) {
1390 up(&u132->scheduler_lock);
1391 u132_endp_put_kref(u132, endp);
1393 } else if (ring->in_use) {
1394 up(&u132->scheduler_lock);
1395 u132_endp_put_kref(u132, endp);
1397 } else if (endp->queue_next == endp->queue_last) {
1398 up(&u132->scheduler_lock);
1399 u132_endp_put_kref(u132, endp);
1401 } else if (endp->pipetype == PIPE_INTERRUPT) {
1402 u8 address = u132->addr[endp->usb_addr].address;
1404 up(&u132->scheduler_lock);
1405 u132_endp_put_kref(u132, endp);
1409 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1412 ring->curr_endp = endp;
1414 up(&u132->scheduler_lock);
1415 retval = edset_single(u132, ring, endp, urb, address,
1416 endp->toggle_bits, u132_hcd_interrupt_recv);
1419 u132_hcd_giveback_urb(u132, endp, urb, retval);
1422 } else if (endp->pipetype == PIPE_CONTROL) {
1423 u8 address = u132->addr[endp->usb_addr].address;
1425 up(&u132->scheduler_lock);
1426 u132_endp_put_kref(u132, endp);
1428 } else if (address == 0) {
1430 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1433 ring->curr_endp = endp;
1435 up(&u132->scheduler_lock);
1436 retval = edset_setup(u132, ring, endp, urb, address,
1437 0x2, u132_hcd_initial_setup_sent);
1440 u132_hcd_giveback_urb(u132, endp, urb, retval);
1442 } else if (endp->usb_addr == 0) {
1444 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1447 ring->curr_endp = endp;
1449 up(&u132->scheduler_lock);
1450 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1451 u132_hcd_enumeration_address_sent);
1454 u132_hcd_giveback_urb(u132, endp, urb, retval);
1458 u8 address = u132->addr[endp->usb_addr].address;
1459 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1462 ring->curr_endp = endp;
1464 up(&u132->scheduler_lock);
1465 retval = edset_setup(u132, ring, endp, urb, address,
1466 0x2, u132_hcd_configure_setup_sent);
1469 u132_hcd_giveback_urb(u132, endp, urb, retval);
1474 u8 address = u132->addr[endp->usb_addr].address;
1476 up(&u132->scheduler_lock);
1477 u132_endp_put_kref(u132, endp);
1481 struct urb *urb = endp->urb_list[
1482 ENDP_QUEUE_MASK & endp->queue_next];
1484 ring->curr_endp = endp;
1486 up(&u132->scheduler_lock);
1487 retval = edset_input(u132, ring, endp, urb,
1488 address, endp->toggle_bits,
1489 u132_hcd_bulk_input_recv);
1492 u132_hcd_giveback_urb(u132, endp, urb,
1496 } else { /* output pipe */
1497 u8 address = u132->addr[endp->usb_addr].address;
1499 up(&u132->scheduler_lock);
1500 u132_endp_put_kref(u132, endp);
1504 struct urb *urb = endp->urb_list[
1505 ENDP_QUEUE_MASK & endp->queue_next];
1507 ring->curr_endp = endp;
1509 up(&u132->scheduler_lock);
1510 retval = edset_output(u132, ring, endp, urb,
1511 address, endp->toggle_bits,
1512 u132_hcd_bulk_output_sent);
1515 u132_hcd_giveback_urb(u132, endp, urb,
1524 static void port_power(struct u132 *u132, int pn, int is_on)
1526 u132->port[pn].power = is_on;
1531 static void u132_power(struct u132 *u132, int is_on)
1533 struct usb_hcd *hcd = u132_to_hcd(u132)
1534 ; /* hub is inactive unless the port is powered */
1539 hcd->self.controller->power.power_state = PMSG_ON;
1542 hcd->state = HC_STATE_HALT;
1543 hcd->self.controller->power.power_state = PMSG_SUSPEND;
1547 static int u132_periodic_reinit(struct u132 *u132)
1550 u32 fi = u132->hc_fminterval & 0x03fff;
1553 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1556 fit = fminterval & FIT;
1557 retval = u132_write_pcimem(u132, fminterval,
1558 (fit ^ FIT) | u132->hc_fminterval);
1561 retval = u132_write_pcimem(u132, periodicstart,
1562 ((9 *fi) / 10) & 0x3fff);
1568 static char *hcfs2string(int state)
1571 case OHCI_USB_RESET:
1573 case OHCI_USB_RESUME:
1576 return "operational";
1577 case OHCI_USB_SUSPEND:
1583 static int u132_init(struct u132 *u132)
1588 u132->next_statechange = jiffies;
1589 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1592 retval = u132_read_pcimem(u132, control, &control);
1595 if (u132->num_ports == 0) {
1597 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1600 u132->num_ports = rh_a & RH_A_NDP;
1601 retval = read_roothub_info(u132);
1605 if (u132->num_ports > MAX_U132_PORTS) {
1612 /* Start an OHCI controller, set the BUS operational
1613 * resets USB and controller
1616 static int u132_run(struct u132 *u132)
1625 int mask = OHCI_INTR_INIT;
1626 int first = u132->hc_fminterval == 0;
1628 int reset_timeout = 30; /* ... allow extra time */
1632 retval = u132_read_pcimem(u132, fminterval, &temp);
1635 u132->hc_fminterval = temp & 0x3fff;
1636 if (u132->hc_fminterval != FI) {
1638 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1640 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1643 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1644 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1646 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1650 case OHCI_USB_SUSPEND:
1651 case OHCI_USB_RESUME:
1652 u132->hc_control &= OHCI_CTRL_RWC;
1653 u132->hc_control |= OHCI_USB_RESUME;
1657 u132->hc_control &= OHCI_CTRL_RWC;
1658 u132->hc_control |= OHCI_USB_RESET;
1662 retval = u132_write_pcimem(u132, control, u132->hc_control);
1665 retval = u132_read_pcimem(u132, control, &control);
1669 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1672 if (!(roothub_a & RH_A_NPS)) {
1673 int temp; /* power down each port */
1674 for (temp = 0; temp < u132->num_ports; temp++) {
1675 retval = u132_write_pcimem(u132,
1676 roothub.portstatus[temp], RH_PS_LSDA);
1681 retval = u132_read_pcimem(u132, control, &control);
1684 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1687 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1691 retval = u132_read_pcimem(u132, cmdstatus, &status);
1694 if (0 != (status & OHCI_HCR)) {
1695 if (--reset_timeout == 0) {
1696 dev_err(&u132->platform_dev->dev, "USB HC reset"
1705 if (u132->flags & OHCI_QUIRK_INITRESET) {
1706 retval = u132_write_pcimem(u132, control, u132->hc_control);
1709 retval = u132_read_pcimem(u132, control, &control);
1713 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1716 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1719 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1722 retval = u132_periodic_reinit(u132);
1725 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1728 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1731 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1732 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1733 u132->flags |= OHCI_QUIRK_INITRESET;
1736 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1737 "\n", fminterval, periodicstart);
1738 } /* start controller operations */
1739 u132->hc_control &= OHCI_CTRL_RWC;
1740 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1741 retval = u132_write_pcimem(u132, control, u132->hc_control);
1744 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1747 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1750 retval = u132_read_pcimem(u132, control, &control);
1753 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1754 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1757 retval = u132_write_pcimem(u132, intrstatus, mask);
1760 retval = u132_write_pcimem(u132, intrdisable,
1761 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1762 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1765 return retval; /* handle root hub init quirks ... */
1766 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1769 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1770 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1771 roothub_a |= RH_A_NOCP;
1772 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1773 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1776 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1777 roothub_a |= RH_A_NPS;
1778 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1782 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1785 retval = u132_write_pcimem(u132, roothub.b,
1786 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1789 retval = u132_read_pcimem(u132, control, &control);
1792 mdelay((roothub_a >> 23) & 0x1fe);
1793 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1797 static void u132_hcd_stop(struct usb_hcd *hcd)
1799 struct u132 *u132 = hcd_to_u132(hcd);
1800 if (u132->going > 1) {
1801 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1802 "een removed %d\n", u132, hcd, u132->going);
1803 } else if (u132->going > 0) {
1804 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1807 down(&u132->sw_lock);
1809 u132_power(u132, 0);
1814 static int u132_hcd_start(struct usb_hcd *hcd)
1816 struct u132 *u132 = hcd_to_u132(hcd);
1817 if (u132->going > 1) {
1818 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1821 } else if (u132->going > 0) {
1822 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1824 } else if (hcd->self.controller) {
1826 struct platform_device *pdev =
1827 to_platform_device(hcd->self.controller);
1828 u16 vendor = ((struct u132_platform_data *)
1829 (pdev->dev.platform_data))->vendor;
1830 u16 device = ((struct u132_platform_data *)
1831 (pdev->dev.platform_data))->device;
1832 down(&u132->sw_lock);
1834 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1835 u132->flags = OHCI_QUIRK_AMD756;
1836 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1837 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1838 "ounds unavailable\n");
1839 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1840 u132->flags |= OHCI_QUIRK_ZFMICRO;
1841 retval = u132_run(u132);
1850 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1855 static int u132_hcd_reset(struct usb_hcd *hcd)
1857 struct u132 *u132 = hcd_to_u132(hcd);
1858 if (u132->going > 1) {
1859 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1862 } else if (u132->going > 0) {
1863 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1867 down(&u132->sw_lock);
1868 retval = u132_init(u132);
1878 static int create_endpoint_and_queue_int(struct u132 *u132,
1879 struct u132_udev *udev, struct urb *urb,
1880 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1883 struct u132_ring *ring;
1887 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1893 spin_lock_init(&endp->queue_lock.slock);
1894 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1895 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1897 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1902 endp_number = ++u132->num_endpoints;
1903 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1904 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1905 INIT_LIST_HEAD(&endp->urb_more);
1906 ring = endp->ring = &u132->ring[0];
1907 if (ring->curr_endp) {
1908 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1910 INIT_LIST_HEAD(&endp->endp_ring);
1911 ring->curr_endp = endp;
1914 endp->dequeueing = 0;
1915 endp->edset_flush = 0;
1918 endp->endp_number = endp_number;
1920 endp->hep = urb->ep;
1921 endp->pipetype = usb_pipetype(urb->pipe);
1922 u132_endp_init_kref(u132, endp);
1923 if (usb_pipein(urb->pipe)) {
1924 endp->toggle_bits = 0x2;
1925 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1928 udev->endp_number_in[usb_endp] = endp_number;
1929 u132_udev_get_kref(u132, udev);
1931 endp->toggle_bits = 0x2;
1932 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1935 udev->endp_number_out[usb_endp] = endp_number;
1936 u132_udev_get_kref(u132, udev);
1940 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1941 endp->udev_number = address;
1942 endp->usb_addr = usb_addr;
1943 endp->usb_endp = usb_endp;
1944 endp->queue_size = 1;
1945 endp->queue_last = 0;
1946 endp->queue_next = 0;
1947 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1948 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1949 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1953 static int queue_int_on_old_endpoint(struct u132 *u132,
1954 struct u132_udev *udev, struct urb *urb,
1955 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1956 u8 usb_endp, u8 address)
1960 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1961 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1962 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1964 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1967 endp->queue_size -= 1;
1970 list_add_tail(&urbq->urb_more, &endp->urb_more);
1977 static int create_endpoint_and_queue_bulk(struct u132 *u132,
1978 struct u132_udev *udev, struct urb *urb,
1979 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1983 struct u132_ring *ring;
1987 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1993 spin_lock_init(&endp->queue_lock.slock);
1994 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1995 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1997 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2002 endp_number = ++u132->num_endpoints;
2003 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2004 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2005 INIT_LIST_HEAD(&endp->urb_more);
2006 endp->dequeueing = 0;
2007 endp->edset_flush = 0;
2010 endp->endp_number = endp_number;
2012 endp->hep = urb->ep;
2013 endp->pipetype = usb_pipetype(urb->pipe);
2014 u132_endp_init_kref(u132, endp);
2015 if (usb_pipein(urb->pipe)) {
2016 endp->toggle_bits = 0x2;
2017 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
2021 udev->endp_number_in[usb_endp] = endp_number;
2022 u132_udev_get_kref(u132, udev);
2024 endp->toggle_bits = 0x2;
2025 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2029 udev->endp_number_out[usb_endp] = endp_number;
2030 u132_udev_get_kref(u132, udev);
2032 ring = endp->ring = &u132->ring[ring_number - 1];
2033 if (ring->curr_endp) {
2034 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2036 INIT_LIST_HEAD(&endp->endp_ring);
2037 ring->curr_endp = endp;
2041 endp->udev_number = address;
2042 endp->usb_addr = usb_addr;
2043 endp->usb_endp = usb_endp;
2044 endp->queue_size = 1;
2045 endp->queue_last = 0;
2046 endp->queue_next = 0;
2047 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2048 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2049 u132_endp_queue_work(u132, endp, 0);
2053 static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2055 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2056 u8 usb_endp, u8 address)
2059 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2060 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2062 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2065 endp->queue_size -= 1;
2068 list_add_tail(&urbq->urb_more, &endp->urb_more);
2075 static int create_endpoint_and_queue_control(struct u132 *u132,
2077 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2080 struct u132_ring *ring;
2084 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
2090 spin_lock_init(&endp->queue_lock.slock);
2091 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2092 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
2094 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2099 endp_number = ++u132->num_endpoints;
2100 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2101 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2102 INIT_LIST_HEAD(&endp->urb_more);
2103 ring = endp->ring = &u132->ring[0];
2104 if (ring->curr_endp) {
2105 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2107 INIT_LIST_HEAD(&endp->endp_ring);
2108 ring->curr_endp = endp;
2111 endp->dequeueing = 0;
2112 endp->edset_flush = 0;
2115 endp->endp_number = endp_number;
2117 endp->hep = urb->ep;
2118 u132_endp_init_kref(u132, endp);
2119 u132_endp_get_kref(u132, endp);
2120 if (usb_addr == 0) {
2121 u8 address = u132->addr[usb_addr].address;
2122 struct u132_udev *udev = &u132->udev[address];
2123 endp->udev_number = address;
2124 endp->usb_addr = usb_addr;
2125 endp->usb_endp = usb_endp;
2128 endp->pipetype = usb_pipetype(urb->pipe);
2129 u132_udev_init_kref(u132, udev);
2130 u132_udev_get_kref(u132, udev);
2131 udev->endp_number_in[usb_endp] = endp_number;
2132 udev->endp_number_out[usb_endp] = endp_number;
2134 endp->queue_size = 1;
2135 endp->queue_last = 0;
2136 endp->queue_next = 0;
2137 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2138 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2139 u132_endp_queue_work(u132, endp, 0);
2141 } else { /*(usb_addr > 0) */
2142 u8 address = u132->addr[usb_addr].address;
2143 struct u132_udev *udev = &u132->udev[address];
2144 endp->udev_number = address;
2145 endp->usb_addr = usb_addr;
2146 endp->usb_endp = usb_endp;
2149 endp->pipetype = usb_pipetype(urb->pipe);
2150 u132_udev_get_kref(u132, udev);
2151 udev->enumeration = 2;
2152 udev->endp_number_in[usb_endp] = endp_number;
2153 udev->endp_number_out[usb_endp] = endp_number;
2155 endp->queue_size = 1;
2156 endp->queue_last = 0;
2157 endp->queue_next = 0;
2158 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2159 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2160 u132_endp_queue_work(u132, endp, 0);
2165 static int queue_control_on_old_endpoint(struct u132 *u132,
2167 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2170 if (usb_addr == 0) {
2171 if (usb_pipein(urb->pipe)) {
2173 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2174 endp->urb_list[ENDP_QUEUE_MASK &
2175 endp->queue_last++] = urb;
2177 struct u132_urbq *urbq =
2178 kmalloc(sizeof(struct u132_urbq),
2181 endp->queue_size -= 1;
2184 list_add_tail(&urbq->urb_more,
2190 } else { /* usb_pipeout(urb->pipe) */
2191 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2192 int I = MAX_U132_UDEVS;
2195 struct u132_udev *udev = &u132->udev[++i];
2196 if (udev->usb_device) {
2199 udev->enumeration = 1;
2200 u132->addr[0].address = i;
2201 endp->udev_number = i;
2202 udev->udev_number = i;
2203 udev->usb_addr = usb_dev->devnum;
2204 u132_udev_init_kref(u132, udev);
2205 udev->endp_number_in[usb_endp] =
2207 u132_udev_get_kref(u132, udev);
2208 udev->endp_number_out[usb_endp] =
2210 udev->usb_device = usb_dev;
2211 ((u8 *) (urb->setup_packet))[2] =
2213 u132_udev_get_kref(u132, udev);
2218 dev_err(&u132->platform_dev->dev, "run out of d"
2223 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2224 endp->urb_list[ENDP_QUEUE_MASK &
2225 endp->queue_last++] = urb;
2227 struct u132_urbq *urbq =
2228 kmalloc(sizeof(struct u132_urbq),
2231 endp->queue_size -= 1;
2234 list_add_tail(&urbq->urb_more,
2241 } else { /*(usb_addr > 0) */
2242 u8 address = u132->addr[usb_addr].address;
2243 struct u132_udev *udev = &u132->udev[address];
2245 if (udev->enumeration == 2) {
2247 udev->enumeration = 2;
2248 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2249 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2252 struct u132_urbq *urbq =
2253 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2255 endp->queue_size -= 1;
2258 list_add_tail(&urbq->urb_more, &endp->urb_more);
2266 static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2269 struct u132 *u132 = hcd_to_u132(hcd);
2270 if (irqs_disabled()) {
2271 if (__GFP_WAIT & mem_flags) {
2272 printk(KERN_ERR "invalid context for function that migh"
2277 if (u132->going > 1) {
2278 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2281 } else if (u132->going > 0) {
2282 dev_err(&u132->platform_dev->dev, "device is being removed urb="
2283 "%p status=%d\n", urb, urb->status);
2286 u8 usb_addr = usb_pipedevice(urb->pipe);
2287 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2288 struct usb_device *usb_dev = urb->dev;
2289 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2290 u8 address = u132->addr[usb_addr].address;
2291 struct u132_udev *udev = &u132->udev[address];
2292 struct u132_endp *endp = urb->ep->hcpriv;
2293 urb->actual_length = 0;
2297 spin_lock_irqsave(&endp->queue_lock.slock,
2299 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2301 retval = queue_int_on_old_endpoint(
2307 usb_hcd_unlink_urb_from_ep(
2310 spin_unlock_irqrestore(&endp->queue_lock.slock,
2315 u132_endp_queue_work(u132, endp,
2316 msecs_to_jiffies(urb->interval))
2320 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2322 } else { /*(endp == NULL) */
2323 return create_endpoint_and_queue_int(u132, udev,
2324 urb, usb_dev, usb_addr,
2325 usb_endp, address, mem_flags);
2327 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2328 dev_err(&u132->platform_dev->dev, "the hardware does no"
2329 "t support PIPE_ISOCHRONOUS\n");
2331 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2332 u8 address = u132->addr[usb_addr].address;
2333 struct u132_udev *udev = &u132->udev[address];
2334 struct u132_endp *endp = urb->ep->hcpriv;
2335 urb->actual_length = 0;
2339 spin_lock_irqsave(&endp->queue_lock.slock,
2341 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2343 retval = queue_bulk_on_old_endpoint(
2349 usb_hcd_unlink_urb_from_ep(
2352 spin_unlock_irqrestore(&endp->queue_lock.slock,
2357 u132_endp_queue_work(u132, endp, 0);
2360 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2363 return create_endpoint_and_queue_bulk(u132,
2364 udev, urb, usb_dev, usb_addr,
2365 usb_endp, address, mem_flags);
2367 struct u132_endp *endp = urb->ep->hcpriv;
2369 u8 *b = urb->setup_packet;
2371 char data[30 *3 + 4];
2373 int m = (sizeof(data) - 1) / 3;
2376 while (urb_size-- > 0) {
2378 } else if (i++ < m) {
2379 int w = sprintf(d, " %02X", *b++);
2383 d += sprintf(d, " ..");
2388 spin_lock_irqsave(&endp->queue_lock.slock,
2390 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2392 retval = queue_control_on_old_endpoint(
2397 usb_hcd_unlink_urb_from_ep(
2400 spin_unlock_irqrestore(&endp->queue_lock.slock,
2405 u132_endp_queue_work(u132, endp, 0);
2408 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2411 return create_endpoint_and_queue_control(u132,
2412 urb, usb_dev, usb_addr, usb_endp,
2418 static int dequeue_from_overflow_chain(struct u132 *u132,
2419 struct u132_endp *endp, struct urb *urb)
2421 struct list_head *scan;
2422 struct list_head *head = &endp->urb_more;
2423 list_for_each(scan, head) {
2424 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2426 if (urbq->urb == urb) {
2427 struct usb_hcd *hcd = u132_to_hcd(u132);
2429 endp->queue_size -= 1;
2430 urb->error_count = 0;
2431 usb_hcd_giveback_urb(hcd, urb);
2436 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2437 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2438 "\n", urb, endp->endp_number, endp, endp->ring->number,
2439 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2440 endp->usb_endp, endp->usb_addr, endp->queue_size,
2441 endp->queue_next, endp->queue_last);
2445 static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2446 struct urb *urb, int status)
2451 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2452 rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status);
2454 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2457 if (endp->queue_size == 0) {
2458 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2459 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2460 endp->endp_number, endp, endp->ring->number,
2461 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2462 endp->usb_endp, endp->usb_addr);
2463 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2466 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2468 endp->dequeueing = 1;
2469 endp->edset_flush = 1;
2470 u132_endp_queue_work(u132, endp, 0);
2471 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2474 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2475 u132_hcd_abandon_urb(u132, endp, urb, urb->status);
2480 u16 queue_size = endp->queue_size;
2481 u16 queue_scan = endp->queue_next;
2482 struct urb **urb_slot = NULL;
2483 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2484 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2486 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2492 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2493 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2495 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2499 struct usb_hcd *hcd = u132_to_hcd(u132);
2501 usb_hcd_unlink_urb_from_ep(hcd, urb);
2502 endp->queue_size -= 1;
2503 if (list_empty(&endp->urb_more)) {
2504 spin_unlock_irqrestore(&endp->queue_lock.slock,
2507 struct list_head *next = endp->urb_more.next;
2508 struct u132_urbq *urbq = list_entry(next,
2509 struct u132_urbq, urb_more);
2511 *urb_slot = urbq->urb;
2512 spin_unlock_irqrestore(&endp->queue_lock.slock,
2515 } urb->error_count = 0;
2516 usb_hcd_giveback_urb(hcd, urb);
2518 } else if (list_empty(&endp->urb_more)) {
2519 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2520 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2521 "=%d size=%d next=%04X last=%04X\n", urb,
2522 endp->endp_number, endp, endp->ring->number,
2523 endp->input ? 'I' : ' ',
2524 endp->output ? 'O' : ' ', endp->usb_endp,
2525 endp->usb_addr, endp->queue_size,
2526 endp->queue_next, endp->queue_last);
2527 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2532 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb);
2533 retval = dequeue_from_overflow_chain(u132, endp,
2535 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2541 static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2543 struct u132 *u132 = hcd_to_u132(hcd);
2544 if (u132->going > 2) {
2545 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2549 u8 usb_addr = usb_pipedevice(urb->pipe);
2550 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2551 u8 address = u132->addr[usb_addr].address;
2552 struct u132_udev *udev = &u132->udev[address];
2553 if (usb_pipein(urb->pipe)) {
2554 u8 endp_number = udev->endp_number_in[usb_endp];
2555 struct u132_endp *endp = u132->endp[endp_number - 1];
2556 return u132_endp_urb_dequeue(u132, endp, urb, status);
2558 u8 endp_number = udev->endp_number_out[usb_endp];
2559 struct u132_endp *endp = u132->endp[endp_number - 1];
2560 return u132_endp_urb_dequeue(u132, endp, urb, status);
2565 static void u132_endpoint_disable(struct usb_hcd *hcd,
2566 struct usb_host_endpoint *hep)
2568 struct u132 *u132 = hcd_to_u132(hcd);
2569 if (u132->going > 2) {
2570 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2571 ") has been removed %d\n", u132, hcd, hep,
2574 struct u132_endp *endp = hep->hcpriv;
2576 u132_endp_put_kref(u132, endp);
2580 static int u132_get_frame(struct usb_hcd *hcd)
2582 struct u132 *u132 = hcd_to_u132(hcd);
2583 if (u132->going > 1) {
2584 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2587 } else if (u132->going > 0) {
2588 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2592 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2598 static int u132_roothub_descriptor(struct u132 *u132,
2599 struct usb_hub_descriptor *desc)
2605 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2608 desc->bDescriptorType = 0x29;
2609 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2610 desc->bHubContrCurrent = 0;
2611 desc->bNbrPorts = u132->num_ports;
2612 temp = 1 + (u132->num_ports / 8);
2613 desc->bDescLength = 7 + 2 *temp;
2615 if (rh_a & RH_A_NPS)
2617 if (rh_a & RH_A_PSM)
2619 if (rh_a & RH_A_NOCP) {
2621 } else if (rh_a & RH_A_OCPM)
2623 desc->wHubCharacteristics = cpu_to_le16(temp);
2624 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2627 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2628 desc->bitmap[0] = rh_b & RH_B_DR;
2629 if (u132->num_ports > 7) {
2630 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2631 desc->bitmap[2] = 0xff;
2633 desc->bitmap[1] = 0xff;
2637 static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2640 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2641 *desc = cpu_to_le32(rh_status);
2645 static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2647 if (wIndex == 0 || wIndex > u132->num_ports) {
2650 int port = wIndex - 1;
2651 u32 rh_portstatus = -1;
2652 int ret_portstatus = u132_read_pcimem(u132,
2653 roothub.portstatus[port], &rh_portstatus);
2654 *desc = cpu_to_le32(rh_portstatus);
2655 if (*(u16 *) (desc + 2)) {
2656 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2657 "ge = %08X\n", port, *desc);
2659 return ret_portstatus;
2664 /* this timer value might be vendor-specific ... */
2665 #define PORT_RESET_HW_MSEC 10
2666 #define PORT_RESET_MSEC 10
2667 /* wrap-aware logic morphed from <linux/jiffies.h> */
2668 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2669 static int u132_roothub_portreset(struct u132 *u132, int port_index)
2675 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2679 reset_done = now + PORT_RESET_MSEC;
2683 retval = u132_read_pcimem(u132,
2684 roothub.portstatus[port_index], &portstat);
2687 if (RH_PS_PRS & portstat) {
2691 } while (tick_before(now, reset_done));
2692 if (RH_PS_PRS & portstat)
2694 if (RH_PS_CCS & portstat) {
2695 if (RH_PS_PRSC & portstat) {
2696 retval = u132_write_pcimem(u132,
2697 roothub.portstatus[port_index],
2703 break; /* start the next reset,
2704 sleep till it's probably done */
2705 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2709 msleep(PORT_RESET_HW_MSEC);
2710 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2714 } while (tick_before(now, reset_done));
2718 static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2721 if (wIndex == 0 || wIndex > u132->num_ports) {
2725 int port_index = wIndex - 1;
2726 struct u132_port *port = &u132->port[port_index];
2727 port->Status &= ~(1 << wValue);
2729 case USB_PORT_FEAT_SUSPEND:
2730 retval = u132_write_pcimem(u132,
2731 roothub.portstatus[port_index], RH_PS_PSS);
2735 case USB_PORT_FEAT_POWER:
2736 retval = u132_write_pcimem(u132,
2737 roothub.portstatus[port_index], RH_PS_PPS);
2741 case USB_PORT_FEAT_RESET:
2742 retval = u132_roothub_portreset(u132, port_index);
2752 static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2755 if (wIndex == 0 || wIndex > u132->num_ports) {
2758 int port_index = wIndex - 1;
2761 struct u132_port *port = &u132->port[port_index];
2762 port->Status &= ~(1 << wValue);
2764 case USB_PORT_FEAT_ENABLE:
2767 case USB_PORT_FEAT_C_ENABLE:
2770 case USB_PORT_FEAT_SUSPEND:
2772 if ((u132->hc_control & OHCI_CTRL_HCFS)
2774 dev_err(&u132->platform_dev->dev, "TODO resume_"
2778 case USB_PORT_FEAT_C_SUSPEND:
2781 case USB_PORT_FEAT_POWER:
2784 case USB_PORT_FEAT_C_CONNECTION:
2787 case USB_PORT_FEAT_C_OVER_CURRENT:
2790 case USB_PORT_FEAT_C_RESET:
2796 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2805 /* the virtual root hub timer IRQ checks for hub status*/
2806 static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2808 struct u132 *u132 = hcd_to_u132(hcd);
2809 if (u132->going > 1) {
2810 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2811 "ed %d\n", hcd, u132->going);
2813 } else if (u132->going > 0) {
2814 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2818 int i, changed = 0, length = 1;
2819 if (u132->flags & OHCI_QUIRK_AMD756) {
2820 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2821 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2822 "ereads as NDP=%d\n",
2823 u132->hc_roothub_a & RH_A_NDP);
2827 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) {
2828 buf[0] = changed = 1;
2831 if (u132->num_ports > 7) {
2835 for (i = 0; i < u132->num_ports; i++) {
2836 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2837 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2841 buf[0] |= 1 << (i + 1);
2843 buf[1] |= 1 << (i - 7);
2846 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) {
2849 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) {
2853 done:return changed ? length : 0;
2857 static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2858 u16 wIndex, char *buf, u16 wLength)
2860 struct u132 *u132 = hcd_to_u132(hcd);
2861 if (u132->going > 1) {
2862 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2865 } else if (u132->going > 0) {
2866 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2870 down(&u132->sw_lock);
2872 case ClearHubFeature:
2874 case C_HUB_OVER_CURRENT:
2875 case C_HUB_LOCAL_POWER:
2883 case C_HUB_OVER_CURRENT:
2884 case C_HUB_LOCAL_POWER:
2890 case ClearPortFeature:{
2891 retval = u132_roothub_clearportfeature(u132,
2897 case GetHubDescriptor:{
2898 retval = u132_roothub_descriptor(u132,
2899 (struct usb_hub_descriptor *)buf);
2905 retval = u132_roothub_status(u132,
2911 case GetPortStatus:{
2912 retval = u132_roothub_portstatus(u132,
2913 (__le32 *) buf, wIndex);
2918 case SetPortFeature:{
2919 retval = u132_roothub_setportfeature(u132,
2927 error:u132_disable(u132);
2930 stall:retval = -EPIPE;
2938 static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2940 struct u132 *u132 = hcd_to_u132(hcd);
2941 if (u132->going > 1) {
2942 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2945 } else if (u132->going > 0) {
2946 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2952 static void u132_hub_irq_enable(struct usb_hcd *hcd)
2954 struct u132 *u132 = hcd_to_u132(hcd);
2955 if (u132->going > 1) {
2956 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2958 } else if (u132->going > 0)
2959 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2964 static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2966 struct u132 *u132 = hcd_to_u132(hcd);
2967 if (u132->going > 1) {
2968 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2971 } else if (u132->going > 0) {
2972 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2978 static int u132_hcd_resume(struct usb_hcd *hcd)
2980 struct u132 *u132 = hcd_to_u132(hcd);
2981 if (u132->going > 1) {
2982 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2985 } else if (u132->going > 0) {
2986 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2992 static int u132_bus_suspend(struct usb_hcd *hcd)
2994 struct u132 *u132 = hcd_to_u132(hcd);
2995 if (u132->going > 1) {
2996 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2999 } else if (u132->going > 0) {
3000 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3006 static int u132_bus_resume(struct usb_hcd *hcd)
3008 struct u132 *u132 = hcd_to_u132(hcd);
3009 if (u132->going > 1) {
3010 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3013 } else if (u132->going > 0) {
3014 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3021 #define u132_hcd_suspend NULL
3022 #define u132_hcd_resume NULL
3023 #define u132_bus_suspend NULL
3024 #define u132_bus_resume NULL
3026 static struct hc_driver u132_hc_driver = {
3027 .description = hcd_name,
3028 .hcd_priv_size = sizeof(struct u132),
3030 .flags = HCD_USB11 | HCD_MEMORY,
3031 .reset = u132_hcd_reset,
3032 .start = u132_hcd_start,
3033 .suspend = u132_hcd_suspend,
3034 .resume = u132_hcd_resume,
3035 .stop = u132_hcd_stop,
3036 .urb_enqueue = u132_urb_enqueue,
3037 .urb_dequeue = u132_urb_dequeue,
3038 .endpoint_disable = u132_endpoint_disable,
3039 .get_frame_number = u132_get_frame,
3040 .hub_status_data = u132_hub_status_data,
3041 .hub_control = u132_hub_control,
3042 .bus_suspend = u132_bus_suspend,
3043 .bus_resume = u132_bus_resume,
3044 .start_port_reset = u132_start_port_reset,
3045 .hub_irq_enable = u132_hub_irq_enable,
3049 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
3050 * is held for writing, thus this module must not call usb_remove_hcd()
3051 * synchronously - but instead should immediately stop activity to the
3052 * device and asynchronously call usb_remove_hcd()
3054 static int __devexit u132_remove(struct platform_device *pdev)
3056 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3058 struct u132 *u132 = hcd_to_u132(hcd);
3059 if (u132->going++ > 1) {
3060 dev_err(&u132->platform_dev->dev, "already being remove"
3064 int rings = MAX_U132_RINGS;
3065 int endps = MAX_U132_ENDPS;
3066 dev_err(&u132->platform_dev->dev, "removing device u132"
3067 ".%d\n", u132->sequence_num);
3069 down(&u132->sw_lock);
3070 u132_monitor_cancel_work(u132);
3071 while (rings-- > 0) {
3072 struct u132_ring *ring = &u132->ring[rings];
3073 u132_ring_cancel_work(u132, ring);
3074 } while (endps-- > 0) {
3075 struct u132_endp *endp = u132->endp[endps];
3077 u132_endp_cancel_work(u132, endp);
3080 printk(KERN_INFO "removing device u132.%d\n",
3081 u132->sequence_num);
3083 usb_remove_hcd(hcd);
3084 u132_u132_put_kref(u132);
3091 static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3093 int rings = MAX_U132_RINGS;
3094 int ports = MAX_U132_PORTS;
3095 int addrs = MAX_U132_ADDRS;
3096 int udevs = MAX_U132_UDEVS;
3097 int endps = MAX_U132_ENDPS;
3098 u132->board = pdev->dev.platform_data;
3099 u132->platform_dev = pdev;
3102 init_MUTEX(&u132->sw_lock);
3103 init_MUTEX(&u132->scheduler_lock);
3104 while (rings-- > 0) {
3105 struct u132_ring *ring = &u132->ring[rings];
3107 ring->number = rings + 1;
3109 ring->curr_endp = NULL;
3110 INIT_DELAYED_WORK(&ring->scheduler,
3111 u132_hcd_ring_work_scheduler);
3112 } down(&u132->sw_lock);
3113 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3114 while (ports-- > 0) {
3115 struct u132_port *port = &u132->port[ports];
3121 } while (addrs-- > 0) {
3122 struct u132_addr *addr = &u132->addr[addrs];
3124 } while (udevs-- > 0) {
3125 struct u132_udev *udev = &u132->udev[udevs];
3126 int i = ARRAY_SIZE(udev->endp_number_in);
3127 int o = ARRAY_SIZE(udev->endp_number_out);
3128 udev->usb_device = NULL;
3129 udev->udev_number = 0;
3131 udev->portnumber = 0;
3133 udev->endp_number_in[i] = 0;
3136 udev->endp_number_out[o] = 0;
3139 while (endps-- > 0) {
3140 u132->endp[endps] = NULL;
3146 static int __devinit u132_probe(struct platform_device *pdev)
3148 struct usb_hcd *hcd;
3154 if (u132_exiting > 0) {
3157 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3160 retval = ftdi_read_pcimem(pdev, control, &control);
3163 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3166 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3167 if (pdev->dev.dma_mask) {
3170 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3172 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3174 ftdi_elan_gone_away(pdev);
3178 struct u132 *u132 = hcd_to_u132(hcd);
3179 hcd->rsrc_start = 0;
3180 mutex_lock(&u132_module_lock);
3181 list_add_tail(&u132->u132_list, &u132_static_list);
3182 u132->sequence_num = ++u132_instances;
3183 mutex_unlock(&u132_module_lock);
3184 u132_u132_init_kref(u132);
3185 u132_initialise(u132, pdev);
3186 hcd->product_desc = "ELAN U132 Host Controller";
3187 retval = usb_add_hcd(hcd, 0, 0);
3189 dev_err(&u132->platform_dev->dev, "init error %d\n",
3191 u132_u132_put_kref(u132);
3194 u132_monitor_queue_work(u132, 100);
3202 /* for this device there's no useful distinction between the controller
3203 * and its root hub, except that the root hub only gets direct PM calls
3204 * when CONFIG_USB_SUSPEND is enabled.
3206 static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3208 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3209 struct u132 *u132 = hcd_to_u132(hcd);
3210 if (u132->going > 1) {
3211 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3214 } else if (u132->going > 0) {
3215 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3219 if (state.event == PM_EVENT_FREEZE) {
3220 retval = u132_bus_suspend(hcd);
3221 } else if (state.event == PM_EVENT_SUSPEND) {
3222 int ports = MAX_U132_PORTS;
3223 while (ports-- > 0) {
3224 port_power(u132, ports, 0);
3228 pdev->dev.power.power_state = state;
3233 static int u132_resume(struct platform_device *pdev)
3235 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3236 struct u132 *u132 = hcd_to_u132(hcd);
3237 if (u132->going > 1) {
3238 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3241 } else if (u132->going > 0) {
3242 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3246 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
3247 int ports = MAX_U132_PORTS;
3248 while (ports-- > 0) {
3249 port_power(u132, ports, 1);
3253 pdev->dev.power.power_state = PMSG_ON;
3254 retval = u132_bus_resume(hcd);
3261 #define u132_suspend NULL
3262 #define u132_resume NULL
3265 * this driver is loaded explicitly by ftdi_u132
3267 * the platform_driver struct is static because it is per type of module
3269 static struct platform_driver u132_platform_driver = {
3270 .probe = u132_probe,
3271 .remove = __devexit_p(u132_remove),
3272 .suspend = u132_suspend,
3273 .resume = u132_resume,
3275 .name = (char *)hcd_name,
3276 .owner = THIS_MODULE,
3279 static int __init u132_hcd_init(void)
3282 INIT_LIST_HEAD(&u132_static_list);
3285 mutex_init(&u132_module_lock);
3288 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3290 workqueue = create_singlethread_workqueue("u132");
3291 retval = platform_driver_register(&u132_platform_driver);
3296 module_init(u132_hcd_init);
3297 static void __exit u132_hcd_exit(void)
3301 mutex_lock(&u132_module_lock);
3303 mutex_unlock(&u132_module_lock);
3304 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3305 platform_device_unregister(u132->platform_dev);
3306 } platform_driver_unregister(&u132_platform_driver);
3307 printk(KERN_INFO "u132-hcd driver deregistered\n");
3308 wait_event(u132_hcd_wait, u132_instances == 0);
3309 flush_workqueue(workqueue);
3310 destroy_workqueue(workqueue);
3314 module_exit(u132_hcd_exit);
3315 MODULE_LICENSE("GPL");