2 * ISP116x HCD (Host Controller Driver) for USB.
4 * Derived from the SL811 HCD, rewritten for ISP116x.
5 * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
8 * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
9 * Copyright (C) 2004 David Brownell
11 * Periodic scheduling is based on Roman's OHCI code
12 * Copyright (C) 1999 Roman Weissgaerber
17 * The driver basically works. A number of people have used it with a range
20 * The driver passes all usbtests 1-14.
22 * Suspending/resuming of root hub via sysfs works. Remote wakeup works too.
23 * And suspending/resuming of platform device works too. Suspend/resume
24 * via HCD operations vector is not implemented.
26 * Iso transfer support is not implemented. Adding this would include
27 * implementing recovery from the failure to service the processed ITL
28 * fifo ram in time, which will involve chip reset.
31 + More testing of suspend/resume.
35 ISP116x chips require certain delays between accesses to its
36 registers. The following timing options exist.
38 1. Configure your memory controller (the best)
39 2. Implement platform-specific delay function possibly
40 combined with configuring the memory controller; see
41 include/linux/usb-isp116x.h for more info. Some broken
42 memory controllers line LH7A400 SMC need this. Also,
43 uncomment for that to work the following
44 USE_PLATFORM_DELAY macro.
45 3. Use ndelay (easiest, poorest). For that, uncomment
46 the following USE_NDELAY macro.
48 #define USE_PLATFORM_DELAY
53 /* Transfer descriptors. See dump_ptd() for printout format */
55 /* enqueuing/finishing log of urbs */
58 #include <linux/config.h>
59 #include <linux/module.h>
60 #include <linux/moduleparam.h>
61 #include <linux/kernel.h>
62 #include <linux/delay.h>
63 #include <linux/ioport.h>
64 #include <linux/sched.h>
65 #include <linux/slab.h>
66 #include <linux/smp_lock.h>
67 #include <linux/errno.h>
68 #include <linux/init.h>
69 #include <linux/list.h>
70 #include <linux/interrupt.h>
71 #include <linux/usb.h>
72 #include <linux/usb_isp116x.h>
76 #include <asm/system.h>
77 #include <asm/byteorder.h>
80 # define STUB_DEBUG_FILE
83 #include "../core/hcd.h"
86 #define DRIVER_VERSION "05 Aug 2005"
87 #define DRIVER_DESC "ISP116x USB Host Controller Driver"
89 MODULE_DESCRIPTION(DRIVER_DESC);
90 MODULE_LICENSE("GPL");
92 static const char hcd_name[] = "isp116x-hcd";
94 /*-----------------------------------------------------------------*/
97 Write len bytes to fifo, pad till 32-bit boundary
99 static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len)
102 u16 *dp2 = (u16 *) buf;
106 if ((unsigned long)dp2 & 1) {
108 for (; len > 1; len -= 2) {
111 isp116x_raw_write_data16(isp116x, w);
114 isp116x_write_data16(isp116x, (u16) * dp);
117 for (; len > 1; len -= 2)
118 isp116x_raw_write_data16(isp116x, *dp2++);
120 isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2));
122 if (quot == 1 || quot == 2)
123 isp116x_raw_write_data16(isp116x, 0);
127 Read len bytes from fifo and then read till 32-bit boundary.
129 static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len)
132 u16 *dp2 = (u16 *) buf;
136 if ((unsigned long)dp2 & 1) {
138 for (; len > 1; len -= 2) {
139 w = isp116x_raw_read_data16(isp116x);
141 *dp++ = (w >> 8) & 0xff;
144 *dp = 0xff & isp116x_read_data16(isp116x);
147 for (; len > 1; len -= 2)
148 *dp2++ = isp116x_raw_read_data16(isp116x);
150 *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x);
152 if (quot == 1 || quot == 2)
153 isp116x_raw_read_data16(isp116x);
157 Write ptd's and data for scheduled transfers into
158 the fifo ram. Fifo must be empty and ready.
160 static void pack_fifo(struct isp116x *isp116x)
162 struct isp116x_ep *ep;
164 int buflen = isp116x->atl_last_dir == PTD_DIR_IN
165 ? isp116x->atl_bufshrt : isp116x->atl_buflen;
168 isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
169 isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
170 isp116x_write_addr(isp116x, HCATLPORT | ISP116x_WRITE_OFFSET);
171 for (ep = isp116x->atl_active; ep; ep = ep->active) {
175 dump_ptd_out_data(ptd, ep->data);
176 isp116x_write_data16(isp116x, ptd->count);
177 isp116x_write_data16(isp116x, ptd->mps);
178 isp116x_write_data16(isp116x, ptd->len);
179 isp116x_write_data16(isp116x, ptd->faddr);
180 buflen -= sizeof(struct ptd);
181 /* Skip writing data for last IN PTD */
182 if (ep->active || (isp116x->atl_last_dir != PTD_DIR_IN)) {
183 write_ptddata_to_fifo(isp116x, ep->data, ep->length);
184 buflen -= ALIGN(ep->length, 4);
191 Read the processed ptd's and data from fifo ram back to
192 URBs' buffers. Fifo must be full and done
194 static void unpack_fifo(struct isp116x *isp116x)
196 struct isp116x_ep *ep;
198 int buflen = isp116x->atl_last_dir == PTD_DIR_IN
199 ? isp116x->atl_buflen : isp116x->atl_bufshrt;
201 isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
202 isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
203 isp116x_write_addr(isp116x, HCATLPORT);
204 for (ep = isp116x->atl_active; ep; ep = ep->active) {
206 ptd->count = isp116x_read_data16(isp116x);
207 ptd->mps = isp116x_read_data16(isp116x);
208 ptd->len = isp116x_read_data16(isp116x);
209 ptd->faddr = isp116x_read_data16(isp116x);
210 buflen -= sizeof(struct ptd);
211 /* Skip reading data for last Setup or Out PTD */
212 if (ep->active || (isp116x->atl_last_dir == PTD_DIR_IN)) {
213 read_ptddata_from_fifo(isp116x, ep->data, ep->length);
214 buflen -= ALIGN(ep->length, 4);
217 dump_ptd_in_data(ptd, ep->data);
222 /*---------------------------------------------------------------*/
227 static void preproc_atl_queue(struct isp116x *isp116x)
229 struct isp116x_ep *ep;
234 for (ep = isp116x->atl_active; ep; ep = ep->active) {
235 u16 toggle = 0, dir = PTD_DIR_SETUP;
237 BUG_ON(list_empty(&ep->hep->urb_list));
238 urb = container_of(ep->hep->urb_list.next,
239 struct urb, urb_list);
242 spin_lock(&urb->lock);
243 ep->data = (unsigned char *)urb->transfer_buffer
244 + urb->actual_length;
246 switch (ep->nextpid) {
248 toggle = usb_gettoggle(urb->dev, ep->epnum, 0);
252 toggle = usb_gettoggle(urb->dev, ep->epnum, 1);
256 len = sizeof(struct usb_ctrlrequest);
257 ep->data = urb->setup_packet;
262 dir = (urb->transfer_buffer_length
263 && usb_pipein(urb->pipe))
264 ? PTD_DIR_OUT : PTD_DIR_IN;
267 ERR("%s %d: ep->nextpid %d\n", __func__, __LINE__,
272 ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle);
273 ptd->mps = PTD_MPS(ep->maxpacket)
274 | PTD_SPD(urb->dev->speed == USB_SPEED_LOW)
276 ptd->len = PTD_LEN(len) | PTD_DIR(dir);
277 ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe));
278 spin_unlock(&urb->lock);
280 ptd->mps |= PTD_LAST_MSK;
281 isp116x->atl_last_dir = dir;
283 isp116x->atl_bufshrt = sizeof(struct ptd) + isp116x->atl_buflen;
284 isp116x->atl_buflen = isp116x->atl_bufshrt + ALIGN(len, 4);
289 Analyze transfer results, handle partial transfers and errors
291 static void postproc_atl_queue(struct isp116x *isp116x)
293 struct isp116x_ep *ep;
295 struct usb_device *udev;
300 for (ep = isp116x->atl_active; ep; ep = ep->active) {
301 BUG_ON(list_empty(&ep->hep->urb_list));
303 container_of(ep->hep->urb_list.next, struct urb, urb_list);
306 cc = PTD_GET_CC(ptd);
308 spin_lock(&urb->lock);
311 /* Data underrun is special. For allowed underrun
312 we clear the error and continue as normal. For
313 forbidden underrun we finish the DATA stage
314 immediately while for control transfer,
315 we do a STATUS stage. */
316 if (cc == TD_DATAUNDERRUN) {
317 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) {
318 DBG("Allowed data underrun\n");
323 if (usb_pipecontrol(urb->pipe))
324 ep->nextpid = USB_PID_ACK;
326 usb_settoggle(udev, ep->epnum,
329 PTD_GET_TOGGLE(ptd));
330 urb->actual_length += PTD_GET_COUNT(ptd);
331 urb->status = cc_to_error[TD_DATAUNDERRUN];
332 spin_unlock(&urb->lock);
336 /* Keep underrun error through the STATUS stage */
337 if (urb->status == cc_to_error[TD_DATAUNDERRUN])
338 cc = TD_DATAUNDERRUN;
340 if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED
341 && (++ep->error_count >= 3 || cc == TD_CC_STALL
342 || cc == TD_DATAOVERRUN)) {
343 if (urb->status == -EINPROGRESS)
344 urb->status = cc_to_error[cc];
345 if (ep->nextpid == USB_PID_ACK)
347 spin_unlock(&urb->lock);
350 /* According to usb spec, zero-length Int transfer signals
351 finishing of the urb. Hey, does this apply only
353 if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) {
354 if (urb->status == -EINPROGRESS)
356 spin_unlock(&urb->lock);
360 /* Relax after previously failed, but later succeeded
361 or correctly NAK'ed retransmission attempt */
363 && (cc == TD_CC_NOERROR || cc == TD_NOTACCESSED))
366 /* Take into account idiosyncracies of the isp116x chip
367 regarding toggle bit for failed transfers */
368 if (ep->nextpid == USB_PID_OUT)
369 usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd)
370 ^ (ep->error_count > 0));
371 else if (ep->nextpid == USB_PID_IN)
372 usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd)
373 ^ (ep->error_count > 0));
375 switch (ep->nextpid) {
378 urb->actual_length += PTD_GET_COUNT(ptd);
379 if (PTD_GET_ACTIVE(ptd)
380 || (cc != TD_CC_NOERROR && cc < 0x0E))
382 if (urb->transfer_buffer_length != urb->actual_length) {
386 if (urb->transfer_flags & URB_ZERO_PACKET
387 && ep->nextpid == USB_PID_OUT
388 && !(PTD_GET_COUNT(ptd) % ep->maxpacket)) {
389 DBG("Zero packet requested\n");
393 /* All data for this URB is transferred, let's finish */
394 if (usb_pipecontrol(urb->pipe))
395 ep->nextpid = USB_PID_ACK;
396 else if (urb->status == -EINPROGRESS)
400 if (PTD_GET_ACTIVE(ptd)
401 || (cc != TD_CC_NOERROR && cc < 0x0E))
403 if (urb->transfer_buffer_length == urb->actual_length)
404 ep->nextpid = USB_PID_ACK;
405 else if (usb_pipeout(urb->pipe)) {
406 usb_settoggle(udev, 0, 1, 1);
407 ep->nextpid = USB_PID_OUT;
409 usb_settoggle(udev, 0, 0, 1);
410 ep->nextpid = USB_PID_IN;
414 if (PTD_GET_ACTIVE(ptd)
415 || (cc != TD_CC_NOERROR && cc < 0x0E))
417 if (urb->status == -EINPROGRESS)
424 spin_unlock(&urb->lock);
429 Take done or failed requests out of schedule. Give back
432 static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
433 struct urb *urb, struct pt_regs *regs)
434 __releases(isp116x->lock) __acquires(isp116x->lock)
441 if (usb_pipecontrol(urb->pipe))
442 ep->nextpid = USB_PID_SETUP;
444 urb_dbg(urb, "Finish");
446 spin_unlock(&isp116x->lock);
447 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb, regs);
448 spin_lock(&isp116x->lock);
450 /* take idle endpoints out of the schedule */
451 if (!list_empty(&ep->hep->urb_list))
454 /* async deschedule */
455 if (!list_empty(&ep->schedule)) {
456 list_del_init(&ep->schedule);
460 /* periodic deschedule */
461 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
462 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
463 struct isp116x_ep *temp;
464 struct isp116x_ep **prev = &isp116x->periodic[i];
466 while (*prev && ((temp = *prev) != ep))
470 isp116x->load[i] -= ep->load;
472 ep->branch = PERIODIC_SIZE;
473 isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
474 ep->load / ep->period;
476 /* switch irq type? */
477 if (!--isp116x->periodic_count) {
478 isp116x->irqenb &= ~HCuPINT_SOF;
479 isp116x->irqenb |= HCuPINT_ATL;
484 Scan transfer lists, schedule transfers, send data off
487 static void start_atl_transfers(struct isp116x *isp116x)
489 struct isp116x_ep *last_ep = NULL, *ep;
492 int len, index, speed, byte_time;
494 if (atomic_read(&isp116x->atl_finishing))
497 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state))
500 /* FIFO not empty? */
501 if (isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_FULL)
504 isp116x->atl_active = NULL;
505 isp116x->atl_buflen = isp116x->atl_bufshrt = 0;
507 /* Schedule int transfers */
508 if (isp116x->periodic_count) {
509 isp116x->fmindex = index =
510 (isp116x->fmindex + 1) & (PERIODIC_SIZE - 1);
511 if ((load = isp116x->load[index])) {
512 /* Bring all int transfers for this frame
513 into the active queue */
514 isp116x->atl_active = last_ep =
515 isp116x->periodic[index];
516 while (last_ep->next)
517 last_ep = (last_ep->active = last_ep->next);
518 last_ep->active = NULL;
522 /* Schedule control/bulk transfers */
523 list_for_each_entry(ep, &isp116x->async, schedule) {
524 urb = container_of(ep->hep->urb_list.next,
525 struct urb, urb_list);
526 speed = urb->dev->speed;
527 byte_time = speed == USB_SPEED_LOW
528 ? BYTE_TIME_LOWSPEED : BYTE_TIME_FULLSPEED;
530 if (ep->nextpid == USB_PID_SETUP) {
531 len = sizeof(struct usb_ctrlrequest);
532 } else if (ep->nextpid == USB_PID_ACK) {
535 /* Find current free length ... */
536 len = (MAX_LOAD_LIMIT - load) / byte_time;
538 /* ... then limit it to configured max size ... */
539 len = min(len, speed == USB_SPEED_LOW ?
540 MAX_TRANSFER_SIZE_LOWSPEED :
541 MAX_TRANSFER_SIZE_FULLSPEED);
543 /* ... and finally cut to the multiple of MaxPacketSize,
544 or to the real length if there's enough room. */
546 (urb->transfer_buffer_length -
547 urb->actual_length)) {
548 len -= len % ep->maxpacket;
552 len = urb->transfer_buffer_length -
557 load += len * byte_time;
558 if (load > MAX_LOAD_LIMIT)
564 last_ep->active = ep;
566 isp116x->atl_active = ep;
570 /* Avoid starving of endpoints */
571 if ((&isp116x->async)->next != (&isp116x->async)->prev)
572 list_move(&isp116x->async, (&isp116x->async)->next);
574 if (isp116x->atl_active) {
575 preproc_atl_queue(isp116x);
581 Finish the processed transfers
583 static void finish_atl_transfers(struct isp116x *isp116x, struct pt_regs *regs)
585 struct isp116x_ep *ep;
588 if (!isp116x->atl_active)
590 /* Fifo not ready? */
591 if (!(isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_DONE))
594 atomic_inc(&isp116x->atl_finishing);
595 unpack_fifo(isp116x);
596 postproc_atl_queue(isp116x);
597 for (ep = isp116x->atl_active; ep; ep = ep->active) {
599 container_of(ep->hep->urb_list.next, struct urb, urb_list);
600 /* USB_PID_ACK check here avoids finishing of
601 control transfers, for which TD_DATAUNDERRUN
602 occured, while URB_SHORT_NOT_OK was set */
603 if (urb && urb->status != -EINPROGRESS
604 && ep->nextpid != USB_PID_ACK)
605 finish_request(isp116x, ep, urb, regs);
607 atomic_dec(&isp116x->atl_finishing);
610 static irqreturn_t isp116x_irq(struct usb_hcd *hcd, struct pt_regs *regs)
612 struct isp116x *isp116x = hcd_to_isp116x(hcd);
614 irqreturn_t ret = IRQ_NONE;
616 spin_lock(&isp116x->lock);
617 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
618 irqstat = isp116x_read_reg16(isp116x, HCuPINT);
619 isp116x_write_reg16(isp116x, HCuPINT, irqstat);
621 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
623 finish_atl_transfers(isp116x, regs);
626 if (irqstat & HCuPINT_OPR) {
627 u32 intstat = isp116x_read_reg32(isp116x, HCINTSTAT);
628 isp116x_write_reg32(isp116x, HCINTSTAT, intstat);
629 if (intstat & HCINT_UE) {
630 ERR("Unrecoverable error\n");
631 /* What should we do here? Reset? */
633 if (intstat & HCINT_RHSC)
634 /* When root hub or any of its ports is going
635 to come out of suspend, it may take more
636 than 10ms for status bits to stabilize. */
637 mod_timer(&hcd->rh_timer, jiffies
638 + msecs_to_jiffies(20) + 1);
639 if (intstat & HCINT_RD) {
640 DBG("---- remote wakeup\n");
641 schedule_work(&isp116x->rh_resume);
644 irqstat &= ~HCuPINT_OPR;
648 if (irqstat & (HCuPINT_ATL | HCuPINT_SOF)) {
649 start_atl_transfers(isp116x);
652 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
653 spin_unlock(&isp116x->lock);
657 /*-----------------------------------------------------------------*/
659 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
660 * this driver doesn't promise that much since it's got to handle an
661 * IRQ per packet; irq handling latencies also use up that time.
665 #define MAX_PERIODIC_LOAD 600
666 static int balance(struct isp116x *isp116x, u16 period, u16 load)
668 int i, branch = -ENOSPC;
670 /* search for the least loaded schedule branch of that period
671 which has enough bandwidth left unreserved. */
672 for (i = 0; i < period; i++) {
673 if (branch < 0 || isp116x->load[branch] > isp116x->load[i]) {
676 for (j = i; j < PERIODIC_SIZE; j += period) {
677 if ((isp116x->load[j] + load)
681 if (j < PERIODIC_SIZE)
689 /* NB! ALL the code above this point runs with isp116x->lock
693 /*-----------------------------------------------------------------*/
695 static int isp116x_urb_enqueue(struct usb_hcd *hcd,
696 struct usb_host_endpoint *hep, struct urb *urb,
699 struct isp116x *isp116x = hcd_to_isp116x(hcd);
700 struct usb_device *udev = urb->dev;
701 unsigned int pipe = urb->pipe;
702 int is_out = !usb_pipein(pipe);
703 int type = usb_pipetype(pipe);
704 int epnum = usb_pipeendpoint(pipe);
705 struct isp116x_ep *ep = NULL;
710 urb_dbg(urb, "Enqueue");
712 if (type == PIPE_ISOCHRONOUS) {
713 ERR("Isochronous transfers not supported\n");
714 urb_dbg(urb, "Refused to enqueue");
717 /* avoid all allocations within spinlocks: request or endpoint */
719 ep = kzalloc(sizeof *ep, mem_flags);
724 spin_lock_irqsave(&isp116x->lock, flags);
725 if (!HC_IS_RUNNING(hcd->state)) {
733 INIT_LIST_HEAD(&ep->schedule);
734 ep->udev = usb_get_dev(udev);
736 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
737 usb_settoggle(udev, epnum, is_out, 0);
739 if (type == PIPE_CONTROL) {
740 ep->nextpid = USB_PID_SETUP;
742 ep->nextpid = USB_PID_OUT;
744 ep->nextpid = USB_PID_IN;
749 With INT URBs submitted, the driver works with SOF
750 interrupt enabled and ATL interrupt disabled. After
751 the PTDs are written to fifo ram, the chip starts
752 fifo processing and usb transfers after the next
753 SOF and continues until the transfers are finished
754 (succeeded or failed) or the frame ends. Therefore,
755 the transfers occur only in every second frame,
756 while fifo reading/writing and data processing
757 occur in every other second frame. */
758 if (urb->interval < 2)
760 if (urb->interval > 2 * PERIODIC_SIZE)
761 urb->interval = 2 * PERIODIC_SIZE;
762 ep->period = urb->interval >> 1;
763 ep->branch = PERIODIC_SIZE;
764 ep->load = usb_calc_bus_time(udev->speed,
766 (type == PIPE_ISOCHRONOUS),
767 usb_maxpacket(udev, pipe,
775 /* maybe put endpoint into schedule */
779 if (list_empty(&ep->schedule))
780 list_add_tail(&ep->schedule, &isp116x->async);
783 urb->interval = ep->period;
784 ep->length = min((int)ep->maxpacket,
785 urb->transfer_buffer_length);
787 /* urb submitted for already existing endpoint */
788 if (ep->branch < PERIODIC_SIZE)
791 ret = ep->branch = balance(isp116x, ep->period, ep->load);
796 urb->start_frame = (isp116x->fmindex & (PERIODIC_SIZE - 1))
799 /* sort each schedule branch by period (slow before fast)
800 to share the faster parts of the tree without needing
801 dummy/placeholder nodes */
802 DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
803 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
804 struct isp116x_ep **prev = &isp116x->periodic[i];
805 struct isp116x_ep *here = *prev;
807 while (here && ep != here) {
808 if (ep->period > here->period)
817 isp116x->load[i] += ep->load;
819 hcd->self.bandwidth_allocated += ep->load / ep->period;
821 /* switch over to SOFint */
822 if (!isp116x->periodic_count++) {
823 isp116x->irqenb &= ~HCuPINT_ATL;
824 isp116x->irqenb |= HCuPINT_SOF;
825 isp116x_write_reg16(isp116x, HCuPINTENB,
830 /* in case of unlink-during-submit */
831 spin_lock(&urb->lock);
832 if (urb->status != -EINPROGRESS) {
833 spin_unlock(&urb->lock);
834 finish_request(isp116x, ep, urb, NULL);
839 spin_unlock(&urb->lock);
840 start_atl_transfers(isp116x);
843 spin_unlock_irqrestore(&isp116x->lock, flags);
850 static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
852 struct isp116x *isp116x = hcd_to_isp116x(hcd);
853 struct usb_host_endpoint *hep;
854 struct isp116x_ep *ep, *ep_act;
857 spin_lock_irqsave(&isp116x->lock, flags);
859 /* URB already unlinked (or never linked)? */
861 spin_unlock_irqrestore(&isp116x->lock, flags);
865 WARN_ON(hep != ep->hep);
867 /* In front of queue? */
868 if (ep->hep->urb_list.next == &urb->urb_list)
870 for (ep_act = isp116x->atl_active; ep_act;
871 ep_act = ep_act->active)
873 VDBG("dequeue, urb %p active; wait for irq\n",
880 finish_request(isp116x, ep, urb, NULL);
882 spin_unlock_irqrestore(&isp116x->lock, flags);
886 static void isp116x_endpoint_disable(struct usb_hcd *hcd,
887 struct usb_host_endpoint *hep)
890 struct isp116x_ep *ep = hep->hcpriv;;
895 /* assume we'd just wait for the irq */
896 for (i = 0; i < 100 && !list_empty(&hep->urb_list); i++)
898 if (!list_empty(&hep->urb_list))
899 WARN("ep %p not empty?\n", ep);
901 usb_put_dev(ep->udev);
906 static int isp116x_get_frame(struct usb_hcd *hcd)
908 struct isp116x *isp116x = hcd_to_isp116x(hcd);
912 spin_lock_irqsave(&isp116x->lock, flags);
913 fmnum = isp116x_read_reg32(isp116x, HCFMNUM);
914 spin_unlock_irqrestore(&isp116x->lock, flags);
918 /*----------------------------------------------------------------*/
921 Adapted from ohci-hub.c. Currently we don't support autosuspend.
923 static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
925 struct isp116x *isp116x = hcd_to_isp116x(hcd);
926 int ports, i, changed = 0;
929 if (!HC_IS_RUNNING(hcd->state))
932 /* Report no status change now, if we are scheduled to be
934 if (timer_pending(&hcd->rh_timer))
937 ports = isp116x->rhdesca & RH_A_NDP;
938 spin_lock_irqsave(&isp116x->lock, flags);
939 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
940 if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
941 buf[0] = changed = 1;
945 for (i = 0; i < ports; i++) {
946 u32 status = isp116x->rhport[i] =
947 isp116x_read_reg32(isp116x, i ? HCRHPORT2 : HCRHPORT1);
949 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
950 | RH_PS_OCIC | RH_PS_PRSC)) {
952 buf[0] |= 1 << (i + 1);
956 spin_unlock_irqrestore(&isp116x->lock, flags);
960 static void isp116x_hub_descriptor(struct isp116x *isp116x,
961 struct usb_hub_descriptor *desc)
963 u32 reg = isp116x->rhdesca;
965 desc->bDescriptorType = 0x29;
966 desc->bDescLength = 9;
967 desc->bHubContrCurrent = 0;
968 desc->bNbrPorts = (u8) (reg & 0x3);
969 /* Power switching, device type, overcurrent. */
970 desc->wHubCharacteristics =
971 (__force __u16) cpu_to_le16((u16) ((reg >> 8) & 0x1f));
972 desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff);
973 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
974 desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
975 desc->bitmap[1] = ~0;
978 /* Perform reset of a given port.
979 It would be great to just start the reset and let the
980 USB core to clear the reset in due time. However,
981 root hub ports should be reset for at least 50 ms, while
982 our chip stays in reset for about 10 ms. I.e., we must
983 repeatedly reset it ourself here.
985 static inline void root_port_reset(struct isp116x *isp116x, unsigned port)
988 unsigned long flags, t;
990 /* Root hub reset should be 50 ms, but some devices
991 want it even longer. */
992 t = jiffies + msecs_to_jiffies(100);
994 while (time_before(jiffies, t)) {
995 spin_lock_irqsave(&isp116x->lock, flags);
996 /* spin until any current reset finishes */
998 tmp = isp116x_read_reg32(isp116x, port ?
999 HCRHPORT2 : HCRHPORT1);
1000 if (!(tmp & RH_PS_PRS))
1004 /* Don't reset a disconnected port */
1005 if (!(tmp & RH_PS_CCS)) {
1006 spin_unlock_irqrestore(&isp116x->lock, flags);
1009 /* Reset lasts 10ms (claims datasheet) */
1010 isp116x_write_reg32(isp116x, port ? HCRHPORT2 :
1011 HCRHPORT1, (RH_PS_PRS));
1012 spin_unlock_irqrestore(&isp116x->lock, flags);
1017 /* Adapted from ohci-hub.c */
1018 static int isp116x_hub_control(struct usb_hcd *hcd,
1020 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1022 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1024 unsigned long flags;
1025 int ports = isp116x->rhdesca & RH_A_NDP;
1029 case ClearHubFeature:
1030 DBG("ClearHubFeature: ");
1032 case C_HUB_OVER_CURRENT:
1033 DBG("C_HUB_OVER_CURRENT\n");
1034 spin_lock_irqsave(&isp116x->lock, flags);
1035 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_OCIC);
1036 spin_unlock_irqrestore(&isp116x->lock, flags);
1037 case C_HUB_LOCAL_POWER:
1038 DBG("C_HUB_LOCAL_POWER\n");
1045 DBG("SetHubFeature: ");
1047 case C_HUB_OVER_CURRENT:
1048 case C_HUB_LOCAL_POWER:
1049 DBG("C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1055 case GetHubDescriptor:
1056 DBG("GetHubDescriptor\n");
1057 isp116x_hub_descriptor(isp116x,
1058 (struct usb_hub_descriptor *)buf);
1061 DBG("GetHubStatus\n");
1062 *(__le32 *) buf = 0;
1065 DBG("GetPortStatus\n");
1066 if (!wIndex || wIndex > ports)
1068 tmp = isp116x->rhport[--wIndex];
1069 *(__le32 *) buf = cpu_to_le32(tmp);
1070 DBG("GetPortStatus: port[%d] %08x\n", wIndex + 1, tmp);
1072 case ClearPortFeature:
1073 DBG("ClearPortFeature: ");
1074 if (!wIndex || wIndex > ports)
1079 case USB_PORT_FEAT_ENABLE:
1080 DBG("USB_PORT_FEAT_ENABLE\n");
1083 case USB_PORT_FEAT_C_ENABLE:
1084 DBG("USB_PORT_FEAT_C_ENABLE\n");
1087 case USB_PORT_FEAT_SUSPEND:
1088 DBG("USB_PORT_FEAT_SUSPEND\n");
1091 case USB_PORT_FEAT_C_SUSPEND:
1092 DBG("USB_PORT_FEAT_C_SUSPEND\n");
1095 case USB_PORT_FEAT_POWER:
1096 DBG("USB_PORT_FEAT_POWER\n");
1099 case USB_PORT_FEAT_C_CONNECTION:
1100 DBG("USB_PORT_FEAT_C_CONNECTION\n");
1103 case USB_PORT_FEAT_C_OVER_CURRENT:
1104 DBG("USB_PORT_FEAT_C_OVER_CURRENT\n");
1107 case USB_PORT_FEAT_C_RESET:
1108 DBG("USB_PORT_FEAT_C_RESET\n");
1114 spin_lock_irqsave(&isp116x->lock, flags);
1115 isp116x_write_reg32(isp116x, wIndex
1116 ? HCRHPORT2 : HCRHPORT1, tmp);
1117 isp116x->rhport[wIndex] =
1118 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1119 spin_unlock_irqrestore(&isp116x->lock, flags);
1121 case SetPortFeature:
1122 DBG("SetPortFeature: ");
1123 if (!wIndex || wIndex > ports)
1127 case USB_PORT_FEAT_SUSPEND:
1128 DBG("USB_PORT_FEAT_SUSPEND\n");
1129 spin_lock_irqsave(&isp116x->lock, flags);
1130 isp116x_write_reg32(isp116x, wIndex
1131 ? HCRHPORT2 : HCRHPORT1, RH_PS_PSS);
1133 case USB_PORT_FEAT_POWER:
1134 DBG("USB_PORT_FEAT_POWER\n");
1135 spin_lock_irqsave(&isp116x->lock, flags);
1136 isp116x_write_reg32(isp116x, wIndex
1137 ? HCRHPORT2 : HCRHPORT1, RH_PS_PPS);
1139 case USB_PORT_FEAT_RESET:
1140 DBG("USB_PORT_FEAT_RESET\n");
1141 root_port_reset(isp116x, wIndex);
1142 spin_lock_irqsave(&isp116x->lock, flags);
1147 isp116x->rhport[wIndex] =
1148 isp116x_read_reg32(isp116x, wIndex ? HCRHPORT2 : HCRHPORT1);
1149 spin_unlock_irqrestore(&isp116x->lock, flags);
1154 /* "protocol stall" on error */
1155 DBG("PROTOCOL STALL\n");
1163 static int isp116x_hub_suspend(struct usb_hcd *hcd)
1165 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1166 unsigned long flags;
1170 spin_lock_irqsave(&isp116x->lock, flags);
1172 val = isp116x_read_reg32(isp116x, HCCONTROL);
1173 switch (val & HCCONTROL_HCFS) {
1174 case HCCONTROL_USB_OPER:
1175 hcd->state = HC_STATE_QUIESCING;
1176 val &= (~HCCONTROL_HCFS & ~HCCONTROL_RWE);
1177 val |= HCCONTROL_USB_SUSPEND;
1178 if (hcd->remote_wakeup)
1179 val |= HCCONTROL_RWE;
1180 /* Wait for usb transfers to finish */
1182 isp116x_write_reg32(isp116x, HCCONTROL, val);
1183 hcd->state = HC_STATE_SUSPENDED;
1184 /* Wait for devices to suspend */
1186 case HCCONTROL_USB_SUSPEND:
1188 case HCCONTROL_USB_RESUME:
1189 isp116x_write_reg32(isp116x, HCCONTROL,
1190 (val & ~HCCONTROL_HCFS) |
1191 HCCONTROL_USB_RESET);
1192 case HCCONTROL_USB_RESET:
1199 spin_unlock_irqrestore(&isp116x->lock, flags);
1203 static int isp116x_hub_resume(struct usb_hcd *hcd)
1205 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1207 int ret = -EINPROGRESS;
1210 spin_lock_irq(&isp116x->lock);
1212 val = isp116x_read_reg32(isp116x, HCCONTROL);
1213 switch (val & HCCONTROL_HCFS) {
1214 case HCCONTROL_USB_SUSPEND:
1215 val &= ~HCCONTROL_HCFS;
1216 val |= HCCONTROL_USB_RESUME;
1217 isp116x_write_reg32(isp116x, HCCONTROL, val);
1218 case HCCONTROL_USB_RESUME:
1220 case HCCONTROL_USB_OPER:
1221 /* Without setting power_state here the
1222 SUSPENDED state won't be removed from
1223 sysfs/usbN/power.state as a response to remote
1224 wakeup. Maybe in the future. */
1225 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1232 if (ret != -EINPROGRESS) {
1233 spin_unlock_irq(&isp116x->lock);
1237 val = isp116x->rhdesca & RH_A_NDP;
1240 isp116x_read_reg32(isp116x, val ? HCRHPORT2 : HCRHPORT1);
1241 /* force global, not selective, resume */
1242 if (!(stat & RH_PS_PSS))
1244 DBG("%s: Resuming port %d\n", __func__, val);
1245 isp116x_write_reg32(isp116x, RH_PS_POCI, val
1246 ? HCRHPORT2 : HCRHPORT1);
1248 spin_unlock_irq(&isp116x->lock);
1250 hcd->state = HC_STATE_RESUMING;
1253 /* Go operational */
1254 spin_lock_irq(&isp116x->lock);
1255 val = isp116x_read_reg32(isp116x, HCCONTROL);
1256 isp116x_write_reg32(isp116x, HCCONTROL,
1257 (val & ~HCCONTROL_HCFS) | HCCONTROL_USB_OPER);
1258 spin_unlock_irq(&isp116x->lock);
1259 /* see analogous comment above */
1260 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1261 hcd->state = HC_STATE_RUNNING;
1266 static void isp116x_rh_resume(void *_hcd)
1268 struct usb_hcd *hcd = _hcd;
1270 usb_resume_device(hcd->self.root_hub);
1275 #define isp116x_hub_suspend NULL
1276 #define isp116x_hub_resume NULL
1278 static void isp116x_rh_resume(void *_hcd)
1284 /*-----------------------------------------------------------------*/
1286 #ifdef STUB_DEBUG_FILE
1288 static inline void create_debug_file(struct isp116x *isp116x)
1292 static inline void remove_debug_file(struct isp116x *isp116x)
1298 #include <linux/proc_fs.h>
1299 #include <linux/seq_file.h>
1301 static void dump_irq(struct seq_file *s, char *label, u16 mask)
1303 seq_printf(s, "%s %04x%s%s%s%s%s%s\n", label, mask,
1304 mask & HCuPINT_CLKRDY ? " clkrdy" : "",
1305 mask & HCuPINT_SUSP ? " susp" : "",
1306 mask & HCuPINT_OPR ? " opr" : "",
1307 mask & HCuPINT_AIIEOT ? " eot" : "",
1308 mask & HCuPINT_ATL ? " atl" : "",
1309 mask & HCuPINT_SOF ? " sof" : "");
1312 static void dump_int(struct seq_file *s, char *label, u32 mask)
1314 seq_printf(s, "%s %08x%s%s%s%s%s%s%s\n", label, mask,
1315 mask & HCINT_MIE ? " MIE" : "",
1316 mask & HCINT_RHSC ? " rhsc" : "",
1317 mask & HCINT_FNO ? " fno" : "",
1318 mask & HCINT_UE ? " ue" : "",
1319 mask & HCINT_RD ? " rd" : "",
1320 mask & HCINT_SF ? " sof" : "", mask & HCINT_SO ? " so" : "");
1323 static int proc_isp116x_show(struct seq_file *s, void *unused)
1325 struct isp116x *isp116x = s->private;
1326 struct isp116x_ep *ep;
1331 seq_printf(s, "%s\n%s version %s\n",
1332 isp116x_to_hcd(isp116x)->product_desc, hcd_name,
1335 if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x)->state)) {
1336 seq_printf(s, "HCD is suspended\n");
1339 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x)->state)) {
1340 seq_printf(s, "HCD not running\n");
1344 spin_lock_irq(&isp116x->lock);
1346 dump_irq(s, "hc_irq_enable", isp116x_read_reg16(isp116x, HCuPINTENB));
1347 dump_irq(s, "hc_irq_status", isp116x_read_reg16(isp116x, HCuPINT));
1348 dump_int(s, "hc_int_enable", isp116x_read_reg32(isp116x, HCINTENB));
1349 dump_int(s, "hc_int_status", isp116x_read_reg32(isp116x, HCINTSTAT));
1351 list_for_each_entry(ep, &isp116x->async, schedule) {
1353 switch (ep->nextpid) {
1370 seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep,
1371 ep->epnum, str, ep->maxpacket);
1372 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
1373 seq_printf(s, " urb%p, %d/%d\n", urb,
1375 urb->transfer_buffer_length);
1378 if (!list_empty(&isp116x->async))
1379 seq_printf(s, "\n");
1381 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1383 for (i = 0; i < PERIODIC_SIZE; i++) {
1384 ep = isp116x->periodic[i];
1387 seq_printf(s, "%2d [%3d]:\n", i, isp116x->load[i]);
1389 /* DUMB: prints shared entries multiple times */
1391 seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
1394 USB_SPEED_FULL) ? "" : "ls ",
1395 ep->udev->devnum, ep->epnum,
1397 0) ? "" : ((ep->nextpid ==
1398 USB_PID_IN) ? "in" : "out"),
1403 spin_unlock_irq(&isp116x->lock);
1404 seq_printf(s, "\n");
1409 static int proc_isp116x_open(struct inode *inode, struct file *file)
1411 return single_open(file, proc_isp116x_show, PDE(inode)->data);
1414 static struct file_operations proc_ops = {
1415 .open = proc_isp116x_open,
1417 .llseek = seq_lseek,
1418 .release = single_release,
1421 /* expect just one isp116x per system */
1422 static const char proc_filename[] = "driver/isp116x";
1424 static void create_debug_file(struct isp116x *isp116x)
1426 struct proc_dir_entry *pde;
1428 pde = create_proc_entry(proc_filename, 0, NULL);
1432 pde->proc_fops = &proc_ops;
1433 pde->data = isp116x;
1437 static void remove_debug_file(struct isp116x *isp116x)
1440 remove_proc_entry(proc_filename, NULL);
1445 /*-----------------------------------------------------------------*/
1448 Software reset - can be called from any contect.
1450 static int isp116x_sw_reset(struct isp116x *isp116x)
1453 unsigned long flags;
1456 spin_lock_irqsave(&isp116x->lock, flags);
1457 isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC);
1458 isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR);
1460 /* It usually resets within 1 ms */
1462 if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR))
1466 ERR("Software reset timeout\n");
1469 spin_unlock_irqrestore(&isp116x->lock, flags);
1473 static int isp116x_reset(struct usb_hcd *hcd)
1475 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1478 int ret = 0, timeout = 15 /* ms */ ;
1480 ret = isp116x_sw_reset(isp116x);
1484 t = jiffies + msecs_to_jiffies(timeout);
1485 while (time_before_eq(jiffies, t)) {
1487 spin_lock_irq(&isp116x->lock);
1488 clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY;
1489 spin_unlock_irq(&isp116x->lock);
1494 ERR("Clock not ready after 20ms\n");
1495 /* After sw_reset the clock won't report to be ready, if
1496 H_WAKEUP pin is high. */
1497 ERR("Please make sure that the H_WAKEUP pin is pulled low!\n");
1503 static void isp116x_stop(struct usb_hcd *hcd)
1505 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1506 unsigned long flags;
1509 spin_lock_irqsave(&isp116x->lock, flags);
1510 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1512 /* Switch off ports' power, some devices don't come up
1513 after next 'insmod' without this */
1514 val = isp116x_read_reg32(isp116x, HCRHDESCA);
1515 val &= ~(RH_A_NPS | RH_A_PSM);
1516 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1517 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
1518 spin_unlock_irqrestore(&isp116x->lock, flags);
1520 isp116x_sw_reset(isp116x);
1524 Configure the chip. The chip must be successfully reset by now.
1526 static int isp116x_start(struct usb_hcd *hcd)
1528 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1529 struct isp116x_platform_data *board = isp116x->board;
1531 unsigned long flags;
1533 spin_lock_irqsave(&isp116x->lock, flags);
1535 /* clear interrupt status and disable all interrupt sources */
1536 isp116x_write_reg16(isp116x, HCuPINT, 0xff);
1537 isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1539 val = isp116x_read_reg16(isp116x, HCCHIPID);
1540 if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
1541 ERR("Invalid chip ID %04x\n", val);
1542 spin_unlock_irqrestore(&isp116x->lock, flags);
1546 /* To be removed in future */
1547 hcd->uses_new_polling = 1;
1549 isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
1550 isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
1553 val = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
1554 if (board->sel15Kres)
1555 val |= HCHWCFG_15KRSEL;
1556 /* Remote wakeup won't work without working clock */
1557 if (board->remote_wakeup_enable)
1558 val |= HCHWCFG_CLKNOTSTOP;
1559 if (board->oc_enable)
1560 val |= HCHWCFG_ANALOG_OC;
1561 if (board->int_act_high)
1562 val |= HCHWCFG_INT_POL;
1563 if (board->int_edge_triggered)
1564 val |= HCHWCFG_INT_TRIGGER;
1565 isp116x_write_reg16(isp116x, HCHWCFG, val);
1567 /* ----- Root hub conf */
1568 val = (25 << 24) & RH_A_POTPGT;
1569 /* AN10003_1.pdf recommends RH_A_NPS (no power switching) to
1570 be always set. Yet, instead, we request individual port
1573 /* Report overcurrent per port */
1575 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1576 isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
1579 isp116x_write_reg32(isp116x, HCRHDESCB, val);
1580 isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB);
1583 if (board->remote_wakeup_enable) {
1584 hcd->can_wakeup = 1;
1587 isp116x_write_reg32(isp116x, HCRHSTATUS, val);
1588 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
1590 isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf);
1592 hcd->state = HC_STATE_RUNNING;
1594 /* Set up interrupts */
1595 isp116x->intenb = HCINT_MIE | HCINT_RHSC | HCINT_UE;
1596 if (board->remote_wakeup_enable)
1597 isp116x->intenb |= HCINT_RD;
1598 isp116x->irqenb = HCuPINT_ATL | HCuPINT_OPR; /* | HCuPINT_SUSP; */
1599 isp116x_write_reg32(isp116x, HCINTENB, isp116x->intenb);
1600 isp116x_write_reg16(isp116x, HCuPINTENB, isp116x->irqenb);
1602 /* Go operational */
1603 val = HCCONTROL_USB_OPER;
1604 if (board->remote_wakeup_enable)
1605 val |= HCCONTROL_RWE;
1606 isp116x_write_reg32(isp116x, HCCONTROL, val);
1608 /* Disable ports to avoid race in device enumeration */
1609 isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS);
1610 isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS);
1612 isp116x_show_regs(isp116x);
1613 spin_unlock_irqrestore(&isp116x->lock, flags);
1617 /*-----------------------------------------------------------------*/
1619 static struct hc_driver isp116x_hc_driver = {
1620 .description = hcd_name,
1621 .product_desc = "ISP116x Host Controller",
1622 .hcd_priv_size = sizeof(struct isp116x),
1627 .reset = isp116x_reset,
1628 .start = isp116x_start,
1629 .stop = isp116x_stop,
1631 .urb_enqueue = isp116x_urb_enqueue,
1632 .urb_dequeue = isp116x_urb_dequeue,
1633 .endpoint_disable = isp116x_endpoint_disable,
1635 .get_frame_number = isp116x_get_frame,
1637 .hub_status_data = isp116x_hub_status_data,
1638 .hub_control = isp116x_hub_control,
1639 .hub_suspend = isp116x_hub_suspend,
1640 .hub_resume = isp116x_hub_resume,
1643 /*----------------------------------------------------------------*/
1645 static int __init_or_module isp116x_remove(struct device *dev)
1647 struct usb_hcd *hcd = dev_get_drvdata(dev);
1648 struct isp116x *isp116x;
1649 struct platform_device *pdev;
1650 struct resource *res;
1654 isp116x = hcd_to_isp116x(hcd);
1655 pdev = container_of(dev, struct platform_device, dev);
1656 remove_debug_file(isp116x);
1657 usb_remove_hcd(hcd);
1659 iounmap(isp116x->data_reg);
1660 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1661 release_mem_region(res->start, 2);
1662 iounmap(isp116x->addr_reg);
1663 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1664 release_mem_region(res->start, 2);
1670 #define resource_len(r) (((r)->end - (r)->start) + 1)
1672 static int __init isp116x_probe(struct device *dev)
1674 struct usb_hcd *hcd;
1675 struct isp116x *isp116x;
1676 struct platform_device *pdev;
1677 struct resource *addr, *data;
1678 void __iomem *addr_reg;
1679 void __iomem *data_reg;
1683 pdev = container_of(dev, struct platform_device, dev);
1684 if (pdev->num_resources < 3) {
1689 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1690 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1691 irq = platform_get_irq(pdev, 0);
1692 if (!addr || !data || irq < 0) {
1697 if (dev->dma_mask) {
1698 DBG("DMA not supported\n");
1703 if (!request_mem_region(addr->start, 2, hcd_name)) {
1707 addr_reg = ioremap(addr->start, resource_len(addr));
1708 if (addr_reg == NULL) {
1712 if (!request_mem_region(data->start, 2, hcd_name)) {
1716 data_reg = ioremap(data->start, resource_len(data));
1717 if (data_reg == NULL) {
1722 /* allocate and initialize hcd */
1723 hcd = usb_create_hcd(&isp116x_hc_driver, dev, dev->bus_id);
1728 /* this rsrc_start is bogus */
1729 hcd->rsrc_start = addr->start;
1730 isp116x = hcd_to_isp116x(hcd);
1731 isp116x->data_reg = data_reg;
1732 isp116x->addr_reg = addr_reg;
1733 spin_lock_init(&isp116x->lock);
1734 INIT_LIST_HEAD(&isp116x->async);
1735 INIT_WORK(&isp116x->rh_resume, isp116x_rh_resume, hcd);
1736 isp116x->board = dev->platform_data;
1738 if (!isp116x->board) {
1739 ERR("Platform data structure not initialized\n");
1743 if (isp116x_check_platform_delay(isp116x)) {
1744 ERR("USE_PLATFORM_DELAY defined, but delay function not "
1746 ERR("See comments in drivers/usb/host/isp116x-hcd.c\n");
1751 ret = usb_add_hcd(hcd, irq, SA_INTERRUPT);
1755 create_debug_file(isp116x);
1763 release_mem_region(data->start, 2);
1767 release_mem_region(addr->start, 2);
1769 ERR("init error, %d\n", ret);
1775 Suspend of platform device
1777 static int isp116x_suspend(struct device *dev, pm_message_t state, u32 phase)
1780 struct usb_hcd *hcd = dev_get_drvdata(dev);
1782 VDBG("%s: state %x, phase %x\n", __func__, state, phase);
1784 if (phase != SUSPEND_DISABLE && phase != SUSPEND_POWER_DOWN)
1787 ret = usb_suspend_device(hcd->self.root_hub, state);
1789 dev->power.power_state = state;
1790 INFO("%s suspended\n", hcd_name);
1792 ERR("%s suspend failed\n", hcd_name);
1798 Resume platform device
1800 static int isp116x_resume(struct device *dev, u32 phase)
1803 struct usb_hcd *hcd = dev_get_drvdata(dev);
1805 VDBG("%s: state %x, phase %x\n", __func__, dev->power.power_state,
1807 if (phase != RESUME_POWER_ON)
1810 ret = usb_resume_device(hcd->self.root_hub);
1812 dev->power.power_state = PMSG_ON;
1813 VDBG("%s resumed\n", (char *)hcd_name);
1820 #define isp116x_suspend NULL
1821 #define isp116x_resume NULL
1825 static struct device_driver isp116x_driver = {
1826 .name = (char *)hcd_name,
1827 .bus = &platform_bus_type,
1828 .probe = isp116x_probe,
1829 .remove = isp116x_remove,
1830 .suspend = isp116x_suspend,
1831 .resume = isp116x_resume,
1834 /*-----------------------------------------------------------------*/
1836 static int __init isp116x_init(void)
1841 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1842 return driver_register(&isp116x_driver);
1845 module_init(isp116x_init);
1847 static void __exit isp116x_cleanup(void)
1849 driver_unregister(&isp116x_driver);
1852 module_exit(isp116x_cleanup);