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
;
232 u16 toggle
, dir
, len
;
234 for (ep
= isp116x
->atl_active
; ep
; ep
= ep
->active
) {
235 BUG_ON(list_empty(&ep
->hep
->urb_list
));
236 urb
= container_of(ep
->hep
->urb_list
.next
,
237 struct urb
, urb_list
);
240 spin_lock(&urb
->lock
);
241 ep
->data
= (unsigned char *)urb
->transfer_buffer
242 + urb
->actual_length
;
244 switch (ep
->nextpid
) {
246 toggle
= usb_gettoggle(urb
->dev
, ep
->epnum
, 0);
250 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
;
269 ERR("%s %d: ep->nextpid %d\n", __func__
, __LINE__
,
274 ptd
->count
= PTD_CC_MSK
| PTD_ACTIVE_MSK
| PTD_TOGGLE(toggle
);
275 ptd
->mps
= PTD_MPS(ep
->maxpacket
)
276 | PTD_SPD(urb
->dev
->speed
== USB_SPEED_LOW
)
278 ptd
->len
= PTD_LEN(len
) | PTD_DIR(dir
);
279 ptd
->faddr
= PTD_FA(usb_pipedevice(urb
->pipe
));
280 spin_unlock(&urb
->lock
);
282 ptd
->mps
|= PTD_LAST_MSK
;
283 isp116x
->atl_last_dir
= dir
;
285 isp116x
->atl_bufshrt
= sizeof(struct ptd
) + isp116x
->atl_buflen
;
286 isp116x
->atl_buflen
= isp116x
->atl_bufshrt
+ ALIGN(len
, 4);
291 Analyze transfer results, handle partial transfers and errors
293 static void postproc_atl_queue(struct isp116x
*isp116x
)
295 struct isp116x_ep
*ep
;
297 struct usb_device
*udev
;
302 for (ep
= isp116x
->atl_active
; ep
; ep
= ep
->active
) {
303 BUG_ON(list_empty(&ep
->hep
->urb_list
));
305 container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
308 cc
= PTD_GET_CC(ptd
);
310 spin_lock(&urb
->lock
);
313 /* Data underrun is special. For allowed underrun
314 we clear the error and continue as normal. For
315 forbidden underrun we finish the DATA stage
316 immediately while for control transfer,
317 we do a STATUS stage. */
318 if (cc
== TD_DATAUNDERRUN
) {
319 if (!(urb
->transfer_flags
& URB_SHORT_NOT_OK
)) {
320 DBG("Allowed data underrun\n");
325 if (usb_pipecontrol(urb
->pipe
))
326 ep
->nextpid
= USB_PID_ACK
;
328 usb_settoggle(udev
, ep
->epnum
,
331 PTD_GET_TOGGLE(ptd
) ^ 1);
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
) {
636 isp116x_read_reg32(isp116x
, HCRHSTATUS
);
638 isp116x_read_reg32(isp116x
, HCRHPORT1
);
640 isp116x_read_reg32(isp116x
, HCRHPORT2
);
642 if (intstat
& HCINT_RD
) {
643 DBG("---- remote wakeup\n");
644 schedule_work(&isp116x
->rh_resume
);
647 irqstat
&= ~HCuPINT_OPR
;
651 if (irqstat
& (HCuPINT_ATL
| HCuPINT_SOF
)) {
652 start_atl_transfers(isp116x
);
655 isp116x_write_reg16(isp116x
, HCuPINTENB
, isp116x
->irqenb
);
656 spin_unlock(&isp116x
->lock
);
660 /*-----------------------------------------------------------------*/
662 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
663 * this driver doesn't promise that much since it's got to handle an
664 * IRQ per packet; irq handling latencies also use up that time.
668 #define MAX_PERIODIC_LOAD 600
669 static int balance(struct isp116x
*isp116x
, u16 period
, u16 load
)
671 int i
, branch
= -ENOSPC
;
673 /* search for the least loaded schedule branch of that period
674 which has enough bandwidth left unreserved. */
675 for (i
= 0; i
< period
; i
++) {
676 if (branch
< 0 || isp116x
->load
[branch
] > isp116x
->load
[i
]) {
679 for (j
= i
; j
< PERIODIC_SIZE
; j
+= period
) {
680 if ((isp116x
->load
[j
] + load
)
684 if (j
< PERIODIC_SIZE
)
692 /* NB! ALL the code above this point runs with isp116x->lock
696 /*-----------------------------------------------------------------*/
698 static int isp116x_urb_enqueue(struct usb_hcd
*hcd
,
699 struct usb_host_endpoint
*hep
, struct urb
*urb
,
702 struct isp116x
*isp116x
= hcd_to_isp116x(hcd
);
703 struct usb_device
*udev
= urb
->dev
;
704 unsigned int pipe
= urb
->pipe
;
705 int is_out
= !usb_pipein(pipe
);
706 int type
= usb_pipetype(pipe
);
707 int epnum
= usb_pipeendpoint(pipe
);
708 struct isp116x_ep
*ep
= NULL
;
713 urb_dbg(urb
, "Enqueue");
715 if (type
== PIPE_ISOCHRONOUS
) {
716 ERR("Isochronous transfers not supported\n");
717 urb_dbg(urb
, "Refused to enqueue");
720 /* avoid all allocations within spinlocks: request or endpoint */
722 ep
= kcalloc(1, sizeof *ep
, (__force
unsigned)mem_flags
);
727 spin_lock_irqsave(&isp116x
->lock
, flags
);
728 if (!HC_IS_RUNNING(hcd
->state
)) {
736 INIT_LIST_HEAD(&ep
->schedule
);
737 ep
->udev
= usb_get_dev(udev
);
739 ep
->maxpacket
= usb_maxpacket(udev
, urb
->pipe
, is_out
);
740 usb_settoggle(udev
, epnum
, is_out
, 0);
742 if (type
== PIPE_CONTROL
) {
743 ep
->nextpid
= USB_PID_SETUP
;
745 ep
->nextpid
= USB_PID_OUT
;
747 ep
->nextpid
= USB_PID_IN
;
752 With INT URBs submitted, the driver works with SOF
753 interrupt enabled and ATL interrupt disabled. After
754 the PTDs are written to fifo ram, the chip starts
755 fifo processing and usb transfers after the next
756 SOF and continues until the transfers are finished
757 (succeeded or failed) or the frame ends. Therefore,
758 the transfers occur only in every second frame,
759 while fifo reading/writing and data processing
760 occur in every other second frame. */
761 if (urb
->interval
< 2)
763 if (urb
->interval
> 2 * PERIODIC_SIZE
)
764 urb
->interval
= 2 * PERIODIC_SIZE
;
765 ep
->period
= urb
->interval
>> 1;
766 ep
->branch
= PERIODIC_SIZE
;
767 ep
->load
= usb_calc_bus_time(udev
->speed
,
769 (type
== PIPE_ISOCHRONOUS
),
770 usb_maxpacket(udev
, pipe
,
778 /* maybe put endpoint into schedule */
782 if (list_empty(&ep
->schedule
))
783 list_add_tail(&ep
->schedule
, &isp116x
->async
);
786 urb
->interval
= ep
->period
;
787 ep
->length
= min((int)ep
->maxpacket
,
788 urb
->transfer_buffer_length
);
790 /* urb submitted for already existing endpoint */
791 if (ep
->branch
< PERIODIC_SIZE
)
794 ret
= ep
->branch
= balance(isp116x
, ep
->period
, ep
->load
);
799 urb
->start_frame
= (isp116x
->fmindex
& (PERIODIC_SIZE
- 1))
802 /* sort each schedule branch by period (slow before fast)
803 to share the faster parts of the tree without needing
804 dummy/placeholder nodes */
805 DBG("schedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
806 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
807 struct isp116x_ep
**prev
= &isp116x
->periodic
[i
];
808 struct isp116x_ep
*here
= *prev
;
810 while (here
&& ep
!= here
) {
811 if (ep
->period
> here
->period
)
820 isp116x
->load
[i
] += ep
->load
;
822 hcd
->self
.bandwidth_allocated
+= ep
->load
/ ep
->period
;
824 /* switch over to SOFint */
825 if (!isp116x
->periodic_count
++) {
826 isp116x
->irqenb
&= ~HCuPINT_ATL
;
827 isp116x
->irqenb
|= HCuPINT_SOF
;
828 isp116x_write_reg16(isp116x
, HCuPINTENB
,
833 /* in case of unlink-during-submit */
834 spin_lock(&urb
->lock
);
835 if (urb
->status
!= -EINPROGRESS
) {
836 spin_unlock(&urb
->lock
);
837 finish_request(isp116x
, ep
, urb
, NULL
);
842 spin_unlock(&urb
->lock
);
843 start_atl_transfers(isp116x
);
846 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
853 static int isp116x_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
)
855 struct isp116x
*isp116x
= hcd_to_isp116x(hcd
);
856 struct usb_host_endpoint
*hep
;
857 struct isp116x_ep
*ep
, *ep_act
;
860 spin_lock_irqsave(&isp116x
->lock
, flags
);
862 /* URB already unlinked (or never linked)? */
864 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
868 WARN_ON(hep
!= ep
->hep
);
870 /* In front of queue? */
871 if (ep
->hep
->urb_list
.next
== &urb
->urb_list
)
873 for (ep_act
= isp116x
->atl_active
; ep_act
;
874 ep_act
= ep_act
->active
)
876 VDBG("dequeue, urb %p active; wait for irq\n",
883 finish_request(isp116x
, ep
, urb
, NULL
);
885 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
889 static void isp116x_endpoint_disable(struct usb_hcd
*hcd
,
890 struct usb_host_endpoint
*hep
)
893 struct isp116x_ep
*ep
= hep
->hcpriv
;;
898 /* assume we'd just wait for the irq */
899 for (i
= 0; i
< 100 && !list_empty(&hep
->urb_list
); i
++)
901 if (!list_empty(&hep
->urb_list
))
902 WARN("ep %p not empty?\n", ep
);
904 usb_put_dev(ep
->udev
);
909 static int isp116x_get_frame(struct usb_hcd
*hcd
)
911 struct isp116x
*isp116x
= hcd_to_isp116x(hcd
);
915 spin_lock_irqsave(&isp116x
->lock
, flags
);
916 fmnum
= isp116x_read_reg32(isp116x
, HCFMNUM
);
917 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
921 /*----------------------------------------------------------------*/
924 Adapted from ohci-hub.c. Currently we don't support autosuspend.
926 static int isp116x_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
928 struct isp116x
*isp116x
= hcd_to_isp116x(hcd
);
929 int ports
, i
, changed
= 0;
931 if (!HC_IS_RUNNING(hcd
->state
))
934 ports
= isp116x
->rhdesca
& RH_A_NDP
;
937 if (isp116x
->rhstatus
& (RH_HS_LPSC
| RH_HS_OCIC
))
938 buf
[0] = changed
= 1;
942 for (i
= 0; i
< ports
; i
++) {
943 u32 status
= isp116x
->rhport
[i
];
945 if (status
& (RH_PS_CSC
| RH_PS_PESC
| RH_PS_PSSC
946 | RH_PS_OCIC
| RH_PS_PRSC
)) {
948 buf
[0] |= 1 << (i
+ 1);
955 static void isp116x_hub_descriptor(struct isp116x
*isp116x
,
956 struct usb_hub_descriptor
*desc
)
958 u32 reg
= isp116x
->rhdesca
;
960 desc
->bDescriptorType
= 0x29;
961 desc
->bDescLength
= 9;
962 desc
->bHubContrCurrent
= 0;
963 desc
->bNbrPorts
= (u8
) (reg
& 0x3);
964 /* Power switching, device type, overcurrent. */
965 desc
->wHubCharacteristics
=
966 (__force __u16
) cpu_to_le16((u16
) ((reg
>> 8) & 0x1f));
967 desc
->bPwrOn2PwrGood
= (u8
) ((reg
>> 24) & 0xff);
968 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
969 desc
->bitmap
[0] = desc
->bNbrPorts
== 1 ? 1 << 1 : 3 << 1;
970 desc
->bitmap
[1] = ~0;
973 /* Perform reset of a given port.
974 It would be great to just start the reset and let the
975 USB core to clear the reset in due time. However,
976 root hub ports should be reset for at least 50 ms, while
977 our chip stays in reset for about 10 ms. I.e., we must
978 repeatedly reset it ourself here.
980 static inline void root_port_reset(struct isp116x
*isp116x
, unsigned port
)
983 unsigned long flags
, t
;
985 /* Root hub reset should be 50 ms, but some devices
986 want it even longer. */
987 t
= jiffies
+ msecs_to_jiffies(100);
989 while (time_before(jiffies
, t
)) {
990 spin_lock_irqsave(&isp116x
->lock
, flags
);
991 /* spin until any current reset finishes */
993 tmp
= isp116x_read_reg32(isp116x
, port
?
994 HCRHPORT2
: HCRHPORT1
);
995 if (!(tmp
& RH_PS_PRS
))
999 /* Don't reset a disconnected port */
1000 if (!(tmp
& RH_PS_CCS
)) {
1001 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
1004 /* Reset lasts 10ms (claims datasheet) */
1005 isp116x_write_reg32(isp116x
, port
? HCRHPORT2
:
1006 HCRHPORT1
, (RH_PS_PRS
));
1007 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
1012 /* Adapted from ohci-hub.c */
1013 static int isp116x_hub_control(struct usb_hcd
*hcd
,
1015 u16 wValue
, u16 wIndex
, char *buf
, u16 wLength
)
1017 struct isp116x
*isp116x
= hcd_to_isp116x(hcd
);
1019 unsigned long flags
;
1020 int ports
= isp116x
->rhdesca
& RH_A_NDP
;
1024 case ClearHubFeature
:
1025 DBG("ClearHubFeature: ");
1027 case C_HUB_OVER_CURRENT
:
1028 DBG("C_HUB_OVER_CURRENT\n");
1029 spin_lock_irqsave(&isp116x
->lock
, flags
);
1030 isp116x_write_reg32(isp116x
, HCRHSTATUS
, RH_HS_OCIC
);
1031 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
1032 case C_HUB_LOCAL_POWER
:
1033 DBG("C_HUB_LOCAL_POWER\n");
1040 DBG("SetHubFeature: ");
1042 case C_HUB_OVER_CURRENT
:
1043 case C_HUB_LOCAL_POWER
:
1044 DBG("C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1050 case GetHubDescriptor
:
1051 DBG("GetHubDescriptor\n");
1052 isp116x_hub_descriptor(isp116x
,
1053 (struct usb_hub_descriptor
*)buf
);
1056 DBG("GetHubStatus\n");
1057 *(__le32
*) buf
= cpu_to_le32(0);
1060 DBG("GetPortStatus\n");
1061 if (!wIndex
|| wIndex
> ports
)
1063 tmp
= isp116x
->rhport
[--wIndex
];
1064 *(__le32
*) buf
= cpu_to_le32(tmp
);
1065 DBG("GetPortStatus: port[%d] %08x\n", wIndex
+ 1, tmp
);
1067 case ClearPortFeature
:
1068 DBG("ClearPortFeature: ");
1069 if (!wIndex
|| wIndex
> ports
)
1074 case USB_PORT_FEAT_ENABLE
:
1075 DBG("USB_PORT_FEAT_ENABLE\n");
1078 case USB_PORT_FEAT_C_ENABLE
:
1079 DBG("USB_PORT_FEAT_C_ENABLE\n");
1082 case USB_PORT_FEAT_SUSPEND
:
1083 DBG("USB_PORT_FEAT_SUSPEND\n");
1086 case USB_PORT_FEAT_C_SUSPEND
:
1087 DBG("USB_PORT_FEAT_C_SUSPEND\n");
1090 case USB_PORT_FEAT_POWER
:
1091 DBG("USB_PORT_FEAT_POWER\n");
1094 case USB_PORT_FEAT_C_CONNECTION
:
1095 DBG("USB_PORT_FEAT_C_CONNECTION\n");
1098 case USB_PORT_FEAT_C_OVER_CURRENT
:
1099 DBG("USB_PORT_FEAT_C_OVER_CURRENT\n");
1102 case USB_PORT_FEAT_C_RESET
:
1103 DBG("USB_PORT_FEAT_C_RESET\n");
1109 spin_lock_irqsave(&isp116x
->lock
, flags
);
1110 isp116x_write_reg32(isp116x
, wIndex
1111 ? HCRHPORT2
: HCRHPORT1
, tmp
);
1112 isp116x
->rhport
[wIndex
] =
1113 isp116x_read_reg32(isp116x
, wIndex
? HCRHPORT2
: HCRHPORT1
);
1114 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
1116 case SetPortFeature
:
1117 DBG("SetPortFeature: ");
1118 if (!wIndex
|| wIndex
> ports
)
1122 case USB_PORT_FEAT_SUSPEND
:
1123 DBG("USB_PORT_FEAT_SUSPEND\n");
1124 spin_lock_irqsave(&isp116x
->lock
, flags
);
1125 isp116x_write_reg32(isp116x
, wIndex
1126 ? HCRHPORT2
: HCRHPORT1
, RH_PS_PSS
);
1128 case USB_PORT_FEAT_POWER
:
1129 DBG("USB_PORT_FEAT_POWER\n");
1130 spin_lock_irqsave(&isp116x
->lock
, flags
);
1131 isp116x_write_reg32(isp116x
, wIndex
1132 ? HCRHPORT2
: HCRHPORT1
, RH_PS_PPS
);
1134 case USB_PORT_FEAT_RESET
:
1135 DBG("USB_PORT_FEAT_RESET\n");
1136 root_port_reset(isp116x
, wIndex
);
1137 spin_lock_irqsave(&isp116x
->lock
, flags
);
1142 isp116x
->rhport
[wIndex
] =
1143 isp116x_read_reg32(isp116x
, wIndex
? HCRHPORT2
: HCRHPORT1
);
1144 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
1149 /* "protocol stall" on error */
1150 DBG("PROTOCOL STALL\n");
1158 static int isp116x_hub_suspend(struct usb_hcd
*hcd
)
1160 struct isp116x
*isp116x
= hcd_to_isp116x(hcd
);
1161 unsigned long flags
;
1165 spin_lock_irqsave(&isp116x
->lock
, flags
);
1167 val
= isp116x_read_reg32(isp116x
, HCCONTROL
);
1168 switch (val
& HCCONTROL_HCFS
) {
1169 case HCCONTROL_USB_OPER
:
1170 hcd
->state
= HC_STATE_QUIESCING
;
1171 val
&= (~HCCONTROL_HCFS
& ~HCCONTROL_RWE
);
1172 val
|= HCCONTROL_USB_SUSPEND
;
1173 if (hcd
->remote_wakeup
)
1174 val
|= HCCONTROL_RWE
;
1175 /* Wait for usb transfers to finish */
1177 isp116x_write_reg32(isp116x
, HCCONTROL
, val
);
1178 hcd
->state
= HC_STATE_SUSPENDED
;
1179 /* Wait for devices to suspend */
1181 case HCCONTROL_USB_SUSPEND
:
1183 case HCCONTROL_USB_RESUME
:
1184 isp116x_write_reg32(isp116x
, HCCONTROL
,
1185 (val
& ~HCCONTROL_HCFS
) |
1186 HCCONTROL_USB_RESET
);
1187 case HCCONTROL_USB_RESET
:
1194 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
1198 static int isp116x_hub_resume(struct usb_hcd
*hcd
)
1200 struct isp116x
*isp116x
= hcd_to_isp116x(hcd
);
1202 int ret
= -EINPROGRESS
;
1205 spin_lock_irq(&isp116x
->lock
);
1207 val
= isp116x_read_reg32(isp116x
, HCCONTROL
);
1208 switch (val
& HCCONTROL_HCFS
) {
1209 case HCCONTROL_USB_SUSPEND
:
1210 val
&= ~HCCONTROL_HCFS
;
1211 val
|= HCCONTROL_USB_RESUME
;
1212 isp116x_write_reg32(isp116x
, HCCONTROL
, val
);
1213 case HCCONTROL_USB_RESUME
:
1215 case HCCONTROL_USB_OPER
:
1216 /* Without setting power_state here the
1217 SUSPENDED state won't be removed from
1218 sysfs/usbN/power.state as a response to remote
1219 wakeup. Maybe in the future. */
1220 hcd
->self
.root_hub
->dev
.power
.power_state
= PMSG_ON
;
1227 if (ret
!= -EINPROGRESS
) {
1228 spin_unlock_irq(&isp116x
->lock
);
1232 val
= isp116x
->rhdesca
& RH_A_NDP
;
1235 isp116x_read_reg32(isp116x
, val
? HCRHPORT2
: HCRHPORT1
);
1236 /* force global, not selective, resume */
1237 if (!(stat
& RH_PS_PSS
))
1239 DBG("%s: Resuming port %d\n", __func__
, val
);
1240 isp116x_write_reg32(isp116x
, RH_PS_POCI
, val
1241 ? HCRHPORT2
: HCRHPORT1
);
1243 spin_unlock_irq(&isp116x
->lock
);
1245 hcd
->state
= HC_STATE_RESUMING
;
1248 /* Go operational */
1249 spin_lock_irq(&isp116x
->lock
);
1250 val
= isp116x_read_reg32(isp116x
, HCCONTROL
);
1251 isp116x_write_reg32(isp116x
, HCCONTROL
,
1252 (val
& ~HCCONTROL_HCFS
) | HCCONTROL_USB_OPER
);
1253 spin_unlock_irq(&isp116x
->lock
);
1254 /* see analogous comment above */
1255 hcd
->self
.root_hub
->dev
.power
.power_state
= PMSG_ON
;
1256 hcd
->state
= HC_STATE_RUNNING
;
1261 static void isp116x_rh_resume(void *_hcd
)
1263 struct usb_hcd
*hcd
= _hcd
;
1265 usb_resume_device(hcd
->self
.root_hub
);
1270 #define isp116x_hub_suspend NULL
1271 #define isp116x_hub_resume NULL
1273 static void isp116x_rh_resume(void *_hcd
)
1279 /*-----------------------------------------------------------------*/
1281 #ifdef STUB_DEBUG_FILE
1283 static inline void create_debug_file(struct isp116x
*isp116x
)
1287 static inline void remove_debug_file(struct isp116x
*isp116x
)
1293 #include <linux/proc_fs.h>
1294 #include <linux/seq_file.h>
1296 static void dump_irq(struct seq_file
*s
, char *label
, u16 mask
)
1298 seq_printf(s
, "%s %04x%s%s%s%s%s%s\n", label
, mask
,
1299 mask
& HCuPINT_CLKRDY
? " clkrdy" : "",
1300 mask
& HCuPINT_SUSP
? " susp" : "",
1301 mask
& HCuPINT_OPR
? " opr" : "",
1302 mask
& HCuPINT_AIIEOT
? " eot" : "",
1303 mask
& HCuPINT_ATL
? " atl" : "",
1304 mask
& HCuPINT_SOF
? " sof" : "");
1307 static void dump_int(struct seq_file
*s
, char *label
, u32 mask
)
1309 seq_printf(s
, "%s %08x%s%s%s%s%s%s%s\n", label
, mask
,
1310 mask
& HCINT_MIE
? " MIE" : "",
1311 mask
& HCINT_RHSC
? " rhsc" : "",
1312 mask
& HCINT_FNO
? " fno" : "",
1313 mask
& HCINT_UE
? " ue" : "",
1314 mask
& HCINT_RD
? " rd" : "",
1315 mask
& HCINT_SF
? " sof" : "", mask
& HCINT_SO
? " so" : "");
1318 static int proc_isp116x_show(struct seq_file
*s
, void *unused
)
1320 struct isp116x
*isp116x
= s
->private;
1321 struct isp116x_ep
*ep
;
1326 seq_printf(s
, "%s\n%s version %s\n",
1327 isp116x_to_hcd(isp116x
)->product_desc
, hcd_name
,
1330 if (HC_IS_SUSPENDED(isp116x_to_hcd(isp116x
)->state
)) {
1331 seq_printf(s
, "HCD is suspended\n");
1334 if (!HC_IS_RUNNING(isp116x_to_hcd(isp116x
)->state
)) {
1335 seq_printf(s
, "HCD not running\n");
1339 spin_lock_irq(&isp116x
->lock
);
1341 dump_irq(s
, "hc_irq_enable", isp116x_read_reg16(isp116x
, HCuPINTENB
));
1342 dump_irq(s
, "hc_irq_status", isp116x_read_reg16(isp116x
, HCuPINT
));
1343 dump_int(s
, "hc_int_enable", isp116x_read_reg32(isp116x
, HCINTENB
));
1344 dump_int(s
, "hc_int_status", isp116x_read_reg32(isp116x
, HCINTSTAT
));
1346 list_for_each_entry(ep
, &isp116x
->async
, schedule
) {
1348 switch (ep
->nextpid
) {
1365 seq_printf(s
, "%p, ep%d%s, maxpacket %d:\n", ep
,
1366 ep
->epnum
, str
, ep
->maxpacket
);
1367 list_for_each_entry(urb
, &ep
->hep
->urb_list
, urb_list
) {
1368 seq_printf(s
, " urb%p, %d/%d\n", urb
,
1370 urb
->transfer_buffer_length
);
1373 if (!list_empty(&isp116x
->async
))
1374 seq_printf(s
, "\n");
1376 seq_printf(s
, "periodic size= %d\n", PERIODIC_SIZE
);
1378 for (i
= 0; i
< PERIODIC_SIZE
; i
++) {
1379 ep
= isp116x
->periodic
[i
];
1382 seq_printf(s
, "%2d [%3d]:\n", i
, isp116x
->load
[i
]);
1384 /* DUMB: prints shared entries multiple times */
1386 seq_printf(s
, " %d/%p (%sdev%d ep%d%s max %d)\n",
1389 USB_SPEED_FULL
) ? "" : "ls ",
1390 ep
->udev
->devnum
, ep
->epnum
,
1392 0) ? "" : ((ep
->nextpid
==
1393 USB_PID_IN
) ? "in" : "out"),
1398 spin_unlock_irq(&isp116x
->lock
);
1399 seq_printf(s
, "\n");
1404 static int proc_isp116x_open(struct inode
*inode
, struct file
*file
)
1406 return single_open(file
, proc_isp116x_show
, PDE(inode
)->data
);
1409 static struct file_operations proc_ops
= {
1410 .open
= proc_isp116x_open
,
1412 .llseek
= seq_lseek
,
1413 .release
= single_release
,
1416 /* expect just one isp116x per system */
1417 static const char proc_filename
[] = "driver/isp116x";
1419 static void create_debug_file(struct isp116x
*isp116x
)
1421 struct proc_dir_entry
*pde
;
1423 pde
= create_proc_entry(proc_filename
, 0, NULL
);
1427 pde
->proc_fops
= &proc_ops
;
1428 pde
->data
= isp116x
;
1432 static void remove_debug_file(struct isp116x
*isp116x
)
1435 remove_proc_entry(proc_filename
, NULL
);
1440 /*-----------------------------------------------------------------*/
1443 Software reset - can be called from any contect.
1445 static int isp116x_sw_reset(struct isp116x
*isp116x
)
1448 unsigned long flags
;
1451 spin_lock_irqsave(&isp116x
->lock
, flags
);
1452 isp116x_write_reg16(isp116x
, HCSWRES
, HCSWRES_MAGIC
);
1453 isp116x_write_reg32(isp116x
, HCCMDSTAT
, HCCMDSTAT_HCR
);
1455 /* It usually resets within 1 ms */
1457 if (!(isp116x_read_reg32(isp116x
, HCCMDSTAT
) & HCCMDSTAT_HCR
))
1461 ERR("Software reset timeout\n");
1464 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
1469 Reset. Tries to perform platform-specific hardware
1470 reset first; falls back to software reset.
1472 static int isp116x_reset(struct usb_hcd
*hcd
)
1474 struct isp116x
*isp116x
= hcd_to_isp116x(hcd
);
1477 int ret
= 0, timeout
= 15 /* ms */ ;
1479 if (isp116x
->board
&& isp116x
->board
->reset
) {
1480 /* Hardware reset */
1481 isp116x
->board
->reset(hcd
->self
.controller
, 1);
1483 if (isp116x
->board
->clock
)
1484 isp116x
->board
->clock(hcd
->self
.controller
, 1);
1486 isp116x
->board
->reset(hcd
->self
.controller
, 0);
1488 ret
= isp116x_sw_reset(isp116x
);
1493 t
= jiffies
+ msecs_to_jiffies(timeout
);
1494 while (time_before_eq(jiffies
, t
)) {
1496 spin_lock_irq(&isp116x
->lock
);
1497 clkrdy
= isp116x_read_reg16(isp116x
, HCuPINT
) & HCuPINT_CLKRDY
;
1498 spin_unlock_irq(&isp116x
->lock
);
1503 ERR("Clock not ready after 20ms\n");
1504 /* After sw_reset the clock won't report to be ready, if
1505 H_WAKEUP pin is high. */
1506 if (!isp116x
->board
|| !isp116x
->board
->reset
)
1507 ERR("The driver does not support hardware wakeup.\n");
1508 ERR("Please make sure that the H_WAKEUP pin "
1509 "is pulled low!\n");
1515 static void isp116x_stop(struct usb_hcd
*hcd
)
1517 struct isp116x
*isp116x
= hcd_to_isp116x(hcd
);
1518 unsigned long flags
;
1521 spin_lock_irqsave(&isp116x
->lock
, flags
);
1522 isp116x_write_reg16(isp116x
, HCuPINTENB
, 0);
1524 /* Switch off ports' power, some devices don't come up
1525 after next 'insmod' without this */
1526 val
= isp116x_read_reg32(isp116x
, HCRHDESCA
);
1527 val
&= ~(RH_A_NPS
| RH_A_PSM
);
1528 isp116x_write_reg32(isp116x
, HCRHDESCA
, val
);
1529 isp116x_write_reg32(isp116x
, HCRHSTATUS
, RH_HS_LPS
);
1530 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
1532 /* Put the chip into reset state */
1533 if (isp116x
->board
&& isp116x
->board
->reset
)
1534 isp116x
->board
->reset(hcd
->self
.controller
, 0);
1536 isp116x_sw_reset(isp116x
);
1538 /* Stop the clock */
1539 if (isp116x
->board
&& isp116x
->board
->clock
)
1540 isp116x
->board
->clock(hcd
->self
.controller
, 0);
1544 Configure the chip. The chip must be successfully reset by now.
1546 static int isp116x_start(struct usb_hcd
*hcd
)
1548 struct isp116x
*isp116x
= hcd_to_isp116x(hcd
);
1549 struct isp116x_platform_data
*board
= isp116x
->board
;
1551 unsigned long flags
;
1553 spin_lock_irqsave(&isp116x
->lock
, flags
);
1555 /* clear interrupt status and disable all interrupt sources */
1556 isp116x_write_reg16(isp116x
, HCuPINT
, 0xff);
1557 isp116x_write_reg16(isp116x
, HCuPINTENB
, 0);
1559 val
= isp116x_read_reg16(isp116x
, HCCHIPID
);
1560 if ((val
& HCCHIPID_MASK
) != HCCHIPID_MAGIC
) {
1561 ERR("Invalid chip ID %04x\n", val
);
1562 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
1566 isp116x_write_reg16(isp116x
, HCITLBUFLEN
, ISP116x_ITL_BUFSIZE
);
1567 isp116x_write_reg16(isp116x
, HCATLBUFLEN
, ISP116x_ATL_BUFSIZE
);
1570 val
= HCHWCFG_INT_ENABLE
| HCHWCFG_DBWIDTH(1);
1571 if (board
->sel15Kres
)
1572 val
|= HCHWCFG_15KRSEL
;
1573 /* Remote wakeup won't work without working clock */
1574 if (board
->clknotstop
|| board
->remote_wakeup_enable
)
1575 val
|= HCHWCFG_CLKNOTSTOP
;
1576 if (board
->oc_enable
)
1577 val
|= HCHWCFG_ANALOG_OC
;
1578 if (board
->int_act_high
)
1579 val
|= HCHWCFG_INT_POL
;
1580 if (board
->int_edge_triggered
)
1581 val
|= HCHWCFG_INT_TRIGGER
;
1582 isp116x_write_reg16(isp116x
, HCHWCFG
, val
);
1584 /* ----- Root hub conf */
1586 /* AN10003_1.pdf recommends NPS to be always 1 */
1587 if (board
->no_power_switching
)
1589 if (board
->power_switching_mode
)
1592 val
|= (board
->potpg
<< 24) & RH_A_POTPGT
;
1594 val
|= (25 << 24) & RH_A_POTPGT
;
1595 isp116x_write_reg32(isp116x
, HCRHDESCA
, val
);
1596 isp116x
->rhdesca
= isp116x_read_reg32(isp116x
, HCRHDESCA
);
1599 isp116x_write_reg32(isp116x
, HCRHDESCB
, val
);
1600 isp116x
->rhdescb
= isp116x_read_reg32(isp116x
, HCRHDESCB
);
1603 if (board
->remote_wakeup_enable
) {
1604 hcd
->can_wakeup
= 1;
1607 isp116x_write_reg32(isp116x
, HCRHSTATUS
, val
);
1608 isp116x
->rhstatus
= isp116x_read_reg32(isp116x
, HCRHSTATUS
);
1610 isp116x_write_reg32(isp116x
, HCFMINTVL
, 0x27782edf);
1612 hcd
->state
= HC_STATE_RUNNING
;
1614 /* Set up interrupts */
1615 isp116x
->intenb
= HCINT_MIE
| HCINT_RHSC
| HCINT_UE
;
1616 if (board
->remote_wakeup_enable
)
1617 isp116x
->intenb
|= HCINT_RD
;
1618 isp116x
->irqenb
= HCuPINT_ATL
| HCuPINT_OPR
; /* | HCuPINT_SUSP; */
1619 isp116x_write_reg32(isp116x
, HCINTENB
, isp116x
->intenb
);
1620 isp116x_write_reg16(isp116x
, HCuPINTENB
, isp116x
->irqenb
);
1622 /* Go operational */
1623 val
= HCCONTROL_USB_OPER
;
1624 /* Remote wakeup connected - NOT SUPPORTED */
1625 /* if (board->remote_wakeup_connected)
1626 val |= HCCONTROL_RWC; */
1627 if (board
->remote_wakeup_enable
)
1628 val
|= HCCONTROL_RWE
;
1629 isp116x_write_reg32(isp116x
, HCCONTROL
, val
);
1631 /* Disable ports to avoid race in device enumeration */
1632 isp116x_write_reg32(isp116x
, HCRHPORT1
, RH_PS_CCS
);
1633 isp116x_write_reg32(isp116x
, HCRHPORT2
, RH_PS_CCS
);
1635 isp116x_show_regs(isp116x
);
1636 spin_unlock_irqrestore(&isp116x
->lock
, flags
);
1640 /*-----------------------------------------------------------------*/
1642 static struct hc_driver isp116x_hc_driver
= {
1643 .description
= hcd_name
,
1644 .product_desc
= "ISP116x Host Controller",
1645 .hcd_priv_size
= sizeof(struct isp116x
),
1650 .reset
= isp116x_reset
,
1651 .start
= isp116x_start
,
1652 .stop
= isp116x_stop
,
1654 .urb_enqueue
= isp116x_urb_enqueue
,
1655 .urb_dequeue
= isp116x_urb_dequeue
,
1656 .endpoint_disable
= isp116x_endpoint_disable
,
1658 .get_frame_number
= isp116x_get_frame
,
1660 .hub_status_data
= isp116x_hub_status_data
,
1661 .hub_control
= isp116x_hub_control
,
1662 .hub_suspend
= isp116x_hub_suspend
,
1663 .hub_resume
= isp116x_hub_resume
,
1666 /*----------------------------------------------------------------*/
1668 static int __init_or_module
isp116x_remove(struct device
*dev
)
1670 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
1671 struct isp116x
*isp116x
;
1672 struct platform_device
*pdev
;
1673 struct resource
*res
;
1677 isp116x
= hcd_to_isp116x(hcd
);
1678 pdev
= container_of(dev
, struct platform_device
, dev
);
1679 remove_debug_file(isp116x
);
1680 usb_remove_hcd(hcd
);
1682 iounmap(isp116x
->data_reg
);
1683 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1684 release_mem_region(res
->start
, 2);
1685 iounmap(isp116x
->addr_reg
);
1686 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1687 release_mem_region(res
->start
, 2);
1693 #define resource_len(r) (((r)->end - (r)->start) + 1)
1695 static int __init
isp116x_probe(struct device
*dev
)
1697 struct usb_hcd
*hcd
;
1698 struct isp116x
*isp116x
;
1699 struct platform_device
*pdev
;
1700 struct resource
*addr
, *data
;
1701 void __iomem
*addr_reg
;
1702 void __iomem
*data_reg
;
1706 pdev
= container_of(dev
, struct platform_device
, dev
);
1707 if (pdev
->num_resources
< 3) {
1712 data
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1713 addr
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1714 irq
= platform_get_irq(pdev
, 0);
1715 if (!addr
|| !data
|| irq
< 0) {
1720 if (dev
->dma_mask
) {
1721 DBG("DMA not supported\n");
1726 if (!request_mem_region(addr
->start
, 2, hcd_name
)) {
1730 addr_reg
= ioremap(addr
->start
, resource_len(addr
));
1731 if (addr_reg
== NULL
) {
1735 if (!request_mem_region(data
->start
, 2, hcd_name
)) {
1739 data_reg
= ioremap(data
->start
, resource_len(data
));
1740 if (data_reg
== NULL
) {
1745 /* allocate and initialize hcd */
1746 hcd
= usb_create_hcd(&isp116x_hc_driver
, dev
, dev
->bus_id
);
1751 /* this rsrc_start is bogus */
1752 hcd
->rsrc_start
= addr
->start
;
1753 isp116x
= hcd_to_isp116x(hcd
);
1754 isp116x
->data_reg
= data_reg
;
1755 isp116x
->addr_reg
= addr_reg
;
1756 spin_lock_init(&isp116x
->lock
);
1757 INIT_LIST_HEAD(&isp116x
->async
);
1758 INIT_WORK(&isp116x
->rh_resume
, isp116x_rh_resume
, hcd
);
1759 isp116x
->board
= dev
->platform_data
;
1761 if (!isp116x
->board
) {
1762 ERR("Platform data structure not initialized\n");
1766 if (isp116x_check_platform_delay(isp116x
)) {
1767 ERR("USE_PLATFORM_DELAY defined, but delay function not "
1769 ERR("See comments in drivers/usb/host/isp116x-hcd.c\n");
1774 ret
= usb_add_hcd(hcd
, irq
, SA_INTERRUPT
);
1778 create_debug_file(isp116x
);
1786 release_mem_region(data
->start
, 2);
1790 release_mem_region(addr
->start
, 2);
1792 ERR("init error, %d\n", ret
);
1798 Suspend of platform device
1800 static int isp116x_suspend(struct device
*dev
, pm_message_t state
, u32 phase
)
1803 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
1805 VDBG("%s: state %x, phase %x\n", __func__
, state
, phase
);
1807 if (phase
!= SUSPEND_DISABLE
&& phase
!= SUSPEND_POWER_DOWN
)
1810 ret
= usb_suspend_device(hcd
->self
.root_hub
, state
);
1812 dev
->power
.power_state
= state
;
1813 INFO("%s suspended\n", (char *)hcd_name
);
1815 ERR("%s suspend failed\n", (char *)hcd_name
);
1821 Resume platform device
1823 static int isp116x_resume(struct device
*dev
, u32 phase
)
1826 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
1828 VDBG("%s: state %x, phase %x\n", __func__
, dev
->power
.power_state
,
1830 if (phase
!= RESUME_POWER_ON
)
1833 ret
= usb_resume_device(hcd
->self
.root_hub
);
1835 dev
->power
.power_state
= PMSG_ON
;
1836 VDBG("%s resumed\n", (char *)hcd_name
);
1843 #define isp116x_suspend NULL
1844 #define isp116x_resume NULL
1848 static struct device_driver isp116x_driver
= {
1849 .name
= (char *)hcd_name
,
1850 .bus
= &platform_bus_type
,
1851 .probe
= isp116x_probe
,
1852 .remove
= isp116x_remove
,
1853 .suspend
= isp116x_suspend
,
1854 .resume
= isp116x_resume
,
1857 /*-----------------------------------------------------------------*/
1859 static int __init
isp116x_init(void)
1864 INFO("driver %s, %s\n", hcd_name
, DRIVER_VERSION
);
1865 return driver_register(&isp116x_driver
);
1868 module_init(isp116x_init
);
1870 static void __exit
isp116x_cleanup(void)
1872 driver_unregister(&isp116x_driver
);
1875 module_exit(isp116x_cleanup
);