2 * ISP1362 HCD (Host Controller Driver) for USB.
4 * Copyright (C) 2005 Lothar Wassmann <LW@KARO-electronics.de>
6 * Derived from the SL811 HCD, rewritten for ISP116x.
7 * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
10 * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
11 * Copyright (C) 2004 David Brownell
15 * The ISP1362 chip requires a large delay (300ns and 462ns) between
16 * accesses to the address and data register.
17 * The following timing options exist:
19 * 1. Configure your memory controller to add such delays if it can (the best)
20 * 2. Implement platform-specific delay function possibly
21 * combined with configuring the memory controller; see
22 * include/linux/usb_isp1362.h for more info.
23 * 3. Use ndelay (easiest, poorest).
25 * Use the corresponding macros USE_PLATFORM_DELAY and USE_NDELAY in the
26 * platform specific section of isp1362.h to select the appropriate variant.
28 * Also note that according to the Philips "ISP1362 Errata" document
29 * Rev 1.00 from 27 May data corruption may occur when the #WR signal
30 * is reasserted (even with #CS deasserted) within 132ns after a
31 * write cycle to any controller register. If the hardware doesn't
32 * implement the recommended fix (gating the #WR with #CS) software
33 * must ensure that no further write cycle (not necessarily to the chip!)
34 * is issued by the CPU within this interval.
36 * For PXA25x this can be ensured by using VLIO with the maximum
37 * recovery time (MSCx = 0x7f8c) with a memory clock of 99.53 MHz.
40 #ifdef CONFIG_USB_DEBUG
41 # define ISP1362_DEBUG
47 * The PXA255 UDC apparently doesn't handle GET_STATUS, GET_CONFIG and
48 * GET_INTERFACE requests correctly when the SETUP and DATA stages of the
49 * requests are carried out in separate frames. This will delay any SETUP
50 * packets until the start of the next frame so that this situation is
51 * unlikely to occur (and makes usbtest happy running with a PXA255 target
54 #undef BUGGY_PXA2XX_UDC_USBTEST
61 /* This enables a memory test on the ISP1362 chip memory to make sure the
62 * chip access timing is correct.
64 #undef CHIP_BUFFER_TEST
66 #include <linux/module.h>
67 #include <linux/moduleparam.h>
68 #include <linux/kernel.h>
69 #include <linux/delay.h>
70 #include <linux/ioport.h>
71 #include <linux/sched.h>
72 #include <linux/slab.h>
73 #include <linux/smp_lock.h>
74 #include <linux/errno.h>
75 #include <linux/init.h>
76 #include <linux/list.h>
77 #include <linux/interrupt.h>
78 #include <linux/usb.h>
79 #include <linux/usb/isp1362.h>
80 #include <linux/platform_device.h>
83 #include <linux/bitmap.h>
86 #include <asm/system.h>
87 #include <asm/byteorder.h>
88 #include <asm/unaligned.h>
92 module_param(dbg_level
, int, 0644);
94 module_param(dbg_level
, int, 0);
95 #define STUB_DEBUG_FILE
98 #include "../core/hcd.h"
99 #include "../core/usb.h"
103 #define DRIVER_VERSION "2005-04-04"
104 #define DRIVER_DESC "ISP1362 USB Host Controller Driver"
106 MODULE_DESCRIPTION(DRIVER_DESC
);
107 MODULE_LICENSE("GPL");
109 static const char hcd_name
[] = "isp1362-hcd";
111 static void isp1362_hc_stop(struct usb_hcd
*hcd
);
112 static int isp1362_hc_start(struct usb_hcd
*hcd
);
114 /*-------------------------------------------------------------------------*/
117 * When called from the interrupthandler only isp1362_hcd->irqenb is modified,
118 * since the interrupt handler will write isp1362_hcd->irqenb to HCuPINT upon
120 * We don't need a 'disable' counterpart, since interrupts will be disabled
121 * only by the interrupt handler.
123 static inline void isp1362_enable_int(struct isp1362_hcd
*isp1362_hcd
, u16 mask
)
125 if ((isp1362_hcd
->irqenb
| mask
) == isp1362_hcd
->irqenb
)
127 if (mask
& ~isp1362_hcd
->irqenb
)
128 isp1362_write_reg16(isp1362_hcd
, HCuPINT
, mask
& ~isp1362_hcd
->irqenb
);
129 isp1362_hcd
->irqenb
|= mask
;
130 if (isp1362_hcd
->irq_active
)
132 isp1362_write_reg16(isp1362_hcd
, HCuPINTENB
, isp1362_hcd
->irqenb
);
135 /*-------------------------------------------------------------------------*/
137 static inline struct isp1362_ep_queue
*get_ptd_queue(struct isp1362_hcd
*isp1362_hcd
,
140 struct isp1362_ep_queue
*epq
= NULL
;
142 if (offset
< isp1362_hcd
->istl_queue
[1].buf_start
)
143 epq
= &isp1362_hcd
->istl_queue
[0];
144 else if (offset
< isp1362_hcd
->intl_queue
.buf_start
)
145 epq
= &isp1362_hcd
->istl_queue
[1];
146 else if (offset
< isp1362_hcd
->atl_queue
.buf_start
)
147 epq
= &isp1362_hcd
->intl_queue
;
148 else if (offset
< isp1362_hcd
->atl_queue
.buf_start
+
149 isp1362_hcd
->atl_queue
.buf_size
)
150 epq
= &isp1362_hcd
->atl_queue
;
153 DBG(1, "%s: PTD $%04x is on %s queue\n", __func__
, offset
, epq
->name
);
155 pr_warning("%s: invalid PTD $%04x\n", __func__
, offset
);
160 static inline int get_ptd_offset(struct isp1362_ep_queue
*epq
, u8 index
)
164 if (index
* epq
->blk_size
> epq
->buf_size
) {
165 pr_warning("%s: Bad %s index %d(%d)\n", __func__
, epq
->name
, index
,
166 epq
->buf_size
/ epq
->blk_size
);
169 offset
= epq
->buf_start
+ index
* epq
->blk_size
;
170 DBG(3, "%s: %s PTD[%02x] # %04x\n", __func__
, epq
->name
, index
, offset
);
175 /*-------------------------------------------------------------------------*/
177 static inline u16
max_transfer_size(struct isp1362_ep_queue
*epq
, size_t size
,
180 u16 xfer_size
= min_t(size_t, MAX_XFER_SIZE
, size
);
182 xfer_size
= min_t(size_t, xfer_size
, epq
->buf_avail
* epq
->blk_size
- PTD_HEADER_SIZE
);
183 if (xfer_size
< size
&& xfer_size
% mps
)
184 xfer_size
-= xfer_size
% mps
;
189 static int claim_ptd_buffers(struct isp1362_ep_queue
*epq
,
190 struct isp1362_ep
*ep
, u16 len
)
192 int ptd_offset
= -EINVAL
;
193 int num_ptds
= ((len
+ PTD_HEADER_SIZE
- 1) / epq
->blk_size
) + 1;
196 BUG_ON(len
> epq
->buf_size
);
202 pr_err("%s: %s len %d/%d num_ptds %d buf_map %08lx skip_map %08lx\n", __func__
,
203 epq
->name
, len
, epq
->blk_size
, num_ptds
, epq
->buf_map
, epq
->skip_map
);
204 BUG_ON(ep
->num_ptds
!= 0);
206 found
= bitmap_find_next_zero_area(&epq
->buf_map
, epq
->buf_count
, 0,
208 if (found
>= epq
->buf_count
)
211 DBG(1, "%s: Found %d PTDs[%d] for %d/%d byte\n", __func__
,
212 num_ptds
, found
, len
, (int)(epq
->blk_size
- PTD_HEADER_SIZE
));
213 ptd_offset
= get_ptd_offset(epq
, found
);
214 WARN_ON(ptd_offset
< 0);
215 ep
->ptd_offset
= ptd_offset
;
216 ep
->num_ptds
+= num_ptds
;
217 epq
->buf_avail
-= num_ptds
;
218 BUG_ON(epq
->buf_avail
> epq
->buf_count
);
219 ep
->ptd_index
= found
;
220 bitmap_set(&epq
->buf_map
, found
, num_ptds
);
221 DBG(1, "%s: Done %s PTD[%d] $%04x, avail %d count %d claimed %d %08lx:%08lx\n",
222 __func__
, epq
->name
, ep
->ptd_index
, ep
->ptd_offset
,
223 epq
->buf_avail
, epq
->buf_count
, num_ptds
, epq
->buf_map
, epq
->skip_map
);
228 static inline void release_ptd_buffers(struct isp1362_ep_queue
*epq
, struct isp1362_ep
*ep
)
230 int index
= ep
->ptd_index
;
231 int last
= ep
->ptd_index
+ ep
->num_ptds
;
233 if (last
> epq
->buf_count
)
234 pr_err("%s: ep %p req %d len %d %s PTD[%d] $%04x num_ptds %d buf_count %d buf_avail %d buf_map %08lx skip_map %08lx\n",
235 __func__
, ep
, ep
->num_req
, ep
->length
, epq
->name
, ep
->ptd_index
,
236 ep
->ptd_offset
, ep
->num_ptds
, epq
->buf_count
, epq
->buf_avail
,
237 epq
->buf_map
, epq
->skip_map
);
238 BUG_ON(last
> epq
->buf_count
);
240 for (; index
< last
; index
++) {
241 __clear_bit(index
, &epq
->buf_map
);
242 __set_bit(index
, &epq
->skip_map
);
244 epq
->buf_avail
+= ep
->num_ptds
;
247 BUG_ON(epq
->buf_avail
> epq
->buf_count
);
248 BUG_ON(epq
->ptd_count
> epq
->buf_count
);
250 DBG(1, "%s: Done %s PTDs $%04x released %d avail %d count %d\n",
252 ep
->ptd_offset
, ep
->num_ptds
, epq
->buf_avail
, epq
->buf_count
);
253 DBG(1, "%s: buf_map %08lx skip_map %08lx\n", __func__
,
254 epq
->buf_map
, epq
->skip_map
);
257 ep
->ptd_offset
= -EINVAL
;
258 ep
->ptd_index
= -EINVAL
;
261 /*-------------------------------------------------------------------------*/
266 static void prepare_ptd(struct isp1362_hcd
*isp1362_hcd
, struct urb
*urb
,
267 struct isp1362_ep
*ep
, struct isp1362_ep_queue
*epq
,
274 size_t buf_len
= urb
->transfer_buffer_length
- urb
->actual_length
;
276 DBG(3, "%s: %s ep %p\n", __func__
, epq
->name
, ep
);
280 ep
->data
= (unsigned char *)urb
->transfer_buffer
+ urb
->actual_length
;
282 switch (ep
->nextpid
) {
284 toggle
= usb_gettoggle(urb
->dev
, ep
->epnum
, 0);
286 if (usb_pipecontrol(urb
->pipe
)) {
287 len
= min_t(size_t, ep
->maxpacket
, buf_len
);
288 } else if (usb_pipeisoc(urb
->pipe
)) {
289 len
= min_t(size_t, urb
->iso_frame_desc
[fno
].length
, MAX_XFER_SIZE
);
290 ep
->data
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[fno
].offset
;
292 len
= max_transfer_size(epq
, buf_len
, ep
->maxpacket
);
293 DBG(1, "%s: IN len %d/%d/%d from URB\n", __func__
, len
, ep
->maxpacket
,
297 toggle
= usb_gettoggle(urb
->dev
, ep
->epnum
, 1);
299 if (usb_pipecontrol(urb
->pipe
))
300 len
= min_t(size_t, ep
->maxpacket
, buf_len
);
301 else if (usb_pipeisoc(urb
->pipe
))
302 len
= min_t(size_t, urb
->iso_frame_desc
[0].length
, MAX_XFER_SIZE
);
304 len
= max_transfer_size(epq
, buf_len
, ep
->maxpacket
);
306 pr_info("%s: Sending ZERO packet: %d\n", __func__
,
307 urb
->transfer_flags
& URB_ZERO_PACKET
);
308 DBG(1, "%s: OUT len %d/%d/%d from URB\n", __func__
, len
, ep
->maxpacket
,
314 len
= sizeof(struct usb_ctrlrequest
);
315 DBG(1, "%s: SETUP len %d\n", __func__
, len
);
316 ep
->data
= urb
->setup_packet
;
321 dir
= (urb
->transfer_buffer_length
&& usb_pipein(urb
->pipe
)) ?
322 PTD_DIR_OUT
: PTD_DIR_IN
;
323 DBG(1, "%s: ACK len %d\n", __func__
, len
);
326 toggle
= dir
= len
= 0;
327 pr_err("%s@%d: ep->nextpid %02x\n", __func__
, __LINE__
, ep
->nextpid
);
335 ptd
->count
= PTD_CC_MSK
| PTD_ACTIVE_MSK
| PTD_TOGGLE(toggle
);
336 ptd
->mps
= PTD_MPS(ep
->maxpacket
) | PTD_SPD(urb
->dev
->speed
== USB_SPEED_LOW
) |
338 ptd
->len
= PTD_LEN(len
) | PTD_DIR(dir
);
339 ptd
->faddr
= PTD_FA(usb_pipedevice(urb
->pipe
));
341 if (usb_pipeint(urb
->pipe
)) {
342 ptd
->faddr
|= PTD_SF_INT(ep
->branch
);
343 ptd
->faddr
|= PTD_PR(ep
->interval
? __ffs(ep
->interval
) : 0);
345 if (usb_pipeisoc(urb
->pipe
))
346 ptd
->faddr
|= PTD_SF_ISO(fno
);
348 DBG(1, "%s: Finished\n", __func__
);
351 static void isp1362_write_ptd(struct isp1362_hcd
*isp1362_hcd
, struct isp1362_ep
*ep
,
352 struct isp1362_ep_queue
*epq
)
354 struct ptd
*ptd
= &ep
->ptd
;
355 int len
= PTD_GET_DIR(ptd
) == PTD_DIR_IN
? 0 : ep
->length
;
357 _BUG_ON(ep
->ptd_offset
< 0);
360 isp1362_write_buffer(isp1362_hcd
, ptd
, ep
->ptd_offset
, PTD_HEADER_SIZE
);
362 isp1362_write_buffer(isp1362_hcd
, ep
->data
,
363 ep
->ptd_offset
+ PTD_HEADER_SIZE
, len
);
366 dump_ptd_out_data(ptd
, ep
->data
);
369 static void isp1362_read_ptd(struct isp1362_hcd
*isp1362_hcd
, struct isp1362_ep
*ep
,
370 struct isp1362_ep_queue
*epq
)
372 struct ptd
*ptd
= &ep
->ptd
;
375 WARN_ON(list_empty(&ep
->active
));
376 BUG_ON(ep
->ptd_offset
< 0);
378 list_del_init(&ep
->active
);
379 DBG(1, "%s: ep %p removed from active list %p\n", __func__
, ep
, &epq
->active
);
382 isp1362_read_buffer(isp1362_hcd
, ptd
, ep
->ptd_offset
, PTD_HEADER_SIZE
);
384 act_len
= PTD_GET_COUNT(ptd
);
385 if (PTD_GET_DIR(ptd
) != PTD_DIR_IN
|| act_len
== 0)
387 if (act_len
> ep
->length
)
388 pr_err("%s: ep %p PTD $%04x act_len %d ep->length %d\n", __func__
, ep
,
389 ep
->ptd_offset
, act_len
, ep
->length
);
390 BUG_ON(act_len
> ep
->length
);
391 /* Only transfer the amount of data that has actually been overwritten
392 * in the chip buffer. We don't want any data that doesn't belong to the
393 * transfer to leak out of the chip to the callers transfer buffer!
396 isp1362_read_buffer(isp1362_hcd
, ep
->data
,
397 ep
->ptd_offset
+ PTD_HEADER_SIZE
, act_len
);
398 dump_ptd_in_data(ptd
, ep
->data
);
402 * INT PTDs will stay in the chip until data is available.
403 * This function will remove a PTD from the chip when the URB is dequeued.
404 * Must be called with the spinlock held and IRQs disabled
406 static void remove_ptd(struct isp1362_hcd
*isp1362_hcd
, struct isp1362_ep
*ep
)
410 struct isp1362_ep_queue
*epq
;
412 DBG(1, "%s: ep %p PTD[%d] $%04x\n", __func__
, ep
, ep
->ptd_index
, ep
->ptd_offset
);
413 BUG_ON(ep
->ptd_offset
< 0);
415 epq
= get_ptd_queue(isp1362_hcd
, ep
->ptd_offset
);
418 /* put ep in remove_list for cleanup */
419 WARN_ON(!list_empty(&ep
->remove_list
));
420 list_add_tail(&ep
->remove_list
, &isp1362_hcd
->remove_list
);
421 /* let SOF interrupt handle the cleanup */
422 isp1362_enable_int(isp1362_hcd
, HCuPINT_SOF
);
424 index
= ep
->ptd_index
;
426 /* ISO queues don't have SKIP registers */
429 DBG(1, "%s: Disabling PTD[%02x] $%04x %08lx|%08x\n", __func__
,
430 index
, ep
->ptd_offset
, epq
->skip_map
, 1 << index
);
432 /* prevent further processing of PTD (will be effective after next SOF) */
433 epq
->skip_map
|= 1 << index
;
434 if (epq
== &isp1362_hcd
->atl_queue
) {
435 DBG(2, "%s: ATLSKIP = %08x -> %08lx\n", __func__
,
436 isp1362_read_reg32(isp1362_hcd
, HCATLSKIP
), epq
->skip_map
);
437 isp1362_write_reg32(isp1362_hcd
, HCATLSKIP
, epq
->skip_map
);
438 if (~epq
->skip_map
== 0)
439 isp1362_clr_mask16(isp1362_hcd
, HCBUFSTAT
, HCBUFSTAT_ATL_ACTIVE
);
440 } else if (epq
== &isp1362_hcd
->intl_queue
) {
441 DBG(2, "%s: INTLSKIP = %08x -> %08lx\n", __func__
,
442 isp1362_read_reg32(isp1362_hcd
, HCINTLSKIP
), epq
->skip_map
);
443 isp1362_write_reg32(isp1362_hcd
, HCINTLSKIP
, epq
->skip_map
);
444 if (~epq
->skip_map
== 0)
445 isp1362_clr_mask16(isp1362_hcd
, HCBUFSTAT
, HCBUFSTAT_INTL_ACTIVE
);
450 Take done or failed requests out of schedule. Give back
453 static void finish_request(struct isp1362_hcd
*isp1362_hcd
, struct isp1362_ep
*ep
,
454 struct urb
*urb
, int status
)
455 __releases(isp1362_hcd
->lock
)
456 __acquires(isp1362_hcd
->lock
)
461 if (usb_pipecontrol(urb
->pipe
))
462 ep
->nextpid
= USB_PID_SETUP
;
464 URB_DBG("%s: req %d FA %d ep%d%s %s: len %d/%d %s stat %d\n", __func__
,
465 ep
->num_req
, usb_pipedevice(urb
->pipe
),
466 usb_pipeendpoint(urb
->pipe
),
467 !usb_pipein(urb
->pipe
) ? "out" : "in",
468 usb_pipecontrol(urb
->pipe
) ? "ctrl" :
469 usb_pipeint(urb
->pipe
) ? "int" :
470 usb_pipebulk(urb
->pipe
) ? "bulk" :
472 urb
->actual_length
, urb
->transfer_buffer_length
,
473 !(urb
->transfer_flags
& URB_SHORT_NOT_OK
) ?
474 "short_ok" : "", urb
->status
);
477 usb_hcd_unlink_urb_from_ep(isp1362_hcd_to_hcd(isp1362_hcd
), urb
);
478 spin_unlock(&isp1362_hcd
->lock
);
479 usb_hcd_giveback_urb(isp1362_hcd_to_hcd(isp1362_hcd
), urb
, status
);
480 spin_lock(&isp1362_hcd
->lock
);
482 /* take idle endpoints out of the schedule right away */
483 if (!list_empty(&ep
->hep
->urb_list
))
486 /* async deschedule */
487 if (!list_empty(&ep
->schedule
)) {
488 list_del_init(&ep
->schedule
);
494 /* periodic deschedule */
495 DBG(1, "deschedule qh%d/%p branch %d load %d bandwidth %d -> %d\n", ep
->interval
,
496 ep
, ep
->branch
, ep
->load
,
497 isp1362_hcd
->load
[ep
->branch
],
498 isp1362_hcd
->load
[ep
->branch
] - ep
->load
);
499 isp1362_hcd
->load
[ep
->branch
] -= ep
->load
;
500 ep
->branch
= PERIODIC_SIZE
;
505 * Analyze transfer results, handle partial transfers and errors
507 static void postproc_ep(struct isp1362_hcd
*isp1362_hcd
, struct isp1362_ep
*ep
)
509 struct urb
*urb
= get_urb(ep
);
510 struct usb_device
*udev
;
514 int urbstat
= -EINPROGRESS
;
517 DBG(2, "%s: ep %p req %d\n", __func__
, ep
, ep
->num_req
);
521 cc
= PTD_GET_CC(ptd
);
522 if (cc
== PTD_NOTACCESSED
) {
523 pr_err("%s: req %d PTD %p Untouched by ISP1362\n", __func__
,
528 short_ok
= !(urb
->transfer_flags
& URB_SHORT_NOT_OK
);
529 len
= urb
->transfer_buffer_length
- urb
->actual_length
;
531 /* Data underrun is special. For allowed underrun
532 we clear the error and continue as normal. For
533 forbidden underrun we finish the DATA stage
534 immediately while for control transfer,
535 we do a STATUS stage.
537 if (cc
== PTD_DATAUNDERRUN
) {
539 DBG(1, "%s: req %d Allowed data underrun short_%sok %d/%d/%d byte\n",
540 __func__
, ep
->num_req
, short_ok
? "" : "not_",
541 PTD_GET_COUNT(ptd
), ep
->maxpacket
, len
);
545 DBG(1, "%s: req %d Data Underrun %s nextpid %02x short_%sok %d/%d/%d byte\n",
546 __func__
, ep
->num_req
,
547 usb_pipein(urb
->pipe
) ? "IN" : "OUT", ep
->nextpid
,
548 short_ok
? "" : "not_",
549 PTD_GET_COUNT(ptd
), ep
->maxpacket
, len
);
550 if (usb_pipecontrol(urb
->pipe
)) {
551 ep
->nextpid
= USB_PID_ACK
;
552 /* save the data underrun error code for later and
553 * procede with the status stage
555 urb
->actual_length
+= PTD_GET_COUNT(ptd
);
556 BUG_ON(urb
->actual_length
> urb
->transfer_buffer_length
);
558 if (urb
->status
== -EINPROGRESS
)
559 urb
->status
= cc_to_error
[PTD_DATAUNDERRUN
];
561 usb_settoggle(udev
, ep
->epnum
, ep
->nextpid
== USB_PID_OUT
,
562 PTD_GET_TOGGLE(ptd
));
563 urbstat
= cc_to_error
[PTD_DATAUNDERRUN
];
569 if (cc
!= PTD_CC_NOERROR
) {
570 if (++ep
->error_count
>= 3 || cc
== PTD_CC_STALL
|| cc
== PTD_DATAOVERRUN
) {
571 urbstat
= cc_to_error
[cc
];
572 DBG(1, "%s: req %d nextpid %02x, status %d, error %d, error_count %d\n",
573 __func__
, ep
->num_req
, ep
->nextpid
, urbstat
, cc
,
579 switch (ep
->nextpid
) {
581 if (PTD_GET_COUNT(ptd
) != ep
->length
)
582 pr_err("%s: count=%d len=%d\n", __func__
,
583 PTD_GET_COUNT(ptd
), ep
->length
);
584 BUG_ON(PTD_GET_COUNT(ptd
) != ep
->length
);
585 urb
->actual_length
+= ep
->length
;
586 BUG_ON(urb
->actual_length
> urb
->transfer_buffer_length
);
587 usb_settoggle(udev
, ep
->epnum
, 1, PTD_GET_TOGGLE(ptd
));
588 if (urb
->actual_length
== urb
->transfer_buffer_length
) {
589 DBG(3, "%s: req %d xfer complete %d/%d status %d -> 0\n", __func__
,
590 ep
->num_req
, len
, ep
->maxpacket
, urbstat
);
591 if (usb_pipecontrol(urb
->pipe
)) {
592 DBG(3, "%s: req %d %s Wait for ACK\n", __func__
,
594 usb_pipein(urb
->pipe
) ? "IN" : "OUT");
595 ep
->nextpid
= USB_PID_ACK
;
597 if (len
% ep
->maxpacket
||
598 !(urb
->transfer_flags
& URB_ZERO_PACKET
)) {
600 DBG(3, "%s: req %d URB %s status %d count %d/%d/%d\n",
601 __func__
, ep
->num_req
, usb_pipein(urb
->pipe
) ? "IN" : "OUT",
602 urbstat
, len
, ep
->maxpacket
, urb
->actual_length
);
608 len
= PTD_GET_COUNT(ptd
);
609 BUG_ON(len
> ep
->length
);
610 urb
->actual_length
+= len
;
611 BUG_ON(urb
->actual_length
> urb
->transfer_buffer_length
);
612 usb_settoggle(udev
, ep
->epnum
, 0, PTD_GET_TOGGLE(ptd
));
613 /* if transfer completed or (allowed) data underrun */
614 if ((urb
->transfer_buffer_length
== urb
->actual_length
) ||
615 len
% ep
->maxpacket
) {
616 DBG(3, "%s: req %d xfer complete %d/%d status %d -> 0\n", __func__
,
617 ep
->num_req
, len
, ep
->maxpacket
, urbstat
);
618 if (usb_pipecontrol(urb
->pipe
)) {
619 DBG(3, "%s: req %d %s Wait for ACK\n", __func__
,
621 usb_pipein(urb
->pipe
) ? "IN" : "OUT");
622 ep
->nextpid
= USB_PID_ACK
;
625 DBG(3, "%s: req %d URB %s status %d count %d/%d/%d\n",
626 __func__
, ep
->num_req
, usb_pipein(urb
->pipe
) ? "IN" : "OUT",
627 urbstat
, len
, ep
->maxpacket
, urb
->actual_length
);
632 if (urb
->transfer_buffer_length
== urb
->actual_length
) {
633 ep
->nextpid
= USB_PID_ACK
;
634 } else if (usb_pipeout(urb
->pipe
)) {
635 usb_settoggle(udev
, 0, 1, 1);
636 ep
->nextpid
= USB_PID_OUT
;
638 usb_settoggle(udev
, 0, 0, 1);
639 ep
->nextpid
= USB_PID_IN
;
643 DBG(3, "%s: req %d got ACK %d -> 0\n", __func__
, ep
->num_req
,
645 WARN_ON(urbstat
!= -EINPROGRESS
);
654 if (urbstat
!= -EINPROGRESS
) {
655 DBG(2, "%s: Finishing ep %p req %d urb %p status %d\n", __func__
,
656 ep
, ep
->num_req
, urb
, urbstat
);
657 finish_request(isp1362_hcd
, ep
, urb
, urbstat
);
661 static void finish_unlinks(struct isp1362_hcd
*isp1362_hcd
)
663 struct isp1362_ep
*ep
;
664 struct isp1362_ep
*tmp
;
666 list_for_each_entry_safe(ep
, tmp
, &isp1362_hcd
->remove_list
, remove_list
) {
667 struct isp1362_ep_queue
*epq
=
668 get_ptd_queue(isp1362_hcd
, ep
->ptd_offset
);
669 int index
= ep
->ptd_index
;
673 DBG(1, "%s: remove PTD[%d] $%04x\n", __func__
, index
, ep
->ptd_offset
);
674 BUG_ON(ep
->num_ptds
== 0);
675 release_ptd_buffers(epq
, ep
);
677 if (!list_empty(&ep
->hep
->urb_list
)) {
678 struct urb
*urb
= get_urb(ep
);
680 DBG(1, "%s: Finishing req %d ep %p from remove_list\n", __func__
,
682 finish_request(isp1362_hcd
, ep
, urb
, -ESHUTDOWN
);
684 WARN_ON(list_empty(&ep
->active
));
685 if (!list_empty(&ep
->active
)) {
686 list_del_init(&ep
->active
);
687 DBG(1, "%s: ep %p removed from active list\n", __func__
, ep
);
689 list_del_init(&ep
->remove_list
);
690 DBG(1, "%s: ep %p removed from remove_list\n", __func__
, ep
);
692 DBG(1, "%s: Done\n", __func__
);
695 static inline void enable_atl_transfers(struct isp1362_hcd
*isp1362_hcd
, int count
)
698 if (count
< isp1362_hcd
->atl_queue
.ptd_count
)
699 isp1362_write_reg16(isp1362_hcd
, HCATLDTC
, count
);
700 isp1362_enable_int(isp1362_hcd
, HCuPINT_ATL
);
701 isp1362_write_reg32(isp1362_hcd
, HCATLSKIP
, isp1362_hcd
->atl_queue
.skip_map
);
702 isp1362_set_mask16(isp1362_hcd
, HCBUFSTAT
, HCBUFSTAT_ATL_ACTIVE
);
704 isp1362_enable_int(isp1362_hcd
, HCuPINT_SOF
);
707 static inline void enable_intl_transfers(struct isp1362_hcd
*isp1362_hcd
)
709 isp1362_enable_int(isp1362_hcd
, HCuPINT_INTL
);
710 isp1362_set_mask16(isp1362_hcd
, HCBUFSTAT
, HCBUFSTAT_INTL_ACTIVE
);
711 isp1362_write_reg32(isp1362_hcd
, HCINTLSKIP
, isp1362_hcd
->intl_queue
.skip_map
);
714 static inline void enable_istl_transfers(struct isp1362_hcd
*isp1362_hcd
, int flip
)
716 isp1362_enable_int(isp1362_hcd
, flip
? HCuPINT_ISTL1
: HCuPINT_ISTL0
);
717 isp1362_set_mask16(isp1362_hcd
, HCBUFSTAT
, flip
?
718 HCBUFSTAT_ISTL1_FULL
: HCBUFSTAT_ISTL0_FULL
);
721 static int submit_req(struct isp1362_hcd
*isp1362_hcd
, struct urb
*urb
,
722 struct isp1362_ep
*ep
, struct isp1362_ep_queue
*epq
)
724 int index
= epq
->free_ptd
;
726 prepare_ptd(isp1362_hcd
, urb
, ep
, epq
, 0);
727 index
= claim_ptd_buffers(epq
, ep
, ep
->length
);
728 if (index
== -ENOMEM
) {
729 DBG(1, "%s: req %d No free %s PTD available: %d, %08lx:%08lx\n", __func__
,
730 ep
->num_req
, epq
->name
, ep
->num_ptds
, epq
->buf_map
, epq
->skip_map
);
732 } else if (index
== -EOVERFLOW
) {
733 DBG(1, "%s: req %d Not enough space for %d byte %s PTD %d %08lx:%08lx\n",
734 __func__
, ep
->num_req
, ep
->length
, epq
->name
, ep
->num_ptds
,
735 epq
->buf_map
, epq
->skip_map
);
739 list_add_tail(&ep
->active
, &epq
->active
);
740 DBG(1, "%s: ep %p req %d len %d added to active list %p\n", __func__
,
741 ep
, ep
->num_req
, ep
->length
, &epq
->active
);
742 DBG(1, "%s: Submitting %s PTD $%04x for ep %p req %d\n", __func__
, epq
->name
,
743 ep
->ptd_offset
, ep
, ep
->num_req
);
744 isp1362_write_ptd(isp1362_hcd
, ep
, epq
);
745 __clear_bit(ep
->ptd_index
, &epq
->skip_map
);
750 static void start_atl_transfers(struct isp1362_hcd
*isp1362_hcd
)
753 struct isp1362_ep_queue
*epq
= &isp1362_hcd
->atl_queue
;
754 struct isp1362_ep
*ep
;
757 if (atomic_read(&epq
->finishing
)) {
758 DBG(1, "%s: finish_transfers is active for %s\n", __func__
, epq
->name
);
762 list_for_each_entry(ep
, &isp1362_hcd
->async
, schedule
) {
763 struct urb
*urb
= get_urb(ep
);
766 if (!list_empty(&ep
->active
)) {
767 DBG(2, "%s: Skipping active %s ep %p\n", __func__
, epq
->name
, ep
);
771 DBG(1, "%s: Processing %s ep %p req %d\n", __func__
, epq
->name
,
774 ret
= submit_req(isp1362_hcd
, urb
, ep
, epq
);
775 if (ret
== -ENOMEM
) {
778 } else if (ret
== -EOVERFLOW
) {
782 #ifdef BUGGY_PXA2XX_UDC_USBTEST
783 defer
= ep
->nextpid
== USB_PID_SETUP
;
788 /* Avoid starving of endpoints */
789 if (isp1362_hcd
->async
.next
!= isp1362_hcd
->async
.prev
) {
790 DBG(2, "%s: Cycling ASYNC schedule %d\n", __func__
, ptd_count
);
791 list_move(&isp1362_hcd
->async
, isp1362_hcd
->async
.next
);
793 if (ptd_count
|| defer
)
794 enable_atl_transfers(isp1362_hcd
, defer
? 0 : ptd_count
);
796 epq
->ptd_count
+= ptd_count
;
797 if (epq
->ptd_count
> epq
->stat_maxptds
) {
798 epq
->stat_maxptds
= epq
->ptd_count
;
799 DBG(0, "%s: max_ptds: %d\n", __func__
, epq
->stat_maxptds
);
803 static void start_intl_transfers(struct isp1362_hcd
*isp1362_hcd
)
806 struct isp1362_ep_queue
*epq
= &isp1362_hcd
->intl_queue
;
807 struct isp1362_ep
*ep
;
809 if (atomic_read(&epq
->finishing
)) {
810 DBG(1, "%s: finish_transfers is active for %s\n", __func__
, epq
->name
);
814 list_for_each_entry(ep
, &isp1362_hcd
->periodic
, schedule
) {
815 struct urb
*urb
= get_urb(ep
);
818 if (!list_empty(&ep
->active
)) {
819 DBG(1, "%s: Skipping active %s ep %p\n", __func__
,
824 DBG(1, "%s: Processing %s ep %p req %d\n", __func__
,
825 epq
->name
, ep
, ep
->num_req
);
826 ret
= submit_req(isp1362_hcd
, urb
, ep
, epq
);
829 else if (ret
== -EOVERFLOW
)
835 static int last_count
;
837 if (ptd_count
!= last_count
) {
838 DBG(0, "%s: ptd_count: %d\n", __func__
, ptd_count
);
839 last_count
= ptd_count
;
841 enable_intl_transfers(isp1362_hcd
);
844 epq
->ptd_count
+= ptd_count
;
845 if (epq
->ptd_count
> epq
->stat_maxptds
)
846 epq
->stat_maxptds
= epq
->ptd_count
;
849 static inline int next_ptd(struct isp1362_ep_queue
*epq
, struct isp1362_ep
*ep
)
851 u16 ptd_offset
= ep
->ptd_offset
;
852 int num_ptds
= (ep
->length
+ PTD_HEADER_SIZE
+ (epq
->blk_size
- 1)) / epq
->blk_size
;
854 DBG(2, "%s: PTD offset $%04x + %04x => %d * %04x -> $%04x\n", __func__
, ptd_offset
,
855 ep
->length
, num_ptds
, epq
->blk_size
, ptd_offset
+ num_ptds
* epq
->blk_size
);
857 ptd_offset
+= num_ptds
* epq
->blk_size
;
858 if (ptd_offset
< epq
->buf_start
+ epq
->buf_size
)
864 static void start_iso_transfers(struct isp1362_hcd
*isp1362_hcd
)
867 int flip
= isp1362_hcd
->istl_flip
;
868 struct isp1362_ep_queue
*epq
;
870 struct isp1362_ep
*ep
;
871 struct isp1362_ep
*tmp
;
872 u16 fno
= isp1362_read_reg32(isp1362_hcd
, HCFMNUM
);
875 epq
= &isp1362_hcd
->istl_queue
[flip
];
876 if (atomic_read(&epq
->finishing
)) {
877 DBG(1, "%s: finish_transfers is active for %s\n", __func__
, epq
->name
);
881 if (!list_empty(&epq
->active
))
884 ptd_offset
= epq
->buf_start
;
885 list_for_each_entry_safe(ep
, tmp
, &isp1362_hcd
->isoc
, schedule
) {
886 struct urb
*urb
= get_urb(ep
);
887 s16 diff
= fno
- (u16
)urb
->start_frame
;
889 DBG(1, "%s: Processing %s ep %p\n", __func__
, epq
->name
, ep
);
891 if (diff
> urb
->number_of_packets
) {
892 /* time frame for this URB has elapsed */
893 finish_request(isp1362_hcd
, ep
, urb
, -EOVERFLOW
);
895 } else if (diff
< -1) {
896 /* URB is not due in this frame or the next one.
897 * Comparing with '-1' instead of '0' accounts for double
898 * buffering in the ISP1362 which enables us to queue the PTD
899 * one frame ahead of time
901 } else if (diff
== -1) {
902 /* submit PTD's that are due in the next frame */
903 prepare_ptd(isp1362_hcd
, urb
, ep
, epq
, fno
);
904 if (ptd_offset
+ PTD_HEADER_SIZE
+ ep
->length
>
905 epq
->buf_start
+ epq
->buf_size
) {
906 pr_err("%s: Not enough ISO buffer space for %d byte PTD\n",
907 __func__
, ep
->length
);
910 ep
->ptd_offset
= ptd_offset
;
911 list_add_tail(&ep
->active
, &epq
->active
);
913 ptd_offset
= next_ptd(epq
, ep
);
914 if (ptd_offset
< 0) {
915 pr_warning("%s: req %d No more %s PTD buffers available\n", __func__
,
916 ep
->num_req
, epq
->name
);
921 list_for_each_entry(ep
, &epq
->active
, active
) {
922 if (epq
->active
.next
== &ep
->active
)
923 ep
->ptd
.mps
|= PTD_LAST_MSK
;
924 isp1362_write_ptd(isp1362_hcd
, ep
, epq
);
929 enable_istl_transfers(isp1362_hcd
, flip
);
931 epq
->ptd_count
+= ptd_count
;
932 if (epq
->ptd_count
> epq
->stat_maxptds
)
933 epq
->stat_maxptds
= epq
->ptd_count
;
935 /* check, whether the second ISTL buffer may also be filled */
936 if (!(isp1362_read_reg16(isp1362_hcd
, HCBUFSTAT
) &
937 (flip
? HCBUFSTAT_ISTL0_FULL
: HCBUFSTAT_ISTL1_FULL
))) {
945 static void finish_transfers(struct isp1362_hcd
*isp1362_hcd
, unsigned long done_map
,
946 struct isp1362_ep_queue
*epq
)
948 struct isp1362_ep
*ep
;
949 struct isp1362_ep
*tmp
;
951 if (list_empty(&epq
->active
)) {
952 DBG(1, "%s: Nothing to do for %s queue\n", __func__
, epq
->name
);
956 DBG(1, "%s: Finishing %s transfers %08lx\n", __func__
, epq
->name
, done_map
);
958 atomic_inc(&epq
->finishing
);
959 list_for_each_entry_safe(ep
, tmp
, &epq
->active
, active
) {
960 int index
= ep
->ptd_index
;
962 DBG(1, "%s: Checking %s PTD[%02x] $%04x\n", __func__
, epq
->name
,
963 index
, ep
->ptd_offset
);
966 if (__test_and_clear_bit(index
, &done_map
)) {
967 isp1362_read_ptd(isp1362_hcd
, ep
, epq
);
968 epq
->free_ptd
= index
;
969 BUG_ON(ep
->num_ptds
== 0);
970 release_ptd_buffers(epq
, ep
);
972 DBG(1, "%s: ep %p req %d removed from active list\n", __func__
,
974 if (!list_empty(&ep
->remove_list
)) {
975 list_del_init(&ep
->remove_list
);
976 DBG(1, "%s: ep %p removed from remove list\n", __func__
, ep
);
978 DBG(1, "%s: Postprocessing %s ep %p req %d\n", __func__
, epq
->name
,
980 postproc_ep(isp1362_hcd
, ep
);
986 pr_warning("%s: done_map not clear: %08lx:%08lx\n", __func__
, done_map
,
988 atomic_dec(&epq
->finishing
);
991 static void finish_iso_transfers(struct isp1362_hcd
*isp1362_hcd
, struct isp1362_ep_queue
*epq
)
993 struct isp1362_ep
*ep
;
994 struct isp1362_ep
*tmp
;
996 if (list_empty(&epq
->active
)) {
997 DBG(1, "%s: Nothing to do for %s queue\n", __func__
, epq
->name
);
1001 DBG(1, "%s: Finishing %s transfers\n", __func__
, epq
->name
);
1003 atomic_inc(&epq
->finishing
);
1004 list_for_each_entry_safe(ep
, tmp
, &epq
->active
, active
) {
1005 DBG(1, "%s: Checking PTD $%04x\n", __func__
, ep
->ptd_offset
);
1007 isp1362_read_ptd(isp1362_hcd
, ep
, epq
);
1008 DBG(1, "%s: Postprocessing %s ep %p\n", __func__
, epq
->name
, ep
);
1009 postproc_ep(isp1362_hcd
, ep
);
1011 WARN_ON(epq
->blk_size
!= 0);
1012 atomic_dec(&epq
->finishing
);
1015 static irqreturn_t
isp1362_irq(struct usb_hcd
*hcd
)
1018 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
1022 spin_lock(&isp1362_hcd
->lock
);
1024 BUG_ON(isp1362_hcd
->irq_active
++);
1026 isp1362_write_reg16(isp1362_hcd
, HCuPINTENB
, 0);
1028 irqstat
= isp1362_read_reg16(isp1362_hcd
, HCuPINT
);
1029 DBG(3, "%s: got IRQ %04x:%04x\n", __func__
, irqstat
, isp1362_hcd
->irqenb
);
1031 /* only handle interrupts that are currently enabled */
1032 irqstat
&= isp1362_hcd
->irqenb
;
1033 isp1362_write_reg16(isp1362_hcd
, HCuPINT
, irqstat
);
1036 if (irqstat
& HCuPINT_SOF
) {
1037 isp1362_hcd
->irqenb
&= ~HCuPINT_SOF
;
1038 isp1362_hcd
->irq_stat
[ISP1362_INT_SOF
]++;
1040 svc_mask
&= ~HCuPINT_SOF
;
1041 DBG(3, "%s: SOF\n", __func__
);
1042 isp1362_hcd
->fmindex
= isp1362_read_reg32(isp1362_hcd
, HCFMNUM
);
1043 if (!list_empty(&isp1362_hcd
->remove_list
))
1044 finish_unlinks(isp1362_hcd
);
1045 if (!list_empty(&isp1362_hcd
->async
) && !(irqstat
& HCuPINT_ATL
)) {
1046 if (list_empty(&isp1362_hcd
->atl_queue
.active
)) {
1047 start_atl_transfers(isp1362_hcd
);
1049 isp1362_enable_int(isp1362_hcd
, HCuPINT_ATL
);
1050 isp1362_write_reg32(isp1362_hcd
, HCATLSKIP
,
1051 isp1362_hcd
->atl_queue
.skip_map
);
1052 isp1362_set_mask16(isp1362_hcd
, HCBUFSTAT
, HCBUFSTAT_ATL_ACTIVE
);
1057 if (irqstat
& HCuPINT_ISTL0
) {
1058 isp1362_hcd
->irq_stat
[ISP1362_INT_ISTL0
]++;
1060 svc_mask
&= ~HCuPINT_ISTL0
;
1061 isp1362_clr_mask16(isp1362_hcd
, HCBUFSTAT
, HCBUFSTAT_ISTL0_FULL
);
1062 DBG(1, "%s: ISTL0\n", __func__
);
1063 WARN_ON((int)!!isp1362_hcd
->istl_flip
);
1064 WARN_ON(isp1362_read_reg16(isp1362_hcd
, HCBUFSTAT
) &
1065 HCBUFSTAT_ISTL0_ACTIVE
);
1066 WARN_ON(!(isp1362_read_reg16(isp1362_hcd
, HCBUFSTAT
) &
1067 HCBUFSTAT_ISTL0_DONE
));
1068 isp1362_hcd
->irqenb
&= ~HCuPINT_ISTL0
;
1071 if (irqstat
& HCuPINT_ISTL1
) {
1072 isp1362_hcd
->irq_stat
[ISP1362_INT_ISTL1
]++;
1074 svc_mask
&= ~HCuPINT_ISTL1
;
1075 isp1362_clr_mask16(isp1362_hcd
, HCBUFSTAT
, HCBUFSTAT_ISTL1_FULL
);
1076 DBG(1, "%s: ISTL1\n", __func__
);
1077 WARN_ON(!(int)isp1362_hcd
->istl_flip
);
1078 WARN_ON(isp1362_read_reg16(isp1362_hcd
, HCBUFSTAT
) &
1079 HCBUFSTAT_ISTL1_ACTIVE
);
1080 WARN_ON(!(isp1362_read_reg16(isp1362_hcd
, HCBUFSTAT
) &
1081 HCBUFSTAT_ISTL1_DONE
));
1082 isp1362_hcd
->irqenb
&= ~HCuPINT_ISTL1
;
1085 if (irqstat
& (HCuPINT_ISTL0
| HCuPINT_ISTL1
)) {
1086 WARN_ON((irqstat
& (HCuPINT_ISTL0
| HCuPINT_ISTL1
)) ==
1087 (HCuPINT_ISTL0
| HCuPINT_ISTL1
));
1088 finish_iso_transfers(isp1362_hcd
,
1089 &isp1362_hcd
->istl_queue
[isp1362_hcd
->istl_flip
]);
1090 start_iso_transfers(isp1362_hcd
);
1091 isp1362_hcd
->istl_flip
= 1 - isp1362_hcd
->istl_flip
;
1094 if (irqstat
& HCuPINT_INTL
) {
1095 u32 done_map
= isp1362_read_reg32(isp1362_hcd
, HCINTLDONE
);
1096 u32 skip_map
= isp1362_read_reg32(isp1362_hcd
, HCINTLSKIP
);
1097 isp1362_hcd
->irq_stat
[ISP1362_INT_INTL
]++;
1099 DBG(2, "%s: INTL\n", __func__
);
1101 svc_mask
&= ~HCuPINT_INTL
;
1103 isp1362_write_reg32(isp1362_hcd
, HCINTLSKIP
, skip_map
| done_map
);
1104 if (~(done_map
| skip_map
) == 0)
1105 /* All PTDs are finished, disable INTL processing entirely */
1106 isp1362_clr_mask16(isp1362_hcd
, HCBUFSTAT
, HCBUFSTAT_INTL_ACTIVE
);
1111 DBG(3, "%s: INTL done_map %08x\n", __func__
, done_map
);
1112 finish_transfers(isp1362_hcd
, done_map
, &isp1362_hcd
->intl_queue
);
1113 start_intl_transfers(isp1362_hcd
);
1117 if (irqstat
& HCuPINT_ATL
) {
1118 u32 done_map
= isp1362_read_reg32(isp1362_hcd
, HCATLDONE
);
1119 u32 skip_map
= isp1362_read_reg32(isp1362_hcd
, HCATLSKIP
);
1120 isp1362_hcd
->irq_stat
[ISP1362_INT_ATL
]++;
1122 DBG(2, "%s: ATL\n", __func__
);
1124 svc_mask
&= ~HCuPINT_ATL
;
1126 isp1362_write_reg32(isp1362_hcd
, HCATLSKIP
, skip_map
| done_map
);
1127 if (~(done_map
| skip_map
) == 0)
1128 isp1362_clr_mask16(isp1362_hcd
, HCBUFSTAT
, HCBUFSTAT_ATL_ACTIVE
);
1130 DBG(3, "%s: ATL done_map %08x\n", __func__
, done_map
);
1131 finish_transfers(isp1362_hcd
, done_map
, &isp1362_hcd
->atl_queue
);
1132 start_atl_transfers(isp1362_hcd
);
1137 if (irqstat
& HCuPINT_OPR
) {
1138 u32 intstat
= isp1362_read_reg32(isp1362_hcd
, HCINTSTAT
);
1139 isp1362_hcd
->irq_stat
[ISP1362_INT_OPR
]++;
1141 svc_mask
&= ~HCuPINT_OPR
;
1142 DBG(2, "%s: OPR %08x:%08x\n", __func__
, intstat
, isp1362_hcd
->intenb
);
1143 intstat
&= isp1362_hcd
->intenb
;
1144 if (intstat
& OHCI_INTR_UE
) {
1145 pr_err("Unrecoverable error\n");
1146 /* FIXME: do here reset or cleanup or whatever */
1148 if (intstat
& OHCI_INTR_RHSC
) {
1149 isp1362_hcd
->rhstatus
= isp1362_read_reg32(isp1362_hcd
, HCRHSTATUS
);
1150 isp1362_hcd
->rhport
[0] = isp1362_read_reg32(isp1362_hcd
, HCRHPORT1
);
1151 isp1362_hcd
->rhport
[1] = isp1362_read_reg32(isp1362_hcd
, HCRHPORT2
);
1153 if (intstat
& OHCI_INTR_RD
) {
1154 pr_info("%s: RESUME DETECTED\n", __func__
);
1155 isp1362_show_reg(isp1362_hcd
, HCCONTROL
);
1156 usb_hcd_resume_root_hub(hcd
);
1158 isp1362_write_reg32(isp1362_hcd
, HCINTSTAT
, intstat
);
1159 irqstat
&= ~HCuPINT_OPR
;
1163 if (irqstat
& HCuPINT_SUSP
) {
1164 isp1362_hcd
->irq_stat
[ISP1362_INT_SUSP
]++;
1166 svc_mask
&= ~HCuPINT_SUSP
;
1168 pr_info("%s: SUSPEND IRQ\n", __func__
);
1171 if (irqstat
& HCuPINT_CLKRDY
) {
1172 isp1362_hcd
->irq_stat
[ISP1362_INT_CLKRDY
]++;
1174 isp1362_hcd
->irqenb
&= ~HCuPINT_CLKRDY
;
1175 svc_mask
&= ~HCuPINT_CLKRDY
;
1176 pr_info("%s: CLKRDY IRQ\n", __func__
);
1180 pr_err("%s: Unserviced interrupt(s) %04x\n", __func__
, svc_mask
);
1182 isp1362_write_reg16(isp1362_hcd
, HCuPINTENB
, isp1362_hcd
->irqenb
);
1183 isp1362_hcd
->irq_active
--;
1184 spin_unlock(&isp1362_hcd
->lock
);
1186 return IRQ_RETVAL(handled
);
1189 /*-------------------------------------------------------------------------*/
1191 #define MAX_PERIODIC_LOAD 900 /* out of 1000 usec */
1192 static int balance(struct isp1362_hcd
*isp1362_hcd
, u16 interval
, u16 load
)
1194 int i
, branch
= -ENOSPC
;
1196 /* search for the least loaded schedule branch of that interval
1197 * which has enough bandwidth left unreserved.
1199 for (i
= 0; i
< interval
; i
++) {
1200 if (branch
< 0 || isp1362_hcd
->load
[branch
] > isp1362_hcd
->load
[i
]) {
1203 for (j
= i
; j
< PERIODIC_SIZE
; j
+= interval
) {
1204 if ((isp1362_hcd
->load
[j
] + load
) > MAX_PERIODIC_LOAD
) {
1205 pr_err("%s: new load %d load[%02x] %d max %d\n", __func__
,
1206 load
, j
, isp1362_hcd
->load
[j
], MAX_PERIODIC_LOAD
);
1210 if (j
< PERIODIC_SIZE
)
1218 /* NB! ALL the code above this point runs with isp1362_hcd->lock
1222 /*-------------------------------------------------------------------------*/
1224 static int isp1362_urb_enqueue(struct usb_hcd
*hcd
,
1228 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
1229 struct usb_device
*udev
= urb
->dev
;
1230 unsigned int pipe
= urb
->pipe
;
1231 int is_out
= !usb_pipein(pipe
);
1232 int type
= usb_pipetype(pipe
);
1233 int epnum
= usb_pipeendpoint(pipe
);
1234 struct usb_host_endpoint
*hep
= urb
->ep
;
1235 struct isp1362_ep
*ep
= NULL
;
1236 unsigned long flags
;
1239 DBG(3, "%s: urb %p\n", __func__
, urb
);
1241 if (type
== PIPE_ISOCHRONOUS
) {
1242 pr_err("Isochronous transfers not supported\n");
1246 URB_DBG("%s: FA %d ep%d%s %s: len %d %s%s\n", __func__
,
1247 usb_pipedevice(pipe
), epnum
,
1248 is_out
? "out" : "in",
1249 usb_pipecontrol(pipe
) ? "ctrl" :
1250 usb_pipeint(pipe
) ? "int" :
1251 usb_pipebulk(pipe
) ? "bulk" :
1253 urb
->transfer_buffer_length
,
1254 (urb
->transfer_flags
& URB_ZERO_PACKET
) ? "ZERO_PACKET " : "",
1255 !(urb
->transfer_flags
& URB_SHORT_NOT_OK
) ?
1258 /* avoid all allocations within spinlocks: request or endpoint */
1260 ep
= kcalloc(1, sizeof *ep
, mem_flags
);
1264 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1266 /* don't submit to a dead or disabled port */
1267 if (!((isp1362_hcd
->rhport
[0] | isp1362_hcd
->rhport
[1]) &
1268 (1 << USB_PORT_FEAT_ENABLE
)) ||
1269 !HC_IS_RUNNING(hcd
->state
)) {
1272 goto fail_not_linked
;
1275 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
1278 goto fail_not_linked
;
1284 INIT_LIST_HEAD(&ep
->schedule
);
1285 INIT_LIST_HEAD(&ep
->active
);
1286 INIT_LIST_HEAD(&ep
->remove_list
);
1287 ep
->udev
= usb_get_dev(udev
);
1290 ep
->maxpacket
= usb_maxpacket(udev
, urb
->pipe
, is_out
);
1291 ep
->ptd_offset
= -EINVAL
;
1292 ep
->ptd_index
= -EINVAL
;
1293 usb_settoggle(udev
, epnum
, is_out
, 0);
1295 if (type
== PIPE_CONTROL
)
1296 ep
->nextpid
= USB_PID_SETUP
;
1298 ep
->nextpid
= USB_PID_OUT
;
1300 ep
->nextpid
= USB_PID_IN
;
1303 case PIPE_ISOCHRONOUS
:
1304 case PIPE_INTERRUPT
:
1305 if (urb
->interval
> PERIODIC_SIZE
)
1306 urb
->interval
= PERIODIC_SIZE
;
1307 ep
->interval
= urb
->interval
;
1308 ep
->branch
= PERIODIC_SIZE
;
1309 ep
->load
= usb_calc_bus_time(udev
->speed
, !is_out
,
1310 (type
== PIPE_ISOCHRONOUS
),
1311 usb_maxpacket(udev
, pipe
, is_out
)) / 1000;
1316 ep
->num_req
= isp1362_hcd
->req_serial
++;
1318 /* maybe put endpoint into schedule */
1322 if (list_empty(&ep
->schedule
)) {
1323 DBG(1, "%s: Adding ep %p req %d to async schedule\n",
1324 __func__
, ep
, ep
->num_req
);
1325 list_add_tail(&ep
->schedule
, &isp1362_hcd
->async
);
1328 case PIPE_ISOCHRONOUS
:
1329 case PIPE_INTERRUPT
:
1330 urb
->interval
= ep
->interval
;
1332 /* urb submitted for already existing EP */
1333 if (ep
->branch
< PERIODIC_SIZE
)
1336 retval
= balance(isp1362_hcd
, ep
->interval
, ep
->load
);
1338 pr_err("%s: balance returned %d\n", __func__
, retval
);
1341 ep
->branch
= retval
;
1343 isp1362_hcd
->fmindex
= isp1362_read_reg32(isp1362_hcd
, HCFMNUM
);
1344 DBG(1, "%s: Current frame %04x branch %02x start_frame %04x(%04x)\n",
1345 __func__
, isp1362_hcd
->fmindex
, ep
->branch
,
1346 ((isp1362_hcd
->fmindex
+ PERIODIC_SIZE
- 1) &
1347 ~(PERIODIC_SIZE
- 1)) + ep
->branch
,
1348 (isp1362_hcd
->fmindex
& (PERIODIC_SIZE
- 1)) + ep
->branch
);
1350 if (list_empty(&ep
->schedule
)) {
1351 if (type
== PIPE_ISOCHRONOUS
) {
1352 u16 frame
= isp1362_hcd
->fmindex
;
1354 frame
+= max_t(u16
, 8, ep
->interval
);
1355 frame
&= ~(ep
->interval
- 1);
1356 frame
|= ep
->branch
;
1357 if (frame_before(frame
, isp1362_hcd
->fmindex
))
1358 frame
+= ep
->interval
;
1359 urb
->start_frame
= frame
;
1361 DBG(1, "%s: Adding ep %p to isoc schedule\n", __func__
, ep
);
1362 list_add_tail(&ep
->schedule
, &isp1362_hcd
->isoc
);
1364 DBG(1, "%s: Adding ep %p to periodic schedule\n", __func__
, ep
);
1365 list_add_tail(&ep
->schedule
, &isp1362_hcd
->periodic
);
1368 DBG(1, "%s: ep %p already scheduled\n", __func__
, ep
);
1370 DBG(2, "%s: load %d bandwidth %d -> %d\n", __func__
,
1371 ep
->load
/ ep
->interval
, isp1362_hcd
->load
[ep
->branch
],
1372 isp1362_hcd
->load
[ep
->branch
] + ep
->load
);
1373 isp1362_hcd
->load
[ep
->branch
] += ep
->load
;
1377 ALIGNSTAT(isp1362_hcd
, urb
->transfer_buffer
);
1382 start_atl_transfers(isp1362_hcd
);
1384 case PIPE_INTERRUPT
:
1385 start_intl_transfers(isp1362_hcd
);
1387 case PIPE_ISOCHRONOUS
:
1388 start_iso_transfers(isp1362_hcd
);
1395 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
1399 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1401 DBG(0, "%s: urb %p failed with %d\n", __func__
, urb
, retval
);
1405 static int isp1362_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
, int status
)
1407 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
1408 struct usb_host_endpoint
*hep
;
1409 unsigned long flags
;
1410 struct isp1362_ep
*ep
;
1413 DBG(3, "%s: urb %p\n", __func__
, urb
);
1415 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1416 retval
= usb_hcd_check_unlink_urb(hcd
, urb
, status
);
1423 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1429 /* In front of queue? */
1430 if (ep
->hep
->urb_list
.next
== &urb
->urb_list
) {
1431 if (!list_empty(&ep
->active
)) {
1432 DBG(1, "%s: urb %p ep %p req %d active PTD[%d] $%04x\n", __func__
,
1433 urb
, ep
, ep
->num_req
, ep
->ptd_index
, ep
->ptd_offset
);
1434 /* disable processing and queue PTD for removal */
1435 remove_ptd(isp1362_hcd
, ep
);
1440 DBG(1, "%s: Finishing ep %p req %d\n", __func__
, ep
,
1442 finish_request(isp1362_hcd
, ep
, urb
, status
);
1444 DBG(1, "%s: urb %p active; wait4irq\n", __func__
, urb
);
1446 pr_warning("%s: No EP in URB %p\n", __func__
, urb
);
1450 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1452 DBG(3, "%s: exit\n", __func__
);
1457 static void isp1362_endpoint_disable(struct usb_hcd
*hcd
, struct usb_host_endpoint
*hep
)
1459 struct isp1362_ep
*ep
= hep
->hcpriv
;
1460 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
1461 unsigned long flags
;
1463 DBG(1, "%s: ep %p\n", __func__
, ep
);
1466 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1467 if (!list_empty(&hep
->urb_list
)) {
1468 if (!list_empty(&ep
->active
) && list_empty(&ep
->remove_list
)) {
1469 DBG(1, "%s: Removing ep %p req %d PTD[%d] $%04x\n", __func__
,
1470 ep
, ep
->num_req
, ep
->ptd_index
, ep
->ptd_offset
);
1471 remove_ptd(isp1362_hcd
, ep
);
1472 pr_info("%s: Waiting for Interrupt to clean up\n", __func__
);
1475 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1476 /* Wait for interrupt to clear out active list */
1477 while (!list_empty(&ep
->active
))
1480 DBG(1, "%s: Freeing EP %p\n", __func__
, ep
);
1482 usb_put_dev(ep
->udev
);
1487 static int isp1362_get_frame(struct usb_hcd
*hcd
)
1489 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
1491 unsigned long flags
;
1493 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1494 fmnum
= isp1362_read_reg32(isp1362_hcd
, HCFMNUM
);
1495 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1500 /*-------------------------------------------------------------------------*/
1502 /* Adapted from ohci-hub.c */
1503 static int isp1362_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
1505 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
1506 int ports
, i
, changed
= 0;
1507 unsigned long flags
;
1509 if (!HC_IS_RUNNING(hcd
->state
))
1512 /* Report no status change now, if we are scheduled to be
1514 if (timer_pending(&hcd
->rh_timer
))
1517 ports
= isp1362_hcd
->rhdesca
& RH_A_NDP
;
1520 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1522 if (isp1362_hcd
->rhstatus
& (RH_HS_LPSC
| RH_HS_OCIC
))
1523 buf
[0] = changed
= 1;
1527 for (i
= 0; i
< ports
; i
++) {
1528 u32 status
= isp1362_hcd
->rhport
[i
];
1530 if (status
& (RH_PS_CSC
| RH_PS_PESC
| RH_PS_PSSC
|
1531 RH_PS_OCIC
| RH_PS_PRSC
)) {
1533 buf
[0] |= 1 << (i
+ 1);
1537 if (!(status
& RH_PS_CCS
))
1540 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1544 static void isp1362_hub_descriptor(struct isp1362_hcd
*isp1362_hcd
,
1545 struct usb_hub_descriptor
*desc
)
1547 u32 reg
= isp1362_hcd
->rhdesca
;
1549 DBG(3, "%s: enter\n", __func__
);
1551 desc
->bDescriptorType
= 0x29;
1552 desc
->bDescLength
= 9;
1553 desc
->bHubContrCurrent
= 0;
1554 desc
->bNbrPorts
= reg
& 0x3;
1555 /* Power switching, device type, overcurrent. */
1556 desc
->wHubCharacteristics
= cpu_to_le16((reg
>> 8) & 0x1f);
1557 DBG(0, "%s: hubcharacteristics = %02x\n", __func__
, cpu_to_le16((reg
>> 8) & 0x1f));
1558 desc
->bPwrOn2PwrGood
= (reg
>> 24) & 0xff;
1559 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
1560 desc
->bitmap
[0] = desc
->bNbrPorts
== 1 ? 1 << 1 : 3 << 1;
1561 desc
->bitmap
[1] = ~0;
1563 DBG(3, "%s: exit\n", __func__
);
1566 /* Adapted from ohci-hub.c */
1567 static int isp1362_hub_control(struct usb_hcd
*hcd
, u16 typeReq
, u16 wValue
,
1568 u16 wIndex
, char *buf
, u16 wLength
)
1570 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
1572 unsigned long flags
;
1574 int ports
= isp1362_hcd
->rhdesca
& RH_A_NDP
;
1578 case ClearHubFeature
:
1579 DBG(0, "ClearHubFeature: ");
1581 case C_HUB_OVER_CURRENT
:
1582 _DBG(0, "C_HUB_OVER_CURRENT\n");
1583 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1584 isp1362_write_reg32(isp1362_hcd
, HCRHSTATUS
, RH_HS_OCIC
);
1585 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1586 case C_HUB_LOCAL_POWER
:
1587 _DBG(0, "C_HUB_LOCAL_POWER\n");
1594 DBG(0, "SetHubFeature: ");
1596 case C_HUB_OVER_CURRENT
:
1597 case C_HUB_LOCAL_POWER
:
1598 _DBG(0, "C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1604 case GetHubDescriptor
:
1605 DBG(0, "GetHubDescriptor\n");
1606 isp1362_hub_descriptor(isp1362_hcd
, (struct usb_hub_descriptor
*)buf
);
1609 DBG(0, "GetHubStatus\n");
1610 put_unaligned(cpu_to_le32(0), (__le32
*) buf
);
1614 DBG(0, "GetPortStatus\n");
1616 if (!wIndex
|| wIndex
> ports
)
1618 tmp
= isp1362_hcd
->rhport
[--wIndex
];
1619 put_unaligned(cpu_to_le32(tmp
), (__le32
*) buf
);
1621 case ClearPortFeature
:
1622 DBG(0, "ClearPortFeature: ");
1623 if (!wIndex
|| wIndex
> ports
)
1628 case USB_PORT_FEAT_ENABLE
:
1629 _DBG(0, "USB_PORT_FEAT_ENABLE\n");
1632 case USB_PORT_FEAT_C_ENABLE
:
1633 _DBG(0, "USB_PORT_FEAT_C_ENABLE\n");
1636 case USB_PORT_FEAT_SUSPEND
:
1637 _DBG(0, "USB_PORT_FEAT_SUSPEND\n");
1640 case USB_PORT_FEAT_C_SUSPEND
:
1641 _DBG(0, "USB_PORT_FEAT_C_SUSPEND\n");
1644 case USB_PORT_FEAT_POWER
:
1645 _DBG(0, "USB_PORT_FEAT_POWER\n");
1649 case USB_PORT_FEAT_C_CONNECTION
:
1650 _DBG(0, "USB_PORT_FEAT_C_CONNECTION\n");
1653 case USB_PORT_FEAT_C_OVER_CURRENT
:
1654 _DBG(0, "USB_PORT_FEAT_C_OVER_CURRENT\n");
1657 case USB_PORT_FEAT_C_RESET
:
1658 _DBG(0, "USB_PORT_FEAT_C_RESET\n");
1665 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1666 isp1362_write_reg32(isp1362_hcd
, HCRHPORT1
+ wIndex
, tmp
);
1667 isp1362_hcd
->rhport
[wIndex
] =
1668 isp1362_read_reg32(isp1362_hcd
, HCRHPORT1
+ wIndex
);
1669 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1671 case SetPortFeature
:
1672 DBG(0, "SetPortFeature: ");
1673 if (!wIndex
|| wIndex
> ports
)
1677 case USB_PORT_FEAT_SUSPEND
:
1678 _DBG(0, "USB_PORT_FEAT_SUSPEND\n");
1679 #ifdef CONFIG_USB_OTG
1680 if (ohci
->hcd
.self
.otg_port
== (wIndex
+ 1) &&
1681 ohci
->hcd
.self
.b_hnp_enable
) {
1686 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1687 isp1362_write_reg32(isp1362_hcd
, HCRHPORT1
+ wIndex
, RH_PS_PSS
);
1688 isp1362_hcd
->rhport
[wIndex
] =
1689 isp1362_read_reg32(isp1362_hcd
, HCRHPORT1
+ wIndex
);
1690 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1692 case USB_PORT_FEAT_POWER
:
1693 _DBG(0, "USB_PORT_FEAT_POWER\n");
1694 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1695 isp1362_write_reg32(isp1362_hcd
, HCRHPORT1
+ wIndex
, RH_PS_PPS
);
1696 isp1362_hcd
->rhport
[wIndex
] =
1697 isp1362_read_reg32(isp1362_hcd
, HCRHPORT1
+ wIndex
);
1698 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1700 case USB_PORT_FEAT_RESET
:
1701 _DBG(0, "USB_PORT_FEAT_RESET\n");
1702 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1704 t1
= jiffies
+ msecs_to_jiffies(USB_RESET_WIDTH
);
1705 while (time_before(jiffies
, t1
)) {
1706 /* spin until any current reset finishes */
1708 tmp
= isp1362_read_reg32(isp1362_hcd
, HCRHPORT1
+ wIndex
);
1709 if (!(tmp
& RH_PS_PRS
))
1713 if (!(tmp
& RH_PS_CCS
))
1715 /* Reset lasts 10ms (claims datasheet) */
1716 isp1362_write_reg32(isp1362_hcd
, HCRHPORT1
+ wIndex
, (RH_PS_PRS
));
1718 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1720 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1723 isp1362_hcd
->rhport
[wIndex
] = isp1362_read_reg32(isp1362_hcd
,
1724 HCRHPORT1
+ wIndex
);
1725 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1734 /* "protocol stall" on error */
1735 _DBG(0, "PROTOCOL STALL\n");
1743 static int isp1362_bus_suspend(struct usb_hcd
*hcd
)
1746 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
1747 unsigned long flags
;
1749 if (time_before(jiffies
, isp1362_hcd
->next_statechange
))
1752 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1754 isp1362_hcd
->hc_control
= isp1362_read_reg32(isp1362_hcd
, HCCONTROL
);
1755 switch (isp1362_hcd
->hc_control
& OHCI_CTRL_HCFS
) {
1756 case OHCI_USB_RESUME
:
1757 DBG(0, "%s: resume/suspend?\n", __func__
);
1758 isp1362_hcd
->hc_control
&= ~OHCI_CTRL_HCFS
;
1759 isp1362_hcd
->hc_control
|= OHCI_USB_RESET
;
1760 isp1362_write_reg32(isp1362_hcd
, HCCONTROL
, isp1362_hcd
->hc_control
);
1762 case OHCI_USB_RESET
:
1764 pr_warning("%s: needs reinit!\n", __func__
);
1766 case OHCI_USB_SUSPEND
:
1767 pr_warning("%s: already suspended?\n", __func__
);
1770 DBG(0, "%s: suspend root hub\n", __func__
);
1772 /* First stop any processing */
1773 hcd
->state
= HC_STATE_QUIESCING
;
1774 if (!list_empty(&isp1362_hcd
->atl_queue
.active
) ||
1775 !list_empty(&isp1362_hcd
->intl_queue
.active
) ||
1776 !list_empty(&isp1362_hcd
->istl_queue
[0] .active
) ||
1777 !list_empty(&isp1362_hcd
->istl_queue
[1] .active
)) {
1780 isp1362_write_reg32(isp1362_hcd
, HCATLSKIP
, ~0);
1781 isp1362_write_reg32(isp1362_hcd
, HCINTLSKIP
, ~0);
1782 isp1362_write_reg16(isp1362_hcd
, HCBUFSTAT
, 0);
1783 isp1362_write_reg16(isp1362_hcd
, HCuPINTENB
, 0);
1784 isp1362_write_reg32(isp1362_hcd
, HCINTSTAT
, OHCI_INTR_SF
);
1786 DBG(0, "%s: stopping schedules ...\n", __func__
);
1791 if (isp1362_read_reg32(isp1362_hcd
, HCINTSTAT
) & OHCI_INTR_SF
)
1795 if (isp1362_read_reg16(isp1362_hcd
, HCuPINT
) & HCuPINT_ATL
) {
1796 u32 done_map
= isp1362_read_reg32(isp1362_hcd
, HCATLDONE
);
1797 finish_transfers(isp1362_hcd
, done_map
, &isp1362_hcd
->atl_queue
);
1799 if (isp1362_read_reg16(isp1362_hcd
, HCuPINT
) & HCuPINT_INTL
) {
1800 u32 done_map
= isp1362_read_reg32(isp1362_hcd
, HCINTLDONE
);
1801 finish_transfers(isp1362_hcd
, done_map
, &isp1362_hcd
->intl_queue
);
1803 if (isp1362_read_reg16(isp1362_hcd
, HCuPINT
) & HCuPINT_ISTL0
)
1804 finish_iso_transfers(isp1362_hcd
, &isp1362_hcd
->istl_queue
[0]);
1805 if (isp1362_read_reg16(isp1362_hcd
, HCuPINT
) & HCuPINT_ISTL1
)
1806 finish_iso_transfers(isp1362_hcd
, &isp1362_hcd
->istl_queue
[1]);
1808 DBG(0, "%s: HCINTSTAT: %08x\n", __func__
,
1809 isp1362_read_reg32(isp1362_hcd
, HCINTSTAT
));
1810 isp1362_write_reg32(isp1362_hcd
, HCINTSTAT
,
1811 isp1362_read_reg32(isp1362_hcd
, HCINTSTAT
));
1814 isp1362_hcd
->hc_control
= OHCI_USB_SUSPEND
;
1815 isp1362_show_reg(isp1362_hcd
, HCCONTROL
);
1816 isp1362_write_reg32(isp1362_hcd
, HCCONTROL
, isp1362_hcd
->hc_control
);
1817 isp1362_show_reg(isp1362_hcd
, HCCONTROL
);
1820 isp1362_hcd
->hc_control
= isp1362_read_reg32(isp1362_hcd
, HCCONTROL
);
1821 if ((isp1362_hcd
->hc_control
& OHCI_CTRL_HCFS
) != OHCI_USB_SUSPEND
) {
1822 pr_err("%s: controller won't suspend %08x\n", __func__
,
1823 isp1362_hcd
->hc_control
);
1828 /* no resumes until devices finish suspending */
1829 isp1362_hcd
->next_statechange
= jiffies
+ msecs_to_jiffies(5);
1833 hcd
->state
= HC_STATE_SUSPENDED
;
1834 DBG(0, "%s: HCD suspended: %08x\n", __func__
,
1835 isp1362_read_reg32(isp1362_hcd
, HCCONTROL
));
1837 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1841 static int isp1362_bus_resume(struct usb_hcd
*hcd
)
1843 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
1845 unsigned long flags
;
1846 int status
= -EINPROGRESS
;
1848 if (time_before(jiffies
, isp1362_hcd
->next_statechange
))
1851 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1852 isp1362_hcd
->hc_control
= isp1362_read_reg32(isp1362_hcd
, HCCONTROL
);
1853 pr_info("%s: HCCONTROL: %08x\n", __func__
, isp1362_hcd
->hc_control
);
1854 if (hcd
->state
== HC_STATE_RESUMING
) {
1855 pr_warning("%s: duplicate resume\n", __func__
);
1858 switch (isp1362_hcd
->hc_control
& OHCI_CTRL_HCFS
) {
1859 case OHCI_USB_SUSPEND
:
1860 DBG(0, "%s: resume root hub\n", __func__
);
1861 isp1362_hcd
->hc_control
&= ~OHCI_CTRL_HCFS
;
1862 isp1362_hcd
->hc_control
|= OHCI_USB_RESUME
;
1863 isp1362_write_reg32(isp1362_hcd
, HCCONTROL
, isp1362_hcd
->hc_control
);
1865 case OHCI_USB_RESUME
:
1866 /* HCFS changes sometime after INTR_RD */
1867 DBG(0, "%s: remote wakeup\n", __func__
);
1870 DBG(0, "%s: odd resume\n", __func__
);
1872 hcd
->self
.root_hub
->dev
.power
.power_state
= PMSG_ON
;
1874 default: /* RESET, we lost power */
1875 DBG(0, "%s: root hub hardware reset\n", __func__
);
1878 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1879 if (status
== -EBUSY
) {
1880 DBG(0, "%s: Restarting HC\n", __func__
);
1881 isp1362_hc_stop(hcd
);
1882 return isp1362_hc_start(hcd
);
1884 if (status
!= -EINPROGRESS
)
1886 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1887 port
= isp1362_read_reg32(isp1362_hcd
, HCRHDESCA
) & RH_A_NDP
;
1889 u32 stat
= isp1362_read_reg32(isp1362_hcd
, HCRHPORT1
+ port
);
1891 /* force global, not selective, resume */
1892 if (!(stat
& RH_PS_PSS
)) {
1893 DBG(0, "%s: Not Resuming RH port %d\n", __func__
, port
);
1896 DBG(0, "%s: Resuming RH port %d\n", __func__
, port
);
1897 isp1362_write_reg32(isp1362_hcd
, HCRHPORT1
+ port
, RH_PS_POCI
);
1899 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1901 /* Some controllers (lucent) need extra-long delays */
1902 hcd
->state
= HC_STATE_RESUMING
;
1903 mdelay(20 /* usb 11.5.1.10 */ + 15);
1905 isp1362_hcd
->hc_control
= OHCI_USB_OPER
;
1906 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
1907 isp1362_show_reg(isp1362_hcd
, HCCONTROL
);
1908 isp1362_write_reg32(isp1362_hcd
, HCCONTROL
, isp1362_hcd
->hc_control
);
1909 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
1913 /* keep it alive for ~5x suspend + resume costs */
1914 isp1362_hcd
->next_statechange
= jiffies
+ msecs_to_jiffies(250);
1916 hcd
->self
.root_hub
->dev
.power
.power_state
= PMSG_ON
;
1917 hcd
->state
= HC_STATE_RUNNING
;
1921 #define isp1362_bus_suspend NULL
1922 #define isp1362_bus_resume NULL
1925 /*-------------------------------------------------------------------------*/
1927 #ifdef STUB_DEBUG_FILE
1929 static inline void create_debug_file(struct isp1362_hcd
*isp1362_hcd
)
1932 static inline void remove_debug_file(struct isp1362_hcd
*isp1362_hcd
)
1938 #include <linux/proc_fs.h>
1939 #include <linux/seq_file.h>
1941 static void dump_irq(struct seq_file
*s
, char *label
, u16 mask
)
1943 seq_printf(s
, "%-15s %04x%s%s%s%s%s%s\n", label
, mask
,
1944 mask
& HCuPINT_CLKRDY
? " clkrdy" : "",
1945 mask
& HCuPINT_SUSP
? " susp" : "",
1946 mask
& HCuPINT_OPR
? " opr" : "",
1947 mask
& HCuPINT_EOT
? " eot" : "",
1948 mask
& HCuPINT_ATL
? " atl" : "",
1949 mask
& HCuPINT_SOF
? " sof" : "");
1952 static void dump_int(struct seq_file
*s
, char *label
, u32 mask
)
1954 seq_printf(s
, "%-15s %08x%s%s%s%s%s%s%s\n", label
, mask
,
1955 mask
& OHCI_INTR_MIE
? " MIE" : "",
1956 mask
& OHCI_INTR_RHSC
? " rhsc" : "",
1957 mask
& OHCI_INTR_FNO
? " fno" : "",
1958 mask
& OHCI_INTR_UE
? " ue" : "",
1959 mask
& OHCI_INTR_RD
? " rd" : "",
1960 mask
& OHCI_INTR_SF
? " sof" : "",
1961 mask
& OHCI_INTR_SO
? " so" : "");
1964 static void dump_ctrl(struct seq_file
*s
, char *label
, u32 mask
)
1966 seq_printf(s
, "%-15s %08x%s%s%s\n", label
, mask
,
1967 mask
& OHCI_CTRL_RWC
? " rwc" : "",
1968 mask
& OHCI_CTRL_RWE
? " rwe" : "",
1971 switch (mask
& OHCI_CTRL_HCFS
) {
1975 case OHCI_USB_RESET
:
1978 case OHCI_USB_RESUME
:
1981 case OHCI_USB_SUSPEND
:
1991 static void dump_regs(struct seq_file
*s
, struct isp1362_hcd
*isp1362_hcd
)
1993 seq_printf(s
, "HCREVISION [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCREVISION
),
1994 isp1362_read_reg32(isp1362_hcd
, HCREVISION
));
1995 seq_printf(s
, "HCCONTROL [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCCONTROL
),
1996 isp1362_read_reg32(isp1362_hcd
, HCCONTROL
));
1997 seq_printf(s
, "HCCMDSTAT [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCCMDSTAT
),
1998 isp1362_read_reg32(isp1362_hcd
, HCCMDSTAT
));
1999 seq_printf(s
, "HCINTSTAT [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTSTAT
),
2000 isp1362_read_reg32(isp1362_hcd
, HCINTSTAT
));
2001 seq_printf(s
, "HCINTENB [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTENB
),
2002 isp1362_read_reg32(isp1362_hcd
, HCINTENB
));
2003 seq_printf(s
, "HCFMINTVL [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMINTVL
),
2004 isp1362_read_reg32(isp1362_hcd
, HCFMINTVL
));
2005 seq_printf(s
, "HCFMREM [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMREM
),
2006 isp1362_read_reg32(isp1362_hcd
, HCFMREM
));
2007 seq_printf(s
, "HCFMNUM [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMNUM
),
2008 isp1362_read_reg32(isp1362_hcd
, HCFMNUM
));
2009 seq_printf(s
, "HCLSTHRESH [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCLSTHRESH
),
2010 isp1362_read_reg32(isp1362_hcd
, HCLSTHRESH
));
2011 seq_printf(s
, "HCRHDESCA [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHDESCA
),
2012 isp1362_read_reg32(isp1362_hcd
, HCRHDESCA
));
2013 seq_printf(s
, "HCRHDESCB [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHDESCB
),
2014 isp1362_read_reg32(isp1362_hcd
, HCRHDESCB
));
2015 seq_printf(s
, "HCRHSTATUS [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHSTATUS
),
2016 isp1362_read_reg32(isp1362_hcd
, HCRHSTATUS
));
2017 seq_printf(s
, "HCRHPORT1 [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHPORT1
),
2018 isp1362_read_reg32(isp1362_hcd
, HCRHPORT1
));
2019 seq_printf(s
, "HCRHPORT2 [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHPORT2
),
2020 isp1362_read_reg32(isp1362_hcd
, HCRHPORT2
));
2021 seq_printf(s
, "\n");
2022 seq_printf(s
, "HCHWCFG [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCHWCFG
),
2023 isp1362_read_reg16(isp1362_hcd
, HCHWCFG
));
2024 seq_printf(s
, "HCDMACFG [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCDMACFG
),
2025 isp1362_read_reg16(isp1362_hcd
, HCDMACFG
));
2026 seq_printf(s
, "HCXFERCTR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCXFERCTR
),
2027 isp1362_read_reg16(isp1362_hcd
, HCXFERCTR
));
2028 seq_printf(s
, "HCuPINT [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCuPINT
),
2029 isp1362_read_reg16(isp1362_hcd
, HCuPINT
));
2030 seq_printf(s
, "HCuPINTENB [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCuPINTENB
),
2031 isp1362_read_reg16(isp1362_hcd
, HCuPINTENB
));
2032 seq_printf(s
, "HCCHIPID [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCCHIPID
),
2033 isp1362_read_reg16(isp1362_hcd
, HCCHIPID
));
2034 seq_printf(s
, "HCSCRATCH [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCSCRATCH
),
2035 isp1362_read_reg16(isp1362_hcd
, HCSCRATCH
));
2036 seq_printf(s
, "HCBUFSTAT [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCBUFSTAT
),
2037 isp1362_read_reg16(isp1362_hcd
, HCBUFSTAT
));
2038 seq_printf(s
, "HCDIRADDR [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCDIRADDR
),
2039 isp1362_read_reg32(isp1362_hcd
, HCDIRADDR
));
2041 seq_printf(s
, "HCDIRDATA [%02x] %04x\n", ISP1362_REG_NO(HCDIRDATA
),
2042 isp1362_read_reg16(isp1362_hcd
, HCDIRDATA
));
2044 seq_printf(s
, "HCISTLBUFSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCISTLBUFSZ
),
2045 isp1362_read_reg16(isp1362_hcd
, HCISTLBUFSZ
));
2046 seq_printf(s
, "HCISTLRATE [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCISTLRATE
),
2047 isp1362_read_reg16(isp1362_hcd
, HCISTLRATE
));
2048 seq_printf(s
, "\n");
2049 seq_printf(s
, "HCINTLBUFSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLBUFSZ
),
2050 isp1362_read_reg16(isp1362_hcd
, HCINTLBUFSZ
));
2051 seq_printf(s
, "HCINTLBLKSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLBLKSZ
),
2052 isp1362_read_reg16(isp1362_hcd
, HCINTLBLKSZ
));
2053 seq_printf(s
, "HCINTLDONE [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLDONE
),
2054 isp1362_read_reg32(isp1362_hcd
, HCINTLDONE
));
2055 seq_printf(s
, "HCINTLSKIP [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLSKIP
),
2056 isp1362_read_reg32(isp1362_hcd
, HCINTLSKIP
));
2057 seq_printf(s
, "HCINTLLAST [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLLAST
),
2058 isp1362_read_reg32(isp1362_hcd
, HCINTLLAST
));
2059 seq_printf(s
, "HCINTLCURR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLCURR
),
2060 isp1362_read_reg16(isp1362_hcd
, HCINTLCURR
));
2061 seq_printf(s
, "\n");
2062 seq_printf(s
, "HCATLBUFSZ [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLBUFSZ
),
2063 isp1362_read_reg16(isp1362_hcd
, HCATLBUFSZ
));
2064 seq_printf(s
, "HCATLBLKSZ [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLBLKSZ
),
2065 isp1362_read_reg16(isp1362_hcd
, HCATLBLKSZ
));
2067 seq_printf(s
, "HCATLDONE [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDONE
),
2068 isp1362_read_reg32(isp1362_hcd
, HCATLDONE
));
2070 seq_printf(s
, "HCATLSKIP [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLSKIP
),
2071 isp1362_read_reg32(isp1362_hcd
, HCATLSKIP
));
2072 seq_printf(s
, "HCATLLAST [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLLAST
),
2073 isp1362_read_reg32(isp1362_hcd
, HCATLLAST
));
2074 seq_printf(s
, "HCATLCURR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLCURR
),
2075 isp1362_read_reg16(isp1362_hcd
, HCATLCURR
));
2076 seq_printf(s
, "\n");
2077 seq_printf(s
, "HCATLDTC [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDTC
),
2078 isp1362_read_reg16(isp1362_hcd
, HCATLDTC
));
2079 seq_printf(s
, "HCATLDTCTO [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDTCTO
),
2080 isp1362_read_reg16(isp1362_hcd
, HCATLDTCTO
));
2083 static int proc_isp1362_show(struct seq_file
*s
, void *unused
)
2085 struct isp1362_hcd
*isp1362_hcd
= s
->private;
2086 struct isp1362_ep
*ep
;
2089 seq_printf(s
, "%s\n%s version %s\n",
2090 isp1362_hcd_to_hcd(isp1362_hcd
)->product_desc
, hcd_name
, DRIVER_VERSION
);
2092 /* collect statistics to help estimate potential win for
2093 * DMA engines that care about alignment (PXA)
2095 seq_printf(s
, "alignment: 16b/%ld 8b/%ld 4b/%ld 2b/%ld 1b/%ld\n",
2096 isp1362_hcd
->stat16
, isp1362_hcd
->stat8
, isp1362_hcd
->stat4
,
2097 isp1362_hcd
->stat2
, isp1362_hcd
->stat1
);
2098 seq_printf(s
, "max # ptds in ATL fifo: %d\n", isp1362_hcd
->atl_queue
.stat_maxptds
);
2099 seq_printf(s
, "max # ptds in INTL fifo: %d\n", isp1362_hcd
->intl_queue
.stat_maxptds
);
2100 seq_printf(s
, "max # ptds in ISTL fifo: %d\n",
2101 max(isp1362_hcd
->istl_queue
[0] .stat_maxptds
,
2102 isp1362_hcd
->istl_queue
[1] .stat_maxptds
));
2104 /* FIXME: don't show the following in suspended state */
2105 spin_lock_irq(&isp1362_hcd
->lock
);
2107 dump_irq(s
, "hc_irq_enable", isp1362_read_reg16(isp1362_hcd
, HCuPINTENB
));
2108 dump_irq(s
, "hc_irq_status", isp1362_read_reg16(isp1362_hcd
, HCuPINT
));
2109 dump_int(s
, "ohci_int_enable", isp1362_read_reg32(isp1362_hcd
, HCINTENB
));
2110 dump_int(s
, "ohci_int_status", isp1362_read_reg32(isp1362_hcd
, HCINTSTAT
));
2111 dump_ctrl(s
, "ohci_control", isp1362_read_reg32(isp1362_hcd
, HCCONTROL
));
2113 for (i
= 0; i
< NUM_ISP1362_IRQS
; i
++)
2114 if (isp1362_hcd
->irq_stat
[i
])
2115 seq_printf(s
, "%-15s: %d\n",
2116 ISP1362_INT_NAME(i
), isp1362_hcd
->irq_stat
[i
]);
2118 dump_regs(s
, isp1362_hcd
);
2119 list_for_each_entry(ep
, &isp1362_hcd
->async
, schedule
) {
2122 seq_printf(s
, "%p, ep%d%s, maxpacket %d:\n", ep
, ep
->epnum
,
2125 switch (ep
->nextpid
) {
2142 s
;}), ep
->maxpacket
) ;
2143 list_for_each_entry(urb
, &ep
->hep
->urb_list
, urb_list
) {
2144 seq_printf(s
, " urb%p, %d/%d\n", urb
,
2146 urb
->transfer_buffer_length
);
2149 if (!list_empty(&isp1362_hcd
->async
))
2150 seq_printf(s
, "\n");
2151 dump_ptd_queue(&isp1362_hcd
->atl_queue
);
2153 seq_printf(s
, "periodic size= %d\n", PERIODIC_SIZE
);
2155 list_for_each_entry(ep
, &isp1362_hcd
->periodic
, schedule
) {
2156 seq_printf(s
, "branch:%2d load:%3d PTD[%d] $%04x:\n", ep
->branch
,
2157 isp1362_hcd
->load
[ep
->branch
], ep
->ptd_index
, ep
->ptd_offset
);
2159 seq_printf(s
, " %d/%p (%sdev%d ep%d%s max %d)\n",
2161 (ep
->udev
->speed
== USB_SPEED_FULL
) ? "" : "ls ",
2162 ep
->udev
->devnum
, ep
->epnum
,
2163 (ep
->epnum
== 0) ? "" :
2164 ((ep
->nextpid
== USB_PID_IN
) ?
2165 "in" : "out"), ep
->maxpacket
);
2167 dump_ptd_queue(&isp1362_hcd
->intl_queue
);
2169 seq_printf(s
, "ISO:\n");
2171 list_for_each_entry(ep
, &isp1362_hcd
->isoc
, schedule
) {
2172 seq_printf(s
, " %d/%p (%sdev%d ep%d%s max %d)\n",
2174 (ep
->udev
->speed
== USB_SPEED_FULL
) ? "" : "ls ",
2175 ep
->udev
->devnum
, ep
->epnum
,
2176 (ep
->epnum
== 0) ? "" :
2177 ((ep
->nextpid
== USB_PID_IN
) ?
2178 "in" : "out"), ep
->maxpacket
);
2181 spin_unlock_irq(&isp1362_hcd
->lock
);
2182 seq_printf(s
, "\n");
2187 static int proc_isp1362_open(struct inode
*inode
, struct file
*file
)
2189 return single_open(file
, proc_isp1362_show
, PDE(inode
)->data
);
2192 static const struct file_operations proc_ops
= {
2193 .open
= proc_isp1362_open
,
2195 .llseek
= seq_lseek
,
2196 .release
= single_release
,
2199 /* expect just one isp1362_hcd per system */
2200 static const char proc_filename
[] = "driver/isp1362";
2202 static void create_debug_file(struct isp1362_hcd
*isp1362_hcd
)
2204 struct proc_dir_entry
*pde
;
2206 pde
= create_proc_entry(proc_filename
, 0, NULL
);
2208 pr_warning("%s: Failed to create debug file '%s'\n", __func__
, proc_filename
);
2212 pde
->proc_fops
= &proc_ops
;
2213 pde
->data
= isp1362_hcd
;
2214 isp1362_hcd
->pde
= pde
;
2217 static void remove_debug_file(struct isp1362_hcd
*isp1362_hcd
)
2219 if (isp1362_hcd
->pde
)
2220 remove_proc_entry(proc_filename
, 0);
2225 /*-------------------------------------------------------------------------*/
2227 static void isp1362_sw_reset(struct isp1362_hcd
*isp1362_hcd
)
2230 unsigned long flags
;
2232 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2234 isp1362_write_reg16(isp1362_hcd
, HCSWRES
, HCSWRES_MAGIC
);
2235 isp1362_write_reg32(isp1362_hcd
, HCCMDSTAT
, OHCI_HCR
);
2238 if (!(isp1362_read_reg32(isp1362_hcd
, HCCMDSTAT
) & OHCI_HCR
))
2242 pr_err("Software reset timeout\n");
2243 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2246 static int isp1362_mem_config(struct usb_hcd
*hcd
)
2248 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
2249 unsigned long flags
;
2251 u16 istl_size
= ISP1362_ISTL_BUFSIZE
;
2252 u16 intl_blksize
= ISP1362_INTL_BLKSIZE
+ PTD_HEADER_SIZE
;
2253 u16 intl_size
= ISP1362_INTL_BUFFERS
* intl_blksize
;
2254 u16 atl_blksize
= ISP1362_ATL_BLKSIZE
+ PTD_HEADER_SIZE
;
2255 u16 atl_buffers
= (ISP1362_BUF_SIZE
- (istl_size
+ intl_size
)) / atl_blksize
;
2259 WARN_ON(istl_size
& 3);
2260 WARN_ON(atl_blksize
& 3);
2261 WARN_ON(intl_blksize
& 3);
2262 WARN_ON(atl_blksize
< PTD_HEADER_SIZE
);
2263 WARN_ON(intl_blksize
< PTD_HEADER_SIZE
);
2265 BUG_ON((unsigned)ISP1362_INTL_BUFFERS
> 32);
2266 if (atl_buffers
> 32)
2268 atl_size
= atl_buffers
* atl_blksize
;
2269 total
= atl_size
+ intl_size
+ istl_size
;
2270 dev_info(hcd
->self
.controller
, "ISP1362 Memory usage:\n");
2271 dev_info(hcd
->self
.controller
, " ISTL: 2 * %4d: %4d @ $%04x:$%04x\n",
2272 istl_size
/ 2, istl_size
, 0, istl_size
/ 2);
2273 dev_info(hcd
->self
.controller
, " INTL: %4d * (%3lu+8): %4d @ $%04x\n",
2274 ISP1362_INTL_BUFFERS
, intl_blksize
- PTD_HEADER_SIZE
,
2275 intl_size
, istl_size
);
2276 dev_info(hcd
->self
.controller
, " ATL : %4d * (%3lu+8): %4d @ $%04x\n",
2277 atl_buffers
, atl_blksize
- PTD_HEADER_SIZE
,
2278 atl_size
, istl_size
+ intl_size
);
2279 dev_info(hcd
->self
.controller
, " USED/FREE: %4d %4d\n", total
,
2280 ISP1362_BUF_SIZE
- total
);
2282 if (total
> ISP1362_BUF_SIZE
) {
2283 dev_err(hcd
->self
.controller
, "%s: Memory requested: %d, available %d\n",
2284 __func__
, total
, ISP1362_BUF_SIZE
);
2288 total
= istl_size
+ intl_size
+ atl_size
;
2289 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2291 for (i
= 0; i
< 2; i
++) {
2292 isp1362_hcd
->istl_queue
[i
].buf_start
= i
* istl_size
/ 2,
2293 isp1362_hcd
->istl_queue
[i
].buf_size
= istl_size
/ 2;
2294 isp1362_hcd
->istl_queue
[i
].blk_size
= 4;
2295 INIT_LIST_HEAD(&isp1362_hcd
->istl_queue
[i
].active
);
2296 snprintf(isp1362_hcd
->istl_queue
[i
].name
,
2297 sizeof(isp1362_hcd
->istl_queue
[i
].name
), "ISTL%d", i
);
2298 DBG(3, "%s: %5s buf $%04x %d\n", __func__
,
2299 isp1362_hcd
->istl_queue
[i
].name
,
2300 isp1362_hcd
->istl_queue
[i
].buf_start
,
2301 isp1362_hcd
->istl_queue
[i
].buf_size
);
2303 isp1362_write_reg16(isp1362_hcd
, HCISTLBUFSZ
, istl_size
/ 2);
2305 isp1362_hcd
->intl_queue
.buf_start
= istl_size
;
2306 isp1362_hcd
->intl_queue
.buf_size
= intl_size
;
2307 isp1362_hcd
->intl_queue
.buf_count
= ISP1362_INTL_BUFFERS
;
2308 isp1362_hcd
->intl_queue
.blk_size
= intl_blksize
;
2309 isp1362_hcd
->intl_queue
.buf_avail
= isp1362_hcd
->intl_queue
.buf_count
;
2310 isp1362_hcd
->intl_queue
.skip_map
= ~0;
2311 INIT_LIST_HEAD(&isp1362_hcd
->intl_queue
.active
);
2313 isp1362_write_reg16(isp1362_hcd
, HCINTLBUFSZ
,
2314 isp1362_hcd
->intl_queue
.buf_size
);
2315 isp1362_write_reg16(isp1362_hcd
, HCINTLBLKSZ
,
2316 isp1362_hcd
->intl_queue
.blk_size
- PTD_HEADER_SIZE
);
2317 isp1362_write_reg32(isp1362_hcd
, HCINTLSKIP
, ~0);
2318 isp1362_write_reg32(isp1362_hcd
, HCINTLLAST
,
2319 1 << (ISP1362_INTL_BUFFERS
- 1));
2321 isp1362_hcd
->atl_queue
.buf_start
= istl_size
+ intl_size
;
2322 isp1362_hcd
->atl_queue
.buf_size
= atl_size
;
2323 isp1362_hcd
->atl_queue
.buf_count
= atl_buffers
;
2324 isp1362_hcd
->atl_queue
.blk_size
= atl_blksize
;
2325 isp1362_hcd
->atl_queue
.buf_avail
= isp1362_hcd
->atl_queue
.buf_count
;
2326 isp1362_hcd
->atl_queue
.skip_map
= ~0;
2327 INIT_LIST_HEAD(&isp1362_hcd
->atl_queue
.active
);
2329 isp1362_write_reg16(isp1362_hcd
, HCATLBUFSZ
,
2330 isp1362_hcd
->atl_queue
.buf_size
);
2331 isp1362_write_reg16(isp1362_hcd
, HCATLBLKSZ
,
2332 isp1362_hcd
->atl_queue
.blk_size
- PTD_HEADER_SIZE
);
2333 isp1362_write_reg32(isp1362_hcd
, HCATLSKIP
, ~0);
2334 isp1362_write_reg32(isp1362_hcd
, HCATLLAST
,
2335 1 << (atl_buffers
- 1));
2337 snprintf(isp1362_hcd
->atl_queue
.name
,
2338 sizeof(isp1362_hcd
->atl_queue
.name
), "ATL");
2339 snprintf(isp1362_hcd
->intl_queue
.name
,
2340 sizeof(isp1362_hcd
->intl_queue
.name
), "INTL");
2341 DBG(3, "%s: %5s buf $%04x %2d * %4d = %4d\n", __func__
,
2342 isp1362_hcd
->intl_queue
.name
,
2343 isp1362_hcd
->intl_queue
.buf_start
,
2344 ISP1362_INTL_BUFFERS
, isp1362_hcd
->intl_queue
.blk_size
,
2345 isp1362_hcd
->intl_queue
.buf_size
);
2346 DBG(3, "%s: %5s buf $%04x %2d * %4d = %4d\n", __func__
,
2347 isp1362_hcd
->atl_queue
.name
,
2348 isp1362_hcd
->atl_queue
.buf_start
,
2349 atl_buffers
, isp1362_hcd
->atl_queue
.blk_size
,
2350 isp1362_hcd
->atl_queue
.buf_size
);
2352 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2357 static int isp1362_hc_reset(struct usb_hcd
*hcd
)
2360 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
2362 unsigned long timeout
= 100;
2363 unsigned long flags
;
2366 pr_info("%s:\n", __func__
);
2368 if (isp1362_hcd
->board
&& isp1362_hcd
->board
->reset
) {
2369 isp1362_hcd
->board
->reset(hcd
->self
.controller
, 1);
2371 if (isp1362_hcd
->board
->clock
)
2372 isp1362_hcd
->board
->clock(hcd
->self
.controller
, 1);
2373 isp1362_hcd
->board
->reset(hcd
->self
.controller
, 0);
2375 isp1362_sw_reset(isp1362_hcd
);
2377 /* chip has been reset. First we need to see a clock */
2378 t
= jiffies
+ msecs_to_jiffies(timeout
);
2379 while (!clkrdy
&& time_before_eq(jiffies
, t
)) {
2380 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2381 clkrdy
= isp1362_read_reg16(isp1362_hcd
, HCuPINT
) & HCuPINT_CLKRDY
;
2382 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2387 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2388 isp1362_write_reg16(isp1362_hcd
, HCuPINT
, HCuPINT_CLKRDY
);
2389 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2391 pr_err("Clock not ready after %lums\n", timeout
);
2397 static void isp1362_hc_stop(struct usb_hcd
*hcd
)
2399 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
2400 unsigned long flags
;
2403 pr_info("%s:\n", __func__
);
2405 del_timer_sync(&hcd
->rh_timer
);
2407 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2409 isp1362_write_reg16(isp1362_hcd
, HCuPINTENB
, 0);
2411 /* Switch off power for all ports */
2412 tmp
= isp1362_read_reg32(isp1362_hcd
, HCRHDESCA
);
2413 tmp
&= ~(RH_A_NPS
| RH_A_PSM
);
2414 isp1362_write_reg32(isp1362_hcd
, HCRHDESCA
, tmp
);
2415 isp1362_write_reg32(isp1362_hcd
, HCRHSTATUS
, RH_HS_LPS
);
2417 /* Reset the chip */
2418 if (isp1362_hcd
->board
&& isp1362_hcd
->board
->reset
)
2419 isp1362_hcd
->board
->reset(hcd
->self
.controller
, 1);
2421 isp1362_sw_reset(isp1362_hcd
);
2423 if (isp1362_hcd
->board
&& isp1362_hcd
->board
->clock
)
2424 isp1362_hcd
->board
->clock(hcd
->self
.controller
, 0);
2426 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2429 #ifdef CHIP_BUFFER_TEST
2430 static int isp1362_chip_test(struct isp1362_hcd
*isp1362_hcd
)
2434 unsigned long flags
;
2436 ref
= kmalloc(2 * ISP1362_BUF_SIZE
, GFP_KERNEL
);
2439 u16
*tst
= &ref
[ISP1362_BUF_SIZE
/ 2];
2441 for (offset
= 0; offset
< ISP1362_BUF_SIZE
/ 2; offset
++) {
2442 ref
[offset
] = ~offset
;
2443 tst
[offset
] = offset
;
2446 for (offset
= 0; offset
< 4; offset
++) {
2449 for (j
= 0; j
< 8; j
++) {
2450 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2451 isp1362_write_buffer(isp1362_hcd
, (u8
*)ref
+ offset
, 0, j
);
2452 isp1362_read_buffer(isp1362_hcd
, (u8
*)tst
+ offset
, 0, j
);
2453 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2455 if (memcmp(ref
, tst
, j
)) {
2457 pr_err("%s: memory check with %d byte offset %d failed\n",
2458 __func__
, j
, offset
);
2459 dump_data((u8
*)ref
+ offset
, j
);
2460 dump_data((u8
*)tst
+ offset
, j
);
2465 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2466 isp1362_write_buffer(isp1362_hcd
, ref
, 0, ISP1362_BUF_SIZE
);
2467 isp1362_read_buffer(isp1362_hcd
, tst
, 0, ISP1362_BUF_SIZE
);
2468 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2470 if (memcmp(ref
, tst
, ISP1362_BUF_SIZE
)) {
2472 pr_err("%s: memory check failed\n", __func__
);
2473 dump_data((u8
*)tst
, ISP1362_BUF_SIZE
/ 2);
2476 for (offset
= 0; offset
< 256; offset
++) {
2481 memset(tst
, 0, ISP1362_BUF_SIZE
);
2482 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2483 isp1362_write_buffer(isp1362_hcd
, tst
, 0, ISP1362_BUF_SIZE
);
2484 isp1362_read_buffer(isp1362_hcd
, tst
, 0, ISP1362_BUF_SIZE
);
2485 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2486 if (memcmp(tst
, tst
+ (ISP1362_BUF_SIZE
/ (2 * sizeof(*tst
))),
2487 ISP1362_BUF_SIZE
/ 2)) {
2488 pr_err("%s: Failed to clear buffer\n", __func__
);
2489 dump_data((u8
*)tst
, ISP1362_BUF_SIZE
);
2492 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2493 isp1362_write_buffer(isp1362_hcd
, ref
, offset
* 2, PTD_HEADER_SIZE
);
2494 isp1362_write_buffer(isp1362_hcd
, ref
+ PTD_HEADER_SIZE
/ sizeof(*ref
),
2495 offset
* 2 + PTD_HEADER_SIZE
, test_size
);
2496 isp1362_read_buffer(isp1362_hcd
, tst
, offset
* 2,
2497 PTD_HEADER_SIZE
+ test_size
);
2498 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2499 if (memcmp(ref
, tst
, PTD_HEADER_SIZE
+ test_size
)) {
2500 dump_data(((u8
*)ref
) + offset
, PTD_HEADER_SIZE
+ test_size
);
2501 dump_data((u8
*)tst
, PTD_HEADER_SIZE
+ test_size
);
2502 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2503 isp1362_read_buffer(isp1362_hcd
, tst
, offset
* 2,
2504 PTD_HEADER_SIZE
+ test_size
);
2505 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2506 if (memcmp(ref
, tst
, PTD_HEADER_SIZE
+ test_size
)) {
2508 pr_err("%s: memory check with offset %02x failed\n",
2512 pr_warning("%s: memory check with offset %02x ok after second read\n",
2522 static int isp1362_hc_start(struct usb_hcd
*hcd
)
2525 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
2526 struct isp1362_platform_data
*board
= isp1362_hcd
->board
;
2529 unsigned long flags
;
2531 pr_info("%s:\n", __func__
);
2533 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2534 chipid
= isp1362_read_reg16(isp1362_hcd
, HCCHIPID
);
2535 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2537 if ((chipid
& HCCHIPID_MASK
) != HCCHIPID_MAGIC
) {
2538 pr_err("%s: Invalid chip ID %04x\n", __func__
, chipid
);
2542 #ifdef CHIP_BUFFER_TEST
2543 ret
= isp1362_chip_test(isp1362_hcd
);
2547 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2548 /* clear interrupt status and disable all interrupt sources */
2549 isp1362_write_reg16(isp1362_hcd
, HCuPINT
, 0xff);
2550 isp1362_write_reg16(isp1362_hcd
, HCuPINTENB
, 0);
2553 hwcfg
= HCHWCFG_INT_ENABLE
| HCHWCFG_DBWIDTH(1);
2554 if (board
->sel15Kres
)
2555 hwcfg
|= HCHWCFG_PULLDOWN_DS2
|
2556 ((MAX_ROOT_PORTS
> 1) ? HCHWCFG_PULLDOWN_DS1
: 0);
2557 if (board
->clknotstop
)
2558 hwcfg
|= HCHWCFG_CLKNOTSTOP
;
2559 if (board
->oc_enable
)
2560 hwcfg
|= HCHWCFG_ANALOG_OC
;
2561 if (board
->int_act_high
)
2562 hwcfg
|= HCHWCFG_INT_POL
;
2563 if (board
->int_edge_triggered
)
2564 hwcfg
|= HCHWCFG_INT_TRIGGER
;
2565 if (board
->dreq_act_high
)
2566 hwcfg
|= HCHWCFG_DREQ_POL
;
2567 if (board
->dack_act_high
)
2568 hwcfg
|= HCHWCFG_DACK_POL
;
2569 isp1362_write_reg16(isp1362_hcd
, HCHWCFG
, hwcfg
);
2570 isp1362_show_reg(isp1362_hcd
, HCHWCFG
);
2571 isp1362_write_reg16(isp1362_hcd
, HCDMACFG
, 0);
2572 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2574 ret
= isp1362_mem_config(hcd
);
2578 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2581 isp1362_hcd
->rhdesca
= 0;
2582 if (board
->no_power_switching
)
2583 isp1362_hcd
->rhdesca
|= RH_A_NPS
;
2584 if (board
->power_switching_mode
)
2585 isp1362_hcd
->rhdesca
|= RH_A_PSM
;
2587 isp1362_hcd
->rhdesca
|= (board
->potpg
<< 24) & RH_A_POTPGT
;
2589 isp1362_hcd
->rhdesca
|= (25 << 24) & RH_A_POTPGT
;
2591 isp1362_write_reg32(isp1362_hcd
, HCRHDESCA
, isp1362_hcd
->rhdesca
& ~RH_A_OCPM
);
2592 isp1362_write_reg32(isp1362_hcd
, HCRHDESCA
, isp1362_hcd
->rhdesca
| RH_A_OCPM
);
2593 isp1362_hcd
->rhdesca
= isp1362_read_reg32(isp1362_hcd
, HCRHDESCA
);
2595 isp1362_hcd
->rhdescb
= RH_B_PPCM
;
2596 isp1362_write_reg32(isp1362_hcd
, HCRHDESCB
, isp1362_hcd
->rhdescb
);
2597 isp1362_hcd
->rhdescb
= isp1362_read_reg32(isp1362_hcd
, HCRHDESCB
);
2599 isp1362_read_reg32(isp1362_hcd
, HCFMINTVL
);
2600 isp1362_write_reg32(isp1362_hcd
, HCFMINTVL
, (FSMP(FI
) << 16) | FI
);
2601 isp1362_write_reg32(isp1362_hcd
, HCLSTHRESH
, LSTHRESH
);
2603 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2605 isp1362_hcd
->hc_control
= OHCI_USB_OPER
;
2606 hcd
->state
= HC_STATE_RUNNING
;
2608 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2609 /* Set up interrupts */
2610 isp1362_hcd
->intenb
= OHCI_INTR_MIE
| OHCI_INTR_RHSC
| OHCI_INTR_UE
;
2611 isp1362_hcd
->intenb
|= OHCI_INTR_RD
;
2612 isp1362_hcd
->irqenb
= HCuPINT_OPR
| HCuPINT_SUSP
;
2613 isp1362_write_reg32(isp1362_hcd
, HCINTENB
, isp1362_hcd
->intenb
);
2614 isp1362_write_reg16(isp1362_hcd
, HCuPINTENB
, isp1362_hcd
->irqenb
);
2616 /* Go operational */
2617 isp1362_write_reg32(isp1362_hcd
, HCCONTROL
, isp1362_hcd
->hc_control
);
2618 /* enable global power */
2619 isp1362_write_reg32(isp1362_hcd
, HCRHSTATUS
, RH_HS_LPSC
| RH_HS_DRWE
);
2621 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2626 /*-------------------------------------------------------------------------*/
2628 static struct hc_driver isp1362_hc_driver
= {
2629 .description
= hcd_name
,
2630 .product_desc
= "ISP1362 Host Controller",
2631 .hcd_priv_size
= sizeof(struct isp1362_hcd
),
2634 .flags
= HCD_USB11
| HCD_MEMORY
,
2636 .reset
= isp1362_hc_reset
,
2637 .start
= isp1362_hc_start
,
2638 .stop
= isp1362_hc_stop
,
2640 .urb_enqueue
= isp1362_urb_enqueue
,
2641 .urb_dequeue
= isp1362_urb_dequeue
,
2642 .endpoint_disable
= isp1362_endpoint_disable
,
2644 .get_frame_number
= isp1362_get_frame
,
2646 .hub_status_data
= isp1362_hub_status_data
,
2647 .hub_control
= isp1362_hub_control
,
2648 .bus_suspend
= isp1362_bus_suspend
,
2649 .bus_resume
= isp1362_bus_resume
,
2652 /*-------------------------------------------------------------------------*/
2654 #define resource_len(r) (((r)->end - (r)->start) + 1)
2656 static int __devexit
isp1362_remove(struct platform_device
*pdev
)
2658 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
2659 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
2660 struct resource
*res
;
2662 remove_debug_file(isp1362_hcd
);
2663 DBG(0, "%s: Removing HCD\n", __func__
);
2664 usb_remove_hcd(hcd
);
2666 DBG(0, "%s: Unmapping data_reg @ %p\n", __func__
,
2667 isp1362_hcd
->data_reg
);
2668 iounmap(isp1362_hcd
->data_reg
);
2670 DBG(0, "%s: Unmapping addr_reg @ %p\n", __func__
,
2671 isp1362_hcd
->addr_reg
);
2672 iounmap(isp1362_hcd
->addr_reg
);
2674 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
2675 DBG(0, "%s: release mem_region: %08lx\n", __func__
, (long unsigned int)res
->start
);
2677 release_mem_region(res
->start
, resource_len(res
));
2679 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2680 DBG(0, "%s: release mem_region: %08lx\n", __func__
, (long unsigned int)res
->start
);
2682 release_mem_region(res
->start
, resource_len(res
));
2684 DBG(0, "%s: put_hcd\n", __func__
);
2686 DBG(0, "%s: Done\n", __func__
);
2691 static int __init
isp1362_probe(struct platform_device
*pdev
)
2693 struct usb_hcd
*hcd
;
2694 struct isp1362_hcd
*isp1362_hcd
;
2695 struct resource
*addr
, *data
;
2696 void __iomem
*addr_reg
;
2697 void __iomem
*data_reg
;
2701 /* basic sanity checks first. board-specific init logic should
2702 * have initialized this the three resources and probably board
2703 * specific platform_data. we don't probe for IRQs, and do only
2704 * minimal sanity checking.
2706 if (pdev
->num_resources
< 3) {
2711 data
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
2712 addr
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
2713 irq
= platform_get_irq(pdev
, 0);
2714 if (!addr
|| !data
|| irq
< 0) {
2719 #ifdef CONFIG_USB_HCD_DMA
2720 if (pdev
->dev
.dma_mask
) {
2721 struct resource
*dma_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 2);
2727 isp1362_hcd
->data_dma
= dma_res
->start
;
2728 isp1362_hcd
->max_dma_size
= resource_len(dma_res
);
2731 if (pdev
->dev
.dma_mask
) {
2732 DBG(1, "won't do DMA");
2738 if (!request_mem_region(addr
->start
, resource_len(addr
), hcd_name
)) {
2742 addr_reg
= ioremap(addr
->start
, resource_len(addr
));
2743 if (addr_reg
== NULL
) {
2748 if (!request_mem_region(data
->start
, resource_len(data
), hcd_name
)) {
2752 data_reg
= ioremap(data
->start
, resource_len(data
));
2753 if (data_reg
== NULL
) {
2758 /* allocate and initialize hcd */
2759 hcd
= usb_create_hcd(&isp1362_hc_driver
, &pdev
->dev
, dev_name(&pdev
->dev
));
2764 hcd
->rsrc_start
= data
->start
;
2765 isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
2766 isp1362_hcd
->data_reg
= data_reg
;
2767 isp1362_hcd
->addr_reg
= addr_reg
;
2769 isp1362_hcd
->next_statechange
= jiffies
;
2770 spin_lock_init(&isp1362_hcd
->lock
);
2771 INIT_LIST_HEAD(&isp1362_hcd
->async
);
2772 INIT_LIST_HEAD(&isp1362_hcd
->periodic
);
2773 INIT_LIST_HEAD(&isp1362_hcd
->isoc
);
2774 INIT_LIST_HEAD(&isp1362_hcd
->remove_list
);
2775 isp1362_hcd
->board
= pdev
->dev
.platform_data
;
2776 #if USE_PLATFORM_DELAY
2777 if (!isp1362_hcd
->board
->delay
) {
2778 dev_err(hcd
->self
.controller
, "No platform delay function given\n");
2785 if (isp1362_hcd
->board
)
2786 set_irq_type(irq
, isp1362_hcd
->board
->int_act_high
? IRQT_RISING
: IRQT_FALLING
);
2789 retval
= usb_add_hcd(hcd
, irq
, IRQF_TRIGGER_LOW
| IRQF_DISABLED
| IRQF_SHARED
);
2792 pr_info("%s, irq %d\n", hcd
->product_desc
, irq
);
2794 create_debug_file(isp1362_hcd
);
2799 DBG(0, "%s: Freeing dev %p\n", __func__
, isp1362_hcd
);
2802 DBG(0, "%s: Unmapping data_reg @ %p\n", __func__
, data_reg
);
2805 DBG(0, "%s: Releasing mem region %08lx\n", __func__
, (long unsigned int)data
->start
);
2806 release_mem_region(data
->start
, resource_len(data
));
2808 DBG(0, "%s: Unmapping addr_reg @ %p\n", __func__
, addr_reg
);
2811 DBG(0, "%s: Releasing mem region %08lx\n", __func__
, (long unsigned int)addr
->start
);
2812 release_mem_region(addr
->start
, resource_len(addr
));
2814 pr_err("%s: init error, %d\n", __func__
, retval
);
2820 static int isp1362_suspend(struct platform_device
*pdev
, pm_message_t state
)
2822 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
2823 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
2824 unsigned long flags
;
2827 DBG(0, "%s: Suspending device\n", __func__
);
2829 if (state
.event
== PM_EVENT_FREEZE
) {
2830 DBG(0, "%s: Suspending root hub\n", __func__
);
2831 retval
= isp1362_bus_suspend(hcd
);
2833 DBG(0, "%s: Suspending RH ports\n", __func__
);
2834 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2835 isp1362_write_reg32(isp1362_hcd
, HCRHSTATUS
, RH_HS_LPS
);
2836 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2839 pdev
->dev
.power
.power_state
= state
;
2843 static int isp1362_resume(struct platform_device
*pdev
)
2845 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
2846 struct isp1362_hcd
*isp1362_hcd
= hcd_to_isp1362_hcd(hcd
);
2847 unsigned long flags
;
2849 DBG(0, "%s: Resuming\n", __func__
);
2851 if (pdev
->dev
.power
.power_state
.event
== PM_EVENT_SUSPEND
) {
2852 DBG(0, "%s: Resume RH ports\n", __func__
);
2853 spin_lock_irqsave(&isp1362_hcd
->lock
, flags
);
2854 isp1362_write_reg32(isp1362_hcd
, HCRHSTATUS
, RH_HS_LPSC
);
2855 spin_unlock_irqrestore(&isp1362_hcd
->lock
, flags
);
2859 pdev
->dev
.power
.power_state
= PMSG_ON
;
2861 return isp1362_bus_resume(isp1362_hcd_to_hcd(isp1362_hcd
));
2864 #define isp1362_suspend NULL
2865 #define isp1362_resume NULL
2868 static struct platform_driver isp1362_driver
= {
2869 .probe
= isp1362_probe
,
2870 .remove
= __devexit_p(isp1362_remove
),
2872 .suspend
= isp1362_suspend
,
2873 .resume
= isp1362_resume
,
2875 .name
= (char *)hcd_name
,
2876 .owner
= THIS_MODULE
,
2880 /*-------------------------------------------------------------------------*/
2882 static int __init
isp1362_init(void)
2886 pr_info("driver %s, %s\n", hcd_name
, DRIVER_VERSION
);
2887 return platform_driver_register(&isp1362_driver
);
2889 module_init(isp1362_init
);
2891 static void __exit
isp1362_cleanup(void)
2893 platform_driver_unregister(&isp1362_driver
);
2895 module_exit(isp1362_cleanup
);