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/overcurrent"
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
;
85 * end of the global variables protected by u132_module_lock
87 static struct workqueue_struct
*workqueue
;
88 #define MAX_U132_PORTS 7
89 #define MAX_U132_ADDRS 128
90 #define MAX_U132_UDEVS 4
91 #define MAX_U132_ENDPS 100
92 #define MAX_U132_RINGS 4
93 static const char *cc_to_text
[16] = {
123 struct usb_device
*usb_device
;
128 u8 endp_number_in
[16];
129 u8 endp_number_out
[16];
131 #define ENDP_QUEUE_SHIFT 3
132 #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
133 #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
135 struct list_head urb_more
;
148 struct list_head endp_ring
;
149 struct u132_ring
*ring
;
150 unsigned toggle_bits
:2;
156 unsigned dequeueing
:1;
157 unsigned edset_flush
:1;
158 unsigned spare_bits
:14;
159 unsigned long jiffies
;
160 struct usb_host_endpoint
*hep
;
161 struct u132_spin queue_lock
;
165 struct urb
*urb_list
[ENDP_QUEUE_SIZE
];
166 struct list_head urb_more
;
167 struct delayed_work scheduler
;
174 struct u132_endp
*curr_endp
;
175 struct delayed_work scheduler
;
179 struct mutex sw_lock
;
180 struct mutex scheduler_lock
;
181 struct u132_platform_data
*board
;
182 struct platform_device
*platform_dev
;
183 struct u132_ring ring
[MAX_U132_RINGS
];
191 u32 hc_roothub_status
;
193 u32 hc_roothub_portstatus
[MAX_ROOT_PORTS
];
195 unsigned long next_statechange
;
196 struct delayed_work monitor
;
198 struct u132_addr addr
[MAX_U132_ADDRS
];
199 struct u132_udev udev
[MAX_U132_UDEVS
];
200 struct u132_port port
[MAX_U132_PORTS
];
201 struct u132_endp
*endp
[MAX_U132_ENDPS
];
205 * these cannot be inlines because we need the structure offset!!
206 * Does anyone have a better way?????
208 #define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
209 offsetof(struct ohci_regs, member), 0, data);
210 #define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
211 offsetof(struct ohci_regs, member), 0, data)
212 #define u132_read_pcimem(u132, member, data) \
213 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
214 ohci_regs, member), 0, data)
215 #define u132_write_pcimem(u132, member, data) \
216 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
217 ohci_regs, member), 0, data)
218 static inline struct u132
*udev_to_u132(struct u132_udev
*udev
)
220 u8 udev_number
= udev
->udev_number
;
221 return container_of(udev
, struct u132
, udev
[udev_number
]);
224 static inline struct u132
*hcd_to_u132(struct usb_hcd
*hcd
)
226 return (struct u132
*)(hcd
->hcd_priv
);
229 static inline struct usb_hcd
*u132_to_hcd(struct u132
*u132
)
231 return container_of((void *)u132
, struct usb_hcd
, hcd_priv
);
234 static inline void u132_disable(struct u132
*u132
)
236 u132_to_hcd(u132
)->state
= HC_STATE_HALT
;
240 #define kref_to_u132(d) container_of(d, struct u132, kref)
241 #define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref)
242 #define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref)
243 #include "../misc/usb_u132.h"
244 static const char hcd_name
[] = "u132_hcd";
245 #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
246 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
247 USB_PORT_STAT_C_RESET) << 16)
248 static void u132_hcd_delete(struct kref
*kref
)
250 struct u132
*u132
= kref_to_u132(kref
);
251 struct platform_device
*pdev
= u132
->platform_dev
;
252 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
254 mutex_lock(&u132_module_lock
);
256 mutex_unlock(&u132_module_lock
);
257 dev_warn(&u132
->platform_dev
->dev
, "FREEING the hcd=%p and thus the u13"
258 "2=%p going=%d pdev=%p\n", hcd
, u132
, u132
->going
, pdev
);
262 static inline void u132_u132_put_kref(struct u132
*u132
)
264 kref_put(&u132
->kref
, u132_hcd_delete
);
267 static inline void u132_u132_init_kref(struct u132
*u132
)
269 kref_init(&u132
->kref
);
272 static void u132_udev_delete(struct kref
*kref
)
274 struct u132_udev
*udev
= kref_to_u132_udev(kref
);
275 udev
->udev_number
= 0;
276 udev
->usb_device
= NULL
;
278 udev
->enumeration
= 0;
281 static inline void u132_udev_put_kref(struct u132
*u132
, struct u132_udev
*udev
)
283 kref_put(&udev
->kref
, u132_udev_delete
);
286 static inline void u132_udev_get_kref(struct u132
*u132
, struct u132_udev
*udev
)
288 kref_get(&udev
->kref
);
291 static inline void u132_udev_init_kref(struct u132
*u132
,
292 struct u132_udev
*udev
)
294 kref_init(&udev
->kref
);
297 static inline void u132_ring_put_kref(struct u132
*u132
, struct u132_ring
*ring
)
299 kref_put(&u132
->kref
, u132_hcd_delete
);
302 static void u132_ring_requeue_work(struct u132
*u132
, struct u132_ring
*ring
,
306 if (queue_delayed_work(workqueue
, &ring
->scheduler
, delta
))
308 } else if (queue_delayed_work(workqueue
, &ring
->scheduler
, 0))
310 kref_put(&u132
->kref
, u132_hcd_delete
);
313 static void u132_ring_queue_work(struct u132
*u132
, struct u132_ring
*ring
,
316 kref_get(&u132
->kref
);
317 u132_ring_requeue_work(u132
, ring
, delta
);
320 static void u132_ring_cancel_work(struct u132
*u132
, struct u132_ring
*ring
)
322 if (cancel_delayed_work(&ring
->scheduler
))
323 kref_put(&u132
->kref
, u132_hcd_delete
);
326 static void u132_endp_delete(struct kref
*kref
)
328 struct u132_endp
*endp
= kref_to_u132_endp(kref
);
329 struct u132
*u132
= endp
->u132
;
330 u8 usb_addr
= endp
->usb_addr
;
331 u8 usb_endp
= endp
->usb_endp
;
332 u8 address
= u132
->addr
[usb_addr
].address
;
333 struct u132_udev
*udev
= &u132
->udev
[address
];
334 u8 endp_number
= endp
->endp_number
;
335 struct usb_host_endpoint
*hep
= endp
->hep
;
336 struct u132_ring
*ring
= endp
->ring
;
337 struct list_head
*head
= &endp
->endp_ring
;
339 if (endp
== ring
->curr_endp
) {
340 if (list_empty(head
)) {
341 ring
->curr_endp
= NULL
;
344 struct u132_endp
*next_endp
= list_entry(head
->next
,
345 struct u132_endp
, endp_ring
);
346 ring
->curr_endp
= next_endp
;
352 udev
->endp_number_in
[usb_endp
] = 0;
353 u132_udev_put_kref(u132
, udev
);
356 udev
->endp_number_out
[usb_endp
] = 0;
357 u132_udev_put_kref(u132
, udev
);
359 u132
->endp
[endp_number
- 1] = NULL
;
362 u132_u132_put_kref(u132
);
365 static inline void u132_endp_put_kref(struct u132
*u132
, struct u132_endp
*endp
)
367 kref_put(&endp
->kref
, u132_endp_delete
);
370 static inline void u132_endp_get_kref(struct u132
*u132
, struct u132_endp
*endp
)
372 kref_get(&endp
->kref
);
375 static inline void u132_endp_init_kref(struct u132
*u132
,
376 struct u132_endp
*endp
)
378 kref_init(&endp
->kref
);
379 kref_get(&u132
->kref
);
382 static void u132_endp_queue_work(struct u132
*u132
, struct u132_endp
*endp
,
385 if (queue_delayed_work(workqueue
, &endp
->scheduler
, delta
))
386 kref_get(&endp
->kref
);
389 static void u132_endp_cancel_work(struct u132
*u132
, struct u132_endp
*endp
)
391 if (cancel_delayed_work(&endp
->scheduler
))
392 kref_put(&endp
->kref
, u132_endp_delete
);
395 static inline void u132_monitor_put_kref(struct u132
*u132
)
397 kref_put(&u132
->kref
, u132_hcd_delete
);
400 static void u132_monitor_queue_work(struct u132
*u132
, unsigned int delta
)
402 if (queue_delayed_work(workqueue
, &u132
->monitor
, delta
))
403 kref_get(&u132
->kref
);
406 static void u132_monitor_requeue_work(struct u132
*u132
, unsigned int delta
)
408 if (!queue_delayed_work(workqueue
, &u132
->monitor
, delta
))
409 kref_put(&u132
->kref
, u132_hcd_delete
);
412 static void u132_monitor_cancel_work(struct u132
*u132
)
414 if (cancel_delayed_work(&u132
->monitor
))
415 kref_put(&u132
->kref
, u132_hcd_delete
);
418 static int read_roothub_info(struct u132
*u132
)
422 retval
= u132_read_pcimem(u132
, revision
, &revision
);
424 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device co"
427 } else if ((revision
& 0xFF) == 0x10) {
428 } else if ((revision
& 0xFF) == 0x11) {
430 dev_err(&u132
->platform_dev
->dev
, "device revision is not valid"
431 " %08X\n", revision
);
434 retval
= u132_read_pcimem(u132
, control
, &u132
->hc_control
);
436 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device co"
440 retval
= u132_read_pcimem(u132
, roothub
.status
,
441 &u132
->hc_roothub_status
);
443 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device re"
444 "g roothub.status\n", retval
);
447 retval
= u132_read_pcimem(u132
, roothub
.a
, &u132
->hc_roothub_a
);
449 dev_err(&u132
->platform_dev
->dev
, "error %d accessing device re"
450 "g roothub.a\n", retval
);
454 int I
= u132
->num_ports
;
457 retval
= u132_read_pcimem(u132
, roothub
.portstatus
[i
],
458 &u132
->hc_roothub_portstatus
[i
]);
460 dev_err(&u132
->platform_dev
->dev
, "error %d acc"
461 "essing device roothub.portstatus[%d]\n"
471 static void u132_hcd_monitor_work(struct work_struct
*work
)
473 struct u132
*u132
= container_of(work
, struct u132
, monitor
.work
);
474 if (u132
->going
> 1) {
475 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
477 u132_monitor_put_kref(u132
);
479 } else if (u132
->going
> 0) {
480 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
481 u132_monitor_put_kref(u132
);
485 mutex_lock(&u132
->sw_lock
);
486 retval
= read_roothub_info(u132
);
488 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
491 mutex_unlock(&u132
->sw_lock
);
493 ftdi_elan_gone_away(u132
->platform_dev
);
494 u132_monitor_put_kref(u132
);
497 u132_monitor_requeue_work(u132
, 500);
498 mutex_unlock(&u132
->sw_lock
);
504 static void u132_hcd_giveback_urb(struct u132
*u132
, struct u132_endp
*endp
,
505 struct urb
*urb
, int status
)
507 struct u132_ring
*ring
;
509 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
510 urb
->error_count
= 0;
511 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
512 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
513 endp
->queue_next
+= 1;
514 if (ENDP_QUEUE_SIZE
> --endp
->queue_size
) {
516 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
518 struct list_head
*next
= endp
->urb_more
.next
;
519 struct u132_urbq
*urbq
= list_entry(next
, struct u132_urbq
,
522 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] =
525 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
528 mutex_lock(&u132
->scheduler_lock
);
531 u132_ring_cancel_work(u132
, ring
);
532 u132_ring_queue_work(u132
, ring
, 0);
533 mutex_unlock(&u132
->scheduler_lock
);
534 u132_endp_put_kref(u132
, endp
);
535 usb_hcd_giveback_urb(hcd
, urb
, status
);
538 static void u132_hcd_forget_urb(struct u132
*u132
, struct u132_endp
*endp
,
539 struct urb
*urb
, int status
)
541 u132_endp_put_kref(u132
, endp
);
544 static void u132_hcd_abandon_urb(struct u132
*u132
, struct u132_endp
*endp
,
545 struct urb
*urb
, int status
)
548 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
549 urb
->error_count
= 0;
550 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
551 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
552 endp
->queue_next
+= 1;
553 if (ENDP_QUEUE_SIZE
> --endp
->queue_size
) {
555 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
557 struct list_head
*next
= endp
->urb_more
.next
;
558 struct u132_urbq
*urbq
= list_entry(next
, struct u132_urbq
,
561 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] =
564 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
567 usb_hcd_giveback_urb(hcd
, urb
, status
);
570 static inline int edset_input(struct u132
*u132
, struct u132_ring
*ring
,
571 struct u132_endp
*endp
, struct urb
*urb
, u8 address
, u8 toggle_bits
,
572 void (*callback
) (void *endp
, struct urb
*urb
, u8
*buf
, int len
,
573 int toggle_bits
, int error_count
, int condition_code
, int repeat_number
,
574 int halted
, int skipped
, int actual
, int non_null
))
576 return usb_ftdi_elan_edset_input(u132
->platform_dev
, ring
->number
, endp
,
577 urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
580 static inline int edset_setup(struct u132
*u132
, struct u132_ring
*ring
,
581 struct u132_endp
*endp
, struct urb
*urb
, u8 address
, u8 toggle_bits
,
582 void (*callback
) (void *endp
, struct urb
*urb
, u8
*buf
, int len
,
583 int toggle_bits
, int error_count
, int condition_code
, int repeat_number
,
584 int halted
, int skipped
, int actual
, int non_null
))
586 return usb_ftdi_elan_edset_setup(u132
->platform_dev
, ring
->number
, endp
,
587 urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
590 static inline int edset_single(struct u132
*u132
, struct u132_ring
*ring
,
591 struct u132_endp
*endp
, struct urb
*urb
, u8 address
, u8 toggle_bits
,
592 void (*callback
) (void *endp
, struct urb
*urb
, u8
*buf
, int len
,
593 int toggle_bits
, int error_count
, int condition_code
, int repeat_number
,
594 int halted
, int skipped
, int actual
, int non_null
))
596 return usb_ftdi_elan_edset_single(u132
->platform_dev
, ring
->number
,
597 endp
, urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
600 static inline int edset_output(struct u132
*u132
, struct u132_ring
*ring
,
601 struct u132_endp
*endp
, struct urb
*urb
, u8 address
, u8 toggle_bits
,
602 void (*callback
) (void *endp
, struct urb
*urb
, u8
*buf
, int len
,
603 int toggle_bits
, int error_count
, int condition_code
, int repeat_number
,
604 int halted
, int skipped
, int actual
, int non_null
))
606 return usb_ftdi_elan_edset_output(u132
->platform_dev
, ring
->number
,
607 endp
, urb
, address
, endp
->usb_endp
, toggle_bits
, callback
);
612 * must not LOCK sw_lock
615 static void u132_hcd_interrupt_recv(void *data
, struct urb
*urb
, u8
*buf
,
616 int len
, int toggle_bits
, int error_count
, int condition_code
,
617 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
619 struct u132_endp
*endp
= data
;
620 struct u132
*u132
= endp
->u132
;
621 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
622 struct u132_udev
*udev
= &u132
->udev
[address
];
623 mutex_lock(&u132
->scheduler_lock
);
624 if (u132
->going
> 1) {
625 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
627 mutex_unlock(&u132
->scheduler_lock
);
628 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
630 } else if (endp
->dequeueing
) {
631 endp
->dequeueing
= 0;
632 mutex_unlock(&u132
->scheduler_lock
);
633 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
635 } else if (u132
->going
> 0) {
636 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
638 mutex_unlock(&u132
->scheduler_lock
);
639 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
641 } else if (!urb
->unlinked
) {
642 struct u132_ring
*ring
= endp
->ring
;
643 u8
*u
= urb
->transfer_buffer
+ urb
->actual_length
;
650 urb
->actual_length
+= len
;
651 if ((condition_code
== TD_CC_NOERROR
) &&
652 (urb
->transfer_buffer_length
> urb
->actual_length
)) {
653 endp
->toggle_bits
= toggle_bits
;
654 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
656 if (urb
->actual_length
> 0) {
658 mutex_unlock(&u132
->scheduler_lock
);
659 retval
= edset_single(u132
, ring
, endp
, urb
,
660 address
, endp
->toggle_bits
,
661 u132_hcd_interrupt_recv
);
663 u132_hcd_giveback_urb(u132
, endp
, urb
,
668 endp
->jiffies
= jiffies
+
669 msecs_to_jiffies(urb
->interval
);
670 u132_ring_cancel_work(u132
, ring
);
671 u132_ring_queue_work(u132
, ring
, 0);
672 mutex_unlock(&u132
->scheduler_lock
);
673 u132_endp_put_kref(u132
, endp
);
676 } else if ((condition_code
== TD_DATAUNDERRUN
) &&
677 ((urb
->transfer_flags
& URB_SHORT_NOT_OK
) == 0)) {
678 endp
->toggle_bits
= toggle_bits
;
679 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
681 mutex_unlock(&u132
->scheduler_lock
);
682 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
685 if (condition_code
== TD_CC_NOERROR
) {
686 endp
->toggle_bits
= toggle_bits
;
687 usb_settoggle(udev
->usb_device
, endp
->usb_endp
,
689 } else if (condition_code
== TD_CC_STALL
) {
690 endp
->toggle_bits
= 0x2;
691 usb_settoggle(udev
->usb_device
, endp
->usb_endp
,
694 endp
->toggle_bits
= 0x2;
695 usb_settoggle(udev
->usb_device
, endp
->usb_endp
,
697 dev_err(&u132
->platform_dev
->dev
, "urb=%p givin"
698 "g back INTERRUPT %s\n", urb
,
699 cc_to_text
[condition_code
]);
701 mutex_unlock(&u132
->scheduler_lock
);
702 u132_hcd_giveback_urb(u132
, endp
, urb
,
703 cc_to_error
[condition_code
]);
707 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
708 "unlinked=%d\n", urb
, urb
->unlinked
);
709 mutex_unlock(&u132
->scheduler_lock
);
710 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
715 static void u132_hcd_bulk_output_sent(void *data
, struct urb
*urb
, u8
*buf
,
716 int len
, int toggle_bits
, int error_count
, int condition_code
,
717 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
719 struct u132_endp
*endp
= data
;
720 struct u132
*u132
= endp
->u132
;
721 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
722 mutex_lock(&u132
->scheduler_lock
);
723 if (u132
->going
> 1) {
724 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
726 mutex_unlock(&u132
->scheduler_lock
);
727 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
729 } else if (endp
->dequeueing
) {
730 endp
->dequeueing
= 0;
731 mutex_unlock(&u132
->scheduler_lock
);
732 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
734 } else if (u132
->going
> 0) {
735 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
737 mutex_unlock(&u132
->scheduler_lock
);
738 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
740 } else if (!urb
->unlinked
) {
741 struct u132_ring
*ring
= endp
->ring
;
742 urb
->actual_length
+= len
;
743 endp
->toggle_bits
= toggle_bits
;
744 if (urb
->transfer_buffer_length
> urb
->actual_length
) {
746 mutex_unlock(&u132
->scheduler_lock
);
747 retval
= edset_output(u132
, ring
, endp
, urb
, address
,
748 endp
->toggle_bits
, u132_hcd_bulk_output_sent
);
750 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
753 mutex_unlock(&u132
->scheduler_lock
);
754 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
758 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
759 "unlinked=%d\n", urb
, urb
->unlinked
);
760 mutex_unlock(&u132
->scheduler_lock
);
761 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
766 static void u132_hcd_bulk_input_recv(void *data
, struct urb
*urb
, u8
*buf
,
767 int len
, int toggle_bits
, int error_count
, int condition_code
,
768 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
770 struct u132_endp
*endp
= data
;
771 struct u132
*u132
= endp
->u132
;
772 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
773 struct u132_udev
*udev
= &u132
->udev
[address
];
774 mutex_lock(&u132
->scheduler_lock
);
775 if (u132
->going
> 1) {
776 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
778 mutex_unlock(&u132
->scheduler_lock
);
779 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
781 } else if (endp
->dequeueing
) {
782 endp
->dequeueing
= 0;
783 mutex_unlock(&u132
->scheduler_lock
);
784 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
786 } else if (u132
->going
> 0) {
787 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
789 mutex_unlock(&u132
->scheduler_lock
);
790 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
792 } else if (!urb
->unlinked
) {
793 struct u132_ring
*ring
= endp
->ring
;
794 u8
*u
= urb
->transfer_buffer
+ urb
->actual_length
;
801 urb
->actual_length
+= len
;
802 if ((condition_code
== TD_CC_NOERROR
) &&
803 (urb
->transfer_buffer_length
> urb
->actual_length
)) {
805 endp
->toggle_bits
= toggle_bits
;
806 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
808 mutex_unlock(&u132
->scheduler_lock
);
809 retval
= usb_ftdi_elan_edset_input(u132
->platform_dev
,
810 ring
->number
, endp
, urb
, address
,
811 endp
->usb_endp
, endp
->toggle_bits
,
812 u132_hcd_bulk_input_recv
);
814 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
816 } else if (condition_code
== TD_CC_NOERROR
) {
817 endp
->toggle_bits
= toggle_bits
;
818 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
820 mutex_unlock(&u132
->scheduler_lock
);
821 u132_hcd_giveback_urb(u132
, endp
, urb
,
822 cc_to_error
[condition_code
]);
824 } else if ((condition_code
== TD_DATAUNDERRUN
) &&
825 ((urb
->transfer_flags
& URB_SHORT_NOT_OK
) == 0)) {
826 endp
->toggle_bits
= toggle_bits
;
827 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
829 mutex_unlock(&u132
->scheduler_lock
);
830 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
832 } else if (condition_code
== TD_DATAUNDERRUN
) {
833 endp
->toggle_bits
= toggle_bits
;
834 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0,
836 dev_warn(&u132
->platform_dev
->dev
, "urb=%p(SHORT NOT OK"
837 ") giving back BULK IN %s\n", urb
,
838 cc_to_text
[condition_code
]);
839 mutex_unlock(&u132
->scheduler_lock
);
840 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
842 } else if (condition_code
== TD_CC_STALL
) {
843 endp
->toggle_bits
= 0x2;
844 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0, 0);
845 mutex_unlock(&u132
->scheduler_lock
);
846 u132_hcd_giveback_urb(u132
, endp
, urb
,
847 cc_to_error
[condition_code
]);
850 endp
->toggle_bits
= 0x2;
851 usb_settoggle(udev
->usb_device
, endp
->usb_endp
, 0, 0);
852 dev_err(&u132
->platform_dev
->dev
, "urb=%p giving back B"
853 "ULK IN code=%d %s\n", urb
, condition_code
,
854 cc_to_text
[condition_code
]);
855 mutex_unlock(&u132
->scheduler_lock
);
856 u132_hcd_giveback_urb(u132
, endp
, urb
,
857 cc_to_error
[condition_code
]);
861 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
862 "unlinked=%d\n", urb
, urb
->unlinked
);
863 mutex_unlock(&u132
->scheduler_lock
);
864 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
869 static void u132_hcd_configure_empty_sent(void *data
, struct urb
*urb
, u8
*buf
,
870 int len
, int toggle_bits
, int error_count
, int condition_code
,
871 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
873 struct u132_endp
*endp
= data
;
874 struct u132
*u132
= endp
->u132
;
875 mutex_lock(&u132
->scheduler_lock
);
876 if (u132
->going
> 1) {
877 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
879 mutex_unlock(&u132
->scheduler_lock
);
880 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
882 } else if (endp
->dequeueing
) {
883 endp
->dequeueing
= 0;
884 mutex_unlock(&u132
->scheduler_lock
);
885 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
887 } else if (u132
->going
> 0) {
888 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
890 mutex_unlock(&u132
->scheduler_lock
);
891 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
893 } else if (!urb
->unlinked
) {
894 mutex_unlock(&u132
->scheduler_lock
);
895 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
898 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
899 "unlinked=%d\n", urb
, urb
->unlinked
);
900 mutex_unlock(&u132
->scheduler_lock
);
901 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
906 static void u132_hcd_configure_input_recv(void *data
, struct urb
*urb
, u8
*buf
,
907 int len
, int toggle_bits
, int error_count
, int condition_code
,
908 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
910 struct u132_endp
*endp
= data
;
911 struct u132
*u132
= endp
->u132
;
912 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
913 mutex_lock(&u132
->scheduler_lock
);
914 if (u132
->going
> 1) {
915 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
917 mutex_unlock(&u132
->scheduler_lock
);
918 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
920 } else if (endp
->dequeueing
) {
921 endp
->dequeueing
= 0;
922 mutex_unlock(&u132
->scheduler_lock
);
923 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
925 } else if (u132
->going
> 0) {
926 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
928 mutex_unlock(&u132
->scheduler_lock
);
929 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
931 } else if (!urb
->unlinked
) {
932 struct u132_ring
*ring
= endp
->ring
;
933 u8
*u
= urb
->transfer_buffer
;
940 urb
->actual_length
= len
;
941 if ((condition_code
== TD_CC_NOERROR
) || ((condition_code
==
942 TD_DATAUNDERRUN
) && ((urb
->transfer_flags
&
943 URB_SHORT_NOT_OK
) == 0))) {
945 mutex_unlock(&u132
->scheduler_lock
);
946 retval
= usb_ftdi_elan_edset_empty(u132
->platform_dev
,
947 ring
->number
, endp
, urb
, address
,
949 u132_hcd_configure_empty_sent
);
951 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
953 } else if (condition_code
== TD_CC_STALL
) {
954 mutex_unlock(&u132
->scheduler_lock
);
955 dev_warn(&u132
->platform_dev
->dev
, "giving back SETUP I"
956 "NPUT STALL urb %p\n", urb
);
957 u132_hcd_giveback_urb(u132
, endp
, urb
,
958 cc_to_error
[condition_code
]);
961 mutex_unlock(&u132
->scheduler_lock
);
962 dev_err(&u132
->platform_dev
->dev
, "giving back SETUP IN"
963 "PUT %s urb %p\n", cc_to_text
[condition_code
],
965 u132_hcd_giveback_urb(u132
, endp
, urb
,
966 cc_to_error
[condition_code
]);
970 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
971 "unlinked=%d\n", urb
, urb
->unlinked
);
972 mutex_unlock(&u132
->scheduler_lock
);
973 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
978 static void u132_hcd_configure_empty_recv(void *data
, struct urb
*urb
, u8
*buf
,
979 int len
, int toggle_bits
, int error_count
, int condition_code
,
980 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
982 struct u132_endp
*endp
= data
;
983 struct u132
*u132
= endp
->u132
;
984 mutex_lock(&u132
->scheduler_lock
);
985 if (u132
->going
> 1) {
986 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
988 mutex_unlock(&u132
->scheduler_lock
);
989 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
991 } else if (endp
->dequeueing
) {
992 endp
->dequeueing
= 0;
993 mutex_unlock(&u132
->scheduler_lock
);
994 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
996 } else if (u132
->going
> 0) {
997 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
999 mutex_unlock(&u132
->scheduler_lock
);
1000 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1002 } else if (!urb
->unlinked
) {
1003 mutex_unlock(&u132
->scheduler_lock
);
1004 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1007 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1008 "unlinked=%d\n", urb
, urb
->unlinked
);
1009 mutex_unlock(&u132
->scheduler_lock
);
1010 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1015 static void u132_hcd_configure_setup_sent(void *data
, struct urb
*urb
, u8
*buf
,
1016 int len
, int toggle_bits
, int error_count
, int condition_code
,
1017 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1019 struct u132_endp
*endp
= data
;
1020 struct u132
*u132
= endp
->u132
;
1021 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1022 mutex_lock(&u132
->scheduler_lock
);
1023 if (u132
->going
> 1) {
1024 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1026 mutex_unlock(&u132
->scheduler_lock
);
1027 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1029 } else if (endp
->dequeueing
) {
1030 endp
->dequeueing
= 0;
1031 mutex_unlock(&u132
->scheduler_lock
);
1032 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1034 } else if (u132
->going
> 0) {
1035 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1037 mutex_unlock(&u132
->scheduler_lock
);
1038 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1040 } else if (!urb
->unlinked
) {
1041 if (usb_pipein(urb
->pipe
)) {
1043 struct u132_ring
*ring
= endp
->ring
;
1044 mutex_unlock(&u132
->scheduler_lock
);
1045 retval
= usb_ftdi_elan_edset_input(u132
->platform_dev
,
1046 ring
->number
, endp
, urb
, address
,
1048 u132_hcd_configure_input_recv
);
1050 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1054 struct u132_ring
*ring
= endp
->ring
;
1055 mutex_unlock(&u132
->scheduler_lock
);
1056 retval
= usb_ftdi_elan_edset_input(u132
->platform_dev
,
1057 ring
->number
, endp
, urb
, address
,
1059 u132_hcd_configure_empty_recv
);
1061 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1065 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1066 "unlinked=%d\n", urb
, urb
->unlinked
);
1067 mutex_unlock(&u132
->scheduler_lock
);
1068 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1073 static void u132_hcd_enumeration_empty_recv(void *data
, struct urb
*urb
,
1074 u8
*buf
, int len
, int toggle_bits
, int error_count
, int condition_code
,
1075 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1077 struct u132_endp
*endp
= data
;
1078 struct u132
*u132
= endp
->u132
;
1079 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1080 struct u132_udev
*udev
= &u132
->udev
[address
];
1081 mutex_lock(&u132
->scheduler_lock
);
1082 if (u132
->going
> 1) {
1083 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1085 mutex_unlock(&u132
->scheduler_lock
);
1086 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1088 } else if (endp
->dequeueing
) {
1089 endp
->dequeueing
= 0;
1090 mutex_unlock(&u132
->scheduler_lock
);
1091 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1093 } else if (u132
->going
> 0) {
1094 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1096 mutex_unlock(&u132
->scheduler_lock
);
1097 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1099 } else if (!urb
->unlinked
) {
1100 u132
->addr
[0].address
= 0;
1101 endp
->usb_addr
= udev
->usb_addr
;
1102 mutex_unlock(&u132
->scheduler_lock
);
1103 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1106 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1107 "unlinked=%d\n", urb
, urb
->unlinked
);
1108 mutex_unlock(&u132
->scheduler_lock
);
1109 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1114 static void u132_hcd_enumeration_address_sent(void *data
, struct urb
*urb
,
1115 u8
*buf
, int len
, int toggle_bits
, int error_count
, int condition_code
,
1116 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1118 struct u132_endp
*endp
= data
;
1119 struct u132
*u132
= endp
->u132
;
1120 mutex_lock(&u132
->scheduler_lock
);
1121 if (u132
->going
> 1) {
1122 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1124 mutex_unlock(&u132
->scheduler_lock
);
1125 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1127 } else if (endp
->dequeueing
) {
1128 endp
->dequeueing
= 0;
1129 mutex_unlock(&u132
->scheduler_lock
);
1130 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1132 } else if (u132
->going
> 0) {
1133 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1135 mutex_unlock(&u132
->scheduler_lock
);
1136 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1138 } else if (!urb
->unlinked
) {
1140 struct u132_ring
*ring
= endp
->ring
;
1141 mutex_unlock(&u132
->scheduler_lock
);
1142 retval
= usb_ftdi_elan_edset_input(u132
->platform_dev
,
1143 ring
->number
, endp
, urb
, 0, endp
->usb_endp
, 0,
1144 u132_hcd_enumeration_empty_recv
);
1146 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1149 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1150 "unlinked=%d\n", urb
, urb
->unlinked
);
1151 mutex_unlock(&u132
->scheduler_lock
);
1152 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1157 static void u132_hcd_initial_empty_sent(void *data
, struct urb
*urb
, u8
*buf
,
1158 int len
, int toggle_bits
, int error_count
, int condition_code
,
1159 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1161 struct u132_endp
*endp
= data
;
1162 struct u132
*u132
= endp
->u132
;
1163 mutex_lock(&u132
->scheduler_lock
);
1164 if (u132
->going
> 1) {
1165 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1167 mutex_unlock(&u132
->scheduler_lock
);
1168 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1170 } else if (endp
->dequeueing
) {
1171 endp
->dequeueing
= 0;
1172 mutex_unlock(&u132
->scheduler_lock
);
1173 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1175 } else if (u132
->going
> 0) {
1176 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1178 mutex_unlock(&u132
->scheduler_lock
);
1179 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1181 } else if (!urb
->unlinked
) {
1182 mutex_unlock(&u132
->scheduler_lock
);
1183 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1186 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1187 "unlinked=%d\n", urb
, urb
->unlinked
);
1188 mutex_unlock(&u132
->scheduler_lock
);
1189 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1194 static void u132_hcd_initial_input_recv(void *data
, struct urb
*urb
, u8
*buf
,
1195 int len
, int toggle_bits
, int error_count
, int condition_code
,
1196 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1198 struct u132_endp
*endp
= data
;
1199 struct u132
*u132
= endp
->u132
;
1200 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1201 mutex_lock(&u132
->scheduler_lock
);
1202 if (u132
->going
> 1) {
1203 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1205 mutex_unlock(&u132
->scheduler_lock
);
1206 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1208 } else if (endp
->dequeueing
) {
1209 endp
->dequeueing
= 0;
1210 mutex_unlock(&u132
->scheduler_lock
);
1211 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1213 } else if (u132
->going
> 0) {
1214 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1216 mutex_unlock(&u132
->scheduler_lock
);
1217 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1219 } else if (!urb
->unlinked
) {
1221 struct u132_ring
*ring
= endp
->ring
;
1222 u8
*u
= urb
->transfer_buffer
;
1229 urb
->actual_length
= len
;
1230 mutex_unlock(&u132
->scheduler_lock
);
1231 retval
= usb_ftdi_elan_edset_empty(u132
->platform_dev
,
1232 ring
->number
, endp
, urb
, address
, endp
->usb_endp
, 0x3,
1233 u132_hcd_initial_empty_sent
);
1235 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1238 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1239 "unlinked=%d\n", urb
, urb
->unlinked
);
1240 mutex_unlock(&u132
->scheduler_lock
);
1241 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1246 static void u132_hcd_initial_setup_sent(void *data
, struct urb
*urb
, u8
*buf
,
1247 int len
, int toggle_bits
, int error_count
, int condition_code
,
1248 int repeat_number
, int halted
, int skipped
, int actual
, int non_null
)
1250 struct u132_endp
*endp
= data
;
1251 struct u132
*u132
= endp
->u132
;
1252 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1253 mutex_lock(&u132
->scheduler_lock
);
1254 if (u132
->going
> 1) {
1255 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1257 mutex_unlock(&u132
->scheduler_lock
);
1258 u132_hcd_forget_urb(u132
, endp
, urb
, -ENODEV
);
1260 } else if (endp
->dequeueing
) {
1261 endp
->dequeueing
= 0;
1262 mutex_unlock(&u132
->scheduler_lock
);
1263 u132_hcd_giveback_urb(u132
, endp
, urb
, -EINTR
);
1265 } else if (u132
->going
> 0) {
1266 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
1268 mutex_unlock(&u132
->scheduler_lock
);
1269 u132_hcd_giveback_urb(u132
, endp
, urb
, -ENODEV
);
1271 } else if (!urb
->unlinked
) {
1273 struct u132_ring
*ring
= endp
->ring
;
1274 mutex_unlock(&u132
->scheduler_lock
);
1275 retval
= usb_ftdi_elan_edset_input(u132
->platform_dev
,
1276 ring
->number
, endp
, urb
, address
, endp
->usb_endp
, 0,
1277 u132_hcd_initial_input_recv
);
1279 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1282 dev_err(&u132
->platform_dev
->dev
, "CALLBACK called urb=%p "
1283 "unlinked=%d\n", urb
, urb
->unlinked
);
1284 mutex_unlock(&u132
->scheduler_lock
);
1285 u132_hcd_giveback_urb(u132
, endp
, urb
, 0);
1291 * this work function is only executed from the work queue
1294 static void u132_hcd_ring_work_scheduler(struct work_struct
*work
)
1296 struct u132_ring
*ring
=
1297 container_of(work
, struct u132_ring
, scheduler
.work
);
1298 struct u132
*u132
= ring
->u132
;
1299 mutex_lock(&u132
->scheduler_lock
);
1301 mutex_unlock(&u132
->scheduler_lock
);
1302 u132_ring_put_kref(u132
, ring
);
1304 } else if (ring
->curr_endp
) {
1305 struct u132_endp
*endp
, *last_endp
= ring
->curr_endp
;
1306 unsigned long wakeup
= 0;
1307 list_for_each_entry(endp
, &last_endp
->endp_ring
, endp_ring
) {
1308 if (endp
->queue_next
== endp
->queue_last
) {
1309 } else if ((endp
->delayed
== 0)
1310 || time_after_eq(jiffies
, endp
->jiffies
)) {
1311 ring
->curr_endp
= endp
;
1312 u132_endp_cancel_work(u132
, last_endp
);
1313 u132_endp_queue_work(u132
, last_endp
, 0);
1314 mutex_unlock(&u132
->scheduler_lock
);
1315 u132_ring_put_kref(u132
, ring
);
1318 unsigned long delta
= endp
->jiffies
- jiffies
;
1323 if (last_endp
->queue_next
== last_endp
->queue_last
) {
1324 } else if ((last_endp
->delayed
== 0) || time_after_eq(jiffies
,
1325 last_endp
->jiffies
)) {
1326 u132_endp_cancel_work(u132
, last_endp
);
1327 u132_endp_queue_work(u132
, last_endp
, 0);
1328 mutex_unlock(&u132
->scheduler_lock
);
1329 u132_ring_put_kref(u132
, ring
);
1332 unsigned long delta
= last_endp
->jiffies
- jiffies
;
1337 u132_ring_requeue_work(u132
, ring
, wakeup
);
1338 mutex_unlock(&u132
->scheduler_lock
);
1341 mutex_unlock(&u132
->scheduler_lock
);
1342 u132_ring_put_kref(u132
, ring
);
1346 mutex_unlock(&u132
->scheduler_lock
);
1347 u132_ring_put_kref(u132
, ring
);
1352 static void u132_hcd_endp_work_scheduler(struct work_struct
*work
)
1354 struct u132_ring
*ring
;
1355 struct u132_endp
*endp
=
1356 container_of(work
, struct u132_endp
, scheduler
.work
);
1357 struct u132
*u132
= endp
->u132
;
1358 mutex_lock(&u132
->scheduler_lock
);
1360 if (endp
->edset_flush
) {
1361 endp
->edset_flush
= 0;
1362 if (endp
->dequeueing
)
1363 usb_ftdi_elan_edset_flush(u132
->platform_dev
,
1364 ring
->number
, endp
);
1365 mutex_unlock(&u132
->scheduler_lock
);
1366 u132_endp_put_kref(u132
, endp
);
1368 } else if (endp
->active
) {
1369 mutex_unlock(&u132
->scheduler_lock
);
1370 u132_endp_put_kref(u132
, endp
);
1372 } else if (ring
->in_use
) {
1373 mutex_unlock(&u132
->scheduler_lock
);
1374 u132_endp_put_kref(u132
, endp
);
1376 } else if (endp
->queue_next
== endp
->queue_last
) {
1377 mutex_unlock(&u132
->scheduler_lock
);
1378 u132_endp_put_kref(u132
, endp
);
1380 } else if (endp
->pipetype
== PIPE_INTERRUPT
) {
1381 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1383 mutex_unlock(&u132
->scheduler_lock
);
1384 u132_endp_put_kref(u132
, endp
);
1388 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1391 ring
->curr_endp
= endp
;
1393 mutex_unlock(&u132
->scheduler_lock
);
1394 retval
= edset_single(u132
, ring
, endp
, urb
, address
,
1395 endp
->toggle_bits
, u132_hcd_interrupt_recv
);
1397 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1400 } else if (endp
->pipetype
== PIPE_CONTROL
) {
1401 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1403 mutex_unlock(&u132
->scheduler_lock
);
1404 u132_endp_put_kref(u132
, endp
);
1406 } else if (address
== 0) {
1408 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1411 ring
->curr_endp
= endp
;
1413 mutex_unlock(&u132
->scheduler_lock
);
1414 retval
= edset_setup(u132
, ring
, endp
, urb
, address
,
1415 0x2, u132_hcd_initial_setup_sent
);
1417 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1419 } else if (endp
->usb_addr
== 0) {
1421 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1424 ring
->curr_endp
= endp
;
1426 mutex_unlock(&u132
->scheduler_lock
);
1427 retval
= edset_setup(u132
, ring
, endp
, urb
, 0, 0x2,
1428 u132_hcd_enumeration_address_sent
);
1430 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1434 struct urb
*urb
= endp
->urb_list
[ENDP_QUEUE_MASK
&
1436 address
= u132
->addr
[endp
->usb_addr
].address
;
1438 ring
->curr_endp
= endp
;
1440 mutex_unlock(&u132
->scheduler_lock
);
1441 retval
= edset_setup(u132
, ring
, endp
, urb
, address
,
1442 0x2, u132_hcd_configure_setup_sent
);
1444 u132_hcd_giveback_urb(u132
, endp
, urb
, retval
);
1449 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1451 mutex_unlock(&u132
->scheduler_lock
);
1452 u132_endp_put_kref(u132
, endp
);
1456 struct urb
*urb
= endp
->urb_list
[
1457 ENDP_QUEUE_MASK
& endp
->queue_next
];
1459 ring
->curr_endp
= endp
;
1461 mutex_unlock(&u132
->scheduler_lock
);
1462 retval
= edset_input(u132
, ring
, endp
, urb
,
1463 address
, endp
->toggle_bits
,
1464 u132_hcd_bulk_input_recv
);
1467 u132_hcd_giveback_urb(u132
, endp
, urb
,
1471 } else { /* output pipe */
1472 u8 address
= u132
->addr
[endp
->usb_addr
].address
;
1474 mutex_unlock(&u132
->scheduler_lock
);
1475 u132_endp_put_kref(u132
, endp
);
1479 struct urb
*urb
= endp
->urb_list
[
1480 ENDP_QUEUE_MASK
& endp
->queue_next
];
1482 ring
->curr_endp
= endp
;
1484 mutex_unlock(&u132
->scheduler_lock
);
1485 retval
= edset_output(u132
, ring
, endp
, urb
,
1486 address
, endp
->toggle_bits
,
1487 u132_hcd_bulk_output_sent
);
1490 u132_hcd_giveback_urb(u132
, endp
, urb
,
1499 static void port_power(struct u132
*u132
, int pn
, int is_on
)
1501 u132
->port
[pn
].power
= is_on
;
1506 static void u132_power(struct u132
*u132
, int is_on
)
1508 struct usb_hcd
*hcd
= u132_to_hcd(u132
)
1509 ; /* hub is inactive unless the port is powered */
1516 hcd
->state
= HC_STATE_HALT
;
1520 static int u132_periodic_reinit(struct u132
*u132
)
1523 u32 fi
= u132
->hc_fminterval
& 0x03fff;
1526 retval
= u132_read_pcimem(u132
, fminterval
, &fminterval
);
1529 fit
= fminterval
& FIT
;
1530 retval
= u132_write_pcimem(u132
, fminterval
,
1531 (fit
^ FIT
) | u132
->hc_fminterval
);
1534 return u132_write_pcimem(u132
, periodicstart
,
1535 ((9 * fi
) / 10) & 0x3fff);
1538 static char *hcfs2string(int state
)
1541 case OHCI_USB_RESET
:
1543 case OHCI_USB_RESUME
:
1546 return "operational";
1547 case OHCI_USB_SUSPEND
:
1553 static int u132_init(struct u132
*u132
)
1558 u132
->next_statechange
= jiffies
;
1559 retval
= u132_write_pcimem(u132
, intrdisable
, OHCI_INTR_MIE
);
1562 retval
= u132_read_pcimem(u132
, control
, &control
);
1565 if (u132
->num_ports
== 0) {
1567 retval
= u132_read_pcimem(u132
, roothub
.a
, &rh_a
);
1570 u132
->num_ports
= rh_a
& RH_A_NDP
;
1571 retval
= read_roothub_info(u132
);
1575 if (u132
->num_ports
> MAX_U132_PORTS
)
1582 /* Start an OHCI controller, set the BUS operational
1583 * resets USB and controller
1586 static int u132_run(struct u132
*u132
)
1595 int mask
= OHCI_INTR_INIT
;
1596 int first
= u132
->hc_fminterval
== 0;
1598 int reset_timeout
= 30; /* ... allow extra time */
1602 retval
= u132_read_pcimem(u132
, fminterval
, &temp
);
1605 u132
->hc_fminterval
= temp
& 0x3fff;
1606 u132
->hc_fminterval
|= FSMP(u132
->hc_fminterval
) << 16;
1608 retval
= u132_read_pcimem(u132
, control
, &u132
->hc_control
);
1611 dev_info(&u132
->platform_dev
->dev
, "resetting from state '%s', control "
1612 "= %08X\n", hcfs2string(u132
->hc_control
& OHCI_CTRL_HCFS
),
1614 switch (u132
->hc_control
& OHCI_CTRL_HCFS
) {
1618 case OHCI_USB_SUSPEND
:
1619 case OHCI_USB_RESUME
:
1620 u132
->hc_control
&= OHCI_CTRL_RWC
;
1621 u132
->hc_control
|= OHCI_USB_RESUME
;
1625 u132
->hc_control
&= OHCI_CTRL_RWC
;
1626 u132
->hc_control
|= OHCI_USB_RESET
;
1630 retval
= u132_write_pcimem(u132
, control
, u132
->hc_control
);
1633 retval
= u132_read_pcimem(u132
, control
, &control
);
1637 retval
= u132_read_pcimem(u132
, roothub
.a
, &roothub_a
);
1640 if (!(roothub_a
& RH_A_NPS
)) {
1641 int temp
; /* power down each port */
1642 for (temp
= 0; temp
< u132
->num_ports
; temp
++) {
1643 retval
= u132_write_pcimem(u132
,
1644 roothub
.portstatus
[temp
], RH_PS_LSDA
);
1649 retval
= u132_read_pcimem(u132
, control
, &control
);
1653 retval
= u132_read_pcimem(u132
, cmdstatus
, &status
);
1656 retval
= u132_write_pcimem(u132
, cmdstatus
, OHCI_HCR
);
1660 retval
= u132_read_pcimem(u132
, cmdstatus
, &status
);
1663 if (0 != (status
& OHCI_HCR
)) {
1664 if (--reset_timeout
== 0) {
1665 dev_err(&u132
->platform_dev
->dev
, "USB HC reset"
1674 if (u132
->flags
& OHCI_QUIRK_INITRESET
) {
1675 retval
= u132_write_pcimem(u132
, control
, u132
->hc_control
);
1678 retval
= u132_read_pcimem(u132
, control
, &control
);
1682 retval
= u132_write_pcimem(u132
, ed_controlhead
, 0x00000000);
1685 retval
= u132_write_pcimem(u132
, ed_bulkhead
, 0x11000000);
1688 retval
= u132_write_pcimem(u132
, hcca
, 0x00000000);
1691 retval
= u132_periodic_reinit(u132
);
1694 retval
= u132_read_pcimem(u132
, fminterval
, &fminterval
);
1697 retval
= u132_read_pcimem(u132
, periodicstart
, &periodicstart
);
1700 if (0 == (fminterval
& 0x3fff0000) || 0 == periodicstart
) {
1701 if (!(u132
->flags
& OHCI_QUIRK_INITRESET
)) {
1702 u132
->flags
|= OHCI_QUIRK_INITRESET
;
1705 dev_err(&u132
->platform_dev
->dev
, "init err(%08x %04x)"
1706 "\n", fminterval
, periodicstart
);
1707 } /* start controller operations */
1708 u132
->hc_control
&= OHCI_CTRL_RWC
;
1709 u132
->hc_control
|= OHCI_CONTROL_INIT
| OHCI_CTRL_BLE
| OHCI_USB_OPER
;
1710 retval
= u132_write_pcimem(u132
, control
, u132
->hc_control
);
1713 retval
= u132_write_pcimem(u132
, cmdstatus
, OHCI_BLF
);
1716 retval
= u132_read_pcimem(u132
, cmdstatus
, &cmdstatus
);
1719 retval
= u132_read_pcimem(u132
, control
, &control
);
1722 u132_to_hcd(u132
)->state
= HC_STATE_RUNNING
;
1723 retval
= u132_write_pcimem(u132
, roothub
.status
, RH_HS_DRWE
);
1726 retval
= u132_write_pcimem(u132
, intrstatus
, mask
);
1729 retval
= u132_write_pcimem(u132
, intrdisable
,
1730 OHCI_INTR_MIE
| OHCI_INTR_OC
| OHCI_INTR_RHSC
| OHCI_INTR_FNO
|
1731 OHCI_INTR_UE
| OHCI_INTR_RD
| OHCI_INTR_SF
| OHCI_INTR_WDH
|
1734 return retval
; /* handle root hub init quirks ... */
1735 retval
= u132_read_pcimem(u132
, roothub
.a
, &roothub_a
);
1738 roothub_a
&= ~(RH_A_PSM
| RH_A_OCPM
);
1739 if (u132
->flags
& OHCI_QUIRK_SUPERIO
) {
1740 roothub_a
|= RH_A_NOCP
;
1741 roothub_a
&= ~(RH_A_POTPGT
| RH_A_NPS
);
1742 retval
= u132_write_pcimem(u132
, roothub
.a
, roothub_a
);
1745 } else if ((u132
->flags
& OHCI_QUIRK_AMD756
) || distrust_firmware
) {
1746 roothub_a
|= RH_A_NPS
;
1747 retval
= u132_write_pcimem(u132
, roothub
.a
, roothub_a
);
1751 retval
= u132_write_pcimem(u132
, roothub
.status
, RH_HS_LPSC
);
1754 retval
= u132_write_pcimem(u132
, roothub
.b
,
1755 (roothub_a
& RH_A_NPS
) ? 0 : RH_B_PPCM
);
1758 retval
= u132_read_pcimem(u132
, control
, &control
);
1761 mdelay((roothub_a
>> 23) & 0x1fe);
1762 u132_to_hcd(u132
)->state
= HC_STATE_RUNNING
;
1766 static void u132_hcd_stop(struct usb_hcd
*hcd
)
1768 struct u132
*u132
= hcd_to_u132(hcd
);
1769 if (u132
->going
> 1) {
1770 dev_err(&u132
->platform_dev
->dev
, "u132 device %p(hcd=%p) has b"
1771 "een removed %d\n", u132
, hcd
, u132
->going
);
1772 } else if (u132
->going
> 0) {
1773 dev_err(&u132
->platform_dev
->dev
, "device hcd=%p is being remov"
1776 mutex_lock(&u132
->sw_lock
);
1778 u132_power(u132
, 0);
1779 mutex_unlock(&u132
->sw_lock
);
1783 static int u132_hcd_start(struct usb_hcd
*hcd
)
1785 struct u132
*u132
= hcd_to_u132(hcd
);
1786 if (u132
->going
> 1) {
1787 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1790 } else if (u132
->going
> 0) {
1791 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
1793 } else if (hcd
->self
.controller
) {
1795 struct platform_device
*pdev
=
1796 to_platform_device(hcd
->self
.controller
);
1797 u16 vendor
= ((struct u132_platform_data
*)
1798 dev_get_platdata(&pdev
->dev
))->vendor
;
1799 u16 device
= ((struct u132_platform_data
*)
1800 dev_get_platdata(&pdev
->dev
))->device
;
1801 mutex_lock(&u132
->sw_lock
);
1803 if (vendor
== PCI_VENDOR_ID_AMD
&& device
== 0x740c) {
1804 u132
->flags
= OHCI_QUIRK_AMD756
;
1805 } else if (vendor
== PCI_VENDOR_ID_OPTI
&& device
== 0xc861) {
1806 dev_err(&u132
->platform_dev
->dev
, "WARNING: OPTi workar"
1807 "ounds unavailable\n");
1808 } else if (vendor
== PCI_VENDOR_ID_COMPAQ
&& device
== 0xa0f8)
1809 u132
->flags
|= OHCI_QUIRK_ZFMICRO
;
1810 retval
= u132_run(u132
);
1816 mutex_unlock(&u132
->sw_lock
);
1819 dev_err(&u132
->platform_dev
->dev
, "platform_device missing\n");
1824 static int u132_hcd_reset(struct usb_hcd
*hcd
)
1826 struct u132
*u132
= hcd_to_u132(hcd
);
1827 if (u132
->going
> 1) {
1828 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
1831 } else if (u132
->going
> 0) {
1832 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
1836 mutex_lock(&u132
->sw_lock
);
1837 retval
= u132_init(u132
);
1842 mutex_unlock(&u132
->sw_lock
);
1847 static int create_endpoint_and_queue_int(struct u132
*u132
,
1848 struct u132_udev
*udev
, struct urb
*urb
,
1849 struct usb_device
*usb_dev
, u8 usb_addr
, u8 usb_endp
, u8 address
,
1852 struct u132_ring
*ring
;
1856 struct u132_endp
*endp
= kmalloc(sizeof(struct u132_endp
), mem_flags
);
1861 spin_lock_init(&endp
->queue_lock
.slock
);
1862 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
1863 rc
= usb_hcd_link_urb_to_ep(u132_to_hcd(u132
), urb
);
1865 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
1870 endp_number
= ++u132
->num_endpoints
;
1871 urb
->ep
->hcpriv
= u132
->endp
[endp_number
- 1] = endp
;
1872 INIT_DELAYED_WORK(&endp
->scheduler
, u132_hcd_endp_work_scheduler
);
1873 INIT_LIST_HEAD(&endp
->urb_more
);
1874 ring
= endp
->ring
= &u132
->ring
[0];
1875 if (ring
->curr_endp
) {
1876 list_add_tail(&endp
->endp_ring
, &ring
->curr_endp
->endp_ring
);
1878 INIT_LIST_HEAD(&endp
->endp_ring
);
1879 ring
->curr_endp
= endp
;
1882 endp
->dequeueing
= 0;
1883 endp
->edset_flush
= 0;
1886 endp
->endp_number
= endp_number
;
1888 endp
->hep
= urb
->ep
;
1889 endp
->pipetype
= usb_pipetype(urb
->pipe
);
1890 u132_endp_init_kref(u132
, endp
);
1891 if (usb_pipein(urb
->pipe
)) {
1892 endp
->toggle_bits
= 0x2;
1893 usb_settoggle(udev
->usb_device
, usb_endp
, 0, 0);
1896 udev
->endp_number_in
[usb_endp
] = endp_number
;
1897 u132_udev_get_kref(u132
, udev
);
1899 endp
->toggle_bits
= 0x2;
1900 usb_settoggle(udev
->usb_device
, usb_endp
, 1, 0);
1903 udev
->endp_number_out
[usb_endp
] = endp_number
;
1904 u132_udev_get_kref(u132
, udev
);
1908 endp
->jiffies
= jiffies
+ msecs_to_jiffies(urb
->interval
);
1909 endp
->udev_number
= address
;
1910 endp
->usb_addr
= usb_addr
;
1911 endp
->usb_endp
= usb_endp
;
1912 endp
->queue_size
= 1;
1913 endp
->queue_last
= 0;
1914 endp
->queue_next
= 0;
1915 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
1916 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
1917 u132_endp_queue_work(u132
, endp
, msecs_to_jiffies(urb
->interval
));
1921 static int queue_int_on_old_endpoint(struct u132
*u132
,
1922 struct u132_udev
*udev
, struct urb
*urb
,
1923 struct usb_device
*usb_dev
, struct u132_endp
*endp
, u8 usb_addr
,
1924 u8 usb_endp
, u8 address
)
1928 endp
->jiffies
= jiffies
+ msecs_to_jiffies(urb
->interval
);
1929 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
1930 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
1932 struct u132_urbq
*urbq
= kmalloc(sizeof(struct u132_urbq
),
1935 endp
->queue_size
-= 1;
1938 list_add_tail(&urbq
->urb_more
, &endp
->urb_more
);
1945 static int create_endpoint_and_queue_bulk(struct u132
*u132
,
1946 struct u132_udev
*udev
, struct urb
*urb
,
1947 struct usb_device
*usb_dev
, u8 usb_addr
, u8 usb_endp
, u8 address
,
1951 struct u132_ring
*ring
;
1955 struct u132_endp
*endp
= kmalloc(sizeof(struct u132_endp
), mem_flags
);
1960 spin_lock_init(&endp
->queue_lock
.slock
);
1961 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
1962 rc
= usb_hcd_link_urb_to_ep(u132_to_hcd(u132
), urb
);
1964 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
1969 endp_number
= ++u132
->num_endpoints
;
1970 urb
->ep
->hcpriv
= u132
->endp
[endp_number
- 1] = endp
;
1971 INIT_DELAYED_WORK(&endp
->scheduler
, u132_hcd_endp_work_scheduler
);
1972 INIT_LIST_HEAD(&endp
->urb_more
);
1973 endp
->dequeueing
= 0;
1974 endp
->edset_flush
= 0;
1977 endp
->endp_number
= endp_number
;
1979 endp
->hep
= urb
->ep
;
1980 endp
->pipetype
= usb_pipetype(urb
->pipe
);
1981 u132_endp_init_kref(u132
, endp
);
1982 if (usb_pipein(urb
->pipe
)) {
1983 endp
->toggle_bits
= 0x2;
1984 usb_settoggle(udev
->usb_device
, usb_endp
, 0, 0);
1988 udev
->endp_number_in
[usb_endp
] = endp_number
;
1989 u132_udev_get_kref(u132
, udev
);
1991 endp
->toggle_bits
= 0x2;
1992 usb_settoggle(udev
->usb_device
, usb_endp
, 1, 0);
1996 udev
->endp_number_out
[usb_endp
] = endp_number
;
1997 u132_udev_get_kref(u132
, udev
);
1999 ring
= endp
->ring
= &u132
->ring
[ring_number
- 1];
2000 if (ring
->curr_endp
) {
2001 list_add_tail(&endp
->endp_ring
, &ring
->curr_endp
->endp_ring
);
2003 INIT_LIST_HEAD(&endp
->endp_ring
);
2004 ring
->curr_endp
= endp
;
2008 endp
->udev_number
= address
;
2009 endp
->usb_addr
= usb_addr
;
2010 endp
->usb_endp
= usb_endp
;
2011 endp
->queue_size
= 1;
2012 endp
->queue_last
= 0;
2013 endp
->queue_next
= 0;
2014 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
2015 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2016 u132_endp_queue_work(u132
, endp
, 0);
2020 static int queue_bulk_on_old_endpoint(struct u132
*u132
, struct u132_udev
*udev
,
2022 struct usb_device
*usb_dev
, struct u132_endp
*endp
, u8 usb_addr
,
2023 u8 usb_endp
, u8 address
)
2026 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2027 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
2029 struct u132_urbq
*urbq
= kmalloc(sizeof(struct u132_urbq
),
2032 endp
->queue_size
-= 1;
2035 list_add_tail(&urbq
->urb_more
, &endp
->urb_more
);
2042 static int create_endpoint_and_queue_control(struct u132
*u132
,
2044 struct usb_device
*usb_dev
, u8 usb_addr
, u8 usb_endp
,
2047 struct u132_ring
*ring
;
2051 struct u132_endp
*endp
= kmalloc(sizeof(struct u132_endp
), mem_flags
);
2056 spin_lock_init(&endp
->queue_lock
.slock
);
2057 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
2058 rc
= usb_hcd_link_urb_to_ep(u132_to_hcd(u132
), urb
);
2060 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2065 endp_number
= ++u132
->num_endpoints
;
2066 urb
->ep
->hcpriv
= u132
->endp
[endp_number
- 1] = endp
;
2067 INIT_DELAYED_WORK(&endp
->scheduler
, u132_hcd_endp_work_scheduler
);
2068 INIT_LIST_HEAD(&endp
->urb_more
);
2069 ring
= endp
->ring
= &u132
->ring
[0];
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
;
2077 endp
->dequeueing
= 0;
2078 endp
->edset_flush
= 0;
2081 endp
->endp_number
= endp_number
;
2083 endp
->hep
= urb
->ep
;
2084 u132_endp_init_kref(u132
, endp
);
2085 u132_endp_get_kref(u132
, endp
);
2086 if (usb_addr
== 0) {
2087 u8 address
= u132
->addr
[usb_addr
].address
;
2088 struct u132_udev
*udev
= &u132
->udev
[address
];
2089 endp
->udev_number
= address
;
2090 endp
->usb_addr
= usb_addr
;
2091 endp
->usb_endp
= usb_endp
;
2094 endp
->pipetype
= usb_pipetype(urb
->pipe
);
2095 u132_udev_init_kref(u132
, udev
);
2096 u132_udev_get_kref(u132
, udev
);
2097 udev
->endp_number_in
[usb_endp
] = endp_number
;
2098 udev
->endp_number_out
[usb_endp
] = endp_number
;
2100 endp
->queue_size
= 1;
2101 endp
->queue_last
= 0;
2102 endp
->queue_next
= 0;
2103 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
2104 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2105 u132_endp_queue_work(u132
, endp
, 0);
2107 } else { /*(usb_addr > 0) */
2108 u8 address
= u132
->addr
[usb_addr
].address
;
2109 struct u132_udev
*udev
= &u132
->udev
[address
];
2110 endp
->udev_number
= address
;
2111 endp
->usb_addr
= usb_addr
;
2112 endp
->usb_endp
= usb_endp
;
2115 endp
->pipetype
= usb_pipetype(urb
->pipe
);
2116 u132_udev_get_kref(u132
, udev
);
2117 udev
->enumeration
= 2;
2118 udev
->endp_number_in
[usb_endp
] = endp_number
;
2119 udev
->endp_number_out
[usb_endp
] = endp_number
;
2121 endp
->queue_size
= 1;
2122 endp
->queue_last
= 0;
2123 endp
->queue_next
= 0;
2124 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] = urb
;
2125 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2126 u132_endp_queue_work(u132
, endp
, 0);
2131 static int queue_control_on_old_endpoint(struct u132
*u132
,
2133 struct usb_device
*usb_dev
, struct u132_endp
*endp
, u8 usb_addr
,
2136 if (usb_addr
== 0) {
2137 if (usb_pipein(urb
->pipe
)) {
2139 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2140 endp
->urb_list
[ENDP_QUEUE_MASK
&
2141 endp
->queue_last
++] = urb
;
2143 struct u132_urbq
*urbq
=
2144 kmalloc(sizeof(struct u132_urbq
),
2147 endp
->queue_size
-= 1;
2150 list_add_tail(&urbq
->urb_more
,
2156 } else { /* usb_pipeout(urb->pipe) */
2157 struct u132_addr
*addr
= &u132
->addr
[usb_dev
->devnum
];
2158 int I
= MAX_U132_UDEVS
;
2161 struct u132_udev
*udev
= &u132
->udev
[++i
];
2162 if (udev
->usb_device
) {
2165 udev
->enumeration
= 1;
2166 u132
->addr
[0].address
= i
;
2167 endp
->udev_number
= i
;
2168 udev
->udev_number
= i
;
2169 udev
->usb_addr
= usb_dev
->devnum
;
2170 u132_udev_init_kref(u132
, udev
);
2171 udev
->endp_number_in
[usb_endp
] =
2173 u132_udev_get_kref(u132
, udev
);
2174 udev
->endp_number_out
[usb_endp
] =
2176 udev
->usb_device
= usb_dev
;
2177 ((u8
*) (urb
->setup_packet
))[2] =
2179 u132_udev_get_kref(u132
, udev
);
2184 dev_err(&u132
->platform_dev
->dev
, "run out of d"
2189 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2190 endp
->urb_list
[ENDP_QUEUE_MASK
&
2191 endp
->queue_last
++] = urb
;
2193 struct u132_urbq
*urbq
=
2194 kmalloc(sizeof(struct u132_urbq
),
2197 endp
->queue_size
-= 1;
2200 list_add_tail(&urbq
->urb_more
,
2207 } else { /*(usb_addr > 0) */
2208 u8 address
= u132
->addr
[usb_addr
].address
;
2209 struct u132_udev
*udev
= &u132
->udev
[address
];
2211 if (udev
->enumeration
!= 2)
2212 udev
->enumeration
= 2;
2213 if (endp
->queue_size
++ < ENDP_QUEUE_SIZE
) {
2214 endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_last
++] =
2217 struct u132_urbq
*urbq
=
2218 kmalloc(sizeof(struct u132_urbq
), GFP_ATOMIC
);
2220 endp
->queue_size
-= 1;
2223 list_add_tail(&urbq
->urb_more
, &endp
->urb_more
);
2231 static int u132_urb_enqueue(struct usb_hcd
*hcd
, struct urb
*urb
,
2234 struct u132
*u132
= hcd_to_u132(hcd
);
2235 if (irqs_disabled()) {
2236 if (gfpflags_allow_blocking(mem_flags
)) {
2237 printk(KERN_ERR
"invalid context for function that might sleep\n");
2241 if (u132
->going
> 1) {
2242 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2245 } else if (u132
->going
> 0) {
2246 dev_err(&u132
->platform_dev
->dev
, "device is being removed "
2250 u8 usb_addr
= usb_pipedevice(urb
->pipe
);
2251 u8 usb_endp
= usb_pipeendpoint(urb
->pipe
);
2252 struct usb_device
*usb_dev
= urb
->dev
;
2253 if (usb_pipetype(urb
->pipe
) == PIPE_INTERRUPT
) {
2254 u8 address
= u132
->addr
[usb_addr
].address
;
2255 struct u132_udev
*udev
= &u132
->udev
[address
];
2256 struct u132_endp
*endp
= urb
->ep
->hcpriv
;
2257 urb
->actual_length
= 0;
2261 spin_lock_irqsave(&endp
->queue_lock
.slock
,
2263 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
2265 retval
= queue_int_on_old_endpoint(
2271 usb_hcd_unlink_urb_from_ep(
2274 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2279 u132_endp_queue_work(u132
, endp
,
2280 msecs_to_jiffies(urb
->interval
))
2284 } else if (u132
->num_endpoints
== MAX_U132_ENDPS
) {
2286 } else { /*(endp == NULL) */
2287 return create_endpoint_and_queue_int(u132
, udev
,
2288 urb
, usb_dev
, usb_addr
,
2289 usb_endp
, address
, mem_flags
);
2291 } else if (usb_pipetype(urb
->pipe
) == PIPE_ISOCHRONOUS
) {
2292 dev_err(&u132
->platform_dev
->dev
, "the hardware does no"
2293 "t support PIPE_ISOCHRONOUS\n");
2295 } else if (usb_pipetype(urb
->pipe
) == PIPE_BULK
) {
2296 u8 address
= u132
->addr
[usb_addr
].address
;
2297 struct u132_udev
*udev
= &u132
->udev
[address
];
2298 struct u132_endp
*endp
= urb
->ep
->hcpriv
;
2299 urb
->actual_length
= 0;
2303 spin_lock_irqsave(&endp
->queue_lock
.slock
,
2305 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
2307 retval
= queue_bulk_on_old_endpoint(
2313 usb_hcd_unlink_urb_from_ep(
2316 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2321 u132_endp_queue_work(u132
, endp
, 0);
2324 } else if (u132
->num_endpoints
== MAX_U132_ENDPS
) {
2327 return create_endpoint_and_queue_bulk(u132
,
2328 udev
, urb
, usb_dev
, usb_addr
,
2329 usb_endp
, address
, mem_flags
);
2331 struct u132_endp
*endp
= urb
->ep
->hcpriv
;
2333 u8
*b
= urb
->setup_packet
;
2335 char data
[30 * 3 + 4];
2337 int m
= (sizeof(data
) - 1) / 3;
2340 while (urb_size
-- > 0) {
2342 } else if (i
++ < m
) {
2343 int w
= sprintf(d
, " %02X", *b
++);
2347 d
+= sprintf(d
, " ..");
2352 spin_lock_irqsave(&endp
->queue_lock
.slock
,
2354 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
2356 retval
= queue_control_on_old_endpoint(
2361 usb_hcd_unlink_urb_from_ep(
2364 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2369 u132_endp_queue_work(u132
, endp
, 0);
2372 } else if (u132
->num_endpoints
== MAX_U132_ENDPS
) {
2375 return create_endpoint_and_queue_control(u132
,
2376 urb
, usb_dev
, usb_addr
, usb_endp
,
2382 static int dequeue_from_overflow_chain(struct u132
*u132
,
2383 struct u132_endp
*endp
, struct urb
*urb
)
2385 struct u132_urbq
*urbq
;
2387 list_for_each_entry(urbq
, &endp
->urb_more
, urb_more
) {
2388 if (urbq
->urb
== urb
) {
2389 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
2390 list_del(&urbq
->urb_more
);
2391 endp
->queue_size
-= 1;
2392 urb
->error_count
= 0;
2393 usb_hcd_giveback_urb(hcd
, urb
, 0);
2398 dev_err(&u132
->platform_dev
->dev
, "urb=%p not found in endp[%d]=%p ring"
2399 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2400 "\n", urb
, endp
->endp_number
, endp
, endp
->ring
->number
,
2401 endp
->input
? 'I' : ' ', endp
->output
? 'O' : ' ',
2402 endp
->usb_endp
, endp
->usb_addr
, endp
->queue_size
,
2403 endp
->queue_next
, endp
->queue_last
);
2407 static int u132_endp_urb_dequeue(struct u132
*u132
, struct u132_endp
*endp
,
2408 struct urb
*urb
, int status
)
2413 spin_lock_irqsave(&endp
->queue_lock
.slock
, irqs
);
2414 rc
= usb_hcd_check_unlink_urb(u132_to_hcd(u132
), urb
, status
);
2416 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2419 if (endp
->queue_size
== 0) {
2420 dev_err(&u132
->platform_dev
->dev
, "urb=%p not found in endp[%d]"
2421 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb
,
2422 endp
->endp_number
, endp
, endp
->ring
->number
,
2423 endp
->input
? 'I' : ' ', endp
->output
? 'O' : ' ',
2424 endp
->usb_endp
, endp
->usb_addr
);
2425 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2428 if (urb
== endp
->urb_list
[ENDP_QUEUE_MASK
& endp
->queue_next
]) {
2430 endp
->dequeueing
= 1;
2431 endp
->edset_flush
= 1;
2432 u132_endp_queue_work(u132
, endp
, 0);
2433 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2436 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2437 u132_hcd_abandon_urb(u132
, endp
, urb
, status
);
2442 u16 queue_size
= endp
->queue_size
;
2443 u16 queue_scan
= endp
->queue_next
;
2444 struct urb
**urb_slot
= NULL
;
2445 while (++queue_list
< ENDP_QUEUE_SIZE
&& --queue_size
> 0) {
2446 if (urb
== endp
->urb_list
[ENDP_QUEUE_MASK
&
2448 urb_slot
= &endp
->urb_list
[ENDP_QUEUE_MASK
&
2454 while (++queue_list
< ENDP_QUEUE_SIZE
&& --queue_size
> 0) {
2455 *urb_slot
= endp
->urb_list
[ENDP_QUEUE_MASK
&
2457 urb_slot
= &endp
->urb_list
[ENDP_QUEUE_MASK
&
2461 struct usb_hcd
*hcd
= u132_to_hcd(u132
);
2463 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
2464 endp
->queue_size
-= 1;
2465 if (list_empty(&endp
->urb_more
)) {
2466 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2469 struct list_head
*next
= endp
->urb_more
.next
;
2470 struct u132_urbq
*urbq
= list_entry(next
,
2471 struct u132_urbq
, urb_more
);
2473 *urb_slot
= urbq
->urb
;
2474 spin_unlock_irqrestore(&endp
->queue_lock
.slock
,
2478 urb
->error_count
= 0;
2479 usb_hcd_giveback_urb(hcd
, urb
, status
);
2481 } else if (list_empty(&endp
->urb_more
)) {
2482 dev_err(&u132
->platform_dev
->dev
, "urb=%p not found in "
2483 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2484 "=%d size=%d next=%04X last=%04X\n", urb
,
2485 endp
->endp_number
, endp
, endp
->ring
->number
,
2486 endp
->input
? 'I' : ' ',
2487 endp
->output
? 'O' : ' ', endp
->usb_endp
,
2488 endp
->usb_addr
, endp
->queue_size
,
2489 endp
->queue_next
, endp
->queue_last
);
2490 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2495 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132
), urb
);
2496 retval
= dequeue_from_overflow_chain(u132
, endp
,
2498 spin_unlock_irqrestore(&endp
->queue_lock
.slock
, irqs
);
2504 static int u132_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
, int status
)
2506 struct u132
*u132
= hcd_to_u132(hcd
);
2507 if (u132
->going
> 2) {
2508 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2512 u8 usb_addr
= usb_pipedevice(urb
->pipe
);
2513 u8 usb_endp
= usb_pipeendpoint(urb
->pipe
);
2514 u8 address
= u132
->addr
[usb_addr
].address
;
2515 struct u132_udev
*udev
= &u132
->udev
[address
];
2516 if (usb_pipein(urb
->pipe
)) {
2517 u8 endp_number
= udev
->endp_number_in
[usb_endp
];
2518 struct u132_endp
*endp
= u132
->endp
[endp_number
- 1];
2519 return u132_endp_urb_dequeue(u132
, endp
, urb
, status
);
2521 u8 endp_number
= udev
->endp_number_out
[usb_endp
];
2522 struct u132_endp
*endp
= u132
->endp
[endp_number
- 1];
2523 return u132_endp_urb_dequeue(u132
, endp
, urb
, status
);
2528 static void u132_endpoint_disable(struct usb_hcd
*hcd
,
2529 struct usb_host_endpoint
*hep
)
2531 struct u132
*u132
= hcd_to_u132(hcd
);
2532 if (u132
->going
> 2) {
2533 dev_err(&u132
->platform_dev
->dev
, "u132 device %p(hcd=%p hep=%p"
2534 ") has been removed %d\n", u132
, hcd
, hep
,
2537 struct u132_endp
*endp
= hep
->hcpriv
;
2539 u132_endp_put_kref(u132
, endp
);
2543 static int u132_get_frame(struct usb_hcd
*hcd
)
2545 struct u132
*u132
= hcd_to_u132(hcd
);
2546 if (u132
->going
> 1) {
2547 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2550 } else if (u132
->going
> 0) {
2551 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2554 dev_err(&u132
->platform_dev
->dev
, "TODO: u132_get_frame\n");
2560 static int u132_roothub_descriptor(struct u132
*u132
,
2561 struct usb_hub_descriptor
*desc
)
2567 retval
= u132_read_pcimem(u132
, roothub
.a
, &rh_a
);
2570 desc
->bDescriptorType
= USB_DT_HUB
;
2571 desc
->bPwrOn2PwrGood
= (rh_a
& RH_A_POTPGT
) >> 24;
2572 desc
->bHubContrCurrent
= 0;
2573 desc
->bNbrPorts
= u132
->num_ports
;
2574 temp
= 1 + (u132
->num_ports
/ 8);
2575 desc
->bDescLength
= 7 + 2 * temp
;
2576 temp
= HUB_CHAR_COMMON_LPSM
| HUB_CHAR_COMMON_OCPM
;
2577 if (rh_a
& RH_A_NPS
)
2578 temp
|= HUB_CHAR_NO_LPSM
;
2579 if (rh_a
& RH_A_PSM
)
2580 temp
|= HUB_CHAR_INDV_PORT_LPSM
;
2581 if (rh_a
& RH_A_NOCP
)
2582 temp
|= HUB_CHAR_NO_OCPM
;
2583 else if (rh_a
& RH_A_OCPM
)
2584 temp
|= HUB_CHAR_INDV_PORT_OCPM
;
2585 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
2586 retval
= u132_read_pcimem(u132
, roothub
.b
, &rh_b
);
2589 memset(desc
->u
.hs
.DeviceRemovable
, 0xff,
2590 sizeof(desc
->u
.hs
.DeviceRemovable
));
2591 desc
->u
.hs
.DeviceRemovable
[0] = rh_b
& RH_B_DR
;
2592 if (u132
->num_ports
> 7) {
2593 desc
->u
.hs
.DeviceRemovable
[1] = (rh_b
& RH_B_DR
) >> 8;
2594 desc
->u
.hs
.DeviceRemovable
[2] = 0xff;
2596 desc
->u
.hs
.DeviceRemovable
[1] = 0xff;
2600 static int u132_roothub_status(struct u132
*u132
, __le32
*desc
)
2603 int ret_status
= u132_read_pcimem(u132
, roothub
.status
, &rh_status
);
2604 *desc
= cpu_to_le32(rh_status
);
2608 static int u132_roothub_portstatus(struct u132
*u132
, __le32
*desc
, u16 wIndex
)
2610 if (wIndex
== 0 || wIndex
> u132
->num_ports
) {
2613 int port
= wIndex
- 1;
2614 u32 rh_portstatus
= -1;
2615 int ret_portstatus
= u132_read_pcimem(u132
,
2616 roothub
.portstatus
[port
], &rh_portstatus
);
2617 *desc
= cpu_to_le32(rh_portstatus
);
2618 if (*(u16
*) (desc
+ 2)) {
2619 dev_info(&u132
->platform_dev
->dev
, "Port %d Status Chan"
2620 "ge = %08X\n", port
, *desc
);
2622 return ret_portstatus
;
2627 /* this timer value might be vendor-specific ... */
2628 #define PORT_RESET_HW_MSEC 10
2629 #define PORT_RESET_MSEC 10
2630 /* wrap-aware logic morphed from <linux/jiffies.h> */
2631 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2632 static int u132_roothub_portreset(struct u132
*u132
, int port_index
)
2638 retval
= u132_read_pcimem(u132
, fmnumber
, &fmnumber
);
2642 reset_done
= now
+ PORT_RESET_MSEC
;
2646 retval
= u132_read_pcimem(u132
,
2647 roothub
.portstatus
[port_index
], &portstat
);
2650 if (RH_PS_PRS
& portstat
)
2654 } while (tick_before(now
, reset_done
));
2655 if (RH_PS_PRS
& portstat
)
2657 if (RH_PS_CCS
& portstat
) {
2658 if (RH_PS_PRSC
& portstat
) {
2659 retval
= u132_write_pcimem(u132
,
2660 roothub
.portstatus
[port_index
],
2666 break; /* start the next reset,
2667 sleep till it's probably done */
2668 retval
= u132_write_pcimem(u132
, roothub
.portstatus
[port_index
],
2672 msleep(PORT_RESET_HW_MSEC
);
2673 retval
= u132_read_pcimem(u132
, fmnumber
, &fmnumber
);
2677 } while (tick_before(now
, reset_done
));
2681 static int u132_roothub_setportfeature(struct u132
*u132
, u16 wValue
,
2684 if (wIndex
== 0 || wIndex
> u132
->num_ports
) {
2687 int port_index
= wIndex
- 1;
2688 struct u132_port
*port
= &u132
->port
[port_index
];
2689 port
->Status
&= ~(1 << wValue
);
2691 case USB_PORT_FEAT_SUSPEND
:
2692 return u132_write_pcimem(u132
,
2693 roothub
.portstatus
[port_index
], RH_PS_PSS
);
2694 case USB_PORT_FEAT_POWER
:
2695 return u132_write_pcimem(u132
,
2696 roothub
.portstatus
[port_index
], RH_PS_PPS
);
2697 case USB_PORT_FEAT_RESET
:
2698 return u132_roothub_portreset(u132
, port_index
);
2705 static int u132_roothub_clearportfeature(struct u132
*u132
, u16 wValue
,
2708 if (wIndex
== 0 || wIndex
> u132
->num_ports
) {
2711 int port_index
= wIndex
- 1;
2713 struct u132_port
*port
= &u132
->port
[port_index
];
2714 port
->Status
&= ~(1 << wValue
);
2716 case USB_PORT_FEAT_ENABLE
:
2719 case USB_PORT_FEAT_C_ENABLE
:
2722 case USB_PORT_FEAT_SUSPEND
:
2724 if ((u132
->hc_control
& OHCI_CTRL_HCFS
)
2726 dev_err(&u132
->platform_dev
->dev
, "TODO resume_"
2730 case USB_PORT_FEAT_C_SUSPEND
:
2733 case USB_PORT_FEAT_POWER
:
2736 case USB_PORT_FEAT_C_CONNECTION
:
2739 case USB_PORT_FEAT_C_OVER_CURRENT
:
2742 case USB_PORT_FEAT_C_RESET
:
2748 return u132_write_pcimem(u132
, roothub
.portstatus
[port_index
],
2754 /* the virtual root hub timer IRQ checks for hub status*/
2755 static int u132_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
2757 struct u132
*u132
= hcd_to_u132(hcd
);
2758 if (u132
->going
> 1) {
2759 dev_err(&u132
->platform_dev
->dev
, "device hcd=%p has been remov"
2760 "ed %d\n", hcd
, u132
->going
);
2762 } else if (u132
->going
> 0) {
2763 dev_err(&u132
->platform_dev
->dev
, "device hcd=%p is being remov"
2767 int i
, changed
= 0, length
= 1;
2768 if (u132
->flags
& OHCI_QUIRK_AMD756
) {
2769 if ((u132
->hc_roothub_a
& RH_A_NDP
) > MAX_ROOT_PORTS
) {
2770 dev_err(&u132
->platform_dev
->dev
, "bogus NDP, r"
2771 "ereads as NDP=%d\n",
2772 u132
->hc_roothub_a
& RH_A_NDP
);
2776 if (u132
->hc_roothub_status
& (RH_HS_LPSC
| RH_HS_OCIC
))
2777 buf
[0] = changed
= 1;
2780 if (u132
->num_ports
> 7) {
2784 for (i
= 0; i
< u132
->num_ports
; i
++) {
2785 if (u132
->hc_roothub_portstatus
[i
] & (RH_PS_CSC
|
2786 RH_PS_PESC
| RH_PS_PSSC
| RH_PS_OCIC
|
2790 buf
[0] |= 1 << (i
+ 1);
2792 buf
[1] |= 1 << (i
- 7);
2795 if (!(u132
->hc_roothub_portstatus
[i
] & RH_PS_CCS
))
2798 if ((u132
->hc_roothub_portstatus
[i
] & RH_PS_PSS
))
2802 return changed
? length
: 0;
2806 static int u132_hub_control(struct usb_hcd
*hcd
, u16 typeReq
, u16 wValue
,
2807 u16 wIndex
, char *buf
, u16 wLength
)
2809 struct u132
*u132
= hcd_to_u132(hcd
);
2810 if (u132
->going
> 1) {
2811 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2814 } else if (u132
->going
> 0) {
2815 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2819 mutex_lock(&u132
->sw_lock
);
2821 case ClearHubFeature
:
2823 case C_HUB_OVER_CURRENT
:
2824 case C_HUB_LOCAL_POWER
:
2832 case C_HUB_OVER_CURRENT
:
2833 case C_HUB_LOCAL_POWER
:
2839 case ClearPortFeature
:{
2840 retval
= u132_roothub_clearportfeature(u132
,
2846 case GetHubDescriptor
:{
2847 retval
= u132_roothub_descriptor(u132
,
2848 (struct usb_hub_descriptor
*)buf
);
2854 retval
= u132_roothub_status(u132
,
2860 case GetPortStatus
:{
2861 retval
= u132_roothub_portstatus(u132
,
2862 (__le32
*) buf
, wIndex
);
2867 case SetPortFeature
:{
2868 retval
= u132_roothub_setportfeature(u132
,
2884 mutex_unlock(&u132
->sw_lock
);
2889 static int u132_start_port_reset(struct usb_hcd
*hcd
, unsigned port_num
)
2891 struct u132
*u132
= hcd_to_u132(hcd
);
2892 if (u132
->going
> 1) {
2893 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2896 } else if (u132
->going
> 0) {
2897 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2905 static int u132_bus_suspend(struct usb_hcd
*hcd
)
2907 struct u132
*u132
= hcd_to_u132(hcd
);
2908 if (u132
->going
> 1) {
2909 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2912 } else if (u132
->going
> 0) {
2913 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2919 static int u132_bus_resume(struct usb_hcd
*hcd
)
2921 struct u132
*u132
= hcd_to_u132(hcd
);
2922 if (u132
->going
> 1) {
2923 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
2926 } else if (u132
->going
> 0) {
2927 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
2934 #define u132_bus_suspend NULL
2935 #define u132_bus_resume NULL
2937 static const struct hc_driver u132_hc_driver
= {
2938 .description
= hcd_name
,
2939 .hcd_priv_size
= sizeof(struct u132
),
2941 .flags
= HCD_USB11
| HCD_MEMORY
,
2942 .reset
= u132_hcd_reset
,
2943 .start
= u132_hcd_start
,
2944 .stop
= u132_hcd_stop
,
2945 .urb_enqueue
= u132_urb_enqueue
,
2946 .urb_dequeue
= u132_urb_dequeue
,
2947 .endpoint_disable
= u132_endpoint_disable
,
2948 .get_frame_number
= u132_get_frame
,
2949 .hub_status_data
= u132_hub_status_data
,
2950 .hub_control
= u132_hub_control
,
2951 .bus_suspend
= u132_bus_suspend
,
2952 .bus_resume
= u132_bus_resume
,
2953 .start_port_reset
= u132_start_port_reset
,
2957 * This function may be called by the USB core whilst the "usb_all_devices_rwsem"
2958 * is held for writing, thus this module must not call usb_remove_hcd()
2959 * synchronously - but instead should immediately stop activity to the
2960 * device and asynchronously call usb_remove_hcd()
2962 static int u132_remove(struct platform_device
*pdev
)
2964 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
2966 struct u132
*u132
= hcd_to_u132(hcd
);
2967 if (u132
->going
++ > 1) {
2968 dev_err(&u132
->platform_dev
->dev
, "already being remove"
2972 int rings
= MAX_U132_RINGS
;
2973 int endps
= MAX_U132_ENDPS
;
2974 dev_err(&u132
->platform_dev
->dev
, "removing device u132"
2975 ".%d\n", u132
->sequence_num
);
2977 mutex_lock(&u132
->sw_lock
);
2978 u132_monitor_cancel_work(u132
);
2979 while (rings
-- > 0) {
2980 struct u132_ring
*ring
= &u132
->ring
[rings
];
2981 u132_ring_cancel_work(u132
, ring
);
2983 while (endps
-- > 0) {
2984 struct u132_endp
*endp
= u132
->endp
[endps
];
2986 u132_endp_cancel_work(u132
, endp
);
2989 printk(KERN_INFO
"removing device u132.%d\n",
2990 u132
->sequence_num
);
2991 mutex_unlock(&u132
->sw_lock
);
2992 usb_remove_hcd(hcd
);
2993 u132_u132_put_kref(u132
);
3000 static void u132_initialise(struct u132
*u132
, struct platform_device
*pdev
)
3002 int rings
= MAX_U132_RINGS
;
3003 int ports
= MAX_U132_PORTS
;
3004 int addrs
= MAX_U132_ADDRS
;
3005 int udevs
= MAX_U132_UDEVS
;
3006 int endps
= MAX_U132_ENDPS
;
3007 u132
->board
= dev_get_platdata(&pdev
->dev
);
3008 u132
->platform_dev
= pdev
;
3011 mutex_init(&u132
->sw_lock
);
3012 mutex_init(&u132
->scheduler_lock
);
3013 while (rings
-- > 0) {
3014 struct u132_ring
*ring
= &u132
->ring
[rings
];
3016 ring
->number
= rings
+ 1;
3018 ring
->curr_endp
= NULL
;
3019 INIT_DELAYED_WORK(&ring
->scheduler
,
3020 u132_hcd_ring_work_scheduler
);
3022 mutex_lock(&u132
->sw_lock
);
3023 INIT_DELAYED_WORK(&u132
->monitor
, u132_hcd_monitor_work
);
3024 while (ports
-- > 0) {
3025 struct u132_port
*port
= &u132
->port
[ports
];
3032 while (addrs
-- > 0) {
3033 struct u132_addr
*addr
= &u132
->addr
[addrs
];
3036 while (udevs
-- > 0) {
3037 struct u132_udev
*udev
= &u132
->udev
[udevs
];
3038 int i
= ARRAY_SIZE(udev
->endp_number_in
);
3039 int o
= ARRAY_SIZE(udev
->endp_number_out
);
3040 udev
->usb_device
= NULL
;
3041 udev
->udev_number
= 0;
3043 udev
->portnumber
= 0;
3045 udev
->endp_number_in
[i
] = 0;
3048 udev
->endp_number_out
[o
] = 0;
3052 u132
->endp
[endps
] = NULL
;
3054 mutex_unlock(&u132
->sw_lock
);
3057 static int u132_probe(struct platform_device
*pdev
)
3059 struct usb_hcd
*hcd
;
3065 if (u132_exiting
> 0)
3068 retval
= ftdi_write_pcimem(pdev
, intrdisable
, OHCI_INTR_MIE
);
3071 retval
= ftdi_read_pcimem(pdev
, control
, &control
);
3074 retval
= ftdi_read_pcimem(pdev
, roothub
.a
, &rh_a
);
3078 hcd
= usb_create_hcd(&u132_hc_driver
, &pdev
->dev
, dev_name(&pdev
->dev
));
3080 printk(KERN_ERR
"failed to create the usb hcd struct for U132\n"
3082 ftdi_elan_gone_away(pdev
);
3085 struct u132
*u132
= hcd_to_u132(hcd
);
3087 hcd
->rsrc_start
= 0;
3088 mutex_lock(&u132_module_lock
);
3089 u132
->sequence_num
= ++u132_instances
;
3090 mutex_unlock(&u132_module_lock
);
3091 u132_u132_init_kref(u132
);
3092 u132_initialise(u132
, pdev
);
3093 hcd
->product_desc
= "ELAN U132 Host Controller";
3094 retval
= usb_add_hcd(hcd
, 0, 0);
3096 dev_err(&u132
->platform_dev
->dev
, "init error %d\n",
3098 u132_u132_put_kref(u132
);
3101 device_wakeup_enable(hcd
->self
.controller
);
3102 u132_monitor_queue_work(u132
, 100);
3111 * for this device there's no useful distinction between the controller
3114 static int u132_suspend(struct platform_device
*pdev
, pm_message_t state
)
3116 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
3117 struct u132
*u132
= hcd_to_u132(hcd
);
3118 if (u132
->going
> 1) {
3119 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
3122 } else if (u132
->going
> 0) {
3123 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
3126 int retval
= 0, ports
;
3128 switch (state
.event
) {
3129 case PM_EVENT_FREEZE
:
3130 retval
= u132_bus_suspend(hcd
);
3132 case PM_EVENT_SUSPEND
:
3133 case PM_EVENT_HIBERNATE
:
3134 ports
= MAX_U132_PORTS
;
3135 while (ports
-- > 0) {
3136 port_power(u132
, ports
, 0);
3144 static int u132_resume(struct platform_device
*pdev
)
3146 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
3147 struct u132
*u132
= hcd_to_u132(hcd
);
3148 if (u132
->going
> 1) {
3149 dev_err(&u132
->platform_dev
->dev
, "device has been removed %d\n"
3152 } else if (u132
->going
> 0) {
3153 dev_err(&u132
->platform_dev
->dev
, "device is being removed\n");
3157 if (!u132
->port
[0].power
) {
3158 int ports
= MAX_U132_PORTS
;
3159 while (ports
-- > 0) {
3160 port_power(u132
, ports
, 1);
3164 retval
= u132_bus_resume(hcd
);
3171 #define u132_suspend NULL
3172 #define u132_resume NULL
3175 * this driver is loaded explicitly by ftdi_u132
3177 * the platform_driver struct is static because it is per type of module
3179 static struct platform_driver u132_platform_driver
= {
3180 .probe
= u132_probe
,
3181 .remove
= u132_remove
,
3182 .suspend
= u132_suspend
,
3183 .resume
= u132_resume
,
3188 static int __init
u132_hcd_init(void)
3193 mutex_init(&u132_module_lock
);
3196 printk(KERN_INFO
"driver %s\n", hcd_name
);
3197 workqueue
= create_singlethread_workqueue("u132");
3200 retval
= platform_driver_register(&u132_platform_driver
);
3202 destroy_workqueue(workqueue
);
3208 module_init(u132_hcd_init
);
3209 static void __exit
u132_hcd_exit(void)
3211 mutex_lock(&u132_module_lock
);
3213 mutex_unlock(&u132_module_lock
);
3214 platform_driver_unregister(&u132_platform_driver
);
3215 printk(KERN_INFO
"u132-hcd driver deregistered\n");
3216 wait_event(u132_hcd_wait
, u132_instances
== 0);
3217 flush_workqueue(workqueue
);
3218 destroy_workqueue(workqueue
);
3222 module_exit(u132_hcd_exit
);
3223 MODULE_LICENSE("GPL");
3224 MODULE_ALIAS("platform:u132_hcd");