aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/omap_udc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/omap_udc.c')
-rw-r--r--drivers/usb/gadget/omap_udc.c434
1 files changed, 181 insertions, 253 deletions
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 89cbd2b22ab0..f9132ada53b5 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -35,10 +35,11 @@
35#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/clk.h> 37#include <linux/clk.h>
38#include <linux/err.h>
38#include <linux/prefetch.h> 39#include <linux/prefetch.h>
40#include <linux/io.h>
39 41
40#include <asm/byteorder.h> 42#include <asm/byteorder.h>
41#include <asm/io.h>
42#include <asm/irq.h> 43#include <asm/irq.h>
43#include <asm/unaligned.h> 44#include <asm/unaligned.h>
44#include <asm/mach-types.h> 45#include <asm/mach-types.h>
@@ -60,11 +61,6 @@
60#define DRIVER_DESC "OMAP UDC driver" 61#define DRIVER_DESC "OMAP UDC driver"
61#define DRIVER_VERSION "4 October 2004" 62#define DRIVER_VERSION "4 October 2004"
62 63
63#define DMA_ADDR_INVALID (~(dma_addr_t)0)
64
65#define OMAP2_DMA_CH(ch) (((ch) - 1) << 1)
66#define OMAP24XX_DMA(name, ch) (OMAP24XX_DMA_##name + OMAP2_DMA_CH(ch))
67
68/* 64/*
69 * The OMAP UDC needs _very_ early endpoint setup: before enabling the 65 * The OMAP UDC needs _very_ early endpoint setup: before enabling the
70 * D+ pullup to allow enumeration. That's too early for the gadget 66 * D+ pullup to allow enumeration. That's too early for the gadget
@@ -88,14 +84,14 @@
88#ifdef USE_ISO 84#ifdef USE_ISO
89static unsigned fifo_mode = 3; 85static unsigned fifo_mode = 3;
90#else 86#else
91static unsigned fifo_mode = 0; 87static unsigned fifo_mode;
92#endif 88#endif
93 89
94/* "modprobe omap_udc fifo_mode=42", or else as a kernel 90/* "modprobe omap_udc fifo_mode=42", or else as a kernel
95 * boot parameter "omap_udc:fifo_mode=42" 91 * boot parameter "omap_udc:fifo_mode=42"
96 */ 92 */
97module_param (fifo_mode, uint, 0); 93module_param(fifo_mode, uint, 0);
98MODULE_PARM_DESC (fifo_mode, "endpoint configuration"); 94MODULE_PARM_DESC(fifo_mode, "endpoint configuration");
99 95
100#ifdef USE_DMA 96#ifdef USE_DMA
101static bool use_dma = 1; 97static bool use_dma = 1;
@@ -103,8 +99,8 @@ static bool use_dma = 1;
103/* "modprobe omap_udc use_dma=y", or else as a kernel 99/* "modprobe omap_udc use_dma=y", or else as a kernel
104 * boot parameter "omap_udc:use_dma=y" 100 * boot parameter "omap_udc:use_dma=y"
105 */ 101 */
106module_param (use_dma, bool, 0); 102module_param(use_dma, bool, 0);
107MODULE_PARM_DESC (use_dma, "enable/disable DMA"); 103MODULE_PARM_DESC(use_dma, "enable/disable DMA");
108#else /* !USE_DMA */ 104#else /* !USE_DMA */
109 105
110/* save a bit of code */ 106/* save a bit of code */
@@ -112,8 +108,8 @@ MODULE_PARM_DESC (use_dma, "enable/disable DMA");
112#endif /* !USE_DMA */ 108#endif /* !USE_DMA */
113 109
114 110
115static const char driver_name [] = "omap_udc"; 111static const char driver_name[] = "omap_udc";
116static const char driver_desc [] = DRIVER_DESC; 112static const char driver_desc[] = DRIVER_DESC;
117 113
118/*-------------------------------------------------------------------------*/ 114/*-------------------------------------------------------------------------*/
119 115
@@ -251,7 +247,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
251 247
252 spin_lock_irqsave(&ep->udc->lock, flags); 248 spin_lock_irqsave(&ep->udc->lock, flags);
253 ep->ep.desc = NULL; 249 ep->ep.desc = NULL;
254 nuke (ep, -ESHUTDOWN); 250 nuke(ep, -ESHUTDOWN);
255 ep->ep.maxpacket = ep->maxpacket; 251 ep->ep.maxpacket = ep->maxpacket;
256 ep->has_dma = 0; 252 ep->has_dma = 0;
257 omap_writew(UDC_SET_HALT, UDC_CTRL); 253 omap_writew(UDC_SET_HALT, UDC_CTRL);
@@ -272,10 +268,11 @@ omap_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
272 struct omap_req *req; 268 struct omap_req *req;
273 269
274 req = kzalloc(sizeof(*req), gfp_flags); 270 req = kzalloc(sizeof(*req), gfp_flags);
275 if (req) { 271 if (!req)
276 req->req.dma = DMA_ADDR_INVALID; 272 return NULL;
277 INIT_LIST_HEAD (&req->queue); 273
278 } 274 INIT_LIST_HEAD(&req->queue);
275
279 return &req->req; 276 return &req->req;
280} 277}
281 278
@@ -284,8 +281,7 @@ omap_free_request(struct usb_ep *ep, struct usb_request *_req)
284{ 281{
285 struct omap_req *req = container_of(_req, struct omap_req, req); 282 struct omap_req *req = container_of(_req, struct omap_req, req);
286 283
287 if (_req) 284 kfree(req);
288 kfree (req);
289} 285}
290 286
291/*-------------------------------------------------------------------------*/ 287/*-------------------------------------------------------------------------*/
@@ -293,6 +289,7 @@ omap_free_request(struct usb_ep *ep, struct usb_request *_req)
293static void 289static void
294done(struct omap_ep *ep, struct omap_req *req, int status) 290done(struct omap_ep *ep, struct omap_req *req, int status)
295{ 291{
292 struct omap_udc *udc = ep->udc;
296 unsigned stopped = ep->stopped; 293 unsigned stopped = ep->stopped;
297 294
298 list_del_init(&req->queue); 295 list_del_init(&req->queue);
@@ -302,22 +299,9 @@ done(struct omap_ep *ep, struct omap_req *req, int status)
302 else 299 else
303 status = req->req.status; 300 status = req->req.status;
304 301
305 if (use_dma && ep->has_dma) { 302 if (use_dma && ep->has_dma)
306 if (req->mapped) { 303 usb_gadget_unmap_request(&udc->gadget, &req->req,
307 dma_unmap_single(ep->udc->gadget.dev.parent, 304 (ep->bEndpointAddress & USB_DIR_IN));
308 req->req.dma, req->req.length,
309 (ep->bEndpointAddress & USB_DIR_IN)
310 ? DMA_TO_DEVICE
311 : DMA_FROM_DEVICE);
312 req->req.dma = DMA_ADDR_INVALID;
313 req->mapped = 0;
314 } else
315 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
316 req->req.dma, req->req.length,
317 (ep->bEndpointAddress & USB_DIR_IN)
318 ? DMA_TO_DEVICE
319 : DMA_FROM_DEVICE);
320 }
321 305
322#ifndef USB_TRACE 306#ifndef USB_TRACE
323 if (status && status != -ESHUTDOWN) 307 if (status && status != -ESHUTDOWN)
@@ -365,10 +349,10 @@ write_packet(u8 *buf, struct omap_req *req, unsigned max)
365 return len; 349 return len;
366} 350}
367 351
368// FIXME change r/w fifo calling convention 352/* FIXME change r/w fifo calling convention */
369 353
370 354
371// return: 0 = still running, 1 = completed, negative = errno 355/* return: 0 = still running, 1 = completed, negative = errno */
372static int write_fifo(struct omap_ep *ep, struct omap_req *req) 356static int write_fifo(struct omap_ep *ep, struct omap_req *req)
373{ 357{
374 u8 *buf; 358 u8 *buf;
@@ -430,7 +414,7 @@ read_packet(u8 *buf, struct omap_req *req, unsigned avail)
430 return len; 414 return len;
431} 415}
432 416
433// return: 0 = still running, 1 = queue empty, negative = errno 417/* return: 0 = still running, 1 = queue empty, negative = errno */
434static int read_fifo(struct omap_ep *ep, struct omap_req *req) 418static int read_fifo(struct omap_ep *ep, struct omap_req *req)
435{ 419{
436 u8 *buf; 420 u8 *buf;
@@ -537,12 +521,8 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
537 : OMAP_DMA_SYNC_ELEMENT; 521 : OMAP_DMA_SYNC_ELEMENT;
538 int dma_trigger = 0; 522 int dma_trigger = 0;
539 523
540 if (cpu_is_omap24xx())
541 dma_trigger = OMAP24XX_DMA(USB_W2FC_TX0, ep->dma_channel);
542
543 /* measure length in either bytes or packets */ 524 /* measure length in either bytes or packets */
544 if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC) 525 if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC)
545 || (cpu_is_omap24xx() && length < ep->maxpacket)
546 || (cpu_is_omap15xx() && length < ep->maxpacket)) { 526 || (cpu_is_omap15xx() && length < ep->maxpacket)) {
547 txdma_ctrl = UDC_TXN_EOT | length; 527 txdma_ctrl = UDC_TXN_EOT | length;
548 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 528 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
@@ -601,28 +581,14 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
601 int dma_trigger = 0; 581 int dma_trigger = 0;
602 u16 w; 582 u16 w;
603 583
604 if (cpu_is_omap24xx()) 584 /* set up this DMA transfer, enable the fifo, start */
605 dma_trigger = OMAP24XX_DMA(USB_W2FC_RX0, ep->dma_channel); 585 packets /= ep->ep.maxpacket;
606 586 packets = min(packets, (unsigned)UDC_RXN_TC + 1);
607 /* NOTE: we filtered out "short reads" before, so we know 587 req->dma_bytes = packets * ep->ep.maxpacket;
608 * the buffer has only whole numbers of packets. 588 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
609 * except MODE SELECT(6) sent the 24 bytes data in OMAP24XX DMA mode 589 ep->ep.maxpacket >> 1, packets,
610 */ 590 OMAP_DMA_SYNC_ELEMENT,
611 if (cpu_is_omap24xx() && packets < ep->maxpacket) { 591 dma_trigger, 0);
612 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
613 packets, 1, OMAP_DMA_SYNC_ELEMENT,
614 dma_trigger, 0);
615 req->dma_bytes = packets;
616 } else {
617 /* set up this DMA transfer, enable the fifo, start */
618 packets /= ep->ep.maxpacket;
619 packets = min(packets, (unsigned)UDC_RXN_TC + 1);
620 req->dma_bytes = packets * ep->ep.maxpacket;
621 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
622 ep->ep.maxpacket >> 1, packets,
623 OMAP_DMA_SYNC_ELEMENT,
624 dma_trigger, 0);
625 }
626 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, 592 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
627 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, 593 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual,
628 0, 0); 594 0, 0);
@@ -684,7 +650,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
684 } 650 }
685 omap_writew(UDC_TXN_DONE, UDC_IRQ_SRC); 651 omap_writew(UDC_TXN_DONE, UDC_IRQ_SRC);
686 652
687 if (!list_empty (&ep->queue)) { 653 if (!list_empty(&ep->queue)) {
688 req = container_of(ep->queue.next, 654 req = container_of(ep->queue.next,
689 struct omap_req, queue); 655 struct omap_req, queue);
690 next_in_dma(ep, req); 656 next_in_dma(ep, req);
@@ -703,7 +669,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
703 } 669 }
704 omap_writew(UDC_RXN_EOT, UDC_IRQ_SRC); 670 omap_writew(UDC_RXN_EOT, UDC_IRQ_SRC);
705 671
706 if (!list_empty (&ep->queue)) { 672 if (!list_empty(&ep->queue)) {
707 req = container_of(ep->queue.next, 673 req = container_of(ep->queue.next,
708 struct omap_req, queue); 674 struct omap_req, queue);
709 next_out_dma(ep, req); 675 next_out_dma(ep, req);
@@ -761,10 +727,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
761 ep->dma_channel = channel; 727 ep->dma_channel = channel;
762 728
763 if (is_in) { 729 if (is_in) {
764 if (cpu_is_omap24xx()) 730 dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel;
765 dma_channel = OMAP24XX_DMA(USB_W2FC_TX0, channel);
766 else
767 dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel;
768 status = omap_request_dma(dma_channel, 731 status = omap_request_dma(dma_channel,
769 ep->ep.name, dma_error, ep, &ep->lch); 732 ep->ep.name, dma_error, ep, &ep->lch);
770 if (status == 0) { 733 if (status == 0) {
@@ -781,11 +744,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
781 0, 0); 744 0, 0);
782 } 745 }
783 } else { 746 } else {
784 if (cpu_is_omap24xx()) 747 dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel;
785 dma_channel = OMAP24XX_DMA(USB_W2FC_RX0, channel);
786 else
787 dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel;
788
789 status = omap_request_dma(dma_channel, 748 status = omap_request_dma(dma_channel,
790 ep->ep.name, dma_error, ep, &ep->lch); 749 ep->ep.name, dma_error, ep, &ep->lch);
791 if (status == 0) { 750 if (status == 0) {
@@ -809,7 +768,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
809 omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ); 768 omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ);
810 769
811 /* channel type P: hw synch (fifo) */ 770 /* channel type P: hw synch (fifo) */
812 if (cpu_class_is_omap1() && !cpu_is_omap15xx()) 771 if (!cpu_is_omap15xx())
813 omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P); 772 omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P);
814 } 773 }
815 774
@@ -929,13 +888,11 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
929 888
930 /* this isn't bogus, but OMAP DMA isn't the only hardware to 889 /* this isn't bogus, but OMAP DMA isn't the only hardware to
931 * have a hard time with partial packet reads... reject it. 890 * have a hard time with partial packet reads... reject it.
932 * Except OMAP2 can handle the small packets.
933 */ 891 */
934 if (use_dma 892 if (use_dma
935 && ep->has_dma 893 && ep->has_dma
936 && ep->bEndpointAddress != 0 894 && ep->bEndpointAddress != 0
937 && (ep->bEndpointAddress & USB_DIR_IN) == 0 895 && (ep->bEndpointAddress & USB_DIR_IN) == 0
938 && !cpu_class_is_omap2()
939 && (req->req.length % ep->ep.maxpacket) != 0) { 896 && (req->req.length % ep->ep.maxpacket) != 0) {
940 DBG("%s, no partial packet OUT reads\n", __func__); 897 DBG("%s, no partial packet OUT reads\n", __func__);
941 return -EMSGSIZE; 898 return -EMSGSIZE;
@@ -945,26 +902,9 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
945 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) 902 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN)
946 return -ESHUTDOWN; 903 return -ESHUTDOWN;
947 904
948 if (use_dma && ep->has_dma) { 905 if (use_dma && ep->has_dma)
949 if (req->req.dma == DMA_ADDR_INVALID) { 906 usb_gadget_map_request(&udc->gadget, &req->req,
950 req->req.dma = dma_map_single( 907 (ep->bEndpointAddress & USB_DIR_IN));
951 ep->udc->gadget.dev.parent,
952 req->req.buf,
953 req->req.length,
954 (ep->bEndpointAddress & USB_DIR_IN)
955 ? DMA_TO_DEVICE
956 : DMA_FROM_DEVICE);
957 req->mapped = 1;
958 } else {
959 dma_sync_single_for_device(
960 ep->udc->gadget.dev.parent,
961 req->req.dma, req->req.length,
962 (ep->bEndpointAddress & USB_DIR_IN)
963 ? DMA_TO_DEVICE
964 : DMA_FROM_DEVICE);
965 req->mapped = 0;
966 }
967 }
968 908
969 VDBG("%s queue req %p, len %d buf %p\n", 909 VDBG("%s queue req %p, len %d buf %p\n",
970 ep->ep.name, _req, _req->length, _req->buf); 910 ep->ep.name, _req, _req->length, _req->buf);
@@ -985,7 +925,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
985 int is_in; 925 int is_in;
986 926
987 if (ep->bEndpointAddress == 0) { 927 if (ep->bEndpointAddress == 0) {
988 if (!udc->ep0_pending || !list_empty (&ep->queue)) { 928 if (!udc->ep0_pending || !list_empty(&ep->queue)) {
989 spin_unlock_irqrestore(&udc->lock, flags); 929 spin_unlock_irqrestore(&udc->lock, flags);
990 return -EL2HLT; 930 return -EL2HLT;
991 } 931 }
@@ -1012,7 +952,8 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
1012 * always an IN ... even for IN transfers, 952 * always an IN ... even for IN transfers,
1013 * a weird case which seem to stall OMAP. 953 * a weird case which seem to stall OMAP.
1014 */ 954 */
1015 omap_writew(UDC_EP_SEL | UDC_EP_DIR, UDC_EP_NUM); 955 omap_writew(UDC_EP_SEL | UDC_EP_DIR,
956 UDC_EP_NUM);
1016 omap_writew(UDC_CLR_EP, UDC_CTRL); 957 omap_writew(UDC_CLR_EP, UDC_CTRL);
1017 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); 958 omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
1018 omap_writew(UDC_EP_DIR, UDC_EP_NUM); 959 omap_writew(UDC_EP_DIR, UDC_EP_NUM);
@@ -1024,7 +965,8 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
1024 965
1025 /* non-empty DATA stage */ 966 /* non-empty DATA stage */
1026 } else if (is_in) { 967 } else if (is_in) {
1027 omap_writew(UDC_EP_SEL | UDC_EP_DIR, UDC_EP_NUM); 968 omap_writew(UDC_EP_SEL | UDC_EP_DIR,
969 UDC_EP_NUM);
1028 } else { 970 } else {
1029 if (udc->ep0_setup) 971 if (udc->ep0_setup)
1030 goto irq_wait; 972 goto irq_wait;
@@ -1072,7 +1014,7 @@ static int omap_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1072 spin_lock_irqsave(&ep->udc->lock, flags); 1014 spin_lock_irqsave(&ep->udc->lock, flags);
1073 1015
1074 /* make sure it's actually queued on this endpoint */ 1016 /* make sure it's actually queued on this endpoint */
1075 list_for_each_entry (req, &ep->queue, queue) { 1017 list_for_each_entry(req, &ep->queue, queue) {
1076 if (&req->req == _req) 1018 if (&req->req == _req)
1077 break; 1019 break;
1078 } 1020 }
@@ -1179,8 +1121,8 @@ static struct usb_ep_ops omap_ep_ops = {
1179 .dequeue = omap_ep_dequeue, 1121 .dequeue = omap_ep_dequeue,
1180 1122
1181 .set_halt = omap_ep_set_halt, 1123 .set_halt = omap_ep_set_halt,
1182 // fifo_status ... report bytes in fifo 1124 /* fifo_status ... report bytes in fifo */
1183 // fifo_flush ... flush fifo 1125 /* fifo_flush ... flush fifo */
1184}; 1126};
1185 1127
1186/*-------------------------------------------------------------------------*/ 1128/*-------------------------------------------------------------------------*/
@@ -1212,7 +1154,7 @@ static int omap_wakeup(struct usb_gadget *gadget)
1212 1154
1213 /* NOTE: non-OTG systems may use SRP TOO... */ 1155 /* NOTE: non-OTG systems may use SRP TOO... */
1214 } else if (!(udc->devstat & UDC_ATT)) { 1156 } else if (!(udc->devstat & UDC_ATT)) {
1215 if (udc->transceiver) 1157 if (!IS_ERR_OR_NULL(udc->transceiver))
1216 retval = otg_start_srp(udc->transceiver->otg); 1158 retval = otg_start_srp(udc->transceiver->otg);
1217 } 1159 }
1218 spin_unlock_irqrestore(&udc->lock, flags); 1160 spin_unlock_irqrestore(&udc->lock, flags);
@@ -1344,7 +1286,7 @@ static int omap_vbus_draw(struct usb_gadget *gadget, unsigned mA)
1344 struct omap_udc *udc; 1286 struct omap_udc *udc;
1345 1287
1346 udc = container_of(gadget, struct omap_udc, gadget); 1288 udc = container_of(gadget, struct omap_udc, gadget);
1347 if (udc->transceiver) 1289 if (!IS_ERR_OR_NULL(udc->transceiver))
1348 return usb_phy_set_power(udc->transceiver, mA); 1290 return usb_phy_set_power(udc->transceiver, mA);
1349 return -EOPNOTSUPP; 1291 return -EOPNOTSUPP;
1350} 1292}
@@ -1410,7 +1352,7 @@ static void udc_quiesce(struct omap_udc *udc)
1410 1352
1411 udc->gadget.speed = USB_SPEED_UNKNOWN; 1353 udc->gadget.speed = USB_SPEED_UNKNOWN;
1412 nuke(&udc->ep[0], -ESHUTDOWN); 1354 nuke(&udc->ep[0], -ESHUTDOWN);
1413 list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) 1355 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list)
1414 nuke(ep, -ESHUTDOWN); 1356 nuke(ep, -ESHUTDOWN);
1415} 1357}
1416 1358
@@ -1526,7 +1468,8 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1526 /* read next OUT packet of request, maybe 1468 /* read next OUT packet of request, maybe
1527 * reactiviting the fifo; stall on errors. 1469 * reactiviting the fifo; stall on errors.
1528 */ 1470 */
1529 if (!req || (stat = read_fifo(ep0, req)) < 0) { 1471 stat = read_fifo(ep0, req);
1472 if (!req || stat < 0) {
1530 omap_writew(UDC_STALL_CMD, UDC_SYSCON2); 1473 omap_writew(UDC_STALL_CMD, UDC_SYSCON2);
1531 udc->ep0_pending = 0; 1474 udc->ep0_pending = 0;
1532 stat = 0; 1475 stat = 0;
@@ -1659,7 +1602,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
1659 /* this has rude side-effects (aborts) and 1602 /* this has rude side-effects (aborts) and
1660 * can't really work if DMA-IN is active 1603 * can't really work if DMA-IN is active
1661 */ 1604 */
1662 DBG("%s host set_halt, NYET \n", ep->name); 1605 DBG("%s host set_halt, NYET\n", ep->name);
1663 goto do_stall; 1606 goto do_stall;
1664 } 1607 }
1665 use_ep(ep, 0); 1608 use_ep(ep, 0);
@@ -1750,7 +1693,7 @@ delegate:
1750 */ 1693 */
1751 udc->ep0_setup = 1; 1694 udc->ep0_setup = 1;
1752 spin_unlock(&udc->lock); 1695 spin_unlock(&udc->lock);
1753 status = udc->driver->setup (&udc->gadget, &u.r); 1696 status = udc->driver->setup(&udc->gadget, &u.r);
1754 spin_lock(&udc->lock); 1697 spin_lock(&udc->lock);
1755 udc->ep0_setup = 0; 1698 udc->ep0_setup = 0;
1756 } 1699 }
@@ -1793,12 +1736,12 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1793 if (devstat & UDC_ATT) { 1736 if (devstat & UDC_ATT) {
1794 udc->gadget.speed = USB_SPEED_FULL; 1737 udc->gadget.speed = USB_SPEED_FULL;
1795 VDBG("connect\n"); 1738 VDBG("connect\n");
1796 if (!udc->transceiver) 1739 if (IS_ERR_OR_NULL(udc->transceiver))
1797 pullup_enable(udc); 1740 pullup_enable(udc);
1798 // if (driver->connect) call it 1741 /* if (driver->connect) call it */
1799 } else if (udc->gadget.speed != USB_SPEED_UNKNOWN) { 1742 } else if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
1800 udc->gadget.speed = USB_SPEED_UNKNOWN; 1743 udc->gadget.speed = USB_SPEED_UNKNOWN;
1801 if (!udc->transceiver) 1744 if (IS_ERR_OR_NULL(udc->transceiver))
1802 pullup_disable(udc); 1745 pullup_disable(udc);
1803 DBG("disconnect, gadget %s\n", 1746 DBG("disconnect, gadget %s\n",
1804 udc->driver->driver.name); 1747 udc->driver->driver.name);
@@ -1827,7 +1770,7 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1827 } 1770 }
1828 if (change & UDC_SUS) { 1771 if (change & UDC_SUS) {
1829 if (udc->gadget.speed != USB_SPEED_UNKNOWN) { 1772 if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
1830 // FIXME tell isp1301 to suspend/resume (?) 1773 /* FIXME tell isp1301 to suspend/resume (?) */
1831 if (devstat & UDC_SUS) { 1774 if (devstat & UDC_SUS) {
1832 VDBG("suspend\n"); 1775 VDBG("suspend\n");
1833 update_otg(udc); 1776 update_otg(udc);
@@ -1838,12 +1781,12 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1838 udc->driver->suspend(&udc->gadget); 1781 udc->driver->suspend(&udc->gadget);
1839 spin_lock(&udc->lock); 1782 spin_lock(&udc->lock);
1840 } 1783 }
1841 if (udc->transceiver) 1784 if (!IS_ERR_OR_NULL(udc->transceiver))
1842 usb_phy_set_suspend( 1785 usb_phy_set_suspend(
1843 udc->transceiver, 1); 1786 udc->transceiver, 1);
1844 } else { 1787 } else {
1845 VDBG("resume\n"); 1788 VDBG("resume\n");
1846 if (udc->transceiver) 1789 if (!IS_ERR_OR_NULL(udc->transceiver))
1847 usb_phy_set_suspend( 1790 usb_phy_set_suspend(
1848 udc->transceiver, 0); 1791 udc->transceiver, 0);
1849 if (udc->gadget.speed == USB_SPEED_FULL 1792 if (udc->gadget.speed == USB_SPEED_FULL
@@ -2030,7 +1973,7 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev)
2030 spin_lock_irqsave(&udc->lock, flags); 1973 spin_lock_irqsave(&udc->lock, flags);
2031 1974
2032 /* handle all non-DMA ISO transfers */ 1975 /* handle all non-DMA ISO transfers */
2033 list_for_each_entry (ep, &udc->iso, iso) { 1976 list_for_each_entry(ep, &udc->iso, iso) {
2034 u16 stat; 1977 u16 stat;
2035 struct omap_req *req; 1978 struct omap_req *req;
2036 1979
@@ -2089,15 +2032,11 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev)
2089 2032
2090static inline int machine_without_vbus_sense(void) 2033static inline int machine_without_vbus_sense(void)
2091{ 2034{
2092 return (machine_is_omap_innovator() 2035 return machine_is_omap_innovator()
2093 || machine_is_omap_osk() 2036 || machine_is_omap_osk()
2094 || machine_is_omap_apollon()
2095#ifndef CONFIG_MACH_OMAP_H4_OTG
2096 || machine_is_omap_h4()
2097#endif
2098 || machine_is_sx1() 2037 || machine_is_sx1()
2099 || cpu_is_omap7xx() /* No known omap7xx boards with vbus sense */ 2038 /* No known omap7xx boards with vbus sense */
2100 ); 2039 || cpu_is_omap7xx();
2101} 2040}
2102 2041
2103static int omap_udc_start(struct usb_gadget_driver *driver, 2042static int omap_udc_start(struct usb_gadget_driver *driver,
@@ -2111,7 +2050,7 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2111 if (!udc) 2050 if (!udc)
2112 return -ENODEV; 2051 return -ENODEV;
2113 if (!driver 2052 if (!driver
2114 // FIXME if otg, check: driver->is_otg 2053 /* FIXME if otg, check: driver->is_otg */
2115 || driver->max_speed < USB_SPEED_FULL 2054 || driver->max_speed < USB_SPEED_FULL
2116 || !bind || !driver->setup) 2055 || !bind || !driver->setup)
2117 return -EINVAL; 2056 return -EINVAL;
@@ -2123,7 +2062,7 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2123 } 2062 }
2124 2063
2125 /* reset state */ 2064 /* reset state */
2126 list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { 2065 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
2127 ep->irqs = 0; 2066 ep->irqs = 0;
2128 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) 2067 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC)
2129 continue; 2068 continue;
@@ -2155,13 +2094,13 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2155 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC); 2094 omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC);
2156 2095
2157 /* connect to bus through transceiver */ 2096 /* connect to bus through transceiver */
2158 if (udc->transceiver) { 2097 if (!IS_ERR_OR_NULL(udc->transceiver)) {
2159 status = otg_set_peripheral(udc->transceiver->otg, 2098 status = otg_set_peripheral(udc->transceiver->otg,
2160 &udc->gadget); 2099 &udc->gadget);
2161 if (status < 0) { 2100 if (status < 0) {
2162 ERR("can't bind to transceiver\n"); 2101 ERR("can't bind to transceiver\n");
2163 if (driver->unbind) { 2102 if (driver->unbind) {
2164 driver->unbind (&udc->gadget); 2103 driver->unbind(&udc->gadget);
2165 udc->gadget.dev.driver = NULL; 2104 udc->gadget.dev.driver = NULL;
2166 udc->driver = NULL; 2105 udc->driver = NULL;
2167 } 2106 }
@@ -2169,9 +2108,9 @@ static int omap_udc_start(struct usb_gadget_driver *driver,
2169 } 2108 }
2170 } else { 2109 } else {
2171 if (can_pullup(udc)) 2110 if (can_pullup(udc))
2172 pullup_enable (udc); 2111 pullup_enable(udc);
2173 else 2112 else
2174 pullup_disable (udc); 2113 pullup_disable(udc);
2175 } 2114 }
2176 2115
2177 /* boards that don't have VBUS sensing can't autogate 48MHz; 2116 /* boards that don't have VBUS sensing can't autogate 48MHz;
@@ -2202,7 +2141,7 @@ static int omap_udc_stop(struct usb_gadget_driver *driver)
2202 if (machine_without_vbus_sense()) 2141 if (machine_without_vbus_sense())
2203 omap_vbus_session(&udc->gadget, 0); 2142 omap_vbus_session(&udc->gadget, 0);
2204 2143
2205 if (udc->transceiver) 2144 if (!IS_ERR_OR_NULL(udc->transceiver))
2206 (void) otg_set_peripheral(udc->transceiver->otg, NULL); 2145 (void) otg_set_peripheral(udc->transceiver->otg, NULL);
2207 else 2146 else
2208 pullup_disable(udc); 2147 pullup_disable(udc);
@@ -2230,7 +2169,7 @@ static int omap_udc_stop(struct usb_gadget_driver *driver)
2230static const char proc_filename[] = "driver/udc"; 2169static const char proc_filename[] = "driver/udc";
2231 2170
2232#define FOURBITS "%s%s%s%s" 2171#define FOURBITS "%s%s%s%s"
2233#define EIGHTBITS FOURBITS FOURBITS 2172#define EIGHTBITS "%s%s%s%s%s%s%s%s"
2234 2173
2235static void proc_ep_show(struct seq_file *s, struct omap_ep *ep) 2174static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
2236{ 2175{
@@ -2252,12 +2191,21 @@ static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
2252 "\n%s %s%s%sirqs %ld stat %04x " EIGHTBITS FOURBITS "%s\n", 2191 "\n%s %s%s%sirqs %ld stat %04x " EIGHTBITS FOURBITS "%s\n",
2253 ep->name, buf, 2192 ep->name, buf,
2254 ep->double_buf ? "dbuf " : "", 2193 ep->double_buf ? "dbuf " : "",
2255 ({char *s; switch(ep->ackwait){ 2194 ({ char *s;
2256 case 0: s = ""; break; 2195 switch (ep->ackwait) {
2257 case 1: s = "(ackw) "; break; 2196 case 0:
2258 case 2: s = "(ackw2) "; break; 2197 s = "";
2259 default: s = "(?) "; break; 2198 break;
2260 } s;}), 2199 case 1:
2200 s = "(ackw) ";
2201 break;
2202 case 2:
2203 s = "(ackw2) ";
2204 break;
2205 default:
2206 s = "(?) ";
2207 break;
2208 } s; }),
2261 ep->irqs, stat_flg, 2209 ep->irqs, stat_flg,
2262 (stat_flg & UDC_NO_RXPACKET) ? "no_rxpacket " : "", 2210 (stat_flg & UDC_NO_RXPACKET) ? "no_rxpacket " : "",
2263 (stat_flg & UDC_MISS_IN) ? "miss_in " : "", 2211 (stat_flg & UDC_MISS_IN) ? "miss_in " : "",
@@ -2273,10 +2221,10 @@ static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
2273 (stat_flg & UDC_NON_ISO_FIFO_EMPTY) ? "fifo_empty " : "", 2221 (stat_flg & UDC_NON_ISO_FIFO_EMPTY) ? "fifo_empty " : "",
2274 (stat_flg & UDC_NON_ISO_FIFO_FULL) ? "fifo_full " : ""); 2222 (stat_flg & UDC_NON_ISO_FIFO_FULL) ? "fifo_full " : "");
2275 2223
2276 if (list_empty (&ep->queue)) 2224 if (list_empty(&ep->queue))
2277 seq_printf(s, "\t(queue empty)\n"); 2225 seq_printf(s, "\t(queue empty)\n");
2278 else 2226 else
2279 list_for_each_entry (req, &ep->queue, queue) { 2227 list_for_each_entry(req, &ep->queue, queue) {
2280 unsigned length = req->req.actual; 2228 unsigned length = req->req.actual;
2281 2229
2282 if (use_dma && buf[0]) { 2230 if (use_dma && buf[0]) {
@@ -2294,11 +2242,16 @@ static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
2294static char *trx_mode(unsigned m, int enabled) 2242static char *trx_mode(unsigned m, int enabled)
2295{ 2243{
2296 switch (m) { 2244 switch (m) {
2297 case 0: return enabled ? "*6wire" : "unused"; 2245 case 0:
2298 case 1: return "4wire"; 2246 return enabled ? "*6wire" : "unused";
2299 case 2: return "3wire"; 2247 case 1:
2300 case 3: return "6wire"; 2248 return "4wire";
2301 default: return "unknown"; 2249 case 2:
2250 return "3wire";
2251 case 3:
2252 return "6wire";
2253 default:
2254 return "unknown";
2302 } 2255 }
2303} 2256}
2304 2257
@@ -2308,12 +2261,9 @@ static int proc_otg_show(struct seq_file *s)
2308 u32 trans = 0; 2261 u32 trans = 0;
2309 char *ctrl_name = "(UNKNOWN)"; 2262 char *ctrl_name = "(UNKNOWN)";
2310 2263
2311 /* XXX This needs major revision for OMAP2+ */
2312 tmp = omap_readl(OTG_REV); 2264 tmp = omap_readl(OTG_REV);
2313 if (cpu_class_is_omap1()) { 2265 ctrl_name = "tranceiver_ctrl";
2314 ctrl_name = "tranceiver_ctrl"; 2266 trans = omap_readw(USB_TRANSCEIVER_CTRL);
2315 trans = omap_readw(USB_TRANSCEIVER_CTRL);
2316 }
2317 seq_printf(s, "\nOTG rev %d.%d, %s %05x\n", 2267 seq_printf(s, "\nOTG rev %d.%d, %s %05x\n",
2318 tmp >> 4, tmp & 0xf, ctrl_name, trans); 2268 tmp >> 4, tmp & 0xf, ctrl_name, trans);
2319 tmp = omap_readw(OTG_SYSCON_1); 2269 tmp = omap_readw(OTG_SYSCON_1);
@@ -2333,7 +2283,7 @@ static int proc_otg_show(struct seq_file *s)
2333 " b_ase_brst=%d hmc=%d\n", tmp, 2283 " b_ase_brst=%d hmc=%d\n", tmp,
2334 (tmp & OTG_EN) ? " otg_en" : "", 2284 (tmp & OTG_EN) ? " otg_en" : "",
2335 (tmp & USBX_SYNCHRO) ? " synchro" : "", 2285 (tmp & USBX_SYNCHRO) ? " synchro" : "",
2336 // much more SRP stuff 2286 /* much more SRP stuff */
2337 (tmp & SRP_DATA) ? " srp_data" : "", 2287 (tmp & SRP_DATA) ? " srp_data" : "",
2338 (tmp & SRP_VBUS) ? " srp_vbus" : "", 2288 (tmp & SRP_VBUS) ? " srp_vbus" : "",
2339 (tmp & OTG_PADEN) ? " otg_paden" : "", 2289 (tmp & OTG_PADEN) ? " otg_paden" : "",
@@ -2400,14 +2350,12 @@ static int proc_udc_show(struct seq_file *s, void *_)
2400 HMC, 2350 HMC,
2401 udc->transceiver 2351 udc->transceiver
2402 ? udc->transceiver->label 2352 ? udc->transceiver->label
2403 : ((cpu_is_omap1710() || cpu_is_omap24xx()) 2353 : (cpu_is_omap1710()
2404 ? "external" : "(none)")); 2354 ? "external" : "(none)"));
2405 if (cpu_class_is_omap1()) { 2355 seq_printf(s, "ULPD control %04x req %04x status %04x\n",
2406 seq_printf(s, "ULPD control %04x req %04x status %04x\n", 2356 omap_readw(ULPD_CLOCK_CTRL),
2407 omap_readw(ULPD_CLOCK_CTRL), 2357 omap_readw(ULPD_SOFT_REQ),
2408 omap_readw(ULPD_SOFT_REQ), 2358 omap_readw(ULPD_STATUS_REQ));
2409 omap_readw(ULPD_STATUS_REQ));
2410 }
2411 2359
2412 /* OTG controller registers */ 2360 /* OTG controller registers */
2413 if (!cpu_is_omap15xx()) 2361 if (!cpu_is_omap15xx())
@@ -2423,7 +2371,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2423 (tmp & UDC_SELF_PWR) ? " self_pwr" : "", 2371 (tmp & UDC_SELF_PWR) ? " self_pwr" : "",
2424 (tmp & UDC_SOFF_DIS) ? " soff_dis" : "", 2372 (tmp & UDC_SOFF_DIS) ? " soff_dis" : "",
2425 (tmp & UDC_PULLUP_EN) ? " PULLUP" : ""); 2373 (tmp & UDC_PULLUP_EN) ? " PULLUP" : "");
2426 // syscon2 is write-only 2374 /* syscon2 is write-only */
2427 2375
2428 /* UDC controller registers */ 2376 /* UDC controller registers */
2429 if (!(tmp & UDC_PULLUP_EN)) { 2377 if (!(tmp & UDC_PULLUP_EN)) {
@@ -2507,7 +2455,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
2507 if (tmp & UDC_ATT) { 2455 if (tmp & UDC_ATT) {
2508 proc_ep_show(s, &udc->ep[0]); 2456 proc_ep_show(s, &udc->ep[0]);
2509 if (tmp & UDC_ADD) { 2457 if (tmp & UDC_ADD) {
2510 list_for_each_entry (ep, &udc->gadget.ep_list, 2458 list_for_each_entry(ep, &udc->gadget.ep_list,
2511 ep.ep_list) { 2459 ep.ep_list) {
2512 if (ep->ep.desc) 2460 if (ep->ep.desc)
2513 proc_ep_show(s, ep); 2461 proc_ep_show(s, ep);
@@ -2558,7 +2506,7 @@ static inline void remove_proc_file(void) {}
2558 * UDC_SYSCON_1.CFG_LOCK is set can now work. We won't use that 2506 * UDC_SYSCON_1.CFG_LOCK is set can now work. We won't use that
2559 * capability yet though. 2507 * capability yet though.
2560 */ 2508 */
2561static unsigned __init 2509static unsigned __devinit
2562omap_ep_setup(char *name, u8 addr, u8 type, 2510omap_ep_setup(char *name, u8 addr, u8 type,
2563 unsigned buf, unsigned maxp, int dbuf) 2511 unsigned buf, unsigned maxp, int dbuf)
2564{ 2512{
@@ -2576,14 +2524,29 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2576 /* chip setup ... bit values are same for IN, OUT */ 2524 /* chip setup ... bit values are same for IN, OUT */
2577 if (type == USB_ENDPOINT_XFER_ISOC) { 2525 if (type == USB_ENDPOINT_XFER_ISOC) {
2578 switch (maxp) { 2526 switch (maxp) {
2579 case 8: epn_rxtx = 0 << 12; break; 2527 case 8:
2580 case 16: epn_rxtx = 1 << 12; break; 2528 epn_rxtx = 0 << 12;
2581 case 32: epn_rxtx = 2 << 12; break; 2529 break;
2582 case 64: epn_rxtx = 3 << 12; break; 2530 case 16:
2583 case 128: epn_rxtx = 4 << 12; break; 2531 epn_rxtx = 1 << 12;
2584 case 256: epn_rxtx = 5 << 12; break; 2532 break;
2585 case 512: epn_rxtx = 6 << 12; break; 2533 case 32:
2586 default: BUG(); 2534 epn_rxtx = 2 << 12;
2535 break;
2536 case 64:
2537 epn_rxtx = 3 << 12;
2538 break;
2539 case 128:
2540 epn_rxtx = 4 << 12;
2541 break;
2542 case 256:
2543 epn_rxtx = 5 << 12;
2544 break;
2545 case 512:
2546 epn_rxtx = 6 << 12;
2547 break;
2548 default:
2549 BUG();
2587 } 2550 }
2588 epn_rxtx |= UDC_EPN_RX_ISO; 2551 epn_rxtx |= UDC_EPN_RX_ISO;
2589 dbuf = 1; 2552 dbuf = 1;
@@ -2592,15 +2555,24 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2592 * and ignored for PIO-IN on newer chips 2555 * and ignored for PIO-IN on newer chips
2593 * (for more reliable behavior) 2556 * (for more reliable behavior)
2594 */ 2557 */
2595 if (!use_dma || cpu_is_omap15xx() || cpu_is_omap24xx()) 2558 if (!use_dma || cpu_is_omap15xx())
2596 dbuf = 0; 2559 dbuf = 0;
2597 2560
2598 switch (maxp) { 2561 switch (maxp) {
2599 case 8: epn_rxtx = 0 << 12; break; 2562 case 8:
2600 case 16: epn_rxtx = 1 << 12; break; 2563 epn_rxtx = 0 << 12;
2601 case 32: epn_rxtx = 2 << 12; break; 2564 break;
2602 case 64: epn_rxtx = 3 << 12; break; 2565 case 16:
2603 default: BUG(); 2566 epn_rxtx = 1 << 12;
2567 break;
2568 case 32:
2569 epn_rxtx = 2 << 12;
2570 break;
2571 case 64:
2572 epn_rxtx = 3 << 12;
2573 break;
2574 default:
2575 BUG();
2604 } 2576 }
2605 if (dbuf && addr) 2577 if (dbuf && addr)
2606 epn_rxtx |= UDC_EPN_RX_DB; 2578 epn_rxtx |= UDC_EPN_RX_DB;
@@ -2640,7 +2612,7 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2640 ep->ep.name = ep->name; 2612 ep->ep.name = ep->name;
2641 ep->ep.ops = &omap_ep_ops; 2613 ep->ep.ops = &omap_ep_ops;
2642 ep->ep.maxpacket = ep->maxpacket = maxp; 2614 ep->ep.maxpacket = ep->maxpacket = maxp;
2643 list_add_tail (&ep->ep.ep_list, &udc->gadget.ep_list); 2615 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
2644 2616
2645 return buf; 2617 return buf;
2646} 2618}
@@ -2648,11 +2620,11 @@ omap_ep_setup(char *name, u8 addr, u8 type,
2648static void omap_udc_release(struct device *dev) 2620static void omap_udc_release(struct device *dev)
2649{ 2621{
2650 complete(udc->done); 2622 complete(udc->done);
2651 kfree (udc); 2623 kfree(udc);
2652 udc = NULL; 2624 udc = NULL;
2653} 2625}
2654 2626
2655static int __init 2627static int __devinit
2656omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv) 2628omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2657{ 2629{
2658 unsigned tmp, buf; 2630 unsigned tmp, buf;
@@ -2666,13 +2638,13 @@ omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2666 omap_writew(0, UDC_TXDMA_CFG); 2638 omap_writew(0, UDC_TXDMA_CFG);
2667 2639
2668 /* UDC_PULLUP_EN gates the chip clock */ 2640 /* UDC_PULLUP_EN gates the chip clock */
2669 // OTG_SYSCON_1 |= DEV_IDLE_EN; 2641 /* OTG_SYSCON_1 |= DEV_IDLE_EN; */
2670 2642
2671 udc = kzalloc(sizeof(*udc), GFP_KERNEL); 2643 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
2672 if (!udc) 2644 if (!udc)
2673 return -ENOMEM; 2645 return -ENOMEM;
2674 2646
2675 spin_lock_init (&udc->lock); 2647 spin_lock_init(&udc->lock);
2676 2648
2677 udc->gadget.ops = &omap_gadget_ops; 2649 udc->gadget.ops = &omap_gadget_ops;
2678 udc->gadget.ep0 = &udc->ep[0].ep; 2650 udc->gadget.ep0 = &udc->ep[0].ep;
@@ -2702,13 +2674,13 @@ omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2702 omap_writew(0, UDC_EP_TX(tmp)); 2674 omap_writew(0, UDC_EP_TX(tmp));
2703 } 2675 }
2704 2676
2705#define OMAP_BULK_EP(name,addr) \ 2677#define OMAP_BULK_EP(name, addr) \
2706 buf = omap_ep_setup(name "-bulk", addr, \ 2678 buf = omap_ep_setup(name "-bulk", addr, \
2707 USB_ENDPOINT_XFER_BULK, buf, 64, 1); 2679 USB_ENDPOINT_XFER_BULK, buf, 64, 1);
2708#define OMAP_INT_EP(name,addr, maxp) \ 2680#define OMAP_INT_EP(name, addr, maxp) \
2709 buf = omap_ep_setup(name "-int", addr, \ 2681 buf = omap_ep_setup(name "-int", addr, \
2710 USB_ENDPOINT_XFER_INT, buf, maxp, 0); 2682 USB_ENDPOINT_XFER_INT, buf, maxp, 0);
2711#define OMAP_ISO_EP(name,addr, maxp) \ 2683#define OMAP_ISO_EP(name, addr, maxp) \
2712 buf = omap_ep_setup(name "-iso", addr, \ 2684 buf = omap_ep_setup(name "-iso", addr, \
2713 USB_ENDPOINT_XFER_ISOC, buf, maxp, 1); 2685 USB_ENDPOINT_XFER_ISOC, buf, maxp, 1);
2714 2686
@@ -2789,15 +2761,18 @@ omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2789 return 0; 2761 return 0;
2790} 2762}
2791 2763
2792static int __init omap_udc_probe(struct platform_device *pdev) 2764static int __devinit omap_udc_probe(struct platform_device *pdev)
2793{ 2765{
2794 int status = -ENODEV; 2766 int status = -ENODEV;
2795 int hmc; 2767 int hmc;
2796 struct usb_phy *xceiv = NULL; 2768 struct usb_phy *xceiv = NULL;
2797 const char *type = NULL; 2769 const char *type = NULL;
2798 struct omap_usb_config *config = pdev->dev.platform_data; 2770 struct omap_usb_config *config = pdev->dev.platform_data;
2799 struct clk *dc_clk; 2771 struct clk *dc_clk = NULL;
2800 struct clk *hhc_clk; 2772 struct clk *hhc_clk = NULL;
2773
2774 if (cpu_is_omap7xx())
2775 use_dma = 0;
2801 2776
2802 /* NOTE: "knows" the order of the resources! */ 2777 /* NOTE: "knows" the order of the resources! */
2803 if (!request_mem_region(pdev->resource[0].start, 2778 if (!request_mem_region(pdev->resource[0].start,
@@ -2817,16 +2792,6 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2817 udelay(100); 2792 udelay(100);
2818 } 2793 }
2819 2794
2820 if (cpu_is_omap24xx()) {
2821 dc_clk = clk_get(&pdev->dev, "usb_fck");
2822 hhc_clk = clk_get(&pdev->dev, "usb_l4_ick");
2823 BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk));
2824 /* can't use omap_udc_enable_clock yet */
2825 clk_enable(dc_clk);
2826 clk_enable(hhc_clk);
2827 udelay(100);
2828 }
2829
2830 if (cpu_is_omap7xx()) { 2795 if (cpu_is_omap7xx()) {
2831 dc_clk = clk_get(&pdev->dev, "usb_dc_ck"); 2796 dc_clk = clk_get(&pdev->dev, "usb_dc_ck");
2832 hhc_clk = clk_get(&pdev->dev, "l3_ocpi_ck"); 2797 hhc_clk = clk_get(&pdev->dev, "l3_ocpi_ck");
@@ -2866,8 +2831,8 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2866 * use it. Except for OTG, we don't _need_ to talk to one; 2831 * use it. Except for OTG, we don't _need_ to talk to one;
2867 * but not having one probably means no VBUS detection. 2832 * but not having one probably means no VBUS detection.
2868 */ 2833 */
2869 xceiv = usb_get_transceiver(); 2834 xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
2870 if (xceiv) 2835 if (!IS_ERR_OR_NULL(xceiv))
2871 type = xceiv->label; 2836 type = xceiv->label;
2872 else if (config->otg) { 2837 else if (config->otg) {
2873 DBG("OTG requires external transceiver!\n"); 2838 DBG("OTG requires external transceiver!\n");
@@ -2876,14 +2841,6 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2876 2841
2877 hmc = HMC_1610; 2842 hmc = HMC_1610;
2878 2843
2879 if (cpu_is_omap24xx()) {
2880 /* this could be transceiverless in one of the
2881 * "we don't need to know" modes.
2882 */
2883 type = "external";
2884 goto known;
2885 }
2886
2887 switch (hmc) { 2844 switch (hmc) {
2888 case 0: /* POWERUP DEFAULT == 0 */ 2845 case 0: /* POWERUP DEFAULT == 0 */
2889 case 4: 2846 case 4:
@@ -2899,7 +2856,7 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2899 case 16: 2856 case 16:
2900 case 19: 2857 case 19:
2901 case 25: 2858 case 25:
2902 if (!xceiv) { 2859 if (IS_ERR_OR_NULL(xceiv)) {
2903 DBG("external transceiver not registered!\n"); 2860 DBG("external transceiver not registered!\n");
2904 type = "unknown"; 2861 type = "unknown";
2905 } 2862 }
@@ -2922,16 +2879,16 @@ bad_on_1710:
2922 goto cleanup0; 2879 goto cleanup0;
2923 } 2880 }
2924 } 2881 }
2925known: 2882
2926 INFO("hmc mode %d, %s transceiver\n", hmc, type); 2883 INFO("hmc mode %d, %s transceiver\n", hmc, type);
2927 2884
2928 /* a "gadget" abstracts/virtualizes the controller */ 2885 /* a "gadget" abstracts/virtualizes the controller */
2929 status = omap_udc_setup(pdev, xceiv); 2886 status = omap_udc_setup(pdev, xceiv);
2930 if (status) { 2887 if (status)
2931 goto cleanup0; 2888 goto cleanup0;
2932 } 2889
2933 xceiv = NULL; 2890 xceiv = NULL;
2934 // "udc" is now valid 2891 /* "udc" is now valid */
2935 pullup_disable(udc); 2892 pullup_disable(udc);
2936#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) 2893#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
2937 udc->gadget.is_otg = (config->otg != 0); 2894 udc->gadget.is_otg = (config->otg != 0);
@@ -2945,7 +2902,7 @@ known:
2945 2902
2946 /* USB general purpose IRQ: ep0, state changes, dma, etc */ 2903 /* USB general purpose IRQ: ep0, state changes, dma, etc */
2947 status = request_irq(pdev->resource[1].start, omap_udc_irq, 2904 status = request_irq(pdev->resource[1].start, omap_udc_irq,
2948 IRQF_SAMPLE_RANDOM, driver_name, udc); 2905 0, driver_name, udc);
2949 if (status != 0) { 2906 if (status != 0) {
2950 ERR("can't get irq %d, err %d\n", 2907 ERR("can't get irq %d, err %d\n",
2951 (int) pdev->resource[1].start, status); 2908 (int) pdev->resource[1].start, status);
@@ -2954,7 +2911,7 @@ known:
2954 2911
2955 /* USB "non-iso" IRQ (PIO for all but ep0) */ 2912 /* USB "non-iso" IRQ (PIO for all but ep0) */
2956 status = request_irq(pdev->resource[2].start, omap_udc_pio_irq, 2913 status = request_irq(pdev->resource[2].start, omap_udc_pio_irq,
2957 IRQF_SAMPLE_RANDOM, "omap_udc pio", udc); 2914 0, "omap_udc pio", udc);
2958 if (status != 0) { 2915 if (status != 0) {
2959 ERR("can't get irq %d, err %d\n", 2916 ERR("can't get irq %d, err %d\n",
2960 (int) pdev->resource[2].start, status); 2917 (int) pdev->resource[2].start, status);
@@ -2976,16 +2933,6 @@ known:
2976 clk_disable(dc_clk); 2933 clk_disable(dc_clk);
2977 } 2934 }
2978 2935
2979 if (cpu_is_omap24xx()) {
2980 udc->dc_clk = dc_clk;
2981 udc->hhc_clk = hhc_clk;
2982 /* FIXME OMAP2 don't release hhc & dc clock */
2983#if 0
2984 clk_disable(hhc_clk);
2985 clk_disable(dc_clk);
2986#endif
2987 }
2988
2989 create_proc_file(); 2936 create_proc_file();
2990 status = device_add(&udc->gadget.dev); 2937 status = device_add(&udc->gadget.dev);
2991 if (status) 2938 if (status)
@@ -3007,14 +2954,14 @@ cleanup2:
3007 free_irq(pdev->resource[1].start, udc); 2954 free_irq(pdev->resource[1].start, udc);
3008 2955
3009cleanup1: 2956cleanup1:
3010 kfree (udc); 2957 kfree(udc);
3011 udc = NULL; 2958 udc = NULL;
3012 2959
3013cleanup0: 2960cleanup0:
3014 if (xceiv) 2961 if (!IS_ERR_OR_NULL(xceiv))
3015 usb_put_transceiver(xceiv); 2962 usb_put_phy(xceiv);
3016 2963
3017 if (cpu_is_omap16xx() || cpu_is_omap24xx() || cpu_is_omap7xx()) { 2964 if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
3018 clk_disable(hhc_clk); 2965 clk_disable(hhc_clk);
3019 clk_disable(dc_clk); 2966 clk_disable(dc_clk);
3020 clk_put(hhc_clk); 2967 clk_put(hhc_clk);
@@ -3027,7 +2974,7 @@ cleanup0:
3027 return status; 2974 return status;
3028} 2975}
3029 2976
3030static int __exit omap_udc_remove(struct platform_device *pdev) 2977static int __devexit omap_udc_remove(struct platform_device *pdev)
3031{ 2978{
3032 DECLARE_COMPLETION_ONSTACK(done); 2979 DECLARE_COMPLETION_ONSTACK(done);
3033 2980
@@ -3041,8 +2988,8 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
3041 udc->done = &done; 2988 udc->done = &done;
3042 2989
3043 pullup_disable(udc); 2990 pullup_disable(udc);
3044 if (udc->transceiver) { 2991 if (!IS_ERR_OR_NULL(udc->transceiver)) {
3045 usb_put_transceiver(udc->transceiver); 2992 usb_put_phy(udc->transceiver);
3046 udc->transceiver = NULL; 2993 udc->transceiver = NULL;
3047 } 2994 }
3048 omap_writew(0, UDC_SYSCON1); 2995 omap_writew(0, UDC_SYSCON1);
@@ -3112,7 +3059,8 @@ static int omap_udc_resume(struct platform_device *dev)
3112/*-------------------------------------------------------------------------*/ 3059/*-------------------------------------------------------------------------*/
3113 3060
3114static struct platform_driver udc_driver = { 3061static struct platform_driver udc_driver = {
3115 .remove = __exit_p(omap_udc_remove), 3062 .probe = omap_udc_probe,
3063 .remove = __devexit_p(omap_udc_remove),
3116 .suspend = omap_udc_suspend, 3064 .suspend = omap_udc_suspend,
3117 .resume = omap_udc_resume, 3065 .resume = omap_udc_resume,
3118 .driver = { 3066 .driver = {
@@ -3121,27 +3069,7 @@ static struct platform_driver udc_driver = {
3121 }, 3069 },
3122}; 3070};
3123 3071
3124static int __init udc_init(void) 3072module_platform_driver(udc_driver);
3125{
3126 /* Disable DMA for omap7xx -- it doesn't work right. */
3127 if (cpu_is_omap7xx())
3128 use_dma = 0;
3129
3130 INFO("%s, version: " DRIVER_VERSION
3131#ifdef USE_ISO
3132 " (iso)"
3133#endif
3134 "%s\n", driver_desc,
3135 use_dma ? " (dma)" : "");
3136 return platform_driver_probe(&udc_driver, omap_udc_probe);
3137}
3138module_init(udc_init);
3139
3140static void __exit udc_exit(void)
3141{
3142 platform_driver_unregister(&udc_driver);
3143}
3144module_exit(udc_exit);
3145 3073
3146MODULE_DESCRIPTION(DRIVER_DESC); 3074MODULE_DESCRIPTION(DRIVER_DESC);
3147MODULE_LICENSE("GPL"); 3075MODULE_LICENSE("GPL");