blob: 722ef339c5f2b9a1d0495ba3e03969e2e38f1b61 [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>
Marc Zyngier3695adc2011-09-08 13:15:22 +01008#include <linux/smp.h>
Russell Kingceade892010-02-11 21:44:53 +00009#include <linux/init.h>
Pawel Moll8deed172012-02-23 13:04:51 +000010#include <linux/of_address.h>
11#include <linux/of_fdt.h>
12#include <linux/of_irq.h>
13#include <linux/of_platform.h>
Russell Kingceade892010-02-11 21:44:53 +000014#include <linux/platform_device.h>
Nick Bowler95c34f82011-01-21 15:51:06 +010015#include <linux/ata_platform.h>
Russell Kingceade892010-02-11 21:44:53 +000016#include <linux/smsc911x.h>
17#include <linux/spinlock.h>
Russell Kingceade892010-02-11 21:44:53 +000018#include <linux/usb/isp1760.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010019#include <linux/clkdev.h>
Pawel Molld1b8a772012-07-13 11:48:16 +010020#include <linux/clk-provider.h>
Marc Zyngier0f71fd42011-05-18 10:51:51 +010021#include <linux/mtd/physmap.h>
Pawel Mollb2a54ff2012-07-09 11:33:47 +010022#include <linux/regulator/fixed.h>
23#include <linux/regulator/machine.h>
Russell Kingceade892010-02-11 21:44:53 +000024
Marc Zyngier120f3d62012-03-28 17:13:53 +010025#include <asm/arch_timer.h>
Will Deacon80b5efbd2011-02-28 17:01:04 +010026#include <asm/mach-types.h>
Russell Kingceade892010-02-11 21:44:53 +000027#include <asm/sizes.h>
Marc Zyngier120f3d62012-03-28 17:13:53 +010028#include <asm/smp_twd.h>
Will Deacon80b5efbd2011-02-28 17:01:04 +010029#include <asm/mach/arch.h>
Russell Kingceade892010-02-11 21:44:53 +000030#include <asm/mach/map.h>
31#include <asm/mach/time.h>
32#include <asm/hardware/arm_timer.h>
Pawel Moll8deed172012-02-23 13:04:51 +000033#include <asm/hardware/cache-l2x0.h>
34#include <asm/hardware/gic.h>
Russell King58daf182011-01-05 18:09:03 +000035#include <asm/hardware/timer-sp.h>
Pawel Mollbaaece22011-01-25 15:53:03 +010036#include <asm/hardware/sp810.h>
Russell Kingceade892010-02-11 21:44:53 +000037
Will Deacon80b5efbd2011-02-28 17:01:04 +010038#include <mach/ct-ca9x4.h>
Russell Kingceade892010-02-11 21:44:53 +000039#include <mach/motherboard.h>
40
Russell King0af85dd2010-12-15 21:58:50 +000041#include <plat/sched_clock.h>
Marc Zyngier3695adc2011-09-08 13:15:22 +010042#include <plat/platsmp.h>
Russell Kingceade892010-02-11 21:44:53 +000043
44#include "core.h"
45
46#define V2M_PA_CS0 0x40000000
47#define V2M_PA_CS1 0x44000000
48#define V2M_PA_CS2 0x48000000
49#define V2M_PA_CS3 0x4c000000
50#define V2M_PA_CS7 0x10000000
51
52static struct map_desc v2m_io_desc[] __initdata = {
53 {
Pawel Moll98ed4ce2012-01-25 15:37:29 +000054 .virtual = V2M_PERIPH,
Russell Kingceade892010-02-11 21:44:53 +000055 .pfn = __phys_to_pfn(V2M_PA_CS7),
56 .length = SZ_128K,
57 .type = MT_DEVICE,
58 },
59};
60
Pawel Moll98ed4ce2012-01-25 15:37:29 +000061static void __iomem *v2m_sysreg_base;
62
63static void __init v2m_sysctl_init(void __iomem *base)
Russell Kingceade892010-02-11 21:44:53 +000064{
Pawel Mollbaaece22011-01-25 15:53:03 +010065 u32 scctrl;
66
Pawel Moll98ed4ce2012-01-25 15:37:29 +000067 if (WARN_ON(!base))
68 return;
69
Pawel Mollbaaece22011-01-25 15:53:03 +010070 /* Select 1MHz TIMCLK as the reference clock for SP804 timers */
Pawel Moll98ed4ce2012-01-25 15:37:29 +000071 scctrl = readl(base + SCCTRL);
Pawel Mollbaaece22011-01-25 15:53:03 +010072 scctrl |= SCCTRL_TIMEREN0SEL_TIMCLK;
73 scctrl |= SCCTRL_TIMEREN1SEL_TIMCLK;
Pawel Moll98ed4ce2012-01-25 15:37:29 +000074 writel(scctrl, base + SCCTRL);
75}
Pawel Mollbaaece22011-01-25 15:53:03 +010076
Pawel Moll98ed4ce2012-01-25 15:37:29 +000077static void __init v2m_sp804_init(void __iomem *base, unsigned int irq)
78{
79 if (WARN_ON(!base || irq == NO_IRQ))
80 return;
Russell Kingceade892010-02-11 21:44:53 +000081
Pawel Moll98ed4ce2012-01-25 15:37:29 +000082 writel(0, base + TIMER_1_BASE + TIMER_CTRL);
83 writel(0, base + TIMER_2_BASE + TIMER_CTRL);
84
85 sp804_clocksource_init(base + TIMER_2_BASE, "v2m-timer1");
86 sp804_clockevents_init(base + TIMER_1_BASE, irq, "v2m-timer0");
87}
88
Russell Kingceade892010-02-11 21:44:53 +000089
90static DEFINE_SPINLOCK(v2m_cfg_lock);
91
92int v2m_cfg_write(u32 devfn, u32 data)
93{
94 /* Configuration interface broken? */
95 u32 val;
96
97 printk("%s: writing %08x to %08x\n", __func__, data, devfn);
98
99 devfn |= SYS_CFG_START | SYS_CFG_WRITE;
100
101 spin_lock(&v2m_cfg_lock);
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000102 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
103 writel(val & ~SYS_CFG_COMPLETE, v2m_sysreg_base + V2M_SYS_CFGSTAT);
Russell Kingceade892010-02-11 21:44:53 +0000104
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000105 writel(data, v2m_sysreg_base + V2M_SYS_CFGDATA);
106 writel(devfn, v2m_sysreg_base + V2M_SYS_CFGCTRL);
Russell Kingceade892010-02-11 21:44:53 +0000107
108 do {
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000109 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
Russell Kingceade892010-02-11 21:44:53 +0000110 } while (val == 0);
111 spin_unlock(&v2m_cfg_lock);
112
113 return !!(val & SYS_CFG_ERR);
114}
115
116int v2m_cfg_read(u32 devfn, u32 *data)
117{
118 u32 val;
119
120 devfn |= SYS_CFG_START;
121
122 spin_lock(&v2m_cfg_lock);
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000123 writel(0, v2m_sysreg_base + V2M_SYS_CFGSTAT);
124 writel(devfn, v2m_sysreg_base + V2M_SYS_CFGCTRL);
Russell Kingceade892010-02-11 21:44:53 +0000125
126 mb();
127
128 do {
129 cpu_relax();
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000130 val = readl(v2m_sysreg_base + V2M_SYS_CFGSTAT);
Russell Kingceade892010-02-11 21:44:53 +0000131 } while (val == 0);
132
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000133 *data = readl(v2m_sysreg_base + V2M_SYS_CFGDATA);
Russell Kingceade892010-02-11 21:44:53 +0000134 spin_unlock(&v2m_cfg_lock);
135
136 return !!(val & SYS_CFG_ERR);
137}
138
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000139void __init v2m_flags_set(u32 data)
140{
141 writel(~0, v2m_sysreg_base + V2M_SYS_FLAGSCLR);
142 writel(data, v2m_sysreg_base + V2M_SYS_FLAGSSET);
143}
144
Pawel Molld927daf2012-06-12 16:14:03 +0100145int v2m_get_master_site(void)
146{
147 u32 misc = readl(v2m_sysreg_base + V2M_SYS_MISC);
148
149 return misc & SYS_MISC_MASTERSITE ? SYS_CFG_SITE_DB2 : SYS_CFG_SITE_DB1;
150}
151
Russell Kingceade892010-02-11 21:44:53 +0000152
153static struct resource v2m_pcie_i2c_resource = {
154 .start = V2M_SERIAL_BUS_PCI,
155 .end = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
156 .flags = IORESOURCE_MEM,
157};
158
159static struct platform_device v2m_pcie_i2c_device = {
160 .name = "versatile-i2c",
161 .id = 0,
162 .num_resources = 1,
163 .resource = &v2m_pcie_i2c_resource,
164};
165
166static struct resource v2m_ddc_i2c_resource = {
167 .start = V2M_SERIAL_BUS_DVI,
168 .end = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
169 .flags = IORESOURCE_MEM,
170};
171
172static struct platform_device v2m_ddc_i2c_device = {
173 .name = "versatile-i2c",
174 .id = 1,
175 .num_resources = 1,
176 .resource = &v2m_ddc_i2c_resource,
177};
178
179static struct resource v2m_eth_resources[] = {
180 {
181 .start = V2M_LAN9118,
182 .end = V2M_LAN9118 + SZ_64K - 1,
183 .flags = IORESOURCE_MEM,
184 }, {
185 .start = IRQ_V2M_LAN9118,
186 .end = IRQ_V2M_LAN9118,
187 .flags = IORESOURCE_IRQ,
188 },
189};
190
191static struct smsc911x_platform_config v2m_eth_config = {
192 .flags = SMSC911X_USE_32BIT,
193 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
194 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
195 .phy_interface = PHY_INTERFACE_MODE_MII,
196};
197
198static struct platform_device v2m_eth_device = {
199 .name = "smsc911x",
200 .id = -1,
201 .resource = v2m_eth_resources,
202 .num_resources = ARRAY_SIZE(v2m_eth_resources),
203 .dev.platform_data = &v2m_eth_config,
204};
205
Pawel Mollb2a54ff2012-07-09 11:33:47 +0100206static struct regulator_consumer_supply v2m_eth_supplies[] = {
207 REGULATOR_SUPPLY("vddvario", "smsc911x"),
208 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
209};
210
Russell Kingceade892010-02-11 21:44:53 +0000211static struct resource v2m_usb_resources[] = {
212 {
213 .start = V2M_ISP1761,
214 .end = V2M_ISP1761 + SZ_128K - 1,
215 .flags = IORESOURCE_MEM,
216 }, {
217 .start = IRQ_V2M_ISP1761,
218 .end = IRQ_V2M_ISP1761,
219 .flags = IORESOURCE_IRQ,
220 },
221};
222
223static struct isp1760_platform_data v2m_usb_config = {
224 .is_isp1761 = true,
225 .bus_width_16 = false,
226 .port1_otg = true,
227 .analog_oc = false,
228 .dack_polarity_high = false,
229 .dreq_polarity_high = false,
230};
231
232static struct platform_device v2m_usb_device = {
233 .name = "isp1760",
234 .id = -1,
235 .resource = v2m_usb_resources,
236 .num_resources = ARRAY_SIZE(v2m_usb_resources),
237 .dev.platform_data = &v2m_usb_config,
238};
239
Marc Zyngier667f3902011-05-18 10:51:55 +0100240static void v2m_flash_set_vpp(struct platform_device *pdev, int on)
Russell Kingceade892010-02-11 21:44:53 +0000241{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000242 writel(on != 0, v2m_sysreg_base + V2M_SYS_FLASH);
Russell Kingceade892010-02-11 21:44:53 +0000243}
244
Marc Zyngier0f71fd42011-05-18 10:51:51 +0100245static struct physmap_flash_data v2m_flash_data = {
Russell Kingceade892010-02-11 21:44:53 +0000246 .width = 4,
Russell Kingceade892010-02-11 21:44:53 +0000247 .set_vpp = v2m_flash_set_vpp,
248};
249
250static struct resource v2m_flash_resources[] = {
251 {
252 .start = V2M_NOR0,
253 .end = V2M_NOR0 + SZ_64M - 1,
254 .flags = IORESOURCE_MEM,
255 }, {
256 .start = V2M_NOR1,
257 .end = V2M_NOR1 + SZ_64M - 1,
258 .flags = IORESOURCE_MEM,
259 },
260};
261
262static struct platform_device v2m_flash_device = {
Marc Zyngier0f71fd42011-05-18 10:51:51 +0100263 .name = "physmap-flash",
Russell Kingceade892010-02-11 21:44:53 +0000264 .id = -1,
265 .resource = v2m_flash_resources,
266 .num_resources = ARRAY_SIZE(v2m_flash_resources),
267 .dev.platform_data = &v2m_flash_data,
268};
269
Nick Bowler95c34f82011-01-21 15:51:06 +0100270static struct pata_platform_info v2m_pata_data = {
271 .ioport_shift = 2,
272};
273
274static struct resource v2m_pata_resources[] = {
275 {
276 .start = V2M_CF,
277 .end = V2M_CF + 0xff,
278 .flags = IORESOURCE_MEM,
279 }, {
280 .start = V2M_CF + 0x100,
281 .end = V2M_CF + SZ_4K - 1,
282 .flags = IORESOURCE_MEM,
283 },
284};
285
286static struct platform_device v2m_cf_device = {
287 .name = "pata_platform",
288 .id = -1,
289 .resource = v2m_pata_resources,
290 .num_resources = ARRAY_SIZE(v2m_pata_resources),
291 .dev.platform_data = &v2m_pata_data,
292};
Russell Kingceade892010-02-11 21:44:53 +0000293
294static unsigned int v2m_mmci_status(struct device *dev)
295{
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000296 return readl(v2m_sysreg_base + V2M_SYS_MCI) & (1 << 0);
Russell Kingceade892010-02-11 21:44:53 +0000297}
298
299static struct mmci_platform_data v2m_mmci_data = {
300 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
301 .status = v2m_mmci_status,
302};
303
Russell Kingcdd4e1a2011-12-18 12:07:09 +0000304static AMBA_APB_DEVICE(aaci, "mb:aaci", 0, V2M_AACI, IRQ_V2M_AACI, NULL);
305static AMBA_APB_DEVICE(mmci, "mb:mmci", 0, V2M_MMCI, IRQ_V2M_MMCI, &v2m_mmci_data);
306static AMBA_APB_DEVICE(kmi0, "mb:kmi0", 0, V2M_KMI0, IRQ_V2M_KMI0, NULL);
307static AMBA_APB_DEVICE(kmi1, "mb:kmi1", 0, V2M_KMI1, IRQ_V2M_KMI1, NULL);
308static AMBA_APB_DEVICE(uart0, "mb:uart0", 0, V2M_UART0, IRQ_V2M_UART0, NULL);
309static AMBA_APB_DEVICE(uart1, "mb:uart1", 0, V2M_UART1, IRQ_V2M_UART1, NULL);
310static AMBA_APB_DEVICE(uart2, "mb:uart2", 0, V2M_UART2, IRQ_V2M_UART2, NULL);
311static AMBA_APB_DEVICE(uart3, "mb:uart3", 0, V2M_UART3, IRQ_V2M_UART3, NULL);
312static AMBA_APB_DEVICE(wdt, "mb:wdt", 0, V2M_WDT, IRQ_V2M_WDT, NULL);
313static AMBA_APB_DEVICE(rtc, "mb:rtc", 0, V2M_RTC, IRQ_V2M_RTC, NULL);
Russell Kingceade892010-02-11 21:44:53 +0000314
315static struct amba_device *v2m_amba_devs[] __initdata = {
316 &aaci_device,
317 &mmci_device,
318 &kmi0_device,
319 &kmi1_device,
320 &uart0_device,
321 &uart1_device,
322 &uart2_device,
323 &uart3_device,
324 &wdt_device,
325 &rtc_device,
326};
327
328
Pawel Molld1b8a772012-07-13 11:48:16 +0100329static unsigned long v2m_osc_recalc_rate(struct clk_hw *hw,
330 unsigned long parent_rate)
Russell Kingceade892010-02-11 21:44:53 +0000331{
Pawel Molld1b8a772012-07-13 11:48:16 +0100332 struct v2m_osc *osc = to_v2m_osc(hw);
333
334 return !parent_rate ? osc->rate_default : parent_rate;
335}
336
337static long v2m_osc_round_rate(struct clk_hw *hw, unsigned long rate,
338 unsigned long *parent_rate)
339{
340 struct v2m_osc *osc = to_v2m_osc(hw);
341
342 if (WARN_ON(rate < osc->rate_min))
343 rate = osc->rate_min;
344
345 if (WARN_ON(rate > osc->rate_max))
346 rate = osc->rate_max;
347
Russell Kingceade892010-02-11 21:44:53 +0000348 return rate;
349}
350
Pawel Molld1b8a772012-07-13 11:48:16 +0100351static int v2m_osc_set_rate(struct clk_hw *hw, unsigned long rate,
352 unsigned long parent_rate)
Russell Kingceade892010-02-11 21:44:53 +0000353{
Pawel Molld1b8a772012-07-13 11:48:16 +0100354 struct v2m_osc *osc = to_v2m_osc(hw);
355
356 v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE(osc->site) |
357 SYS_CFG_STACK(osc->stack) | osc->osc, rate);
358
359 return 0;
Russell Kingceade892010-02-11 21:44:53 +0000360}
361
Pawel Molld1b8a772012-07-13 11:48:16 +0100362static struct clk_ops v2m_osc_ops = {
363 .recalc_rate = v2m_osc_recalc_rate,
364 .round_rate = v2m_osc_round_rate,
365 .set_rate = v2m_osc_set_rate,
Russell Kingceade892010-02-11 21:44:53 +0000366};
367
Pawel Molld1b8a772012-07-13 11:48:16 +0100368struct clk * __init v2m_osc_register(const char *name, struct v2m_osc *osc)
369{
370 struct clk_init_data init;
371
372 WARN_ON(osc->site > 2);
373 WARN_ON(osc->stack > 15);
374 WARN_ON(osc->osc > 4095);
375
376 init.name = name;
377 init.ops = &v2m_osc_ops;
378 init.flags = CLK_IS_ROOT;
379 init.num_parents = 0;
380
381 osc->hw.init = &init;
382
383 return clk_register(NULL, &osc->hw);
384}
385
386static struct v2m_osc v2m_mb_osc1 = {
387 .site = SYS_CFG_SITE_MB,
388 .osc = 1,
389 .rate_min = 23750000,
390 .rate_max = 63500000,
391 .rate_default = 23750000,
Russell Kingceade892010-02-11 21:44:53 +0000392};
393
Pawel Molld1b8a772012-07-13 11:48:16 +0100394static const char *v2m_ref_clk_periphs[] __initconst = {
395 "mb:wdt", "1000f000.wdt", "1c0f0000.wdt", /* SP805 WDT */
Russell Kingceade892010-02-11 21:44:53 +0000396};
397
Pawel Molld1b8a772012-07-13 11:48:16 +0100398static const char *v2m_osc1_periphs[] __initconst = {
399 "mb:clcd", "1001f000.clcd", "1c1f0000.clcd", /* PL111 CLCD */
Russell King7ff550d2011-05-12 13:31:48 +0100400};
401
Pawel Molld1b8a772012-07-13 11:48:16 +0100402static const char *v2m_osc2_periphs[] __initconst = {
403 "mb:mmci", "10005000.mmci", "1c050000.mmci", /* PL180 MMCI */
404 "mb:kmi0", "10006000.kmi", "1c060000.kmi", /* PL050 KMI0 */
405 "mb:kmi1", "10007000.kmi", "1c070000.kmi", /* PL050 KMI1 */
406 "mb:uart0", "10009000.uart", "1c090000.uart", /* PL011 UART0 */
407 "mb:uart1", "1000a000.uart", "1c0a0000.uart", /* PL011 UART1 */
408 "mb:uart2", "1000b000.uart", "1c0b0000.uart", /* PL011 UART2 */
409 "mb:uart3", "1000c000.uart", "1c0c0000.uart", /* PL011 UART3 */
Nick Bowler0ebb9622011-07-20 15:43:42 +0100410};
411
Pawel Molld1b8a772012-07-13 11:48:16 +0100412static void __init v2m_clk_init(void)
413{
414 struct clk *clk;
415 int i;
Russell King3126c7b2010-07-15 11:01:17 +0100416
Pawel Molld1b8a772012-07-13 11:48:16 +0100417 clk = clk_register_fixed_rate(NULL, "dummy_apb_pclk", NULL,
418 CLK_IS_ROOT, 0);
419 WARN_ON(clk_register_clkdev(clk, "apb_pclk", NULL));
420
421 clk = clk_register_fixed_rate(NULL, "mb:ref_clk", NULL,
422 CLK_IS_ROOT, 32768);
423 for (i = 0; i < ARRAY_SIZE(v2m_ref_clk_periphs); i++)
424 WARN_ON(clk_register_clkdev(clk, NULL, v2m_ref_clk_periphs[i]));
425
426 clk = clk_register_fixed_rate(NULL, "mb:sp804_clk", NULL,
427 CLK_IS_ROOT, 1000000);
428 WARN_ON(clk_register_clkdev(clk, "v2m-timer0", "sp804"));
429 WARN_ON(clk_register_clkdev(clk, "v2m-timer1", "sp804"));
430
431 clk = v2m_osc_register("mb:osc1", &v2m_mb_osc1);
432 for (i = 0; i < ARRAY_SIZE(v2m_osc1_periphs); i++)
433 WARN_ON(clk_register_clkdev(clk, NULL, v2m_osc1_periphs[i]));
434
435 clk = clk_register_fixed_rate(NULL, "mb:osc2", NULL,
436 CLK_IS_ROOT, 24000000);
437 for (i = 0; i < ARRAY_SIZE(v2m_osc2_periphs); i++)
438 WARN_ON(clk_register_clkdev(clk, NULL, v2m_osc2_periphs[i]));
439}
440
441static void __init v2m_timer_init(void)
442{
443 v2m_sysctl_init(ioremap(V2M_SYSCTL, SZ_4K));
444 v2m_clk_init();
445 v2m_sp804_init(ioremap(V2M_TIMER01, SZ_4K), IRQ_V2M_TIMER0);
446}
447
448static struct sys_timer v2m_timer = {
449 .init = v2m_timer_init,
Russell Kingceade892010-02-11 21:44:53 +0000450};
451
Rob Herring2fdf9992011-05-30 19:44:22 +0100452static void __init v2m_init_early(void)
453{
Pawel Molld1b8a772012-07-13 11:48:16 +0100454 if (ct_desc->init_early)
455 ct_desc->init_early();
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000456 versatile_sched_clock_init(v2m_sysreg_base + V2M_SYS_24MHZ, 24000000);
Rob Herring2fdf9992011-05-30 19:44:22 +0100457}
458
Russell Kingceade892010-02-11 21:44:53 +0000459static void v2m_power_off(void)
460{
Pawel Molld927daf2012-06-12 16:14:03 +0100461 if (v2m_cfg_write(SYS_CFG_SHUTDOWN | SYS_CFG_SITE(SYS_CFG_SITE_MB), 0))
Russell Kingceade892010-02-11 21:44:53 +0000462 printk(KERN_EMERG "Unable to shutdown\n");
463}
464
465static void v2m_restart(char str, const char *cmd)
466{
Pawel Molld927daf2012-06-12 16:14:03 +0100467 if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE(SYS_CFG_SITE_MB), 0))
Russell Kingceade892010-02-11 21:44:53 +0000468 printk(KERN_EMERG "Unable to reboot\n");
469}
470
Will Deacon80b5efbd2011-02-28 17:01:04 +0100471struct ct_desc *ct_desc;
472
473static struct ct_desc *ct_descs[] __initdata = {
474#ifdef CONFIG_ARCH_VEXPRESS_CA9X4
475 &ct_ca9x4_desc,
476#endif
477};
478
479static void __init v2m_populate_ct_desc(void)
480{
481 int i;
482 u32 current_tile_id;
483
484 ct_desc = NULL;
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000485 current_tile_id = readl(v2m_sysreg_base + V2M_SYS_PROCID0)
486 & V2M_CT_ID_MASK;
Will Deacon80b5efbd2011-02-28 17:01:04 +0100487
488 for (i = 0; i < ARRAY_SIZE(ct_descs) && !ct_desc; ++i)
489 if (ct_descs[i]->id == current_tile_id)
490 ct_desc = ct_descs[i];
491
492 if (!ct_desc)
Pawel Moll8deed172012-02-23 13:04:51 +0000493 panic("vexpress: this kernel does not support core tile ID 0x%08x when booting via ATAGs.\n"
494 "You may need a device tree blob or a different kernel to boot on this board.\n",
495 current_tile_id);
Will Deacon80b5efbd2011-02-28 17:01:04 +0100496}
497
498static void __init v2m_map_io(void)
499{
500 iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
Pawel Moll98ed4ce2012-01-25 15:37:29 +0000501 v2m_sysreg_base = ioremap(V2M_SYSREGS, SZ_4K);
Will Deacon80b5efbd2011-02-28 17:01:04 +0100502 v2m_populate_ct_desc();
503 ct_desc->map_io();
504}
505
506static void __init v2m_init_irq(void)
507{
508 ct_desc->init_irq();
509}
510
511static void __init v2m_init(void)
Russell Kingceade892010-02-11 21:44:53 +0000512{
513 int i;
514
Pawel Mollb2a54ff2012-07-09 11:33:47 +0100515 regulator_register_fixed(0, v2m_eth_supplies,
516 ARRAY_SIZE(v2m_eth_supplies));
517
Russell Kingceade892010-02-11 21:44:53 +0000518 platform_device_register(&v2m_pcie_i2c_device);
519 platform_device_register(&v2m_ddc_i2c_device);
520 platform_device_register(&v2m_flash_device);
Nick Bowler95c34f82011-01-21 15:51:06 +0100521 platform_device_register(&v2m_cf_device);
Russell Kingceade892010-02-11 21:44:53 +0000522 platform_device_register(&v2m_eth_device);
523 platform_device_register(&v2m_usb_device);
524
525 for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
526 amba_device_register(v2m_amba_devs[i], &iomem_resource);
527
528 pm_power_off = v2m_power_off;
Russell Kingceade892010-02-11 21:44:53 +0000529
Will Deacon80b5efbd2011-02-28 17:01:04 +0100530 ct_desc->init_tile();
Russell Kingceade892010-02-11 21:44:53 +0000531}
Will Deacon80b5efbd2011-02-28 17:01:04 +0100532
533MACHINE_START(VEXPRESS, "ARM-Versatile Express")
Nicolas Pitree9ce8e52011-07-05 22:38:18 -0400534 .atag_offset = 0x100,
Marc Zyngier3695adc2011-09-08 13:15:22 +0100535 .smp = smp_ops(vexpress_smp_ops),
Will Deacon80b5efbd2011-02-28 17:01:04 +0100536 .map_io = v2m_map_io,
537 .init_early = v2m_init_early,
538 .init_irq = v2m_init_irq,
539 .timer = &v2m_timer,
Marc Zyngierabd3ca52011-09-06 10:23:45 +0100540 .handle_irq = gic_handle_irq,
Will Deacon80b5efbd2011-02-28 17:01:04 +0100541 .init_machine = v2m_init,
Russell Kingf5733a12011-11-04 15:47:50 +0000542 .restart = v2m_restart,
Will Deacon80b5efbd2011-02-28 17:01:04 +0100543MACHINE_END
Pawel Moll8deed172012-02-23 13:04:51 +0000544
545#if defined(CONFIG_ARCH_VEXPRESS_DT)
546
Pawel Moll6a371952011-12-09 18:47:39 +0000547static struct map_desc v2m_rs1_io_desc __initdata = {
548 .virtual = V2M_PERIPH,
549 .pfn = __phys_to_pfn(0x1c000000),
550 .length = SZ_2M,
551 .type = MT_DEVICE,
552};
553
554static int __init v2m_dt_scan_memory_map(unsigned long node, const char *uname,
555 int depth, void *data)
556{
557 const char **map = data;
558
559 if (strcmp(uname, "motherboard") != 0)
560 return 0;
561
562 *map = of_get_flat_dt_prop(node, "arm,v2m-memory-map", NULL);
563
564 return 1;
565}
566
Pawel Moll8deed172012-02-23 13:04:51 +0000567void __init v2m_dt_map_io(void)
568{
Pawel Moll6a371952011-12-09 18:47:39 +0000569 const char *map = NULL;
570
571 of_scan_flat_dt(v2m_dt_scan_memory_map, &map);
572
573 if (map && strcmp(map, "rs1") == 0)
574 iotable_init(&v2m_rs1_io_desc, 1);
575 else
576 iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
Pawel Moll8deed172012-02-23 13:04:51 +0000577
578#if defined(CONFIG_SMP)
579 vexpress_dt_smp_map_io();
580#endif
581}
582
Pawel Moll8deed172012-02-23 13:04:51 +0000583void __init v2m_dt_init_early(void)
584{
585 struct device_node *node;
586 u32 dt_hbi;
587
588 node = of_find_compatible_node(NULL, NULL, "arm,vexpress-sysreg");
589 v2m_sysreg_base = of_iomap(node, 0);
590 if (WARN_ON(!v2m_sysreg_base))
591 return;
592
593 /* Confirm board type against DT property, if available */
594 if (of_property_read_u32(allnodes, "arm,hbi", &dt_hbi) == 0) {
Pawel Molld927daf2012-06-12 16:14:03 +0100595 int site = v2m_get_master_site();
596 u32 id = readl(v2m_sysreg_base + (site == SYS_CFG_SITE_DB2 ?
Pawel Moll8deed172012-02-23 13:04:51 +0000597 V2M_SYS_PROCID1 : V2M_SYS_PROCID0));
598 u32 hbi = id & SYS_PROCIDx_HBI_MASK;
599
600 if (WARN_ON(dt_hbi != hbi))
601 pr_warning("vexpress: DT HBI (%x) is not matching "
602 "hardware (%x)!\n", dt_hbi, hbi);
603 }
Pawel Moll8deed172012-02-23 13:04:51 +0000604}
605
606static struct of_device_id vexpress_irq_match[] __initdata = {
607 { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, },
608 {}
609};
610
611static void __init v2m_dt_init_irq(void)
612{
613 of_irq_init(vexpress_irq_match);
614}
615
616static void __init v2m_dt_timer_init(void)
617{
618 struct device_node *node;
619 const char *path;
620 int err;
621
622 node = of_find_compatible_node(NULL, NULL, "arm,sp810");
623 v2m_sysctl_init(of_iomap(node, 0));
624
Pawel Molld1b8a772012-07-13 11:48:16 +0100625 v2m_clk_init();
626
Pawel Moll8deed172012-02-23 13:04:51 +0000627 err = of_property_read_string(of_aliases, "arm,v2m_timer", &path);
628 if (WARN_ON(err))
629 return;
630 node = of_find_node_by_path(path);
631 v2m_sp804_init(of_iomap(node, 0), irq_of_parse_and_map(node, 0));
Marc Zyngier120f3d62012-03-28 17:13:53 +0100632 if (arch_timer_of_register() != 0)
633 twd_local_timer_of_register();
634
635 if (arch_timer_sched_clock_init() != 0)
636 versatile_sched_clock_init(v2m_sysreg_base + V2M_SYS_24MHZ, 24000000);
Pawel Moll8deed172012-02-23 13:04:51 +0000637}
638
639static struct sys_timer v2m_dt_timer = {
640 .init = v2m_dt_timer_init,
641};
642
643static struct of_dev_auxdata v2m_dt_auxdata_lookup[] __initdata = {
644 OF_DEV_AUXDATA("arm,vexpress-flash", V2M_NOR0, "physmap-flash",
645 &v2m_flash_data),
646 OF_DEV_AUXDATA("arm,primecell", V2M_MMCI, "mb:mmci", &v2m_mmci_data),
Pawel Moll6a371952011-12-09 18:47:39 +0000647 /* RS1 memory map */
648 OF_DEV_AUXDATA("arm,vexpress-flash", 0x08000000, "physmap-flash",
649 &v2m_flash_data),
650 OF_DEV_AUXDATA("arm,primecell", 0x1c050000, "mb:mmci", &v2m_mmci_data),
Pawel Moll8deed172012-02-23 13:04:51 +0000651 {}
652};
653
654static void __init v2m_dt_init(void)
655{
656 l2x0_of_init(0x00400000, 0xfe0fffff);
657 of_platform_populate(NULL, of_default_bus_match_table,
658 v2m_dt_auxdata_lookup, NULL);
659 pm_power_off = v2m_power_off;
660}
661
662const static char *v2m_dt_match[] __initconst = {
663 "arm,vexpress",
664 NULL,
665};
666
667DT_MACHINE_START(VEXPRESS_DT, "ARM-Versatile Express")
668 .dt_compat = v2m_dt_match,
Marc Zyngier3695adc2011-09-08 13:15:22 +0100669 .smp = smp_ops(vexpress_smp_ops),
Pawel Moll8deed172012-02-23 13:04:51 +0000670 .map_io = v2m_dt_map_io,
671 .init_early = v2m_dt_init_early,
672 .init_irq = v2m_dt_init_irq,
673 .timer = &v2m_dt_timer,
674 .init_machine = v2m_dt_init,
675 .handle_irq = gic_handle_irq,
676 .restart = v2m_restart,
677MACHINE_END
678
679#endif