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 /* Get rid of these declarations later in cleanup */
1205 static int isp116x_reset(struct usb_hcd *hcd);
1206 static int isp116x_start(struct usb_hcd *hcd);
1208 static int isp116x_bus_resume(struct usb_hcd *hcd)
1210 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1214 spin_lock_irq(&isp116x->lock);
1216 val = isp116x_read_reg32(isp116x, HCCONTROL);
1217 switch (val & HCCONTROL_HCFS) {
1218 case HCCONTROL_USB_SUSPEND:
1219 val &= ~HCCONTROL_HCFS;
1220 val |= HCCONTROL_USB_RESUME;
1221 isp116x_write_reg32(isp116x, HCCONTROL, val);
1222 case HCCONTROL_USB_RESUME:
1224 case HCCONTROL_USB_OPER:
1225 spin_unlock_irq(&isp116x->lock);
1226 /* Without setting power_state here the
1227 SUSPENDED state won't be removed from
1228 sysfs/usbN/power.state as a response to remote
1229 wakeup. Maybe in the future. */
1230 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1233 /* HCCONTROL_USB_RESET: this may happen, when during
1234 suspension the HC lost power. Reinitialize completely */
1235 spin_unlock_irq(&isp116x->lock);
1236 DBG("Chip has been reset while suspended. Reinit from scratch.\n");
1239 isp116x_hub_control(hcd, SetPortFeature,
1240 USB_PORT_FEAT_POWER, 1, NULL, 0);
1241 if ((isp116x->rhdesca & RH_A_NDP) == 2)
1242 isp116x_hub_control(hcd, SetPortFeature,
1243 USB_PORT_FEAT_POWER, 2, NULL, 0);
1244 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1248 val = isp116x->rhdesca & RH_A_NDP;
1251 isp116x_read_reg32(isp116x, val ? HCRHPORT2 : HCRHPORT1);
1252 /* force global, not selective, resume */
1253 if (!(stat & RH_PS_PSS))
1255 DBG("%s: Resuming port %d\n", __func__, val);
1256 isp116x_write_reg32(isp116x, RH_PS_POCI, val
1257 ? HCRHPORT2 : HCRHPORT1);
1259 spin_unlock_irq(&isp116x->lock);
1261 hcd->state = HC_STATE_RESUMING;
1264 /* Go operational */
1265 spin_lock_irq(&isp116x->lock);
1266 val = isp116x_read_reg32(isp116x, HCCONTROL);
1267 isp116x_write_reg32(isp116x, HCCONTROL,
1268 (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER);
1269 spin_unlock_irq(&isp116x->lock);
1270 /* see analogous comment above */
1271 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1272 hcd->state = HC_STATE_RUNNING;
1280 #define isp116x_bus_suspend NULL
1281 #define isp116x_bus_resume NULL
1285 /*-----------------------------------------------------------------*/
1287 #ifdef STUB_DEBUG_FILE
1289 static inline void create_debug_file(struct isp116x *isp116x)
1293 static inline void remove_debug_file(struct isp116x *isp116x)
1299 #include <linux/proc_fs.h>
1300 #include <linux/seq_file.h>
1302 static void dump_irq(struct seq_file *s, char *label, u16 mask)
1304 seq_printf(s, "%s %04x%s%s%s%s%s%s\n", label, mask,
1305 mask & HCuPINT_CLKRDY ? " clkrdy" : "",
1306 mask & HCuPINT_SUSP ? " susp" : "",
1307 mask & HCuPINT_OPR ? " opr" : "",
1308 mask & HCuPINT_AIIEOT ? " eot" : "",
1309 mask & HCuPINT_ATL ? " atl" : "",
1310 mask & HCuPINT_SOF ? " sof" : "");
1313 static void dump_int(struct seq_file *s, char *label, u32 mask)
1315 seq_printf(s, "%s %08x%s%s%s%s%s%s%s\n", label, mask,
1316 mask & HCINT_MIE ? " MIE" : "",
1317 mask & HCINT_RHSC ? " rhsc" : "",
1318 mask & HCINT_FNO ? " fno" : "",
1319 mask & HCINT_UE ? " ue" : "",
1320 mask & HCINT_RD ? " rd" : "",
1321 mask & HCINT_SF ? " sof" : "", mask & HCINT_SO ? " so" : "");
1324 static int proc_isp116x_show(struct seq_file *s, void *unused)
1326 struct isp116x *isp116x = s->private;
1327 struct isp116x_ep *ep;
1332 seq_printf(s, "%s\n%s version %s\n",
1333 isp116x_to_hcd(isp116x)->product_desc, hcd_name,
1336 if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x)->state)) {
1337 seq_printf(s, "HCD is suspended\n");
1340 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) {
1341 seq_printf(s, "HCD not running\n");
1345 spin_lock_irq(&isp116x->lock);
1347 dump_irq(s, "hc_irq_enable", isp116x_read_reg16(isp116x, HCuPINTENB));
1348 dump_irq(s, "hc_irq_status", isp116x_read_reg16(isp116x, HCuPINT));
1349 dump_int(s, "hc_int_enable", isp116x_read_reg32(isp116x, HCINTENB));
1350 dump_int(s, "hc_int_status", isp116x_read_reg32(isp116x, HCINTSTAT));
1352 list_for_each_entry(ep, &isp116x->async, schedule) {
1354 switch (ep->nextpid) {
1371 seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep,
1372 ep->epnum, str, ep->maxpacket);
1373 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
1374 seq_printf(s, " urb%p, %d/%d\n", urb,
1376 urb->transfer_buffer_length);
1379 if (!list_empty(&isp116x->async))
1380 seq_printf(s, "\n");
1382 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1384 for (i = 0; i < PERIODIC_SIZE; i++) {
1385 ep = isp116x->periodic[i];
1388 seq_printf(s, "%2d [%3d]:\n", i, isp116x->load[i]);
1390 /* DUMB: prints shared entries multiple times */
1392 seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
1395 USB_SPEED_FULL) ? "" : "ls ",
1396 ep->udev->devnum, ep->epnum,
1398 0) ? "" : ((ep->nextpid ==
1399 USB_PID_IN) ? "in" : "out"),
1404 spin_unlock_irq(&isp116x->lock);
1405 seq_printf(s, "\n");
1410 static int proc_isp116x_open(struct inode *inode, struct file *file)
1412 return single_open(file, proc_isp116x_show, PDE(inode)->data);
1415 static struct file_operations proc_ops = {
1416 .open = proc_isp116x_open,
1418 .llseek = seq_lseek,
1419 .release = single_release,
1422 /* expect just one isp116x per system */
1423 static const char proc_filename[] = "driver/isp116x";
1425 static void create_debug_file(struct isp116x *isp116x)
1427 struct proc_dir_entry *pde;
1429 pde = create_proc_entry(proc_filename, 0, NULL);
1433 pde->proc_fops = &proc_ops;
1434 pde->data = isp116x;
1438 static void remove_debug_file(struct isp116x *isp116x)
1441 remove_proc_entry(proc_filename, NULL);
1446 /*-----------------------------------------------------------------*/
1449 Software reset - can be called from any contect.
1451 static int isp116x_sw_reset(struct isp116x *isp116x)
1454 unsigned long flags;
1457 spin_lock_irqsave(&isp116x->lock, flags);
1458 isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC);
1459 isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR);
1461 /* It usually resets within 1 ms */
1463 if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR))
1467 ERR("Software reset timeout\n");
1470 spin_unlock_irqrestore(&isp116x->lock, flags);
1474 static int isp116x_reset(struct usb_hcd *hcd)
1476 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1479 int ret = 0, timeout = 15 /* ms */ ;
1481 ret = isp116x_sw_reset(isp116x);
1485 t = jiffies + msecs_to_jiffies(timeout);
1486 while (time_before_eq(jiffies, t)) {
1488 spin_lock_irq(&isp116x->lock);
1489 clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY;
1490 spin_unlock_irq(&isp116x->lock);
1495 ERR("Clock not ready after 20ms\n");
1496 /* After sw_reset the clock won't report to be ready, if
1497 H_WAKEUP pin is high. */
1498 ERR("Please make sure that the H_WAKEUP pin is pulled low!\n");
1504 static void isp116x_stop(struct usb_hcd *hcd)
1506 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1507 unsigned long flags;
1510 spin_lock_irqsave(&isp116x->lock, flags);
1511 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1513 /* Switch off ports' power, some devices don't come up
1514 after next 'insmod' without this */
1515 val = isp116x_read_reg32(isp116x, HCRHDESCA);
1516 val &= ~(RH_A_NPS | RH_A_PSM);
1517 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1518 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
1519 spin_unlock_irqrestore(&isp116x->lock, flags);
1521 isp116x_sw_reset(isp116x);
1525 Configure the chip. The chip must be successfully reset by now.
1527 static int isp116x_start(struct usb_hcd *hcd)
1529 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1530 struct isp116x_platform_data *board = isp116x->board;
1532 unsigned long flags;
1534 spin_lock_irqsave(&isp116x->lock, flags);
1536 /* clear interrupt status and disable all interrupt sources */
1537 isp116x_write_reg16(isp116x, HCuPINT, 0xff);
1538 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1540 val = isp116x_read_reg16(isp116x, HCCHIPID);
1541 if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
1542 ERR("Invalid chip ID %04x\n", val);
1543 spin_unlock_irqrestore(&isp116x->lock, flags);
1547 /* To be removed in future */
1548 hcd->uses_new_polling = 1;
1550 isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
1551 isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
1554 val = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
1555 if (board->sel15Kres)
1556 val |= HCHWCFG_15KRSEL;
1557 /* Remote wakeup won't work without working clock */
1558 if (board->remote_wakeup_enable)
1559 val |= HCHWCFG_CLKNOTSTOP;
1560 if (board->oc_enable)
1561 val |= HCHWCFG_ANALOG_OC;
1562 if (board->int_act_high)
1563 val |= HCHWCFG_INT_POL;
1564 if (board->int_edge_triggered)
1565 val |= HCHWCFG_INT_TRIGGER;
1566 isp116x_write_reg16(isp116x, HCHWCFG, val);
1568 /* ----- Root hub conf */
1569 val = (25 << 24) & RH_A_POTPGT;
1570 /* AN10003_1.pdf recommends RH_A_NPS (no power switching) to
1571 be always set. Yet, instead, we request individual port
1574 /* Report overcurrent per port */
1576 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1577 isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
1580 isp116x_write_reg32(isp116x, HCRHDESCB, val);
1581 isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB);
1584 if (board->remote_wakeup_enable) {
1585 hcd->can_wakeup = 1;
1588 isp116x_write_reg32(isp116x, HCRHSTATUS, val);
1589 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
1591 isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf);
1593 hcd->state = HC_STATE_RUNNING;
1595 /* Set up interrupts */
1596 isp116x->intenb = HCINT_MIE | HCINT_RHSC | HCINT_UE;
1597 if (board->remote_wakeup_enable)
1598 isp116x->intenb |= HCINT_RD;
1599 isp116x->irqenb = HCuPINT_ATL | HCuPINT_OPR; /* | HCuPINT_SUSP; */
1600 isp116x_write_reg32(isp116x, HCINTENB, isp116x->intenb);
1601 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
1603 /* Go operational */
1604 val = HCCONTROL_USB_OPER;
1605 if (board->remote_wakeup_enable)
1606 val |= HCCONTROL_RWE;
1607 isp116x_write_reg32(isp116x, HCCONTROL, val);
1609 /* Disable ports to avoid race in device enumeration */
1610 isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS);
1611 isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS);
1613 isp116x_show_regs(isp116x);
1614 spin_unlock_irqrestore(&isp116x->lock, flags);
1618 /*-----------------------------------------------------------------*/
1620 static struct hc_driver isp116x_hc_driver = {
1621 .description = hcd_name,
1622 .product_desc = "ISP116x Host Controller",
1623 .hcd_priv_size = sizeof(struct isp116x),
1628 .reset = isp116x_reset,
1629 .start = isp116x_start,
1630 .stop = isp116x_stop,
1632 .urb_enqueue = isp116x_urb_enqueue,
1633 .urb_dequeue = isp116x_urb_dequeue,
1634 .endpoint_disable = isp116x_endpoint_disable,
1636 .get_frame_number = isp116x_get_frame,
1638 .hub_status_data = isp116x_hub_status_data,
1639 .hub_control = isp116x_hub_control,
1640 .bus_suspend = isp116x_bus_suspend,
1641 .bus_resume = isp116x_bus_resume,
1644 /*----------------------------------------------------------------*/
1646 static int __init_or_module isp116x_remove(struct platform_device *pdev)
1648 struct usb_hcd *hcd = platform_get_drvdata(pdev);
1649 struct isp116x *isp116x;
1650 struct resource *res;
1654 isp116x = hcd_to_isp116x(hcd);
1655 remove_debug_file(isp116x);
1656 usb_remove_hcd(hcd);
1658 iounmap(isp116x->data_reg);
1659 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1660 release_mem_region(res->start, 2);
1661 iounmap(isp116x->addr_reg);
1662 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1663 release_mem_region(res->start, 2);
1669 #define resource_len(r) (((r)->end - (r)->start) + 1)
1671 static int __init isp116x_probe(struct platform_device *pdev)
1673 struct usb_hcd *hcd;
1674 struct isp116x *isp116x;
1675 struct resource *addr, *data;
1676 void __iomem *addr_reg;
1677 void __iomem *data_reg;
1681 if (pdev->num_resources < 3) {
1686 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1687 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1688 irq = platform_get_irq(pdev, 0);
1689 if (!addr || !data || irq < 0) {
1694 if (pdev->dev.dma_mask) {
1695 DBG("DMA not supported\n");
1700 if (!request_mem_region(addr->start, 2, hcd_name)) {
1704 addr_reg = ioremap(addr->start, resource_len(addr));
1705 if (addr_reg == NULL) {
1709 if (!request_mem_region(data->start, 2, hcd_name)) {
1713 data_reg = ioremap(data->start, resource_len(data));
1714 if (data_reg == NULL) {
1719 /* allocate and initialize hcd */
1720 hcd = usb_create_hcd(&isp116x_hc_driver, &pdev->dev, pdev->dev.bus_id);
1725 /* this rsrc_start is bogus */
1726 hcd->rsrc_start = addr->start;
1727 isp116x = hcd_to_isp116x(hcd);
1728 isp116x->data_reg = data_reg;
1729 isp116x->addr_reg = addr_reg;
1730 spin_lock_init(&isp116x->lock);
1731 INIT_LIST_HEAD(&isp116x->async);
1732 isp116x->board = pdev->dev.platform_data;
1734 if (!isp116x->board) {
1735 ERR("Platform data structure not initialized\n");
1739 if (isp116x_check_platform_delay(isp116x)) {
1740 ERR("USE_PLATFORM_DELAY defined, but delay function not "
1742 ERR("See comments in drivers/usb/host/isp116x-hcd.c\n");
1747 ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
1751 create_debug_file(isp116x);
1759 release_mem_region(data->start, 2);
1763 release_mem_region(addr->start, 2);
1765 ERR("init error, %d\n", ret);
1771 Suspend of platform device
1773 static int isp116x_suspend(struct platform_device *dev, pm_message_t state)
1777 VDBG("%s: state %x\n", __func__, state);
1779 dev->dev.power.power_state = state;
1785 Resume platform device
1787 static int isp116x_resume(struct platform_device *dev)
1791 VDBG("%s: state %x\n", __func__, dev->dev.power.power_state);
1793 dev->dev.power.power_state = PMSG_ON;
1800 #define isp116x_suspend NULL
1801 #define isp116x_resume NULL
1805 static struct platform_driver isp116x_driver = {
1806 .probe = isp116x_probe,
1807 .remove = isp116x_remove,
1808 .suspend = isp116x_suspend,
1809 .resume = isp116x_resume,
1811 .name = (char *)hcd_name,
1815 /*-----------------------------------------------------------------*/
1817 static int __init isp116x_init(void)
1822 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1823 return platform_driver_register(&isp116x_driver);
1826 module_init(isp116x_init);
1828 static void __exit isp116x_cleanup(void)
1830 platform_driver_unregister(&isp116x_driver);
1833 module_exit(isp116x_cleanup);