blob: c76f9144898aa6e19bd8f6cf233df963cab7269a [file] [log] [blame]
Russell Kingceade892010-02-11 21:44:53 +00001/*
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>
Nick Bowler95c34f82011-01-21 15:51:06 +010010#include <linux/ata_platform.h>
Russell Kingceade892010-02-11 21:44:53 +000011#include <linux/smsc911x.h>
12#include <linux/spinlock.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080013#include <linux/device.h>
Russell Kingceade892010-02-11 21:44:53 +000014#include <linux/usb/isp1760.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010015#include <linux/clkdev.h>
Marc Zyngier0f71fd42011-05-18 10:51:51 +010016#include <linux/mtd/physmap.h>
Russell Kingceade892010-02-11 21:44:53 +000017
Will Deacon80b5efbd2011-02-28 17:01:04 +010018#include <asm/mach-types.h>
Russell Kingceade892010-02-11 21:44:53 +000019#include <asm/sizes.h>
Will Deacon80b5efbd2011-02-28 17:01:04 +010020#include <asm/mach/arch.h>
Russell Kingceade892010-02-11 21:44:53 +000021#include <asm/mach/map.h>
22#include <asm/mach/time.h>
23#include <asm/hardware/arm_timer.h>
Russell King58daf182011-01-05 18:09:03 +000024#include <asm/hardware/timer-sp.h>
Pawel Mollbaaece22011-01-25 15:53:03 +010025#include <asm/hardware/sp810.h>
Marc Zyngierabd3ca52011-09-06 10:23:45 +010026#include <asm/hardware/gic.h>
Russell Kingceade892010-02-11 21:44:53 +000027
Will Deacon80b5efbd2011-02-28 17:01:04 +010028#include <mach/ct-ca9x4.h>
Russell Kingceade892010-02-11 21:44:53 +000029#include <mach/motherboard.h>
30
Russell King0af85dd2010-12-15 21:58:50 +000031#include <plat/sched_clock.h>
Russell Kingceade892010-02-11 21:44:53 +000032
33#include "core.h"
34
35#define V2M_PA_CS0 0x40000000
36#define V2M_PA_CS1 0x44000000
37#define V2M_PA_CS2 0x48000000
38#define V2M_PA_CS3 0x4c000000
39#define V2M_PA_CS7 0x10000000
40
41static struct map_desc v2m_io_desc[] __initdata = {
42 {
Pawel Moll98ed4ce2012-01-25 15:37:29 +000043 .virtual = V2M_PERIPH,
Russell Kingceade892010-02-11 21:44:53 +000044 .pfn = __phys_to_pfn(V2M_PA_CS7),
45 .length = SZ_128K,
46 .type = MT_DEVICE,
47 },
48};
49
Pawel Moll98ed4ce2012-01-25 15:37:29 +000050static void __iomem *v2m_sysreg_base;
51
52static void __init v2m_sysctl_init(void __iomem *base)
Russell Kingceade892010-02-11 21:44:53 +000053{
Pawel Mollbaaece22011-01-25 15:53:03 +010054 u32 scctrl;
55
Pawel Moll98ed4ce2012-01-25 15:37:29 +000056 if (WARN_ON(!base))
57 return;
58
Pawel Mollbaaece22011-01-25 15:53:03 +010059 /* Select 1MHz TIMCLK as the reference clock for SP804 timers */
Pawel Moll98ed4ce2012-01-25 15:37:29 +000060 scctrl = readl(base + SCCTRL);
Pawel Mollbaaece22011-01-25 15:53:03 +010061 scctrl |= SCCTRL_TIMEREN0SEL_TIMCLK;
62 scctrl |= SCCTRL_TIMEREN1SEL_TIMCLK;
Pawel Moll98ed4ce2012-01-25 15:37:29 +000063 writel(scctrl, base + SCCTRL);
64}
Pawel Mollbaaece22011-01-25 15:53:03 +010065
Pawel Moll98ed4ce2012-01-25 15:37:29 +000066static void __init v2m_sp804_init(void __iomem *base, unsigned int irq)
67{
68 if (WARN_ON(!base || irq == NO_IRQ))
69 return;
Russell Kingceade892010-02-11 21:44:53 +000070
Pawel Moll98ed4ce2012-01-25 15:37:29 +000071 writel(0, base + TIMER_1_BASE + TIMER_CTRL);
72 writel(0, base + TIMER_2_BASE + TIMER_CTRL);
73
74 sp804_clocksource_init(base + TIMER_2_BASE, "v2m-timer1");
75 sp804_clockevents_init(base + TIMER_1_BASE, irq, "v2m-timer0");
76}
77
78static void __init v2m_timer_init(void)
79{
80 v2m_sysctl_init(ioremap(V2M_SYSCTL, SZ_4K));
81 v2m_sp804_init(ioremap(V2M_TIMER01, SZ_4K), IRQ_V2M_TIMER0);
Russell Kingceade892010-02-11 21:44:53 +000082}
83
Will Deacon80b5efbd2011-02-28 17:01:04 +010084static struct sys_timer v2m_timer = {
Russell Kingceade892010-02-11 21:44:53 +000085 .init = v2m_timer_init,
86};
87
88
89static DEFINE_SPINLOCK(v2m_cfg_lock);
90
91int v2m_cfg_write(u32 devfn, u32 data)
92{
93 /* Configuration interface broken? */
94 u32 val;
95
96 printk("%s: writing %08x to %08x\n", __func__, data, devfn);
97
98 devfn |= SYS_CFG_START | SYS_CFG_WRITE;
99
100 spin_lock(&v2m_cfg_lock);
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000101 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
102 writel(val & ~SYS_CFG_COMPLETE, v2m_sysreg_base + V2M_SYS_CFGSTAT);
Russell Kingceade892010-02-11 21:44:53 +0000103
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000104 writel(data, v2m_sysreg_base + V2M_SYS_CFGDATA);
105 writel(devfn, v2m_sysreg_base + V2M_SYS_CFGCTRL);
Russell Kingceade892010-02-11 21:44:53 +0000106
107 do {
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000108 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
Russell Kingceade892010-02-11 21:44:53 +0000109 } while (val == 0);
110 spin_unlock(&v2m_cfg_lock);
111
112 return !!(val & SYS_CFG_ERR);
113}
114
115int v2m_cfg_read(u32 devfn, u32 *data)
116{
117 u32 val;
118
119 devfn |= SYS_CFG_START;
120
121 spin_lock(&v2m_cfg_lock);
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000122 writel(0, v2m_sysreg_base + V2M_SYS_CFGSTAT);
123 writel(devfn, v2m_sysreg_base + V2M_SYS_CFGCTRL);
Russell Kingceade892010-02-11 21:44:53 +0000124
125 mb();
126
127 do {
128 cpu_relax();
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000129 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
Russell Kingceade892010-02-11 21:44:53 +0000130 } while (val == 0);
131
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000132 *data = readl(v2m_sysreg_base + V2M_SYS_CFGDATA);
Russell Kingceade892010-02-11 21:44:53 +0000133 spin_unlock(&v2m_cfg_lock);
134
135 return !!(val & SYS_CFG_ERR);
136}
137
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000138void __init v2m_flags_set(u32 data)
139{
140 writel(~0, v2m_sysreg_base + V2M_SYS_FLAGSCLR);
141 writel(data, v2m_sysreg_base + V2M_SYS_FLAGSSET);
142}
143
Russell Kingceade892010-02-11 21:44:53 +0000144
145static struct resource v2m_pcie_i2c_resource = {
146 .start = V2M_SERIAL_BUS_PCI,
147 .end = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
148 .flags = IORESOURCE_MEM,
149};
150
151static struct platform_device v2m_pcie_i2c_device = {
152 .name = "versatile-i2c",
153 .id = 0,
154 .num_resources = 1,
155 .resource = &v2m_pcie_i2c_resource,
156};
157
158static struct resource v2m_ddc_i2c_resource = {
159 .start = V2M_SERIAL_BUS_DVI,
160 .end = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
161 .flags = IORESOURCE_MEM,
162};
163
164static struct platform_device v2m_ddc_i2c_device = {
165 .name = "versatile-i2c",
166 .id = 1,
167 .num_resources = 1,
168 .resource = &v2m_ddc_i2c_resource,
169};
170
171static struct resource v2m_eth_resources[] = {
172 {
173 .start = V2M_LAN9118,
174 .end = V2M_LAN9118 + SZ_64K - 1,
175 .flags = IORESOURCE_MEM,
176 }, {
177 .start = IRQ_V2M_LAN9118,
178 .end = IRQ_V2M_LAN9118,
179 .flags = IORESOURCE_IRQ,
180 },
181};
182
183static struct smsc911x_platform_config v2m_eth_config = {
184 .flags = SMSC911X_USE_32BIT,
185 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
186 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
187 .phy_interface = PHY_INTERFACE_MODE_MII,
188};
189
190static struct platform_device v2m_eth_device = {
191 .name = "smsc911x",
192 .id = -1,
193 .resource = v2m_eth_resources,
194 .num_resources = ARRAY_SIZE(v2m_eth_resources),
195 .dev.platform_data = &v2m_eth_config,
196};
197
198static struct resource v2m_usb_resources[] = {
199 {
200 .start = V2M_ISP1761,
201 .end = V2M_ISP1761 + SZ_128K - 1,
202 .flags = IORESOURCE_MEM,
203 }, {
204 .start = IRQ_V2M_ISP1761,
205 .end = IRQ_V2M_ISP1761,
206 .flags = IORESOURCE_IRQ,
207 },
208};
209
210static struct isp1760_platform_data v2m_usb_config = {
211 .is_isp1761 = true,
212 .bus_width_16 = false,
213 .port1_otg = true,
214 .analog_oc = false,
215 .dack_polarity_high = false,
216 .dreq_polarity_high = false,
217};
218
219static struct platform_device v2m_usb_device = {
220 .name = "isp1760",
221 .id = -1,
222 .resource = v2m_usb_resources,
223 .num_resources = ARRAY_SIZE(v2m_usb_resources),
224 .dev.platform_data = &v2m_usb_config,
225};
226
Marc Zyngier667f3902011-05-18 10:51:55 +0100227static void v2m_flash_set_vpp(struct platform_device *pdev, int on)
Russell Kingceade892010-02-11 21:44:53 +0000228{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000229 writel(on != 0, v2m_sysreg_base + V2M_SYS_FLASH);
Russell Kingceade892010-02-11 21:44:53 +0000230}
231
Marc Zyngier0f71fd42011-05-18 10:51:51 +0100232static struct physmap_flash_data v2m_flash_data = {
Russell Kingceade892010-02-11 21:44:53 +0000233 .width = 4,
Russell Kingceade892010-02-11 21:44:53 +0000234 .set_vpp = v2m_flash_set_vpp,
235};
236
237static struct resource v2m_flash_resources[] = {
238 {
239 .start = V2M_NOR0,
240 .end = V2M_NOR0 + SZ_64M - 1,
241 .flags = IORESOURCE_MEM,
242 }, {
243 .start = V2M_NOR1,
244 .end = V2M_NOR1 + SZ_64M - 1,
245 .flags = IORESOURCE_MEM,
246 },
247};
248
249static struct platform_device v2m_flash_device = {
Marc Zyngier0f71fd42011-05-18 10:51:51 +0100250 .name = "physmap-flash",
Russell Kingceade892010-02-11 21:44:53 +0000251 .id = -1,
252 .resource = v2m_flash_resources,
253 .num_resources = ARRAY_SIZE(v2m_flash_resources),
254 .dev.platform_data = &v2m_flash_data,
255};
256
Nick Bowler95c34f82011-01-21 15:51:06 +0100257static struct pata_platform_info v2m_pata_data = {
258 .ioport_shift = 2,
259};
260
261static struct resource v2m_pata_resources[] = {
262 {
263 .start = V2M_CF,
264 .end = V2M_CF + 0xff,
265 .flags = IORESOURCE_MEM,
266 }, {
267 .start = V2M_CF + 0x100,
268 .end = V2M_CF + SZ_4K - 1,
269 .flags = IORESOURCE_MEM,
270 },
271};
272
273static struct platform_device v2m_cf_device = {
274 .name = "pata_platform",
275 .id = -1,
276 .resource = v2m_pata_resources,
277 .num_resources = ARRAY_SIZE(v2m_pata_resources),
278 .dev.platform_data = &v2m_pata_data,
279};
Russell Kingceade892010-02-11 21:44:53 +0000280
281static unsigned int v2m_mmci_status(struct device *dev)
282{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000283 return readl(v2m_sysreg_base + V2M_SYS_MCI) & (1 << 0);
Russell Kingceade892010-02-11 21:44:53 +0000284}
285
286static struct mmci_platform_data v2m_mmci_data = {
287 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
288 .status = v2m_mmci_status,
289};
290
291static AMBA_DEVICE(aaci, "mb:aaci", V2M_AACI, NULL);
292static AMBA_DEVICE(mmci, "mb:mmci", V2M_MMCI, &v2m_mmci_data);
293static AMBA_DEVICE(kmi0, "mb:kmi0", V2M_KMI0, NULL);
294static AMBA_DEVICE(kmi1, "mb:kmi1", V2M_KMI1, NULL);
295static AMBA_DEVICE(uart0, "mb:uart0", V2M_UART0, NULL);
296static AMBA_DEVICE(uart1, "mb:uart1", V2M_UART1, NULL);
297static AMBA_DEVICE(uart2, "mb:uart2", V2M_UART2, NULL);
298static AMBA_DEVICE(uart3, "mb:uart3", V2M_UART3, NULL);
299static AMBA_DEVICE(wdt, "mb:wdt", V2M_WDT, NULL);
300static AMBA_DEVICE(rtc, "mb:rtc", V2M_RTC, NULL);
301
302static struct amba_device *v2m_amba_devs[] __initdata = {
303 &aaci_device,
304 &mmci_device,
305 &kmi0_device,
306 &kmi1_device,
307 &uart0_device,
308 &uart1_device,
309 &uart2_device,
310 &uart3_device,
311 &wdt_device,
312 &rtc_device,
313};
314
315
316static long v2m_osc_round(struct clk *clk, unsigned long rate)
317{
318 return rate;
319}
320
321static int v2m_osc1_set(struct clk *clk, unsigned long rate)
322{
323 return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_MB | 1, rate);
324}
325
326static const struct clk_ops osc1_clk_ops = {
327 .round = v2m_osc_round,
328 .set = v2m_osc1_set,
329};
330
331static struct clk osc1_clk = {
332 .ops = &osc1_clk_ops,
333 .rate = 24000000,
334};
335
336static struct clk osc2_clk = {
337 .rate = 24000000,
338};
339
Russell King7ff550d2011-05-12 13:31:48 +0100340static struct clk v2m_sp804_clk = {
341 .rate = 1000000,
342};
343
Nick Bowler0ebb9622011-07-20 15:43:42 +0100344static struct clk v2m_ref_clk = {
345 .rate = 32768,
346};
347
Russell King3126c7b2010-07-15 11:01:17 +0100348static struct clk dummy_apb_pclk;
349
Russell Kingceade892010-02-11 21:44:53 +0000350static struct clk_lookup v2m_lookups[] = {
Russell King3126c7b2010-07-15 11:01:17 +0100351 { /* AMBA bus clock */
352 .con_id = "apb_pclk",
353 .clk = &dummy_apb_pclk,
354 }, { /* UART0 */
Russell Kingceade892010-02-11 21:44:53 +0000355 .dev_id = "mb:uart0",
356 .clk = &osc2_clk,
357 }, { /* UART1 */
358 .dev_id = "mb:uart1",
359 .clk = &osc2_clk,
360 }, { /* UART2 */
361 .dev_id = "mb:uart2",
362 .clk = &osc2_clk,
363 }, { /* UART3 */
364 .dev_id = "mb:uart3",
365 .clk = &osc2_clk,
366 }, { /* KMI0 */
367 .dev_id = "mb:kmi0",
368 .clk = &osc2_clk,
369 }, { /* KMI1 */
370 .dev_id = "mb:kmi1",
371 .clk = &osc2_clk,
372 }, { /* MMC0 */
373 .dev_id = "mb:mmci",
374 .clk = &osc2_clk,
375 }, { /* CLCD */
376 .dev_id = "mb:clcd",
377 .clk = &osc1_clk,
Nick Bowler0ebb9622011-07-20 15:43:42 +0100378 }, { /* SP805 WDT */
379 .dev_id = "mb:wdt",
380 .clk = &v2m_ref_clk,
Russell King7ff550d2011-05-12 13:31:48 +0100381 }, { /* SP804 timers */
382 .dev_id = "sp804",
Russell King23828a72011-05-12 15:45:16 +0100383 .con_id = "v2m-timer0",
384 .clk = &v2m_sp804_clk,
385 }, { /* SP804 timers */
386 .dev_id = "sp804",
Russell King7ff550d2011-05-12 13:31:48 +0100387 .con_id = "v2m-timer1",
388 .clk = &v2m_sp804_clk,
Russell Kingceade892010-02-11 21:44:53 +0000389 },
390};
391
Rob Herring2fdf9992011-05-30 19:44:22 +0100392static void __init v2m_init_early(void)
393{
394 ct_desc->init_early();
395 clkdev_add_table(v2m_lookups, ARRAY_SIZE(v2m_lookups));
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000396 versatile_sched_clock_init(v2m_sysreg_base + V2M_SYS_24MHZ, 24000000);
Rob Herring2fdf9992011-05-30 19:44:22 +0100397}
398
Russell Kingceade892010-02-11 21:44:53 +0000399static void v2m_power_off(void)
400{
401 if (v2m_cfg_write(SYS_CFG_SHUTDOWN | SYS_CFG_SITE_MB, 0))
402 printk(KERN_EMERG "Unable to shutdown\n");
403}
404
405static void v2m_restart(char str, const char *cmd)
406{
407 if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
408 printk(KERN_EMERG "Unable to reboot\n");
409}
410
Will Deacon80b5efbd2011-02-28 17:01:04 +0100411struct ct_desc *ct_desc;
412
413static struct ct_desc *ct_descs[] __initdata = {
414#ifdef CONFIG_ARCH_VEXPRESS_CA9X4
415 &ct_ca9x4_desc,
416#endif
417};
418
419static void __init v2m_populate_ct_desc(void)
420{
421 int i;
422 u32 current_tile_id;
423
424 ct_desc = NULL;
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000425 current_tile_id = readl(v2m_sysreg_base + V2M_SYS_PROCID0)
426 & V2M_CT_ID_MASK;
Will Deacon80b5efbd2011-02-28 17:01:04 +0100427
428 for (i = 0; i < ARRAY_SIZE(ct_descs) && !ct_desc; ++i)
429 if (ct_descs[i]->id == current_tile_id)
430 ct_desc = ct_descs[i];
431
432 if (!ct_desc)
433 panic("vexpress: failed to populate core tile description "
434 "for tile ID 0x%8x\n", current_tile_id);
435}
436
437static void __init v2m_map_io(void)
438{
439 iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000440 v2m_sysreg_base = ioremap(V2M_SYSREGS, SZ_4K);
Will Deacon80b5efbd2011-02-28 17:01:04 +0100441 v2m_populate_ct_desc();
442 ct_desc->map_io();
443}
444
445static void __init v2m_init_irq(void)
446{
447 ct_desc->init_irq();
448}
449
450static void __init v2m_init(void)
Russell Kingceade892010-02-11 21:44:53 +0000451{
452 int i;
453
Russell Kingceade892010-02-11 21:44:53 +0000454 platform_device_register(&v2m_pcie_i2c_device);
455 platform_device_register(&v2m_ddc_i2c_device);
456 platform_device_register(&v2m_flash_device);
Nick Bowler95c34f82011-01-21 15:51:06 +0100457 platform_device_register(&v2m_cf_device);
Russell Kingceade892010-02-11 21:44:53 +0000458 platform_device_register(&v2m_eth_device);
459 platform_device_register(&v2m_usb_device);
460
461 for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
462 amba_device_register(v2m_amba_devs[i], &iomem_resource);
463
464 pm_power_off = v2m_power_off;
Russell Kingceade892010-02-11 21:44:53 +0000465
Will Deacon80b5efbd2011-02-28 17:01:04 +0100466 ct_desc->init_tile();
Russell Kingceade892010-02-11 21:44:53 +0000467}
Will Deacon80b5efbd2011-02-28 17:01:04 +0100468
469MACHINE_START(VEXPRESS, "ARM-Versatile Express")
Nicolas Pitree9ce8e52011-07-05 22:38:18 -0400470 .atag_offset = 0x100,
Will Deacon80b5efbd2011-02-28 17:01:04 +0100471 .map_io = v2m_map_io,
472 .init_early = v2m_init_early,
473 .init_irq = v2m_init_irq,
474 .timer = &v2m_timer,
Marc Zyngierabd3ca52011-09-06 10:23:45 +0100475 .handle_irq = gic_handle_irq,
Will Deacon80b5efbd2011-02-28 17:01:04 +0100476 .init_machine = v2m_init,
Russell Kingf5733a12011-11-04 15:47:50 +0000477 .restart = v2m_restart,
Will Deacon80b5efbd2011-02-28 17:01:04 +0100478MACHINE_END