1 // SPDX-License-Identifier: GPL-2.0
3 * Host Controller Driver for the Elan Digital Systems U132 adapter
5 * Copyright(C) 2006 Elan Digital Systems Limited
6 * http://www.elandigitalsystems.com
8 * Author and Maintainer - Tony Olech - Elan Digital Systems
9 * tony.olech@elandigitalsystems.com
11 * This driver was written by Tony Olech(tony.olech@elandigitalsystems.com)
12 * based on various USB host drivers in the 2.6.15 linux kernel
13 * with constant reference to the 3rd Edition of Linux Device Drivers
14 * published by O'Reilly
16 * The U132 adapter is a USB to CardBus adapter specifically designed
17 * for PC cards that contain an OHCI host controller. Typical PC cards
18 * are the Orange Mobile 3G Option GlobeTrotter Fusion card.
20 * The U132 adapter will *NOT *work with PC cards that do not contain
21 * an OHCI controller. A simple way to test whether a PC card has an
22 * OHCI controller as an interface is to insert the PC card directly
23 * into a laptop(or desktop) with a CardBus slot and if "lspci" shows
24 * a new USB controller and "lsusb -v" shows a new OHCI Host Controller
25 * then there is a good chance that the U132 adapter will support the
26 * PC card.(you also need the specific client driver for the PC card)
28 * Please inform the Author and Maintainer about any PC cards that
29 * contain OHCI Host Controller and work when directly connected to
30 * an embedded CardBus slot but do not work when they are connected
31 * via an ELAN U132 adapter.
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/moduleparam.h>
37 #include <linux/delay.h>
38 #include <linux/ioport.h>
39 #include <linux/pci_ids.h>
40 #include <linux/sched.h>
41 #include <linux/slab.h>
42 #include <linux/errno.h>
43 #include <linux/init.h>
44 #include <linux/timer.h>
45 #include <linux/list.h>
46 #include <linux/interrupt.h>
47 #include <linux/usb.h>
48 #include <linux/usb/hcd.h>
49 #include <linux/workqueue.h>
50 #include <linux/platform_device.h>
51 #include <linux/mutex.h>
54 #include <asm/byteorder.h>
56 /* FIXME ohci.h is ONLY for internal use by the OHCI driver.
57 * If you're going to try stuff like this, you need to split
58 * out shareable stuff (register declarations?) into its own
59 * file, maybe name <linux/usb/ohci.h>
63 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
64 #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
66 MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
67 MODULE_DESCRIPTION("U132 USB Host Controller Driver");
68 MODULE_LICENSE("GPL");
69 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
70 INT_MODULE_PARM(testing
, 0);
71 /* Some boards misreport power switching/overcurrent*/
72 static bool distrust_firmware
= true;
73 module_param(distrust_firmware
, bool, 0);
74 MODULE_PARM_DESC(distrust_firmware
, "true to distrust firmware power/overcurren"
76 static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait
);
78 * u132_module_lock exists to protect access to global variables
81 static struct mutex u132_module_lock
;
82 static int u132_exiting
;
83 static int u132_instances
;
84 static struct list_head u132_static_list
;
86 * end of the global variables protected by u132_module_lock
88 static struct workqueue_struct
*workqueue
;
89 #define MAX_U132_PORTS 7
90 #define MAX_U132_ADDRS 128
91 #define MAX_U132_UDEVS 4
92 #define MAX_U132_ENDPS 100
93 #define MAX_U132_RINGS 4
94 static const char *cc_to_text
[16] = {
124 struct usb_device
*usb_device
;
129 u8 endp_number_in
[16];
130 u8 endp_number_out
[16];
132 #define ENDP_QUEUE_SHIFT 3
133 #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
134 #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
136 struct list_head urb_more
;
149 struct list_head endp_ring
;
150 struct u132_ring
*ring
;
151 unsigned toggle_bits
:2;
157 unsigned dequeueing
:1;
158 unsigned edset_flush
:1;
159 unsigned spare_bits
:14;
160 unsigned long jiffies
;
161 struct usb_host_endpoint
*hep
;
162 struct u132_spin queue_lock
;
166 struct urb
*urb_list
[ENDP_QUEUE_SIZE
];
167 struct list_head urb_more
;
168 struct delayed_work scheduler
;
175 struct u132_endp
*curr_endp
;
176 struct delayed_work scheduler
;
180 struct list_head u132_list
;
181 struct mutex sw_lock
;
182 struct mutex scheduler_lock
;
183 struct u132_platform_data
*board
;
184 struct platform_device
*platform_dev
;
185 struct u132_ring ring
[MAX_U132_RINGS
];
193 u32 hc_roothub_status
;
195 u32 hc_roothub_portstatus
[MAX_ROOT_PORTS
];
197 unsigned long next_statechange
;
198 struct delayed_work monitor
;
200 struct u132_addr addr
[MAX_U132_ADDRS
];
201 struct u132_udev udev
[MAX_U132_UDEVS
];
202 struct u132_port port
[MAX_U132_PORTS
];
203 struct u132_endp
*endp
[MAX_U132_ENDPS
];
207 * these cannot be inlines because we need the structure offset!!
208 * Does anyone have a better way?????
210 #define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
211 offsetof(struct ohci_regs, member), 0, data);
212 #define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
213 offsetof(struct ohci_regs, member), 0, data);
214 #define u132_read_pcimem(u132, member, data) \
215 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
216 ohci_regs, member), 0, data);
217 #define u132_write_pcimem(u132, member, data) \
218 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
219 ohci_regs, member), 0, data);
220 static inline struct u132
*udev_to_u132(struct u132_udev
*udev
)
222 u8 udev_number
= udev
->udev_number
;
223 return container_of(udev
, struct u132
, udev
[udev_number
]);
226 static inline struct u132
*hcd_to_u132(struct usb_hcd
*hcd
)
228 return (struct u132
*)(hcd
->hcd_priv
);
231 static inline struct usb_hcd
*u132_to_hcd(struct u132
*u132
)
233 return container_of((void *)u132
, struct usb_hcd
, hcd_priv
);
236 static inline void u132_disable(struct u132
*u132
)
238 u132_to_hcd(u132
)->state
= HC_STATE_HALT
;
242 #define kref_to_u132(d) container_of(d, struct u132, kref)
243 #define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref)
244 #define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref)
245 #include "../misc/usb_u132.h"
246 static const char hcd_name
[] = "u132_hcd";
247 #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
248 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
249 USB_PORT_STAT_C_RESET) << 16)
250 static void u132_hcd_delete(struct kref
*kref
)
252 struct u132
*u132
= kref_to_u132(kref
);
253 struct platform_device
*pdev
= u132
->platform_dev
;
254 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
256 mutex_lock(&u132_module_lock
);
257 list_del_init(&u132
->u132_list
);
259 mutex_unlock(&u132_module_lock
);
260 dev_warn(&u132
->platform_dev
->dev
, "FREEING the hcd=%p and thus the u13"
261 "2=%p going=%d pdev=%p\n", hcd
, u132
, u132
->going
, pdev
);
265 static inline void u132_u132_put_kref(struct u132
*u132
)
267 kref_put(&u132
->kref
, u132_hcd_delete
);
270 static inline void u132_u132_init_kref(struct u132
*u132
)
272 kref_init(&u132
->kref
);
275 static void u132_udev_delete(struct kref
*kref
)
277 struct u132_udev
*udev
= kref_to_u132_udev(kref
);
278 udev
->udev_number
= 0;
279 udev
->usb_device
= NULL
;
281 udev
->enumeration
= 0;
284 static inline void u132_udev_put_kref(struct u132
*u132
, struct u132_udev
*udev
)
286 kref_put(&udev
->kref
, u132_udev_delete
);
289 static inline void u132_udev_get_kref(struct u132
*u132
, struct u132_udev
*udev
)
291 kref_get(&udev
->kref
);
294 static inline void u132_udev_init_kref(struct u132
*u132
,
295 struct u132_udev
*udev
)
297 kref_init(&udev
->kref
);
300 static inline void u132_ring_put_kref(struct u132
*u132
, struct u132_ring
*ring
)
302 kref_put(&u132
->kref
, u132_hcd_delete
);
305 static void u132_ring_requeue_work(struct u132
*u132
, struct u132_ring
*ring
,
309 if (queue_delayed_work(workqueue
, &ring
->scheduler
, delta
))
311 } else if (queue_delayed_work(workqueue
, &ring
->scheduler
, 0))
313 kref_put(&u132
->kref
, u132_hcd_delete
);
316 static void u132_ring_queue_work(struct u132
*u132
, struct u132_ring
*ring
,
319 kref_get(&u132
->kref
);
320 u132_ring_requeue_work(u132
, ring
, delta
);
323 static void u132_ring_cancel_work(struct u132
*u132
, struct u132_ring
*ring
)
325 if (cancel_delayed_work(&ring
->scheduler
))
326 kref_put(&u132
->kref
, u132_hcd_delete
);
329 static void u132_endp_delete(struct kref
*kref
)
331 struct u132_endp
*endp
= kref_to_u132_endp(kref
);
332 struct u132
*u132
= endp
->u132
;
333 u8 usb_addr
= endp
->usb_addr
;
334 u8 usb_endp
= endp
->usb_endp
;
335 u8 address
= u132
->addr
[usb_addr
].address
;
336 struct u132_udev
*udev
= &u132
->udev
[address
];
337 u8 endp_number
= endp
->endp_number
;
338 struct usb_host_endpoint
*hep
= endp
->hep
;
339 struct u132_ring
*ring
= endp
->ring
;
340 struct list_head
*head
= &endp
->endp_ring
;
342 if (endp
== ring
->curr_endp
) {
343 if (list_empty(head
)) {
344 ring
->curr_endp
= NULL
;
347 struct u132_endp
*next_endp
= list_entry(head
->next
,
348 struct u132_endp
, endp_ring
);
349 ring
->curr_endp
= next_endp
;
355 udev
->endp_number_in
[usb_endp
] = 0;
356 u132_udev_put_kref(u132
, udev
);
359 udev
->endp_number_out
[usb_endp
] = 0;
360 u132_udev_put_kref(u132
, udev
);
362 u132
->endp
[endp_number
- 1] = NULL
;
365 u132_u132_put_kref(u132
);
368 static inline void u132_endp_put_kref(struct u132
*u132
, struct u132_endp
*endp
)
370 kref_put(&endp
->kref
, u132_endp_delete
);
373 static inline void u132_endp_get_kref(struct u132
*u132
, struct u132_endp
*endp
)
375 kref_get(&endp
->kref
);
378 static inline void u132_endp_init_kref(struct u132
*u132
,
379 struct u132_endp
*endp
)
381 kref_init(&endp
->kref
);
382 kref_get(&u132
->kref
);
385 static void u132_endp_queue_work(struct u132
*u132
, struct u132_endp
*endp
,
388 if (queue_delayed_work(workqueue
, &endp
->scheduler
, delta
))
389 kref_get(&endp
->kref
);
392 static void u132_endp_cancel_work(struct u132
*u132
, struct u132_endp
*endp
)
394 if (cancel_delayed_work(&endp
->scheduler
))
395 kref_put(&endp
->kref
, u132_endp_delete
);
398 static inline void u132_monitor_put_kref(struct u132
*u132
)
400 kref_put(&u132
->kref
, u132_hcd_delete
);
403 static void u132_monitor_queue_work(struct u132
*u132
, unsigned int delta
)
405 if (queue_delayed_work(workqueue
, &u132
->monitor
, delta
))
406 kref_get(&u132
->kref
);
409 static void u132_monitor_requeue_work(struct u132
*u132
, unsigned int delta
)
411 if (!queue_delayed_work(workqueue
, &u132
->monitor
, delta
))
412 kref_put(&u132
->kref
, u132_hcd_delete
);
415 static void u132_monitor_cancel_work(struct u132
*u132
)
417 if (cancel_delayed_work(&u132
->monitor
))
418 kref_put(&u132
->kref
, u132_hcd_delete
);
421 static int read_roothub_info(struct u132
*u132
)
425 retval
= u132_read_pcimem(u132
, revision
, &revision
);
427 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device co"
430 } else if ((revision
& 0xFF) == 0x10) {
431 } else if ((revision
& 0xFF) == 0x11) {
433 dev_err(&u132
->platform_dev
->dev
, "device revision is not valid"
434 " %08X\n", revision
);
437 retval
= u132_read_pcimem(u132
, control
, &u132
->hc_control
);
439 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device co"
443 retval
= u132_read_pcimem(u132
, roothub
.status
,
444 &u132
->hc_roothub_status
);
446 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device re"
447 "g roothub.status\n", retval
);
450 retval
= u132_read_pcimem(u132
, roothub
.a
, &u132
->hc_roothub_a
);
452 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device re"
453 "g roothub.a\n", retval
);
457 int I
= u132
->num_ports
;
460 retval
= u132_read_pcimem(u132
, roothub
.portstatus
[i
],
461 &u132
->hc_roothub_portstatus
[i
]);
463 dev_err(&u132
->platform_dev
->dev
, "error %d acc"
464 "essing device roothub.portstatus[%d]\n"
474 static void u132_hcd_monitor_work(struct work_struct
*work
)
476 struct u132
*u132
= container_of(work
, struct u132
, monitor
.work
);
477 if (u132
->going
> 1) {
478 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
480 u132_monitor_put_kref(u132
);
482 } else if (u132
->going
> 0) {
483 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
484 u132_monitor_put_kref(u132
);
488 mutex_lock(&u132
->sw_lock
);
489 retval
= read_roothub_info(u132
);
491 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
494 mutex_unlock(&u132
->sw_lock
);
496 ftdi_elan_gone_away(u132
->platform_dev
);
497 u132_monitor_put_kref(u132
);
500 u132_monitor_requeue_work(u132
, 500);
501 mutex_unlock(&u132
->sw_lock
);
507 static void u132_hcd_giveback_urb(struct u132
*u132
, struct u132_endp
*endp
,
508 struct urb
*urb
, int status
)
510 struct u132_ring
*ring
;
512 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
513 urb
->error_count
= 0;
514 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
515 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
516 endp
->queue_next
+= 1;
517 if (ENDP_QUEUE_SIZE
> --endp
->queue_size
) {
519 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
521 struct list_head
*next
= endp
->urb_more
.next
;
522 struct u132_urbq
*urbq
= list_entry(next
, struct u132_urbq
,
525 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] =
528 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
531 mutex_lock(&u132
->scheduler_lock
);
534 u132_ring_cancel_work(u132
, ring
);
535 u132_ring_queue_work(u132
, ring
, 0);
536 mutex_unlock(&u132
->scheduler_lock
);
537 u132_endp_put_kref(u132
, endp
);
538 usb_hcd_giveback_urb(hcd
, urb
, status
);
541 static void u132_hcd_forget_urb(struct u132
*u132
, struct u132_endp
*endp
,
542 struct urb
*urb
, int status
)
544 u132_endp_put_kref(u132
, endp
);
547 static void u132_hcd_abandon_urb(struct u132
*u132
, struct u132_endp
*endp
,
548 struct urb
*urb
, int status
)
551 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
552 urb
->error_count
= 0;
553 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
554 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
555 endp
->queue_next
+= 1;
556 if (ENDP_QUEUE_SIZE
> --endp
->queue_size
) {
558 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
560 struct list_head
*next
= endp
->urb_more
.next
;
561 struct u132_urbq
*urbq
= list_entry(next
, struct u132_urbq
,
564 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] =
567 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
570 usb_hcd_giveback_urb(hcd
, urb
, status
);
573 static inline int edset_input(struct u132
*u132
, struct u132_ring
*ring
,
574 struct u132_endp
*endp
, struct urb
*urb
, u8 address
, u8 toggle_bits
,
575 void (*callback
) (void *endp
, struct urb
*urb
, u8
*buf
, int len
,
576 int toggle_bits
, int error_count
, int condition_code
, int repeat_number
,
577 int halted
, int skipped
, int actual
, int non_null
))
579 return usb_ftdi_elan_edset_input(u132
->platform_dev
, ring
->number
, endp
,
580 urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
583 static inline int edset_setup(struct u132
*u132
, struct u132_ring
*ring
,
584 struct u132_endp
*endp
, struct urb
*urb
, u8 address
, u8 toggle_bits
,
585 void (*callback
) (void *endp
, struct urb
*urb
, u8
*buf
, int len
,
586 int toggle_bits
, int error_count
, int condition_code
, int repeat_number
,
587 int halted
, int skipped
, int actual
, int non_null
))
589 return usb_ftdi_elan_edset_setup(u132
->platform_dev
, ring
->number
, endp
,
590 urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
593 static inline int edset_single(struct u132
*u132
, struct u132_ring
*ring
,
594 struct u132_endp
*endp
, struct urb
*urb
, u8 address
, u8 toggle_bits
,
595 void (*callback
) (void *endp
, struct urb
*urb
, u8
*buf
, int len
,
596 int toggle_bits
, int error_count
, int condition_code
, int repeat_number
,
597 int halted
, int skipped
, int actual
, int non_null
))
599 return usb_ftdi_elan_edset_single(u132
->platform_dev
, ring
->number
,
600 endp
, urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
603 static inline int edset_output(struct u132
*u132
, struct u132_ring
*ring
,
604 struct u132_endp
*endp
, struct urb
*urb
, u8 address
, u8 toggle_bits
,
605 void (*callback
) (void *endp
, struct urb
*urb
, u8
*buf
, int len
,
606 int toggle_bits
, int error_count
, int condition_code
, int repeat_number
,
607 int halted
, int skipped
, int actual
, int non_null
))
609 return usb_ftdi_elan_edset_output(u132
->platform_dev
, ring
->number
,
610 endp
, urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
615 * must not LOCK sw_lock
618 static void u132_hcd_interrupt_recv(void *data
, struct urb
*urb
, u8
*buf
,
619 int len
, int toggle_bits
, int error_count
, int condition_code
,
620 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
622 struct u132_endp
*endp
= data
;
623 struct u132
*u132
= endp
->u132
;
624 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
625 struct u132_udev
*udev
= &u132
->udev
[address
];
626 mutex_lock(&u132
->scheduler_lock
);
627 if (u132
->going
> 1) {
628 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
630 mutex_unlock(&u132
->scheduler_lock
);
631 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
633 } else if (endp
->dequeueing
) {
634 endp
->dequeueing
= 0;
635 mutex_unlock(&u132
->scheduler_lock
);
636 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
638 } else if (u132
->going
> 0) {
639 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
641 mutex_unlock(&u132
->scheduler_lock
);
642 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
644 } else if (!urb
->unlinked
) {
645 struct u132_ring
*ring
= endp
->ring
;
646 u8
*u
= urb
->transfer_buffer
+ urb
->actual_length
;
653 urb
->actual_length
+= len
;
654 if ((condition_code
== TD_CC_NOERROR
) &&
655 (urb
->transfer_buffer_length
> urb
->actual_length
)) {
656 endp
->toggle_bits
= toggle_bits
;
657 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
659 if (urb
->actual_length
> 0) {
661 mutex_unlock(&u132
->scheduler_lock
);
662 retval
= edset_single(u132
, ring
, endp
, urb
,
663 address
, endp
->toggle_bits
,
664 u132_hcd_interrupt_recv
);
666 u132_hcd_giveback_urb(u132
, endp
, urb
,
671 endp
->jiffies
= jiffies
+
672 msecs_to_jiffies(urb
->interval
);
673 u132_ring_cancel_work(u132
, ring
);
674 u132_ring_queue_work(u132
, ring
, 0);
675 mutex_unlock(&u132
->scheduler_lock
);
676 u132_endp_put_kref(u132
, endp
);
679 } else if ((condition_code
== TD_DATAUNDERRUN
) &&
680 ((urb
->transfer_flags
& URB_SHORT_NOT_OK
) == 0)) {
681 endp
->toggle_bits
= toggle_bits
;
682 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
684 mutex_unlock(&u132
->scheduler_lock
);
685 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
688 if (condition_code
== TD_CC_NOERROR
) {
689 endp
->toggle_bits
= toggle_bits
;
690 usb_settoggle(udev
->usb_device
, endp
->usb_endp
,
692 } else if (condition_code
== TD_CC_STALL
) {
693 endp
->toggle_bits
= 0x2;
694 usb_settoggle(udev
->usb_device
, endp
->usb_endp
,
697 endp
->toggle_bits
= 0x2;
698 usb_settoggle(udev
->usb_device
, endp
->usb_endp
,
700 dev_err(&u132
->platform_dev
->dev
, "urb=%p givin"
701 "g back INTERRUPT %s\n", urb
,
702 cc_to_text
[condition_code
]);
704 mutex_unlock(&u132
->scheduler_lock
);
705 u132_hcd_giveback_urb(u132
, endp
, urb
,
706 cc_to_error
[condition_code
]);
710 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
711 "unlinked=%d\n", urb
, urb
->unlinked
);
712 mutex_unlock(&u132
->scheduler_lock
);
713 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
718 static void u132_hcd_bulk_output_sent(void *data
, struct urb
*urb
, u8
*buf
,
719 int len
, int toggle_bits
, int error_count
, int condition_code
,
720 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
722 struct u132_endp
*endp
= data
;
723 struct u132
*u132
= endp
->u132
;
724 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
725 mutex_lock(&u132
->scheduler_lock
);
726 if (u132
->going
> 1) {
727 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
729 mutex_unlock(&u132
->scheduler_lock
);
730 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
732 } else if (endp
->dequeueing
) {
733 endp
->dequeueing
= 0;
734 mutex_unlock(&u132
->scheduler_lock
);
735 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
737 } else if (u132
->going
> 0) {
738 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
740 mutex_unlock(&u132
->scheduler_lock
);
741 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
743 } else if (!urb
->unlinked
) {
744 struct u132_ring
*ring
= endp
->ring
;
745 urb
->actual_length
+= len
;
746 endp
->toggle_bits
= toggle_bits
;
747 if (urb
->transfer_buffer_length
> urb
->actual_length
) {
749 mutex_unlock(&u132
->scheduler_lock
);
750 retval
= edset_output(u132
, ring
, endp
, urb
, address
,
751 endp
->toggle_bits
, u132_hcd_bulk_output_sent
);
753 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
756 mutex_unlock(&u132
->scheduler_lock
);
757 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
761 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
762 "unlinked=%d\n", urb
, urb
->unlinked
);
763 mutex_unlock(&u132
->scheduler_lock
);
764 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
769 static void u132_hcd_bulk_input_recv(void *data
, struct urb
*urb
, u8
*buf
,
770 int len
, int toggle_bits
, int error_count
, int condition_code
,
771 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
773 struct u132_endp
*endp
= data
;
774 struct u132
*u132
= endp
->u132
;
775 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
776 struct u132_udev
*udev
= &u132
->udev
[address
];
777 mutex_lock(&u132
->scheduler_lock
);
778 if (u132
->going
> 1) {
779 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
781 mutex_unlock(&u132
->scheduler_lock
);
782 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
784 } else if (endp
->dequeueing
) {
785 endp
->dequeueing
= 0;
786 mutex_unlock(&u132
->scheduler_lock
);
787 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
789 } else if (u132
->going
> 0) {
790 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
792 mutex_unlock(&u132
->scheduler_lock
);
793 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
795 } else if (!urb
->unlinked
) {
796 struct u132_ring
*ring
= endp
->ring
;
797 u8
*u
= urb
->transfer_buffer
+ urb
->actual_length
;
804 urb
->actual_length
+= len
;
805 if ((condition_code
== TD_CC_NOERROR
) &&
806 (urb
->transfer_buffer_length
> urb
->actual_length
)) {
808 endp
->toggle_bits
= toggle_bits
;
809 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
811 mutex_unlock(&u132
->scheduler_lock
);
812 retval
= usb_ftdi_elan_edset_input(u132
->platform_dev
,
813 ring
->number
, endp
, urb
, address
,
814 endp
->usb_endp
, endp
->toggle_bits
,
815 u132_hcd_bulk_input_recv
);
817 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
819 } else if (condition_code
== TD_CC_NOERROR
) {
820 endp
->toggle_bits
= toggle_bits
;
821 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
823 mutex_unlock(&u132
->scheduler_lock
);
824 u132_hcd_giveback_urb(u132
, endp
, urb
,
825 cc_to_error
[condition_code
]);
827 } else if ((condition_code
== TD_DATAUNDERRUN
) &&
828 ((urb
->transfer_flags
& URB_SHORT_NOT_OK
) == 0)) {
829 endp
->toggle_bits
= toggle_bits
;
830 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
832 mutex_unlock(&u132
->scheduler_lock
);
833 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
835 } else if (condition_code
== TD_DATAUNDERRUN
) {
836 endp
->toggle_bits
= toggle_bits
;
837 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
839 dev_warn(&u132
->platform_dev
->dev
, "urb=%p(SHORT NOT OK"
840 ") giving back BULK IN %s\n", urb
,
841 cc_to_text
[condition_code
]);
842 mutex_unlock(&u132
->scheduler_lock
);
843 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
845 } else if (condition_code
== TD_CC_STALL
) {
846 endp
->toggle_bits
= 0x2;
847 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0, 0);
848 mutex_unlock(&u132
->scheduler_lock
);
849 u132_hcd_giveback_urb(u132
, endp
, urb
,
850 cc_to_error
[condition_code
]);
853 endp
->toggle_bits
= 0x2;
854 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0, 0);
855 dev_err(&u132
->platform_dev
->dev
, "urb=%p giving back B"
856 "ULK IN code=%d %s\n", urb
, condition_code
,
857 cc_to_text
[condition_code
]);
858 mutex_unlock(&u132
->scheduler_lock
);
859 u132_hcd_giveback_urb(u132
, endp
, urb
,
860 cc_to_error
[condition_code
]);
864 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
865 "unlinked=%d\n", urb
, urb
->unlinked
);
866 mutex_unlock(&u132
->scheduler_lock
);
867 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
872 static void u132_hcd_configure_empty_sent(void *data
, struct urb
*urb
, u8
*buf
,
873 int len
, int toggle_bits
, int error_count
, int condition_code
,
874 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
876 struct u132_endp
*endp
= data
;
877 struct u132
*u132
= endp
->u132
;
878 mutex_lock(&u132
->scheduler_lock
);
879 if (u132
->going
> 1) {
880 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
882 mutex_unlock(&u132
->scheduler_lock
);
883 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
885 } else if (endp
->dequeueing
) {
886 endp
->dequeueing
= 0;
887 mutex_unlock(&u132
->scheduler_lock
);
888 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
890 } else if (u132
->going
> 0) {
891 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
893 mutex_unlock(&u132
->scheduler_lock
);
894 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
896 } else if (!urb
->unlinked
) {
897 mutex_unlock(&u132
->scheduler_lock
);
898 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
901 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
902 "unlinked=%d\n", urb
, urb
->unlinked
);
903 mutex_unlock(&u132
->scheduler_lock
);
904 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
909 static void u132_hcd_configure_input_recv(void *data
, struct urb
*urb
, u8
*buf
,
910 int len
, int toggle_bits
, int error_count
, int condition_code
,
911 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
913 struct u132_endp
*endp
= data
;
914 struct u132
*u132
= endp
->u132
;
915 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
916 mutex_lock(&u132
->scheduler_lock
);
917 if (u132
->going
> 1) {
918 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
920 mutex_unlock(&u132
->scheduler_lock
);
921 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
923 } else if (endp
->dequeueing
) {
924 endp
->dequeueing
= 0;
925 mutex_unlock(&u132
->scheduler_lock
);
926 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
928 } else if (u132
->going
> 0) {
929 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
931 mutex_unlock(&u132
->scheduler_lock
);
932 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
934 } else if (!urb
->unlinked
) {
935 struct u132_ring
*ring
= endp
->ring
;
936 u8
*u
= urb
->transfer_buffer
;
943 urb
->actual_length
= len
;
944 if ((condition_code
== TD_CC_NOERROR
) || ((condition_code
==
945 TD_DATAUNDERRUN
) && ((urb
->transfer_flags
&
946 URB_SHORT_NOT_OK
) == 0))) {
948 mutex_unlock(&u132
->scheduler_lock
);
949 retval
= usb_ftdi_elan_edset_empty(u132
->platform_dev
,
950 ring
->number
, endp
, urb
, address
,
952 u132_hcd_configure_empty_sent
);
954 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
956 } else if (condition_code
== TD_CC_STALL
) {
957 mutex_unlock(&u132
->scheduler_lock
);
958 dev_warn(&u132
->platform_dev
->dev
, "giving back SETUP I"
959 "NPUT STALL urb %p\n", urb
);
960 u132_hcd_giveback_urb(u132
, endp
, urb
,
961 cc_to_error
[condition_code
]);
964 mutex_unlock(&u132
->scheduler_lock
);
965 dev_err(&u132
->platform_dev
->dev
, "giving back SETUP IN"
966 "PUT %s urb %p\n", cc_to_text
[condition_code
],
968 u132_hcd_giveback_urb(u132
, endp
, urb
,
969 cc_to_error
[condition_code
]);
973 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
974 "unlinked=%d\n", urb
, urb
->unlinked
);
975 mutex_unlock(&u132
->scheduler_lock
);
976 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
981 static void u132_hcd_configure_empty_recv(void *data
, struct urb
*urb
, u8
*buf
,
982 int len
, int toggle_bits
, int error_count
, int condition_code
,
983 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
985 struct u132_endp
*endp
= data
;
986 struct u132
*u132
= endp
->u132
;
987 mutex_lock(&u132
->scheduler_lock
);
988 if (u132
->going
> 1) {
989 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
991 mutex_unlock(&u132
->scheduler_lock
);
992 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
994 } else if (endp
->dequeueing
) {
995 endp
->dequeueing
= 0;
996 mutex_unlock(&u132
->scheduler_lock
);
997 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
999 } else if (u132
->going
> 0) {
1000 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1002 mutex_unlock(&u132
->scheduler_lock
);
1003 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1005 } else if (!urb
->unlinked
) {
1006 mutex_unlock(&u132
->scheduler_lock
);
1007 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1010 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1011 "unlinked=%d\n", urb
, urb
->unlinked
);
1012 mutex_unlock(&u132
->scheduler_lock
);
1013 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1018 static void u132_hcd_configure_setup_sent(void *data
, struct urb
*urb
, u8
*buf
,
1019 int len
, int toggle_bits
, int error_count
, int condition_code
,
1020 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1022 struct u132_endp
*endp
= data
;
1023 struct u132
*u132
= endp
->u132
;
1024 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1025 mutex_lock(&u132
->scheduler_lock
);
1026 if (u132
->going
> 1) {
1027 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1029 mutex_unlock(&u132
->scheduler_lock
);
1030 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1032 } else if (endp
->dequeueing
) {
1033 endp
->dequeueing
= 0;
1034 mutex_unlock(&u132
->scheduler_lock
);
1035 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1037 } else if (u132
->going
> 0) {
1038 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1040 mutex_unlock(&u132
->scheduler_lock
);
1041 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1043 } else if (!urb
->unlinked
) {
1044 if (usb_pipein(urb
->pipe
)) {
1046 struct u132_ring
*ring
= endp
->ring
;
1047 mutex_unlock(&u132
->scheduler_lock
);
1048 retval
= usb_ftdi_elan_edset_input(u132
->platform_dev
,
1049 ring
->number
, endp
, urb
, address
,
1051 u132_hcd_configure_input_recv
);
1053 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1057 struct u132_ring
*ring
= endp
->ring
;
1058 mutex_unlock(&u132
->scheduler_lock
);
1059 retval
= usb_ftdi_elan_edset_input(u132
->platform_dev
,
1060 ring
->number
, endp
, urb
, address
,
1062 u132_hcd_configure_empty_recv
);
1064 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1068 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1069 "unlinked=%d\n", urb
, urb
->unlinked
);
1070 mutex_unlock(&u132
->scheduler_lock
);
1071 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1076 static void u132_hcd_enumeration_empty_recv(void *data
, struct urb
*urb
,
1077 u8
*buf
, int len
, int toggle_bits
, int error_count
, int condition_code
,
1078 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1080 struct u132_endp
*endp
= data
;
1081 struct u132
*u132
= endp
->u132
;
1082 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1083 struct u132_udev
*udev
= &u132
->udev
[address
];
1084 mutex_lock(&u132
->scheduler_lock
);
1085 if (u132
->going
> 1) {
1086 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1088 mutex_unlock(&u132
->scheduler_lock
);
1089 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1091 } else if (endp
->dequeueing
) {
1092 endp
->dequeueing
= 0;
1093 mutex_unlock(&u132
->scheduler_lock
);
1094 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1096 } else if (u132
->going
> 0) {
1097 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1099 mutex_unlock(&u132
->scheduler_lock
);
1100 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1102 } else if (!urb
->unlinked
) {
1103 u132
->addr
[0].address
= 0;
1104 endp
->usb_addr
= udev
->usb_addr
;
1105 mutex_unlock(&u132
->scheduler_lock
);
1106 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1109 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1110 "unlinked=%d\n", urb
, urb
->unlinked
);
1111 mutex_unlock(&u132
->scheduler_lock
);
1112 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1117 static void u132_hcd_enumeration_address_sent(void *data
, struct urb
*urb
,
1118 u8
*buf
, int len
, int toggle_bits
, int error_count
, int condition_code
,
1119 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1121 struct u132_endp
*endp
= data
;
1122 struct u132
*u132
= endp
->u132
;
1123 mutex_lock(&u132
->scheduler_lock
);
1124 if (u132
->going
> 1) {
1125 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1127 mutex_unlock(&u132
->scheduler_lock
);
1128 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1130 } else if (endp
->dequeueing
) {
1131 endp
->dequeueing
= 0;
1132 mutex_unlock(&u132
->scheduler_lock
);
1133 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1135 } else if (u132
->going
> 0) {
1136 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1138 mutex_unlock(&u132
->scheduler_lock
);
1139 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1141 } else if (!urb
->unlinked
) {
1143 struct u132_ring
*ring
= endp
->ring
;
1144 mutex_unlock(&u132
->scheduler_lock
);
1145 retval
= usb_ftdi_elan_edset_input(u132
->platform_dev
,
1146 ring
->number
, endp
, urb
, 0, endp
->usb_endp
, 0,
1147 u132_hcd_enumeration_empty_recv
);
1149 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1152 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1153 "unlinked=%d\n", urb
, urb
->unlinked
);
1154 mutex_unlock(&u132
->scheduler_lock
);
1155 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1160 static void u132_hcd_initial_empty_sent(void *data
, struct urb
*urb
, u8
*buf
,
1161 int len
, int toggle_bits
, int error_count
, int condition_code
,
1162 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1164 struct u132_endp
*endp
= data
;
1165 struct u132
*u132
= endp
->u132
;
1166 mutex_lock(&u132
->scheduler_lock
);
1167 if (u132
->going
> 1) {
1168 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1170 mutex_unlock(&u132
->scheduler_lock
);
1171 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1173 } else if (endp
->dequeueing
) {
1174 endp
->dequeueing
= 0;
1175 mutex_unlock(&u132
->scheduler_lock
);
1176 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1178 } else if (u132
->going
> 0) {
1179 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1181 mutex_unlock(&u132
->scheduler_lock
);
1182 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1184 } else if (!urb
->unlinked
) {
1185 mutex_unlock(&u132
->scheduler_lock
);
1186 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1189 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1190 "unlinked=%d\n", urb
, urb
->unlinked
);
1191 mutex_unlock(&u132
->scheduler_lock
);
1192 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1197 static void u132_hcd_initial_input_recv(void *data
, struct urb
*urb
, u8
*buf
,
1198 int len
, int toggle_bits
, int error_count
, int condition_code
,
1199 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1201 struct u132_endp
*endp
= data
;
1202 struct u132
*u132
= endp
->u132
;
1203 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1204 mutex_lock(&u132
->scheduler_lock
);
1205 if (u132
->going
> 1) {
1206 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1208 mutex_unlock(&u132
->scheduler_lock
);
1209 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1211 } else if (endp
->dequeueing
) {
1212 endp
->dequeueing
= 0;
1213 mutex_unlock(&u132
->scheduler_lock
);
1214 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1216 } else if (u132
->going
> 0) {
1217 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1219 mutex_unlock(&u132
->scheduler_lock
);
1220 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1222 } else if (!urb
->unlinked
) {
1224 struct u132_ring
*ring
= endp
->ring
;
1225 u8
*u
= urb
->transfer_buffer
;
1232 urb
->actual_length
= len
;
1233 mutex_unlock(&u132
->scheduler_lock
);
1234 retval
= usb_ftdi_elan_edset_empty(u132
->platform_dev
,
1235 ring
->number
, endp
, urb
, address
, endp
->usb_endp
, 0x3,
1236 u132_hcd_initial_empty_sent
);
1238 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1241 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1242 "unlinked=%d\n", urb
, urb
->unlinked
);
1243 mutex_unlock(&u132
->scheduler_lock
);
1244 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1249 static void u132_hcd_initial_setup_sent(void *data
, struct urb
*urb
, u8
*buf
,
1250 int len
, int toggle_bits
, int error_count
, int condition_code
,
1251 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1253 struct u132_endp
*endp
= data
;
1254 struct u132
*u132
= endp
->u132
;
1255 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1256 mutex_lock(&u132
->scheduler_lock
);
1257 if (u132
->going
> 1) {
1258 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1260 mutex_unlock(&u132
->scheduler_lock
);
1261 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1263 } else if (endp
->dequeueing
) {
1264 endp
->dequeueing
= 0;
1265 mutex_unlock(&u132
->scheduler_lock
);
1266 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1268 } else if (u132
->going
> 0) {
1269 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1271 mutex_unlock(&u132
->scheduler_lock
);
1272 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1274 } else if (!urb
->unlinked
) {
1276 struct u132_ring
*ring
= endp
->ring
;
1277 mutex_unlock(&u132
->scheduler_lock
);
1278 retval
= usb_ftdi_elan_edset_input(u132
->platform_dev
,
1279 ring
->number
, endp
, urb
, address
, endp
->usb_endp
, 0,
1280 u132_hcd_initial_input_recv
);
1282 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1285 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1286 "unlinked=%d\n", urb
, urb
->unlinked
);
1287 mutex_unlock(&u132
->scheduler_lock
);
1288 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1294 * this work function is only executed from the work queue
1297 static void u132_hcd_ring_work_scheduler(struct work_struct
*work
)
1299 struct u132_ring
*ring
=
1300 container_of(work
, struct u132_ring
, scheduler
.work
);
1301 struct u132
*u132
= ring
->u132
;
1302 mutex_lock(&u132
->scheduler_lock
);
1304 mutex_unlock(&u132
->scheduler_lock
);
1305 u132_ring_put_kref(u132
, ring
);
1307 } else if (ring
->curr_endp
) {
1308 struct u132_endp
*endp
, *last_endp
= ring
->curr_endp
;
1309 unsigned long wakeup
= 0;
1310 list_for_each_entry(endp
, &last_endp
->endp_ring
, endp_ring
) {
1311 if (endp
->queue_next
== endp
->queue_last
) {
1312 } else if ((endp
->delayed
== 0)
1313 || time_after_eq(jiffies
, endp
->jiffies
)) {
1314 ring
->curr_endp
= endp
;
1315 u132_endp_cancel_work(u132
, last_endp
);
1316 u132_endp_queue_work(u132
, last_endp
, 0);
1317 mutex_unlock(&u132
->scheduler_lock
);
1318 u132_ring_put_kref(u132
, ring
);
1321 unsigned long delta
= endp
->jiffies
- jiffies
;
1326 if (last_endp
->queue_next
== last_endp
->queue_last
) {
1327 } else if ((last_endp
->delayed
== 0) || time_after_eq(jiffies
,
1328 last_endp
->jiffies
)) {
1329 u132_endp_cancel_work(u132
, last_endp
);
1330 u132_endp_queue_work(u132
, last_endp
, 0);
1331 mutex_unlock(&u132
->scheduler_lock
);
1332 u132_ring_put_kref(u132
, ring
);
1335 unsigned long delta
= last_endp
->jiffies
- jiffies
;
1340 u132_ring_requeue_work(u132
, ring
, wakeup
);
1341 mutex_unlock(&u132
->scheduler_lock
);
1344 mutex_unlock(&u132
->scheduler_lock
);
1345 u132_ring_put_kref(u132
, ring
);
1349 mutex_unlock(&u132
->scheduler_lock
);
1350 u132_ring_put_kref(u132
, ring
);
1355 static void u132_hcd_endp_work_scheduler(struct work_struct
*work
)
1357 struct u132_ring
*ring
;
1358 struct u132_endp
*endp
=
1359 container_of(work
, struct u132_endp
, scheduler
.work
);
1360 struct u132
*u132
= endp
->u132
;
1361 mutex_lock(&u132
->scheduler_lock
);
1363 if (endp
->edset_flush
) {
1364 endp
->edset_flush
= 0;
1365 if (endp
->dequeueing
)
1366 usb_ftdi_elan_edset_flush(u132
->platform_dev
,
1367 ring
->number
, endp
);
1368 mutex_unlock(&u132
->scheduler_lock
);
1369 u132_endp_put_kref(u132
, endp
);
1371 } else if (endp
->active
) {
1372 mutex_unlock(&u132
->scheduler_lock
);
1373 u132_endp_put_kref(u132
, endp
);
1375 } else if (ring
->in_use
) {
1376 mutex_unlock(&u132
->scheduler_lock
);
1377 u132_endp_put_kref(u132
, endp
);
1379 } else if (endp
->queue_next
== endp
->queue_last
) {
1380 mutex_unlock(&u132
->scheduler_lock
);
1381 u132_endp_put_kref(u132
, endp
);
1383 } else if (endp
->pipetype
== PIPE_INTERRUPT
) {
1384 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1386 mutex_unlock(&u132
->scheduler_lock
);
1387 u132_endp_put_kref(u132
, endp
);
1391 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1394 ring
->curr_endp
= endp
;
1396 mutex_unlock(&u132
->scheduler_lock
);
1397 retval
= edset_single(u132
, ring
, endp
, urb
, address
,
1398 endp
->toggle_bits
, u132_hcd_interrupt_recv
);
1400 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1403 } else if (endp
->pipetype
== PIPE_CONTROL
) {
1404 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1406 mutex_unlock(&u132
->scheduler_lock
);
1407 u132_endp_put_kref(u132
, endp
);
1409 } else if (address
== 0) {
1411 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1414 ring
->curr_endp
= endp
;
1416 mutex_unlock(&u132
->scheduler_lock
);
1417 retval
= edset_setup(u132
, ring
, endp
, urb
, address
,
1418 0x2, u132_hcd_initial_setup_sent
);
1420 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1422 } else if (endp
->usb_addr
== 0) {
1424 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1427 ring
->curr_endp
= endp
;
1429 mutex_unlock(&u132
->scheduler_lock
);
1430 retval
= edset_setup(u132
, ring
, endp
, urb
, 0, 0x2,
1431 u132_hcd_enumeration_address_sent
);
1433 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1437 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1439 address
= u132
->addr
[endp
->usb_addr
].address
;
1441 ring
->curr_endp
= endp
;
1443 mutex_unlock(&u132
->scheduler_lock
);
1444 retval
= edset_setup(u132
, ring
, endp
, urb
, address
,
1445 0x2, u132_hcd_configure_setup_sent
);
1447 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1452 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1454 mutex_unlock(&u132
->scheduler_lock
);
1455 u132_endp_put_kref(u132
, endp
);
1459 struct urb
*urb
= endp
->urb_list
[
1460 ENDP_QUEUE_MASK
& endp
->queue_next
];
1462 ring
->curr_endp
= endp
;
1464 mutex_unlock(&u132
->scheduler_lock
);
1465 retval
= edset_input(u132
, ring
, endp
, urb
,
1466 address
, endp
->toggle_bits
,
1467 u132_hcd_bulk_input_recv
);
1470 u132_hcd_giveback_urb(u132
, endp
, urb
,
1474 } else { /* output pipe */
1475 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1477 mutex_unlock(&u132
->scheduler_lock
);
1478 u132_endp_put_kref(u132
, endp
);
1482 struct urb
*urb
= endp
->urb_list
[
1483 ENDP_QUEUE_MASK
& endp
->queue_next
];
1485 ring
->curr_endp
= endp
;
1487 mutex_unlock(&u132
->scheduler_lock
);
1488 retval
= edset_output(u132
, ring
, endp
, urb
,
1489 address
, endp
->toggle_bits
,
1490 u132_hcd_bulk_output_sent
);
1493 u132_hcd_giveback_urb(u132
, endp
, urb
,
1502 static void port_power(struct u132
*u132
, int pn
, int is_on
)
1504 u132
->port
[pn
].power
= is_on
;
1509 static void u132_power(struct u132
*u132
, int is_on
)
1511 struct usb_hcd
*hcd
= u132_to_hcd(u132
)
1512 ; /* hub is inactive unless the port is powered */
1519 hcd
->state
= HC_STATE_HALT
;
1523 static int u132_periodic_reinit(struct u132
*u132
)
1526 u32 fi
= u132
->hc_fminterval
& 0x03fff;
1529 retval
= u132_read_pcimem(u132
, fminterval
, &fminterval
);
1532 fit
= fminterval
& FIT
;
1533 retval
= u132_write_pcimem(u132
, fminterval
,
1534 (fit
^ FIT
) | u132
->hc_fminterval
);
1537 return u132_write_pcimem(u132
, periodicstart
,
1538 ((9 * fi
) / 10) & 0x3fff);
1541 static char *hcfs2string(int state
)
1544 case OHCI_USB_RESET
:
1546 case OHCI_USB_RESUME
:
1549 return "operational";
1550 case OHCI_USB_SUSPEND
:
1556 static int u132_init(struct u132
*u132
)
1561 u132
->next_statechange
= jiffies
;
1562 retval
= u132_write_pcimem(u132
, intrdisable
, OHCI_INTR_MIE
);
1565 retval
= u132_read_pcimem(u132
, control
, &control
);
1568 if (u132
->num_ports
== 0) {
1570 retval
= u132_read_pcimem(u132
, roothub
.a
, &rh_a
);
1573 u132
->num_ports
= rh_a
& RH_A_NDP
;
1574 retval
= read_roothub_info(u132
);
1578 if (u132
->num_ports
> MAX_U132_PORTS
)
1585 /* Start an OHCI controller, set the BUS operational
1586 * resets USB and controller
1589 static int u132_run(struct u132
*u132
)
1598 int mask
= OHCI_INTR_INIT
;
1599 int first
= u132
->hc_fminterval
== 0;
1601 int reset_timeout
= 30; /* ... allow extra time */
1605 retval
= u132_read_pcimem(u132
, fminterval
, &temp
);
1608 u132
->hc_fminterval
= temp
& 0x3fff;
1609 u132
->hc_fminterval
|= FSMP(u132
->hc_fminterval
) << 16;
1611 retval
= u132_read_pcimem(u132
, control
, &u132
->hc_control
);
1614 dev_info(&u132
->platform_dev
->dev
, "resetting from state '%s', control "
1615 "= %08X\n", hcfs2string(u132
->hc_control
& OHCI_CTRL_HCFS
),
1617 switch (u132
->hc_control
& OHCI_CTRL_HCFS
) {
1621 case OHCI_USB_SUSPEND
:
1622 case OHCI_USB_RESUME
:
1623 u132
->hc_control
&= OHCI_CTRL_RWC
;
1624 u132
->hc_control
|= OHCI_USB_RESUME
;
1628 u132
->hc_control
&= OHCI_CTRL_RWC
;
1629 u132
->hc_control
|= OHCI_USB_RESET
;
1633 retval
= u132_write_pcimem(u132
, control
, u132
->hc_control
);
1636 retval
= u132_read_pcimem(u132
, control
, &control
);
1640 retval
= u132_read_pcimem(u132
, roothub
.a
, &roothub_a
);
1643 if (!(roothub_a
& RH_A_NPS
)) {
1644 int temp
; /* power down each port */
1645 for (temp
= 0; temp
< u132
->num_ports
; temp
++) {
1646 retval
= u132_write_pcimem(u132
,
1647 roothub
.portstatus
[temp
], RH_PS_LSDA
);
1652 retval
= u132_read_pcimem(u132
, control
, &control
);
1656 retval
= u132_read_pcimem(u132
, cmdstatus
, &status
);
1659 retval
= u132_write_pcimem(u132
, cmdstatus
, OHCI_HCR
);
1663 retval
= u132_read_pcimem(u132
, cmdstatus
, &status
);
1666 if (0 != (status
& OHCI_HCR
)) {
1667 if (--reset_timeout
== 0) {
1668 dev_err(&u132
->platform_dev
->dev
, "USB HC reset"
1677 if (u132
->flags
& OHCI_QUIRK_INITRESET
) {
1678 retval
= u132_write_pcimem(u132
, control
, u132
->hc_control
);
1681 retval
= u132_read_pcimem(u132
, control
, &control
);
1685 retval
= u132_write_pcimem(u132
, ed_controlhead
, 0x00000000);
1688 retval
= u132_write_pcimem(u132
, ed_bulkhead
, 0x11000000);
1691 retval
= u132_write_pcimem(u132
, hcca
, 0x00000000);
1694 retval
= u132_periodic_reinit(u132
);
1697 retval
= u132_read_pcimem(u132
, fminterval
, &fminterval
);
1700 retval
= u132_read_pcimem(u132
, periodicstart
, &periodicstart
);
1703 if (0 == (fminterval
& 0x3fff0000) || 0 == periodicstart
) {
1704 if (!(u132
->flags
& OHCI_QUIRK_INITRESET
)) {
1705 u132
->flags
|= OHCI_QUIRK_INITRESET
;
1708 dev_err(&u132
->platform_dev
->dev
, "init err(%08x %04x)"
1709 "\n", fminterval
, periodicstart
);
1710 } /* start controller operations */
1711 u132
->hc_control
&= OHCI_CTRL_RWC
;
1712 u132
->hc_control
|= OHCI_CONTROL_INIT
| OHCI_CTRL_BLE
| OHCI_USB_OPER
;
1713 retval
= u132_write_pcimem(u132
, control
, u132
->hc_control
);
1716 retval
= u132_write_pcimem(u132
, cmdstatus
, OHCI_BLF
);
1719 retval
= u132_read_pcimem(u132
, cmdstatus
, &cmdstatus
);
1722 retval
= u132_read_pcimem(u132
, control
, &control
);
1725 u132_to_hcd(u132
)->state
= HC_STATE_RUNNING
;
1726 retval
= u132_write_pcimem(u132
, roothub
.status
, RH_HS_DRWE
);
1729 retval
= u132_write_pcimem(u132
, intrstatus
, mask
);
1732 retval
= u132_write_pcimem(u132
, intrdisable
,
1733 OHCI_INTR_MIE
| OHCI_INTR_OC
| OHCI_INTR_RHSC
| OHCI_INTR_FNO
|
1734 OHCI_INTR_UE
| OHCI_INTR_RD
| OHCI_INTR_SF
| OHCI_INTR_WDH
|
1737 return retval
; /* handle root hub init quirks ... */
1738 retval
= u132_read_pcimem(u132
, roothub
.a
, &roothub_a
);
1741 roothub_a
&= ~(RH_A_PSM
| RH_A_OCPM
);
1742 if (u132
->flags
& OHCI_QUIRK_SUPERIO
) {
1743 roothub_a
|= RH_A_NOCP
;
1744 roothub_a
&= ~(RH_A_POTPGT
| RH_A_NPS
);
1745 retval
= u132_write_pcimem(u132
, roothub
.a
, roothub_a
);
1748 } else if ((u132
->flags
& OHCI_QUIRK_AMD756
) || distrust_firmware
) {
1749 roothub_a
|= RH_A_NPS
;
1750 retval
= u132_write_pcimem(u132
, roothub
.a
, roothub_a
);
1754 retval
= u132_write_pcimem(u132
, roothub
.status
, RH_HS_LPSC
);
1757 retval
= u132_write_pcimem(u132
, roothub
.b
,
1758 (roothub_a
& RH_A_NPS
) ? 0 : RH_B_PPCM
);
1761 retval
= u132_read_pcimem(u132
, control
, &control
);
1764 mdelay((roothub_a
>> 23) & 0x1fe);
1765 u132_to_hcd(u132
)->state
= HC_STATE_RUNNING
;
1769 static void u132_hcd_stop(struct usb_hcd
*hcd
)
1771 struct u132
*u132
= hcd_to_u132(hcd
);
1772 if (u132
->going
> 1) {
1773 dev_err(&u132
->platform_dev
->dev
, "u132 device %p(hcd=%p) has b"
1774 "een removed %d\n", u132
, hcd
, u132
->going
);
1775 } else if (u132
->going
> 0) {
1776 dev_err(&u132
->platform_dev
->dev
, "device hcd=%p is being remov"
1779 mutex_lock(&u132
->sw_lock
);
1781 u132_power(u132
, 0);
1782 mutex_unlock(&u132
->sw_lock
);
1786 static int u132_hcd_start(struct usb_hcd
*hcd
)
1788 struct u132
*u132
= hcd_to_u132(hcd
);
1789 if (u132
->going
> 1) {
1790 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1793 } else if (u132
->going
> 0) {
1794 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
1796 } else if (hcd
->self
.controller
) {
1798 struct platform_device
*pdev
=
1799 to_platform_device(hcd
->self
.controller
);
1800 u16 vendor
= ((struct u132_platform_data
*)
1801 dev_get_platdata(&pdev
->dev
))->vendor
;
1802 u16 device
= ((struct u132_platform_data
*)
1803 dev_get_platdata(&pdev
->dev
))->device
;
1804 mutex_lock(&u132
->sw_lock
);
1806 if (vendor
== PCI_VENDOR_ID_AMD
&& device
== 0x740c) {
1807 u132
->flags
= OHCI_QUIRK_AMD756
;
1808 } else if (vendor
== PCI_VENDOR_ID_OPTI
&& device
== 0xc861) {
1809 dev_err(&u132
->platform_dev
->dev
, "WARNING: OPTi workar"
1810 "ounds unavailable\n");
1811 } else if (vendor
== PCI_VENDOR_ID_COMPAQ
&& device
== 0xa0f8)
1812 u132
->flags
|= OHCI_QUIRK_ZFMICRO
;
1813 retval
= u132_run(u132
);
1819 mutex_unlock(&u132
->sw_lock
);
1822 dev_err(&u132
->platform_dev
->dev
, "platform_device missing\n");
1827 static int u132_hcd_reset(struct usb_hcd
*hcd
)
1829 struct u132
*u132
= hcd_to_u132(hcd
);
1830 if (u132
->going
> 1) {
1831 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1834 } else if (u132
->going
> 0) {
1835 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
1839 mutex_lock(&u132
->sw_lock
);
1840 retval
= u132_init(u132
);
1845 mutex_unlock(&u132
->sw_lock
);
1850 static int create_endpoint_and_queue_int(struct u132
*u132
,
1851 struct u132_udev
*udev
, struct urb
*urb
,
1852 struct usb_device
*usb_dev
, u8 usb_addr
, u8 usb_endp
, u8 address
,
1855 struct u132_ring
*ring
;
1859 struct u132_endp
*endp
= kmalloc(sizeof(struct u132_endp
), mem_flags
);
1864 spin_lock_init(&endp
->queue_lock
.slock
);
1865 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
1866 rc
= usb_hcd_link_urb_to_ep(u132_to_hcd(u132
), urb
);
1868 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
1873 endp_number
= ++u132
->num_endpoints
;
1874 urb
->ep
->hcpriv
= u132
->endp
[endp_number
- 1] = endp
;
1875 INIT_DELAYED_WORK(&endp
->scheduler
, u132_hcd_endp_work_scheduler
);
1876 INIT_LIST_HEAD(&endp
->urb_more
);
1877 ring
= endp
->ring
= &u132
->ring
[0];
1878 if (ring
->curr_endp
) {
1879 list_add_tail(&endp
->endp_ring
, &ring
->curr_endp
->endp_ring
);
1881 INIT_LIST_HEAD(&endp
->endp_ring
);
1882 ring
->curr_endp
= endp
;
1885 endp
->dequeueing
= 0;
1886 endp
->edset_flush
= 0;
1889 endp
->endp_number
= endp_number
;
1891 endp
->hep
= urb
->ep
;
1892 endp
->pipetype
= usb_pipetype(urb
->pipe
);
1893 u132_endp_init_kref(u132
, endp
);
1894 if (usb_pipein(urb
->pipe
)) {
1895 endp
->toggle_bits
= 0x2;
1896 usb_settoggle(udev
->usb_device
, usb_endp
, 0, 0);
1899 udev
->endp_number_in
[usb_endp
] = endp_number
;
1900 u132_udev_get_kref(u132
, udev
);
1902 endp
->toggle_bits
= 0x2;
1903 usb_settoggle(udev
->usb_device
, usb_endp
, 1, 0);
1906 udev
->endp_number_out
[usb_endp
] = endp_number
;
1907 u132_udev_get_kref(u132
, udev
);
1911 endp
->jiffies
= jiffies
+ msecs_to_jiffies(urb
->interval
);
1912 endp
->udev_number
= address
;
1913 endp
->usb_addr
= usb_addr
;
1914 endp
->usb_endp
= usb_endp
;
1915 endp
->queue_size
= 1;
1916 endp
->queue_last
= 0;
1917 endp
->queue_next
= 0;
1918 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
1919 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
1920 u132_endp_queue_work(u132
, endp
, msecs_to_jiffies(urb
->interval
));
1924 static int queue_int_on_old_endpoint(struct u132
*u132
,
1925 struct u132_udev
*udev
, struct urb
*urb
,
1926 struct usb_device
*usb_dev
, struct u132_endp
*endp
, u8 usb_addr
,
1927 u8 usb_endp
, u8 address
)
1931 endp
->jiffies
= jiffies
+ msecs_to_jiffies(urb
->interval
);
1932 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
1933 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
1935 struct u132_urbq
*urbq
= kmalloc(sizeof(struct u132_urbq
),
1938 endp
->queue_size
-= 1;
1941 list_add_tail(&urbq
->urb_more
, &endp
->urb_more
);
1948 static int create_endpoint_and_queue_bulk(struct u132
*u132
,
1949 struct u132_udev
*udev
, struct urb
*urb
,
1950 struct usb_device
*usb_dev
, u8 usb_addr
, u8 usb_endp
, u8 address
,
1954 struct u132_ring
*ring
;
1958 struct u132_endp
*endp
= kmalloc(sizeof(struct u132_endp
), mem_flags
);
1963 spin_lock_init(&endp
->queue_lock
.slock
);
1964 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
1965 rc
= usb_hcd_link_urb_to_ep(u132_to_hcd(u132
), urb
);
1967 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
1972 endp_number
= ++u132
->num_endpoints
;
1973 urb
->ep
->hcpriv
= u132
->endp
[endp_number
- 1] = endp
;
1974 INIT_DELAYED_WORK(&endp
->scheduler
, u132_hcd_endp_work_scheduler
);
1975 INIT_LIST_HEAD(&endp
->urb_more
);
1976 endp
->dequeueing
= 0;
1977 endp
->edset_flush
= 0;
1980 endp
->endp_number
= endp_number
;
1982 endp
->hep
= urb
->ep
;
1983 endp
->pipetype
= usb_pipetype(urb
->pipe
);
1984 u132_endp_init_kref(u132
, endp
);
1985 if (usb_pipein(urb
->pipe
)) {
1986 endp
->toggle_bits
= 0x2;
1987 usb_settoggle(udev
->usb_device
, usb_endp
, 0, 0);
1991 udev
->endp_number_in
[usb_endp
] = endp_number
;
1992 u132_udev_get_kref(u132
, udev
);
1994 endp
->toggle_bits
= 0x2;
1995 usb_settoggle(udev
->usb_device
, usb_endp
, 1, 0);
1999 udev
->endp_number_out
[usb_endp
] = endp_number
;
2000 u132_udev_get_kref(u132
, udev
);
2002 ring
= endp
->ring
= &u132
->ring
[ring_number
- 1];
2003 if (ring
->curr_endp
) {
2004 list_add_tail(&endp
->endp_ring
, &ring
->curr_endp
->endp_ring
);
2006 INIT_LIST_HEAD(&endp
->endp_ring
);
2007 ring
->curr_endp
= endp
;
2011 endp
->udev_number
= address
;
2012 endp
->usb_addr
= usb_addr
;
2013 endp
->usb_endp
= usb_endp
;
2014 endp
->queue_size
= 1;
2015 endp
->queue_last
= 0;
2016 endp
->queue_next
= 0;
2017 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
2018 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2019 u132_endp_queue_work(u132
, endp
, 0);
2023 static int queue_bulk_on_old_endpoint(struct u132
*u132
, struct u132_udev
*udev
,
2025 struct usb_device
*usb_dev
, struct u132_endp
*endp
, u8 usb_addr
,
2026 u8 usb_endp
, u8 address
)
2029 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2030 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
2032 struct u132_urbq
*urbq
= kmalloc(sizeof(struct u132_urbq
),
2035 endp
->queue_size
-= 1;
2038 list_add_tail(&urbq
->urb_more
, &endp
->urb_more
);
2045 static int create_endpoint_and_queue_control(struct u132
*u132
,
2047 struct usb_device
*usb_dev
, u8 usb_addr
, u8 usb_endp
,
2050 struct u132_ring
*ring
;
2054 struct u132_endp
*endp
= kmalloc(sizeof(struct u132_endp
), mem_flags
);
2059 spin_lock_init(&endp
->queue_lock
.slock
);
2060 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
2061 rc
= usb_hcd_link_urb_to_ep(u132_to_hcd(u132
), urb
);
2063 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2068 endp_number
= ++u132
->num_endpoints
;
2069 urb
->ep
->hcpriv
= u132
->endp
[endp_number
- 1] = endp
;
2070 INIT_DELAYED_WORK(&endp
->scheduler
, u132_hcd_endp_work_scheduler
);
2071 INIT_LIST_HEAD(&endp
->urb_more
);
2072 ring
= endp
->ring
= &u132
->ring
[0];
2073 if (ring
->curr_endp
) {
2074 list_add_tail(&endp
->endp_ring
, &ring
->curr_endp
->endp_ring
);
2076 INIT_LIST_HEAD(&endp
->endp_ring
);
2077 ring
->curr_endp
= endp
;
2080 endp
->dequeueing
= 0;
2081 endp
->edset_flush
= 0;
2084 endp
->endp_number
= endp_number
;
2086 endp
->hep
= urb
->ep
;
2087 u132_endp_init_kref(u132
, endp
);
2088 u132_endp_get_kref(u132
, endp
);
2089 if (usb_addr
== 0) {
2090 u8 address
= u132
->addr
[usb_addr
].address
;
2091 struct u132_udev
*udev
= &u132
->udev
[address
];
2092 endp
->udev_number
= address
;
2093 endp
->usb_addr
= usb_addr
;
2094 endp
->usb_endp
= usb_endp
;
2097 endp
->pipetype
= usb_pipetype(urb
->pipe
);
2098 u132_udev_init_kref(u132
, udev
);
2099 u132_udev_get_kref(u132
, udev
);
2100 udev
->endp_number_in
[usb_endp
] = endp_number
;
2101 udev
->endp_number_out
[usb_endp
] = endp_number
;
2103 endp
->queue_size
= 1;
2104 endp
->queue_last
= 0;
2105 endp
->queue_next
= 0;
2106 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
2107 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2108 u132_endp_queue_work(u132
, endp
, 0);
2110 } else { /*(usb_addr > 0) */
2111 u8 address
= u132
->addr
[usb_addr
].address
;
2112 struct u132_udev
*udev
= &u132
->udev
[address
];
2113 endp
->udev_number
= address
;
2114 endp
->usb_addr
= usb_addr
;
2115 endp
->usb_endp
= usb_endp
;
2118 endp
->pipetype
= usb_pipetype(urb
->pipe
);
2119 u132_udev_get_kref(u132
, udev
);
2120 udev
->enumeration
= 2;
2121 udev
->endp_number_in
[usb_endp
] = endp_number
;
2122 udev
->endp_number_out
[usb_endp
] = endp_number
;
2124 endp
->queue_size
= 1;
2125 endp
->queue_last
= 0;
2126 endp
->queue_next
= 0;
2127 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
2128 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2129 u132_endp_queue_work(u132
, endp
, 0);
2134 static int queue_control_on_old_endpoint(struct u132
*u132
,
2136 struct usb_device
*usb_dev
, struct u132_endp
*endp
, u8 usb_addr
,
2139 if (usb_addr
== 0) {
2140 if (usb_pipein(urb
->pipe
)) {
2142 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2143 endp
->urb_list
[ENDP_QUEUE_MASK
&
2144 endp
->queue_last
++] = urb
;
2146 struct u132_urbq
*urbq
=
2147 kmalloc(sizeof(struct u132_urbq
),
2150 endp
->queue_size
-= 1;
2153 list_add_tail(&urbq
->urb_more
,
2159 } else { /* usb_pipeout(urb->pipe) */
2160 struct u132_addr
*addr
= &u132
->addr
[usb_dev
->devnum
];
2161 int I
= MAX_U132_UDEVS
;
2164 struct u132_udev
*udev
= &u132
->udev
[++i
];
2165 if (udev
->usb_device
) {
2168 udev
->enumeration
= 1;
2169 u132
->addr
[0].address
= i
;
2170 endp
->udev_number
= i
;
2171 udev
->udev_number
= i
;
2172 udev
->usb_addr
= usb_dev
->devnum
;
2173 u132_udev_init_kref(u132
, udev
);
2174 udev
->endp_number_in
[usb_endp
] =
2176 u132_udev_get_kref(u132
, udev
);
2177 udev
->endp_number_out
[usb_endp
] =
2179 udev
->usb_device
= usb_dev
;
2180 ((u8
*) (urb
->setup_packet
))[2] =
2182 u132_udev_get_kref(u132
, udev
);
2187 dev_err(&u132
->platform_dev
->dev
, "run out of d"
2192 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2193 endp
->urb_list
[ENDP_QUEUE_MASK
&
2194 endp
->queue_last
++] = urb
;
2196 struct u132_urbq
*urbq
=
2197 kmalloc(sizeof(struct u132_urbq
),
2200 endp
->queue_size
-= 1;
2203 list_add_tail(&urbq
->urb_more
,
2210 } else { /*(usb_addr > 0) */
2211 u8 address
= u132
->addr
[usb_addr
].address
;
2212 struct u132_udev
*udev
= &u132
->udev
[address
];
2214 if (udev
->enumeration
!= 2)
2215 udev
->enumeration
= 2;
2216 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2217 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] =
2220 struct u132_urbq
*urbq
=
2221 kmalloc(sizeof(struct u132_urbq
), GFP_ATOMIC
);
2223 endp
->queue_size
-= 1;
2226 list_add_tail(&urbq
->urb_more
, &endp
->urb_more
);
2234 static int u132_urb_enqueue(struct usb_hcd
*hcd
, struct urb
*urb
,
2237 struct u132
*u132
= hcd_to_u132(hcd
);
2238 if (irqs_disabled()) {
2239 if (gfpflags_allow_blocking(mem_flags
)) {
2240 printk(KERN_ERR
"invalid context for function that might sleep\n");
2244 if (u132
->going
> 1) {
2245 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2248 } else if (u132
->going
> 0) {
2249 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
2253 u8 usb_addr
= usb_pipedevice(urb
->pipe
);
2254 u8 usb_endp
= usb_pipeendpoint(urb
->pipe
);
2255 struct usb_device
*usb_dev
= urb
->dev
;
2256 if (usb_pipetype(urb
->pipe
) == PIPE_INTERRUPT
) {
2257 u8 address
= u132
->addr
[usb_addr
].address
;
2258 struct u132_udev
*udev
= &u132
->udev
[address
];
2259 struct u132_endp
*endp
= urb
->ep
->hcpriv
;
2260 urb
->actual_length
= 0;
2264 spin_lock_irqsave(&endp
->queue_lock
.slock
,
2266 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
2268 retval
= queue_int_on_old_endpoint(
2274 usb_hcd_unlink_urb_from_ep(
2277 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2282 u132_endp_queue_work(u132
, endp
,
2283 msecs_to_jiffies(urb
->interval
))
2287 } else if (u132
->num_endpoints
== MAX_U132_ENDPS
) {
2289 } else { /*(endp == NULL) */
2290 return create_endpoint_and_queue_int(u132
, udev
,
2291 urb
, usb_dev
, usb_addr
,
2292 usb_endp
, address
, mem_flags
);
2294 } else if (usb_pipetype(urb
->pipe
) == PIPE_ISOCHRONOUS
) {
2295 dev_err(&u132
->platform_dev
->dev
, "the hardware does no"
2296 "t support PIPE_ISOCHRONOUS\n");
2298 } else if (usb_pipetype(urb
->pipe
) == PIPE_BULK
) {
2299 u8 address
= u132
->addr
[usb_addr
].address
;
2300 struct u132_udev
*udev
= &u132
->udev
[address
];
2301 struct u132_endp
*endp
= urb
->ep
->hcpriv
;
2302 urb
->actual_length
= 0;
2306 spin_lock_irqsave(&endp
->queue_lock
.slock
,
2308 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
2310 retval
= queue_bulk_on_old_endpoint(
2316 usb_hcd_unlink_urb_from_ep(
2319 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2324 u132_endp_queue_work(u132
, endp
, 0);
2327 } else if (u132
->num_endpoints
== MAX_U132_ENDPS
) {
2330 return create_endpoint_and_queue_bulk(u132
,
2331 udev
, urb
, usb_dev
, usb_addr
,
2332 usb_endp
, address
, mem_flags
);
2334 struct u132_endp
*endp
= urb
->ep
->hcpriv
;
2336 u8
*b
= urb
->setup_packet
;
2338 char data
[30 * 3 + 4];
2340 int m
= (sizeof(data
) - 1) / 3;
2343 while (urb_size
-- > 0) {
2345 } else if (i
++ < m
) {
2346 int w
= sprintf(d
, " %02X", *b
++);
2350 d
+= sprintf(d
, " ..");
2355 spin_lock_irqsave(&endp
->queue_lock
.slock
,
2357 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
2359 retval
= queue_control_on_old_endpoint(
2364 usb_hcd_unlink_urb_from_ep(
2367 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2372 u132_endp_queue_work(u132
, endp
, 0);
2375 } else if (u132
->num_endpoints
== MAX_U132_ENDPS
) {
2378 return create_endpoint_and_queue_control(u132
,
2379 urb
, usb_dev
, usb_addr
, usb_endp
,
2385 static int dequeue_from_overflow_chain(struct u132
*u132
,
2386 struct u132_endp
*endp
, struct urb
*urb
)
2388 struct u132_urbq
*urbq
;
2390 list_for_each_entry(urbq
, &endp
->urb_more
, urb_more
) {
2391 if (urbq
->urb
== urb
) {
2392 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
2393 list_del(&urbq
->urb_more
);
2394 endp
->queue_size
-= 1;
2395 urb
->error_count
= 0;
2396 usb_hcd_giveback_urb(hcd
, urb
, 0);
2401 dev_err(&u132
->platform_dev
->dev
, "urb=%p not found in endp[%d]=%p ring"
2402 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2403 "\n", urb
, endp
->endp_number
, endp
, endp
->ring
->number
,
2404 endp
->input
? 'I' : ' ', endp
->output
? 'O' : ' ',
2405 endp
->usb_endp
, endp
->usb_addr
, endp
->queue_size
,
2406 endp
->queue_next
, endp
->queue_last
);
2410 static int u132_endp_urb_dequeue(struct u132
*u132
, struct u132_endp
*endp
,
2411 struct urb
*urb
, int status
)
2416 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
2417 rc
= usb_hcd_check_unlink_urb(u132_to_hcd(u132
), urb
, status
);
2419 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2422 if (endp
->queue_size
== 0) {
2423 dev_err(&u132
->platform_dev
->dev
, "urb=%p not found in endp[%d]"
2424 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb
,
2425 endp
->endp_number
, endp
, endp
->ring
->number
,
2426 endp
->input
? 'I' : ' ', endp
->output
? 'O' : ' ',
2427 endp
->usb_endp
, endp
->usb_addr
);
2428 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2431 if (urb
== endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_next
]) {
2433 endp
->dequeueing
= 1;
2434 endp
->edset_flush
= 1;
2435 u132_endp_queue_work(u132
, endp
, 0);
2436 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2439 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2440 u132_hcd_abandon_urb(u132
, endp
, urb
, status
);
2445 u16 queue_size
= endp
->queue_size
;
2446 u16 queue_scan
= endp
->queue_next
;
2447 struct urb
**urb_slot
= NULL
;
2448 while (++queue_list
< ENDP_QUEUE_SIZE
&& --queue_size
> 0) {
2449 if (urb
== endp
->urb_list
[ENDP_QUEUE_MASK
&
2451 urb_slot
= &endp
->urb_list
[ENDP_QUEUE_MASK
&
2457 while (++queue_list
< ENDP_QUEUE_SIZE
&& --queue_size
> 0) {
2458 *urb_slot
= endp
->urb_list
[ENDP_QUEUE_MASK
&
2460 urb_slot
= &endp
->urb_list
[ENDP_QUEUE_MASK
&
2464 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
2466 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
2467 endp
->queue_size
-= 1;
2468 if (list_empty(&endp
->urb_more
)) {
2469 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2472 struct list_head
*next
= endp
->urb_more
.next
;
2473 struct u132_urbq
*urbq
= list_entry(next
,
2474 struct u132_urbq
, urb_more
);
2476 *urb_slot
= urbq
->urb
;
2477 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2481 urb
->error_count
= 0;
2482 usb_hcd_giveback_urb(hcd
, urb
, status
);
2484 } else if (list_empty(&endp
->urb_more
)) {
2485 dev_err(&u132
->platform_dev
->dev
, "urb=%p not found in "
2486 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2487 "=%d size=%d next=%04X last=%04X\n", urb
,
2488 endp
->endp_number
, endp
, endp
->ring
->number
,
2489 endp
->input
? 'I' : ' ',
2490 endp
->output
? 'O' : ' ', endp
->usb_endp
,
2491 endp
->usb_addr
, endp
->queue_size
,
2492 endp
->queue_next
, endp
->queue_last
);
2493 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2498 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132
), urb
);
2499 retval
= dequeue_from_overflow_chain(u132
, endp
,
2501 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2507 static int u132_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
, int status
)
2509 struct u132
*u132
= hcd_to_u132(hcd
);
2510 if (u132
->going
> 2) {
2511 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2515 u8 usb_addr
= usb_pipedevice(urb
->pipe
);
2516 u8 usb_endp
= usb_pipeendpoint(urb
->pipe
);
2517 u8 address
= u132
->addr
[usb_addr
].address
;
2518 struct u132_udev
*udev
= &u132
->udev
[address
];
2519 if (usb_pipein(urb
->pipe
)) {
2520 u8 endp_number
= udev
->endp_number_in
[usb_endp
];
2521 struct u132_endp
*endp
= u132
->endp
[endp_number
- 1];
2522 return u132_endp_urb_dequeue(u132
, endp
, urb
, status
);
2524 u8 endp_number
= udev
->endp_number_out
[usb_endp
];
2525 struct u132_endp
*endp
= u132
->endp
[endp_number
- 1];
2526 return u132_endp_urb_dequeue(u132
, endp
, urb
, status
);
2531 static void u132_endpoint_disable(struct usb_hcd
*hcd
,
2532 struct usb_host_endpoint
*hep
)
2534 struct u132
*u132
= hcd_to_u132(hcd
);
2535 if (u132
->going
> 2) {
2536 dev_err(&u132
->platform_dev
->dev
, "u132 device %p(hcd=%p hep=%p"
2537 ") has been removed %d\n", u132
, hcd
, hep
,
2540 struct u132_endp
*endp
= hep
->hcpriv
;
2542 u132_endp_put_kref(u132
, endp
);
2546 static int u132_get_frame(struct usb_hcd
*hcd
)
2548 struct u132
*u132
= hcd_to_u132(hcd
);
2549 if (u132
->going
> 1) {
2550 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2553 } else if (u132
->going
> 0) {
2554 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2558 dev_err(&u132
->platform_dev
->dev
, "TODO: u132_get_frame\n");
2564 static int u132_roothub_descriptor(struct u132
*u132
,
2565 struct usb_hub_descriptor
*desc
)
2571 retval
= u132_read_pcimem(u132
, roothub
.a
, &rh_a
);
2574 desc
->bDescriptorType
= USB_DT_HUB
;
2575 desc
->bPwrOn2PwrGood
= (rh_a
& RH_A_POTPGT
) >> 24;
2576 desc
->bHubContrCurrent
= 0;
2577 desc
->bNbrPorts
= u132
->num_ports
;
2578 temp
= 1 + (u132
->num_ports
/ 8);
2579 desc
->bDescLength
= 7 + 2 * temp
;
2580 temp
= HUB_CHAR_COMMON_LPSM
| HUB_CHAR_COMMON_OCPM
;
2581 if (rh_a
& RH_A_NPS
)
2582 temp
|= HUB_CHAR_NO_LPSM
;
2583 if (rh_a
& RH_A_PSM
)
2584 temp
|= HUB_CHAR_INDV_PORT_LPSM
;
2585 if (rh_a
& RH_A_NOCP
)
2586 temp
|= HUB_CHAR_NO_OCPM
;
2587 else if (rh_a
& RH_A_OCPM
)
2588 temp
|= HUB_CHAR_INDV_PORT_OCPM
;
2589 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
2590 retval
= u132_read_pcimem(u132
, roothub
.b
, &rh_b
);
2593 memset(desc
->u
.hs
.DeviceRemovable
, 0xff,
2594 sizeof(desc
->u
.hs
.DeviceRemovable
));
2595 desc
->u
.hs
.DeviceRemovable
[0] = rh_b
& RH_B_DR
;
2596 if (u132
->num_ports
> 7) {
2597 desc
->u
.hs
.DeviceRemovable
[1] = (rh_b
& RH_B_DR
) >> 8;
2598 desc
->u
.hs
.DeviceRemovable
[2] = 0xff;
2600 desc
->u
.hs
.DeviceRemovable
[1] = 0xff;
2604 static int u132_roothub_status(struct u132
*u132
, __le32
*desc
)
2607 int ret_status
= u132_read_pcimem(u132
, roothub
.status
, &rh_status
);
2608 *desc
= cpu_to_le32(rh_status
);
2612 static int u132_roothub_portstatus(struct u132
*u132
, __le32
*desc
, u16 wIndex
)
2614 if (wIndex
== 0 || wIndex
> u132
->num_ports
) {
2617 int port
= wIndex
- 1;
2618 u32 rh_portstatus
= -1;
2619 int ret_portstatus
= u132_read_pcimem(u132
,
2620 roothub
.portstatus
[port
], &rh_portstatus
);
2621 *desc
= cpu_to_le32(rh_portstatus
);
2622 if (*(u16
*) (desc
+ 2)) {
2623 dev_info(&u132
->platform_dev
->dev
, "Port %d Status Chan"
2624 "ge = %08X\n", port
, *desc
);
2626 return ret_portstatus
;
2631 /* this timer value might be vendor-specific ... */
2632 #define PORT_RESET_HW_MSEC 10
2633 #define PORT_RESET_MSEC 10
2634 /* wrap-aware logic morphed from <linux/jiffies.h> */
2635 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2636 static int u132_roothub_portreset(struct u132
*u132
, int port_index
)
2642 retval
= u132_read_pcimem(u132
, fmnumber
, &fmnumber
);
2646 reset_done
= now
+ PORT_RESET_MSEC
;
2650 retval
= u132_read_pcimem(u132
,
2651 roothub
.portstatus
[port_index
], &portstat
);
2654 if (RH_PS_PRS
& portstat
)
2658 } while (tick_before(now
, reset_done
));
2659 if (RH_PS_PRS
& portstat
)
2661 if (RH_PS_CCS
& portstat
) {
2662 if (RH_PS_PRSC
& portstat
) {
2663 retval
= u132_write_pcimem(u132
,
2664 roothub
.portstatus
[port_index
],
2670 break; /* start the next reset,
2671 sleep till it's probably done */
2672 retval
= u132_write_pcimem(u132
, roothub
.portstatus
[port_index
],
2676 msleep(PORT_RESET_HW_MSEC
);
2677 retval
= u132_read_pcimem(u132
, fmnumber
, &fmnumber
);
2681 } while (tick_before(now
, reset_done
));
2685 static int u132_roothub_setportfeature(struct u132
*u132
, u16 wValue
,
2688 if (wIndex
== 0 || wIndex
> u132
->num_ports
) {
2691 int port_index
= wIndex
- 1;
2692 struct u132_port
*port
= &u132
->port
[port_index
];
2693 port
->Status
&= ~(1 << wValue
);
2695 case USB_PORT_FEAT_SUSPEND
:
2696 return u132_write_pcimem(u132
,
2697 roothub
.portstatus
[port_index
], RH_PS_PSS
);
2698 case USB_PORT_FEAT_POWER
:
2699 return u132_write_pcimem(u132
,
2700 roothub
.portstatus
[port_index
], RH_PS_PPS
);
2701 case USB_PORT_FEAT_RESET
:
2702 return u132_roothub_portreset(u132
, port_index
);
2709 static int u132_roothub_clearportfeature(struct u132
*u132
, u16 wValue
,
2712 if (wIndex
== 0 || wIndex
> u132
->num_ports
) {
2715 int port_index
= wIndex
- 1;
2717 struct u132_port
*port
= &u132
->port
[port_index
];
2718 port
->Status
&= ~(1 << wValue
);
2720 case USB_PORT_FEAT_ENABLE
:
2723 case USB_PORT_FEAT_C_ENABLE
:
2726 case USB_PORT_FEAT_SUSPEND
:
2728 if ((u132
->hc_control
& OHCI_CTRL_HCFS
)
2730 dev_err(&u132
->platform_dev
->dev
, "TODO resume_"
2734 case USB_PORT_FEAT_C_SUSPEND
:
2737 case USB_PORT_FEAT_POWER
:
2740 case USB_PORT_FEAT_C_CONNECTION
:
2743 case USB_PORT_FEAT_C_OVER_CURRENT
:
2746 case USB_PORT_FEAT_C_RESET
:
2752 return u132_write_pcimem(u132
, roothub
.portstatus
[port_index
],
2758 /* the virtual root hub timer IRQ checks for hub status*/
2759 static int u132_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
2761 struct u132
*u132
= hcd_to_u132(hcd
);
2762 if (u132
->going
> 1) {
2763 dev_err(&u132
->platform_dev
->dev
, "device hcd=%p has been remov"
2764 "ed %d\n", hcd
, u132
->going
);
2766 } else if (u132
->going
> 0) {
2767 dev_err(&u132
->platform_dev
->dev
, "device hcd=%p is being remov"
2771 int i
, changed
= 0, length
= 1;
2772 if (u132
->flags
& OHCI_QUIRK_AMD756
) {
2773 if ((u132
->hc_roothub_a
& RH_A_NDP
) > MAX_ROOT_PORTS
) {
2774 dev_err(&u132
->platform_dev
->dev
, "bogus NDP, r"
2775 "ereads as NDP=%d\n",
2776 u132
->hc_roothub_a
& RH_A_NDP
);
2780 if (u132
->hc_roothub_status
& (RH_HS_LPSC
| RH_HS_OCIC
))
2781 buf
[0] = changed
= 1;
2784 if (u132
->num_ports
> 7) {
2788 for (i
= 0; i
< u132
->num_ports
; i
++) {
2789 if (u132
->hc_roothub_portstatus
[i
] & (RH_PS_CSC
|
2790 RH_PS_PESC
| RH_PS_PSSC
| RH_PS_OCIC
|
2794 buf
[0] |= 1 << (i
+ 1);
2796 buf
[1] |= 1 << (i
- 7);
2799 if (!(u132
->hc_roothub_portstatus
[i
] & RH_PS_CCS
))
2802 if ((u132
->hc_roothub_portstatus
[i
] & RH_PS_PSS
))
2806 return changed
? length
: 0;
2810 static int u132_hub_control(struct usb_hcd
*hcd
, u16 typeReq
, u16 wValue
,
2811 u16 wIndex
, char *buf
, u16 wLength
)
2813 struct u132
*u132
= hcd_to_u132(hcd
);
2814 if (u132
->going
> 1) {
2815 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2818 } else if (u132
->going
> 0) {
2819 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2823 mutex_lock(&u132
->sw_lock
);
2825 case ClearHubFeature
:
2827 case C_HUB_OVER_CURRENT
:
2828 case C_HUB_LOCAL_POWER
:
2836 case C_HUB_OVER_CURRENT
:
2837 case C_HUB_LOCAL_POWER
:
2843 case ClearPortFeature
:{
2844 retval
= u132_roothub_clearportfeature(u132
,
2850 case GetHubDescriptor
:{
2851 retval
= u132_roothub_descriptor(u132
,
2852 (struct usb_hub_descriptor
*)buf
);
2858 retval
= u132_roothub_status(u132
,
2864 case GetPortStatus
:{
2865 retval
= u132_roothub_portstatus(u132
,
2866 (__le32
*) buf
, wIndex
);
2871 case SetPortFeature
:{
2872 retval
= u132_roothub_setportfeature(u132
,
2888 mutex_unlock(&u132
->sw_lock
);
2893 static int u132_start_port_reset(struct usb_hcd
*hcd
, unsigned port_num
)
2895 struct u132
*u132
= hcd_to_u132(hcd
);
2896 if (u132
->going
> 1) {
2897 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2900 } else if (u132
->going
> 0) {
2901 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2909 static int u132_bus_suspend(struct usb_hcd
*hcd
)
2911 struct u132
*u132
= hcd_to_u132(hcd
);
2912 if (u132
->going
> 1) {
2913 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2916 } else if (u132
->going
> 0) {
2917 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2923 static int u132_bus_resume(struct usb_hcd
*hcd
)
2925 struct u132
*u132
= hcd_to_u132(hcd
);
2926 if (u132
->going
> 1) {
2927 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2930 } else if (u132
->going
> 0) {
2931 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2938 #define u132_bus_suspend NULL
2939 #define u132_bus_resume NULL
2941 static const struct hc_driver u132_hc_driver
= {
2942 .description
= hcd_name
,
2943 .hcd_priv_size
= sizeof(struct u132
),
2945 .flags
= HCD_USB11
| HCD_MEMORY
,
2946 .reset
= u132_hcd_reset
,
2947 .start
= u132_hcd_start
,
2948 .stop
= u132_hcd_stop
,
2949 .urb_enqueue
= u132_urb_enqueue
,
2950 .urb_dequeue
= u132_urb_dequeue
,
2951 .endpoint_disable
= u132_endpoint_disable
,
2952 .get_frame_number
= u132_get_frame
,
2953 .hub_status_data
= u132_hub_status_data
,
2954 .hub_control
= u132_hub_control
,
2955 .bus_suspend
= u132_bus_suspend
,
2956 .bus_resume
= u132_bus_resume
,
2957 .start_port_reset
= u132_start_port_reset
,
2961 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
2962 * is held for writing, thus this module must not call usb_remove_hcd()
2963 * synchronously - but instead should immediately stop activity to the
2964 * device and asynchronously call usb_remove_hcd()
2966 static int u132_remove(struct platform_device
*pdev
)
2968 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
2970 struct u132
*u132
= hcd_to_u132(hcd
);
2971 if (u132
->going
++ > 1) {
2972 dev_err(&u132
->platform_dev
->dev
, "already being remove"
2976 int rings
= MAX_U132_RINGS
;
2977 int endps
= MAX_U132_ENDPS
;
2978 dev_err(&u132
->platform_dev
->dev
, "removing device u132"
2979 ".%d\n", u132
->sequence_num
);
2981 mutex_lock(&u132
->sw_lock
);
2982 u132_monitor_cancel_work(u132
);
2983 while (rings
-- > 0) {
2984 struct u132_ring
*ring
= &u132
->ring
[rings
];
2985 u132_ring_cancel_work(u132
, ring
);
2987 while (endps
-- > 0) {
2988 struct u132_endp
*endp
= u132
->endp
[endps
];
2990 u132_endp_cancel_work(u132
, endp
);
2993 printk(KERN_INFO
"removing device u132.%d\n",
2994 u132
->sequence_num
);
2995 mutex_unlock(&u132
->sw_lock
);
2996 usb_remove_hcd(hcd
);
2997 u132_u132_put_kref(u132
);
3004 static void u132_initialise(struct u132
*u132
, struct platform_device
*pdev
)
3006 int rings
= MAX_U132_RINGS
;
3007 int ports
= MAX_U132_PORTS
;
3008 int addrs
= MAX_U132_ADDRS
;
3009 int udevs
= MAX_U132_UDEVS
;
3010 int endps
= MAX_U132_ENDPS
;
3011 u132
->board
= dev_get_platdata(&pdev
->dev
);
3012 u132
->platform_dev
= pdev
;
3015 mutex_init(&u132
->sw_lock
);
3016 mutex_init(&u132
->scheduler_lock
);
3017 while (rings
-- > 0) {
3018 struct u132_ring
*ring
= &u132
->ring
[rings
];
3020 ring
->number
= rings
+ 1;
3022 ring
->curr_endp
= NULL
;
3023 INIT_DELAYED_WORK(&ring
->scheduler
,
3024 u132_hcd_ring_work_scheduler
);
3026 mutex_lock(&u132
->sw_lock
);
3027 INIT_DELAYED_WORK(&u132
->monitor
, u132_hcd_monitor_work
);
3028 while (ports
-- > 0) {
3029 struct u132_port
*port
= &u132
->port
[ports
];
3036 while (addrs
-- > 0) {
3037 struct u132_addr
*addr
= &u132
->addr
[addrs
];
3040 while (udevs
-- > 0) {
3041 struct u132_udev
*udev
= &u132
->udev
[udevs
];
3042 int i
= ARRAY_SIZE(udev
->endp_number_in
);
3043 int o
= ARRAY_SIZE(udev
->endp_number_out
);
3044 udev
->usb_device
= NULL
;
3045 udev
->udev_number
= 0;
3047 udev
->portnumber
= 0;
3049 udev
->endp_number_in
[i
] = 0;
3052 udev
->endp_number_out
[o
] = 0;
3056 u132
->endp
[endps
] = NULL
;
3058 mutex_unlock(&u132
->sw_lock
);
3061 static int u132_probe(struct platform_device
*pdev
)
3063 struct usb_hcd
*hcd
;
3069 if (u132_exiting
> 0)
3072 retval
= ftdi_write_pcimem(pdev
, intrdisable
, OHCI_INTR_MIE
);
3075 retval
= ftdi_read_pcimem(pdev
, control
, &control
);
3078 retval
= ftdi_read_pcimem(pdev
, roothub
.a
, &rh_a
);
3081 if (pdev
->dev
.dma_mask
)
3084 hcd
= usb_create_hcd(&u132_hc_driver
, &pdev
->dev
, dev_name(&pdev
->dev
));
3086 printk(KERN_ERR
"failed to create the usb hcd struct for U132\n"
3088 ftdi_elan_gone_away(pdev
);
3091 struct u132
*u132
= hcd_to_u132(hcd
);
3093 hcd
->rsrc_start
= 0;
3094 mutex_lock(&u132_module_lock
);
3095 list_add_tail(&u132
->u132_list
, &u132_static_list
);
3096 u132
->sequence_num
= ++u132_instances
;
3097 mutex_unlock(&u132_module_lock
);
3098 u132_u132_init_kref(u132
);
3099 u132_initialise(u132
, pdev
);
3100 hcd
->product_desc
= "ELAN U132 Host Controller";
3101 retval
= usb_add_hcd(hcd
, 0, 0);
3103 dev_err(&u132
->platform_dev
->dev
, "init error %d\n",
3105 u132_u132_put_kref(u132
);
3108 device_wakeup_enable(hcd
->self
.controller
);
3109 u132_monitor_queue_work(u132
, 100);
3118 * for this device there's no useful distinction between the controller
3121 static int u132_suspend(struct platform_device
*pdev
, pm_message_t state
)
3123 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
3124 struct u132
*u132
= hcd_to_u132(hcd
);
3125 if (u132
->going
> 1) {
3126 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
3129 } else if (u132
->going
> 0) {
3130 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
3133 int retval
= 0, ports
;
3135 switch (state
.event
) {
3136 case PM_EVENT_FREEZE
:
3137 retval
= u132_bus_suspend(hcd
);
3139 case PM_EVENT_SUSPEND
:
3140 case PM_EVENT_HIBERNATE
:
3141 ports
= MAX_U132_PORTS
;
3142 while (ports
-- > 0) {
3143 port_power(u132
, ports
, 0);
3151 static int u132_resume(struct platform_device
*pdev
)
3153 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
3154 struct u132
*u132
= hcd_to_u132(hcd
);
3155 if (u132
->going
> 1) {
3156 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
3159 } else if (u132
->going
> 0) {
3160 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
3164 if (!u132
->port
[0].power
) {
3165 int ports
= MAX_U132_PORTS
;
3166 while (ports
-- > 0) {
3167 port_power(u132
, ports
, 1);
3171 retval
= u132_bus_resume(hcd
);
3178 #define u132_suspend NULL
3179 #define u132_resume NULL
3182 * this driver is loaded explicitly by ftdi_u132
3184 * the platform_driver struct is static because it is per type of module
3186 static struct platform_driver u132_platform_driver
= {
3187 .probe
= u132_probe
,
3188 .remove
= u132_remove
,
3189 .suspend
= u132_suspend
,
3190 .resume
= u132_resume
,
3195 static int __init
u132_hcd_init(void)
3198 INIT_LIST_HEAD(&u132_static_list
);
3201 mutex_init(&u132_module_lock
);
3204 printk(KERN_INFO
"driver %s\n", hcd_name
);
3205 workqueue
= create_singlethread_workqueue("u132");
3206 retval
= platform_driver_register(&u132_platform_driver
);
3211 module_init(u132_hcd_init
);
3212 static void __exit
u132_hcd_exit(void)
3216 mutex_lock(&u132_module_lock
);
3218 mutex_unlock(&u132_module_lock
);
3219 list_for_each_entry_safe(u132
, temp
, &u132_static_list
, u132_list
) {
3220 platform_device_unregister(u132
->platform_dev
);
3222 platform_driver_unregister(&u132_platform_driver
);
3223 printk(KERN_INFO
"u132-hcd driver deregistered\n");
3224 wait_event(u132_hcd_wait
, u132_instances
== 0);
3225 flush_workqueue(workqueue
);
3226 destroy_workqueue(workqueue
);
3230 module_exit(u132_hcd_exit
);
3231 MODULE_LICENSE("GPL");
3232 MODULE_ALIAS("platform:u132_hcd");