diff options
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r-- | drivers/usb/gadget/omap_udc.c | 245 | ||||
-rw-r--r-- | drivers/usb/gadget/omap_udc.h | 3 |
2 files changed, 195 insertions, 53 deletions
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index 15d77c307930..cdcfd42843d4 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include <linux/usb_gadget.h> | 42 | #include <linux/usb_gadget.h> |
43 | #include <linux/usb/otg.h> | 43 | #include <linux/usb/otg.h> |
44 | #include <linux/dma-mapping.h> | 44 | #include <linux/dma-mapping.h> |
45 | #include <linux/clk.h> | ||
45 | 46 | ||
46 | #include <asm/byteorder.h> | 47 | #include <asm/byteorder.h> |
47 | #include <asm/io.h> | 48 | #include <asm/io.h> |
@@ -60,6 +61,11 @@ | |||
60 | /* bulk DMA seems to be behaving for both IN and OUT */ | 61 | /* bulk DMA seems to be behaving for both IN and OUT */ |
61 | #define USE_DMA | 62 | #define USE_DMA |
62 | 63 | ||
64 | /* FIXME: OMAP2 currently has some problem in DMA mode */ | ||
65 | #ifdef CONFIG_ARCH_OMAP2 | ||
66 | #undef USE_DMA | ||
67 | #endif | ||
68 | |||
63 | /* ISO too */ | 69 | /* ISO too */ |
64 | #define USE_ISO | 70 | #define USE_ISO |
65 | 71 | ||
@@ -99,7 +105,7 @@ static unsigned fifo_mode = 0; | |||
99 | * boot parameter "omap_udc:fifo_mode=42" | 105 | * boot parameter "omap_udc:fifo_mode=42" |
100 | */ | 106 | */ |
101 | module_param (fifo_mode, uint, 0); | 107 | module_param (fifo_mode, uint, 0); |
102 | MODULE_PARM_DESC (fifo_mode, "endpoint setup (0 == default)"); | 108 | MODULE_PARM_DESC (fifo_mode, "endpoint configuration"); |
103 | 109 | ||
104 | #ifdef USE_DMA | 110 | #ifdef USE_DMA |
105 | static unsigned use_dma = 1; | 111 | static unsigned use_dma = 1; |
@@ -122,7 +128,7 @@ static const char driver_desc [] = DRIVER_DESC; | |||
122 | /*-------------------------------------------------------------------------*/ | 128 | /*-------------------------------------------------------------------------*/ |
123 | 129 | ||
124 | /* there's a notion of "current endpoint" for modifying endpoint | 130 | /* there's a notion of "current endpoint" for modifying endpoint |
125 | * state, and PIO access to its FIFO. | 131 | * state, and PIO access to its FIFO. |
126 | */ | 132 | */ |
127 | 133 | ||
128 | static void use_ep(struct omap_ep *ep, u16 select) | 134 | static void use_ep(struct omap_ep *ep, u16 select) |
@@ -391,7 +397,7 @@ done(struct omap_ep *ep, struct omap_req *req, int status) | |||
391 | #define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY) | 397 | #define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY) |
392 | #define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY) | 398 | #define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY) |
393 | 399 | ||
394 | static inline int | 400 | static inline int |
395 | write_packet(u8 *buf, struct omap_req *req, unsigned max) | 401 | write_packet(u8 *buf, struct omap_req *req, unsigned max) |
396 | { | 402 | { |
397 | unsigned len; | 403 | unsigned len; |
@@ -456,7 +462,7 @@ static int write_fifo(struct omap_ep *ep, struct omap_req *req) | |||
456 | return is_last; | 462 | return is_last; |
457 | } | 463 | } |
458 | 464 | ||
459 | static inline int | 465 | static inline int |
460 | read_packet(u8 *buf, struct omap_req *req, unsigned avail) | 466 | read_packet(u8 *buf, struct omap_req *req, unsigned avail) |
461 | { | 467 | { |
462 | unsigned len; | 468 | unsigned len; |
@@ -542,9 +548,9 @@ static inline dma_addr_t dma_csac(unsigned lch) | |||
542 | /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is | 548 | /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is |
543 | * read before the DMA controller finished disabling the channel. | 549 | * read before the DMA controller finished disabling the channel. |
544 | */ | 550 | */ |
545 | csac = omap_readw(OMAP_DMA_CSAC(lch)); | 551 | csac = OMAP_DMA_CSAC_REG(lch); |
546 | if (csac == 0) | 552 | if (csac == 0) |
547 | csac = omap_readw(OMAP_DMA_CSAC(lch)); | 553 | csac = OMAP_DMA_CSAC_REG(lch); |
548 | return csac; | 554 | return csac; |
549 | } | 555 | } |
550 | 556 | ||
@@ -555,9 +561,9 @@ static inline dma_addr_t dma_cdac(unsigned lch) | |||
555 | /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is | 561 | /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is |
556 | * read before the DMA controller finished disabling the channel. | 562 | * read before the DMA controller finished disabling the channel. |
557 | */ | 563 | */ |
558 | cdac = omap_readw(OMAP_DMA_CDAC(lch)); | 564 | cdac = OMAP_DMA_CDAC_REG(lch); |
559 | if (cdac == 0) | 565 | if (cdac == 0) |
560 | cdac = omap_readw(OMAP_DMA_CDAC(lch)); | 566 | cdac = OMAP_DMA_CDAC_REG(lch); |
561 | return cdac; | 567 | return cdac; |
562 | } | 568 | } |
563 | 569 | ||
@@ -582,7 +588,7 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start) | |||
582 | } | 588 | } |
583 | 589 | ||
584 | #define DMA_DEST_LAST(x) (cpu_is_omap15xx() \ | 590 | #define DMA_DEST_LAST(x) (cpu_is_omap15xx() \ |
585 | ? omap_readw(OMAP_DMA_CSAC(x)) /* really: CPC */ \ | 591 | ? OMAP_DMA_CSAC_REG(x) /* really: CPC */ \ |
586 | : dma_cdac(x)) | 592 | : dma_cdac(x)) |
587 | 593 | ||
588 | static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) | 594 | static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) |
@@ -620,17 +626,19 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req) | |||
620 | || (cpu_is_omap15xx() && length < ep->maxpacket)) { | 626 | || (cpu_is_omap15xx() && length < ep->maxpacket)) { |
621 | txdma_ctrl = UDC_TXN_EOT | length; | 627 | txdma_ctrl = UDC_TXN_EOT | length; |
622 | omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, | 628 | omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, |
623 | length, 1, sync_mode); | 629 | length, 1, sync_mode, 0, 0); |
624 | } else { | 630 | } else { |
625 | length = min(length / ep->maxpacket, | 631 | length = min(length / ep->maxpacket, |
626 | (unsigned) UDC_TXN_TSC + 1); | 632 | (unsigned) UDC_TXN_TSC + 1); |
627 | txdma_ctrl = length; | 633 | txdma_ctrl = length; |
628 | omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, | 634 | omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, |
629 | ep->ep.maxpacket >> 1, length, sync_mode); | 635 | ep->ep.maxpacket >> 1, length, sync_mode, |
636 | 0, 0); | ||
630 | length *= ep->maxpacket; | 637 | length *= ep->maxpacket; |
631 | } | 638 | } |
632 | omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, | 639 | omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, |
633 | OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); | 640 | OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, |
641 | 0, 0); | ||
634 | 642 | ||
635 | omap_start_dma(ep->lch); | 643 | omap_start_dma(ep->lch); |
636 | ep->dma_counter = dma_csac(ep->lch); | 644 | ep->dma_counter = dma_csac(ep->lch); |
@@ -675,9 +683,11 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req) | |||
675 | req->dma_bytes = packets * ep->ep.maxpacket; | 683 | req->dma_bytes = packets * ep->ep.maxpacket; |
676 | omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, | 684 | omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, |
677 | ep->ep.maxpacket >> 1, packets, | 685 | ep->ep.maxpacket >> 1, packets, |
678 | OMAP_DMA_SYNC_ELEMENT); | 686 | OMAP_DMA_SYNC_ELEMENT, |
687 | 0, 0); | ||
679 | omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, | 688 | omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, |
680 | OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); | 689 | OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, |
690 | 0, 0); | ||
681 | ep->dma_counter = DMA_DEST_LAST(ep->lch); | 691 | ep->dma_counter = DMA_DEST_LAST(ep->lch); |
682 | 692 | ||
683 | UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1); | 693 | UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1); |
@@ -820,7 +830,8 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel) | |||
820 | omap_set_dma_dest_params(ep->lch, | 830 | omap_set_dma_dest_params(ep->lch, |
821 | OMAP_DMA_PORT_TIPB, | 831 | OMAP_DMA_PORT_TIPB, |
822 | OMAP_DMA_AMODE_CONSTANT, | 832 | OMAP_DMA_AMODE_CONSTANT, |
823 | (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG)); | 833 | (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG), |
834 | 0, 0); | ||
824 | } | 835 | } |
825 | } else { | 836 | } else { |
826 | status = omap_request_dma(OMAP_DMA_USB_W2FC_RX0 - 1 + channel, | 837 | status = omap_request_dma(OMAP_DMA_USB_W2FC_RX0 - 1 + channel, |
@@ -831,7 +842,8 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel) | |||
831 | omap_set_dma_src_params(ep->lch, | 842 | omap_set_dma_src_params(ep->lch, |
832 | OMAP_DMA_PORT_TIPB, | 843 | OMAP_DMA_PORT_TIPB, |
833 | OMAP_DMA_AMODE_CONSTANT, | 844 | OMAP_DMA_AMODE_CONSTANT, |
834 | (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG)); | 845 | (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG), |
846 | 0, 0); | ||
835 | /* EMIFF */ | 847 | /* EMIFF */ |
836 | omap_set_dma_dest_burst_mode(ep->lch, | 848 | omap_set_dma_dest_burst_mode(ep->lch, |
837 | OMAP_DMA_DATA_BURST_4); | 849 | OMAP_DMA_DATA_BURST_4); |
@@ -846,7 +858,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel) | |||
846 | 858 | ||
847 | /* channel type P: hw synch (fifo) */ | 859 | /* channel type P: hw synch (fifo) */ |
848 | if (!cpu_is_omap15xx()) | 860 | if (!cpu_is_omap15xx()) |
849 | omap_writew(2, OMAP_DMA_LCH_CTRL(ep->lch)); | 861 | OMAP1_DMA_LCH_CTRL_REG(ep->lch) = 2; |
850 | } | 862 | } |
851 | 863 | ||
852 | just_restart: | 864 | just_restart: |
@@ -893,7 +905,7 @@ static void dma_channel_release(struct omap_ep *ep) | |||
893 | else | 905 | else |
894 | req = NULL; | 906 | req = NULL; |
895 | 907 | ||
896 | active = ((1 << 7) & omap_readl(OMAP_DMA_CCR(ep->lch))) != 0; | 908 | active = ((1 << 7) & OMAP_DMA_CCR_REG(ep->lch)) != 0; |
897 | 909 | ||
898 | DBG("%s release %s %cxdma%d %p\n", ep->ep.name, | 910 | DBG("%s release %s %cxdma%d %p\n", ep->ep.name, |
899 | active ? "active" : "idle", | 911 | active ? "active" : "idle", |
@@ -1117,7 +1129,7 @@ static int omap_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) | |||
1117 | */ | 1129 | */ |
1118 | dma_channel_release(ep); | 1130 | dma_channel_release(ep); |
1119 | dma_channel_claim(ep, channel); | 1131 | dma_channel_claim(ep, channel); |
1120 | } else | 1132 | } else |
1121 | done(ep, req, -ECONNRESET); | 1133 | done(ep, req, -ECONNRESET); |
1122 | spin_unlock_irqrestore(&ep->udc->lock, flags); | 1134 | spin_unlock_irqrestore(&ep->udc->lock, flags); |
1123 | return 0; | 1135 | return 0; |
@@ -1153,7 +1165,7 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value) | |||
1153 | 1165 | ||
1154 | /* IN endpoints must already be idle */ | 1166 | /* IN endpoints must already be idle */ |
1155 | if ((ep->bEndpointAddress & USB_DIR_IN) | 1167 | if ((ep->bEndpointAddress & USB_DIR_IN) |
1156 | && !list_empty(&ep->queue)) { | 1168 | && !list_empty(&ep->queue)) { |
1157 | status = -EAGAIN; | 1169 | status = -EAGAIN; |
1158 | goto done; | 1170 | goto done; |
1159 | } | 1171 | } |
@@ -1298,6 +1310,23 @@ static void pullup_disable(struct omap_udc *udc) | |||
1298 | UDC_SYSCON1_REG &= ~UDC_PULLUP_EN; | 1310 | UDC_SYSCON1_REG &= ~UDC_PULLUP_EN; |
1299 | } | 1311 | } |
1300 | 1312 | ||
1313 | static struct omap_udc *udc; | ||
1314 | |||
1315 | static void omap_udc_enable_clock(int enable) | ||
1316 | { | ||
1317 | if (udc == NULL || udc->dc_clk == NULL || udc->hhc_clk == NULL) | ||
1318 | return; | ||
1319 | |||
1320 | if (enable) { | ||
1321 | clk_enable(udc->dc_clk); | ||
1322 | clk_enable(udc->hhc_clk); | ||
1323 | udelay(100); | ||
1324 | } else { | ||
1325 | clk_disable(udc->hhc_clk); | ||
1326 | clk_disable(udc->dc_clk); | ||
1327 | } | ||
1328 | } | ||
1329 | |||
1301 | /* | 1330 | /* |
1302 | * Called by whatever detects VBUS sessions: external transceiver | 1331 | * Called by whatever detects VBUS sessions: external transceiver |
1303 | * driver, or maybe GPIO0 VBUS IRQ. May request 48 MHz clock. | 1332 | * driver, or maybe GPIO0 VBUS IRQ. May request 48 MHz clock. |
@@ -1318,10 +1347,22 @@ static int omap_vbus_session(struct usb_gadget *gadget, int is_active) | |||
1318 | else | 1347 | else |
1319 | FUNC_MUX_CTRL_0_REG &= ~VBUS_CTRL_1510; | 1348 | FUNC_MUX_CTRL_0_REG &= ~VBUS_CTRL_1510; |
1320 | } | 1349 | } |
1350 | if (udc->dc_clk != NULL && is_active) { | ||
1351 | if (!udc->clk_requested) { | ||
1352 | omap_udc_enable_clock(1); | ||
1353 | udc->clk_requested = 1; | ||
1354 | } | ||
1355 | } | ||
1321 | if (can_pullup(udc)) | 1356 | if (can_pullup(udc)) |
1322 | pullup_enable(udc); | 1357 | pullup_enable(udc); |
1323 | else | 1358 | else |
1324 | pullup_disable(udc); | 1359 | pullup_disable(udc); |
1360 | if (udc->dc_clk != NULL && !is_active) { | ||
1361 | if (udc->clk_requested) { | ||
1362 | omap_udc_enable_clock(0); | ||
1363 | udc->clk_requested = 0; | ||
1364 | } | ||
1365 | } | ||
1325 | spin_unlock_irqrestore(&udc->lock, flags); | 1366 | spin_unlock_irqrestore(&udc->lock, flags); |
1326 | return 0; | 1367 | return 0; |
1327 | } | 1368 | } |
@@ -1441,7 +1482,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src) | |||
1441 | } | 1482 | } |
1442 | } | 1483 | } |
1443 | 1484 | ||
1444 | /* IN/OUT packets mean we're in the DATA or STATUS stage. | 1485 | /* IN/OUT packets mean we're in the DATA or STATUS stage. |
1445 | * This driver uses only uses protocol stalls (ep0 never halts), | 1486 | * This driver uses only uses protocol stalls (ep0 never halts), |
1446 | * and if we got this far the gadget driver already had a | 1487 | * and if we got this far the gadget driver already had a |
1447 | * chance to stall. Tries to be forgiving of host oddities. | 1488 | * chance to stall. Tries to be forgiving of host oddities. |
@@ -1509,7 +1550,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src) | |||
1509 | } else if (stat == 0) | 1550 | } else if (stat == 0) |
1510 | UDC_CTRL_REG = UDC_SET_FIFO_EN; | 1551 | UDC_CTRL_REG = UDC_SET_FIFO_EN; |
1511 | UDC_EP_NUM_REG = 0; | 1552 | UDC_EP_NUM_REG = 0; |
1512 | 1553 | ||
1513 | /* activate status stage */ | 1554 | /* activate status stage */ |
1514 | if (stat == 1) { | 1555 | if (stat == 1) { |
1515 | done(ep0, req, 0); | 1556 | done(ep0, req, 0); |
@@ -1866,7 +1907,7 @@ static void pio_out_timer(unsigned long _ep) | |||
1866 | 1907 | ||
1867 | spin_lock_irqsave(&ep->udc->lock, flags); | 1908 | spin_lock_irqsave(&ep->udc->lock, flags); |
1868 | if (!list_empty(&ep->queue) && ep->ackwait) { | 1909 | if (!list_empty(&ep->queue) && ep->ackwait) { |
1869 | use_ep(ep, 0); | 1910 | use_ep(ep, UDC_EP_SEL); |
1870 | stat_flg = UDC_STAT_FLG_REG; | 1911 | stat_flg = UDC_STAT_FLG_REG; |
1871 | 1912 | ||
1872 | if ((stat_flg & UDC_ACK) && (!(stat_flg & UDC_FIFO_EN) | 1913 | if ((stat_flg & UDC_ACK) && (!(stat_flg & UDC_FIFO_EN) |
@@ -1876,12 +1917,12 @@ static void pio_out_timer(unsigned long _ep) | |||
1876 | VDBG("%s: lose, %04x\n", ep->ep.name, stat_flg); | 1917 | VDBG("%s: lose, %04x\n", ep->ep.name, stat_flg); |
1877 | req = container_of(ep->queue.next, | 1918 | req = container_of(ep->queue.next, |
1878 | struct omap_req, queue); | 1919 | struct omap_req, queue); |
1879 | UDC_EP_NUM_REG = ep->bEndpointAddress | UDC_EP_SEL; | ||
1880 | (void) read_fifo(ep, req); | 1920 | (void) read_fifo(ep, req); |
1881 | UDC_EP_NUM_REG = ep->bEndpointAddress; | 1921 | UDC_EP_NUM_REG = ep->bEndpointAddress; |
1882 | UDC_CTRL_REG = UDC_SET_FIFO_EN; | 1922 | UDC_CTRL_REG = UDC_SET_FIFO_EN; |
1883 | ep->ackwait = 1 + ep->double_buf; | 1923 | ep->ackwait = 1 + ep->double_buf; |
1884 | } | 1924 | } else |
1925 | deselect_ep(); | ||
1885 | } | 1926 | } |
1886 | mod_timer(&ep->timer, PIO_OUT_TIMEOUT); | 1927 | mod_timer(&ep->timer, PIO_OUT_TIMEOUT); |
1887 | spin_unlock_irqrestore(&ep->udc->lock, flags); | 1928 | spin_unlock_irqrestore(&ep->udc->lock, flags); |
@@ -2028,7 +2069,17 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev) | |||
2028 | 2069 | ||
2029 | /*-------------------------------------------------------------------------*/ | 2070 | /*-------------------------------------------------------------------------*/ |
2030 | 2071 | ||
2031 | static struct omap_udc *udc; | 2072 | static inline int machine_needs_vbus_session(void) |
2073 | { | ||
2074 | return (machine_is_omap_innovator() | ||
2075 | || machine_is_omap_osk() | ||
2076 | || machine_is_omap_apollon() | ||
2077 | #ifndef CONFIG_MACH_OMAP_H4_OTG | ||
2078 | || machine_is_omap_h4() | ||
2079 | #endif | ||
2080 | || machine_is_sx1() | ||
2081 | ); | ||
2082 | } | ||
2032 | 2083 | ||
2033 | int usb_gadget_register_driver (struct usb_gadget_driver *driver) | 2084 | int usb_gadget_register_driver (struct usb_gadget_driver *driver) |
2034 | { | 2085 | { |
@@ -2070,6 +2121,9 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) | |||
2070 | udc->gadget.dev.driver = &driver->driver; | 2121 | udc->gadget.dev.driver = &driver->driver; |
2071 | spin_unlock_irqrestore(&udc->lock, flags); | 2122 | spin_unlock_irqrestore(&udc->lock, flags); |
2072 | 2123 | ||
2124 | if (udc->dc_clk != NULL) | ||
2125 | omap_udc_enable_clock(1); | ||
2126 | |||
2073 | status = driver->bind (&udc->gadget); | 2127 | status = driver->bind (&udc->gadget); |
2074 | if (status) { | 2128 | if (status) { |
2075 | DBG("bind to %s --> %d\n", driver->driver.name, status); | 2129 | DBG("bind to %s --> %d\n", driver->driver.name, status); |
@@ -2103,10 +2157,12 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) | |||
2103 | /* boards that don't have VBUS sensing can't autogate 48MHz; | 2157 | /* boards that don't have VBUS sensing can't autogate 48MHz; |
2104 | * can't enter deep sleep while a gadget driver is active. | 2158 | * can't enter deep sleep while a gadget driver is active. |
2105 | */ | 2159 | */ |
2106 | if (machine_is_omap_innovator() || machine_is_omap_osk()) | 2160 | if (machine_needs_vbus_session()) |
2107 | omap_vbus_session(&udc->gadget, 1); | 2161 | omap_vbus_session(&udc->gadget, 1); |
2108 | 2162 | ||
2109 | done: | 2163 | done: |
2164 | if (udc->dc_clk != NULL) | ||
2165 | omap_udc_enable_clock(0); | ||
2110 | return status; | 2166 | return status; |
2111 | } | 2167 | } |
2112 | EXPORT_SYMBOL(usb_gadget_register_driver); | 2168 | EXPORT_SYMBOL(usb_gadget_register_driver); |
@@ -2121,7 +2177,10 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | |||
2121 | if (!driver || driver != udc->driver || !driver->unbind) | 2177 | if (!driver || driver != udc->driver || !driver->unbind) |
2122 | return -EINVAL; | 2178 | return -EINVAL; |
2123 | 2179 | ||
2124 | if (machine_is_omap_innovator() || machine_is_omap_osk()) | 2180 | if (udc->dc_clk != NULL) |
2181 | omap_udc_enable_clock(1); | ||
2182 | |||
2183 | if (machine_needs_vbus_session()) | ||
2125 | omap_vbus_session(&udc->gadget, 0); | 2184 | omap_vbus_session(&udc->gadget, 0); |
2126 | 2185 | ||
2127 | if (udc->transceiver) | 2186 | if (udc->transceiver) |
@@ -2137,6 +2196,8 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | |||
2137 | udc->gadget.dev.driver = NULL; | 2196 | udc->gadget.dev.driver = NULL; |
2138 | udc->driver = NULL; | 2197 | udc->driver = NULL; |
2139 | 2198 | ||
2199 | if (udc->dc_clk != NULL) | ||
2200 | omap_udc_enable_clock(0); | ||
2140 | DBG("unregistered driver '%s'\n", driver->driver.name); | 2201 | DBG("unregistered driver '%s'\n", driver->driver.name); |
2141 | return status; | 2202 | return status; |
2142 | } | 2203 | } |
@@ -2219,7 +2280,7 @@ static char *trx_mode(unsigned m, int enabled) | |||
2219 | case 0: return enabled ? "*6wire" : "unused"; | 2280 | case 0: return enabled ? "*6wire" : "unused"; |
2220 | case 1: return "4wire"; | 2281 | case 1: return "4wire"; |
2221 | case 2: return "3wire"; | 2282 | case 2: return "3wire"; |
2222 | case 3: return "6wire"; | 2283 | case 3: return "6wire"; |
2223 | default: return "unknown"; | 2284 | default: return "unknown"; |
2224 | } | 2285 | } |
2225 | } | 2286 | } |
@@ -2228,11 +2289,18 @@ static int proc_otg_show(struct seq_file *s) | |||
2228 | { | 2289 | { |
2229 | u32 tmp; | 2290 | u32 tmp; |
2230 | u32 trans; | 2291 | u32 trans; |
2292 | char *ctrl_name; | ||
2231 | 2293 | ||
2232 | tmp = OTG_REV_REG; | 2294 | tmp = OTG_REV_REG; |
2233 | trans = USB_TRANSCEIVER_CTRL_REG; | 2295 | if (cpu_is_omap24xx()) { |
2234 | seq_printf(s, "\nOTG rev %d.%d, transceiver_ctrl %05x\n", | 2296 | ctrl_name = "control_devconf"; |
2235 | tmp >> 4, tmp & 0xf, trans); | 2297 | trans = CONTROL_DEVCONF_REG; |
2298 | } else { | ||
2299 | ctrl_name = "tranceiver_ctrl"; | ||
2300 | trans = USB_TRANSCEIVER_CTRL_REG; | ||
2301 | } | ||
2302 | seq_printf(s, "\nOTG rev %d.%d, %s %05x\n", | ||
2303 | tmp >> 4, tmp & 0xf, ctrl_name, trans); | ||
2236 | tmp = OTG_SYSCON_1_REG; | 2304 | tmp = OTG_SYSCON_1_REG; |
2237 | seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," | 2305 | seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," |
2238 | FOURBITS "\n", tmp, | 2306 | FOURBITS "\n", tmp, |
@@ -2307,7 +2375,7 @@ static int proc_udc_show(struct seq_file *s, void *_) | |||
2307 | driver_desc, | 2375 | driver_desc, |
2308 | use_dma ? " (dma)" : ""); | 2376 | use_dma ? " (dma)" : ""); |
2309 | 2377 | ||
2310 | tmp = UDC_REV_REG & 0xff; | 2378 | tmp = UDC_REV_REG & 0xff; |
2311 | seq_printf(s, | 2379 | seq_printf(s, |
2312 | "UDC rev %d.%d, fifo mode %d, gadget %s\n" | 2380 | "UDC rev %d.%d, fifo mode %d, gadget %s\n" |
2313 | "hmc %d, transceiver %s\n", | 2381 | "hmc %d, transceiver %s\n", |
@@ -2315,11 +2383,16 @@ static int proc_udc_show(struct seq_file *s, void *_) | |||
2315 | fifo_mode, | 2383 | fifo_mode, |
2316 | udc->driver ? udc->driver->driver.name : "(none)", | 2384 | udc->driver ? udc->driver->driver.name : "(none)", |
2317 | HMC, | 2385 | HMC, |
2318 | udc->transceiver ? udc->transceiver->label : "(none)"); | 2386 | udc->transceiver |
2319 | seq_printf(s, "ULPD control %04x req %04x status %04x\n", | 2387 | ? udc->transceiver->label |
2320 | __REG16(ULPD_CLOCK_CTRL), | 2388 | : ((cpu_is_omap1710() || cpu_is_omap24xx()) |
2321 | __REG16(ULPD_SOFT_REQ), | 2389 | ? "external" : "(none)")); |
2322 | __REG16(ULPD_STATUS_REQ)); | 2390 | if (cpu_class_is_omap1()) { |
2391 | seq_printf(s, "ULPD control %04x req %04x status %04x\n", | ||
2392 | __REG16(ULPD_CLOCK_CTRL), | ||
2393 | __REG16(ULPD_SOFT_REQ), | ||
2394 | __REG16(ULPD_STATUS_REQ)); | ||
2395 | } | ||
2323 | 2396 | ||
2324 | /* OTG controller registers */ | 2397 | /* OTG controller registers */ |
2325 | if (!cpu_is_omap15xx()) | 2398 | if (!cpu_is_omap15xx()) |
@@ -2504,9 +2577,10 @@ omap_ep_setup(char *name, u8 addr, u8 type, | |||
2504 | dbuf = 1; | 2577 | dbuf = 1; |
2505 | } else { | 2578 | } else { |
2506 | /* double-buffering "not supported" on 15xx, | 2579 | /* double-buffering "not supported" on 15xx, |
2507 | * and ignored for PIO-IN on 16xx | 2580 | * and ignored for PIO-IN on newer chips |
2581 | * (for more reliable behavior) | ||
2508 | */ | 2582 | */ |
2509 | if (!use_dma || cpu_is_omap15xx()) | 2583 | if (!use_dma || cpu_is_omap15xx() || cpu_is_omap24xx()) |
2510 | dbuf = 0; | 2584 | dbuf = 0; |
2511 | 2585 | ||
2512 | switch (maxp) { | 2586 | switch (maxp) { |
@@ -2549,7 +2623,7 @@ omap_ep_setup(char *name, u8 addr, u8 type, | |||
2549 | ep->bEndpointAddress = addr; | 2623 | ep->bEndpointAddress = addr; |
2550 | ep->bmAttributes = type; | 2624 | ep->bmAttributes = type; |
2551 | ep->double_buf = dbuf; | 2625 | ep->double_buf = dbuf; |
2552 | ep->udc = udc; | 2626 | ep->udc = udc; |
2553 | 2627 | ||
2554 | ep->ep.name = ep->name; | 2628 | ep->ep.name = ep->name; |
2555 | ep->ep.ops = &omap_ep_ops; | 2629 | ep->ep.ops = &omap_ep_ops; |
@@ -2709,15 +2783,37 @@ static int __init omap_udc_probe(struct platform_device *pdev) | |||
2709 | struct otg_transceiver *xceiv = NULL; | 2783 | struct otg_transceiver *xceiv = NULL; |
2710 | const char *type = NULL; | 2784 | const char *type = NULL; |
2711 | struct omap_usb_config *config = pdev->dev.platform_data; | 2785 | struct omap_usb_config *config = pdev->dev.platform_data; |
2786 | struct clk *dc_clk; | ||
2787 | struct clk *hhc_clk; | ||
2712 | 2788 | ||
2713 | /* NOTE: "knows" the order of the resources! */ | 2789 | /* NOTE: "knows" the order of the resources! */ |
2714 | if (!request_mem_region(pdev->resource[0].start, | 2790 | if (!request_mem_region(pdev->resource[0].start, |
2715 | pdev->resource[0].end - pdev->resource[0].start + 1, | 2791 | pdev->resource[0].end - pdev->resource[0].start + 1, |
2716 | driver_name)) { | 2792 | driver_name)) { |
2717 | DBG("request_mem_region failed\n"); | 2793 | DBG("request_mem_region failed\n"); |
2718 | return -EBUSY; | 2794 | return -EBUSY; |
2719 | } | 2795 | } |
2720 | 2796 | ||
2797 | if (cpu_is_omap16xx()) { | ||
2798 | dc_clk = clk_get(&pdev->dev, "usb_dc_ck"); | ||
2799 | hhc_clk = clk_get(&pdev->dev, "usb_hhc_ck"); | ||
2800 | BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk)); | ||
2801 | /* can't use omap_udc_enable_clock yet */ | ||
2802 | clk_enable(dc_clk); | ||
2803 | clk_enable(hhc_clk); | ||
2804 | udelay(100); | ||
2805 | } | ||
2806 | |||
2807 | if (cpu_is_omap24xx()) { | ||
2808 | dc_clk = clk_get(&pdev->dev, "usb_fck"); | ||
2809 | hhc_clk = clk_get(&pdev->dev, "usb_l4_ick"); | ||
2810 | BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk)); | ||
2811 | /* can't use omap_udc_enable_clock yet */ | ||
2812 | clk_enable(dc_clk); | ||
2813 | clk_enable(hhc_clk); | ||
2814 | udelay(100); | ||
2815 | } | ||
2816 | |||
2721 | INFO("OMAP UDC rev %d.%d%s\n", | 2817 | INFO("OMAP UDC rev %d.%d%s\n", |
2722 | UDC_REV_REG >> 4, UDC_REV_REG & 0xf, | 2818 | UDC_REV_REG >> 4, UDC_REV_REG & 0xf, |
2723 | config->otg ? ", Mini-AB" : ""); | 2819 | config->otg ? ", Mini-AB" : ""); |
@@ -2727,7 +2823,7 @@ static int __init omap_udc_probe(struct platform_device *pdev) | |||
2727 | hmc = HMC_1510; | 2823 | hmc = HMC_1510; |
2728 | type = "(unknown)"; | 2824 | type = "(unknown)"; |
2729 | 2825 | ||
2730 | if (machine_is_omap_innovator()) { | 2826 | if (machine_is_omap_innovator() || machine_is_sx1()) { |
2731 | /* just set up software VBUS detect, and then | 2827 | /* just set up software VBUS detect, and then |
2732 | * later rig it so we always report VBUS. | 2828 | * later rig it so we always report VBUS. |
2733 | * FIXME without really sensing VBUS, we can't | 2829 | * FIXME without really sensing VBUS, we can't |
@@ -2756,6 +2852,15 @@ static int __init omap_udc_probe(struct platform_device *pdev) | |||
2756 | } | 2852 | } |
2757 | 2853 | ||
2758 | hmc = HMC_1610; | 2854 | hmc = HMC_1610; |
2855 | |||
2856 | if (cpu_is_omap24xx()) { | ||
2857 | /* this could be transceiverless in one of the | ||
2858 | * "we don't need to know" modes. | ||
2859 | */ | ||
2860 | type = "external"; | ||
2861 | goto known; | ||
2862 | } | ||
2863 | |||
2759 | switch (hmc) { | 2864 | switch (hmc) { |
2760 | case 0: /* POWERUP DEFAULT == 0 */ | 2865 | case 0: /* POWERUP DEFAULT == 0 */ |
2761 | case 4: | 2866 | case 4: |
@@ -2794,6 +2899,7 @@ bad_on_1710: | |||
2794 | goto cleanup0; | 2899 | goto cleanup0; |
2795 | } | 2900 | } |
2796 | } | 2901 | } |
2902 | known: | ||
2797 | INFO("hmc mode %d, %s transceiver\n", hmc, type); | 2903 | INFO("hmc mode %d, %s transceiver\n", hmc, type); |
2798 | 2904 | ||
2799 | /* a "gadget" abstracts/virtualizes the controller */ | 2905 | /* a "gadget" abstracts/virtualizes the controller */ |
@@ -2818,8 +2924,8 @@ bad_on_1710: | |||
2818 | status = request_irq(pdev->resource[1].start, omap_udc_irq, | 2924 | status = request_irq(pdev->resource[1].start, omap_udc_irq, |
2819 | IRQF_SAMPLE_RANDOM, driver_name, udc); | 2925 | IRQF_SAMPLE_RANDOM, driver_name, udc); |
2820 | if (status != 0) { | 2926 | if (status != 0) { |
2821 | ERR( "can't get irq %ld, err %d\n", | 2927 | ERR("can't get irq %d, err %d\n", |
2822 | pdev->resource[1].start, status); | 2928 | (int) pdev->resource[1].start, status); |
2823 | goto cleanup1; | 2929 | goto cleanup1; |
2824 | } | 2930 | } |
2825 | 2931 | ||
@@ -2827,24 +2933,41 @@ bad_on_1710: | |||
2827 | status = request_irq(pdev->resource[2].start, omap_udc_pio_irq, | 2933 | status = request_irq(pdev->resource[2].start, omap_udc_pio_irq, |
2828 | IRQF_SAMPLE_RANDOM, "omap_udc pio", udc); | 2934 | IRQF_SAMPLE_RANDOM, "omap_udc pio", udc); |
2829 | if (status != 0) { | 2935 | if (status != 0) { |
2830 | ERR( "can't get irq %ld, err %d\n", | 2936 | ERR("can't get irq %d, err %d\n", |
2831 | pdev->resource[2].start, status); | 2937 | (int) pdev->resource[2].start, status); |
2832 | goto cleanup2; | 2938 | goto cleanup2; |
2833 | } | 2939 | } |
2834 | #ifdef USE_ISO | 2940 | #ifdef USE_ISO |
2835 | status = request_irq(pdev->resource[3].start, omap_udc_iso_irq, | 2941 | status = request_irq(pdev->resource[3].start, omap_udc_iso_irq, |
2836 | IRQF_DISABLED, "omap_udc iso", udc); | 2942 | IRQF_DISABLED, "omap_udc iso", udc); |
2837 | if (status != 0) { | 2943 | if (status != 0) { |
2838 | ERR("can't get irq %ld, err %d\n", | 2944 | ERR("can't get irq %d, err %d\n", |
2839 | pdev->resource[3].start, status); | 2945 | (int) pdev->resource[3].start, status); |
2840 | goto cleanup3; | 2946 | goto cleanup3; |
2841 | } | 2947 | } |
2842 | #endif | 2948 | #endif |
2949 | if (cpu_is_omap16xx()) { | ||
2950 | udc->dc_clk = dc_clk; | ||
2951 | udc->hhc_clk = hhc_clk; | ||
2952 | clk_disable(hhc_clk); | ||
2953 | clk_disable(dc_clk); | ||
2954 | } | ||
2955 | |||
2956 | if (cpu_is_omap24xx()) { | ||
2957 | udc->dc_clk = dc_clk; | ||
2958 | udc->hhc_clk = hhc_clk; | ||
2959 | /* FIXME OMAP2 don't release hhc & dc clock */ | ||
2960 | #if 0 | ||
2961 | clk_disable(hhc_clk); | ||
2962 | clk_disable(dc_clk); | ||
2963 | #endif | ||
2964 | } | ||
2843 | 2965 | ||
2844 | create_proc_file(); | 2966 | create_proc_file(); |
2845 | device_add(&udc->gadget.dev); | 2967 | status = device_add(&udc->gadget.dev); |
2846 | return 0; | 2968 | if (!status) |
2847 | 2969 | return status; | |
2970 | /* If fail, fall through */ | ||
2848 | #ifdef USE_ISO | 2971 | #ifdef USE_ISO |
2849 | cleanup3: | 2972 | cleanup3: |
2850 | free_irq(pdev->resource[2].start, udc); | 2973 | free_irq(pdev->resource[2].start, udc); |
@@ -2860,8 +2983,17 @@ cleanup1: | |||
2860 | cleanup0: | 2983 | cleanup0: |
2861 | if (xceiv) | 2984 | if (xceiv) |
2862 | put_device(xceiv->dev); | 2985 | put_device(xceiv->dev); |
2986 | |||
2987 | if (cpu_is_omap16xx() || cpu_is_omap24xx()) { | ||
2988 | clk_disable(hhc_clk); | ||
2989 | clk_disable(dc_clk); | ||
2990 | clk_put(hhc_clk); | ||
2991 | clk_put(dc_clk); | ||
2992 | } | ||
2993 | |||
2863 | release_mem_region(pdev->resource[0].start, | 2994 | release_mem_region(pdev->resource[0].start, |
2864 | pdev->resource[0].end - pdev->resource[0].start + 1); | 2995 | pdev->resource[0].end - pdev->resource[0].start + 1); |
2996 | |||
2865 | return status; | 2997 | return status; |
2866 | } | 2998 | } |
2867 | 2999 | ||
@@ -2891,6 +3023,13 @@ static int __exit omap_udc_remove(struct platform_device *pdev) | |||
2891 | free_irq(pdev->resource[2].start, udc); | 3023 | free_irq(pdev->resource[2].start, udc); |
2892 | free_irq(pdev->resource[1].start, udc); | 3024 | free_irq(pdev->resource[1].start, udc); |
2893 | 3025 | ||
3026 | if (udc->dc_clk) { | ||
3027 | if (udc->clk_requested) | ||
3028 | omap_udc_enable_clock(0); | ||
3029 | clk_put(udc->hhc_clk); | ||
3030 | clk_put(udc->dc_clk); | ||
3031 | } | ||
3032 | |||
2894 | release_mem_region(pdev->resource[0].start, | 3033 | release_mem_region(pdev->resource[0].start, |
2895 | pdev->resource[0].end - pdev->resource[0].start + 1); | 3034 | pdev->resource[0].end - pdev->resource[0].start + 1); |
2896 | 3035 | ||
diff --git a/drivers/usb/gadget/omap_udc.h b/drivers/usb/gadget/omap_udc.h index 652ee4627344..1dc398bb9ab2 100644 --- a/drivers/usb/gadget/omap_udc.h +++ b/drivers/usb/gadget/omap_udc.h | |||
@@ -175,6 +175,9 @@ struct omap_udc { | |||
175 | unsigned ep0_reset_config:1; | 175 | unsigned ep0_reset_config:1; |
176 | unsigned ep0_setup:1; | 176 | unsigned ep0_setup:1; |
177 | struct completion *done; | 177 | struct completion *done; |
178 | struct clk *dc_clk; | ||
179 | struct clk *hhc_clk; | ||
180 | unsigned clk_requested:1; | ||
178 | }; | 181 | }; |
179 | 182 | ||
180 | /*-------------------------------------------------------------------------*/ | 183 | /*-------------------------------------------------------------------------*/ |