2 * ISP116x HCD (Host Controller Driver) for USB.
4 * Derived from the SL811 HCD, rewritten for ISP116x.
5 * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
8 * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
9 * Copyright (C) 2004 David Brownell
11 * Periodic scheduling is based on Roman's OHCI code
12 * Copyright (C) 1999 Roman Weissgaerber
17 * The driver basically works. A number of people have used it with a range
20 * The driver passes all usbtests 1-14.
22 * Suspending/resuming of root hub via sysfs works. Remote wakeup works too.
23 * And suspending/resuming of platform device works too. Suspend/resume
24 * via HCD operations vector is not implemented.
26 * Iso transfer support is not implemented. Adding this would include
27 * implementing recovery from the failure to service the processed ITL
28 * fifo ram in time, which will involve chip reset.
31 + More testing of suspend/resume.
35 ISP116x chips require certain delays between accesses to its
36 registers. The following timing options exist.
38 1. Configure your memory controller (the best)
39 2. Implement platform-specific delay function possibly
40 combined with configuring the memory controller; see
41 include/linux/usb-isp116x.h for more info. Some broken
42 memory controllers line LH7A400 SMC need this. Also,
43 uncomment for that to work the following
44 USE_PLATFORM_DELAY macro.
45 3. Use ndelay (easiest, poorest). For that, uncomment
46 the following USE_NDELAY macro.
48 #define USE_PLATFORM_DELAY
53 /* Transfer descriptors. See dump_ptd() for printout format */
55 /* enqueuing/finishing log of urbs */
58 #include <linux/config.h>
59 #include <linux/module.h>
60 #include <linux/moduleparam.h>
61 #include <linux/kernel.h>
62 #include <linux/delay.h>
63 #include <linux/ioport.h>
64 #include <linux/sched.h>
65 #include <linux/slab.h>
66 #include <linux/smp_lock.h>
67 #include <linux/errno.h>
68 #include <linux/init.h>
69 #include <linux/list.h>
70 #include <linux/interrupt.h>
71 #include <linux/usb.h>
72 #include <linux/usb_isp116x.h>
76 #include <asm/system.h>
77 #include <asm/byteorder.h>
80 # define STUB_DEBUG_FILE
83 #include "../core/hcd.h"
86 #define DRIVER_VERSION "05 Aug 2005"
87 #define DRIVER_DESC "ISP116x USB Host Controller Driver"
89 MODULE_DESCRIPTION(DRIVER_DESC);
90 MODULE_LICENSE("GPL");
92 static const char hcd_name[] = "isp116x-hcd";
94 /*-----------------------------------------------------------------*/
97 Write len bytes to fifo, pad till 32-bit boundary
99 static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len)
102 u16 *dp2 = (u16 *) buf;
106 if ((unsigned long)dp2 & 1) {
108 for (; len > 1; len -= 2) {
111 isp116x_raw_write_data16(isp116x, w);
114 isp116x_write_data16(isp116x, (u16) * dp);
117 for (; len > 1; len -= 2)
118 isp116x_raw_write_data16(isp116x, *dp2++);
120 isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2));
122 if (quot == 1 || quot == 2)
123 isp116x_raw_write_data16(isp116x, 0);
127 Read len bytes from fifo and then read till 32-bit boundary.
129 static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len)
132 u16 *dp2 = (u16 *) buf;
136 if ((unsigned long)dp2 & 1) {
138 for (; len > 1; len -= 2) {
139 w = isp116x_raw_read_data16(isp116x);
141 *dp++ = (w >> 8) & 0xff;
144 *dp = 0xff & isp116x_read_data16(isp116x);
147 for (; len > 1; len -= 2)
148 *dp2++ = isp116x_raw_read_data16(isp116x);
150 *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x);
152 if (quot == 1 || quot == 2)
153 isp116x_raw_read_data16(isp116x);
157 Write ptd's and data for scheduled transfers into
158 the fifo ram. Fifo must be empty and ready.
160 static void pack_fifo(struct isp116x *isp116x)
162 struct isp116x_ep *ep;
164 int buflen = isp116x->atl_last_dir == PTD_DIR_IN
165 ? isp116x->atl_bufshrt : isp116x->atl_buflen;
168 isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
169 isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
170 isp116x_write_addr(isp116x, HCATLPORT | ISP116x_WRITE_OFFSET);
171 for (ep = isp116x->atl_active; ep; ep = ep->active) {
175 dump_ptd_out_data(ptd, ep->data);
176 isp116x_write_data16(isp116x, ptd->count);
177 isp116x_write_data16(isp116x, ptd->mps);
178 isp116x_write_data16(isp116x, ptd->len);
179 isp116x_write_data16(isp116x, ptd->faddr);
180 buflen -= sizeof(struct ptd);
181 /* Skip writing data for last IN PTD */
182 if (ep->active || (isp116x->atl_last_dir != PTD_DIR_IN)) {
183 write_ptddata_to_fifo(isp116x, ep->data, ep->length);
184 buflen -= ALIGN(ep->length, 4);
191 Read the processed ptd's and data from fifo ram back to
192 URBs' buffers. Fifo must be full and done
194 static void unpack_fifo(struct isp116x *isp116x)
196 struct isp116x_ep *ep;
198 int buflen = isp116x->atl_last_dir == PTD_DIR_IN
199 ? isp116x->atl_buflen : isp116x->atl_bufshrt;
201 isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
202 isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
203 isp116x_write_addr(isp116x, HCATLPORT);
204 for (ep = isp116x->atl_active; ep; ep = ep->active) {
206 ptd->count = isp116x_read_data16(isp116x);
207 ptd->mps = isp116x_read_data16(isp116x);
208 ptd->len = isp116x_read_data16(isp116x);
209 ptd->faddr = isp116x_read_data16(isp116x);
210 buflen -= sizeof(struct ptd);
211 /* Skip reading data for last Setup or Out PTD */
212 if (ep->active || (isp116x->atl_last_dir == PTD_DIR_IN)) {
213 read_ptddata_from_fifo(isp116x, ep->data, ep->length);
214 buflen -= ALIGN(ep->length, 4);
217 dump_ptd_in_data(ptd, ep->data);
222 /*---------------------------------------------------------------*/
227 static void preproc_atl_queue(struct isp116x *isp116x)
229 struct isp116x_ep *ep;
234 for (ep = isp116x->atl_active; ep; ep = ep->active) {
235 u16 toggle = 0, dir = PTD_DIR_SETUP;
237 BUG_ON(list_empty(&ep->hep->urb_list));
238 urb = container_of(ep->hep->urb_list.next,
239 struct urb, urb_list);
242 spin_lock(&urb->lock);
243 ep->data = (unsigned char *)urb->transfer_buffer
244 + urb->actual_length;
246 switch (ep->nextpid) {
248 toggle = usb_gettoggle(urb->dev, ep->epnum, 0);
252 toggle = usb_gettoggle(urb->dev, ep->epnum, 1);
256 len = sizeof(struct usb_ctrlrequest);
257 ep->data = urb->setup_packet;
262 dir = (urb->transfer_buffer_length
263 && usb_pipein(urb->pipe))
264 ? PTD_DIR_OUT : PTD_DIR_IN;
267 ERR("%s %d: ep->nextpid %d\n", __func__, __LINE__,
272 ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle);
273 ptd->mps = PTD_MPS(ep->maxpacket)
274 | PTD_SPD(urb->dev->speed == USB_SPEED_LOW)
276 ptd->len = PTD_LEN(len) | PTD_DIR(dir);
277 ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe));
278 spin_unlock(&urb->lock);
280 ptd->mps |= PTD_LAST_MSK;
281 isp116x->atl_last_dir = dir;
283 isp116x->atl_bufshrt = sizeof(struct ptd) + isp116x->atl_buflen;
284 isp116x->atl_buflen = isp116x->atl_bufshrt + ALIGN(len, 4);
289 Analyze transfer results, handle partial transfers and errors
291 static void postproc_atl_queue(struct isp116x *isp116x)
293 struct isp116x_ep *ep;
295 struct usb_device *udev;
300 for (ep = isp116x->atl_active; ep; ep = ep->active) {
301 BUG_ON(list_empty(&ep->hep->urb_list));
303 container_of(ep->hep->urb_list.next, struct urb, urb_list);
306 cc = PTD_GET_CC(ptd);
308 spin_lock(&urb->lock);
311 /* Data underrun is special. For allowed underrun
312 we clear the error and continue as normal. For
313 forbidden underrun we finish the DATA stage
314 immediately while for control transfer,
315 we do a STATUS stage. */
316 if (cc == TD_DATAUNDERRUN) {
317 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) {
318 DBG("Allowed data underrun\n");
323 if (usb_pipecontrol(urb->pipe))
324 ep->nextpid = USB_PID_ACK;
326 usb_settoggle(udev, ep->epnum,
329 PTD_GET_TOGGLE(ptd) ^ 1);
330 urb->status = cc_to_error[TD_DATAUNDERRUN];
331 spin_unlock(&urb->lock);
335 /* Keep underrun error through the STATUS stage */
336 if (urb->status == cc_to_error[TD_DATAUNDERRUN])
337 cc = TD_DATAUNDERRUN;
339 if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED
340 && (++ep->error_count >= 3 || cc == TD_CC_STALL
341 || cc == TD_DATAOVERRUN)) {
342 if (urb->status == -EINPROGRESS)
343 urb->status = cc_to_error[cc];
344 if (ep->nextpid == USB_PID_ACK)
346 spin_unlock(&urb->lock);
349 /* According to usb spec, zero-length Int transfer signals
350 finishing of the urb. Hey, does this apply only
352 if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) {
353 if (urb->status == -EINPROGRESS)
355 spin_unlock(&urb->lock);
359 /* Relax after previously failed, but later succeeded
360 or correctly NAK'ed retransmission attempt */
362 && (cc == TD_CC_NOERROR || cc == TD_NOTACCESSED))
365 /* Take into account idiosyncracies of the isp116x chip
366 regarding toggle bit for failed transfers */
367 if (ep->nextpid == USB_PID_OUT)
368 usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd)
369 ^ (ep->error_count > 0));
370 else if (ep->nextpid == USB_PID_IN)
371 usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd)
372 ^ (ep->error_count > 0));
374 switch (ep->nextpid) {
377 urb->actual_length += PTD_GET_COUNT(ptd);
378 if (PTD_GET_ACTIVE(ptd)
379 || (cc != TD_CC_NOERROR && cc < 0x0E))
381 if (urb->transfer_buffer_length != urb->actual_length) {
385 if (urb->transfer_flags & URB_ZERO_PACKET
386 && ep->nextpid == USB_PID_OUT
387 && !(PTD_GET_COUNT(ptd) % ep->maxpacket)) {
388 DBG("Zero packet requested\n");
392 /* All data for this URB is transferred, let's finish */
393 if (usb_pipecontrol(urb->pipe))
394 ep->nextpid = USB_PID_ACK;
395 else if (urb->status == -EINPROGRESS)
399 if (PTD_GET_ACTIVE(ptd)
400 || (cc != TD_CC_NOERROR && cc < 0x0E))
402 if (urb->transfer_buffer_length == urb->actual_length)
403 ep->nextpid = USB_PID_ACK;
404 else if (usb_pipeout(urb->pipe)) {
405 usb_settoggle(udev, 0, 1, 1);
406 ep->nextpid = USB_PID_OUT;
408 usb_settoggle(udev, 0, 0, 1);
409 ep->nextpid = USB_PID_IN;
413 if (PTD_GET_ACTIVE(ptd)
414 || (cc != TD_CC_NOERROR && cc < 0x0E))
416 if (urb->status == -EINPROGRESS)
423 spin_unlock(&urb->lock);
428 Take done or failed requests out of schedule. Give back
431 static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
432 struct urb *urb, struct pt_regs *regs)
433 __releases(isp116x->lock) __acquires(isp116x->lock)
440 if (usb_pipecontrol(urb->pipe))
441 ep->nextpid = USB_PID_SETUP;
443 urb_dbg(urb, "Finish");
445 spin_unlock(&isp116x->lock);
446 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb, regs);
447 spin_lock(&isp116x->lock);
449 /* take idle endpoints out of the schedule */
450 if (!list_empty(&ep->hep->urb_list))
453 /* async deschedule */
454 if (!list_empty(&ep->schedule)) {
455 list_del_init(&ep->schedule);
459 /* periodic deschedule */
460 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
461 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
462 struct isp116x_ep *temp;
463 struct isp116x_ep **prev = &isp116x->periodic[i];
465 while (*prev && ((temp = *prev) != ep))
469 isp116x->load[i] -= ep->load;
471 ep->branch = PERIODIC_SIZE;
472 isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
473 ep->load / ep->period;
475 /* switch irq type? */
476 if (!--isp116x->periodic_count) {
477 isp116x->irqenb &= ~HCuPINT_SOF;
478 isp116x->irqenb |= HCuPINT_ATL;
483 Scan transfer lists, schedule transfers, send data off
486 static void start_atl_transfers(struct isp116x *isp116x)
488 struct isp116x_ep *last_ep = NULL, *ep;
491 int len, index, speed, byte_time;
493 if (atomic_read(&isp116x->atl_finishing))
496 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state))
499 /* FIFO not empty? */
500 if (isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_FULL)
503 isp116x->atl_active = NULL;
504 isp116x->atl_buflen = isp116x->atl_bufshrt = 0;
506 /* Schedule int transfers */
507 if (isp116x->periodic_count) {
508 isp116x->fmindex = index =
509 (isp116x->fmindex + 1) & (PERIODIC_SIZE - 1);
510 if ((load = isp116x->load[index])) {
511 /* Bring all int transfers for this frame
512 into the active queue */
513 isp116x->atl_active = last_ep =
514 isp116x->periodic[index];
515 while (last_ep->next)
516 last_ep = (last_ep->active = last_ep->next);
517 last_ep->active = NULL;
521 /* Schedule control/bulk transfers */
522 list_for_each_entry(ep, &isp116x->async, schedule) {
523 urb = container_of(ep->hep->urb_list.next,
524 struct urb, urb_list);
525 speed = urb->dev->speed;
526 byte_time = speed == USB_SPEED_LOW
527 ? BYTE_TIME_LOWSPEED : BYTE_TIME_FULLSPEED;
529 if (ep->nextpid == USB_PID_SETUP) {
530 len = sizeof(struct usb_ctrlrequest);
531 } else if (ep->nextpid == USB_PID_ACK) {
534 /* Find current free length ... */
535 len = (MAX_LOAD_LIMIT - load) / byte_time;
537 /* ... then limit it to configured max size ... */
538 len = min(len, speed == USB_SPEED_LOW ?
539 MAX_TRANSFER_SIZE_LOWSPEED :
540 MAX_TRANSFER_SIZE_FULLSPEED);
542 /* ... and finally cut to the multiple of MaxPacketSize,
543 or to the real length if there's enough room. */
545 (urb->transfer_buffer_length -
546 urb->actual_length)) {
547 len -= len % ep->maxpacket;
551 len = urb->transfer_buffer_length -
556 load += len * byte_time;
557 if (load > MAX_LOAD_LIMIT)
563 last_ep->active = ep;
565 isp116x->atl_active = ep;
569 /* Avoid starving of endpoints */
570 if ((&isp116x->async)->next != (&isp116x->async)->prev)
571 list_move(&isp116x->async, (&isp116x->async)->next);
573 if (isp116x->atl_active) {
574 preproc_atl_queue(isp116x);
580 Finish the processed transfers
582 static void finish_atl_transfers(struct isp116x *isp116x, struct pt_regs *regs)
584 struct isp116x_ep *ep;
587 if (!isp116x->atl_active)
589 /* Fifo not ready? */
590 if (!(isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_DONE))
593 atomic_inc(&isp116x->atl_finishing);
594 unpack_fifo(isp116x);
595 postproc_atl_queue(isp116x);
596 for (ep = isp116x->atl_active; ep; ep = ep->active) {
598 container_of(ep->hep->urb_list.next, struct urb, urb_list);
599 /* USB_PID_ACK check here avoids finishing of
600 control transfers, for which TD_DATAUNDERRUN
601 occured, while URB_SHORT_NOT_OK was set */
602 if (urb && urb->status != -EINPROGRESS
603 && ep->nextpid != USB_PID_ACK)
604 finish_request(isp116x, ep, urb, regs);
606 atomic_dec(&isp116x->atl_finishing);
609 static irqreturn_t isp116x_irq(struct usb_hcd *hcd, struct pt_regs *regs)
611 struct isp116x *isp116x = hcd_to_isp116x(hcd);
613 irqreturn_t ret = IRQ_NONE;
615 spin_lock(&isp116x->lock);
616 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
617 irqstat = isp116x_read_reg16(isp116x, HCuPINT);
618 isp116x_write_reg16(isp116x, HCuPINT, irqstat);
620 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
622 finish_atl_transfers(isp116x, regs);
625 if (irqstat & HCuPINT_OPR) {
626 u32 intstat = isp116x_read_reg32(isp116x, HCINTSTAT);
627 isp116x_write_reg32(isp116x, HCINTSTAT, intstat);
628 if (intstat & HCINT_UE) {
629 ERR("Unrecoverable error\n");
630 /* What should we do here? Reset? */
632 if (intstat & HCINT_RHSC)
633 /* When root hub or any of its ports is going
634 to come out of suspend, it may take more
635 than 10ms for status bits to stabilize. */
636 mod_timer(&hcd->rh_timer, jiffies
637 + msecs_to_jiffies(20) + 1);
638 if (intstat & HCINT_RD) {
639 DBG("---- remote wakeup\n");
640 schedule_work(&isp116x->rh_resume);
643 irqstat &= ~HCuPINT_OPR;
647 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
648 start_atl_transfers(isp116x);
651 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
652 spin_unlock(&isp116x->lock);
656 /*-----------------------------------------------------------------*/
658 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
659 * this driver doesn't promise that much since it's got to handle an
660 * IRQ per packet; irq handling latencies also use up that time.
664 #define MAX_PERIODIC_LOAD 600
665 static int balance(struct isp116x *isp116x, u16 period, u16 load)
667 int i, branch = -ENOSPC;
669 /* search for the least loaded schedule branch of that period
670 which has enough bandwidth left unreserved. */
671 for (i = 0; i < period; i++) {
672 if (branch < 0 || isp116x->load[branch] > isp116x->load[i]) {
675 for (j = i; j < PERIODIC_SIZE; j += period) {
676 if ((isp116x->load[j] + load)
680 if (j < PERIODIC_SIZE)
688 /* NB! ALL the code above this point runs with isp116x->lock
692 /*-----------------------------------------------------------------*/
694 static int isp116x_urb_enqueue(struct usb_hcd *hcd,
695 struct usb_host_endpoint *hep, struct urb *urb,
698 struct isp116x *isp116x = hcd_to_isp116x(hcd);
699 struct usb_device *udev = urb->dev;
700 unsigned int pipe = urb->pipe;
701 int is_out = !usb_pipein(pipe);
702 int type = usb_pipetype(pipe);
703 int epnum = usb_pipeendpoint(pipe);
704 struct isp116x_ep *ep = NULL;
709 urb_dbg(urb, "Enqueue");
711 if (type == PIPE_ISOCHRONOUS) {
712 ERR("Isochronous transfers not supported\n");
713 urb_dbg(urb, "Refused to enqueue");
716 /* avoid all allocations within spinlocks: request or endpoint */
718 ep = kzalloc(sizeof *ep, mem_flags);
723 spin_lock_irqsave(&isp116x->lock, flags);
724 if (!HC_IS_RUNNING(hcd->state)) {
732 INIT_LIST_HEAD(&ep->schedule);
733 ep->udev = usb_get_dev(udev);
735 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
736 usb_settoggle(udev, epnum, is_out, 0);
738 if (type == PIPE_CONTROL) {
739 ep->nextpid = USB_PID_SETUP;
741 ep->nextpid = USB_PID_OUT;
743 ep->nextpid = USB_PID_IN;
748 With INT URBs submitted, the driver works with SOF
749 interrupt enabled and ATL interrupt disabled. After
750 the PTDs are written to fifo ram, the chip starts
751 fifo processing and usb transfers after the next
752 SOF and continues until the transfers are finished
753 (succeeded or failed) or the frame ends. Therefore,
754 the transfers occur only in every second frame,
755 while fifo reading/writing and data processing
756 occur in every other second frame. */
757 if (urb->interval < 2)
759 if (urb->interval > 2 * PERIODIC_SIZE)
760 urb->interval = 2 * PERIODIC_SIZE;
761 ep->period = urb->interval >> 1;
762 ep->branch = PERIODIC_SIZE;
763 ep->load = usb_calc_bus_time(udev->speed,
765 (type == PIPE_ISOCHRONOUS),
766 usb_maxpacket(udev, pipe,
774 /* maybe put endpoint into schedule */
778 if (list_empty(&ep->schedule))
779 list_add_tail(&ep->schedule, &isp116x->async);
782 urb->interval = ep->period;
783 ep->length = min((int)ep->maxpacket,
784 urb->transfer_buffer_length);
786 /* urb submitted for already existing endpoint */
787 if (ep->branch < PERIODIC_SIZE)
790 ret = ep->branch = balance(isp116x, ep->period, ep->load);
795 urb->start_frame = (isp116x->fmindex & (PERIODIC_SIZE - 1))
798 /* sort each schedule branch by period (slow before fast)
799 to share the faster parts of the tree without needing
800 dummy/placeholder nodes */
801 DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
802 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
803 struct isp116x_ep **prev = &isp116x->periodic[i];
804 struct isp116x_ep *here = *prev;
806 while (here && ep != here) {
807 if (ep->period > here->period)
816 isp116x->load[i] += ep->load;
818 hcd->self.bandwidth_allocated += ep->load / ep->period;
820 /* switch over to SOFint */
821 if (!isp116x->periodic_count++) {
822 isp116x->irqenb &= ~HCuPINT_ATL;
823 isp116x->irqenb |= HCuPINT_SOF;
824 isp116x_write_reg16(isp116x, HCuPINTENB,
829 /* in case of unlink-during-submit */
830 spin_lock(&urb->lock);
831 if (urb->status != -EINPROGRESS) {
832 spin_unlock(&urb->lock);
833 finish_request(isp116x, ep, urb, NULL);
838 spin_unlock(&urb->lock);
839 start_atl_transfers(isp116x);
842 spin_unlock_irqrestore(&isp116x->lock, flags);
849 static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
851 struct isp116x *isp116x = hcd_to_isp116x(hcd);
852 struct usb_host_endpoint *hep;
853 struct isp116x_ep *ep, *ep_act;
856 spin_lock_irqsave(&isp116x->lock, flags);
858 /* URB already unlinked (or never linked)? */
860 spin_unlock_irqrestore(&isp116x->lock, flags);
864 WARN_ON(hep != ep->hep);
866 /* In front of queue? */
867 if (ep->hep->urb_list.next == &urb->urb_list)
869 for (ep_act = isp116x->atl_active; ep_act;
870 ep_act = ep_act->active)
872 VDBG("dequeue, urb %p active; wait for irq\n",
879 finish_request(isp116x, ep, urb, NULL);
881 spin_unlock_irqrestore(&isp116x->lock, flags);
885 static void isp116x_endpoint_disable(struct usb_hcd *hcd,
886 struct usb_host_endpoint *hep)
889 struct isp116x_ep *ep = hep->hcpriv;;
894 /* assume we'd just wait for the irq */
895 for (i = 0; i < 100 && !list_empty(&hep->urb_list); i++)
897 if (!list_empty(&hep->urb_list))
898 WARN("ep %p not empty?\n", ep);
900 usb_put_dev(ep->udev);
905 static int isp116x_get_frame(struct usb_hcd *hcd)
907 struct isp116x *isp116x = hcd_to_isp116x(hcd);
911 spin_lock_irqsave(&isp116x->lock, flags);
912 fmnum = isp116x_read_reg32(isp116x, HCFMNUM);
913 spin_unlock_irqrestore(&isp116x->lock, flags);
917 /*----------------------------------------------------------------*/
920 Adapted from ohci-hub.c. Currently we don't support autosuspend.
922 static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
924 struct isp116x *isp116x = hcd_to_isp116x(hcd);
925 int ports, i, changed = 0;
928 if (!HC_IS_RUNNING(hcd->state))
931 /* Report no status change now, if we are scheduled to be
933 if (timer_pending(&hcd->rh_timer))
936 ports = isp116x->rhdesca & RH_A_NDP;
937 spin_lock_irqsave(&isp116x->lock, flags);
938 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
939 if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
940 buf[0] = changed = 1;
944 for (i = 0; i < ports; i++) {
945 u32 status = isp116x->rhport[i] =
946 isp116x_read_reg32(isp116x, i ? HCRHPORT2 : HCRHPORT1);
948 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
949 | RH_PS_OCIC | RH_PS_PRSC)) {
951 buf[0] |= 1 << (i + 1);
955 spin_unlock_irqrestore(&isp116x->lock, flags);
959 static void isp116x_hub_descriptor(struct isp116x *isp116x,
960 struct usb_hub_descriptor *desc)
962 u32 reg = isp116x->rhdesca;
964 desc->bDescriptorType = 0x29;
965 desc->bDescLength = 9;
966 desc->bHubContrCurrent = 0;
967 desc->bNbrPorts = (u8) (reg & 0x3);
968 /* Power switching, device type, overcurrent. */
969 desc->wHubCharacteristics =
970 (__force __u16) cpu_to_le16((u16) ((reg >> 8) & 0x1f));
971 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff);
972 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
973 desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
974 desc->bitmap[1] = ~0;
977 /* Perform reset of a given port.
978 It would be great to just start the reset and let the
979 USB core to clear the reset in due time. However,
980 root hub ports should be reset for at least 50 ms, while
981 our chip stays in reset for about 10 ms. I.e., we must
982 repeatedly reset it ourself here.
984 static inline void root_port_reset(struct isp116x *isp116x, unsigned port)
987 unsigned long flags, t;
989 /* Root hub reset should be 50 ms, but some devices
990 want it even longer. */
991 t = jiffies + msecs_to_jiffies(100);
993 while (time_before(jiffies, t)) {
994 spin_lock_irqsave(&isp116x->lock, flags);
995 /* spin until any current reset finishes */
997 tmp = isp116x_read_reg32(isp116x, port ?
998 HCRHPORT2 : HCRHPORT1);
999 if (!(tmp & RH_PS_PRS))
1003 /* Don't reset a disconnected port */
1004 if (!(tmp & RH_PS_CCS)) {
1005 spin_unlock_irqrestore(&isp116x->lock, flags);
1008 /* Reset lasts 10ms (claims datasheet) */
1009 isp116x_write_reg32(isp116x, port ? HCRHPORT2 :
1010 HCRHPORT1, (RH_PS_PRS));
1011 spin_unlock_irqrestore(&isp116x->lock, flags);
1016 /* Adapted from ohci-hub.c */
1017 static int isp116x_hub_control(struct usb_hcd *hcd,
1019 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1021 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1023 unsigned long flags;
1024 int ports = isp116x->rhdesca & RH_A_NDP;
1028 case ClearHubFeature:
1029 DBG("ClearHubFeature: ");
1031 case C_HUB_OVER_CURRENT:
1032 DBG("C_HUB_OVER_CURRENT\n");
1033 spin_lock_irqsave(&isp116x->lock, flags);
1034 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_OCIC);
1035 spin_unlock_irqrestore(&isp116x->lock, flags);
1036 case C_HUB_LOCAL_POWER:
1037 DBG("C_HUB_LOCAL_POWER\n");
1044 DBG("SetHubFeature: ");
1046 case C_HUB_OVER_CURRENT:
1047 case C_HUB_LOCAL_POWER:
1048 DBG("C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1054 case GetHubDescriptor:
1055 DBG("GetHubDescriptor\n");
1056 isp116x_hub_descriptor(isp116x,
1057 (struct usb_hub_descriptor *)buf);
1060 DBG("GetHubStatus\n");
1061 *(__le32 *) buf = 0;
1064 DBG("GetPortStatus\n");
1065 if (!wIndex || wIndex > ports)
1067 tmp = isp116x->rhport[--wIndex];
1068 *(__le32 *) buf = cpu_to_le32(tmp);
1069 DBG("GetPortStatus: port[%d] %08x\n", wIndex + 1, tmp);
1071 case ClearPortFeature:
1072 DBG("ClearPortFeature: ");
1073 if (!wIndex || wIndex > ports)
1078 case USB_PORT_FEAT_ENABLE:
1079 DBG("USB_PORT_FEAT_ENABLE\n");
1082 case USB_PORT_FEAT_C_ENABLE:
1083 DBG("USB_PORT_FEAT_C_ENABLE\n");
1086 case USB_PORT_FEAT_SUSPEND:
1087 DBG("USB_PORT_FEAT_SUSPEND\n");
1090 case USB_PORT_FEAT_C_SUSPEND:
1091 DBG("USB_PORT_FEAT_C_SUSPEND\n");
1094 case USB_PORT_FEAT_POWER:
1095 DBG("USB_PORT_FEAT_POWER\n");
1098 case USB_PORT_FEAT_C_CONNECTION:
1099 DBG("USB_PORT_FEAT_C_CONNECTION\n");
1102 case USB_PORT_FEAT_C_OVER_CURRENT:
1103 DBG("USB_PORT_FEAT_C_OVER_CURRENT\n");
1106 case USB_PORT_FEAT_C_RESET:
1107 DBG("USB_PORT_FEAT_C_RESET\n");
1113 spin_lock_irqsave(&isp116x->lock, flags);
1114 isp116x_write_reg32(isp116x, wIndex
1115 ? HCRHPORT2 : HCRHPORT1, tmp);
1116 isp116x->rhport[wIndex] =
1117 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1118 spin_unlock_irqrestore(&isp116x->lock, flags);
1120 case SetPortFeature:
1121 DBG("SetPortFeature: ");
1122 if (!wIndex || wIndex > ports)
1126 case USB_PORT_FEAT_SUSPEND:
1127 DBG("USB_PORT_FEAT_SUSPEND\n");
1128 spin_lock_irqsave(&isp116x->lock, flags);
1129 isp116x_write_reg32(isp116x, wIndex
1130 ? HCRHPORT2 : HCRHPORT1, RH_PS_PSS);
1132 case USB_PORT_FEAT_POWER:
1133 DBG("USB_PORT_FEAT_POWER\n");
1134 spin_lock_irqsave(&isp116x->lock, flags);
1135 isp116x_write_reg32(isp116x, wIndex
1136 ? HCRHPORT2 : HCRHPORT1, RH_PS_PPS);
1138 case USB_PORT_FEAT_RESET:
1139 DBG("USB_PORT_FEAT_RESET\n");
1140 root_port_reset(isp116x, wIndex);
1141 spin_lock_irqsave(&isp116x->lock, flags);
1146 isp116x->rhport[wIndex] =
1147 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1148 spin_unlock_irqrestore(&isp116x->lock, flags);
1153 /* "protocol stall" on error */
1154 DBG("PROTOCOL STALL\n");
1162 static int isp116x_hub_suspend(struct usb_hcd *hcd)
1164 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1165 unsigned long flags;
1169 spin_lock_irqsave(&isp116x->lock, flags);
1171 val = isp116x_read_reg32(isp116x, HCCONTROL);
1172 switch (val & HCCONTROL_HCFS) {
1173 case HCCONTROL_USB_OPER:
1174 hcd->state = HC_STATE_QUIESCING;
1175 val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE);
1176 val |= HCCONTROL_USB_SUSPEND;
1177 if (hcd->remote_wakeup)
1178 val |= HCCONTROL_RWE;
1179 /* Wait for usb transfers to finish */
1181 isp116x_write_reg32(isp116x, HCCONTROL, val);
1182 hcd->state = HC_STATE_SUSPENDED;
1183 /* Wait for devices to suspend */
1185 case HCCONTROL_USB_SUSPEND:
1187 case HCCONTROL_USB_RESUME:
1188 isp116x_write_reg32(isp116x, HCCONTROL,
1189 (val & ~HCCONTROL_HCFS) |
1190 HCCONTROL_USB_RESET);
1191 case HCCONTROL_USB_RESET:
1198 spin_unlock_irqrestore(&isp116x->lock, flags);
1202 static int isp116x_hub_resume(struct usb_hcd *hcd)
1204 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1206 int ret = -EINPROGRESS;
1209 spin_lock_irq(&isp116x->lock);
1211 val = isp116x_read_reg32(isp116x, HCCONTROL);
1212 switch (val & HCCONTROL_HCFS) {
1213 case HCCONTROL_USB_SUSPEND:
1214 val &= ~HCCONTROL_HCFS;
1215 val |= HCCONTROL_USB_RESUME;
1216 isp116x_write_reg32(isp116x, HCCONTROL, val);
1217 case HCCONTROL_USB_RESUME:
1219 case HCCONTROL_USB_OPER:
1220 /* Without setting power_state here the
1221 SUSPENDED state won't be removed from
1222 sysfs/usbN/power.state as a response to remote
1223 wakeup. Maybe in the future. */
1224 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1231 if (ret != -EINPROGRESS) {
1232 spin_unlock_irq(&isp116x->lock);
1236 val = isp116x->rhdesca & RH_A_NDP;
1239 isp116x_read_reg32(isp116x, val ? HCRHPORT2 : HCRHPORT1);
1240 /* force global, not selective, resume */
1241 if (!(stat & RH_PS_PSS))
1243 DBG("%s: Resuming port %d\n", __func__, val);
1244 isp116x_write_reg32(isp116x, RH_PS_POCI, val
1245 ? HCRHPORT2 : HCRHPORT1);
1247 spin_unlock_irq(&isp116x->lock);
1249 hcd->state = HC_STATE_RESUMING;
1252 /* Go operational */
1253 spin_lock_irq(&isp116x->lock);
1254 val = isp116x_read_reg32(isp116x, HCCONTROL);
1255 isp116x_write_reg32(isp116x, HCCONTROL,
1256 (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER);
1257 spin_unlock_irq(&isp116x->lock);
1258 /* see analogous comment above */
1259 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1260 hcd->state = HC_STATE_RUNNING;
1265 static void isp116x_rh_resume(void *_hcd)
1267 struct usb_hcd *hcd = _hcd;
1269 usb_resume_device(hcd->self.root_hub);
1274 #define isp116x_hub_suspend NULL
1275 #define isp116x_hub_resume NULL
1277 static void isp116x_rh_resume(void *_hcd)
1283 /*-----------------------------------------------------------------*/
1285 #ifdef STUB_DEBUG_FILE
1287 static inline void create_debug_file(struct isp116x *isp116x)
1291 static inline void remove_debug_file(struct isp116x *isp116x)
1297 #include <linux/proc_fs.h>
1298 #include <linux/seq_file.h>
1300 static void dump_irq(struct seq_file *s, char *label, u16 mask)
1302 seq_printf(s, "%s %04x%s%s%s%s%s%s\n", label, mask,
1303 mask & HCuPINT_CLKRDY ? " clkrdy" : "",
1304 mask & HCuPINT_SUSP ? " susp" : "",
1305 mask & HCuPINT_OPR ? " opr" : "",
1306 mask & HCuPINT_AIIEOT ? " eot" : "",
1307 mask & HCuPINT_ATL ? " atl" : "",
1308 mask & HCuPINT_SOF ? " sof" : "");
1311 static void dump_int(struct seq_file *s, char *label, u32 mask)
1313 seq_printf(s, "%s %08x%s%s%s%s%s%s%s\n", label, mask,
1314 mask & HCINT_MIE ? " MIE" : "",
1315 mask & HCINT_RHSC ? " rhsc" : "",
1316 mask & HCINT_FNO ? " fno" : "",
1317 mask & HCINT_UE ? " ue" : "",
1318 mask & HCINT_RD ? " rd" : "",
1319 mask & HCINT_SF ? " sof" : "", mask & HCINT_SO ? " so" : "");
1322 static int proc_isp116x_show(struct seq_file *s, void *unused)
1324 struct isp116x *isp116x = s->private;
1325 struct isp116x_ep *ep;
1330 seq_printf(s, "%s\n%s version %s\n",
1331 isp116x_to_hcd(isp116x)->product_desc, hcd_name,
1334 if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x)->state)) {
1335 seq_printf(s, "HCD is suspended\n");
1338 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) {
1339 seq_printf(s, "HCD not running\n");
1343 spin_lock_irq(&isp116x->lock);
1345 dump_irq(s, "hc_irq_enable", isp116x_read_reg16(isp116x, HCuPINTENB));
1346 dump_irq(s, "hc_irq_status", isp116x_read_reg16(isp116x, HCuPINT));
1347 dump_int(s, "hc_int_enable", isp116x_read_reg32(isp116x, HCINTENB));
1348 dump_int(s, "hc_int_status", isp116x_read_reg32(isp116x, HCINTSTAT));
1350 list_for_each_entry(ep, &isp116x->async, schedule) {
1352 switch (ep->nextpid) {
1369 seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep,
1370 ep->epnum, str, ep->maxpacket);
1371 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
1372 seq_printf(s, " urb%p, %d/%d\n", urb,
1374 urb->transfer_buffer_length);
1377 if (!list_empty(&isp116x->async))
1378 seq_printf(s, "\n");
1380 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1382 for (i = 0; i < PERIODIC_SIZE; i++) {
1383 ep = isp116x->periodic[i];
1386 seq_printf(s, "%2d [%3d]:\n", i, isp116x->load[i]);
1388 /* DUMB: prints shared entries multiple times */
1390 seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
1393 USB_SPEED_FULL) ? "" : "ls ",
1394 ep->udev->devnum, ep->epnum,
1396 0) ? "" : ((ep->nextpid ==
1397 USB_PID_IN) ? "in" : "out"),
1402 spin_unlock_irq(&isp116x->lock);
1403 seq_printf(s, "\n");
1408 static int proc_isp116x_open(struct inode *inode, struct file *file)
1410 return single_open(file, proc_isp116x_show, PDE(inode)->data);
1413 static struct file_operations proc_ops = {
1414 .open = proc_isp116x_open,
1416 .llseek = seq_lseek,
1417 .release = single_release,
1420 /* expect just one isp116x per system */
1421 static const char proc_filename[] = "driver/isp116x";
1423 static void create_debug_file(struct isp116x *isp116x)
1425 struct proc_dir_entry *pde;
1427 pde = create_proc_entry(proc_filename, 0, NULL);
1431 pde->proc_fops = &proc_ops;
1432 pde->data = isp116x;
1436 static void remove_debug_file(struct isp116x *isp116x)
1439 remove_proc_entry(proc_filename, NULL);
1444 /*-----------------------------------------------------------------*/
1447 Software reset - can be called from any contect.
1449 static int isp116x_sw_reset(struct isp116x *isp116x)
1452 unsigned long flags;
1455 spin_lock_irqsave(&isp116x->lock, flags);
1456 isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC);
1457 isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR);
1459 /* It usually resets within 1 ms */
1461 if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR))
1465 ERR("Software reset timeout\n");
1468 spin_unlock_irqrestore(&isp116x->lock, flags);
1472 static int isp116x_reset(struct usb_hcd *hcd)
1474 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1477 int ret = 0, timeout = 15 /* ms */ ;
1479 ret = isp116x_sw_reset(isp116x);
1483 t = jiffies + msecs_to_jiffies(timeout);
1484 while (time_before_eq(jiffies, t)) {
1486 spin_lock_irq(&isp116x->lock);
1487 clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY;
1488 spin_unlock_irq(&isp116x->lock);
1493 ERR("Clock not ready after 20ms\n");
1494 /* After sw_reset the clock won't report to be ready, if
1495 H_WAKEUP pin is high. */
1496 ERR("Please make sure that the H_WAKEUP pin is pulled low!\n");
1502 static void isp116x_stop(struct usb_hcd *hcd)
1504 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1505 unsigned long flags;
1508 spin_lock_irqsave(&isp116x->lock, flags);
1509 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1511 /* Switch off ports' power, some devices don't come up
1512 after next 'insmod' without this */
1513 val = isp116x_read_reg32(isp116x, HCRHDESCA);
1514 val &= ~(RH_A_NPS | RH_A_PSM);
1515 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1516 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
1517 spin_unlock_irqrestore(&isp116x->lock, flags);
1519 isp116x_sw_reset(isp116x);
1523 Configure the chip. The chip must be successfully reset by now.
1525 static int isp116x_start(struct usb_hcd *hcd)
1527 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1528 struct isp116x_platform_data *board = isp116x->board;
1530 unsigned long flags;
1532 spin_lock_irqsave(&isp116x->lock, flags);
1534 /* clear interrupt status and disable all interrupt sources */
1535 isp116x_write_reg16(isp116x, HCuPINT, 0xff);
1536 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1538 val = isp116x_read_reg16(isp116x, HCCHIPID);
1539 if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
1540 ERR("Invalid chip ID %04x\n", val);
1541 spin_unlock_irqrestore(&isp116x->lock, flags);
1545 /* To be removed in future */
1546 hcd->uses_new_polling = 1;
1548 isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
1549 isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
1552 val = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
1553 if (board->sel15Kres)
1554 val |= HCHWCFG_15KRSEL;
1555 /* Remote wakeup won't work without working clock */
1556 if (board->remote_wakeup_enable)
1557 val |= HCHWCFG_CLKNOTSTOP;
1558 if (board->oc_enable)
1559 val |= HCHWCFG_ANALOG_OC;
1560 if (board->int_act_high)
1561 val |= HCHWCFG_INT_POL;
1562 if (board->int_edge_triggered)
1563 val |= HCHWCFG_INT_TRIGGER;
1564 isp116x_write_reg16(isp116x, HCHWCFG, val);
1566 /* ----- Root hub conf */
1567 val = (25 << 24) & RH_A_POTPGT;
1568 /* AN10003_1.pdf recommends RH_A_NPS (no power switching) to
1569 be always set. Yet, instead, we request individual port
1572 /* Report overcurrent per port */
1574 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1575 isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
1578 isp116x_write_reg32(isp116x, HCRHDESCB, val);
1579 isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB);
1582 if (board->remote_wakeup_enable) {
1583 hcd->can_wakeup = 1;
1586 isp116x_write_reg32(isp116x, HCRHSTATUS, val);
1587 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
1589 isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf);
1591 hcd->state = HC_STATE_RUNNING;
1593 /* Set up interrupts */
1594 isp116x->intenb = HCINT_MIE | HCINT_RHSC | HCINT_UE;
1595 if (board->remote_wakeup_enable)
1596 isp116x->intenb |= HCINT_RD;
1597 isp116x->irqenb = HCuPINT_ATL | HCuPINT_OPR; /* | HCuPINT_SUSP; */
1598 isp116x_write_reg32(isp116x, HCINTENB, isp116x->intenb);
1599 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
1601 /* Go operational */
1602 val = HCCONTROL_USB_OPER;
1603 if (board->remote_wakeup_enable)
1604 val |= HCCONTROL_RWE;
1605 isp116x_write_reg32(isp116x, HCCONTROL, val);
1607 /* Disable ports to avoid race in device enumeration */
1608 isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS);
1609 isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS);
1611 isp116x_show_regs(isp116x);
1612 spin_unlock_irqrestore(&isp116x->lock, flags);
1616 /*-----------------------------------------------------------------*/
1618 static struct hc_driver isp116x_hc_driver = {
1619 .description = hcd_name,
1620 .product_desc = "ISP116x Host Controller",
1621 .hcd_priv_size = sizeof(struct isp116x),
1626 .reset = isp116x_reset,
1627 .start = isp116x_start,
1628 .stop = isp116x_stop,
1630 .urb_enqueue = isp116x_urb_enqueue,
1631 .urb_dequeue = isp116x_urb_dequeue,
1632 .endpoint_disable = isp116x_endpoint_disable,
1634 .get_frame_number = isp116x_get_frame,
1636 .hub_status_data = isp116x_hub_status_data,
1637 .hub_control = isp116x_hub_control,
1638 .hub_suspend = isp116x_hub_suspend,
1639 .hub_resume = isp116x_hub_resume,
1642 /*----------------------------------------------------------------*/
1644 static int __init_or_module isp116x_remove(struct device *dev)
1646 struct usb_hcd *hcd = dev_get_drvdata(dev);
1647 struct isp116x *isp116x;
1648 struct platform_device *pdev;
1649 struct resource *res;
1653 isp116x = hcd_to_isp116x(hcd);
1654 pdev = container_of(dev, struct platform_device, dev);
1655 remove_debug_file(isp116x);
1656 usb_remove_hcd(hcd);
1658 iounmap(isp116x->data_reg);
1659 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1660 release_mem_region(res->start, 2);
1661 iounmap(isp116x->addr_reg);
1662 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1663 release_mem_region(res->start, 2);
1669 #define resource_len(r) (((r)->end - (r)->start) + 1)
1671 static int __init isp116x_probe(struct device *dev)
1673 struct usb_hcd *hcd;
1674 struct isp116x *isp116x;
1675 struct platform_device *pdev;
1676 struct resource *addr, *data;
1677 void __iomem *addr_reg;
1678 void __iomem *data_reg;
1682 pdev = container_of(dev, struct platform_device, dev);
1683 if (pdev->num_resources < 3) {
1688 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1689 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1690 irq = platform_get_irq(pdev, 0);
1691 if (!addr || !data || irq < 0) {
1696 if (dev->dma_mask) {
1697 DBG("DMA not supported\n");
1702 if (!request_mem_region(addr->start, 2, hcd_name)) {
1706 addr_reg = ioremap(addr->start, resource_len(addr));
1707 if (addr_reg == NULL) {
1711 if (!request_mem_region(data->start, 2, hcd_name)) {
1715 data_reg = ioremap(data->start, resource_len(data));
1716 if (data_reg == NULL) {
1721 /* allocate and initialize hcd */
1722 hcd = usb_create_hcd(&isp116x_hc_driver, dev, dev->bus_id);
1727 /* this rsrc_start is bogus */
1728 hcd->rsrc_start = addr->start;
1729 isp116x = hcd_to_isp116x(hcd);
1730 isp116x->data_reg = data_reg;
1731 isp116x->addr_reg = addr_reg;
1732 spin_lock_init(&isp116x->lock);
1733 INIT_LIST_HEAD(&isp116x->async);
1734 INIT_WORK(&isp116x->rh_resume, isp116x_rh_resume, hcd);
1735 isp116x->board = dev->platform_data;
1737 if (!isp116x->board) {
1738 ERR("Platform data structure not initialized\n");
1742 if (isp116x_check_platform_delay(isp116x)) {
1743 ERR("USE_PLATFORM_DELAY defined, but delay function not "
1745 ERR("See comments in drivers/usb/host/isp116x-hcd.c\n");
1750 ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
1754 create_debug_file(isp116x);
1762 release_mem_region(data->start, 2);
1766 release_mem_region(addr->start, 2);
1768 ERR("init error, %d\n", ret);
1774 Suspend of platform device
1776 static int isp116x_suspend(struct device *dev, pm_message_t state, u32 phase)
1779 struct usb_hcd *hcd = dev_get_drvdata(dev);
1781 VDBG("%s: state %x, phase %x\n", __func__, state, phase);
1783 if (phase != SUSPEND_DISABLE && phase != SUSPEND_POWER_DOWN)
1786 ret = usb_suspend_device(hcd->self.root_hub, state);
1788 dev->power.power_state = state;
1789 INFO("%s suspended\n", hcd_name);
1791 ERR("%s suspend failed\n", hcd_name);
1797 Resume platform device
1799 static int isp116x_resume(struct device *dev, u32 phase)
1802 struct usb_hcd *hcd = dev_get_drvdata(dev);
1804 VDBG("%s: state %x, phase %x\n", __func__, dev->power.power_state,
1806 if (phase != RESUME_POWER_ON)
1809 ret = usb_resume_device(hcd->self.root_hub);
1811 dev->power.power_state = PMSG_ON;
1812 VDBG("%s resumed\n", (char *)hcd_name);
1819 #define isp116x_suspend NULL
1820 #define isp116x_resume NULL
1824 static struct device_driver isp116x_driver = {
1825 .name = (char *)hcd_name,
1826 .bus = &platform_bus_type,
1827 .probe = isp116x_probe,
1828 .remove = isp116x_remove,
1829 .suspend = isp116x_suspend,
1830 .resume = isp116x_resume,
1833 /*-----------------------------------------------------------------*/
1835 static int __init isp116x_init(void)
1840 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1841 return driver_register(&isp116x_driver);
1844 module_init(isp116x_init);
1846 static void __exit isp116x_cleanup(void)
1848 driver_unregister(&isp116x_driver);
1851 module_exit(isp116x_cleanup);