blob: 9d9d4af384e226716a0cc1c028bb0592186da45a [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>
13#include <linux/sysdev.h>
14#include <linux/usb/isp1760.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010015#include <linux/clkdev.h>
Russell Kingceade892010-02-11 21:44:53 +000016
Will Deacon80b5efbd2011-02-28 17:01:04 +010017#include <asm/mach-types.h>
Russell Kingceade892010-02-11 21:44:53 +000018#include <asm/sizes.h>
Will Deacon80b5efbd2011-02-28 17:01:04 +010019#include <asm/mach/arch.h>
Russell Kingceade892010-02-11 21:44:53 +000020#include <asm/mach/flash.h>
21#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>
Russell Kingceade892010-02-11 21:44:53 +000026
Will Deacon80b5efbd2011-02-28 17:01:04 +010027#include <mach/ct-ca9x4.h>
Russell Kingceade892010-02-11 21:44:53 +000028#include <mach/motherboard.h>
29
Russell King0af85dd2010-12-15 21:58:50 +000030#include <plat/sched_clock.h>
Russell Kingceade892010-02-11 21:44:53 +000031
32#include "core.h"
33
34#define V2M_PA_CS0 0x40000000
35#define V2M_PA_CS1 0x44000000
36#define V2M_PA_CS2 0x48000000
37#define V2M_PA_CS3 0x4c000000
38#define V2M_PA_CS7 0x10000000
39
40static struct map_desc v2m_io_desc[] __initdata = {
41 {
42 .virtual = __MMIO_P2V(V2M_PA_CS7),
43 .pfn = __phys_to_pfn(V2M_PA_CS7),
44 .length = SZ_128K,
45 .type = MT_DEVICE,
46 },
47};
48
Will Deacon80b5efbd2011-02-28 17:01:04 +010049static void __init v2m_init_early(void)
Russell Kingceade892010-02-11 21:44:53 +000050{
Will Deacon80b5efbd2011-02-28 17:01:04 +010051 ct_desc->init_early();
Russell King493a4512011-01-11 13:07:52 +000052 versatile_sched_clock_init(MMIO_P2V(V2M_SYS_24MHZ), 24000000);
53}
Russell Kingceade892010-02-11 21:44:53 +000054
Russell Kingcdaf9a22010-10-05 11:29:28 +010055static void __init v2m_timer_init(void)
Russell Kingceade892010-02-11 21:44:53 +000056{
Pawel Mollbaaece22011-01-25 15:53:03 +010057 u32 scctrl;
58
Pawel Mollbaaece22011-01-25 15:53:03 +010059 /* Select 1MHz TIMCLK as the reference clock for SP804 timers */
60 scctrl = readl(MMIO_P2V(V2M_SYSCTL + SCCTRL));
61 scctrl |= SCCTRL_TIMEREN0SEL_TIMCLK;
62 scctrl |= SCCTRL_TIMEREN1SEL_TIMCLK;
63 writel(scctrl, MMIO_P2V(V2M_SYSCTL + SCCTRL));
64
Russell Kingceade892010-02-11 21:44:53 +000065 writel(0, MMIO_P2V(V2M_TIMER0) + TIMER_CTRL);
66 writel(0, MMIO_P2V(V2M_TIMER1) + TIMER_CTRL);
67
Russell Kingfb593cf2011-05-12 12:08:23 +010068 sp804_clocksource_init(MMIO_P2V(V2M_TIMER1), "v2m-timer1");
Russell King57cc4f72011-05-12 15:31:13 +010069 sp804_clockevents_init(MMIO_P2V(V2M_TIMER0), IRQ_V2M_TIMER0,
70 "v2m-timer0");
Russell Kingceade892010-02-11 21:44:53 +000071}
72
Will Deacon80b5efbd2011-02-28 17:01:04 +010073static struct sys_timer v2m_timer = {
Russell Kingceade892010-02-11 21:44:53 +000074 .init = v2m_timer_init,
75};
76
77
78static DEFINE_SPINLOCK(v2m_cfg_lock);
79
80int v2m_cfg_write(u32 devfn, u32 data)
81{
82 /* Configuration interface broken? */
83 u32 val;
84
85 printk("%s: writing %08x to %08x\n", __func__, data, devfn);
86
87 devfn |= SYS_CFG_START | SYS_CFG_WRITE;
88
89 spin_lock(&v2m_cfg_lock);
90 val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
91 writel(val & ~SYS_CFG_COMPLETE, MMIO_P2V(V2M_SYS_CFGSTAT));
92
93 writel(data, MMIO_P2V(V2M_SYS_CFGDATA));
94 writel(devfn, MMIO_P2V(V2M_SYS_CFGCTRL));
95
96 do {
97 val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
98 } while (val == 0);
99 spin_unlock(&v2m_cfg_lock);
100
101 return !!(val & SYS_CFG_ERR);
102}
103
104int v2m_cfg_read(u32 devfn, u32 *data)
105{
106 u32 val;
107
108 devfn |= SYS_CFG_START;
109
110 spin_lock(&v2m_cfg_lock);
111 writel(0, MMIO_P2V(V2M_SYS_CFGSTAT));
112 writel(devfn, MMIO_P2V(V2M_SYS_CFGCTRL));
113
114 mb();
115
116 do {
117 cpu_relax();
118 val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
119 } while (val == 0);
120
121 *data = readl(MMIO_P2V(V2M_SYS_CFGDATA));
122 spin_unlock(&v2m_cfg_lock);
123
124 return !!(val & SYS_CFG_ERR);
125}
126
127
128static struct resource v2m_pcie_i2c_resource = {
129 .start = V2M_SERIAL_BUS_PCI,
130 .end = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
131 .flags = IORESOURCE_MEM,
132};
133
134static struct platform_device v2m_pcie_i2c_device = {
135 .name = "versatile-i2c",
136 .id = 0,
137 .num_resources = 1,
138 .resource = &v2m_pcie_i2c_resource,
139};
140
141static struct resource v2m_ddc_i2c_resource = {
142 .start = V2M_SERIAL_BUS_DVI,
143 .end = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
144 .flags = IORESOURCE_MEM,
145};
146
147static struct platform_device v2m_ddc_i2c_device = {
148 .name = "versatile-i2c",
149 .id = 1,
150 .num_resources = 1,
151 .resource = &v2m_ddc_i2c_resource,
152};
153
154static struct resource v2m_eth_resources[] = {
155 {
156 .start = V2M_LAN9118,
157 .end = V2M_LAN9118 + SZ_64K - 1,
158 .flags = IORESOURCE_MEM,
159 }, {
160 .start = IRQ_V2M_LAN9118,
161 .end = IRQ_V2M_LAN9118,
162 .flags = IORESOURCE_IRQ,
163 },
164};
165
166static struct smsc911x_platform_config v2m_eth_config = {
167 .flags = SMSC911X_USE_32BIT,
168 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
169 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
170 .phy_interface = PHY_INTERFACE_MODE_MII,
171};
172
173static struct platform_device v2m_eth_device = {
174 .name = "smsc911x",
175 .id = -1,
176 .resource = v2m_eth_resources,
177 .num_resources = ARRAY_SIZE(v2m_eth_resources),
178 .dev.platform_data = &v2m_eth_config,
179};
180
181static struct resource v2m_usb_resources[] = {
182 {
183 .start = V2M_ISP1761,
184 .end = V2M_ISP1761 + SZ_128K - 1,
185 .flags = IORESOURCE_MEM,
186 }, {
187 .start = IRQ_V2M_ISP1761,
188 .end = IRQ_V2M_ISP1761,
189 .flags = IORESOURCE_IRQ,
190 },
191};
192
193static struct isp1760_platform_data v2m_usb_config = {
194 .is_isp1761 = true,
195 .bus_width_16 = false,
196 .port1_otg = true,
197 .analog_oc = false,
198 .dack_polarity_high = false,
199 .dreq_polarity_high = false,
200};
201
202static struct platform_device v2m_usb_device = {
203 .name = "isp1760",
204 .id = -1,
205 .resource = v2m_usb_resources,
206 .num_resources = ARRAY_SIZE(v2m_usb_resources),
207 .dev.platform_data = &v2m_usb_config,
208};
209
210static int v2m_flash_init(void)
211{
212 writel(0, MMIO_P2V(V2M_SYS_FLASH));
213 return 0;
214}
215
216static void v2m_flash_exit(void)
217{
218 writel(0, MMIO_P2V(V2M_SYS_FLASH));
219}
220
221static void v2m_flash_set_vpp(int on)
222{
223 writel(on != 0, MMIO_P2V(V2M_SYS_FLASH));
224}
225
226static struct flash_platform_data v2m_flash_data = {
227 .map_name = "cfi_probe",
228 .width = 4,
229 .init = v2m_flash_init,
230 .exit = v2m_flash_exit,
231 .set_vpp = v2m_flash_set_vpp,
232};
233
234static struct resource v2m_flash_resources[] = {
235 {
236 .start = V2M_NOR0,
237 .end = V2M_NOR0 + SZ_64M - 1,
238 .flags = IORESOURCE_MEM,
239 }, {
240 .start = V2M_NOR1,
241 .end = V2M_NOR1 + SZ_64M - 1,
242 .flags = IORESOURCE_MEM,
243 },
244};
245
246static struct platform_device v2m_flash_device = {
247 .name = "armflash",
248 .id = -1,
249 .resource = v2m_flash_resources,
250 .num_resources = ARRAY_SIZE(v2m_flash_resources),
251 .dev.platform_data = &v2m_flash_data,
252};
253
Nick Bowler95c34f82011-01-21 15:51:06 +0100254static struct pata_platform_info v2m_pata_data = {
255 .ioport_shift = 2,
256};
257
258static struct resource v2m_pata_resources[] = {
259 {
260 .start = V2M_CF,
261 .end = V2M_CF + 0xff,
262 .flags = IORESOURCE_MEM,
263 }, {
264 .start = V2M_CF + 0x100,
265 .end = V2M_CF + SZ_4K - 1,
266 .flags = IORESOURCE_MEM,
267 },
268};
269
270static struct platform_device v2m_cf_device = {
271 .name = "pata_platform",
272 .id = -1,
273 .resource = v2m_pata_resources,
274 .num_resources = ARRAY_SIZE(v2m_pata_resources),
275 .dev.platform_data = &v2m_pata_data,
276};
Russell Kingceade892010-02-11 21:44:53 +0000277
278static unsigned int v2m_mmci_status(struct device *dev)
279{
Russell King74bc8092010-07-29 15:58:59 +0100280 return readl(MMIO_P2V(V2M_SYS_MCI)) & (1 << 0);
Russell Kingceade892010-02-11 21:44:53 +0000281}
282
283static struct mmci_platform_data v2m_mmci_data = {
284 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
285 .status = v2m_mmci_status,
286};
287
288static AMBA_DEVICE(aaci, "mb:aaci", V2M_AACI, NULL);
289static AMBA_DEVICE(mmci, "mb:mmci", V2M_MMCI, &v2m_mmci_data);
290static AMBA_DEVICE(kmi0, "mb:kmi0", V2M_KMI0, NULL);
291static AMBA_DEVICE(kmi1, "mb:kmi1", V2M_KMI1, NULL);
292static AMBA_DEVICE(uart0, "mb:uart0", V2M_UART0, NULL);
293static AMBA_DEVICE(uart1, "mb:uart1", V2M_UART1, NULL);
294static AMBA_DEVICE(uart2, "mb:uart2", V2M_UART2, NULL);
295static AMBA_DEVICE(uart3, "mb:uart3", V2M_UART3, NULL);
296static AMBA_DEVICE(wdt, "mb:wdt", V2M_WDT, NULL);
297static AMBA_DEVICE(rtc, "mb:rtc", V2M_RTC, NULL);
298
299static struct amba_device *v2m_amba_devs[] __initdata = {
300 &aaci_device,
301 &mmci_device,
302 &kmi0_device,
303 &kmi1_device,
304 &uart0_device,
305 &uart1_device,
306 &uart2_device,
307 &uart3_device,
308 &wdt_device,
309 &rtc_device,
310};
311
312
313static long v2m_osc_round(struct clk *clk, unsigned long rate)
314{
315 return rate;
316}
317
318static int v2m_osc1_set(struct clk *clk, unsigned long rate)
319{
320 return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_MB | 1, rate);
321}
322
323static const struct clk_ops osc1_clk_ops = {
324 .round = v2m_osc_round,
325 .set = v2m_osc1_set,
326};
327
328static struct clk osc1_clk = {
329 .ops = &osc1_clk_ops,
330 .rate = 24000000,
331};
332
333static struct clk osc2_clk = {
334 .rate = 24000000,
335};
336
Russell King7ff550d2011-05-12 13:31:48 +0100337static struct clk v2m_sp804_clk = {
338 .rate = 1000000,
339};
340
Russell King3126c7b2010-07-15 11:01:17 +0100341static struct clk dummy_apb_pclk;
342
Russell Kingceade892010-02-11 21:44:53 +0000343static struct clk_lookup v2m_lookups[] = {
Russell King3126c7b2010-07-15 11:01:17 +0100344 { /* AMBA bus clock */
345 .con_id = "apb_pclk",
346 .clk = &dummy_apb_pclk,
347 }, { /* UART0 */
Russell Kingceade892010-02-11 21:44:53 +0000348 .dev_id = "mb:uart0",
349 .clk = &osc2_clk,
350 }, { /* UART1 */
351 .dev_id = "mb:uart1",
352 .clk = &osc2_clk,
353 }, { /* UART2 */
354 .dev_id = "mb:uart2",
355 .clk = &osc2_clk,
356 }, { /* UART3 */
357 .dev_id = "mb:uart3",
358 .clk = &osc2_clk,
359 }, { /* KMI0 */
360 .dev_id = "mb:kmi0",
361 .clk = &osc2_clk,
362 }, { /* KMI1 */
363 .dev_id = "mb:kmi1",
364 .clk = &osc2_clk,
365 }, { /* MMC0 */
366 .dev_id = "mb:mmci",
367 .clk = &osc2_clk,
368 }, { /* CLCD */
369 .dev_id = "mb:clcd",
370 .clk = &osc1_clk,
Russell King7ff550d2011-05-12 13:31:48 +0100371 }, { /* SP804 timers */
372 .dev_id = "sp804",
Russell King23828a72011-05-12 15:45:16 +0100373 .con_id = "v2m-timer0",
374 .clk = &v2m_sp804_clk,
375 }, { /* SP804 timers */
376 .dev_id = "sp804",
Russell King7ff550d2011-05-12 13:31:48 +0100377 .con_id = "v2m-timer1",
378 .clk = &v2m_sp804_clk,
Russell Kingceade892010-02-11 21:44:53 +0000379 },
380};
381
382static void v2m_power_off(void)
383{
384 if (v2m_cfg_write(SYS_CFG_SHUTDOWN | SYS_CFG_SITE_MB, 0))
385 printk(KERN_EMERG "Unable to shutdown\n");
386}
387
388static void v2m_restart(char str, const char *cmd)
389{
390 if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
391 printk(KERN_EMERG "Unable to reboot\n");
392}
393
Will Deacon80b5efbd2011-02-28 17:01:04 +0100394struct ct_desc *ct_desc;
395
396static struct ct_desc *ct_descs[] __initdata = {
397#ifdef CONFIG_ARCH_VEXPRESS_CA9X4
398 &ct_ca9x4_desc,
399#endif
400};
401
402static void __init v2m_populate_ct_desc(void)
403{
404 int i;
405 u32 current_tile_id;
406
407 ct_desc = NULL;
408 current_tile_id = readl(MMIO_P2V(V2M_SYS_PROCID0)) & V2M_CT_ID_MASK;
409
410 for (i = 0; i < ARRAY_SIZE(ct_descs) && !ct_desc; ++i)
411 if (ct_descs[i]->id == current_tile_id)
412 ct_desc = ct_descs[i];
413
414 if (!ct_desc)
415 panic("vexpress: failed to populate core tile description "
416 "for tile ID 0x%8x\n", current_tile_id);
417}
418
419static void __init v2m_map_io(void)
420{
421 iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
422 v2m_populate_ct_desc();
423 ct_desc->map_io();
424}
425
426static void __init v2m_init_irq(void)
427{
428 ct_desc->init_irq();
429}
430
431static void __init v2m_init(void)
Russell Kingceade892010-02-11 21:44:53 +0000432{
433 int i;
434
435 clkdev_add_table(v2m_lookups, ARRAY_SIZE(v2m_lookups));
436
437 platform_device_register(&v2m_pcie_i2c_device);
438 platform_device_register(&v2m_ddc_i2c_device);
439 platform_device_register(&v2m_flash_device);
Nick Bowler95c34f82011-01-21 15:51:06 +0100440 platform_device_register(&v2m_cf_device);
Russell Kingceade892010-02-11 21:44:53 +0000441 platform_device_register(&v2m_eth_device);
442 platform_device_register(&v2m_usb_device);
443
444 for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
445 amba_device_register(v2m_amba_devs[i], &iomem_resource);
446
447 pm_power_off = v2m_power_off;
448 arm_pm_restart = v2m_restart;
449
Will Deacon80b5efbd2011-02-28 17:01:04 +0100450 ct_desc->init_tile();
Russell Kingceade892010-02-11 21:44:53 +0000451}
Will Deacon80b5efbd2011-02-28 17:01:04 +0100452
453MACHINE_START(VEXPRESS, "ARM-Versatile Express")
454 .boot_params = PLAT_PHYS_OFFSET + 0x00000100,
455 .map_io = v2m_map_io,
456 .init_early = v2m_init_early,
457 .init_irq = v2m_init_irq,
458 .timer = &v2m_timer,
459 .init_machine = v2m_init,
460MACHINE_END