31 #define UDC_MOD_DESCRIPTION "AMD 5536 UDC - USB Device Controller"
32 #define UDC_DRIVER_VERSION_STRING "01.00.0206"
35 #include <linux/module.h>
36 #include <linux/pci.h>
37 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/slab.h>
42 #include <linux/errno.h>
45 #include <linux/list.h>
51 #include <linux/device.h>
54 #include <linux/prefetch.h>
56 #include <asm/byteorder.h>
57 #include <asm/unaligned.h>
60 #include <linux/usb/ch9.h>
67 static void udc_tasklet_disconnect(
unsigned long);
68 static void empty_req_queue(
struct udc_ep *);
69 static int udc_probe(
struct udc *
dev);
70 static void udc_basic_init(
struct udc *
dev);
71 static void udc_setup_endpoints(
struct udc *
dev);
72 static void udc_soft_reset(
struct udc *
dev);
77 unsigned long buf_len,
gfp_t gfp_flags);
78 static int udc_remote_wakeup(
struct udc *
dev);
80 static void udc_pci_remove(
struct pci_dev *pdev);
84 static const char name[] =
"amd5536udc";
104 static unsigned int udc_rxfifo_pending;
107 static int soft_reset_occured;
108 static int soft_reset_after_usbreset_occured;
112 static int stop_timer;
128 static int set_rde = -1;
132 static int stop_pollstall_timer;
137 (
unsigned long) &udc);
141 static const char ep0_string[] =
"ep0in";
142 static const char *
const ep_string[] = {
144 "ep1in-int",
"ep2in-bulk",
"ep3in-bulk",
"ep4in-bulk",
"ep5in-bulk",
145 "ep6in-bulk",
"ep7in-bulk",
"ep8in-bulk",
"ep9in-bulk",
"ep10in-bulk",
146 "ep11in-bulk",
"ep12in-bulk",
"ep13in-bulk",
"ep14in-bulk",
147 "ep15in-bulk",
"ep0out",
"ep1out-bulk",
"ep2out-bulk",
"ep3out-bulk",
148 "ep4out-bulk",
"ep5out-bulk",
"ep6out-bulk",
"ep7out-bulk",
149 "ep8out-bulk",
"ep9out-bulk",
"ep10out-bulk",
"ep11out-bulk",
150 "ep12out-bulk",
"ep13out-bulk",
"ep14out-bulk",
"ep15out-bulk"
156 static bool use_dma_ppb = 1;
158 static bool use_dma_ppb_du;
160 static int use_dma_bufferfill_mode;
162 static bool use_fullspeed;
173 "true for DMA in packet per buffer mode with descriptor update");
179 static void print_regs(
struct udc *
dev)
181 DBG(dev,
"------- Device registers -------\n");
182 DBG(dev,
"dev config = %08x\n",
readl(&dev->
regs->cfg));
183 DBG(dev,
"dev control = %08x\n",
readl(&dev->
regs->ctl));
184 DBG(dev,
"dev status = %08x\n",
readl(&dev->
regs->sts));
186 DBG(dev,
"dev int's = %08x\n",
readl(&dev->
regs->irqsts));
187 DBG(dev,
"dev intmask = %08x\n",
readl(&dev->
regs->irqmsk));
189 DBG(dev,
"dev ep int's = %08x\n",
readl(&dev->
regs->ep_irqsts));
190 DBG(dev,
"dev ep intmask = %08x\n",
readl(&dev->
regs->ep_irqmsk));
192 DBG(dev,
"USE DMA = %d\n", use_dma);
193 if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
194 DBG(dev,
"DMA mode = PPBNDU (packet per buffer "
195 "WITHOUT desc. update)\n");
197 }
else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
198 DBG(dev,
"DMA mode = PPBDU (packet per buffer "
199 "WITH desc. update)\n");
202 if (use_dma && use_dma_bufferfill_mode) {
203 DBG(dev,
"DMA mode = BF (buffer fill mode)\n");
208 DBG(dev,
"-------------------------------------------------------\n");
212 static int udc_mask_unused_interrupts(
struct udc *dev)
234 static int udc_enable_ep0_interrupts(
struct udc *dev)
238 DBG(dev,
"udc_enable_ep0_interrupts()\n");
251 static int udc_enable_dev_setup_interrupts(
struct udc *dev)
255 DBG(dev,
"enable device interrupts for setup data\n");
272 static int udc_set_txfifo_addr(
struct udc_ep *ep)
278 if (!ep || !(ep->
in))
285 for (i = 0; i < ep->
num; i++) {
286 if (dev->
ep[i].regs) {
288 tmp =
readl(&dev->
ep[i].regs->bufin_framenum);
297 static u32 cnak_pending;
299 static void UDC_QUEUE_CNAK(
struct udc_ep *ep,
unsigned num)
302 DBG(ep->
dev,
"NAK could not be cleared for ep%d\n", num);
303 cnak_pending |= 1 << (num);
306 cnak_pending = cnak_pending & (~(1 << (num)));
317 unsigned long iflags;
322 || usbep->
name == ep0_string
330 DBG(dev,
"udc_ep_enable() ep %d\n", ep->
num);
346 maxpacket = usb_endpoint_maxp(desc);
347 tmp =
readl(&dev->
ep[ep->
num].regs->bufout_maxpkt);
348 tmp =
AMD_ADDBITS(tmp, maxpacket, UDC_EP_MAX_PKT_SIZE);
349 ep->
ep.maxpacket = maxpacket;
350 writel(tmp, &dev->
ep[ep->
num].regs->bufout_maxpkt);
356 udc_csr_epix = ep->
num;
359 tmp =
readl(&dev->
ep[ep->
num].regs->bufin_framenum);
366 writel(tmp, &dev->
ep[ep->
num].regs->bufin_framenum);
369 udc_set_txfifo_addr(ep);
387 if (use_dma && !ep->
in) {
398 tmp =
readl(&dev->
csr->ne[udc_csr_epix]);
400 tmp =
AMD_ADDBITS(tmp, maxpacket, UDC_CSR_NE_MAX_PKT);
414 writel(tmp, &dev->
csr->ne[udc_csr_epix]);
425 if (!use_dma || ep->
in) {
430 UDC_QUEUE_CNAK(ep, ep->
num);
433 DBG(dev,
"%s enabled\n", usbep->
name);
435 spin_unlock_irqrestore(&dev->
lock, iflags);
446 ep->
ep.ops = &udc_ep_ops;
447 INIT_LIST_HEAD(&ep->
queue);
449 ep->
ep.maxpacket = (
u16) ~0;
457 tmp =
readl(®s->ep_irqmsk);
459 writel(tmp, ®s->ep_irqmsk);
482 static int udc_ep_disable(
struct usb_ep *usbep)
485 unsigned long iflags;
491 if (usbep->
name == ep0_string || !ep->
ep.desc)
494 DBG(ep->
dev,
"Disable ep-%d\n", ep->
num);
499 ep_init(ep->
dev->regs, ep);
500 spin_unlock_irqrestore(&ep->
dev->lock, iflags);
518 VDBG(ep->
dev,
"udc_alloc_req(): ep%d\n", ep->
num);
524 INIT_LIST_HEAD(&req->
queue);
528 dma_desc = pci_pool_alloc(ep->
dev->data_requests, gfp,
535 VDBG(ep->
dev,
"udc_alloc_req: req = %p dma_desc = %p, "
559 if (!usbep || !usbreq)
564 VDBG(ep->
dev,
"free_req req=%p\n", req);
571 udc_free_dma_chain(ep->
dev, req);
573 pci_pool_free(ep->
dev->data_requests, req->
td_data,
580 static void udc_init_bna_dummy(
struct udc_request *req)
593 pr_debug(
"bna desc = %p, sts = %08x\n",
610 udc_init_bna_dummy(req);
623 unsigned remaining = 0;
632 buf = (
u32 *) req_buf;
634 bytes = ep->
ep.maxpacket;
635 if (bytes > remaining)
653 static int udc_rxfifo_read_dwords(
struct udc *dev,
u32 *buf,
int dwords)
657 VDBG(dev,
"udc_read_dwords(): %d dwords\n", dwords);
659 for (i = 0; i < dwords; i++)
665 static int udc_rxfifo_read_bytes(
struct udc *dev,
u8 *buf,
int bytes)
670 VDBG(dev,
"udc_read_bytes(): %d bytes\n", bytes);
701 buf_space = req->
req.length - req->
req.actual;
702 buf = req->
req.buf + req->
req.actual;
703 if (bytes > buf_space) {
704 if ((buf_space % ep->
ep.maxpacket) != 0) {
706 "%s: rx %d bytes, rx-buf space = %d bytesn\n",
707 ep->
ep.name, bytes, buf_space);
715 if (((bytes % ep->
ep.maxpacket) != 0) || (!bytes)
716 || ((req->
req.actual == req->
req.length) && !req->
req.zero))
720 VDBG(ep->
dev,
"ep %s: rxfifo read %d bytes\n", ep->
ep.name, bytes);
721 udc_rxfifo_read_bytes(ep->
dev, buf, bytes);
733 VDBG(ep->
dev,
"prep_dma ep%d req->td_data=%p\n",
745 retval = udc_create_dma_chain(ep, req, ep->
ep.maxpacket, gfp);
748 DBG(ep->
dev,
"Out of DMA memory\n");
752 if (req->
req.length == ep->
ep.maxpacket) {
757 UDC_DMA_IN_STS_TXBYTES);
765 VDBG(ep->
dev,
"IN: use_dma_ppb=%d req->req.len=%d "
766 "maxpacket=%d ep%d\n",
767 use_dma_ppb, req->
req.length,
768 ep->
ep.maxpacket, ep->
num);
773 if (!use_dma_ppb || req->
req.length < ep->
ep.maxpacket
780 UDC_DMA_IN_STS_TXBYTES);
785 UDC_DMA_IN_STS_FRAMENUM);
793 VDBG(ep->
dev,
"OUT set host ready\n");
807 UDC_QUEUE_CNAK(ep, ep->
num);
824 VDBG(ep->
dev,
"complete_req(): ep%d\n", ep->
num);
839 list_del_init(&req->
queue);
841 VDBG(ep->
dev,
"req %p => complete %d bytes at %s with sts %d\n",
844 spin_unlock(&dev->
lock);
845 req->
req.complete(&ep->
ep, &req->
req);
846 spin_lock(&dev->
lock);
851 static int udc_free_dma_chain(
struct udc *dev,
struct udc_request *req)
859 DBG(dev,
"free chain req = %p\n", req);
904 UDC_DMA_OUT_STS_RXBYTES);
913 static int udc_create_dma_chain(
916 unsigned long buf_len,
gfp_t gfp_flags
919 unsigned long bytes = req->
req.length;
924 unsigned long txbytes;
925 unsigned create_new_chain = 0;
928 VDBG(ep->
dev,
"udc_create_dma_chain: bytes=%ld buf_len=%ld\n",
937 len = req->
req.length / ep->
ep.maxpacket;
938 if (req->
req.length % ep->
ep.maxpacket)
944 udc_free_dma_chain(ep->
dev, req);
946 create_new_chain = 1;
951 for (i = buf_len; i <
bytes; i += buf_len) {
953 if (create_new_chain) {
955 td = pci_pool_alloc(ep->
dev->data_requests,
956 gfp_flags, &dma_addr);
961 }
else if (i == buf_len) {
978 if ((bytes - i) >= buf_len) {
987 if (create_new_chain)
999 UDC_DMA_IN_STS_TXBYTES);
1003 UDC_DMA_IN_STS_TXBYTES);
1006 if (create_new_chain)
1016 UDC_DMA_IN_STS_TXBYTES);
1032 static void udc_set_rde(
struct udc *dev)
1036 VDBG(dev,
"udc_set_rde()\n");
1038 if (timer_pending(&udc_timer)) {
1054 unsigned long iflags;
1063 if (!usbep || !usbreq || !usbreq->
complete || !usbreq->
buf
1064 || !list_empty(&req->
queue))
1071 VDBG(ep->
dev,
"udc_queue(): ep%d-in=%d\n", ep->
num, ep->
in);
1079 VDBG(dev,
"DMA map req %p\n", req);
1085 VDBG(dev,
"%s queue req %p, len %d req->td_data=%p buf %p\n",
1095 if (list_empty(&ep->
queue)) {
1097 if (usbreq->
length == 0) {
1099 complete_req(ep, req, 0);
1100 VDBG(dev,
"%s: zlp\n", ep->
ep.name);
1125 retval = prep_dma(ep, req, gfp);
1140 if (timer_pending(&udc_timer)) {
1155 VDBG(dev,
"copy to BNA dummy desc.\n");
1170 UDC_QUEUE_CNAK(ep, ep->
num);
1179 }
else if (ep->
in) {
1186 }
else if (ep->
dma) {
1193 retval = prep_dma(ep, req, gfp);
1198 VDBG(dev,
"list_add\n");
1214 if (!use_dma && udc_rxfifo_pending) {
1215 DBG(dev,
"udc_queue(): pending bytes in "
1216 "rxfifo after nyet\n");
1221 if (udc_rxfifo_read(ep, req)) {
1223 complete_req(ep, req, 0);
1225 udc_rxfifo_pending = 0;
1232 spin_unlock_irqrestore(&dev->
lock, iflags);
1237 static void empty_req_queue(
struct udc_ep *ep)
1242 while (!list_empty(&ep->
queue)) {
1256 unsigned long iflags;
1259 if (!usbep || !usbreq || (!ep->
ep.desc && (ep->
num != 0
1285 UDC_DMA_OUT_STS_BS);
1289 udc_init_bna_dummy(ep->
req);
1300 spin_unlock_irqrestore(&ep->
dev->lock, iflags);
1306 udc_set_halt(
struct usb_ep *usbep,
int halt)
1310 unsigned long iflags;
1328 ep->
dev->stall_ep0in = 1;
1340 if (!timer_pending(&udc_pollstall_timer)) {
1341 udc_pollstall_timer.expires =
jiffies +
1344 if (!stop_pollstall_timer) {
1345 DBG(ep->
dev,
"start polltimer\n");
1360 UDC_QUEUE_CNAK(ep, ep->
num);
1363 spin_unlock_irqrestore(&udc_stall_spinlock, iflags);
1368 static const struct usb_ep_ops udc_ep_ops = {
1369 .enable = udc_ep_enable,
1370 .disable = udc_ep_disable,
1372 .alloc_request = udc_alloc_request,
1373 .free_request = udc_free_request,
1376 .dequeue = udc_dequeue,
1378 .set_halt = udc_set_halt,
1385 static int udc_get_frame(
struct usb_gadget *gadget)
1391 static int udc_wakeup(
struct usb_gadget *gadget)
1398 udc_remote_wakeup(dev);
1408 .wakeup = udc_wakeup,
1409 .get_frame = udc_get_frame,
1410 .start = amd5536_start,
1411 .stop = amd5536_stop,
1415 static void make_ep_lists(
struct udc *dev)
1418 INIT_LIST_HEAD(&dev->
gadget.ep_list);
1436 static int startup_registers(
struct udc *dev)
1441 udc_soft_reset(dev);
1444 udc_mask_unused_interrupts(dev);
1447 udc_basic_init(dev);
1449 udc_setup_endpoints(dev);
1463 static void udc_basic_init(
struct udc *dev)
1467 DBG(dev,
"udc_basic_init()\n");
1472 if (timer_pending(&udc_timer)) {
1477 if (timer_pending(&udc_pollstall_timer))
1478 mod_timer(&udc_pollstall_timer, jiffies - 1);
1501 static void udc_setup_endpoints(
struct udc *dev)
1507 DBG(dev,
"udc_setup_endpoints()\n");
1521 ep->
ep.name = ep_string[
tmp];
1542 ep_init(dev->
regs, ep);
1556 reg =
readl(&dev->
ep[tmp].regs->ctl);
1558 writel(reg, &dev->
ep[tmp].regs->ctl);
1559 dev->
ep[
tmp].naking = 1;
1580 INIT_LIST_HEAD(&dev->
gadget.ep0->ep_list);
1589 static void usb_connect(
struct udc *dev)
1597 udc_basic_init(dev);
1600 udc_enable_dev_setup_interrupts(dev);
1615 udc_mask_unused_interrupts(dev);
1622 tasklet_schedule(&disconnect_tasklet);
1626 static void udc_tasklet_disconnect(
unsigned long par)
1628 struct udc *dev = (
struct udc *)(*((
struct udc **) par));
1631 DBG(dev,
"Tasklet disconnect\n");
1632 spin_lock_irq(&dev->
lock);
1635 spin_unlock(&dev->
lock);
1637 spin_lock(&dev->
lock);
1641 empty_req_queue(&dev->
ep[tmp]);
1650 if (!soft_reset_occured) {
1652 udc_soft_reset(dev);
1653 soft_reset_occured++;
1657 udc_enable_dev_setup_interrupts(dev);
1659 if (use_fullspeed) {
1665 spin_unlock_irq(&dev->
lock);
1669 static void udc_soft_reset(
struct udc *dev)
1671 unsigned long flags;
1673 DBG(dev,
"Soft reset\n");
1686 spin_unlock_irqrestore(&udc_irq_spinlock, flags);
1691 static void udc_timer_function(
unsigned long v)
1695 spin_lock_irq(&udc_irq_spinlock);
1734 spin_unlock_irq(&udc_irq_spinlock);
1741 static void udc_handle_halt_state(
struct udc_ep *ep)
1765 UDC_QUEUE_CNAK(ep, ep->
num);
1771 static void udc_pollstall_timer_function(
unsigned long v)
1776 spin_lock_irq(&udc_stall_spinlock);
1782 udc_handle_halt_state(ep);
1787 udc_handle_halt_state(ep);
1792 if (!stop_pollstall_timer && halted) {
1793 udc_pollstall_timer.expires =
jiffies +
1798 spin_unlock_irq(&udc_stall_spinlock);
1800 if (stop_pollstall_timer)
1805 static void activate_control_endpoints(
struct udc *dev)
1809 DBG(dev,
"activate_control_endpoints\n");
1834 UDC_EP_MAX_PKT_SIZE);
1837 UDC_EP_MAX_PKT_SIZE);
1844 UDC_EP_MAX_PKT_SIZE);
1847 UDC_EP_MAX_PKT_SIZE);
1854 UDC_CSR_NE_MAX_PKT);
1857 UDC_CSR_NE_MAX_PKT);
1869 if (timer_pending(&udc_timer)) {
1874 if (timer_pending(&udc_pollstall_timer))
1875 mod_timer(&udc_pollstall_timer, jiffies - 1);
1881 if (use_dma_bufferfill_mode)
1883 else if (use_dma_ppb_du)
1904 static int setup_ep0(
struct udc *dev)
1906 activate_control_endpoints(dev);
1908 udc_enable_ep0_interrupts(dev);
1910 udc_enable_dev_setup_interrupts(dev);
1919 struct udc *dev = udc;
1923 if (!driver || !bind || !driver->
setup
1935 retval = bind(&dev->
gadget, driver);
1944 DBG(dev,
"binding to %s returning %d\n",
1945 driver->
driver.name, retval);
1973 spin_unlock(&dev->
lock);
1975 spin_lock(&dev->
lock);
1979 udc_basic_init(dev);
1981 empty_req_queue(&dev->
ep[tmp]);
1983 udc_setup_endpoints(dev);
1989 struct udc *dev = udc;
1990 unsigned long flags;
1995 if (!driver || driver != dev->
driver || !driver->
unbind)
1999 udc_mask_unused_interrupts(dev);
2000 shutdown(dev, driver);
2001 spin_unlock_irqrestore(&dev->
lock, flags);
2013 DBG(dev,
"%s: unregistered\n", driver->
driver.name);
2019 static void udc_process_cnak_queue(
struct udc *dev)
2025 DBG(dev,
"CNAK pending queue processing\n");
2027 if (cnak_pending & (1 << tmp)) {
2028 DBG(dev,
"CNAK pending for ep%d\n", tmp);
2030 reg =
readl(&dev->
ep[tmp].regs->ctl);
2032 writel(reg, &dev->
ep[tmp].regs->ctl);
2033 dev->
ep[
tmp].naking = 0;
2034 UDC_QUEUE_CNAK(&dev->
ep[tmp], dev->
ep[tmp].num);
2051 static void udc_ep0_set_rde(
struct udc *dev)
2065 if (set_rde != 0 && !timer_pending(&udc_timer)) {
2078 static irqreturn_t udc_data_out_isr(
struct udc *dev,
int ep_ix)
2088 VDBG(dev,
"ep%d irq\n", ep_ix);
2089 ep = &dev->
ep[ep_ix];
2095 DBG(dev,
"BNA ep%dout occurred - DESPTR = %x\n",
2117 if (!list_empty(&ep->
queue)) {
2124 udc_rxfifo_pending = 1;
2126 VDBG(dev,
"req = %p\n", req);
2131 if (req && udc_rxfifo_read(ep, req)) {
2135 complete_req(ep, req, 0);
2151 UDC_DMA_OUT_STS_BS);
2159 VDBG(dev,
"Recover desc. from BNA dummy\n");
2163 udc_init_bna_dummy(ep->
req);
2165 td = udc_get_last_dma_desc(req);
2173 UDC_DMA_OUT_STS_RXBYTES);
2174 VDBG(dev,
"rx bytes=%u\n", count);
2178 VDBG(dev,
"last desc = %p\n", td);
2180 if (use_dma_ppb_du) {
2182 count = udc_get_ppbdu_rxbytes(req);
2186 UDC_DMA_OUT_STS_RXBYTES);
2187 if (!count && req->
req.length
2196 VDBG(dev,
"last desc rx bytes=%u\n", count);
2199 tmp = req->
req.length - req->
req.actual;
2201 if ((tmp % ep->
ep.maxpacket) != 0) {
2202 DBG(dev,
"%s: rx %db, space=%db\n",
2203 ep->
ep.name, count, tmp);
2211 complete_req(ep, req, 0);
2253 && !timer_pending(&udc_timer)) {
2282 udc_process_cnak_queue(dev);
2292 static irqreturn_t udc_data_in_isr(
struct udc *dev,
int ep_ix)
2303 ep = &dev->
ep[ep_ix];
2310 "BNA ep%din occurred - DESPTR = %08lx\n",
2312 (
unsigned long)
readl(&ep->
regs->desptr));
2323 "HE ep%dn occurred - DESPTR = %08lx\n",
2334 VDBG(dev,
"TDC set- completion\n");
2343 if (use_dma_ppb_du) {
2344 td = udc_get_last_dma_desc(req);
2350 req->
req.actual = req->
req.length;
2354 req->
req.actual = req->
req.length;
2357 if (req->
req.actual == req->
req.length) {
2359 complete_req(ep, req, 0);
2362 if (list_empty(&ep->
queue)) {
2380 if (!list_empty(&ep->
queue)) {
2387 udc_txfifo_write(ep, &req->
req);
2388 len = req->
req.length - req->
req.actual;
2389 if (len > ep->
ep.maxpacket)
2390 len = ep->
ep.maxpacket;
2391 req->
req.actual += len;
2392 if (req->
req.actual == req->
req.length
2393 || (len != ep->
ep.maxpacket)) {
2395 complete_req(ep, req, 0);
2399 VDBG(dev,
"IN DMA : req=%p req->td_data=%p\n",
2409 if (use_dma_ppb && req->
req.length >
2433 }
else if (!use_dma && ep->
in) {
2436 &dev->
regs->ep_irqmsk);
2439 &dev->
regs->ep_irqmsk);
2451 static irqreturn_t udc_control_out_isr(
struct udc *dev)
2457 int setup_supported;
2471 VDBG(dev,
"ep0: BNA set\n");
2481 VDBG(dev,
"data_typ = %x\n", tmp);
2487 ep->
dev->stall_ep0in = 0;
2518 udc_ep0_set_rde(dev);
2540 if (!timer_pending(&udc_timer)) {
2556 DBG(dev,
"MSC Reset\n");
2562 udc_set_halt(&ep_tmp->
ep, 0);
2564 udc_set_halt(&ep_tmp->
ep, 0);
2568 spin_unlock(&dev->
lock);
2571 spin_lock(&dev->
lock);
2575 if (setup_supported >= 0 && setup_supported <
2584 }
else if (setup_supported < 0) {
2622 UDC_DMA_OUT_STS_BS);
2624 udc_ep0_set_rde(dev);
2634 udc_ep0_set_rde(dev);
2640 count =
AMD_GETBITS(count, UDC_EPSTS_RX_PKT_SIZE);
2659 udc_process_cnak_queue(dev);
2667 static irqreturn_t udc_control_in_isr(
struct udc *dev)
2683 VDBG(dev,
"isr: TDC clear\n");
2700 DBG(dev,
"stall ep0in\n");
2706 if (!list_empty(&ep->
queue)) {
2719 UDC_DMA_STP_STS_BS);
2729 req->
req.actual = req->
req.length;
2732 complete_req(ep, req, 0);
2736 udc_txfifo_write(ep, &req->
req);
2739 len = req->
req.length - req->
req.actual;
2740 if (len > ep->
ep.maxpacket)
2741 len = ep->
ep.maxpacket;
2743 req->
req.actual += len;
2744 if (req->
req.actual == req->
req.length
2745 || (len != ep->
ep.maxpacket)) {
2747 complete_req(ep, req, 0);
2785 DBG(dev,
"SET_CONFIG interrupt: config=%d\n", cfg);
2800 udc_csr_epix = ep->
num;
2809 tmp =
readl(&dev->
csr->ne[udc_csr_epix]);
2814 writel(tmp, &dev->
csr->ne[udc_csr_epix]);
2823 spin_unlock(&dev->
lock);
2825 spin_lock(&dev->
lock);
2844 DBG(dev,
"SET_INTERFACE interrupt: alt=%d intf=%d\n",
2853 udc_csr_epix = ep->
num;
2864 tmp =
readl(&dev->
csr->ne[udc_csr_epix]);
2873 writel(tmp, &dev->
csr->ne[udc_csr_epix]);
2883 spin_unlock(&dev->
lock);
2885 spin_lock(&dev->
lock);
2889 DBG(dev,
"USB Reset interrupt\n");
2893 soft_reset_occured = 0;
2899 udc_mask_unused_interrupts(dev);
2902 spin_unlock(&dev->
lock);
2908 spin_lock(&dev->
lock);
2917 && !soft_reset_after_usbreset_occured) {
2918 udc_soft_reset(dev);
2919 soft_reset_after_usbreset_occured++;
2927 DBG(dev,
"DMA machine reset\n");
2933 udc_basic_init(dev);
2936 udc_enable_dev_setup_interrupts(dev);
2945 DBG(dev,
"USB Suspend interrupt\n");
2947 if (dev->
driver->suspend) {
2948 spin_unlock(&dev->
lock);
2951 spin_lock(&dev->
lock);
2955 DBG(dev,
"ENUM interrupt\n");
2957 soft_reset_after_usbreset_occured = 0;
2964 udc_setup_endpoints(dev);
2969 activate_control_endpoints(dev);
2972 udc_enable_ep0_interrupts(dev);
2976 DBG(dev,
"USB SVC interrupt\n");
2986 DBG(dev,
"USB Disconnect (session valid low)\n");
2999 struct udc *dev =
pdev;
3005 spin_lock(&dev->
lock);
3011 ret_val |= udc_control_out_isr(dev);
3013 ret_val |= udc_control_in_isr(dev);
3029 ret_val |= udc_data_out_isr(dev, i);
3031 ret_val |= udc_data_in_isr(dev, i);
3042 ret_val |= udc_dev_isr(dev, reg);
3046 spin_unlock(&dev->
lock);
3051 static void gadget_release(
struct device *pdev)
3058 static void udc_remove(
struct udc *dev)
3062 if (timer_pending(&udc_timer))
3067 stop_pollstall_timer++;
3068 if (timer_pending(&udc_pollstall_timer))
3070 if (udc_pollstall_timer.data)
3076 static void udc_pci_remove(
struct pci_dev *pdev)
3080 dev = pci_get_drvdata(pdev);
3115 pci_set_drvdata(pdev,
NULL);
3121 static int init_dma_pools(
struct udc *dev)
3129 use_dma_bufferfill_mode = 0;
3132 use_dma_bufferfill_mode = 1;
3139 DBG(dev,
"can't get request data pool\n");
3151 DBG(dev,
"can't get stp request pool\n");
3158 if (td_stp ==
NULL) {
3167 if (td_data ==
NULL) {
3179 static int udc_pci_probe(
3196 dev = kzalloc(
sizeof(
struct udc),
GFP_KERNEL);
3216 dev_dbg(&pdev->
dev,
"pci device used already\n");
3226 dev_dbg(&pdev->
dev,
"start address cannot be mapped\n");
3261 pci_set_drvdata(pdev, dev);
3271 retval = init_dma_pools(dev);
3280 dev->
gadget.dev.dma_mask = pdev->
dev.dma_mask;
3283 if (udc_probe(dev) == 0)
3288 udc_pci_remove(pdev);
3293 static int udc_probe(
struct udc *dev)
3301 udc_pollstall_timer.data = 0;
3304 dev->
gadget.ops = &udc_ops;
3307 dev->
gadget.dev.release = gadget_release;
3312 startup_registers(dev);
3318 "irq %s, pci mem %08lx, chip rev %02x(Geode5536 %s)\n",
3323 dev_err(&dev->
pdev->dev,
"chip revision is A0; too old\n");
3328 "driver version: %s(for Geode5536 B1)\n", tmp);
3344 udc_timer.function = udc_timer_function;
3348 udc_pollstall_timer.function = udc_pollstall_timer_function;
3349 udc_pollstall_timer.data = 1;
3366 static int udc_remote_wakeup(
struct udc *dev)
3368 unsigned long flags;
3371 DBG(dev,
"UDC initiates remote wakeup\n");
3381 spin_unlock_irqrestore(&dev->
lock, flags);
3390 .class_mask = 0xffffffff,
3398 .name = (
char *)
name,
3400 .
probe = udc_pci_probe,
3401 .
remove = udc_pci_remove,