41 #include <linux/module.h>
42 #include <linux/pci.h>
44 #include <linux/kernel.h>
47 #include <linux/slab.h>
48 #include <linux/errno.h>
51 #include <linux/list.h>
54 #include <linux/device.h>
55 #include <linux/usb/ch9.h>
57 #include <linux/prefetch.h>
59 #include <asm/byteorder.h>
62 #include <asm/unaligned.h>
65 #define DRIVER_DESC "PLX NET228x USB Peripheral Controller"
66 #define DRIVER_VERSION "2005 Sept 27"
68 #define DMA_ADDR_INVALID (~(dma_addr_t)0)
77 static const char ep0name [] =
"ep0";
78 static const char *
const ep_name [] = {
80 "ep-a",
"ep-b",
"ep-c",
"ep-d",
93 static bool use_dma_chaining = 0;
104 static ushort fifo_mode = 0;
114 static bool enable_suspend = 0;
120 #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")
122 #if defined(CONFIG_USB_GADGET_DEBUG_FILES) || defined (DEBUG)
136 #define valid_bit cpu_to_le32 (1 << VALID_BIT)
137 #define dma_done_ie cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE)
145 struct net2280_ep *ep;
150 if (!_ep || !desc || ep->desc || _ep->
name == ep0name
162 max = usb_endpoint_maxp (desc) & 0x1fff;
163 if (ep->num > 4 && max > 64)
173 ep->out_overflow = 0;
176 set_idx_reg (dev->regs, REG_EP_MAXPKT (dev, ep->num), max);
181 if (ep->dma && (max % 4) != 0 && use_dma_chaining) {
182 DEBUG (ep->dev,
"%s, no dma for maxpacket %d\n",
183 ep->ep.name, ep->ep.maxpacket);
192 if (dev->chiprev == 0100
203 spin_unlock_irqrestore (&dev->lock, flags);
218 else if (dev->pdev->device != 0x2280) {
226 writel (tmp, &ep->regs->ep_cfg);
230 tmp = (1 << ep->num) |
readl (&dev->regs->pciirqenb0);
231 writel (tmp, &dev->regs->pciirqenb0);
235 if (dev->pdev->device == 0x2280)
236 tmp |=
readl (&ep->regs->ep_irqenb);
237 writel (tmp, &ep->regs->ep_irqenb);
239 tmp = (1 << (8 + ep->num));
240 tmp |=
readl (&dev->regs->pciirqenb1);
241 writel (tmp, &dev->regs->pciirqenb1);
249 writel (tmp, &ep->regs->ep_irqenb);
251 tmp = (1 << ep->num) |
readl (&dev->regs->pciirqenb0);
252 writel (tmp, &dev->regs->pciirqenb0);
257 DEBUG (dev,
"enabled %s (ep%d%s-%s) %s max %04x\n",
260 ep->dma ?
"dma" :
"pio", max);
263 spin_unlock_irqrestore (&dev->lock, flags);
272 result =
readl (ptr);
273 if (result == ~(
u32)0)
284 static const struct usb_ep_ops net2280_ep_ops;
291 INIT_LIST_HEAD (&ep->queue);
293 ep->ep.maxpacket = ~0;
294 ep->ep.ops = &net2280_ep_ops;
298 writel (0, &ep->dma->dmactl);
302 , &ep->dma->dmastat);
304 tmp =
readl (®s->pciirqenb0);
305 tmp &= ~(1 << ep->num);
306 writel (tmp, ®s->pciirqenb0);
308 tmp =
readl (®s->pciirqenb1);
309 tmp &= ~(1 << (8 + ep->num));
310 writel (tmp, ®s->pciirqenb1);
312 writel (0, &ep->regs->ep_irqenb);
317 if (!ep->is_in || ep->dev->pdev->device == 0x2280) {
334 writel (tmp, &ep->regs->ep_rsp);
337 if (ep->dev->pdev->device == 0x2280)
356 , &ep->regs->ep_stat);
361 static void nuke (
struct net2280_ep *);
363 static int net2280_disable (
struct usb_ep *_ep)
365 struct net2280_ep *ep;
369 if (!_ep || !ep->
desc || _ep->
name == ep0name)
374 ep_reset (ep->dev->regs, ep);
376 VDEBUG (ep->dev,
"disabled %s %s\n",
377 ep->dma ?
"dma" :
"pio", _ep->
name);
382 if (
use_dma && !ep->dma && ep->num >= 1 && ep->num <= 4)
383 ep->dma = &ep->dev->dma [ep->num - 1];
385 spin_unlock_irqrestore (&ep->dev->lock, flags);
392 net2280_alloc_request (
struct usb_ep *_ep,
gfp_t gfp_flags)
394 struct net2280_ep *ep;
395 struct net2280_request *
req;
401 req = kzalloc(
sizeof(*req), gfp_flags);
406 INIT_LIST_HEAD (&req->queue);
410 struct net2280_dma *
td;
412 td = pci_pool_alloc (ep->dev->requests, gfp_flags,
420 td->dmadesc = td->dmaaddr;
429 struct net2280_ep *ep;
430 struct net2280_request *
req;
437 WARN_ON (!list_empty (&req->queue));
439 pci_pool_free (ep->dev->requests, req->td, req->td_dma);
453 write_fifo (
struct net2280_ep *ep,
struct usb_request *req)
458 unsigned count, total;
472 count = ep->ep.maxpacket;
476 VDEBUG (ep->dev,
"write %s fifo (IN) %d bytes%s req %p\n",
478 (count != ep->ep.maxpacket) ?
" (short)" :
"",
496 if (count || total < ep->ep.maxpacket) {
499 set_fifo_bytecount (ep, count & 0x03);
513 static void out_flush (
struct net2280_ep *ep)
520 statp = &ep->regs->ep_stat;
547 read_fifo (
struct net2280_ep *ep,
struct net2280_request *req)
550 u8 *buf = req->req.buf + req->req.actual;
552 unsigned cleanup = 0, prevent = 0;
557 if (ep->dev->chiprev == 0x0100
560 tmp =
readl (&ep->regs->ep_stat);
564 start_out_naking (ep);
577 tmp =
readl (&ep->regs->ep_stat);
584 tmp = req->req.length - req->req.actual;
587 if ((tmp % ep->ep.maxpacket) != 0) {
589 "%s out fifo %d bytes, expected %d\n",
590 ep->ep.name, count, tmp);
599 req->req.actual +=
count;
601 is_short = (count == 0) || ((count % ep->ep.maxpacket) != 0);
603 VDEBUG (ep->dev,
"read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n",
604 ep->ep.name, count, is_short ?
" (short)" :
"",
605 cleanup ?
" flush" :
"", prevent ?
" nak" :
"",
606 req, req->req.actual, req->req.length);
630 return is_short || ((req->req.actual == req->req.length)
636 fill_dma_desc (
struct net2280_ep *ep,
struct net2280_request *req,
int valid)
638 struct net2280_dma *
td = req->td;
648 if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0)
649 || ep->dev->pdev->device != 0x2280)
655 if (
likely(!req->req.no_interrupt || !use_dma_chaining))
666 static const u32 dmactl_default =
693 if (ep->dev->pdev->device != 0x2280)
708 stop_out_naking (ep);
711 static void start_dma (
struct net2280_ep *ep,
struct net2280_request *req)
720 writel (0, &ep->dma->dmactl);
723 if (!ep->is_in && ((tmp =
readl (&ep->regs->ep_stat))
728 tmp =
readl (&ep->regs->ep_avail);
734 tmp =
min (tmp, req->req.length);
737 req->td->dmacount =
cpu_to_le32 (req->req.length - tmp);
740 req->td->dmadesc = 0;
749 tmp = dmactl_default;
756 if (
likely ((req->req.length % ep->ep.maxpacket) != 0
759 ep->in_fifo_validate = 1;
761 ep->in_fifo_validate = 0;
766 fill_dma_desc (ep, req, 1);
768 if (!use_dma_chaining)
771 start_queue (ep, tmp, req->td_dma);
775 queue_dma (
struct net2280_ep *ep,
struct net2280_request *req,
int valid)
777 struct net2280_dma *
end;
786 ep->td_dma = req->td_dma;
791 fill_dma_desc (ep, req, valid);
795 done (
struct net2280_ep *ep,
struct net2280_request *req,
int status)
798 unsigned stopped = ep->stopped;
800 list_del_init (&req->queue);
805 status = req->req.status;
812 VDEBUG (dev,
"complete %s req %p stat %d len %u/%u\n",
813 ep->ep.name, &req->req, status,
814 req->req.actual, req->req.length);
818 spin_unlock (&dev->lock);
819 req->req.complete (&ep->ep, &req->req);
820 spin_lock (&dev->lock);
829 struct net2280_request *
req;
830 struct net2280_ep *ep;
839 || !list_empty (&req->queue))
844 if (!_ep || (!ep->desc && ep->num != 0))
851 if (ep->dma && _req->
length == 0)
865 VDEBUG (dev,
"%s queue req %p, len %d buf %p\n",
875 if (list_empty (&ep->queue) && !ep->stopped) {
881 if (ep->num == 0 && _req->
length == 0) {
884 VDEBUG (dev,
"%s status ack\n", ep->ep.name);
890 write_fifo (ep, _req);
891 else if (list_empty (&ep->queue)) {
895 s =
readl (&ep->regs->ep_stat);
903 if (read_fifo (ep, req)) {
910 s =
readl (&ep->regs->ep_stat);
920 }
else if (ep->dma) {
929 expect =
likely (req->req.zero
930 || (req->req.length % ep->ep.maxpacket) != 0);
931 if (expect != ep->in_fifo_validate)
934 queue_dma (ep, req, valid);
942 spin_unlock_irqrestore (&dev->lock, flags);
950 struct net2280_ep *ep,
951 struct net2280_request *req,
957 done (ep, req, status);
960 static void restart_dma (
struct net2280_ep *ep);
962 static void scan_dma_completions (
struct net2280_ep *ep)
967 while (!list_empty (&ep->queue)) {
968 struct net2280_request *
req;
972 struct net2280_request,
queue);
984 if (
unlikely (req->td->dmadesc == 0)) {
986 tmp =
readl (&ep->dma->dmacount);
990 dma_done (ep, req, tmp, 0);
992 }
else if (!ep->is_in
993 && (req->req.length % ep->ep.maxpacket) != 0) {
994 tmp =
readl (&ep->regs->ep_stat);
1001 WARNING (ep->dev,
"%s lost packet sync!\n",
1004 }
else if ((tmp =
readl (&ep->regs->ep_avail)) != 0) {
1006 ep->out_overflow = 1;
1007 DEBUG (ep->dev,
"%s dma, discard %d len %d\n",
1013 dma_done (ep, req, tmp, 0);
1017 static void restart_dma (
struct net2280_ep *ep)
1019 struct net2280_request *
req;
1020 u32 dmactl = dmactl_default;
1026 if (!use_dma_chaining) {
1027 start_dma (ep, req);
1037 if (ep->is_in && !req->valid) {
1041 DEBUG (ep->dev,
"%s dma hiccup td %p\n", ep->ep.name, req->td);
1042 ep->in_fifo_validate =
likely (req->req.zero
1043 || (req->req.length % ep->ep.maxpacket) != 0);
1044 if (ep->in_fifo_validate)
1051 dmacount = entry->td->dmacount;
1053 reqmode =
likely (entry->req.zero
1054 || (entry->req.length
1055 % ep->ep.maxpacket) != 0);
1056 if (reqmode == ep->in_fifo_validate) {
1077 writel (0, &ep->dma->dmactl);
1078 start_queue (ep, dmactl, req->td_dma);
1081 static void abort_dma (
struct net2280_ep *ep)
1084 if (
likely (!list_empty (&ep->queue))) {
1087 spin_stop_dma (ep->dma);
1090 scan_dma_completions (ep);
1094 static void nuke (
struct net2280_ep *ep)
1096 struct net2280_request *
req;
1102 while (!list_empty (&ep->queue)) {
1104 struct net2280_request,
1113 struct net2280_ep *ep;
1114 struct net2280_request *
req;
1115 unsigned long flags;
1120 if (!_ep || (!ep->desc && ep->num != 0) || !_req)
1124 stopped = ep->stopped;
1130 dmactl =
readl (&ep->dma->dmactl);
1133 scan_dma_completions (ep);
1138 if (&req->req == _req)
1141 if (&req->req != _req) {
1142 spin_unlock_irqrestore (&ep->dev->lock, flags);
1147 if (ep->queue.next == &req->queue) {
1149 DEBUG (ep->dev,
"unlink (%s) dma\n", _ep->
name);
1152 if (
likely (ep->queue.next == &req->queue)) {
1154 req->td->dmacount = 0;
1156 readl (&ep->dma->dmacount),
1160 DEBUG (ep->dev,
"unlink (%s) pio\n", _ep->
name);
1166 }
else if (ep->dma && use_dma_chaining) {
1167 if (req->queue.prev == ep->queue.next) {
1173 &ep->dma->dmacount);
1175 struct net2280_request *
prev;
1178 struct net2280_request,
queue);
1179 prev->td->dmadesc = req->td->dmadesc;
1191 if (list_empty (&ep->queue))
1193 else if (!ep->stopped) {
1196 writel (dmactl, &ep->dma->dmactl);
1199 struct net2280_request,
queue));
1203 spin_unlock_irqrestore (&ep->dev->lock, flags);
1209 static int net2280_fifo_status (
struct usb_ep *_ep);
1212 net2280_set_halt_and_wedge(
struct usb_ep *_ep,
int value,
int wedged)
1214 struct net2280_ep *ep;
1215 unsigned long flags;
1219 if (!_ep || (!ep->desc && ep->num != 0))
1223 if (ep->desc && (ep->desc->bmAttributes & 0x03)
1228 if (!list_empty (&ep->queue))
1230 else if (ep->is_in && value && net2280_fifo_status (_ep) != 0)
1234 value ?
"set" :
"clear",
1235 wedged ?
"wedge" :
"halt");
1239 ep->dev->protocol_stall = 1;
1250 spin_unlock_irqrestore (&ep->dev->lock, flags);
1256 net2280_set_halt(
struct usb_ep *_ep,
int value)
1258 return net2280_set_halt_and_wedge(_ep, value, 0);
1262 net2280_set_wedge(
struct usb_ep *_ep)
1264 if (!_ep || _ep->
name == ep0name)
1266 return net2280_set_halt_and_wedge(_ep, 1, 1);
1270 net2280_fifo_status (
struct usb_ep *_ep)
1272 struct net2280_ep *ep;
1276 if (!_ep || (!ep->desc && ep->num != 0))
1281 avail =
readl (&ep->regs->ep_avail) & ((1 << 12) - 1);
1282 if (avail > ep->fifo_size)
1285 avail = ep->fifo_size -
avail;
1290 net2280_fifo_flush (
struct usb_ep *_ep)
1292 struct net2280_ep *ep;
1295 if (!_ep || (!ep->desc && ep->num != 0))
1304 static const struct usb_ep_ops net2280_ep_ops = {
1305 .enable = net2280_enable,
1306 .disable = net2280_disable,
1308 .alloc_request = net2280_alloc_request,
1309 .free_request = net2280_free_request,
1311 .queue = net2280_queue,
1312 .dequeue = net2280_dequeue,
1314 .set_halt = net2280_set_halt,
1315 .set_wedge = net2280_set_wedge,
1316 .fifo_status = net2280_fifo_status,
1317 .fifo_flush = net2280_fifo_flush,
1322 static int net2280_get_frame (
struct usb_gadget *_gadget)
1324 struct net2280 *
dev;
1325 unsigned long flags;
1332 retval = get_idx_reg (dev->regs,
REG_FRAME) & 0x03ff;
1333 spin_unlock_irqrestore (&dev->lock, flags);
1337 static int net2280_wakeup (
struct usb_gadget *_gadget)
1339 struct net2280 *
dev;
1341 unsigned long flags;
1348 tmp =
readl (&dev->usb->usbctl);
1351 spin_unlock_irqrestore (&dev->lock, flags);
1357 static int net2280_set_selfpowered (
struct usb_gadget *_gadget,
int value)
1359 struct net2280 *
dev;
1361 unsigned long flags;
1368 tmp =
readl (&dev->usb->usbctl);
1373 writel (tmp, &dev->usb->usbctl);
1374 spin_unlock_irqrestore (&dev->lock, flags);
1379 static int net2280_pullup(
struct usb_gadget *_gadget,
int is_on)
1381 struct net2280 *
dev;
1383 unsigned long flags;
1390 tmp =
readl (&dev->usb->usbctl);
1391 dev->softconnect = (is_on != 0);
1396 writel (tmp, &dev->usb->usbctl);
1397 spin_unlock_irqrestore (&dev->lock, flags);
1402 static int net2280_start(
struct usb_gadget *_gadget,
1404 static int net2280_stop(
struct usb_gadget *_gadget,
1408 .get_frame = net2280_get_frame,
1409 .wakeup = net2280_wakeup,
1410 .set_selfpowered = net2280_set_selfpowered,
1411 .pullup = net2280_pullup,
1412 .udc_start = net2280_start,
1413 .udc_stop = net2280_stop,
1418 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1432 || !dev->driver->function
1442 struct net2280 *
dev;
1445 unsigned long flags;
1456 s = dev->driver->driver.name;
1462 ", chiprev %04x, dma %s\n\n"
1463 "devinit %03x fifoctl %08x gadget '%s'\n"
1464 "pci irqenb0 %02x irqenb1 %08x "
1465 "irqstat0 %04x irqstat1 %08x\n",
1468 ? (use_dma_chaining ?
"chaining" :
"enabled")
1470 readl (&dev->regs->devinit),
1471 readl (&dev->regs->fifoctl),
1473 readl (&dev->regs->pciirqenb0),
1474 readl (&dev->regs->pciirqenb1),
1475 readl (&dev->regs->irqstat0),
1476 readl (&dev->regs->irqstat1));
1481 t1 =
readl (&dev->usb->usbctl);
1482 t2 =
readl (&dev->usb->usbstat);
1494 "stdrsp %08x usbctl %08x usbstat %08x "
1495 "addr 0x%02x (%s)\n",
1496 readl (&dev->usb->stdrsp), t1, t2,
1497 readl (&dev->usb->ouraddr), s);
1506 for (i = 0; i < 7; i++) {
1507 struct net2280_ep *ep;
1513 t1 =
readl (&ep->regs->ep_cfg);
1514 t2 =
readl (&ep->regs->ep_rsp) & 0xff;
1516 "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s"
1518 ep->ep.name, t1, t2,
1526 ?
"interrupt " :
"",
1532 ?
"DATA1 " :
"DATA0 ",
1535 readl (&ep->regs->ep_irqenb));
1540 "\tstat %08x avail %04x "
1542 readl (&ep->regs->ep_stat),
1543 readl (&ep->regs->ep_avail),
1545 type_string (t1 >> 8),
1546 ep->stopped ?
"*" :
"");
1554 " dma\tctl %08x stat %08x count %08x\n"
1555 "\taddr %08x desc %08x\n",
1556 readl (&ep->dma->dmactl),
1557 readl (&ep->dma->dmastat),
1558 readl (&ep->dma->dmacount),
1559 readl (&ep->dma->dmaaddr),
1560 readl (&ep->dma->dmadesc));
1573 for (i = 0; i < 7; i++) {
1574 struct net2280_ep *ep;
1579 t =
scnprintf (next, size,
" %s/%lu", ep->ep.name, ep->irqs);
1588 spin_unlock_irqrestore (&dev->lock, flags);
1597 struct net2280 *
dev;
1600 unsigned long flags;
1608 for (i = 0; i < 7; i++) {
1609 struct net2280_ep *ep = &dev->ep [
i];
1610 struct net2280_request *
req;
1621 "\n%s (ep%d%s-%s) max %04x %s fifo %d\n",
1627 val =
"bulk";
break;
1629 val =
"intr";
break;
1633 usb_endpoint_maxp (d) & 0x1fff,
1634 ep->dma ?
"dma" :
"pio", ep->fifo_size
1637 t =
scnprintf (next, size,
"ep0 max 64 pio %s\n",
1638 ep->is_in ?
"in" :
"out");
1639 if (t <= 0 || t > size)
1644 if (list_empty (&ep->queue)) {
1645 t =
scnprintf (next, size,
"\t(nothing queued)\n");
1646 if (t <= 0 || t > size)
1653 if (ep->dma && req->td_dma ==
readl (&ep->dma->dmadesc))
1655 "\treq %p len %d/%d "
1656 "buf %p (dmacount %08x)\n",
1657 &req->req, req->req.actual,
1658 req->req.length, req->req.buf,
1659 readl (&ep->dma->dmacount));
1662 "\treq %p len %d/%d buf %p\n",
1663 &req->req, req->req.actual,
1664 req->req.length, req->req.buf);
1665 if (t <= 0 || t > size)
1671 struct net2280_dma *
td;
1674 t =
scnprintf (next, size,
"\t td %08x "
1675 " count %08x buf %08x desc %08x\n",
1680 if (t <= 0 || t > size)
1689 spin_unlock_irqrestore (&dev->lock, flags);
1697 #define device_create_file(a,b) (0)
1698 #define device_remove_file(a,b) do { } while (0)
1708 static void set_fifo_mode (
struct net2280 *dev,
int mode)
1714 INIT_LIST_HEAD (&dev->gadget.ep_list);
1715 list_add_tail (&dev->ep [1].ep.ep_list, &dev->gadget.ep_list);
1716 list_add_tail (&dev->ep [2].ep.ep_list, &dev->gadget.ep_list);
1719 list_add_tail (&dev->ep [3].ep.ep_list, &dev->gadget.ep_list);
1720 list_add_tail (&dev->ep [4].ep.ep_list, &dev->gadget.ep_list);
1721 dev->ep [1].fifo_size = dev->ep [2].fifo_size = 1024;
1724 dev->ep [1].fifo_size = dev->ep [2].fifo_size = 2048;
1727 list_add_tail (&dev->ep [3].ep.ep_list, &dev->gadget.ep_list);
1728 dev->ep [1].fifo_size = 2048;
1729 dev->ep [2].fifo_size = 1024;
1733 list_add_tail (&dev->ep [5].ep.ep_list, &dev->gadget.ep_list);
1734 list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list);
1746 static void usb_reset (
struct net2280 *dev)
1753 net2280_led_init (dev);
1756 writel (0, &dev->usb->stdrsp);
1757 writel (0, &dev->regs->pciirqenb0);
1758 writel (0, &dev->regs->pciirqenb1);
1761 for (tmp = 0; tmp < 4; tmp++) {
1762 struct net2280_ep *ep = &dev->ep [tmp + 1];
1767 writel (~0, &dev->regs->irqstat0),
1771 tmp =
readl (&dev->regs->devinit)
1776 writel (tmp, &dev->regs->devinit);
1779 set_fifo_mode (dev, (fifo_mode <= 2) ? fifo_mode : 0);
1782 static void usb_reinit (
struct net2280 *dev)
1791 for (tmp = 0; tmp < 7; tmp++) {
1792 struct net2280_ep *ep = &dev->ep [
tmp];
1794 ep->ep.name = ep_name [
tmp];
1798 if (tmp > 0 && tmp <= 4) {
1799 ep->fifo_size = 1024;
1801 ep->dma = &dev->dma [tmp - 1];
1804 ep->regs = &dev->epregs [
tmp];
1805 ep_reset (dev->regs, ep);
1807 dev->ep [0].ep.maxpacket = 64;
1808 dev->ep [5].ep.maxpacket = 64;
1809 dev->ep [6].ep.maxpacket = 64;
1811 dev->gadget.ep0 = &dev->ep [0].ep;
1812 dev->ep [0].stopped = 0;
1813 INIT_LIST_HEAD (&dev->gadget.ep0->ep_list);
1818 for (tmp = 0; tmp < 5; tmp++)
1822 static void ep0_start (
struct net2280 *dev)
1827 , &dev->epregs [0].ep_rsp);
1840 , &dev->usb->stdrsp);
1846 , &dev->usb->usbctl);
1851 , &dev->regs->pciirqenb0);
1859 , &dev->regs->pciirqenb1);
1871 static int net2280_start(
struct usb_gadget *_gadget,
1874 struct net2280 *
dev;
1888 for (i = 0; i < 7; i++)
1889 dev->ep [i].irqs = 0;
1892 dev->softconnect = 1;
1894 dev->driver = driver;
1898 if (retval)
goto err_unbind;
1900 if (retval)
goto err_func;
1905 net2280_led_active (dev, 1);
1908 DEBUG (dev,
"%s ready, usbctl %08x stdrsp %08x\n",
1910 readl (&dev->usb->usbctl),
1911 readl (&dev->usb->stdrsp));
1919 driver->
unbind (&dev->gadget);
1920 dev->gadget.dev.driver =
NULL;
1938 for (i = 0; i < 7; i++)
1939 nuke (&dev->ep [i]);
1944 static int net2280_stop(
struct usb_gadget *_gadget,
1947 struct net2280 *
dev;
1948 unsigned long flags;
1953 stop_activity (dev, driver);
1954 spin_unlock_irqrestore (&dev->lock, flags);
1956 dev->gadget.dev.driver =
NULL;
1959 net2280_led_active (dev, 0);
1963 DEBUG (dev,
"unregistered driver '%s'\n", driver->
driver.name);
1973 static void handle_ep_small (
struct net2280_ep *ep)
1975 struct net2280_request *
req;
1980 if (!list_empty (&ep->queue))
1982 struct net2280_request,
queue);
1987 t =
readl (&ep->regs->ep_stat);
1990 VDEBUG (ep->dev,
"%s ack ep_stat %08x, req %p\n",
1991 ep->ep.name, t, req ? &req->req : 0);
1993 if (!ep->is_in || ep->dev->pdev->device == 0x2280)
1997 writel (t, &ep->regs->ep_stat);
2013 if (ep->dev->protocol_stall) {
2022 if (ep->dev->protocol_stall) {
2026 }
else if (ep->responded &&
2027 !req && !ep->stopped)
2028 write_fifo (ep,
NULL);
2033 if (ep->dev->protocol_stall) {
2041 && req->req.actual == req->req.length)
2042 || (ep->responded && !req)) {
2043 ep->dev->protocol_stall = 1;
2057 if (
likely (ep->dma != 0)) {
2060 int stopped = ep->stopped;
2067 for (count = 0; ; t =
readl (&ep->regs->ep_stat)) {
2072 scan_dma_completions (ep);
2073 if (
unlikely (list_empty (&ep->queue)
2074 || ep->out_overflow)) {
2079 struct net2280_request,
queue);
2085 count =
readl (&ep->dma->dmacount);
2087 if (
readl (&ep->dma->dmadesc)
2097 spin_stop_dma (ep->dma);
2100 req->td->dmacount = 0;
2101 t =
readl (&ep->regs->ep_avail);
2102 dma_done (ep, req, count,
2103 (ep->out_overflow || t)
2109 || (ep->dev->chiprev == 0x0100
2110 && ep->dev->gadget.speed
2113 ep->out_overflow = 0;
2118 if (!list_empty (&ep->queue))
2121 DEBUG (ep->dev,
"%s dma ep_stat %08x ??\n",
2127 if (read_fifo (ep, req) && ep->num != 0)
2134 len = req->req.length - req->req.actual;
2135 if (len > ep->ep.maxpacket)
2136 len = ep->ep.maxpacket;
2137 req->req.actual += len;
2140 if (req->req.actual == req->req.length) {
2143 }
else if (!req->req.zero || len != ep->ep.maxpacket)
2148 }
else if (mode == 1)
2166 if (!list_empty (&ep->queue) && !ep->stopped)
2168 struct net2280_request,
queue);
2171 if (req && !ep->is_in)
2172 stop_out_naking (ep);
2179 if (req && !ep->stopped) {
2183 write_fifo (ep, &req->req);
2187 static struct net2280_ep *
2188 get_ep_by_addr (
struct net2280 *dev,
u16 wIndex)
2190 struct net2280_ep *ep;
2193 return &dev->ep [0];
2199 bEndpointAddress = ep->desc->bEndpointAddress;
2200 if ((wIndex ^ bEndpointAddress) &
USB_DIR_IN)
2202 if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f))
2208 static void handle_stat0_irqs (
struct net2280 *dev,
u32 stat)
2210 struct net2280_ep *ep;
2226 struct net2280_request *
req;
2233 net2280_led_speed (dev, dev->gadget.speed);
2242 while (!list_empty (&ep->queue)) {
2244 struct net2280_request,
queue);
2245 done (ep, req, (req->req.actual == req->req.length)
2249 dev->protocol_stall = 0;
2251 if (ep->dev->pdev->device == 0x2280)
2269 , &ep->regs->ep_stat);
2270 u.raw [0] =
readl (&dev->usb->setup0123);
2271 u.raw [1] =
readl (&dev->usb->setup4567);
2278 #define w_value le16_to_cpu(u.r.wValue)
2279 #define w_index le16_to_cpu(u.r.wIndex)
2280 #define w_length le16_to_cpu(u.r.wLength)
2296 stop_out_naking (ep);
2301 writel (scratch, &dev->epregs [0].ep_irqenb);
2307 switch (
u.r.bRequest) {
2309 struct net2280_ep *
e;
2315 if ((e = get_ep_by_addr (dev, w_index)) == 0
2319 if (
readl (&e->regs->ep_rsp)
2326 writel (0, &dev->epregs [0].ep_irqenb);
2327 set_fifo_bytecount (ep, w_length);
2330 VDEBUG (dev,
"%s stat %02x\n", ep->ep.name, status);
2331 goto next_endpoints;
2335 struct net2280_ep *
e;
2343 if ((e = get_ep_by_addr (dev, w_index)) == 0)
2346 VDEBUG(dev,
"%s wedged, halt not cleared\n",
2349 VDEBUG(dev,
"%s clear halt\n", ep->ep.name);
2353 goto next_endpoints;
2357 struct net2280_ep *
e;
2365 if ((e = get_ep_by_addr (dev, w_index)) == 0)
2367 if (e->ep.name == ep0name)
2371 VDEBUG (dev,
"%s set halt\n", ep->ep.name);
2372 goto next_endpoints;
2377 VDEBUG (dev,
"setup %02x.%02x v%04x i%04x l%04x "
2379 u.r.bRequestType,
u.r.bRequest,
2380 w_value, w_index, w_length,
2381 readl (&ep->regs->ep_cfg));
2383 spin_unlock (&dev->lock);
2384 tmp = dev->driver->setup (&dev->gadget, &
u.r);
2385 spin_lock (&dev->lock);
2391 VDEBUG (dev,
"req %02x.%02x protocol STALL; stat %d\n",
2392 u.r.bRequestType,
u.r.bRequest, tmp);
2393 dev->protocol_stall = 1;
2408 scratch = stat & 0x7f;
2410 for (num = 0;
scratch; num++) {
2415 if ((scratch & t) == 0)
2419 ep = &dev->ep [num];
2420 handle_ep_small (ep);
2424 DEBUG (dev,
"unhandled irqstat0 %08x\n", stat);
2427 #define DMA_INTERRUPTS ( \
2428 (1 << DMA_D_INTERRUPT) \
2429 | (1 << DMA_C_INTERRUPT) \
2430 | (1 << DMA_B_INTERRUPT) \
2431 | (1 << DMA_A_INTERRUPT))
2432 #define PCI_ERROR_INTERRUPTS ( \
2433 (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT) \
2434 | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT) \
2435 | (1 << PCI_RETRY_ABORT_INTERRUPT))
2437 static void handle_stat1_irqs (
struct net2280 *dev,
u32 stat)
2439 struct net2280_ep *ep;
2452 writel (tmp, &dev->regs->irqstat1);
2454 && ((
readl (&dev->usb->usbstat) & mask)
2456 || ((
readl (&dev->usb->usbctl)
2459 DEBUG (dev,
"disconnect %s\n",
2460 dev->driver->driver.name);
2461 stop_activity (dev, dev->driver);
2479 writel (tmp, &dev->regs->irqstat1);
2481 if (dev->driver->suspend)
2482 dev->driver->suspend (&dev->gadget);
2483 if (!enable_suspend)
2486 if (dev->driver->resume)
2487 dev->driver->resume (&dev->gadget);
2495 writel (stat, &dev->regs->irqstat1);
2498 if (dev->pdev->device == 0x2280)
2515 stat &= ~DMA_INTERRUPTS;
2517 for (num = 0;
scratch; num++) {
2521 if ((tmp & scratch) == 0)
2525 ep = &dev->ep [num + 1];
2538 if (!use_dma_chaining) {
2541 DEBUG (ep->dev,
"%s no xact done? %08x\n",
2558 scan_dma_completions (ep);
2561 if (list_empty (&ep->queue)) {
2562 if (use_dma_chaining)
2566 if (!use_dma_chaining
2569 else if (ep->is_in && use_dma_chaining) {
2570 struct net2280_request *
req;
2579 struct net2280_request,
queue);
2580 dmacount = req->td->dmacount;
2584 if (dmacount && (dmacount &
valid_bit) == 0)
2595 ERROR (dev,
"pci dma error; stat %08x\n", stat);
2596 stat &= ~PCI_ERROR_INTERRUPTS;
2600 stop_activity (dev, dev->driver);
2606 DEBUG (dev,
"unhandled irqstat1 %08x\n", stat);
2609 static irqreturn_t net2280_irq (
int irq,
void *_dev)
2611 struct net2280 *dev = _dev;
2617 spin_lock (&dev->lock);
2620 handle_stat1_irqs (dev,
readl (&dev->regs->irqstat1));
2623 handle_stat0_irqs (dev,
readl (&dev->regs->irqstat0));
2625 spin_unlock (&dev->lock);
2632 static void gadget_release (
struct device *_dev)
2641 static void net2280_remove (
struct pci_dev *pdev)
2643 struct net2280 *dev = pci_get_drvdata (pdev);
2650 net2280_led_shutdown (dev);
2651 if (dev->requests) {
2653 for (i = 1; i < 5; i++) {
2654 if (!dev->ep [i].dummy)
2656 pci_pool_free (dev->requests, dev->ep [i].dummy,
2657 dev->ep [i].td_dma);
2659 pci_pool_destroy (dev->requests);
2672 pci_set_drvdata (pdev,
NULL);
2674 INFO (dev,
"unbind\n");
2683 struct net2280 *
dev;
2695 pci_set_drvdata (pdev, dev);
2698 dev->gadget.ops = &net2280_ops;
2703 dev->gadget.dev.parent = &pdev->
dev;
2704 dev->gadget.dev.dma_mask = pdev->
dev.dma_mask;
2705 dev->gadget.dev.release = gadget_release;
2722 DEBUG (dev,
"controller already in use\n");
2734 DEBUG (dev,
"can't map memory\n");
2746 writel (0, &dev->usb->usbctl);
2752 ERROR (dev,
"No IRQ. Check PCI setup!\n");
2759 ERROR (dev,
"request interrupt %d failed\n", pdev->
irq);
2767 dev->requests = pci_pool_create (
"requests", pdev,
2768 sizeof (
struct net2280_dma),
2771 if (!dev->requests) {
2772 DEBUG (dev,
"can't get request pool\n");
2776 for (i = 1; i < 5; i++) {
2777 struct net2280_dma *
td;
2779 td = pci_pool_alloc (dev->requests,
GFP_KERNEL,
2780 &dev->ep [i].td_dma);
2782 DEBUG (dev,
"can't get dummy %d\n", i);
2788 td->dmadesc = td->dmaaddr;
2789 dev->ep [
i].dummy =
td;
2798 , &dev->pci->pcimstctl);
2804 dev->chiprev = get_idx_reg (dev->regs,
REG_CHIPREV) & 0xffff;
2807 INFO (dev,
"%s\n", driver_desc);
2808 INFO (dev,
"irq %d, pci mem %p, chip rev %04x\n",
2809 pdev->
irq, base, dev->chiprev);
2812 ? (use_dma_chaining ?
"chaining" :
"enabled")
2815 if (retval)
goto done;
2817 if (retval)
goto done;
2826 net2280_remove (pdev);
2834 static void net2280_shutdown (
struct pci_dev *pdev)
2836 struct net2280 *dev = pci_get_drvdata (pdev);
2839 writel (0, &dev->regs->pciirqenb0);
2840 writel (0, &dev->regs->pciirqenb1);
2843 writel (0, &dev->usb->usbctl);
2869 static struct pci_driver net2280_pci_driver = {
2873 .
probe = net2280_probe,
2874 .
remove = net2280_remove,
2887 use_dma_chaining = 0;
2888 return pci_register_driver (&net2280_pci_driver);
2892 static void __exit cleanup (
void)