Merge branch 'timers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[pandora-kernel.git] / arch / arm / mach-realview / realview_pbx.c
1 /*
2  *  arch/arm/mach-realview/realview_pbx.c
3  *
4  *  Copyright (C) 2009 ARM Limited
5  *  Copyright (C) 2000 Deep Blue Solutions Ltd
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <linux/init.h>
22 #include <linux/platform_device.h>
23 #include <linux/sysdev.h>
24 #include <linux/amba/bus.h>
25 #include <linux/amba/pl061.h>
26 #include <linux/amba/mmci.h>
27 #include <linux/io.h>
28
29 #include <asm/irq.h>
30 #include <asm/leds.h>
31 #include <asm/mach-types.h>
32 #include <asm/pmu.h>
33 #include <asm/smp_twd.h>
34 #include <asm/hardware/gic.h>
35 #include <asm/hardware/cache-l2x0.h>
36
37 #include <asm/mach/arch.h>
38 #include <asm/mach/map.h>
39 #include <asm/mach/time.h>
40
41 #include <mach/hardware.h>
42 #include <mach/board-pbx.h>
43 #include <mach/irqs.h>
44
45 #include "core.h"
46
47 static struct map_desc realview_pbx_io_desc[] __initdata = {
48         {
49                 .virtual        = IO_ADDRESS(REALVIEW_SYS_BASE),
50                 .pfn            = __phys_to_pfn(REALVIEW_SYS_BASE),
51                 .length         = SZ_4K,
52                 .type           = MT_DEVICE,
53         }, {
54                 .virtual        = IO_ADDRESS(REALVIEW_PBX_GIC_CPU_BASE),
55                 .pfn            = __phys_to_pfn(REALVIEW_PBX_GIC_CPU_BASE),
56                 .length         = SZ_4K,
57                 .type           = MT_DEVICE,
58         }, {
59                 .virtual        = IO_ADDRESS(REALVIEW_PBX_GIC_DIST_BASE),
60                 .pfn            = __phys_to_pfn(REALVIEW_PBX_GIC_DIST_BASE),
61                 .length         = SZ_4K,
62                 .type           = MT_DEVICE,
63         }, {
64                 .virtual        = IO_ADDRESS(REALVIEW_SCTL_BASE),
65                 .pfn            = __phys_to_pfn(REALVIEW_SCTL_BASE),
66                 .length         = SZ_4K,
67                 .type           = MT_DEVICE,
68         }, {
69                 .virtual        = IO_ADDRESS(REALVIEW_PBX_TIMER0_1_BASE),
70                 .pfn            = __phys_to_pfn(REALVIEW_PBX_TIMER0_1_BASE),
71                 .length         = SZ_4K,
72                 .type           = MT_DEVICE,
73         }, {
74                 .virtual        = IO_ADDRESS(REALVIEW_PBX_TIMER2_3_BASE),
75                 .pfn            = __phys_to_pfn(REALVIEW_PBX_TIMER2_3_BASE),
76                 .length         = SZ_4K,
77                 .type           = MT_DEVICE,
78         },
79 #ifdef CONFIG_PCI
80         {
81                 .virtual        = PCIX_UNIT_BASE,
82                 .pfn            = __phys_to_pfn(REALVIEW_PBX_PCI_BASE),
83                 .length         = REALVIEW_PBX_PCI_BASE_SIZE,
84                 .type           = MT_DEVICE,
85         },
86 #endif
87 #ifdef CONFIG_DEBUG_LL
88         {
89                 .virtual        = IO_ADDRESS(REALVIEW_PBX_UART0_BASE),
90                 .pfn            = __phys_to_pfn(REALVIEW_PBX_UART0_BASE),
91                 .length         = SZ_4K,
92                 .type           = MT_DEVICE,
93         },
94 #endif
95 };
96
97 static struct map_desc realview_local_io_desc[] __initdata = {
98         {
99                 .virtual        = IO_ADDRESS(REALVIEW_PBX_TILE_GIC_CPU_BASE),
100                 .pfn            = __phys_to_pfn(REALVIEW_PBX_TILE_GIC_CPU_BASE),
101                 .length         = SZ_4K,
102                 .type           = MT_DEVICE,
103         }, {
104                 .virtual        = IO_ADDRESS(REALVIEW_PBX_TILE_GIC_DIST_BASE),
105                 .pfn            = __phys_to_pfn(REALVIEW_PBX_TILE_GIC_DIST_BASE),
106                 .length         = SZ_4K,
107                 .type           = MT_DEVICE,
108         }, {
109                 .virtual        = IO_ADDRESS(REALVIEW_PBX_TILE_L220_BASE),
110                 .pfn            = __phys_to_pfn(REALVIEW_PBX_TILE_L220_BASE),
111                 .length         = SZ_8K,
112                 .type           = MT_DEVICE,
113         }
114 };
115
116 static void __init realview_pbx_map_io(void)
117 {
118         iotable_init(realview_pbx_io_desc, ARRAY_SIZE(realview_pbx_io_desc));
119         if (core_tile_pbx11mp() || core_tile_pbxa9mp())
120                 iotable_init(realview_local_io_desc, ARRAY_SIZE(realview_local_io_desc));
121 }
122
123 static struct pl061_platform_data gpio0_plat_data = {
124         .gpio_base      = 0,
125         .irq_base       = -1,
126 };
127
128 static struct pl061_platform_data gpio1_plat_data = {
129         .gpio_base      = 8,
130         .irq_base       = -1,
131 };
132
133 static struct pl061_platform_data gpio2_plat_data = {
134         .gpio_base      = 16,
135         .irq_base       = -1,
136 };
137
138 /*
139  * RealView PBXCore AMBA devices
140  */
141
142 #define GPIO2_IRQ               { IRQ_PBX_GPIO2, NO_IRQ }
143 #define GPIO2_DMA               { 0, 0 }
144 #define GPIO3_IRQ               { IRQ_PBX_GPIO3, NO_IRQ }
145 #define GPIO3_DMA               { 0, 0 }
146 #define AACI_IRQ                { IRQ_PBX_AACI, NO_IRQ }
147 #define AACI_DMA                { 0x80, 0x81 }
148 #define MMCI0_IRQ               { IRQ_PBX_MMCI0A, IRQ_PBX_MMCI0B }
149 #define MMCI0_DMA               { 0x84, 0 }
150 #define KMI0_IRQ                { IRQ_PBX_KMI0, NO_IRQ }
151 #define KMI0_DMA                { 0, 0 }
152 #define KMI1_IRQ                { IRQ_PBX_KMI1, NO_IRQ }
153 #define KMI1_DMA                { 0, 0 }
154 #define PBX_SMC_IRQ             { NO_IRQ, NO_IRQ }
155 #define PBX_SMC_DMA             { 0, 0 }
156 #define MPMC_IRQ                { NO_IRQ, NO_IRQ }
157 #define MPMC_DMA                { 0, 0 }
158 #define PBX_CLCD_IRQ            { IRQ_PBX_CLCD, NO_IRQ }
159 #define PBX_CLCD_DMA            { 0, 0 }
160 #define DMAC_IRQ                { IRQ_PBX_DMAC, NO_IRQ }
161 #define DMAC_DMA                { 0, 0 }
162 #define SCTL_IRQ                { NO_IRQ, NO_IRQ }
163 #define SCTL_DMA                { 0, 0 }
164 #define PBX_WATCHDOG_IRQ        { IRQ_PBX_WATCHDOG, NO_IRQ }
165 #define PBX_WATCHDOG_DMA        { 0, 0 }
166 #define PBX_GPIO0_IRQ           { IRQ_PBX_GPIO0, NO_IRQ }
167 #define PBX_GPIO0_DMA           { 0, 0 }
168 #define GPIO1_IRQ               { IRQ_PBX_GPIO1, NO_IRQ }
169 #define GPIO1_DMA               { 0, 0 }
170 #define PBX_RTC_IRQ             { IRQ_PBX_RTC, NO_IRQ }
171 #define PBX_RTC_DMA             { 0, 0 }
172 #define SCI_IRQ                 { IRQ_PBX_SCI, NO_IRQ }
173 #define SCI_DMA                 { 7, 6 }
174 #define PBX_UART0_IRQ           { IRQ_PBX_UART0, NO_IRQ }
175 #define PBX_UART0_DMA           { 15, 14 }
176 #define PBX_UART1_IRQ           { IRQ_PBX_UART1, NO_IRQ }
177 #define PBX_UART1_DMA           { 13, 12 }
178 #define PBX_UART2_IRQ           { IRQ_PBX_UART2, NO_IRQ }
179 #define PBX_UART2_DMA           { 11, 10 }
180 #define PBX_UART3_IRQ           { IRQ_PBX_UART3, NO_IRQ }
181 #define PBX_UART3_DMA           { 0x86, 0x87 }
182 #define PBX_SSP_IRQ             { IRQ_PBX_SSP, NO_IRQ }
183 #define PBX_SSP_DMA             { 9, 8 }
184
185 /* FPGA Primecells */
186 AMBA_DEVICE(aaci,       "fpga:aaci",    AACI,           NULL);
187 AMBA_DEVICE(mmc0,       "fpga:mmc0",    MMCI0,          &realview_mmc0_plat_data);
188 AMBA_DEVICE(kmi0,       "fpga:kmi0",    KMI0,           NULL);
189 AMBA_DEVICE(kmi1,       "fpga:kmi1",    KMI1,           NULL);
190 AMBA_DEVICE(uart3,      "fpga:uart3",   PBX_UART3,      NULL);
191
192 /* DevChip Primecells */
193 AMBA_DEVICE(smc,        "dev:smc",      PBX_SMC,        NULL);
194 AMBA_DEVICE(sctl,       "dev:sctl",     SCTL,           NULL);
195 AMBA_DEVICE(wdog,       "dev:wdog",     PBX_WATCHDOG,   NULL);
196 AMBA_DEVICE(gpio0,      "dev:gpio0",    PBX_GPIO0,      &gpio0_plat_data);
197 AMBA_DEVICE(gpio1,      "dev:gpio1",    GPIO1,          &gpio1_plat_data);
198 AMBA_DEVICE(gpio2,      "dev:gpio2",    GPIO2,          &gpio2_plat_data);
199 AMBA_DEVICE(rtc,        "dev:rtc",      PBX_RTC,        NULL);
200 AMBA_DEVICE(sci0,       "dev:sci0",     SCI,            NULL);
201 AMBA_DEVICE(uart0,      "dev:uart0",    PBX_UART0,      NULL);
202 AMBA_DEVICE(uart1,      "dev:uart1",    PBX_UART1,      NULL);
203 AMBA_DEVICE(uart2,      "dev:uart2",    PBX_UART2,      NULL);
204 AMBA_DEVICE(ssp0,       "dev:ssp0",     PBX_SSP,        NULL);
205
206 /* Primecells on the NEC ISSP chip */
207 AMBA_DEVICE(clcd,       "issp:clcd",    PBX_CLCD,       &clcd_plat_data);
208 AMBA_DEVICE(dmac,       "issp:dmac",    DMAC,           NULL);
209
210 static struct amba_device *amba_devs[] __initdata = {
211         &dmac_device,
212         &uart0_device,
213         &uart1_device,
214         &uart2_device,
215         &uart3_device,
216         &smc_device,
217         &clcd_device,
218         &sctl_device,
219         &wdog_device,
220         &gpio0_device,
221         &gpio1_device,
222         &gpio2_device,
223         &rtc_device,
224         &sci0_device,
225         &ssp0_device,
226         &aaci_device,
227         &mmc0_device,
228         &kmi0_device,
229         &kmi1_device,
230 };
231
232 /*
233  * RealView PB-X platform devices
234  */
235 static struct resource realview_pbx_flash_resources[] = {
236         [0] = {
237                 .start          = REALVIEW_PBX_FLASH0_BASE,
238                 .end            = REALVIEW_PBX_FLASH0_BASE + REALVIEW_PBX_FLASH0_SIZE - 1,
239                 .flags          = IORESOURCE_MEM,
240         },
241         [1] = {
242                 .start          = REALVIEW_PBX_FLASH1_BASE,
243                 .end            = REALVIEW_PBX_FLASH1_BASE + REALVIEW_PBX_FLASH1_SIZE - 1,
244                 .flags          = IORESOURCE_MEM,
245         },
246 };
247
248 static struct resource realview_pbx_smsc911x_resources[] = {
249         [0] = {
250                 .start          = REALVIEW_PBX_ETH_BASE,
251                 .end            = REALVIEW_PBX_ETH_BASE + SZ_64K - 1,
252                 .flags          = IORESOURCE_MEM,
253         },
254         [1] = {
255                 .start          = IRQ_PBX_ETH,
256                 .end            = IRQ_PBX_ETH,
257                 .flags          = IORESOURCE_IRQ,
258         },
259 };
260
261 static struct resource realview_pbx_isp1761_resources[] = {
262         [0] = {
263                 .start          = REALVIEW_PBX_USB_BASE,
264                 .end            = REALVIEW_PBX_USB_BASE + SZ_128K - 1,
265                 .flags          = IORESOURCE_MEM,
266         },
267         [1] = {
268                 .start          = IRQ_PBX_USB,
269                 .end            = IRQ_PBX_USB,
270                 .flags          = IORESOURCE_IRQ,
271         },
272 };
273
274 static struct resource pmu_resources[] = {
275         [0] = {
276                 .start          = IRQ_PBX_PMU_CPU0,
277                 .end            = IRQ_PBX_PMU_CPU0,
278                 .flags          = IORESOURCE_IRQ,
279         },
280         [1] = {
281                 .start          = IRQ_PBX_PMU_CPU1,
282                 .end            = IRQ_PBX_PMU_CPU1,
283                 .flags          = IORESOURCE_IRQ,
284         },
285         [2] = {
286                 .start          = IRQ_PBX_PMU_CPU2,
287                 .end            = IRQ_PBX_PMU_CPU2,
288                 .flags          = IORESOURCE_IRQ,
289         },
290         [3] = {
291                 .start          = IRQ_PBX_PMU_CPU3,
292                 .end            = IRQ_PBX_PMU_CPU3,
293                 .flags          = IORESOURCE_IRQ,
294         },
295 };
296
297 static struct platform_device pmu_device = {
298         .name                   = "arm-pmu",
299         .id                     = ARM_PMU_DEVICE_CPU,
300         .num_resources          = ARRAY_SIZE(pmu_resources),
301         .resource               = pmu_resources,
302 };
303
304 static void __init gic_init_irq(void)
305 {
306         /* ARM PBX on-board GIC */
307         if (core_tile_pbx11mp() || core_tile_pbxa9mp()) {
308                 gic_cpu_base_addr = __io_address(REALVIEW_PBX_TILE_GIC_CPU_BASE);
309                 gic_dist_init(0, __io_address(REALVIEW_PBX_TILE_GIC_DIST_BASE),
310                               29);
311                 gic_cpu_init(0, __io_address(REALVIEW_PBX_TILE_GIC_CPU_BASE));
312         } else {
313                 gic_cpu_base_addr = __io_address(REALVIEW_PBX_GIC_CPU_BASE);
314                 gic_dist_init(0, __io_address(REALVIEW_PBX_GIC_DIST_BASE),
315                               IRQ_PBX_GIC_START);
316                 gic_cpu_init(0, __io_address(REALVIEW_PBX_GIC_CPU_BASE));
317         }
318 }
319
320 static void __init realview_pbx_timer_init(void)
321 {
322         timer0_va_base = __io_address(REALVIEW_PBX_TIMER0_1_BASE);
323         timer1_va_base = __io_address(REALVIEW_PBX_TIMER0_1_BASE) + 0x20;
324         timer2_va_base = __io_address(REALVIEW_PBX_TIMER2_3_BASE);
325         timer3_va_base = __io_address(REALVIEW_PBX_TIMER2_3_BASE) + 0x20;
326
327 #ifdef CONFIG_LOCAL_TIMERS
328         if (core_tile_pbx11mp() || core_tile_pbxa9mp())
329                 twd_base = __io_address(REALVIEW_PBX_TILE_TWD_BASE);
330 #endif
331         realview_timer_init(IRQ_PBX_TIMER0_1);
332 }
333
334 static struct sys_timer realview_pbx_timer = {
335         .init           = realview_pbx_timer_init,
336 };
337
338 static void realview_pbx_fixup(struct machine_desc *mdesc, struct tag *tags,
339                                char **from, struct meminfo *meminfo)
340 {
341 #ifdef CONFIG_SPARSEMEM
342         /*
343          * Memory configuration with SPARSEMEM enabled on RealView PBX (see
344          * asm/mach/memory.h for more information).
345          */
346         meminfo->bank[0].start = 0;
347         meminfo->bank[0].size = SZ_256M;
348         meminfo->bank[1].start = 0x20000000;
349         meminfo->bank[1].size = SZ_512M;
350         meminfo->bank[2].start = 0x80000000;
351         meminfo->bank[2].size = SZ_256M;
352         meminfo->nr_banks = 3;
353 #else
354         realview_fixup(mdesc, tags, from, meminfo);
355 #endif
356 }
357
358 static void realview_pbx_reset(char mode)
359 {
360         void __iomem *reset_ctrl = __io_address(REALVIEW_SYS_RESETCTL);
361         void __iomem *lock_ctrl = __io_address(REALVIEW_SYS_LOCK);
362
363         /*
364          * To reset, we hit the on-board reset register
365          * in the system FPGA
366          */
367         __raw_writel(REALVIEW_SYS_LOCK_VAL, lock_ctrl);
368         __raw_writel(0x00F0, reset_ctrl);
369         __raw_writel(0x00F4, reset_ctrl);
370 }
371
372 static void __init realview_pbx_init(void)
373 {
374         int i;
375
376 #ifdef CONFIG_CACHE_L2X0
377         if (core_tile_pbxa9mp()) {
378                 void __iomem *l2x0_base =
379                         __io_address(REALVIEW_PBX_TILE_L220_BASE);
380
381                 /* set RAM latencies to 1 cycle for eASIC */
382                 writel(0, l2x0_base + L2X0_TAG_LATENCY_CTRL);
383                 writel(0, l2x0_base + L2X0_DATA_LATENCY_CTRL);
384
385                 /* 16KB way size, 8-way associativity, parity disabled
386                  * Bits:  .. 0 0 0 0 1 00 1 0 1 001 0 000 0 .... .... .... */
387                 l2x0_init(l2x0_base, 0x02520000, 0xc0000fff);
388                 platform_device_register(&pmu_device);
389         }
390 #endif
391
392         realview_flash_register(realview_pbx_flash_resources,
393                                 ARRAY_SIZE(realview_pbx_flash_resources));
394         realview_eth_register(NULL, realview_pbx_smsc911x_resources);
395         platform_device_register(&realview_i2c_device);
396         platform_device_register(&realview_cf_device);
397         realview_usb_register(realview_pbx_isp1761_resources);
398
399         for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
400                 struct amba_device *d = amba_devs[i];
401                 amba_device_register(d, &iomem_resource);
402         }
403
404 #ifdef CONFIG_LEDS
405         leds_event = realview_leds_event;
406 #endif
407         realview_reset = realview_pbx_reset;
408 }
409
410 MACHINE_START(REALVIEW_PBX, "ARM-RealView PBX")
411         /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
412         .phys_io        = REALVIEW_PBX_UART0_BASE,
413         .io_pg_offst    = (IO_ADDRESS(REALVIEW_PBX_UART0_BASE) >> 18) & 0xfffc,
414         .boot_params    = PHYS_OFFSET + 0x00000100,
415         .fixup          = realview_pbx_fixup,
416         .map_io         = realview_pbx_map_io,
417         .init_irq       = gic_init_irq,
418         .timer          = &realview_pbx_timer,
419         .init_machine   = realview_pbx_init,
420 MACHINE_END