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/config.h>
39 #include <linux/kernel.h>
40 #include <linux/module.h>
41 #include <linux/moduleparam.h>
42 #include <linux/delay.h>
43 #include <linux/ioport.h>
44 #include <linux/sched.h>
45 #include <linux/slab.h>
46 #include <linux/smp_lock.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/timer.h>
50 #include <linux/list.h>
51 #include <linux/interrupt.h>
52 #include <linux/usb.h>
53 #include <linux/workqueue.h>
54 #include <linux/platform_device.h>
55 #include <linux/pci_ids.h>
58 #include <asm/system.h>
59 #include <asm/byteorder.h>
60 #include "../core/hcd.h"
62 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
63 #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
65 MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
66 MODULE_DESCRIPTION("U132 USB Host Controller Driver");
67 MODULE_LICENSE("GPL");
68 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
69 INT_MODULE_PARM(testing, 0);
70 /* Some boards misreport power switching/overcurrent*/
71 static int distrust_firmware = 1;
72 module_param(distrust_firmware, bool, 0);
73 MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
75 DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
77 * u132_module_lock exists to protect access to global variables
80 static struct semaphore u132_module_lock;
81 static int u132_exiting = 0;
82 static int u132_instances = 0;
83 static struct list_head u132_static_list;
85 * end of the global variables protected by u132_module_lock
87 static struct workqueue_struct *workqueue;
88 #define MAX_U132_PORTS 7
89 #define MAX_U132_ADDRS 128
90 #define MAX_U132_UDEVS 4
91 #define MAX_U132_ENDPS 100
92 #define MAX_U132_RINGS 4
93 static const char *cc_to_text[16] = {
123 struct usb_device *usb_device;
128 u8 endp_number_in[16];
129 u8 endp_number_out[16];
131 #define ENDP_QUEUE_SHIFT 3
132 #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
133 #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
135 struct list_head urb_more;
148 struct list_head endp_ring;
149 struct u132_ring *ring;
150 unsigned toggle_bits:2;
156 unsigned dequeueing:1;
157 unsigned edset_flush:1;
158 unsigned spare_bits:14;
159 unsigned long jiffies;
160 struct usb_host_endpoint *hep;
161 struct u132_spin queue_lock;
165 struct urb *urb_list[ENDP_QUEUE_SIZE];
166 struct list_head urb_more;
167 struct work_struct scheduler;
174 struct u132_endp *curr_endp;
175 struct work_struct scheduler;
177 #define OHCI_QUIRK_AMD756 0x01
178 #define OHCI_QUIRK_SUPERIO 0x02
179 #define OHCI_QUIRK_INITRESET 0x04
180 #define OHCI_BIG_ENDIAN 0x08
181 #define OHCI_QUIRK_ZFMICRO 0x10
184 struct list_head u132_list;
185 struct semaphore sw_lock;
186 struct semaphore scheduler_lock;
187 struct u132_platform_data *board;
188 struct platform_device *platform_dev;
189 struct u132_ring ring[MAX_U132_RINGS];
197 u32 hc_roothub_status;
199 u32 hc_roothub_portstatus[MAX_ROOT_PORTS];
201 unsigned long next_statechange;
202 struct work_struct 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];
209 int usb_ftdi_elan_read_reg(struct platform_device *pdev, u32 *data);
210 int usb_ftdi_elan_read_pcimem(struct platform_device *pdev, u8 addressofs,
211 u8 width, u32 *data);
212 int usb_ftdi_elan_write_pcimem(struct platform_device *pdev, u8 addressofs,
215 * these can not be inlines because we need the structure offset!!
216 * Does anyone have a better way?????
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 #define u132_write_pcimem_byte(u132, member, data) \
225 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
226 ohci_regs, member), 0x0e, data);
227 static inline struct u132 *udev_to_u132(struct u132_udev *udev)
229 u8 udev_number = udev->udev_number;
230 return container_of(udev, struct u132, udev[udev_number]);
233 static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd)
235 return (struct u132 *)(hcd->hcd_priv);
238 static inline struct usb_hcd *u132_to_hcd(struct u132 *u132)
240 return container_of((void *)u132, struct usb_hcd, hcd_priv);
243 static inline void u132_disable(struct u132 *u132)
245 u132_to_hcd(u132)->state = HC_STATE_HALT;
249 #define kref_to_u132(d) container_of(d, struct u132, kref)
250 #define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref)
251 #define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref)
252 #include "../misc/usb_u132.h"
253 static const char hcd_name[] = "u132_hcd";
254 #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
255 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
256 USB_PORT_STAT_C_RESET) << 16)
257 static void u132_hcd_delete(struct kref *kref)
259 struct u132 *u132 = kref_to_u132(kref);
260 struct platform_device *pdev = u132->platform_dev;
261 struct usb_hcd *hcd = u132_to_hcd(u132);
263 down(&u132_module_lock);
264 list_del_init(&u132->u132_list);
266 up(&u132_module_lock);
267 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
268 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
272 static inline void u132_u132_put_kref(struct u132 *u132)
274 kref_put(&u132->kref, u132_hcd_delete);
277 static inline void u132_u132_init_kref(struct u132 *u132)
279 kref_init(&u132->kref);
282 static void u132_udev_delete(struct kref *kref)
284 struct u132_udev *udev = kref_to_u132_udev(kref);
285 udev->udev_number = 0;
286 udev->usb_device = NULL;
288 udev->enumeration = 0;
291 static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev)
293 kref_put(&udev->kref, u132_udev_delete);
296 static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev)
298 kref_get(&udev->kref);
301 static inline void u132_udev_init_kref(struct u132 *u132,
302 struct u132_udev *udev)
304 kref_init(&udev->kref);
307 static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring)
309 kref_put(&u132->kref, u132_hcd_delete);
312 static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring,
316 if (queue_delayed_work(workqueue, &ring->scheduler, delta))
318 } else if (queue_work(workqueue, &ring->scheduler))
320 kref_put(&u132->kref, u132_hcd_delete);
324 static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
327 kref_get(&u132->kref);
328 u132_ring_requeue_work(u132, ring, delta);
332 static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
334 if (cancel_delayed_work(&ring->scheduler)) {
335 kref_put(&u132->kref, u132_hcd_delete);
339 static void u132_endp_delete(struct kref *kref)
341 struct u132_endp *endp = kref_to_u132_endp(kref);
342 struct u132 *u132 = endp->u132;
343 u8 usb_addr = endp->usb_addr;
344 u8 usb_endp = endp->usb_endp;
345 u8 address = u132->addr[usb_addr].address;
346 struct u132_udev *udev = &u132->udev[address];
347 u8 endp_number = endp->endp_number;
348 struct usb_host_endpoint *hep = endp->hep;
349 struct u132_ring *ring = endp->ring;
350 struct list_head *head = &endp->endp_ring;
352 if (endp == ring->curr_endp) {
353 if (list_empty(head)) {
354 ring->curr_endp = NULL;
357 struct u132_endp *next_endp = list_entry(head->next,
358 struct u132_endp, endp_ring);
359 ring->curr_endp = next_endp;
364 udev->endp_number_in[usb_endp] = 0;
365 u132_udev_put_kref(u132, udev);
368 udev->endp_number_out[usb_endp] = 0;
369 u132_udev_put_kref(u132, udev);
371 u132->endp[endp_number - 1] = NULL;
374 u132_u132_put_kref(u132);
377 static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp)
379 kref_put(&endp->kref, u132_endp_delete);
382 static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp)
384 kref_get(&endp->kref);
387 static inline void u132_endp_init_kref(struct u132 *u132,
388 struct u132_endp *endp)
390 kref_init(&endp->kref);
391 kref_get(&u132->kref);
394 static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
398 if (queue_delayed_work(workqueue, &endp->scheduler, delta))
399 kref_get(&endp->kref);
400 } else if (queue_work(workqueue, &endp->scheduler))
401 kref_get(&endp->kref);
405 static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp)
407 if (cancel_delayed_work(&endp->scheduler))
408 kref_put(&endp->kref, u132_endp_delete);
411 static inline void u132_monitor_put_kref(struct u132 *u132)
413 kref_put(&u132->kref, u132_hcd_delete);
416 static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta)
419 if (queue_delayed_work(workqueue, &u132->monitor, delta)) {
420 kref_get(&u132->kref);
422 } else if (queue_work(workqueue, &u132->monitor))
423 kref_get(&u132->kref);
427 static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta)
430 if (queue_delayed_work(workqueue, &u132->monitor, delta))
432 } else if (queue_work(workqueue, &u132->monitor))
434 kref_put(&u132->kref, u132_hcd_delete);
438 static void u132_monitor_cancel_work(struct u132 *u132)
440 if (cancel_delayed_work(&u132->monitor))
441 kref_put(&u132->kref, u132_hcd_delete);
444 static int read_roothub_info(struct u132 *u132)
448 retval = u132_read_pcimem(u132, revision, &revision);
450 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
453 } else if ((revision & 0xFF) == 0x10) {
454 } else if ((revision & 0xFF) == 0x11) {
456 dev_err(&u132->platform_dev->dev, "device revision is not valid"
457 " %08X\n", revision);
460 retval = u132_read_pcimem(u132, control, &u132->hc_control);
462 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
466 retval = u132_read_pcimem(u132, roothub.status,
467 &u132->hc_roothub_status);
469 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
470 "g roothub.status\n", retval);
473 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a);
475 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
476 "g roothub.a\n", retval);
480 int I = u132->num_ports;
483 retval = u132_read_pcimem(u132, roothub.portstatus[i],
484 &u132->hc_roothub_portstatus[i]);
486 dev_err(&u132->platform_dev->dev, "error %d acc"
487 "essing device roothub.portstatus[%d]\n"
497 static void u132_hcd_monitor_work(void *data)
499 struct u132 *u132 = data;
500 if (u132->going > 1) {
501 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
503 u132_monitor_put_kref(u132);
505 } else if (u132->going > 0) {
506 dev_err(&u132->platform_dev->dev, "device is being removed\n");
507 u132_monitor_put_kref(u132);
511 down(&u132->sw_lock);
512 retval = read_roothub_info(u132);
514 struct usb_hcd *hcd = u132_to_hcd(u132);
519 ftdi_elan_gone_away(u132->platform_dev);
520 u132_monitor_put_kref(u132);
523 u132_monitor_requeue_work(u132, 500);
530 static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
531 struct urb *urb, int status)
533 struct u132_ring *ring;
535 struct usb_hcd *hcd = u132_to_hcd(u132);
536 urb->error_count = 0;
537 urb->status = status;
539 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
540 endp->queue_next += 1;
541 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
543 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
545 struct list_head *next = endp->urb_more.next;
546 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
549 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
552 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
554 } down(&u132->scheduler_lock);
557 u132_ring_cancel_work(u132, ring);
558 u132_ring_queue_work(u132, ring, 0);
559 up(&u132->scheduler_lock);
560 u132_endp_put_kref(u132, endp);
561 usb_hcd_giveback_urb(hcd, urb, NULL);
565 static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp,
566 struct urb *urb, int status)
568 u132_endp_put_kref(u132, endp);
571 static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
572 struct urb *urb, int status)
575 struct usb_hcd *hcd = u132_to_hcd(u132);
576 urb->error_count = 0;
577 urb->status = status;
579 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
580 endp->queue_next += 1;
581 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
583 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
585 struct list_head *next = endp->urb_more.next;
586 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
589 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
592 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
594 } usb_hcd_giveback_urb(hcd, urb, NULL);
598 static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
599 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
600 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
601 int toggle_bits, int error_count, int condition_code, int repeat_number,
602 int halted, int skipped, int actual, int non_null))
604 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
605 urb, address, endp->usb_endp, toggle_bits, callback);
608 static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
609 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
610 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
611 int toggle_bits, int error_count, int condition_code, int repeat_number,
612 int halted, int skipped, int actual, int non_null))
614 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
615 urb, address, endp->usb_endp, toggle_bits, callback);
618 static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
619 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
620 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
621 int toggle_bits, int error_count, int condition_code, int repeat_number,
622 int halted, int skipped, int actual, int non_null))
624 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
625 endp, urb, address, endp->usb_endp, toggle_bits, callback);
628 static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
629 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
630 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
631 int toggle_bits, int error_count, int condition_code, int repeat_number,
632 int halted, int skipped, int actual, int non_null))
634 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
635 endp, urb, address, endp->usb_endp, toggle_bits, callback);
640 * must not LOCK sw_lock
643 static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
644 int len, int toggle_bits, int error_count, int condition_code,
645 int repeat_number, int halted, int skipped, int actual, int non_null)
647 struct u132_endp *endp = data;
648 struct u132 *u132 = endp->u132;
649 u8 address = u132->addr[endp->usb_addr].address;
650 struct u132_udev *udev = &u132->udev[address];
651 down(&u132->scheduler_lock);
652 if (u132->going > 1) {
653 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
655 up(&u132->scheduler_lock);
656 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
658 } else if (endp->dequeueing) {
659 endp->dequeueing = 0;
660 up(&u132->scheduler_lock);
661 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
663 } else if (u132->going > 0) {
664 dev_err(&u132->platform_dev->dev, "device is being removed urb="
665 "%p status=%d\n", urb, urb->status);
666 up(&u132->scheduler_lock);
667 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
669 } else if (urb->status == -EINPROGRESS) {
670 struct u132_ring *ring = endp->ring;
671 u8 *u = urb->transfer_buffer + urb->actual_length;
677 urb->actual_length += len;
678 if ((condition_code == TD_CC_NOERROR) &&
679 (urb->transfer_buffer_length > urb->actual_length)) {
680 endp->toggle_bits = toggle_bits;
681 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
683 if (urb->actual_length > 0) {
685 up(&u132->scheduler_lock);
686 retval = edset_single(u132, ring, endp, urb,
687 address, endp->toggle_bits,
688 u132_hcd_interrupt_recv);
691 u132_hcd_giveback_urb(u132, endp, urb,
696 endp->jiffies = jiffies +
697 msecs_to_jiffies(urb->interval);
698 u132_ring_cancel_work(u132, ring);
699 u132_ring_queue_work(u132, ring, 0);
700 up(&u132->scheduler_lock);
701 u132_endp_put_kref(u132, endp);
704 } else if ((condition_code == TD_DATAUNDERRUN) &&
705 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
706 endp->toggle_bits = toggle_bits;
707 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
709 up(&u132->scheduler_lock);
710 u132_hcd_giveback_urb(u132, endp, urb, 0);
713 if (condition_code == TD_CC_NOERROR) {
714 endp->toggle_bits = toggle_bits;
715 usb_settoggle(udev->usb_device, endp->usb_endp,
717 } else if (condition_code == TD_CC_STALL) {
718 endp->toggle_bits = 0x2;
719 usb_settoggle(udev->usb_device, endp->usb_endp,
722 endp->toggle_bits = 0x2;
723 usb_settoggle(udev->usb_device, endp->usb_endp,
725 dev_err(&u132->platform_dev->dev, "urb=%p givin"
726 "g back INTERRUPT %s\n", urb,
727 cc_to_text[condition_code]);
729 up(&u132->scheduler_lock);
730 u132_hcd_giveback_urb(u132, endp, urb,
731 cc_to_error[condition_code]);
735 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
736 "s=%d\n", urb, urb->status);
737 up(&u132->scheduler_lock);
738 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
743 static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
744 int len, int toggle_bits, int error_count, int condition_code,
745 int repeat_number, int halted, int skipped, int actual, int non_null)
747 struct u132_endp *endp = data;
748 struct u132 *u132 = endp->u132;
749 u8 address = u132->addr[endp->usb_addr].address;
750 down(&u132->scheduler_lock);
751 if (u132->going > 1) {
752 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
754 up(&u132->scheduler_lock);
755 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
757 } else if (endp->dequeueing) {
758 endp->dequeueing = 0;
759 up(&u132->scheduler_lock);
760 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
762 } else if (u132->going > 0) {
763 dev_err(&u132->platform_dev->dev, "device is being removed urb="
764 "%p status=%d\n", urb, urb->status);
765 up(&u132->scheduler_lock);
766 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
768 } else if (urb->status == -EINPROGRESS) {
769 struct u132_ring *ring = endp->ring;
770 urb->actual_length += len;
771 endp->toggle_bits = toggle_bits;
772 if (urb->transfer_buffer_length > urb->actual_length) {
774 up(&u132->scheduler_lock);
775 retval = edset_output(u132, ring, endp, urb, address,
776 endp->toggle_bits, u132_hcd_bulk_output_sent);
779 u132_hcd_giveback_urb(u132, endp, urb, retval);
782 up(&u132->scheduler_lock);
783 u132_hcd_giveback_urb(u132, endp, urb, 0);
787 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
788 "s=%d\n", urb, urb->status);
789 up(&u132->scheduler_lock);
790 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
795 static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
796 int len, int toggle_bits, int error_count, int condition_code,
797 int repeat_number, int halted, int skipped, int actual, int non_null)
799 struct u132_endp *endp = data;
800 struct u132 *u132 = endp->u132;
801 u8 address = u132->addr[endp->usb_addr].address;
802 struct u132_udev *udev = &u132->udev[address];
803 down(&u132->scheduler_lock);
804 if (u132->going > 1) {
805 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
807 up(&u132->scheduler_lock);
808 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
810 } else if (endp->dequeueing) {
811 endp->dequeueing = 0;
812 up(&u132->scheduler_lock);
813 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
815 } else if (u132->going > 0) {
816 dev_err(&u132->platform_dev->dev, "device is being removed urb="
817 "%p status=%d\n", urb, urb->status);
818 up(&u132->scheduler_lock);
819 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
821 } else if (urb->status == -EINPROGRESS) {
822 struct u132_ring *ring = endp->ring;
823 u8 *u = urb->transfer_buffer + urb->actual_length;
829 urb->actual_length += len;
830 if ((condition_code == TD_CC_NOERROR) &&
831 (urb->transfer_buffer_length > urb->actual_length)) {
833 endp->toggle_bits = toggle_bits;
834 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
836 up(&u132->scheduler_lock);
837 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
838 ring->number, endp, urb, address,
839 endp->usb_endp, endp->toggle_bits,
840 u132_hcd_bulk_input_recv);
843 u132_hcd_giveback_urb(u132, endp, urb, retval);
845 } else if (condition_code == TD_CC_NOERROR) {
846 endp->toggle_bits = toggle_bits;
847 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
849 up(&u132->scheduler_lock);
850 u132_hcd_giveback_urb(u132, endp, urb,
851 cc_to_error[condition_code]);
853 } else if ((condition_code == TD_DATAUNDERRUN) &&
854 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
855 endp->toggle_bits = toggle_bits;
856 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
858 up(&u132->scheduler_lock);
859 u132_hcd_giveback_urb(u132, endp, urb, 0);
861 } else if (condition_code == TD_DATAUNDERRUN) {
862 endp->toggle_bits = toggle_bits;
863 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
865 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
866 ") giving back BULK IN %s\n", urb,
867 cc_to_text[condition_code]);
868 up(&u132->scheduler_lock);
869 u132_hcd_giveback_urb(u132, endp, urb, 0);
871 } else if (condition_code == TD_CC_STALL) {
872 endp->toggle_bits = 0x2;
873 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
874 up(&u132->scheduler_lock);
875 u132_hcd_giveback_urb(u132, endp, urb,
876 cc_to_error[condition_code]);
879 endp->toggle_bits = 0x2;
880 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
881 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
882 "ULK IN code=%d %s\n", urb, condition_code,
883 cc_to_text[condition_code]);
884 up(&u132->scheduler_lock);
885 u132_hcd_giveback_urb(u132, endp, urb,
886 cc_to_error[condition_code]);
890 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
891 "s=%d\n", urb, urb->status);
892 up(&u132->scheduler_lock);
893 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
898 static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
899 int len, int toggle_bits, int error_count, int condition_code,
900 int repeat_number, int halted, int skipped, int actual, int non_null)
902 struct u132_endp *endp = data;
903 struct u132 *u132 = endp->u132;
904 down(&u132->scheduler_lock);
905 if (u132->going > 1) {
906 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
908 up(&u132->scheduler_lock);
909 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
911 } else if (endp->dequeueing) {
912 endp->dequeueing = 0;
913 up(&u132->scheduler_lock);
914 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
916 } else if (u132->going > 0) {
917 dev_err(&u132->platform_dev->dev, "device is being removed urb="
918 "%p status=%d\n", urb, urb->status);
919 up(&u132->scheduler_lock);
920 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
922 } else if (urb->status == -EINPROGRESS) {
923 up(&u132->scheduler_lock);
924 u132_hcd_giveback_urb(u132, endp, urb, 0);
927 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
928 "s=%d\n", urb, urb->status);
929 up(&u132->scheduler_lock);
930 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
935 static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
936 int len, int toggle_bits, int error_count, int condition_code,
937 int repeat_number, int halted, int skipped, int actual, int non_null)
939 struct u132_endp *endp = data;
940 struct u132 *u132 = endp->u132;
941 u8 address = u132->addr[endp->usb_addr].address;
942 down(&u132->scheduler_lock);
943 if (u132->going > 1) {
944 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
946 up(&u132->scheduler_lock);
947 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
949 } else if (endp->dequeueing) {
950 endp->dequeueing = 0;
951 up(&u132->scheduler_lock);
952 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
954 } else if (u132->going > 0) {
955 dev_err(&u132->platform_dev->dev, "device is being removed urb="
956 "%p status=%d\n", urb, urb->status);
957 up(&u132->scheduler_lock);
958 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
960 } else if (urb->status == -EINPROGRESS) {
961 struct u132_ring *ring = endp->ring;
962 u8 *u = urb->transfer_buffer;
968 urb->actual_length = len;
969 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
970 TD_DATAUNDERRUN) && ((urb->transfer_flags &
971 URB_SHORT_NOT_OK) == 0))) {
973 up(&u132->scheduler_lock);
974 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
975 ring->number, endp, urb, address,
977 u132_hcd_configure_empty_sent);
980 u132_hcd_giveback_urb(u132, endp, urb, retval);
982 } else if (condition_code == TD_CC_STALL) {
983 up(&u132->scheduler_lock);
984 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
985 "NPUT STALL urb %p\n", urb);
986 u132_hcd_giveback_urb(u132, endp, urb,
987 cc_to_error[condition_code]);
990 up(&u132->scheduler_lock);
991 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
992 "PUT %s urb %p\n", cc_to_text[condition_code],
994 u132_hcd_giveback_urb(u132, endp, urb,
995 cc_to_error[condition_code]);
999 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1000 "s=%d\n", urb, urb->status);
1001 up(&u132->scheduler_lock);
1002 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1007 static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
1008 int len, int toggle_bits, int error_count, int condition_code,
1009 int repeat_number, int halted, int skipped, int actual, int non_null)
1011 struct u132_endp *endp = data;
1012 struct u132 *u132 = endp->u132;
1013 down(&u132->scheduler_lock);
1014 if (u132->going > 1) {
1015 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1017 up(&u132->scheduler_lock);
1018 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1020 } else if (endp->dequeueing) {
1021 endp->dequeueing = 0;
1022 up(&u132->scheduler_lock);
1023 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1025 } else if (u132->going > 0) {
1026 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1027 "%p status=%d\n", urb, urb->status);
1028 up(&u132->scheduler_lock);
1029 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1031 } else if (urb->status == -EINPROGRESS) {
1032 up(&u132->scheduler_lock);
1033 u132_hcd_giveback_urb(u132, endp, urb, 0);
1036 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1037 "s=%d\n", urb, urb->status);
1038 up(&u132->scheduler_lock);
1039 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1044 static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1045 int len, int toggle_bits, int error_count, int condition_code,
1046 int repeat_number, int halted, int skipped, int actual, int non_null)
1048 struct u132_endp *endp = data;
1049 struct u132 *u132 = endp->u132;
1050 u8 address = u132->addr[endp->usb_addr].address;
1051 down(&u132->scheduler_lock);
1052 if (u132->going > 1) {
1053 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1055 up(&u132->scheduler_lock);
1056 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1058 } else if (endp->dequeueing) {
1059 endp->dequeueing = 0;
1060 up(&u132->scheduler_lock);
1061 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1063 } else if (u132->going > 0) {
1064 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1065 "%p status=%d\n", urb, urb->status);
1066 up(&u132->scheduler_lock);
1067 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1069 } else if (urb->status == -EINPROGRESS) {
1070 if (usb_pipein(urb->pipe)) {
1072 struct u132_ring *ring = endp->ring;
1073 up(&u132->scheduler_lock);
1074 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1075 ring->number, endp, urb, address,
1077 u132_hcd_configure_input_recv);
1080 u132_hcd_giveback_urb(u132, endp, urb, retval);
1084 struct u132_ring *ring = endp->ring;
1085 up(&u132->scheduler_lock);
1086 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1087 ring->number, endp, urb, address,
1089 u132_hcd_configure_empty_recv);
1092 u132_hcd_giveback_urb(u132, endp, urb, retval);
1096 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1097 "s=%d\n", urb, urb->status);
1098 up(&u132->scheduler_lock);
1099 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1104 static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1105 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1106 int repeat_number, int halted, int skipped, int actual, int non_null)
1108 struct u132_endp *endp = data;
1109 struct u132 *u132 = endp->u132;
1110 u8 address = u132->addr[endp->usb_addr].address;
1111 struct u132_udev *udev = &u132->udev[address];
1112 down(&u132->scheduler_lock);
1113 if (u132->going > 1) {
1114 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1116 up(&u132->scheduler_lock);
1117 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1119 } else if (endp->dequeueing) {
1120 endp->dequeueing = 0;
1121 up(&u132->scheduler_lock);
1122 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1124 } else if (u132->going > 0) {
1125 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1126 "%p status=%d\n", urb, urb->status);
1127 up(&u132->scheduler_lock);
1128 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1130 } else if (urb->status == -EINPROGRESS) {
1131 u132->addr[0].address = 0;
1132 endp->usb_addr = udev->usb_addr;
1133 up(&u132->scheduler_lock);
1134 u132_hcd_giveback_urb(u132, endp, urb, 0);
1137 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1138 "s=%d\n", urb, urb->status);
1139 up(&u132->scheduler_lock);
1140 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1145 static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1146 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1147 int repeat_number, int halted, int skipped, int actual, int non_null)
1149 struct u132_endp *endp = data;
1150 struct u132 *u132 = endp->u132;
1151 down(&u132->scheduler_lock);
1152 if (u132->going > 1) {
1153 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1155 up(&u132->scheduler_lock);
1156 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1158 } else if (endp->dequeueing) {
1159 endp->dequeueing = 0;
1160 up(&u132->scheduler_lock);
1161 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1163 } else if (u132->going > 0) {
1164 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1165 "%p status=%d\n", urb, urb->status);
1166 up(&u132->scheduler_lock);
1167 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1169 } else if (urb->status == -EINPROGRESS) {
1171 struct u132_ring *ring = endp->ring;
1172 up(&u132->scheduler_lock);
1173 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1174 ring->number, endp, urb, 0, endp->usb_endp, 0,
1175 u132_hcd_enumeration_empty_recv);
1178 u132_hcd_giveback_urb(u132, endp, urb, retval);
1181 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1182 "s=%d\n", urb, urb->status);
1183 up(&u132->scheduler_lock);
1184 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1189 static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1190 int len, int toggle_bits, int error_count, int condition_code,
1191 int repeat_number, int halted, int skipped, int actual, int non_null)
1193 struct u132_endp *endp = data;
1194 struct u132 *u132 = endp->u132;
1195 down(&u132->scheduler_lock);
1196 if (u132->going > 1) {
1197 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1199 up(&u132->scheduler_lock);
1200 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1202 } else if (endp->dequeueing) {
1203 endp->dequeueing = 0;
1204 up(&u132->scheduler_lock);
1205 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1207 } else if (u132->going > 0) {
1208 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1209 "%p status=%d\n", urb, urb->status);
1210 up(&u132->scheduler_lock);
1211 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1213 } else if (urb->status == -EINPROGRESS) {
1214 up(&u132->scheduler_lock);
1215 u132_hcd_giveback_urb(u132, endp, urb, 0);
1218 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1219 "s=%d\n", urb, urb->status);
1220 up(&u132->scheduler_lock);
1221 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1226 static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1227 int len, int toggle_bits, int error_count, int condition_code,
1228 int repeat_number, int halted, int skipped, int actual, int non_null)
1230 struct u132_endp *endp = data;
1231 struct u132 *u132 = endp->u132;
1232 u8 address = u132->addr[endp->usb_addr].address;
1233 down(&u132->scheduler_lock);
1234 if (u132->going > 1) {
1235 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1237 up(&u132->scheduler_lock);
1238 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1240 } else if (endp->dequeueing) {
1241 endp->dequeueing = 0;
1242 up(&u132->scheduler_lock);
1243 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1245 } else if (u132->going > 0) {
1246 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1247 "%p status=%d\n", urb, urb->status);
1248 up(&u132->scheduler_lock);
1249 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1251 } else if (urb->status == -EINPROGRESS) {
1253 struct u132_ring *ring = endp->ring;
1254 u8 *u = urb->transfer_buffer;
1260 urb->actual_length = len;
1261 up(&u132->scheduler_lock);
1262 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1263 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1264 u132_hcd_initial_empty_sent);
1267 u132_hcd_giveback_urb(u132, endp, urb, retval);
1270 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1271 "s=%d\n", urb, urb->status);
1272 up(&u132->scheduler_lock);
1273 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1278 static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1279 int len, int toggle_bits, int error_count, int condition_code,
1280 int repeat_number, int halted, int skipped, int actual, int non_null)
1282 struct u132_endp *endp = data;
1283 struct u132 *u132 = endp->u132;
1284 u8 address = u132->addr[endp->usb_addr].address;
1285 down(&u132->scheduler_lock);
1286 if (u132->going > 1) {
1287 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1289 up(&u132->scheduler_lock);
1290 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1292 } else if (endp->dequeueing) {
1293 endp->dequeueing = 0;
1294 up(&u132->scheduler_lock);
1295 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1297 } else if (u132->going > 0) {
1298 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1299 "%p status=%d\n", urb, urb->status);
1300 up(&u132->scheduler_lock);
1301 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1303 } else if (urb->status == -EINPROGRESS) {
1305 struct u132_ring *ring = endp->ring;
1306 up(&u132->scheduler_lock);
1307 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1308 ring->number, endp, urb, address, endp->usb_endp, 0,
1309 u132_hcd_initial_input_recv);
1312 u132_hcd_giveback_urb(u132, endp, urb, retval);
1315 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1316 "s=%d\n", urb, urb->status);
1317 up(&u132->scheduler_lock);
1318 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1323 static void u132_hcd_ring_work_scheduler(void *data);
1324 static void u132_hcd_endp_work_scheduler(void *data);
1326 * this work function is only executed from the work queue
1329 static void u132_hcd_ring_work_scheduler(void *data)
1331 struct u132_ring *ring = data;
1332 struct u132 *u132 = ring->u132;
1333 down(&u132->scheduler_lock);
1335 up(&u132->scheduler_lock);
1336 u132_ring_put_kref(u132, ring);
1338 } else if (ring->curr_endp) {
1339 struct u132_endp *last_endp = ring->curr_endp;
1340 struct list_head *scan;
1341 struct list_head *head = &last_endp->endp_ring;
1342 unsigned long wakeup = 0;
1343 list_for_each(scan, head) {
1344 struct u132_endp *endp = list_entry(scan,
1345 struct u132_endp, endp_ring);
1346 if (endp->queue_next == endp->queue_last) {
1347 } else if ((endp->delayed == 0)
1348 || time_after_eq(jiffies, endp->jiffies)) {
1349 ring->curr_endp = endp;
1350 u132_endp_cancel_work(u132, last_endp);
1351 u132_endp_queue_work(u132, last_endp, 0);
1352 up(&u132->scheduler_lock);
1353 u132_ring_put_kref(u132, ring);
1356 unsigned long delta = endp->jiffies - jiffies;
1361 if (last_endp->queue_next == last_endp->queue_last) {
1362 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1363 last_endp->jiffies)) {
1364 u132_endp_cancel_work(u132, last_endp);
1365 u132_endp_queue_work(u132, last_endp, 0);
1366 up(&u132->scheduler_lock);
1367 u132_ring_put_kref(u132, ring);
1370 unsigned long delta = last_endp->jiffies - jiffies;
1375 u132_ring_requeue_work(u132, ring, wakeup);
1376 up(&u132->scheduler_lock);
1379 up(&u132->scheduler_lock);
1380 u132_ring_put_kref(u132, ring);
1384 up(&u132->scheduler_lock);
1385 u132_ring_put_kref(u132, ring);
1390 static void u132_hcd_endp_work_scheduler(void *data)
1392 struct u132_ring *ring;
1393 struct u132_endp *endp = data;
1394 struct u132 *u132 = endp->u132;
1395 down(&u132->scheduler_lock);
1397 if (endp->edset_flush) {
1398 endp->edset_flush = 0;
1399 if (endp->dequeueing)
1400 usb_ftdi_elan_edset_flush(u132->platform_dev,
1401 ring->number, endp);
1402 up(&u132->scheduler_lock);
1403 u132_endp_put_kref(u132, endp);
1405 } else if (endp->active) {
1406 up(&u132->scheduler_lock);
1407 u132_endp_put_kref(u132, endp);
1409 } else if (ring->in_use) {
1410 up(&u132->scheduler_lock);
1411 u132_endp_put_kref(u132, endp);
1413 } else if (endp->queue_next == endp->queue_last) {
1414 up(&u132->scheduler_lock);
1415 u132_endp_put_kref(u132, endp);
1417 } else if (endp->pipetype == PIPE_INTERRUPT) {
1418 u8 address = u132->addr[endp->usb_addr].address;
1420 up(&u132->scheduler_lock);
1421 u132_endp_put_kref(u132, endp);
1425 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1428 ring->curr_endp = endp;
1430 up(&u132->scheduler_lock);
1431 retval = edset_single(u132, ring, endp, urb, address,
1432 endp->toggle_bits, u132_hcd_interrupt_recv);
1435 u132_hcd_giveback_urb(u132, endp, urb, retval);
1438 } else if (endp->pipetype == PIPE_CONTROL) {
1439 u8 address = u132->addr[endp->usb_addr].address;
1441 up(&u132->scheduler_lock);
1442 u132_endp_put_kref(u132, endp);
1444 } else if (address == 0) {
1446 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1449 ring->curr_endp = endp;
1451 up(&u132->scheduler_lock);
1452 retval = edset_setup(u132, ring, endp, urb, address,
1453 0x2, u132_hcd_initial_setup_sent);
1456 u132_hcd_giveback_urb(u132, endp, urb, retval);
1458 } else if (endp->usb_addr == 0) {
1460 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1463 ring->curr_endp = endp;
1465 up(&u132->scheduler_lock);
1466 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1467 u132_hcd_enumeration_address_sent);
1470 u132_hcd_giveback_urb(u132, endp, urb, retval);
1474 u8 address = u132->addr[endp->usb_addr].address;
1475 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1478 ring->curr_endp = endp;
1480 up(&u132->scheduler_lock);
1481 retval = edset_setup(u132, ring, endp, urb, address,
1482 0x2, u132_hcd_configure_setup_sent);
1485 u132_hcd_giveback_urb(u132, endp, urb, retval);
1490 u8 address = u132->addr[endp->usb_addr].address;
1492 up(&u132->scheduler_lock);
1493 u132_endp_put_kref(u132, endp);
1497 struct urb *urb = endp->urb_list[
1498 ENDP_QUEUE_MASK & endp->queue_next];
1500 ring->curr_endp = endp;
1502 up(&u132->scheduler_lock);
1503 retval = edset_input(u132, ring, endp, urb,
1504 address, endp->toggle_bits,
1505 u132_hcd_bulk_input_recv);
1508 u132_hcd_giveback_urb(u132, endp, urb,
1512 } else { /* output pipe */
1513 u8 address = u132->addr[endp->usb_addr].address;
1515 up(&u132->scheduler_lock);
1516 u132_endp_put_kref(u132, endp);
1520 struct urb *urb = endp->urb_list[
1521 ENDP_QUEUE_MASK & endp->queue_next];
1523 ring->curr_endp = endp;
1525 up(&u132->scheduler_lock);
1526 retval = edset_output(u132, ring, endp, urb,
1527 address, endp->toggle_bits,
1528 u132_hcd_bulk_output_sent);
1531 u132_hcd_giveback_urb(u132, endp, urb,
1539 static void port_power(struct u132 *u132, int pn, int is_on)
1541 u132->port[pn].power = is_on;
1544 static void u132_power(struct u132 *u132, int is_on)
1546 struct usb_hcd *hcd = u132_to_hcd(u132)
1547 ; /* hub is inactive unless the port is powered */
1552 hcd->self.controller->power.power_state = PMSG_ON;
1555 hcd->state = HC_STATE_HALT;
1556 hcd->self.controller->power.power_state = PMSG_SUSPEND;
1560 static int u132_periodic_reinit(struct u132 *u132)
1563 u32 fi = u132->hc_fminterval & 0x03fff;
1566 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1569 fit = fminterval & FIT;
1570 retval = u132_write_pcimem(u132, fminterval,
1571 (fit ^ FIT) | u132->hc_fminterval);
1574 retval = u132_write_pcimem(u132, periodicstart,
1575 ((9 *fi) / 10) & 0x3fff);
1581 static char *hcfs2string(int state)
1584 case OHCI_USB_RESET:
1586 case OHCI_USB_RESUME:
1589 return "operational";
1590 case OHCI_USB_SUSPEND:
1596 static int u132_usb_reset(struct u132 *u132)
1599 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1602 u132->hc_control &= OHCI_CTRL_RWC;
1603 retval = u132_write_pcimem(u132, control, u132->hc_control);
1609 static int u132_init(struct u132 *u132)
1614 u132->next_statechange =
1615 jiffies; /* SMM owns the HC? not for long! */ {
1617 retval = u132_read_pcimem(u132, control, &control);
1620 if (control & OHCI_CTRL_IR) {
1622 retval = u132_write_pcimem(u132, intrenable,
1626 retval = u132_write_pcimem_byte(u132, cmdstatus,
1631 retval = u132_read_pcimem(u132, control,
1636 if (control & OHCI_CTRL_IR) {
1639 dev_err(&u132->platform_dev->dev, "USB "
1640 "HC takeover failed!(BIOS/SMM b"
1641 "ug) control=%08X\n", control);
1646 u132_usb_reset(u132);
1649 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1652 retval = u132_read_pcimem(u132, control, &control);
1655 if (u132->num_ports == 0) {
1657 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1660 u132->num_ports = rh_a & RH_A_NDP;
1661 retval = read_roothub_info(u132);
1665 if (u132->num_ports > MAX_U132_PORTS) {
1672 /* Start an OHCI controller, set the BUS operational
1673 * resets USB and controller
1676 static int u132_run(struct u132 *u132)
1685 int mask = OHCI_INTR_INIT;
1686 int first = u132->hc_fminterval == 0;
1688 int reset_timeout = 30; /* ... allow extra time */
1692 retval = u132_read_pcimem(u132, fminterval, &temp);
1695 u132->hc_fminterval = temp & 0x3fff;
1696 if (u132->hc_fminterval != FI) {
1698 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1700 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1703 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1704 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1706 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1710 case OHCI_USB_SUSPEND:
1711 case OHCI_USB_RESUME:
1712 u132->hc_control &= OHCI_CTRL_RWC;
1713 u132->hc_control |= OHCI_USB_RESUME;
1717 u132->hc_control &= OHCI_CTRL_RWC;
1718 u132->hc_control |= OHCI_USB_RESET;
1722 retval = u132_write_pcimem(u132, control, u132->hc_control);
1725 retval = u132_read_pcimem(u132, control, &control);
1729 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1732 if (!(roothub_a & RH_A_NPS)) {
1733 int temp; /* power down each port */
1734 for (temp = 0; temp < u132->num_ports; temp++) {
1735 retval = u132_write_pcimem(u132,
1736 roothub.portstatus[temp], RH_PS_LSDA);
1741 retval = u132_read_pcimem(u132, control, &control);
1744 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1747 retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_HCR);
1751 retval = u132_read_pcimem(u132, cmdstatus, &status);
1754 if (0 != (status & OHCI_HCR)) {
1755 if (--reset_timeout == 0) {
1756 dev_err(&u132->platform_dev->dev, "USB HC reset"
1765 if (u132->flags & OHCI_QUIRK_INITRESET) {
1766 retval = u132_write_pcimem(u132, control, u132->hc_control);
1769 retval = u132_read_pcimem(u132, control, &control);
1773 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1776 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1779 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1782 retval = u132_periodic_reinit(u132);
1785 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1788 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1791 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1792 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1793 u132->flags |= OHCI_QUIRK_INITRESET;
1796 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1797 "\n", fminterval, periodicstart);
1798 } /* start controller operations */
1799 u132->hc_control &= OHCI_CTRL_RWC;
1800 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1801 retval = u132_write_pcimem(u132, control, u132->hc_control);
1804 retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_BLF);
1807 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1810 retval = u132_read_pcimem(u132, control, &control);
1813 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1814 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1817 retval = u132_write_pcimem(u132, intrstatus, mask);
1820 retval = u132_write_pcimem(u132, intrdisable,
1821 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1822 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1825 return retval; /* handle root hub init quirks ... */
1826 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1829 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1830 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1831 roothub_a |= RH_A_NOCP;
1832 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1833 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1836 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1837 roothub_a |= RH_A_NPS;
1838 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1842 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1845 retval = u132_write_pcimem(u132, roothub.b,
1846 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1849 retval = u132_read_pcimem(u132, control, &control);
1852 mdelay((roothub_a >> 23) & 0x1fe);
1853 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1857 static void u132_hcd_stop(struct usb_hcd *hcd)
1859 struct u132 *u132 = hcd_to_u132(hcd);
1860 if (u132->going > 1) {
1861 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1863 } else if (u132->going > 0) {
1864 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1867 down(&u132->sw_lock);
1869 u132_power(u132, 0);
1874 static int u132_hcd_start(struct usb_hcd *hcd)
1876 struct u132 *u132 = hcd_to_u132(hcd);
1877 if (u132->going > 1) {
1878 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1881 } else if (u132->going > 0) {
1882 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1884 } else if (hcd->self.controller) {
1886 struct platform_device *pdev =
1887 to_platform_device(hcd->self.controller);
1888 u16 vendor = ((struct u132_platform_data *)
1889 (pdev->dev.platform_data))->vendor;
1890 u16 device = ((struct u132_platform_data *)
1891 (pdev->dev.platform_data))->device;
1892 down(&u132->sw_lock);
1894 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1895 u132->flags = OHCI_QUIRK_AMD756;
1896 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1897 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1898 "ounds unavailable\n");
1899 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1900 u132->flags |= OHCI_QUIRK_ZFMICRO;
1901 retval = u132_run(u132);
1910 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1915 static int u132_hcd_reset(struct usb_hcd *hcd)
1917 struct u132 *u132 = hcd_to_u132(hcd);
1918 if (u132->going > 1) {
1919 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1922 } else if (u132->going > 0) {
1923 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1927 down(&u132->sw_lock);
1928 retval = u132_init(u132);
1938 static int create_endpoint_and_queue_int(struct u132 *u132,
1939 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1940 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1943 struct u132_ring *ring;
1945 u8 endp_number = ++u132->num_endpoints;
1946 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1947 kmalloc(sizeof(struct u132_endp), mem_flags);
1951 INIT_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler, (void *)endp);
1952 spin_lock_init(&endp->queue_lock.slock);
1953 INIT_LIST_HEAD(&endp->urb_more);
1954 ring = endp->ring = &u132->ring[0];
1955 if (ring->curr_endp) {
1956 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1958 INIT_LIST_HEAD(&endp->endp_ring);
1959 ring->curr_endp = endp;
1962 endp->dequeueing = 0;
1963 endp->edset_flush = 0;
1966 endp->endp_number = endp_number;
1969 endp->pipetype = usb_pipetype(urb->pipe);
1970 u132_endp_init_kref(u132, endp);
1971 if (usb_pipein(urb->pipe)) {
1972 endp->toggle_bits = 0x2;
1973 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1976 udev->endp_number_in[usb_endp] = endp_number;
1977 u132_udev_get_kref(u132, udev);
1979 endp->toggle_bits = 0x2;
1980 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1983 udev->endp_number_out[usb_endp] = endp_number;
1984 u132_udev_get_kref(u132, udev);
1987 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1989 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1990 endp->udev_number = address;
1991 endp->usb_addr = usb_addr;
1992 endp->usb_endp = usb_endp;
1993 endp->queue_size = 1;
1994 endp->queue_last = 0;
1995 endp->queue_next = 0;
1996 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1997 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1998 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
2002 static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2003 struct usb_host_endpoint *hep, struct urb *urb,
2004 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2005 u8 usb_endp, u8 address)
2009 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
2010 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2011 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2013 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2016 endp->queue_size -= 1;
2019 list_add_tail(&urbq->urb_more, &endp->urb_more);
2026 static int create_endpoint_and_queue_bulk(struct u132 *u132,
2027 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
2028 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
2032 struct u132_ring *ring;
2034 u8 endp_number = ++u132->num_endpoints;
2035 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
2036 kmalloc(sizeof(struct u132_endp), mem_flags);
2040 INIT_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler, (void *)endp);
2041 spin_lock_init(&endp->queue_lock.slock);
2042 INIT_LIST_HEAD(&endp->urb_more);
2043 endp->dequeueing = 0;
2044 endp->edset_flush = 0;
2047 endp->endp_number = endp_number;
2050 endp->pipetype = usb_pipetype(urb->pipe);
2051 u132_endp_init_kref(u132, endp);
2052 if (usb_pipein(urb->pipe)) {
2053 endp->toggle_bits = 0x2;
2054 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
2058 udev->endp_number_in[usb_endp] = endp_number;
2059 u132_udev_get_kref(u132, udev);
2061 endp->toggle_bits = 0x2;
2062 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2066 udev->endp_number_out[usb_endp] = endp_number;
2067 u132_udev_get_kref(u132, udev);
2069 ring = endp->ring = &u132->ring[ring_number - 1];
2070 if (ring->curr_endp) {
2071 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2073 INIT_LIST_HEAD(&endp->endp_ring);
2074 ring->curr_endp = endp;
2078 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2079 endp->udev_number = address;
2080 endp->usb_addr = usb_addr;
2081 endp->usb_endp = usb_endp;
2082 endp->queue_size = 1;
2083 endp->queue_last = 0;
2084 endp->queue_next = 0;
2085 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2086 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2087 u132_endp_queue_work(u132, endp, 0);
2091 static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2092 struct usb_host_endpoint *hep, struct urb *urb,
2093 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2094 u8 usb_endp, u8 address)
2097 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2098 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2100 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2103 endp->queue_size -= 1;
2106 list_add_tail(&urbq->urb_more, &endp->urb_more);
2113 static int create_endpoint_and_queue_control(struct u132 *u132,
2114 struct usb_host_endpoint *hep, struct urb *urb,
2115 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2118 struct u132_ring *ring;
2119 u8 endp_number = ++u132->num_endpoints;
2120 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
2121 kmalloc(sizeof(struct u132_endp), mem_flags);
2125 INIT_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler, (void *)endp);
2126 spin_lock_init(&endp->queue_lock.slock);
2127 INIT_LIST_HEAD(&endp->urb_more);
2128 ring = endp->ring = &u132->ring[0];
2129 if (ring->curr_endp) {
2130 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2132 INIT_LIST_HEAD(&endp->endp_ring);
2133 ring->curr_endp = endp;
2136 endp->dequeueing = 0;
2137 endp->edset_flush = 0;
2140 endp->endp_number = endp_number;
2143 u132_endp_init_kref(u132, endp);
2144 u132_endp_get_kref(u132, endp);
2145 if (usb_addr == 0) {
2147 u8 address = u132->addr[usb_addr].address;
2148 struct u132_udev *udev = &u132->udev[address];
2149 endp->udev_number = address;
2150 endp->usb_addr = usb_addr;
2151 endp->usb_endp = usb_endp;
2154 endp->pipetype = usb_pipetype(urb->pipe);
2155 u132_udev_init_kref(u132, udev);
2156 u132_udev_get_kref(u132, udev);
2157 udev->endp_number_in[usb_endp] = endp_number;
2158 udev->endp_number_out[usb_endp] = endp_number;
2160 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2161 endp->queue_size = 1;
2162 endp->queue_last = 0;
2163 endp->queue_next = 0;
2164 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2165 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2166 u132_endp_queue_work(u132, endp, 0);
2168 } else { /*(usb_addr > 0) */
2170 u8 address = u132->addr[usb_addr].address;
2171 struct u132_udev *udev = &u132->udev[address];
2172 endp->udev_number = address;
2173 endp->usb_addr = usb_addr;
2174 endp->usb_endp = usb_endp;
2177 endp->pipetype = usb_pipetype(urb->pipe);
2178 u132_udev_get_kref(u132, udev);
2179 udev->enumeration = 2;
2180 udev->endp_number_in[usb_endp] = endp_number;
2181 udev->endp_number_out[usb_endp] = endp_number;
2183 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2184 endp->queue_size = 1;
2185 endp->queue_last = 0;
2186 endp->queue_next = 0;
2187 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2188 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2189 u132_endp_queue_work(u132, endp, 0);
2194 static int queue_control_on_old_endpoint(struct u132 *u132,
2195 struct usb_host_endpoint *hep, struct urb *urb,
2196 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2199 if (usb_addr == 0) {
2200 if (usb_pipein(urb->pipe)) {
2202 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2203 endp->urb_list[ENDP_QUEUE_MASK &
2204 endp->queue_last++] = urb;
2206 struct u132_urbq *urbq =
2207 kmalloc(sizeof(struct u132_urbq),
2210 endp->queue_size -= 1;
2213 list_add_tail(&urbq->urb_more,
2219 } else { /* usb_pipeout(urb->pipe) */
2220 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2221 int I = MAX_U132_UDEVS;
2224 struct u132_udev *udev = &u132->udev[++i];
2225 if (udev->usb_device) {
2228 udev->enumeration = 1;
2229 u132->addr[0].address = i;
2230 endp->udev_number = i;
2231 udev->udev_number = i;
2232 udev->usb_addr = usb_dev->devnum;
2233 u132_udev_init_kref(u132, udev);
2234 udev->endp_number_in[usb_endp] =
2236 u132_udev_get_kref(u132, udev);
2237 udev->endp_number_out[usb_endp] =
2239 udev->usb_device = usb_dev;
2240 ((u8 *) (urb->setup_packet))[2] =
2242 u132_udev_get_kref(u132, udev);
2247 dev_err(&u132->platform_dev->dev, "run out of d"
2252 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2253 endp->urb_list[ENDP_QUEUE_MASK &
2254 endp->queue_last++] = urb;
2256 struct u132_urbq *urbq =
2257 kmalloc(sizeof(struct u132_urbq),
2260 endp->queue_size -= 1;
2263 list_add_tail(&urbq->urb_more,
2270 } else { /*(usb_addr > 0) */
2271 u8 address = u132->addr[usb_addr].address;
2272 struct u132_udev *udev = &u132->udev[address];
2274 if (udev->enumeration == 2) {
2276 udev->enumeration = 2;
2277 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2278 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2281 struct u132_urbq *urbq =
2282 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2284 endp->queue_size -= 1;
2287 list_add_tail(&urbq->urb_more, &endp->urb_more);
2295 static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2296 struct urb *urb, gfp_t mem_flags)
2298 struct u132 *u132 = hcd_to_u132(hcd);
2299 if (irqs_disabled()) {
2300 if (__GFP_WAIT & mem_flags) {
2301 printk(KERN_ERR "invalid context for function that migh"
2306 if (u132->going > 1) {
2307 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2310 } else if (u132->going > 0) {
2311 dev_err(&u132->platform_dev->dev, "device is being removed urb="
2312 "%p status=%d\n", urb, urb->status);
2315 u8 usb_addr = usb_pipedevice(urb->pipe);
2316 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2317 struct usb_device *usb_dev = urb->dev;
2318 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2319 u8 address = u132->addr[usb_addr].address;
2320 struct u132_udev *udev = &u132->udev[address];
2321 struct u132_endp *endp = hep->hcpriv;
2322 urb->actual_length = 0;
2326 spin_lock_irqsave(&endp->queue_lock.slock,
2328 retval = queue_int_on_old_endpoint(u132, udev,
2329 hep, urb, usb_dev, endp, usb_addr,
2331 spin_unlock_irqrestore(&endp->queue_lock.slock,
2336 u132_endp_queue_work(u132, endp,
2337 msecs_to_jiffies(urb->interval))
2341 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2343 } else { /*(endp == NULL) */
2344 return create_endpoint_and_queue_int(u132, udev,
2345 hep, urb, usb_dev, usb_addr, usb_endp,
2346 address, mem_flags);
2348 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2349 dev_err(&u132->platform_dev->dev, "the hardware does no"
2350 "t support PIPE_ISOCHRONOUS\n");
2352 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2353 u8 address = u132->addr[usb_addr].address;
2354 struct u132_udev *udev = &u132->udev[address];
2355 struct u132_endp *endp = hep->hcpriv;
2356 urb->actual_length = 0;
2360 spin_lock_irqsave(&endp->queue_lock.slock,
2362 retval = queue_bulk_on_old_endpoint(u132, udev,
2363 hep, urb, usb_dev, endp, usb_addr,
2365 spin_unlock_irqrestore(&endp->queue_lock.slock,
2370 u132_endp_queue_work(u132, endp, 0);
2373 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2376 return create_endpoint_and_queue_bulk(u132,
2377 udev, hep, urb, usb_dev, usb_addr,
2378 usb_endp, address, mem_flags);
2380 struct u132_endp *endp = hep->hcpriv;
2382 u8 *b = urb->setup_packet;
2384 char data[30 *3 + 4];
2386 int m = (sizeof(data) - 1) / 3;
2389 while (urb_size-- > 0) {
2391 } else if (i++ < m) {
2392 int w = sprintf(d, " %02X", *b++);
2396 d += sprintf(d, " ..");
2401 spin_lock_irqsave(&endp->queue_lock.slock,
2403 retval = queue_control_on_old_endpoint(u132,
2404 hep, urb, usb_dev, endp, usb_addr,
2406 spin_unlock_irqrestore(&endp->queue_lock.slock,
2411 u132_endp_queue_work(u132, endp, 0);
2414 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2417 return create_endpoint_and_queue_control(u132,
2418 hep, urb, usb_dev, usb_addr, usb_endp,
2424 static int dequeue_from_overflow_chain(struct u132 *u132,
2425 struct u132_endp *endp, struct urb *urb)
2427 struct list_head *scan;
2428 struct list_head *head = &endp->urb_more;
2429 list_for_each(scan, head) {
2430 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2432 if (urbq->urb == urb) {
2433 struct usb_hcd *hcd = u132_to_hcd(u132);
2435 endp->queue_size -= 1;
2436 urb->error_count = 0;
2438 usb_hcd_giveback_urb(hcd, urb, NULL);
2443 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2444 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2445 "\n", urb, endp->endp_number, endp, endp->ring->number,
2446 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2447 endp->usb_endp, endp->usb_addr, endp->queue_size,
2448 endp->queue_next, endp->queue_last);
2452 static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2456 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2457 if (endp->queue_size == 0) {
2458 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2459 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2460 endp->endp_number, endp, endp->ring->number,
2461 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2462 endp->usb_endp, endp->usb_addr);
2463 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2466 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2468 endp->dequeueing = 1;
2469 endp->edset_flush = 1;
2470 u132_endp_queue_work(u132, endp, 0);
2471 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2475 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2476 u132_hcd_abandon_urb(u132, endp, urb, urb->status);
2481 u16 queue_size = endp->queue_size;
2482 u16 queue_scan = endp->queue_next;
2483 struct urb **urb_slot = NULL;
2484 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2485 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2487 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2493 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2494 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2496 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2500 struct usb_hcd *hcd = u132_to_hcd(u132);
2501 endp->queue_size -= 1;
2502 if (list_empty(&endp->urb_more)) {
2503 spin_unlock_irqrestore(&endp->queue_lock.slock,
2506 struct list_head *next = endp->urb_more.next;
2507 struct u132_urbq *urbq = list_entry(next,
2508 struct u132_urbq, urb_more);
2510 *urb_slot = urbq->urb;
2511 spin_unlock_irqrestore(&endp->queue_lock.slock,
2514 } urb->error_count = 0;
2516 usb_hcd_giveback_urb(hcd, urb, NULL);
2518 } else if (list_empty(&endp->urb_more)) {
2519 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2520 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2521 "=%d size=%d next=%04X last=%04X\n", urb,
2522 endp->endp_number, endp, endp->ring->number,
2523 endp->input ? 'I' : ' ',
2524 endp->output ? 'O' : ' ', endp->usb_endp,
2525 endp->usb_addr, endp->queue_size,
2526 endp->queue_next, endp->queue_last);
2527 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2530 int retval = dequeue_from_overflow_chain(u132, endp,
2532 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2538 static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
2540 struct u132 *u132 = hcd_to_u132(hcd);
2541 if (u132->going > 2) {
2542 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2546 u8 usb_addr = usb_pipedevice(urb->pipe);
2547 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2548 u8 address = u132->addr[usb_addr].address;
2549 struct u132_udev *udev = &u132->udev[address];
2550 if (usb_pipein(urb->pipe)) {
2551 u8 endp_number = udev->endp_number_in[usb_endp];
2552 struct u132_endp *endp = u132->endp[endp_number - 1];
2553 return u132_endp_urb_dequeue(u132, endp, urb);
2555 u8 endp_number = udev->endp_number_out[usb_endp];
2556 struct u132_endp *endp = u132->endp[endp_number - 1];
2557 return u132_endp_urb_dequeue(u132, endp, urb);
2562 static void u132_endpoint_disable(struct usb_hcd *hcd,
2563 struct usb_host_endpoint *hep)
2565 struct u132 *u132 = hcd_to_u132(hcd);
2566 if (u132->going > 2) {
2567 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
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"
2815 int i, changed = 0, length = 1;
2816 if (u132->flags & OHCI_QUIRK_AMD756) {
2817 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2818 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2819 "ereads as NDP=%d\n",
2820 u132->hc_roothub_a & RH_A_NDP);
2824 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) {
2825 buf[0] = changed = 1;
2828 if (u132->num_ports > 7) {
2832 for (i = 0; i < u132->num_ports; i++) {
2833 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2834 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2838 buf[0] |= 1 << (i + 1);
2840 buf[1] |= 1 << (i - 7);
2843 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) {
2846 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) {
2850 done:return changed ? length : 0;
2854 static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2855 u16 wIndex, char *buf, u16 wLength)
2857 struct u132 *u132 = hcd_to_u132(hcd);
2858 if (u132->going > 1) {
2859 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2862 } else if (u132->going > 0) {
2863 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2867 down(&u132->sw_lock);
2869 case ClearHubFeature:
2871 case C_HUB_OVER_CURRENT:
2872 case C_HUB_LOCAL_POWER:
2880 case C_HUB_OVER_CURRENT:
2881 case C_HUB_LOCAL_POWER:
2887 case ClearPortFeature:{
2888 retval = u132_roothub_clearportfeature(u132,
2894 case GetHubDescriptor:{
2895 retval = u132_roothub_descriptor(u132,
2896 (struct usb_hub_descriptor *)buf);
2902 retval = u132_roothub_status(u132,
2908 case GetPortStatus:{
2909 retval = u132_roothub_portstatus(u132,
2910 (__le32 *) buf, wIndex);
2915 case SetPortFeature:{
2916 retval = u132_roothub_setportfeature(u132,
2924 error:u132_disable(u132);
2927 stall:retval = -EPIPE;
2935 static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2937 struct u132 *u132 = hcd_to_u132(hcd);
2938 if (u132->going > 1) {
2939 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2942 } else if (u132->going > 0) {
2943 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2949 static void u132_hub_irq_enable(struct usb_hcd *hcd)
2951 struct u132 *u132 = hcd_to_u132(hcd);
2952 if (u132->going > 1) {
2953 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2955 } else if (u132->going > 0)
2956 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2961 static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2963 struct u132 *u132 = hcd_to_u132(hcd);
2964 if (u132->going > 1) {
2965 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2968 } else if (u132->going > 0) {
2969 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2975 static int u132_hcd_resume(struct usb_hcd *hcd)
2977 struct u132 *u132 = hcd_to_u132(hcd);
2978 if (u132->going > 1) {
2979 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2982 } else if (u132->going > 0) {
2983 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2989 static int u132_bus_suspend(struct usb_hcd *hcd)
2991 struct u132 *u132 = hcd_to_u132(hcd);
2992 if (u132->going > 1) {
2993 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2996 } else if (u132->going > 0) {
2997 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3003 static int u132_bus_resume(struct usb_hcd *hcd)
3005 struct u132 *u132 = hcd_to_u132(hcd);
3006 if (u132->going > 1) {
3007 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3010 } else if (u132->going > 0) {
3011 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3018 #define u132_hcd_suspend NULL
3019 #define u132_hcd_resume NULL
3020 #define u132_bus_suspend NULL
3021 #define u132_bus_resume NULL
3023 static struct hc_driver u132_hc_driver = {
3024 .description = hcd_name,
3025 .hcd_priv_size = sizeof(struct u132),
3027 .flags = HCD_USB11 | HCD_MEMORY,
3028 .reset = u132_hcd_reset,
3029 .start = u132_hcd_start,
3030 .suspend = u132_hcd_suspend,
3031 .resume = u132_hcd_resume,
3032 .stop = u132_hcd_stop,
3033 .urb_enqueue = u132_urb_enqueue,
3034 .urb_dequeue = u132_urb_dequeue,
3035 .endpoint_disable = u132_endpoint_disable,
3036 .get_frame_number = u132_get_frame,
3037 .hub_status_data = u132_hub_status_data,
3038 .hub_control = u132_hub_control,
3039 .bus_suspend = u132_bus_suspend,
3040 .bus_resume = u132_bus_resume,
3041 .start_port_reset = u132_start_port_reset,
3042 .hub_irq_enable = u132_hub_irq_enable,
3046 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
3047 * is held for writing, thus this module must not call usb_remove_hcd()
3048 * synchronously - but instead should immediately stop activity to the
3049 * device and ansynchronously call usb_remove_hcd()
3051 static int __devexit u132_remove(struct platform_device *pdev)
3053 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3055 struct u132 *u132 = hcd_to_u132(hcd);
3057 if (u132->going++ > 1) {
3060 int rings = MAX_U132_RINGS;
3061 int endps = MAX_U132_ENDPS;
3063 down(&u132->sw_lock);
3064 u132_monitor_cancel_work(u132);
3065 while (rings-- > 0) {
3066 struct u132_ring *ring = &u132->ring[rings];
3067 u132_ring_cancel_work(u132, ring);
3068 } while (endps-- > 0) {
3069 struct u132_endp *endp = u132->endp[endps];
3071 u132_endp_cancel_work(u132, endp);
3074 printk(KERN_INFO "removing device u132.%d\n",
3075 u132->sequence_num);
3077 usb_remove_hcd(hcd);
3078 u132_u132_put_kref(u132);
3085 static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3087 int rings = MAX_U132_RINGS;
3088 int ports = MAX_U132_PORTS;
3089 int addrs = MAX_U132_ADDRS;
3090 int udevs = MAX_U132_UDEVS;
3091 int endps = MAX_U132_ENDPS;
3092 u132->board = pdev->dev.platform_data;
3093 u132->platform_dev = pdev;
3096 init_MUTEX(&u132->sw_lock);
3097 init_MUTEX(&u132->scheduler_lock);
3098 while (rings-- > 0) {
3099 struct u132_ring *ring = &u132->ring[rings];
3101 ring->number = rings + 1;
3103 ring->curr_endp = NULL;
3104 INIT_WORK(&ring->scheduler, u132_hcd_ring_work_scheduler,
3106 } down(&u132->sw_lock);
3107 INIT_WORK(&u132->monitor, u132_hcd_monitor_work, (void *)u132);
3108 while (ports-- > 0) {
3109 struct u132_port *port = &u132->port[ports];
3115 } while (addrs-- > 0) {
3116 struct u132_addr *addr = &u132->addr[addrs];
3118 } while (udevs-- > 0) {
3119 struct u132_udev *udev = &u132->udev[udevs];
3120 int i = ARRAY_SIZE(udev->endp_number_in);
3121 int o = ARRAY_SIZE(udev->endp_number_out);
3122 udev->usb_device = NULL;
3123 udev->udev_number = 0;
3125 udev->portnumber = 0;
3127 udev->endp_number_in[i] = 0;
3130 udev->endp_number_out[o] = 0;
3133 while (endps-- > 0) {
3134 u132->endp[endps] = NULL;
3140 static int __devinit u132_probe(struct platform_device *pdev)
3142 struct usb_hcd *hcd;
3144 if (u132_exiting > 0) {
3146 } /* refuse to confuse usbcore */
3147 if (pdev->dev.dma_mask) {
3150 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3152 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3154 ftdi_elan_gone_away(pdev);
3158 struct u132 *u132 = hcd_to_u132(hcd);
3159 hcd->rsrc_start = 0;
3160 down(&u132_module_lock);
3161 list_add_tail(&u132->u132_list, &u132_static_list);
3162 u132->sequence_num = ++u132_instances;
3163 up(&u132_module_lock);
3164 u132_u132_init_kref(u132);
3165 u132_initialise(u132, pdev);
3166 hcd->product_desc = "ELAN U132 Host Controller";
3167 retval = usb_add_hcd(hcd, 0, 0);
3169 dev_err(&u132->platform_dev->dev, "init error %d\n",
3171 u132_u132_put_kref(u132);
3174 u132_monitor_queue_work(u132, 100);
3182 /* for this device there's no useful distinction between the controller
3183 * and its root hub, except that the root hub only gets direct PM calls
3184 * when CONFIG_USB_SUSPEND is enabled.
3186 static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3188 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3189 struct u132 *u132 = hcd_to_u132(hcd);
3190 if (u132->going > 1) {
3191 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3194 } else if (u132->going > 0) {
3195 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3199 if (state.event == PM_EVENT_FREEZE) {
3200 retval = u132_bus_suspend(hcd);
3201 } else if (state.event == PM_EVENT_SUSPEND) {
3202 int ports = MAX_U132_PORTS;
3203 while (ports-- > 0) {
3204 port_power(u132, ports, 0);
3208 pdev->dev.power.power_state = state;
3213 static int u132_resume(struct platform_device *pdev)
3215 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3216 struct u132 *u132 = hcd_to_u132(hcd);
3217 if (u132->going > 1) {
3218 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3221 } else if (u132->going > 0) {
3222 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3226 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
3227 int ports = MAX_U132_PORTS;
3228 while (ports-- > 0) {
3229 port_power(u132, ports, 1);
3233 pdev->dev.power.power_state = PMSG_ON;
3234 retval = u132_bus_resume(hcd);
3241 #define u132_suspend NULL
3242 #define u132_resume NULL
3245 * this driver is loaded explicitely by ftdi_u132
3247 * the platform_driver struct is static because it is per type of module
3249 static struct platform_driver u132_platform_driver = {
3250 .probe = u132_probe,
3251 .remove = __devexit_p(u132_remove),
3252 .suspend = u132_suspend,
3253 .resume = u132_resume,
3255 .name = (char *)hcd_name,
3256 .owner = THIS_MODULE,
3259 static int __init u132_hcd_init(void)
3262 INIT_LIST_HEAD(&u132_static_list);
3265 init_MUTEX(&u132_module_lock);
3268 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3270 workqueue = create_singlethread_workqueue("u132");
3271 retval = platform_driver_register(&u132_platform_driver);
3276 module_init(u132_hcd_init);
3277 static void __exit u132_hcd_exit(void)
3281 down(&u132_module_lock);
3283 up(&u132_module_lock);
3284 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3285 platform_device_unregister(u132->platform_dev);
3286 } platform_driver_unregister(&u132_platform_driver);
3287 printk(KERN_INFO "u132-hcd driver deregistered\n");
3288 wait_event(u132_hcd_wait, u132_instances == 0);
3289 flush_workqueue(workqueue);
3290 destroy_workqueue(workqueue);
3294 module_exit(u132_hcd_exit);
3295 MODULE_LICENSE("GPL");