Merge branch 'master' into for-next
[sfrench/cifs-2.6.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/device.h>
24 #include <linux/amba/bus.h>
25 #include <linux/amba/pl061.h>
26 #include <linux/amba/mmci.h>
27 #include <linux/amba/pl022.h>
28 #include <linux/io.h>
29 #include <linux/irqchip/arm-gic.h>
30 #include <linux/platform_data/clk-realview.h>
31
32 #include <asm/irq.h>
33 #include <asm/mach-types.h>
34 #include <asm/smp_twd.h>
35 #include <asm/pgtable.h>
36 #include <asm/hardware/cache-l2x0.h>
37
38 #include <asm/mach/arch.h>
39 #include <asm/mach/map.h>
40 #include <asm/mach/time.h>
41
42 #include <mach/hardware.h>
43 #include <mach/board-pbx.h>
44 #include <mach/irqs.h>
45
46 #include "core.h"
47
48 static struct map_desc realview_pbx_io_desc[] __initdata = {
49         {
50                 .virtual        = IO_ADDRESS(REALVIEW_SYS_BASE),
51                 .pfn            = __phys_to_pfn(REALVIEW_SYS_BASE),
52                 .length         = SZ_4K,
53                 .type           = MT_DEVICE,
54         }, {
55                 .virtual        = IO_ADDRESS(REALVIEW_PBX_GIC_CPU_BASE),
56                 .pfn            = __phys_to_pfn(REALVIEW_PBX_GIC_CPU_BASE),
57                 .length         = SZ_4K,
58                 .type           = MT_DEVICE,
59         }, {
60                 .virtual        = IO_ADDRESS(REALVIEW_PBX_GIC_DIST_BASE),
61                 .pfn            = __phys_to_pfn(REALVIEW_PBX_GIC_DIST_BASE),
62                 .length         = SZ_4K,
63                 .type           = MT_DEVICE,
64         }, {
65                 .virtual        = IO_ADDRESS(REALVIEW_SCTL_BASE),
66                 .pfn            = __phys_to_pfn(REALVIEW_SCTL_BASE),
67                 .length         = SZ_4K,
68                 .type           = MT_DEVICE,
69         }, {
70                 .virtual        = IO_ADDRESS(REALVIEW_PBX_TIMER0_1_BASE),
71                 .pfn            = __phys_to_pfn(REALVIEW_PBX_TIMER0_1_BASE),
72                 .length         = SZ_4K,
73                 .type           = MT_DEVICE,
74         }, {
75                 .virtual        = IO_ADDRESS(REALVIEW_PBX_TIMER2_3_BASE),
76                 .pfn            = __phys_to_pfn(REALVIEW_PBX_TIMER2_3_BASE),
77                 .length         = SZ_4K,
78                 .type           = MT_DEVICE,
79         },
80 #ifdef CONFIG_PCI
81         {
82                 .virtual        = PCIX_UNIT_BASE,
83                 .pfn            = __phys_to_pfn(REALVIEW_PBX_PCI_BASE),
84                 .length         = REALVIEW_PBX_PCI_BASE_SIZE,
85                 .type           = MT_DEVICE,
86         },
87 #endif
88 #ifdef CONFIG_DEBUG_LL
89         {
90                 .virtual        = IO_ADDRESS(REALVIEW_PBX_UART0_BASE),
91                 .pfn            = __phys_to_pfn(REALVIEW_PBX_UART0_BASE),
92                 .length         = SZ_4K,
93                 .type           = MT_DEVICE,
94         },
95 #endif
96 };
97
98 static struct map_desc realview_local_io_desc[] __initdata = {
99         {
100                 .virtual        = IO_ADDRESS(REALVIEW_PBX_TILE_SCU_BASE),
101                 .pfn            = __phys_to_pfn(REALVIEW_PBX_TILE_SCU_BASE),
102                 .length         = SZ_4K,
103                 .type           = MT_DEVICE,
104         }, {
105                 .virtual        = IO_ADDRESS(REALVIEW_PBX_TILE_GIC_DIST_BASE),
106                 .pfn            = __phys_to_pfn(REALVIEW_PBX_TILE_GIC_DIST_BASE),
107                 .length         = SZ_4K,
108                 .type           = MT_DEVICE,
109         }, {
110                 .virtual        = IO_ADDRESS(REALVIEW_PBX_TILE_L220_BASE),
111                 .pfn            = __phys_to_pfn(REALVIEW_PBX_TILE_L220_BASE),
112                 .length         = SZ_8K,
113                 .type           = MT_DEVICE,
114         }
115 };
116
117 static void __init realview_pbx_map_io(void)
118 {
119         iotable_init(realview_pbx_io_desc, ARRAY_SIZE(realview_pbx_io_desc));
120         if (core_tile_pbx11mp() || core_tile_pbxa9mp())
121                 iotable_init(realview_local_io_desc, ARRAY_SIZE(realview_local_io_desc));
122 }
123
124 static struct pl061_platform_data gpio0_plat_data = {
125         .gpio_base      = 0,
126 };
127
128 static struct pl061_platform_data gpio1_plat_data = {
129         .gpio_base      = 8,
130 };
131
132 static struct pl061_platform_data gpio2_plat_data = {
133         .gpio_base      = 16,
134 };
135
136 static struct pl022_ssp_controller ssp0_plat_data = {
137         .bus_id = 0,
138         .enable_dma = 0,
139         .num_chipselect = 1,
140 };
141
142 /*
143  * RealView PBXCore AMBA devices
144  */
145
146 #define GPIO2_IRQ               { IRQ_PBX_GPIO2 }
147 #define GPIO3_IRQ               { IRQ_PBX_GPIO3 }
148 #define AACI_IRQ                { IRQ_PBX_AACI }
149 #define MMCI0_IRQ               { IRQ_PBX_MMCI0A, IRQ_PBX_MMCI0B }
150 #define KMI0_IRQ                { IRQ_PBX_KMI0 }
151 #define KMI1_IRQ                { IRQ_PBX_KMI1 }
152 #define PBX_SMC_IRQ             { }
153 #define MPMC_IRQ                { }
154 #define PBX_CLCD_IRQ            { IRQ_PBX_CLCD }
155 #define DMAC_IRQ                { IRQ_PBX_DMAC }
156 #define SCTL_IRQ                { }
157 #define PBX_WATCHDOG_IRQ        { IRQ_PBX_WATCHDOG }
158 #define PBX_GPIO0_IRQ           { IRQ_PBX_GPIO0 }
159 #define GPIO1_IRQ               { IRQ_PBX_GPIO1 }
160 #define PBX_RTC_IRQ             { IRQ_PBX_RTC }
161 #define SCI_IRQ                 { IRQ_PBX_SCI }
162 #define PBX_UART0_IRQ           { IRQ_PBX_UART0 }
163 #define PBX_UART1_IRQ           { IRQ_PBX_UART1 }
164 #define PBX_UART2_IRQ           { IRQ_PBX_UART2 }
165 #define PBX_UART3_IRQ           { IRQ_PBX_UART3 }
166 #define PBX_SSP_IRQ             { IRQ_PBX_SSP }
167
168 /* FPGA Primecells */
169 APB_DEVICE(aaci,        "fpga:aaci",    AACI,           NULL);
170 APB_DEVICE(mmc0,        "fpga:mmc0",    MMCI0,          &realview_mmc0_plat_data);
171 APB_DEVICE(kmi0,        "fpga:kmi0",    KMI0,           NULL);
172 APB_DEVICE(kmi1,        "fpga:kmi1",    KMI1,           NULL);
173 APB_DEVICE(uart3,       "fpga:uart3",   PBX_UART3,      NULL);
174
175 /* DevChip Primecells */
176 AHB_DEVICE(smc, "dev:smc",      PBX_SMC,        NULL);
177 AHB_DEVICE(sctl,        "dev:sctl",     SCTL,           NULL);
178 APB_DEVICE(wdog,        "dev:wdog",     PBX_WATCHDOG,   NULL);
179 APB_DEVICE(gpio0,       "dev:gpio0",    PBX_GPIO0,      &gpio0_plat_data);
180 APB_DEVICE(gpio1,       "dev:gpio1",    GPIO1,          &gpio1_plat_data);
181 APB_DEVICE(gpio2,       "dev:gpio2",    GPIO2,          &gpio2_plat_data);
182 APB_DEVICE(rtc,         "dev:rtc",      PBX_RTC,        NULL);
183 APB_DEVICE(sci0,        "dev:sci0",     SCI,            NULL);
184 APB_DEVICE(uart0,       "dev:uart0",    PBX_UART0,      NULL);
185 APB_DEVICE(uart1,       "dev:uart1",    PBX_UART1,      NULL);
186 APB_DEVICE(uart2,       "dev:uart2",    PBX_UART2,      NULL);
187 APB_DEVICE(ssp0,        "dev:ssp0",     PBX_SSP,        &ssp0_plat_data);
188
189 /* Primecells on the NEC ISSP chip */
190 AHB_DEVICE(clcd,        "issp:clcd",    PBX_CLCD,       &clcd_plat_data);
191 AHB_DEVICE(dmac,        "issp:dmac",    DMAC,           NULL);
192
193 static struct amba_device *amba_devs[] __initdata = {
194         &dmac_device,
195         &uart0_device,
196         &uart1_device,
197         &uart2_device,
198         &uart3_device,
199         &smc_device,
200         &clcd_device,
201         &sctl_device,
202         &wdog_device,
203         &gpio0_device,
204         &gpio1_device,
205         &gpio2_device,
206         &rtc_device,
207         &sci0_device,
208         &ssp0_device,
209         &aaci_device,
210         &mmc0_device,
211         &kmi0_device,
212         &kmi1_device,
213 };
214
215 /*
216  * RealView PB-X platform devices
217  */
218 static struct resource realview_pbx_flash_resources[] = {
219         [0] = {
220                 .start          = REALVIEW_PBX_FLASH0_BASE,
221                 .end            = REALVIEW_PBX_FLASH0_BASE + REALVIEW_PBX_FLASH0_SIZE - 1,
222                 .flags          = IORESOURCE_MEM,
223         },
224         [1] = {
225                 .start          = REALVIEW_PBX_FLASH1_BASE,
226                 .end            = REALVIEW_PBX_FLASH1_BASE + REALVIEW_PBX_FLASH1_SIZE - 1,
227                 .flags          = IORESOURCE_MEM,
228         },
229 };
230
231 static struct resource realview_pbx_smsc911x_resources[] = {
232         [0] = {
233                 .start          = REALVIEW_PBX_ETH_BASE,
234                 .end            = REALVIEW_PBX_ETH_BASE + SZ_64K - 1,
235                 .flags          = IORESOURCE_MEM,
236         },
237         [1] = {
238                 .start          = IRQ_PBX_ETH,
239                 .end            = IRQ_PBX_ETH,
240                 .flags          = IORESOURCE_IRQ,
241         },
242 };
243
244 static struct resource realview_pbx_isp1761_resources[] = {
245         [0] = {
246                 .start          = REALVIEW_PBX_USB_BASE,
247                 .end            = REALVIEW_PBX_USB_BASE + SZ_128K - 1,
248                 .flags          = IORESOURCE_MEM,
249         },
250         [1] = {
251                 .start          = IRQ_PBX_USB,
252                 .end            = IRQ_PBX_USB,
253                 .flags          = IORESOURCE_IRQ,
254         },
255 };
256
257 static struct resource pmu_resources[] = {
258         [0] = {
259                 .start          = IRQ_PBX_PMU_CPU0,
260                 .end            = IRQ_PBX_PMU_CPU0,
261                 .flags          = IORESOURCE_IRQ,
262         },
263         [1] = {
264                 .start          = IRQ_PBX_PMU_CPU1,
265                 .end            = IRQ_PBX_PMU_CPU1,
266                 .flags          = IORESOURCE_IRQ,
267         },
268         [2] = {
269                 .start          = IRQ_PBX_PMU_CPU2,
270                 .end            = IRQ_PBX_PMU_CPU2,
271                 .flags          = IORESOURCE_IRQ,
272         },
273         [3] = {
274                 .start          = IRQ_PBX_PMU_CPU3,
275                 .end            = IRQ_PBX_PMU_CPU3,
276                 .flags          = IORESOURCE_IRQ,
277         },
278 };
279
280 static struct platform_device pmu_device = {
281         .name                   = "arm-pmu",
282         .id                     = -1,
283         .num_resources          = ARRAY_SIZE(pmu_resources),
284         .resource               = pmu_resources,
285 };
286
287 static void __init gic_init_irq(void)
288 {
289         /* ARM PBX on-board GIC */
290         if (core_tile_pbx11mp() || core_tile_pbxa9mp()) {
291                 gic_init(0, 29, __io_address(REALVIEW_PBX_TILE_GIC_DIST_BASE),
292                          __io_address(REALVIEW_PBX_TILE_GIC_CPU_BASE));
293         } else {
294                 gic_init(0, IRQ_PBX_GIC_START,
295                          __io_address(REALVIEW_PBX_GIC_DIST_BASE),
296                          __io_address(REALVIEW_PBX_GIC_CPU_BASE));
297         }
298 }
299
300 #ifdef CONFIG_HAVE_ARM_TWD
301 static DEFINE_TWD_LOCAL_TIMER(twd_local_timer,
302                               REALVIEW_PBX_TILE_TWD_BASE,
303                               IRQ_LOCALTIMER);
304
305 static void __init realview_pbx_twd_init(void)
306 {
307         int err = twd_local_timer_register(&twd_local_timer);
308         if (err)
309                 pr_err("twd_local_timer_register failed %d\n", err);
310 }
311 #else
312 #define realview_pbx_twd_init() do { } while(0)
313 #endif
314
315 static void __init realview_pbx_timer_init(void)
316 {
317         timer0_va_base = __io_address(REALVIEW_PBX_TIMER0_1_BASE);
318         timer1_va_base = __io_address(REALVIEW_PBX_TIMER0_1_BASE) + 0x20;
319         timer2_va_base = __io_address(REALVIEW_PBX_TIMER2_3_BASE);
320         timer3_va_base = __io_address(REALVIEW_PBX_TIMER2_3_BASE) + 0x20;
321
322         realview_clk_init(__io_address(REALVIEW_SYS_BASE), false);
323         realview_timer_init(IRQ_PBX_TIMER0_1);
324         realview_pbx_twd_init();
325 }
326
327 static void realview_pbx_fixup(struct tag *tags, char **from,
328                                struct meminfo *meminfo)
329 {
330 #ifdef CONFIG_SPARSEMEM
331         /*
332          * Memory configuration with SPARSEMEM enabled on RealView PBX (see
333          * asm/mach/memory.h for more information).
334          */
335         meminfo->bank[0].start = 0;
336         meminfo->bank[0].size = SZ_256M;
337         meminfo->bank[1].start = 0x20000000;
338         meminfo->bank[1].size = SZ_512M;
339         meminfo->bank[2].start = 0x80000000;
340         meminfo->bank[2].size = SZ_256M;
341         meminfo->nr_banks = 3;
342 #else
343         realview_fixup(tags, from, meminfo);
344 #endif
345 }
346
347 static void realview_pbx_restart(char mode, const char *cmd)
348 {
349         void __iomem *reset_ctrl = __io_address(REALVIEW_SYS_RESETCTL);
350         void __iomem *lock_ctrl = __io_address(REALVIEW_SYS_LOCK);
351
352         /*
353          * To reset, we hit the on-board reset register
354          * in the system FPGA
355          */
356         __raw_writel(REALVIEW_SYS_LOCK_VAL, lock_ctrl);
357         __raw_writel(0x00F0, reset_ctrl);
358         __raw_writel(0x00F4, reset_ctrl);
359         dsb();
360 }
361
362 static void __init realview_pbx_init(void)
363 {
364         int i;
365
366 #ifdef CONFIG_CACHE_L2X0
367         if (core_tile_pbxa9mp()) {
368                 void __iomem *l2x0_base =
369                         __io_address(REALVIEW_PBX_TILE_L220_BASE);
370
371                 /* set RAM latencies to 1 cycle for eASIC */
372                 writel(0, l2x0_base + L2X0_TAG_LATENCY_CTRL);
373                 writel(0, l2x0_base + L2X0_DATA_LATENCY_CTRL);
374
375                 /* 16KB way size, 8-way associativity, parity disabled
376                  * Bits:  .. 0 0 0 0 1 00 1 0 1 001 0 000 0 .... .... .... */
377                 l2x0_init(l2x0_base, 0x02520000, 0xc0000fff);
378                 platform_device_register(&pmu_device);
379         }
380 #endif
381
382         realview_flash_register(realview_pbx_flash_resources,
383                                 ARRAY_SIZE(realview_pbx_flash_resources));
384         realview_eth_register(NULL, realview_pbx_smsc911x_resources);
385         platform_device_register(&realview_i2c_device);
386         platform_device_register(&realview_cf_device);
387         realview_usb_register(realview_pbx_isp1761_resources);
388
389         for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
390                 struct amba_device *d = amba_devs[i];
391                 amba_device_register(d, &iomem_resource);
392         }
393 }
394
395 MACHINE_START(REALVIEW_PBX, "ARM-RealView PBX")
396         /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
397         .atag_offset    = 0x100,
398         .smp            = smp_ops(realview_smp_ops),
399         .fixup          = realview_pbx_fixup,
400         .map_io         = realview_pbx_map_io,
401         .init_early     = realview_init_early,
402         .init_irq       = gic_init_irq,
403         .init_time      = realview_pbx_timer_init,
404         .init_machine   = realview_pbx_init,
405 #ifdef CONFIG_ZONE_DMA
406         .dma_zone_size  = SZ_256M,
407 #endif
408         .restart        = realview_pbx_restart,
409 MACHINE_END