aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/pxa27x_udc.c
diff options
context:
space:
mode:
authorRobert Jarzmik <robert.jarzmik@free.fr>2009-04-21 23:41:03 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-06-16 00:44:42 -0400
commit367815eea4e483d9c3630f69ae0a57e1e32a92b0 (patch)
tree6f4031e06ab7bb589452fb31291eb2167796ff6c /drivers/usb/gadget/pxa27x_udc.c
parent9f5351b743716c796d13235651699fb4ec7aa64f (diff)
USB: pxa27x_udc: single-thread setup requests
Since the PXA 27x UDC automatically ACK's some control packets such as SET_INTERFACE, the gadgets may not get a chance to process the request before another control packet is received. The Linux gadgets do not expect to receive setup callbacks out of order. The file storage gadget only saves the "highest" priority request. The PXA27x UDC driver must make sure it only sends one up at a time, allowing the gadget to make changes before continuing. In theory, the host would be NACK'd while the gadget processes the change but the UDC has already ACK'd the request. If another request is sent by the host that is not automatically ACK'd by the UDC, then the throttling happens properly to regain sync. The observed case was the file_storage gadget timing out on a BulkReset request because the SET_INTERFACE was being processed by the gadget. Since SET_INTERFACE is higher priority than BulkReset, the BulkReset was dropped. This was exacerbated by turning on the debug which delayed the fsg signal processing thread. This also fixes the "should never get in WAIT_ACK_SET_CONF_INTERF state here!!!" warning. Reported-by: Vernon Sauder <vernoninhand@gmail.com> Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> Acked-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> index 51790b0..1937d8c 100644
Diffstat (limited to 'drivers/usb/gadget/pxa27x_udc.c')
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c50
1 files changed, 35 insertions, 15 deletions
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 51790b06b8ca..1937d8c7b433 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -473,6 +473,23 @@ static inline void udc_clear_mask_UDCCR(struct pxa_udc *udc, int mask)
473} 473}
474 474
475/** 475/**
476 * ep_write_UDCCSR - set bits in UDCCSR
477 * @udc: udc device
478 * @mask: bits to set in UDCCR
479 *
480 * Sets bits in UDCCSR (UDCCSR0 and UDCCSR*).
481 *
482 * A specific case is applied to ep0 : the ACM bit is always set to 1, for
483 * SET_INTERFACE and SET_CONFIGURATION.
484 */
485static inline void ep_write_UDCCSR(struct pxa_ep *ep, int mask)
486{
487 if (is_ep0(ep))
488 mask |= UDCCSR0_ACM;
489 udc_ep_writel(ep, UDCCSR, mask);
490}
491
492/**
476 * ep_count_bytes_remain - get how many bytes in udc endpoint 493 * ep_count_bytes_remain - get how many bytes in udc endpoint
477 * @ep: udc endpoint 494 * @ep: udc endpoint
478 * 495 *
@@ -860,7 +877,7 @@ static int read_packet(struct pxa_ep *ep, struct pxa27x_request *req)
860 *buf++ = udc_ep_readl(ep, UDCDR); 877 *buf++ = udc_ep_readl(ep, UDCDR);
861 req->req.actual += count; 878 req->req.actual += count;
862 879
863 udc_ep_writel(ep, UDCCSR, UDCCSR_PC); 880 ep_write_UDCCSR(ep, UDCCSR_PC);
864 881
865 return count; 882 return count;
866} 883}
@@ -968,12 +985,12 @@ static int write_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
968 if (udccsr & UDCCSR_PC) { 985 if (udccsr & UDCCSR_PC) {
969 ep_vdbg(ep, "Clearing Transmit Complete, udccsr=%x\n", 986 ep_vdbg(ep, "Clearing Transmit Complete, udccsr=%x\n",
970 udccsr); 987 udccsr);
971 udc_ep_writel(ep, UDCCSR, UDCCSR_PC); 988 ep_write_UDCCSR(ep, UDCCSR_PC);
972 } 989 }
973 if (udccsr & UDCCSR_TRN) { 990 if (udccsr & UDCCSR_TRN) {
974 ep_vdbg(ep, "Clearing Underrun on, udccsr=%x\n", 991 ep_vdbg(ep, "Clearing Underrun on, udccsr=%x\n",
975 udccsr); 992 udccsr);
976 udc_ep_writel(ep, UDCCSR, UDCCSR_TRN); 993 ep_write_UDCCSR(ep, UDCCSR_TRN);
977 } 994 }
978 995
979 count = write_packet(ep, req, max); 996 count = write_packet(ep, req, max);
@@ -995,7 +1012,7 @@ static int write_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
995 } 1012 }
996 1013
997 if (is_short) 1014 if (is_short)
998 udc_ep_writel(ep, UDCCSR, UDCCSR_SP); 1015 ep_write_UDCCSR(ep, UDCCSR_SP);
999 1016
1000 /* requests complete when all IN data is in the FIFO */ 1017 /* requests complete when all IN data is in the FIFO */
1001 if (is_last) { 1018 if (is_last) {
@@ -1028,7 +1045,7 @@ static int read_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
1028 1045
1029 while (epout_has_pkt(ep)) { 1046 while (epout_has_pkt(ep)) {
1030 count = read_packet(ep, req); 1047 count = read_packet(ep, req);
1031 udc_ep_writel(ep, UDCCSR, UDCCSR0_OPC); 1048 ep_write_UDCCSR(ep, UDCCSR0_OPC);
1032 inc_ep_stats_bytes(ep, count, !USB_DIR_IN); 1049 inc_ep_stats_bytes(ep, count, !USB_DIR_IN);
1033 1050
1034 is_short = (count < ep->fifo_size); 1051 is_short = (count < ep->fifo_size);
@@ -1073,7 +1090,7 @@ static int write_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
1073 1090
1074 /* Sends either a short packet or a 0 length packet */ 1091 /* Sends either a short packet or a 0 length packet */
1075 if (unlikely(is_short)) 1092 if (unlikely(is_short))
1076 udc_ep_writel(ep, UDCCSR, UDCCSR0_IPR); 1093 ep_write_UDCCSR(ep, UDCCSR0_IPR);
1077 1094
1078 ep_dbg(ep, "in %d bytes%s%s, %d left, req=%p, udccsr0=0x%03x\n", 1095 ep_dbg(ep, "in %d bytes%s%s, %d left, req=%p, udccsr0=0x%03x\n",
1079 count, is_short ? "/S" : "", is_last ? "/L" : "", 1096 count, is_short ? "/S" : "", is_last ? "/L" : "",
@@ -1276,7 +1293,7 @@ static int pxa_ep_set_halt(struct usb_ep *_ep, int value)
1276 1293
1277 /* FST, FEF bits are the same for control and non control endpoints */ 1294 /* FST, FEF bits are the same for control and non control endpoints */
1278 rc = 0; 1295 rc = 0;
1279 udc_ep_writel(ep, UDCCSR, UDCCSR_FST | UDCCSR_FEF); 1296 ep_write_UDCCSR(ep, UDCCSR_FST | UDCCSR_FEF);
1280 if (is_ep0(ep)) 1297 if (is_ep0(ep))
1281 set_ep0state(ep->dev, STALL); 1298 set_ep0state(ep->dev, STALL);
1282 1299
@@ -1342,7 +1359,7 @@ static void pxa_ep_fifo_flush(struct usb_ep *_ep)
1342 udc_ep_readl(ep, UDCDR); 1359 udc_ep_readl(ep, UDCDR);
1343 } else { 1360 } else {
1344 /* most IN status is the same, but ISO can't stall */ 1361 /* most IN status is the same, but ISO can't stall */
1345 udc_ep_writel(ep, UDCCSR, 1362 ep_write_UDCCSR(ep,
1346 UDCCSR_PC | UDCCSR_FEF | UDCCSR_TRN 1363 UDCCSR_PC | UDCCSR_FEF | UDCCSR_TRN
1347 | (EPXFERTYPE_is_ISO(ep) ? 0 : UDCCSR_SST)); 1364 | (EPXFERTYPE_is_ISO(ep) ? 0 : UDCCSR_SST));
1348 } 1365 }
@@ -1727,6 +1744,7 @@ static void udc_enable(struct pxa_udc *udc)
1727 memset(&udc->stats, 0, sizeof(udc->stats)); 1744 memset(&udc->stats, 0, sizeof(udc->stats));
1728 1745
1729 udc_set_mask_UDCCR(udc, UDCCR_UDE); 1746 udc_set_mask_UDCCR(udc, UDCCR_UDE);
1747 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_ACM);
1730 udelay(2); 1748 udelay(2);
1731 if (udc_readl(udc, UDCCR) & UDCCR_EMCE) 1749 if (udc_readl(udc, UDCCR) & UDCCR_EMCE)
1732 dev_err(udc->dev, "Configuration errors, udc disabled\n"); 1750 dev_err(udc->dev, "Configuration errors, udc disabled\n");
@@ -1899,7 +1917,7 @@ static void handle_ep0_ctrl_req(struct pxa_udc *udc,
1899 * packet. Generalize to pxa27x CPUs. 1917 * packet. Generalize to pxa27x CPUs.
1900 */ 1918 */
1901 if (epout_has_pkt(ep) && (ep_count_bytes_remain(ep) == 0)) 1919 if (epout_has_pkt(ep) && (ep_count_bytes_remain(ep) == 0))
1902 udc_ep_writel(ep, UDCCSR, UDCCSR0_OPC); 1920 ep_write_UDCCSR(ep, UDCCSR0_OPC);
1903 1921
1904 /* read SETUP packet */ 1922 /* read SETUP packet */
1905 for (i = 0; i < 2; i++) { 1923 for (i = 0; i < 2; i++) {
@@ -1927,7 +1945,7 @@ static void handle_ep0_ctrl_req(struct pxa_udc *udc,
1927 set_ep0state(udc, OUT_DATA_STAGE); 1945 set_ep0state(udc, OUT_DATA_STAGE);
1928 1946
1929 /* Tell UDC to enter Data Stage */ 1947 /* Tell UDC to enter Data Stage */
1930 udc_ep_writel(ep, UDCCSR, UDCCSR0_SA | UDCCSR0_OPC); 1948 ep_write_UDCCSR(ep, UDCCSR0_SA | UDCCSR0_OPC);
1931 1949
1932 i = udc->driver->setup(&udc->gadget, &u.r); 1950 i = udc->driver->setup(&udc->gadget, &u.r);
1933 if (i < 0) 1951 if (i < 0)
@@ -1937,7 +1955,7 @@ out:
1937stall: 1955stall:
1938 ep_dbg(ep, "protocol STALL, udccsr0=%03x err %d\n", 1956 ep_dbg(ep, "protocol STALL, udccsr0=%03x err %d\n",
1939 udc_ep_readl(ep, UDCCSR), i); 1957 udc_ep_readl(ep, UDCCSR), i);
1940 udc_ep_writel(ep, UDCCSR, UDCCSR0_FST | UDCCSR0_FTF); 1958 ep_write_UDCCSR(ep, UDCCSR0_FST | UDCCSR0_FTF);
1941 set_ep0state(udc, STALL); 1959 set_ep0state(udc, STALL);
1942 goto out; 1960 goto out;
1943} 1961}
@@ -2008,7 +2026,7 @@ static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
2008 if (udccsr0 & UDCCSR0_SST) { 2026 if (udccsr0 & UDCCSR0_SST) {
2009 ep_dbg(ep, "clearing stall status\n"); 2027 ep_dbg(ep, "clearing stall status\n");
2010 nuke(ep, -EPIPE); 2028 nuke(ep, -EPIPE);
2011 udc_ep_writel(ep, UDCCSR, UDCCSR0_SST); 2029 ep_write_UDCCSR(ep, UDCCSR0_SST);
2012 ep0_idle(udc); 2030 ep0_idle(udc);
2013 } 2031 }
2014 2032
@@ -2033,7 +2051,7 @@ static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
2033 break; 2051 break;
2034 case IN_DATA_STAGE: /* GET_DESCRIPTOR */ 2052 case IN_DATA_STAGE: /* GET_DESCRIPTOR */
2035 if (epout_has_pkt(ep)) 2053 if (epout_has_pkt(ep))
2036 udc_ep_writel(ep, UDCCSR, UDCCSR0_OPC); 2054 ep_write_UDCCSR(ep, UDCCSR0_OPC);
2037 if (req && !ep_is_full(ep)) 2055 if (req && !ep_is_full(ep))
2038 completed = write_ep0_fifo(ep, req); 2056 completed = write_ep0_fifo(ep, req);
2039 if (completed) 2057 if (completed)
@@ -2046,7 +2064,7 @@ static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
2046 ep0_end_out_req(ep, req); 2064 ep0_end_out_req(ep, req);
2047 break; 2065 break;
2048 case STALL: 2066 case STALL:
2049 udc_ep_writel(ep, UDCCSR, UDCCSR0_FST); 2067 ep_write_UDCCSR(ep, UDCCSR0_FST);
2050 break; 2068 break;
2051 case IN_STATUS_STAGE: 2069 case IN_STATUS_STAGE:
2052 /* 2070 /*
@@ -2141,6 +2159,7 @@ static void pxa27x_change_configuration(struct pxa_udc *udc, int config)
2141 2159
2142 set_ep0state(udc, WAIT_ACK_SET_CONF_INTERF); 2160 set_ep0state(udc, WAIT_ACK_SET_CONF_INTERF);
2143 udc->driver->setup(&udc->gadget, &req); 2161 udc->driver->setup(&udc->gadget, &req);
2162 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_AREN);
2144} 2163}
2145 2164
2146/** 2165/**
@@ -2169,6 +2188,7 @@ static void pxa27x_change_interface(struct pxa_udc *udc, int iface, int alt)
2169 2188
2170 set_ep0state(udc, WAIT_ACK_SET_CONF_INTERF); 2189 set_ep0state(udc, WAIT_ACK_SET_CONF_INTERF);
2171 udc->driver->setup(&udc->gadget, &req); 2190 udc->driver->setup(&udc->gadget, &req);
2191 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_AREN);
2172} 2192}
2173 2193
2174/* 2194/*
@@ -2290,7 +2310,7 @@ static void irq_udc_reset(struct pxa_udc *udc)
2290 memset(&udc->stats, 0, sizeof udc->stats); 2310 memset(&udc->stats, 0, sizeof udc->stats);
2291 2311
2292 nuke(ep, -EPROTO); 2312 nuke(ep, -EPROTO);
2293 udc_ep_writel(ep, UDCCSR, UDCCSR0_FTF | UDCCSR0_OPC); 2313 ep_write_UDCCSR(ep, UDCCSR0_FTF | UDCCSR0_OPC);
2294 ep0_idle(udc); 2314 ep0_idle(udc);
2295} 2315}
2296 2316