2 * Host Controller Driver for the Elan Digital Systems U132 adapter
4 * Copyright(C) 2006 Elan Digital Systems Limited
5 * http://www.elandigitalsystems.com
7 * Author and Maintainer - Tony Olech - Elan Digital Systems
8 * tony.olech@elandigitalsystems.com
10 * This program is free software;you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation, version 2.
15 * This driver was written by Tony Olech(tony.olech@elandigitalsystems.com)
16 * based on various USB host drivers in the 2.6.15 linux kernel
17 * with constant reference to the 3rd Edition of Linux Device Drivers
18 * published by O'Reilly
20 * The U132 adapter is a USB to CardBus adapter specifically designed
21 * for PC cards that contain an OHCI host controller. Typical PC cards
22 * are the Orange Mobile 3G Option GlobeTrotter Fusion card.
24 * The U132 adapter will *NOT *work with PC cards that do not contain
25 * an OHCI controller. A simple way to test whether a PC card has an
26 * OHCI controller as an interface is to insert the PC card directly
27 * into a laptop(or desktop) with a CardBus slot and if "lspci" shows
28 * a new USB controller and "lsusb -v" shows a new OHCI Host Controller
29 * then there is a good chance that the U132 adapter will support the
30 * PC card.(you also need the specific client driver for the PC card)
32 * Please inform the Author and Maintainer about any PC cards that
33 * contain OHCI Host Controller and work when directly connected to
34 * an embedded CardBus slot but do not work when they are connected
35 * via an ELAN U132 adapter.
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/moduleparam.h>
41 #include <linux/delay.h>
42 #include <linux/ioport.h>
43 #include <linux/pci_ids.h>
44 #include <linux/sched.h>
45 #include <linux/slab.h>
46 #include <linux/errno.h>
47 #include <linux/init.h>
48 #include <linux/timer.h>
49 #include <linux/list.h>
50 #include <linux/interrupt.h>
51 #include <linux/usb.h>
52 #include <linux/workqueue.h>
53 #include <linux/platform_device.h>
54 #include <linux/pci_ids.h>
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 semaphore 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 down(&u132_module_lock);
262 list_del_init(&u132->u132_list);
264 up(&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 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;
563 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
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,
1523 static void port_power(struct u132 *u132, int pn, int is_on)
1525 u132->port[pn].power = is_on;
1528 static void u132_power(struct u132 *u132, int is_on)
1530 struct usb_hcd *hcd = u132_to_hcd(u132)
1531 ; /* hub is inactive unless the port is powered */
1536 hcd->self.controller->power.power_state = PMSG_ON;
1539 hcd->state = HC_STATE_HALT;
1540 hcd->self.controller->power.power_state = PMSG_SUSPEND;
1544 static int u132_periodic_reinit(struct u132 *u132)
1547 u32 fi = u132->hc_fminterval & 0x03fff;
1550 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1553 fit = fminterval & FIT;
1554 retval = u132_write_pcimem(u132, fminterval,
1555 (fit ^ FIT) | u132->hc_fminterval);
1558 retval = u132_write_pcimem(u132, periodicstart,
1559 ((9 *fi) / 10) & 0x3fff);
1565 static char *hcfs2string(int state)
1568 case OHCI_USB_RESET:
1570 case OHCI_USB_RESUME:
1573 return "operational";
1574 case OHCI_USB_SUSPEND:
1580 static int u132_init(struct u132 *u132)
1585 u132->next_statechange = jiffies;
1586 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1589 retval = u132_read_pcimem(u132, control, &control);
1592 if (u132->num_ports == 0) {
1594 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1597 u132->num_ports = rh_a & RH_A_NDP;
1598 retval = read_roothub_info(u132);
1602 if (u132->num_ports > MAX_U132_PORTS) {
1609 /* Start an OHCI controller, set the BUS operational
1610 * resets USB and controller
1613 static int u132_run(struct u132 *u132)
1622 int mask = OHCI_INTR_INIT;
1623 int first = u132->hc_fminterval == 0;
1625 int reset_timeout = 30; /* ... allow extra time */
1629 retval = u132_read_pcimem(u132, fminterval, &temp);
1632 u132->hc_fminterval = temp & 0x3fff;
1633 if (u132->hc_fminterval != FI) {
1635 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1637 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1640 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1641 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1643 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1647 case OHCI_USB_SUSPEND:
1648 case OHCI_USB_RESUME:
1649 u132->hc_control &= OHCI_CTRL_RWC;
1650 u132->hc_control |= OHCI_USB_RESUME;
1654 u132->hc_control &= OHCI_CTRL_RWC;
1655 u132->hc_control |= OHCI_USB_RESET;
1659 retval = u132_write_pcimem(u132, control, u132->hc_control);
1662 retval = u132_read_pcimem(u132, control, &control);
1666 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1669 if (!(roothub_a & RH_A_NPS)) {
1670 int temp; /* power down each port */
1671 for (temp = 0; temp < u132->num_ports; temp++) {
1672 retval = u132_write_pcimem(u132,
1673 roothub.portstatus[temp], RH_PS_LSDA);
1678 retval = u132_read_pcimem(u132, control, &control);
1681 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1684 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1688 retval = u132_read_pcimem(u132, cmdstatus, &status);
1691 if (0 != (status & OHCI_HCR)) {
1692 if (--reset_timeout == 0) {
1693 dev_err(&u132->platform_dev->dev, "USB HC reset"
1702 if (u132->flags & OHCI_QUIRK_INITRESET) {
1703 retval = u132_write_pcimem(u132, control, u132->hc_control);
1706 retval = u132_read_pcimem(u132, control, &control);
1710 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1713 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1716 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1719 retval = u132_periodic_reinit(u132);
1722 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1725 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1728 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1729 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1730 u132->flags |= OHCI_QUIRK_INITRESET;
1733 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1734 "\n", fminterval, periodicstart);
1735 } /* start controller operations */
1736 u132->hc_control &= OHCI_CTRL_RWC;
1737 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1738 retval = u132_write_pcimem(u132, control, u132->hc_control);
1741 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1744 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1747 retval = u132_read_pcimem(u132, control, &control);
1750 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1751 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1754 retval = u132_write_pcimem(u132, intrstatus, mask);
1757 retval = u132_write_pcimem(u132, intrdisable,
1758 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1759 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1762 return retval; /* handle root hub init quirks ... */
1763 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1766 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1767 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1768 roothub_a |= RH_A_NOCP;
1769 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1770 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1773 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1774 roothub_a |= RH_A_NPS;
1775 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1779 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1782 retval = u132_write_pcimem(u132, roothub.b,
1783 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1786 retval = u132_read_pcimem(u132, control, &control);
1789 mdelay((roothub_a >> 23) & 0x1fe);
1790 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1794 static void u132_hcd_stop(struct usb_hcd *hcd)
1796 struct u132 *u132 = hcd_to_u132(hcd);
1797 if (u132->going > 1) {
1798 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1799 "een removed %d\n", u132, hcd, u132->going);
1800 } else if (u132->going > 0) {
1801 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1804 down(&u132->sw_lock);
1806 u132_power(u132, 0);
1811 static int u132_hcd_start(struct usb_hcd *hcd)
1813 struct u132 *u132 = hcd_to_u132(hcd);
1814 if (u132->going > 1) {
1815 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1818 } else if (u132->going > 0) {
1819 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1821 } else if (hcd->self.controller) {
1823 struct platform_device *pdev =
1824 to_platform_device(hcd->self.controller);
1825 u16 vendor = ((struct u132_platform_data *)
1826 (pdev->dev.platform_data))->vendor;
1827 u16 device = ((struct u132_platform_data *)
1828 (pdev->dev.platform_data))->device;
1829 down(&u132->sw_lock);
1831 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1832 u132->flags = OHCI_QUIRK_AMD756;
1833 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1834 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1835 "ounds unavailable\n");
1836 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1837 u132->flags |= OHCI_QUIRK_ZFMICRO;
1838 retval = u132_run(u132);
1847 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1852 static int u132_hcd_reset(struct usb_hcd *hcd)
1854 struct u132 *u132 = hcd_to_u132(hcd);
1855 if (u132->going > 1) {
1856 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1859 } else if (u132->going > 0) {
1860 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1864 down(&u132->sw_lock);
1865 retval = u132_init(u132);
1875 static int create_endpoint_and_queue_int(struct u132 *u132,
1876 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1877 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1880 struct u132_ring *ring;
1882 u8 endp_number = ++u132->num_endpoints;
1883 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1884 kmalloc(sizeof(struct u132_endp), mem_flags);
1888 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1889 spin_lock_init(&endp->queue_lock.slock);
1890 INIT_LIST_HEAD(&endp->urb_more);
1891 ring = endp->ring = &u132->ring[0];
1892 if (ring->curr_endp) {
1893 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1895 INIT_LIST_HEAD(&endp->endp_ring);
1896 ring->curr_endp = endp;
1899 endp->dequeueing = 0;
1900 endp->edset_flush = 0;
1903 endp->endp_number = endp_number;
1906 endp->pipetype = usb_pipetype(urb->pipe);
1907 u132_endp_init_kref(u132, endp);
1908 if (usb_pipein(urb->pipe)) {
1909 endp->toggle_bits = 0x2;
1910 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1913 udev->endp_number_in[usb_endp] = endp_number;
1914 u132_udev_get_kref(u132, udev);
1916 endp->toggle_bits = 0x2;
1917 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1920 udev->endp_number_out[usb_endp] = endp_number;
1921 u132_udev_get_kref(u132, udev);
1924 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1926 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1927 endp->udev_number = address;
1928 endp->usb_addr = usb_addr;
1929 endp->usb_endp = usb_endp;
1930 endp->queue_size = 1;
1931 endp->queue_last = 0;
1932 endp->queue_next = 0;
1933 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1934 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1935 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1939 static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
1940 struct usb_host_endpoint *hep, struct urb *urb,
1941 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1942 u8 usb_endp, u8 address)
1946 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1947 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1948 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1950 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1953 endp->queue_size -= 1;
1956 list_add_tail(&urbq->urb_more, &endp->urb_more);
1963 static int create_endpoint_and_queue_bulk(struct u132 *u132,
1964 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1965 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1969 struct u132_ring *ring;
1971 u8 endp_number = ++u132->num_endpoints;
1972 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1973 kmalloc(sizeof(struct u132_endp), mem_flags);
1977 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1978 spin_lock_init(&endp->queue_lock.slock);
1979 INIT_LIST_HEAD(&endp->urb_more);
1980 endp->dequeueing = 0;
1981 endp->edset_flush = 0;
1984 endp->endp_number = endp_number;
1987 endp->pipetype = usb_pipetype(urb->pipe);
1988 u132_endp_init_kref(u132, endp);
1989 if (usb_pipein(urb->pipe)) {
1990 endp->toggle_bits = 0x2;
1991 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1995 udev->endp_number_in[usb_endp] = endp_number;
1996 u132_udev_get_kref(u132, udev);
1998 endp->toggle_bits = 0x2;
1999 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2003 udev->endp_number_out[usb_endp] = endp_number;
2004 u132_udev_get_kref(u132, udev);
2006 ring = endp->ring = &u132->ring[ring_number - 1];
2007 if (ring->curr_endp) {
2008 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2010 INIT_LIST_HEAD(&endp->endp_ring);
2011 ring->curr_endp = endp;
2015 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2016 endp->udev_number = address;
2017 endp->usb_addr = usb_addr;
2018 endp->usb_endp = usb_endp;
2019 endp->queue_size = 1;
2020 endp->queue_last = 0;
2021 endp->queue_next = 0;
2022 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2023 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2024 u132_endp_queue_work(u132, endp, 0);
2028 static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2029 struct usb_host_endpoint *hep, struct urb *urb,
2030 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2031 u8 usb_endp, u8 address)
2034 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2035 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2037 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2040 endp->queue_size -= 1;
2043 list_add_tail(&urbq->urb_more, &endp->urb_more);
2050 static int create_endpoint_and_queue_control(struct u132 *u132,
2051 struct usb_host_endpoint *hep, struct urb *urb,
2052 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2055 struct u132_ring *ring;
2056 u8 endp_number = ++u132->num_endpoints;
2057 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
2058 kmalloc(sizeof(struct u132_endp), mem_flags);
2062 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2063 spin_lock_init(&endp->queue_lock.slock);
2064 INIT_LIST_HEAD(&endp->urb_more);
2065 ring = endp->ring = &u132->ring[0];
2066 if (ring->curr_endp) {
2067 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2069 INIT_LIST_HEAD(&endp->endp_ring);
2070 ring->curr_endp = endp;
2073 endp->dequeueing = 0;
2074 endp->edset_flush = 0;
2077 endp->endp_number = endp_number;
2080 u132_endp_init_kref(u132, endp);
2081 u132_endp_get_kref(u132, endp);
2082 if (usb_addr == 0) {
2084 u8 address = u132->addr[usb_addr].address;
2085 struct u132_udev *udev = &u132->udev[address];
2086 endp->udev_number = address;
2087 endp->usb_addr = usb_addr;
2088 endp->usb_endp = usb_endp;
2091 endp->pipetype = usb_pipetype(urb->pipe);
2092 u132_udev_init_kref(u132, udev);
2093 u132_udev_get_kref(u132, udev);
2094 udev->endp_number_in[usb_endp] = endp_number;
2095 udev->endp_number_out[usb_endp] = endp_number;
2097 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2098 endp->queue_size = 1;
2099 endp->queue_last = 0;
2100 endp->queue_next = 0;
2101 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2102 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2103 u132_endp_queue_work(u132, endp, 0);
2105 } else { /*(usb_addr > 0) */
2107 u8 address = u132->addr[usb_addr].address;
2108 struct u132_udev *udev = &u132->udev[address];
2109 endp->udev_number = address;
2110 endp->usb_addr = usb_addr;
2111 endp->usb_endp = usb_endp;
2114 endp->pipetype = usb_pipetype(urb->pipe);
2115 u132_udev_get_kref(u132, udev);
2116 udev->enumeration = 2;
2117 udev->endp_number_in[usb_endp] = endp_number;
2118 udev->endp_number_out[usb_endp] = endp_number;
2120 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2121 endp->queue_size = 1;
2122 endp->queue_last = 0;
2123 endp->queue_next = 0;
2124 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2125 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2126 u132_endp_queue_work(u132, endp, 0);
2131 static int queue_control_on_old_endpoint(struct u132 *u132,
2132 struct usb_host_endpoint *hep, struct urb *urb,
2133 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2136 if (usb_addr == 0) {
2137 if (usb_pipein(urb->pipe)) {
2139 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2140 endp->urb_list[ENDP_QUEUE_MASK &
2141 endp->queue_last++] = urb;
2143 struct u132_urbq *urbq =
2144 kmalloc(sizeof(struct u132_urbq),
2147 endp->queue_size -= 1;
2150 list_add_tail(&urbq->urb_more,
2156 } else { /* usb_pipeout(urb->pipe) */
2157 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2158 int I = MAX_U132_UDEVS;
2161 struct u132_udev *udev = &u132->udev[++i];
2162 if (udev->usb_device) {
2165 udev->enumeration = 1;
2166 u132->addr[0].address = i;
2167 endp->udev_number = i;
2168 udev->udev_number = i;
2169 udev->usb_addr = usb_dev->devnum;
2170 u132_udev_init_kref(u132, udev);
2171 udev->endp_number_in[usb_endp] =
2173 u132_udev_get_kref(u132, udev);
2174 udev->endp_number_out[usb_endp] =
2176 udev->usb_device = usb_dev;
2177 ((u8 *) (urb->setup_packet))[2] =
2179 u132_udev_get_kref(u132, udev);
2184 dev_err(&u132->platform_dev->dev, "run out of d"
2189 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2190 endp->urb_list[ENDP_QUEUE_MASK &
2191 endp->queue_last++] = urb;
2193 struct u132_urbq *urbq =
2194 kmalloc(sizeof(struct u132_urbq),
2197 endp->queue_size -= 1;
2200 list_add_tail(&urbq->urb_more,
2207 } else { /*(usb_addr > 0) */
2208 u8 address = u132->addr[usb_addr].address;
2209 struct u132_udev *udev = &u132->udev[address];
2211 if (udev->enumeration == 2) {
2213 udev->enumeration = 2;
2214 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2215 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2218 struct u132_urbq *urbq =
2219 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2221 endp->queue_size -= 1;
2224 list_add_tail(&urbq->urb_more, &endp->urb_more);
2232 static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2233 struct urb *urb, gfp_t mem_flags)
2235 struct u132 *u132 = hcd_to_u132(hcd);
2236 if (irqs_disabled()) {
2237 if (__GFP_WAIT & mem_flags) {
2238 printk(KERN_ERR "invalid context for function that migh"
2243 if (u132->going > 1) {
2244 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2247 } else if (u132->going > 0) {
2248 dev_err(&u132->platform_dev->dev, "device is being removed urb="
2249 "%p status=%d\n", urb, urb->status);
2252 u8 usb_addr = usb_pipedevice(urb->pipe);
2253 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2254 struct usb_device *usb_dev = urb->dev;
2255 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2256 u8 address = u132->addr[usb_addr].address;
2257 struct u132_udev *udev = &u132->udev[address];
2258 struct u132_endp *endp = hep->hcpriv;
2259 urb->actual_length = 0;
2263 spin_lock_irqsave(&endp->queue_lock.slock,
2265 retval = queue_int_on_old_endpoint(u132, udev,
2266 hep, urb, usb_dev, endp, usb_addr,
2268 spin_unlock_irqrestore(&endp->queue_lock.slock,
2273 u132_endp_queue_work(u132, endp,
2274 msecs_to_jiffies(urb->interval))
2278 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2280 } else { /*(endp == NULL) */
2281 return create_endpoint_and_queue_int(u132, udev,
2282 hep, urb, usb_dev, usb_addr, usb_endp,
2283 address, mem_flags);
2285 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2286 dev_err(&u132->platform_dev->dev, "the hardware does no"
2287 "t support PIPE_ISOCHRONOUS\n");
2289 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2290 u8 address = u132->addr[usb_addr].address;
2291 struct u132_udev *udev = &u132->udev[address];
2292 struct u132_endp *endp = hep->hcpriv;
2293 urb->actual_length = 0;
2297 spin_lock_irqsave(&endp->queue_lock.slock,
2299 retval = queue_bulk_on_old_endpoint(u132, udev,
2300 hep, urb, usb_dev, endp, usb_addr,
2302 spin_unlock_irqrestore(&endp->queue_lock.slock,
2307 u132_endp_queue_work(u132, endp, 0);
2310 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2313 return create_endpoint_and_queue_bulk(u132,
2314 udev, hep, urb, usb_dev, usb_addr,
2315 usb_endp, address, mem_flags);
2317 struct u132_endp *endp = hep->hcpriv;
2319 u8 *b = urb->setup_packet;
2321 char data[30 *3 + 4];
2323 int m = (sizeof(data) - 1) / 3;
2326 while (urb_size-- > 0) {
2328 } else if (i++ < m) {
2329 int w = sprintf(d, " %02X", *b++);
2333 d += sprintf(d, " ..");
2338 spin_lock_irqsave(&endp->queue_lock.slock,
2340 retval = queue_control_on_old_endpoint(u132,
2341 hep, urb, usb_dev, endp, usb_addr,
2343 spin_unlock_irqrestore(&endp->queue_lock.slock,
2348 u132_endp_queue_work(u132, endp, 0);
2351 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2354 return create_endpoint_and_queue_control(u132,
2355 hep, urb, usb_dev, usb_addr, usb_endp,
2361 static int dequeue_from_overflow_chain(struct u132 *u132,
2362 struct u132_endp *endp, struct urb *urb)
2364 struct list_head *scan;
2365 struct list_head *head = &endp->urb_more;
2366 list_for_each(scan, head) {
2367 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2369 if (urbq->urb == urb) {
2370 struct usb_hcd *hcd = u132_to_hcd(u132);
2372 endp->queue_size -= 1;
2373 urb->error_count = 0;
2375 usb_hcd_giveback_urb(hcd, urb);
2380 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2381 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2382 "\n", urb, endp->endp_number, endp, endp->ring->number,
2383 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2384 endp->usb_endp, endp->usb_addr, endp->queue_size,
2385 endp->queue_next, endp->queue_last);
2389 static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2393 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2394 if (endp->queue_size == 0) {
2395 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2396 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2397 endp->endp_number, endp, endp->ring->number,
2398 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2399 endp->usb_endp, endp->usb_addr);
2400 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2403 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2405 endp->dequeueing = 1;
2406 endp->edset_flush = 1;
2407 u132_endp_queue_work(u132, endp, 0);
2408 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2412 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2413 u132_hcd_abandon_urb(u132, endp, urb, urb->status);
2418 u16 queue_size = endp->queue_size;
2419 u16 queue_scan = endp->queue_next;
2420 struct urb **urb_slot = NULL;
2421 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2422 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2424 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2430 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2431 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2433 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2437 struct usb_hcd *hcd = u132_to_hcd(u132);
2438 endp->queue_size -= 1;
2439 if (list_empty(&endp->urb_more)) {
2440 spin_unlock_irqrestore(&endp->queue_lock.slock,
2443 struct list_head *next = endp->urb_more.next;
2444 struct u132_urbq *urbq = list_entry(next,
2445 struct u132_urbq, urb_more);
2447 *urb_slot = urbq->urb;
2448 spin_unlock_irqrestore(&endp->queue_lock.slock,
2451 } urb->error_count = 0;
2453 usb_hcd_giveback_urb(hcd, urb);
2455 } else if (list_empty(&endp->urb_more)) {
2456 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2457 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2458 "=%d size=%d next=%04X last=%04X\n", urb,
2459 endp->endp_number, endp, endp->ring->number,
2460 endp->input ? 'I' : ' ',
2461 endp->output ? 'O' : ' ', endp->usb_endp,
2462 endp->usb_addr, endp->queue_size,
2463 endp->queue_next, endp->queue_last);
2464 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2467 int retval = dequeue_from_overflow_chain(u132, endp,
2469 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2475 static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
2477 struct u132 *u132 = hcd_to_u132(hcd);
2478 if (u132->going > 2) {
2479 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2483 u8 usb_addr = usb_pipedevice(urb->pipe);
2484 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2485 u8 address = u132->addr[usb_addr].address;
2486 struct u132_udev *udev = &u132->udev[address];
2487 if (usb_pipein(urb->pipe)) {
2488 u8 endp_number = udev->endp_number_in[usb_endp];
2489 struct u132_endp *endp = u132->endp[endp_number - 1];
2490 return u132_endp_urb_dequeue(u132, endp, urb);
2492 u8 endp_number = udev->endp_number_out[usb_endp];
2493 struct u132_endp *endp = u132->endp[endp_number - 1];
2494 return u132_endp_urb_dequeue(u132, endp, urb);
2499 static void u132_endpoint_disable(struct usb_hcd *hcd,
2500 struct usb_host_endpoint *hep)
2502 struct u132 *u132 = hcd_to_u132(hcd);
2503 if (u132->going > 2) {
2504 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2505 ") has been removed %d\n", u132, hcd, hep,
2508 struct u132_endp *endp = hep->hcpriv;
2510 u132_endp_put_kref(u132, endp);
2514 static int u132_get_frame(struct usb_hcd *hcd)
2516 struct u132 *u132 = hcd_to_u132(hcd);
2517 if (u132->going > 1) {
2518 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2521 } else if (u132->going > 0) {
2522 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2526 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2532 static int u132_roothub_descriptor(struct u132 *u132,
2533 struct usb_hub_descriptor *desc)
2539 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2542 desc->bDescriptorType = 0x29;
2543 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2544 desc->bHubContrCurrent = 0;
2545 desc->bNbrPorts = u132->num_ports;
2546 temp = 1 + (u132->num_ports / 8);
2547 desc->bDescLength = 7 + 2 *temp;
2549 if (rh_a & RH_A_NPS)
2551 if (rh_a & RH_A_PSM)
2553 if (rh_a & RH_A_NOCP) {
2555 } else if (rh_a & RH_A_OCPM)
2557 desc->wHubCharacteristics = cpu_to_le16(temp);
2558 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2561 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2562 desc->bitmap[0] = rh_b & RH_B_DR;
2563 if (u132->num_ports > 7) {
2564 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2565 desc->bitmap[2] = 0xff;
2567 desc->bitmap[1] = 0xff;
2571 static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2574 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2575 *desc = cpu_to_le32(rh_status);
2579 static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2581 if (wIndex == 0 || wIndex > u132->num_ports) {
2584 int port = wIndex - 1;
2585 u32 rh_portstatus = -1;
2586 int ret_portstatus = u132_read_pcimem(u132,
2587 roothub.portstatus[port], &rh_portstatus);
2588 *desc = cpu_to_le32(rh_portstatus);
2589 if (*(u16 *) (desc + 2)) {
2590 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2591 "ge = %08X\n", port, *desc);
2593 return ret_portstatus;
2598 /* this timer value might be vendor-specific ... */
2599 #define PORT_RESET_HW_MSEC 10
2600 #define PORT_RESET_MSEC 10
2601 /* wrap-aware logic morphed from <linux/jiffies.h> */
2602 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2603 static int u132_roothub_portreset(struct u132 *u132, int port_index)
2609 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2613 reset_done = now + PORT_RESET_MSEC;
2617 retval = u132_read_pcimem(u132,
2618 roothub.portstatus[port_index], &portstat);
2621 if (RH_PS_PRS & portstat) {
2625 } while (tick_before(now, reset_done));
2626 if (RH_PS_PRS & portstat)
2628 if (RH_PS_CCS & portstat) {
2629 if (RH_PS_PRSC & portstat) {
2630 retval = u132_write_pcimem(u132,
2631 roothub.portstatus[port_index],
2637 break; /* start the next reset,
2638 sleep till it's probably done */
2639 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2643 msleep(PORT_RESET_HW_MSEC);
2644 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2648 } while (tick_before(now, reset_done));
2652 static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2655 if (wIndex == 0 || wIndex > u132->num_ports) {
2659 int port_index = wIndex - 1;
2660 struct u132_port *port = &u132->port[port_index];
2661 port->Status &= ~(1 << wValue);
2663 case USB_PORT_FEAT_SUSPEND:
2664 retval = u132_write_pcimem(u132,
2665 roothub.portstatus[port_index], RH_PS_PSS);
2669 case USB_PORT_FEAT_POWER:
2670 retval = u132_write_pcimem(u132,
2671 roothub.portstatus[port_index], RH_PS_PPS);
2675 case USB_PORT_FEAT_RESET:
2676 retval = u132_roothub_portreset(u132, port_index);
2686 static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2689 if (wIndex == 0 || wIndex > u132->num_ports) {
2692 int port_index = wIndex - 1;
2695 struct u132_port *port = &u132->port[port_index];
2696 port->Status &= ~(1 << wValue);
2698 case USB_PORT_FEAT_ENABLE:
2701 case USB_PORT_FEAT_C_ENABLE:
2704 case USB_PORT_FEAT_SUSPEND:
2706 if ((u132->hc_control & OHCI_CTRL_HCFS)
2708 dev_err(&u132->platform_dev->dev, "TODO resume_"
2712 case USB_PORT_FEAT_C_SUSPEND:
2715 case USB_PORT_FEAT_POWER:
2718 case USB_PORT_FEAT_C_CONNECTION:
2721 case USB_PORT_FEAT_C_OVER_CURRENT:
2724 case USB_PORT_FEAT_C_RESET:
2730 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2739 /* the virtual root hub timer IRQ checks for hub status*/
2740 static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2742 struct u132 *u132 = hcd_to_u132(hcd);
2743 if (u132->going > 1) {
2744 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2745 "ed %d\n", hcd, u132->going);
2747 } else if (u132->going > 0) {
2748 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2752 int i, changed = 0, length = 1;
2753 if (u132->flags & OHCI_QUIRK_AMD756) {
2754 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2755 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2756 "ereads as NDP=%d\n",
2757 u132->hc_roothub_a & RH_A_NDP);
2761 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) {
2762 buf[0] = changed = 1;
2765 if (u132->num_ports > 7) {
2769 for (i = 0; i < u132->num_ports; i++) {
2770 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2771 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2775 buf[0] |= 1 << (i + 1);
2777 buf[1] |= 1 << (i - 7);
2780 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) {
2783 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) {
2787 done:return changed ? length : 0;
2791 static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2792 u16 wIndex, char *buf, u16 wLength)
2794 struct u132 *u132 = hcd_to_u132(hcd);
2795 if (u132->going > 1) {
2796 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2799 } else if (u132->going > 0) {
2800 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2804 down(&u132->sw_lock);
2806 case ClearHubFeature:
2808 case C_HUB_OVER_CURRENT:
2809 case C_HUB_LOCAL_POWER:
2817 case C_HUB_OVER_CURRENT:
2818 case C_HUB_LOCAL_POWER:
2824 case ClearPortFeature:{
2825 retval = u132_roothub_clearportfeature(u132,
2831 case GetHubDescriptor:{
2832 retval = u132_roothub_descriptor(u132,
2833 (struct usb_hub_descriptor *)buf);
2839 retval = u132_roothub_status(u132,
2845 case GetPortStatus:{
2846 retval = u132_roothub_portstatus(u132,
2847 (__le32 *) buf, wIndex);
2852 case SetPortFeature:{
2853 retval = u132_roothub_setportfeature(u132,
2861 error:u132_disable(u132);
2864 stall:retval = -EPIPE;
2872 static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2874 struct u132 *u132 = hcd_to_u132(hcd);
2875 if (u132->going > 1) {
2876 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2879 } else if (u132->going > 0) {
2880 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2886 static void u132_hub_irq_enable(struct usb_hcd *hcd)
2888 struct u132 *u132 = hcd_to_u132(hcd);
2889 if (u132->going > 1) {
2890 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2892 } else if (u132->going > 0)
2893 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2898 static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2900 struct u132 *u132 = hcd_to_u132(hcd);
2901 if (u132->going > 1) {
2902 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2905 } else if (u132->going > 0) {
2906 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2912 static int u132_hcd_resume(struct usb_hcd *hcd)
2914 struct u132 *u132 = hcd_to_u132(hcd);
2915 if (u132->going > 1) {
2916 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2919 } else if (u132->going > 0) {
2920 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2926 static int u132_bus_suspend(struct usb_hcd *hcd)
2928 struct u132 *u132 = hcd_to_u132(hcd);
2929 if (u132->going > 1) {
2930 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2933 } else if (u132->going > 0) {
2934 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2940 static int u132_bus_resume(struct usb_hcd *hcd)
2942 struct u132 *u132 = hcd_to_u132(hcd);
2943 if (u132->going > 1) {
2944 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2947 } else if (u132->going > 0) {
2948 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2955 #define u132_hcd_suspend NULL
2956 #define u132_hcd_resume NULL
2957 #define u132_bus_suspend NULL
2958 #define u132_bus_resume NULL
2960 static struct hc_driver u132_hc_driver = {
2961 .description = hcd_name,
2962 .hcd_priv_size = sizeof(struct u132),
2964 .flags = HCD_USB11 | HCD_MEMORY,
2965 .reset = u132_hcd_reset,
2966 .start = u132_hcd_start,
2967 .suspend = u132_hcd_suspend,
2968 .resume = u132_hcd_resume,
2969 .stop = u132_hcd_stop,
2970 .urb_enqueue = u132_urb_enqueue,
2971 .urb_dequeue = u132_urb_dequeue,
2972 .endpoint_disable = u132_endpoint_disable,
2973 .get_frame_number = u132_get_frame,
2974 .hub_status_data = u132_hub_status_data,
2975 .hub_control = u132_hub_control,
2976 .bus_suspend = u132_bus_suspend,
2977 .bus_resume = u132_bus_resume,
2978 .start_port_reset = u132_start_port_reset,
2979 .hub_irq_enable = u132_hub_irq_enable,
2983 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
2984 * is held for writing, thus this module must not call usb_remove_hcd()
2985 * synchronously - but instead should immediately stop activity to the
2986 * device and asynchronously call usb_remove_hcd()
2988 static int __devexit u132_remove(struct platform_device *pdev)
2990 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2992 struct u132 *u132 = hcd_to_u132(hcd);
2993 if (u132->going++ > 1) {
2994 dev_err(&u132->platform_dev->dev, "already being remove"
2998 int rings = MAX_U132_RINGS;
2999 int endps = MAX_U132_ENDPS;
3000 dev_err(&u132->platform_dev->dev, "removing device u132"
3001 ".%d\n", u132->sequence_num);
3003 down(&u132->sw_lock);
3004 u132_monitor_cancel_work(u132);
3005 while (rings-- > 0) {
3006 struct u132_ring *ring = &u132->ring[rings];
3007 u132_ring_cancel_work(u132, ring);
3008 } while (endps-- > 0) {
3009 struct u132_endp *endp = u132->endp[endps];
3011 u132_endp_cancel_work(u132, endp);
3014 printk(KERN_INFO "removing device u132.%d\n",
3015 u132->sequence_num);
3017 usb_remove_hcd(hcd);
3018 u132_u132_put_kref(u132);
3025 static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3027 int rings = MAX_U132_RINGS;
3028 int ports = MAX_U132_PORTS;
3029 int addrs = MAX_U132_ADDRS;
3030 int udevs = MAX_U132_UDEVS;
3031 int endps = MAX_U132_ENDPS;
3032 u132->board = pdev->dev.platform_data;
3033 u132->platform_dev = pdev;
3036 init_MUTEX(&u132->sw_lock);
3037 init_MUTEX(&u132->scheduler_lock);
3038 while (rings-- > 0) {
3039 struct u132_ring *ring = &u132->ring[rings];
3041 ring->number = rings + 1;
3043 ring->curr_endp = NULL;
3044 INIT_DELAYED_WORK(&ring->scheduler,
3045 u132_hcd_ring_work_scheduler);
3046 } down(&u132->sw_lock);
3047 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3048 while (ports-- > 0) {
3049 struct u132_port *port = &u132->port[ports];
3055 } while (addrs-- > 0) {
3056 struct u132_addr *addr = &u132->addr[addrs];
3058 } while (udevs-- > 0) {
3059 struct u132_udev *udev = &u132->udev[udevs];
3060 int i = ARRAY_SIZE(udev->endp_number_in);
3061 int o = ARRAY_SIZE(udev->endp_number_out);
3062 udev->usb_device = NULL;
3063 udev->udev_number = 0;
3065 udev->portnumber = 0;
3067 udev->endp_number_in[i] = 0;
3070 udev->endp_number_out[o] = 0;
3073 while (endps-- > 0) {
3074 u132->endp[endps] = NULL;
3080 static int __devinit u132_probe(struct platform_device *pdev)
3082 struct usb_hcd *hcd;
3088 if (u132_exiting > 0) {
3091 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3094 retval = ftdi_read_pcimem(pdev, control, &control);
3097 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3100 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3101 if (pdev->dev.dma_mask) {
3104 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3106 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3108 ftdi_elan_gone_away(pdev);
3112 struct u132 *u132 = hcd_to_u132(hcd);
3113 hcd->rsrc_start = 0;
3114 down(&u132_module_lock);
3115 list_add_tail(&u132->u132_list, &u132_static_list);
3116 u132->sequence_num = ++u132_instances;
3117 up(&u132_module_lock);
3118 u132_u132_init_kref(u132);
3119 u132_initialise(u132, pdev);
3120 hcd->product_desc = "ELAN U132 Host Controller";
3121 retval = usb_add_hcd(hcd, 0, 0);
3123 dev_err(&u132->platform_dev->dev, "init error %d\n",
3125 u132_u132_put_kref(u132);
3128 u132_monitor_queue_work(u132, 100);
3136 /* for this device there's no useful distinction between the controller
3137 * and its root hub, except that the root hub only gets direct PM calls
3138 * when CONFIG_USB_SUSPEND is enabled.
3140 static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3142 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3143 struct u132 *u132 = hcd_to_u132(hcd);
3144 if (u132->going > 1) {
3145 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3148 } else if (u132->going > 0) {
3149 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3153 if (state.event == PM_EVENT_FREEZE) {
3154 retval = u132_bus_suspend(hcd);
3155 } else if (state.event == PM_EVENT_SUSPEND) {
3156 int ports = MAX_U132_PORTS;
3157 while (ports-- > 0) {
3158 port_power(u132, ports, 0);
3162 pdev->dev.power.power_state = state;
3167 static int u132_resume(struct platform_device *pdev)
3169 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3170 struct u132 *u132 = hcd_to_u132(hcd);
3171 if (u132->going > 1) {
3172 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3175 } else if (u132->going > 0) {
3176 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3180 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
3181 int ports = MAX_U132_PORTS;
3182 while (ports-- > 0) {
3183 port_power(u132, ports, 1);
3187 pdev->dev.power.power_state = PMSG_ON;
3188 retval = u132_bus_resume(hcd);
3195 #define u132_suspend NULL
3196 #define u132_resume NULL
3199 * this driver is loaded explicitly by ftdi_u132
3201 * the platform_driver struct is static because it is per type of module
3203 static struct platform_driver u132_platform_driver = {
3204 .probe = u132_probe,
3205 .remove = __devexit_p(u132_remove),
3206 .suspend = u132_suspend,
3207 .resume = u132_resume,
3209 .name = (char *)hcd_name,
3210 .owner = THIS_MODULE,
3213 static int __init u132_hcd_init(void)
3216 INIT_LIST_HEAD(&u132_static_list);
3219 init_MUTEX(&u132_module_lock);
3222 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3224 workqueue = create_singlethread_workqueue("u132");
3225 retval = platform_driver_register(&u132_platform_driver);
3230 module_init(u132_hcd_init);
3231 static void __exit u132_hcd_exit(void)
3235 down(&u132_module_lock);
3237 up(&u132_module_lock);
3238 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3239 platform_device_unregister(u132->platform_dev);
3240 } platform_driver_unregister(&u132_platform_driver);
3241 printk(KERN_INFO "u132-hcd driver deregistered\n");
3242 wait_event(u132_hcd_wait, u132_instances == 0);
3243 flush_workqueue(workqueue);
3244 destroy_workqueue(workqueue);
3248 module_exit(u132_hcd_exit);
3249 MODULE_LICENSE("GPL");