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));
330 urb->actual_length += PTD_GET_COUNT(ptd);
331 urb->status = cc_to_error[TD_DATAUNDERRUN];
332 spin_unlock(&urb->lock);
336 /* Keep underrun error through the STATUS stage */
337 if (urb->status == cc_to_error[TD_DATAUNDERRUN])
338 cc = TD_DATAUNDERRUN;
340 if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED
341 && (++ep->error_count >= 3 || cc == TD_CC_STALL
342 || cc == TD_DATAOVERRUN)) {
343 if (urb->status == -EINPROGRESS)
344 urb->status = cc_to_error[cc];
345 if (ep->nextpid == USB_PID_ACK)
347 spin_unlock(&urb->lock);
350 /* According to usb spec, zero-length Int transfer signals
351 finishing of the urb. Hey, does this apply only
353 if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) {
354 if (urb->status == -EINPROGRESS)
356 spin_unlock(&urb->lock);
360 /* Relax after previously failed, but later succeeded
361 or correctly NAK'ed retransmission attempt */
363 && (cc == TD_CC_NOERROR || cc == TD_NOTACCESSED))
366 /* Take into account idiosyncracies of the isp116x chip
367 regarding toggle bit for failed transfers */
368 if (ep->nextpid == USB_PID_OUT)
369 usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd)
370 ^ (ep->error_count > 0));
371 else if (ep->nextpid == USB_PID_IN)
372 usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd)
373 ^ (ep->error_count > 0));
375 switch (ep->nextpid) {
378 urb->actual_length += PTD_GET_COUNT(ptd);
379 if (PTD_GET_ACTIVE(ptd)
380 || (cc != TD_CC_NOERROR && cc < 0x0E))
382 if (urb->transfer_buffer_length != urb->actual_length) {
386 if (urb->transfer_flags & URB_ZERO_PACKET
387 && ep->nextpid == USB_PID_OUT
388 && !(PTD_GET_COUNT(ptd) % ep->maxpacket)) {
389 DBG("Zero packet requested\n");
393 /* All data for this URB is transferred, let's finish */
394 if (usb_pipecontrol(urb->pipe))
395 ep->nextpid = USB_PID_ACK;
396 else if (urb->status == -EINPROGRESS)
400 if (PTD_GET_ACTIVE(ptd)
401 || (cc != TD_CC_NOERROR && cc < 0x0E))
403 if (urb->transfer_buffer_length == urb->actual_length)
404 ep->nextpid = USB_PID_ACK;
405 else if (usb_pipeout(urb->pipe)) {
406 usb_settoggle(udev, 0, 1, 1);
407 ep->nextpid = USB_PID_OUT;
409 usb_settoggle(udev, 0, 0, 1);
410 ep->nextpid = USB_PID_IN;
414 if (PTD_GET_ACTIVE(ptd)
415 || (cc != TD_CC_NOERROR && cc < 0x0E))
417 if (urb->status == -EINPROGRESS)
424 spin_unlock(&urb->lock);
429 Take done or failed requests out of schedule. Give back
432 static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
433 struct urb *urb, struct pt_regs *regs)
434 __releases(isp116x->lock) __acquires(isp116x->lock)
441 if (usb_pipecontrol(urb->pipe))
442 ep->nextpid = USB_PID_SETUP;
444 urb_dbg(urb, "Finish");
446 spin_unlock(&isp116x->lock);
447 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb, regs);
448 spin_lock(&isp116x->lock);
450 /* take idle endpoints out of the schedule */
451 if (!list_empty(&ep->hep->urb_list))
454 /* async deschedule */
455 if (!list_empty(&ep->schedule)) {
456 list_del_init(&ep->schedule);
460 /* periodic deschedule */
461 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
462 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
463 struct isp116x_ep *temp;
464 struct isp116x_ep **prev = &isp116x->periodic[i];
466 while (*prev && ((temp = *prev) != ep))
470 isp116x->load[i] -= ep->load;
472 ep->branch = PERIODIC_SIZE;
473 isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
474 ep->load / ep->period;
476 /* switch irq type? */
477 if (!--isp116x->periodic_count) {
478 isp116x->irqenb &= ~HCuPINT_SOF;
479 isp116x->irqenb |= HCuPINT_ATL;
484 Scan transfer lists, schedule transfers, send data off
487 static void start_atl_transfers(struct isp116x *isp116x)
489 struct isp116x_ep *last_ep = NULL, *ep;
492 int len, index, speed, byte_time;
494 if (atomic_read(&isp116x->atl_finishing))
497 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state))
500 /* FIFO not empty? */
501 if (isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_FULL)
504 isp116x->atl_active = NULL;
505 isp116x->atl_buflen = isp116x->atl_bufshrt = 0;
507 /* Schedule int transfers */
508 if (isp116x->periodic_count) {
509 isp116x->fmindex = index =
510 (isp116x->fmindex + 1) & (PERIODIC_SIZE - 1);
511 if ((load = isp116x->load[index])) {
512 /* Bring all int transfers for this frame
513 into the active queue */
514 isp116x->atl_active = last_ep =
515 isp116x->periodic[index];
516 while (last_ep->next)
517 last_ep = (last_ep->active = last_ep->next);
518 last_ep->active = NULL;
522 /* Schedule control/bulk transfers */
523 list_for_each_entry(ep, &isp116x->async, schedule) {
524 urb = container_of(ep->hep->urb_list.next,
525 struct urb, urb_list);
526 speed = urb->dev->speed;
527 byte_time = speed == USB_SPEED_LOW
528 ? BYTE_TIME_LOWSPEED : BYTE_TIME_FULLSPEED;
530 if (ep->nextpid == USB_PID_SETUP) {
531 len = sizeof(struct usb_ctrlrequest);
532 } else if (ep->nextpid == USB_PID_ACK) {
535 /* Find current free length ... */
536 len = (MAX_LOAD_LIMIT - load) / byte_time;
538 /* ... then limit it to configured max size ... */
539 len = min(len, speed == USB_SPEED_LOW ?
540 MAX_TRANSFER_SIZE_LOWSPEED :
541 MAX_TRANSFER_SIZE_FULLSPEED);
543 /* ... and finally cut to the multiple of MaxPacketSize,
544 or to the real length if there's enough room. */
546 (urb->transfer_buffer_length -
547 urb->actual_length)) {
548 len -= len % ep->maxpacket;
552 len = urb->transfer_buffer_length -
557 load += len * byte_time;
558 if (load > MAX_LOAD_LIMIT)
564 last_ep->active = ep;
566 isp116x->atl_active = ep;
570 /* Avoid starving of endpoints */
571 if ((&isp116x->async)->next != (&isp116x->async)->prev)
572 list_move(&isp116x->async, (&isp116x->async)->next);
574 if (isp116x->atl_active) {
575 preproc_atl_queue(isp116x);
581 Finish the processed transfers
583 static void finish_atl_transfers(struct isp116x *isp116x, struct pt_regs *regs)
585 struct isp116x_ep *ep;
588 if (!isp116x->atl_active)
590 /* Fifo not ready? */
591 if (!(isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_DONE))
594 atomic_inc(&isp116x->atl_finishing);
595 unpack_fifo(isp116x);
596 postproc_atl_queue(isp116x);
597 for (ep = isp116x->atl_active; ep; ep = ep->active) {
599 container_of(ep->hep->urb_list.next, struct urb, urb_list);
600 /* USB_PID_ACK check here avoids finishing of
601 control transfers, for which TD_DATAUNDERRUN
602 occured, while URB_SHORT_NOT_OK was set */
603 if (urb && urb->status != -EINPROGRESS
604 && ep->nextpid != USB_PID_ACK)
605 finish_request(isp116x, ep, urb, regs);
607 atomic_dec(&isp116x->atl_finishing);
610 static irqreturn_t isp116x_irq(struct usb_hcd *hcd, struct pt_regs *regs)
612 struct isp116x *isp116x = hcd_to_isp116x(hcd);
614 irqreturn_t ret = IRQ_NONE;
616 spin_lock(&isp116x->lock);
617 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
618 irqstat = isp116x_read_reg16(isp116x, HCuPINT);
619 isp116x_write_reg16(isp116x, HCuPINT, irqstat);
621 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
623 finish_atl_transfers(isp116x, regs);
626 if (irqstat & HCuPINT_OPR) {
627 u32 intstat = isp116x_read_reg32(isp116x, HCINTSTAT);
628 isp116x_write_reg32(isp116x, HCINTSTAT, intstat);
629 if (intstat & HCINT_UE) {
630 ERR("Unrecoverable error\n");
631 /* What should we do here? Reset? */
633 if (intstat & HCINT_RHSC)
634 /* When root hub or any of its ports is going
635 to come out of suspend, it may take more
636 than 10ms for status bits to stabilize. */
637 mod_timer(&hcd->rh_timer, jiffies
638 + msecs_to_jiffies(20) + 1);
639 if (intstat & HCINT_RD) {
640 DBG("---- remote wakeup\n");
641 usb_hcd_resume_root_hub(hcd);
644 irqstat &= ~HCuPINT_OPR;
648 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
649 start_atl_transfers(isp116x);
652 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
653 spin_unlock(&isp116x->lock);
657 /*-----------------------------------------------------------------*/
659 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
660 * this driver doesn't promise that much since it's got to handle an
661 * IRQ per packet; irq handling latencies also use up that time.
665 #define MAX_PERIODIC_LOAD 600
666 static int balance(struct isp116x *isp116x, u16 period, u16 load)
668 int i, branch = -ENOSPC;
670 /* search for the least loaded schedule branch of that period
671 which has enough bandwidth left unreserved. */
672 for (i = 0; i < period; i++) {
673 if (branch < 0 || isp116x->load[branch] > isp116x->load[i]) {
676 for (j = i; j < PERIODIC_SIZE; j += period) {
677 if ((isp116x->load[j] + load)
681 if (j < PERIODIC_SIZE)
689 /* NB! ALL the code above this point runs with isp116x->lock
693 /*-----------------------------------------------------------------*/
695 static int isp116x_urb_enqueue(struct usb_hcd *hcd,
696 struct usb_host_endpoint *hep, struct urb *urb,
699 struct isp116x *isp116x = hcd_to_isp116x(hcd);
700 struct usb_device *udev = urb->dev;
701 unsigned int pipe = urb->pipe;
702 int is_out = !usb_pipein(pipe);
703 int type = usb_pipetype(pipe);
704 int epnum = usb_pipeendpoint(pipe);
705 struct isp116x_ep *ep = NULL;
710 urb_dbg(urb, "Enqueue");
712 if (type == PIPE_ISOCHRONOUS) {
713 ERR("Isochronous transfers not supported\n");
714 urb_dbg(urb, "Refused to enqueue");
717 /* avoid all allocations within spinlocks: request or endpoint */
719 ep = kzalloc(sizeof *ep, mem_flags);
724 spin_lock_irqsave(&isp116x->lock, flags);
725 if (!HC_IS_RUNNING(hcd->state)) {
733 INIT_LIST_HEAD(&ep->schedule);
734 ep->udev = usb_get_dev(udev);
736 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
737 usb_settoggle(udev, epnum, is_out, 0);
739 if (type == PIPE_CONTROL) {
740 ep->nextpid = USB_PID_SETUP;
742 ep->nextpid = USB_PID_OUT;
744 ep->nextpid = USB_PID_IN;
749 With INT URBs submitted, the driver works with SOF
750 interrupt enabled and ATL interrupt disabled. After
751 the PTDs are written to fifo ram, the chip starts
752 fifo processing and usb transfers after the next
753 SOF and continues until the transfers are finished
754 (succeeded or failed) or the frame ends. Therefore,
755 the transfers occur only in every second frame,
756 while fifo reading/writing and data processing
757 occur in every other second frame. */
758 if (urb->interval < 2)
760 if (urb->interval > 2 * PERIODIC_SIZE)
761 urb->interval = 2 * PERIODIC_SIZE;
762 ep->period = urb->interval >> 1;
763 ep->branch = PERIODIC_SIZE;
764 ep->load = usb_calc_bus_time(udev->speed,
766 (type == PIPE_ISOCHRONOUS),
767 usb_maxpacket(udev, pipe,
775 /* maybe put endpoint into schedule */
779 if (list_empty(&ep->schedule))
780 list_add_tail(&ep->schedule, &isp116x->async);
783 urb->interval = ep->period;
784 ep->length = min((int)ep->maxpacket,
785 urb->transfer_buffer_length);
787 /* urb submitted for already existing endpoint */
788 if (ep->branch < PERIODIC_SIZE)
791 ret = ep->branch = balance(isp116x, ep->period, ep->load);
796 urb->start_frame = (isp116x->fmindex & (PERIODIC_SIZE - 1))
799 /* sort each schedule branch by period (slow before fast)
800 to share the faster parts of the tree without needing
801 dummy/placeholder nodes */
802 DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
803 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
804 struct isp116x_ep **prev = &isp116x->periodic[i];
805 struct isp116x_ep *here = *prev;
807 while (here && ep != here) {
808 if (ep->period > here->period)
817 isp116x->load[i] += ep->load;
819 hcd->self.bandwidth_allocated += ep->load / ep->period;
821 /* switch over to SOFint */
822 if (!isp116x->periodic_count++) {
823 isp116x->irqenb &= ~HCuPINT_ATL;
824 isp116x->irqenb |= HCuPINT_SOF;
825 isp116x_write_reg16(isp116x, HCuPINTENB,
830 /* in case of unlink-during-submit */
831 spin_lock(&urb->lock);
832 if (urb->status != -EINPROGRESS) {
833 spin_unlock(&urb->lock);
834 finish_request(isp116x, ep, urb, NULL);
839 spin_unlock(&urb->lock);
840 start_atl_transfers(isp116x);
843 spin_unlock_irqrestore(&isp116x->lock, flags);
850 static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
852 struct isp116x *isp116x = hcd_to_isp116x(hcd);
853 struct usb_host_endpoint *hep;
854 struct isp116x_ep *ep, *ep_act;
857 spin_lock_irqsave(&isp116x->lock, flags);
859 /* URB already unlinked (or never linked)? */
861 spin_unlock_irqrestore(&isp116x->lock, flags);
865 WARN_ON(hep != ep->hep);
867 /* In front of queue? */
868 if (ep->hep->urb_list.next == &urb->urb_list)
870 for (ep_act = isp116x->atl_active; ep_act;
871 ep_act = ep_act->active)
873 VDBG("dequeue, urb %p active; wait for irq\n",
880 finish_request(isp116x, ep, urb, NULL);
882 spin_unlock_irqrestore(&isp116x->lock, flags);
886 static void isp116x_endpoint_disable(struct usb_hcd *hcd,
887 struct usb_host_endpoint *hep)
890 struct isp116x_ep *ep = hep->hcpriv;;
895 /* assume we'd just wait for the irq */
896 for (i = 0; i < 100 && !list_empty(&hep->urb_list); i++)
898 if (!list_empty(&hep->urb_list))
899 WARN("ep %p not empty?\n", ep);
901 usb_put_dev(ep->udev);
906 static int isp116x_get_frame(struct usb_hcd *hcd)
908 struct isp116x *isp116x = hcd_to_isp116x(hcd);
912 spin_lock_irqsave(&isp116x->lock, flags);
913 fmnum = isp116x_read_reg32(isp116x, HCFMNUM);
914 spin_unlock_irqrestore(&isp116x->lock, flags);
918 /*----------------------------------------------------------------*/
921 Adapted from ohci-hub.c. Currently we don't support autosuspend.
923 static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
925 struct isp116x *isp116x = hcd_to_isp116x(hcd);
926 int ports, i, changed = 0;
929 if (!HC_IS_RUNNING(hcd->state))
932 /* Report no status change now, if we are scheduled to be
934 if (timer_pending(&hcd->rh_timer))
937 ports = isp116x->rhdesca & RH_A_NDP;
938 spin_lock_irqsave(&isp116x->lock, flags);
939 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
940 if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
941 buf[0] = changed = 1;
945 for (i = 0; i < ports; i++) {
946 u32 status = isp116x->rhport[i] =
947 isp116x_read_reg32(isp116x, i ? HCRHPORT2 : HCRHPORT1);
949 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
950 | RH_PS_OCIC | RH_PS_PRSC)) {
952 buf[0] |= 1 << (i + 1);
956 spin_unlock_irqrestore(&isp116x->lock, flags);
960 static void isp116x_hub_descriptor(struct isp116x *isp116x,
961 struct usb_hub_descriptor *desc)
963 u32 reg = isp116x->rhdesca;
965 desc->bDescriptorType = 0x29;
966 desc->bDescLength = 9;
967 desc->bHubContrCurrent = 0;
968 desc->bNbrPorts = (u8) (reg & 0x3);
969 /* Power switching, device type, overcurrent. */
970 desc->wHubCharacteristics =
971 (__force __u16) cpu_to_le16((u16) ((reg >> 8) & 0x1f));
972 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff);
973 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
974 desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
975 desc->bitmap[1] = ~0;
978 /* Perform reset of a given port.
979 It would be great to just start the reset and let the
980 USB core to clear the reset in due time. However,
981 root hub ports should be reset for at least 50 ms, while
982 our chip stays in reset for about 10 ms. I.e., we must
983 repeatedly reset it ourself here.
985 static inline void root_port_reset(struct isp116x *isp116x, unsigned port)
988 unsigned long flags, t;
990 /* Root hub reset should be 50 ms, but some devices
991 want it even longer. */
992 t = jiffies + msecs_to_jiffies(100);
994 while (time_before(jiffies, t)) {
995 spin_lock_irqsave(&isp116x->lock, flags);
996 /* spin until any current reset finishes */
998 tmp = isp116x_read_reg32(isp116x, port ?
999 HCRHPORT2 : HCRHPORT1);
1000 if (!(tmp & RH_PS_PRS))
1004 /* Don't reset a disconnected port */
1005 if (!(tmp & RH_PS_CCS)) {
1006 spin_unlock_irqrestore(&isp116x->lock, flags);
1009 /* Reset lasts 10ms (claims datasheet) */
1010 isp116x_write_reg32(isp116x, port ? HCRHPORT2 :
1011 HCRHPORT1, (RH_PS_PRS));
1012 spin_unlock_irqrestore(&isp116x->lock, flags);
1017 /* Adapted from ohci-hub.c */
1018 static int isp116x_hub_control(struct usb_hcd *hcd,
1020 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1022 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1024 unsigned long flags;
1025 int ports = isp116x->rhdesca & RH_A_NDP;
1029 case ClearHubFeature:
1030 DBG("ClearHubFeature: ");
1032 case C_HUB_OVER_CURRENT:
1033 DBG("C_HUB_OVER_CURRENT\n");
1034 spin_lock_irqsave(&isp116x->lock, flags);
1035 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_OCIC);
1036 spin_unlock_irqrestore(&isp116x->lock, flags);
1037 case C_HUB_LOCAL_POWER:
1038 DBG("C_HUB_LOCAL_POWER\n");
1045 DBG("SetHubFeature: ");
1047 case C_HUB_OVER_CURRENT:
1048 case C_HUB_LOCAL_POWER:
1049 DBG("C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1055 case GetHubDescriptor:
1056 DBG("GetHubDescriptor\n");
1057 isp116x_hub_descriptor(isp116x,
1058 (struct usb_hub_descriptor *)buf);
1061 DBG("GetHubStatus\n");
1062 *(__le32 *) buf = 0;
1065 DBG("GetPortStatus\n");
1066 if (!wIndex || wIndex > ports)
1068 tmp = isp116x->rhport[--wIndex];
1069 *(__le32 *) buf = cpu_to_le32(tmp);
1070 DBG("GetPortStatus: port[%d] %08x\n", wIndex + 1, tmp);
1072 case ClearPortFeature:
1073 DBG("ClearPortFeature: ");
1074 if (!wIndex || wIndex > ports)
1079 case USB_PORT_FEAT_ENABLE:
1080 DBG("USB_PORT_FEAT_ENABLE\n");
1083 case USB_PORT_FEAT_C_ENABLE:
1084 DBG("USB_PORT_FEAT_C_ENABLE\n");
1087 case USB_PORT_FEAT_SUSPEND:
1088 DBG("USB_PORT_FEAT_SUSPEND\n");
1091 case USB_PORT_FEAT_C_SUSPEND:
1092 DBG("USB_PORT_FEAT_C_SUSPEND\n");
1095 case USB_PORT_FEAT_POWER:
1096 DBG("USB_PORT_FEAT_POWER\n");
1099 case USB_PORT_FEAT_C_CONNECTION:
1100 DBG("USB_PORT_FEAT_C_CONNECTION\n");
1103 case USB_PORT_FEAT_C_OVER_CURRENT:
1104 DBG("USB_PORT_FEAT_C_OVER_CURRENT\n");
1107 case USB_PORT_FEAT_C_RESET:
1108 DBG("USB_PORT_FEAT_C_RESET\n");
1114 spin_lock_irqsave(&isp116x->lock, flags);
1115 isp116x_write_reg32(isp116x, wIndex
1116 ? HCRHPORT2 : HCRHPORT1, tmp);
1117 isp116x->rhport[wIndex] =
1118 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1119 spin_unlock_irqrestore(&isp116x->lock, flags);
1121 case SetPortFeature:
1122 DBG("SetPortFeature: ");
1123 if (!wIndex || wIndex > ports)
1127 case USB_PORT_FEAT_SUSPEND:
1128 DBG("USB_PORT_FEAT_SUSPEND\n");
1129 spin_lock_irqsave(&isp116x->lock, flags);
1130 isp116x_write_reg32(isp116x, wIndex
1131 ? HCRHPORT2 : HCRHPORT1, RH_PS_PSS);
1133 case USB_PORT_FEAT_POWER:
1134 DBG("USB_PORT_FEAT_POWER\n");
1135 spin_lock_irqsave(&isp116x->lock, flags);
1136 isp116x_write_reg32(isp116x, wIndex
1137 ? HCRHPORT2 : HCRHPORT1, RH_PS_PPS);
1139 case USB_PORT_FEAT_RESET:
1140 DBG("USB_PORT_FEAT_RESET\n");
1141 root_port_reset(isp116x, wIndex);
1142 spin_lock_irqsave(&isp116x->lock, flags);
1147 isp116x->rhport[wIndex] =
1148 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1149 spin_unlock_irqrestore(&isp116x->lock, flags);
1154 /* "protocol stall" on error */
1155 DBG("PROTOCOL STALL\n");
1163 static int isp116x_bus_suspend(struct usb_hcd *hcd)
1165 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1166 unsigned long flags;
1170 spin_lock_irqsave(&isp116x->lock, flags);
1172 val = isp116x_read_reg32(isp116x, HCCONTROL);
1173 switch (val & HCCONTROL_HCFS) {
1174 case HCCONTROL_USB_OPER:
1175 hcd->state = HC_STATE_QUIESCING;
1176 val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE);
1177 val |= HCCONTROL_USB_SUSPEND;
1178 if (hcd->remote_wakeup)
1179 val |= HCCONTROL_RWE;
1180 /* Wait for usb transfers to finish */
1182 isp116x_write_reg32(isp116x, HCCONTROL, val);
1183 hcd->state = HC_STATE_SUSPENDED;
1184 /* Wait for devices to suspend */
1186 case HCCONTROL_USB_SUSPEND:
1188 case HCCONTROL_USB_RESUME:
1189 isp116x_write_reg32(isp116x, HCCONTROL,
1190 (val & ~HCCONTROL_HCFS) |
1191 HCCONTROL_USB_RESET);
1192 case HCCONTROL_USB_RESET:
1199 spin_unlock_irqrestore(&isp116x->lock, flags);
1203 static int isp116x_bus_resume(struct usb_hcd *hcd)
1205 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1207 int ret = -EINPROGRESS;
1210 spin_lock_irq(&isp116x->lock);
1212 val = isp116x_read_reg32(isp116x, HCCONTROL);
1213 switch (val & HCCONTROL_HCFS) {
1214 case HCCONTROL_USB_SUSPEND:
1215 val &= ~HCCONTROL_HCFS;
1216 val |= HCCONTROL_USB_RESUME;
1217 isp116x_write_reg32(isp116x, HCCONTROL, val);
1218 case HCCONTROL_USB_RESUME:
1220 case HCCONTROL_USB_OPER:
1221 /* Without setting power_state here the
1222 SUSPENDED state won't be removed from
1223 sysfs/usbN/power.state as a response to remote
1224 wakeup. Maybe in the future. */
1225 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1232 if (ret != -EINPROGRESS) {
1233 spin_unlock_irq(&isp116x->lock);
1237 val = isp116x->rhdesca & RH_A_NDP;
1240 isp116x_read_reg32(isp116x, val ? HCRHPORT2 : HCRHPORT1);
1241 /* force global, not selective, resume */
1242 if (!(stat & RH_PS_PSS))
1244 DBG("%s: Resuming port %d\n", __func__, val);
1245 isp116x_write_reg32(isp116x, RH_PS_POCI, val
1246 ? HCRHPORT2 : HCRHPORT1);
1248 spin_unlock_irq(&isp116x->lock);
1250 hcd->state = HC_STATE_RESUMING;
1253 /* Go operational */
1254 spin_lock_irq(&isp116x->lock);
1255 val = isp116x_read_reg32(isp116x, HCCONTROL);
1256 isp116x_write_reg32(isp116x, HCCONTROL,
1257 (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER);
1258 spin_unlock_irq(&isp116x->lock);
1259 /* see analogous comment above */
1260 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1261 hcd->state = HC_STATE_RUNNING;
1269 #define isp116x_bus_suspend NULL
1270 #define isp116x_bus_resume NULL
1274 /*-----------------------------------------------------------------*/
1276 #ifdef STUB_DEBUG_FILE
1278 static inline void create_debug_file(struct isp116x *isp116x)
1282 static inline void remove_debug_file(struct isp116x *isp116x)
1288 #include <linux/proc_fs.h>
1289 #include <linux/seq_file.h>
1291 static void dump_irq(struct seq_file *s, char *label, u16 mask)
1293 seq_printf(s, "%s %04x%s%s%s%s%s%s\n", label, mask,
1294 mask & HCuPINT_CLKRDY ? " clkrdy" : "",
1295 mask & HCuPINT_SUSP ? " susp" : "",
1296 mask & HCuPINT_OPR ? " opr" : "",
1297 mask & HCuPINT_AIIEOT ? " eot" : "",
1298 mask & HCuPINT_ATL ? " atl" : "",
1299 mask & HCuPINT_SOF ? " sof" : "");
1302 static void dump_int(struct seq_file *s, char *label, u32 mask)
1304 seq_printf(s, "%s %08x%s%s%s%s%s%s%s\n", label, mask,
1305 mask & HCINT_MIE ? " MIE" : "",
1306 mask & HCINT_RHSC ? " rhsc" : "",
1307 mask & HCINT_FNO ? " fno" : "",
1308 mask & HCINT_UE ? " ue" : "",
1309 mask & HCINT_RD ? " rd" : "",
1310 mask & HCINT_SF ? " sof" : "", mask & HCINT_SO ? " so" : "");
1313 static int proc_isp116x_show(struct seq_file *s, void *unused)
1315 struct isp116x *isp116x = s->private;
1316 struct isp116x_ep *ep;
1321 seq_printf(s, "%s\n%s version %s\n",
1322 isp116x_to_hcd(isp116x)->product_desc, hcd_name,
1325 if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x)->state)) {
1326 seq_printf(s, "HCD is suspended\n");
1329 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) {
1330 seq_printf(s, "HCD not running\n");
1334 spin_lock_irq(&isp116x->lock);
1336 dump_irq(s, "hc_irq_enable", isp116x_read_reg16(isp116x, HCuPINTENB));
1337 dump_irq(s, "hc_irq_status", isp116x_read_reg16(isp116x, HCuPINT));
1338 dump_int(s, "hc_int_enable", isp116x_read_reg32(isp116x, HCINTENB));
1339 dump_int(s, "hc_int_status", isp116x_read_reg32(isp116x, HCINTSTAT));
1341 list_for_each_entry(ep, &isp116x->async, schedule) {
1343 switch (ep->nextpid) {
1360 seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep,
1361 ep->epnum, str, ep->maxpacket);
1362 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
1363 seq_printf(s, " urb%p, %d/%d\n", urb,
1365 urb->transfer_buffer_length);
1368 if (!list_empty(&isp116x->async))
1369 seq_printf(s, "\n");
1371 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1373 for (i = 0; i < PERIODIC_SIZE; i++) {
1374 ep = isp116x->periodic[i];
1377 seq_printf(s, "%2d [%3d]:\n", i, isp116x->load[i]);
1379 /* DUMB: prints shared entries multiple times */
1381 seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
1384 USB_SPEED_FULL) ? "" : "ls ",
1385 ep->udev->devnum, ep->epnum,
1387 0) ? "" : ((ep->nextpid ==
1388 USB_PID_IN) ? "in" : "out"),
1393 spin_unlock_irq(&isp116x->lock);
1394 seq_printf(s, "\n");
1399 static int proc_isp116x_open(struct inode *inode, struct file *file)
1401 return single_open(file, proc_isp116x_show, PDE(inode)->data);
1404 static struct file_operations proc_ops = {
1405 .open = proc_isp116x_open,
1407 .llseek = seq_lseek,
1408 .release = single_release,
1411 /* expect just one isp116x per system */
1412 static const char proc_filename[] = "driver/isp116x";
1414 static void create_debug_file(struct isp116x *isp116x)
1416 struct proc_dir_entry *pde;
1418 pde = create_proc_entry(proc_filename, 0, NULL);
1422 pde->proc_fops = &proc_ops;
1423 pde->data = isp116x;
1427 static void remove_debug_file(struct isp116x *isp116x)
1430 remove_proc_entry(proc_filename, NULL);
1435 /*-----------------------------------------------------------------*/
1438 Software reset - can be called from any contect.
1440 static int isp116x_sw_reset(struct isp116x *isp116x)
1443 unsigned long flags;
1446 spin_lock_irqsave(&isp116x->lock, flags);
1447 isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC);
1448 isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR);
1450 /* It usually resets within 1 ms */
1452 if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR))
1456 ERR("Software reset timeout\n");
1459 spin_unlock_irqrestore(&isp116x->lock, flags);
1463 static int isp116x_reset(struct usb_hcd *hcd)
1465 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1468 int ret = 0, timeout = 15 /* ms */ ;
1470 ret = isp116x_sw_reset(isp116x);
1474 t = jiffies + msecs_to_jiffies(timeout);
1475 while (time_before_eq(jiffies, t)) {
1477 spin_lock_irq(&isp116x->lock);
1478 clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY;
1479 spin_unlock_irq(&isp116x->lock);
1484 ERR("Clock not ready after 20ms\n");
1485 /* After sw_reset the clock won't report to be ready, if
1486 H_WAKEUP pin is high. */
1487 ERR("Please make sure that the H_WAKEUP pin is pulled low!\n");
1493 static void isp116x_stop(struct usb_hcd *hcd)
1495 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1496 unsigned long flags;
1499 spin_lock_irqsave(&isp116x->lock, flags);
1500 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1502 /* Switch off ports' power, some devices don't come up
1503 after next 'insmod' without this */
1504 val = isp116x_read_reg32(isp116x, HCRHDESCA);
1505 val &= ~(RH_A_NPS | RH_A_PSM);
1506 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1507 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
1508 spin_unlock_irqrestore(&isp116x->lock, flags);
1510 isp116x_sw_reset(isp116x);
1514 Configure the chip. The chip must be successfully reset by now.
1516 static int isp116x_start(struct usb_hcd *hcd)
1518 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1519 struct isp116x_platform_data *board = isp116x->board;
1521 unsigned long flags;
1523 spin_lock_irqsave(&isp116x->lock, flags);
1525 /* clear interrupt status and disable all interrupt sources */
1526 isp116x_write_reg16(isp116x, HCuPINT, 0xff);
1527 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1529 val = isp116x_read_reg16(isp116x, HCCHIPID);
1530 if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
1531 ERR("Invalid chip ID %04x\n", val);
1532 spin_unlock_irqrestore(&isp116x->lock, flags);
1536 /* To be removed in future */
1537 hcd->uses_new_polling = 1;
1539 isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
1540 isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
1543 val = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
1544 if (board->sel15Kres)
1545 val |= HCHWCFG_15KRSEL;
1546 /* Remote wakeup won't work without working clock */
1547 if (board->remote_wakeup_enable)
1548 val |= HCHWCFG_CLKNOTSTOP;
1549 if (board->oc_enable)
1550 val |= HCHWCFG_ANALOG_OC;
1551 if (board->int_act_high)
1552 val |= HCHWCFG_INT_POL;
1553 if (board->int_edge_triggered)
1554 val |= HCHWCFG_INT_TRIGGER;
1555 isp116x_write_reg16(isp116x, HCHWCFG, val);
1557 /* ----- Root hub conf */
1558 val = (25 << 24) & RH_A_POTPGT;
1559 /* AN10003_1.pdf recommends RH_A_NPS (no power switching) to
1560 be always set. Yet, instead, we request individual port
1563 /* Report overcurrent per port */
1565 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1566 isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
1569 isp116x_write_reg32(isp116x, HCRHDESCB, val);
1570 isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB);
1573 if (board->remote_wakeup_enable) {
1574 hcd->can_wakeup = 1;
1577 isp116x_write_reg32(isp116x, HCRHSTATUS, val);
1578 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
1580 isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf);
1582 hcd->state = HC_STATE_RUNNING;
1584 /* Set up interrupts */
1585 isp116x->intenb = HCINT_MIE | HCINT_RHSC | HCINT_UE;
1586 if (board->remote_wakeup_enable)
1587 isp116x->intenb |= HCINT_RD;
1588 isp116x->irqenb = HCuPINT_ATL | HCuPINT_OPR; /* | HCuPINT_SUSP; */
1589 isp116x_write_reg32(isp116x, HCINTENB, isp116x->intenb);
1590 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
1592 /* Go operational */
1593 val = HCCONTROL_USB_OPER;
1594 if (board->remote_wakeup_enable)
1595 val |= HCCONTROL_RWE;
1596 isp116x_write_reg32(isp116x, HCCONTROL, val);
1598 /* Disable ports to avoid race in device enumeration */
1599 isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS);
1600 isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS);
1602 isp116x_show_regs(isp116x);
1603 spin_unlock_irqrestore(&isp116x->lock, flags);
1607 /*-----------------------------------------------------------------*/
1609 static struct hc_driver isp116x_hc_driver = {
1610 .description = hcd_name,
1611 .product_desc = "ISP116x Host Controller",
1612 .hcd_priv_size = sizeof(struct isp116x),
1617 .reset = isp116x_reset,
1618 .start = isp116x_start,
1619 .stop = isp116x_stop,
1621 .urb_enqueue = isp116x_urb_enqueue,
1622 .urb_dequeue = isp116x_urb_dequeue,
1623 .endpoint_disable = isp116x_endpoint_disable,
1625 .get_frame_number = isp116x_get_frame,
1627 .hub_status_data = isp116x_hub_status_data,
1628 .hub_control = isp116x_hub_control,
1629 .bus_suspend = isp116x_bus_suspend,
1630 .bus_resume = isp116x_bus_resume,
1633 /*----------------------------------------------------------------*/
1635 static int __init_or_module isp116x_remove(struct device *dev)
1637 struct usb_hcd *hcd = dev_get_drvdata(dev);
1638 struct isp116x *isp116x;
1639 struct platform_device *pdev;
1640 struct resource *res;
1644 isp116x = hcd_to_isp116x(hcd);
1645 pdev = container_of(dev, struct platform_device, dev);
1646 remove_debug_file(isp116x);
1647 usb_remove_hcd(hcd);
1649 iounmap(isp116x->data_reg);
1650 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1651 release_mem_region(res->start, 2);
1652 iounmap(isp116x->addr_reg);
1653 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1654 release_mem_region(res->start, 2);
1660 #define resource_len(r) (((r)->end - (r)->start) + 1)
1662 static int __init isp116x_probe(struct device *dev)
1664 struct usb_hcd *hcd;
1665 struct isp116x *isp116x;
1666 struct platform_device *pdev;
1667 struct resource *addr, *data;
1668 void __iomem *addr_reg;
1669 void __iomem *data_reg;
1673 pdev = container_of(dev, struct platform_device, dev);
1674 if (pdev->num_resources < 3) {
1679 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1680 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1681 irq = platform_get_irq(pdev, 0);
1682 if (!addr || !data || irq < 0) {
1687 if (dev->dma_mask) {
1688 DBG("DMA not supported\n");
1693 if (!request_mem_region(addr->start, 2, hcd_name)) {
1697 addr_reg = ioremap(addr->start, resource_len(addr));
1698 if (addr_reg == NULL) {
1702 if (!request_mem_region(data->start, 2, hcd_name)) {
1706 data_reg = ioremap(data->start, resource_len(data));
1707 if (data_reg == NULL) {
1712 /* allocate and initialize hcd */
1713 hcd = usb_create_hcd(&isp116x_hc_driver, dev, dev->bus_id);
1718 /* this rsrc_start is bogus */
1719 hcd->rsrc_start = addr->start;
1720 isp116x = hcd_to_isp116x(hcd);
1721 isp116x->data_reg = data_reg;
1722 isp116x->addr_reg = addr_reg;
1723 spin_lock_init(&isp116x->lock);
1724 INIT_LIST_HEAD(&isp116x->async);
1725 isp116x->board = dev->platform_data;
1727 if (!isp116x->board) {
1728 ERR("Platform data structure not initialized\n");
1732 if (isp116x_check_platform_delay(isp116x)) {
1733 ERR("USE_PLATFORM_DELAY defined, but delay function not "
1735 ERR("See comments in drivers/usb/host/isp116x-hcd.c\n");
1740 ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
1744 create_debug_file(isp116x);
1752 release_mem_region(data->start, 2);
1756 release_mem_region(addr->start, 2);
1758 ERR("init error, %d\n", ret);
1764 Suspend of platform device
1766 static int isp116x_suspend(struct device *dev, pm_message_t state)
1770 VDBG("%s: state %x\n", __func__, state);
1772 dev->power.power_state = state;
1778 Resume platform device
1780 static int isp116x_resume(struct device *dev)
1784 VDBG("%s: state %x\n", __func__, dev->power.power_state);
1786 dev->power.power_state = PMSG_ON;
1793 #define isp116x_suspend NULL
1794 #define isp116x_resume NULL
1798 static struct device_driver isp116x_driver = {
1799 .name = (char *)hcd_name,
1800 .bus = &platform_bus_type,
1801 .probe = isp116x_probe,
1802 .remove = isp116x_remove,
1803 .suspend = isp116x_suspend,
1804 .resume = isp116x_resume,
1807 /*-----------------------------------------------------------------*/
1809 static int __init isp116x_init(void)
1814 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1815 return driver_register(&isp116x_driver);
1818 module_init(isp116x_init);
1820 static void __exit isp116x_cleanup(void)
1822 driver_unregister(&isp116x_driver);
1825 module_exit(isp116x_cleanup);