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 "08 Apr 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) {
634 isp116x_read_reg32(isp116x, HCRHSTATUS);
636 isp116x_read_reg32(isp116x, HCRHPORT1);
638 isp116x_read_reg32(isp116x, HCRHPORT2);
640 if (intstat & HCINT_RD) {
641 DBG("---- remote wakeup\n");
642 schedule_work(&isp116x->rh_resume);
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;
929 if (!HC_IS_RUNNING(hcd->state))
932 ports = isp116x->rhdesca & RH_A_NDP;
935 if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
936 buf[0] = changed = 1;
940 for (i = 0; i < ports; i++) {
941 u32 status = isp116x->rhport[i];
943 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
944 | RH_PS_OCIC | RH_PS_PRSC)) {
946 buf[0] |= 1 << (i + 1);
953 static void isp116x_hub_descriptor(struct isp116x *isp116x,
954 struct usb_hub_descriptor *desc)
956 u32 reg = isp116x->rhdesca;
958 desc->bDescriptorType = 0x29;
959 desc->bDescLength = 9;
960 desc->bHubContrCurrent = 0;
961 desc->bNbrPorts = (u8) (reg & 0x3);
962 /* Power switching, device type, overcurrent. */
963 desc->wHubCharacteristics =
964 (__force __u16) cpu_to_le16((u16) ((reg >> 8) & 0x1f));
965 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff);
966 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
967 desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
968 desc->bitmap[1] = ~0;
971 /* Perform reset of a given port.
972 It would be great to just start the reset and let the
973 USB core to clear the reset in due time. However,
974 root hub ports should be reset for at least 50 ms, while
975 our chip stays in reset for about 10 ms. I.e., we must
976 repeatedly reset it ourself here.
978 static inline void root_port_reset(struct isp116x *isp116x, unsigned port)
981 unsigned long flags, t;
983 /* Root hub reset should be 50 ms, but some devices
984 want it even longer. */
985 t = jiffies + msecs_to_jiffies(100);
987 while (time_before(jiffies, t)) {
988 spin_lock_irqsave(&isp116x->lock, flags);
989 /* spin until any current reset finishes */
991 tmp = isp116x_read_reg32(isp116x, port ?
992 HCRHPORT2 : HCRHPORT1);
993 if (!(tmp & RH_PS_PRS))
997 /* Don't reset a disconnected port */
998 if (!(tmp & RH_PS_CCS)) {
999 spin_unlock_irqrestore(&isp116x->lock, flags);
1002 /* Reset lasts 10ms (claims datasheet) */
1003 isp116x_write_reg32(isp116x, port ? HCRHPORT2 :
1004 HCRHPORT1, (RH_PS_PRS));
1005 spin_unlock_irqrestore(&isp116x->lock, flags);
1010 /* Adapted from ohci-hub.c */
1011 static int isp116x_hub_control(struct usb_hcd *hcd,
1013 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1015 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1017 unsigned long flags;
1018 int ports = isp116x->rhdesca & RH_A_NDP;
1022 case ClearHubFeature:
1023 DBG("ClearHubFeature: ");
1025 case C_HUB_OVER_CURRENT:
1026 DBG("C_HUB_OVER_CURRENT\n");
1027 spin_lock_irqsave(&isp116x->lock, flags);
1028 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_OCIC);
1029 spin_unlock_irqrestore(&isp116x->lock, flags);
1030 case C_HUB_LOCAL_POWER:
1031 DBG("C_HUB_LOCAL_POWER\n");
1038 DBG("SetHubFeature: ");
1040 case C_HUB_OVER_CURRENT:
1041 case C_HUB_LOCAL_POWER:
1042 DBG("C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1048 case GetHubDescriptor:
1049 DBG("GetHubDescriptor\n");
1050 isp116x_hub_descriptor(isp116x,
1051 (struct usb_hub_descriptor *)buf);
1054 DBG("GetHubStatus\n");
1055 *(__le32 *) buf = 0;
1058 DBG("GetPortStatus\n");
1059 if (!wIndex || wIndex > ports)
1061 tmp = isp116x->rhport[--wIndex];
1062 *(__le32 *) buf = cpu_to_le32(tmp);
1063 DBG("GetPortStatus: port[%d] %08x\n", wIndex + 1, tmp);
1065 case ClearPortFeature:
1066 DBG("ClearPortFeature: ");
1067 if (!wIndex || wIndex > ports)
1072 case USB_PORT_FEAT_ENABLE:
1073 DBG("USB_PORT_FEAT_ENABLE\n");
1076 case USB_PORT_FEAT_C_ENABLE:
1077 DBG("USB_PORT_FEAT_C_ENABLE\n");
1080 case USB_PORT_FEAT_SUSPEND:
1081 DBG("USB_PORT_FEAT_SUSPEND\n");
1084 case USB_PORT_FEAT_C_SUSPEND:
1085 DBG("USB_PORT_FEAT_C_SUSPEND\n");
1088 case USB_PORT_FEAT_POWER:
1089 DBG("USB_PORT_FEAT_POWER\n");
1092 case USB_PORT_FEAT_C_CONNECTION:
1093 DBG("USB_PORT_FEAT_C_CONNECTION\n");
1096 case USB_PORT_FEAT_C_OVER_CURRENT:
1097 DBG("USB_PORT_FEAT_C_OVER_CURRENT\n");
1100 case USB_PORT_FEAT_C_RESET:
1101 DBG("USB_PORT_FEAT_C_RESET\n");
1107 spin_lock_irqsave(&isp116x->lock, flags);
1108 isp116x_write_reg32(isp116x, wIndex
1109 ? HCRHPORT2 : HCRHPORT1, tmp);
1110 isp116x->rhport[wIndex] =
1111 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1112 spin_unlock_irqrestore(&isp116x->lock, flags);
1114 case SetPortFeature:
1115 DBG("SetPortFeature: ");
1116 if (!wIndex || wIndex > ports)
1120 case USB_PORT_FEAT_SUSPEND:
1121 DBG("USB_PORT_FEAT_SUSPEND\n");
1122 spin_lock_irqsave(&isp116x->lock, flags);
1123 isp116x_write_reg32(isp116x, wIndex
1124 ? HCRHPORT2 : HCRHPORT1, RH_PS_PSS);
1126 case USB_PORT_FEAT_POWER:
1127 DBG("USB_PORT_FEAT_POWER\n");
1128 spin_lock_irqsave(&isp116x->lock, flags);
1129 isp116x_write_reg32(isp116x, wIndex
1130 ? HCRHPORT2 : HCRHPORT1, RH_PS_PPS);
1132 case USB_PORT_FEAT_RESET:
1133 DBG("USB_PORT_FEAT_RESET\n");
1134 root_port_reset(isp116x, wIndex);
1135 spin_lock_irqsave(&isp116x->lock, flags);
1140 isp116x->rhport[wIndex] =
1141 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1142 spin_unlock_irqrestore(&isp116x->lock, flags);
1147 /* "protocol stall" on error */
1148 DBG("PROTOCOL STALL\n");
1156 static int isp116x_hub_suspend(struct usb_hcd *hcd)
1158 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1159 unsigned long flags;
1163 spin_lock_irqsave(&isp116x->lock, flags);
1165 val = isp116x_read_reg32(isp116x, HCCONTROL);
1166 switch (val & HCCONTROL_HCFS) {
1167 case HCCONTROL_USB_OPER:
1168 hcd->state = HC_STATE_QUIESCING;
1169 val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE);
1170 val |= HCCONTROL_USB_SUSPEND;
1171 if (hcd->remote_wakeup)
1172 val |= HCCONTROL_RWE;
1173 /* Wait for usb transfers to finish */
1175 isp116x_write_reg32(isp116x, HCCONTROL, val);
1176 hcd->state = HC_STATE_SUSPENDED;
1177 /* Wait for devices to suspend */
1179 case HCCONTROL_USB_SUSPEND:
1181 case HCCONTROL_USB_RESUME:
1182 isp116x_write_reg32(isp116x, HCCONTROL,
1183 (val & ~HCCONTROL_HCFS) |
1184 HCCONTROL_USB_RESET);
1185 case HCCONTROL_USB_RESET:
1192 spin_unlock_irqrestore(&isp116x->lock, flags);
1196 static int isp116x_hub_resume(struct usb_hcd *hcd)
1198 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1200 int ret = -EINPROGRESS;
1203 spin_lock_irq(&isp116x->lock);
1205 val = isp116x_read_reg32(isp116x, HCCONTROL);
1206 switch (val & HCCONTROL_HCFS) {
1207 case HCCONTROL_USB_SUSPEND:
1208 val &= ~HCCONTROL_HCFS;
1209 val |= HCCONTROL_USB_RESUME;
1210 isp116x_write_reg32(isp116x, HCCONTROL, val);
1211 case HCCONTROL_USB_RESUME:
1213 case HCCONTROL_USB_OPER:
1214 /* Without setting power_state here the
1215 SUSPENDED state won't be removed from
1216 sysfs/usbN/power.state as a response to remote
1217 wakeup. Maybe in the future. */
1218 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1225 if (ret != -EINPROGRESS) {
1226 spin_unlock_irq(&isp116x->lock);
1230 val = isp116x->rhdesca & RH_A_NDP;
1233 isp116x_read_reg32(isp116x, val ? HCRHPORT2 : HCRHPORT1);
1234 /* force global, not selective, resume */
1235 if (!(stat & RH_PS_PSS))
1237 DBG("%s: Resuming port %d\n", __func__, val);
1238 isp116x_write_reg32(isp116x, RH_PS_POCI, val
1239 ? HCRHPORT2 : HCRHPORT1);
1241 spin_unlock_irq(&isp116x->lock);
1243 hcd->state = HC_STATE_RESUMING;
1246 /* Go operational */
1247 spin_lock_irq(&isp116x->lock);
1248 val = isp116x_read_reg32(isp116x, HCCONTROL);
1249 isp116x_write_reg32(isp116x, HCCONTROL,
1250 (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER);
1251 spin_unlock_irq(&isp116x->lock);
1252 /* see analogous comment above */
1253 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1254 hcd->state = HC_STATE_RUNNING;
1259 static void isp116x_rh_resume(void *_hcd)
1261 struct usb_hcd *hcd = _hcd;
1263 usb_resume_device(hcd->self.root_hub);
1268 #define isp116x_hub_suspend NULL
1269 #define isp116x_hub_resume NULL
1271 static void isp116x_rh_resume(void *_hcd)
1277 /*-----------------------------------------------------------------*/
1279 #ifdef STUB_DEBUG_FILE
1281 static inline void create_debug_file(struct isp116x *isp116x)
1285 static inline void remove_debug_file(struct isp116x *isp116x)
1291 #include <linux/proc_fs.h>
1292 #include <linux/seq_file.h>
1294 static void dump_irq(struct seq_file *s, char *label, u16 mask)
1296 seq_printf(s, "%s %04x%s%s%s%s%s%s\n", label, mask,
1297 mask & HCuPINT_CLKRDY ? " clkrdy" : "",
1298 mask & HCuPINT_SUSP ? " susp" : "",
1299 mask & HCuPINT_OPR ? " opr" : "",
1300 mask & HCuPINT_AIIEOT ? " eot" : "",
1301 mask & HCuPINT_ATL ? " atl" : "",
1302 mask & HCuPINT_SOF ? " sof" : "");
1305 static void dump_int(struct seq_file *s, char *label, u32 mask)
1307 seq_printf(s, "%s %08x%s%s%s%s%s%s%s\n", label, mask,
1308 mask & HCINT_MIE ? " MIE" : "",
1309 mask & HCINT_RHSC ? " rhsc" : "",
1310 mask & HCINT_FNO ? " fno" : "",
1311 mask & HCINT_UE ? " ue" : "",
1312 mask & HCINT_RD ? " rd" : "",
1313 mask & HCINT_SF ? " sof" : "", mask & HCINT_SO ? " so" : "");
1316 static int proc_isp116x_show(struct seq_file *s, void *unused)
1318 struct isp116x *isp116x = s->private;
1319 struct isp116x_ep *ep;
1324 seq_printf(s, "%s\n%s version %s\n",
1325 isp116x_to_hcd(isp116x)->product_desc, hcd_name,
1328 if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x)->state)) {
1329 seq_printf(s, "HCD is suspended\n");
1332 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) {
1333 seq_printf(s, "HCD not running\n");
1337 spin_lock_irq(&isp116x->lock);
1339 dump_irq(s, "hc_irq_enable", isp116x_read_reg16(isp116x, HCuPINTENB));
1340 dump_irq(s, "hc_irq_status", isp116x_read_reg16(isp116x, HCuPINT));
1341 dump_int(s, "hc_int_enable", isp116x_read_reg32(isp116x, HCINTENB));
1342 dump_int(s, "hc_int_status", isp116x_read_reg32(isp116x, HCINTSTAT));
1344 list_for_each_entry(ep, &isp116x->async, schedule) {
1346 switch (ep->nextpid) {
1363 seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep,
1364 ep->epnum, str, ep->maxpacket);
1365 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
1366 seq_printf(s, " urb%p, %d/%d\n", urb,
1368 urb->transfer_buffer_length);
1371 if (!list_empty(&isp116x->async))
1372 seq_printf(s, "\n");
1374 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1376 for (i = 0; i < PERIODIC_SIZE; i++) {
1377 ep = isp116x->periodic[i];
1380 seq_printf(s, "%2d [%3d]:\n", i, isp116x->load[i]);
1382 /* DUMB: prints shared entries multiple times */
1384 seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
1387 USB_SPEED_FULL) ? "" : "ls ",
1388 ep->udev->devnum, ep->epnum,
1390 0) ? "" : ((ep->nextpid ==
1391 USB_PID_IN) ? "in" : "out"),
1396 spin_unlock_irq(&isp116x->lock);
1397 seq_printf(s, "\n");
1402 static int proc_isp116x_open(struct inode *inode, struct file *file)
1404 return single_open(file, proc_isp116x_show, PDE(inode)->data);
1407 static struct file_operations proc_ops = {
1408 .open = proc_isp116x_open,
1410 .llseek = seq_lseek,
1411 .release = single_release,
1414 /* expect just one isp116x per system */
1415 static const char proc_filename[] = "driver/isp116x";
1417 static void create_debug_file(struct isp116x *isp116x)
1419 struct proc_dir_entry *pde;
1421 pde = create_proc_entry(proc_filename, 0, NULL);
1425 pde->proc_fops = &proc_ops;
1426 pde->data = isp116x;
1430 static void remove_debug_file(struct isp116x *isp116x)
1433 remove_proc_entry(proc_filename, NULL);
1438 /*-----------------------------------------------------------------*/
1441 Software reset - can be called from any contect.
1443 static int isp116x_sw_reset(struct isp116x *isp116x)
1446 unsigned long flags;
1449 spin_lock_irqsave(&isp116x->lock, flags);
1450 isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC);
1451 isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR);
1453 /* It usually resets within 1 ms */
1455 if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR))
1459 ERR("Software reset timeout\n");
1462 spin_unlock_irqrestore(&isp116x->lock, flags);
1467 Reset. Tries to perform platform-specific hardware
1468 reset first; falls back to software reset.
1470 static int isp116x_reset(struct usb_hcd *hcd)
1472 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1475 int ret = 0, timeout = 15 /* ms */ ;
1477 if (isp116x->board && isp116x->board->reset) {
1478 /* Hardware reset */
1479 isp116x->board->reset(hcd->self.controller, 1);
1481 if (isp116x->board->clock)
1482 isp116x->board->clock(hcd->self.controller, 1);
1484 isp116x->board->reset(hcd->self.controller, 0);
1486 ret = isp116x_sw_reset(isp116x);
1491 t = jiffies + msecs_to_jiffies(timeout);
1492 while (time_before_eq(jiffies, t)) {
1494 spin_lock_irq(&isp116x->lock);
1495 clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY;
1496 spin_unlock_irq(&isp116x->lock);
1501 ERR("Clock not ready after 20ms\n");
1502 /* After sw_reset the clock won't report to be ready, if
1503 H_WAKEUP pin is high. */
1504 if (!isp116x->board || !isp116x->board->reset)
1505 ERR("The driver does not support hardware wakeup.\n");
1506 ERR("Please make sure that the H_WAKEUP pin "
1507 "is pulled low!\n");
1513 static void isp116x_stop(struct usb_hcd *hcd)
1515 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1516 unsigned long flags;
1519 spin_lock_irqsave(&isp116x->lock, flags);
1520 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1522 /* Switch off ports' power, some devices don't come up
1523 after next 'insmod' without this */
1524 val = isp116x_read_reg32(isp116x, HCRHDESCA);
1525 val &= ~(RH_A_NPS | RH_A_PSM);
1526 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1527 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
1528 spin_unlock_irqrestore(&isp116x->lock, flags);
1530 /* Put the chip into reset state */
1531 if (isp116x->board && isp116x->board->reset)
1532 isp116x->board->reset(hcd->self.controller, 0);
1534 isp116x_sw_reset(isp116x);
1536 /* Stop the clock */
1537 if (isp116x->board && isp116x->board->clock)
1538 isp116x->board->clock(hcd->self.controller, 0);
1542 Configure the chip. The chip must be successfully reset by now.
1544 static int isp116x_start(struct usb_hcd *hcd)
1546 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1547 struct isp116x_platform_data *board = isp116x->board;
1549 unsigned long flags;
1551 spin_lock_irqsave(&isp116x->lock, flags);
1553 /* clear interrupt status and disable all interrupt sources */
1554 isp116x_write_reg16(isp116x, HCuPINT, 0xff);
1555 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1557 val = isp116x_read_reg16(isp116x, HCCHIPID);
1558 if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
1559 ERR("Invalid chip ID %04x\n", val);
1560 spin_unlock_irqrestore(&isp116x->lock, flags);
1564 isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
1565 isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
1568 val = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
1569 if (board->sel15Kres)
1570 val |= HCHWCFG_15KRSEL;
1571 /* Remote wakeup won't work without working clock */
1572 if (board->clknotstop || board->remote_wakeup_enable)
1573 val |= HCHWCFG_CLKNOTSTOP;
1574 if (board->oc_enable)
1575 val |= HCHWCFG_ANALOG_OC;
1576 if (board->int_act_high)
1577 val |= HCHWCFG_INT_POL;
1578 if (board->int_edge_triggered)
1579 val |= HCHWCFG_INT_TRIGGER;
1580 isp116x_write_reg16(isp116x, HCHWCFG, val);
1582 /* ----- Root hub conf */
1584 /* AN10003_1.pdf recommends NPS to be always 1 */
1585 if (board->no_power_switching)
1587 if (board->power_switching_mode)
1590 val |= (board->potpg << 24) & RH_A_POTPGT;
1592 val |= (25 << 24) & RH_A_POTPGT;
1593 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1594 isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
1597 isp116x_write_reg32(isp116x, HCRHDESCB, val);
1598 isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB);
1601 if (board->remote_wakeup_enable) {
1602 hcd->can_wakeup = 1;
1605 isp116x_write_reg32(isp116x, HCRHSTATUS, val);
1606 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
1608 isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf);
1610 hcd->state = HC_STATE_RUNNING;
1612 /* Set up interrupts */
1613 isp116x->intenb = HCINT_MIE | HCINT_RHSC | HCINT_UE;
1614 if (board->remote_wakeup_enable)
1615 isp116x->intenb |= HCINT_RD;
1616 isp116x->irqenb = HCuPINT_ATL | HCuPINT_OPR; /* | HCuPINT_SUSP; */
1617 isp116x_write_reg32(isp116x, HCINTENB, isp116x->intenb);
1618 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
1620 /* Go operational */
1621 val = HCCONTROL_USB_OPER;
1622 /* Remote wakeup connected - NOT SUPPORTED */
1623 /* if (board->remote_wakeup_connected)
1624 val |= HCCONTROL_RWC; */
1625 if (board->remote_wakeup_enable)
1626 val |= HCCONTROL_RWE;
1627 isp116x_write_reg32(isp116x, HCCONTROL, val);
1629 /* Disable ports to avoid race in device enumeration */
1630 isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS);
1631 isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS);
1633 isp116x_show_regs(isp116x);
1634 spin_unlock_irqrestore(&isp116x->lock, flags);
1638 /*-----------------------------------------------------------------*/
1640 static struct hc_driver isp116x_hc_driver = {
1641 .description = hcd_name,
1642 .product_desc = "ISP116x Host Controller",
1643 .hcd_priv_size = sizeof(struct isp116x),
1648 .reset = isp116x_reset,
1649 .start = isp116x_start,
1650 .stop = isp116x_stop,
1652 .urb_enqueue = isp116x_urb_enqueue,
1653 .urb_dequeue = isp116x_urb_dequeue,
1654 .endpoint_disable = isp116x_endpoint_disable,
1656 .get_frame_number = isp116x_get_frame,
1658 .hub_status_data = isp116x_hub_status_data,
1659 .hub_control = isp116x_hub_control,
1660 .hub_suspend = isp116x_hub_suspend,
1661 .hub_resume = isp116x_hub_resume,
1664 /*----------------------------------------------------------------*/
1666 static int __init_or_module isp116x_remove(struct device *dev)
1668 struct usb_hcd *hcd = dev_get_drvdata(dev);
1669 struct isp116x *isp116x;
1670 struct platform_device *pdev;
1671 struct resource *res;
1675 isp116x = hcd_to_isp116x(hcd);
1676 pdev = container_of(dev, struct platform_device, dev);
1677 remove_debug_file(isp116x);
1678 usb_remove_hcd(hcd);
1680 iounmap(isp116x->data_reg);
1681 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1682 release_mem_region(res->start, 2);
1683 iounmap(isp116x->addr_reg);
1684 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1685 release_mem_region(res->start, 2);
1691 #define resource_len(r) (((r)->end - (r)->start) + 1)
1693 static int __init isp116x_probe(struct device *dev)
1695 struct usb_hcd *hcd;
1696 struct isp116x *isp116x;
1697 struct platform_device *pdev;
1698 struct resource *addr, *data;
1699 void __iomem *addr_reg;
1700 void __iomem *data_reg;
1704 pdev = container_of(dev, struct platform_device, dev);
1705 if (pdev->num_resources < 3) {
1710 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1711 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1712 irq = platform_get_irq(pdev, 0);
1713 if (!addr || !data || irq < 0) {
1718 if (dev->dma_mask) {
1719 DBG("DMA not supported\n");
1724 if (!request_mem_region(addr->start, 2, hcd_name)) {
1728 addr_reg = ioremap(addr->start, resource_len(addr));
1729 if (addr_reg == NULL) {
1733 if (!request_mem_region(data->start, 2, hcd_name)) {
1737 data_reg = ioremap(data->start, resource_len(data));
1738 if (data_reg == NULL) {
1743 /* allocate and initialize hcd */
1744 hcd = usb_create_hcd(&isp116x_hc_driver, dev, dev->bus_id);
1749 /* this rsrc_start is bogus */
1750 hcd->rsrc_start = addr->start;
1751 isp116x = hcd_to_isp116x(hcd);
1752 isp116x->data_reg = data_reg;
1753 isp116x->addr_reg = addr_reg;
1754 spin_lock_init(&isp116x->lock);
1755 INIT_LIST_HEAD(&isp116x->async);
1756 INIT_WORK(&isp116x->rh_resume, isp116x_rh_resume, hcd);
1757 isp116x->board = dev->platform_data;
1759 if (!isp116x->board) {
1760 ERR("Platform data structure not initialized\n");
1764 if (isp116x_check_platform_delay(isp116x)) {
1765 ERR("USE_PLATFORM_DELAY defined, but delay function not "
1767 ERR("See comments in drivers/usb/host/isp116x-hcd.c\n");
1772 ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
1776 create_debug_file(isp116x);
1784 release_mem_region(data->start, 2);
1788 release_mem_region(addr->start, 2);
1790 ERR("init error, %d\n", ret);
1796 Suspend of platform device
1798 static int isp116x_suspend(struct device *dev, pm_message_t state, u32 phase)
1801 struct usb_hcd *hcd = dev_get_drvdata(dev);
1803 VDBG("%s: state %x, phase %x\n", __func__, state, phase);
1805 if (phase != SUSPEND_DISABLE && phase != SUSPEND_POWER_DOWN)
1808 ret = usb_suspend_device(hcd->self.root_hub, state);
1810 dev->power.power_state = state;
1811 INFO("%s suspended\n", hcd_name);
1813 ERR("%s suspend failed\n", hcd_name);
1819 Resume platform device
1821 static int isp116x_resume(struct device *dev, u32 phase)
1824 struct usb_hcd *hcd = dev_get_drvdata(dev);
1826 VDBG("%s: state %x, phase %x\n", __func__, dev->power.power_state,
1828 if (phase != RESUME_POWER_ON)
1831 ret = usb_resume_device(hcd->self.root_hub);
1833 dev->power.power_state = PMSG_ON;
1834 VDBG("%s resumed\n", (char *)hcd_name);
1841 #define isp116x_suspend NULL
1842 #define isp116x_resume NULL
1846 static struct device_driver isp116x_driver = {
1847 .name = (char *)hcd_name,
1848 .bus = &platform_bus_type,
1849 .probe = isp116x_probe,
1850 .remove = isp116x_remove,
1851 .suspend = isp116x_suspend,
1852 .resume = isp116x_resume,
1855 /*-----------------------------------------------------------------*/
1857 static int __init isp116x_init(void)
1862 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1863 return driver_register(&isp116x_driver);
1866 module_init(isp116x_init);
1868 static void __exit isp116x_cleanup(void)
1870 driver_unregister(&isp116x_driver);
1873 module_exit(isp116x_cleanup);