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/usb/hcd.h>
53 #include <linux/workqueue.h>
54 #include <linux/platform_device.h>
55 #include <linux/mutex.h>
58 #include <asm/byteorder.h>
60 /* FIXME ohci.h is ONLY for internal use by the OHCI driver.
61 * If you're going to try stuff like this, you need to split
62 * out shareable stuff (register declarations?) into its own
63 * file, maybe name <linux/usb/ohci.h>
67 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
68 #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
70 MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
71 MODULE_DESCRIPTION("U132 USB Host Controller Driver");
72 MODULE_LICENSE("GPL");
73 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
74 INT_MODULE_PARM(testing, 0);
75 /* Some boards misreport power switching/overcurrent*/
76 static bool distrust_firmware = 1;
77 module_param(distrust_firmware, bool, 0);
78 MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
80 static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
82 * u132_module_lock exists to protect access to global variables
85 static struct mutex u132_module_lock;
86 static int u132_exiting;
87 static int u132_instances;
88 static struct list_head u132_static_list;
90 * end of the global variables protected by u132_module_lock
92 static struct workqueue_struct *workqueue;
93 #define MAX_U132_PORTS 7
94 #define MAX_U132_ADDRS 128
95 #define MAX_U132_UDEVS 4
96 #define MAX_U132_ENDPS 100
97 #define MAX_U132_RINGS 4
98 static const char *cc_to_text[16] = {
128 struct usb_device *usb_device;
133 u8 endp_number_in[16];
134 u8 endp_number_out[16];
136 #define ENDP_QUEUE_SHIFT 3
137 #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
138 #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
140 struct list_head urb_more;
153 struct list_head endp_ring;
154 struct u132_ring *ring;
155 unsigned toggle_bits:2;
161 unsigned dequeueing:1;
162 unsigned edset_flush:1;
163 unsigned spare_bits:14;
164 unsigned long jiffies;
165 struct usb_host_endpoint *hep;
166 struct u132_spin queue_lock;
170 struct urb *urb_list[ENDP_QUEUE_SIZE];
171 struct list_head urb_more;
172 struct delayed_work scheduler;
179 struct u132_endp *curr_endp;
180 struct delayed_work scheduler;
184 struct list_head u132_list;
185 struct mutex sw_lock;
186 struct mutex 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 mutex_lock(&u132_module_lock);
261 list_del_init(&u132->u132_list);
263 mutex_unlock(&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);
320 static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
323 kref_get(&u132->kref);
324 u132_ring_requeue_work(u132, ring, delta);
327 static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
329 if (cancel_delayed_work(&ring->scheduler))
330 kref_put(&u132->kref, u132_hcd_delete);
333 static void u132_endp_delete(struct kref *kref)
335 struct u132_endp *endp = kref_to_u132_endp(kref);
336 struct u132 *u132 = endp->u132;
337 u8 usb_addr = endp->usb_addr;
338 u8 usb_endp = endp->usb_endp;
339 u8 address = u132->addr[usb_addr].address;
340 struct u132_udev *udev = &u132->udev[address];
341 u8 endp_number = endp->endp_number;
342 struct usb_host_endpoint *hep = endp->hep;
343 struct u132_ring *ring = endp->ring;
344 struct list_head *head = &endp->endp_ring;
346 if (endp == ring->curr_endp) {
347 if (list_empty(head)) {
348 ring->curr_endp = NULL;
351 struct u132_endp *next_endp = list_entry(head->next,
352 struct u132_endp, endp_ring);
353 ring->curr_endp = next_endp;
359 udev->endp_number_in[usb_endp] = 0;
360 u132_udev_put_kref(u132, udev);
363 udev->endp_number_out[usb_endp] = 0;
364 u132_udev_put_kref(u132, udev);
366 u132->endp[endp_number - 1] = NULL;
369 u132_u132_put_kref(u132);
372 static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp)
374 kref_put(&endp->kref, u132_endp_delete);
377 static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp)
379 kref_get(&endp->kref);
382 static inline void u132_endp_init_kref(struct u132 *u132,
383 struct u132_endp *endp)
385 kref_init(&endp->kref);
386 kref_get(&u132->kref);
389 static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
392 if (queue_delayed_work(workqueue, &endp->scheduler, delta))
393 kref_get(&endp->kref);
396 static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp)
398 if (cancel_delayed_work(&endp->scheduler))
399 kref_put(&endp->kref, u132_endp_delete);
402 static inline void u132_monitor_put_kref(struct u132 *u132)
404 kref_put(&u132->kref, u132_hcd_delete);
407 static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta)
409 if (queue_delayed_work(workqueue, &u132->monitor, delta))
410 kref_get(&u132->kref);
413 static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta)
415 if (!queue_delayed_work(workqueue, &u132->monitor, delta))
416 kref_put(&u132->kref, u132_hcd_delete);
419 static void u132_monitor_cancel_work(struct u132 *u132)
421 if (cancel_delayed_work(&u132->monitor))
422 kref_put(&u132->kref, u132_hcd_delete);
425 static int read_roothub_info(struct u132 *u132)
429 retval = u132_read_pcimem(u132, revision, &revision);
431 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
434 } else if ((revision & 0xFF) == 0x10) {
435 } else if ((revision & 0xFF) == 0x11) {
437 dev_err(&u132->platform_dev->dev, "device revision is not valid"
438 " %08X\n", revision);
441 retval = u132_read_pcimem(u132, control, &u132->hc_control);
443 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
447 retval = u132_read_pcimem(u132, roothub.status,
448 &u132->hc_roothub_status);
450 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
451 "g roothub.status\n", retval);
454 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a);
456 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
457 "g roothub.a\n", retval);
461 int I = u132->num_ports;
464 retval = u132_read_pcimem(u132, roothub.portstatus[i],
465 &u132->hc_roothub_portstatus[i]);
467 dev_err(&u132->platform_dev->dev, "error %d acc"
468 "essing device roothub.portstatus[%d]\n"
478 static void u132_hcd_monitor_work(struct work_struct *work)
480 struct u132 *u132 = container_of(work, struct u132, monitor.work);
481 if (u132->going > 1) {
482 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
484 u132_monitor_put_kref(u132);
486 } else if (u132->going > 0) {
487 dev_err(&u132->platform_dev->dev, "device is being removed\n");
488 u132_monitor_put_kref(u132);
492 mutex_lock(&u132->sw_lock);
493 retval = read_roothub_info(u132);
495 struct usb_hcd *hcd = u132_to_hcd(u132);
498 mutex_unlock(&u132->sw_lock);
500 ftdi_elan_gone_away(u132->platform_dev);
501 u132_monitor_put_kref(u132);
504 u132_monitor_requeue_work(u132, 500);
505 mutex_unlock(&u132->sw_lock);
511 static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
512 struct urb *urb, int status)
514 struct u132_ring *ring;
516 struct usb_hcd *hcd = u132_to_hcd(u132);
517 urb->error_count = 0;
518 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
519 usb_hcd_unlink_urb_from_ep(hcd, urb);
520 endp->queue_next += 1;
521 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
523 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
525 struct list_head *next = endp->urb_more.next;
526 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
529 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
532 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
535 mutex_lock(&u132->scheduler_lock);
538 u132_ring_cancel_work(u132, ring);
539 u132_ring_queue_work(u132, ring, 0);
540 mutex_unlock(&u132->scheduler_lock);
541 u132_endp_put_kref(u132, endp);
542 usb_hcd_giveback_urb(hcd, urb, status);
545 static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp,
546 struct urb *urb, int status)
548 u132_endp_put_kref(u132, endp);
551 static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
552 struct urb *urb, int status)
555 struct usb_hcd *hcd = u132_to_hcd(u132);
556 urb->error_count = 0;
557 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
558 usb_hcd_unlink_urb_from_ep(hcd, urb);
559 endp->queue_next += 1;
560 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
562 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
564 struct list_head *next = endp->urb_more.next;
565 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
568 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
571 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
574 usb_hcd_giveback_urb(hcd, urb, status);
577 static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
578 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
579 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
580 int toggle_bits, int error_count, int condition_code, int repeat_number,
581 int halted, int skipped, int actual, int non_null))
583 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
584 urb, address, endp->usb_endp, toggle_bits, callback);
587 static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
588 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
589 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
590 int toggle_bits, int error_count, int condition_code, int repeat_number,
591 int halted, int skipped, int actual, int non_null))
593 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
594 urb, address, endp->usb_endp, toggle_bits, callback);
597 static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
598 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
599 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
600 int toggle_bits, int error_count, int condition_code, int repeat_number,
601 int halted, int skipped, int actual, int non_null))
603 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
604 endp, urb, address, endp->usb_endp, toggle_bits, callback);
607 static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
608 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
609 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
610 int toggle_bits, int error_count, int condition_code, int repeat_number,
611 int halted, int skipped, int actual, int non_null))
613 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
614 endp, urb, address, endp->usb_endp, toggle_bits, callback);
619 * must not LOCK sw_lock
622 static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
623 int len, int toggle_bits, int error_count, int condition_code,
624 int repeat_number, int halted, int skipped, int actual, int non_null)
626 struct u132_endp *endp = data;
627 struct u132 *u132 = endp->u132;
628 u8 address = u132->addr[endp->usb_addr].address;
629 struct u132_udev *udev = &u132->udev[address];
630 mutex_lock(&u132->scheduler_lock);
631 if (u132->going > 1) {
632 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
634 mutex_unlock(&u132->scheduler_lock);
635 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
637 } else if (endp->dequeueing) {
638 endp->dequeueing = 0;
639 mutex_unlock(&u132->scheduler_lock);
640 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
642 } else if (u132->going > 0) {
643 dev_err(&u132->platform_dev->dev, "device is being removed "
645 mutex_unlock(&u132->scheduler_lock);
646 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
648 } else if (!urb->unlinked) {
649 struct u132_ring *ring = endp->ring;
650 u8 *u = urb->transfer_buffer + urb->actual_length;
657 urb->actual_length += len;
658 if ((condition_code == TD_CC_NOERROR) &&
659 (urb->transfer_buffer_length > urb->actual_length)) {
660 endp->toggle_bits = toggle_bits;
661 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
663 if (urb->actual_length > 0) {
665 mutex_unlock(&u132->scheduler_lock);
666 retval = edset_single(u132, ring, endp, urb,
667 address, endp->toggle_bits,
668 u132_hcd_interrupt_recv);
670 u132_hcd_giveback_urb(u132, endp, urb,
675 endp->jiffies = jiffies +
676 msecs_to_jiffies(urb->interval);
677 u132_ring_cancel_work(u132, ring);
678 u132_ring_queue_work(u132, ring, 0);
679 mutex_unlock(&u132->scheduler_lock);
680 u132_endp_put_kref(u132, endp);
683 } else if ((condition_code == TD_DATAUNDERRUN) &&
684 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
685 endp->toggle_bits = toggle_bits;
686 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
688 mutex_unlock(&u132->scheduler_lock);
689 u132_hcd_giveback_urb(u132, endp, urb, 0);
692 if (condition_code == TD_CC_NOERROR) {
693 endp->toggle_bits = toggle_bits;
694 usb_settoggle(udev->usb_device, endp->usb_endp,
696 } else if (condition_code == TD_CC_STALL) {
697 endp->toggle_bits = 0x2;
698 usb_settoggle(udev->usb_device, endp->usb_endp,
701 endp->toggle_bits = 0x2;
702 usb_settoggle(udev->usb_device, endp->usb_endp,
704 dev_err(&u132->platform_dev->dev, "urb=%p givin"
705 "g back INTERRUPT %s\n", urb,
706 cc_to_text[condition_code]);
708 mutex_unlock(&u132->scheduler_lock);
709 u132_hcd_giveback_urb(u132, endp, urb,
710 cc_to_error[condition_code]);
714 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
715 "unlinked=%d\n", urb, urb->unlinked);
716 mutex_unlock(&u132->scheduler_lock);
717 u132_hcd_giveback_urb(u132, endp, urb, 0);
722 static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
723 int len, int toggle_bits, int error_count, int condition_code,
724 int repeat_number, int halted, int skipped, int actual, int non_null)
726 struct u132_endp *endp = data;
727 struct u132 *u132 = endp->u132;
728 u8 address = u132->addr[endp->usb_addr].address;
729 mutex_lock(&u132->scheduler_lock);
730 if (u132->going > 1) {
731 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
733 mutex_unlock(&u132->scheduler_lock);
734 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
736 } else if (endp->dequeueing) {
737 endp->dequeueing = 0;
738 mutex_unlock(&u132->scheduler_lock);
739 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
741 } else if (u132->going > 0) {
742 dev_err(&u132->platform_dev->dev, "device is being removed "
744 mutex_unlock(&u132->scheduler_lock);
745 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
747 } else if (!urb->unlinked) {
748 struct u132_ring *ring = endp->ring;
749 urb->actual_length += len;
750 endp->toggle_bits = toggle_bits;
751 if (urb->transfer_buffer_length > urb->actual_length) {
753 mutex_unlock(&u132->scheduler_lock);
754 retval = edset_output(u132, ring, endp, urb, address,
755 endp->toggle_bits, u132_hcd_bulk_output_sent);
757 u132_hcd_giveback_urb(u132, endp, urb, retval);
760 mutex_unlock(&u132->scheduler_lock);
761 u132_hcd_giveback_urb(u132, endp, urb, 0);
765 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
766 "unlinked=%d\n", urb, urb->unlinked);
767 mutex_unlock(&u132->scheduler_lock);
768 u132_hcd_giveback_urb(u132, endp, urb, 0);
773 static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
774 int len, int toggle_bits, int error_count, int condition_code,
775 int repeat_number, int halted, int skipped, int actual, int non_null)
777 struct u132_endp *endp = data;
778 struct u132 *u132 = endp->u132;
779 u8 address = u132->addr[endp->usb_addr].address;
780 struct u132_udev *udev = &u132->udev[address];
781 mutex_lock(&u132->scheduler_lock);
782 if (u132->going > 1) {
783 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
785 mutex_unlock(&u132->scheduler_lock);
786 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
788 } else if (endp->dequeueing) {
789 endp->dequeueing = 0;
790 mutex_unlock(&u132->scheduler_lock);
791 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
793 } else if (u132->going > 0) {
794 dev_err(&u132->platform_dev->dev, "device is being removed "
796 mutex_unlock(&u132->scheduler_lock);
797 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
799 } else if (!urb->unlinked) {
800 struct u132_ring *ring = endp->ring;
801 u8 *u = urb->transfer_buffer + urb->actual_length;
808 urb->actual_length += len;
809 if ((condition_code == TD_CC_NOERROR) &&
810 (urb->transfer_buffer_length > urb->actual_length)) {
812 endp->toggle_bits = toggle_bits;
813 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
815 mutex_unlock(&u132->scheduler_lock);
816 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
817 ring->number, endp, urb, address,
818 endp->usb_endp, endp->toggle_bits,
819 u132_hcd_bulk_input_recv);
821 u132_hcd_giveback_urb(u132, endp, urb, retval);
823 } else if (condition_code == TD_CC_NOERROR) {
824 endp->toggle_bits = toggle_bits;
825 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
827 mutex_unlock(&u132->scheduler_lock);
828 u132_hcd_giveback_urb(u132, endp, urb,
829 cc_to_error[condition_code]);
831 } else if ((condition_code == TD_DATAUNDERRUN) &&
832 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
833 endp->toggle_bits = toggle_bits;
834 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
836 mutex_unlock(&u132->scheduler_lock);
837 u132_hcd_giveback_urb(u132, endp, urb, 0);
839 } else if (condition_code == TD_DATAUNDERRUN) {
840 endp->toggle_bits = toggle_bits;
841 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
843 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
844 ") giving back BULK IN %s\n", urb,
845 cc_to_text[condition_code]);
846 mutex_unlock(&u132->scheduler_lock);
847 u132_hcd_giveback_urb(u132, endp, urb, 0);
849 } else if (condition_code == TD_CC_STALL) {
850 endp->toggle_bits = 0x2;
851 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
852 mutex_unlock(&u132->scheduler_lock);
853 u132_hcd_giveback_urb(u132, endp, urb,
854 cc_to_error[condition_code]);
857 endp->toggle_bits = 0x2;
858 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
859 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
860 "ULK IN code=%d %s\n", urb, condition_code,
861 cc_to_text[condition_code]);
862 mutex_unlock(&u132->scheduler_lock);
863 u132_hcd_giveback_urb(u132, endp, urb,
864 cc_to_error[condition_code]);
868 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
869 "unlinked=%d\n", urb, urb->unlinked);
870 mutex_unlock(&u132->scheduler_lock);
871 u132_hcd_giveback_urb(u132, endp, urb, 0);
876 static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
877 int len, int toggle_bits, int error_count, int condition_code,
878 int repeat_number, int halted, int skipped, int actual, int non_null)
880 struct u132_endp *endp = data;
881 struct u132 *u132 = endp->u132;
882 mutex_lock(&u132->scheduler_lock);
883 if (u132->going > 1) {
884 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
886 mutex_unlock(&u132->scheduler_lock);
887 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
889 } else if (endp->dequeueing) {
890 endp->dequeueing = 0;
891 mutex_unlock(&u132->scheduler_lock);
892 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
894 } else if (u132->going > 0) {
895 dev_err(&u132->platform_dev->dev, "device is being removed "
897 mutex_unlock(&u132->scheduler_lock);
898 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
900 } else if (!urb->unlinked) {
901 mutex_unlock(&u132->scheduler_lock);
902 u132_hcd_giveback_urb(u132, endp, urb, 0);
905 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
906 "unlinked=%d\n", urb, urb->unlinked);
907 mutex_unlock(&u132->scheduler_lock);
908 u132_hcd_giveback_urb(u132, endp, urb, 0);
913 static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
914 int len, int toggle_bits, int error_count, int condition_code,
915 int repeat_number, int halted, int skipped, int actual, int non_null)
917 struct u132_endp *endp = data;
918 struct u132 *u132 = endp->u132;
919 u8 address = u132->addr[endp->usb_addr].address;
920 mutex_lock(&u132->scheduler_lock);
921 if (u132->going > 1) {
922 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
924 mutex_unlock(&u132->scheduler_lock);
925 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
927 } else if (endp->dequeueing) {
928 endp->dequeueing = 0;
929 mutex_unlock(&u132->scheduler_lock);
930 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
932 } else if (u132->going > 0) {
933 dev_err(&u132->platform_dev->dev, "device is being removed "
935 mutex_unlock(&u132->scheduler_lock);
936 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
938 } else if (!urb->unlinked) {
939 struct u132_ring *ring = endp->ring;
940 u8 *u = urb->transfer_buffer;
947 urb->actual_length = len;
948 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
949 TD_DATAUNDERRUN) && ((urb->transfer_flags &
950 URB_SHORT_NOT_OK) == 0))) {
952 mutex_unlock(&u132->scheduler_lock);
953 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
954 ring->number, endp, urb, address,
956 u132_hcd_configure_empty_sent);
958 u132_hcd_giveback_urb(u132, endp, urb, retval);
960 } else if (condition_code == TD_CC_STALL) {
961 mutex_unlock(&u132->scheduler_lock);
962 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
963 "NPUT STALL urb %p\n", urb);
964 u132_hcd_giveback_urb(u132, endp, urb,
965 cc_to_error[condition_code]);
968 mutex_unlock(&u132->scheduler_lock);
969 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
970 "PUT %s urb %p\n", cc_to_text[condition_code],
972 u132_hcd_giveback_urb(u132, endp, urb,
973 cc_to_error[condition_code]);
977 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
978 "unlinked=%d\n", urb, urb->unlinked);
979 mutex_unlock(&u132->scheduler_lock);
980 u132_hcd_giveback_urb(u132, endp, urb, 0);
985 static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
986 int len, int toggle_bits, int error_count, int condition_code,
987 int repeat_number, int halted, int skipped, int actual, int non_null)
989 struct u132_endp *endp = data;
990 struct u132 *u132 = endp->u132;
991 mutex_lock(&u132->scheduler_lock);
992 if (u132->going > 1) {
993 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
995 mutex_unlock(&u132->scheduler_lock);
996 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
998 } else if (endp->dequeueing) {
999 endp->dequeueing = 0;
1000 mutex_unlock(&u132->scheduler_lock);
1001 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1003 } else if (u132->going > 0) {
1004 dev_err(&u132->platform_dev->dev, "device is being removed "
1006 mutex_unlock(&u132->scheduler_lock);
1007 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1009 } else if (!urb->unlinked) {
1010 mutex_unlock(&u132->scheduler_lock);
1011 u132_hcd_giveback_urb(u132, endp, urb, 0);
1014 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1015 "unlinked=%d\n", urb, urb->unlinked);
1016 mutex_unlock(&u132->scheduler_lock);
1017 u132_hcd_giveback_urb(u132, endp, urb, 0);
1022 static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1023 int len, int toggle_bits, int error_count, int condition_code,
1024 int repeat_number, int halted, int skipped, int actual, int non_null)
1026 struct u132_endp *endp = data;
1027 struct u132 *u132 = endp->u132;
1028 u8 address = u132->addr[endp->usb_addr].address;
1029 mutex_lock(&u132->scheduler_lock);
1030 if (u132->going > 1) {
1031 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1033 mutex_unlock(&u132->scheduler_lock);
1034 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1036 } else if (endp->dequeueing) {
1037 endp->dequeueing = 0;
1038 mutex_unlock(&u132->scheduler_lock);
1039 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1041 } else if (u132->going > 0) {
1042 dev_err(&u132->platform_dev->dev, "device is being removed "
1044 mutex_unlock(&u132->scheduler_lock);
1045 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1047 } else if (!urb->unlinked) {
1048 if (usb_pipein(urb->pipe)) {
1050 struct u132_ring *ring = endp->ring;
1051 mutex_unlock(&u132->scheduler_lock);
1052 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1053 ring->number, endp, urb, address,
1055 u132_hcd_configure_input_recv);
1057 u132_hcd_giveback_urb(u132, endp, urb, retval);
1061 struct u132_ring *ring = endp->ring;
1062 mutex_unlock(&u132->scheduler_lock);
1063 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1064 ring->number, endp, urb, address,
1066 u132_hcd_configure_empty_recv);
1068 u132_hcd_giveback_urb(u132, endp, urb, retval);
1072 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1073 "unlinked=%d\n", urb, urb->unlinked);
1074 mutex_unlock(&u132->scheduler_lock);
1075 u132_hcd_giveback_urb(u132, endp, urb, 0);
1080 static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1081 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1082 int repeat_number, int halted, int skipped, int actual, int non_null)
1084 struct u132_endp *endp = data;
1085 struct u132 *u132 = endp->u132;
1086 u8 address = u132->addr[endp->usb_addr].address;
1087 struct u132_udev *udev = &u132->udev[address];
1088 mutex_lock(&u132->scheduler_lock);
1089 if (u132->going > 1) {
1090 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1092 mutex_unlock(&u132->scheduler_lock);
1093 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1095 } else if (endp->dequeueing) {
1096 endp->dequeueing = 0;
1097 mutex_unlock(&u132->scheduler_lock);
1098 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1100 } else if (u132->going > 0) {
1101 dev_err(&u132->platform_dev->dev, "device is being removed "
1103 mutex_unlock(&u132->scheduler_lock);
1104 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1106 } else if (!urb->unlinked) {
1107 u132->addr[0].address = 0;
1108 endp->usb_addr = udev->usb_addr;
1109 mutex_unlock(&u132->scheduler_lock);
1110 u132_hcd_giveback_urb(u132, endp, urb, 0);
1113 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1114 "unlinked=%d\n", urb, urb->unlinked);
1115 mutex_unlock(&u132->scheduler_lock);
1116 u132_hcd_giveback_urb(u132, endp, urb, 0);
1121 static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1122 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1123 int repeat_number, int halted, int skipped, int actual, int non_null)
1125 struct u132_endp *endp = data;
1126 struct u132 *u132 = endp->u132;
1127 mutex_lock(&u132->scheduler_lock);
1128 if (u132->going > 1) {
1129 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1131 mutex_unlock(&u132->scheduler_lock);
1132 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1134 } else if (endp->dequeueing) {
1135 endp->dequeueing = 0;
1136 mutex_unlock(&u132->scheduler_lock);
1137 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1139 } else if (u132->going > 0) {
1140 dev_err(&u132->platform_dev->dev, "device is being removed "
1142 mutex_unlock(&u132->scheduler_lock);
1143 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1145 } else if (!urb->unlinked) {
1147 struct u132_ring *ring = endp->ring;
1148 mutex_unlock(&u132->scheduler_lock);
1149 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1150 ring->number, endp, urb, 0, endp->usb_endp, 0,
1151 u132_hcd_enumeration_empty_recv);
1153 u132_hcd_giveback_urb(u132, endp, urb, retval);
1156 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1157 "unlinked=%d\n", urb, urb->unlinked);
1158 mutex_unlock(&u132->scheduler_lock);
1159 u132_hcd_giveback_urb(u132, endp, urb, 0);
1164 static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1165 int len, int toggle_bits, int error_count, int condition_code,
1166 int repeat_number, int halted, int skipped, int actual, int non_null)
1168 struct u132_endp *endp = data;
1169 struct u132 *u132 = endp->u132;
1170 mutex_lock(&u132->scheduler_lock);
1171 if (u132->going > 1) {
1172 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1174 mutex_unlock(&u132->scheduler_lock);
1175 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1177 } else if (endp->dequeueing) {
1178 endp->dequeueing = 0;
1179 mutex_unlock(&u132->scheduler_lock);
1180 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1182 } else if (u132->going > 0) {
1183 dev_err(&u132->platform_dev->dev, "device is being removed "
1185 mutex_unlock(&u132->scheduler_lock);
1186 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1188 } else if (!urb->unlinked) {
1189 mutex_unlock(&u132->scheduler_lock);
1190 u132_hcd_giveback_urb(u132, endp, urb, 0);
1193 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1194 "unlinked=%d\n", urb, urb->unlinked);
1195 mutex_unlock(&u132->scheduler_lock);
1196 u132_hcd_giveback_urb(u132, endp, urb, 0);
1201 static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1202 int len, int toggle_bits, int error_count, int condition_code,
1203 int repeat_number, int halted, int skipped, int actual, int non_null)
1205 struct u132_endp *endp = data;
1206 struct u132 *u132 = endp->u132;
1207 u8 address = u132->addr[endp->usb_addr].address;
1208 mutex_lock(&u132->scheduler_lock);
1209 if (u132->going > 1) {
1210 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1212 mutex_unlock(&u132->scheduler_lock);
1213 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1215 } else if (endp->dequeueing) {
1216 endp->dequeueing = 0;
1217 mutex_unlock(&u132->scheduler_lock);
1218 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1220 } else if (u132->going > 0) {
1221 dev_err(&u132->platform_dev->dev, "device is being removed "
1223 mutex_unlock(&u132->scheduler_lock);
1224 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1226 } else if (!urb->unlinked) {
1228 struct u132_ring *ring = endp->ring;
1229 u8 *u = urb->transfer_buffer;
1236 urb->actual_length = len;
1237 mutex_unlock(&u132->scheduler_lock);
1238 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1239 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1240 u132_hcd_initial_empty_sent);
1242 u132_hcd_giveback_urb(u132, endp, urb, retval);
1245 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1246 "unlinked=%d\n", urb, urb->unlinked);
1247 mutex_unlock(&u132->scheduler_lock);
1248 u132_hcd_giveback_urb(u132, endp, urb, 0);
1253 static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1254 int len, int toggle_bits, int error_count, int condition_code,
1255 int repeat_number, int halted, int skipped, int actual, int non_null)
1257 struct u132_endp *endp = data;
1258 struct u132 *u132 = endp->u132;
1259 u8 address = u132->addr[endp->usb_addr].address;
1260 mutex_lock(&u132->scheduler_lock);
1261 if (u132->going > 1) {
1262 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1264 mutex_unlock(&u132->scheduler_lock);
1265 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1267 } else if (endp->dequeueing) {
1268 endp->dequeueing = 0;
1269 mutex_unlock(&u132->scheduler_lock);
1270 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1272 } else if (u132->going > 0) {
1273 dev_err(&u132->platform_dev->dev, "device is being removed "
1275 mutex_unlock(&u132->scheduler_lock);
1276 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1278 } else if (!urb->unlinked) {
1280 struct u132_ring *ring = endp->ring;
1281 mutex_unlock(&u132->scheduler_lock);
1282 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1283 ring->number, endp, urb, address, endp->usb_endp, 0,
1284 u132_hcd_initial_input_recv);
1286 u132_hcd_giveback_urb(u132, endp, urb, retval);
1289 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1290 "unlinked=%d\n", urb, urb->unlinked);
1291 mutex_unlock(&u132->scheduler_lock);
1292 u132_hcd_giveback_urb(u132, endp, urb, 0);
1298 * this work function is only executed from the work queue
1301 static void u132_hcd_ring_work_scheduler(struct work_struct *work)
1303 struct u132_ring *ring =
1304 container_of(work, struct u132_ring, scheduler.work);
1305 struct u132 *u132 = ring->u132;
1306 mutex_lock(&u132->scheduler_lock);
1308 mutex_unlock(&u132->scheduler_lock);
1309 u132_ring_put_kref(u132, ring);
1311 } else if (ring->curr_endp) {
1312 struct u132_endp *last_endp = ring->curr_endp;
1313 struct list_head *scan;
1314 struct list_head *head = &last_endp->endp_ring;
1315 unsigned long wakeup = 0;
1316 list_for_each(scan, head) {
1317 struct u132_endp *endp = list_entry(scan,
1318 struct u132_endp, endp_ring);
1319 if (endp->queue_next == endp->queue_last) {
1320 } else if ((endp->delayed == 0)
1321 || time_after_eq(jiffies, endp->jiffies)) {
1322 ring->curr_endp = endp;
1323 u132_endp_cancel_work(u132, last_endp);
1324 u132_endp_queue_work(u132, last_endp, 0);
1325 mutex_unlock(&u132->scheduler_lock);
1326 u132_ring_put_kref(u132, ring);
1329 unsigned long delta = endp->jiffies - jiffies;
1334 if (last_endp->queue_next == last_endp->queue_last) {
1335 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1336 last_endp->jiffies)) {
1337 u132_endp_cancel_work(u132, last_endp);
1338 u132_endp_queue_work(u132, last_endp, 0);
1339 mutex_unlock(&u132->scheduler_lock);
1340 u132_ring_put_kref(u132, ring);
1343 unsigned long delta = last_endp->jiffies - jiffies;
1348 u132_ring_requeue_work(u132, ring, wakeup);
1349 mutex_unlock(&u132->scheduler_lock);
1352 mutex_unlock(&u132->scheduler_lock);
1353 u132_ring_put_kref(u132, ring);
1357 mutex_unlock(&u132->scheduler_lock);
1358 u132_ring_put_kref(u132, ring);
1363 static void u132_hcd_endp_work_scheduler(struct work_struct *work)
1365 struct u132_ring *ring;
1366 struct u132_endp *endp =
1367 container_of(work, struct u132_endp, scheduler.work);
1368 struct u132 *u132 = endp->u132;
1369 mutex_lock(&u132->scheduler_lock);
1371 if (endp->edset_flush) {
1372 endp->edset_flush = 0;
1373 if (endp->dequeueing)
1374 usb_ftdi_elan_edset_flush(u132->platform_dev,
1375 ring->number, endp);
1376 mutex_unlock(&u132->scheduler_lock);
1377 u132_endp_put_kref(u132, endp);
1379 } else if (endp->active) {
1380 mutex_unlock(&u132->scheduler_lock);
1381 u132_endp_put_kref(u132, endp);
1383 } else if (ring->in_use) {
1384 mutex_unlock(&u132->scheduler_lock);
1385 u132_endp_put_kref(u132, endp);
1387 } else if (endp->queue_next == endp->queue_last) {
1388 mutex_unlock(&u132->scheduler_lock);
1389 u132_endp_put_kref(u132, endp);
1391 } else if (endp->pipetype == PIPE_INTERRUPT) {
1392 u8 address = u132->addr[endp->usb_addr].address;
1394 mutex_unlock(&u132->scheduler_lock);
1395 u132_endp_put_kref(u132, endp);
1399 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1402 ring->curr_endp = endp;
1404 mutex_unlock(&u132->scheduler_lock);
1405 retval = edset_single(u132, ring, endp, urb, address,
1406 endp->toggle_bits, u132_hcd_interrupt_recv);
1408 u132_hcd_giveback_urb(u132, endp, urb, retval);
1411 } else if (endp->pipetype == PIPE_CONTROL) {
1412 u8 address = u132->addr[endp->usb_addr].address;
1414 mutex_unlock(&u132->scheduler_lock);
1415 u132_endp_put_kref(u132, endp);
1417 } else if (address == 0) {
1419 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1422 ring->curr_endp = endp;
1424 mutex_unlock(&u132->scheduler_lock);
1425 retval = edset_setup(u132, ring, endp, urb, address,
1426 0x2, u132_hcd_initial_setup_sent);
1428 u132_hcd_giveback_urb(u132, endp, urb, retval);
1430 } else if (endp->usb_addr == 0) {
1432 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1435 ring->curr_endp = endp;
1437 mutex_unlock(&u132->scheduler_lock);
1438 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1439 u132_hcd_enumeration_address_sent);
1441 u132_hcd_giveback_urb(u132, endp, urb, retval);
1445 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1447 address = u132->addr[endp->usb_addr].address;
1449 ring->curr_endp = endp;
1451 mutex_unlock(&u132->scheduler_lock);
1452 retval = edset_setup(u132, ring, endp, urb, address,
1453 0x2, u132_hcd_configure_setup_sent);
1455 u132_hcd_giveback_urb(u132, endp, urb, retval);
1460 u8 address = u132->addr[endp->usb_addr].address;
1462 mutex_unlock(&u132->scheduler_lock);
1463 u132_endp_put_kref(u132, endp);
1467 struct urb *urb = endp->urb_list[
1468 ENDP_QUEUE_MASK & endp->queue_next];
1470 ring->curr_endp = endp;
1472 mutex_unlock(&u132->scheduler_lock);
1473 retval = edset_input(u132, ring, endp, urb,
1474 address, endp->toggle_bits,
1475 u132_hcd_bulk_input_recv);
1478 u132_hcd_giveback_urb(u132, endp, urb,
1482 } else { /* output pipe */
1483 u8 address = u132->addr[endp->usb_addr].address;
1485 mutex_unlock(&u132->scheduler_lock);
1486 u132_endp_put_kref(u132, endp);
1490 struct urb *urb = endp->urb_list[
1491 ENDP_QUEUE_MASK & endp->queue_next];
1493 ring->curr_endp = endp;
1495 mutex_unlock(&u132->scheduler_lock);
1496 retval = edset_output(u132, ring, endp, urb,
1497 address, endp->toggle_bits,
1498 u132_hcd_bulk_output_sent);
1501 u132_hcd_giveback_urb(u132, endp, urb,
1510 static void port_power(struct u132 *u132, int pn, int is_on)
1512 u132->port[pn].power = is_on;
1517 static void u132_power(struct u132 *u132, int is_on)
1519 struct usb_hcd *hcd = u132_to_hcd(u132)
1520 ; /* hub is inactive unless the port is powered */
1527 hcd->state = HC_STATE_HALT;
1531 static int u132_periodic_reinit(struct u132 *u132)
1534 u32 fi = u132->hc_fminterval & 0x03fff;
1537 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1540 fit = fminterval & FIT;
1541 retval = u132_write_pcimem(u132, fminterval,
1542 (fit ^ FIT) | u132->hc_fminterval);
1545 retval = u132_write_pcimem(u132, periodicstart,
1546 ((9 * fi) / 10) & 0x3fff);
1552 static char *hcfs2string(int state)
1555 case OHCI_USB_RESET:
1557 case OHCI_USB_RESUME:
1560 return "operational";
1561 case OHCI_USB_SUSPEND:
1567 static int u132_init(struct u132 *u132)
1572 u132->next_statechange = jiffies;
1573 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1576 retval = u132_read_pcimem(u132, control, &control);
1579 if (u132->num_ports == 0) {
1581 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1584 u132->num_ports = rh_a & RH_A_NDP;
1585 retval = read_roothub_info(u132);
1589 if (u132->num_ports > MAX_U132_PORTS)
1596 /* Start an OHCI controller, set the BUS operational
1597 * resets USB and controller
1600 static int u132_run(struct u132 *u132)
1609 int mask = OHCI_INTR_INIT;
1610 int first = u132->hc_fminterval == 0;
1612 int reset_timeout = 30; /* ... allow extra time */
1616 retval = u132_read_pcimem(u132, fminterval, &temp);
1619 u132->hc_fminterval = temp & 0x3fff;
1620 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1622 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1625 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1626 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1628 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1632 case OHCI_USB_SUSPEND:
1633 case OHCI_USB_RESUME:
1634 u132->hc_control &= OHCI_CTRL_RWC;
1635 u132->hc_control |= OHCI_USB_RESUME;
1639 u132->hc_control &= OHCI_CTRL_RWC;
1640 u132->hc_control |= OHCI_USB_RESET;
1644 retval = u132_write_pcimem(u132, control, u132->hc_control);
1647 retval = u132_read_pcimem(u132, control, &control);
1651 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1654 if (!(roothub_a & RH_A_NPS)) {
1655 int temp; /* power down each port */
1656 for (temp = 0; temp < u132->num_ports; temp++) {
1657 retval = u132_write_pcimem(u132,
1658 roothub.portstatus[temp], RH_PS_LSDA);
1663 retval = u132_read_pcimem(u132, control, &control);
1667 retval = u132_read_pcimem(u132, cmdstatus, &status);
1670 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1674 retval = u132_read_pcimem(u132, cmdstatus, &status);
1677 if (0 != (status & OHCI_HCR)) {
1678 if (--reset_timeout == 0) {
1679 dev_err(&u132->platform_dev->dev, "USB HC reset"
1688 if (u132->flags & OHCI_QUIRK_INITRESET) {
1689 retval = u132_write_pcimem(u132, control, u132->hc_control);
1692 retval = u132_read_pcimem(u132, control, &control);
1696 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1699 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1702 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1705 retval = u132_periodic_reinit(u132);
1708 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1711 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1714 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1715 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1716 u132->flags |= OHCI_QUIRK_INITRESET;
1719 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1720 "\n", fminterval, periodicstart);
1721 } /* start controller operations */
1722 u132->hc_control &= OHCI_CTRL_RWC;
1723 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1724 retval = u132_write_pcimem(u132, control, u132->hc_control);
1727 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1730 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1733 retval = u132_read_pcimem(u132, control, &control);
1736 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1737 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1740 retval = u132_write_pcimem(u132, intrstatus, mask);
1743 retval = u132_write_pcimem(u132, intrdisable,
1744 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1745 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1748 return retval; /* handle root hub init quirks ... */
1749 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1752 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1753 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1754 roothub_a |= RH_A_NOCP;
1755 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1756 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1759 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1760 roothub_a |= RH_A_NPS;
1761 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1765 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1768 retval = u132_write_pcimem(u132, roothub.b,
1769 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1772 retval = u132_read_pcimem(u132, control, &control);
1775 mdelay((roothub_a >> 23) & 0x1fe);
1776 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1780 static void u132_hcd_stop(struct usb_hcd *hcd)
1782 struct u132 *u132 = hcd_to_u132(hcd);
1783 if (u132->going > 1) {
1784 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1785 "een removed %d\n", u132, hcd, u132->going);
1786 } else if (u132->going > 0) {
1787 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1790 mutex_lock(&u132->sw_lock);
1792 u132_power(u132, 0);
1793 mutex_unlock(&u132->sw_lock);
1797 static int u132_hcd_start(struct usb_hcd *hcd)
1799 struct u132 *u132 = hcd_to_u132(hcd);
1800 if (u132->going > 1) {
1801 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1804 } else if (u132->going > 0) {
1805 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1807 } else if (hcd->self.controller) {
1809 struct platform_device *pdev =
1810 to_platform_device(hcd->self.controller);
1811 u16 vendor = ((struct u132_platform_data *)
1812 dev_get_platdata(&pdev->dev))->vendor;
1813 u16 device = ((struct u132_platform_data *)
1814 dev_get_platdata(&pdev->dev))->device;
1815 mutex_lock(&u132->sw_lock);
1817 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1818 u132->flags = OHCI_QUIRK_AMD756;
1819 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1820 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1821 "ounds unavailable\n");
1822 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1823 u132->flags |= OHCI_QUIRK_ZFMICRO;
1824 retval = u132_run(u132);
1830 mutex_unlock(&u132->sw_lock);
1833 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1838 static int u132_hcd_reset(struct usb_hcd *hcd)
1840 struct u132 *u132 = hcd_to_u132(hcd);
1841 if (u132->going > 1) {
1842 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1845 } else if (u132->going > 0) {
1846 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1850 mutex_lock(&u132->sw_lock);
1851 retval = u132_init(u132);
1856 mutex_unlock(&u132->sw_lock);
1861 static int create_endpoint_and_queue_int(struct u132 *u132,
1862 struct u132_udev *udev, struct urb *urb,
1863 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1866 struct u132_ring *ring;
1870 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1875 spin_lock_init(&endp->queue_lock.slock);
1876 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1877 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1879 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1884 endp_number = ++u132->num_endpoints;
1885 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1886 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1887 INIT_LIST_HEAD(&endp->urb_more);
1888 ring = endp->ring = &u132->ring[0];
1889 if (ring->curr_endp) {
1890 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1892 INIT_LIST_HEAD(&endp->endp_ring);
1893 ring->curr_endp = endp;
1896 endp->dequeueing = 0;
1897 endp->edset_flush = 0;
1900 endp->endp_number = endp_number;
1902 endp->hep = urb->ep;
1903 endp->pipetype = usb_pipetype(urb->pipe);
1904 u132_endp_init_kref(u132, endp);
1905 if (usb_pipein(urb->pipe)) {
1906 endp->toggle_bits = 0x2;
1907 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1910 udev->endp_number_in[usb_endp] = endp_number;
1911 u132_udev_get_kref(u132, udev);
1913 endp->toggle_bits = 0x2;
1914 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1917 udev->endp_number_out[usb_endp] = endp_number;
1918 u132_udev_get_kref(u132, udev);
1922 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1923 endp->udev_number = address;
1924 endp->usb_addr = usb_addr;
1925 endp->usb_endp = usb_endp;
1926 endp->queue_size = 1;
1927 endp->queue_last = 0;
1928 endp->queue_next = 0;
1929 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1930 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1931 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1935 static int queue_int_on_old_endpoint(struct u132 *u132,
1936 struct u132_udev *udev, struct urb *urb,
1937 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1938 u8 usb_endp, u8 address)
1942 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1943 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1944 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1946 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1949 endp->queue_size -= 1;
1952 list_add_tail(&urbq->urb_more, &endp->urb_more);
1959 static int create_endpoint_and_queue_bulk(struct u132 *u132,
1960 struct u132_udev *udev, struct urb *urb,
1961 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1965 struct u132_ring *ring;
1969 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1974 spin_lock_init(&endp->queue_lock.slock);
1975 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1976 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1978 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1983 endp_number = ++u132->num_endpoints;
1984 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1985 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1986 INIT_LIST_HEAD(&endp->urb_more);
1987 endp->dequeueing = 0;
1988 endp->edset_flush = 0;
1991 endp->endp_number = endp_number;
1993 endp->hep = urb->ep;
1994 endp->pipetype = usb_pipetype(urb->pipe);
1995 u132_endp_init_kref(u132, endp);
1996 if (usb_pipein(urb->pipe)) {
1997 endp->toggle_bits = 0x2;
1998 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
2002 udev->endp_number_in[usb_endp] = endp_number;
2003 u132_udev_get_kref(u132, udev);
2005 endp->toggle_bits = 0x2;
2006 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2010 udev->endp_number_out[usb_endp] = endp_number;
2011 u132_udev_get_kref(u132, udev);
2013 ring = endp->ring = &u132->ring[ring_number - 1];
2014 if (ring->curr_endp) {
2015 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2017 INIT_LIST_HEAD(&endp->endp_ring);
2018 ring->curr_endp = endp;
2022 endp->udev_number = address;
2023 endp->usb_addr = usb_addr;
2024 endp->usb_endp = usb_endp;
2025 endp->queue_size = 1;
2026 endp->queue_last = 0;
2027 endp->queue_next = 0;
2028 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2029 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2030 u132_endp_queue_work(u132, endp, 0);
2034 static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2036 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2037 u8 usb_endp, u8 address)
2040 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2041 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2043 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2046 endp->queue_size -= 1;
2049 list_add_tail(&urbq->urb_more, &endp->urb_more);
2056 static int create_endpoint_and_queue_control(struct u132 *u132,
2058 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2061 struct u132_ring *ring;
2065 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
2070 spin_lock_init(&endp->queue_lock.slock);
2071 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2072 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
2074 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2079 endp_number = ++u132->num_endpoints;
2080 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2081 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2082 INIT_LIST_HEAD(&endp->urb_more);
2083 ring = endp->ring = &u132->ring[0];
2084 if (ring->curr_endp) {
2085 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2087 INIT_LIST_HEAD(&endp->endp_ring);
2088 ring->curr_endp = endp;
2091 endp->dequeueing = 0;
2092 endp->edset_flush = 0;
2095 endp->endp_number = endp_number;
2097 endp->hep = urb->ep;
2098 u132_endp_init_kref(u132, endp);
2099 u132_endp_get_kref(u132, endp);
2100 if (usb_addr == 0) {
2101 u8 address = u132->addr[usb_addr].address;
2102 struct u132_udev *udev = &u132->udev[address];
2103 endp->udev_number = address;
2104 endp->usb_addr = usb_addr;
2105 endp->usb_endp = usb_endp;
2108 endp->pipetype = usb_pipetype(urb->pipe);
2109 u132_udev_init_kref(u132, udev);
2110 u132_udev_get_kref(u132, udev);
2111 udev->endp_number_in[usb_endp] = endp_number;
2112 udev->endp_number_out[usb_endp] = endp_number;
2114 endp->queue_size = 1;
2115 endp->queue_last = 0;
2116 endp->queue_next = 0;
2117 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2118 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2119 u132_endp_queue_work(u132, endp, 0);
2121 } else { /*(usb_addr > 0) */
2122 u8 address = u132->addr[usb_addr].address;
2123 struct u132_udev *udev = &u132->udev[address];
2124 endp->udev_number = address;
2125 endp->usb_addr = usb_addr;
2126 endp->usb_endp = usb_endp;
2129 endp->pipetype = usb_pipetype(urb->pipe);
2130 u132_udev_get_kref(u132, udev);
2131 udev->enumeration = 2;
2132 udev->endp_number_in[usb_endp] = endp_number;
2133 udev->endp_number_out[usb_endp] = endp_number;
2135 endp->queue_size = 1;
2136 endp->queue_last = 0;
2137 endp->queue_next = 0;
2138 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2139 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2140 u132_endp_queue_work(u132, endp, 0);
2145 static int queue_control_on_old_endpoint(struct u132 *u132,
2147 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2150 if (usb_addr == 0) {
2151 if (usb_pipein(urb->pipe)) {
2153 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2154 endp->urb_list[ENDP_QUEUE_MASK &
2155 endp->queue_last++] = urb;
2157 struct u132_urbq *urbq =
2158 kmalloc(sizeof(struct u132_urbq),
2161 endp->queue_size -= 1;
2164 list_add_tail(&urbq->urb_more,
2170 } else { /* usb_pipeout(urb->pipe) */
2171 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2172 int I = MAX_U132_UDEVS;
2175 struct u132_udev *udev = &u132->udev[++i];
2176 if (udev->usb_device) {
2179 udev->enumeration = 1;
2180 u132->addr[0].address = i;
2181 endp->udev_number = i;
2182 udev->udev_number = i;
2183 udev->usb_addr = usb_dev->devnum;
2184 u132_udev_init_kref(u132, udev);
2185 udev->endp_number_in[usb_endp] =
2187 u132_udev_get_kref(u132, udev);
2188 udev->endp_number_out[usb_endp] =
2190 udev->usb_device = usb_dev;
2191 ((u8 *) (urb->setup_packet))[2] =
2193 u132_udev_get_kref(u132, udev);
2198 dev_err(&u132->platform_dev->dev, "run out of d"
2203 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2204 endp->urb_list[ENDP_QUEUE_MASK &
2205 endp->queue_last++] = urb;
2207 struct u132_urbq *urbq =
2208 kmalloc(sizeof(struct u132_urbq),
2211 endp->queue_size -= 1;
2214 list_add_tail(&urbq->urb_more,
2221 } else { /*(usb_addr > 0) */
2222 u8 address = u132->addr[usb_addr].address;
2223 struct u132_udev *udev = &u132->udev[address];
2225 if (udev->enumeration != 2)
2226 udev->enumeration = 2;
2227 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2228 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2231 struct u132_urbq *urbq =
2232 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2234 endp->queue_size -= 1;
2237 list_add_tail(&urbq->urb_more, &endp->urb_more);
2245 static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2248 struct u132 *u132 = hcd_to_u132(hcd);
2249 if (irqs_disabled()) {
2250 if (__GFP_WAIT & mem_flags) {
2251 printk(KERN_ERR "invalid context for function that migh"
2256 if (u132->going > 1) {
2257 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2260 } else if (u132->going > 0) {
2261 dev_err(&u132->platform_dev->dev, "device is being removed "
2265 u8 usb_addr = usb_pipedevice(urb->pipe);
2266 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2267 struct usb_device *usb_dev = urb->dev;
2268 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2269 u8 address = u132->addr[usb_addr].address;
2270 struct u132_udev *udev = &u132->udev[address];
2271 struct u132_endp *endp = urb->ep->hcpriv;
2272 urb->actual_length = 0;
2276 spin_lock_irqsave(&endp->queue_lock.slock,
2278 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2280 retval = queue_int_on_old_endpoint(
2286 usb_hcd_unlink_urb_from_ep(
2289 spin_unlock_irqrestore(&endp->queue_lock.slock,
2294 u132_endp_queue_work(u132, endp,
2295 msecs_to_jiffies(urb->interval))
2299 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2301 } else { /*(endp == NULL) */
2302 return create_endpoint_and_queue_int(u132, udev,
2303 urb, usb_dev, usb_addr,
2304 usb_endp, address, mem_flags);
2306 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2307 dev_err(&u132->platform_dev->dev, "the hardware does no"
2308 "t support PIPE_ISOCHRONOUS\n");
2310 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2311 u8 address = u132->addr[usb_addr].address;
2312 struct u132_udev *udev = &u132->udev[address];
2313 struct u132_endp *endp = urb->ep->hcpriv;
2314 urb->actual_length = 0;
2318 spin_lock_irqsave(&endp->queue_lock.slock,
2320 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2322 retval = queue_bulk_on_old_endpoint(
2328 usb_hcd_unlink_urb_from_ep(
2331 spin_unlock_irqrestore(&endp->queue_lock.slock,
2336 u132_endp_queue_work(u132, endp, 0);
2339 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2342 return create_endpoint_and_queue_bulk(u132,
2343 udev, urb, usb_dev, usb_addr,
2344 usb_endp, address, mem_flags);
2346 struct u132_endp *endp = urb->ep->hcpriv;
2348 u8 *b = urb->setup_packet;
2350 char data[30 * 3 + 4];
2352 int m = (sizeof(data) - 1) / 3;
2355 while (urb_size-- > 0) {
2357 } else if (i++ < m) {
2358 int w = sprintf(d, " %02X", *b++);
2362 d += sprintf(d, " ..");
2367 spin_lock_irqsave(&endp->queue_lock.slock,
2369 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2371 retval = queue_control_on_old_endpoint(
2376 usb_hcd_unlink_urb_from_ep(
2379 spin_unlock_irqrestore(&endp->queue_lock.slock,
2384 u132_endp_queue_work(u132, endp, 0);
2387 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2390 return create_endpoint_and_queue_control(u132,
2391 urb, usb_dev, usb_addr, usb_endp,
2397 static int dequeue_from_overflow_chain(struct u132 *u132,
2398 struct u132_endp *endp, struct urb *urb)
2400 struct list_head *scan;
2401 struct list_head *head = &endp->urb_more;
2402 list_for_each(scan, head) {
2403 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2405 if (urbq->urb == urb) {
2406 struct usb_hcd *hcd = u132_to_hcd(u132);
2408 endp->queue_size -= 1;
2409 urb->error_count = 0;
2410 usb_hcd_giveback_urb(hcd, urb, 0);
2415 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2416 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2417 "\n", urb, endp->endp_number, endp, endp->ring->number,
2418 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2419 endp->usb_endp, endp->usb_addr, endp->queue_size,
2420 endp->queue_next, endp->queue_last);
2424 static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2425 struct urb *urb, int status)
2430 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2431 rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status);
2433 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2436 if (endp->queue_size == 0) {
2437 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2438 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2439 endp->endp_number, endp, endp->ring->number,
2440 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2441 endp->usb_endp, endp->usb_addr);
2442 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2445 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2447 endp->dequeueing = 1;
2448 endp->edset_flush = 1;
2449 u132_endp_queue_work(u132, endp, 0);
2450 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2453 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2454 u132_hcd_abandon_urb(u132, endp, urb, status);
2459 u16 queue_size = endp->queue_size;
2460 u16 queue_scan = endp->queue_next;
2461 struct urb **urb_slot = NULL;
2462 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2463 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2465 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2471 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2472 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2474 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2478 struct usb_hcd *hcd = u132_to_hcd(u132);
2480 usb_hcd_unlink_urb_from_ep(hcd, urb);
2481 endp->queue_size -= 1;
2482 if (list_empty(&endp->urb_more)) {
2483 spin_unlock_irqrestore(&endp->queue_lock.slock,
2486 struct list_head *next = endp->urb_more.next;
2487 struct u132_urbq *urbq = list_entry(next,
2488 struct u132_urbq, urb_more);
2490 *urb_slot = urbq->urb;
2491 spin_unlock_irqrestore(&endp->queue_lock.slock,
2494 } urb->error_count = 0;
2495 usb_hcd_giveback_urb(hcd, urb, status);
2497 } else if (list_empty(&endp->urb_more)) {
2498 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2499 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2500 "=%d size=%d next=%04X last=%04X\n", urb,
2501 endp->endp_number, endp, endp->ring->number,
2502 endp->input ? 'I' : ' ',
2503 endp->output ? 'O' : ' ', endp->usb_endp,
2504 endp->usb_addr, endp->queue_size,
2505 endp->queue_next, endp->queue_last);
2506 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2511 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb);
2512 retval = dequeue_from_overflow_chain(u132, endp,
2514 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2520 static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2522 struct u132 *u132 = hcd_to_u132(hcd);
2523 if (u132->going > 2) {
2524 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2528 u8 usb_addr = usb_pipedevice(urb->pipe);
2529 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2530 u8 address = u132->addr[usb_addr].address;
2531 struct u132_udev *udev = &u132->udev[address];
2532 if (usb_pipein(urb->pipe)) {
2533 u8 endp_number = udev->endp_number_in[usb_endp];
2534 struct u132_endp *endp = u132->endp[endp_number - 1];
2535 return u132_endp_urb_dequeue(u132, endp, urb, status);
2537 u8 endp_number = udev->endp_number_out[usb_endp];
2538 struct u132_endp *endp = u132->endp[endp_number - 1];
2539 return u132_endp_urb_dequeue(u132, endp, urb, status);
2544 static void u132_endpoint_disable(struct usb_hcd *hcd,
2545 struct usb_host_endpoint *hep)
2547 struct u132 *u132 = hcd_to_u132(hcd);
2548 if (u132->going > 2) {
2549 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2550 ") has been removed %d\n", u132, hcd, hep,
2553 struct u132_endp *endp = hep->hcpriv;
2555 u132_endp_put_kref(u132, endp);
2559 static int u132_get_frame(struct usb_hcd *hcd)
2561 struct u132 *u132 = hcd_to_u132(hcd);
2562 if (u132->going > 1) {
2563 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2566 } else if (u132->going > 0) {
2567 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2571 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2577 static int u132_roothub_descriptor(struct u132 *u132,
2578 struct usb_hub_descriptor *desc)
2584 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2587 desc->bDescriptorType = 0x29;
2588 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2589 desc->bHubContrCurrent = 0;
2590 desc->bNbrPorts = u132->num_ports;
2591 temp = 1 + (u132->num_ports / 8);
2592 desc->bDescLength = 7 + 2 * temp;
2594 if (rh_a & RH_A_NPS)
2596 if (rh_a & RH_A_PSM)
2598 if (rh_a & RH_A_NOCP)
2600 else if (rh_a & RH_A_OCPM)
2602 desc->wHubCharacteristics = cpu_to_le16(temp);
2603 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2606 memset(desc->u.hs.DeviceRemovable, 0xff,
2607 sizeof(desc->u.hs.DeviceRemovable));
2608 desc->u.hs.DeviceRemovable[0] = rh_b & RH_B_DR;
2609 if (u132->num_ports > 7) {
2610 desc->u.hs.DeviceRemovable[1] = (rh_b & RH_B_DR) >> 8;
2611 desc->u.hs.DeviceRemovable[2] = 0xff;
2613 desc->u.hs.DeviceRemovable[1] = 0xff;
2617 static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2620 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2621 *desc = cpu_to_le32(rh_status);
2625 static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2627 if (wIndex == 0 || wIndex > u132->num_ports) {
2630 int port = wIndex - 1;
2631 u32 rh_portstatus = -1;
2632 int ret_portstatus = u132_read_pcimem(u132,
2633 roothub.portstatus[port], &rh_portstatus);
2634 *desc = cpu_to_le32(rh_portstatus);
2635 if (*(u16 *) (desc + 2)) {
2636 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2637 "ge = %08X\n", port, *desc);
2639 return ret_portstatus;
2644 /* this timer value might be vendor-specific ... */
2645 #define PORT_RESET_HW_MSEC 10
2646 #define PORT_RESET_MSEC 10
2647 /* wrap-aware logic morphed from <linux/jiffies.h> */
2648 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2649 static int u132_roothub_portreset(struct u132 *u132, int port_index)
2655 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2659 reset_done = now + PORT_RESET_MSEC;
2663 retval = u132_read_pcimem(u132,
2664 roothub.portstatus[port_index], &portstat);
2667 if (RH_PS_PRS & portstat)
2671 } while (tick_before(now, reset_done));
2672 if (RH_PS_PRS & portstat)
2674 if (RH_PS_CCS & portstat) {
2675 if (RH_PS_PRSC & portstat) {
2676 retval = u132_write_pcimem(u132,
2677 roothub.portstatus[port_index],
2683 break; /* start the next reset,
2684 sleep till it's probably done */
2685 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2689 msleep(PORT_RESET_HW_MSEC);
2690 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2694 } while (tick_before(now, reset_done));
2698 static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2701 if (wIndex == 0 || wIndex > u132->num_ports) {
2705 int port_index = wIndex - 1;
2706 struct u132_port *port = &u132->port[port_index];
2707 port->Status &= ~(1 << wValue);
2709 case USB_PORT_FEAT_SUSPEND:
2710 retval = u132_write_pcimem(u132,
2711 roothub.portstatus[port_index], RH_PS_PSS);
2715 case USB_PORT_FEAT_POWER:
2716 retval = u132_write_pcimem(u132,
2717 roothub.portstatus[port_index], RH_PS_PPS);
2721 case USB_PORT_FEAT_RESET:
2722 retval = u132_roothub_portreset(u132, port_index);
2732 static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2735 if (wIndex == 0 || wIndex > u132->num_ports) {
2738 int port_index = wIndex - 1;
2741 struct u132_port *port = &u132->port[port_index];
2742 port->Status &= ~(1 << wValue);
2744 case USB_PORT_FEAT_ENABLE:
2747 case USB_PORT_FEAT_C_ENABLE:
2750 case USB_PORT_FEAT_SUSPEND:
2752 if ((u132->hc_control & OHCI_CTRL_HCFS)
2754 dev_err(&u132->platform_dev->dev, "TODO resume_"
2758 case USB_PORT_FEAT_C_SUSPEND:
2761 case USB_PORT_FEAT_POWER:
2764 case USB_PORT_FEAT_C_CONNECTION:
2767 case USB_PORT_FEAT_C_OVER_CURRENT:
2770 case USB_PORT_FEAT_C_RESET:
2776 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2785 /* the virtual root hub timer IRQ checks for hub status*/
2786 static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2788 struct u132 *u132 = hcd_to_u132(hcd);
2789 if (u132->going > 1) {
2790 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2791 "ed %d\n", hcd, u132->going);
2793 } else if (u132->going > 0) {
2794 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2798 int i, changed = 0, length = 1;
2799 if (u132->flags & OHCI_QUIRK_AMD756) {
2800 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2801 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2802 "ereads as NDP=%d\n",
2803 u132->hc_roothub_a & RH_A_NDP);
2807 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC))
2808 buf[0] = changed = 1;
2811 if (u132->num_ports > 7) {
2815 for (i = 0; i < u132->num_ports; i++) {
2816 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2817 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2821 buf[0] |= 1 << (i + 1);
2823 buf[1] |= 1 << (i - 7);
2826 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS))
2829 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS))
2833 return changed ? length : 0;
2837 static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2838 u16 wIndex, char *buf, u16 wLength)
2840 struct u132 *u132 = hcd_to_u132(hcd);
2841 if (u132->going > 1) {
2842 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2845 } else if (u132->going > 0) {
2846 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2850 mutex_lock(&u132->sw_lock);
2852 case ClearHubFeature:
2854 case C_HUB_OVER_CURRENT:
2855 case C_HUB_LOCAL_POWER:
2863 case C_HUB_OVER_CURRENT:
2864 case C_HUB_LOCAL_POWER:
2870 case ClearPortFeature:{
2871 retval = u132_roothub_clearportfeature(u132,
2877 case GetHubDescriptor:{
2878 retval = u132_roothub_descriptor(u132,
2879 (struct usb_hub_descriptor *)buf);
2885 retval = u132_roothub_status(u132,
2891 case GetPortStatus:{
2892 retval = u132_roothub_portstatus(u132,
2893 (__le32 *) buf, wIndex);
2898 case SetPortFeature:{
2899 retval = u132_roothub_setportfeature(u132,
2915 mutex_unlock(&u132->sw_lock);
2920 static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2922 struct u132 *u132 = hcd_to_u132(hcd);
2923 if (u132->going > 1) {
2924 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2927 } else if (u132->going > 0) {
2928 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2936 static int u132_bus_suspend(struct usb_hcd *hcd)
2938 struct u132 *u132 = hcd_to_u132(hcd);
2939 if (u132->going > 1) {
2940 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2943 } else if (u132->going > 0) {
2944 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2950 static int u132_bus_resume(struct usb_hcd *hcd)
2952 struct u132 *u132 = hcd_to_u132(hcd);
2953 if (u132->going > 1) {
2954 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2957 } else if (u132->going > 0) {
2958 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2965 #define u132_bus_suspend NULL
2966 #define u132_bus_resume NULL
2968 static struct hc_driver u132_hc_driver = {
2969 .description = hcd_name,
2970 .hcd_priv_size = sizeof(struct u132),
2972 .flags = HCD_USB11 | HCD_MEMORY,
2973 .reset = u132_hcd_reset,
2974 .start = u132_hcd_start,
2975 .stop = u132_hcd_stop,
2976 .urb_enqueue = u132_urb_enqueue,
2977 .urb_dequeue = u132_urb_dequeue,
2978 .endpoint_disable = u132_endpoint_disable,
2979 .get_frame_number = u132_get_frame,
2980 .hub_status_data = u132_hub_status_data,
2981 .hub_control = u132_hub_control,
2982 .bus_suspend = u132_bus_suspend,
2983 .bus_resume = u132_bus_resume,
2984 .start_port_reset = u132_start_port_reset,
2988 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
2989 * is held for writing, thus this module must not call usb_remove_hcd()
2990 * synchronously - but instead should immediately stop activity to the
2991 * device and asynchronously call usb_remove_hcd()
2993 static int u132_remove(struct platform_device *pdev)
2995 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2997 struct u132 *u132 = hcd_to_u132(hcd);
2998 if (u132->going++ > 1) {
2999 dev_err(&u132->platform_dev->dev, "already being remove"
3003 int rings = MAX_U132_RINGS;
3004 int endps = MAX_U132_ENDPS;
3005 dev_err(&u132->platform_dev->dev, "removing device u132"
3006 ".%d\n", u132->sequence_num);
3008 mutex_lock(&u132->sw_lock);
3009 u132_monitor_cancel_work(u132);
3010 while (rings-- > 0) {
3011 struct u132_ring *ring = &u132->ring[rings];
3012 u132_ring_cancel_work(u132, ring);
3013 } while (endps-- > 0) {
3014 struct u132_endp *endp = u132->endp[endps];
3016 u132_endp_cancel_work(u132, endp);
3019 printk(KERN_INFO "removing device u132.%d\n",
3020 u132->sequence_num);
3021 mutex_unlock(&u132->sw_lock);
3022 usb_remove_hcd(hcd);
3023 u132_u132_put_kref(u132);
3030 static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3032 int rings = MAX_U132_RINGS;
3033 int ports = MAX_U132_PORTS;
3034 int addrs = MAX_U132_ADDRS;
3035 int udevs = MAX_U132_UDEVS;
3036 int endps = MAX_U132_ENDPS;
3037 u132->board = dev_get_platdata(&pdev->dev);
3038 u132->platform_dev = pdev;
3041 mutex_init(&u132->sw_lock);
3042 mutex_init(&u132->scheduler_lock);
3043 while (rings-- > 0) {
3044 struct u132_ring *ring = &u132->ring[rings];
3046 ring->number = rings + 1;
3048 ring->curr_endp = NULL;
3049 INIT_DELAYED_WORK(&ring->scheduler,
3050 u132_hcd_ring_work_scheduler);
3052 mutex_lock(&u132->sw_lock);
3053 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3054 while (ports-- > 0) {
3055 struct u132_port *port = &u132->port[ports];
3062 while (addrs-- > 0) {
3063 struct u132_addr *addr = &u132->addr[addrs];
3066 while (udevs-- > 0) {
3067 struct u132_udev *udev = &u132->udev[udevs];
3068 int i = ARRAY_SIZE(udev->endp_number_in);
3069 int o = ARRAY_SIZE(udev->endp_number_out);
3070 udev->usb_device = NULL;
3071 udev->udev_number = 0;
3073 udev->portnumber = 0;
3075 udev->endp_number_in[i] = 0;
3078 udev->endp_number_out[o] = 0;
3082 u132->endp[endps] = NULL;
3084 mutex_unlock(&u132->sw_lock);
3087 static int u132_probe(struct platform_device *pdev)
3089 struct usb_hcd *hcd;
3096 if (u132_exiting > 0)
3099 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3102 retval = ftdi_read_pcimem(pdev, control, &control);
3105 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3108 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3109 if (pdev->dev.dma_mask)
3112 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, dev_name(&pdev->dev));
3114 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3116 ftdi_elan_gone_away(pdev);
3119 struct u132 *u132 = hcd_to_u132(hcd);
3121 hcd->rsrc_start = 0;
3122 mutex_lock(&u132_module_lock);
3123 list_add_tail(&u132->u132_list, &u132_static_list);
3124 u132->sequence_num = ++u132_instances;
3125 mutex_unlock(&u132_module_lock);
3126 u132_u132_init_kref(u132);
3127 u132_initialise(u132, pdev);
3128 hcd->product_desc = "ELAN U132 Host Controller";
3129 retval = usb_add_hcd(hcd, 0, 0);
3131 dev_err(&u132->platform_dev->dev, "init error %d\n",
3133 u132_u132_put_kref(u132);
3136 device_wakeup_enable(hcd->self.controller);
3137 u132_monitor_queue_work(u132, 100);
3146 * for this device there's no useful distinction between the controller
3147 * and its root hub, except that the root hub only gets direct PM calls
3148 * when CONFIG_PM_RUNTIME is enabled.
3150 static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3152 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3153 struct u132 *u132 = hcd_to_u132(hcd);
3154 if (u132->going > 1) {
3155 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3158 } else if (u132->going > 0) {
3159 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3162 int retval = 0, ports;
3164 switch (state.event) {
3165 case PM_EVENT_FREEZE:
3166 retval = u132_bus_suspend(hcd);
3168 case PM_EVENT_SUSPEND:
3169 case PM_EVENT_HIBERNATE:
3170 ports = MAX_U132_PORTS;
3171 while (ports-- > 0) {
3172 port_power(u132, ports, 0);
3180 static int u132_resume(struct platform_device *pdev)
3182 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3183 struct u132 *u132 = hcd_to_u132(hcd);
3184 if (u132->going > 1) {
3185 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3188 } else if (u132->going > 0) {
3189 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3193 if (!u132->port[0].power) {
3194 int ports = MAX_U132_PORTS;
3195 while (ports-- > 0) {
3196 port_power(u132, ports, 1);
3200 retval = u132_bus_resume(hcd);
3207 #define u132_suspend NULL
3208 #define u132_resume NULL
3211 * this driver is loaded explicitly by ftdi_u132
3213 * the platform_driver struct is static because it is per type of module
3215 static struct platform_driver u132_platform_driver = {
3216 .probe = u132_probe,
3217 .remove = u132_remove,
3218 .suspend = u132_suspend,
3219 .resume = u132_resume,
3222 .owner = THIS_MODULE,
3225 static int __init u132_hcd_init(void)
3228 INIT_LIST_HEAD(&u132_static_list);
3231 mutex_init(&u132_module_lock);
3234 printk(KERN_INFO "driver %s\n", hcd_name);
3235 workqueue = create_singlethread_workqueue("u132");
3236 retval = platform_driver_register(&u132_platform_driver);
3241 module_init(u132_hcd_init);
3242 static void __exit u132_hcd_exit(void)
3246 mutex_lock(&u132_module_lock);
3248 mutex_unlock(&u132_module_lock);
3249 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3250 platform_device_unregister(u132->platform_dev);
3252 platform_driver_unregister(&u132_platform_driver);
3253 printk(KERN_INFO "u132-hcd driver deregistered\n");
3254 wait_event(u132_hcd_wait, u132_instances == 0);
3255 flush_workqueue(workqueue);
3256 destroy_workqueue(workqueue);
3260 module_exit(u132_hcd_exit);
3261 MODULE_LICENSE("GPL");
3262 MODULE_ALIAS("platform:u132_hcd");