38 #include <linux/kernel.h>
39 #include <linux/module.h>
44 #include <linux/sched.h>
45 #include <linux/slab.h>
46 #include <linux/errno.h>
49 #include <linux/list.h>
58 #include <asm/byteorder.h>
67 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
68 #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
73 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
76 static bool distrust_firmware = 1;
78 MODULE_PARM_DESC(distrust_firmware,
"true to distrust firmware power/overcurren"
85 static struct mutex u132_module_lock;
86 static int u132_exiting;
87 static int u132_instances;
93 #define MAX_U132_PORTS 7
94 #define MAX_U132_ADDRS 128
95 #define MAX_U132_UDEVS 4
96 #define MAX_U132_ENDPS 100
97 #define MAX_U132_RINGS 4
98 static const char *cc_to_text[16] = {
136 #define ENDP_QUEUE_SHIFT 3
137 #define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
138 #define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
165 struct usb_host_endpoint *
hep;
214 #define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
215 offsetof(struct ohci_regs, member), 0, data);
216 #define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
217 offsetof(struct ohci_regs, member), 0, data);
218 #define u132_read_pcimem(u132, member, data) \
219 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
220 ohci_regs, member), 0, data);
221 #define u132_write_pcimem(u132, member, data) \
222 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
223 ohci_regs, member), 0, data);
230 static inline struct u132 *hcd_to_u132(
struct usb_hcd *hcd)
232 return (
struct u132 *)(hcd->hcd_priv);
235 static inline struct usb_hcd *u132_to_hcd(
struct u132 *
u132)
237 return container_of((
void *)u132,
struct usb_hcd, hcd_priv);
240 static inline void u132_disable(
struct u132 *u132)
242 u132_to_hcd(u132)->state = HC_STATE_HALT;
246 #define kref_to_u132(d) container_of(d, struct u132, kref)
247 #define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref)
248 #define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref)
249 #include "../misc/usb_u132.h"
250 static const char hcd_name[] =
"u132_hcd";
251 #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
252 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
253 USB_PORT_STAT_C_RESET) << 16)
254 static void u132_hcd_delete(
struct kref *
kref)
258 struct usb_hcd *hcd = u132_to_hcd(u132);
265 "2=%p going=%d pdev=%p\n", hcd, u132, u132->
going, pdev);
269 static inline void u132_u132_put_kref(
struct u132 *u132)
271 kref_put(&u132->
kref, u132_hcd_delete);
274 static inline void u132_u132_init_kref(
struct u132 *u132)
276 kref_init(&u132->
kref);
279 static void u132_udev_delete(
struct kref *
kref)
288 static inline void u132_udev_put_kref(
struct u132 *u132,
struct u132_udev *
udev)
290 kref_put(&udev->
kref, u132_udev_delete);
293 static inline void u132_udev_get_kref(
struct u132 *u132,
struct u132_udev *
udev)
295 kref_get(&udev->
kref);
298 static inline void u132_udev_init_kref(
struct u132 *u132,
301 kref_init(&udev->
kref);
304 static inline void u132_ring_put_kref(
struct u132 *u132,
struct u132_ring *
ring)
306 kref_put(&u132->
kref, u132_hcd_delete);
309 static void u132_ring_requeue_work(
struct u132 *u132,
struct u132_ring *
ring,
317 kref_put(&u132->
kref, u132_hcd_delete);
320 static void u132_ring_queue_work(
struct u132 *u132,
struct u132_ring *ring,
323 kref_get(&u132->
kref);
324 u132_ring_requeue_work(u132, ring, delta);
327 static void u132_ring_cancel_work(
struct u132 *u132,
struct u132_ring *ring)
330 kref_put(&u132->
kref, u132_hcd_delete);
333 static void u132_endp_delete(
struct kref *
kref)
336 struct u132 *u132 = endp->
u132;
342 struct usb_host_endpoint *
hep = endp->
hep;
347 if (list_empty(head)) {
360 u132_udev_put_kref(u132, udev);
364 u132_udev_put_kref(u132, udev);
369 u132_u132_put_kref(u132);
372 static inline void u132_endp_put_kref(
struct u132 *u132,
struct u132_endp *endp)
374 kref_put(&endp->
kref, u132_endp_delete);
377 static inline void u132_endp_get_kref(
struct u132 *u132,
struct u132_endp *endp)
379 kref_get(&endp->
kref);
382 static inline void u132_endp_init_kref(
struct u132 *u132,
385 kref_init(&endp->
kref);
386 kref_get(&u132->
kref);
389 static void u132_endp_queue_work(
struct u132 *u132,
struct u132_endp *endp,
393 kref_get(&endp->
kref);
396 static void u132_endp_cancel_work(
struct u132 *u132,
struct u132_endp *endp)
399 kref_put(&endp->
kref, u132_endp_delete);
402 static inline void u132_monitor_put_kref(
struct u132 *u132)
404 kref_put(&u132->
kref, u132_hcd_delete);
407 static void u132_monitor_queue_work(
struct u132 *u132,
unsigned int delta)
410 kref_get(&u132->
kref);
413 static void u132_monitor_requeue_work(
struct u132 *u132,
unsigned int delta)
416 kref_put(&u132->
kref, u132_hcd_delete);
419 static void u132_monitor_cancel_work(
struct u132 *u132)
422 kref_put(&u132->
kref, u132_hcd_delete);
425 static int read_roothub_info(
struct u132 *u132)
434 }
else if ((revision & 0xFF) == 0x10) {
435 }
else if ((revision & 0xFF) == 0x11) {
438 " %08X\n", revision);
451 "g roothub.status\n", retval);
457 "g roothub.a\n", retval);
468 "essing device roothub.portstatus[%d]\n"
481 if (u132->
going > 1) {
484 u132_monitor_put_kref(u132);
486 }
else if (u132->
going > 0) {
488 u132_monitor_put_kref(u132);
493 retval = read_roothub_info(u132);
495 struct usb_hcd *hcd = u132_to_hcd(u132);
501 u132_monitor_put_kref(u132);
504 u132_monitor_requeue_work(u132, 500);
511 static void u132_hcd_giveback_urb(
struct u132 *u132,
struct u132_endp *endp,
516 struct usb_hcd *hcd = u132_to_hcd(u132);
517 urb->error_count = 0;
523 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
532 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
538 u132_ring_cancel_work(u132, ring);
539 u132_ring_queue_work(u132, ring, 0);
541 u132_endp_put_kref(u132, endp);
545 static void u132_hcd_forget_urb(
struct u132 *u132,
struct u132_endp *endp,
546 struct urb *urb,
int status)
548 u132_endp_put_kref(u132, endp);
551 static void u132_hcd_abandon_urb(
struct u132 *u132,
struct u132_endp *endp,
552 struct urb *urb,
int status)
555 struct usb_hcd *hcd = u132_to_hcd(u132);
556 urb->error_count = 0;
562 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
571 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
577 static inline int edset_input(
struct u132 *u132,
struct u132_ring *ring,
578 struct u132_endp *endp,
struct urb *urb,
u8 address,
u8 toggle_bits,
579 void (*
callback) (
void *endp,
struct urb *urb,
u8 *
buf,
int len,
580 int toggle_bits,
int error_count,
int condition_code,
int repeat_number,
581 int halted,
int skipped,
int actual,
int non_null))
584 urb, address, endp->usb_endp, toggle_bits,
callback);
587 static inline int edset_setup(
struct u132 *u132,
struct u132_ring *ring,
588 struct u132_endp *endp,
struct urb *urb,
u8 address,
u8 toggle_bits,
589 void (*
callback) (
void *endp,
struct urb *urb,
u8 *
buf,
int len,
590 int toggle_bits,
int error_count,
int condition_code,
int repeat_number,
591 int halted,
int skipped,
int actual,
int non_null))
594 urb, address, endp->usb_endp, toggle_bits,
callback);
597 static inline int edset_single(
struct u132 *u132,
struct u132_ring *ring,
598 struct u132_endp *endp,
struct urb *urb,
u8 address,
u8 toggle_bits,
599 void (*
callback) (
void *endp,
struct urb *urb,
u8 *
buf,
int len,
600 int toggle_bits,
int error_count,
int condition_code,
int repeat_number,
601 int halted,
int skipped,
int actual,
int non_null))
604 endp, urb, address, endp->usb_endp, toggle_bits,
callback);
607 static inline int edset_output(
struct u132 *u132,
struct u132_ring *ring,
608 struct u132_endp *endp,
struct urb *urb,
u8 address,
u8 toggle_bits,
609 void (*
callback) (
void *endp,
struct urb *urb,
u8 *
buf,
int len,
610 int toggle_bits,
int error_count,
int condition_code,
int repeat_number,
611 int halted,
int skipped,
int actual,
int non_null))
614 endp, urb, address, endp->usb_endp, toggle_bits,
callback);
622 static void u132_hcd_interrupt_recv(
void *
data,
struct urb *urb,
u8 *
buf,
623 int len,
int toggle_bits,
int error_count,
int condition_code,
624 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
627 struct u132 *u132 = endp->
u132;
631 if (u132->
going > 1) {
635 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
640 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
642 }
else if (u132->
going > 0) {
646 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
648 }
else if (!urb->unlinked) {
650 u8 *
u = urb->transfer_buffer + urb->actual_length;
657 urb->actual_length += len;
659 (urb->transfer_buffer_length > urb->actual_length)) {
663 if (urb->actual_length > 0) {
666 retval = edset_single(u132, ring, endp, urb,
668 u132_hcd_interrupt_recv);
670 u132_hcd_giveback_urb(u132, endp, urb,
677 u132_ring_cancel_work(u132, ring);
678 u132_ring_queue_work(u132, ring, 0);
680 u132_endp_put_kref(u132, endp);
684 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
689 u132_hcd_giveback_urb(u132, endp, urb, 0);
705 "g back INTERRUPT %s\n", urb,
706 cc_to_text[condition_code]);
709 u132_hcd_giveback_urb(u132, endp, urb,
710 cc_to_error[condition_code]);
715 "unlinked=%d\n", urb, urb->unlinked);
717 u132_hcd_giveback_urb(u132, endp, urb, 0);
722 static void u132_hcd_bulk_output_sent(
void *data,
struct urb *urb,
u8 *buf,
723 int len,
int toggle_bits,
int error_count,
int condition_code,
724 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
727 struct u132 *u132 = endp->
u132;
730 if (u132->
going > 1) {
734 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
739 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
741 }
else if (u132->
going > 0) {
745 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
747 }
else if (!urb->unlinked) {
749 urb->actual_length += len;
751 if (urb->transfer_buffer_length > urb->actual_length) {
754 retval = edset_output(u132, ring, endp, urb, address,
757 u132_hcd_giveback_urb(u132, endp, urb, retval);
761 u132_hcd_giveback_urb(u132, endp, urb, 0);
766 "unlinked=%d\n", urb, urb->unlinked);
768 u132_hcd_giveback_urb(u132, endp, urb, 0);
773 static void u132_hcd_bulk_input_recv(
void *data,
struct urb *urb,
u8 *buf,
774 int len,
int toggle_bits,
int error_count,
int condition_code,
775 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
778 struct u132 *u132 = endp->
u132;
782 if (u132->
going > 1) {
786 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
791 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
793 }
else if (u132->
going > 0) {
797 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
799 }
else if (!urb->unlinked) {
801 u8 *u = urb->transfer_buffer + urb->actual_length;
808 urb->actual_length += len;
810 (urb->transfer_buffer_length > urb->actual_length)) {
817 ring->
number, endp, urb, address,
819 u132_hcd_bulk_input_recv);
821 u132_hcd_giveback_urb(u132, endp, urb, retval);
828 u132_hcd_giveback_urb(u132, endp, urb,
829 cc_to_error[condition_code]);
832 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
837 u132_hcd_giveback_urb(u132, endp, urb, 0);
844 ") giving back BULK IN %s\n", urb,
845 cc_to_text[condition_code]);
847 u132_hcd_giveback_urb(u132, endp, urb, 0);
853 u132_hcd_giveback_urb(u132, endp, urb,
854 cc_to_error[condition_code]);
860 "ULK IN code=%d %s\n", urb, condition_code,
861 cc_to_text[condition_code]);
863 u132_hcd_giveback_urb(u132, endp, urb,
864 cc_to_error[condition_code]);
869 "unlinked=%d\n", urb, urb->unlinked);
871 u132_hcd_giveback_urb(u132, endp, urb, 0);
876 static void u132_hcd_configure_empty_sent(
void *data,
struct urb *urb,
u8 *buf,
877 int len,
int toggle_bits,
int error_count,
int condition_code,
878 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
881 struct u132 *u132 = endp->
u132;
883 if (u132->
going > 1) {
887 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
892 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
894 }
else if (u132->
going > 0) {
898 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
900 }
else if (!urb->unlinked) {
902 u132_hcd_giveback_urb(u132, endp, urb, 0);
906 "unlinked=%d\n", urb, urb->unlinked);
908 u132_hcd_giveback_urb(u132, endp, urb, 0);
913 static void u132_hcd_configure_input_recv(
void *data,
struct urb *urb,
u8 *buf,
914 int len,
int toggle_bits,
int error_count,
int condition_code,
915 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
918 struct u132 *u132 = endp->
u132;
921 if (u132->
going > 1) {
925 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
930 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
932 }
else if (u132->
going > 0) {
936 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
938 }
else if (!urb->unlinked) {
940 u8 *u = urb->transfer_buffer;
947 urb->actual_length = len;
950 URB_SHORT_NOT_OK) == 0))) {
954 ring->
number, endp, urb, address,
956 u132_hcd_configure_empty_sent);
958 u132_hcd_giveback_urb(u132, endp, urb, retval);
963 "NPUT STALL urb %p\n", urb);
964 u132_hcd_giveback_urb(u132, endp, urb,
965 cc_to_error[condition_code]);
970 "PUT %s urb %p\n", cc_to_text[condition_code],
972 u132_hcd_giveback_urb(u132, endp, urb,
973 cc_to_error[condition_code]);
978 "unlinked=%d\n", urb, urb->unlinked);
980 u132_hcd_giveback_urb(u132, endp, urb, 0);
985 static void u132_hcd_configure_empty_recv(
void *data,
struct urb *urb,
u8 *buf,
986 int len,
int toggle_bits,
int error_count,
int condition_code,
987 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
990 struct u132 *u132 = endp->
u132;
992 if (u132->
going > 1) {
996 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
1001 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
1003 }
else if (u132->
going > 0) {
1007 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
1009 }
else if (!urb->unlinked) {
1011 u132_hcd_giveback_urb(u132, endp, urb, 0);
1015 "unlinked=%d\n", urb, urb->unlinked);
1017 u132_hcd_giveback_urb(u132, endp, urb, 0);
1022 static void u132_hcd_configure_setup_sent(
void *data,
struct urb *urb,
u8 *buf,
1023 int len,
int toggle_bits,
int error_count,
int condition_code,
1024 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
1027 struct u132 *u132 = endp->
u132;
1030 if (u132->
going > 1) {
1034 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
1039 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
1041 }
else if (u132->
going > 0) {
1045 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
1047 }
else if (!urb->unlinked) {
1048 if (usb_pipein(urb->pipe)) {
1053 ring->
number, endp, urb, address,
1055 u132_hcd_configure_input_recv);
1057 u132_hcd_giveback_urb(u132, endp, urb, retval);
1064 ring->
number, endp, urb, address,
1066 u132_hcd_configure_empty_recv);
1068 u132_hcd_giveback_urb(u132, endp, urb, retval);
1073 "unlinked=%d\n", urb, urb->unlinked);
1075 u132_hcd_giveback_urb(u132, endp, urb, 0);
1080 static void u132_hcd_enumeration_empty_recv(
void *data,
struct urb *urb,
1081 u8 *buf,
int len,
int toggle_bits,
int error_count,
int condition_code,
1082 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
1085 struct u132 *u132 = endp->
u132;
1089 if (u132->
going > 1) {
1093 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
1098 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
1100 }
else if (u132->
going > 0) {
1104 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
1106 }
else if (!urb->unlinked) {
1107 u132->
addr[0].address = 0;
1110 u132_hcd_giveback_urb(u132, endp, urb, 0);
1114 "unlinked=%d\n", urb, urb->unlinked);
1116 u132_hcd_giveback_urb(u132, endp, urb, 0);
1121 static void u132_hcd_enumeration_address_sent(
void *data,
struct urb *urb,
1122 u8 *buf,
int len,
int toggle_bits,
int error_count,
int condition_code,
1123 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
1126 struct u132 *u132 = endp->
u132;
1128 if (u132->
going > 1) {
1132 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
1137 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
1139 }
else if (u132->
going > 0) {
1143 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
1145 }
else if (!urb->unlinked) {
1151 u132_hcd_enumeration_empty_recv);
1153 u132_hcd_giveback_urb(u132, endp, urb, retval);
1157 "unlinked=%d\n", urb, urb->unlinked);
1159 u132_hcd_giveback_urb(u132, endp, urb, 0);
1164 static void u132_hcd_initial_empty_sent(
void *data,
struct urb *urb,
u8 *buf,
1165 int len,
int toggle_bits,
int error_count,
int condition_code,
1166 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
1169 struct u132 *u132 = endp->
u132;
1171 if (u132->
going > 1) {
1175 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
1180 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
1182 }
else if (u132->
going > 0) {
1186 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
1188 }
else if (!urb->unlinked) {
1190 u132_hcd_giveback_urb(u132, endp, urb, 0);
1194 "unlinked=%d\n", urb, urb->unlinked);
1196 u132_hcd_giveback_urb(u132, endp, urb, 0);
1201 static void u132_hcd_initial_input_recv(
void *data,
struct urb *urb,
u8 *buf,
1202 int len,
int toggle_bits,
int error_count,
int condition_code,
1203 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
1206 struct u132 *u132 = endp->
u132;
1209 if (u132->
going > 1) {
1213 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
1218 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
1220 }
else if (u132->
going > 0) {
1224 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
1226 }
else if (!urb->unlinked) {
1229 u8 *u = urb->transfer_buffer;
1236 urb->actual_length = len;
1240 u132_hcd_initial_empty_sent);
1242 u132_hcd_giveback_urb(u132, endp, urb, retval);
1246 "unlinked=%d\n", urb, urb->unlinked);
1248 u132_hcd_giveback_urb(u132, endp, urb, 0);
1253 static void u132_hcd_initial_setup_sent(
void *data,
struct urb *urb,
u8 *buf,
1254 int len,
int toggle_bits,
int error_count,
int condition_code,
1255 int repeat_number,
int halted,
int skipped,
int actual,
int non_null)
1258 struct u132 *u132 = endp->
u132;
1261 if (u132->
going > 1) {
1265 u132_hcd_forget_urb(u132, endp, urb, -
ENODEV);
1270 u132_hcd_giveback_urb(u132, endp, urb, -
EINTR);
1272 }
else if (u132->
going > 0) {
1276 u132_hcd_giveback_urb(u132, endp, urb, -
ENODEV);
1278 }
else if (!urb->unlinked) {
1284 u132_hcd_initial_input_recv);
1286 u132_hcd_giveback_urb(u132, endp, urb, retval);
1290 "unlinked=%d\n", urb, urb->unlinked);
1292 u132_hcd_giveback_urb(u132, endp, urb, 0);
1301 static void u132_hcd_ring_work_scheduler(
struct work_struct *work)
1305 struct u132 *u132 = ring->
u132;
1309 u132_ring_put_kref(u132, ring);
1315 unsigned long wakeup = 0;
1320 }
else if ((endp->
delayed == 0)
1323 u132_endp_cancel_work(u132, last_endp);
1324 u132_endp_queue_work(u132, last_endp, 0);
1326 u132_ring_put_kref(u132, ring);
1337 u132_endp_cancel_work(u132, last_endp);
1338 u132_endp_queue_work(u132, last_endp, 0);
1340 u132_ring_put_kref(u132, ring);
1348 u132_ring_requeue_work(u132, ring, wakeup);
1353 u132_ring_put_kref(u132, ring);
1358 u132_ring_put_kref(u132, ring);
1363 static void u132_hcd_endp_work_scheduler(
struct work_struct *work)
1368 struct u132 *u132 = endp->
u132;
1377 u132_endp_put_kref(u132, endp);
1379 }
else if (endp->
active) {
1381 u132_endp_put_kref(u132, endp);
1383 }
else if (ring->
in_use) {
1385 u132_endp_put_kref(u132, endp);
1389 u132_endp_put_kref(u132, endp);
1391 }
else if (endp->
pipetype == PIPE_INTERRUPT) {
1395 u132_endp_put_kref(u132, endp);
1405 retval = edset_single(u132, ring, endp, urb, address,
1408 u132_hcd_giveback_urb(u132, endp, urb, retval);
1411 }
else if (endp->
pipetype == PIPE_CONTROL) {
1415 u132_endp_put_kref(u132, endp);
1417 }
else if (address == 0) {
1425 retval = edset_setup(u132, ring, endp, urb, address,
1426 0x2, u132_hcd_initial_setup_sent);
1428 u132_hcd_giveback_urb(u132, endp, urb, retval);
1438 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1439 u132_hcd_enumeration_address_sent);
1441 u132_hcd_giveback_urb(u132, endp, urb, retval);
1452 retval = edset_setup(u132, ring, endp, urb, address,
1453 0x2, u132_hcd_configure_setup_sent);
1455 u132_hcd_giveback_urb(u132, endp, urb, retval);
1463 u132_endp_put_kref(u132, endp);
1473 retval = edset_input(u132, ring, endp, urb,
1475 u132_hcd_bulk_input_recv);
1478 u132_hcd_giveback_urb(u132, endp, urb,
1486 u132_endp_put_kref(u132, endp);
1496 retval = edset_output(u132, ring, endp, urb,
1498 u132_hcd_bulk_output_sent);
1501 u132_hcd_giveback_urb(u132, endp, urb,
1510 static void port_power(
struct u132 *u132,
int pn,
int is_on)
1512 u132->
port[
pn].power = is_on;
1517 static void u132_power(
struct u132 *u132,
int is_on)
1519 struct usb_hcd *hcd = u132_to_hcd(u132)
1527 hcd->state = HC_STATE_HALT;
1531 static int u132_periodic_reinit(
struct u132 *u132)
1540 fit = fminterval &
FIT;
1546 ((9 * fi) / 10) & 0x3fff);
1552 static char *hcfs2string(
int state)
1560 return "operational";
1567 static int u132_init(
struct u132 *u132)
1585 retval = read_roothub_info(u132);
1600 static int u132_run(
struct u132 *u132)
1612 int reset_timeout = 30;
1656 for (temp = 0; temp < u132->
num_ports; temp++) {
1678 if (--reset_timeout == 0) {
1705 retval = u132_periodic_reinit(u132);
1714 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1720 "\n", fminterval, periodicstart);
1736 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1769 (roothub_a & RH_A_NPS) ? 0 :
RH_B_PPCM);
1775 mdelay((roothub_a >> 23) & 0x1fe);
1776 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1780 static void u132_hcd_stop(
struct usb_hcd *hcd)
1782 struct u132 *u132 = hcd_to_u132(hcd);
1783 if (u132->
going > 1) {
1785 "een removed %d\n", u132, hcd, u132->
going);
1786 }
else if (u132->
going > 0) {
1792 u132_power(u132, 0);
1797 static int u132_hcd_start(
struct usb_hcd *hcd)
1799 struct u132 *u132 = hcd_to_u132(hcd);
1800 if (u132->
going > 1) {
1804 }
else if (u132->
going > 0) {
1807 }
else if (hcd->self.controller) {
1812 (pdev->
dev.platform_data))->vendor;
1814 (pdev->
dev.platform_data))->device;
1821 "ounds unavailable\n");
1824 retval = u132_run(u132);
1838 static int u132_hcd_reset(
struct usb_hcd *hcd)
1840 struct u132 *u132 = hcd_to_u132(hcd);
1841 if (u132->
going > 1) {
1845 }
else if (u132->
going > 0) {
1851 retval = u132_init(u132);
1861 static int create_endpoint_and_queue_int(
struct u132 *u132,
1862 struct u132_udev *udev,
struct urb *urb,
1863 struct usb_device *usb_dev,
u8 usb_addr,
u8 usb_endp,
u8 address,
1879 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
1885 urb->ep->hcpriv = u132->
endp[endp_number - 1] = endp;
1888 ring = endp->
ring = &u132->
ring[0];
1902 endp->
hep = urb->ep;
1903 endp->
pipetype = usb_pipetype(urb->pipe);
1904 u132_endp_init_kref(u132, endp);
1905 if (usb_pipein(urb->pipe)) {
1907 usb_settoggle(udev->
usb_device, usb_endp, 0, 0);
1911 u132_udev_get_kref(u132, udev);
1914 usb_settoggle(udev->
usb_device, usb_endp, 1, 0);
1918 u132_udev_get_kref(u132, udev);
1930 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
1935 static int queue_int_on_old_endpoint(
struct u132 *u132,
1936 struct u132_udev *udev,
struct urb *urb,
1937 struct usb_device *usb_dev,
struct u132_endp *endp,
u8 usb_addr,
1938 u8 usb_endp,
u8 address)
1959 static int create_endpoint_and_queue_bulk(
struct u132 *u132,
1960 struct u132_udev *udev,
struct urb *urb,
1961 struct usb_device *usb_dev,
u8 usb_addr,
u8 usb_endp,
u8 address,
1978 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
1984 urb->ep->hcpriv = u132->
endp[endp_number - 1] = endp;
1993 endp->
hep = urb->ep;
1994 endp->
pipetype = usb_pipetype(urb->pipe);
1995 u132_endp_init_kref(u132, endp);
1996 if (usb_pipein(urb->pipe)) {
1998 usb_settoggle(udev->
usb_device, usb_endp, 0, 0);
2003 u132_udev_get_kref(u132, udev);
2006 usb_settoggle(udev->
usb_device, usb_endp, 1, 0);
2011 u132_udev_get_kref(u132, udev);
2013 ring = endp->
ring = &u132->
ring[ring_number - 1];
2029 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
2030 u132_endp_queue_work(u132, endp, 0);
2034 static int queue_bulk_on_old_endpoint(
struct u132 *u132,
struct u132_udev *udev,
2036 struct usb_device *usb_dev,
struct u132_endp *endp,
u8 usb_addr,
2037 u8 usb_endp,
u8 address)
2056 static int create_endpoint_and_queue_control(
struct u132 *u132,
2058 struct usb_device *usb_dev,
u8 usb_addr,
u8 usb_endp,
2074 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
2080 urb->ep->hcpriv = u132->
endp[endp_number - 1] = endp;
2083 ring = endp->
ring = &u132->
ring[0];
2097 endp->
hep = urb->ep;
2098 u132_endp_init_kref(u132, endp);
2099 u132_endp_get_kref(u132, endp);
2100 if (usb_addr == 0) {
2108 endp->
pipetype = usb_pipetype(urb->pipe);
2109 u132_udev_init_kref(u132, udev);
2110 u132_udev_get_kref(u132, udev);
2118 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
2119 u132_endp_queue_work(u132, endp, 0);
2129 endp->
pipetype = usb_pipetype(urb->pipe);
2130 u132_udev_get_kref(u132, udev);
2139 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
2140 u132_endp_queue_work(u132, endp, 0);
2145 static int queue_control_on_old_endpoint(
struct u132 *u132,
2150 if (usb_addr == 0) {
2151 if (usb_pipein(urb->pipe)) {
2180 u132->
addr[0].address =
i;
2184 u132_udev_init_kref(u132, udev);
2187 u132_udev_get_kref(u132, udev);
2191 ((
u8 *) (urb->setup_packet))[2] =
2193 u132_udev_get_kref(u132, udev);
2222 u8 address = u132->
addr[usb_addr].address;
2245 static int u132_urb_enqueue(
struct usb_hcd *hcd,
struct urb *urb,
2248 struct u132 *u132 = hcd_to_u132(hcd);
2256 if (u132->
going > 1) {
2260 }
else if (u132->
going > 0) {
2265 u8 usb_addr = usb_pipedevice(urb->pipe);
2266 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2267 struct usb_device *usb_dev = urb->dev;
2268 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2269 u8 address = u132->
addr[usb_addr].address;
2271 struct u132_endp *endp = urb->ep->hcpriv;
2272 urb->actual_length = 0;
2280 retval = queue_int_on_old_endpoint(
2289 spin_unlock_irqrestore(&endp->
queue_lock.slock,
2294 u132_endp_queue_work(u132, endp,
2302 return create_endpoint_and_queue_int(u132, udev,
2303 urb, usb_dev, usb_addr,
2304 usb_endp, address, mem_flags);
2306 }
else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2308 "t support PIPE_ISOCHRONOUS\n");
2310 }
else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2313 struct u132_endp *endp = urb->ep->hcpriv;
2314 urb->actual_length = 0;
2322 retval = queue_bulk_on_old_endpoint(
2331 spin_unlock_irqrestore(&endp->
queue_lock.slock,
2336 u132_endp_queue_work(u132, endp, 0);
2342 return create_endpoint_and_queue_bulk(u132,
2343 udev, urb, usb_dev, usb_addr,
2344 usb_endp, address, mem_flags);
2346 struct u132_endp *endp = urb->ep->hcpriv;
2348 u8 *b = urb->setup_packet;
2350 char data[30 * 3 + 4];
2352 int m = (
sizeof(
data) - 1) / 3;
2355 while (urb_size-- > 0) {
2357 }
else if (i++ < m) {
2371 retval = queue_control_on_old_endpoint(
2379 spin_unlock_irqrestore(&endp->
queue_lock.slock,
2384 u132_endp_queue_work(u132, endp, 0);
2390 return create_endpoint_and_queue_control(u132,
2391 urb, usb_dev, usb_addr, usb_endp,
2397 static int dequeue_from_overflow_chain(
struct u132 *u132,
2398 struct u132_endp *endp,
struct urb *urb)
2405 if (urbq->
urb == urb) {
2406 struct usb_hcd *hcd = u132_to_hcd(u132);
2409 urb->error_count = 0;
2416 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2418 endp->
input ?
'I' :
' ', endp->
output ?
'O' :
' ',
2424 static int u132_endp_urb_dequeue(
struct u132 *u132,
struct u132_endp *endp,
2425 struct urb *urb,
int status)
2433 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
2438 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2440 endp->
input ?
'I' :
' ', endp->
output ?
'O' :
' ',
2442 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
2449 u132_endp_queue_work(u132, endp, 0);
2450 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
2453 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
2454 u132_hcd_abandon_urb(u132, endp, urb, status);
2461 struct urb **urb_slot =
NULL;
2462 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2471 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2478 struct usb_hcd *hcd = u132_to_hcd(u132);
2483 spin_unlock_irqrestore(&endp->
queue_lock.slock,
2490 *urb_slot = urbq->
urb;
2491 spin_unlock_irqrestore(&endp->
queue_lock.slock,
2494 } urb->error_count = 0;
2497 }
else if (list_empty(&endp->
urb_more)) {
2499 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2500 "=%d size=%d next=%04X last=%04X\n", urb,
2502 endp->
input ?
'I' :
' ',
2506 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
2512 retval = dequeue_from_overflow_chain(u132, endp,
2514 spin_unlock_irqrestore(&endp->
queue_lock.slock, irqs);
2520 static int u132_urb_dequeue(
struct usb_hcd *hcd,
struct urb *urb,
int status)
2522 struct u132 *u132 = hcd_to_u132(hcd);
2523 if (u132->
going > 2) {
2528 u8 usb_addr = usb_pipedevice(urb->pipe);
2529 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2530 u8 address = u132->
addr[usb_addr].address;
2532 if (usb_pipein(urb->pipe)) {
2535 return u132_endp_urb_dequeue(u132, endp, urb, status);
2539 return u132_endp_urb_dequeue(u132, endp, urb, status);
2544 static void u132_endpoint_disable(
struct usb_hcd *hcd,
2545 struct usb_host_endpoint *hep)
2547 struct u132 *u132 = hcd_to_u132(hcd);
2548 if (u132->
going > 2) {
2550 ") has been removed %d\n", u132, hcd, hep,
2555 u132_endp_put_kref(u132, endp);
2559 static int u132_get_frame(
struct usb_hcd *hcd)
2561 struct u132 *u132 = hcd_to_u132(hcd);
2562 if (u132->
going > 1) {
2566 }
else if (u132->
going > 0) {
2577 static int u132_roothub_descriptor(
struct u132 *u132,
2594 if (rh_a & RH_A_NPS)
2617 static int u132_roothub_status(
struct u132 *u132,
__le32 *desc)
2625 static int u132_roothub_portstatus(
struct u132 *u132,
__le32 *desc,
u16 wIndex)
2627 if (wIndex == 0 || wIndex > u132->
num_ports) {
2630 int port = wIndex - 1;
2631 u32 rh_portstatus = -1;
2633 roothub.portstatus[port], &rh_portstatus);
2635 if (*(
u16 *) (desc + 2)) {
2637 "ge = %08X\n", port, *desc);
2639 return ret_portstatus;
2645 #define PORT_RESET_HW_MSEC 10
2646 #define PORT_RESET_MSEC 10
2648 #define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2649 static int u132_roothub_portreset(
struct u132 *u132,
int port_index)
2664 roothub.portstatus[port_index], &portstat);
2677 roothub.portstatus[port_index],
2698 static int u132_roothub_setportfeature(
struct u132 *u132,
u16 wValue,
2701 if (wIndex == 0 || wIndex > u132->
num_ports) {
2705 int port_index = wIndex - 1;
2722 retval = u132_roothub_portreset(u132, port_index);
2732 static int u132_roothub_clearportfeature(
struct u132 *u132,
u16 wValue,
2735 if (wIndex == 0 || wIndex > u132->
num_ports) {
2738 int port_index = wIndex - 1;
2786 static int u132_hub_status_data(
struct usb_hcd *hcd,
char *buf)
2788 struct u132 *u132 = hcd_to_u132(hcd);
2789 if (u132->
going > 1) {
2791 "ed %d\n", hcd, u132->
going);
2793 }
else if (u132->
going > 0) {
2802 "ereads as NDP=%d\n",
2808 buf[0] = changed = 1;
2821 buf[0] |= 1 << (i + 1);
2823 buf[1] |= 1 << (i - 7);
2833 return changed ?
length : 0;
2837 static int u132_hub_control(
struct usb_hcd *hcd,
u16 typeReq,
u16 wValue,
2840 struct u132 *u132 = hcd_to_u132(hcd);
2841 if (u132->
going > 1) {
2845 }
else if (u132->
going > 0) {
2852 case ClearHubFeature:
2870 case ClearPortFeature:{
2871 retval = u132_roothub_clearportfeature(u132,
2877 case GetHubDescriptor:{
2878 retval = u132_roothub_descriptor(u132,
2885 retval = u132_roothub_status(u132,
2891 case GetPortStatus:{
2892 retval = u132_roothub_portstatus(u132,
2898 case SetPortFeature:{
2899 retval = u132_roothub_setportfeature(u132,
2920 static int u132_start_port_reset(
struct usb_hcd *hcd,
unsigned port_num)
2922 struct u132 *u132 = hcd_to_u132(hcd);
2923 if (u132->
going > 1) {
2927 }
else if (u132->
going > 0) {
2938 struct u132 *u132 = hcd_to_u132(hcd);
2939 if (u132->
going > 1) {
2943 }
else if (u132->
going > 0) {
2952 struct u132 *u132 = hcd_to_u132(hcd);
2953 if (u132->
going > 1) {
2957 }
else if (u132->
going > 0) {
2965 #define u132_bus_suspend NULL
2966 #define u132_bus_resume NULL
2968 static struct hc_driver u132_hc_driver = {
2969 .description = hcd_name,
2970 .hcd_priv_size =
sizeof(
struct u132),
2972 .flags = HCD_USB11 | HCD_MEMORY,
2973 .reset = u132_hcd_reset,
2974 .start = u132_hcd_start,
2975 .stop = u132_hcd_stop,
2976 .urb_enqueue = u132_urb_enqueue,
2977 .urb_dequeue = u132_urb_dequeue,
2978 .endpoint_disable = u132_endpoint_disable,
2979 .get_frame_number = u132_get_frame,
2980 .hub_status_data = u132_hub_status_data,
2981 .hub_control = u132_hub_control,
2984 .start_port_reset = u132_start_port_reset,
2995 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2997 struct u132 *u132 = hcd_to_u132(hcd);
2998 if (u132->
going++ > 1) {
3009 u132_monitor_cancel_work(u132);
3010 while (rings-- > 0) {
3012 u132_ring_cancel_work(u132, ring);
3013 }
while (endps-- > 0) {
3016 u132_endp_cancel_work(u132, endp);
3023 u132_u132_put_kref(u132);
3030 static void u132_initialise(
struct u132 *u132,
struct platform_device *pdev)
3037 u132->
board = pdev->
dev.platform_data;
3043 while (rings-- > 0) {
3046 ring->
number = rings + 1;
3050 u132_hcd_ring_work_scheduler);
3054 while (ports-- > 0) {
3062 while (addrs-- > 0) {
3066 while (udevs-- > 0) {
3089 struct usb_hcd *hcd;
3096 if (u132_exiting > 0)
3109 if (pdev->
dev.dma_mask)
3119 struct u132 *u132 = hcd_to_u132(hcd);
3121 hcd->rsrc_start = 0;
3126 u132_u132_init_kref(u132);
3127 u132_initialise(u132, pdev);
3128 hcd->product_desc =
"ELAN U132 Host Controller";
3133 u132_u132_put_kref(u132);
3136 u132_monitor_queue_work(u132, 100);
3150 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3151 struct u132 *u132 = hcd_to_u132(hcd);
3152 if (u132->
going > 1) {
3156 }
else if (u132->
going > 0) {
3160 int retval = 0, ports;
3162 switch (state.
event) {
3169 while (ports-- > 0) {
3170 port_power(u132, ports, 0);
3180 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3181 struct u132 *u132 = hcd_to_u132(hcd);
3182 if (u132->
going > 1) {
3186 }
else if (u132->
going > 0) {
3191 if (!u132->
port[0].power) {
3193 while (ports-- > 0) {
3194 port_power(u132, ports, 1);
3205 #define u132_suspend NULL
3206 #define u132_resume NULL
3214 .probe = u132_probe,
3219 .name = (
char *)hcd_name,
3223 static int __init u132_hcd_init(
void)
3226 INIT_LIST_HEAD(&u132_static_list);
3240 static void __exit u132_hcd_exit(
void)
3252 wait_event(u132_hcd_wait, u132_instances == 0);