Merge branches 'sh/serial-rework' and 'sh/oprofile'
[pandora-kernel.git] / arch / arm / mach-davinci / usb.c
1 /*
2  * USB
3  */
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <linux/init.h>
7 #include <linux/platform_device.h>
8 #include <linux/dma-mapping.h>
9
10 #include <linux/usb/musb.h>
11 #include <linux/usb/otg.h>
12
13 #include <mach/common.h>
14 #include <mach/hardware.h>
15
16 #if defined(CONFIG_USB_MUSB_HDRC) || defined(CONFIG_USB_MUSB_HDRC_MODULE)
17 static struct musb_hdrc_eps_bits musb_eps[] = {
18         { "ep1_tx", 8, },
19         { "ep1_rx", 8, },
20         { "ep2_tx", 8, },
21         { "ep2_rx", 8, },
22         { "ep3_tx", 5, },
23         { "ep3_rx", 5, },
24         { "ep4_tx", 5, },
25         { "ep4_rx", 5, },
26 };
27
28 static struct musb_hdrc_config musb_config = {
29         .multipoint     = true,
30         .dyn_fifo       = true,
31         .soft_con       = true,
32         .dma            = true,
33
34         .num_eps        = 5,
35         .dma_channels   = 8,
36         .ram_bits       = 10,
37         .eps_bits       = musb_eps,
38 };
39
40 static struct musb_hdrc_platform_data usb_data = {
41 #if defined(CONFIG_USB_MUSB_OTG)
42         /* OTG requires a Mini-AB connector */
43         .mode           = MUSB_OTG,
44 #elif defined(CONFIG_USB_MUSB_PERIPHERAL)
45         .mode           = MUSB_PERIPHERAL,
46 #elif defined(CONFIG_USB_MUSB_HOST)
47         .mode           = MUSB_HOST,
48 #endif
49         .config         = &musb_config,
50 };
51
52 static struct resource usb_resources[] = {
53         {
54                 /* physical address */
55                 .start          = DAVINCI_USB_OTG_BASE,
56                 .end            = DAVINCI_USB_OTG_BASE + 0x5ff,
57                 .flags          = IORESOURCE_MEM,
58         },
59         {
60                 .start          = IRQ_USBINT,
61                 .flags          = IORESOURCE_IRQ,
62         },
63 };
64
65 static u64 usb_dmamask = DMA_32BIT_MASK;
66
67 static struct platform_device usb_dev = {
68         .name           = "musb_hdrc",
69         .id             = -1,
70         .dev = {
71                 .platform_data          = &usb_data,
72                 .dma_mask               = &usb_dmamask,
73                 .coherent_dma_mask      = DMA_32BIT_MASK,
74         },
75         .resource       = usb_resources,
76         .num_resources  = ARRAY_SIZE(usb_resources),
77 };
78
79 #ifdef CONFIG_USB_MUSB_OTG
80
81 static struct otg_transceiver *xceiv;
82
83 struct otg_transceiver *otg_get_transceiver(void)
84 {
85         if (xceiv)
86                 get_device(xceiv->dev);
87         return xceiv;
88 }
89 EXPORT_SYMBOL(otg_get_transceiver);
90
91 int otg_set_transceiver(struct otg_transceiver *x)
92 {
93         if (xceiv && x)
94                 return -EBUSY;
95         xceiv = x;
96         return 0;
97 }
98 EXPORT_SYMBOL(otg_set_transceiver);
99
100 #endif
101
102 void __init setup_usb(unsigned mA, unsigned potpgt_msec)
103 {
104         usb_data.power = mA / 2;
105         usb_data.potpgt = potpgt_msec / 2;
106         platform_device_register(&usb_dev);
107 }
108
109 #else
110
111 void __init setup_usb(unsigned mA, unsigned potpgt_msec)
112 {
113 }
114
115 #endif  /* CONFIG_USB_MUSB_HDRC */
116