blob: 77d5db3d7808e9045172ccae544514c3fab1e1d0 [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 Deacon80b5efb2011-02-28 17:01:04 +010017#include <asm/mach-types.h>
Russell Kingceade892010-02-11 21:44:53 +000018#include <asm/sizes.h>
Will Deacon80b5efb2011-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 Deacon80b5efb2011-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 Deacon80b5efb2011-02-28 17:01:04 +010049static void __init v2m_init_early(void)
Russell Kingceade892010-02-11 21:44:53 +000050{
Will Deacon80b5efb2011-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 Kingceade892010-02-11 21:44:53 +000069 sp804_clockevents_init(MMIO_P2V(V2M_TIMER0), IRQ_V2M_TIMER0);
70}
71
Will Deacon80b5efb2011-02-28 17:01:04 +010072static struct sys_timer v2m_timer = {
Russell Kingceade892010-02-11 21:44:53 +000073 .init = v2m_timer_init,
74};
75
76
77static DEFINE_SPINLOCK(v2m_cfg_lock);
78
79int v2m_cfg_write(u32 devfn, u32 data)
80{
81 /* Configuration interface broken? */
82 u32 val;
83
84 printk("%s: writing %08x to %08x\n", __func__, data, devfn);
85
86 devfn |= SYS_CFG_START | SYS_CFG_WRITE;
87
88 spin_lock(&v2m_cfg_lock);
89 val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
90 writel(val & ~SYS_CFG_COMPLETE, MMIO_P2V(V2M_SYS_CFGSTAT));
91
92 writel(data, MMIO_P2V(V2M_SYS_CFGDATA));
93 writel(devfn, MMIO_P2V(V2M_SYS_CFGCTRL));
94
95 do {
96 val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
97 } while (val == 0);
98 spin_unlock(&v2m_cfg_lock);
99
100 return !!(val & SYS_CFG_ERR);
101}
102
103int v2m_cfg_read(u32 devfn, u32 *data)
104{
105 u32 val;
106
107 devfn |= SYS_CFG_START;
108
109 spin_lock(&v2m_cfg_lock);
110 writel(0, MMIO_P2V(V2M_SYS_CFGSTAT));
111 writel(devfn, MMIO_P2V(V2M_SYS_CFGCTRL));
112
113 mb();
114
115 do {
116 cpu_relax();
117 val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
118 } while (val == 0);
119
120 *data = readl(MMIO_P2V(V2M_SYS_CFGDATA));
121 spin_unlock(&v2m_cfg_lock);
122
123 return !!(val & SYS_CFG_ERR);
124}
125
126
127static struct resource v2m_pcie_i2c_resource = {
128 .start = V2M_SERIAL_BUS_PCI,
129 .end = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
130 .flags = IORESOURCE_MEM,
131};
132
133static struct platform_device v2m_pcie_i2c_device = {
134 .name = "versatile-i2c",
135 .id = 0,
136 .num_resources = 1,
137 .resource = &v2m_pcie_i2c_resource,
138};
139
140static struct resource v2m_ddc_i2c_resource = {
141 .start = V2M_SERIAL_BUS_DVI,
142 .end = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
143 .flags = IORESOURCE_MEM,
144};
145
146static struct platform_device v2m_ddc_i2c_device = {
147 .name = "versatile-i2c",
148 .id = 1,
149 .num_resources = 1,
150 .resource = &v2m_ddc_i2c_resource,
151};
152
153static struct resource v2m_eth_resources[] = {
154 {
155 .start = V2M_LAN9118,
156 .end = V2M_LAN9118 + SZ_64K - 1,
157 .flags = IORESOURCE_MEM,
158 }, {
159 .start = IRQ_V2M_LAN9118,
160 .end = IRQ_V2M_LAN9118,
161 .flags = IORESOURCE_IRQ,
162 },
163};
164
165static struct smsc911x_platform_config v2m_eth_config = {
166 .flags = SMSC911X_USE_32BIT,
167 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
168 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
169 .phy_interface = PHY_INTERFACE_MODE_MII,
170};
171
172static struct platform_device v2m_eth_device = {
173 .name = "smsc911x",
174 .id = -1,
175 .resource = v2m_eth_resources,
176 .num_resources = ARRAY_SIZE(v2m_eth_resources),
177 .dev.platform_data = &v2m_eth_config,
178};
179
180static struct resource v2m_usb_resources[] = {
181 {
182 .start = V2M_ISP1761,
183 .end = V2M_ISP1761 + SZ_128K - 1,
184 .flags = IORESOURCE_MEM,
185 }, {
186 .start = IRQ_V2M_ISP1761,
187 .end = IRQ_V2M_ISP1761,
188 .flags = IORESOURCE_IRQ,
189 },
190};
191
192static struct isp1760_platform_data v2m_usb_config = {
193 .is_isp1761 = true,
194 .bus_width_16 = false,
195 .port1_otg = true,
196 .analog_oc = false,
197 .dack_polarity_high = false,
198 .dreq_polarity_high = false,
199};
200
201static struct platform_device v2m_usb_device = {
202 .name = "isp1760",
203 .id = -1,
204 .resource = v2m_usb_resources,
205 .num_resources = ARRAY_SIZE(v2m_usb_resources),
206 .dev.platform_data = &v2m_usb_config,
207};
208
209static int v2m_flash_init(void)
210{
211 writel(0, MMIO_P2V(V2M_SYS_FLASH));
212 return 0;
213}
214
215static void v2m_flash_exit(void)
216{
217 writel(0, MMIO_P2V(V2M_SYS_FLASH));
218}
219
220static void v2m_flash_set_vpp(int on)
221{
222 writel(on != 0, MMIO_P2V(V2M_SYS_FLASH));
223}
224
225static struct flash_platform_data v2m_flash_data = {
226 .map_name = "cfi_probe",
227 .width = 4,
228 .init = v2m_flash_init,
229 .exit = v2m_flash_exit,
230 .set_vpp = v2m_flash_set_vpp,
231};
232
233static struct resource v2m_flash_resources[] = {
234 {
235 .start = V2M_NOR0,
236 .end = V2M_NOR0 + SZ_64M - 1,
237 .flags = IORESOURCE_MEM,
238 }, {
239 .start = V2M_NOR1,
240 .end = V2M_NOR1 + SZ_64M - 1,
241 .flags = IORESOURCE_MEM,
242 },
243};
244
245static struct platform_device v2m_flash_device = {
246 .name = "armflash",
247 .id = -1,
248 .resource = v2m_flash_resources,
249 .num_resources = ARRAY_SIZE(v2m_flash_resources),
250 .dev.platform_data = &v2m_flash_data,
251};
252
Nick Bowler95c34f82011-01-21 15:51:06 +0100253static struct pata_platform_info v2m_pata_data = {
254 .ioport_shift = 2,
255};
256
257static struct resource v2m_pata_resources[] = {
258 {
259 .start = V2M_CF,
260 .end = V2M_CF + 0xff,
261 .flags = IORESOURCE_MEM,
262 }, {
263 .start = V2M_CF + 0x100,
264 .end = V2M_CF + SZ_4K - 1,
265 .flags = IORESOURCE_MEM,
266 },
267};
268
269static struct platform_device v2m_cf_device = {
270 .name = "pata_platform",
271 .id = -1,
272 .resource = v2m_pata_resources,
273 .num_resources = ARRAY_SIZE(v2m_pata_resources),
274 .dev.platform_data = &v2m_pata_data,
275};
Russell Kingceade892010-02-11 21:44:53 +0000276
277static unsigned int v2m_mmci_status(struct device *dev)
278{
Russell King74bc8092010-07-29 15:58:59 +0100279 return readl(MMIO_P2V(V2M_SYS_MCI)) & (1 << 0);
Russell Kingceade892010-02-11 21:44:53 +0000280}
281
282static struct mmci_platform_data v2m_mmci_data = {
283 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
284 .status = v2m_mmci_status,
285};
286
287static AMBA_DEVICE(aaci, "mb:aaci", V2M_AACI, NULL);
288static AMBA_DEVICE(mmci, "mb:mmci", V2M_MMCI, &v2m_mmci_data);
289static AMBA_DEVICE(kmi0, "mb:kmi0", V2M_KMI0, NULL);
290static AMBA_DEVICE(kmi1, "mb:kmi1", V2M_KMI1, NULL);
291static AMBA_DEVICE(uart0, "mb:uart0", V2M_UART0, NULL);
292static AMBA_DEVICE(uart1, "mb:uart1", V2M_UART1, NULL);
293static AMBA_DEVICE(uart2, "mb:uart2", V2M_UART2, NULL);
294static AMBA_DEVICE(uart3, "mb:uart3", V2M_UART3, NULL);
295static AMBA_DEVICE(wdt, "mb:wdt", V2M_WDT, NULL);
296static AMBA_DEVICE(rtc, "mb:rtc", V2M_RTC, NULL);
297
298static struct amba_device *v2m_amba_devs[] __initdata = {
299 &aaci_device,
300 &mmci_device,
301 &kmi0_device,
302 &kmi1_device,
303 &uart0_device,
304 &uart1_device,
305 &uart2_device,
306 &uart3_device,
307 &wdt_device,
308 &rtc_device,
309};
310
311
312static long v2m_osc_round(struct clk *clk, unsigned long rate)
313{
314 return rate;
315}
316
317static int v2m_osc1_set(struct clk *clk, unsigned long rate)
318{
319 return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_MB | 1, rate);
320}
321
322static const struct clk_ops osc1_clk_ops = {
323 .round = v2m_osc_round,
324 .set = v2m_osc1_set,
325};
326
327static struct clk osc1_clk = {
328 .ops = &osc1_clk_ops,
329 .rate = 24000000,
330};
331
332static struct clk osc2_clk = {
333 .rate = 24000000,
334};
335
Russell King7ff550d2011-05-12 13:31:48 +0100336static struct clk v2m_sp804_clk = {
337 .rate = 1000000,
338};
339
Russell King3126c7b2010-07-15 11:01:17 +0100340static struct clk dummy_apb_pclk;
341
Russell Kingceade892010-02-11 21:44:53 +0000342static struct clk_lookup v2m_lookups[] = {
Russell King3126c7b2010-07-15 11:01:17 +0100343 { /* AMBA bus clock */
344 .con_id = "apb_pclk",
345 .clk = &dummy_apb_pclk,
346 }, { /* UART0 */
Russell Kingceade892010-02-11 21:44:53 +0000347 .dev_id = "mb:uart0",
348 .clk = &osc2_clk,
349 }, { /* UART1 */
350 .dev_id = "mb:uart1",
351 .clk = &osc2_clk,
352 }, { /* UART2 */
353 .dev_id = "mb:uart2",
354 .clk = &osc2_clk,
355 }, { /* UART3 */
356 .dev_id = "mb:uart3",
357 .clk = &osc2_clk,
358 }, { /* KMI0 */
359 .dev_id = "mb:kmi0",
360 .clk = &osc2_clk,
361 }, { /* KMI1 */
362 .dev_id = "mb:kmi1",
363 .clk = &osc2_clk,
364 }, { /* MMC0 */
365 .dev_id = "mb:mmci",
366 .clk = &osc2_clk,
367 }, { /* CLCD */
368 .dev_id = "mb:clcd",
369 .clk = &osc1_clk,
Russell King7ff550d2011-05-12 13:31:48 +0100370 }, { /* SP804 timers */
371 .dev_id = "sp804",
372 .con_id = "v2m-timer1",
373 .clk = &v2m_sp804_clk,
Russell Kingceade892010-02-11 21:44:53 +0000374 },
375};
376
377static void v2m_power_off(void)
378{
379 if (v2m_cfg_write(SYS_CFG_SHUTDOWN | SYS_CFG_SITE_MB, 0))
380 printk(KERN_EMERG "Unable to shutdown\n");
381}
382
383static void v2m_restart(char str, const char *cmd)
384{
385 if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
386 printk(KERN_EMERG "Unable to reboot\n");
387}
388
Will Deacon80b5efb2011-02-28 17:01:04 +0100389struct ct_desc *ct_desc;
390
391static struct ct_desc *ct_descs[] __initdata = {
392#ifdef CONFIG_ARCH_VEXPRESS_CA9X4
393 &ct_ca9x4_desc,
394#endif
395};
396
397static void __init v2m_populate_ct_desc(void)
398{
399 int i;
400 u32 current_tile_id;
401
402 ct_desc = NULL;
403 current_tile_id = readl(MMIO_P2V(V2M_SYS_PROCID0)) & V2M_CT_ID_MASK;
404
405 for (i = 0; i < ARRAY_SIZE(ct_descs) && !ct_desc; ++i)
406 if (ct_descs[i]->id == current_tile_id)
407 ct_desc = ct_descs[i];
408
409 if (!ct_desc)
410 panic("vexpress: failed to populate core tile description "
411 "for tile ID 0x%8x\n", current_tile_id);
412}
413
414static void __init v2m_map_io(void)
415{
416 iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
417 v2m_populate_ct_desc();
418 ct_desc->map_io();
419}
420
421static void __init v2m_init_irq(void)
422{
423 ct_desc->init_irq();
424}
425
426static void __init v2m_init(void)
Russell Kingceade892010-02-11 21:44:53 +0000427{
428 int i;
429
430 clkdev_add_table(v2m_lookups, ARRAY_SIZE(v2m_lookups));
431
432 platform_device_register(&v2m_pcie_i2c_device);
433 platform_device_register(&v2m_ddc_i2c_device);
434 platform_device_register(&v2m_flash_device);
Nick Bowler95c34f82011-01-21 15:51:06 +0100435 platform_device_register(&v2m_cf_device);
Russell Kingceade892010-02-11 21:44:53 +0000436 platform_device_register(&v2m_eth_device);
437 platform_device_register(&v2m_usb_device);
438
439 for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
440 amba_device_register(v2m_amba_devs[i], &iomem_resource);
441
442 pm_power_off = v2m_power_off;
443 arm_pm_restart = v2m_restart;
444
Will Deacon80b5efb2011-02-28 17:01:04 +0100445 ct_desc->init_tile();
Russell Kingceade892010-02-11 21:44:53 +0000446}
Will Deacon80b5efb2011-02-28 17:01:04 +0100447
448MACHINE_START(VEXPRESS, "ARM-Versatile Express")
449 .boot_params = PLAT_PHYS_OFFSET + 0x00000100,
450 .map_io = v2m_map_io,
451 .init_early = v2m_init_early,
452 .init_irq = v2m_init_irq,
453 .timer = &v2m_timer,
454 .init_machine = v2m_init,
455MACHINE_END