31 #include <linux/kernel.h>
32 #include <linux/module.h>
36 #include <linux/slab.h>
37 #include <linux/errno.h>
39 #include <linux/list.h>
43 #include <linux/usb/ch9.h>
45 #include <linux/i2c.h>
54 #include <asm/byteorder.h>
55 #include <mach/hardware.h>
58 #include <asm/system.h>
60 #include <mach/platform.h>
61 #include <mach/irqs.h>
62 #include <mach/board.h>
63 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
84 #define NUM_ENDPOINTS 16
91 #define IRQ_USB_DEVDMA 2
98 #define EP_MASK_SEL(ep, dir) (1 << (((ep) * 2) + dir))
100 #define EP_INT_TYPE 0
101 #define EP_ISO_TYPE 1
102 #define EP_BLK_TYPE 2
103 #define EP_CTL_TYPE 3
106 #define WAIT_FOR_SETUP 0
217 #define ep_dbg(epp, fmt, arg...) \
218 dev_dbg(epp->udc->dev, "%s: " fmt, __func__, ## arg)
219 #define ep_err(epp, fmt, arg...) \
220 dev_err(epp->udc->dev, "%s: " fmt, __func__, ## arg)
221 #define ep_info(epp, fmt, arg...) \
222 dev_info(epp->udc->dev, "%s: " fmt, __func__, ## arg)
223 #define ep_warn(epp, fmt, arg...) \
224 dev_warn(epp->udc->dev, "%s:" fmt, __func__, ## arg)
226 #define UDCA_BUFF_SIZE (128)
231 #define USB_CTRL IO_ADDRESS(LPC32XX_CLK_PM_BASE + 0x64)
234 #define USB_SLAVE_HCLK_EN (1 << 24)
235 #define USB_HOST_NEED_CLK_EN (1 << 21)
236 #define USB_DEV_NEED_CLK_EN (1 << 22)
242 #define USBD_DEVINTST(x) ((x) + 0x200)
243 #define USBD_DEVINTEN(x) ((x) + 0x204)
244 #define USBD_DEVINTCLR(x) ((x) + 0x208)
245 #define USBD_DEVINTSET(x) ((x) + 0x20C)
246 #define USBD_CMDCODE(x) ((x) + 0x210)
247 #define USBD_CMDDATA(x) ((x) + 0x214)
248 #define USBD_RXDATA(x) ((x) + 0x218)
249 #define USBD_TXDATA(x) ((x) + 0x21C)
250 #define USBD_RXPLEN(x) ((x) + 0x220)
251 #define USBD_TXPLEN(x) ((x) + 0x224)
252 #define USBD_CTRL(x) ((x) + 0x228)
253 #define USBD_DEVINTPRI(x) ((x) + 0x22C)
254 #define USBD_EPINTST(x) ((x) + 0x230)
255 #define USBD_EPINTEN(x) ((x) + 0x234)
256 #define USBD_EPINTCLR(x) ((x) + 0x238)
257 #define USBD_EPINTSET(x) ((x) + 0x23C)
258 #define USBD_EPINTPRI(x) ((x) + 0x240)
259 #define USBD_REEP(x) ((x) + 0x244)
260 #define USBD_EPIND(x) ((x) + 0x248)
261 #define USBD_EPMAXPSIZE(x) ((x) + 0x24C)
265 #define USBD_DMARST(x) ((x) + 0x250)
266 #define USBD_DMARCLR(x) ((x) + 0x254)
267 #define USBD_DMARSET(x) ((x) + 0x258)
269 #define USBD_UDCAH(x) ((x) + 0x280)
272 #define USBD_EPDMAST(x) ((x) + 0x284)
273 #define USBD_EPDMAEN(x) ((x) + 0x288)
274 #define USBD_EPDMADIS(x) ((x) + 0x28C)
276 #define USBD_DMAINTST(x) ((x) + 0x290)
277 #define USBD_DMAINTEN(x) ((x) + 0x294)
279 #define USBD_EOTINTST(x) ((x) + 0x2A0)
280 #define USBD_EOTINTCLR(x) ((x) + 0x2A4)
281 #define USBD_EOTINTSET(x) ((x) + 0x2A8)
283 #define USBD_NDDRTINTST(x) ((x) + 0x2AC)
284 #define USBD_NDDRTINTCLR(x) ((x) + 0x2B0)
285 #define USBD_NDDRTINTSET(x) ((x) + 0x2B4)
287 #define USBD_SYSERRTINTST(x) ((x) + 0x2B8)
288 #define USBD_SYSERRTINTCLR(x) ((x) + 0x2BC)
289 #define USBD_SYSERRTINTSET(x) ((x) + 0x2C0)
295 #define USBD_ERR_INT (1 << 9)
296 #define USBD_EP_RLZED (1 << 8)
297 #define USBD_TXENDPKT (1 << 7)
298 #define USBD_RXENDPKT (1 << 6)
299 #define USBD_CDFULL (1 << 5)
300 #define USBD_CCEMPTY (1 << 4)
301 #define USBD_DEV_STAT (1 << 3)
302 #define USBD_EP_SLOW (1 << 2)
303 #define USBD_EP_FAST (1 << 1)
304 #define USBD_FRAME (1 << 0)
311 #define USBD_RX_EP_SEL(e) (1 << ((e) << 1))
314 #define USBD_TX_EP_SEL(e) (1 << (((e) << 1) + 1))
325 #define USBD_EP_SEL(e) (1 << (e))
330 #define USBD_SYS_ERR_INT (1 << 2)
331 #define USBD_NEW_DD_INT (1 << 1)
332 #define USBD_EOT_INT (1 << 0)
337 #define USBD_PKT_RDY (1 << 11)
338 #define USBD_DV (1 << 10)
339 #define USBD_PK_LEN_MASK 0x3FF
344 #define USBD_LOG_ENDPOINT(e) ((e) << 2)
345 #define USBD_WR_EN (1 << 1)
346 #define USBD_RD_EN (1 << 0)
351 #define USBD_CMD_CODE(c) ((c) << 16)
352 #define USBD_CMD_PHASE(p) ((p) << 8)
357 #define USBD_DMAEP(e) (1 << (e))
369 #define DD_SETUP_ATLE_DMA_MODE 0x01
370 #define DD_SETUP_NEXT_DD_VALID 0x04
371 #define DD_SETUP_ISO_EP 0x10
372 #define DD_SETUP_PACKETLEN(n) (((n) & 0x7FF) << 5)
373 #define DD_SETUP_DMALENBYTES(n) (((n) & 0xFFFF) << 16)
376 #define DD_STATUS_DD_RETIRED 0x01
377 #define DD_STATUS_STS_MASK 0x1E
378 #define DD_STATUS_STS_NS 0x00
379 #define DD_STATUS_STS_BS 0x02
380 #define DD_STATUS_STS_NC 0x04
381 #define DD_STATUS_STS_DUR 0x06
382 #define DD_STATUS_STS_DOR 0x08
383 #define DD_STATUS_STS_SE 0x12
384 #define DD_STATUS_PKT_VAL 0x20
385 #define DD_STATUS_LSB_EX 0x40
386 #define DD_STATUS_MSB_EX 0x80
387 #define DD_STATUS_MLEN(n) (((n) >> 8) & 0x3F)
388 #define DD_STATUS_CURDMACNT(n) (((n) >> 16) & 0xFFFF)
396 #define FRAME_INT 0x00000001
397 #define EP_FAST_INT 0x00000002
398 #define EP_SLOW_INT 0x00000004
399 #define DEV_STAT_INT 0x00000008
400 #define CCEMTY_INT 0x00000010
401 #define CDFULL_INT 0x00000020
402 #define RxENDPKT_INT 0x00000040
403 #define TxENDPKT_INT 0x00000080
404 #define EP_RLZED_INT 0x00000100
405 #define ERR_INT 0x00000200
408 #define PKT_LNGTH_MASK 0x000003FF
409 #define PKT_DV 0x00000400
410 #define PKT_RDY 0x00000800
413 #define CTRL_RD_EN 0x00000001
414 #define CTRL_WR_EN 0x00000002
417 #define CMD_SET_ADDR 0x00D00500
418 #define CMD_CFG_DEV 0x00D80500
419 #define CMD_SET_MODE 0x00F30500
420 #define CMD_RD_FRAME 0x00F50500
421 #define DAT_RD_FRAME 0x00F50200
422 #define CMD_RD_TEST 0x00FD0500
423 #define DAT_RD_TEST 0x00FD0200
424 #define CMD_SET_DEV_STAT 0x00FE0500
425 #define CMD_GET_DEV_STAT 0x00FE0500
426 #define DAT_GET_DEV_STAT 0x00FE0200
427 #define CMD_GET_ERR_CODE 0x00FF0500
428 #define DAT_GET_ERR_CODE 0x00FF0200
429 #define CMD_RD_ERR_STAT 0x00FB0500
430 #define DAT_RD_ERR_STAT 0x00FB0200
431 #define DAT_WR_BYTE(x) (0x00000100 | ((x) << 16))
432 #define CMD_SEL_EP(x) (0x00000500 | ((x) << 16))
433 #define DAT_SEL_EP(x) (0x00000200 | ((x) << 16))
434 #define CMD_SEL_EP_CLRI(x) (0x00400500 | ((x) << 16))
435 #define DAT_SEL_EP_CLRI(x) (0x00400200 | ((x) << 16))
436 #define CMD_SET_EP_STAT(x) (0x00400500 | ((x) << 16))
437 #define CMD_CLR_BUF 0x00F20500
438 #define DAT_CLR_BUF 0x00F20200
439 #define CMD_VALID_BUF 0x00FA0500
442 #define DEV_ADDR_MASK 0x7F
446 #define CONF_DVICE 0x01
459 #define DEV_CON_CH 0x02
461 #define DEV_SUS_CH 0x08
465 #define ERR_EC_MASK 0x0F
470 #define ERR_UEPKT 0x02
471 #define ERR_DCRC 0x04
472 #define ERR_TIMOUT 0x08
474 #define ERR_B_OVRN 0x20
475 #define ERR_BTSTF 0x40
479 #define EP_SEL_F 0x01
480 #define EP_SEL_ST 0x02
481 #define EP_SEL_STP 0x04
482 #define EP_SEL_PO 0x08
483 #define EP_SEL_EPN 0x10
484 #define EP_SEL_B_1_FULL 0x20
485 #define EP_SEL_B_2_FULL 0x40
488 #define EP_STAT_ST 0x01
489 #define EP_STAT_DA 0x20
490 #define EP_STAT_RF_MO 0x40
491 #define EP_STAT_CND_ST 0x80
494 #define CLR_BUF_PO 0x01
498 #define NDD_REQ_INT 0x02
499 #define SYS_ERR_INT 0x04
501 #define DRIVER_VERSION "1.03"
509 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
510 static char *epnames[] = {
"INT",
"ISO",
"BULK",
"CTRL"};
511 static const char debug_filename[] =
"driver/udc";
519 ep->
ep.name, ep->
ep.maxpacket,
520 ep->
is_in ?
"in" :
"out");
524 if (list_empty(&ep->
queue))
532 req->
req.length, req->
req.buf);
547 seq_printf(s,
"vbus %s, pullup %s, %s powered%s, gadget %s\n\n",
548 udc->
vbus ?
"present" :
"off",
549 udc->
enabled ? (udc->
vbus ?
"active" :
"enabled") :
556 proc_ep_show(s, &udc->
ep[0]);
561 spin_unlock_irqrestore(&udc->lock, flags);
573 .open = proc_udc_open,
596 static void isp1301_udc_configure(
struct lpc32xx_udc *udc)
621 if (udc->
board->vbus_drv_pol != 0)
663 dev_info(udc->
dev,
"ISP1301 Product ID : 0x%04x\n",
665 dev_info(udc->
dev,
"ISP1301 Version ID : 0x%04x\n",
670 static void isp1301_pullup_set(
struct lpc32xx_udc *udc)
688 isp1301_pullup_set(udc);
691 static void isp1301_pullup_enable(
struct lpc32xx_udc *udc,
int en_pullup,
694 if (en_pullup == udc->
pullup)
699 isp1301_pullup_set(udc);
726 isp1301_set_powerstate(udc, udc->
poweron);
764 static inline void udc_protocol_cmd_data_w(
struct lpc32xx_udc *udc,
u32 cmd,
767 udc_protocol_cmd_w(udc, cmd);
768 udc_protocol_cmd_w(udc, data);
783 udc_protocol_cmd_w(udc, cmd);
791 "Protocol engine didn't receive response (CDFULL)\n");
802 static inline void uda_enable_devint(
struct lpc32xx_udc *udc,
u32 devmask)
816 static inline void uda_clear_devint(
struct lpc32xx_udc *udc,
u32 mask)
834 static void uda_disable_hwepint(
struct lpc32xx_udc *udc,
u32 hwep)
841 static inline void uda_clear_hwepint(
struct lpc32xx_udc *udc,
u32 hwep)
847 static inline void udc_ep_dma_enable(
struct lpc32xx_udc *udc,
u32 hwep)
853 static inline void udc_ep_dma_disable(
struct lpc32xx_udc *udc,
u32 hwep)
882 dev_dbg(udc->
dev,
"EP not correctly realized in hardware\n");
939 static void udc_clr_buffer_hwep(
struct lpc32xx_udc *udc,
u32 hwep)
941 udc_select_hwep(udc, hwep);
946 static void udc_val_buffer_hwep(
struct lpc32xx_udc *udc,
u32 hwep)
948 udc_select_hwep(udc, hwep);
955 uda_clear_hwepint(udc, hwep);
956 return udc_selep_clrint(udc, hwep);
992 static void udc_clk_set(
struct lpc32xx_udc *udc,
int enable)
1053 udc_ep_dma_enable(udc, hwep);
1056 if (req->
req.length % ep->
ep.maxpacket)
1079 udc_ep_dma_enable(udc, hwep);
1092 uda_disable_devint(udc, 0x3FF);
1095 for (i = 0; i < 32; i++) {
1096 uda_disable_hwepint(udc, i);
1097 uda_clear_hwepint(udc, i);
1098 udc_disable_hwep(udc, i);
1099 udc_unrealize_hwep(udc, i);
1103 udc_ep_dma_disable(udc, i);
1138 for (i = 0; i <= 1; i++) {
1139 udc_realize_hwep(udc, i, ep->
ep.maxpacket);
1140 uda_enable_hwepint(udc, i);
1141 udc_select_hwep(udc, i);
1142 udc_clrstall_hwep(udc, i);
1143 udc_clr_buffer_hwep(udc, i);
1154 udc_set_address(udc, 0);
1155 udc_set_address(udc, 0);
1174 udc->
board->conn_chgb(conn);
1178 static void uda_resm_susp_event(
struct lpc32xx_udc *udc,
u32 conn)
1182 udc->
board->susp_chgb(conn);
1191 static void uda_remwkp_cgh(
struct lpc32xx_udc *udc)
1206 switch (((
u32) data) & 0x3) {
1209 cbytes = (bytes & ~0x3);
1212 for (n = 0; n < cbytes; n += 4)
1216 bl = bytes - cbytes;
1219 for (n = 0; n <
bl; n++)
1220 data[cbytes + n] = ((tmp >> (n * 8)) & 0xFF);
1228 for (n = 0; n <
bytes; n += 4) {
1235 for (i = 0; i <
bl; i++)
1236 data[n + i] = (
u8) ((tmp >> (n * 8)) & 0xFF);
1242 cbytes = (bytes & ~0x3);
1245 for (n = 0; n < cbytes; n += 4) {
1247 *p16++ = (
u16)(tmp & 0xFFFF);
1248 *p16++ = (
u16)((tmp >> 16) & 0xFFFF);
1252 bl = bytes - cbytes;
1255 for (n = 0; n <
bl; n++)
1256 data[cbytes + n] = ((tmp >> (n * 8)) & 0xFF);
1281 dev_dbg(udc->
dev,
"No packet ready on FIFO EP read\n");
1288 if ((tmp > 0) && (data !=
NULL))
1289 udc_pop_fifo(udc, (
u8 *) data, tmp);
1294 udc_clr_buffer_hwep(udc, hwep);
1307 switch (((
u32) data) & 0x3) {
1310 cbytes = (bytes & ~0x3);
1313 for (n = 0; n < cbytes; n += 4)
1317 bl = bytes - cbytes;
1320 for (n = 0; n <
bl; n++)
1321 tmp |= data[cbytes + n] << (n * 8);
1330 for (n = 0; n <
bytes; n += 4) {
1336 for (i = 0; i <
bl; i++)
1337 tmp |= data[n + i] << (i * 8);
1345 cbytes = (bytes & ~0x3);
1348 for (n = 0; n < cbytes; n += 4) {
1349 tmp = *p16++ & 0xFFFF;
1350 tmp |= (*p16++ & 0xFFFF) << 16;
1355 bl = bytes - cbytes;
1358 for (n = 0; n <
bl; n++)
1359 tmp |= data[cbytes + n] << (n * 8);
1375 if ((bytes > 0) && (data ==
NULL))
1387 udc_stuff_fifo(udc, (
u8 *) data, bytes);
1391 udc_val_buffer_hwep(udc, hwep);
1396 static void uda_usb_reset(
struct lpc32xx_udc *udc)
1410 static void udc_ep0_send_zlp(
struct lpc32xx_udc *udc)
1424 return (fhi << 8) | flo;
1428 static inline void udc_set_device_configured(
struct lpc32xx_udc *udc)
1434 static inline void udc_set_device_unconfigured(
struct lpc32xx_udc *udc)
1444 INIT_LIST_HEAD(&udc->
gadget.ep_list);
1445 INIT_LIST_HEAD(&udc->
gadget.ep0->ep_list);
1453 INIT_LIST_HEAD(&ep->
queue);
1465 list_del_init(&req->
queue);
1469 status = req->
req.status;
1481 req->
req.dma, req->
req.length,
1487 req->
req.dma, req->
req.length,
1495 ep_dbg(ep,
"%s done %p, status %d\n", ep->
ep.name, req, status);
1498 spin_unlock(&udc->
lock);
1499 req->
req.complete(&ep->
ep, &req->
req);
1500 spin_lock(&udc->
lock);
1504 static void nuke(
struct lpc32xx_ep *ep,
int status)
1508 while (!list_empty(&ep->
queue)) {
1510 done(ep, req, status);
1520 static int udc_ep0_in_req(
struct lpc32xx_udc *udc)
1526 if (list_empty(&ep0->
queue))
1533 tsend = ts = req->
req.length - req->
req.actual;
1536 udc_ep0_send_zlp(udc);
1539 }
else if (ts > ep0->
ep.maxpacket)
1540 ts = ep0->
ep.maxpacket;
1543 udc_write_hwep(udc,
EP_IN, (req->
req.buf + req->
req.actual), ts);
1546 req->
req.actual +=
ts;
1548 if (tsend >= ep0->
ep.maxpacket)
1558 static int udc_ep0_out_req(
struct lpc32xx_udc *udc)
1562 u32 tr, bufferspace;
1564 if (list_empty(&ep0->
queue))
1571 if (req->
req.length == 0) {
1579 bufferspace = req->
req.length - req->
req.actual;
1580 if (bufferspace > ep0->
ep.maxpacket)
1581 bufferspace = ep0->
ep.maxpacket;
1585 tr = udc_read_hwep(udc,
EP_OUT, req->
req.buf + req->
req.actual,
1587 req->
req.actual += bufferspace;
1601 static void stop_activity(
struct lpc32xx_udc *udc)
1617 spin_unlock(&udc->
lock);
1619 spin_lock(&udc->
lock);
1622 isp1301_pullup_enable(udc, 0, 0);
1631 static void pullup(
struct lpc32xx_udc *udc,
int is_on)
1639 if (is_on != udc->
pullup)
1640 isp1301_pullup_enable(udc, is_on, 0);
1644 static int lpc32xx_ep_disable(
struct usb_ep *_ep)
1648 unsigned long flags;
1657 udc_ep_dma_disable(udc, ep->
hwep_num);
1667 uda_clear_hwepint(udc, ep->
hwep_num);
1668 udc_unrealize_hwep(udc, ep->
hwep_num);
1672 spin_unlock_irqrestore(&udc->
lock, flags);
1681 static int lpc32xx_ep_enable(
struct usb_ep *_ep,
1688 unsigned long flags;
1691 if ((!_ep) || (!ep) || (!desc) ||
1696 maxpacket = usb_endpoint_maxp(desc);
1697 if ((maxpacket == 0) || (maxpacket > ep->
maxpacket)) {
1698 dev_dbg(udc->
dev,
"bad ep descriptor's packet size\n");
1704 dev_dbg(udc->
dev,
"Can't re-enable EP0!!!\n");
1722 "Bad INT endpoint maxpacket %d\n", maxpacket);
1728 switch (maxpacket) {
1737 "Bad BULK endpoint maxpacket %d\n", maxpacket);
1749 ep->
ep.maxpacket = maxpacket;
1758 ep_dbg(ep,
"EP enabled: %s, HW:%d, MP:%d IN:%d\n", ep->
ep.name,
1763 udc_realize_hwep(udc, ep->
hwep_num, ep->
ep.maxpacket);
1764 udc_clr_buffer_hwep(udc, ep->
hwep_num);
1765 uda_disable_hwepint(udc, ep->
hwep_num);
1766 udc_clrstall_hwep(udc, ep->
hwep_num);
1769 udc_ep_dma_disable(udc, ep->
hwep_num);
1775 spin_unlock_irqrestore(&udc->
lock, flags);
1794 INIT_LIST_HEAD(&req->
queue);
1802 static void lpc32xx_ep_free_request(
struct usb_ep *_ep,
1813 static int lpc32xx_ep_queue(
struct usb_ep *_ep,
1819 unsigned long flags;
1826 !list_empty(&req->
queue))
1837 if ((!udc) || (!udc->
driver) ||
1853 if (req->
req.dma == 0) {
1855 ep->
udc->gadget.dev.parent,
1856 req->
req.buf, req->
req.length, direction);
1860 ep->
udc->gadget.dev.parent, req->
req.dma,
1861 req->
req.length, direction);
1866 dd = udc_dd_alloc(udc);
1893 ep_dbg(ep,
"%s queue req %p len %d buf %p (in=%d) z=%d\n", _ep->
name,
1903 if (list_empty(&ep->
queue)) {
1911 status = udc_ep0_in_req(udc);
1915 status = udc_ep0_out_req(udc);
1917 }
else if (ep->
is_in) {
1920 udc_ep_in_req_dma(udc, ep);
1924 udc_ep_out_req_dma(udc, ep);
1928 spin_unlock_irqrestore(&udc->
lock, flags);
1930 return (status < 0) ? status : 0;
1938 unsigned long flags;
1948 if (&req->
req == _req)
1951 if (&req->
req != _req) {
1952 spin_unlock_irqrestore(&ep->
udc->lock, flags);
1958 spin_unlock_irqrestore(&ep->
udc->lock, flags);
1964 static int lpc32xx_ep_set_halt(
struct usb_ep *_ep,
int value)
1968 unsigned long flags;
1990 spin_unlock_irqrestore(&udc->
lock, flags);
1996 static int lpc32xx_ep_set_wedge(
struct usb_ep *_ep)
2000 if (!_ep || !ep->
udc)
2005 return usb_ep_set_halt(_ep);
2008 static const struct usb_ep_ops lpc32xx_ep_ops = {
2009 .enable = lpc32xx_ep_enable,
2010 .disable = lpc32xx_ep_disable,
2011 .alloc_request = lpc32xx_ep_alloc_request,
2012 .free_request = lpc32xx_ep_free_request,
2013 .queue = lpc32xx_ep_queue,
2014 .dequeue = lpc32xx_ep_dequeue,
2015 .set_halt = lpc32xx_ep_set_halt,
2016 .set_wedge = lpc32xx_ep_set_wedge,
2023 udc_clearep_getsts(udc, ep->
hwep_num);
2042 uda_clear_hwepint(udc, ep->
hwep_num);
2049 epstatus = udc_clearep_getsts(udc, ep->
hwep_num);
2060 uda_disable_hwepint(udc, ep->
hwep_num);
2070 if (!list_empty(&ep->
queue)) {
2072 udc_ep_in_req_dma(udc, ep);
2074 udc_ep_out_req_dma(udc, ep);
2088 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
2094 ep_err(ep,
"DMA interrupt on no req!\n");
2101 ep_warn(ep,
"DMA descriptor did not retire\n");
2104 udc_ep_dma_disable(udc, ep->
hwep_num);
2113 ep_err(ep,
"AHB critical error!\n");
2129 ep_err(ep,
"DMA critical EP error: DD not serviced (0x%x)!\n",
2138 ep_err(ep,
"DMA critical EP error: EOT prior to service completion (0x%x)!\n",
2152 ep_err(ep,
"DMA critical EP error: System error (0x%x)!\n",
2161 req->
req.actual = req->
req.length;
2176 udc_clearep_getsts(udc, ep->
hwep_num);
2177 uda_enable_hwepint(udc, ep->
hwep_num);
2178 epstatus = udc_clearep_getsts(udc, ep->
hwep_num);
2190 udc_clearep_getsts(udc, ep->
hwep_num);
2191 if (!list_empty((&ep->
queue))) {
2193 udc_ep_in_req_dma(udc, ep);
2195 udc_ep_out_req_dma(udc, ep);
2206 static void udc_handle_dev(
struct lpc32xx_udc *udc)
2216 uda_power_event(udc, (tmp &
DEV_CON));
2226 uda_resm_susp_event(udc, 1);
2230 uda_resm_susp_event(udc, 0);
2262 }
else if (ep->
is_in)
2280 udc_write_hwep(udc,
EP_IN, &ep0buff, 2);
2285 static void udc_handle_ep0_setup(
struct lpc32xx_udc *udc)
2296 bytes = udc_read_hwep(udc,
EP_OUT, (
u32 *) &ctrlpkt, 8);
2298 ep_warn(ep0,
"Incorrectly sized setup packet (s/b 8, is %d)!\n",
2310 if (
likely(reqtype & USB_DIR_IN))
2332 uda_remwkp_cgh(udc);
2338 (tmp >= NUM_ENDPOINTS))
2348 udc_stall_hwep(udc, tmp);
2349 else if (!ep->
wedge)
2350 udc_clrstall_hwep(udc, tmp);
2361 udc_set_address(udc, wValue);
2367 udc_get_status(udc, reqtype, wIndex);
2377 spin_unlock(&udc->
lock);
2380 spin_lock(&udc->
lock);
2385 udc_set_device_configured(udc);
2392 udc_set_device_unconfigured(udc);
2403 "req %02x.%02x protocol STALL; stat %d\n",
2411 udc_ep0_send_zlp(udc);
2416 udc_stall_hwep(udc,
EP_IN);
2420 udc_ep0_send_zlp(udc);
2425 static void udc_handle_ep0_in(
struct lpc32xx_udc *udc)
2431 epstatus = udc_clearep_getsts(udc,
EP_IN);
2433 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
2439 udc_clrstall_hwep(udc,
EP_IN);
2449 udc_ep0_in_req(udc);
2459 static void udc_handle_ep0_out(
struct lpc32xx_udc *udc)
2465 epstatus = udc_clearep_getsts(udc,
EP_OUT);
2468 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
2473 if (epstatus & EP_SEL_ST) {
2474 udc_clrstall_hwep(udc,
EP_OUT);
2490 if (epstatus & EP_SEL_F)
2494 udc_handle_ep0_setup(udc);
2498 udc_ep0_out_req(udc);
2509 static int lpc32xx_get_frame(
struct usb_gadget *gadget)
2512 unsigned long flags;
2520 frame = (
int) udc_get_current_frame(udc);
2522 spin_unlock_irqrestore(&udc->
lock, flags);
2527 static int lpc32xx_wakeup(
struct usb_gadget *gadget)
2532 static int lpc32xx_set_selfpowered(
struct usb_gadget *gadget,
int is_on)
2548 unsigned long flags;
2555 udc_clk_set(udc, 1);
2562 spin_unlock_irqrestore(&udc->
lock, flags);
2574 udc_clk_set(udc, 0);
2577 spin_unlock_irqrestore(&udc->
lock, flags);
2583 static int lpc32xx_pullup(
struct usb_gadget *gadget,
int is_on)
2597 .get_frame = lpc32xx_get_frame,
2598 .wakeup = lpc32xx_wakeup,
2599 .set_selfpowered = lpc32xx_set_selfpowered,
2600 .vbus_session = lpc32xx_vbus_session,
2601 .pullup = lpc32xx_pullup,
2602 .udc_start = lpc32xx_start,
2603 .udc_stop = lpc32xx_stop,
2606 static void nop_release(
struct device *
dev)
2611 static const struct lpc32xx_udc controller_template = {
2613 .ops = &lpc32xx_udc_ops,
2616 .init_name =
"gadget",
2617 .release = nop_release,
2623 .ops = &lpc32xx_ep_ops,
2634 .ops = &lpc32xx_ep_ops,
2645 .ops = &lpc32xx_ep_ops,
2656 .ops = &lpc32xx_ep_ops,
2667 .ops = &lpc32xx_ep_ops,
2678 .ops = &lpc32xx_ep_ops,
2681 .hwep_num_base = 10,
2689 .ops = &lpc32xx_ep_ops,
2692 .hwep_num_base = 12,
2700 .ops = &lpc32xx_ep_ops,
2703 .hwep_num_base = 14,
2711 .ops = &lpc32xx_ep_ops,
2714 .hwep_num_base = 16,
2722 .ops = &lpc32xx_ep_ops,
2725 .hwep_num_base = 18,
2733 .ops = &lpc32xx_ep_ops,
2736 .hwep_num_base = 20,
2743 .name =
"ep11-bulk",
2744 .ops = &lpc32xx_ep_ops,
2747 .hwep_num_base = 22,
2755 .ops = &lpc32xx_ep_ops,
2758 .hwep_num_base = 24,
2766 .ops = &lpc32xx_ep_ops,
2769 .hwep_num_base = 26,
2776 .name =
"ep14-bulk",
2777 .ops = &lpc32xx_ep_ops,
2780 .hwep_num_base = 28,
2787 .name =
"ep15-bulk",
2788 .ops = &lpc32xx_ep_ops,
2791 .hwep_num_base = 30,
2799 static irqreturn_t lpc32xx_usb_lp_irq(
int irq,
void *_udc)
2804 spin_lock(&udc->
lock);
2815 udc_handle_dev(udc);
2829 dev_dbg(udc->
dev,
"Device error (0x%x)!\n", tmp);
2832 spin_unlock(&udc->
lock);
2838 static irqreturn_t lpc32xx_usb_hp_irq(
int irq,
void *_udc)
2843 spin_lock(&udc->
lock);
2855 udc_handle_ep0_in(udc);
2859 udc_handle_ep0_out(udc);
2868 if (tmp & (1 << udc->
ep[i].hwep_num))
2873 spin_unlock(&udc->
lock);
2878 static irqreturn_t lpc32xx_usb_devdma_irq(
int irq,
void *_udc)
2885 spin_lock(&udc->
lock);
2893 if (tmp & (1 << udc->
ep[i].hwep_num))
2894 udc_handle_dma_ep(udc, &udc->
ep[i]);
2897 spin_unlock(&udc->
lock);
2944 lpc32xx_vbus_session(&udc->
gadget, udc->
vbus);
2952 static irqreturn_t lpc32xx_usb_vbus_irq(
int irq,
void *_udc)
2963 static int lpc32xx_start(
struct usb_gadget *gadget,
2975 dev_err(udc->
dev,
"UDC already has a gadget driver\n");
2981 udc->
gadget.dev.of_node = udc->
dev->of_node;
2997 static int lpc32xx_stop(
struct usb_gadget *gadget,
3003 if (!driver || driver != udc->
driver)
3010 spin_lock(&udc->
lock);
3012 spin_unlock(&udc->
lock);
3023 spin_lock(&udc->
lock);
3024 udc_clk_set(udc, 0);
3025 spin_unlock(&udc->
lock);
3038 struct lpc32xx_udc *udc = platform_get_drvdata(dev);
3047 static void lpc32xx_usbd_conn_chg(
int conn)
3053 static void lpc32xx_usbd_susp_chg(
int susp)
3058 static void lpc32xx_rmwkup_chg(
int remote_wakup_enable)
3065 .conn_chgb = &lpc32xx_usbd_conn_chg,
3066 .susp_chgb = &lpc32xx_usbd_susp_chg,
3067 .rmwk_chgb = &lpc32xx_rmwkup_chg,
3071 static u64 lpc32xx_usbd_dmamask = ~(
u32) 0x7F;
3086 memcpy(udc, &controller_template,
sizeof(*udc));
3087 for (i = 0; i <= 15; i++)
3088 udc->
ep[i].udc = udc;
3092 udc->
gadget.dev.parent = dev;
3097 if (pdev->
dev.of_node) {
3101 isp1301_node =
NULL;
3110 dev_info(udc->
dev,
"ISP1301 I2C device at address 0x%x\n",
3113 pdev->
dev.dma_mask = &lpc32xx_usbd_dmamask;
3135 for (i = 0; i < 4; i++) {
3139 "irq resource %d not available!\n", i);
3148 dev_err(udc->
dev,
"someone's using UDC memory\n");
3150 goto request_mem_region_fail;
3166 dev_err(udc->
dev,
"failed to acquire USB PLL\n");
3172 dev_err(udc->
dev,
"failed to acquire USB device clock\n");
3174 goto usb_clk_get_fail;
3178 dev_err(udc->
dev,
"failed to acquire USB otg clock\n");
3180 goto usb_otg_clk_get_fail;
3186 dev_err(udc->
dev,
"failed to start USB PLL\n");
3187 goto pll_enable_fail;
3192 dev_err(udc->
dev,
"failed to set USB clock rate\n");
3201 dev_err(udc->
dev,
"failed to start USB device clock\n");
3202 goto usb_clk_enable_fail;
3208 dev_err(udc->
dev,
"failed to start USB otg clock\n");
3209 goto usb_otg_clk_enable_fail;
3223 isp1301_udc_configure(udc);
3229 dev_err(udc->
dev,
"error getting UDCA region\n");
3234 dev_dbg(udc->
dev,
"DMA buffer(0x%x bytes), P:0x%08x, V:0x%p\n",
3242 dev_err(udc->
dev,
"error getting DD DMA region\n");
3244 goto dma_alloc_fail;
3253 dev_err(udc->
dev,
"Device registration failure\n");
3254 goto dev_register_fail;
3262 dev_err(udc->
dev,
"LP request irq %d failed\n",
3269 dev_err(udc->
dev,
"HP request irq %d failed\n",
3275 lpc32xx_usb_devdma_irq, 0,
"udc_dma", udc);
3277 dev_err(udc->
dev,
"DEV request irq %d failed\n",
3287 dev_err(udc->
dev,
"VBUS request irq %d failed\n",
3302 goto add_gadget_fail;
3309 udc_clk_set(udc, 0);
3331 usb_otg_clk_enable_fail:
3333 usb_clk_enable_fail:
3338 usb_otg_clk_get_fail:
3347 request_mem_region_fail:
3357 struct lpc32xx_udc *udc = platform_get_drvdata(pdev);
3363 udc_clk_set(udc, 1);
3397 struct lpc32xx_udc *udc = platform_get_drvdata(pdev);
3402 isp1301_set_powerstate(udc, 0);
3405 udc_clk_set(udc, 0);
3420 struct lpc32xx_udc *udc = platform_get_drvdata(pdev);
3427 udc_clk_set(udc, 1);
3431 isp1301_set_powerstate(udc, 1);
3437 #define lpc32xx_udc_suspend NULL
3438 #define lpc32xx_udc_resume NULL
3451 .shutdown = lpc32xx_udc_shutdown,
3461 static int __init udc_init_module(
void)
3467 static void __exit udc_exit_module(
void)