blob: b0d6b07431c00cfea94f60e07172065125dd6d7d [file] [log] [blame]
David Brownellcece6e52008-09-07 23:41:57 -07001/*
2 * USB
3 */
David Brownellcece6e52008-09-07 23:41:57 -07004#include <linux/init.h>
5#include <linux/platform_device.h>
6#include <linux/dma-mapping.h>
7
8#include <linux/usb/musb.h>
David Brownellcece6e52008-09-07 23:41:57 -07009
10#include <mach/common.h>
David Brownelld0e58ae2009-01-18 17:29:10 +010011#include <mach/irqs.h>
Sergei Shtylyovefd91182009-07-16 19:58:53 +040012#include <mach/cputype.h>
Sergei Shtylyove5d3d252009-09-25 23:14:02 +040013#include <mach/usb.h>
David Brownellcece6e52008-09-07 23:41:57 -070014
Sergei Shtylyove5d3d252009-09-25 23:14:02 +040015#define DAVINCI_USB_OTG_BASE 0x01c64000
Sergei Shtylyovb0ea26e2009-10-30 23:49:44 +040016
17#define DA8XX_USB0_BASE 0x01e00000
Sergei Shtylyove5d3d252009-09-25 23:14:02 +040018#define DA8XX_USB1_BASE 0x01e25000
Kevin Hilmanf5c122d2009-04-14 07:04:16 -050019
David Brownellcece6e52008-09-07 23:41:57 -070020#if defined(CONFIG_USB_MUSB_HDRC) || defined(CONFIG_USB_MUSB_HDRC_MODULE)
21static struct musb_hdrc_eps_bits musb_eps[] = {
22 { "ep1_tx", 8, },
23 { "ep1_rx", 8, },
24 { "ep2_tx", 8, },
25 { "ep2_rx", 8, },
26 { "ep3_tx", 5, },
27 { "ep3_rx", 5, },
28 { "ep4_tx", 5, },
29 { "ep4_rx", 5, },
30};
31
32static struct musb_hdrc_config musb_config = {
33 .multipoint = true,
34 .dyn_fifo = true,
35 .soft_con = true,
36 .dma = true,
37
38 .num_eps = 5,
39 .dma_channels = 8,
40 .ram_bits = 10,
41 .eps_bits = musb_eps,
42};
43
44static struct musb_hdrc_platform_data usb_data = {
45#if defined(CONFIG_USB_MUSB_OTG)
46 /* OTG requires a Mini-AB connector */
47 .mode = MUSB_OTG,
48#elif defined(CONFIG_USB_MUSB_PERIPHERAL)
49 .mode = MUSB_PERIPHERAL,
50#elif defined(CONFIG_USB_MUSB_HOST)
51 .mode = MUSB_HOST,
52#endif
David Brownell34f32c92009-02-20 13:45:17 -080053 .clock = "usb",
David Brownellcece6e52008-09-07 23:41:57 -070054 .config = &musb_config,
55};
56
57static struct resource usb_resources[] = {
58 {
59 /* physical address */
60 .start = DAVINCI_USB_OTG_BASE,
61 .end = DAVINCI_USB_OTG_BASE + 0x5ff,
62 .flags = IORESOURCE_MEM,
63 },
64 {
65 .start = IRQ_USBINT,
66 .flags = IORESOURCE_IRQ,
Hema Kalliguddifcf173e2010-09-29 11:26:39 -050067 .name = "mc"
David Brownellcece6e52008-09-07 23:41:57 -070068 },
Sergei Shtylyovefd91182009-07-16 19:58:53 +040069 {
70 /* placeholder for the dedicated CPPI IRQ */
71 .flags = IORESOURCE_IRQ,
Hema Kalliguddifcf173e2010-09-29 11:26:39 -050072 .name = "dma"
Sergei Shtylyovefd91182009-07-16 19:58:53 +040073 },
David Brownellcece6e52008-09-07 23:41:57 -070074};
75
Yang Hongyang284901a2009-04-06 19:01:15 -070076static u64 usb_dmamask = DMA_BIT_MASK(32);
David Brownellcece6e52008-09-07 23:41:57 -070077
78static struct platform_device usb_dev = {
79 .name = "musb_hdrc",
80 .id = -1,
81 .dev = {
82 .platform_data = &usb_data,
83 .dma_mask = &usb_dmamask,
Yang Hongyang284901a2009-04-06 19:01:15 -070084 .coherent_dma_mask = DMA_BIT_MASK(32),
David Brownellcece6e52008-09-07 23:41:57 -070085 },
86 .resource = usb_resources,
87 .num_resources = ARRAY_SIZE(usb_resources),
88};
89
Sergei Shtylyov355fb4e2009-10-30 23:46:14 +040090void __init davinci_setup_usb(unsigned mA, unsigned potpgt_ms)
David Brownellcece6e52008-09-07 23:41:57 -070091{
Sergei Shtylyov355fb4e2009-10-30 23:46:14 +040092 usb_data.power = mA > 510 ? 255 : mA / 2;
93 usb_data.potpgt = (potpgt_ms + 1) / 2;
Sergei Shtylyovefd91182009-07-16 19:58:53 +040094
95 if (cpu_is_davinci_dm646x()) {
96 /* Override the defaults as DM6467 uses different IRQs. */
97 usb_dev.resource[1].start = IRQ_DM646X_USBINT;
98 usb_dev.resource[2].start = IRQ_DM646X_USBDMAINT;
99 } else /* other devices don't have dedicated CPPI IRQ */
100 usb_dev.num_resources = 2;
101
David Brownellcece6e52008-09-07 23:41:57 -0700102 platform_device_register(&usb_dev);
103}
104
Sergei Shtylyovb0ea26e2009-10-30 23:49:44 +0400105#ifdef CONFIG_ARCH_DAVINCI_DA8XX
106static struct resource da8xx_usb20_resources[] = {
107 {
108 .start = DA8XX_USB0_BASE,
109 .end = DA8XX_USB0_BASE + SZ_64K - 1,
110 .flags = IORESOURCE_MEM,
111 },
112 {
113 .start = IRQ_DA8XX_USB_INT,
114 .flags = IORESOURCE_IRQ,
115 },
116};
117
118int __init da8xx_register_usb20(unsigned mA, unsigned potpgt)
119{
120 usb_data.clock = "usb20";
121 usb_data.power = mA > 510 ? 255 : mA / 2;
122 usb_data.potpgt = (potpgt + 1) / 2;
123
124 usb_dev.resource = da8xx_usb20_resources;
125 usb_dev.num_resources = ARRAY_SIZE(da8xx_usb20_resources);
126
127 return platform_device_register(&usb_dev);
128}
129#endif /* CONFIG_DAVINCI_DA8XX */
130
David Brownellcece6e52008-09-07 23:41:57 -0700131#else
132
Sergei Shtylyov355fb4e2009-10-30 23:46:14 +0400133void __init davinci_setup_usb(unsigned mA, unsigned potpgt_ms)
David Brownellcece6e52008-09-07 23:41:57 -0700134{
135}
136
Sergei Shtylyovb0ea26e2009-10-30 23:49:44 +0400137#ifdef CONFIG_ARCH_DAVINCI_DA8XX
138int __init da8xx_register_usb20(unsigned mA, unsigned potpgt)
139{
140 return 0;
141}
142#endif
143
David Brownellcece6e52008-09-07 23:41:57 -0700144#endif /* CONFIG_USB_MUSB_HDRC */
145
Sergei Shtylyove5d3d252009-09-25 23:14:02 +0400146#ifdef CONFIG_ARCH_DAVINCI_DA8XX
147static struct resource da8xx_usb11_resources[] = {
148 [0] = {
149 .start = DA8XX_USB1_BASE,
150 .end = DA8XX_USB1_BASE + SZ_4K - 1,
151 .flags = IORESOURCE_MEM,
152 },
153 [1] = {
154 .start = IRQ_DA8XX_IRQN,
155 .end = IRQ_DA8XX_IRQN,
156 .flags = IORESOURCE_IRQ,
157 },
158};
159
160static u64 da8xx_usb11_dma_mask = DMA_BIT_MASK(32);
161
162static struct platform_device da8xx_usb11_device = {
163 .name = "ohci",
164 .id = 0,
165 .dev = {
166 .dma_mask = &da8xx_usb11_dma_mask,
167 .coherent_dma_mask = DMA_BIT_MASK(32),
168 },
169 .num_resources = ARRAY_SIZE(da8xx_usb11_resources),
170 .resource = da8xx_usb11_resources,
171};
172
173int __init da8xx_register_usb11(struct da8xx_ohci_root_hub *pdata)
174{
175 da8xx_usb11_device.dev.platform_data = pdata;
176 return platform_device_register(&da8xx_usb11_device);
177}
178#endif /* CONFIG_DAVINCI_DA8XX */