Lines Matching +full:dbg +full:- +full:halt

1 // SPDX-License-Identifier: GPL-2.0
3 * Toshiba TC86C001 ("Goku-S") USB Device Controller driver
5 * Copyright (C) 2000-2002 Lineo
12 * This device has ep0 and three semi-configurable bulk/interrupt endpoints.
14 * - Endpoint numbering is fixed: ep{1,2,3}-bulk
15 * - Gadget drivers can choose ep maxpacket (8/16/32/64)
16 * - Gadget drivers can choose direction (IN, OUT)
17 * - DMA works with ep1 (OUT transfers) and ep2 (IN transfers).
21 // #define USB_TRACE /* packet-level success messages */
49 #define DRIVER_VERSION "30-Oct 2003"
60 * IN dma behaves ok under testing, though the IN-dma abort paths don't
65 * if the OUT-dma abort problems had a resolution.
79 /*-------------------------------------------------------------------------*/
86 writel(COMMAND_EP(epnum) | command, &regs->Command); in command()
101 || desc->bDescriptorType != USB_DT_ENDPOINT) in goku_ep_enable()
102 return -EINVAL; in goku_ep_enable()
103 dev = ep->dev; in goku_ep_enable()
104 if (ep == &dev->ep[0]) in goku_ep_enable()
105 return -EINVAL; in goku_ep_enable()
106 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) in goku_ep_enable()
107 return -ESHUTDOWN; in goku_ep_enable()
108 if (ep->num != usb_endpoint_num(desc)) in goku_ep_enable()
109 return -EINVAL; in goku_ep_enable()
116 return -EINVAL; in goku_ep_enable()
119 if ((readl(ep->reg_status) & EPxSTATUS_EP_MASK) in goku_ep_enable()
121 return -EBUSY; in goku_ep_enable()
123 /* enabling the no-toggle interrupt mode would need an api hook */ in goku_ep_enable()
125 max = get_unaligned_le16(&desc->wMaxPacketSize); in goku_ep_enable()
140 return -EINVAL; in goku_ep_enable()
142 mode |= 2 << 1; /* bulk, or intr-with-toggle */ in goku_ep_enable()
145 * direction, with pio. be cautious with out-dma. in goku_ep_enable()
147 ep->is_in = usb_endpoint_dir_in(desc); in goku_ep_enable()
148 if (ep->is_in) { in goku_ep_enable()
150 ep->dma = (use_dma != 0) && (ep->num == UDC_MSTRD_ENDPOINT); in goku_ep_enable()
152 ep->dma = (use_dma == 2) && (ep->num == UDC_MSTWR_ENDPOINT); in goku_ep_enable()
153 if (ep->dma) in goku_ep_enable()
154 DBG(dev, "%s out-dma hides short packets\n", in goku_ep_enable()
155 ep->ep.name); in goku_ep_enable()
158 spin_lock_irqsave(&ep->dev->lock, flags); in goku_ep_enable()
161 if (ep->num < 3) { in goku_ep_enable()
162 struct goku_udc_regs __iomem *regs = ep->dev->regs; in goku_ep_enable()
166 tmp = ((ep->dma || !ep->is_in) in goku_ep_enable()
169 ) << ep->num; in goku_ep_enable()
170 tmp |= readl(&regs->EPxSingle); in goku_ep_enable()
171 writel(tmp, &regs->EPxSingle); in goku_ep_enable()
173 tmp = (ep->dma ? 0x10/*dma*/ : 0x11/*pio*/) << ep->num; in goku_ep_enable()
174 tmp |= readl(&regs->EPxBCS); in goku_ep_enable()
175 writel(tmp, &regs->EPxBCS); in goku_ep_enable()
177 writel(mode, ep->reg_mode); in goku_ep_enable()
178 command(ep->dev->regs, COMMAND_RESET, ep->num); in goku_ep_enable()
179 ep->ep.maxpacket = max; in goku_ep_enable()
180 ep->stopped = 0; in goku_ep_enable()
181 ep->ep.desc = desc; in goku_ep_enable()
182 spin_unlock_irqrestore(&ep->dev->lock, flags); in goku_ep_enable()
184 DBG(dev, "enable %s %s %s maxpacket %u\n", ep->ep.name, in goku_ep_enable()
185 ep->is_in ? "IN" : "OUT", in goku_ep_enable()
186 ep->dma ? "dma" : "pio", in goku_ep_enable()
194 struct goku_udc *dev = ep->dev; in ep_reset()
197 command(regs, COMMAND_INVALID, ep->num); in ep_reset()
198 if (ep->num) { in ep_reset()
199 if (ep->num == UDC_MSTWR_ENDPOINT) in ep_reset()
200 dev->int_enable &= ~(INT_MSTWREND in ep_reset()
202 else if (ep->num == UDC_MSTRD_ENDPOINT) in ep_reset()
203 dev->int_enable &= ~INT_MSTRDEND; in ep_reset()
204 dev->int_enable &= ~INT_EPxDATASET (ep->num); in ep_reset()
206 dev->int_enable &= ~INT_EP0; in ep_reset()
207 writel(dev->int_enable, &regs->int_enable); in ep_reset()
208 readl(&regs->int_enable); in ep_reset()
209 if (ep->num < 3) { in ep_reset()
210 struct goku_udc_regs __iomem *r = ep->dev->regs; in ep_reset()
213 tmp = readl(&r->EPxSingle); in ep_reset()
214 tmp &= ~(0x11 << ep->num); in ep_reset()
215 writel(tmp, &r->EPxSingle); in ep_reset()
217 tmp = readl(&r->EPxBCS); in ep_reset()
218 tmp &= ~(0x11 << ep->num); in ep_reset()
219 writel(tmp, &r->EPxBCS); in ep_reset()
222 if (ep->dma) { in ep_reset()
225 master = readl(&regs->dma_master) & MST_RW_BITS; in ep_reset()
226 if (ep->num == UDC_MSTWR_ENDPOINT) { in ep_reset()
233 writel(master, &regs->dma_master); in ep_reset()
237 usb_ep_set_maxpacket_limit(&ep->ep, MAX_FIFO_SIZE); in ep_reset()
238 ep->ep.desc = NULL; in ep_reset()
239 ep->stopped = 1; in ep_reset()
240 ep->irqs = 0; in ep_reset()
241 ep->dma = 0; in ep_reset()
251 if (!_ep || !ep->ep.desc) in goku_ep_disable()
252 return -ENODEV; in goku_ep_disable()
253 dev = ep->dev; in goku_ep_disable()
254 if (dev->ep0state == EP0_SUSPEND) in goku_ep_disable()
255 return -EBUSY; in goku_ep_disable()
257 VDBG(dev, "disable %s\n", _ep->name); in goku_ep_disable()
259 spin_lock_irqsave(&dev->lock, flags); in goku_ep_disable()
260 nuke(ep, -ESHUTDOWN); in goku_ep_disable()
261 ep_reset(dev->regs, ep); in goku_ep_disable()
262 spin_unlock_irqrestore(&dev->lock, flags); in goku_ep_disable()
267 /*-------------------------------------------------------------------------*/
280 INIT_LIST_HEAD(&req->queue); in goku_alloc_request()
281 return &req->req; in goku_alloc_request()
293 WARN_ON(!list_empty(&req->queue)); in goku_free_request()
297 /*-------------------------------------------------------------------------*/
303 unsigned stopped = ep->stopped; in done()
305 list_del_init(&req->queue); in done()
307 if (likely(req->req.status == -EINPROGRESS)) in done()
308 req->req.status = status; in done()
310 status = req->req.status; in done()
312 dev = ep->dev; in done()
314 if (ep->dma) in done()
315 usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in); in done()
318 if (status && status != -ESHUTDOWN) in done()
321 ep->ep.name, &req->req, status, in done()
322 req->req.actual, req->req.length); in done()
325 ep->stopped = 1; in done()
326 spin_unlock(&dev->lock); in done()
327 usb_gadget_giveback_request(&ep->ep, &req->req); in done()
328 spin_lock(&dev->lock); in done()
329 ep->stopped = stopped; in done()
332 /*-------------------------------------------------------------------------*/
339 length = min(req->req.length - req->req.actual, max); in write_packet()
340 req->req.actual += length; in write_packet()
343 while (likely(count--)) in write_packet()
351 struct goku_udc *dev = ep->dev; in write_fifo()
357 tmp = readl(&dev->regs->DataSet); in write_fifo()
358 buf = req->req.buf + req->req.actual; in write_fifo()
361 dev = ep->dev; in write_fifo()
362 if (unlikely(ep->num == 0 && dev->ep0state != EP0_IN)) in write_fifo()
363 return -EL2HLT; in write_fifo()
365 /* NOTE: just single-buffered PIO-IN for now. */ in write_fifo()
366 if (unlikely((tmp & DATASET_A(ep->num)) != 0)) in write_fifo()
370 if (ep->num != 0) in write_fifo()
371 writel(~INT_EPxDATASET(ep->num), &dev->regs->int_status); in write_fifo()
373 count = write_packet(ep->reg_fifo, buf, req, ep->ep.maxpacket); in write_fifo()
376 if (unlikely(count != ep->ep.maxpacket)) { in write_fifo()
377 writel(~(1<<ep->num), &dev->regs->EOP); in write_fifo()
378 if (ep->num == 0) { in write_fifo()
379 dev->ep[0].stopped = 1; in write_fifo()
380 dev->ep0state = EP0_STATUS; in write_fifo()
384 if (likely(req->req.length != req->req.actual) in write_fifo()
385 || req->req.zero) in write_fifo()
393 ep->ep.name, count, is_last ? "/last" : "", in write_fifo()
394 req->req.length - req->req.actual, req); in write_fifo()
415 regs = ep->dev->regs; in read_fifo()
417 buf = req->req.buf + req->req.actual; in read_fifo()
420 if (unlikely(ep->num == 0 && ep->dev->ep0state != EP0_OUT)) in read_fifo()
421 return -EL2HLT; in read_fifo()
423 dbuff = (ep->num == 1 || ep->num == 2); in read_fifo()
426 if (ep->num != 0) in read_fifo()
427 writel(~INT_EPxDATASET(ep->num), &regs->int_status); in read_fifo()
429 set = readl(&regs->DataSet) & DATASET_AB(ep->num); in read_fifo()
430 size = readl(&regs->EPxSizeLA[ep->num]); in read_fifo()
431 bufferspace = req->req.length - req->req.actual; in read_fifo()
434 if (likely(ep->num != 0 || bufferspace != 0)) { in read_fifo()
437 /* use ep1/ep2 double-buffering for OUT */ in read_fifo()
439 size = readl(&regs->EPxSizeLB[ep->num]); in read_fifo()
444 /* ep0out no-out-data case for set_config, etc */ in read_fifo()
449 req->req.actual += size; in read_fifo()
450 is_short = (size < ep->ep.maxpacket); in read_fifo()
452 VDBG(ep->dev, "read %s %u bytes%s OUT req %p %u/%u\n", in read_fifo()
453 ep->ep.name, size, is_short ? "/S" : "", in read_fifo()
454 req, req->req.actual, req->req.length); in read_fifo()
456 while (likely(size-- != 0)) { in read_fifo()
457 u8 byte = (u8) readl(ep->reg_fifo); in read_fifo()
464 if (req->req.status != -EOVERFLOW) in read_fifo()
465 DBG(ep->dev, "%s overflow %u\n", in read_fifo()
466 ep->ep.name, size); in read_fifo()
467 req->req.status = -EOVERFLOW; in read_fifo()
470 bufferspace--; in read_fifo()
475 if (unlikely(is_short || req->req.actual == req->req.length)) { in read_fifo()
476 if (unlikely(ep->num == 0)) { in read_fifo()
477 /* non-control endpoints now usable? */ in read_fifo()
478 if (ep->dev->req_config) in read_fifo()
479 writel(ep->dev->configured in read_fifo()
482 &regs->UsbState); in read_fifo()
484 writel(~(1<<0), &regs->EOP); in read_fifo()
485 ep->stopped = 1; in read_fifo()
486 ep->dev->ep0state = EP0_STATUS; in read_fifo()
491 if (dbuff && !list_empty(&ep->queue)) { in read_fifo()
492 req = list_entry(ep->queue.next, in read_fifo()
506 dev->int_enable |= INT_EPxDATASET (epnum); in pio_irq_enable()
507 writel(dev->int_enable, &regs->int_enable); in pio_irq_enable()
515 dev->int_enable &= ~INT_EPxDATASET (epnum); in pio_irq_disable()
516 writel(dev->int_enable, &regs->int_enable); in pio_irq_disable()
525 if (unlikely(list_empty (&ep->queue))) in pio_advance()
527 req = list_entry(ep->queue.next, struct goku_request, queue); in pio_advance()
528 (ep->is_in ? write_fifo : read_fifo)(ep, req); in pio_advance()
532 /*-------------------------------------------------------------------------*/
537 struct goku_udc_regs __iomem *regs = ep->dev->regs; in start_dma()
539 u32 start = req->req.dma; in start_dma()
540 u32 end = start + req->req.length - 1; in start_dma()
542 master = readl(&regs->dma_master) & MST_RW_BITS; in start_dma()
544 /* re-init the bits affecting IN dma; careful with zlps */ in start_dma()
545 if (likely(ep->is_in)) { in start_dma()
547 DBG (ep->dev, "start, IN active dma %03x!!\n", in start_dma()
549 // return -EL2HLT; in start_dma()
551 writel(end, &regs->in_dma_end); in start_dma()
552 writel(start, &regs->in_dma_start); in start_dma()
555 if (unlikely(req->req.length == 0)) in start_dma()
557 else if ((req->req.length % ep->ep.maxpacket) != 0 in start_dma()
558 || req->req.zero) in start_dma()
563 ep->dev->int_enable |= INT_MSTRDEND; in start_dma()
565 /* Goku DMA-OUT merges short packets, which plays poorly with in start_dma()
572 DBG (ep->dev, "start, OUT active dma %03x!!\n", in start_dma()
574 // return -EL2HLT; in start_dma()
576 writel(end, &regs->out_dma_end); in start_dma()
577 writel(start, &regs->out_dma_start); in start_dma()
582 ep->dev->int_enable |= INT_MSTWREND|INT_MSTWRTMOUT; in start_dma()
585 writel(master, &regs->dma_master); in start_dma()
586 writel(ep->dev->int_enable, &regs->int_enable); in start_dma()
593 struct goku_udc_regs __iomem *regs = ep->dev->regs; in dma_advance()
596 master = readl(&regs->dma_master); in dma_advance()
598 if (unlikely(list_empty(&ep->queue))) { in dma_advance()
600 if (ep->is_in) in dma_advance()
601 dev->int_enable &= ~INT_MSTRDEND; in dma_advance()
603 dev->int_enable &= ~(INT_MSTWREND|INT_MSTWRTMOUT); in dma_advance()
604 writel(dev->int_enable, &regs->int_enable); in dma_advance()
607 req = list_entry(ep->queue.next, struct goku_request, queue); in dma_advance()
610 if (likely(ep->is_in)) { in dma_advance()
613 req->req.actual = readl(&regs->in_dma_current); in dma_advance()
621 req->req.actual = readl(&regs->out_dma_current); in dma_advance()
623 req->req.actual -= req->req.dma; in dma_advance()
624 req->req.actual++; in dma_advance()
628 ep->ep.name, ep->is_in ? "IN" : "OUT", in dma_advance()
629 req->req.actual, req->req.length, req); in dma_advance()
632 if (list_empty(&ep->queue)) in dma_advance()
634 req = list_entry(ep->queue.next, struct goku_request, queue); in dma_advance()
640 struct goku_udc_regs __iomem *regs = ep->dev->regs; in abort_dma()
649 * we can't do that for IN without side effects to HALT and TOGGLE. in abort_dma()
651 command(regs, COMMAND_FIFO_DISABLE, ep->num); in abort_dma()
652 req = list_entry(ep->queue.next, struct goku_request, queue); in abort_dma()
653 master = readl(&regs->dma_master) & MST_RW_BITS; in abort_dma()
660 if (ep->is_in) { in abort_dma()
661 if (unlikely((readl(&regs->dma_master) & MST_RD_ENA) == 0)) in abort_dma()
663 curr = readl(&regs->in_dma_current); in abort_dma()
665 writel(curr, &regs->in_dma_end); in abort_dma()
666 writel(curr, &regs->in_dma_start); in abort_dma()
670 writel(master, &regs->dma_master); in abort_dma()
672 if (readl(&regs->dma_master) & MST_RD_ENA) in abort_dma()
673 DBG(ep->dev, "IN dma active after reset!\n"); in abort_dma()
676 if (unlikely((readl(&regs->dma_master) & MST_WR_ENA) == 0)) in abort_dma()
678 curr = readl(&regs->out_dma_current); in abort_dma()
680 writel(curr, &regs->out_dma_end); in abort_dma()
681 writel(curr, &regs->out_dma_start); in abort_dma()
685 writel(master, &regs->dma_master); in abort_dma()
687 if (readl(&regs->dma_master) & MST_WR_ENA) in abort_dma()
688 DBG(ep->dev, "OUT dma active after reset!\n"); in abort_dma()
690 req->req.actual = (curr - req->req.dma) + 1; in abort_dma()
691 req->req.status = status; in abort_dma()
693 VDBG(ep->dev, "%s %s %s %d/%d\n", __func__, ep->ep.name, in abort_dma()
694 ep->is_in ? "IN" : "OUT", in abort_dma()
695 req->req.actual, req->req.length); in abort_dma()
697 command(regs, COMMAND_FIFO_ENABLE, ep->num); in abort_dma()
703 command(regs, COMMAND_FIFO_ENABLE, ep->num); in abort_dma()
704 req->req.actual = req->req.length; in abort_dma()
705 req->req.status = 0; in abort_dma()
708 /*-------------------------------------------------------------------------*/
719 /* always require a cpu-view buffer so pio works */ in goku_queue()
721 if (unlikely(!_req || !_req->complete in goku_queue()
722 || !_req->buf || !list_empty(&req->queue))) in goku_queue()
723 return -EINVAL; in goku_queue()
725 if (unlikely(!_ep || (!ep->ep.desc && ep->num != 0))) in goku_queue()
726 return -EINVAL; in goku_queue()
727 dev = ep->dev; in goku_queue()
728 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) in goku_queue()
729 return -ESHUTDOWN; in goku_queue()
732 if (dev->ep0state == EP0_SUSPEND) in goku_queue()
733 return -EBUSY; in goku_queue()
736 if (ep->dma) { in goku_queue()
737 status = usb_gadget_map_request(&dev->gadget, &req->req, in goku_queue()
738 ep->is_in); in goku_queue()
745 _ep->name, _req, _req->length, _req->buf); in goku_queue()
748 spin_lock_irqsave(&dev->lock, flags); in goku_queue()
750 _req->status = -EINPROGRESS; in goku_queue()
751 _req->actual = 0; in goku_queue()
756 if (unlikely(ep->num == 0 && ep->is_in)) in goku_queue()
757 _req->zero = 1; in goku_queue()
761 if (list_empty(&ep->queue) && likely(!ep->stopped)) { in goku_queue()
765 if (ep->dma) in goku_queue()
768 status = (ep->is_in ? write_fifo : read_fifo)(ep, req); in goku_queue()
779 list_add_tail(&req->queue, &ep->queue); in goku_queue()
781 if (likely(!list_empty(&ep->queue)) in goku_queue()
782 && likely(ep->num != 0) in goku_queue()
783 && !ep->dma in goku_queue()
784 && !(dev->int_enable & INT_EPxDATASET (ep->num))) in goku_queue()
785 pio_irq_enable(dev, dev->regs, ep->num); in goku_queue()
787 spin_unlock_irqrestore(&dev->lock, flags); in goku_queue()
798 ep->stopped = 1; in nuke()
799 if (list_empty(&ep->queue)) in nuke()
801 if (ep->dma) in nuke()
803 while (!list_empty(&ep->queue)) { in nuke()
804 req = list_entry(ep->queue.next, struct goku_request, queue); in nuke()
818 if (!_ep || !_req || (!ep->ep.desc && ep->num != 0)) in goku_dequeue()
819 return -EINVAL; in goku_dequeue()
820 dev = ep->dev; in goku_dequeue()
821 if (!dev->driver) in goku_dequeue()
822 return -ESHUTDOWN; in goku_dequeue()
825 if (dev->ep0state == EP0_SUSPEND) in goku_dequeue()
826 return -EBUSY; in goku_dequeue()
828 VDBG(dev, "%s %s %s %s %p\n", __func__, _ep->name, in goku_dequeue()
829 ep->is_in ? "IN" : "OUT", in goku_dequeue()
830 ep->dma ? "dma" : "pio", in goku_dequeue()
833 spin_lock_irqsave(&dev->lock, flags); in goku_dequeue()
836 list_for_each_entry(iter, &ep->queue, queue) { in goku_dequeue()
837 if (&iter->req != _req) in goku_dequeue()
843 spin_unlock_irqrestore (&dev->lock, flags); in goku_dequeue()
844 return -EINVAL; in goku_dequeue()
847 if (ep->dma && ep->queue.next == &req->queue && !ep->stopped) { in goku_dequeue()
848 abort_dma(ep, -ECONNRESET); in goku_dequeue()
849 done(ep, req, -ECONNRESET); in goku_dequeue()
851 } else if (!list_empty(&req->queue)) in goku_dequeue()
852 done(ep, req, -ECONNRESET); in goku_dequeue()
855 spin_unlock_irqrestore(&dev->lock, flags); in goku_dequeue()
857 return req ? 0 : -EOPNOTSUPP; in goku_dequeue()
860 /*-------------------------------------------------------------------------*/
864 // assert (ep->num !=0) in goku_clear_halt()
865 VDBG(ep->dev, "%s clear halt\n", ep->ep.name); in goku_clear_halt()
866 command(ep->dev->regs, COMMAND_SETDATA0, ep->num); in goku_clear_halt()
867 command(ep->dev->regs, COMMAND_STALL_CLEAR, ep->num); in goku_clear_halt()
868 if (ep->stopped) { in goku_clear_halt()
869 ep->stopped = 0; in goku_clear_halt()
870 if (ep->dma) { in goku_clear_halt()
873 if (list_empty(&ep->queue)) in goku_clear_halt()
875 req = list_entry(ep->queue.next, struct goku_request, in goku_clear_halt()
890 return -ENODEV; in goku_set_halt()
893 if (ep->num == 0) { in goku_set_halt()
895 ep->dev->ep0state = EP0_STALL; in goku_set_halt()
896 ep->dev->ep[0].stopped = 1; in goku_set_halt()
898 return -EINVAL; in goku_set_halt()
901 } else if (!ep->ep.desc) { in goku_set_halt()
902 DBG(ep->dev, "%s %s inactive?\n", __func__, ep->ep.name); in goku_set_halt()
903 return -EINVAL; in goku_set_halt()
906 spin_lock_irqsave(&ep->dev->lock, flags); in goku_set_halt()
907 if (!list_empty(&ep->queue)) in goku_set_halt()
908 retval = -EAGAIN; in goku_set_halt()
909 else if (ep->is_in && value in goku_set_halt()
911 && (readl(&ep->dev->regs->DataSet) in goku_set_halt()
912 & DATASET_AB(ep->num))) in goku_set_halt()
913 retval = -EAGAIN; in goku_set_halt()
917 ep->stopped = 1; in goku_set_halt()
918 VDBG(ep->dev, "%s set halt\n", ep->ep.name); in goku_set_halt()
919 command(ep->dev->regs, COMMAND_STALL, ep->num); in goku_set_halt()
920 readl(ep->reg_status); in goku_set_halt()
922 spin_unlock_irqrestore(&ep->dev->lock, flags); in goku_set_halt()
933 return -ENODEV; in goku_fifo_status()
937 if (ep->is_in) in goku_fifo_status()
938 return -EOPNOTSUPP; in goku_fifo_status()
940 /* ignores 16-byte dma buffer; SizeH == 0 */ in goku_fifo_status()
941 regs = ep->dev->regs; in goku_fifo_status()
942 size = readl(&regs->EPxSizeLA[ep->num]) & DATASIZE; in goku_fifo_status()
943 size += readl(&regs->EPxSizeLB[ep->num]) & DATASIZE; in goku_fifo_status()
944 VDBG(ep->dev, "%s %s %u\n", __func__, ep->ep.name, size); in goku_fifo_status()
957 VDBG(ep->dev, "%s %s\n", __func__, ep->ep.name); in goku_fifo_flush()
960 if (!ep->ep.desc && ep->num != 0) { in goku_fifo_flush()
961 DBG(ep->dev, "%s %s inactive?\n", __func__, ep->ep.name); in goku_fifo_flush()
965 regs = ep->dev->regs; in goku_fifo_flush()
966 size = readl(&regs->EPxSizeLA[ep->num]); in goku_fifo_flush()
969 /* Non-desirable behavior: FIFO_CLEAR also clears the in goku_fifo_flush()
970 * endpoint halt feature. For OUT, we _could_ just read in goku_fifo_flush()
971 * the bytes out (PIO, if !ep->dma); for in, no choice. in goku_fifo_flush()
974 command(regs, COMMAND_FIFO_CLEAR, ep->num); in goku_fifo_flush()
992 /*-------------------------------------------------------------------------*/
996 return -EOPNOTSUPP; in goku_get_frame()
1009 ep = &dev->ep[3].ep; in goku_match_ep()
1016 ep = &dev->ep[2].ep; in goku_match_ep()
1041 /*-------------------------------------------------------------------------*/
1067 (mask & INT_MSTRDEND) ? " in-dma" : "", in dump_intmask()
1070 (mask & INT_MSTWREND) ? " out-dma" : "", in dump_intmask()
1139 struct goku_udc *dev = m->private; in udc_proc_read()
1140 struct goku_udc_regs __iomem *regs = dev->regs; in udc_proc_read()
1148 tmp = readl(&regs->power_detect); in udc_proc_read()
1151 "%s - %s\n" in udc_proc_read()
1156 pci_name(dev->pdev), driver_desc, in udc_proc_read()
1158 dev->driver ? dev->driver->driver.name : "(none)", in udc_proc_read()
1162 udc_ep_state(dev->ep0state)); in udc_proc_read()
1164 dump_intmask(m, "int_status", readl(&regs->int_status)); in udc_proc_read()
1165 dump_intmask(m, "int_enable", readl(&regs->int_enable)); in udc_proc_read()
1167 if (!is_usb_connected || !dev->driver || (tmp & PW_PULLUP) == 0) in udc_proc_read()
1172 dev->irqs, readl(&regs->DataSet), in udc_proc_read()
1173 readl(&regs->EPxSingle), readl(&regs->EPxBCS), in udc_proc_read()
1174 readl(&regs->UsbState), in udc_proc_read()
1175 readl(&regs->address)); in udc_proc_read()
1179 tmp = readl(&regs->dma_master); in udc_proc_read()
1182 (tmp & MST_EOPB_DIS) ? " eopb-" : "", in udc_proc_read()
1184 (tmp & MST_TIMEOUT_DIS) ? " tmo-" : "", in udc_proc_read()
1199 struct goku_ep *ep = &dev->ep [i]; in udc_proc_read()
1202 if (i && !ep->ep.desc) in udc_proc_read()
1205 tmp = readl(ep->reg_status); in udc_proc_read()
1207 ep->ep.name, in udc_proc_read()
1208 ep->is_in ? "in" : "out", in udc_proc_read()
1209 ep->ep.maxpacket, in udc_proc_read()
1210 ep->dma ? "dma" : "pio", in udc_proc_read()
1211 ep->irqs, in udc_proc_read()
1220 if (list_empty(&ep->queue)) { in udc_proc_read()
1226 list_for_each_entry(req, &ep->queue, queue) { in udc_proc_read()
1227 if (ep->dma && req->queue.prev == &ep->queue) { in udc_proc_read()
1229 tmp = readl(&regs->in_dma_current); in udc_proc_read()
1231 tmp = readl(&regs->out_dma_current); in udc_proc_read()
1232 tmp -= req->req.dma; in udc_proc_read()
1235 tmp = req->req.actual; in udc_proc_read()
1238 &req->req, tmp, req->req.length, in udc_proc_read()
1239 req->req.buf); in udc_proc_read()
1251 /*-------------------------------------------------------------------------*/
1255 static char *names [] = { "ep0", "ep1-bulk", "ep2-bulk", "ep3-bulk" }; in udc_reinit()
1259 INIT_LIST_HEAD (&dev->gadget.ep_list); in udc_reinit()
1260 dev->gadget.ep0 = &dev->ep [0].ep; in udc_reinit()
1261 dev->gadget.speed = USB_SPEED_UNKNOWN; in udc_reinit()
1262 dev->ep0state = EP0_DISCONNECT; in udc_reinit()
1263 dev->irqs = 0; in udc_reinit()
1266 struct goku_ep *ep = &dev->ep[i]; in udc_reinit()
1268 ep->num = i; in udc_reinit()
1269 ep->ep.name = names[i]; in udc_reinit()
1270 ep->reg_fifo = &dev->regs->ep_fifo [i]; in udc_reinit()
1271 ep->reg_status = &dev->regs->ep_status [i]; in udc_reinit()
1272 ep->reg_mode = &dev->regs->ep_mode[i]; in udc_reinit()
1274 ep->ep.ops = &goku_ep_ops; in udc_reinit()
1275 list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list); in udc_reinit()
1276 ep->dev = dev; in udc_reinit()
1277 INIT_LIST_HEAD (&ep->queue); in udc_reinit()
1282 ep->ep.caps.type_control = true; in udc_reinit()
1284 ep->ep.caps.type_bulk = true; in udc_reinit()
1286 ep->ep.caps.dir_in = true; in udc_reinit()
1287 ep->ep.caps.dir_out = true; in udc_reinit()
1290 dev->ep[0].reg_mode = NULL; in udc_reinit()
1291 usb_ep_set_maxpacket_limit(&dev->ep[0].ep, MAX_EP0_SIZE); in udc_reinit()
1292 list_del_init (&dev->ep[0].ep.ep_list); in udc_reinit()
1297 struct goku_udc_regs __iomem *regs = dev->regs; in udc_reset()
1299 writel(0, &regs->power_detect); in udc_reset()
1300 writel(0, &regs->int_enable); in udc_reset()
1301 readl(&regs->int_enable); in udc_reset()
1302 dev->int_enable = 0; in udc_reset()
1304 /* deassert reset, leave USB D+ at hi-Z (no pullup) in udc_reset()
1308 writel(PW_RESETB, &regs->power_detect); in udc_reset()
1309 readl(&regs->int_enable); in udc_reset()
1314 struct goku_udc_regs __iomem *regs = dev->regs; in ep0_start()
1321 //writel(MST_EOPB_ENA | MST_TIMEOUT_ENA, &regs->dma_master); in ep0_start()
1328 , &regs->reqmode); in ep0_start()
1331 dev->ep[i].irqs = 0; in ep0_start()
1335 writel(0, &regs->descriptors[i]); in ep0_start()
1336 writel(0, &regs->UsbReady); in ep0_start()
1339 writel(PW_RESETB | PW_PULLUP, &regs->power_detect); in ep0_start()
1340 dev->int_enable = INT_DEVWIDE | INT_EP0; in ep0_start()
1341 writel(dev->int_enable, &dev->regs->int_enable); in ep0_start()
1342 readl(&regs->int_enable); in ep0_start()
1343 dev->gadget.speed = USB_SPEED_FULL; in ep0_start()
1344 dev->ep0state = EP0_IDLE; in ep0_start()
1350 if (readl(&dev->regs->power_detect) & PW_DETECT) in udc_enable()
1353 DBG(dev, "%s\n", __func__); in udc_enable()
1354 dev->int_enable = INT_PWRDETECT; in udc_enable()
1355 writel(dev->int_enable, &dev->regs->int_enable); in udc_enable()
1359 /*-------------------------------------------------------------------------*/
1362 * - one bus driver, initted first;
1363 * - one function driver, initted second
1368 * non-control requests. then usb traffic follows until a
1378 dev->driver = driver; in goku_udc_start()
1393 DBG (dev, "%s\n", __func__); in stop_activity()
1398 nuke(&dev->ep [i], -ESHUTDOWN); in stop_activity()
1400 if (dev->driver) in stop_activity()
1409 spin_lock_irqsave(&dev->lock, flags); in goku_udc_stop()
1410 dev->driver = NULL; in goku_udc_stop()
1412 spin_unlock_irqrestore(&dev->lock, flags); in goku_udc_stop()
1417 /*-------------------------------------------------------------------------*/
1421 struct goku_udc_regs __iomem *regs = dev->regs; in ep0_setup()
1426 ctrl.bRequestType = readl(&regs->bRequestType); in ep0_setup()
1427 ctrl.bRequest = readl(&regs->bRequest); in ep0_setup()
1428 ctrl.wValue = cpu_to_le16((readl(&regs->wValueH) << 8) in ep0_setup()
1429 | readl(&regs->wValueL)); in ep0_setup()
1430 ctrl.wIndex = cpu_to_le16((readl(&regs->wIndexH) << 8) in ep0_setup()
1431 | readl(&regs->wIndexL)); in ep0_setup()
1432 ctrl.wLength = cpu_to_le16((readl(&regs->wLengthH) << 8) in ep0_setup()
1433 | readl(&regs->wLengthL)); in ep0_setup()
1434 writel(0, &regs->SetupRecv); in ep0_setup()
1436 nuke(&dev->ep[0], 0); in ep0_setup()
1437 dev->ep[0].stopped = 0; in ep0_setup()
1439 dev->ep[0].is_in = 1; in ep0_setup()
1440 dev->ep0state = EP0_IN; in ep0_setup()
1442 writel(ICONTROL_STATUSNAK, &dev->regs->IntControl); in ep0_setup()
1444 dev->ep[0].is_in = 0; in ep0_setup()
1445 dev->ep0state = EP0_OUT; in ep0_setup()
1449 * won't even enter the fifo until the halt is cleared. in ep0_setup()
1458 (!dev->ep[tmp].ep.desc && tmp != 0)) in ep0_setup()
1462 if (!dev->ep[tmp].is_in) in ep0_setup()
1465 if (dev->ep[tmp].is_in) in ep0_setup()
1472 goku_clear_halt(&dev->ep[tmp]); in ep0_setup()
1475 writel(~(1<<0), &regs->EOP); in ep0_setup()
1476 dev->ep[0].stopped = 1; in ep0_setup()
1477 dev->ep0state = EP0_STATUS; in ep0_setup()
1504 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION in ep0_setup()
1506 if (unlikely(dev->req_config)) in ep0_setup()
1507 dev->configured = (ctrl.wValue != cpu_to_le16(0)); in ep0_setup()
1512 spin_unlock (&dev->lock); in ep0_setup()
1513 tmp = dev->driver->setup(&dev->gadget, &ctrl); in ep0_setup()
1514 spin_lock (&dev->lock); in ep0_setup()
1522 dev->ep[0].stopped = 1; in ep0_setup()
1523 dev->ep0state = EP0_STALL; in ep0_setup()
1531 writel(~irqbit, &regs->int_status); \
1538 struct goku_udc_regs __iomem *regs = dev->regs; in goku_irq()
1543 spin_lock(&dev->lock); in goku_irq()
1546 stat = readl(&regs->int_status) & dev->int_enable; in goku_irq()
1549 dev->irqs++; in goku_irq()
1551 /* device-wide irqs */ in goku_irq()
1558 // FIXME have a neater way to prevent re-enumeration in goku_irq()
1559 dev->driver = NULL; in goku_irq()
1563 writel(~stat, &regs->int_status); in goku_irq()
1564 if (readl(&dev->regs->power_detect) & PW_DETECT) { in goku_irq()
1568 DBG(dev, "disconnect\n"); in goku_irq()
1569 if (dev->gadget.speed == USB_SPEED_FULL) in goku_irq()
1571 dev->ep0state = EP0_DISCONNECT; in goku_irq()
1572 dev->int_enable = INT_DEVWIDE; in goku_irq()
1573 writel(dev->int_enable, &dev->regs->int_enable); in goku_irq()
1581 if (readl(&regs->ep_status[0]) & EPxSTATUS_SUSPEND) { in goku_irq()
1582 switch (dev->ep0state) { in goku_irq()
1589 DBG(dev, "USB suspend\n"); in goku_irq()
1590 dev->ep0state = EP0_SUSPEND; in goku_irq()
1591 if (dev->gadget.speed != USB_SPEED_UNKNOWN in goku_irq()
1592 && dev->driver in goku_irq()
1593 && dev->driver->suspend) { in goku_irq()
1594 spin_unlock(&dev->lock); in goku_irq()
1595 dev->driver->suspend(&dev->gadget); in goku_irq()
1596 spin_lock(&dev->lock); in goku_irq()
1599 if (dev->ep0state != EP0_SUSPEND) { in goku_irq()
1600 DBG(dev, "bogus USB resume %d\n", in goku_irq()
1601 dev->ep0state); in goku_irq()
1604 DBG(dev, "USB resume\n"); in goku_irq()
1605 dev->ep0state = EP0_IDLE; in goku_irq()
1606 if (dev->gadget.speed != USB_SPEED_UNKNOWN in goku_irq()
1607 && dev->driver in goku_irq()
1608 && dev->driver->resume) { in goku_irq()
1609 spin_unlock(&dev->lock); in goku_irq()
1610 dev->driver->resume(&dev->gadget); in goku_irq()
1611 spin_lock(&dev->lock); in goku_irq()
1619 dev->driver->driver.name); in goku_irq()
1625 * no transition {EP0_STATUS, EP0_STALL} --> EP0_IDLE; saves irqs in goku_irq()
1629 dev->ep[0].irqs++; in goku_irq()
1634 if (dev->ep0state == EP0_IN) { in goku_irq()
1635 ep = &dev->ep[0]; in goku_irq()
1636 ep->irqs++; in goku_irq()
1638 writel(~(1<<0), &regs->EOP); in goku_irq()
1639 dev->ep0state = EP0_STATUS; in goku_irq()
1644 ep = &dev->ep[0]; in goku_irq()
1645 ep->irqs++; in goku_irq()
1652 ep = &dev->ep[UDC_MSTRD_ENDPOINT]; in goku_irq()
1653 ep->irqs++; in goku_irq()
1658 ep = &dev->ep[UDC_MSTWR_ENDPOINT]; in goku_irq()
1659 ep->irqs++; in goku_irq()
1664 ep = &dev->ep[UDC_MSTWR_ENDPOINT]; in goku_irq()
1665 ep->irqs++; in goku_irq()
1666 ERROR(dev, "%s write timeout ?\n", ep->ep.name); in goku_irq()
1676 ep = &dev->ep[i]; in goku_irq()
1678 if (list_empty (&ep->queue)) in goku_irq()
1682 ep->irqs++; in goku_irq()
1685 if (rescans--) in goku_irq()
1689 (void)readl(&regs->int_enable); in goku_irq()
1690 spin_unlock(&dev->lock); in goku_irq()
1692 DBG(dev, "unhandled irq status: %05x (%05x, %05x)\n", stat, in goku_irq()
1693 readl(&regs->int_status), dev->int_enable); in goku_irq()
1699 /*-------------------------------------------------------------------------*/
1714 DBG(dev, "%s\n", __func__); in goku_remove()
1716 usb_del_gadget_udc(&dev->gadget); in goku_remove()
1718 BUG_ON(dev->driver); in goku_remove()
1723 if (dev->regs) in goku_remove()
1725 if (dev->got_irq) in goku_remove()
1726 free_irq(pdev->irq, dev); in goku_remove()
1727 if (dev->regs) in goku_remove()
1728 iounmap(dev->regs); in goku_remove()
1729 if (dev->got_region) in goku_remove()
1732 if (dev->enabled) in goku_remove()
1735 dev->regs = NULL; in goku_remove()
1751 if (!pdev->irq) { in goku_probe()
1753 retval = -ENODEV; in goku_probe()
1760 retval = -ENOMEM; in goku_probe()
1765 spin_lock_init(&dev->lock); in goku_probe()
1766 dev->pdev = pdev; in goku_probe()
1767 dev->gadget.ops = &goku_ops; in goku_probe()
1768 dev->gadget.max_speed = USB_SPEED_FULL; in goku_probe()
1771 dev->gadget.name = driver_name; in goku_probe()
1776 DBG(dev, "can't enable, %d\n", retval); in goku_probe()
1779 dev->enabled = 1; in goku_probe()
1784 DBG(dev, "controller already in use\n"); in goku_probe()
1785 retval = -EBUSY; in goku_probe()
1788 dev->got_region = 1; in goku_probe()
1792 DBG(dev, "can't map memory\n"); in goku_probe()
1793 retval = -EFAULT; in goku_probe()
1796 dev->regs = (struct goku_udc_regs __iomem *) base; in goku_probe()
1800 INFO(dev, "irq %d, pci mem %p\n", pdev->irq, base); in goku_probe()
1805 if (request_irq(pdev->irq, goku_irq, IRQF_SHARED, in goku_probe()
1807 DBG(dev, "request interrupt %d failed\n", pdev->irq); in goku_probe()
1808 retval = -EBUSY; in goku_probe()
1811 dev->got_irq = 1; in goku_probe()
1820 retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget, in goku_probe()
1836 /*-------------------------------------------------------------------------*/