Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph...
[pandora-kernel.git] / arch / arm / mach-vexpress / v2m.c
1 /*
2  * Versatile Express V2M Motherboard Support
3  */
4 #include <linux/device.h>
5 #include <linux/amba/bus.h>
6 #include <linux/amba/mmci.h>
7 #include <linux/io.h>
8 #include <linux/init.h>
9 #include <linux/platform_device.h>
10 #include <linux/smsc911x.h>
11 #include <linux/spinlock.h>
12 #include <linux/sysdev.h>
13 #include <linux/usb/isp1760.h>
14 #include <linux/clkdev.h>
15
16 #include <asm/sizes.h>
17 #include <asm/mach/flash.h>
18 #include <asm/mach/map.h>
19 #include <asm/mach/time.h>
20 #include <asm/hardware/arm_timer.h>
21 #include <asm/hardware/timer-sp.h>
22 #include <asm/hardware/sp810.h>
23
24 #include <mach/motherboard.h>
25
26 #include <plat/sched_clock.h>
27
28 #include "core.h"
29
30 #define V2M_PA_CS0      0x40000000
31 #define V2M_PA_CS1      0x44000000
32 #define V2M_PA_CS2      0x48000000
33 #define V2M_PA_CS3      0x4c000000
34 #define V2M_PA_CS7      0x10000000
35
36 static struct map_desc v2m_io_desc[] __initdata = {
37         {
38                 .virtual        = __MMIO_P2V(V2M_PA_CS7),
39                 .pfn            = __phys_to_pfn(V2M_PA_CS7),
40                 .length         = SZ_128K,
41                 .type           = MT_DEVICE,
42         },
43 };
44
45 void __init v2m_map_io(struct map_desc *tile, size_t num)
46 {
47         iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
48         iotable_init(tile, num);
49 }
50
51
52 static void __init v2m_timer_init(void)
53 {
54         u32 scctrl;
55
56         versatile_sched_clock_init(MMIO_P2V(V2M_SYS_24MHZ), 24000000);
57
58         /* Select 1MHz TIMCLK as the reference clock for SP804 timers */
59         scctrl = readl(MMIO_P2V(V2M_SYSCTL + SCCTRL));
60         scctrl |= SCCTRL_TIMEREN0SEL_TIMCLK;
61         scctrl |= SCCTRL_TIMEREN1SEL_TIMCLK;
62         writel(scctrl, MMIO_P2V(V2M_SYSCTL + SCCTRL));
63
64         writel(0, MMIO_P2V(V2M_TIMER0) + TIMER_CTRL);
65         writel(0, MMIO_P2V(V2M_TIMER1) + TIMER_CTRL);
66
67         sp804_clocksource_init(MMIO_P2V(V2M_TIMER1));
68         sp804_clockevents_init(MMIO_P2V(V2M_TIMER0), IRQ_V2M_TIMER0);
69 }
70
71 struct sys_timer v2m_timer = {
72         .init   = v2m_timer_init,
73 };
74
75
76 static DEFINE_SPINLOCK(v2m_cfg_lock);
77
78 int v2m_cfg_write(u32 devfn, u32 data)
79 {
80         /* Configuration interface broken? */
81         u32 val;
82
83         printk("%s: writing %08x to %08x\n", __func__, data, devfn);
84
85         devfn |= SYS_CFG_START | SYS_CFG_WRITE;
86
87         spin_lock(&v2m_cfg_lock);
88         val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
89         writel(val & ~SYS_CFG_COMPLETE, MMIO_P2V(V2M_SYS_CFGSTAT));
90
91         writel(data, MMIO_P2V(V2M_SYS_CFGDATA));
92         writel(devfn, MMIO_P2V(V2M_SYS_CFGCTRL));
93
94         do {
95                 val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
96         } while (val == 0);
97         spin_unlock(&v2m_cfg_lock);
98
99         return !!(val & SYS_CFG_ERR);
100 }
101
102 int v2m_cfg_read(u32 devfn, u32 *data)
103 {
104         u32 val;
105
106         devfn |= SYS_CFG_START;
107
108         spin_lock(&v2m_cfg_lock);
109         writel(0, MMIO_P2V(V2M_SYS_CFGSTAT));
110         writel(devfn, MMIO_P2V(V2M_SYS_CFGCTRL));
111
112         mb();
113
114         do {
115                 cpu_relax();
116                 val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
117         } while (val == 0);
118
119         *data = readl(MMIO_P2V(V2M_SYS_CFGDATA));
120         spin_unlock(&v2m_cfg_lock);
121
122         return !!(val & SYS_CFG_ERR);
123 }
124
125
126 static struct resource v2m_pcie_i2c_resource = {
127         .start  = V2M_SERIAL_BUS_PCI,
128         .end    = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
129         .flags  = IORESOURCE_MEM,
130 };
131
132 static struct platform_device v2m_pcie_i2c_device = {
133         .name           = "versatile-i2c",
134         .id             = 0,
135         .num_resources  = 1,
136         .resource       = &v2m_pcie_i2c_resource,
137 };
138
139 static struct resource v2m_ddc_i2c_resource = {
140         .start  = V2M_SERIAL_BUS_DVI,
141         .end    = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
142         .flags  = IORESOURCE_MEM,
143 };
144
145 static struct platform_device v2m_ddc_i2c_device = {
146         .name           = "versatile-i2c",
147         .id             = 1,
148         .num_resources  = 1,
149         .resource       = &v2m_ddc_i2c_resource,
150 };
151
152 static struct resource v2m_eth_resources[] = {
153         {
154                 .start  = V2M_LAN9118,
155                 .end    = V2M_LAN9118 + SZ_64K - 1,
156                 .flags  = IORESOURCE_MEM,
157         }, {
158                 .start  = IRQ_V2M_LAN9118,
159                 .end    = IRQ_V2M_LAN9118,
160                 .flags  = IORESOURCE_IRQ,
161         },
162 };
163
164 static struct smsc911x_platform_config v2m_eth_config = {
165         .flags          = SMSC911X_USE_32BIT,
166         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
167         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
168         .phy_interface  = PHY_INTERFACE_MODE_MII,
169 };
170
171 static struct platform_device v2m_eth_device = {
172         .name           = "smsc911x",
173         .id             = -1,
174         .resource       = v2m_eth_resources,
175         .num_resources  = ARRAY_SIZE(v2m_eth_resources),
176         .dev.platform_data = &v2m_eth_config,
177 };
178
179 static struct resource v2m_usb_resources[] = {
180         {
181                 .start  = V2M_ISP1761,
182                 .end    = V2M_ISP1761 + SZ_128K - 1,
183                 .flags  = IORESOURCE_MEM,
184         }, {
185                 .start  = IRQ_V2M_ISP1761,
186                 .end    = IRQ_V2M_ISP1761,
187                 .flags  = IORESOURCE_IRQ,
188         },
189 };
190
191 static struct isp1760_platform_data v2m_usb_config = {
192         .is_isp1761             = true,
193         .bus_width_16           = false,
194         .port1_otg              = true,
195         .analog_oc              = false,
196         .dack_polarity_high     = false,
197         .dreq_polarity_high     = false,
198 };
199
200 static struct platform_device v2m_usb_device = {
201         .name           = "isp1760",
202         .id             = -1,
203         .resource       = v2m_usb_resources,
204         .num_resources  = ARRAY_SIZE(v2m_usb_resources),
205         .dev.platform_data = &v2m_usb_config,
206 };
207
208 static int v2m_flash_init(void)
209 {
210         writel(0, MMIO_P2V(V2M_SYS_FLASH));
211         return 0;
212 }
213
214 static void v2m_flash_exit(void)
215 {
216         writel(0, MMIO_P2V(V2M_SYS_FLASH));
217 }
218
219 static void v2m_flash_set_vpp(int on)
220 {
221         writel(on != 0, MMIO_P2V(V2M_SYS_FLASH));
222 }
223
224 static struct flash_platform_data v2m_flash_data = {
225         .map_name       = "cfi_probe",
226         .width          = 4,
227         .init           = v2m_flash_init,
228         .exit           = v2m_flash_exit,
229         .set_vpp        = v2m_flash_set_vpp,
230 };
231
232 static struct resource v2m_flash_resources[] = {
233         {
234                 .start  = V2M_NOR0,
235                 .end    = V2M_NOR0 + SZ_64M - 1,
236                 .flags  = IORESOURCE_MEM,
237         }, {
238                 .start  = V2M_NOR1,
239                 .end    = V2M_NOR1 + SZ_64M - 1,
240                 .flags  = IORESOURCE_MEM,
241         },
242 };
243
244 static struct platform_device v2m_flash_device = {
245         .name           = "armflash",
246         .id             = -1,
247         .resource       = v2m_flash_resources,
248         .num_resources  = ARRAY_SIZE(v2m_flash_resources),
249         .dev.platform_data = &v2m_flash_data,
250 };
251
252
253 static unsigned int v2m_mmci_status(struct device *dev)
254 {
255         return readl(MMIO_P2V(V2M_SYS_MCI)) & (1 << 0);
256 }
257
258 static struct mmci_platform_data v2m_mmci_data = {
259         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
260         .status         = v2m_mmci_status,
261 };
262
263 static AMBA_DEVICE(aaci,  "mb:aaci",  V2M_AACI, NULL);
264 static AMBA_DEVICE(mmci,  "mb:mmci",  V2M_MMCI, &v2m_mmci_data);
265 static AMBA_DEVICE(kmi0,  "mb:kmi0",  V2M_KMI0, NULL);
266 static AMBA_DEVICE(kmi1,  "mb:kmi1",  V2M_KMI1, NULL);
267 static AMBA_DEVICE(uart0, "mb:uart0", V2M_UART0, NULL);
268 static AMBA_DEVICE(uart1, "mb:uart1", V2M_UART1, NULL);
269 static AMBA_DEVICE(uart2, "mb:uart2", V2M_UART2, NULL);
270 static AMBA_DEVICE(uart3, "mb:uart3", V2M_UART3, NULL);
271 static AMBA_DEVICE(wdt,   "mb:wdt",   V2M_WDT, NULL);
272 static AMBA_DEVICE(rtc,   "mb:rtc",   V2M_RTC, NULL);
273
274 static struct amba_device *v2m_amba_devs[] __initdata = {
275         &aaci_device,
276         &mmci_device,
277         &kmi0_device,
278         &kmi1_device,
279         &uart0_device,
280         &uart1_device,
281         &uart2_device,
282         &uart3_device,
283         &wdt_device,
284         &rtc_device,
285 };
286
287
288 static long v2m_osc_round(struct clk *clk, unsigned long rate)
289 {
290         return rate;
291 }
292
293 static int v2m_osc1_set(struct clk *clk, unsigned long rate)
294 {
295         return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_MB | 1, rate);
296 }
297
298 static const struct clk_ops osc1_clk_ops = {
299         .round  = v2m_osc_round,
300         .set    = v2m_osc1_set,
301 };
302
303 static struct clk osc1_clk = {
304         .ops    = &osc1_clk_ops,
305         .rate   = 24000000,
306 };
307
308 static struct clk osc2_clk = {
309         .rate   = 24000000,
310 };
311
312 static struct clk dummy_apb_pclk;
313
314 static struct clk_lookup v2m_lookups[] = {
315         {       /* AMBA bus clock */
316                 .con_id         = "apb_pclk",
317                 .clk            = &dummy_apb_pclk,
318         }, {    /* UART0 */
319                 .dev_id         = "mb:uart0",
320                 .clk            = &osc2_clk,
321         }, {    /* UART1 */
322                 .dev_id         = "mb:uart1",
323                 .clk            = &osc2_clk,
324         }, {    /* UART2 */
325                 .dev_id         = "mb:uart2",
326                 .clk            = &osc2_clk,
327         }, {    /* UART3 */
328                 .dev_id         = "mb:uart3",
329                 .clk            = &osc2_clk,
330         }, {    /* KMI0 */
331                 .dev_id         = "mb:kmi0",
332                 .clk            = &osc2_clk,
333         }, {    /* KMI1 */
334                 .dev_id         = "mb:kmi1",
335                 .clk            = &osc2_clk,
336         }, {    /* MMC0 */
337                 .dev_id         = "mb:mmci",
338                 .clk            = &osc2_clk,
339         }, {    /* CLCD */
340                 .dev_id         = "mb:clcd",
341                 .clk            = &osc1_clk,
342         },
343 };
344
345 static void v2m_power_off(void)
346 {
347         if (v2m_cfg_write(SYS_CFG_SHUTDOWN | SYS_CFG_SITE_MB, 0))
348                 printk(KERN_EMERG "Unable to shutdown\n");
349 }
350
351 static void v2m_restart(char str, const char *cmd)
352 {
353         if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
354                 printk(KERN_EMERG "Unable to reboot\n");
355 }
356
357 static int __init v2m_init(void)
358 {
359         int i;
360
361         clkdev_add_table(v2m_lookups, ARRAY_SIZE(v2m_lookups));
362
363         platform_device_register(&v2m_pcie_i2c_device);
364         platform_device_register(&v2m_ddc_i2c_device);
365         platform_device_register(&v2m_flash_device);
366         platform_device_register(&v2m_eth_device);
367         platform_device_register(&v2m_usb_device);
368
369         for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
370                 amba_device_register(v2m_amba_devs[i], &iomem_resource);
371
372         pm_power_off = v2m_power_off;
373         arm_pm_restart = v2m_restart;
374
375         return 0;
376 }
377 arch_initcall(v2m_init);