clocksource: ARM sp804: obtain sp804 timer rate via clks
[deliverable/linux.git] / arch / arm / mach-realview / core.c
CommitLineData
8ad68bbf
CM
1/*
2 * linux/arch/arm/mach-realview/core.c
3 *
4 * Copyright (C) 1999 - 2003 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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
8ad68bbf 21#include <linux/init.h>
1be7228d 22#include <linux/platform_device.h>
8ad68bbf
CM
23#include <linux/dma-mapping.h>
24#include <linux/sysdev.h>
25#include <linux/interrupt.h>
a62c80e5
RK
26#include <linux/amba/bus.h>
27#include <linux/amba/clcd.h>
fced80c7 28#include <linux/io.h>
c5142e84 29#include <linux/smsc911x.h>
6be62ba2 30#include <linux/ata_platform.h>
6ef297f8 31#include <linux/amba/mmci.h>
5a0e3ad6 32#include <linux/gfp.h>
6d803ba7 33#include <linux/clkdev.h>
8ad68bbf
CM
34
35#include <asm/system.h>
a09e64fb 36#include <mach/hardware.h>
8ad68bbf
CM
37#include <asm/irq.h>
38#include <asm/leds.h>
68c3d935 39#include <asm/mach-types.h>
8ad68bbf 40#include <asm/hardware/arm_timer.h>
c5a0adb5 41#include <asm/hardware/icst.h>
8ad68bbf
CM
42
43#include <asm/mach/arch.h>
44#include <asm/mach/flash.h>
45#include <asm/mach/irq.h>
8ad68bbf 46#include <asm/mach/map.h>
8ad68bbf
CM
47
48#include <asm/hardware/gic.h>
49
ee8c9571
CM
50#include <mach/platform.h>
51#include <mach/irqs.h>
8a9618f5 52#include <asm/hardware/timer-sp.h>
ee8c9571 53
3cb5ee49 54#include <plat/clcd.h>
1da0c89c
RK
55#include <plat/sched_clock.h>
56
8ad68bbf 57#include "core.h"
8ad68bbf 58
c97c5aa8
CM
59#ifdef CONFIG_ZONE_DMA
60/*
61 * Adjust the zones if there are restrictions for DMA access.
62 */
b65b4781 63void __init realview_adjust_zones(unsigned long *size, unsigned long *hole)
c97c5aa8
CM
64{
65 unsigned long dma_size = SZ_256M >> PAGE_SHIFT;
66
b65b4781 67 if (!machine_is_realview_pbx() || size[0] <= dma_size)
c97c5aa8
CM
68 return;
69
70 size[ZONE_NORMAL] = size[0] - dma_size;
71 size[ZONE_DMA] = dma_size;
72 hole[ZONE_NORMAL] = hole[0];
73 hole[ZONE_DMA] = 0;
74}
75#endif
76
8ad68bbf
CM
77
78#define REALVIEW_FLASHCTRL (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
79
80static int realview_flash_init(void)
81{
82 u32 val;
83
84 val = __raw_readl(REALVIEW_FLASHCTRL);
85 val &= ~REALVIEW_FLASHPROG_FLVPPEN;
86 __raw_writel(val, REALVIEW_FLASHCTRL);
87
88 return 0;
89}
90
91static void realview_flash_exit(void)
92{
93 u32 val;
94
95 val = __raw_readl(REALVIEW_FLASHCTRL);
96 val &= ~REALVIEW_FLASHPROG_FLVPPEN;
97 __raw_writel(val, REALVIEW_FLASHCTRL);
98}
99
100static void realview_flash_set_vpp(int on)
101{
102 u32 val;
103
104 val = __raw_readl(REALVIEW_FLASHCTRL);
105 if (on)
106 val |= REALVIEW_FLASHPROG_FLVPPEN;
107 else
108 val &= ~REALVIEW_FLASHPROG_FLVPPEN;
109 __raw_writel(val, REALVIEW_FLASHCTRL);
110}
111
112static struct flash_platform_data realview_flash_data = {
113 .map_name = "cfi_probe",
114 .width = 4,
115 .init = realview_flash_init,
116 .exit = realview_flash_exit,
117 .set_vpp = realview_flash_set_vpp,
118};
119
8ad68bbf
CM
120struct platform_device realview_flash_device = {
121 .name = "armflash",
122 .id = 0,
123 .dev = {
124 .platform_data = &realview_flash_data,
125 },
8ad68bbf
CM
126};
127
a44ddfd5
CM
128int realview_flash_register(struct resource *res, u32 num)
129{
130 realview_flash_device.resource = res;
131 realview_flash_device.num_resources = num;
132 return platform_device_register(&realview_flash_device);
133}
134
c5142e84
SG
135static struct smsc911x_platform_config smsc911x_config = {
136 .flags = SMSC911X_USE_32BIT,
137 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
138 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
139 .phy_interface = PHY_INTERFACE_MODE_MII,
0a5b2f6b
CM
140};
141
0a381330 142static struct platform_device realview_eth_device = {
c5142e84 143 .name = "smsc911x",
0a381330
CM
144 .id = 0,
145 .num_resources = 2,
146};
147
148int realview_eth_register(const char *name, struct resource *res)
149{
150 if (name)
151 realview_eth_device.name = name;
152 realview_eth_device.resource = res;
c5142e84
SG
153 if (strcmp(realview_eth_device.name, "smsc911x") == 0)
154 realview_eth_device.dev.platform_data = &smsc911x_config;
0a381330
CM
155
156 return platform_device_register(&realview_eth_device);
7db21712
CM
157}
158
159struct platform_device realview_usb_device = {
160 .name = "isp1760",
161 .num_resources = 2,
162};
163
164int realview_usb_register(struct resource *res)
165{
166 realview_usb_device.resource = res;
167 return platform_device_register(&realview_usb_device);
0a381330
CM
168}
169
6be62ba2
CM
170static struct pata_platform_info pata_platform_data = {
171 .ioport_shift = 1,
172};
173
174static struct resource pata_resources[] = {
175 [0] = {
176 .start = REALVIEW_CF_BASE,
177 .end = REALVIEW_CF_BASE + 0xff,
178 .flags = IORESOURCE_MEM,
179 },
180 [1] = {
181 .start = REALVIEW_CF_BASE + 0x100,
182 .end = REALVIEW_CF_BASE + SZ_4K - 1,
183 .flags = IORESOURCE_MEM,
184 },
185};
186
187struct platform_device realview_cf_device = {
188 .name = "pata_platform",
189 .id = -1,
190 .num_resources = ARRAY_SIZE(pata_resources),
191 .resource = pata_resources,
192 .dev = {
193 .platform_data = &pata_platform_data,
194 },
195};
196
6b65cd74
RK
197static struct resource realview_i2c_resource = {
198 .start = REALVIEW_I2C_BASE,
199 .end = REALVIEW_I2C_BASE + SZ_4K - 1,
200 .flags = IORESOURCE_MEM,
201};
202
203struct platform_device realview_i2c_device = {
204 .name = "versatile-i2c",
533ad5e6 205 .id = 0,
6b65cd74
RK
206 .num_resources = 1,
207 .resource = &realview_i2c_resource,
208};
209
533ad5e6
CM
210static struct i2c_board_info realview_i2c_board_info[] = {
211 {
64e8be6e 212 I2C_BOARD_INFO("ds1338", 0xd0 >> 1),
533ad5e6
CM
213 },
214};
215
216static int __init realview_i2c_init(void)
217{
218 return i2c_register_board_info(0, realview_i2c_board_info,
219 ARRAY_SIZE(realview_i2c_board_info));
220}
221arch_initcall(realview_i2c_init);
222
8ad68bbf
CM
223#define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
224
98b0979f
RK
225/*
226 * This is only used if GPIOLIB support is disabled
227 */
8ad68bbf
CM
228static unsigned int realview_mmc_status(struct device *dev)
229{
230 struct amba_device *adev = container_of(dev, struct amba_device, dev);
231 u32 mask;
232
48f1d5a3
LW
233 if (machine_is_realview_pb1176()) {
234 static bool inserted = false;
235
236 /*
237 * The PB1176 does not have the status register,
238 * assume it is inserted at startup, then invert
239 * for each call so card insertion/removal will
240 * be detected anyway. This will not be called if
241 * GPIO on PL061 is active, which is the proper
242 * way to do this on the PB1176.
243 */
244 inserted = !inserted;
245 return inserted ? 0 : 1;
246 }
247
8ad68bbf
CM
248 if (adev->res.start == REALVIEW_MMCI0_BASE)
249 mask = 1;
250 else
251 mask = 2;
252
74bc8093 253 return readl(REALVIEW_SYSMCI) & mask;
8ad68bbf
CM
254}
255
6ef297f8 256struct mmci_platform_data realview_mmc0_plat_data = {
8ad68bbf
CM
257 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
258 .status = realview_mmc_status,
98b0979f
RK
259 .gpio_wp = 17,
260 .gpio_cd = 16,
29719445 261 .cd_invert = true,
8ad68bbf
CM
262};
263
6ef297f8 264struct mmci_platform_data realview_mmc1_plat_data = {
8ad68bbf
CM
265 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
266 .status = realview_mmc_status,
98b0979f
RK
267 .gpio_wp = 19,
268 .gpio_cd = 18,
29719445 269 .cd_invert = true,
8ad68bbf
CM
270};
271
272/*
273 * Clock handling
274 */
39c0cb02 275static const struct icst_params realview_oscvco_params = {
64fceb1d 276 .ref = 24000000,
4de2edbd 277 .vco_max = ICST307_VCO_MAX,
e73a46a3 278 .vco_min = ICST307_VCO_MIN,
8ad68bbf
CM
279 .vd_min = 4 + 8,
280 .vd_max = 511 + 8,
281 .rd_min = 1 + 2,
282 .rd_max = 127 + 2,
232eaf7f
RK
283 .s2div = icst307_s2div,
284 .idx2s = icst307_idx2s,
8ad68bbf
CM
285};
286
39c0cb02 287static void realview_oscvco_set(struct clk *clk, struct icst_vco vco)
8ad68bbf
CM
288{
289 void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
8ad68bbf
CM
290 u32 val;
291
d1914c7e 292 val = readl(clk->vcoreg) & ~0x7ffff;
8ad68bbf
CM
293 val |= vco.v | (vco.r << 9) | (vco.s << 16);
294
295 writel(0xa05f, sys_lock);
d1914c7e 296 writel(val, clk->vcoreg);
8ad68bbf
CM
297 writel(0, sys_lock);
298}
299
9bf5b2ef
RK
300static const struct clk_ops oscvco_clk_ops = {
301 .round = icst_clk_round,
302 .set = icst_clk_set,
303 .setvco = realview_oscvco_set,
304};
305
cf30fb4a 306static struct clk oscvco_clk = {
9bf5b2ef 307 .ops = &oscvco_clk_ops,
8ad68bbf 308 .params = &realview_oscvco_params,
8ad68bbf
CM
309};
310
cf30fb4a
RK
311/*
312 * These are fixed clocks.
313 */
314static struct clk ref24_clk = {
315 .rate = 24000000,
316};
317
7ff550de
RK
318static struct clk sp804_clk = {
319 .rate = 1000000,
320};
321
3126c7bc
RK
322static struct clk dummy_apb_pclk;
323
cf30fb4a 324static struct clk_lookup lookups[] = {
3126c7bc
RK
325 { /* Bus clock */
326 .con_id = "apb_pclk",
327 .clk = &dummy_apb_pclk,
328 }, { /* UART0 */
4321532c 329 .dev_id = "dev:uart0",
cf30fb4a
RK
330 .clk = &ref24_clk,
331 }, { /* UART1 */
4321532c 332 .dev_id = "dev:uart1",
cf30fb4a
RK
333 .clk = &ref24_clk,
334 }, { /* UART2 */
4321532c 335 .dev_id = "dev:uart2",
cf30fb4a
RK
336 .clk = &ref24_clk,
337 }, { /* UART3 */
4321532c 338 .dev_id = "fpga:uart3",
cf30fb4a 339 .clk = &ref24_clk,
48f1d5a3
LW
340 }, { /* UART3 is on the dev chip in PB1176 */
341 .dev_id = "dev:uart3",
342 .clk = &ref24_clk,
343 }, { /* UART4 only exists in PB1176 */
344 .dev_id = "fpga:uart4",
345 .clk = &ref24_clk,
cf30fb4a 346 }, { /* KMI0 */
4321532c 347 .dev_id = "fpga:kmi0",
cf30fb4a
RK
348 .clk = &ref24_clk,
349 }, { /* KMI1 */
4321532c 350 .dev_id = "fpga:kmi1",
cf30fb4a
RK
351 .clk = &ref24_clk,
352 }, { /* MMC0 */
4321532c 353 .dev_id = "fpga:mmc0",
cf30fb4a 354 .clk = &ref24_clk,
48f1d5a3 355 }, { /* CLCD is in the PB1176 and EB DevChip */
4321532c 356 .dev_id = "dev:clcd",
cf30fb4a
RK
357 .clk = &oscvco_clk,
358 }, { /* PB:CLCD */
4321532c 359 .dev_id = "issp:clcd",
cf30fb4a 360 .clk = &oscvco_clk,
d6ada860
LW
361 }, { /* SSP */
362 .dev_id = "dev:ssp0",
363 .clk = &ref24_clk,
7ff550de
RK
364 }, { /* SP804 timers */
365 .dev_id = "sp804",
366 .clk = &sp804_clk,
367 },
cf30fb4a
RK
368};
369
631e55f9 370void __init realview_init_early(void)
cf30fb4a 371{
631e55f9
RK
372 void __iomem *sys = __io_address(REALVIEW_SYS_BASE);
373
d1914c7e 374 if (machine_is_realview_pb1176())
631e55f9 375 oscvco_clk.vcoreg = sys + REALVIEW_SYS_OSC0_OFFSET;
d1914c7e 376 else
631e55f9 377 oscvco_clk.vcoreg = sys + REALVIEW_SYS_OSC4_OFFSET;
d1914c7e 378
0a0300dc 379 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
d1914c7e 380
631e55f9 381 versatile_sched_clock_init(sys + REALVIEW_SYS_24MHz_OFFSET, 24000000);
cf30fb4a 382}
cf30fb4a 383
8ad68bbf
CM
384/*
385 * CLCD support.
386 */
8ad68bbf
CM
387#define SYS_CLCD_NLCDIOON (1 << 2)
388#define SYS_CLCD_VDDPOSSWITCH (1 << 3)
389#define SYS_CLCD_PWR3V5SWITCH (1 << 4)
390#define SYS_CLCD_ID_MASK (0x1f << 8)
391#define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
392#define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
393#define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
394#define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
395#define SYS_CLCD_ID_VGA (0x1f << 8)
396
8ad68bbf
CM
397/*
398 * Disable all display connectors on the interface module.
399 */
400static void realview_clcd_disable(struct clcd_fb *fb)
401{
402 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
403 u32 val;
404
405 val = readl(sys_clcd);
406 val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
407 writel(val, sys_clcd);
408}
409
410/*
411 * Enable the relevant connector on the interface module.
412 */
413static void realview_clcd_enable(struct clcd_fb *fb)
414{
415 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
416 u32 val;
417
8ad68bbf 418 /*
9e7714d0 419 * Enable the PSUs
8ad68bbf 420 */
9e7714d0 421 val = readl(sys_clcd);
8ad68bbf
CM
422 val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
423 writel(val, sys_clcd);
424}
425
3cb5ee49
RK
426/*
427 * Detect which LCD panel is connected, and return the appropriate
428 * clcd_panel structure. Note: we do not have any information on
429 * the required timings for the 8.4in panel, so we presently assume
430 * VGA timings.
431 */
8ad68bbf
CM
432static int realview_clcd_setup(struct clcd_fb *fb)
433{
3cb5ee49
RK
434 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
435 const char *panel_name, *vga_panel_name;
c34a1025 436 unsigned long framesize;
3cb5ee49 437 u32 val;
8ad68bbf 438
3cb5ee49 439 if (machine_is_realview_eb()) {
c34a1025
CT
440 /* VGA, 16bpp */
441 framesize = 640 * 480 * 2;
3cb5ee49
RK
442 vga_panel_name = "VGA";
443 } else {
c34a1025
CT
444 /* XVGA, 16bpp */
445 framesize = 1024 * 768 * 2;
3cb5ee49 446 vga_panel_name = "XVGA";
8ad68bbf
CM
447 }
448
3cb5ee49
RK
449 val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
450 if (val == SYS_CLCD_ID_SANYO_3_8)
451 panel_name = "Sanyo TM38QV67A02A";
452 else if (val == SYS_CLCD_ID_SANYO_2_5)
453 panel_name = "Sanyo QVGA Portrait";
454 else if (val == SYS_CLCD_ID_EPSON_2_2)
455 panel_name = "Epson L2F50113T00";
456 else if (val == SYS_CLCD_ID_VGA)
457 panel_name = vga_panel_name;
458 else {
459 pr_err("CLCD: unknown LCD panel ID 0x%08x, using VGA\n", val);
460 panel_name = vga_panel_name;
461 }
8ad68bbf 462
3cb5ee49
RK
463 fb->panel = versatile_clcd_get_panel(panel_name);
464 if (!fb->panel)
465 return -EINVAL;
8ad68bbf 466
3cb5ee49 467 return versatile_clcd_setup_dma(fb, framesize);
8ad68bbf
CM
468}
469
470struct clcd_board clcd_plat_data = {
471 .name = "RealView",
3cb5ee49 472 .caps = CLCD_CAP_ALL,
8ad68bbf
CM
473 .check = clcdfb_check,
474 .decode = clcdfb_decode,
475 .disable = realview_clcd_disable,
476 .enable = realview_clcd_enable,
477 .setup = realview_clcd_setup,
3cb5ee49
RK
478 .mmap = versatile_clcd_mmap_dma,
479 .remove = versatile_clcd_remove_dma,
8ad68bbf
CM
480};
481
482#ifdef CONFIG_LEDS
483#define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
484
485void realview_leds_event(led_event_t ledevt)
486{
487 unsigned long flags;
488 u32 val;
da055eb5 489 u32 led = 1 << smp_processor_id();
8ad68bbf
CM
490
491 local_irq_save(flags);
492 val = readl(VA_LEDS_BASE);
493
494 switch (ledevt) {
495 case led_idle_start:
da055eb5 496 val = val & ~led;
8ad68bbf
CM
497 break;
498
499 case led_idle_end:
da055eb5 500 val = val | led;
8ad68bbf
CM
501 break;
502
503 case led_timer:
da055eb5 504 val = val ^ REALVIEW_SYS_LED7;
8ad68bbf
CM
505 break;
506
507 case led_halted:
508 val = 0;
509 break;
510
511 default:
512 break;
513 }
514
515 writel(val, VA_LEDS_BASE);
516 local_irq_restore(flags);
517}
518#endif /* CONFIG_LEDS */
519
520/*
521 * Where is the timer (VA)?
522 */
80192735
CM
523void __iomem *timer0_va_base;
524void __iomem *timer1_va_base;
525void __iomem *timer2_va_base;
526void __iomem *timer3_va_base;
8ad68bbf 527
8ad68bbf 528/*
a8655e83 529 * Set up the clock source and clock events devices
8ad68bbf 530 */
8cc4c548 531void __init realview_timer_init(unsigned int timer_irq)
8ad68bbf
CM
532{
533 u32 val;
534
535 /*
536 * set clock frequency:
537 * REALVIEW_REFCLK is 32KHz
538 * REALVIEW_TIMCLK is 1MHz
539 */
540 val = readl(__io_address(REALVIEW_SCTL_BASE));
541 writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
542 (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
543 (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
544 (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
545 __io_address(REALVIEW_SCTL_BASE));
546
547 /*
548 * Initialise to a known state (all timers off)
549 */
80192735
CM
550 writel(0, timer0_va_base + TIMER_CTRL);
551 writel(0, timer1_va_base + TIMER_CTRL);
552 writel(0, timer2_va_base + TIMER_CTRL);
553 writel(0, timer3_va_base + TIMER_CTRL);
8ad68bbf 554
fb593cf3 555 sp804_clocksource_init(timer3_va_base, "timer3");
e3887714 556 sp804_clockevents_init(timer0_va_base, timer_irq);
8ad68bbf 557}
5b39d154
CM
558
559/*
560 * Setup the memory banks.
561 */
562void realview_fixup(struct machine_desc *mdesc, struct tag *tags, char **from,
563 struct meminfo *meminfo)
564{
565 /*
566 * Most RealView platforms have 512MB contiguous RAM at 0x70000000.
567 * Half of this is mirrored at 0.
568 */
569#ifdef CONFIG_REALVIEW_HIGH_PHYS_OFFSET
570 meminfo->bank[0].start = 0x70000000;
571 meminfo->bank[0].size = SZ_512M;
572 meminfo->nr_banks = 1;
573#else
574 meminfo->bank[0].start = 0;
575 meminfo->bank[0].size = SZ_256M;
576 meminfo->nr_banks = 1;
577#endif
578}
This page took 0.58627 seconds and 5 git commands to generate.