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>
73 #include <linux/platform_device.h>
77 #include <asm/system.h>
78 #include <asm/byteorder.h>
81 # define STUB_DEBUG_FILE
84 #include "../core/hcd.h"
87 #define DRIVER_VERSION "05 Aug 2005"
88 #define DRIVER_DESC "ISP116x USB Host Controller Driver"
90 MODULE_DESCRIPTION(DRIVER_DESC);
91 MODULE_LICENSE("GPL");
93 static const char hcd_name[] = "isp116x-hcd";
95 /*-----------------------------------------------------------------*/
98 Write len bytes to fifo, pad till 32-bit boundary
100 static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len)
103 u16 *dp2 = (u16 *) buf;
107 if ((unsigned long)dp2 & 1) {
109 for (; len > 1; len -= 2) {
112 isp116x_raw_write_data16(isp116x, w);
115 isp116x_write_data16(isp116x, (u16) * dp);
118 for (; len > 1; len -= 2)
119 isp116x_raw_write_data16(isp116x, *dp2++);
121 isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2));
123 if (quot == 1 || quot == 2)
124 isp116x_raw_write_data16(isp116x, 0);
128 Read len bytes from fifo and then read till 32-bit boundary.
130 static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len)
133 u16 *dp2 = (u16 *) buf;
137 if ((unsigned long)dp2 & 1) {
139 for (; len > 1; len -= 2) {
140 w = isp116x_raw_read_data16(isp116x);
142 *dp++ = (w >> 8) & 0xff;
145 *dp = 0xff & isp116x_read_data16(isp116x);
148 for (; len > 1; len -= 2)
149 *dp2++ = isp116x_raw_read_data16(isp116x);
151 *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x);
153 if (quot == 1 || quot == 2)
154 isp116x_raw_read_data16(isp116x);
158 Write ptd's and data for scheduled transfers into
159 the fifo ram. Fifo must be empty and ready.
161 static void pack_fifo(struct isp116x *isp116x)
163 struct isp116x_ep *ep;
165 int buflen = isp116x->atl_last_dir == PTD_DIR_IN
166 ? isp116x->atl_bufshrt : isp116x->atl_buflen;
169 isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
170 isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
171 isp116x_write_addr(isp116x, HCATLPORT | ISP116x_WRITE_OFFSET);
172 for (ep = isp116x->atl_active; ep; ep = ep->active) {
176 dump_ptd_out_data(ptd, ep->data);
177 isp116x_write_data16(isp116x, ptd->count);
178 isp116x_write_data16(isp116x, ptd->mps);
179 isp116x_write_data16(isp116x, ptd->len);
180 isp116x_write_data16(isp116x, ptd->faddr);
181 buflen -= sizeof(struct ptd);
182 /* Skip writing data for last IN PTD */
183 if (ep->active || (isp116x->atl_last_dir != PTD_DIR_IN)) {
184 write_ptddata_to_fifo(isp116x, ep->data, ep->length);
185 buflen -= ALIGN(ep->length, 4);
192 Read the processed ptd's and data from fifo ram back to
193 URBs' buffers. Fifo must be full and done
195 static void unpack_fifo(struct isp116x *isp116x)
197 struct isp116x_ep *ep;
199 int buflen = isp116x->atl_last_dir == PTD_DIR_IN
200 ? isp116x->atl_buflen : isp116x->atl_bufshrt;
202 isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
203 isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
204 isp116x_write_addr(isp116x, HCATLPORT);
205 for (ep = isp116x->atl_active; ep; ep = ep->active) {
207 ptd->count = isp116x_read_data16(isp116x);
208 ptd->mps = isp116x_read_data16(isp116x);
209 ptd->len = isp116x_read_data16(isp116x);
210 ptd->faddr = isp116x_read_data16(isp116x);
211 buflen -= sizeof(struct ptd);
212 /* Skip reading data for last Setup or Out PTD */
213 if (ep->active || (isp116x->atl_last_dir == PTD_DIR_IN)) {
214 read_ptddata_from_fifo(isp116x, ep->data, ep->length);
215 buflen -= ALIGN(ep->length, 4);
218 dump_ptd_in_data(ptd, ep->data);
223 /*---------------------------------------------------------------*/
228 static void preproc_atl_queue(struct isp116x *isp116x)
230 struct isp116x_ep *ep;
235 for (ep = isp116x->atl_active; ep; ep = ep->active) {
236 u16 toggle = 0, dir = PTD_DIR_SETUP;
238 BUG_ON(list_empty(&ep->hep->urb_list));
239 urb = container_of(ep->hep->urb_list.next,
240 struct urb, urb_list);
243 spin_lock(&urb->lock);
244 ep->data = (unsigned char *)urb->transfer_buffer
245 + urb->actual_length;
247 switch (ep->nextpid) {
249 toggle = usb_gettoggle(urb->dev, ep->epnum, 0);
253 toggle = usb_gettoggle(urb->dev, ep->epnum, 1);
257 len = sizeof(struct usb_ctrlrequest);
258 ep->data = urb->setup_packet;
263 dir = (urb->transfer_buffer_length
264 && usb_pipein(urb->pipe))
265 ? PTD_DIR_OUT : PTD_DIR_IN;
268 ERR("%s %d: ep->nextpid %d\n", __func__, __LINE__,
273 ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle);
274 ptd->mps = PTD_MPS(ep->maxpacket)
275 | PTD_SPD(urb->dev->speed == USB_SPEED_LOW)
277 ptd->len = PTD_LEN(len) | PTD_DIR(dir);
278 ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe));
279 spin_unlock(&urb->lock);
281 ptd->mps |= PTD_LAST_MSK;
282 isp116x->atl_last_dir = dir;
284 isp116x->atl_bufshrt = sizeof(struct ptd) + isp116x->atl_buflen;
285 isp116x->atl_buflen = isp116x->atl_bufshrt + ALIGN(len, 4);
290 Analyze transfer results, handle partial transfers and errors
292 static void postproc_atl_queue(struct isp116x *isp116x)
294 struct isp116x_ep *ep;
296 struct usb_device *udev;
301 for (ep = isp116x->atl_active; ep; ep = ep->active) {
302 BUG_ON(list_empty(&ep->hep->urb_list));
304 container_of(ep->hep->urb_list.next, struct urb, urb_list);
307 cc = PTD_GET_CC(ptd);
309 spin_lock(&urb->lock);
312 /* Data underrun is special. For allowed underrun
313 we clear the error and continue as normal. For
314 forbidden underrun we finish the DATA stage
315 immediately while for control transfer,
316 we do a STATUS stage. */
317 if (cc == TD_DATAUNDERRUN) {
318 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) {
319 DBG("Allowed data underrun\n");
324 if (usb_pipecontrol(urb->pipe))
325 ep->nextpid = USB_PID_ACK;
327 usb_settoggle(udev, ep->epnum,
330 PTD_GET_TOGGLE(ptd));
331 urb->actual_length += PTD_GET_COUNT(ptd);
332 urb->status = cc_to_error[TD_DATAUNDERRUN];
333 spin_unlock(&urb->lock);
337 /* Keep underrun error through the STATUS stage */
338 if (urb->status == cc_to_error[TD_DATAUNDERRUN])
339 cc = TD_DATAUNDERRUN;
341 if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED
342 && (++ep->error_count >= 3 || cc == TD_CC_STALL
343 || cc == TD_DATAOVERRUN)) {
344 if (urb->status == -EINPROGRESS)
345 urb->status = cc_to_error[cc];
346 if (ep->nextpid == USB_PID_ACK)
348 spin_unlock(&urb->lock);
351 /* According to usb spec, zero-length Int transfer signals
352 finishing of the urb. Hey, does this apply only
354 if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) {
355 if (urb->status == -EINPROGRESS)
357 spin_unlock(&urb->lock);
361 /* Relax after previously failed, but later succeeded
362 or correctly NAK'ed retransmission attempt */
364 && (cc == TD_CC_NOERROR || cc == TD_NOTACCESSED))
367 /* Take into account idiosyncracies of the isp116x chip
368 regarding toggle bit for failed transfers */
369 if (ep->nextpid == USB_PID_OUT)
370 usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd)
371 ^ (ep->error_count > 0));
372 else if (ep->nextpid == USB_PID_IN)
373 usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd)
374 ^ (ep->error_count > 0));
376 switch (ep->nextpid) {
379 urb->actual_length += PTD_GET_COUNT(ptd);
380 if (PTD_GET_ACTIVE(ptd)
381 || (cc != TD_CC_NOERROR && cc < 0x0E))
383 if (urb->transfer_buffer_length != urb->actual_length) {
387 if (urb->transfer_flags & URB_ZERO_PACKET
388 && ep->nextpid == USB_PID_OUT
389 && !(PTD_GET_COUNT(ptd) % ep->maxpacket)) {
390 DBG("Zero packet requested\n");
394 /* All data for this URB is transferred, let's finish */
395 if (usb_pipecontrol(urb->pipe))
396 ep->nextpid = USB_PID_ACK;
397 else if (urb->status == -EINPROGRESS)
401 if (PTD_GET_ACTIVE(ptd)
402 || (cc != TD_CC_NOERROR && cc < 0x0E))
404 if (urb->transfer_buffer_length == urb->actual_length)
405 ep->nextpid = USB_PID_ACK;
406 else if (usb_pipeout(urb->pipe)) {
407 usb_settoggle(udev, 0, 1, 1);
408 ep->nextpid = USB_PID_OUT;
410 usb_settoggle(udev, 0, 0, 1);
411 ep->nextpid = USB_PID_IN;
415 if (PTD_GET_ACTIVE(ptd)
416 || (cc != TD_CC_NOERROR && cc < 0x0E))
418 if (urb->status == -EINPROGRESS)
425 spin_unlock(&urb->lock);
430 Take done or failed requests out of schedule. Give back
433 static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
434 struct urb *urb, struct pt_regs *regs)
435 __releases(isp116x->lock) __acquires(isp116x->lock)
442 if (usb_pipecontrol(urb->pipe))
443 ep->nextpid = USB_PID_SETUP;
445 urb_dbg(urb, "Finish");
447 spin_unlock(&isp116x->lock);
448 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb, regs);
449 spin_lock(&isp116x->lock);
451 /* take idle endpoints out of the schedule */
452 if (!list_empty(&ep->hep->urb_list))
455 /* async deschedule */
456 if (!list_empty(&ep->schedule)) {
457 list_del_init(&ep->schedule);
461 /* periodic deschedule */
462 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
463 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
464 struct isp116x_ep *temp;
465 struct isp116x_ep **prev = &isp116x->periodic[i];
467 while (*prev && ((temp = *prev) != ep))
471 isp116x->load[i] -= ep->load;
473 ep->branch = PERIODIC_SIZE;
474 isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
475 ep->load / ep->period;
477 /* switch irq type? */
478 if (!--isp116x->periodic_count) {
479 isp116x->irqenb &= ~HCuPINT_SOF;
480 isp116x->irqenb |= HCuPINT_ATL;
485 Scan transfer lists, schedule transfers, send data off
488 static void start_atl_transfers(struct isp116x *isp116x)
490 struct isp116x_ep *last_ep = NULL, *ep;
493 int len, index, speed, byte_time;
495 if (atomic_read(&isp116x->atl_finishing))
498 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state))
501 /* FIFO not empty? */
502 if (isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_FULL)
505 isp116x->atl_active = NULL;
506 isp116x->atl_buflen = isp116x->atl_bufshrt = 0;
508 /* Schedule int transfers */
509 if (isp116x->periodic_count) {
510 isp116x->fmindex = index =
511 (isp116x->fmindex + 1) & (PERIODIC_SIZE - 1);
512 if ((load = isp116x->load[index])) {
513 /* Bring all int transfers for this frame
514 into the active queue */
515 isp116x->atl_active = last_ep =
516 isp116x->periodic[index];
517 while (last_ep->next)
518 last_ep = (last_ep->active = last_ep->next);
519 last_ep->active = NULL;
523 /* Schedule control/bulk transfers */
524 list_for_each_entry(ep, &isp116x->async, schedule) {
525 urb = container_of(ep->hep->urb_list.next,
526 struct urb, urb_list);
527 speed = urb->dev->speed;
528 byte_time = speed == USB_SPEED_LOW
529 ? BYTE_TIME_LOWSPEED : BYTE_TIME_FULLSPEED;
531 if (ep->nextpid == USB_PID_SETUP) {
532 len = sizeof(struct usb_ctrlrequest);
533 } else if (ep->nextpid == USB_PID_ACK) {
536 /* Find current free length ... */
537 len = (MAX_LOAD_LIMIT - load) / byte_time;
539 /* ... then limit it to configured max size ... */
540 len = min(len, speed == USB_SPEED_LOW ?
541 MAX_TRANSFER_SIZE_LOWSPEED :
542 MAX_TRANSFER_SIZE_FULLSPEED);
544 /* ... and finally cut to the multiple of MaxPacketSize,
545 or to the real length if there's enough room. */
547 (urb->transfer_buffer_length -
548 urb->actual_length)) {
549 len -= len % ep->maxpacket;
553 len = urb->transfer_buffer_length -
558 load += len * byte_time;
559 if (load > MAX_LOAD_LIMIT)
565 last_ep->active = ep;
567 isp116x->atl_active = ep;
571 /* Avoid starving of endpoints */
572 if ((&isp116x->async)->next != (&isp116x->async)->prev)
573 list_move(&isp116x->async, (&isp116x->async)->next);
575 if (isp116x->atl_active) {
576 preproc_atl_queue(isp116x);
582 Finish the processed transfers
584 static void finish_atl_transfers(struct isp116x *isp116x, struct pt_regs *regs)
586 struct isp116x_ep *ep;
589 if (!isp116x->atl_active)
591 /* Fifo not ready? */
592 if (!(isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_DONE))
595 atomic_inc(&isp116x->atl_finishing);
596 unpack_fifo(isp116x);
597 postproc_atl_queue(isp116x);
598 for (ep = isp116x->atl_active; ep; ep = ep->active) {
600 container_of(ep->hep->urb_list.next, struct urb, urb_list);
601 /* USB_PID_ACK check here avoids finishing of
602 control transfers, for which TD_DATAUNDERRUN
603 occured, while URB_SHORT_NOT_OK was set */
604 if (urb && urb->status != -EINPROGRESS
605 && ep->nextpid != USB_PID_ACK)
606 finish_request(isp116x, ep, urb, regs);
608 atomic_dec(&isp116x->atl_finishing);
611 static irqreturn_t isp116x_irq(struct usb_hcd *hcd, struct pt_regs *regs)
613 struct isp116x *isp116x = hcd_to_isp116x(hcd);
615 irqreturn_t ret = IRQ_NONE;
617 spin_lock(&isp116x->lock);
618 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
619 irqstat = isp116x_read_reg16(isp116x, HCuPINT);
620 isp116x_write_reg16(isp116x, HCuPINT, irqstat);
622 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
624 finish_atl_transfers(isp116x, regs);
627 if (irqstat & HCuPINT_OPR) {
628 u32 intstat = isp116x_read_reg32(isp116x, HCINTSTAT);
629 isp116x_write_reg32(isp116x, HCINTSTAT, intstat);
630 if (intstat & HCINT_UE) {
631 ERR("Unrecoverable error\n");
632 /* What should we do here? Reset? */
634 if (intstat & HCINT_RHSC)
635 /* When root hub or any of its ports is going
636 to come out of suspend, it may take more
637 than 10ms for status bits to stabilize. */
638 mod_timer(&hcd->rh_timer, jiffies
639 + msecs_to_jiffies(20) + 1);
640 if (intstat & HCINT_RD) {
641 DBG("---- remote wakeup\n");
642 usb_hcd_resume_root_hub(hcd);
645 irqstat &= ~HCuPINT_OPR;
649 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
650 start_atl_transfers(isp116x);
653 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
654 spin_unlock(&isp116x->lock);
658 /*-----------------------------------------------------------------*/
660 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
661 * this driver doesn't promise that much since it's got to handle an
662 * IRQ per packet; irq handling latencies also use up that time.
666 #define MAX_PERIODIC_LOAD 600
667 static int balance(struct isp116x *isp116x, u16 period, u16 load)
669 int i, branch = -ENOSPC;
671 /* search for the least loaded schedule branch of that period
672 which has enough bandwidth left unreserved. */
673 for (i = 0; i < period; i++) {
674 if (branch < 0 || isp116x->load[branch] > isp116x->load[i]) {
677 for (j = i; j < PERIODIC_SIZE; j += period) {
678 if ((isp116x->load[j] + load)
682 if (j < PERIODIC_SIZE)
690 /* NB! ALL the code above this point runs with isp116x->lock
694 /*-----------------------------------------------------------------*/
696 static int isp116x_urb_enqueue(struct usb_hcd *hcd,
697 struct usb_host_endpoint *hep, struct urb *urb,
700 struct isp116x *isp116x = hcd_to_isp116x(hcd);
701 struct usb_device *udev = urb->dev;
702 unsigned int pipe = urb->pipe;
703 int is_out = !usb_pipein(pipe);
704 int type = usb_pipetype(pipe);
705 int epnum = usb_pipeendpoint(pipe);
706 struct isp116x_ep *ep = NULL;
711 urb_dbg(urb, "Enqueue");
713 if (type == PIPE_ISOCHRONOUS) {
714 ERR("Isochronous transfers not supported\n");
715 urb_dbg(urb, "Refused to enqueue");
718 /* avoid all allocations within spinlocks: request or endpoint */
720 ep = kzalloc(sizeof *ep, mem_flags);
725 spin_lock_irqsave(&isp116x->lock, flags);
726 if (!HC_IS_RUNNING(hcd->state)) {
734 INIT_LIST_HEAD(&ep->schedule);
735 ep->udev = usb_get_dev(udev);
737 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
738 usb_settoggle(udev, epnum, is_out, 0);
740 if (type == PIPE_CONTROL) {
741 ep->nextpid = USB_PID_SETUP;
743 ep->nextpid = USB_PID_OUT;
745 ep->nextpid = USB_PID_IN;
750 With INT URBs submitted, the driver works with SOF
751 interrupt enabled and ATL interrupt disabled. After
752 the PTDs are written to fifo ram, the chip starts
753 fifo processing and usb transfers after the next
754 SOF and continues until the transfers are finished
755 (succeeded or failed) or the frame ends. Therefore,
756 the transfers occur only in every second frame,
757 while fifo reading/writing and data processing
758 occur in every other second frame. */
759 if (urb->interval < 2)
761 if (urb->interval > 2 * PERIODIC_SIZE)
762 urb->interval = 2 * PERIODIC_SIZE;
763 ep->period = urb->interval >> 1;
764 ep->branch = PERIODIC_SIZE;
765 ep->load = usb_calc_bus_time(udev->speed,
767 (type == PIPE_ISOCHRONOUS),
768 usb_maxpacket(udev, pipe,
776 /* maybe put endpoint into schedule */
780 if (list_empty(&ep->schedule))
781 list_add_tail(&ep->schedule, &isp116x->async);
784 urb->interval = ep->period;
785 ep->length = min((int)ep->maxpacket,
786 urb->transfer_buffer_length);
788 /* urb submitted for already existing endpoint */
789 if (ep->branch < PERIODIC_SIZE)
792 ret = ep->branch = balance(isp116x, ep->period, ep->load);
797 urb->start_frame = (isp116x->fmindex & (PERIODIC_SIZE - 1))
800 /* sort each schedule branch by period (slow before fast)
801 to share the faster parts of the tree without needing
802 dummy/placeholder nodes */
803 DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
804 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
805 struct isp116x_ep **prev = &isp116x->periodic[i];
806 struct isp116x_ep *here = *prev;
808 while (here && ep != here) {
809 if (ep->period > here->period)
818 isp116x->load[i] += ep->load;
820 hcd->self.bandwidth_allocated += ep->load / ep->period;
822 /* switch over to SOFint */
823 if (!isp116x->periodic_count++) {
824 isp116x->irqenb &= ~HCuPINT_ATL;
825 isp116x->irqenb |= HCuPINT_SOF;
826 isp116x_write_reg16(isp116x, HCuPINTENB,
831 /* in case of unlink-during-submit */
832 spin_lock(&urb->lock);
833 if (urb->status != -EINPROGRESS) {
834 spin_unlock(&urb->lock);
835 finish_request(isp116x, ep, urb, NULL);
840 spin_unlock(&urb->lock);
841 start_atl_transfers(isp116x);
844 spin_unlock_irqrestore(&isp116x->lock, flags);
851 static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
853 struct isp116x *isp116x = hcd_to_isp116x(hcd);
854 struct usb_host_endpoint *hep;
855 struct isp116x_ep *ep, *ep_act;
858 spin_lock_irqsave(&isp116x->lock, flags);
860 /* URB already unlinked (or never linked)? */
862 spin_unlock_irqrestore(&isp116x->lock, flags);
866 WARN_ON(hep != ep->hep);
868 /* In front of queue? */
869 if (ep->hep->urb_list.next == &urb->urb_list)
871 for (ep_act = isp116x->atl_active; ep_act;
872 ep_act = ep_act->active)
874 VDBG("dequeue, urb %p active; wait for irq\n",
881 finish_request(isp116x, ep, urb, NULL);
883 spin_unlock_irqrestore(&isp116x->lock, flags);
887 static void isp116x_endpoint_disable(struct usb_hcd *hcd,
888 struct usb_host_endpoint *hep)
891 struct isp116x_ep *ep = hep->hcpriv;;
896 /* assume we'd just wait for the irq */
897 for (i = 0; i < 100 && !list_empty(&hep->urb_list); i++)
899 if (!list_empty(&hep->urb_list))
900 WARN("ep %p not empty?\n", ep);
902 usb_put_dev(ep->udev);
907 static int isp116x_get_frame(struct usb_hcd *hcd)
909 struct isp116x *isp116x = hcd_to_isp116x(hcd);
913 spin_lock_irqsave(&isp116x->lock, flags);
914 fmnum = isp116x_read_reg32(isp116x, HCFMNUM);
915 spin_unlock_irqrestore(&isp116x->lock, flags);
919 /*----------------------------------------------------------------*/
922 Adapted from ohci-hub.c. Currently we don't support autosuspend.
924 static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
926 struct isp116x *isp116x = hcd_to_isp116x(hcd);
927 int ports, i, changed = 0;
930 if (!HC_IS_RUNNING(hcd->state))
933 /* Report no status change now, if we are scheduled to be
935 if (timer_pending(&hcd->rh_timer))
938 ports = isp116x->rhdesca & RH_A_NDP;
939 spin_lock_irqsave(&isp116x->lock, flags);
940 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
941 if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
942 buf[0] = changed = 1;
946 for (i = 0; i < ports; i++) {
947 u32 status = isp116x->rhport[i] =
948 isp116x_read_reg32(isp116x, i ? HCRHPORT2 : HCRHPORT1);
950 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
951 | RH_PS_OCIC | RH_PS_PRSC)) {
953 buf[0] |= 1 << (i + 1);
957 spin_unlock_irqrestore(&isp116x->lock, flags);
961 static void isp116x_hub_descriptor(struct isp116x *isp116x,
962 struct usb_hub_descriptor *desc)
964 u32 reg = isp116x->rhdesca;
966 desc->bDescriptorType = 0x29;
967 desc->bDescLength = 9;
968 desc->bHubContrCurrent = 0;
969 desc->bNbrPorts = (u8) (reg & 0x3);
970 /* Power switching, device type, overcurrent. */
971 desc->wHubCharacteristics =
972 (__force __u16) cpu_to_le16((u16) ((reg >> 8) & 0x1f));
973 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff);
974 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
975 desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
976 desc->bitmap[1] = ~0;
979 /* Perform reset of a given port.
980 It would be great to just start the reset and let the
981 USB core to clear the reset in due time. However,
982 root hub ports should be reset for at least 50 ms, while
983 our chip stays in reset for about 10 ms. I.e., we must
984 repeatedly reset it ourself here.
986 static inline void root_port_reset(struct isp116x *isp116x, unsigned port)
989 unsigned long flags, t;
991 /* Root hub reset should be 50 ms, but some devices
992 want it even longer. */
993 t = jiffies + msecs_to_jiffies(100);
995 while (time_before(jiffies, t)) {
996 spin_lock_irqsave(&isp116x->lock, flags);
997 /* spin until any current reset finishes */
999 tmp = isp116x_read_reg32(isp116x, port ?
1000 HCRHPORT2 : HCRHPORT1);
1001 if (!(tmp & RH_PS_PRS))
1005 /* Don't reset a disconnected port */
1006 if (!(tmp & RH_PS_CCS)) {
1007 spin_unlock_irqrestore(&isp116x->lock, flags);
1010 /* Reset lasts 10ms (claims datasheet) */
1011 isp116x_write_reg32(isp116x, port ? HCRHPORT2 :
1012 HCRHPORT1, (RH_PS_PRS));
1013 spin_unlock_irqrestore(&isp116x->lock, flags);
1018 /* Adapted from ohci-hub.c */
1019 static int isp116x_hub_control(struct usb_hcd *hcd,
1021 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1023 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1025 unsigned long flags;
1026 int ports = isp116x->rhdesca & RH_A_NDP;
1030 case ClearHubFeature:
1031 DBG("ClearHubFeature: ");
1033 case C_HUB_OVER_CURRENT:
1034 DBG("C_HUB_OVER_CURRENT\n");
1035 spin_lock_irqsave(&isp116x->lock, flags);
1036 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_OCIC);
1037 spin_unlock_irqrestore(&isp116x->lock, flags);
1038 case C_HUB_LOCAL_POWER:
1039 DBG("C_HUB_LOCAL_POWER\n");
1046 DBG("SetHubFeature: ");
1048 case C_HUB_OVER_CURRENT:
1049 case C_HUB_LOCAL_POWER:
1050 DBG("C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1056 case GetHubDescriptor:
1057 DBG("GetHubDescriptor\n");
1058 isp116x_hub_descriptor(isp116x,
1059 (struct usb_hub_descriptor *)buf);
1062 DBG("GetHubStatus\n");
1063 *(__le32 *) buf = 0;
1066 DBG("GetPortStatus\n");
1067 if (!wIndex || wIndex > ports)
1069 tmp = isp116x->rhport[--wIndex];
1070 *(__le32 *) buf = cpu_to_le32(tmp);
1071 DBG("GetPortStatus: port[%d] %08x\n", wIndex + 1, tmp);
1073 case ClearPortFeature:
1074 DBG("ClearPortFeature: ");
1075 if (!wIndex || wIndex > ports)
1080 case USB_PORT_FEAT_ENABLE:
1081 DBG("USB_PORT_FEAT_ENABLE\n");
1084 case USB_PORT_FEAT_C_ENABLE:
1085 DBG("USB_PORT_FEAT_C_ENABLE\n");
1088 case USB_PORT_FEAT_SUSPEND:
1089 DBG("USB_PORT_FEAT_SUSPEND\n");
1092 case USB_PORT_FEAT_C_SUSPEND:
1093 DBG("USB_PORT_FEAT_C_SUSPEND\n");
1096 case USB_PORT_FEAT_POWER:
1097 DBG("USB_PORT_FEAT_POWER\n");
1100 case USB_PORT_FEAT_C_CONNECTION:
1101 DBG("USB_PORT_FEAT_C_CONNECTION\n");
1104 case USB_PORT_FEAT_C_OVER_CURRENT:
1105 DBG("USB_PORT_FEAT_C_OVER_CURRENT\n");
1108 case USB_PORT_FEAT_C_RESET:
1109 DBG("USB_PORT_FEAT_C_RESET\n");
1115 spin_lock_irqsave(&isp116x->lock, flags);
1116 isp116x_write_reg32(isp116x, wIndex
1117 ? HCRHPORT2 : HCRHPORT1, tmp);
1118 isp116x->rhport[wIndex] =
1119 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1120 spin_unlock_irqrestore(&isp116x->lock, flags);
1122 case SetPortFeature:
1123 DBG("SetPortFeature: ");
1124 if (!wIndex || wIndex > ports)
1128 case USB_PORT_FEAT_SUSPEND:
1129 DBG("USB_PORT_FEAT_SUSPEND\n");
1130 spin_lock_irqsave(&isp116x->lock, flags);
1131 isp116x_write_reg32(isp116x, wIndex
1132 ? HCRHPORT2 : HCRHPORT1, RH_PS_PSS);
1134 case USB_PORT_FEAT_POWER:
1135 DBG("USB_PORT_FEAT_POWER\n");
1136 spin_lock_irqsave(&isp116x->lock, flags);
1137 isp116x_write_reg32(isp116x, wIndex
1138 ? HCRHPORT2 : HCRHPORT1, RH_PS_PPS);
1140 case USB_PORT_FEAT_RESET:
1141 DBG("USB_PORT_FEAT_RESET\n");
1142 root_port_reset(isp116x, wIndex);
1143 spin_lock_irqsave(&isp116x->lock, flags);
1148 isp116x->rhport[wIndex] =
1149 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1150 spin_unlock_irqrestore(&isp116x->lock, flags);
1155 /* "protocol stall" on error */
1156 DBG("PROTOCOL STALL\n");
1164 static int isp116x_bus_suspend(struct usb_hcd *hcd)
1166 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1167 unsigned long flags;
1171 spin_lock_irqsave(&isp116x->lock, flags);
1173 val = isp116x_read_reg32(isp116x, HCCONTROL);
1174 switch (val & HCCONTROL_HCFS) {
1175 case HCCONTROL_USB_OPER:
1176 hcd->state = HC_STATE_QUIESCING;
1177 val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE);
1178 val |= HCCONTROL_USB_SUSPEND;
1179 if (hcd->remote_wakeup)
1180 val |= HCCONTROL_RWE;
1181 /* Wait for usb transfers to finish */
1183 isp116x_write_reg32(isp116x, HCCONTROL, val);
1184 hcd->state = HC_STATE_SUSPENDED;
1185 /* Wait for devices to suspend */
1187 case HCCONTROL_USB_SUSPEND:
1189 case HCCONTROL_USB_RESUME:
1190 isp116x_write_reg32(isp116x, HCCONTROL,
1191 (val & ~HCCONTROL_HCFS) |
1192 HCCONTROL_USB_RESET);
1193 case HCCONTROL_USB_RESET:
1200 spin_unlock_irqrestore(&isp116x->lock, flags);
1204 static int isp116x_bus_resume(struct usb_hcd *hcd)
1206 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1208 int ret = -EINPROGRESS;
1211 spin_lock_irq(&isp116x->lock);
1213 val = isp116x_read_reg32(isp116x, HCCONTROL);
1214 switch (val & HCCONTROL_HCFS) {
1215 case HCCONTROL_USB_SUSPEND:
1216 val &= ~HCCONTROL_HCFS;
1217 val |= HCCONTROL_USB_RESUME;
1218 isp116x_write_reg32(isp116x, HCCONTROL, val);
1219 case HCCONTROL_USB_RESUME:
1221 case HCCONTROL_USB_OPER:
1222 /* Without setting power_state here the
1223 SUSPENDED state won't be removed from
1224 sysfs/usbN/power.state as a response to remote
1225 wakeup. Maybe in the future. */
1226 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1233 if (ret != -EINPROGRESS) {
1234 spin_unlock_irq(&isp116x->lock);
1238 val = isp116x->rhdesca & RH_A_NDP;
1241 isp116x_read_reg32(isp116x, val ? HCRHPORT2 : HCRHPORT1);
1242 /* force global, not selective, resume */
1243 if (!(stat & RH_PS_PSS))
1245 DBG("%s: Resuming port %d\n", __func__, val);
1246 isp116x_write_reg32(isp116x, RH_PS_POCI, val
1247 ? HCRHPORT2 : HCRHPORT1);
1249 spin_unlock_irq(&isp116x->lock);
1251 hcd->state = HC_STATE_RESUMING;
1254 /* Go operational */
1255 spin_lock_irq(&isp116x->lock);
1256 val = isp116x_read_reg32(isp116x, HCCONTROL);
1257 isp116x_write_reg32(isp116x, HCCONTROL,
1258 (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER);
1259 spin_unlock_irq(&isp116x->lock);
1260 /* see analogous comment above */
1261 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1262 hcd->state = HC_STATE_RUNNING;
1270 #define isp116x_bus_suspend NULL
1271 #define isp116x_bus_resume NULL
1275 /*-----------------------------------------------------------------*/
1277 #ifdef STUB_DEBUG_FILE
1279 static inline void create_debug_file(struct isp116x *isp116x)
1283 static inline void remove_debug_file(struct isp116x *isp116x)
1289 #include <linux/proc_fs.h>
1290 #include <linux/seq_file.h>
1292 static void dump_irq(struct seq_file *s, char *label, u16 mask)
1294 seq_printf(s, "%s %04x%s%s%s%s%s%s\n", label, mask,
1295 mask & HCuPINT_CLKRDY ? " clkrdy" : "",
1296 mask & HCuPINT_SUSP ? " susp" : "",
1297 mask & HCuPINT_OPR ? " opr" : "",
1298 mask & HCuPINT_AIIEOT ? " eot" : "",
1299 mask & HCuPINT_ATL ? " atl" : "",
1300 mask & HCuPINT_SOF ? " sof" : "");
1303 static void dump_int(struct seq_file *s, char *label, u32 mask)
1305 seq_printf(s, "%s %08x%s%s%s%s%s%s%s\n", label, mask,
1306 mask & HCINT_MIE ? " MIE" : "",
1307 mask & HCINT_RHSC ? " rhsc" : "",
1308 mask & HCINT_FNO ? " fno" : "",
1309 mask & HCINT_UE ? " ue" : "",
1310 mask & HCINT_RD ? " rd" : "",
1311 mask & HCINT_SF ? " sof" : "", mask & HCINT_SO ? " so" : "");
1314 static int proc_isp116x_show(struct seq_file *s, void *unused)
1316 struct isp116x *isp116x = s->private;
1317 struct isp116x_ep *ep;
1322 seq_printf(s, "%s\n%s version %s\n",
1323 isp116x_to_hcd(isp116x)->product_desc, hcd_name,
1326 if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x)->state)) {
1327 seq_printf(s, "HCD is suspended\n");
1330 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) {
1331 seq_printf(s, "HCD not running\n");
1335 spin_lock_irq(&isp116x->lock);
1337 dump_irq(s, "hc_irq_enable", isp116x_read_reg16(isp116x, HCuPINTENB));
1338 dump_irq(s, "hc_irq_status", isp116x_read_reg16(isp116x, HCuPINT));
1339 dump_int(s, "hc_int_enable", isp116x_read_reg32(isp116x, HCINTENB));
1340 dump_int(s, "hc_int_status", isp116x_read_reg32(isp116x, HCINTSTAT));
1342 list_for_each_entry(ep, &isp116x->async, schedule) {
1344 switch (ep->nextpid) {
1361 seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep,
1362 ep->epnum, str, ep->maxpacket);
1363 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
1364 seq_printf(s, " urb%p, %d/%d\n", urb,
1366 urb->transfer_buffer_length);
1369 if (!list_empty(&isp116x->async))
1370 seq_printf(s, "\n");
1372 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1374 for (i = 0; i < PERIODIC_SIZE; i++) {
1375 ep = isp116x->periodic[i];
1378 seq_printf(s, "%2d [%3d]:\n", i, isp116x->load[i]);
1380 /* DUMB: prints shared entries multiple times */
1382 seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
1385 USB_SPEED_FULL) ? "" : "ls ",
1386 ep->udev->devnum, ep->epnum,
1388 0) ? "" : ((ep->nextpid ==
1389 USB_PID_IN) ? "in" : "out"),
1394 spin_unlock_irq(&isp116x->lock);
1395 seq_printf(s, "\n");
1400 static int proc_isp116x_open(struct inode *inode, struct file *file)
1402 return single_open(file, proc_isp116x_show, PDE(inode)->data);
1405 static struct file_operations proc_ops = {
1406 .open = proc_isp116x_open,
1408 .llseek = seq_lseek,
1409 .release = single_release,
1412 /* expect just one isp116x per system */
1413 static const char proc_filename[] = "driver/isp116x";
1415 static void create_debug_file(struct isp116x *isp116x)
1417 struct proc_dir_entry *pde;
1419 pde = create_proc_entry(proc_filename, 0, NULL);
1423 pde->proc_fops = &proc_ops;
1424 pde->data = isp116x;
1428 static void remove_debug_file(struct isp116x *isp116x)
1431 remove_proc_entry(proc_filename, NULL);
1436 /*-----------------------------------------------------------------*/
1439 Software reset - can be called from any contect.
1441 static int isp116x_sw_reset(struct isp116x *isp116x)
1444 unsigned long flags;
1447 spin_lock_irqsave(&isp116x->lock, flags);
1448 isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC);
1449 isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR);
1451 /* It usually resets within 1 ms */
1453 if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR))
1457 ERR("Software reset timeout\n");
1460 spin_unlock_irqrestore(&isp116x->lock, flags);
1464 static int isp116x_reset(struct usb_hcd *hcd)
1466 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1469 int ret = 0, timeout = 15 /* ms */ ;
1471 ret = isp116x_sw_reset(isp116x);
1475 t = jiffies + msecs_to_jiffies(timeout);
1476 while (time_before_eq(jiffies, t)) {
1478 spin_lock_irq(&isp116x->lock);
1479 clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY;
1480 spin_unlock_irq(&isp116x->lock);
1485 ERR("Clock not ready after 20ms\n");
1486 /* After sw_reset the clock won't report to be ready, if
1487 H_WAKEUP pin is high. */
1488 ERR("Please make sure that the H_WAKEUP pin is pulled low!\n");
1494 static void isp116x_stop(struct usb_hcd *hcd)
1496 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1497 unsigned long flags;
1500 spin_lock_irqsave(&isp116x->lock, flags);
1501 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1503 /* Switch off ports' power, some devices don't come up
1504 after next 'insmod' without this */
1505 val = isp116x_read_reg32(isp116x, HCRHDESCA);
1506 val &= ~(RH_A_NPS | RH_A_PSM);
1507 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1508 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
1509 spin_unlock_irqrestore(&isp116x->lock, flags);
1511 isp116x_sw_reset(isp116x);
1515 Configure the chip. The chip must be successfully reset by now.
1517 static int isp116x_start(struct usb_hcd *hcd)
1519 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1520 struct isp116x_platform_data *board = isp116x->board;
1522 unsigned long flags;
1524 spin_lock_irqsave(&isp116x->lock, flags);
1526 /* clear interrupt status and disable all interrupt sources */
1527 isp116x_write_reg16(isp116x, HCuPINT, 0xff);
1528 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1530 val = isp116x_read_reg16(isp116x, HCCHIPID);
1531 if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
1532 ERR("Invalid chip ID %04x\n", val);
1533 spin_unlock_irqrestore(&isp116x->lock, flags);
1537 /* To be removed in future */
1538 hcd->uses_new_polling = 1;
1540 isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
1541 isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
1544 val = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
1545 if (board->sel15Kres)
1546 val |= HCHWCFG_15KRSEL;
1547 /* Remote wakeup won't work without working clock */
1548 if (board->remote_wakeup_enable)
1549 val |= HCHWCFG_CLKNOTSTOP;
1550 if (board->oc_enable)
1551 val |= HCHWCFG_ANALOG_OC;
1552 if (board->int_act_high)
1553 val |= HCHWCFG_INT_POL;
1554 if (board->int_edge_triggered)
1555 val |= HCHWCFG_INT_TRIGGER;
1556 isp116x_write_reg16(isp116x, HCHWCFG, val);
1558 /* ----- Root hub conf */
1559 val = (25 << 24) & RH_A_POTPGT;
1560 /* AN10003_1.pdf recommends RH_A_NPS (no power switching) to
1561 be always set. Yet, instead, we request individual port
1564 /* Report overcurrent per port */
1566 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1567 isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
1570 isp116x_write_reg32(isp116x, HCRHDESCB, val);
1571 isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB);
1574 if (board->remote_wakeup_enable) {
1575 hcd->can_wakeup = 1;
1578 isp116x_write_reg32(isp116x, HCRHSTATUS, val);
1579 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
1581 isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf);
1583 hcd->state = HC_STATE_RUNNING;
1585 /* Set up interrupts */
1586 isp116x->intenb = HCINT_MIE | HCINT_RHSC | HCINT_UE;
1587 if (board->remote_wakeup_enable)
1588 isp116x->intenb |= HCINT_RD;
1589 isp116x->irqenb = HCuPINT_ATL | HCuPINT_OPR; /* | HCuPINT_SUSP; */
1590 isp116x_write_reg32(isp116x, HCINTENB, isp116x->intenb);
1591 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
1593 /* Go operational */
1594 val = HCCONTROL_USB_OPER;
1595 if (board->remote_wakeup_enable)
1596 val |= HCCONTROL_RWE;
1597 isp116x_write_reg32(isp116x, HCCONTROL, val);
1599 /* Disable ports to avoid race in device enumeration */
1600 isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS);
1601 isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS);
1603 isp116x_show_regs(isp116x);
1604 spin_unlock_irqrestore(&isp116x->lock, flags);
1608 /*-----------------------------------------------------------------*/
1610 static struct hc_driver isp116x_hc_driver = {
1611 .description = hcd_name,
1612 .product_desc = "ISP116x Host Controller",
1613 .hcd_priv_size = sizeof(struct isp116x),
1618 .reset = isp116x_reset,
1619 .start = isp116x_start,
1620 .stop = isp116x_stop,
1622 .urb_enqueue = isp116x_urb_enqueue,
1623 .urb_dequeue = isp116x_urb_dequeue,
1624 .endpoint_disable = isp116x_endpoint_disable,
1626 .get_frame_number = isp116x_get_frame,
1628 .hub_status_data = isp116x_hub_status_data,
1629 .hub_control = isp116x_hub_control,
1630 .bus_suspend = isp116x_bus_suspend,
1631 .bus_resume = isp116x_bus_resume,
1634 /*----------------------------------------------------------------*/
1636 static int __init_or_module isp116x_remove(struct device *dev)
1638 struct usb_hcd *hcd = dev_get_drvdata(dev);
1639 struct isp116x *isp116x;
1640 struct platform_device *pdev;
1641 struct resource *res;
1645 isp116x = hcd_to_isp116x(hcd);
1646 pdev = container_of(dev, struct platform_device, dev);
1647 remove_debug_file(isp116x);
1648 usb_remove_hcd(hcd);
1650 iounmap(isp116x->data_reg);
1651 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1652 release_mem_region(res->start, 2);
1653 iounmap(isp116x->addr_reg);
1654 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1655 release_mem_region(res->start, 2);
1661 #define resource_len(r) (((r)->end - (r)->start) + 1)
1663 static int __init isp116x_probe(struct device *dev)
1665 struct usb_hcd *hcd;
1666 struct isp116x *isp116x;
1667 struct platform_device *pdev;
1668 struct resource *addr, *data;
1669 void __iomem *addr_reg;
1670 void __iomem *data_reg;
1674 pdev = container_of(dev, struct platform_device, dev);
1675 if (pdev->num_resources < 3) {
1680 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1681 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1682 irq = platform_get_irq(pdev, 0);
1683 if (!addr || !data || irq < 0) {
1688 if (dev->dma_mask) {
1689 DBG("DMA not supported\n");
1694 if (!request_mem_region(addr->start, 2, hcd_name)) {
1698 addr_reg = ioremap(addr->start, resource_len(addr));
1699 if (addr_reg == NULL) {
1703 if (!request_mem_region(data->start, 2, hcd_name)) {
1707 data_reg = ioremap(data->start, resource_len(data));
1708 if (data_reg == NULL) {
1713 /* allocate and initialize hcd */
1714 hcd = usb_create_hcd(&isp116x_hc_driver, dev, dev->bus_id);
1719 /* this rsrc_start is bogus */
1720 hcd->rsrc_start = addr->start;
1721 isp116x = hcd_to_isp116x(hcd);
1722 isp116x->data_reg = data_reg;
1723 isp116x->addr_reg = addr_reg;
1724 spin_lock_init(&isp116x->lock);
1725 INIT_LIST_HEAD(&isp116x->async);
1726 isp116x->board = dev->platform_data;
1728 if (!isp116x->board) {
1729 ERR("Platform data structure not initialized\n");
1733 if (isp116x_check_platform_delay(isp116x)) {
1734 ERR("USE_PLATFORM_DELAY defined, but delay function not "
1736 ERR("See comments in drivers/usb/host/isp116x-hcd.c\n");
1741 ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
1745 create_debug_file(isp116x);
1753 release_mem_region(data->start, 2);
1757 release_mem_region(addr->start, 2);
1759 ERR("init error, %d\n", ret);
1765 Suspend of platform device
1767 static int isp116x_suspend(struct device *dev, pm_message_t state)
1771 VDBG("%s: state %x\n", __func__, state);
1773 dev->power.power_state = state;
1779 Resume platform device
1781 static int isp116x_resume(struct device *dev)
1785 VDBG("%s: state %x\n", __func__, dev->power.power_state);
1787 dev->power.power_state = PMSG_ON;
1794 #define isp116x_suspend NULL
1795 #define isp116x_resume NULL
1799 static struct device_driver isp116x_driver = {
1800 .name = (char *)hcd_name,
1801 .bus = &platform_bus_type,
1802 .probe = isp116x_probe,
1803 .remove = isp116x_remove,
1804 .suspend = isp116x_suspend,
1805 .resume = isp116x_resume,
1808 /*-----------------------------------------------------------------*/
1810 static int __init isp116x_init(void)
1815 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1816 return driver_register(&isp116x_driver);
1819 module_init(isp116x_init);
1821 static void __exit isp116x_cleanup(void)
1823 driver_unregister(&isp116x_driver);
1826 module_exit(isp116x_cleanup);