40 #ifdef CONFIG_USB_DEBUG
41 # define ISP1362_DEBUG
54 #undef BUGGY_PXA2XX_UDC_USBTEST
64 #undef CHIP_BUFFER_TEST
66 #include <linux/module.h>
68 #include <linux/kernel.h>
71 #include <linux/sched.h>
72 #include <linux/slab.h>
73 #include <linux/errno.h>
75 #include <linux/list.h>
83 #include <linux/bitmap.h>
84 #include <linux/prefetch.h>
87 #include <asm/byteorder.h>
88 #include <asm/unaligned.h>
95 #define STUB_DEBUG_FILE
98 #include "../core/usb.h"
102 #define DRIVER_VERSION "2005-04-04"
103 #define DRIVER_DESC "ISP1362 USB Host Controller Driver"
108 static const char hcd_name[] =
"isp1362-hcd";
110 static void isp1362_hc_stop(
struct usb_hcd *hcd);
111 static int isp1362_hc_start(
struct usb_hcd *hcd);
124 if ((isp1362_hcd->
irqenb | mask) == isp1362_hcd->
irqenb)
126 if (mask & ~isp1362_hcd->
irqenb)
136 static inline struct isp1362_ep_queue *get_ptd_queue(
struct isp1362_hcd *isp1362_hcd,
152 DBG(1,
"%s: PTD $%04x is on %s queue\n", __func__, offset, epq->
name);
154 pr_warning(
"%s: invalid PTD $%04x\n", __func__, offset);
164 pr_warning(
"%s: Bad %s index %d(%d)\n", __func__, epq->
name, index,
169 DBG(3,
"%s: %s PTD[%02x] # %04x\n", __func__, epq->
name, index, offset);
182 if (xfer_size < size && xfer_size % mps)
183 xfer_size -= xfer_size %
mps;
201 pr_err(
"%s: %s len %d/%d num_ptds %d buf_map %08lx skip_map %08lx\n", __func__,
210 DBG(1,
"%s: Found %d PTDs[%d] for %d/%d byte\n", __func__,
212 ptd_offset = get_ptd_offset(epq, found);
220 DBG(1,
"%s: Done %s PTD[%d] $%04x, avail %d count %d claimed %d %08lx:%08lx\n",
232 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",
246 DBG(1,
"%s: Done %s PTDs $%04x released %d avail %d count %d\n",
249 DBG(1,
"%s: buf_map %08lx skip_map %08lx\n", __func__,
262 static void prepare_ptd(
struct isp1362_hcd *isp1362_hcd,
struct urb *
urb,
270 size_t buf_len = urb->transfer_buffer_length - urb->actual_length;
272 DBG(3,
"%s: %s ep %p\n", __func__, epq->
name, ep);
276 ep->
data = (
unsigned char *)urb->transfer_buffer + urb->actual_length;
280 toggle = usb_gettoggle(urb->dev, ep->
epnum, 0);
282 if (usb_pipecontrol(urb->pipe)) {
284 }
else if (usb_pipeisoc(urb->pipe)) {
286 ep->
data = urb->transfer_buffer + urb->iso_frame_desc[fno].offset;
289 DBG(1,
"%s: IN len %d/%d/%d from URB\n", __func__, len, ep->
maxpacket,
293 toggle = usb_gettoggle(urb->dev, ep->
epnum, 1);
295 if (usb_pipecontrol(urb->pipe))
297 else if (usb_pipeisoc(urb->pipe))
302 pr_info(
"%s: Sending ZERO packet: %d\n", __func__,
303 urb->transfer_flags & URB_ZERO_PACKET);
304 DBG(1,
"%s: OUT len %d/%d/%d from URB\n", __func__, len, ep->
maxpacket,
311 DBG(1,
"%s: SETUP len %d\n", __func__, len);
312 ep->
data = urb->setup_packet;
317 dir = (urb->transfer_buffer_length && usb_pipein(urb->pipe)) ?
319 DBG(1,
"%s: ACK len %d\n", __func__, len);
322 toggle = dir = len = 0;
323 pr_err(
"%s@%d: ep->nextpid %02x\n", __func__, __LINE__, ep->
nextpid);
337 if (usb_pipeint(urb->pipe)) {
341 if (usb_pipeisoc(urb->pipe))
344 DBG(1,
"%s: Finished\n", __func__);
347 static void isp1362_write_ptd(
struct isp1362_hcd *isp1362_hcd,
struct isp1362_ep *ep,
350 struct ptd *ptd = &ep->
ptd;
358 isp1362_write_buffer(isp1362_hcd, ep->
data,
365 static void isp1362_read_ptd(
struct isp1362_hcd *isp1362_hcd,
struct isp1362_ep *ep,
368 struct ptd *ptd = &ep->
ptd;
374 list_del_init(&ep->
active);
375 DBG(1,
"%s: ep %p removed from active list %p\n", __func__, ep, &epq->
active);
384 pr_err(
"%s: ep %p PTD $%04x act_len %d ep->length %d\n", __func__, ep,
392 isp1362_read_buffer(isp1362_hcd, ep->
data,
402 static void remove_ptd(
struct isp1362_hcd *isp1362_hcd,
struct isp1362_ep *ep)
411 epq = get_ptd_queue(isp1362_hcd, ep->
ptd_offset);
425 DBG(1,
"%s: Disabling PTD[%02x] $%04x %08lx|%08x\n", __func__,
431 DBG(2,
"%s: ATLSKIP = %08x -> %08lx\n", __func__,
437 DBG(2,
"%s: INTLSKIP = %08x -> %08lx\n", __func__,
449 static void finish_request(
struct isp1362_hcd *isp1362_hcd,
struct isp1362_ep *ep,
450 struct urb *urb,
int status)
457 if (usb_pipecontrol(urb->pipe))
460 URB_DBG(
"%s: req %d FA %d ep%d%s %s: len %d/%d %s stat %d\n", __func__,
461 ep->
num_req, usb_pipedevice(urb->pipe),
462 usb_pipeendpoint(urb->pipe),
463 !usb_pipein(urb->pipe) ?
"out" :
"in",
464 usb_pipecontrol(urb->pipe) ?
"ctrl" :
465 usb_pipeint(urb->pipe) ?
"int" :
466 usb_pipebulk(urb->pipe) ?
"bulk" :
468 urb->actual_length, urb->transfer_buffer_length,
469 !(urb->transfer_flags & URB_SHORT_NOT_OK) ?
470 "short_ok" :
"", urb->status);
474 spin_unlock(&isp1362_hcd->
lock);
476 spin_lock(&isp1362_hcd->
lock);
479 if (!list_empty(&ep->
hep->urb_list))
491 DBG(1,
"deschedule qh%d/%p branch %d load %d bandwidth %d -> %d\n", ep->
interval,
503 static void postproc_ep(
struct isp1362_hcd *isp1362_hcd,
struct isp1362_ep *ep)
506 struct usb_device *
udev;
513 DBG(2,
"%s: ep %p req %d\n", __func__, ep, ep->
num_req);
519 pr_err(
"%s: req %d PTD %p Untouched by ISP1362\n", __func__,
524 short_ok = !(urb->transfer_flags & URB_SHORT_NOT_OK);
525 len = urb->transfer_buffer_length - urb->actual_length;
535 DBG(1,
"%s: req %d Allowed data underrun short_%sok %d/%d/%d byte\n",
536 __func__, ep->
num_req, short_ok ?
"" :
"not_",
541 DBG(1,
"%s: req %d Data Underrun %s nextpid %02x short_%sok %d/%d/%d byte\n",
543 usb_pipein(urb->pipe) ?
"IN" :
"OUT", ep->
nextpid,
544 short_ok ?
"" :
"not_",
550 if (usb_pipecontrol(urb->pipe)) {
552 BUG_ON(urb->actual_length > urb->transfer_buffer_length);
567 urbstat = cc_to_error[
cc];
568 DBG(1,
"%s: req %d nextpid %02x, status %d, error %d, error_count %d\n",
578 pr_err(
"%s: count=%d len=%d\n", __func__,
581 urb->actual_length += ep->
length;
582 BUG_ON(urb->actual_length > urb->transfer_buffer_length);
584 if (urb->actual_length == urb->transfer_buffer_length) {
585 DBG(3,
"%s: req %d xfer complete %d/%d status %d -> 0\n", __func__,
587 if (usb_pipecontrol(urb->pipe)) {
588 DBG(3,
"%s: req %d %s Wait for ACK\n", __func__,
590 usb_pipein(urb->pipe) ?
"IN" :
"OUT");
594 !(urb->transfer_flags & URB_ZERO_PACKET)) {
596 DBG(3,
"%s: req %d URB %s status %d count %d/%d/%d\n",
597 __func__, ep->
num_req, usb_pipein(urb->pipe) ?
"IN" :
"OUT",
598 urbstat, len, ep->
maxpacket, urb->actual_length);
606 urb->actual_length +=
len;
607 BUG_ON(urb->actual_length > urb->transfer_buffer_length);
610 if ((urb->transfer_buffer_length == urb->actual_length) ||
612 DBG(3,
"%s: req %d xfer complete %d/%d status %d -> 0\n", __func__,
614 if (usb_pipecontrol(urb->pipe)) {
615 DBG(3,
"%s: req %d %s Wait for ACK\n", __func__,
617 usb_pipein(urb->pipe) ?
"IN" :
"OUT");
621 DBG(3,
"%s: req %d URB %s status %d count %d/%d/%d\n",
622 __func__, ep->
num_req, usb_pipein(urb->pipe) ?
"IN" :
"OUT",
623 urbstat, len, ep->
maxpacket, urb->actual_length);
628 if (urb->transfer_buffer_length == urb->actual_length) {
630 }
else if (usb_pipeout(urb->pipe)) {
631 usb_settoggle(udev, 0, 1, 1);
634 usb_settoggle(udev, 0, 0, 1);
639 DBG(3,
"%s: req %d got ACK %d -> 0\n", __func__, ep->
num_req,
651 DBG(2,
"%s: Finishing ep %p req %d urb %p status %d\n", __func__,
652 ep, ep->
num_req, urb, urbstat);
653 finish_request(isp1362_hcd, ep, urb, urbstat);
657 static void finish_unlinks(
struct isp1362_hcd *isp1362_hcd)
669 DBG(1,
"%s: remove PTD[%d] $%04x\n", __func__, index, ep->
ptd_offset);
671 release_ptd_buffers(epq, ep);
673 if (!list_empty(&ep->
hep->urb_list)) {
676 DBG(1,
"%s: Finishing req %d ep %p from remove_list\n", __func__,
678 finish_request(isp1362_hcd, ep, urb, -
ESHUTDOWN);
681 if (!list_empty(&ep->
active)) {
682 list_del_init(&ep->
active);
683 DBG(1,
"%s: ep %p removed from active list\n", __func__, ep);
686 DBG(1,
"%s: ep %p removed from remove_list\n", __func__, ep);
688 DBG(1,
"%s: Done\n", __func__);
691 static inline void enable_atl_transfers(
struct isp1362_hcd *isp1362_hcd,
int count)
694 if (count < isp1362_hcd->atl_queue.ptd_count)
703 static inline void enable_intl_transfers(
struct isp1362_hcd *isp1362_hcd)
710 static inline void enable_istl_transfers(
struct isp1362_hcd *isp1362_hcd,
int flip)
717 static int submit_req(
struct isp1362_hcd *isp1362_hcd,
struct urb *urb,
722 prepare_ptd(isp1362_hcd, urb, ep, epq, 0);
723 index = claim_ptd_buffers(epq, ep, ep->
length);
725 DBG(1,
"%s: req %d No free %s PTD available: %d, %08lx:%08lx\n", __func__,
729 DBG(1,
"%s: req %d Not enough space for %d byte %s PTD %d %08lx:%08lx\n",
736 DBG(1,
"%s: ep %p req %d len %d added to active list %p\n", __func__,
738 DBG(1,
"%s: Submitting %s PTD $%04x for ep %p req %d\n", __func__, epq->
name,
740 isp1362_write_ptd(isp1362_hcd, ep, epq);
746 static void start_atl_transfers(
struct isp1362_hcd *isp1362_hcd)
754 DBG(1,
"%s: finish_transfers is active for %s\n", __func__, epq->
name);
762 if (!list_empty(&ep->
active)) {
763 DBG(2,
"%s: Skipping active %s ep %p\n", __func__, epq->
name, ep);
767 DBG(1,
"%s: Processing %s ep %p req %d\n", __func__, epq->
name,
770 ret = submit_req(isp1362_hcd, urb, ep, epq);
778 #ifdef BUGGY_PXA2XX_UDC_USBTEST
785 if (isp1362_hcd->
async.next != isp1362_hcd->
async.prev) {
786 DBG(2,
"%s: Cycling ASYNC schedule %d\n", __func__, ptd_count);
787 list_move(&isp1362_hcd->
async, isp1362_hcd->
async.next);
789 if (ptd_count || defer)
790 enable_atl_transfers(isp1362_hcd, defer ? 0 : ptd_count);
799 static void start_intl_transfers(
struct isp1362_hcd *isp1362_hcd)
806 DBG(1,
"%s: finish_transfers is active for %s\n", __func__, epq->
name);
814 if (!list_empty(&ep->
active)) {
815 DBG(1,
"%s: Skipping active %s ep %p\n", __func__,
820 DBG(1,
"%s: Processing %s ep %p req %d\n", __func__,
822 ret = submit_req(isp1362_hcd, urb, ep, epq);
831 static int last_count;
833 if (ptd_count != last_count) {
834 DBG(0,
"%s: ptd_count: %d\n", __func__, ptd_count);
835 last_count = ptd_count;
837 enable_intl_transfers(isp1362_hcd);
850 DBG(2,
"%s: PTD offset $%04x + %04x => %d * %04x -> $%04x\n", __func__, ptd_offset,
853 ptd_offset += num_ptds * epq->
blk_size;
854 if (ptd_offset < epq->buf_start + epq->
buf_size)
860 static void start_iso_transfers(
struct isp1362_hcd *isp1362_hcd)
873 DBG(1,
"%s: finish_transfers is active for %s\n", __func__, epq->
name);
877 if (!list_empty(&epq->
active))
883 s16 diff = fno - (
u16)urb->start_frame;
885 DBG(1,
"%s: Processing %s ep %p\n", __func__, epq->
name, ep);
887 if (diff > urb->number_of_packets) {
889 finish_request(isp1362_hcd, ep, urb, -
EOVERFLOW);
891 }
else if (diff < -1) {
897 }
else if (diff == -1) {
899 prepare_ptd(isp1362_hcd, urb, ep, epq, fno);
902 pr_err(
"%s: Not enough ISO buffer space for %d byte PTD\n",
909 ptd_offset = next_ptd(epq, ep);
910 if (ptd_offset < 0) {
911 pr_warning(
"%s: req %d No more %s PTD buffers available\n", __func__,
920 isp1362_write_ptd(isp1362_hcd, ep, epq);
925 enable_istl_transfers(isp1362_hcd, flip);
941 static void finish_transfers(
struct isp1362_hcd *isp1362_hcd,
unsigned long done_map,
947 if (list_empty(&epq->
active)) {
948 DBG(1,
"%s: Nothing to do for %s queue\n", __func__, epq->
name);
952 DBG(1,
"%s: Finishing %s transfers %08lx\n", __func__, epq->
name, done_map);
958 DBG(1,
"%s: Checking %s PTD[%02x] $%04x\n", __func__, epq->
name,
963 isp1362_read_ptd(isp1362_hcd, ep, epq);
966 release_ptd_buffers(epq, ep);
968 DBG(1,
"%s: ep %p req %d removed from active list\n", __func__,
972 DBG(1,
"%s: ep %p removed from remove list\n", __func__, ep);
974 DBG(1,
"%s: Postprocessing %s ep %p req %d\n", __func__, epq->
name,
976 postproc_ep(isp1362_hcd, ep);
982 pr_warning(
"%s: done_map not clear: %08lx:%08lx\n", __func__, done_map,
987 static void finish_iso_transfers(
struct isp1362_hcd *isp1362_hcd,
struct isp1362_ep_queue *epq)
992 if (list_empty(&epq->
active)) {
993 DBG(1,
"%s: Nothing to do for %s queue\n", __func__, epq->
name);
997 DBG(1,
"%s: Finishing %s transfers\n", __func__, epq->
name);
1001 DBG(1,
"%s: Checking PTD $%04x\n", __func__, ep->
ptd_offset);
1003 isp1362_read_ptd(isp1362_hcd, ep, epq);
1004 DBG(1,
"%s: Postprocessing %s ep %p\n", __func__, epq->
name, ep);
1005 postproc_ep(isp1362_hcd, ep);
1011 static irqreturn_t isp1362_irq(
struct usb_hcd *hcd)
1014 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1018 spin_lock(&isp1362_hcd->
lock);
1025 DBG(3,
"%s: got IRQ %04x:%04x\n", __func__, irqstat, isp1362_hcd->
irqenb);
1028 irqstat &= isp1362_hcd->
irqenb;
1033 isp1362_hcd->
irqenb &= ~HCuPINT_SOF;
1036 svc_mask &= ~HCuPINT_SOF;
1037 DBG(3,
"%s: SOF\n", __func__);
1040 finish_unlinks(isp1362_hcd);
1042 if (list_empty(&isp1362_hcd->
atl_queue.active)) {
1043 start_atl_transfers(isp1362_hcd);
1045 isp1362_enable_int(isp1362_hcd, HCuPINT_ATL);
1056 svc_mask &= ~HCuPINT_ISTL0;
1058 DBG(1,
"%s: ISTL0\n", __func__);
1064 isp1362_hcd->
irqenb &= ~HCuPINT_ISTL0;
1070 svc_mask &= ~HCuPINT_ISTL1;
1072 DBG(1,
"%s: ISTL1\n", __func__);
1078 isp1362_hcd->
irqenb &= ~HCuPINT_ISTL1;
1081 if (irqstat & (HCuPINT_ISTL0 | HCuPINT_ISTL1)) {
1082 WARN_ON((irqstat & (HCuPINT_ISTL0 | HCuPINT_ISTL1)) ==
1083 (HCuPINT_ISTL0 | HCuPINT_ISTL1));
1084 finish_iso_transfers(isp1362_hcd,
1086 start_iso_transfers(isp1362_hcd);
1095 DBG(2,
"%s: INTL\n", __func__);
1097 svc_mask &= ~HCuPINT_INTL;
1100 if (~(done_map | skip_map) == 0)
1107 DBG(3,
"%s: INTL done_map %08x\n", __func__, done_map);
1108 finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->
intl_queue);
1109 start_intl_transfers(isp1362_hcd);
1113 if (irqstat & HCuPINT_ATL) {
1118 DBG(2,
"%s: ATL\n", __func__);
1120 svc_mask &= ~HCuPINT_ATL;
1123 if (~(done_map | skip_map) == 0)
1126 DBG(3,
"%s: ATL done_map %08x\n", __func__, done_map);
1127 finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->
atl_queue);
1128 start_atl_transfers(isp1362_hcd);
1137 svc_mask &= ~HCuPINT_OPR;
1138 DBG(2,
"%s: OPR %08x:%08x\n", __func__, intstat, isp1362_hcd->
intenb);
1139 intstat &= isp1362_hcd->
intenb;
1141 pr_err(
"Unrecoverable error\n");
1150 pr_info(
"%s: RESUME DETECTED\n", __func__);
1152 usb_hcd_resume_root_hub(hcd);
1155 irqstat &= ~HCuPINT_OPR;
1162 svc_mask &= ~HCuPINT_SUSP;
1164 pr_info(
"%s: SUSPEND IRQ\n", __func__);
1170 isp1362_hcd->
irqenb &= ~HCuPINT_CLKRDY;
1171 svc_mask &= ~HCuPINT_CLKRDY;
1172 pr_info(
"%s: CLKRDY IRQ\n", __func__);
1176 pr_err(
"%s: Unserviced interrupt(s) %04x\n", __func__, svc_mask);
1180 spin_unlock(&isp1362_hcd->
lock);
1187 #define MAX_PERIODIC_LOAD 900
1201 pr_err(
"%s: new load %d load[%02x] %d max %d\n", __func__,
1206 if (j < PERIODIC_SIZE)
1220 static int isp1362_urb_enqueue(
struct usb_hcd *hcd,
1224 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1225 struct usb_device *udev = urb->dev;
1226 unsigned int pipe = urb->pipe;
1227 int is_out = !usb_pipein(pipe);
1228 int type = usb_pipetype(pipe);
1229 int epnum = usb_pipeendpoint(pipe);
1230 struct usb_host_endpoint *
hep = urb->ep;
1232 unsigned long flags;
1235 DBG(3,
"%s: urb %p\n", __func__, urb);
1237 if (type == PIPE_ISOCHRONOUS) {
1238 pr_err(
"Isochronous transfers not supported\n");
1242 URB_DBG(
"%s: FA %d ep%d%s %s: len %d %s%s\n", __func__,
1243 usb_pipedevice(pipe), epnum,
1244 is_out ?
"out" :
"in",
1245 usb_pipecontrol(pipe) ?
"ctrl" :
1246 usb_pipeint(pipe) ?
"int" :
1247 usb_pipebulk(pipe) ?
"bulk" :
1249 urb->transfer_buffer_length,
1250 (urb->transfer_flags & URB_ZERO_PACKET) ?
"ZERO_PACKET " :
"",
1251 !(urb->transfer_flags & URB_SHORT_NOT_OK) ?
1256 ep = kzalloc(
sizeof *ep, mem_flags);
1263 if (!((isp1362_hcd->
rhport[0] | isp1362_hcd->
rhport[1]) &
1265 !HC_IS_RUNNING(hcd->state)) {
1268 goto fail_not_linked;
1274 goto fail_not_linked;
1281 INIT_LIST_HEAD(&ep->
active);
1286 ep->
maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
1289 usb_settoggle(udev, epnum, is_out, 0);
1291 if (type == PIPE_CONTROL)
1299 case PIPE_ISOCHRONOUS:
1300 case PIPE_INTERRUPT:
1306 (type == PIPE_ISOCHRONOUS),
1307 usb_maxpacket(udev, pipe, is_out)) / 1000;
1319 DBG(1,
"%s: Adding ep %p req %d to async schedule\n",
1324 case PIPE_ISOCHRONOUS:
1325 case PIPE_INTERRUPT:
1334 pr_err(
"%s: balance returned %d\n", __func__, retval);
1340 DBG(1,
"%s: Current frame %04x branch %02x start_frame %04x(%04x)\n",
1347 if (type == PIPE_ISOCHRONOUS) {
1355 urb->start_frame = frame;
1357 DBG(1,
"%s: Adding ep %p to isoc schedule\n", __func__, ep);
1360 DBG(1,
"%s: Adding ep %p to periodic schedule\n", __func__, ep);
1364 DBG(1,
"%s: ep %p already scheduled\n", __func__, ep);
1366 DBG(2,
"%s: load %d bandwidth %d -> %d\n", __func__,
1373 ALIGNSTAT(isp1362_hcd, urb->transfer_buffer);
1378 start_atl_transfers(isp1362_hcd);
1380 case PIPE_INTERRUPT:
1381 start_intl_transfers(isp1362_hcd);
1383 case PIPE_ISOCHRONOUS:
1384 start_iso_transfers(isp1362_hcd);
1395 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1397 DBG(0,
"%s: urb %p failed with %d\n", __func__, urb, retval);
1401 static int isp1362_urb_dequeue(
struct usb_hcd *hcd,
struct urb *urb,
int status)
1403 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1404 struct usb_host_endpoint *
hep;
1405 unsigned long flags;
1409 DBG(3,
"%s: urb %p\n", __func__, urb);
1419 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1426 if (ep->
hep->urb_list.next == &urb->urb_list) {
1427 if (!list_empty(&ep->
active)) {
1428 DBG(1,
"%s: urb %p ep %p req %d active PTD[%d] $%04x\n", __func__,
1431 remove_ptd(isp1362_hcd, ep);
1436 DBG(1,
"%s: Finishing ep %p req %d\n", __func__, ep,
1438 finish_request(isp1362_hcd, ep, urb, status);
1440 DBG(1,
"%s: urb %p active; wait4irq\n", __func__, urb);
1442 pr_warning(
"%s: No EP in URB %p\n", __func__, urb);
1446 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1448 DBG(3,
"%s: exit\n", __func__);
1453 static void isp1362_endpoint_disable(
struct usb_hcd *hcd,
struct usb_host_endpoint *hep)
1456 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1457 unsigned long flags;
1459 DBG(1,
"%s: ep %p\n", __func__, ep);
1463 if (!list_empty(&hep->urb_list)) {
1465 DBG(1,
"%s: Removing ep %p req %d PTD[%d] $%04x\n", __func__,
1467 remove_ptd(isp1362_hcd, ep);
1468 pr_info(
"%s: Waiting for Interrupt to clean up\n", __func__);
1471 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1473 while (!list_empty(&ep->
active))
1476 DBG(1,
"%s: Freeing EP %p\n", __func__, ep);
1483 static int isp1362_get_frame(
struct usb_hcd *hcd)
1485 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1487 unsigned long flags;
1491 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1499 static int isp1362_hub_status_data(
struct usb_hcd *hcd,
char *
buf)
1501 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1503 unsigned long flags;
1505 if (!HC_IS_RUNNING(hcd->state))
1510 if (timer_pending(&hcd->rh_timer))
1519 buf[0] = changed = 1;
1523 for (i = 0; i < ports; i++) {
1529 buf[0] |= 1 << (i + 1);
1536 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1540 static void isp1362_hub_descriptor(
struct isp1362_hcd *isp1362_hcd,
1545 DBG(3,
"%s: enter\n", __func__);
1553 DBG(0,
"%s: hubcharacteristics = %02x\n", __func__,
cpu_to_le16((reg >> 8) & 0x1f));
1559 DBG(3,
"%s: exit\n", __func__);
1563 static int isp1362_hub_control(
struct usb_hcd *hcd,
u16 typeReq,
u16 wValue,
1566 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1568 unsigned long flags;
1574 case ClearHubFeature:
1575 DBG(0,
"ClearHubFeature: ");
1578 _DBG(0,
"C_HUB_OVER_CURRENT\n");
1581 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1583 _DBG(0,
"C_HUB_LOCAL_POWER\n");
1590 DBG(0,
"SetHubFeature: ");
1594 _DBG(0,
"C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1600 case GetHubDescriptor:
1601 DBG(0,
"GetHubDescriptor\n");
1605 DBG(0,
"GetHubStatus\n");
1610 DBG(0,
"GetPortStatus\n");
1612 if (!wIndex || wIndex > ports)
1617 case ClearPortFeature:
1618 DBG(0,
"ClearPortFeature: ");
1619 if (!wIndex || wIndex > ports)
1625 _DBG(0,
"USB_PORT_FEAT_ENABLE\n");
1629 _DBG(0,
"USB_PORT_FEAT_C_ENABLE\n");
1633 _DBG(0,
"USB_PORT_FEAT_SUSPEND\n");
1637 _DBG(0,
"USB_PORT_FEAT_C_SUSPEND\n");
1641 _DBG(0,
"USB_PORT_FEAT_POWER\n");
1646 _DBG(0,
"USB_PORT_FEAT_C_CONNECTION\n");
1650 _DBG(0,
"USB_PORT_FEAT_C_OVER_CURRENT\n");
1654 _DBG(0,
"USB_PORT_FEAT_C_RESET\n");
1665 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1667 case SetPortFeature:
1668 DBG(0,
"SetPortFeature: ");
1669 if (!wIndex || wIndex > ports)
1674 _DBG(0,
"USB_PORT_FEAT_SUSPEND\n");
1679 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1682 _DBG(0,
"USB_PORT_FEAT_POWER\n");
1687 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1690 _DBG(0,
"USB_PORT_FEAT_RESET\n");
1707 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1714 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1724 _DBG(0,
"PROTOCOL STALL\n");
1735 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1736 unsigned long flags;
1746 DBG(0,
"%s: resume/suspend?\n", __func__);
1756 pr_warning(
"%s: already suspended?\n", __func__);
1759 DBG(0,
"%s: suspend root hub\n", __func__);
1762 hcd->state = HC_STATE_QUIESCING;
1763 if (!list_empty(&isp1362_hcd->
atl_queue.active) ||
1764 !list_empty(&isp1362_hcd->
intl_queue.active) ||
1765 !list_empty(&isp1362_hcd->
istl_queue[0] .active) ||
1766 !list_empty(&isp1362_hcd->
istl_queue[1] .active)) {
1775 DBG(0,
"%s: stopping schedules ...\n", __func__);
1786 finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->
atl_queue);
1790 finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->
intl_queue);
1793 finish_iso_transfers(isp1362_hcd, &isp1362_hcd->
istl_queue[0]);
1795 finish_iso_transfers(isp1362_hcd, &isp1362_hcd->
istl_queue[1]);
1797 DBG(0,
"%s: HCINTSTAT: %08x\n", __func__,
1811 pr_err(
"%s: controller won't suspend %08x\n", __func__,
1822 hcd->state = HC_STATE_SUSPENDED;
1823 DBG(0,
"%s: HCD suspended: %08x\n", __func__,
1826 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1832 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1834 unsigned long flags;
1843 if (hcd->state == HC_STATE_RESUMING) {
1844 pr_warning(
"%s: duplicate resume\n", __func__);
1849 DBG(0,
"%s: resume root hub\n", __func__);
1856 DBG(0,
"%s: remote wakeup\n", __func__);
1859 DBG(0,
"%s: odd resume\n", __func__);
1861 hcd->self.root_hub->dev.power.power_state =
PMSG_ON;
1864 DBG(0,
"%s: root hub hardware reset\n", __func__);
1867 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1868 if (status == -
EBUSY) {
1869 DBG(0,
"%s: Restarting HC\n", __func__);
1870 isp1362_hc_stop(hcd);
1871 return isp1362_hc_start(hcd);
1882 DBG(0,
"%s: Not Resuming RH port %d\n", __func__, port);
1885 DBG(0,
"%s: Resuming RH port %d\n", __func__, port);
1888 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1891 hcd->state = HC_STATE_RESUMING;
1898 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
1905 hcd->self.root_hub->dev.power.power_state =
PMSG_ON;
1906 hcd->state = HC_STATE_RUNNING;
1910 #define isp1362_bus_suspend NULL
1911 #define isp1362_bus_resume NULL
1916 #ifdef STUB_DEBUG_FILE
1932 seq_printf(s,
"%-15s %04x%s%s%s%s%s%s\n", label, mask,
1933 mask & HCuPINT_CLKRDY ?
" clkrdy" :
"",
1934 mask & HCuPINT_SUSP ?
" susp" :
"",
1935 mask & HCuPINT_OPR ?
" opr" :
"",
1937 mask & HCuPINT_ATL ?
" atl" :
"",
1938 mask & HCuPINT_SOF ?
" sof" :
"");
1943 seq_printf(s,
"%-15s %08x%s%s%s%s%s%s%s\n", label, mask,
1945 mask & OHCI_INTR_RHSC ?
" rhsc" :
"",
1947 mask & OHCI_INTR_UE ?
" ue" :
"",
1955 seq_printf(s,
"%-15s %08x%s%s%s\n", label, mask,
1980 static void dump_regs(
struct seq_file *s,
struct isp1362_hcd *isp1362_hcd)
2074 struct isp1362_hcd *isp1362_hcd = s->
private;
2079 isp1362_hcd_to_hcd(isp1362_hcd)->product_desc, hcd_name,
DRIVER_VERSION);
2084 seq_printf(s,
"alignment: 16b/%ld 8b/%ld 4b/%ld 2b/%ld 1b/%ld\n",
2089 seq_printf(s,
"max # ptds in ISTL fifo: %d\n",
2094 spin_lock_irq(&isp1362_hcd->
lock);
2102 for (i = 0; i < NUM_ISP1362_IRQS; i++)
2105 ISP1362_INT_NAME(i), isp1362_hcd->
irq_stat[i]);
2107 dump_regs(s, isp1362_hcd);
2135 urb->transfer_buffer_length);
2138 if (!list_empty(&isp1362_hcd->
async))
2148 seq_printf(s,
" %d/%p (%sdev%d ep%d%s max %d)\n",
2152 (ep->
epnum == 0) ?
"" :
2161 seq_printf(s,
" %d/%p (%sdev%d ep%d%s max %d)\n",
2165 (ep->
epnum == 0) ?
"" :
2170 spin_unlock_irq(&isp1362_hcd->
lock);
2182 .
open = proc_isp1362_open,
2189 static const char proc_filename[] =
"driver/isp1362";
2197 pr_warning(
"%s: Failed to create debug file '%s'\n", __func__, proc_filename);
2202 pde->
data = isp1362_hcd;
2203 isp1362_hcd->
pde = pde;
2208 if (isp1362_hcd->
pde)
2216 static void __isp1362_sw_reset(
struct isp1362_hcd *isp1362_hcd)
2228 pr_err(
"Software reset timeout\n");
2231 static void isp1362_sw_reset(
struct isp1362_hcd *isp1362_hcd)
2233 unsigned long flags;
2236 __isp1362_sw_reset(isp1362_hcd);
2237 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2240 static int isp1362_mem_config(
struct usb_hcd *hcd)
2242 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2243 unsigned long flags;
2256 WARN_ON(atl_blksize < PTD_HEADER_SIZE);
2257 WARN_ON(intl_blksize < PTD_HEADER_SIZE);
2260 if (atl_buffers > 32)
2262 atl_size = atl_buffers * atl_blksize;
2263 total = atl_size + intl_size + istl_size;
2264 dev_info(hcd->self.controller,
"ISP1362 Memory usage:\n");
2265 dev_info(hcd->self.controller,
" ISTL: 2 * %4d: %4d @ $%04x:$%04x\n",
2266 istl_size / 2, istl_size, 0, istl_size / 2);
2267 dev_info(hcd->self.controller,
" INTL: %4d * (%3zu+8): %4d @ $%04x\n",
2269 intl_size, istl_size);
2270 dev_info(hcd->self.controller,
" ATL : %4d * (%3zu+8): %4d @ $%04x\n",
2271 atl_buffers, atl_blksize - PTD_HEADER_SIZE,
2272 atl_size, istl_size + intl_size);
2273 dev_info(hcd->self.controller,
" USED/FREE: %4d %4d\n", total,
2277 dev_err(hcd->self.controller,
"%s: Memory requested: %d, available %d\n",
2282 total = istl_size + intl_size + atl_size;
2285 for (i = 0; i < 2; i++) {
2286 isp1362_hcd->
istl_queue[
i].buf_start = i * istl_size / 2,
2287 isp1362_hcd->
istl_queue[
i].buf_size = istl_size / 2;
2289 INIT_LIST_HEAD(&isp1362_hcd->
istl_queue[i].active);
2291 sizeof(isp1362_hcd->
istl_queue[i].name),
"ISTL%d", i);
2292 DBG(3,
"%s: %5s buf $%04x %d\n", __func__,
2299 isp1362_hcd->
intl_queue.buf_start = istl_size;
2300 isp1362_hcd->
intl_queue.buf_size = intl_size;
2302 isp1362_hcd->
intl_queue.blk_size = intl_blksize;
2305 INIT_LIST_HEAD(&isp1362_hcd->
intl_queue.active);
2310 isp1362_hcd->
intl_queue.blk_size - PTD_HEADER_SIZE);
2315 isp1362_hcd->
atl_queue.buf_start = istl_size + intl_size;
2316 isp1362_hcd->
atl_queue.buf_size = atl_size;
2317 isp1362_hcd->
atl_queue.buf_count = atl_buffers;
2318 isp1362_hcd->
atl_queue.blk_size = atl_blksize;
2321 INIT_LIST_HEAD(&isp1362_hcd->
atl_queue.active);
2326 isp1362_hcd->
atl_queue.blk_size - PTD_HEADER_SIZE);
2329 1 << (atl_buffers - 1));
2332 sizeof(isp1362_hcd->
atl_queue.name),
"ATL");
2334 sizeof(isp1362_hcd->
intl_queue.name),
"INTL");
2335 DBG(3,
"%s: %5s buf $%04x %2d * %4d = %4d\n", __func__,
2340 DBG(3,
"%s: %5s buf $%04x %2d * %4d = %4d\n", __func__,
2343 atl_buffers, isp1362_hcd->
atl_queue.blk_size,
2346 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2351 static int isp1362_hc_reset(
struct usb_hcd *hcd)
2354 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2357 unsigned long flags;
2362 if (isp1362_hcd->
board && isp1362_hcd->
board->reset) {
2363 isp1362_hcd->
board->reset(hcd->self.controller, 1);
2365 if (isp1362_hcd->
board->clock)
2366 isp1362_hcd->
board->clock(hcd->self.controller, 1);
2367 isp1362_hcd->
board->reset(hcd->self.controller, 0);
2369 isp1362_sw_reset(isp1362_hcd);
2376 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2383 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2385 pr_err(
"Clock not ready after %lums\n", timeout);
2391 static void isp1362_hc_stop(
struct usb_hcd *hcd)
2393 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2394 unsigned long flags;
2412 if (isp1362_hcd->
board && isp1362_hcd->
board->reset)
2413 isp1362_hcd->
board->reset(hcd->self.controller, 1);
2415 __isp1362_sw_reset(isp1362_hcd);
2417 if (isp1362_hcd->
board && isp1362_hcd->
board->clock)
2418 isp1362_hcd->
board->clock(hcd->self.controller, 0);
2420 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2423 #ifdef CHIP_BUFFER_TEST
2424 static int isp1362_chip_test(
struct isp1362_hcd *isp1362_hcd)
2428 unsigned long flags;
2440 for (offset = 0; offset < 4; offset++) {
2443 for (j = 0; j < 8; j++) {
2445 isp1362_write_buffer(isp1362_hcd, (
u8 *)ref + offset, 0, j);
2446 isp1362_read_buffer(isp1362_hcd, (
u8 *)tst + offset, 0, j);
2447 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2449 if (
memcmp(ref, tst, j)) {
2451 pr_err(
"%s: memory check with %d byte offset %d failed\n",
2452 __func__, j, offset);
2462 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2466 pr_err(
"%s: memory check failed\n", __func__);
2470 for (offset = 0; offset < 256; offset++) {
2479 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2482 pr_err(
"%s: Failed to clear buffer\n", __func__);
2487 isp1362_write_buffer(isp1362_hcd, ref, offset * 2, PTD_HEADER_SIZE);
2488 isp1362_write_buffer(isp1362_hcd, ref + PTD_HEADER_SIZE /
sizeof(*ref),
2489 offset * 2 + PTD_HEADER_SIZE, test_size);
2490 isp1362_read_buffer(isp1362_hcd, tst, offset * 2,
2491 PTD_HEADER_SIZE + test_size);
2492 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2493 if (
memcmp(ref, tst, PTD_HEADER_SIZE + test_size)) {
2494 dump_data(((
u8 *)ref) + offset, PTD_HEADER_SIZE + test_size);
2495 dump_data((
u8 *)tst, PTD_HEADER_SIZE + test_size);
2497 isp1362_read_buffer(isp1362_hcd, tst, offset * 2,
2498 PTD_HEADER_SIZE + test_size);
2499 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2500 if (
memcmp(ref, tst, PTD_HEADER_SIZE + test_size)) {
2502 pr_err(
"%s: memory check with offset %02x failed\n",
2506 pr_warning(
"%s: memory check with offset %02x ok after second read\n",
2516 static int isp1362_hc_start(
struct usb_hcd *hcd)
2519 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2523 unsigned long flags;
2529 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2532 pr_err(
"%s: Invalid chip ID %04x\n", __func__, chipid);
2536 #ifdef CHIP_BUFFER_TEST
2537 ret = isp1362_chip_test(isp1362_hcd);
2566 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2568 ret = isp1362_mem_config(hcd);
2597 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2600 hcd->state = HC_STATE_RUNNING;
2615 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2622 static struct hc_driver isp1362_hc_driver = {
2623 .description = hcd_name,
2624 .product_desc =
"ISP1362 Host Controller",
2625 .hcd_priv_size =
sizeof(
struct isp1362_hcd),
2628 .flags = HCD_USB11 | HCD_MEMORY,
2630 .reset = isp1362_hc_reset,
2631 .start = isp1362_hc_start,
2632 .stop = isp1362_hc_stop,
2634 .urb_enqueue = isp1362_urb_enqueue,
2635 .urb_dequeue = isp1362_urb_dequeue,
2636 .endpoint_disable = isp1362_endpoint_disable,
2638 .get_frame_number = isp1362_get_frame,
2640 .hub_status_data = isp1362_hub_status_data,
2641 .hub_control = isp1362_hub_control,
2650 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2651 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2655 DBG(0,
"%s: Removing HCD\n", __func__);
2658 DBG(0,
"%s: Unmapping data_reg @ %p\n", __func__,
2662 DBG(0,
"%s: Unmapping addr_reg @ %p\n", __func__,
2667 DBG(0,
"%s: release mem_region: %08lx\n", __func__, (
long unsigned int)res->
start);
2672 DBG(0,
"%s: release mem_region: %08lx\n", __func__, (
long unsigned int)res->
start);
2676 DBG(0,
"%s: put_hcd\n", __func__);
2678 DBG(0,
"%s: Done\n", __func__);
2685 struct usb_hcd *hcd;
2686 struct isp1362_hcd *isp1362_hcd;
2693 unsigned int irq_flags = 0;
2711 if (!addr || !data || !irq_res) {
2715 irq = irq_res->
start;
2717 if (pdev->
dev.dma_mask) {
2718 DBG(1,
"won't do DMA");
2728 if (addr_reg ==
NULL) {
2738 if (data_reg ==
NULL) {
2749 hcd->rsrc_start = data->
start;
2750 isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2756 INIT_LIST_HEAD(&isp1362_hcd->
async);
2757 INIT_LIST_HEAD(&isp1362_hcd->
periodic);
2758 INIT_LIST_HEAD(&isp1362_hcd->
isoc);
2760 isp1362_hcd->
board = pdev->
dev.platform_data;
2761 #if USE_PLATFORM_DELAY
2762 if (!isp1362_hcd->
board->delay) {
2763 dev_err(hcd->self.controller,
"No platform delay function given\n");
2781 pr_info(
"%s, irq %d\n", hcd->product_desc, irq);
2788 DBG(0,
"%s: Freeing dev %p\n", __func__, isp1362_hcd);
2791 DBG(0,
"%s: Unmapping data_reg @ %p\n", __func__, data_reg);
2794 DBG(0,
"%s: Releasing mem region %08lx\n", __func__, (
long unsigned int)data->
start);
2797 DBG(0,
"%s: Unmapping addr_reg @ %p\n", __func__, addr_reg);
2800 DBG(0,
"%s: Releasing mem region %08lx\n", __func__, (
long unsigned int)addr->
start);
2803 pr_err(
"%s: init error, %d\n", __func__, retval);
2811 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2812 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2813 unsigned long flags;
2816 DBG(0,
"%s: Suspending device\n", __func__);
2819 DBG(0,
"%s: Suspending root hub\n", __func__);
2822 DBG(0,
"%s: Suspending RH ports\n", __func__);
2825 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2828 pdev->
dev.power.power_state =
state;
2834 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2835 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2836 unsigned long flags;
2838 DBG(0,
"%s: Resuming\n", __func__);
2841 DBG(0,
"%s: Resume RH ports\n", __func__);
2844 spin_unlock_irqrestore(&isp1362_hcd->
lock, flags);
2853 #define isp1362_suspend NULL
2854 #define isp1362_resume NULL
2858 .probe = isp1362_probe,
2864 .name = (
char *)hcd_name,