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/smp_lock.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/timer.h>
50 #include <linux/list.h>
51 #include <linux/interrupt.h>
52 #include <linux/usb.h>
53 #include <linux/workqueue.h>
54 #include <linux/platform_device.h>
55 #include <linux/pci_ids.h>
58 #include <asm/system.h>
59 #include <asm/byteorder.h>
60 #include "../core/hcd.h"
62 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
63 #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
65 MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
66 MODULE_DESCRIPTION("U132 USB Host Controller Driver");
67 MODULE_LICENSE("GPL");
68 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
69 INT_MODULE_PARM(testing, 0);
70 /* Some boards misreport power switching/overcurrent*/
71 static int distrust_firmware = 1;
72 module_param(distrust_firmware, bool, 0);
73 MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
75 static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
77 * u132_module_lock exists to protect access to global variables
80 static struct semaphore u132_module_lock;
81 static int u132_exiting = 0;
82 static int u132_instances = 0;
83 static struct list_head u132_static_list;
85 * end of the global variables protected by u132_module_lock
87 static struct workqueue_struct *workqueue;
88 #define MAX_U132_PORTS 7
89 #define MAX_U132_ADDRS 128
90 #define MAX_U132_UDEVS 4
91 #define MAX_U132_ENDPS 100
92 #define MAX_U132_RINGS 4
93 static const char *cc_to_text[16] = {
123 struct usb_device *usb_device;
128 u8 endp_number_in[16];
129 u8 endp_number_out[16];
131 #define ENDP_QUEUE_SHIFT 3
132 #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
133 #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
135 struct list_head urb_more;
148 struct list_head endp_ring;
149 struct u132_ring *ring;
150 unsigned toggle_bits:2;
156 unsigned dequeueing:1;
157 unsigned edset_flush:1;
158 unsigned spare_bits:14;
159 unsigned long jiffies;
160 struct usb_host_endpoint *hep;
161 struct u132_spin queue_lock;
165 struct urb *urb_list[ENDP_QUEUE_SIZE];
166 struct list_head urb_more;
167 struct delayed_work scheduler;
174 struct u132_endp *curr_endp;
175 struct delayed_work scheduler;
177 #define OHCI_QUIRK_AMD756 0x01
178 #define OHCI_QUIRK_SUPERIO 0x02
179 #define OHCI_QUIRK_INITRESET 0x04
180 #define OHCI_BIG_ENDIAN 0x08
181 #define OHCI_QUIRK_ZFMICRO 0x10
184 struct list_head u132_list;
185 struct semaphore sw_lock;
186 struct semaphore scheduler_lock;
187 struct u132_platform_data *board;
188 struct platform_device *platform_dev;
189 struct u132_ring ring[MAX_U132_RINGS];
197 u32 hc_roothub_status;
199 u32 hc_roothub_portstatus[MAX_ROOT_PORTS];
201 unsigned long next_statechange;
202 struct delayed_work monitor;
204 struct u132_addr addr[MAX_U132_ADDRS];
205 struct u132_udev udev[MAX_U132_UDEVS];
206 struct u132_port port[MAX_U132_PORTS];
207 struct u132_endp *endp[MAX_U132_ENDPS];
211 * these cannot be inlines because we need the structure offset!!
212 * Does anyone have a better way?????
214 #define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
215 offsetof(struct ohci_regs, member), 0, data);
216 #define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
217 offsetof(struct ohci_regs, member), 0, data);
218 #define u132_read_pcimem(u132, member, data) \
219 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
220 ohci_regs, member), 0, data);
221 #define u132_write_pcimem(u132, member, data) \
222 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
223 ohci_regs, member), 0, data);
224 static inline struct u132 *udev_to_u132(struct u132_udev *udev)
226 u8 udev_number = udev->udev_number;
227 return container_of(udev, struct u132, udev[udev_number]);
230 static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd)
232 return (struct u132 *)(hcd->hcd_priv);
235 static inline struct usb_hcd *u132_to_hcd(struct u132 *u132)
237 return container_of((void *)u132, struct usb_hcd, hcd_priv);
240 static inline void u132_disable(struct u132 *u132)
242 u132_to_hcd(u132)->state = HC_STATE_HALT;
246 #define kref_to_u132(d) container_of(d, struct u132, kref)
247 #define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref)
248 #define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref)
249 #include "../misc/usb_u132.h"
250 static const char hcd_name[] = "u132_hcd";
251 #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
252 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
253 USB_PORT_STAT_C_RESET) << 16)
254 static void u132_hcd_delete(struct kref *kref)
256 struct u132 *u132 = kref_to_u132(kref);
257 struct platform_device *pdev = u132->platform_dev;
258 struct usb_hcd *hcd = u132_to_hcd(u132);
260 down(&u132_module_lock);
261 list_del_init(&u132->u132_list);
263 up(&u132_module_lock);
264 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
265 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
269 static inline void u132_u132_put_kref(struct u132 *u132)
271 kref_put(&u132->kref, u132_hcd_delete);
274 static inline void u132_u132_init_kref(struct u132 *u132)
276 kref_init(&u132->kref);
279 static void u132_udev_delete(struct kref *kref)
281 struct u132_udev *udev = kref_to_u132_udev(kref);
282 udev->udev_number = 0;
283 udev->usb_device = NULL;
285 udev->enumeration = 0;
288 static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev)
290 kref_put(&udev->kref, u132_udev_delete);
293 static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev)
295 kref_get(&udev->kref);
298 static inline void u132_udev_init_kref(struct u132 *u132,
299 struct u132_udev *udev)
301 kref_init(&udev->kref);
304 static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring)
306 kref_put(&u132->kref, u132_hcd_delete);
309 static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring,
313 if (queue_delayed_work(workqueue, &ring->scheduler, delta))
315 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0))
317 kref_put(&u132->kref, u132_hcd_delete);
321 static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
324 kref_get(&u132->kref);
325 u132_ring_requeue_work(u132, ring, delta);
329 static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
331 if (cancel_delayed_work(&ring->scheduler)) {
332 kref_put(&u132->kref, u132_hcd_delete);
336 static void u132_endp_delete(struct kref *kref)
338 struct u132_endp *endp = kref_to_u132_endp(kref);
339 struct u132 *u132 = endp->u132;
340 u8 usb_addr = endp->usb_addr;
341 u8 usb_endp = endp->usb_endp;
342 u8 address = u132->addr[usb_addr].address;
343 struct u132_udev *udev = &u132->udev[address];
344 u8 endp_number = endp->endp_number;
345 struct usb_host_endpoint *hep = endp->hep;
346 struct u132_ring *ring = endp->ring;
347 struct list_head *head = &endp->endp_ring;
349 if (endp == ring->curr_endp) {
350 if (list_empty(head)) {
351 ring->curr_endp = NULL;
354 struct u132_endp *next_endp = list_entry(head->next,
355 struct u132_endp, endp_ring);
356 ring->curr_endp = next_endp;
361 udev->endp_number_in[usb_endp] = 0;
362 u132_udev_put_kref(u132, udev);
365 udev->endp_number_out[usb_endp] = 0;
366 u132_udev_put_kref(u132, udev);
368 u132->endp[endp_number - 1] = NULL;
371 u132_u132_put_kref(u132);
374 static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp)
376 kref_put(&endp->kref, u132_endp_delete);
379 static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp)
381 kref_get(&endp->kref);
384 static inline void u132_endp_init_kref(struct u132 *u132,
385 struct u132_endp *endp)
387 kref_init(&endp->kref);
388 kref_get(&u132->kref);
391 static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
394 if (queue_delayed_work(workqueue, &endp->scheduler, delta))
395 kref_get(&endp->kref);
398 static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp)
400 if (cancel_delayed_work(&endp->scheduler))
401 kref_put(&endp->kref, u132_endp_delete);
404 static inline void u132_monitor_put_kref(struct u132 *u132)
406 kref_put(&u132->kref, u132_hcd_delete);
409 static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta)
411 if (queue_delayed_work(workqueue, &u132->monitor, delta))
412 kref_get(&u132->kref);
415 static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta)
417 if (!queue_delayed_work(workqueue, &u132->monitor, delta))
418 kref_put(&u132->kref, u132_hcd_delete);
421 static void u132_monitor_cancel_work(struct u132 *u132)
423 if (cancel_delayed_work(&u132->monitor))
424 kref_put(&u132->kref, u132_hcd_delete);
427 static int read_roothub_info(struct u132 *u132)
431 retval = u132_read_pcimem(u132, revision, &revision);
433 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
436 } else if ((revision & 0xFF) == 0x10) {
437 } else if ((revision & 0xFF) == 0x11) {
439 dev_err(&u132->platform_dev->dev, "device revision is not valid"
440 " %08X\n", revision);
443 retval = u132_read_pcimem(u132, control, &u132->hc_control);
445 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
449 retval = u132_read_pcimem(u132, roothub.status,
450 &u132->hc_roothub_status);
452 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
453 "g roothub.status\n", retval);
456 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a);
458 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
459 "g roothub.a\n", retval);
463 int I = u132->num_ports;
466 retval = u132_read_pcimem(u132, roothub.portstatus[i],
467 &u132->hc_roothub_portstatus[i]);
469 dev_err(&u132->platform_dev->dev, "error %d acc"
470 "essing device roothub.portstatus[%d]\n"
480 static void u132_hcd_monitor_work(struct work_struct *work)
482 struct u132 *u132 = container_of(work, struct u132, monitor.work);
483 if (u132->going > 1) {
484 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
486 u132_monitor_put_kref(u132);
488 } else if (u132->going > 0) {
489 dev_err(&u132->platform_dev->dev, "device is being removed\n");
490 u132_monitor_put_kref(u132);
494 down(&u132->sw_lock);
495 retval = read_roothub_info(u132);
497 struct usb_hcd *hcd = u132_to_hcd(u132);
502 ftdi_elan_gone_away(u132->platform_dev);
503 u132_monitor_put_kref(u132);
506 u132_monitor_requeue_work(u132, 500);
513 static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
514 struct urb *urb, int status)
516 struct u132_ring *ring;
518 struct usb_hcd *hcd = u132_to_hcd(u132);
519 urb->error_count = 0;
520 urb->status = status;
522 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
523 endp->queue_next += 1;
524 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
526 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
528 struct list_head *next = endp->urb_more.next;
529 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
532 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
535 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
537 } down(&u132->scheduler_lock);
540 u132_ring_cancel_work(u132, ring);
541 u132_ring_queue_work(u132, ring, 0);
542 up(&u132->scheduler_lock);
543 u132_endp_put_kref(u132, endp);
544 usb_hcd_giveback_urb(hcd, urb);
548 static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp,
549 struct urb *urb, int status)
551 u132_endp_put_kref(u132, endp);
554 static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
555 struct urb *urb, int status)
558 struct usb_hcd *hcd = u132_to_hcd(u132);
559 urb->error_count = 0;
560 urb->status = status;
562 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
563 endp->queue_next += 1;
564 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
566 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
568 struct list_head *next = endp->urb_more.next;
569 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
572 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
575 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
577 } usb_hcd_giveback_urb(hcd, urb);
581 static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
582 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
583 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
584 int toggle_bits, int error_count, int condition_code, int repeat_number,
585 int halted, int skipped, int actual, int non_null))
587 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
588 urb, address, endp->usb_endp, toggle_bits, callback);
591 static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
592 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
593 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
594 int toggle_bits, int error_count, int condition_code, int repeat_number,
595 int halted, int skipped, int actual, int non_null))
597 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
598 urb, address, endp->usb_endp, toggle_bits, callback);
601 static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
602 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
603 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
604 int toggle_bits, int error_count, int condition_code, int repeat_number,
605 int halted, int skipped, int actual, int non_null))
607 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
608 endp, urb, address, endp->usb_endp, toggle_bits, callback);
611 static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
612 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
613 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
614 int toggle_bits, int error_count, int condition_code, int repeat_number,
615 int halted, int skipped, int actual, int non_null))
617 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
618 endp, urb, address, endp->usb_endp, toggle_bits, callback);
623 * must not LOCK sw_lock
626 static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
627 int len, int toggle_bits, int error_count, int condition_code,
628 int repeat_number, int halted, int skipped, int actual, int non_null)
630 struct u132_endp *endp = data;
631 struct u132 *u132 = endp->u132;
632 u8 address = u132->addr[endp->usb_addr].address;
633 struct u132_udev *udev = &u132->udev[address];
634 down(&u132->scheduler_lock);
635 if (u132->going > 1) {
636 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
638 up(&u132->scheduler_lock);
639 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
641 } else if (endp->dequeueing) {
642 endp->dequeueing = 0;
643 up(&u132->scheduler_lock);
644 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
646 } else if (u132->going > 0) {
647 dev_err(&u132->platform_dev->dev, "device is being removed urb="
648 "%p status=%d\n", urb, urb->status);
649 up(&u132->scheduler_lock);
650 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
652 } else if (urb->status == -EINPROGRESS) {
653 struct u132_ring *ring = endp->ring;
654 u8 *u = urb->transfer_buffer + urb->actual_length;
660 urb->actual_length += len;
661 if ((condition_code == TD_CC_NOERROR) &&
662 (urb->transfer_buffer_length > urb->actual_length)) {
663 endp->toggle_bits = toggle_bits;
664 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
666 if (urb->actual_length > 0) {
668 up(&u132->scheduler_lock);
669 retval = edset_single(u132, ring, endp, urb,
670 address, endp->toggle_bits,
671 u132_hcd_interrupt_recv);
674 u132_hcd_giveback_urb(u132, endp, urb,
679 endp->jiffies = jiffies +
680 msecs_to_jiffies(urb->interval);
681 u132_ring_cancel_work(u132, ring);
682 u132_ring_queue_work(u132, ring, 0);
683 up(&u132->scheduler_lock);
684 u132_endp_put_kref(u132, endp);
687 } else if ((condition_code == TD_DATAUNDERRUN) &&
688 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
689 endp->toggle_bits = toggle_bits;
690 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
692 up(&u132->scheduler_lock);
693 u132_hcd_giveback_urb(u132, endp, urb, 0);
696 if (condition_code == TD_CC_NOERROR) {
697 endp->toggle_bits = toggle_bits;
698 usb_settoggle(udev->usb_device, endp->usb_endp,
700 } else if (condition_code == TD_CC_STALL) {
701 endp->toggle_bits = 0x2;
702 usb_settoggle(udev->usb_device, endp->usb_endp,
705 endp->toggle_bits = 0x2;
706 usb_settoggle(udev->usb_device, endp->usb_endp,
708 dev_err(&u132->platform_dev->dev, "urb=%p givin"
709 "g back INTERRUPT %s\n", urb,
710 cc_to_text[condition_code]);
712 up(&u132->scheduler_lock);
713 u132_hcd_giveback_urb(u132, endp, urb,
714 cc_to_error[condition_code]);
718 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
719 "s=%d\n", urb, urb->status);
720 up(&u132->scheduler_lock);
721 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
726 static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
727 int len, int toggle_bits, int error_count, int condition_code,
728 int repeat_number, int halted, int skipped, int actual, int non_null)
730 struct u132_endp *endp = data;
731 struct u132 *u132 = endp->u132;
732 u8 address = u132->addr[endp->usb_addr].address;
733 down(&u132->scheduler_lock);
734 if (u132->going > 1) {
735 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
737 up(&u132->scheduler_lock);
738 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
740 } else if (endp->dequeueing) {
741 endp->dequeueing = 0;
742 up(&u132->scheduler_lock);
743 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
745 } else if (u132->going > 0) {
746 dev_err(&u132->platform_dev->dev, "device is being removed urb="
747 "%p status=%d\n", urb, urb->status);
748 up(&u132->scheduler_lock);
749 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
751 } else if (urb->status == -EINPROGRESS) {
752 struct u132_ring *ring = endp->ring;
753 urb->actual_length += len;
754 endp->toggle_bits = toggle_bits;
755 if (urb->transfer_buffer_length > urb->actual_length) {
757 up(&u132->scheduler_lock);
758 retval = edset_output(u132, ring, endp, urb, address,
759 endp->toggle_bits, u132_hcd_bulk_output_sent);
762 u132_hcd_giveback_urb(u132, endp, urb, retval);
765 up(&u132->scheduler_lock);
766 u132_hcd_giveback_urb(u132, endp, urb, 0);
770 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
771 "s=%d\n", urb, urb->status);
772 up(&u132->scheduler_lock);
773 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
778 static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
779 int len, int toggle_bits, int error_count, int condition_code,
780 int repeat_number, int halted, int skipped, int actual, int non_null)
782 struct u132_endp *endp = data;
783 struct u132 *u132 = endp->u132;
784 u8 address = u132->addr[endp->usb_addr].address;
785 struct u132_udev *udev = &u132->udev[address];
786 down(&u132->scheduler_lock);
787 if (u132->going > 1) {
788 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
790 up(&u132->scheduler_lock);
791 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
793 } else if (endp->dequeueing) {
794 endp->dequeueing = 0;
795 up(&u132->scheduler_lock);
796 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
798 } else if (u132->going > 0) {
799 dev_err(&u132->platform_dev->dev, "device is being removed urb="
800 "%p status=%d\n", urb, urb->status);
801 up(&u132->scheduler_lock);
802 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
804 } else if (urb->status == -EINPROGRESS) {
805 struct u132_ring *ring = endp->ring;
806 u8 *u = urb->transfer_buffer + urb->actual_length;
812 urb->actual_length += len;
813 if ((condition_code == TD_CC_NOERROR) &&
814 (urb->transfer_buffer_length > urb->actual_length)) {
816 endp->toggle_bits = toggle_bits;
817 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
819 up(&u132->scheduler_lock);
820 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
821 ring->number, endp, urb, address,
822 endp->usb_endp, endp->toggle_bits,
823 u132_hcd_bulk_input_recv);
826 u132_hcd_giveback_urb(u132, endp, urb, retval);
828 } else if (condition_code == TD_CC_NOERROR) {
829 endp->toggle_bits = toggle_bits;
830 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
832 up(&u132->scheduler_lock);
833 u132_hcd_giveback_urb(u132, endp, urb,
834 cc_to_error[condition_code]);
836 } else if ((condition_code == TD_DATAUNDERRUN) &&
837 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
838 endp->toggle_bits = toggle_bits;
839 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
841 up(&u132->scheduler_lock);
842 u132_hcd_giveback_urb(u132, endp, urb, 0);
844 } else if (condition_code == TD_DATAUNDERRUN) {
845 endp->toggle_bits = toggle_bits;
846 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
848 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
849 ") giving back BULK IN %s\n", urb,
850 cc_to_text[condition_code]);
851 up(&u132->scheduler_lock);
852 u132_hcd_giveback_urb(u132, endp, urb, 0);
854 } else if (condition_code == TD_CC_STALL) {
855 endp->toggle_bits = 0x2;
856 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
857 up(&u132->scheduler_lock);
858 u132_hcd_giveback_urb(u132, endp, urb,
859 cc_to_error[condition_code]);
862 endp->toggle_bits = 0x2;
863 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
864 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
865 "ULK IN code=%d %s\n", urb, condition_code,
866 cc_to_text[condition_code]);
867 up(&u132->scheduler_lock);
868 u132_hcd_giveback_urb(u132, endp, urb,
869 cc_to_error[condition_code]);
873 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
874 "s=%d\n", urb, urb->status);
875 up(&u132->scheduler_lock);
876 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
881 static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
882 int len, int toggle_bits, int error_count, int condition_code,
883 int repeat_number, int halted, int skipped, int actual, int non_null)
885 struct u132_endp *endp = data;
886 struct u132 *u132 = endp->u132;
887 down(&u132->scheduler_lock);
888 if (u132->going > 1) {
889 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
891 up(&u132->scheduler_lock);
892 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
894 } else if (endp->dequeueing) {
895 endp->dequeueing = 0;
896 up(&u132->scheduler_lock);
897 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
899 } else if (u132->going > 0) {
900 dev_err(&u132->platform_dev->dev, "device is being removed urb="
901 "%p status=%d\n", urb, urb->status);
902 up(&u132->scheduler_lock);
903 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
905 } else if (urb->status == -EINPROGRESS) {
906 up(&u132->scheduler_lock);
907 u132_hcd_giveback_urb(u132, endp, urb, 0);
910 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
911 "s=%d\n", urb, urb->status);
912 up(&u132->scheduler_lock);
913 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
918 static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
919 int len, int toggle_bits, int error_count, int condition_code,
920 int repeat_number, int halted, int skipped, int actual, int non_null)
922 struct u132_endp *endp = data;
923 struct u132 *u132 = endp->u132;
924 u8 address = u132->addr[endp->usb_addr].address;
925 down(&u132->scheduler_lock);
926 if (u132->going > 1) {
927 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
929 up(&u132->scheduler_lock);
930 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
932 } else if (endp->dequeueing) {
933 endp->dequeueing = 0;
934 up(&u132->scheduler_lock);
935 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
937 } else if (u132->going > 0) {
938 dev_err(&u132->platform_dev->dev, "device is being removed urb="
939 "%p status=%d\n", urb, urb->status);
940 up(&u132->scheduler_lock);
941 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
943 } else if (urb->status == -EINPROGRESS) {
944 struct u132_ring *ring = endp->ring;
945 u8 *u = urb->transfer_buffer;
951 urb->actual_length = len;
952 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
953 TD_DATAUNDERRUN) && ((urb->transfer_flags &
954 URB_SHORT_NOT_OK) == 0))) {
956 up(&u132->scheduler_lock);
957 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
958 ring->number, endp, urb, address,
960 u132_hcd_configure_empty_sent);
963 u132_hcd_giveback_urb(u132, endp, urb, retval);
965 } else if (condition_code == TD_CC_STALL) {
966 up(&u132->scheduler_lock);
967 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
968 "NPUT STALL urb %p\n", urb);
969 u132_hcd_giveback_urb(u132, endp, urb,
970 cc_to_error[condition_code]);
973 up(&u132->scheduler_lock);
974 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
975 "PUT %s urb %p\n", cc_to_text[condition_code],
977 u132_hcd_giveback_urb(u132, endp, urb,
978 cc_to_error[condition_code]);
982 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
983 "s=%d\n", urb, urb->status);
984 up(&u132->scheduler_lock);
985 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
990 static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
991 int len, int toggle_bits, int error_count, int condition_code,
992 int repeat_number, int halted, int skipped, int actual, int non_null)
994 struct u132_endp *endp = data;
995 struct u132 *u132 = endp->u132;
996 down(&u132->scheduler_lock);
997 if (u132->going > 1) {
998 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1000 up(&u132->scheduler_lock);
1001 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1003 } else if (endp->dequeueing) {
1004 endp->dequeueing = 0;
1005 up(&u132->scheduler_lock);
1006 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1008 } else if (u132->going > 0) {
1009 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1010 "%p status=%d\n", urb, urb->status);
1011 up(&u132->scheduler_lock);
1012 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1014 } else if (urb->status == -EINPROGRESS) {
1015 up(&u132->scheduler_lock);
1016 u132_hcd_giveback_urb(u132, endp, urb, 0);
1019 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1020 "s=%d\n", urb, urb->status);
1021 up(&u132->scheduler_lock);
1022 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1027 static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1028 int len, int toggle_bits, int error_count, int condition_code,
1029 int repeat_number, int halted, int skipped, int actual, int non_null)
1031 struct u132_endp *endp = data;
1032 struct u132 *u132 = endp->u132;
1033 u8 address = u132->addr[endp->usb_addr].address;
1034 down(&u132->scheduler_lock);
1035 if (u132->going > 1) {
1036 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1038 up(&u132->scheduler_lock);
1039 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1041 } else if (endp->dequeueing) {
1042 endp->dequeueing = 0;
1043 up(&u132->scheduler_lock);
1044 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1046 } else if (u132->going > 0) {
1047 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1048 "%p status=%d\n", urb, urb->status);
1049 up(&u132->scheduler_lock);
1050 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1052 } else if (urb->status == -EINPROGRESS) {
1053 if (usb_pipein(urb->pipe)) {
1055 struct u132_ring *ring = endp->ring;
1056 up(&u132->scheduler_lock);
1057 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1058 ring->number, endp, urb, address,
1060 u132_hcd_configure_input_recv);
1063 u132_hcd_giveback_urb(u132, endp, urb, retval);
1067 struct u132_ring *ring = endp->ring;
1068 up(&u132->scheduler_lock);
1069 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1070 ring->number, endp, urb, address,
1072 u132_hcd_configure_empty_recv);
1075 u132_hcd_giveback_urb(u132, endp, urb, retval);
1079 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1080 "s=%d\n", urb, urb->status);
1081 up(&u132->scheduler_lock);
1082 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1087 static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1088 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1089 int repeat_number, int halted, int skipped, int actual, int non_null)
1091 struct u132_endp *endp = data;
1092 struct u132 *u132 = endp->u132;
1093 u8 address = u132->addr[endp->usb_addr].address;
1094 struct u132_udev *udev = &u132->udev[address];
1095 down(&u132->scheduler_lock);
1096 if (u132->going > 1) {
1097 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1099 up(&u132->scheduler_lock);
1100 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1102 } else if (endp->dequeueing) {
1103 endp->dequeueing = 0;
1104 up(&u132->scheduler_lock);
1105 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1107 } else if (u132->going > 0) {
1108 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1109 "%p status=%d\n", urb, urb->status);
1110 up(&u132->scheduler_lock);
1111 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1113 } else if (urb->status == -EINPROGRESS) {
1114 u132->addr[0].address = 0;
1115 endp->usb_addr = udev->usb_addr;
1116 up(&u132->scheduler_lock);
1117 u132_hcd_giveback_urb(u132, endp, urb, 0);
1120 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1121 "s=%d\n", urb, urb->status);
1122 up(&u132->scheduler_lock);
1123 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1128 static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1129 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1130 int repeat_number, int halted, int skipped, int actual, int non_null)
1132 struct u132_endp *endp = data;
1133 struct u132 *u132 = endp->u132;
1134 down(&u132->scheduler_lock);
1135 if (u132->going > 1) {
1136 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1138 up(&u132->scheduler_lock);
1139 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1141 } else if (endp->dequeueing) {
1142 endp->dequeueing = 0;
1143 up(&u132->scheduler_lock);
1144 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1146 } else if (u132->going > 0) {
1147 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1148 "%p status=%d\n", urb, urb->status);
1149 up(&u132->scheduler_lock);
1150 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1152 } else if (urb->status == -EINPROGRESS) {
1154 struct u132_ring *ring = endp->ring;
1155 up(&u132->scheduler_lock);
1156 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1157 ring->number, endp, urb, 0, endp->usb_endp, 0,
1158 u132_hcd_enumeration_empty_recv);
1161 u132_hcd_giveback_urb(u132, endp, urb, retval);
1164 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1165 "s=%d\n", urb, urb->status);
1166 up(&u132->scheduler_lock);
1167 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1172 static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1173 int len, int toggle_bits, int error_count, int condition_code,
1174 int repeat_number, int halted, int skipped, int actual, int non_null)
1176 struct u132_endp *endp = data;
1177 struct u132 *u132 = endp->u132;
1178 down(&u132->scheduler_lock);
1179 if (u132->going > 1) {
1180 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1182 up(&u132->scheduler_lock);
1183 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1185 } else if (endp->dequeueing) {
1186 endp->dequeueing = 0;
1187 up(&u132->scheduler_lock);
1188 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1190 } else if (u132->going > 0) {
1191 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1192 "%p status=%d\n", urb, urb->status);
1193 up(&u132->scheduler_lock);
1194 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1196 } else if (urb->status == -EINPROGRESS) {
1197 up(&u132->scheduler_lock);
1198 u132_hcd_giveback_urb(u132, endp, urb, 0);
1201 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1202 "s=%d\n", urb, urb->status);
1203 up(&u132->scheduler_lock);
1204 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1209 static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1210 int len, int toggle_bits, int error_count, int condition_code,
1211 int repeat_number, int halted, int skipped, int actual, int non_null)
1213 struct u132_endp *endp = data;
1214 struct u132 *u132 = endp->u132;
1215 u8 address = u132->addr[endp->usb_addr].address;
1216 down(&u132->scheduler_lock);
1217 if (u132->going > 1) {
1218 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1220 up(&u132->scheduler_lock);
1221 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1223 } else if (endp->dequeueing) {
1224 endp->dequeueing = 0;
1225 up(&u132->scheduler_lock);
1226 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1228 } else if (u132->going > 0) {
1229 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1230 "%p status=%d\n", urb, urb->status);
1231 up(&u132->scheduler_lock);
1232 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1234 } else if (urb->status == -EINPROGRESS) {
1236 struct u132_ring *ring = endp->ring;
1237 u8 *u = urb->transfer_buffer;
1243 urb->actual_length = len;
1244 up(&u132->scheduler_lock);
1245 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1246 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1247 u132_hcd_initial_empty_sent);
1250 u132_hcd_giveback_urb(u132, endp, urb, retval);
1253 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1254 "s=%d\n", urb, urb->status);
1255 up(&u132->scheduler_lock);
1256 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1261 static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1262 int len, int toggle_bits, int error_count, int condition_code,
1263 int repeat_number, int halted, int skipped, int actual, int non_null)
1265 struct u132_endp *endp = data;
1266 struct u132 *u132 = endp->u132;
1267 u8 address = u132->addr[endp->usb_addr].address;
1268 down(&u132->scheduler_lock);
1269 if (u132->going > 1) {
1270 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1272 up(&u132->scheduler_lock);
1273 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1275 } else if (endp->dequeueing) {
1276 endp->dequeueing = 0;
1277 up(&u132->scheduler_lock);
1278 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1280 } else if (u132->going > 0) {
1281 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1282 "%p status=%d\n", urb, urb->status);
1283 up(&u132->scheduler_lock);
1284 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1286 } else if (urb->status == -EINPROGRESS) {
1288 struct u132_ring *ring = endp->ring;
1289 up(&u132->scheduler_lock);
1290 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1291 ring->number, endp, urb, address, endp->usb_endp, 0,
1292 u132_hcd_initial_input_recv);
1295 u132_hcd_giveback_urb(u132, endp, urb, retval);
1298 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1299 "s=%d\n", urb, urb->status);
1300 up(&u132->scheduler_lock);
1301 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1307 * this work function is only executed from the work queue
1310 static void u132_hcd_ring_work_scheduler(struct work_struct *work)
1312 struct u132_ring *ring =
1313 container_of(work, struct u132_ring, scheduler.work);
1314 struct u132 *u132 = ring->u132;
1315 down(&u132->scheduler_lock);
1317 up(&u132->scheduler_lock);
1318 u132_ring_put_kref(u132, ring);
1320 } else if (ring->curr_endp) {
1321 struct u132_endp *last_endp = ring->curr_endp;
1322 struct list_head *scan;
1323 struct list_head *head = &last_endp->endp_ring;
1324 unsigned long wakeup = 0;
1325 list_for_each(scan, head) {
1326 struct u132_endp *endp = list_entry(scan,
1327 struct u132_endp, endp_ring);
1328 if (endp->queue_next == endp->queue_last) {
1329 } else if ((endp->delayed == 0)
1330 || time_after_eq(jiffies, endp->jiffies)) {
1331 ring->curr_endp = endp;
1332 u132_endp_cancel_work(u132, last_endp);
1333 u132_endp_queue_work(u132, last_endp, 0);
1334 up(&u132->scheduler_lock);
1335 u132_ring_put_kref(u132, ring);
1338 unsigned long delta = endp->jiffies - jiffies;
1343 if (last_endp->queue_next == last_endp->queue_last) {
1344 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1345 last_endp->jiffies)) {
1346 u132_endp_cancel_work(u132, last_endp);
1347 u132_endp_queue_work(u132, last_endp, 0);
1348 up(&u132->scheduler_lock);
1349 u132_ring_put_kref(u132, ring);
1352 unsigned long delta = last_endp->jiffies - jiffies;
1357 u132_ring_requeue_work(u132, ring, wakeup);
1358 up(&u132->scheduler_lock);
1361 up(&u132->scheduler_lock);
1362 u132_ring_put_kref(u132, ring);
1366 up(&u132->scheduler_lock);
1367 u132_ring_put_kref(u132, ring);
1372 static void u132_hcd_endp_work_scheduler(struct work_struct *work)
1374 struct u132_ring *ring;
1375 struct u132_endp *endp =
1376 container_of(work, struct u132_endp, scheduler.work);
1377 struct u132 *u132 = endp->u132;
1378 down(&u132->scheduler_lock);
1380 if (endp->edset_flush) {
1381 endp->edset_flush = 0;
1382 if (endp->dequeueing)
1383 usb_ftdi_elan_edset_flush(u132->platform_dev,
1384 ring->number, endp);
1385 up(&u132->scheduler_lock);
1386 u132_endp_put_kref(u132, endp);
1388 } else if (endp->active) {
1389 up(&u132->scheduler_lock);
1390 u132_endp_put_kref(u132, endp);
1392 } else if (ring->in_use) {
1393 up(&u132->scheduler_lock);
1394 u132_endp_put_kref(u132, endp);
1396 } else if (endp->queue_next == endp->queue_last) {
1397 up(&u132->scheduler_lock);
1398 u132_endp_put_kref(u132, endp);
1400 } else if (endp->pipetype == PIPE_INTERRUPT) {
1401 u8 address = u132->addr[endp->usb_addr].address;
1403 up(&u132->scheduler_lock);
1404 u132_endp_put_kref(u132, endp);
1408 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1411 ring->curr_endp = endp;
1413 up(&u132->scheduler_lock);
1414 retval = edset_single(u132, ring, endp, urb, address,
1415 endp->toggle_bits, u132_hcd_interrupt_recv);
1418 u132_hcd_giveback_urb(u132, endp, urb, retval);
1421 } else if (endp->pipetype == PIPE_CONTROL) {
1422 u8 address = u132->addr[endp->usb_addr].address;
1424 up(&u132->scheduler_lock);
1425 u132_endp_put_kref(u132, endp);
1427 } else if (address == 0) {
1429 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1432 ring->curr_endp = endp;
1434 up(&u132->scheduler_lock);
1435 retval = edset_setup(u132, ring, endp, urb, address,
1436 0x2, u132_hcd_initial_setup_sent);
1439 u132_hcd_giveback_urb(u132, endp, urb, retval);
1441 } else if (endp->usb_addr == 0) {
1443 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1446 ring->curr_endp = endp;
1448 up(&u132->scheduler_lock);
1449 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1450 u132_hcd_enumeration_address_sent);
1453 u132_hcd_giveback_urb(u132, endp, urb, retval);
1457 u8 address = u132->addr[endp->usb_addr].address;
1458 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1461 ring->curr_endp = endp;
1463 up(&u132->scheduler_lock);
1464 retval = edset_setup(u132, ring, endp, urb, address,
1465 0x2, u132_hcd_configure_setup_sent);
1468 u132_hcd_giveback_urb(u132, endp, urb, retval);
1473 u8 address = u132->addr[endp->usb_addr].address;
1475 up(&u132->scheduler_lock);
1476 u132_endp_put_kref(u132, endp);
1480 struct urb *urb = endp->urb_list[
1481 ENDP_QUEUE_MASK & endp->queue_next];
1483 ring->curr_endp = endp;
1485 up(&u132->scheduler_lock);
1486 retval = edset_input(u132, ring, endp, urb,
1487 address, endp->toggle_bits,
1488 u132_hcd_bulk_input_recv);
1491 u132_hcd_giveback_urb(u132, endp, urb,
1495 } else { /* output pipe */
1496 u8 address = u132->addr[endp->usb_addr].address;
1498 up(&u132->scheduler_lock);
1499 u132_endp_put_kref(u132, endp);
1503 struct urb *urb = endp->urb_list[
1504 ENDP_QUEUE_MASK & endp->queue_next];
1506 ring->curr_endp = endp;
1508 up(&u132->scheduler_lock);
1509 retval = edset_output(u132, ring, endp, urb,
1510 address, endp->toggle_bits,
1511 u132_hcd_bulk_output_sent);
1514 u132_hcd_giveback_urb(u132, endp, urb,
1522 static void port_power(struct u132 *u132, int pn, int is_on)
1524 u132->port[pn].power = is_on;
1527 static void u132_power(struct u132 *u132, int is_on)
1529 struct usb_hcd *hcd = u132_to_hcd(u132)
1530 ; /* hub is inactive unless the port is powered */
1535 hcd->self.controller->power.power_state = PMSG_ON;
1538 hcd->state = HC_STATE_HALT;
1539 hcd->self.controller->power.power_state = PMSG_SUSPEND;
1543 static int u132_periodic_reinit(struct u132 *u132)
1546 u32 fi = u132->hc_fminterval & 0x03fff;
1549 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1552 fit = fminterval & FIT;
1553 retval = u132_write_pcimem(u132, fminterval,
1554 (fit ^ FIT) | u132->hc_fminterval);
1557 retval = u132_write_pcimem(u132, periodicstart,
1558 ((9 *fi) / 10) & 0x3fff);
1564 static char *hcfs2string(int state)
1567 case OHCI_USB_RESET:
1569 case OHCI_USB_RESUME:
1572 return "operational";
1573 case OHCI_USB_SUSPEND:
1579 static int u132_init(struct u132 *u132)
1584 u132->next_statechange = jiffies;
1585 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1588 retval = u132_read_pcimem(u132, control, &control);
1591 if (u132->num_ports == 0) {
1593 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1596 u132->num_ports = rh_a & RH_A_NDP;
1597 retval = read_roothub_info(u132);
1601 if (u132->num_ports > MAX_U132_PORTS) {
1608 /* Start an OHCI controller, set the BUS operational
1609 * resets USB and controller
1612 static int u132_run(struct u132 *u132)
1621 int mask = OHCI_INTR_INIT;
1622 int first = u132->hc_fminterval == 0;
1624 int reset_timeout = 30; /* ... allow extra time */
1628 retval = u132_read_pcimem(u132, fminterval, &temp);
1631 u132->hc_fminterval = temp & 0x3fff;
1632 if (u132->hc_fminterval != FI) {
1634 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1636 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1639 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1640 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1642 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1646 case OHCI_USB_SUSPEND:
1647 case OHCI_USB_RESUME:
1648 u132->hc_control &= OHCI_CTRL_RWC;
1649 u132->hc_control |= OHCI_USB_RESUME;
1653 u132->hc_control &= OHCI_CTRL_RWC;
1654 u132->hc_control |= OHCI_USB_RESET;
1658 retval = u132_write_pcimem(u132, control, u132->hc_control);
1661 retval = u132_read_pcimem(u132, control, &control);
1665 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1668 if (!(roothub_a & RH_A_NPS)) {
1669 int temp; /* power down each port */
1670 for (temp = 0; temp < u132->num_ports; temp++) {
1671 retval = u132_write_pcimem(u132,
1672 roothub.portstatus[temp], RH_PS_LSDA);
1677 retval = u132_read_pcimem(u132, control, &control);
1680 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1683 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1687 retval = u132_read_pcimem(u132, cmdstatus, &status);
1690 if (0 != (status & OHCI_HCR)) {
1691 if (--reset_timeout == 0) {
1692 dev_err(&u132->platform_dev->dev, "USB HC reset"
1701 if (u132->flags & OHCI_QUIRK_INITRESET) {
1702 retval = u132_write_pcimem(u132, control, u132->hc_control);
1705 retval = u132_read_pcimem(u132, control, &control);
1709 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1712 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1715 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1718 retval = u132_periodic_reinit(u132);
1721 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1724 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1727 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1728 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1729 u132->flags |= OHCI_QUIRK_INITRESET;
1732 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1733 "\n", fminterval, periodicstart);
1734 } /* start controller operations */
1735 u132->hc_control &= OHCI_CTRL_RWC;
1736 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1737 retval = u132_write_pcimem(u132, control, u132->hc_control);
1740 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1743 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1746 retval = u132_read_pcimem(u132, control, &control);
1749 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1750 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1753 retval = u132_write_pcimem(u132, intrstatus, mask);
1756 retval = u132_write_pcimem(u132, intrdisable,
1757 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1758 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1761 return retval; /* handle root hub init quirks ... */
1762 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1765 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1766 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1767 roothub_a |= RH_A_NOCP;
1768 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1769 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1772 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1773 roothub_a |= RH_A_NPS;
1774 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1778 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1781 retval = u132_write_pcimem(u132, roothub.b,
1782 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1785 retval = u132_read_pcimem(u132, control, &control);
1788 mdelay((roothub_a >> 23) & 0x1fe);
1789 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1793 static void u132_hcd_stop(struct usb_hcd *hcd)
1795 struct u132 *u132 = hcd_to_u132(hcd);
1796 if (u132->going > 1) {
1797 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1798 "een removed %d\n", u132, hcd, u132->going);
1799 } else if (u132->going > 0) {
1800 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1803 down(&u132->sw_lock);
1805 u132_power(u132, 0);
1810 static int u132_hcd_start(struct usb_hcd *hcd)
1812 struct u132 *u132 = hcd_to_u132(hcd);
1813 if (u132->going > 1) {
1814 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1817 } else if (u132->going > 0) {
1818 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1820 } else if (hcd->self.controller) {
1822 struct platform_device *pdev =
1823 to_platform_device(hcd->self.controller);
1824 u16 vendor = ((struct u132_platform_data *)
1825 (pdev->dev.platform_data))->vendor;
1826 u16 device = ((struct u132_platform_data *)
1827 (pdev->dev.platform_data))->device;
1828 down(&u132->sw_lock);
1830 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1831 u132->flags = OHCI_QUIRK_AMD756;
1832 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1833 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1834 "ounds unavailable\n");
1835 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1836 u132->flags |= OHCI_QUIRK_ZFMICRO;
1837 retval = u132_run(u132);
1846 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1851 static int u132_hcd_reset(struct usb_hcd *hcd)
1853 struct u132 *u132 = hcd_to_u132(hcd);
1854 if (u132->going > 1) {
1855 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1858 } else if (u132->going > 0) {
1859 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1863 down(&u132->sw_lock);
1864 retval = u132_init(u132);
1874 static int create_endpoint_and_queue_int(struct u132 *u132,
1875 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1876 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1879 struct u132_ring *ring;
1881 u8 endp_number = ++u132->num_endpoints;
1882 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1883 kmalloc(sizeof(struct u132_endp), mem_flags);
1887 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1888 spin_lock_init(&endp->queue_lock.slock);
1889 INIT_LIST_HEAD(&endp->urb_more);
1890 ring = endp->ring = &u132->ring[0];
1891 if (ring->curr_endp) {
1892 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1894 INIT_LIST_HEAD(&endp->endp_ring);
1895 ring->curr_endp = endp;
1898 endp->dequeueing = 0;
1899 endp->edset_flush = 0;
1902 endp->endp_number = endp_number;
1905 endp->pipetype = usb_pipetype(urb->pipe);
1906 u132_endp_init_kref(u132, endp);
1907 if (usb_pipein(urb->pipe)) {
1908 endp->toggle_bits = 0x2;
1909 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1912 udev->endp_number_in[usb_endp] = endp_number;
1913 u132_udev_get_kref(u132, udev);
1915 endp->toggle_bits = 0x2;
1916 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1919 udev->endp_number_out[usb_endp] = endp_number;
1920 u132_udev_get_kref(u132, udev);
1923 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1925 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1926 endp->udev_number = address;
1927 endp->usb_addr = usb_addr;
1928 endp->usb_endp = usb_endp;
1929 endp->queue_size = 1;
1930 endp->queue_last = 0;
1931 endp->queue_next = 0;
1932 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1933 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1934 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1938 static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
1939 struct usb_host_endpoint *hep, struct urb *urb,
1940 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1941 u8 usb_endp, u8 address)
1945 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1946 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1947 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1949 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1952 endp->queue_size -= 1;
1955 list_add_tail(&urbq->urb_more, &endp->urb_more);
1962 static int create_endpoint_and_queue_bulk(struct u132 *u132,
1963 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1964 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1968 struct u132_ring *ring;
1970 u8 endp_number = ++u132->num_endpoints;
1971 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1972 kmalloc(sizeof(struct u132_endp), mem_flags);
1976 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1977 spin_lock_init(&endp->queue_lock.slock);
1978 INIT_LIST_HEAD(&endp->urb_more);
1979 endp->dequeueing = 0;
1980 endp->edset_flush = 0;
1983 endp->endp_number = endp_number;
1986 endp->pipetype = usb_pipetype(urb->pipe);
1987 u132_endp_init_kref(u132, endp);
1988 if (usb_pipein(urb->pipe)) {
1989 endp->toggle_bits = 0x2;
1990 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1994 udev->endp_number_in[usb_endp] = endp_number;
1995 u132_udev_get_kref(u132, udev);
1997 endp->toggle_bits = 0x2;
1998 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2002 udev->endp_number_out[usb_endp] = endp_number;
2003 u132_udev_get_kref(u132, udev);
2005 ring = endp->ring = &u132->ring[ring_number - 1];
2006 if (ring->curr_endp) {
2007 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2009 INIT_LIST_HEAD(&endp->endp_ring);
2010 ring->curr_endp = endp;
2014 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2015 endp->udev_number = address;
2016 endp->usb_addr = usb_addr;
2017 endp->usb_endp = usb_endp;
2018 endp->queue_size = 1;
2019 endp->queue_last = 0;
2020 endp->queue_next = 0;
2021 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2022 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2023 u132_endp_queue_work(u132, endp, 0);
2027 static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2028 struct usb_host_endpoint *hep, struct urb *urb,
2029 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2030 u8 usb_endp, u8 address)
2033 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2034 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2036 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2039 endp->queue_size -= 1;
2042 list_add_tail(&urbq->urb_more, &endp->urb_more);
2049 static int create_endpoint_and_queue_control(struct u132 *u132,
2050 struct usb_host_endpoint *hep, struct urb *urb,
2051 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2054 struct u132_ring *ring;
2055 u8 endp_number = ++u132->num_endpoints;
2056 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
2057 kmalloc(sizeof(struct u132_endp), mem_flags);
2061 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2062 spin_lock_init(&endp->queue_lock.slock);
2063 INIT_LIST_HEAD(&endp->urb_more);
2064 ring = endp->ring = &u132->ring[0];
2065 if (ring->curr_endp) {
2066 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2068 INIT_LIST_HEAD(&endp->endp_ring);
2069 ring->curr_endp = endp;
2072 endp->dequeueing = 0;
2073 endp->edset_flush = 0;
2076 endp->endp_number = endp_number;
2079 u132_endp_init_kref(u132, endp);
2080 u132_endp_get_kref(u132, endp);
2081 if (usb_addr == 0) {
2083 u8 address = u132->addr[usb_addr].address;
2084 struct u132_udev *udev = &u132->udev[address];
2085 endp->udev_number = address;
2086 endp->usb_addr = usb_addr;
2087 endp->usb_endp = usb_endp;
2090 endp->pipetype = usb_pipetype(urb->pipe);
2091 u132_udev_init_kref(u132, udev);
2092 u132_udev_get_kref(u132, udev);
2093 udev->endp_number_in[usb_endp] = endp_number;
2094 udev->endp_number_out[usb_endp] = endp_number;
2096 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2097 endp->queue_size = 1;
2098 endp->queue_last = 0;
2099 endp->queue_next = 0;
2100 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2101 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2102 u132_endp_queue_work(u132, endp, 0);
2104 } else { /*(usb_addr > 0) */
2106 u8 address = u132->addr[usb_addr].address;
2107 struct u132_udev *udev = &u132->udev[address];
2108 endp->udev_number = address;
2109 endp->usb_addr = usb_addr;
2110 endp->usb_endp = usb_endp;
2113 endp->pipetype = usb_pipetype(urb->pipe);
2114 u132_udev_get_kref(u132, udev);
2115 udev->enumeration = 2;
2116 udev->endp_number_in[usb_endp] = endp_number;
2117 udev->endp_number_out[usb_endp] = endp_number;
2119 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2120 endp->queue_size = 1;
2121 endp->queue_last = 0;
2122 endp->queue_next = 0;
2123 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2124 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2125 u132_endp_queue_work(u132, endp, 0);
2130 static int queue_control_on_old_endpoint(struct u132 *u132,
2131 struct usb_host_endpoint *hep, struct urb *urb,
2132 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2135 if (usb_addr == 0) {
2136 if (usb_pipein(urb->pipe)) {
2138 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2139 endp->urb_list[ENDP_QUEUE_MASK &
2140 endp->queue_last++] = urb;
2142 struct u132_urbq *urbq =
2143 kmalloc(sizeof(struct u132_urbq),
2146 endp->queue_size -= 1;
2149 list_add_tail(&urbq->urb_more,
2155 } else { /* usb_pipeout(urb->pipe) */
2156 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2157 int I = MAX_U132_UDEVS;
2160 struct u132_udev *udev = &u132->udev[++i];
2161 if (udev->usb_device) {
2164 udev->enumeration = 1;
2165 u132->addr[0].address = i;
2166 endp->udev_number = i;
2167 udev->udev_number = i;
2168 udev->usb_addr = usb_dev->devnum;
2169 u132_udev_init_kref(u132, udev);
2170 udev->endp_number_in[usb_endp] =
2172 u132_udev_get_kref(u132, udev);
2173 udev->endp_number_out[usb_endp] =
2175 udev->usb_device = usb_dev;
2176 ((u8 *) (urb->setup_packet))[2] =
2178 u132_udev_get_kref(u132, udev);
2183 dev_err(&u132->platform_dev->dev, "run out of d"
2188 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2189 endp->urb_list[ENDP_QUEUE_MASK &
2190 endp->queue_last++] = urb;
2192 struct u132_urbq *urbq =
2193 kmalloc(sizeof(struct u132_urbq),
2196 endp->queue_size -= 1;
2199 list_add_tail(&urbq->urb_more,
2206 } else { /*(usb_addr > 0) */
2207 u8 address = u132->addr[usb_addr].address;
2208 struct u132_udev *udev = &u132->udev[address];
2210 if (udev->enumeration == 2) {
2212 udev->enumeration = 2;
2213 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2214 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2217 struct u132_urbq *urbq =
2218 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2220 endp->queue_size -= 1;
2223 list_add_tail(&urbq->urb_more, &endp->urb_more);
2231 static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2232 struct urb *urb, gfp_t mem_flags)
2234 struct u132 *u132 = hcd_to_u132(hcd);
2235 if (irqs_disabled()) {
2236 if (__GFP_WAIT & mem_flags) {
2237 printk(KERN_ERR "invalid context for function that migh"
2242 if (u132->going > 1) {
2243 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2246 } else if (u132->going > 0) {
2247 dev_err(&u132->platform_dev->dev, "device is being removed urb="
2248 "%p status=%d\n", urb, urb->status);
2251 u8 usb_addr = usb_pipedevice(urb->pipe);
2252 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2253 struct usb_device *usb_dev = urb->dev;
2254 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2255 u8 address = u132->addr[usb_addr].address;
2256 struct u132_udev *udev = &u132->udev[address];
2257 struct u132_endp *endp = hep->hcpriv;
2258 urb->actual_length = 0;
2262 spin_lock_irqsave(&endp->queue_lock.slock,
2264 retval = queue_int_on_old_endpoint(u132, udev,
2265 hep, urb, usb_dev, endp, usb_addr,
2267 spin_unlock_irqrestore(&endp->queue_lock.slock,
2272 u132_endp_queue_work(u132, endp,
2273 msecs_to_jiffies(urb->interval))
2277 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2279 } else { /*(endp == NULL) */
2280 return create_endpoint_and_queue_int(u132, udev,
2281 hep, urb, usb_dev, usb_addr, usb_endp,
2282 address, mem_flags);
2284 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2285 dev_err(&u132->platform_dev->dev, "the hardware does no"
2286 "t support PIPE_ISOCHRONOUS\n");
2288 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2289 u8 address = u132->addr[usb_addr].address;
2290 struct u132_udev *udev = &u132->udev[address];
2291 struct u132_endp *endp = hep->hcpriv;
2292 urb->actual_length = 0;
2296 spin_lock_irqsave(&endp->queue_lock.slock,
2298 retval = queue_bulk_on_old_endpoint(u132, udev,
2299 hep, urb, usb_dev, endp, usb_addr,
2301 spin_unlock_irqrestore(&endp->queue_lock.slock,
2306 u132_endp_queue_work(u132, endp, 0);
2309 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2312 return create_endpoint_and_queue_bulk(u132,
2313 udev, hep, urb, usb_dev, usb_addr,
2314 usb_endp, address, mem_flags);
2316 struct u132_endp *endp = hep->hcpriv;
2318 u8 *b = urb->setup_packet;
2320 char data[30 *3 + 4];
2322 int m = (sizeof(data) - 1) / 3;
2325 while (urb_size-- > 0) {
2327 } else if (i++ < m) {
2328 int w = sprintf(d, " %02X", *b++);
2332 d += sprintf(d, " ..");
2337 spin_lock_irqsave(&endp->queue_lock.slock,
2339 retval = queue_control_on_old_endpoint(u132,
2340 hep, urb, usb_dev, endp, usb_addr,
2342 spin_unlock_irqrestore(&endp->queue_lock.slock,
2347 u132_endp_queue_work(u132, endp, 0);
2350 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2353 return create_endpoint_and_queue_control(u132,
2354 hep, urb, usb_dev, usb_addr, usb_endp,
2360 static int dequeue_from_overflow_chain(struct u132 *u132,
2361 struct u132_endp *endp, struct urb *urb)
2363 struct list_head *scan;
2364 struct list_head *head = &endp->urb_more;
2365 list_for_each(scan, head) {
2366 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2368 if (urbq->urb == urb) {
2369 struct usb_hcd *hcd = u132_to_hcd(u132);
2371 endp->queue_size -= 1;
2372 urb->error_count = 0;
2374 usb_hcd_giveback_urb(hcd, urb);
2379 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2380 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2381 "\n", urb, endp->endp_number, endp, endp->ring->number,
2382 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2383 endp->usb_endp, endp->usb_addr, endp->queue_size,
2384 endp->queue_next, endp->queue_last);
2388 static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2392 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2393 if (endp->queue_size == 0) {
2394 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2395 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2396 endp->endp_number, endp, endp->ring->number,
2397 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2398 endp->usb_endp, endp->usb_addr);
2399 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2402 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2404 endp->dequeueing = 1;
2405 endp->edset_flush = 1;
2406 u132_endp_queue_work(u132, endp, 0);
2407 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2411 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2412 u132_hcd_abandon_urb(u132, endp, urb, urb->status);
2417 u16 queue_size = endp->queue_size;
2418 u16 queue_scan = endp->queue_next;
2419 struct urb **urb_slot = NULL;
2420 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2421 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2423 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2429 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2430 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2432 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2436 struct usb_hcd *hcd = u132_to_hcd(u132);
2437 endp->queue_size -= 1;
2438 if (list_empty(&endp->urb_more)) {
2439 spin_unlock_irqrestore(&endp->queue_lock.slock,
2442 struct list_head *next = endp->urb_more.next;
2443 struct u132_urbq *urbq = list_entry(next,
2444 struct u132_urbq, urb_more);
2446 *urb_slot = urbq->urb;
2447 spin_unlock_irqrestore(&endp->queue_lock.slock,
2450 } urb->error_count = 0;
2452 usb_hcd_giveback_urb(hcd, urb);
2454 } else if (list_empty(&endp->urb_more)) {
2455 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2456 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2457 "=%d size=%d next=%04X last=%04X\n", urb,
2458 endp->endp_number, endp, endp->ring->number,
2459 endp->input ? 'I' : ' ',
2460 endp->output ? 'O' : ' ', endp->usb_endp,
2461 endp->usb_addr, endp->queue_size,
2462 endp->queue_next, endp->queue_last);
2463 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2466 int retval = dequeue_from_overflow_chain(u132, endp,
2468 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2474 static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
2476 struct u132 *u132 = hcd_to_u132(hcd);
2477 if (u132->going > 2) {
2478 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2482 u8 usb_addr = usb_pipedevice(urb->pipe);
2483 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2484 u8 address = u132->addr[usb_addr].address;
2485 struct u132_udev *udev = &u132->udev[address];
2486 if (usb_pipein(urb->pipe)) {
2487 u8 endp_number = udev->endp_number_in[usb_endp];
2488 struct u132_endp *endp = u132->endp[endp_number - 1];
2489 return u132_endp_urb_dequeue(u132, endp, urb);
2491 u8 endp_number = udev->endp_number_out[usb_endp];
2492 struct u132_endp *endp = u132->endp[endp_number - 1];
2493 return u132_endp_urb_dequeue(u132, endp, urb);
2498 static void u132_endpoint_disable(struct usb_hcd *hcd,
2499 struct usb_host_endpoint *hep)
2501 struct u132 *u132 = hcd_to_u132(hcd);
2502 if (u132->going > 2) {
2503 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2504 ") has been removed %d\n", u132, hcd, hep,
2507 struct u132_endp *endp = hep->hcpriv;
2509 u132_endp_put_kref(u132, endp);
2513 static int u132_get_frame(struct usb_hcd *hcd)
2515 struct u132 *u132 = hcd_to_u132(hcd);
2516 if (u132->going > 1) {
2517 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2520 } else if (u132->going > 0) {
2521 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2525 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2531 static int u132_roothub_descriptor(struct u132 *u132,
2532 struct usb_hub_descriptor *desc)
2538 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2541 desc->bDescriptorType = 0x29;
2542 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2543 desc->bHubContrCurrent = 0;
2544 desc->bNbrPorts = u132->num_ports;
2545 temp = 1 + (u132->num_ports / 8);
2546 desc->bDescLength = 7 + 2 *temp;
2548 if (rh_a & RH_A_NPS)
2550 if (rh_a & RH_A_PSM)
2552 if (rh_a & RH_A_NOCP) {
2554 } else if (rh_a & RH_A_OCPM)
2556 desc->wHubCharacteristics = cpu_to_le16(temp);
2557 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2560 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2561 desc->bitmap[0] = rh_b & RH_B_DR;
2562 if (u132->num_ports > 7) {
2563 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2564 desc->bitmap[2] = 0xff;
2566 desc->bitmap[1] = 0xff;
2570 static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2573 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2574 *desc = cpu_to_le32(rh_status);
2578 static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2580 if (wIndex == 0 || wIndex > u132->num_ports) {
2583 int port = wIndex - 1;
2584 u32 rh_portstatus = -1;
2585 int ret_portstatus = u132_read_pcimem(u132,
2586 roothub.portstatus[port], &rh_portstatus);
2587 *desc = cpu_to_le32(rh_portstatus);
2588 if (*(u16 *) (desc + 2)) {
2589 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2590 "ge = %08X\n", port, *desc);
2592 return ret_portstatus;
2597 /* this timer value might be vendor-specific ... */
2598 #define PORT_RESET_HW_MSEC 10
2599 #define PORT_RESET_MSEC 10
2600 /* wrap-aware logic morphed from <linux/jiffies.h> */
2601 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2602 static int u132_roothub_portreset(struct u132 *u132, int port_index)
2608 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2612 reset_done = now + PORT_RESET_MSEC;
2616 retval = u132_read_pcimem(u132,
2617 roothub.portstatus[port_index], &portstat);
2620 if (RH_PS_PRS & portstat) {
2624 } while (tick_before(now, reset_done));
2625 if (RH_PS_PRS & portstat)
2627 if (RH_PS_CCS & portstat) {
2628 if (RH_PS_PRSC & portstat) {
2629 retval = u132_write_pcimem(u132,
2630 roothub.portstatus[port_index],
2636 break; /* start the next reset,
2637 sleep till it's probably done */
2638 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2642 msleep(PORT_RESET_HW_MSEC);
2643 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2647 } while (tick_before(now, reset_done));
2651 static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2654 if (wIndex == 0 || wIndex > u132->num_ports) {
2658 int port_index = wIndex - 1;
2659 struct u132_port *port = &u132->port[port_index];
2660 port->Status &= ~(1 << wValue);
2662 case USB_PORT_FEAT_SUSPEND:
2663 retval = u132_write_pcimem(u132,
2664 roothub.portstatus[port_index], RH_PS_PSS);
2668 case USB_PORT_FEAT_POWER:
2669 retval = u132_write_pcimem(u132,
2670 roothub.portstatus[port_index], RH_PS_PPS);
2674 case USB_PORT_FEAT_RESET:
2675 retval = u132_roothub_portreset(u132, port_index);
2685 static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2688 if (wIndex == 0 || wIndex > u132->num_ports) {
2691 int port_index = wIndex - 1;
2694 struct u132_port *port = &u132->port[port_index];
2695 port->Status &= ~(1 << wValue);
2697 case USB_PORT_FEAT_ENABLE:
2700 case USB_PORT_FEAT_C_ENABLE:
2703 case USB_PORT_FEAT_SUSPEND:
2705 if ((u132->hc_control & OHCI_CTRL_HCFS)
2707 dev_err(&u132->platform_dev->dev, "TODO resume_"
2711 case USB_PORT_FEAT_C_SUSPEND:
2714 case USB_PORT_FEAT_POWER:
2717 case USB_PORT_FEAT_C_CONNECTION:
2720 case USB_PORT_FEAT_C_OVER_CURRENT:
2723 case USB_PORT_FEAT_C_RESET:
2729 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2738 /* the virtual root hub timer IRQ checks for hub status*/
2739 static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2741 struct u132 *u132 = hcd_to_u132(hcd);
2742 if (u132->going > 1) {
2743 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2744 "ed %d\n", hcd, u132->going);
2746 } else if (u132->going > 0) {
2747 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2751 int i, changed = 0, length = 1;
2752 if (u132->flags & OHCI_QUIRK_AMD756) {
2753 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2754 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2755 "ereads as NDP=%d\n",
2756 u132->hc_roothub_a & RH_A_NDP);
2760 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) {
2761 buf[0] = changed = 1;
2764 if (u132->num_ports > 7) {
2768 for (i = 0; i < u132->num_ports; i++) {
2769 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2770 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2774 buf[0] |= 1 << (i + 1);
2776 buf[1] |= 1 << (i - 7);
2779 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) {
2782 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) {
2786 done:return changed ? length : 0;
2790 static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2791 u16 wIndex, char *buf, u16 wLength)
2793 struct u132 *u132 = hcd_to_u132(hcd);
2794 if (u132->going > 1) {
2795 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2798 } else if (u132->going > 0) {
2799 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2803 down(&u132->sw_lock);
2805 case ClearHubFeature:
2807 case C_HUB_OVER_CURRENT:
2808 case C_HUB_LOCAL_POWER:
2816 case C_HUB_OVER_CURRENT:
2817 case C_HUB_LOCAL_POWER:
2823 case ClearPortFeature:{
2824 retval = u132_roothub_clearportfeature(u132,
2830 case GetHubDescriptor:{
2831 retval = u132_roothub_descriptor(u132,
2832 (struct usb_hub_descriptor *)buf);
2838 retval = u132_roothub_status(u132,
2844 case GetPortStatus:{
2845 retval = u132_roothub_portstatus(u132,
2846 (__le32 *) buf, wIndex);
2851 case SetPortFeature:{
2852 retval = u132_roothub_setportfeature(u132,
2860 error:u132_disable(u132);
2863 stall:retval = -EPIPE;
2871 static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2873 struct u132 *u132 = hcd_to_u132(hcd);
2874 if (u132->going > 1) {
2875 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2878 } else if (u132->going > 0) {
2879 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2885 static void u132_hub_irq_enable(struct usb_hcd *hcd)
2887 struct u132 *u132 = hcd_to_u132(hcd);
2888 if (u132->going > 1) {
2889 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2891 } else if (u132->going > 0)
2892 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2897 static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2899 struct u132 *u132 = hcd_to_u132(hcd);
2900 if (u132->going > 1) {
2901 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2904 } else if (u132->going > 0) {
2905 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2911 static int u132_hcd_resume(struct usb_hcd *hcd)
2913 struct u132 *u132 = hcd_to_u132(hcd);
2914 if (u132->going > 1) {
2915 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2918 } else if (u132->going > 0) {
2919 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2925 static int u132_bus_suspend(struct usb_hcd *hcd)
2927 struct u132 *u132 = hcd_to_u132(hcd);
2928 if (u132->going > 1) {
2929 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2932 } else if (u132->going > 0) {
2933 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2939 static int u132_bus_resume(struct usb_hcd *hcd)
2941 struct u132 *u132 = hcd_to_u132(hcd);
2942 if (u132->going > 1) {
2943 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2946 } else if (u132->going > 0) {
2947 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2954 #define u132_hcd_suspend NULL
2955 #define u132_hcd_resume NULL
2956 #define u132_bus_suspend NULL
2957 #define u132_bus_resume NULL
2959 static struct hc_driver u132_hc_driver = {
2960 .description = hcd_name,
2961 .hcd_priv_size = sizeof(struct u132),
2963 .flags = HCD_USB11 | HCD_MEMORY,
2964 .reset = u132_hcd_reset,
2965 .start = u132_hcd_start,
2966 .suspend = u132_hcd_suspend,
2967 .resume = u132_hcd_resume,
2968 .stop = u132_hcd_stop,
2969 .urb_enqueue = u132_urb_enqueue,
2970 .urb_dequeue = u132_urb_dequeue,
2971 .endpoint_disable = u132_endpoint_disable,
2972 .get_frame_number = u132_get_frame,
2973 .hub_status_data = u132_hub_status_data,
2974 .hub_control = u132_hub_control,
2975 .bus_suspend = u132_bus_suspend,
2976 .bus_resume = u132_bus_resume,
2977 .start_port_reset = u132_start_port_reset,
2978 .hub_irq_enable = u132_hub_irq_enable,
2982 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
2983 * is held for writing, thus this module must not call usb_remove_hcd()
2984 * synchronously - but instead should immediately stop activity to the
2985 * device and asynchronously call usb_remove_hcd()
2987 static int __devexit u132_remove(struct platform_device *pdev)
2989 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2991 struct u132 *u132 = hcd_to_u132(hcd);
2992 if (u132->going++ > 1) {
2993 dev_err(&u132->platform_dev->dev, "already being remove"
2997 int rings = MAX_U132_RINGS;
2998 int endps = MAX_U132_ENDPS;
2999 dev_err(&u132->platform_dev->dev, "removing device u132"
3000 ".%d\n", u132->sequence_num);
3002 down(&u132->sw_lock);
3003 u132_monitor_cancel_work(u132);
3004 while (rings-- > 0) {
3005 struct u132_ring *ring = &u132->ring[rings];
3006 u132_ring_cancel_work(u132, ring);
3007 } while (endps-- > 0) {
3008 struct u132_endp *endp = u132->endp[endps];
3010 u132_endp_cancel_work(u132, endp);
3013 printk(KERN_INFO "removing device u132.%d\n",
3014 u132->sequence_num);
3016 usb_remove_hcd(hcd);
3017 u132_u132_put_kref(u132);
3024 static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3026 int rings = MAX_U132_RINGS;
3027 int ports = MAX_U132_PORTS;
3028 int addrs = MAX_U132_ADDRS;
3029 int udevs = MAX_U132_UDEVS;
3030 int endps = MAX_U132_ENDPS;
3031 u132->board = pdev->dev.platform_data;
3032 u132->platform_dev = pdev;
3035 init_MUTEX(&u132->sw_lock);
3036 init_MUTEX(&u132->scheduler_lock);
3037 while (rings-- > 0) {
3038 struct u132_ring *ring = &u132->ring[rings];
3040 ring->number = rings + 1;
3042 ring->curr_endp = NULL;
3043 INIT_DELAYED_WORK(&ring->scheduler,
3044 u132_hcd_ring_work_scheduler);
3045 } down(&u132->sw_lock);
3046 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3047 while (ports-- > 0) {
3048 struct u132_port *port = &u132->port[ports];
3054 } while (addrs-- > 0) {
3055 struct u132_addr *addr = &u132->addr[addrs];
3057 } while (udevs-- > 0) {
3058 struct u132_udev *udev = &u132->udev[udevs];
3059 int i = ARRAY_SIZE(udev->endp_number_in);
3060 int o = ARRAY_SIZE(udev->endp_number_out);
3061 udev->usb_device = NULL;
3062 udev->udev_number = 0;
3064 udev->portnumber = 0;
3066 udev->endp_number_in[i] = 0;
3069 udev->endp_number_out[o] = 0;
3072 while (endps-- > 0) {
3073 u132->endp[endps] = NULL;
3079 static int __devinit u132_probe(struct platform_device *pdev)
3081 struct usb_hcd *hcd;
3087 if (u132_exiting > 0) {
3090 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3093 retval = ftdi_read_pcimem(pdev, control, &control);
3096 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3099 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3100 if (pdev->dev.dma_mask) {
3103 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3105 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3107 ftdi_elan_gone_away(pdev);
3111 struct u132 *u132 = hcd_to_u132(hcd);
3112 hcd->rsrc_start = 0;
3113 down(&u132_module_lock);
3114 list_add_tail(&u132->u132_list, &u132_static_list);
3115 u132->sequence_num = ++u132_instances;
3116 up(&u132_module_lock);
3117 u132_u132_init_kref(u132);
3118 u132_initialise(u132, pdev);
3119 hcd->product_desc = "ELAN U132 Host Controller";
3120 retval = usb_add_hcd(hcd, 0, 0);
3122 dev_err(&u132->platform_dev->dev, "init error %d\n",
3124 u132_u132_put_kref(u132);
3127 u132_monitor_queue_work(u132, 100);
3135 /* for this device there's no useful distinction between the controller
3136 * and its root hub, except that the root hub only gets direct PM calls
3137 * when CONFIG_USB_SUSPEND is enabled.
3139 static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3141 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3142 struct u132 *u132 = hcd_to_u132(hcd);
3143 if (u132->going > 1) {
3144 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3147 } else if (u132->going > 0) {
3148 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3152 if (state.event == PM_EVENT_FREEZE) {
3153 retval = u132_bus_suspend(hcd);
3154 } else if (state.event == PM_EVENT_SUSPEND) {
3155 int ports = MAX_U132_PORTS;
3156 while (ports-- > 0) {
3157 port_power(u132, ports, 0);
3161 pdev->dev.power.power_state = state;
3166 static int u132_resume(struct platform_device *pdev)
3168 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3169 struct u132 *u132 = hcd_to_u132(hcd);
3170 if (u132->going > 1) {
3171 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3174 } else if (u132->going > 0) {
3175 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3179 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
3180 int ports = MAX_U132_PORTS;
3181 while (ports-- > 0) {
3182 port_power(u132, ports, 1);
3186 pdev->dev.power.power_state = PMSG_ON;
3187 retval = u132_bus_resume(hcd);
3194 #define u132_suspend NULL
3195 #define u132_resume NULL
3198 * this driver is loaded explicitly by ftdi_u132
3200 * the platform_driver struct is static because it is per type of module
3202 static struct platform_driver u132_platform_driver = {
3203 .probe = u132_probe,
3204 .remove = __devexit_p(u132_remove),
3205 .suspend = u132_suspend,
3206 .resume = u132_resume,
3208 .name = (char *)hcd_name,
3209 .owner = THIS_MODULE,
3212 static int __init u132_hcd_init(void)
3215 INIT_LIST_HEAD(&u132_static_list);
3218 init_MUTEX(&u132_module_lock);
3221 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3223 workqueue = create_singlethread_workqueue("u132");
3224 retval = platform_driver_register(&u132_platform_driver);
3229 module_init(u132_hcd_init);
3230 static void __exit u132_hcd_exit(void)
3234 down(&u132_module_lock);
3236 up(&u132_module_lock);
3237 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3238 platform_device_unregister(u132->platform_dev);
3239 } platform_driver_unregister(&u132_platform_driver);
3240 printk(KERN_INFO "u132-hcd driver deregistered\n");
3241 wait_event(u132_hcd_wait, u132_instances == 0);
3242 flush_workqueue(workqueue);
3243 destroy_workqueue(workqueue);
3247 module_exit(u132_hcd_exit);
3248 MODULE_LICENSE("GPL");