blob: 4f95a249c9137ff17c1b1a4ba766d55021436822 [file] [log] [blame]
Tony Olechd774efe2006-09-13 11:27:35 +01001/*
2* Host Controller Driver for the Elan Digital Systems U132 adapter
3*
4* Copyright(C) 2006 Elan Digital Systems Limited
5* http://www.elandigitalsystems.com
6*
7* Author and Maintainer - Tony Olech - Elan Digital Systems
8* tony.olech@elandigitalsystems.com
9*
10* This program is free software;you can redistribute it and/or
11* modify it under the terms of the GNU General Public License as
12* published by the Free Software Foundation, version 2.
13*
14*
15* This driver was written by Tony Olech(tony.olech@elandigitalsystems.com)
16* based on various USB host drivers in the 2.6.15 linux kernel
17* with constant reference to the 3rd Edition of Linux Device Drivers
18* published by O'Reilly
19*
20* The U132 adapter is a USB to CardBus adapter specifically designed
21* for PC cards that contain an OHCI host controller. Typical PC cards
22* are the Orange Mobile 3G Option GlobeTrotter Fusion card.
23*
24* The U132 adapter will *NOT *work with PC cards that do not contain
25* an OHCI controller. A simple way to test whether a PC card has an
26* OHCI controller as an interface is to insert the PC card directly
27* into a laptop(or desktop) with a CardBus slot and if "lspci" shows
28* a new USB controller and "lsusb -v" shows a new OHCI Host Controller
29* then there is a good chance that the U132 adapter will support the
30* PC card.(you also need the specific client driver for the PC card)
31*
32* Please inform the Author and Maintainer about any PC cards that
33* contain OHCI Host Controller and work when directly connected to
34* an embedded CardBus slot but do not work when they are connected
35* via an ELAN U132 adapter.
36*
37*/
Tony Olechd774efe2006-09-13 11:27:35 +010038#include <linux/kernel.h>
39#include <linux/module.h>
40#include <linux/moduleparam.h>
41#include <linux/delay.h>
42#include <linux/ioport.h>
43#include <linux/sched.h>
44#include <linux/slab.h>
45#include <linux/smp_lock.h>
46#include <linux/errno.h>
47#include <linux/init.h>
48#include <linux/timer.h>
49#include <linux/list.h>
50#include <linux/interrupt.h>
51#include <linux/usb.h>
52#include <linux/workqueue.h>
53#include <linux/platform_device.h>
54#include <linux/pci_ids.h>
55#include <asm/io.h>
56#include <asm/irq.h>
57#include <asm/system.h>
58#include <asm/byteorder.h>
59#include "../core/hcd.h"
60#include "ohci.h"
61#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
62#define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
63 OHCI_INTR_WDH)
64MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
65MODULE_DESCRIPTION("U132 USB Host Controller Driver");
66MODULE_LICENSE("GPL");
67#define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
68INT_MODULE_PARM(testing, 0);
69/* Some boards misreport power switching/overcurrent*/
70static int distrust_firmware = 1;
71module_param(distrust_firmware, bool, 0);
72MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
73 "t setup");
74DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
75/*
76* u132_module_lock exists to protect access to global variables
77*
78*/
79static struct semaphore u132_module_lock;
80static int u132_exiting = 0;
81static int u132_instances = 0;
82static struct list_head u132_static_list;
83/*
84* end of the global variables protected by u132_module_lock
85*/
86static struct workqueue_struct *workqueue;
87#define MAX_U132_PORTS 7
88#define MAX_U132_ADDRS 128
89#define MAX_U132_UDEVS 4
90#define MAX_U132_ENDPS 100
91#define MAX_U132_RINGS 4
92static const char *cc_to_text[16] = {
93 "No Error ",
94 "CRC Error ",
95 "Bit Stuff ",
96 "Data Togg ",
97 "Stall ",
98 "DevNotResp ",
99 "PIDCheck ",
100 "UnExpPID ",
101 "DataOver ",
102 "DataUnder ",
103 "(for hw) ",
104 "(for hw) ",
105 "BufferOver ",
106 "BuffUnder ",
107 "(for HCD) ",
108 "(for HCD) "
109};
110struct u132_port {
111 struct u132 *u132;
112 int reset;
113 int enable;
114 int power;
115 int Status;
116};
117struct u132_addr {
118 u8 address;
119};
120struct u132_udev {
121 struct kref kref;
122 struct usb_device *usb_device;
123 u8 enumeration;
124 u8 udev_number;
125 u8 usb_addr;
126 u8 portnumber;
127 u8 endp_number_in[16];
128 u8 endp_number_out[16];
129};
130#define ENDP_QUEUE_SHIFT 3
131#define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
132#define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
133struct u132_urbq {
134 struct list_head urb_more;
135 struct urb *urb;
136};
137struct u132_spin {
138 spinlock_t slock;
139};
140struct u132_endp {
141 struct kref kref;
142 u8 udev_number;
143 u8 endp_number;
144 u8 usb_addr;
145 u8 usb_endp;
146 struct u132 *u132;
147 struct list_head endp_ring;
148 struct u132_ring *ring;
149 unsigned toggle_bits:2;
150 unsigned active:1;
151 unsigned delayed:1;
152 unsigned input:1;
153 unsigned output:1;
154 unsigned pipetype:2;
155 unsigned dequeueing:1;
156 unsigned edset_flush:1;
157 unsigned spare_bits:14;
158 unsigned long jiffies;
159 struct usb_host_endpoint *hep;
160 struct u132_spin queue_lock;
161 u16 queue_size;
162 u16 queue_last;
163 u16 queue_next;
164 struct urb *urb_list[ENDP_QUEUE_SIZE];
165 struct list_head urb_more;
David Howellsc4028952006-11-22 14:57:56 +0000166 struct delayed_work scheduler;
Tony Olechd774efe2006-09-13 11:27:35 +0100167};
168struct u132_ring {
169 unsigned in_use:1;
170 unsigned length:7;
171 u8 number;
172 struct u132 *u132;
173 struct u132_endp *curr_endp;
David Howellsc4028952006-11-22 14:57:56 +0000174 struct delayed_work scheduler;
Tony Olechd774efe2006-09-13 11:27:35 +0100175};
176#define OHCI_QUIRK_AMD756 0x01
177#define OHCI_QUIRK_SUPERIO 0x02
178#define OHCI_QUIRK_INITRESET 0x04
179#define OHCI_BIG_ENDIAN 0x08
180#define OHCI_QUIRK_ZFMICRO 0x10
181struct u132 {
182 struct kref kref;
183 struct list_head u132_list;
184 struct semaphore sw_lock;
185 struct semaphore scheduler_lock;
186 struct u132_platform_data *board;
187 struct platform_device *platform_dev;
188 struct u132_ring ring[MAX_U132_RINGS];
189 int sequence_num;
190 int going;
191 int power;
192 int reset;
193 int num_ports;
194 u32 hc_control;
195 u32 hc_fminterval;
196 u32 hc_roothub_status;
197 u32 hc_roothub_a;
198 u32 hc_roothub_portstatus[MAX_ROOT_PORTS];
199 int flags;
200 unsigned long next_statechange;
David Howellsc4028952006-11-22 14:57:56 +0000201 struct delayed_work monitor;
Tony Olechd774efe2006-09-13 11:27:35 +0100202 int num_endpoints;
203 struct u132_addr addr[MAX_U132_ADDRS];
204 struct u132_udev udev[MAX_U132_UDEVS];
205 struct u132_port port[MAX_U132_PORTS];
206 struct u132_endp *endp[MAX_U132_ENDPS];
207};
208int usb_ftdi_elan_read_reg(struct platform_device *pdev, u32 *data);
209int usb_ftdi_elan_read_pcimem(struct platform_device *pdev, u8 addressofs,
210 u8 width, u32 *data);
211int usb_ftdi_elan_write_pcimem(struct platform_device *pdev, u8 addressofs,
212 u8 width, u32 data);
213/*
214* these can not be inlines because we need the structure offset!!
215* Does anyone have a better way?????
216*/
217#define u132_read_pcimem(u132, member, data) \
218 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
219 ohci_regs, member), 0, data);
220#define u132_write_pcimem(u132, member, data) \
221 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
222 ohci_regs, member), 0, data);
223#define u132_write_pcimem_byte(u132, member, data) \
224 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
225 ohci_regs, member), 0x0e, data);
226static inline struct u132 *udev_to_u132(struct u132_udev *udev)
227{
228 u8 udev_number = udev->udev_number;
229 return container_of(udev, struct u132, udev[udev_number]);
230}
231
232static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd)
233{
234 return (struct u132 *)(hcd->hcd_priv);
235}
236
237static inline struct usb_hcd *u132_to_hcd(struct u132 *u132)
238{
239 return container_of((void *)u132, struct usb_hcd, hcd_priv);
240}
241
242static inline void u132_disable(struct u132 *u132)
243{
244 u132_to_hcd(u132)->state = HC_STATE_HALT;
245}
246
247
248#define kref_to_u132(d) container_of(d, struct u132, kref)
249#define kref_to_u132_endp(d) container_of(d, struct u132_endp, kref)
250#define kref_to_u132_udev(d) container_of(d, struct u132_udev, kref)
251#include "../misc/usb_u132.h"
252static const char hcd_name[] = "u132_hcd";
253#define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
254 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
255 USB_PORT_STAT_C_RESET) << 16)
256static void u132_hcd_delete(struct kref *kref)
257{
258 struct u132 *u132 = kref_to_u132(kref);
259 struct platform_device *pdev = u132->platform_dev;
260 struct usb_hcd *hcd = u132_to_hcd(u132);
261 u132->going += 1;
262 down(&u132_module_lock);
263 list_del_init(&u132->u132_list);
264 u132_instances -= 1;
265 up(&u132_module_lock);
266 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
267 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
268 usb_put_hcd(hcd);
269}
270
271static inline void u132_u132_put_kref(struct u132 *u132)
272{
273 kref_put(&u132->kref, u132_hcd_delete);
274}
275
276static inline void u132_u132_init_kref(struct u132 *u132)
277{
278 kref_init(&u132->kref);
279}
280
281static void u132_udev_delete(struct kref *kref)
282{
283 struct u132_udev *udev = kref_to_u132_udev(kref);
284 udev->udev_number = 0;
285 udev->usb_device = NULL;
286 udev->usb_addr = 0;
287 udev->enumeration = 0;
288}
289
290static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev)
291{
292 kref_put(&udev->kref, u132_udev_delete);
293}
294
295static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev)
296{
297 kref_get(&udev->kref);
298}
299
300static inline void u132_udev_init_kref(struct u132 *u132,
301 struct u132_udev *udev)
302{
303 kref_init(&udev->kref);
304}
305
306static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring)
307{
308 kref_put(&u132->kref, u132_hcd_delete);
309}
310
311static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring,
312 unsigned int delta)
313{
314 if (delta > 0) {
315 if (queue_delayed_work(workqueue, &ring->scheduler, delta))
316 return;
David Howellsc4028952006-11-22 14:57:56 +0000317 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0))
Tony Olechd774efe2006-09-13 11:27:35 +0100318 return;
319 kref_put(&u132->kref, u132_hcd_delete);
320 return;
321}
322
323static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
324 unsigned int delta)
325{
326 kref_get(&u132->kref);
327 u132_ring_requeue_work(u132, ring, delta);
328 return;
329}
330
331static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
332{
333 if (cancel_delayed_work(&ring->scheduler)) {
334 kref_put(&u132->kref, u132_hcd_delete);
335 }
336}
337
338static void u132_endp_delete(struct kref *kref)
339{
340 struct u132_endp *endp = kref_to_u132_endp(kref);
341 struct u132 *u132 = endp->u132;
342 u8 usb_addr = endp->usb_addr;
343 u8 usb_endp = endp->usb_endp;
344 u8 address = u132->addr[usb_addr].address;
345 struct u132_udev *udev = &u132->udev[address];
346 u8 endp_number = endp->endp_number;
347 struct usb_host_endpoint *hep = endp->hep;
348 struct u132_ring *ring = endp->ring;
349 struct list_head *head = &endp->endp_ring;
350 ring->length -= 1;
351 if (endp == ring->curr_endp) {
352 if (list_empty(head)) {
353 ring->curr_endp = NULL;
354 list_del(head);
355 } else {
356 struct u132_endp *next_endp = list_entry(head->next,
357 struct u132_endp, endp_ring);
358 ring->curr_endp = next_endp;
359 list_del(head);
360 }} else
361 list_del(head);
362 if (endp->input) {
363 udev->endp_number_in[usb_endp] = 0;
364 u132_udev_put_kref(u132, udev);
365 }
366 if (endp->output) {
367 udev->endp_number_out[usb_endp] = 0;
368 u132_udev_put_kref(u132, udev);
369 }
370 u132->endp[endp_number - 1] = NULL;
371 hep->hcpriv = NULL;
372 kfree(endp);
373 u132_u132_put_kref(u132);
374}
375
376static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp)
377{
378 kref_put(&endp->kref, u132_endp_delete);
379}
380
381static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp)
382{
383 kref_get(&endp->kref);
384}
385
386static inline void u132_endp_init_kref(struct u132 *u132,
387 struct u132_endp *endp)
388{
389 kref_init(&endp->kref);
390 kref_get(&u132->kref);
391}
392
393static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
394 unsigned int delta)
395{
David Howellsc4028952006-11-22 14:57:56 +0000396 if (queue_delayed_work(workqueue, &endp->scheduler, delta))
397 kref_get(&endp->kref);
Tony Olechd774efe2006-09-13 11:27:35 +0100398}
399
400static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp)
401{
402 if (cancel_delayed_work(&endp->scheduler))
403 kref_put(&endp->kref, u132_endp_delete);
404}
405
406static inline void u132_monitor_put_kref(struct u132 *u132)
407{
408 kref_put(&u132->kref, u132_hcd_delete);
409}
410
411static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta)
412{
David Howellsc4028952006-11-22 14:57:56 +0000413 if (queue_delayed_work(workqueue, &u132->monitor, delta))
414 kref_get(&u132->kref);
Tony Olechd774efe2006-09-13 11:27:35 +0100415}
416
417static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta)
418{
David Howellsc4028952006-11-22 14:57:56 +0000419 if (!queue_delayed_work(workqueue, &u132->monitor, delta))
420 kref_put(&u132->kref, u132_hcd_delete);
Tony Olechd774efe2006-09-13 11:27:35 +0100421}
422
423static void u132_monitor_cancel_work(struct u132 *u132)
424{
425 if (cancel_delayed_work(&u132->monitor))
426 kref_put(&u132->kref, u132_hcd_delete);
427}
428
429static int read_roothub_info(struct u132 *u132)
430{
431 u32 revision;
432 int retval;
433 retval = u132_read_pcimem(u132, revision, &revision);
434 if (retval) {
435 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
436 "ntrol\n", retval);
437 return retval;
438 } else if ((revision & 0xFF) == 0x10) {
439 } else if ((revision & 0xFF) == 0x11) {
440 } else {
441 dev_err(&u132->platform_dev->dev, "device revision is not valid"
442 " %08X\n", revision);
443 return -ENODEV;
444 }
445 retval = u132_read_pcimem(u132, control, &u132->hc_control);
446 if (retval) {
447 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
448 "ntrol\n", retval);
449 return retval;
450 }
451 retval = u132_read_pcimem(u132, roothub.status,
452 &u132->hc_roothub_status);
453 if (retval) {
454 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
455 "g roothub.status\n", retval);
456 return retval;
457 }
458 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a);
459 if (retval) {
460 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
461 "g roothub.a\n", retval);
462 return retval;
463 }
464 {
465 int I = u132->num_ports;
466 int i = 0;
467 while (I-- > 0) {
468 retval = u132_read_pcimem(u132, roothub.portstatus[i],
469 &u132->hc_roothub_portstatus[i]);
470 if (retval) {
471 dev_err(&u132->platform_dev->dev, "error %d acc"
472 "essing device roothub.portstatus[%d]\n"
473 , retval, i);
474 return retval;
475 } else
476 i += 1;
477 }
478 }
479 return 0;
480}
481
David Howellsc4028952006-11-22 14:57:56 +0000482static void u132_hcd_monitor_work(struct work_struct *work)
Tony Olechd774efe2006-09-13 11:27:35 +0100483{
David Howellsc4028952006-11-22 14:57:56 +0000484 struct u132 *u132 = container_of(work, struct u132, monitor.work);
Tony Olechd774efe2006-09-13 11:27:35 +0100485 if (u132->going > 1) {
486 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
487 , u132->going);
488 u132_monitor_put_kref(u132);
489 return;
490 } else if (u132->going > 0) {
491 dev_err(&u132->platform_dev->dev, "device is being removed\n");
492 u132_monitor_put_kref(u132);
493 return;
494 } else {
495 int retval;
496 down(&u132->sw_lock);
497 retval = read_roothub_info(u132);
498 if (retval) {
499 struct usb_hcd *hcd = u132_to_hcd(u132);
500 u132_disable(u132);
501 u132->going = 1;
502 up(&u132->sw_lock);
503 usb_hc_died(hcd);
504 ftdi_elan_gone_away(u132->platform_dev);
505 u132_monitor_put_kref(u132);
506 return;
507 } else {
508 u132_monitor_requeue_work(u132, 500);
509 up(&u132->sw_lock);
510 return;
511 }
512 }
513}
514
515static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
516 struct urb *urb, int status)
517{
518 struct u132_ring *ring;
519 unsigned long irqs;
520 struct usb_hcd *hcd = u132_to_hcd(u132);
521 urb->error_count = 0;
522 urb->status = status;
523 urb->hcpriv = NULL;
524 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
525 endp->queue_next += 1;
526 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
527 endp->active = 0;
528 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
529 } else {
530 struct list_head *next = endp->urb_more.next;
531 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
532 urb_more);
533 list_del(next);
534 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
535 urbq->urb;
536 endp->active = 0;
537 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
538 kfree(urbq);
539 } down(&u132->scheduler_lock);
540 ring = endp->ring;
541 ring->in_use = 0;
542 u132_ring_cancel_work(u132, ring);
543 u132_ring_queue_work(u132, ring, 0);
544 up(&u132->scheduler_lock);
545 u132_endp_put_kref(u132, endp);
David Howells7d12e782006-10-05 14:55:46 +0100546 usb_hcd_giveback_urb(hcd, urb);
Tony Olechd774efe2006-09-13 11:27:35 +0100547 return;
548}
549
550static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp,
551 struct urb *urb, int status)
552{
553 u132_endp_put_kref(u132, endp);
554}
555
556static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
557 struct urb *urb, int status)
558{
559 unsigned long irqs;
560 struct usb_hcd *hcd = u132_to_hcd(u132);
561 urb->error_count = 0;
562 urb->status = status;
563 urb->hcpriv = NULL;
564 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
565 endp->queue_next += 1;
566 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
567 endp->active = 0;
568 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
569 } else {
570 struct list_head *next = endp->urb_more.next;
571 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
572 urb_more);
573 list_del(next);
574 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
575 urbq->urb;
576 endp->active = 0;
577 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
578 kfree(urbq);
David Howells7d12e782006-10-05 14:55:46 +0100579 } usb_hcd_giveback_urb(hcd, urb);
Tony Olechd774efe2006-09-13 11:27:35 +0100580 return;
581}
582
583static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
584 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
585 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
586 int toggle_bits, int error_count, int condition_code, int repeat_number,
587 int halted, int skipped, int actual, int non_null))
588{
589 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
590 urb, address, endp->usb_endp, toggle_bits, callback);
591}
592
593static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
594 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
595 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
596 int toggle_bits, int error_count, int condition_code, int repeat_number,
597 int halted, int skipped, int actual, int non_null))
598{
599 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
600 urb, address, endp->usb_endp, toggle_bits, callback);
601}
602
603static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
604 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
605 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
606 int toggle_bits, int error_count, int condition_code, int repeat_number,
607 int halted, int skipped, int actual, int non_null))
608{
609 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
610 endp, urb, address, endp->usb_endp, toggle_bits, callback);
611}
612
613static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
614 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
615 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
616 int toggle_bits, int error_count, int condition_code, int repeat_number,
617 int halted, int skipped, int actual, int non_null))
618{
619 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
620 endp, urb, address, endp->usb_endp, toggle_bits, callback);
621}
622
623
624/*
625* must not LOCK sw_lock
626*
627*/
628static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
629 int len, int toggle_bits, int error_count, int condition_code,
630 int repeat_number, int halted, int skipped, int actual, int non_null)
631{
632 struct u132_endp *endp = data;
633 struct u132 *u132 = endp->u132;
634 u8 address = u132->addr[endp->usb_addr].address;
635 struct u132_udev *udev = &u132->udev[address];
636 down(&u132->scheduler_lock);
637 if (u132->going > 1) {
638 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
639 , u132->going);
640 up(&u132->scheduler_lock);
641 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
642 return;
643 } else if (endp->dequeueing) {
644 endp->dequeueing = 0;
645 up(&u132->scheduler_lock);
646 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
647 return;
648 } else if (u132->going > 0) {
649 dev_err(&u132->platform_dev->dev, "device is being removed urb="
650 "%p status=%d\n", urb, urb->status);
651 up(&u132->scheduler_lock);
652 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
653 return;
654 } else if (urb->status == -EINPROGRESS) {
655 struct u132_ring *ring = endp->ring;
656 u8 *u = urb->transfer_buffer + urb->actual_length;
657 u8 *b = buf;
658 int L = len;
659 while (L-- > 0) {
660 *u++ = *b++;
661 }
662 urb->actual_length += len;
663 if ((condition_code == TD_CC_NOERROR) &&
664 (urb->transfer_buffer_length > urb->actual_length)) {
665 endp->toggle_bits = toggle_bits;
666 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
667 1 & toggle_bits);
668 if (urb->actual_length > 0) {
669 int retval;
670 up(&u132->scheduler_lock);
671 retval = edset_single(u132, ring, endp, urb,
672 address, endp->toggle_bits,
673 u132_hcd_interrupt_recv);
674 if (retval == 0) {
675 } else
676 u132_hcd_giveback_urb(u132, endp, urb,
677 retval);
678 } else {
679 ring->in_use = 0;
680 endp->active = 0;
681 endp->jiffies = jiffies +
682 msecs_to_jiffies(urb->interval);
683 u132_ring_cancel_work(u132, ring);
684 u132_ring_queue_work(u132, ring, 0);
685 up(&u132->scheduler_lock);
686 u132_endp_put_kref(u132, endp);
687 }
688 return;
689 } else if ((condition_code == TD_DATAUNDERRUN) &&
690 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
691 endp->toggle_bits = toggle_bits;
692 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
693 1 & toggle_bits);
694 up(&u132->scheduler_lock);
695 u132_hcd_giveback_urb(u132, endp, urb, 0);
696 return;
697 } else {
698 if (condition_code == TD_CC_NOERROR) {
699 endp->toggle_bits = toggle_bits;
700 usb_settoggle(udev->usb_device, endp->usb_endp,
701 0, 1 & toggle_bits);
702 } else if (condition_code == TD_CC_STALL) {
703 endp->toggle_bits = 0x2;
704 usb_settoggle(udev->usb_device, endp->usb_endp,
705 0, 0);
706 } else {
707 endp->toggle_bits = 0x2;
708 usb_settoggle(udev->usb_device, endp->usb_endp,
709 0, 0);
710 dev_err(&u132->platform_dev->dev, "urb=%p givin"
711 "g back INTERRUPT %s\n", urb,
712 cc_to_text[condition_code]);
713 }
714 up(&u132->scheduler_lock);
715 u132_hcd_giveback_urb(u132, endp, urb,
716 cc_to_error[condition_code]);
717 return;
718 }
719 } else {
720 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
721 "s=%d\n", urb, urb->status);
722 up(&u132->scheduler_lock);
723 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
724 return;
725 }
726}
727
728static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
729 int len, int toggle_bits, int error_count, int condition_code,
730 int repeat_number, int halted, int skipped, int actual, int non_null)
731{
732 struct u132_endp *endp = data;
733 struct u132 *u132 = endp->u132;
734 u8 address = u132->addr[endp->usb_addr].address;
735 down(&u132->scheduler_lock);
736 if (u132->going > 1) {
737 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
738 , u132->going);
739 up(&u132->scheduler_lock);
740 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
741 return;
742 } else if (endp->dequeueing) {
743 endp->dequeueing = 0;
744 up(&u132->scheduler_lock);
745 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
746 return;
747 } else if (u132->going > 0) {
748 dev_err(&u132->platform_dev->dev, "device is being removed urb="
749 "%p status=%d\n", urb, urb->status);
750 up(&u132->scheduler_lock);
751 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
752 return;
753 } else if (urb->status == -EINPROGRESS) {
754 struct u132_ring *ring = endp->ring;
755 urb->actual_length += len;
756 endp->toggle_bits = toggle_bits;
757 if (urb->transfer_buffer_length > urb->actual_length) {
758 int retval;
759 up(&u132->scheduler_lock);
760 retval = edset_output(u132, ring, endp, urb, address,
761 endp->toggle_bits, u132_hcd_bulk_output_sent);
762 if (retval == 0) {
763 } else
764 u132_hcd_giveback_urb(u132, endp, urb, retval);
765 return;
766 } else {
767 up(&u132->scheduler_lock);
768 u132_hcd_giveback_urb(u132, endp, urb, 0);
769 return;
770 }
771 } else {
772 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
773 "s=%d\n", urb, urb->status);
774 up(&u132->scheduler_lock);
775 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
776 return;
777 }
778}
779
780static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
781 int len, int toggle_bits, int error_count, int condition_code,
782 int repeat_number, int halted, int skipped, int actual, int non_null)
783{
784 struct u132_endp *endp = data;
785 struct u132 *u132 = endp->u132;
786 u8 address = u132->addr[endp->usb_addr].address;
787 struct u132_udev *udev = &u132->udev[address];
788 down(&u132->scheduler_lock);
789 if (u132->going > 1) {
790 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
791 , u132->going);
792 up(&u132->scheduler_lock);
793 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
794 return;
795 } else if (endp->dequeueing) {
796 endp->dequeueing = 0;
797 up(&u132->scheduler_lock);
798 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
799 return;
800 } else if (u132->going > 0) {
801 dev_err(&u132->platform_dev->dev, "device is being removed urb="
802 "%p status=%d\n", urb, urb->status);
803 up(&u132->scheduler_lock);
804 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
805 return;
806 } else if (urb->status == -EINPROGRESS) {
807 struct u132_ring *ring = endp->ring;
808 u8 *u = urb->transfer_buffer + urb->actual_length;
809 u8 *b = buf;
810 int L = len;
811 while (L-- > 0) {
812 *u++ = *b++;
813 }
814 urb->actual_length += len;
815 if ((condition_code == TD_CC_NOERROR) &&
816 (urb->transfer_buffer_length > urb->actual_length)) {
817 int retval;
818 endp->toggle_bits = toggle_bits;
819 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
820 1 & toggle_bits);
821 up(&u132->scheduler_lock);
822 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
823 ring->number, endp, urb, address,
824 endp->usb_endp, endp->toggle_bits,
825 u132_hcd_bulk_input_recv);
826 if (retval == 0) {
827 } else
828 u132_hcd_giveback_urb(u132, endp, urb, retval);
829 return;
830 } else if (condition_code == TD_CC_NOERROR) {
831 endp->toggle_bits = toggle_bits;
832 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
833 1 & toggle_bits);
834 up(&u132->scheduler_lock);
835 u132_hcd_giveback_urb(u132, endp, urb,
836 cc_to_error[condition_code]);
837 return;
838 } else if ((condition_code == TD_DATAUNDERRUN) &&
839 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
840 endp->toggle_bits = toggle_bits;
841 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
842 1 & toggle_bits);
843 up(&u132->scheduler_lock);
844 u132_hcd_giveback_urb(u132, endp, urb, 0);
845 return;
846 } else if (condition_code == TD_DATAUNDERRUN) {
847 endp->toggle_bits = toggle_bits;
848 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
849 1 & toggle_bits);
850 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
851 ") giving back BULK IN %s\n", urb,
852 cc_to_text[condition_code]);
853 up(&u132->scheduler_lock);
854 u132_hcd_giveback_urb(u132, endp, urb, 0);
855 return;
856 } else if (condition_code == TD_CC_STALL) {
857 endp->toggle_bits = 0x2;
858 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
859 up(&u132->scheduler_lock);
860 u132_hcd_giveback_urb(u132, endp, urb,
861 cc_to_error[condition_code]);
862 return;
863 } else {
864 endp->toggle_bits = 0x2;
865 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
866 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
867 "ULK IN code=%d %s\n", urb, condition_code,
868 cc_to_text[condition_code]);
869 up(&u132->scheduler_lock);
870 u132_hcd_giveback_urb(u132, endp, urb,
871 cc_to_error[condition_code]);
872 return;
873 }
874 } else {
875 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
876 "s=%d\n", urb, urb->status);
877 up(&u132->scheduler_lock);
878 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
879 return;
880 }
881}
882
883static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
884 int len, int toggle_bits, int error_count, int condition_code,
885 int repeat_number, int halted, int skipped, int actual, int non_null)
886{
887 struct u132_endp *endp = data;
888 struct u132 *u132 = endp->u132;
889 down(&u132->scheduler_lock);
890 if (u132->going > 1) {
891 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
892 , u132->going);
893 up(&u132->scheduler_lock);
894 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
895 return;
896 } else if (endp->dequeueing) {
897 endp->dequeueing = 0;
898 up(&u132->scheduler_lock);
899 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
900 return;
901 } else if (u132->going > 0) {
902 dev_err(&u132->platform_dev->dev, "device is being removed urb="
903 "%p status=%d\n", urb, urb->status);
904 up(&u132->scheduler_lock);
905 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
906 return;
907 } else if (urb->status == -EINPROGRESS) {
908 up(&u132->scheduler_lock);
909 u132_hcd_giveback_urb(u132, endp, urb, 0);
910 return;
911 } else {
912 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
913 "s=%d\n", urb, urb->status);
914 up(&u132->scheduler_lock);
915 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
916 return;
917 }
918}
919
920static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
921 int len, int toggle_bits, int error_count, int condition_code,
922 int repeat_number, int halted, int skipped, int actual, int non_null)
923{
924 struct u132_endp *endp = data;
925 struct u132 *u132 = endp->u132;
926 u8 address = u132->addr[endp->usb_addr].address;
927 down(&u132->scheduler_lock);
928 if (u132->going > 1) {
929 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
930 , u132->going);
931 up(&u132->scheduler_lock);
932 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
933 return;
934 } else if (endp->dequeueing) {
935 endp->dequeueing = 0;
936 up(&u132->scheduler_lock);
937 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
938 return;
939 } else if (u132->going > 0) {
940 dev_err(&u132->platform_dev->dev, "device is being removed urb="
941 "%p status=%d\n", urb, urb->status);
942 up(&u132->scheduler_lock);
943 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
944 return;
945 } else if (urb->status == -EINPROGRESS) {
946 struct u132_ring *ring = endp->ring;
947 u8 *u = urb->transfer_buffer;
948 u8 *b = buf;
949 int L = len;
950 while (L-- > 0) {
951 *u++ = *b++;
952 }
953 urb->actual_length = len;
954 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
955 TD_DATAUNDERRUN) && ((urb->transfer_flags &
956 URB_SHORT_NOT_OK) == 0))) {
957 int retval;
958 up(&u132->scheduler_lock);
959 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
960 ring->number, endp, urb, address,
961 endp->usb_endp, 0x3,
962 u132_hcd_configure_empty_sent);
963 if (retval == 0) {
964 } else
965 u132_hcd_giveback_urb(u132, endp, urb, retval);
966 return;
967 } else if (condition_code == TD_CC_STALL) {
968 up(&u132->scheduler_lock);
969 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
970 "NPUT STALL urb %p\n", urb);
971 u132_hcd_giveback_urb(u132, endp, urb,
972 cc_to_error[condition_code]);
973 return;
974 } else {
975 up(&u132->scheduler_lock);
976 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
977 "PUT %s urb %p\n", cc_to_text[condition_code],
978 urb);
979 u132_hcd_giveback_urb(u132, endp, urb,
980 cc_to_error[condition_code]);
981 return;
982 }
983 } else {
984 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
985 "s=%d\n", urb, urb->status);
986 up(&u132->scheduler_lock);
987 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
988 return;
989 }
990}
991
992static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
993 int len, int toggle_bits, int error_count, int condition_code,
994 int repeat_number, int halted, int skipped, int actual, int non_null)
995{
996 struct u132_endp *endp = data;
997 struct u132 *u132 = endp->u132;
998 down(&u132->scheduler_lock);
999 if (u132->going > 1) {
1000 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1001 , u132->going);
1002 up(&u132->scheduler_lock);
1003 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1004 return;
1005 } else if (endp->dequeueing) {
1006 endp->dequeueing = 0;
1007 up(&u132->scheduler_lock);
1008 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1009 return;
1010 } else if (u132->going > 0) {
1011 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1012 "%p status=%d\n", urb, urb->status);
1013 up(&u132->scheduler_lock);
1014 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1015 return;
1016 } else if (urb->status == -EINPROGRESS) {
1017 up(&u132->scheduler_lock);
1018 u132_hcd_giveback_urb(u132, endp, urb, 0);
1019 return;
1020 } else {
1021 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1022 "s=%d\n", urb, urb->status);
1023 up(&u132->scheduler_lock);
1024 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1025 return;
1026 }
1027}
1028
1029static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1030 int len, int toggle_bits, int error_count, int condition_code,
1031 int repeat_number, int halted, int skipped, int actual, int non_null)
1032{
1033 struct u132_endp *endp = data;
1034 struct u132 *u132 = endp->u132;
1035 u8 address = u132->addr[endp->usb_addr].address;
1036 down(&u132->scheduler_lock);
1037 if (u132->going > 1) {
1038 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1039 , u132->going);
1040 up(&u132->scheduler_lock);
1041 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1042 return;
1043 } else if (endp->dequeueing) {
1044 endp->dequeueing = 0;
1045 up(&u132->scheduler_lock);
1046 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1047 return;
1048 } else if (u132->going > 0) {
1049 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1050 "%p status=%d\n", urb, urb->status);
1051 up(&u132->scheduler_lock);
1052 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1053 return;
1054 } else if (urb->status == -EINPROGRESS) {
1055 if (usb_pipein(urb->pipe)) {
1056 int retval;
1057 struct u132_ring *ring = endp->ring;
1058 up(&u132->scheduler_lock);
1059 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1060 ring->number, endp, urb, address,
1061 endp->usb_endp, 0,
1062 u132_hcd_configure_input_recv);
1063 if (retval == 0) {
1064 } else
1065 u132_hcd_giveback_urb(u132, endp, urb, retval);
1066 return;
1067 } else {
1068 int retval;
1069 struct u132_ring *ring = endp->ring;
1070 up(&u132->scheduler_lock);
1071 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1072 ring->number, endp, urb, address,
1073 endp->usb_endp, 0,
1074 u132_hcd_configure_empty_recv);
1075 if (retval == 0) {
1076 } else
1077 u132_hcd_giveback_urb(u132, endp, urb, retval);
1078 return;
1079 }
1080 } else {
1081 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1082 "s=%d\n", urb, urb->status);
1083 up(&u132->scheduler_lock);
1084 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1085 return;
1086 }
1087}
1088
1089static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1090 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1091 int repeat_number, int halted, int skipped, int actual, int non_null)
1092{
1093 struct u132_endp *endp = data;
1094 struct u132 *u132 = endp->u132;
1095 u8 address = u132->addr[endp->usb_addr].address;
1096 struct u132_udev *udev = &u132->udev[address];
1097 down(&u132->scheduler_lock);
1098 if (u132->going > 1) {
1099 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1100 , u132->going);
1101 up(&u132->scheduler_lock);
1102 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1103 return;
1104 } else if (endp->dequeueing) {
1105 endp->dequeueing = 0;
1106 up(&u132->scheduler_lock);
1107 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1108 return;
1109 } else if (u132->going > 0) {
1110 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1111 "%p status=%d\n", urb, urb->status);
1112 up(&u132->scheduler_lock);
1113 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1114 return;
1115 } else if (urb->status == -EINPROGRESS) {
1116 u132->addr[0].address = 0;
1117 endp->usb_addr = udev->usb_addr;
1118 up(&u132->scheduler_lock);
1119 u132_hcd_giveback_urb(u132, endp, urb, 0);
1120 return;
1121 } else {
1122 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1123 "s=%d\n", urb, urb->status);
1124 up(&u132->scheduler_lock);
1125 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1126 return;
1127 }
1128}
1129
1130static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1131 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1132 int repeat_number, int halted, int skipped, int actual, int non_null)
1133{
1134 struct u132_endp *endp = data;
1135 struct u132 *u132 = endp->u132;
1136 down(&u132->scheduler_lock);
1137 if (u132->going > 1) {
1138 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1139 , u132->going);
1140 up(&u132->scheduler_lock);
1141 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1142 return;
1143 } else if (endp->dequeueing) {
1144 endp->dequeueing = 0;
1145 up(&u132->scheduler_lock);
1146 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1147 return;
1148 } else if (u132->going > 0) {
1149 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1150 "%p status=%d\n", urb, urb->status);
1151 up(&u132->scheduler_lock);
1152 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1153 return;
1154 } else if (urb->status == -EINPROGRESS) {
1155 int retval;
1156 struct u132_ring *ring = endp->ring;
1157 up(&u132->scheduler_lock);
1158 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1159 ring->number, endp, urb, 0, endp->usb_endp, 0,
1160 u132_hcd_enumeration_empty_recv);
1161 if (retval == 0) {
1162 } else
1163 u132_hcd_giveback_urb(u132, endp, urb, retval);
1164 return;
1165 } else {
1166 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1167 "s=%d\n", urb, urb->status);
1168 up(&u132->scheduler_lock);
1169 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1170 return;
1171 }
1172}
1173
1174static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1175 int len, int toggle_bits, int error_count, int condition_code,
1176 int repeat_number, int halted, int skipped, int actual, int non_null)
1177{
1178 struct u132_endp *endp = data;
1179 struct u132 *u132 = endp->u132;
1180 down(&u132->scheduler_lock);
1181 if (u132->going > 1) {
1182 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1183 , u132->going);
1184 up(&u132->scheduler_lock);
1185 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1186 return;
1187 } else if (endp->dequeueing) {
1188 endp->dequeueing = 0;
1189 up(&u132->scheduler_lock);
1190 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1191 return;
1192 } else if (u132->going > 0) {
1193 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1194 "%p status=%d\n", urb, urb->status);
1195 up(&u132->scheduler_lock);
1196 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1197 return;
1198 } else if (urb->status == -EINPROGRESS) {
1199 up(&u132->scheduler_lock);
1200 u132_hcd_giveback_urb(u132, endp, urb, 0);
1201 return;
1202 } else {
1203 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1204 "s=%d\n", urb, urb->status);
1205 up(&u132->scheduler_lock);
1206 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1207 return;
1208 }
1209}
1210
1211static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1212 int len, int toggle_bits, int error_count, int condition_code,
1213 int repeat_number, int halted, int skipped, int actual, int non_null)
1214{
1215 struct u132_endp *endp = data;
1216 struct u132 *u132 = endp->u132;
1217 u8 address = u132->addr[endp->usb_addr].address;
1218 down(&u132->scheduler_lock);
1219 if (u132->going > 1) {
1220 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1221 , u132->going);
1222 up(&u132->scheduler_lock);
1223 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1224 return;
1225 } else if (endp->dequeueing) {
1226 endp->dequeueing = 0;
1227 up(&u132->scheduler_lock);
1228 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1229 return;
1230 } else if (u132->going > 0) {
1231 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1232 "%p status=%d\n", urb, urb->status);
1233 up(&u132->scheduler_lock);
1234 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1235 return;
1236 } else if (urb->status == -EINPROGRESS) {
1237 int retval;
1238 struct u132_ring *ring = endp->ring;
1239 u8 *u = urb->transfer_buffer;
1240 u8 *b = buf;
1241 int L = len;
1242 while (L-- > 0) {
1243 *u++ = *b++;
1244 }
1245 urb->actual_length = len;
1246 up(&u132->scheduler_lock);
1247 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1248 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1249 u132_hcd_initial_empty_sent);
1250 if (retval == 0) {
1251 } else
1252 u132_hcd_giveback_urb(u132, endp, urb, retval);
1253 return;
1254 } else {
1255 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1256 "s=%d\n", urb, urb->status);
1257 up(&u132->scheduler_lock);
1258 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1259 return;
1260 }
1261}
1262
1263static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1264 int len, int toggle_bits, int error_count, int condition_code,
1265 int repeat_number, int halted, int skipped, int actual, int non_null)
1266{
1267 struct u132_endp *endp = data;
1268 struct u132 *u132 = endp->u132;
1269 u8 address = u132->addr[endp->usb_addr].address;
1270 down(&u132->scheduler_lock);
1271 if (u132->going > 1) {
1272 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1273 , u132->going);
1274 up(&u132->scheduler_lock);
1275 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1276 return;
1277 } else if (endp->dequeueing) {
1278 endp->dequeueing = 0;
1279 up(&u132->scheduler_lock);
1280 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1281 return;
1282 } else if (u132->going > 0) {
1283 dev_err(&u132->platform_dev->dev, "device is being removed urb="
1284 "%p status=%d\n", urb, urb->status);
1285 up(&u132->scheduler_lock);
1286 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1287 return;
1288 } else if (urb->status == -EINPROGRESS) {
1289 int retval;
1290 struct u132_ring *ring = endp->ring;
1291 up(&u132->scheduler_lock);
1292 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1293 ring->number, endp, urb, address, endp->usb_endp, 0,
1294 u132_hcd_initial_input_recv);
1295 if (retval == 0) {
1296 } else
1297 u132_hcd_giveback_urb(u132, endp, urb, retval);
1298 return;
1299 } else {
1300 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p statu"
1301 "s=%d\n", urb, urb->status);
1302 up(&u132->scheduler_lock);
1303 u132_hcd_giveback_urb(u132, endp, urb, urb->status);
1304 return;
1305 }
1306}
1307
Tony Olechd774efe2006-09-13 11:27:35 +01001308/*
1309* this work function is only executed from the work queue
1310*
1311*/
David Howellsc4028952006-11-22 14:57:56 +00001312static void u132_hcd_ring_work_scheduler(struct work_struct *work)
Tony Olechd774efe2006-09-13 11:27:35 +01001313{
David Howellsc4028952006-11-22 14:57:56 +00001314 struct u132_ring *ring =
1315 container_of(work, struct u132_ring, scheduler.work);
Tony Olechd774efe2006-09-13 11:27:35 +01001316 struct u132 *u132 = ring->u132;
1317 down(&u132->scheduler_lock);
1318 if (ring->in_use) {
1319 up(&u132->scheduler_lock);
1320 u132_ring_put_kref(u132, ring);
1321 return;
1322 } else if (ring->curr_endp) {
1323 struct u132_endp *last_endp = ring->curr_endp;
1324 struct list_head *scan;
1325 struct list_head *head = &last_endp->endp_ring;
1326 unsigned long wakeup = 0;
1327 list_for_each(scan, head) {
1328 struct u132_endp *endp = list_entry(scan,
1329 struct u132_endp, endp_ring);
1330 if (endp->queue_next == endp->queue_last) {
1331 } else if ((endp->delayed == 0)
1332 || time_after_eq(jiffies, endp->jiffies)) {
1333 ring->curr_endp = endp;
1334 u132_endp_cancel_work(u132, last_endp);
1335 u132_endp_queue_work(u132, last_endp, 0);
1336 up(&u132->scheduler_lock);
1337 u132_ring_put_kref(u132, ring);
1338 return;
1339 } else {
1340 unsigned long delta = endp->jiffies - jiffies;
1341 if (delta > wakeup)
1342 wakeup = delta;
1343 }
1344 }
1345 if (last_endp->queue_next == last_endp->queue_last) {
1346 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1347 last_endp->jiffies)) {
1348 u132_endp_cancel_work(u132, last_endp);
1349 u132_endp_queue_work(u132, last_endp, 0);
1350 up(&u132->scheduler_lock);
1351 u132_ring_put_kref(u132, ring);
1352 return;
1353 } else {
1354 unsigned long delta = last_endp->jiffies - jiffies;
1355 if (delta > wakeup)
1356 wakeup = delta;
1357 }
1358 if (wakeup > 0) {
1359 u132_ring_requeue_work(u132, ring, wakeup);
1360 up(&u132->scheduler_lock);
1361 return;
1362 } else {
1363 up(&u132->scheduler_lock);
1364 u132_ring_put_kref(u132, ring);
1365 return;
1366 }
1367 } else {
1368 up(&u132->scheduler_lock);
1369 u132_ring_put_kref(u132, ring);
1370 return;
1371 }
1372}
1373
David Howellsc4028952006-11-22 14:57:56 +00001374static void u132_hcd_endp_work_scheduler(struct work_struct *work)
Tony Olechd774efe2006-09-13 11:27:35 +01001375{
1376 struct u132_ring *ring;
David Howellsc4028952006-11-22 14:57:56 +00001377 struct u132_endp *endp =
1378 container_of(work, struct u132_endp, scheduler.work);
Tony Olechd774efe2006-09-13 11:27:35 +01001379 struct u132 *u132 = endp->u132;
1380 down(&u132->scheduler_lock);
1381 ring = endp->ring;
1382 if (endp->edset_flush) {
1383 endp->edset_flush = 0;
1384 if (endp->dequeueing)
1385 usb_ftdi_elan_edset_flush(u132->platform_dev,
1386 ring->number, endp);
1387 up(&u132->scheduler_lock);
1388 u132_endp_put_kref(u132, endp);
1389 return;
1390 } else if (endp->active) {
1391 up(&u132->scheduler_lock);
1392 u132_endp_put_kref(u132, endp);
1393 return;
1394 } else if (ring->in_use) {
1395 up(&u132->scheduler_lock);
1396 u132_endp_put_kref(u132, endp);
1397 return;
1398 } else if (endp->queue_next == endp->queue_last) {
1399 up(&u132->scheduler_lock);
1400 u132_endp_put_kref(u132, endp);
1401 return;
1402 } else if (endp->pipetype == PIPE_INTERRUPT) {
1403 u8 address = u132->addr[endp->usb_addr].address;
1404 if (ring->in_use) {
1405 up(&u132->scheduler_lock);
1406 u132_endp_put_kref(u132, endp);
1407 return;
1408 } else {
1409 int retval;
1410 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1411 endp->queue_next];
1412 endp->active = 1;
1413 ring->curr_endp = endp;
1414 ring->in_use = 1;
1415 up(&u132->scheduler_lock);
1416 retval = edset_single(u132, ring, endp, urb, address,
1417 endp->toggle_bits, u132_hcd_interrupt_recv);
1418 if (retval == 0) {
1419 } else
1420 u132_hcd_giveback_urb(u132, endp, urb, retval);
1421 return;
1422 }
1423 } else if (endp->pipetype == PIPE_CONTROL) {
1424 u8 address = u132->addr[endp->usb_addr].address;
1425 if (ring->in_use) {
1426 up(&u132->scheduler_lock);
1427 u132_endp_put_kref(u132, endp);
1428 return;
1429 } else if (address == 0) {
1430 int retval;
1431 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1432 endp->queue_next];
1433 endp->active = 1;
1434 ring->curr_endp = endp;
1435 ring->in_use = 1;
1436 up(&u132->scheduler_lock);
1437 retval = edset_setup(u132, ring, endp, urb, address,
1438 0x2, u132_hcd_initial_setup_sent);
1439 if (retval == 0) {
1440 } else
1441 u132_hcd_giveback_urb(u132, endp, urb, retval);
1442 return;
1443 } else if (endp->usb_addr == 0) {
1444 int retval;
1445 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1446 endp->queue_next];
1447 endp->active = 1;
1448 ring->curr_endp = endp;
1449 ring->in_use = 1;
1450 up(&u132->scheduler_lock);
1451 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1452 u132_hcd_enumeration_address_sent);
1453 if (retval == 0) {
1454 } else
1455 u132_hcd_giveback_urb(u132, endp, urb, retval);
1456 return;
1457 } else {
1458 int retval;
1459 u8 address = u132->addr[endp->usb_addr].address;
1460 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1461 endp->queue_next];
1462 endp->active = 1;
1463 ring->curr_endp = endp;
1464 ring->in_use = 1;
1465 up(&u132->scheduler_lock);
1466 retval = edset_setup(u132, ring, endp, urb, address,
1467 0x2, u132_hcd_configure_setup_sent);
1468 if (retval == 0) {
1469 } else
1470 u132_hcd_giveback_urb(u132, endp, urb, retval);
1471 return;
1472 }
1473 } else {
1474 if (endp->input) {
1475 u8 address = u132->addr[endp->usb_addr].address;
1476 if (ring->in_use) {
1477 up(&u132->scheduler_lock);
1478 u132_endp_put_kref(u132, endp);
1479 return;
1480 } else {
1481 int retval;
1482 struct urb *urb = endp->urb_list[
1483 ENDP_QUEUE_MASK & endp->queue_next];
1484 endp->active = 1;
1485 ring->curr_endp = endp;
1486 ring->in_use = 1;
1487 up(&u132->scheduler_lock);
1488 retval = edset_input(u132, ring, endp, urb,
1489 address, endp->toggle_bits,
1490 u132_hcd_bulk_input_recv);
1491 if (retval == 0) {
1492 } else
1493 u132_hcd_giveback_urb(u132, endp, urb,
1494 retval);
1495 return;
1496 }
1497 } else { /* output pipe */
1498 u8 address = u132->addr[endp->usb_addr].address;
1499 if (ring->in_use) {
1500 up(&u132->scheduler_lock);
1501 u132_endp_put_kref(u132, endp);
1502 return;
1503 } else {
1504 int retval;
1505 struct urb *urb = endp->urb_list[
1506 ENDP_QUEUE_MASK & endp->queue_next];
1507 endp->active = 1;
1508 ring->curr_endp = endp;
1509 ring->in_use = 1;
1510 up(&u132->scheduler_lock);
1511 retval = edset_output(u132, ring, endp, urb,
1512 address, endp->toggle_bits,
1513 u132_hcd_bulk_output_sent);
1514 if (retval == 0) {
1515 } else
1516 u132_hcd_giveback_urb(u132, endp, urb,
1517 retval);
1518 return;
1519 }
1520 }
1521 }
1522}
1523
1524static void port_power(struct u132 *u132, int pn, int is_on)
1525{
1526 u132->port[pn].power = is_on;
1527}
1528
1529static void u132_power(struct u132 *u132, int is_on)
1530{
1531 struct usb_hcd *hcd = u132_to_hcd(u132)
1532 ; /* hub is inactive unless the port is powered */
1533 if (is_on) {
1534 if (u132->power)
1535 return;
1536 u132->power = 1;
1537 hcd->self.controller->power.power_state = PMSG_ON;
1538 } else {
1539 u132->power = 0;
1540 hcd->state = HC_STATE_HALT;
1541 hcd->self.controller->power.power_state = PMSG_SUSPEND;
1542 }
1543}
1544
1545static int u132_periodic_reinit(struct u132 *u132)
1546{
1547 int retval;
1548 u32 fi = u132->hc_fminterval & 0x03fff;
1549 u32 fit;
1550 u32 fminterval;
1551 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1552 if (retval)
1553 return retval;
1554 fit = fminterval & FIT;
1555 retval = u132_write_pcimem(u132, fminterval,
1556 (fit ^ FIT) | u132->hc_fminterval);
1557 if (retval)
1558 return retval;
1559 retval = u132_write_pcimem(u132, periodicstart,
1560 ((9 *fi) / 10) & 0x3fff);
1561 if (retval)
1562 return retval;
1563 return 0;
1564}
1565
1566static char *hcfs2string(int state)
1567{
1568 switch (state) {
1569 case OHCI_USB_RESET:
1570 return "reset";
1571 case OHCI_USB_RESUME:
1572 return "resume";
1573 case OHCI_USB_OPER:
1574 return "operational";
1575 case OHCI_USB_SUSPEND:
1576 return "suspend";
1577 }
1578 return "?";
1579}
1580
1581static int u132_usb_reset(struct u132 *u132)
1582{
1583 int retval;
1584 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1585 if (retval)
1586 return retval;
1587 u132->hc_control &= OHCI_CTRL_RWC;
1588 retval = u132_write_pcimem(u132, control, u132->hc_control);
1589 if (retval)
1590 return retval;
1591 return 0;
1592}
1593
1594static int u132_init(struct u132 *u132)
1595{
1596 int retval;
1597 u32 control;
1598 u132_disable(u132);
1599 u132->next_statechange =
1600 jiffies; /* SMM owns the HC? not for long! */ {
1601 u32 control;
1602 retval = u132_read_pcimem(u132, control, &control);
1603 if (retval)
1604 return retval;
1605 if (control & OHCI_CTRL_IR) {
1606 u32 temp = 50;
1607 retval = u132_write_pcimem(u132, intrenable,
1608 OHCI_INTR_OC);
1609 if (retval)
1610 return retval;
1611 retval = u132_write_pcimem_byte(u132, cmdstatus,
1612 OHCI_OCR);
1613 if (retval)
1614 return retval;
1615 check:{
1616 retval = u132_read_pcimem(u132, control,
1617 &control);
1618 if (retval)
1619 return retval;
1620 }
1621 if (control & OHCI_CTRL_IR) {
1622 msleep(10);
1623 if (--temp == 0) {
1624 dev_err(&u132->platform_dev->dev, "USB "
1625 "HC takeover failed!(BIOS/SMM b"
1626 "ug) control=%08X\n", control);
1627 return -EBUSY;
1628 }
1629 goto check;
1630 }
1631 u132_usb_reset(u132);
1632 }
1633 }
1634 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1635 if (retval)
1636 return retval;
1637 retval = u132_read_pcimem(u132, control, &control);
1638 if (retval)
1639 return retval;
1640 if (u132->num_ports == 0) {
1641 u32 rh_a = -1;
1642 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1643 if (retval)
1644 return retval;
1645 u132->num_ports = rh_a & RH_A_NDP;
1646 retval = read_roothub_info(u132);
1647 if (retval)
1648 return retval;
1649 }
1650 if (u132->num_ports > MAX_U132_PORTS) {
1651 return -EINVAL;
1652 }
1653 return 0;
1654}
1655
1656
1657/* Start an OHCI controller, set the BUS operational
1658* resets USB and controller
1659* enable interrupts
1660*/
1661static int u132_run(struct u132 *u132)
1662{
1663 int retval;
1664 u32 control;
1665 u32 status;
1666 u32 fminterval;
1667 u32 periodicstart;
1668 u32 cmdstatus;
1669 u32 roothub_a;
1670 int mask = OHCI_INTR_INIT;
1671 int first = u132->hc_fminterval == 0;
1672 int sleep_time = 0;
1673 int reset_timeout = 30; /* ... allow extra time */
1674 u132_disable(u132);
1675 if (first) {
1676 u32 temp;
1677 retval = u132_read_pcimem(u132, fminterval, &temp);
1678 if (retval)
1679 return retval;
1680 u132->hc_fminterval = temp & 0x3fff;
1681 if (u132->hc_fminterval != FI) {
1682 }
1683 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1684 }
1685 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1686 if (retval)
1687 return retval;
1688 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1689 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1690 u132->hc_control);
1691 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1692 case OHCI_USB_OPER:
1693 sleep_time = 0;
1694 break;
1695 case OHCI_USB_SUSPEND:
1696 case OHCI_USB_RESUME:
1697 u132->hc_control &= OHCI_CTRL_RWC;
1698 u132->hc_control |= OHCI_USB_RESUME;
1699 sleep_time = 10;
1700 break;
1701 default:
1702 u132->hc_control &= OHCI_CTRL_RWC;
1703 u132->hc_control |= OHCI_USB_RESET;
1704 sleep_time = 50;
1705 break;
1706 }
1707 retval = u132_write_pcimem(u132, control, u132->hc_control);
1708 if (retval)
1709 return retval;
1710 retval = u132_read_pcimem(u132, control, &control);
1711 if (retval)
1712 return retval;
1713 msleep(sleep_time);
1714 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1715 if (retval)
1716 return retval;
1717 if (!(roothub_a & RH_A_NPS)) {
1718 int temp; /* power down each port */
1719 for (temp = 0; temp < u132->num_ports; temp++) {
1720 retval = u132_write_pcimem(u132,
1721 roothub.portstatus[temp], RH_PS_LSDA);
1722 if (retval)
1723 return retval;
1724 }
1725 }
1726 retval = u132_read_pcimem(u132, control, &control);
1727 if (retval)
1728 return retval;
1729 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1730 if (retval)
1731 return retval;
1732 retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_HCR);
1733 if (retval)
1734 return retval;
1735 extra:{
1736 retval = u132_read_pcimem(u132, cmdstatus, &status);
1737 if (retval)
1738 return retval;
1739 if (0 != (status & OHCI_HCR)) {
1740 if (--reset_timeout == 0) {
1741 dev_err(&u132->platform_dev->dev, "USB HC reset"
1742 " timed out!\n");
1743 return -ENODEV;
1744 } else {
1745 msleep(5);
1746 goto extra;
1747 }
1748 }
1749 }
1750 if (u132->flags & OHCI_QUIRK_INITRESET) {
1751 retval = u132_write_pcimem(u132, control, u132->hc_control);
1752 if (retval)
1753 return retval;
1754 retval = u132_read_pcimem(u132, control, &control);
1755 if (retval)
1756 return retval;
1757 }
1758 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1759 if (retval)
1760 return retval;
1761 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1762 if (retval)
1763 return retval;
1764 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1765 if (retval)
1766 return retval;
1767 retval = u132_periodic_reinit(u132);
1768 if (retval)
1769 return retval;
1770 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1771 if (retval)
1772 return retval;
1773 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1774 if (retval)
1775 return retval;
1776 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1777 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1778 u132->flags |= OHCI_QUIRK_INITRESET;
1779 goto retry;
1780 } else
1781 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1782 "\n", fminterval, periodicstart);
1783 } /* start controller operations */
1784 u132->hc_control &= OHCI_CTRL_RWC;
1785 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1786 retval = u132_write_pcimem(u132, control, u132->hc_control);
1787 if (retval)
1788 return retval;
1789 retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_BLF);
1790 if (retval)
1791 return retval;
1792 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1793 if (retval)
1794 return retval;
1795 retval = u132_read_pcimem(u132, control, &control);
1796 if (retval)
1797 return retval;
1798 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1799 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1800 if (retval)
1801 return retval;
1802 retval = u132_write_pcimem(u132, intrstatus, mask);
1803 if (retval)
1804 return retval;
1805 retval = u132_write_pcimem(u132, intrdisable,
1806 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1807 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1808 OHCI_INTR_SO);
1809 if (retval)
1810 return retval; /* handle root hub init quirks ... */
1811 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1812 if (retval)
1813 return retval;
1814 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1815 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1816 roothub_a |= RH_A_NOCP;
1817 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1818 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1819 if (retval)
1820 return retval;
1821 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1822 roothub_a |= RH_A_NPS;
1823 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1824 if (retval)
1825 return retval;
1826 }
1827 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1828 if (retval)
1829 return retval;
1830 retval = u132_write_pcimem(u132, roothub.b,
1831 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1832 if (retval)
1833 return retval;
1834 retval = u132_read_pcimem(u132, control, &control);
1835 if (retval)
1836 return retval;
1837 mdelay((roothub_a >> 23) & 0x1fe);
1838 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1839 return 0;
1840}
1841
1842static void u132_hcd_stop(struct usb_hcd *hcd)
1843{
1844 struct u132 *u132 = hcd_to_u132(hcd);
1845 if (u132->going > 1) {
1846 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1847 , u132->going);
1848 } else if (u132->going > 0) {
1849 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1850 "ed\n", hcd);
1851 } else {
1852 down(&u132->sw_lock);
1853 msleep(100);
1854 u132_power(u132, 0);
1855 up(&u132->sw_lock);
1856 }
1857}
1858
1859static int u132_hcd_start(struct usb_hcd *hcd)
1860{
1861 struct u132 *u132 = hcd_to_u132(hcd);
1862 if (u132->going > 1) {
1863 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1864 , u132->going);
1865 return -ENODEV;
1866 } else if (u132->going > 0) {
1867 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1868 return -ESHUTDOWN;
1869 } else if (hcd->self.controller) {
1870 int retval;
1871 struct platform_device *pdev =
1872 to_platform_device(hcd->self.controller);
1873 u16 vendor = ((struct u132_platform_data *)
1874 (pdev->dev.platform_data))->vendor;
1875 u16 device = ((struct u132_platform_data *)
1876 (pdev->dev.platform_data))->device;
1877 down(&u132->sw_lock);
1878 msleep(10);
1879 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1880 u132->flags = OHCI_QUIRK_AMD756;
1881 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1882 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1883 "ounds unavailable\n");
1884 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1885 u132->flags |= OHCI_QUIRK_ZFMICRO;
1886 retval = u132_run(u132);
1887 if (retval) {
1888 u132_disable(u132);
1889 u132->going = 1;
1890 }
1891 msleep(100);
1892 up(&u132->sw_lock);
1893 return retval;
1894 } else {
1895 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1896 return -ENODEV;
1897 }
1898}
1899
1900static int u132_hcd_reset(struct usb_hcd *hcd)
1901{
1902 struct u132 *u132 = hcd_to_u132(hcd);
1903 if (u132->going > 1) {
1904 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1905 , u132->going);
1906 return -ENODEV;
1907 } else if (u132->going > 0) {
1908 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1909 return -ESHUTDOWN;
1910 } else {
1911 int retval;
1912 down(&u132->sw_lock);
1913 retval = u132_init(u132);
1914 if (retval) {
1915 u132_disable(u132);
1916 u132->going = 1;
1917 }
1918 up(&u132->sw_lock);
1919 return retval;
1920 }
1921}
1922
1923static int create_endpoint_and_queue_int(struct u132 *u132,
1924 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
1925 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1926 gfp_t mem_flags)
1927{
1928 struct u132_ring *ring;
1929 unsigned long irqs;
1930 u8 endp_number = ++u132->num_endpoints;
1931 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
1932 kmalloc(sizeof(struct u132_endp), mem_flags);
1933 if (!endp) {
1934 return -ENOMEM;
1935 }
David Howellsc4028952006-11-22 14:57:56 +00001936 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
Tony Olechd774efe2006-09-13 11:27:35 +01001937 spin_lock_init(&endp->queue_lock.slock);
1938 INIT_LIST_HEAD(&endp->urb_more);
1939 ring = endp->ring = &u132->ring[0];
1940 if (ring->curr_endp) {
1941 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1942 } else {
1943 INIT_LIST_HEAD(&endp->endp_ring);
1944 ring->curr_endp = endp;
1945 }
1946 ring->length += 1;
1947 endp->dequeueing = 0;
1948 endp->edset_flush = 0;
1949 endp->active = 0;
1950 endp->delayed = 0;
1951 endp->endp_number = endp_number;
1952 endp->u132 = u132;
1953 endp->hep = hep;
1954 endp->pipetype = usb_pipetype(urb->pipe);
1955 u132_endp_init_kref(u132, endp);
1956 if (usb_pipein(urb->pipe)) {
1957 endp->toggle_bits = 0x2;
1958 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1959 endp->input = 1;
1960 endp->output = 0;
1961 udev->endp_number_in[usb_endp] = endp_number;
1962 u132_udev_get_kref(u132, udev);
1963 } else {
1964 endp->toggle_bits = 0x2;
1965 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1966 endp->input = 0;
1967 endp->output = 1;
1968 udev->endp_number_out[usb_endp] = endp_number;
1969 u132_udev_get_kref(u132, udev);
1970 }
1971 urb->hcpriv = u132;
1972 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1973 endp->delayed = 1;
1974 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1975 endp->udev_number = address;
1976 endp->usb_addr = usb_addr;
1977 endp->usb_endp = usb_endp;
1978 endp->queue_size = 1;
1979 endp->queue_last = 0;
1980 endp->queue_next = 0;
1981 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1982 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1983 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1984 return 0;
1985}
1986
1987static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
1988 struct usb_host_endpoint *hep, struct urb *urb,
1989 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1990 u8 usb_endp, u8 address)
1991{
1992 urb->hcpriv = u132;
1993 endp->delayed = 1;
1994 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1995 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1996 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1997 } else {
1998 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1999 GFP_ATOMIC);
2000 if (urbq == NULL) {
2001 endp->queue_size -= 1;
2002 return -ENOMEM;
2003 } else {
2004 list_add_tail(&urbq->urb_more, &endp->urb_more);
2005 urbq->urb = urb;
2006 }
2007 }
2008 return 0;
2009}
2010
2011static int create_endpoint_and_queue_bulk(struct u132 *u132,
2012 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb,
2013 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
2014 gfp_t mem_flags)
2015{
2016 int ring_number;
2017 struct u132_ring *ring;
2018 unsigned long irqs;
2019 u8 endp_number = ++u132->num_endpoints;
2020 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
2021 kmalloc(sizeof(struct u132_endp), mem_flags);
2022 if (!endp) {
2023 return -ENOMEM;
2024 }
David Howellsc4028952006-11-22 14:57:56 +00002025 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
Tony Olechd774efe2006-09-13 11:27:35 +01002026 spin_lock_init(&endp->queue_lock.slock);
2027 INIT_LIST_HEAD(&endp->urb_more);
2028 endp->dequeueing = 0;
2029 endp->edset_flush = 0;
2030 endp->active = 0;
2031 endp->delayed = 0;
2032 endp->endp_number = endp_number;
2033 endp->u132 = u132;
2034 endp->hep = hep;
2035 endp->pipetype = usb_pipetype(urb->pipe);
2036 u132_endp_init_kref(u132, endp);
2037 if (usb_pipein(urb->pipe)) {
2038 endp->toggle_bits = 0x2;
2039 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
2040 ring_number = 3;
2041 endp->input = 1;
2042 endp->output = 0;
2043 udev->endp_number_in[usb_endp] = endp_number;
2044 u132_udev_get_kref(u132, udev);
2045 } else {
2046 endp->toggle_bits = 0x2;
2047 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2048 ring_number = 2;
2049 endp->input = 0;
2050 endp->output = 1;
2051 udev->endp_number_out[usb_endp] = endp_number;
2052 u132_udev_get_kref(u132, udev);
2053 }
2054 ring = endp->ring = &u132->ring[ring_number - 1];
2055 if (ring->curr_endp) {
2056 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2057 } else {
2058 INIT_LIST_HEAD(&endp->endp_ring);
2059 ring->curr_endp = endp;
2060 }
2061 ring->length += 1;
2062 urb->hcpriv = u132;
2063 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2064 endp->udev_number = address;
2065 endp->usb_addr = usb_addr;
2066 endp->usb_endp = usb_endp;
2067 endp->queue_size = 1;
2068 endp->queue_last = 0;
2069 endp->queue_next = 0;
2070 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2071 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2072 u132_endp_queue_work(u132, endp, 0);
2073 return 0;
2074}
2075
2076static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2077 struct usb_host_endpoint *hep, struct urb *urb,
2078 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2079 u8 usb_endp, u8 address)
2080{
2081 urb->hcpriv = u132;
2082 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2083 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2084 } else {
2085 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2086 GFP_ATOMIC);
2087 if (urbq == NULL) {
2088 endp->queue_size -= 1;
2089 return -ENOMEM;
2090 } else {
2091 list_add_tail(&urbq->urb_more, &endp->urb_more);
2092 urbq->urb = urb;
2093 }
2094 }
2095 return 0;
2096}
2097
2098static int create_endpoint_and_queue_control(struct u132 *u132,
2099 struct usb_host_endpoint *hep, struct urb *urb,
2100 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2101 gfp_t mem_flags)
2102{
2103 struct u132_ring *ring;
2104 u8 endp_number = ++u132->num_endpoints;
2105 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] =
2106 kmalloc(sizeof(struct u132_endp), mem_flags);
2107 if (!endp) {
2108 return -ENOMEM;
2109 }
David Howellsc4028952006-11-22 14:57:56 +00002110 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
Tony Olechd774efe2006-09-13 11:27:35 +01002111 spin_lock_init(&endp->queue_lock.slock);
2112 INIT_LIST_HEAD(&endp->urb_more);
2113 ring = endp->ring = &u132->ring[0];
2114 if (ring->curr_endp) {
2115 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2116 } else {
2117 INIT_LIST_HEAD(&endp->endp_ring);
2118 ring->curr_endp = endp;
2119 }
2120 ring->length += 1;
2121 endp->dequeueing = 0;
2122 endp->edset_flush = 0;
2123 endp->active = 0;
2124 endp->delayed = 0;
2125 endp->endp_number = endp_number;
2126 endp->u132 = u132;
2127 endp->hep = hep;
2128 u132_endp_init_kref(u132, endp);
2129 u132_endp_get_kref(u132, endp);
2130 if (usb_addr == 0) {
2131 unsigned long irqs;
2132 u8 address = u132->addr[usb_addr].address;
2133 struct u132_udev *udev = &u132->udev[address];
2134 endp->udev_number = address;
2135 endp->usb_addr = usb_addr;
2136 endp->usb_endp = usb_endp;
2137 endp->input = 1;
2138 endp->output = 1;
2139 endp->pipetype = usb_pipetype(urb->pipe);
2140 u132_udev_init_kref(u132, udev);
2141 u132_udev_get_kref(u132, udev);
2142 udev->endp_number_in[usb_endp] = endp_number;
2143 udev->endp_number_out[usb_endp] = endp_number;
2144 urb->hcpriv = u132;
2145 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2146 endp->queue_size = 1;
2147 endp->queue_last = 0;
2148 endp->queue_next = 0;
2149 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2150 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2151 u132_endp_queue_work(u132, endp, 0);
2152 return 0;
2153 } else { /*(usb_addr > 0) */
2154 unsigned long irqs;
2155 u8 address = u132->addr[usb_addr].address;
2156 struct u132_udev *udev = &u132->udev[address];
2157 endp->udev_number = address;
2158 endp->usb_addr = usb_addr;
2159 endp->usb_endp = usb_endp;
2160 endp->input = 1;
2161 endp->output = 1;
2162 endp->pipetype = usb_pipetype(urb->pipe);
2163 u132_udev_get_kref(u132, udev);
2164 udev->enumeration = 2;
2165 udev->endp_number_in[usb_endp] = endp_number;
2166 udev->endp_number_out[usb_endp] = endp_number;
2167 urb->hcpriv = u132;
2168 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2169 endp->queue_size = 1;
2170 endp->queue_last = 0;
2171 endp->queue_next = 0;
2172 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2173 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2174 u132_endp_queue_work(u132, endp, 0);
2175 return 0;
2176 }
2177}
2178
2179static int queue_control_on_old_endpoint(struct u132 *u132,
2180 struct usb_host_endpoint *hep, struct urb *urb,
2181 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2182 u8 usb_endp)
2183{
2184 if (usb_addr == 0) {
2185 if (usb_pipein(urb->pipe)) {
2186 urb->hcpriv = u132;
2187 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2188 endp->urb_list[ENDP_QUEUE_MASK &
2189 endp->queue_last++] = urb;
2190 } else {
2191 struct u132_urbq *urbq =
2192 kmalloc(sizeof(struct u132_urbq),
2193 GFP_ATOMIC);
2194 if (urbq == NULL) {
2195 endp->queue_size -= 1;
2196 return -ENOMEM;
2197 } else {
2198 list_add_tail(&urbq->urb_more,
2199 &endp->urb_more);
2200 urbq->urb = urb;
2201 }
2202 }
2203 return 0;
2204 } else { /* usb_pipeout(urb->pipe) */
2205 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2206 int I = MAX_U132_UDEVS;
2207 int i = 0;
2208 while (--I > 0) {
2209 struct u132_udev *udev = &u132->udev[++i];
2210 if (udev->usb_device) {
2211 continue;
2212 } else {
2213 udev->enumeration = 1;
2214 u132->addr[0].address = i;
2215 endp->udev_number = i;
2216 udev->udev_number = i;
2217 udev->usb_addr = usb_dev->devnum;
2218 u132_udev_init_kref(u132, udev);
2219 udev->endp_number_in[usb_endp] =
2220 endp->endp_number;
2221 u132_udev_get_kref(u132, udev);
2222 udev->endp_number_out[usb_endp] =
2223 endp->endp_number;
2224 udev->usb_device = usb_dev;
2225 ((u8 *) (urb->setup_packet))[2] =
2226 addr->address = i;
2227 u132_udev_get_kref(u132, udev);
2228 break;
2229 }
2230 }
2231 if (I == 0) {
2232 dev_err(&u132->platform_dev->dev, "run out of d"
2233 "evice space\n");
2234 return -EINVAL;
2235 }
2236 urb->hcpriv = u132;
2237 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2238 endp->urb_list[ENDP_QUEUE_MASK &
2239 endp->queue_last++] = urb;
2240 } else {
2241 struct u132_urbq *urbq =
2242 kmalloc(sizeof(struct u132_urbq),
2243 GFP_ATOMIC);
2244 if (urbq == NULL) {
2245 endp->queue_size -= 1;
2246 return -ENOMEM;
2247 } else {
2248 list_add_tail(&urbq->urb_more,
2249 &endp->urb_more);
2250 urbq->urb = urb;
2251 }
2252 }
2253 return 0;
2254 }
2255 } else { /*(usb_addr > 0) */
2256 u8 address = u132->addr[usb_addr].address;
2257 struct u132_udev *udev = &u132->udev[address];
2258 urb->hcpriv = u132;
2259 if (udev->enumeration == 2) {
2260 } else
2261 udev->enumeration = 2;
2262 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2263 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2264 urb;
2265 } else {
2266 struct u132_urbq *urbq =
2267 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2268 if (urbq == NULL) {
2269 endp->queue_size -= 1;
2270 return -ENOMEM;
2271 } else {
2272 list_add_tail(&urbq->urb_more, &endp->urb_more);
2273 urbq->urb = urb;
2274 }
2275 }
2276 return 0;
2277 }
2278}
2279
2280static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2281 struct urb *urb, gfp_t mem_flags)
2282{
2283 struct u132 *u132 = hcd_to_u132(hcd);
2284 if (irqs_disabled()) {
2285 if (__GFP_WAIT & mem_flags) {
2286 printk(KERN_ERR "invalid context for function that migh"
2287 "t sleep\n");
2288 return -EINVAL;
2289 }
2290 }
2291 if (u132->going > 1) {
2292 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2293 , u132->going);
2294 return -ENODEV;
2295 } else if (u132->going > 0) {
2296 dev_err(&u132->platform_dev->dev, "device is being removed urb="
2297 "%p status=%d\n", urb, urb->status);
2298 return -ESHUTDOWN;
2299 } else {
2300 u8 usb_addr = usb_pipedevice(urb->pipe);
2301 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2302 struct usb_device *usb_dev = urb->dev;
2303 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2304 u8 address = u132->addr[usb_addr].address;
2305 struct u132_udev *udev = &u132->udev[address];
2306 struct u132_endp *endp = hep->hcpriv;
2307 urb->actual_length = 0;
2308 if (endp) {
2309 unsigned long irqs;
2310 int retval;
2311 spin_lock_irqsave(&endp->queue_lock.slock,
2312 irqs);
2313 retval = queue_int_on_old_endpoint(u132, udev,
2314 hep, urb, usb_dev, endp, usb_addr,
2315 usb_endp, address);
2316 spin_unlock_irqrestore(&endp->queue_lock.slock,
2317 irqs);
2318 if (retval) {
2319 return retval;
2320 } else {
2321 u132_endp_queue_work(u132, endp,
2322 msecs_to_jiffies(urb->interval))
2323 ;
2324 return 0;
2325 }
2326 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2327 return -EINVAL;
2328 } else { /*(endp == NULL) */
2329 return create_endpoint_and_queue_int(u132, udev,
2330 hep, urb, usb_dev, usb_addr, usb_endp,
2331 address, mem_flags);
2332 }
2333 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2334 dev_err(&u132->platform_dev->dev, "the hardware does no"
2335 "t support PIPE_ISOCHRONOUS\n");
2336 return -EINVAL;
2337 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2338 u8 address = u132->addr[usb_addr].address;
2339 struct u132_udev *udev = &u132->udev[address];
2340 struct u132_endp *endp = hep->hcpriv;
2341 urb->actual_length = 0;
2342 if (endp) {
2343 unsigned long irqs;
2344 int retval;
2345 spin_lock_irqsave(&endp->queue_lock.slock,
2346 irqs);
2347 retval = queue_bulk_on_old_endpoint(u132, udev,
2348 hep, urb, usb_dev, endp, usb_addr,
2349 usb_endp, address);
2350 spin_unlock_irqrestore(&endp->queue_lock.slock,
2351 irqs);
2352 if (retval) {
2353 return retval;
2354 } else {
2355 u132_endp_queue_work(u132, endp, 0);
2356 return 0;
2357 }
2358 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2359 return -EINVAL;
2360 } else
2361 return create_endpoint_and_queue_bulk(u132,
2362 udev, hep, urb, usb_dev, usb_addr,
2363 usb_endp, address, mem_flags);
2364 } else {
2365 struct u132_endp *endp = hep->hcpriv;
2366 u16 urb_size = 8;
2367 u8 *b = urb->setup_packet;
2368 int i = 0;
2369 char data[30 *3 + 4];
2370 char *d = data;
2371 int m = (sizeof(data) - 1) / 3;
2372 int l = 0;
2373 data[0] = 0;
2374 while (urb_size-- > 0) {
2375 if (i > m) {
2376 } else if (i++ < m) {
2377 int w = sprintf(d, " %02X", *b++);
2378 d += w;
2379 l += w;
2380 } else
2381 d += sprintf(d, " ..");
2382 }
2383 if (endp) {
2384 unsigned long irqs;
2385 int retval;
2386 spin_lock_irqsave(&endp->queue_lock.slock,
2387 irqs);
2388 retval = queue_control_on_old_endpoint(u132,
2389 hep, urb, usb_dev, endp, usb_addr,
2390 usb_endp);
2391 spin_unlock_irqrestore(&endp->queue_lock.slock,
2392 irqs);
2393 if (retval) {
2394 return retval;
2395 } else {
2396 u132_endp_queue_work(u132, endp, 0);
2397 return 0;
2398 }
2399 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2400 return -EINVAL;
2401 } else
2402 return create_endpoint_and_queue_control(u132,
2403 hep, urb, usb_dev, usb_addr, usb_endp,
2404 mem_flags);
2405 }
2406 }
2407}
2408
2409static int dequeue_from_overflow_chain(struct u132 *u132,
2410 struct u132_endp *endp, struct urb *urb)
2411{
2412 struct list_head *scan;
2413 struct list_head *head = &endp->urb_more;
2414 list_for_each(scan, head) {
2415 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2416 urb_more);
2417 if (urbq->urb == urb) {
2418 struct usb_hcd *hcd = u132_to_hcd(u132);
2419 list_del(scan);
2420 endp->queue_size -= 1;
2421 urb->error_count = 0;
2422 urb->hcpriv = NULL;
David Howells7d12e782006-10-05 14:55:46 +01002423 usb_hcd_giveback_urb(hcd, urb);
Tony Olechd774efe2006-09-13 11:27:35 +01002424 return 0;
2425 } else
2426 continue;
2427 }
2428 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2429 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2430 "\n", urb, endp->endp_number, endp, endp->ring->number,
2431 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2432 endp->usb_endp, endp->usb_addr, endp->queue_size,
2433 endp->queue_next, endp->queue_last);
2434 return -EINVAL;
2435}
2436
2437static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2438 struct urb *urb)
2439{
2440 unsigned long irqs;
2441 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2442 if (endp->queue_size == 0) {
2443 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2444 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2445 endp->endp_number, endp, endp->ring->number,
2446 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2447 endp->usb_endp, endp->usb_addr);
2448 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2449 return -EINVAL;
2450 }
2451 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2452 if (endp->active) {
2453 endp->dequeueing = 1;
2454 endp->edset_flush = 1;
2455 u132_endp_queue_work(u132, endp, 0);
2456 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2457 urb->hcpriv = NULL;
2458 return 0;
2459 } else {
2460 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2461 u132_hcd_abandon_urb(u132, endp, urb, urb->status);
2462 return 0;
2463 }
2464 } else {
2465 u16 queue_list = 0;
2466 u16 queue_size = endp->queue_size;
2467 u16 queue_scan = endp->queue_next;
2468 struct urb **urb_slot = NULL;
2469 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2470 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2471 ++queue_scan]) {
2472 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2473 queue_scan];
2474 break;
2475 } else
2476 continue;
2477 }
2478 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2479 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2480 ++queue_scan];
2481 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2482 queue_scan];
2483 }
2484 if (urb_slot) {
2485 struct usb_hcd *hcd = u132_to_hcd(u132);
2486 endp->queue_size -= 1;
2487 if (list_empty(&endp->urb_more)) {
2488 spin_unlock_irqrestore(&endp->queue_lock.slock,
2489 irqs);
2490 } else {
2491 struct list_head *next = endp->urb_more.next;
2492 struct u132_urbq *urbq = list_entry(next,
2493 struct u132_urbq, urb_more);
2494 list_del(next);
2495 *urb_slot = urbq->urb;
2496 spin_unlock_irqrestore(&endp->queue_lock.slock,
2497 irqs);
2498 kfree(urbq);
2499 } urb->error_count = 0;
2500 urb->hcpriv = NULL;
David Howells7d12e782006-10-05 14:55:46 +01002501 usb_hcd_giveback_urb(hcd, urb);
Tony Olechd774efe2006-09-13 11:27:35 +01002502 return 0;
2503 } else if (list_empty(&endp->urb_more)) {
2504 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2505 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2506 "=%d size=%d next=%04X last=%04X\n", urb,
2507 endp->endp_number, endp, endp->ring->number,
2508 endp->input ? 'I' : ' ',
2509 endp->output ? 'O' : ' ', endp->usb_endp,
2510 endp->usb_addr, endp->queue_size,
2511 endp->queue_next, endp->queue_last);
2512 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2513 return -EINVAL;
2514 } else {
2515 int retval = dequeue_from_overflow_chain(u132, endp,
2516 urb);
2517 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2518 return retval;
2519 }
2520 }
2521}
2522
2523static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
2524{
2525 struct u132 *u132 = hcd_to_u132(hcd);
2526 if (u132->going > 2) {
2527 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2528 , u132->going);
2529 return -ENODEV;
2530 } else {
2531 u8 usb_addr = usb_pipedevice(urb->pipe);
2532 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2533 u8 address = u132->addr[usb_addr].address;
2534 struct u132_udev *udev = &u132->udev[address];
2535 if (usb_pipein(urb->pipe)) {
2536 u8 endp_number = udev->endp_number_in[usb_endp];
2537 struct u132_endp *endp = u132->endp[endp_number - 1];
2538 return u132_endp_urb_dequeue(u132, endp, urb);
2539 } else {
2540 u8 endp_number = udev->endp_number_out[usb_endp];
2541 struct u132_endp *endp = u132->endp[endp_number - 1];
2542 return u132_endp_urb_dequeue(u132, endp, urb);
2543 }
2544 }
2545}
2546
2547static void u132_endpoint_disable(struct usb_hcd *hcd,
2548 struct usb_host_endpoint *hep)
2549{
2550 struct u132 *u132 = hcd_to_u132(hcd);
2551 if (u132->going > 2) {
2552 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2553 , u132->going);
2554 } else {
2555 struct u132_endp *endp = hep->hcpriv;
2556 if (endp)
2557 u132_endp_put_kref(u132, endp);
2558 }
2559}
2560
2561static int u132_get_frame(struct usb_hcd *hcd)
2562{
2563 struct u132 *u132 = hcd_to_u132(hcd);
2564 if (u132->going > 1) {
2565 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2566 , u132->going);
2567 return -ENODEV;
2568 } else if (u132->going > 0) {
2569 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2570 return -ESHUTDOWN;
2571 } else {
2572 int frame = 0;
2573 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2574 msleep(100);
2575 return frame;
2576 }
2577}
2578
2579static int u132_roothub_descriptor(struct u132 *u132,
2580 struct usb_hub_descriptor *desc)
2581{
2582 int retval;
2583 u16 temp;
2584 u32 rh_a = -1;
2585 u32 rh_b = -1;
2586 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2587 if (retval)
2588 return retval;
2589 desc->bDescriptorType = 0x29;
2590 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2591 desc->bHubContrCurrent = 0;
2592 desc->bNbrPorts = u132->num_ports;
2593 temp = 1 + (u132->num_ports / 8);
2594 desc->bDescLength = 7 + 2 *temp;
2595 temp = 0;
2596 if (rh_a & RH_A_NPS)
2597 temp |= 0x0002;
2598 if (rh_a & RH_A_PSM)
2599 temp |= 0x0001;
2600 if (rh_a & RH_A_NOCP) {
2601 temp |= 0x0010;
2602 } else if (rh_a & RH_A_OCPM)
2603 temp |= 0x0008;
2604 desc->wHubCharacteristics = cpu_to_le16(temp);
2605 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2606 if (retval)
2607 return retval;
2608 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2609 desc->bitmap[0] = rh_b & RH_B_DR;
2610 if (u132->num_ports > 7) {
2611 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2612 desc->bitmap[2] = 0xff;
2613 } else
2614 desc->bitmap[1] = 0xff;
2615 return 0;
2616}
2617
2618static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2619{
2620 u32 rh_status = -1;
2621 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2622 *desc = cpu_to_le32(rh_status);
2623 return ret_status;
2624}
2625
2626static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2627{
2628 if (wIndex == 0 || wIndex > u132->num_ports) {
2629 return -EINVAL;
2630 } else {
2631 int port = wIndex - 1;
2632 u32 rh_portstatus = -1;
2633 int ret_portstatus = u132_read_pcimem(u132,
2634 roothub.portstatus[port], &rh_portstatus);
2635 *desc = cpu_to_le32(rh_portstatus);
2636 if (*(u16 *) (desc + 2)) {
2637 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2638 "ge = %08X\n", port, *desc);
2639 }
2640 return ret_portstatus;
2641 }
2642}
2643
2644
2645/* this timer value might be vendor-specific ... */
2646#define PORT_RESET_HW_MSEC 10
2647#define PORT_RESET_MSEC 10
2648/* wrap-aware logic morphed from <linux/jiffies.h> */
2649#define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2650static int u132_roothub_portreset(struct u132 *u132, int port_index)
2651{
2652 int retval;
2653 u32 fmnumber;
2654 u16 now;
2655 u16 reset_done;
2656 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2657 if (retval)
2658 return retval;
2659 now = fmnumber;
2660 reset_done = now + PORT_RESET_MSEC;
2661 do {
2662 u32 portstat;
2663 do {
2664 retval = u132_read_pcimem(u132,
2665 roothub.portstatus[port_index], &portstat);
2666 if (retval)
2667 return retval;
2668 if (RH_PS_PRS & portstat) {
2669 continue;
2670 } else
2671 break;
2672 } while (tick_before(now, reset_done));
2673 if (RH_PS_PRS & portstat)
2674 return -ENODEV;
2675 if (RH_PS_CCS & portstat) {
2676 if (RH_PS_PRSC & portstat) {
2677 retval = u132_write_pcimem(u132,
2678 roothub.portstatus[port_index],
2679 RH_PS_PRSC);
2680 if (retval)
2681 return retval;
2682 }
2683 } else
2684 break; /* start the next reset,
2685 sleep till it's probably done */
2686 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2687 RH_PS_PRS);
2688 if (retval)
2689 return retval;
2690 msleep(PORT_RESET_HW_MSEC);
2691 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2692 if (retval)
2693 return retval;
2694 now = fmnumber;
2695 } while (tick_before(now, reset_done));
2696 return 0;
2697}
2698
2699static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2700 u16 wIndex)
2701{
2702 if (wIndex == 0 || wIndex > u132->num_ports) {
2703 return -EINVAL;
2704 } else {
2705 int retval;
2706 int port_index = wIndex - 1;
2707 struct u132_port *port = &u132->port[port_index];
2708 port->Status &= ~(1 << wValue);
2709 switch (wValue) {
2710 case USB_PORT_FEAT_SUSPEND:
2711 retval = u132_write_pcimem(u132,
2712 roothub.portstatus[port_index], RH_PS_PSS);
2713 if (retval)
2714 return retval;
2715 return 0;
2716 case USB_PORT_FEAT_POWER:
2717 retval = u132_write_pcimem(u132,
2718 roothub.portstatus[port_index], RH_PS_PPS);
2719 if (retval)
2720 return retval;
2721 return 0;
2722 case USB_PORT_FEAT_RESET:
2723 retval = u132_roothub_portreset(u132, port_index);
2724 if (retval)
2725 return retval;
2726 return 0;
2727 default:
2728 return -EPIPE;
2729 }
2730 }
2731}
2732
2733static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2734 u16 wIndex)
2735{
2736 if (wIndex == 0 || wIndex > u132->num_ports) {
2737 return -EINVAL;
2738 } else {
2739 int port_index = wIndex - 1;
2740 u32 temp;
2741 int retval;
2742 struct u132_port *port = &u132->port[port_index];
2743 port->Status &= ~(1 << wValue);
2744 switch (wValue) {
2745 case USB_PORT_FEAT_ENABLE:
2746 temp = RH_PS_CCS;
2747 break;
2748 case USB_PORT_FEAT_C_ENABLE:
2749 temp = RH_PS_PESC;
2750 break;
2751 case USB_PORT_FEAT_SUSPEND:
2752 temp = RH_PS_POCI;
2753 if ((u132->hc_control & OHCI_CTRL_HCFS)
2754 != OHCI_USB_OPER) {
2755 dev_err(&u132->platform_dev->dev, "TODO resume_"
2756 "root_hub\n");
2757 }
2758 break;
2759 case USB_PORT_FEAT_C_SUSPEND:
2760 temp = RH_PS_PSSC;
2761 break;
2762 case USB_PORT_FEAT_POWER:
2763 temp = RH_PS_LSDA;
2764 break;
2765 case USB_PORT_FEAT_C_CONNECTION:
2766 temp = RH_PS_CSC;
2767 break;
2768 case USB_PORT_FEAT_C_OVER_CURRENT:
2769 temp = RH_PS_OCIC;
2770 break;
2771 case USB_PORT_FEAT_C_RESET:
2772 temp = RH_PS_PRSC;
2773 break;
2774 default:
2775 return -EPIPE;
2776 }
2777 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2778 temp);
2779 if (retval)
2780 return retval;
2781 return 0;
2782 }
2783}
2784
2785
2786/* the virtual root hub timer IRQ checks for hub status*/
2787static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2788{
2789 struct u132 *u132 = hcd_to_u132(hcd);
2790 if (u132->going > 1) {
2791 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2792 "ed %d\n", hcd, u132->going);
2793 return -ENODEV;
2794 } else if (u132->going > 0) {
2795 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2796 "ed\n", hcd);
2797 dump_stack();
2798 return -ESHUTDOWN;
2799 } else {
2800 int i, changed = 0, length = 1;
2801 if (u132->flags & OHCI_QUIRK_AMD756) {
2802 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2803 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2804 "ereads as NDP=%d\n",
2805 u132->hc_roothub_a & RH_A_NDP);
2806 goto done;
2807 }
2808 }
2809 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) {
2810 buf[0] = changed = 1;
2811 } else
2812 buf[0] = 0;
2813 if (u132->num_ports > 7) {
2814 buf[1] = 0;
2815 length++;
2816 }
2817 for (i = 0; i < u132->num_ports; i++) {
2818 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2819 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2820 RH_PS_PRSC)) {
2821 changed = 1;
2822 if (i < 7) {
2823 buf[0] |= 1 << (i + 1);
2824 } else
2825 buf[1] |= 1 << (i - 7);
2826 continue;
2827 }
2828 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) {
2829 continue;
2830 }
2831 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) {
2832 continue;
2833 }
2834 }
2835 done:return changed ? length : 0;
2836 }
2837}
2838
2839static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2840 u16 wIndex, char *buf, u16 wLength)
2841{
2842 struct u132 *u132 = hcd_to_u132(hcd);
2843 if (u132->going > 1) {
2844 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2845 , u132->going);
2846 return -ENODEV;
2847 } else if (u132->going > 0) {
2848 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2849 return -ESHUTDOWN;
2850 } else {
2851 int retval = 0;
2852 down(&u132->sw_lock);
2853 switch (typeReq) {
2854 case ClearHubFeature:
2855 switch (wValue) {
2856 case C_HUB_OVER_CURRENT:
2857 case C_HUB_LOCAL_POWER:
2858 break;
2859 default:
2860 goto stall;
2861 }
2862 break;
2863 case SetHubFeature:
2864 switch (wValue) {
2865 case C_HUB_OVER_CURRENT:
2866 case C_HUB_LOCAL_POWER:
2867 break;
2868 default:
2869 goto stall;
2870 }
2871 break;
2872 case ClearPortFeature:{
2873 retval = u132_roothub_clearportfeature(u132,
2874 wValue, wIndex);
2875 if (retval)
2876 goto error;
2877 break;
2878 }
2879 case GetHubDescriptor:{
2880 retval = u132_roothub_descriptor(u132,
2881 (struct usb_hub_descriptor *)buf);
2882 if (retval)
2883 goto error;
2884 break;
2885 }
2886 case GetHubStatus:{
2887 retval = u132_roothub_status(u132,
2888 (__le32 *) buf);
2889 if (retval)
2890 goto error;
2891 break;
2892 }
2893 case GetPortStatus:{
2894 retval = u132_roothub_portstatus(u132,
2895 (__le32 *) buf, wIndex);
2896 if (retval)
2897 goto error;
2898 break;
2899 }
2900 case SetPortFeature:{
2901 retval = u132_roothub_setportfeature(u132,
2902 wValue, wIndex);
2903 if (retval)
2904 goto error;
2905 break;
2906 }
2907 default:
2908 goto stall;
2909 error:u132_disable(u132);
2910 u132->going = 1;
2911 break;
2912 stall:retval = -EPIPE;
2913 break;
2914 }
2915 up(&u132->sw_lock);
2916 return retval;
2917 }
2918}
2919
2920static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2921{
2922 struct u132 *u132 = hcd_to_u132(hcd);
2923 if (u132->going > 1) {
2924 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2925 , u132->going);
2926 return -ENODEV;
2927 } else if (u132->going > 0) {
2928 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2929 return -ESHUTDOWN;
2930 } else
2931 return 0;
2932}
2933
2934static void u132_hub_irq_enable(struct usb_hcd *hcd)
2935{
2936 struct u132 *u132 = hcd_to_u132(hcd);
2937 if (u132->going > 1) {
2938 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2939 , u132->going);
2940 } else if (u132->going > 0)
2941 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2942}
2943
2944
2945#ifdef CONFIG_PM
2946static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2947{
2948 struct u132 *u132 = hcd_to_u132(hcd);
2949 if (u132->going > 1) {
2950 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2951 , u132->going);
2952 return -ENODEV;
2953 } else if (u132->going > 0) {
2954 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2955 return -ESHUTDOWN;
2956 } else
2957 return 0;
2958}
2959
2960static int u132_hcd_resume(struct usb_hcd *hcd)
2961{
2962 struct u132 *u132 = hcd_to_u132(hcd);
2963 if (u132->going > 1) {
2964 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2965 , u132->going);
2966 return -ENODEV;
2967 } else if (u132->going > 0) {
2968 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2969 return -ESHUTDOWN;
2970 } else
2971 return 0;
2972}
2973
2974static int u132_bus_suspend(struct usb_hcd *hcd)
2975{
2976 struct u132 *u132 = hcd_to_u132(hcd);
2977 if (u132->going > 1) {
2978 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2979 , u132->going);
2980 return -ENODEV;
2981 } else if (u132->going > 0) {
2982 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2983 return -ESHUTDOWN;
2984 } else
2985 return 0;
2986}
2987
2988static int u132_bus_resume(struct usb_hcd *hcd)
2989{
2990 struct u132 *u132 = hcd_to_u132(hcd);
2991 if (u132->going > 1) {
2992 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2993 , u132->going);
2994 return -ENODEV;
2995 } else if (u132->going > 0) {
2996 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2997 return -ESHUTDOWN;
2998 } else
2999 return 0;
3000}
3001
3002#else
3003#define u132_hcd_suspend NULL
3004#define u132_hcd_resume NULL
3005#define u132_bus_suspend NULL
3006#define u132_bus_resume NULL
3007#endif
3008static struct hc_driver u132_hc_driver = {
3009 .description = hcd_name,
3010 .hcd_priv_size = sizeof(struct u132),
3011 .irq = NULL,
3012 .flags = HCD_USB11 | HCD_MEMORY,
3013 .reset = u132_hcd_reset,
3014 .start = u132_hcd_start,
3015 .suspend = u132_hcd_suspend,
3016 .resume = u132_hcd_resume,
3017 .stop = u132_hcd_stop,
3018 .urb_enqueue = u132_urb_enqueue,
3019 .urb_dequeue = u132_urb_dequeue,
3020 .endpoint_disable = u132_endpoint_disable,
3021 .get_frame_number = u132_get_frame,
3022 .hub_status_data = u132_hub_status_data,
3023 .hub_control = u132_hub_control,
3024 .bus_suspend = u132_bus_suspend,
3025 .bus_resume = u132_bus_resume,
3026 .start_port_reset = u132_start_port_reset,
3027 .hub_irq_enable = u132_hub_irq_enable,
3028};
3029
3030/*
3031* This function may be called by the USB core whilst the "usb_all_devices_rwsem"
3032* is held for writing, thus this module must not call usb_remove_hcd()
3033* synchronously - but instead should immediately stop activity to the
3034* device and ansynchronously call usb_remove_hcd()
3035*/
3036static int __devexit u132_remove(struct platform_device *pdev)
3037{
3038 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3039 if (hcd) {
3040 struct u132 *u132 = hcd_to_u132(hcd);
3041 dump_stack();
3042 if (u132->going++ > 1) {
3043 return -ENODEV;
3044 } else {
3045 int rings = MAX_U132_RINGS;
3046 int endps = MAX_U132_ENDPS;
3047 msleep(100);
3048 down(&u132->sw_lock);
3049 u132_monitor_cancel_work(u132);
3050 while (rings-- > 0) {
3051 struct u132_ring *ring = &u132->ring[rings];
3052 u132_ring_cancel_work(u132, ring);
3053 } while (endps-- > 0) {
3054 struct u132_endp *endp = u132->endp[endps];
3055 if (endp)
3056 u132_endp_cancel_work(u132, endp);
3057 }
3058 u132->going += 1;
3059 printk(KERN_INFO "removing device u132.%d\n",
3060 u132->sequence_num);
3061 up(&u132->sw_lock);
3062 usb_remove_hcd(hcd);
3063 u132_u132_put_kref(u132);
3064 return 0;
3065 }
3066 } else
3067 return 0;
3068}
3069
3070static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3071{
3072 int rings = MAX_U132_RINGS;
3073 int ports = MAX_U132_PORTS;
3074 int addrs = MAX_U132_ADDRS;
3075 int udevs = MAX_U132_UDEVS;
3076 int endps = MAX_U132_ENDPS;
3077 u132->board = pdev->dev.platform_data;
3078 u132->platform_dev = pdev;
3079 u132->power = 0;
3080 u132->reset = 0;
3081 init_MUTEX(&u132->sw_lock);
3082 init_MUTEX(&u132->scheduler_lock);
3083 while (rings-- > 0) {
3084 struct u132_ring *ring = &u132->ring[rings];
3085 ring->u132 = u132;
3086 ring->number = rings + 1;
3087 ring->length = 0;
3088 ring->curr_endp = NULL;
David Howellsc4028952006-11-22 14:57:56 +00003089 INIT_DELAYED_WORK(&ring->scheduler,
3090 u132_hcd_ring_work_scheduler);
Tony Olechd774efe2006-09-13 11:27:35 +01003091 } down(&u132->sw_lock);
David Howellsc4028952006-11-22 14:57:56 +00003092 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
Tony Olechd774efe2006-09-13 11:27:35 +01003093 while (ports-- > 0) {
3094 struct u132_port *port = &u132->port[ports];
3095 port->u132 = u132;
3096 port->reset = 0;
3097 port->enable = 0;
3098 port->power = 0;
3099 port->Status = 0;
3100 } while (addrs-- > 0) {
3101 struct u132_addr *addr = &u132->addr[addrs];
3102 addr->address = 0;
3103 } while (udevs-- > 0) {
3104 struct u132_udev *udev = &u132->udev[udevs];
3105 int i = ARRAY_SIZE(udev->endp_number_in);
3106 int o = ARRAY_SIZE(udev->endp_number_out);
3107 udev->usb_device = NULL;
3108 udev->udev_number = 0;
3109 udev->usb_addr = 0;
3110 udev->portnumber = 0;
3111 while (i-- > 0) {
3112 udev->endp_number_in[i] = 0;
3113 }
3114 while (o-- > 0) {
3115 udev->endp_number_out[o] = 0;
3116 }
3117 }
3118 while (endps-- > 0) {
3119 u132->endp[endps] = NULL;
3120 }
3121 up(&u132->sw_lock);
3122 return;
3123}
3124
3125static int __devinit u132_probe(struct platform_device *pdev)
3126{
3127 struct usb_hcd *hcd;
3128 msleep(100);
3129 if (u132_exiting > 0) {
3130 return -ENODEV;
3131 } /* refuse to confuse usbcore */
3132 if (pdev->dev.dma_mask) {
3133 return -EINVAL;
3134 }
3135 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3136 if (!hcd) {
3137 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3138 );
3139 ftdi_elan_gone_away(pdev);
3140 return -ENOMEM;
3141 } else {
3142 int retval = 0;
3143 struct u132 *u132 = hcd_to_u132(hcd);
3144 hcd->rsrc_start = 0;
3145 down(&u132_module_lock);
3146 list_add_tail(&u132->u132_list, &u132_static_list);
3147 u132->sequence_num = ++u132_instances;
3148 up(&u132_module_lock);
3149 u132_u132_init_kref(u132);
3150 u132_initialise(u132, pdev);
3151 hcd->product_desc = "ELAN U132 Host Controller";
3152 retval = usb_add_hcd(hcd, 0, 0);
3153 if (retval != 0) {
3154 dev_err(&u132->platform_dev->dev, "init error %d\n",
3155 retval);
3156 u132_u132_put_kref(u132);
3157 return retval;
3158 } else {
3159 u132_monitor_queue_work(u132, 100);
3160 return 0;
3161 }
3162 }
3163}
3164
3165
3166#ifdef CONFIG_PM
3167/* for this device there's no useful distinction between the controller
3168* and its root hub, except that the root hub only gets direct PM calls
3169* when CONFIG_USB_SUSPEND is enabled.
3170*/
3171static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3172{
3173 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3174 struct u132 *u132 = hcd_to_u132(hcd);
3175 if (u132->going > 1) {
3176 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3177 , u132->going);
3178 return -ENODEV;
3179 } else if (u132->going > 0) {
3180 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3181 return -ESHUTDOWN;
3182 } else {
3183 int retval = 0;
3184 if (state.event == PM_EVENT_FREEZE) {
3185 retval = u132_bus_suspend(hcd);
3186 } else if (state.event == PM_EVENT_SUSPEND) {
3187 int ports = MAX_U132_PORTS;
3188 while (ports-- > 0) {
3189 port_power(u132, ports, 0);
3190 }
3191 }
3192 if (retval == 0)
3193 pdev->dev.power.power_state = state;
3194 return retval;
3195 }
3196}
3197
3198static int u132_resume(struct platform_device *pdev)
3199{
3200 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3201 struct u132 *u132 = hcd_to_u132(hcd);
3202 if (u132->going > 1) {
3203 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3204 , u132->going);
3205 return -ENODEV;
3206 } else if (u132->going > 0) {
3207 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3208 return -ESHUTDOWN;
3209 } else {
3210 int retval = 0;
3211 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
3212 int ports = MAX_U132_PORTS;
3213 while (ports-- > 0) {
3214 port_power(u132, ports, 1);
3215 }
3216 retval = 0;
3217 } else {
3218 pdev->dev.power.power_state = PMSG_ON;
3219 retval = u132_bus_resume(hcd);
3220 }
3221 return retval;
3222 }
3223}
3224
3225#else
3226#define u132_suspend NULL
3227#define u132_resume NULL
3228#endif
3229/*
3230* this driver is loaded explicitely by ftdi_u132
3231*
3232* the platform_driver struct is static because it is per type of module
3233*/
3234static struct platform_driver u132_platform_driver = {
3235 .probe = u132_probe,
3236 .remove = __devexit_p(u132_remove),
3237 .suspend = u132_suspend,
3238 .resume = u132_resume,
3239 .driver = {
3240 .name = (char *)hcd_name,
3241 .owner = THIS_MODULE,
3242 },
3243};
3244static int __init u132_hcd_init(void)
3245{
3246 int retval;
3247 INIT_LIST_HEAD(&u132_static_list);
3248 u132_instances = 0;
3249 u132_exiting = 0;
3250 init_MUTEX(&u132_module_lock);
3251 if (usb_disabled())
3252 return -ENODEV;
3253 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3254 __DATE__);
3255 workqueue = create_singlethread_workqueue("u132");
3256 retval = platform_driver_register(&u132_platform_driver);
3257 return retval;
3258}
3259
3260
3261module_init(u132_hcd_init);
3262static void __exit u132_hcd_exit(void)
3263{
3264 struct u132 *u132;
3265 struct u132 *temp;
3266 down(&u132_module_lock);
3267 u132_exiting += 1;
3268 up(&u132_module_lock);
3269 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3270 platform_device_unregister(u132->platform_dev);
3271 } platform_driver_unregister(&u132_platform_driver);
3272 printk(KERN_INFO "u132-hcd driver deregistered\n");
3273 wait_event(u132_hcd_wait, u132_instances == 0);
3274 flush_workqueue(workqueue);
3275 destroy_workqueue(workqueue);
3276}
3277
3278
3279module_exit(u132_hcd_exit);
3280MODULE_LICENSE("GPL");