2 * Host Controller Driver for the Elan Digital Systems U132 adapter
4 * Copyright(C) 2006 Elan Digital Systems Limited
5 * http://www.elandigitalsystems.com
7 * Author and Maintainer - Tony Olech - Elan Digital Systems
8 * tony.olech@elandigitalsystems.com
10 * This program is free software;you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation, version 2.
15 * This driver was written by Tony Olech(tony.olech@elandigitalsystems.com)
16 * based on various USB host drivers in the 2.6.15 linux kernel
17 * with constant reference to the 3rd Edition of Linux Device Drivers
18 * published by O'Reilly
20 * The U132 adapter is a USB to CardBus adapter specifically designed
21 * for PC cards that contain an OHCI host controller. Typical PC cards
22 * are the Orange Mobile 3G Option GlobeTrotter Fusion card.
24 * The U132 adapter will *NOT *work with PC cards that do not contain
25 * an OHCI controller. A simple way to test whether a PC card has an
26 * OHCI controller as an interface is to insert the PC card directly
27 * into a laptop(or desktop) with a CardBus slot and if "lspci" shows
28 * a new USB controller and "lsusb -v" shows a new OHCI Host Controller
29 * then there is a good chance that the U132 adapter will support the
30 * PC card.(you also need the specific client driver for the PC card)
32 * Please inform the Author and Maintainer about any PC cards that
33 * contain OHCI Host Controller and work when directly connected to
34 * an embedded CardBus slot but do not work when they are connected
35 * via an ELAN U132 adapter.
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/moduleparam.h>
41 #include <linux/delay.h>
42 #include <linux/ioport.h>
43 #include <linux/pci_ids.h>
44 #include <linux/sched.h>
45 #include <linux/slab.h>
46 #include <linux/errno.h>
47 #include <linux/init.h>
48 #include <linux/timer.h>
49 #include <linux/list.h>
50 #include <linux/interrupt.h>
51 #include <linux/usb.h>
52 #include <linux/workqueue.h>
53 #include <linux/platform_device.h>
54 #include <linux/mutex.h>
57 #include <asm/system.h>
58 #include <asm/byteorder.h>
59 #include "../core/hcd.h"
61 /* FIXME ohci.h is ONLY for internal use by the OHCI driver.
62 * If you're going to try stuff like this, you need to split
63 * out shareable stuff (register declarations?) into its own
64 * file, maybe name <linux/usb/ohci.h>
68 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
69 #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
71 MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
72 MODULE_DESCRIPTION("U132 USB Host Controller Driver");
73 MODULE_LICENSE("GPL");
74 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
75 INT_MODULE_PARM(testing, 0);
76 /* Some boards misreport power switching/overcurrent*/
77 static int distrust_firmware = 1;
78 module_param(distrust_firmware, bool, 0);
79 MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
81 static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
83 * u132_module_lock exists to protect access to global variables
86 static struct mutex u132_module_lock;
87 static int u132_exiting = 0;
88 static int u132_instances = 0;
89 static struct list_head u132_static_list;
91 * end of the global variables protected by u132_module_lock
93 static struct workqueue_struct *workqueue;
94 #define MAX_U132_PORTS 7
95 #define MAX_U132_ADDRS 128
96 #define MAX_U132_UDEVS 4
97 #define MAX_U132_ENDPS 100
98 #define MAX_U132_RINGS 4
99 static const char *cc_to_text[16] = {
129 struct usb_device *usb_device;
134 u8 endp_number_in[16];
135 u8 endp_number_out[16];
137 #define ENDP_QUEUE_SHIFT 3
138 #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
139 #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
141 struct list_head urb_more;
154 struct list_head endp_ring;
155 struct u132_ring *ring;
156 unsigned toggle_bits:2;
162 unsigned dequeueing:1;
163 unsigned edset_flush:1;
164 unsigned spare_bits:14;
165 unsigned long jiffies;
166 struct usb_host_endpoint *hep;
167 struct u132_spin queue_lock;
171 struct urb *urb_list[ENDP_QUEUE_SIZE];
172 struct list_head urb_more;
173 struct delayed_work scheduler;
180 struct u132_endp *curr_endp;
181 struct delayed_work scheduler;
185 struct list_head u132_list;
186 struct mutex sw_lock;
187 struct semaphore scheduler_lock;
188 struct u132_platform_data *board;
189 struct platform_device *platform_dev;
190 struct u132_ring ring[MAX_U132_RINGS];
198 u32 hc_roothub_status;
200 u32 hc_roothub_portstatus[MAX_ROOT_PORTS];
202 unsigned long next_statechange;
203 struct delayed_work monitor;
205 struct u132_addr addr[MAX_U132_ADDRS];
206 struct u132_udev udev[MAX_U132_UDEVS];
207 struct u132_port port[MAX_U132_PORTS];
208 struct u132_endp *endp[MAX_U132_ENDPS];
212 * these cannot be inlines because we need the structure offset!!
213 * Does anyone have a better way?????
215 #define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
216 offsetof(struct ohci_regs, member), 0, data);
217 #define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
218 offsetof(struct ohci_regs, member), 0, data);
219 #define u132_read_pcimem(u132, member, data) \
220 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
221 ohci_regs, member), 0, data);
222 #define u132_write_pcimem(u132, member, data) \
223 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
224 ohci_regs, member), 0, data);
225 static inline struct u132 *udev_to_u132(struct u132_udev *udev)
227 u8 udev_number = udev->udev_number;
228 return container_of(udev, struct u132, udev[udev_number]);
231 static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd)
233 return (struct u132 *)(hcd->hcd_priv);
236 static inline struct usb_hcd *u132_to_hcd(struct u132 *u132)
238 return container_of((void *)u132, struct usb_hcd, hcd_priv);
241 static inline void u132_disable(struct u132 *u132)
243 u132_to_hcd(u132)->state = HC_STATE_HALT;
247 #define kref_to_u132(d) container_of(d, struct u132, kref)
248 #define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref)
249 #define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref)
250 #include "../misc/usb_u132.h"
251 static const char hcd_name[] = "u132_hcd";
252 #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
253 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
254 USB_PORT_STAT_C_RESET) << 16)
255 static void u132_hcd_delete(struct kref *kref)
257 struct u132 *u132 = kref_to_u132(kref);
258 struct platform_device *pdev = u132->platform_dev;
259 struct usb_hcd *hcd = u132_to_hcd(u132);
261 mutex_lock(&u132_module_lock);
262 list_del_init(&u132->u132_list);
264 mutex_unlock(&u132_module_lock);
265 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
266 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
270 static inline void u132_u132_put_kref(struct u132 *u132)
272 kref_put(&u132->kref, u132_hcd_delete);
275 static inline void u132_u132_init_kref(struct u132 *u132)
277 kref_init(&u132->kref);
280 static void u132_udev_delete(struct kref *kref)
282 struct u132_udev *udev = kref_to_u132_udev(kref);
283 udev->udev_number = 0;
284 udev->usb_device = NULL;
286 udev->enumeration = 0;
289 static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev)
291 kref_put(&udev->kref, u132_udev_delete);
294 static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev)
296 kref_get(&udev->kref);
299 static inline void u132_udev_init_kref(struct u132 *u132,
300 struct u132_udev *udev)
302 kref_init(&udev->kref);
305 static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring)
307 kref_put(&u132->kref, u132_hcd_delete);
310 static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring,
314 if (queue_delayed_work(workqueue, &ring->scheduler, delta))
316 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0))
318 kref_put(&u132->kref, u132_hcd_delete);
322 static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
325 kref_get(&u132->kref);
326 u132_ring_requeue_work(u132, ring, delta);
330 static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
332 if (cancel_delayed_work(&ring->scheduler)) {
333 kref_put(&u132->kref, u132_hcd_delete);
337 static void u132_endp_delete(struct kref *kref)
339 struct u132_endp *endp = kref_to_u132_endp(kref);
340 struct u132 *u132 = endp->u132;
341 u8 usb_addr = endp->usb_addr;
342 u8 usb_endp = endp->usb_endp;
343 u8 address = u132->addr[usb_addr].address;
344 struct u132_udev *udev = &u132->udev[address];
345 u8 endp_number = endp->endp_number;
346 struct usb_host_endpoint *hep = endp->hep;
347 struct u132_ring *ring = endp->ring;
348 struct list_head *head = &endp->endp_ring;
350 if (endp == ring->curr_endp) {
351 if (list_empty(head)) {
352 ring->curr_endp = NULL;
355 struct u132_endp *next_endp = list_entry(head->next,
356 struct u132_endp, endp_ring);
357 ring->curr_endp = next_endp;
362 udev->endp_number_in[usb_endp] = 0;
363 u132_udev_put_kref(u132, udev);
366 udev->endp_number_out[usb_endp] = 0;
367 u132_udev_put_kref(u132, udev);
369 u132->endp[endp_number - 1] = NULL;
372 u132_u132_put_kref(u132);
375 static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp)
377 kref_put(&endp->kref, u132_endp_delete);
380 static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp)
382 kref_get(&endp->kref);
385 static inline void u132_endp_init_kref(struct u132 *u132,
386 struct u132_endp *endp)
388 kref_init(&endp->kref);
389 kref_get(&u132->kref);
392 static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
395 if (queue_delayed_work(workqueue, &endp->scheduler, delta))
396 kref_get(&endp->kref);
399 static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp)
401 if (cancel_delayed_work(&endp->scheduler))
402 kref_put(&endp->kref, u132_endp_delete);
405 static inline void u132_monitor_put_kref(struct u132 *u132)
407 kref_put(&u132->kref, u132_hcd_delete);
410 static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta)
412 if (queue_delayed_work(workqueue, &u132->monitor, delta))
413 kref_get(&u132->kref);
416 static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta)
418 if (!queue_delayed_work(workqueue, &u132->monitor, delta))
419 kref_put(&u132->kref, u132_hcd_delete);
422 static void u132_monitor_cancel_work(struct u132 *u132)
424 if (cancel_delayed_work(&u132->monitor))
425 kref_put(&u132->kref, u132_hcd_delete);
428 static int read_roothub_info(struct u132 *u132)
432 retval = u132_read_pcimem(u132, revision, &revision);
434 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
437 } else if ((revision & 0xFF) == 0x10) {
438 } else if ((revision & 0xFF) == 0x11) {
440 dev_err(&u132->platform_dev->dev, "device revision is not valid"
441 " %08X\n", revision);
444 retval = u132_read_pcimem(u132, control, &u132->hc_control);
446 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
450 retval = u132_read_pcimem(u132, roothub.status,
451 &u132->hc_roothub_status);
453 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
454 "g roothub.status\n", retval);
457 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a);
459 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
460 "g roothub.a\n", retval);
464 int I = u132->num_ports;
467 retval = u132_read_pcimem(u132, roothub.portstatus[i],
468 &u132->hc_roothub_portstatus[i]);
470 dev_err(&u132->platform_dev->dev, "error %d acc"
471 "essing device roothub.portstatus[%d]\n"
481 static void u132_hcd_monitor_work(struct work_struct *work)
483 struct u132 *u132 = container_of(work, struct u132, monitor.work);
484 if (u132->going > 1) {
485 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
487 u132_monitor_put_kref(u132);
489 } else if (u132->going > 0) {
490 dev_err(&u132->platform_dev->dev, "device is being removed\n");
491 u132_monitor_put_kref(u132);
495 mutex_lock(&u132->sw_lock);
496 retval = read_roothub_info(u132);
498 struct usb_hcd *hcd = u132_to_hcd(u132);
501 mutex_unlock(&u132->sw_lock);
503 ftdi_elan_gone_away(u132->platform_dev);
504 u132_monitor_put_kref(u132);
507 u132_monitor_requeue_work(u132, 500);
508 mutex_unlock(&u132->sw_lock);
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 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
522 usb_hcd_unlink_urb_from_ep(hcd, urb);
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, status);
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 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
561 usb_hcd_unlink_urb_from_ep(hcd, urb);
562 endp->queue_next += 1;
563 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
565 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
567 struct list_head *next = endp->urb_more.next;
568 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
571 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
574 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
576 } usb_hcd_giveback_urb(hcd, urb, status);
580 static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
581 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
582 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
583 int toggle_bits, int error_count, int condition_code, int repeat_number,
584 int halted, int skipped, int actual, int non_null))
586 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
587 urb, address, endp->usb_endp, toggle_bits, callback);
590 static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
591 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
592 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
593 int toggle_bits, int error_count, int condition_code, int repeat_number,
594 int halted, int skipped, int actual, int non_null))
596 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
597 urb, address, endp->usb_endp, toggle_bits, callback);
600 static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
601 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
602 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
603 int toggle_bits, int error_count, int condition_code, int repeat_number,
604 int halted, int skipped, int actual, int non_null))
606 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
607 endp, urb, address, endp->usb_endp, toggle_bits, callback);
610 static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
611 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
612 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
613 int toggle_bits, int error_count, int condition_code, int repeat_number,
614 int halted, int skipped, int actual, int non_null))
616 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
617 endp, urb, address, endp->usb_endp, toggle_bits, callback);
622 * must not LOCK sw_lock
625 static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
626 int len, int toggle_bits, int error_count, int condition_code,
627 int repeat_number, int halted, int skipped, int actual, int non_null)
629 struct u132_endp *endp = data;
630 struct u132 *u132 = endp->u132;
631 u8 address = u132->addr[endp->usb_addr].address;
632 struct u132_udev *udev = &u132->udev[address];
633 down(&u132->scheduler_lock);
634 if (u132->going > 1) {
635 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
637 up(&u132->scheduler_lock);
638 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
640 } else if (endp->dequeueing) {
641 endp->dequeueing = 0;
642 up(&u132->scheduler_lock);
643 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
645 } else if (u132->going > 0) {
646 dev_err(&u132->platform_dev->dev, "device is being removed "
648 up(&u132->scheduler_lock);
649 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
651 } else if (!urb->unlinked) {
652 struct u132_ring *ring = endp->ring;
653 u8 *u = urb->transfer_buffer + urb->actual_length;
659 urb->actual_length += len;
660 if ((condition_code == TD_CC_NOERROR) &&
661 (urb->transfer_buffer_length > urb->actual_length)) {
662 endp->toggle_bits = toggle_bits;
663 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
665 if (urb->actual_length > 0) {
667 up(&u132->scheduler_lock);
668 retval = edset_single(u132, ring, endp, urb,
669 address, endp->toggle_bits,
670 u132_hcd_interrupt_recv);
673 u132_hcd_giveback_urb(u132, endp, urb,
678 endp->jiffies = jiffies +
679 msecs_to_jiffies(urb->interval);
680 u132_ring_cancel_work(u132, ring);
681 u132_ring_queue_work(u132, ring, 0);
682 up(&u132->scheduler_lock);
683 u132_endp_put_kref(u132, endp);
686 } else if ((condition_code == TD_DATAUNDERRUN) &&
687 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
688 endp->toggle_bits = toggle_bits;
689 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
691 up(&u132->scheduler_lock);
692 u132_hcd_giveback_urb(u132, endp, urb, 0);
695 if (condition_code == TD_CC_NOERROR) {
696 endp->toggle_bits = toggle_bits;
697 usb_settoggle(udev->usb_device, endp->usb_endp,
699 } else if (condition_code == TD_CC_STALL) {
700 endp->toggle_bits = 0x2;
701 usb_settoggle(udev->usb_device, endp->usb_endp,
704 endp->toggle_bits = 0x2;
705 usb_settoggle(udev->usb_device, endp->usb_endp,
707 dev_err(&u132->platform_dev->dev, "urb=%p givin"
708 "g back INTERRUPT %s\n", urb,
709 cc_to_text[condition_code]);
711 up(&u132->scheduler_lock);
712 u132_hcd_giveback_urb(u132, endp, urb,
713 cc_to_error[condition_code]);
717 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
718 "unlinked=%d\n", urb, urb->unlinked);
719 up(&u132->scheduler_lock);
720 u132_hcd_giveback_urb(u132, endp, urb, 0);
725 static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
726 int len, int toggle_bits, int error_count, int condition_code,
727 int repeat_number, int halted, int skipped, int actual, int non_null)
729 struct u132_endp *endp = data;
730 struct u132 *u132 = endp->u132;
731 u8 address = u132->addr[endp->usb_addr].address;
732 down(&u132->scheduler_lock);
733 if (u132->going > 1) {
734 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
736 up(&u132->scheduler_lock);
737 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
739 } else if (endp->dequeueing) {
740 endp->dequeueing = 0;
741 up(&u132->scheduler_lock);
742 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
744 } else if (u132->going > 0) {
745 dev_err(&u132->platform_dev->dev, "device is being removed "
747 up(&u132->scheduler_lock);
748 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
750 } else if (!urb->unlinked) {
751 struct u132_ring *ring = endp->ring;
752 urb->actual_length += len;
753 endp->toggle_bits = toggle_bits;
754 if (urb->transfer_buffer_length > urb->actual_length) {
756 up(&u132->scheduler_lock);
757 retval = edset_output(u132, ring, endp, urb, address,
758 endp->toggle_bits, u132_hcd_bulk_output_sent);
761 u132_hcd_giveback_urb(u132, endp, urb, retval);
764 up(&u132->scheduler_lock);
765 u132_hcd_giveback_urb(u132, endp, urb, 0);
769 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
770 "unlinked=%d\n", urb, urb->unlinked);
771 up(&u132->scheduler_lock);
772 u132_hcd_giveback_urb(u132, endp, urb, 0);
777 static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
778 int len, int toggle_bits, int error_count, int condition_code,
779 int repeat_number, int halted, int skipped, int actual, int non_null)
781 struct u132_endp *endp = data;
782 struct u132 *u132 = endp->u132;
783 u8 address = u132->addr[endp->usb_addr].address;
784 struct u132_udev *udev = &u132->udev[address];
785 down(&u132->scheduler_lock);
786 if (u132->going > 1) {
787 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
789 up(&u132->scheduler_lock);
790 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
792 } else if (endp->dequeueing) {
793 endp->dequeueing = 0;
794 up(&u132->scheduler_lock);
795 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
797 } else if (u132->going > 0) {
798 dev_err(&u132->platform_dev->dev, "device is being removed "
800 up(&u132->scheduler_lock);
801 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
803 } else if (!urb->unlinked) {
804 struct u132_ring *ring = endp->ring;
805 u8 *u = urb->transfer_buffer + urb->actual_length;
811 urb->actual_length += len;
812 if ((condition_code == TD_CC_NOERROR) &&
813 (urb->transfer_buffer_length > urb->actual_length)) {
815 endp->toggle_bits = toggle_bits;
816 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
818 up(&u132->scheduler_lock);
819 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
820 ring->number, endp, urb, address,
821 endp->usb_endp, endp->toggle_bits,
822 u132_hcd_bulk_input_recv);
825 u132_hcd_giveback_urb(u132, endp, urb, retval);
827 } else if (condition_code == TD_CC_NOERROR) {
828 endp->toggle_bits = toggle_bits;
829 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
831 up(&u132->scheduler_lock);
832 u132_hcd_giveback_urb(u132, endp, urb,
833 cc_to_error[condition_code]);
835 } else if ((condition_code == TD_DATAUNDERRUN) &&
836 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
837 endp->toggle_bits = toggle_bits;
838 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
840 up(&u132->scheduler_lock);
841 u132_hcd_giveback_urb(u132, endp, urb, 0);
843 } else if (condition_code == TD_DATAUNDERRUN) {
844 endp->toggle_bits = toggle_bits;
845 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
847 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
848 ") giving back BULK IN %s\n", urb,
849 cc_to_text[condition_code]);
850 up(&u132->scheduler_lock);
851 u132_hcd_giveback_urb(u132, endp, urb, 0);
853 } else if (condition_code == TD_CC_STALL) {
854 endp->toggle_bits = 0x2;
855 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
856 up(&u132->scheduler_lock);
857 u132_hcd_giveback_urb(u132, endp, urb,
858 cc_to_error[condition_code]);
861 endp->toggle_bits = 0x2;
862 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
863 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
864 "ULK IN code=%d %s\n", urb, condition_code,
865 cc_to_text[condition_code]);
866 up(&u132->scheduler_lock);
867 u132_hcd_giveback_urb(u132, endp, urb,
868 cc_to_error[condition_code]);
872 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
873 "unlinked=%d\n", urb, urb->unlinked);
874 up(&u132->scheduler_lock);
875 u132_hcd_giveback_urb(u132, endp, urb, 0);
880 static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
881 int len, int toggle_bits, int error_count, int condition_code,
882 int repeat_number, int halted, int skipped, int actual, int non_null)
884 struct u132_endp *endp = data;
885 struct u132 *u132 = endp->u132;
886 down(&u132->scheduler_lock);
887 if (u132->going > 1) {
888 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
890 up(&u132->scheduler_lock);
891 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
893 } else if (endp->dequeueing) {
894 endp->dequeueing = 0;
895 up(&u132->scheduler_lock);
896 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
898 } else if (u132->going > 0) {
899 dev_err(&u132->platform_dev->dev, "device is being removed "
901 up(&u132->scheduler_lock);
902 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
904 } else if (!urb->unlinked) {
905 up(&u132->scheduler_lock);
906 u132_hcd_giveback_urb(u132, endp, urb, 0);
909 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
910 "unlinked=%d\n", urb, urb->unlinked);
911 up(&u132->scheduler_lock);
912 u132_hcd_giveback_urb(u132, endp, urb, 0);
917 static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
918 int len, int toggle_bits, int error_count, int condition_code,
919 int repeat_number, int halted, int skipped, int actual, int non_null)
921 struct u132_endp *endp = data;
922 struct u132 *u132 = endp->u132;
923 u8 address = u132->addr[endp->usb_addr].address;
924 down(&u132->scheduler_lock);
925 if (u132->going > 1) {
926 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
928 up(&u132->scheduler_lock);
929 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
931 } else if (endp->dequeueing) {
932 endp->dequeueing = 0;
933 up(&u132->scheduler_lock);
934 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
936 } else if (u132->going > 0) {
937 dev_err(&u132->platform_dev->dev, "device is being removed "
939 up(&u132->scheduler_lock);
940 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
942 } else if (!urb->unlinked) {
943 struct u132_ring *ring = endp->ring;
944 u8 *u = urb->transfer_buffer;
950 urb->actual_length = len;
951 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
952 TD_DATAUNDERRUN) && ((urb->transfer_flags &
953 URB_SHORT_NOT_OK) == 0))) {
955 up(&u132->scheduler_lock);
956 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
957 ring->number, endp, urb, address,
959 u132_hcd_configure_empty_sent);
962 u132_hcd_giveback_urb(u132, endp, urb, retval);
964 } else if (condition_code == TD_CC_STALL) {
965 up(&u132->scheduler_lock);
966 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
967 "NPUT STALL urb %p\n", urb);
968 u132_hcd_giveback_urb(u132, endp, urb,
969 cc_to_error[condition_code]);
972 up(&u132->scheduler_lock);
973 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
974 "PUT %s urb %p\n", cc_to_text[condition_code],
976 u132_hcd_giveback_urb(u132, endp, urb,
977 cc_to_error[condition_code]);
981 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
982 "unlinked=%d\n", urb, urb->unlinked);
983 up(&u132->scheduler_lock);
984 u132_hcd_giveback_urb(u132, endp, urb, 0);
989 static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
990 int len, int toggle_bits, int error_count, int condition_code,
991 int repeat_number, int halted, int skipped, int actual, int non_null)
993 struct u132_endp *endp = data;
994 struct u132 *u132 = endp->u132;
995 down(&u132->scheduler_lock);
996 if (u132->going > 1) {
997 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
999 up(&u132->scheduler_lock);
1000 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1002 } else if (endp->dequeueing) {
1003 endp->dequeueing = 0;
1004 up(&u132->scheduler_lock);
1005 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1007 } else if (u132->going > 0) {
1008 dev_err(&u132->platform_dev->dev, "device is being removed "
1010 up(&u132->scheduler_lock);
1011 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1013 } else if (!urb->unlinked) {
1014 up(&u132->scheduler_lock);
1015 u132_hcd_giveback_urb(u132, endp, urb, 0);
1018 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1019 "unlinked=%d\n", urb, urb->unlinked);
1020 up(&u132->scheduler_lock);
1021 u132_hcd_giveback_urb(u132, endp, urb, 0);
1026 static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1027 int len, int toggle_bits, int error_count, int condition_code,
1028 int repeat_number, int halted, int skipped, int actual, int non_null)
1030 struct u132_endp *endp = data;
1031 struct u132 *u132 = endp->u132;
1032 u8 address = u132->addr[endp->usb_addr].address;
1033 down(&u132->scheduler_lock);
1034 if (u132->going > 1) {
1035 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1037 up(&u132->scheduler_lock);
1038 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1040 } else if (endp->dequeueing) {
1041 endp->dequeueing = 0;
1042 up(&u132->scheduler_lock);
1043 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1045 } else if (u132->going > 0) {
1046 dev_err(&u132->platform_dev->dev, "device is being removed "
1048 up(&u132->scheduler_lock);
1049 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1051 } else if (!urb->unlinked) {
1052 if (usb_pipein(urb->pipe)) {
1054 struct u132_ring *ring = endp->ring;
1055 up(&u132->scheduler_lock);
1056 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1057 ring->number, endp, urb, address,
1059 u132_hcd_configure_input_recv);
1062 u132_hcd_giveback_urb(u132, endp, urb, retval);
1066 struct u132_ring *ring = endp->ring;
1067 up(&u132->scheduler_lock);
1068 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1069 ring->number, endp, urb, address,
1071 u132_hcd_configure_empty_recv);
1074 u132_hcd_giveback_urb(u132, endp, urb, retval);
1078 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1079 "unlinked=%d\n", urb, urb->unlinked);
1080 up(&u132->scheduler_lock);
1081 u132_hcd_giveback_urb(u132, endp, urb, 0);
1086 static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1087 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1088 int repeat_number, int halted, int skipped, int actual, int non_null)
1090 struct u132_endp *endp = data;
1091 struct u132 *u132 = endp->u132;
1092 u8 address = u132->addr[endp->usb_addr].address;
1093 struct u132_udev *udev = &u132->udev[address];
1094 down(&u132->scheduler_lock);
1095 if (u132->going > 1) {
1096 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1098 up(&u132->scheduler_lock);
1099 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1101 } else if (endp->dequeueing) {
1102 endp->dequeueing = 0;
1103 up(&u132->scheduler_lock);
1104 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1106 } else if (u132->going > 0) {
1107 dev_err(&u132->platform_dev->dev, "device is being removed "
1109 up(&u132->scheduler_lock);
1110 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1112 } else if (!urb->unlinked) {
1113 u132->addr[0].address = 0;
1114 endp->usb_addr = udev->usb_addr;
1115 up(&u132->scheduler_lock);
1116 u132_hcd_giveback_urb(u132, endp, urb, 0);
1119 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1120 "unlinked=%d\n", urb, urb->unlinked);
1121 up(&u132->scheduler_lock);
1122 u132_hcd_giveback_urb(u132, endp, urb, 0);
1127 static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1128 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1129 int repeat_number, int halted, int skipped, int actual, int non_null)
1131 struct u132_endp *endp = data;
1132 struct u132 *u132 = endp->u132;
1133 down(&u132->scheduler_lock);
1134 if (u132->going > 1) {
1135 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1137 up(&u132->scheduler_lock);
1138 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1140 } else if (endp->dequeueing) {
1141 endp->dequeueing = 0;
1142 up(&u132->scheduler_lock);
1143 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1145 } else if (u132->going > 0) {
1146 dev_err(&u132->platform_dev->dev, "device is being removed "
1148 up(&u132->scheduler_lock);
1149 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1151 } else if (!urb->unlinked) {
1153 struct u132_ring *ring = endp->ring;
1154 up(&u132->scheduler_lock);
1155 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1156 ring->number, endp, urb, 0, endp->usb_endp, 0,
1157 u132_hcd_enumeration_empty_recv);
1160 u132_hcd_giveback_urb(u132, endp, urb, retval);
1163 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1164 "unlinked=%d\n", urb, urb->unlinked);
1165 up(&u132->scheduler_lock);
1166 u132_hcd_giveback_urb(u132, endp, urb, 0);
1171 static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1172 int len, int toggle_bits, int error_count, int condition_code,
1173 int repeat_number, int halted, int skipped, int actual, int non_null)
1175 struct u132_endp *endp = data;
1176 struct u132 *u132 = endp->u132;
1177 down(&u132->scheduler_lock);
1178 if (u132->going > 1) {
1179 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1181 up(&u132->scheduler_lock);
1182 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1184 } else if (endp->dequeueing) {
1185 endp->dequeueing = 0;
1186 up(&u132->scheduler_lock);
1187 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1189 } else if (u132->going > 0) {
1190 dev_err(&u132->platform_dev->dev, "device is being removed "
1192 up(&u132->scheduler_lock);
1193 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1195 } else if (!urb->unlinked) {
1196 up(&u132->scheduler_lock);
1197 u132_hcd_giveback_urb(u132, endp, urb, 0);
1200 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1201 "unlinked=%d\n", urb, urb->unlinked);
1202 up(&u132->scheduler_lock);
1203 u132_hcd_giveback_urb(u132, endp, urb, 0);
1208 static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1209 int len, int toggle_bits, int error_count, int condition_code,
1210 int repeat_number, int halted, int skipped, int actual, int non_null)
1212 struct u132_endp *endp = data;
1213 struct u132 *u132 = endp->u132;
1214 u8 address = u132->addr[endp->usb_addr].address;
1215 down(&u132->scheduler_lock);
1216 if (u132->going > 1) {
1217 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1219 up(&u132->scheduler_lock);
1220 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1222 } else if (endp->dequeueing) {
1223 endp->dequeueing = 0;
1224 up(&u132->scheduler_lock);
1225 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1227 } else if (u132->going > 0) {
1228 dev_err(&u132->platform_dev->dev, "device is being removed "
1230 up(&u132->scheduler_lock);
1231 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1233 } else if (!urb->unlinked) {
1235 struct u132_ring *ring = endp->ring;
1236 u8 *u = urb->transfer_buffer;
1242 urb->actual_length = len;
1243 up(&u132->scheduler_lock);
1244 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1245 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1246 u132_hcd_initial_empty_sent);
1249 u132_hcd_giveback_urb(u132, endp, urb, retval);
1252 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1253 "unlinked=%d\n", urb, urb->unlinked);
1254 up(&u132->scheduler_lock);
1255 u132_hcd_giveback_urb(u132, endp, urb, 0);
1260 static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1261 int len, int toggle_bits, int error_count, int condition_code,
1262 int repeat_number, int halted, int skipped, int actual, int non_null)
1264 struct u132_endp *endp = data;
1265 struct u132 *u132 = endp->u132;
1266 u8 address = u132->addr[endp->usb_addr].address;
1267 down(&u132->scheduler_lock);
1268 if (u132->going > 1) {
1269 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1271 up(&u132->scheduler_lock);
1272 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1274 } else if (endp->dequeueing) {
1275 endp->dequeueing = 0;
1276 up(&u132->scheduler_lock);
1277 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1279 } else if (u132->going > 0) {
1280 dev_err(&u132->platform_dev->dev, "device is being removed "
1282 up(&u132->scheduler_lock);
1283 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1285 } else if (!urb->unlinked) {
1287 struct u132_ring *ring = endp->ring;
1288 up(&u132->scheduler_lock);
1289 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1290 ring->number, endp, urb, address, endp->usb_endp, 0,
1291 u132_hcd_initial_input_recv);
1294 u132_hcd_giveback_urb(u132, endp, urb, retval);
1297 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1298 "unlinked=%d\n", urb, urb->unlinked);
1299 up(&u132->scheduler_lock);
1300 u132_hcd_giveback_urb(u132, endp, urb, 0);
1306 * this work function is only executed from the work queue
1309 static void u132_hcd_ring_work_scheduler(struct work_struct *work)
1311 struct u132_ring *ring =
1312 container_of(work, struct u132_ring, scheduler.work);
1313 struct u132 *u132 = ring->u132;
1314 down(&u132->scheduler_lock);
1316 up(&u132->scheduler_lock);
1317 u132_ring_put_kref(u132, ring);
1319 } else if (ring->curr_endp) {
1320 struct u132_endp *last_endp = ring->curr_endp;
1321 struct list_head *scan;
1322 struct list_head *head = &last_endp->endp_ring;
1323 unsigned long wakeup = 0;
1324 list_for_each(scan, head) {
1325 struct u132_endp *endp = list_entry(scan,
1326 struct u132_endp, endp_ring);
1327 if (endp->queue_next == endp->queue_last) {
1328 } else if ((endp->delayed == 0)
1329 || time_after_eq(jiffies, endp->jiffies)) {
1330 ring->curr_endp = endp;
1331 u132_endp_cancel_work(u132, last_endp);
1332 u132_endp_queue_work(u132, last_endp, 0);
1333 up(&u132->scheduler_lock);
1334 u132_ring_put_kref(u132, ring);
1337 unsigned long delta = endp->jiffies - jiffies;
1342 if (last_endp->queue_next == last_endp->queue_last) {
1343 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1344 last_endp->jiffies)) {
1345 u132_endp_cancel_work(u132, last_endp);
1346 u132_endp_queue_work(u132, last_endp, 0);
1347 up(&u132->scheduler_lock);
1348 u132_ring_put_kref(u132, ring);
1351 unsigned long delta = last_endp->jiffies - jiffies;
1356 u132_ring_requeue_work(u132, ring, wakeup);
1357 up(&u132->scheduler_lock);
1360 up(&u132->scheduler_lock);
1361 u132_ring_put_kref(u132, ring);
1365 up(&u132->scheduler_lock);
1366 u132_ring_put_kref(u132, ring);
1371 static void u132_hcd_endp_work_scheduler(struct work_struct *work)
1373 struct u132_ring *ring;
1374 struct u132_endp *endp =
1375 container_of(work, struct u132_endp, scheduler.work);
1376 struct u132 *u132 = endp->u132;
1377 down(&u132->scheduler_lock);
1379 if (endp->edset_flush) {
1380 endp->edset_flush = 0;
1381 if (endp->dequeueing)
1382 usb_ftdi_elan_edset_flush(u132->platform_dev,
1383 ring->number, endp);
1384 up(&u132->scheduler_lock);
1385 u132_endp_put_kref(u132, endp);
1387 } else if (endp->active) {
1388 up(&u132->scheduler_lock);
1389 u132_endp_put_kref(u132, endp);
1391 } else if (ring->in_use) {
1392 up(&u132->scheduler_lock);
1393 u132_endp_put_kref(u132, endp);
1395 } else if (endp->queue_next == endp->queue_last) {
1396 up(&u132->scheduler_lock);
1397 u132_endp_put_kref(u132, endp);
1399 } else if (endp->pipetype == PIPE_INTERRUPT) {
1400 u8 address = u132->addr[endp->usb_addr].address;
1402 up(&u132->scheduler_lock);
1403 u132_endp_put_kref(u132, endp);
1407 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1410 ring->curr_endp = endp;
1412 up(&u132->scheduler_lock);
1413 retval = edset_single(u132, ring, endp, urb, address,
1414 endp->toggle_bits, u132_hcd_interrupt_recv);
1417 u132_hcd_giveback_urb(u132, endp, urb, retval);
1420 } else if (endp->pipetype == PIPE_CONTROL) {
1421 u8 address = u132->addr[endp->usb_addr].address;
1423 up(&u132->scheduler_lock);
1424 u132_endp_put_kref(u132, endp);
1426 } else if (address == 0) {
1428 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1431 ring->curr_endp = endp;
1433 up(&u132->scheduler_lock);
1434 retval = edset_setup(u132, ring, endp, urb, address,
1435 0x2, u132_hcd_initial_setup_sent);
1438 u132_hcd_giveback_urb(u132, endp, urb, retval);
1440 } else if (endp->usb_addr == 0) {
1442 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1445 ring->curr_endp = endp;
1447 up(&u132->scheduler_lock);
1448 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1449 u132_hcd_enumeration_address_sent);
1452 u132_hcd_giveback_urb(u132, endp, urb, retval);
1456 u8 address = u132->addr[endp->usb_addr].address;
1457 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1460 ring->curr_endp = endp;
1462 up(&u132->scheduler_lock);
1463 retval = edset_setup(u132, ring, endp, urb, address,
1464 0x2, u132_hcd_configure_setup_sent);
1467 u132_hcd_giveback_urb(u132, endp, urb, retval);
1472 u8 address = u132->addr[endp->usb_addr].address;
1474 up(&u132->scheduler_lock);
1475 u132_endp_put_kref(u132, endp);
1479 struct urb *urb = endp->urb_list[
1480 ENDP_QUEUE_MASK & endp->queue_next];
1482 ring->curr_endp = endp;
1484 up(&u132->scheduler_lock);
1485 retval = edset_input(u132, ring, endp, urb,
1486 address, endp->toggle_bits,
1487 u132_hcd_bulk_input_recv);
1490 u132_hcd_giveback_urb(u132, endp, urb,
1494 } else { /* output pipe */
1495 u8 address = u132->addr[endp->usb_addr].address;
1497 up(&u132->scheduler_lock);
1498 u132_endp_put_kref(u132, endp);
1502 struct urb *urb = endp->urb_list[
1503 ENDP_QUEUE_MASK & endp->queue_next];
1505 ring->curr_endp = endp;
1507 up(&u132->scheduler_lock);
1508 retval = edset_output(u132, ring, endp, urb,
1509 address, endp->toggle_bits,
1510 u132_hcd_bulk_output_sent);
1513 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;
1529 static void u132_power(struct u132 *u132, int is_on)
1531 struct usb_hcd *hcd = u132_to_hcd(u132)
1532 ; /* hub is inactive unless the port is powered */
1539 hcd->state = HC_STATE_HALT;
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 mutex_lock(&u132->sw_lock);
1805 u132_power(u132, 0);
1806 mutex_unlock(&u132->sw_lock);
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 mutex_lock(&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);
1843 mutex_unlock(&u132->sw_lock);
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 mutex_lock(&u132->sw_lock);
1864 retval = u132_init(u132);
1869 mutex_unlock(&u132->sw_lock);
1874 static int create_endpoint_and_queue_int(struct u132 *u132,
1875 struct u132_udev *udev, struct urb *urb,
1876 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1879 struct u132_ring *ring;
1883 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1889 spin_lock_init(&endp->queue_lock.slock);
1890 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1891 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1893 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1898 endp_number = ++u132->num_endpoints;
1899 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1900 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1901 INIT_LIST_HEAD(&endp->urb_more);
1902 ring = endp->ring = &u132->ring[0];
1903 if (ring->curr_endp) {
1904 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1906 INIT_LIST_HEAD(&endp->endp_ring);
1907 ring->curr_endp = endp;
1910 endp->dequeueing = 0;
1911 endp->edset_flush = 0;
1914 endp->endp_number = endp_number;
1916 endp->hep = urb->ep;
1917 endp->pipetype = usb_pipetype(urb->pipe);
1918 u132_endp_init_kref(u132, endp);
1919 if (usb_pipein(urb->pipe)) {
1920 endp->toggle_bits = 0x2;
1921 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1924 udev->endp_number_in[usb_endp] = endp_number;
1925 u132_udev_get_kref(u132, udev);
1927 endp->toggle_bits = 0x2;
1928 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1931 udev->endp_number_out[usb_endp] = endp_number;
1932 u132_udev_get_kref(u132, udev);
1936 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1937 endp->udev_number = address;
1938 endp->usb_addr = usb_addr;
1939 endp->usb_endp = usb_endp;
1940 endp->queue_size = 1;
1941 endp->queue_last = 0;
1942 endp->queue_next = 0;
1943 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1944 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1945 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1949 static int queue_int_on_old_endpoint(struct u132 *u132,
1950 struct u132_udev *udev, struct urb *urb,
1951 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1952 u8 usb_endp, u8 address)
1956 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1957 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1958 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1960 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1963 endp->queue_size -= 1;
1966 list_add_tail(&urbq->urb_more, &endp->urb_more);
1973 static int create_endpoint_and_queue_bulk(struct u132 *u132,
1974 struct u132_udev *udev, struct urb *urb,
1975 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1979 struct u132_ring *ring;
1983 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1989 spin_lock_init(&endp->queue_lock.slock);
1990 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1991 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1993 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1998 endp_number = ++u132->num_endpoints;
1999 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2000 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2001 INIT_LIST_HEAD(&endp->urb_more);
2002 endp->dequeueing = 0;
2003 endp->edset_flush = 0;
2006 endp->endp_number = endp_number;
2008 endp->hep = urb->ep;
2009 endp->pipetype = usb_pipetype(urb->pipe);
2010 u132_endp_init_kref(u132, endp);
2011 if (usb_pipein(urb->pipe)) {
2012 endp->toggle_bits = 0x2;
2013 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
2017 udev->endp_number_in[usb_endp] = endp_number;
2018 u132_udev_get_kref(u132, udev);
2020 endp->toggle_bits = 0x2;
2021 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2025 udev->endp_number_out[usb_endp] = endp_number;
2026 u132_udev_get_kref(u132, udev);
2028 ring = endp->ring = &u132->ring[ring_number - 1];
2029 if (ring->curr_endp) {
2030 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2032 INIT_LIST_HEAD(&endp->endp_ring);
2033 ring->curr_endp = endp;
2037 endp->udev_number = address;
2038 endp->usb_addr = usb_addr;
2039 endp->usb_endp = usb_endp;
2040 endp->queue_size = 1;
2041 endp->queue_last = 0;
2042 endp->queue_next = 0;
2043 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2044 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2045 u132_endp_queue_work(u132, endp, 0);
2049 static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2051 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2052 u8 usb_endp, u8 address)
2055 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2056 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2058 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2061 endp->queue_size -= 1;
2064 list_add_tail(&urbq->urb_more, &endp->urb_more);
2071 static int create_endpoint_and_queue_control(struct u132 *u132,
2073 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2076 struct u132_ring *ring;
2080 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
2086 spin_lock_init(&endp->queue_lock.slock);
2087 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2088 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
2090 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2095 endp_number = ++u132->num_endpoints;
2096 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2097 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2098 INIT_LIST_HEAD(&endp->urb_more);
2099 ring = endp->ring = &u132->ring[0];
2100 if (ring->curr_endp) {
2101 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2103 INIT_LIST_HEAD(&endp->endp_ring);
2104 ring->curr_endp = endp;
2107 endp->dequeueing = 0;
2108 endp->edset_flush = 0;
2111 endp->endp_number = endp_number;
2113 endp->hep = urb->ep;
2114 u132_endp_init_kref(u132, endp);
2115 u132_endp_get_kref(u132, endp);
2116 if (usb_addr == 0) {
2117 u8 address = u132->addr[usb_addr].address;
2118 struct u132_udev *udev = &u132->udev[address];
2119 endp->udev_number = address;
2120 endp->usb_addr = usb_addr;
2121 endp->usb_endp = usb_endp;
2124 endp->pipetype = usb_pipetype(urb->pipe);
2125 u132_udev_init_kref(u132, udev);
2126 u132_udev_get_kref(u132, udev);
2127 udev->endp_number_in[usb_endp] = endp_number;
2128 udev->endp_number_out[usb_endp] = endp_number;
2130 endp->queue_size = 1;
2131 endp->queue_last = 0;
2132 endp->queue_next = 0;
2133 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2134 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2135 u132_endp_queue_work(u132, endp, 0);
2137 } else { /*(usb_addr > 0) */
2138 u8 address = u132->addr[usb_addr].address;
2139 struct u132_udev *udev = &u132->udev[address];
2140 endp->udev_number = address;
2141 endp->usb_addr = usb_addr;
2142 endp->usb_endp = usb_endp;
2145 endp->pipetype = usb_pipetype(urb->pipe);
2146 u132_udev_get_kref(u132, udev);
2147 udev->enumeration = 2;
2148 udev->endp_number_in[usb_endp] = endp_number;
2149 udev->endp_number_out[usb_endp] = endp_number;
2151 endp->queue_size = 1;
2152 endp->queue_last = 0;
2153 endp->queue_next = 0;
2154 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2155 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2156 u132_endp_queue_work(u132, endp, 0);
2161 static int queue_control_on_old_endpoint(struct u132 *u132,
2163 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2166 if (usb_addr == 0) {
2167 if (usb_pipein(urb->pipe)) {
2169 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2170 endp->urb_list[ENDP_QUEUE_MASK &
2171 endp->queue_last++] = urb;
2173 struct u132_urbq *urbq =
2174 kmalloc(sizeof(struct u132_urbq),
2177 endp->queue_size -= 1;
2180 list_add_tail(&urbq->urb_more,
2186 } else { /* usb_pipeout(urb->pipe) */
2187 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2188 int I = MAX_U132_UDEVS;
2191 struct u132_udev *udev = &u132->udev[++i];
2192 if (udev->usb_device) {
2195 udev->enumeration = 1;
2196 u132->addr[0].address = i;
2197 endp->udev_number = i;
2198 udev->udev_number = i;
2199 udev->usb_addr = usb_dev->devnum;
2200 u132_udev_init_kref(u132, udev);
2201 udev->endp_number_in[usb_endp] =
2203 u132_udev_get_kref(u132, udev);
2204 udev->endp_number_out[usb_endp] =
2206 udev->usb_device = usb_dev;
2207 ((u8 *) (urb->setup_packet))[2] =
2209 u132_udev_get_kref(u132, udev);
2214 dev_err(&u132->platform_dev->dev, "run out of d"
2219 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2220 endp->urb_list[ENDP_QUEUE_MASK &
2221 endp->queue_last++] = urb;
2223 struct u132_urbq *urbq =
2224 kmalloc(sizeof(struct u132_urbq),
2227 endp->queue_size -= 1;
2230 list_add_tail(&urbq->urb_more,
2237 } else { /*(usb_addr > 0) */
2238 u8 address = u132->addr[usb_addr].address;
2239 struct u132_udev *udev = &u132->udev[address];
2241 if (udev->enumeration == 2) {
2243 udev->enumeration = 2;
2244 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2245 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2248 struct u132_urbq *urbq =
2249 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2251 endp->queue_size -= 1;
2254 list_add_tail(&urbq->urb_more, &endp->urb_more);
2262 static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2265 struct u132 *u132 = hcd_to_u132(hcd);
2266 if (irqs_disabled()) {
2267 if (__GFP_WAIT & mem_flags) {
2268 printk(KERN_ERR "invalid context for function that migh"
2273 if (u132->going > 1) {
2274 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2277 } else if (u132->going > 0) {
2278 dev_err(&u132->platform_dev->dev, "device is being removed "
2282 u8 usb_addr = usb_pipedevice(urb->pipe);
2283 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2284 struct usb_device *usb_dev = urb->dev;
2285 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2286 u8 address = u132->addr[usb_addr].address;
2287 struct u132_udev *udev = &u132->udev[address];
2288 struct u132_endp *endp = urb->ep->hcpriv;
2289 urb->actual_length = 0;
2293 spin_lock_irqsave(&endp->queue_lock.slock,
2295 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2297 retval = queue_int_on_old_endpoint(
2303 usb_hcd_unlink_urb_from_ep(
2306 spin_unlock_irqrestore(&endp->queue_lock.slock,
2311 u132_endp_queue_work(u132, endp,
2312 msecs_to_jiffies(urb->interval))
2316 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2318 } else { /*(endp == NULL) */
2319 return create_endpoint_and_queue_int(u132, udev,
2320 urb, usb_dev, usb_addr,
2321 usb_endp, address, mem_flags);
2323 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2324 dev_err(&u132->platform_dev->dev, "the hardware does no"
2325 "t support PIPE_ISOCHRONOUS\n");
2327 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2328 u8 address = u132->addr[usb_addr].address;
2329 struct u132_udev *udev = &u132->udev[address];
2330 struct u132_endp *endp = urb->ep->hcpriv;
2331 urb->actual_length = 0;
2335 spin_lock_irqsave(&endp->queue_lock.slock,
2337 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2339 retval = queue_bulk_on_old_endpoint(
2345 usb_hcd_unlink_urb_from_ep(
2348 spin_unlock_irqrestore(&endp->queue_lock.slock,
2353 u132_endp_queue_work(u132, endp, 0);
2356 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2359 return create_endpoint_and_queue_bulk(u132,
2360 udev, urb, usb_dev, usb_addr,
2361 usb_endp, address, mem_flags);
2363 struct u132_endp *endp = urb->ep->hcpriv;
2365 u8 *b = urb->setup_packet;
2367 char data[30 *3 + 4];
2369 int m = (sizeof(data) - 1) / 3;
2372 while (urb_size-- > 0) {
2374 } else if (i++ < m) {
2375 int w = sprintf(d, " %02X", *b++);
2379 d += sprintf(d, " ..");
2384 spin_lock_irqsave(&endp->queue_lock.slock,
2386 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2388 retval = queue_control_on_old_endpoint(
2393 usb_hcd_unlink_urb_from_ep(
2396 spin_unlock_irqrestore(&endp->queue_lock.slock,
2401 u132_endp_queue_work(u132, endp, 0);
2404 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2407 return create_endpoint_and_queue_control(u132,
2408 urb, usb_dev, usb_addr, usb_endp,
2414 static int dequeue_from_overflow_chain(struct u132 *u132,
2415 struct u132_endp *endp, struct urb *urb)
2417 struct list_head *scan;
2418 struct list_head *head = &endp->urb_more;
2419 list_for_each(scan, head) {
2420 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2422 if (urbq->urb == urb) {
2423 struct usb_hcd *hcd = u132_to_hcd(u132);
2425 endp->queue_size -= 1;
2426 urb->error_count = 0;
2427 usb_hcd_giveback_urb(hcd, urb, 0);
2432 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2433 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2434 "\n", urb, endp->endp_number, endp, endp->ring->number,
2435 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2436 endp->usb_endp, endp->usb_addr, endp->queue_size,
2437 endp->queue_next, endp->queue_last);
2441 static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2442 struct urb *urb, int status)
2447 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2448 rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status);
2450 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2453 if (endp->queue_size == 0) {
2454 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2455 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2456 endp->endp_number, endp, endp->ring->number,
2457 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2458 endp->usb_endp, endp->usb_addr);
2459 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2462 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2464 endp->dequeueing = 1;
2465 endp->edset_flush = 1;
2466 u132_endp_queue_work(u132, endp, 0);
2467 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2470 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2471 u132_hcd_abandon_urb(u132, endp, urb, status);
2476 u16 queue_size = endp->queue_size;
2477 u16 queue_scan = endp->queue_next;
2478 struct urb **urb_slot = NULL;
2479 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2480 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2482 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2488 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2489 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2491 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2495 struct usb_hcd *hcd = u132_to_hcd(u132);
2497 usb_hcd_unlink_urb_from_ep(hcd, urb);
2498 endp->queue_size -= 1;
2499 if (list_empty(&endp->urb_more)) {
2500 spin_unlock_irqrestore(&endp->queue_lock.slock,
2503 struct list_head *next = endp->urb_more.next;
2504 struct u132_urbq *urbq = list_entry(next,
2505 struct u132_urbq, urb_more);
2507 *urb_slot = urbq->urb;
2508 spin_unlock_irqrestore(&endp->queue_lock.slock,
2511 } urb->error_count = 0;
2512 usb_hcd_giveback_urb(hcd, urb, status);
2514 } else if (list_empty(&endp->urb_more)) {
2515 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2516 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2517 "=%d size=%d next=%04X last=%04X\n", urb,
2518 endp->endp_number, endp, endp->ring->number,
2519 endp->input ? 'I' : ' ',
2520 endp->output ? 'O' : ' ', endp->usb_endp,
2521 endp->usb_addr, endp->queue_size,
2522 endp->queue_next, endp->queue_last);
2523 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2528 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb);
2529 retval = dequeue_from_overflow_chain(u132, endp,
2531 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2537 static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2539 struct u132 *u132 = hcd_to_u132(hcd);
2540 if (u132->going > 2) {
2541 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2545 u8 usb_addr = usb_pipedevice(urb->pipe);
2546 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2547 u8 address = u132->addr[usb_addr].address;
2548 struct u132_udev *udev = &u132->udev[address];
2549 if (usb_pipein(urb->pipe)) {
2550 u8 endp_number = udev->endp_number_in[usb_endp];
2551 struct u132_endp *endp = u132->endp[endp_number - 1];
2552 return u132_endp_urb_dequeue(u132, endp, urb, status);
2554 u8 endp_number = udev->endp_number_out[usb_endp];
2555 struct u132_endp *endp = u132->endp[endp_number - 1];
2556 return u132_endp_urb_dequeue(u132, endp, urb, status);
2561 static void u132_endpoint_disable(struct usb_hcd *hcd,
2562 struct usb_host_endpoint *hep)
2564 struct u132 *u132 = hcd_to_u132(hcd);
2565 if (u132->going > 2) {
2566 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2567 ") has been removed %d\n", u132, hcd, hep,
2570 struct u132_endp *endp = hep->hcpriv;
2572 u132_endp_put_kref(u132, endp);
2576 static int u132_get_frame(struct usb_hcd *hcd)
2578 struct u132 *u132 = hcd_to_u132(hcd);
2579 if (u132->going > 1) {
2580 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2583 } else if (u132->going > 0) {
2584 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2588 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2594 static int u132_roothub_descriptor(struct u132 *u132,
2595 struct usb_hub_descriptor *desc)
2601 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2604 desc->bDescriptorType = 0x29;
2605 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2606 desc->bHubContrCurrent = 0;
2607 desc->bNbrPorts = u132->num_ports;
2608 temp = 1 + (u132->num_ports / 8);
2609 desc->bDescLength = 7 + 2 *temp;
2611 if (rh_a & RH_A_NPS)
2613 if (rh_a & RH_A_PSM)
2615 if (rh_a & RH_A_NOCP) {
2617 } else if (rh_a & RH_A_OCPM)
2619 desc->wHubCharacteristics = cpu_to_le16(temp);
2620 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2623 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2624 desc->bitmap[0] = rh_b & RH_B_DR;
2625 if (u132->num_ports > 7) {
2626 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2627 desc->bitmap[2] = 0xff;
2629 desc->bitmap[1] = 0xff;
2633 static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2636 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2637 *desc = cpu_to_le32(rh_status);
2641 static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2643 if (wIndex == 0 || wIndex > u132->num_ports) {
2646 int port = wIndex - 1;
2647 u32 rh_portstatus = -1;
2648 int ret_portstatus = u132_read_pcimem(u132,
2649 roothub.portstatus[port], &rh_portstatus);
2650 *desc = cpu_to_le32(rh_portstatus);
2651 if (*(u16 *) (desc + 2)) {
2652 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2653 "ge = %08X\n", port, *desc);
2655 return ret_portstatus;
2660 /* this timer value might be vendor-specific ... */
2661 #define PORT_RESET_HW_MSEC 10
2662 #define PORT_RESET_MSEC 10
2663 /* wrap-aware logic morphed from <linux/jiffies.h> */
2664 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2665 static int u132_roothub_portreset(struct u132 *u132, int port_index)
2671 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2675 reset_done = now + PORT_RESET_MSEC;
2679 retval = u132_read_pcimem(u132,
2680 roothub.portstatus[port_index], &portstat);
2683 if (RH_PS_PRS & portstat) {
2687 } while (tick_before(now, reset_done));
2688 if (RH_PS_PRS & portstat)
2690 if (RH_PS_CCS & portstat) {
2691 if (RH_PS_PRSC & portstat) {
2692 retval = u132_write_pcimem(u132,
2693 roothub.portstatus[port_index],
2699 break; /* start the next reset,
2700 sleep till it's probably done */
2701 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2705 msleep(PORT_RESET_HW_MSEC);
2706 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2710 } while (tick_before(now, reset_done));
2714 static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2717 if (wIndex == 0 || wIndex > u132->num_ports) {
2721 int port_index = wIndex - 1;
2722 struct u132_port *port = &u132->port[port_index];
2723 port->Status &= ~(1 << wValue);
2725 case USB_PORT_FEAT_SUSPEND:
2726 retval = u132_write_pcimem(u132,
2727 roothub.portstatus[port_index], RH_PS_PSS);
2731 case USB_PORT_FEAT_POWER:
2732 retval = u132_write_pcimem(u132,
2733 roothub.portstatus[port_index], RH_PS_PPS);
2737 case USB_PORT_FEAT_RESET:
2738 retval = u132_roothub_portreset(u132, port_index);
2748 static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2751 if (wIndex == 0 || wIndex > u132->num_ports) {
2754 int port_index = wIndex - 1;
2757 struct u132_port *port = &u132->port[port_index];
2758 port->Status &= ~(1 << wValue);
2760 case USB_PORT_FEAT_ENABLE:
2763 case USB_PORT_FEAT_C_ENABLE:
2766 case USB_PORT_FEAT_SUSPEND:
2768 if ((u132->hc_control & OHCI_CTRL_HCFS)
2770 dev_err(&u132->platform_dev->dev, "TODO resume_"
2774 case USB_PORT_FEAT_C_SUSPEND:
2777 case USB_PORT_FEAT_POWER:
2780 case USB_PORT_FEAT_C_CONNECTION:
2783 case USB_PORT_FEAT_C_OVER_CURRENT:
2786 case USB_PORT_FEAT_C_RESET:
2792 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2801 /* the virtual root hub timer IRQ checks for hub status*/
2802 static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2804 struct u132 *u132 = hcd_to_u132(hcd);
2805 if (u132->going > 1) {
2806 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2807 "ed %d\n", hcd, u132->going);
2809 } else if (u132->going > 0) {
2810 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2814 int i, changed = 0, length = 1;
2815 if (u132->flags & OHCI_QUIRK_AMD756) {
2816 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2817 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2818 "ereads as NDP=%d\n",
2819 u132->hc_roothub_a & RH_A_NDP);
2823 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) {
2824 buf[0] = changed = 1;
2827 if (u132->num_ports > 7) {
2831 for (i = 0; i < u132->num_ports; i++) {
2832 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2833 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2837 buf[0] |= 1 << (i + 1);
2839 buf[1] |= 1 << (i - 7);
2842 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) {
2845 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) {
2849 done:return changed ? length : 0;
2853 static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2854 u16 wIndex, char *buf, u16 wLength)
2856 struct u132 *u132 = hcd_to_u132(hcd);
2857 if (u132->going > 1) {
2858 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2861 } else if (u132->going > 0) {
2862 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2866 mutex_lock(&u132->sw_lock);
2868 case ClearHubFeature:
2870 case C_HUB_OVER_CURRENT:
2871 case C_HUB_LOCAL_POWER:
2879 case C_HUB_OVER_CURRENT:
2880 case C_HUB_LOCAL_POWER:
2886 case ClearPortFeature:{
2887 retval = u132_roothub_clearportfeature(u132,
2893 case GetHubDescriptor:{
2894 retval = u132_roothub_descriptor(u132,
2895 (struct usb_hub_descriptor *)buf);
2901 retval = u132_roothub_status(u132,
2907 case GetPortStatus:{
2908 retval = u132_roothub_portstatus(u132,
2909 (__le32 *) buf, wIndex);
2914 case SetPortFeature:{
2915 retval = u132_roothub_setportfeature(u132,
2923 error:u132_disable(u132);
2926 stall:retval = -EPIPE;
2929 mutex_unlock(&u132->sw_lock);
2934 static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2936 struct u132 *u132 = hcd_to_u132(hcd);
2937 if (u132->going > 1) {
2938 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2941 } else if (u132->going > 0) {
2942 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2948 static void u132_hub_irq_enable(struct usb_hcd *hcd)
2950 struct u132 *u132 = hcd_to_u132(hcd);
2951 if (u132->going > 1) {
2952 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2954 } else if (u132->going > 0)
2955 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2960 static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2962 struct u132 *u132 = hcd_to_u132(hcd);
2963 if (u132->going > 1) {
2964 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2967 } else if (u132->going > 0) {
2968 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2974 static int u132_hcd_resume(struct usb_hcd *hcd)
2976 struct u132 *u132 = hcd_to_u132(hcd);
2977 if (u132->going > 1) {
2978 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2981 } else if (u132->going > 0) {
2982 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2988 static int u132_bus_suspend(struct usb_hcd *hcd)
2990 struct u132 *u132 = hcd_to_u132(hcd);
2991 if (u132->going > 1) {
2992 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2995 } else if (u132->going > 0) {
2996 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3002 static int u132_bus_resume(struct usb_hcd *hcd)
3004 struct u132 *u132 = hcd_to_u132(hcd);
3005 if (u132->going > 1) {
3006 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3009 } else if (u132->going > 0) {
3010 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3017 #define u132_hcd_suspend NULL
3018 #define u132_hcd_resume NULL
3019 #define u132_bus_suspend NULL
3020 #define u132_bus_resume NULL
3022 static struct hc_driver u132_hc_driver = {
3023 .description = hcd_name,
3024 .hcd_priv_size = sizeof(struct u132),
3026 .flags = HCD_USB11 | HCD_MEMORY,
3027 .reset = u132_hcd_reset,
3028 .start = u132_hcd_start,
3029 .suspend = u132_hcd_suspend,
3030 .resume = u132_hcd_resume,
3031 .stop = u132_hcd_stop,
3032 .urb_enqueue = u132_urb_enqueue,
3033 .urb_dequeue = u132_urb_dequeue,
3034 .endpoint_disable = u132_endpoint_disable,
3035 .get_frame_number = u132_get_frame,
3036 .hub_status_data = u132_hub_status_data,
3037 .hub_control = u132_hub_control,
3038 .bus_suspend = u132_bus_suspend,
3039 .bus_resume = u132_bus_resume,
3040 .start_port_reset = u132_start_port_reset,
3041 .hub_irq_enable = u132_hub_irq_enable,
3045 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
3046 * is held for writing, thus this module must not call usb_remove_hcd()
3047 * synchronously - but instead should immediately stop activity to the
3048 * device and asynchronously call usb_remove_hcd()
3050 static int __devexit u132_remove(struct platform_device *pdev)
3052 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3054 struct u132 *u132 = hcd_to_u132(hcd);
3055 if (u132->going++ > 1) {
3056 dev_err(&u132->platform_dev->dev, "already being remove"
3060 int rings = MAX_U132_RINGS;
3061 int endps = MAX_U132_ENDPS;
3062 dev_err(&u132->platform_dev->dev, "removing device u132"
3063 ".%d\n", u132->sequence_num);
3065 mutex_lock(&u132->sw_lock);
3066 u132_monitor_cancel_work(u132);
3067 while (rings-- > 0) {
3068 struct u132_ring *ring = &u132->ring[rings];
3069 u132_ring_cancel_work(u132, ring);
3070 } while (endps-- > 0) {
3071 struct u132_endp *endp = u132->endp[endps];
3073 u132_endp_cancel_work(u132, endp);
3076 printk(KERN_INFO "removing device u132.%d\n",
3077 u132->sequence_num);
3078 mutex_unlock(&u132->sw_lock);
3079 usb_remove_hcd(hcd);
3080 u132_u132_put_kref(u132);
3087 static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3089 int rings = MAX_U132_RINGS;
3090 int ports = MAX_U132_PORTS;
3091 int addrs = MAX_U132_ADDRS;
3092 int udevs = MAX_U132_UDEVS;
3093 int endps = MAX_U132_ENDPS;
3094 u132->board = pdev->dev.platform_data;
3095 u132->platform_dev = pdev;
3098 mutex_init(&u132->sw_lock);
3099 init_MUTEX(&u132->scheduler_lock);
3100 while (rings-- > 0) {
3101 struct u132_ring *ring = &u132->ring[rings];
3103 ring->number = rings + 1;
3105 ring->curr_endp = NULL;
3106 INIT_DELAYED_WORK(&ring->scheduler,
3107 u132_hcd_ring_work_scheduler);
3108 } mutex_lock(&u132->sw_lock);
3109 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3110 while (ports-- > 0) {
3111 struct u132_port *port = &u132->port[ports];
3117 } while (addrs-- > 0) {
3118 struct u132_addr *addr = &u132->addr[addrs];
3120 } while (udevs-- > 0) {
3121 struct u132_udev *udev = &u132->udev[udevs];
3122 int i = ARRAY_SIZE(udev->endp_number_in);
3123 int o = ARRAY_SIZE(udev->endp_number_out);
3124 udev->usb_device = NULL;
3125 udev->udev_number = 0;
3127 udev->portnumber = 0;
3129 udev->endp_number_in[i] = 0;
3132 udev->endp_number_out[o] = 0;
3135 while (endps-- > 0) {
3136 u132->endp[endps] = NULL;
3138 mutex_unlock(&u132->sw_lock);
3142 static int __devinit u132_probe(struct platform_device *pdev)
3144 struct usb_hcd *hcd;
3150 if (u132_exiting > 0) {
3153 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3156 retval = ftdi_read_pcimem(pdev, control, &control);
3159 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3162 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3163 if (pdev->dev.dma_mask) {
3166 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3168 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3170 ftdi_elan_gone_away(pdev);
3174 struct u132 *u132 = hcd_to_u132(hcd);
3175 hcd->rsrc_start = 0;
3176 mutex_lock(&u132_module_lock);
3177 list_add_tail(&u132->u132_list, &u132_static_list);
3178 u132->sequence_num = ++u132_instances;
3179 mutex_unlock(&u132_module_lock);
3180 u132_u132_init_kref(u132);
3181 u132_initialise(u132, pdev);
3182 hcd->product_desc = "ELAN U132 Host Controller";
3183 retval = usb_add_hcd(hcd, 0, 0);
3185 dev_err(&u132->platform_dev->dev, "init error %d\n",
3187 u132_u132_put_kref(u132);
3190 u132_monitor_queue_work(u132, 100);
3198 /* for this device there's no useful distinction between the controller
3199 * and its root hub, except that the root hub only gets direct PM calls
3200 * when CONFIG_USB_SUSPEND is enabled.
3202 static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3204 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3205 struct u132 *u132 = hcd_to_u132(hcd);
3206 if (u132->going > 1) {
3207 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3210 } else if (u132->going > 0) {
3211 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3214 int retval = 0, ports;
3216 switch (state.event) {
3217 case PM_EVENT_FREEZE:
3218 retval = u132_bus_suspend(hcd);
3220 case PM_EVENT_SUSPEND:
3221 case PM_EVENT_HIBERNATE:
3222 ports = MAX_U132_PORTS;
3223 while (ports-- > 0) {
3224 port_power(u132, ports, 0);
3232 static int u132_resume(struct platform_device *pdev)
3234 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3235 struct u132 *u132 = hcd_to_u132(hcd);
3236 if (u132->going > 1) {
3237 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3240 } else if (u132->going > 0) {
3241 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3245 if (!u132->port[0].power) {
3246 int ports = MAX_U132_PORTS;
3247 while (ports-- > 0) {
3248 port_power(u132, ports, 1);
3252 retval = u132_bus_resume(hcd);
3259 #define u132_suspend NULL
3260 #define u132_resume NULL
3263 * this driver is loaded explicitly by ftdi_u132
3265 * the platform_driver struct is static because it is per type of module
3267 static struct platform_driver u132_platform_driver = {
3268 .probe = u132_probe,
3269 .remove = __devexit_p(u132_remove),
3270 .suspend = u132_suspend,
3271 .resume = u132_resume,
3273 .name = (char *)hcd_name,
3274 .owner = THIS_MODULE,
3277 static int __init u132_hcd_init(void)
3280 INIT_LIST_HEAD(&u132_static_list);
3283 mutex_init(&u132_module_lock);
3286 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3288 workqueue = create_singlethread_workqueue("u132");
3289 retval = platform_driver_register(&u132_platform_driver);
3294 module_init(u132_hcd_init);
3295 static void __exit u132_hcd_exit(void)
3299 mutex_lock(&u132_module_lock);
3301 mutex_unlock(&u132_module_lock);
3302 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3303 platform_device_unregister(u132->platform_dev);
3304 } platform_driver_unregister(&u132_platform_driver);
3305 printk(KERN_INFO "u132-hcd driver deregistered\n");
3306 wait_event(u132_hcd_wait, u132_instances == 0);
3307 flush_workqueue(workqueue);
3308 destroy_workqueue(workqueue);
3312 module_exit(u132_hcd_exit);
3313 MODULE_LICENSE("GPL");
3314 MODULE_ALIAS("platform:u132_hcd");