2 * linux/arch/arm/mach-realview/core.c
4 * Copyright (C) 1999 - 2003 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd
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.
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.
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
21 #include <linux/init.h>
22 #include <linux/platform_device.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/sysdev.h>
25 #include <linux/interrupt.h>
26 #include <linux/amba/bus.h>
27 #include <linux/amba/clcd.h>
28 #include <linux/clocksource.h>
29 #include <linux/clockchips.h>
31 #include <linux/smc911x.h>
32 #include <linux/ata_platform.h>
34 #include <asm/clkdev.h>
35 #include <asm/system.h>
36 #include <mach/hardware.h>
39 #include <asm/mach-types.h>
40 #include <asm/hardware/arm_timer.h>
41 #include <asm/hardware/icst307.h>
43 #include <asm/mach/arch.h>
44 #include <asm/mach/flash.h>
45 #include <asm/mach/irq.h>
46 #include <asm/mach/map.h>
47 #include <asm/mach/mmc.h>
49 #include <asm/hardware/gic.h>
54 #define REALVIEW_REFCOUNTER (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_24MHz_OFFSET)
56 /* used by entry-macro.S and platsmp.c */
57 void __iomem *gic_cpu_base_addr;
60 * This is the RealView sched_clock implementation. This has
61 * a resolution of 41.7ns, and a maximum value of about 179s.
63 unsigned long long sched_clock(void)
67 v = (unsigned long long)readl(REALVIEW_REFCOUNTER) * 125;
74 #define REALVIEW_FLASHCTRL (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
76 static int realview_flash_init(void)
80 val = __raw_readl(REALVIEW_FLASHCTRL);
81 val &= ~REALVIEW_FLASHPROG_FLVPPEN;
82 __raw_writel(val, REALVIEW_FLASHCTRL);
87 static void realview_flash_exit(void)
91 val = __raw_readl(REALVIEW_FLASHCTRL);
92 val &= ~REALVIEW_FLASHPROG_FLVPPEN;
93 __raw_writel(val, REALVIEW_FLASHCTRL);
96 static void realview_flash_set_vpp(int on)
100 val = __raw_readl(REALVIEW_FLASHCTRL);
102 val |= REALVIEW_FLASHPROG_FLVPPEN;
104 val &= ~REALVIEW_FLASHPROG_FLVPPEN;
105 __raw_writel(val, REALVIEW_FLASHCTRL);
108 static struct flash_platform_data realview_flash_data = {
109 .map_name = "cfi_probe",
111 .init = realview_flash_init,
112 .exit = realview_flash_exit,
113 .set_vpp = realview_flash_set_vpp,
116 struct platform_device realview_flash_device = {
120 .platform_data = &realview_flash_data,
124 int realview_flash_register(struct resource *res, u32 num)
126 realview_flash_device.resource = res;
127 realview_flash_device.num_resources = num;
128 return platform_device_register(&realview_flash_device);
131 static struct smc911x_platdata realview_smc911x_platdata = {
132 .flags = SMC911X_USE_32BIT,
133 .irq_flags = IRQF_SHARED,
137 static struct platform_device realview_eth_device = {
143 int realview_eth_register(const char *name, struct resource *res)
146 realview_eth_device.name = name;
147 realview_eth_device.resource = res;
148 if (strcmp(realview_eth_device.name, "smc911x") == 0)
149 realview_eth_device.dev.platform_data = &realview_smc911x_platdata;
151 return platform_device_register(&realview_eth_device);
154 static struct pata_platform_info pata_platform_data = {
158 static struct resource pata_resources[] = {
160 .start = REALVIEW_CF_BASE,
161 .end = REALVIEW_CF_BASE + 0xff,
162 .flags = IORESOURCE_MEM,
165 .start = REALVIEW_CF_BASE + 0x100,
166 .end = REALVIEW_CF_BASE + SZ_4K - 1,
167 .flags = IORESOURCE_MEM,
171 struct platform_device realview_cf_device = {
172 .name = "pata_platform",
174 .num_resources = ARRAY_SIZE(pata_resources),
175 .resource = pata_resources,
177 .platform_data = &pata_platform_data,
181 static struct resource realview_i2c_resource = {
182 .start = REALVIEW_I2C_BASE,
183 .end = REALVIEW_I2C_BASE + SZ_4K - 1,
184 .flags = IORESOURCE_MEM,
187 struct platform_device realview_i2c_device = {
188 .name = "versatile-i2c",
191 .resource = &realview_i2c_resource,
194 static struct i2c_board_info realview_i2c_board_info[] = {
196 I2C_BOARD_INFO("rtc-ds1307", 0xd0 >> 1),
201 static int __init realview_i2c_init(void)
203 return i2c_register_board_info(0, realview_i2c_board_info,
204 ARRAY_SIZE(realview_i2c_board_info));
206 arch_initcall(realview_i2c_init);
208 #define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
210 static unsigned int realview_mmc_status(struct device *dev)
212 struct amba_device *adev = container_of(dev, struct amba_device, dev);
215 if (adev->res.start == REALVIEW_MMCI0_BASE)
220 return readl(REALVIEW_SYSMCI) & mask;
223 struct mmc_platform_data realview_mmc0_plat_data = {
224 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
225 .status = realview_mmc_status,
228 struct mmc_platform_data realview_mmc1_plat_data = {
229 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
230 .status = realview_mmc_status,
236 static const struct icst307_params realview_oscvco_params = {
245 static void realview_oscvco_set(struct clk *clk, struct icst307_vco vco)
247 void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
248 void __iomem *sys_osc;
251 if (machine_is_realview_pb1176())
252 sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC0_OFFSET;
254 sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC4_OFFSET;
256 val = readl(sys_osc) & ~0x7ffff;
257 val |= vco.v | (vco.r << 9) | (vco.s << 16);
259 writel(0xa05f, sys_lock);
260 writel(val, sys_osc);
264 static struct clk oscvco_clk = {
265 .params = &realview_oscvco_params,
266 .setvco = realview_oscvco_set,
270 * These are fixed clocks.
272 static struct clk ref24_clk = {
276 static struct clk_lookup lookups[] = {
307 static int __init clk_init(void)
311 for (i = 0; i < ARRAY_SIZE(lookups); i++)
312 clkdev_add(&lookups[i]);
315 arch_initcall(clk_init);
320 #define SYS_CLCD_NLCDIOON (1 << 2)
321 #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
322 #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
323 #define SYS_CLCD_ID_MASK (0x1f << 8)
324 #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
325 #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
326 #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
327 #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
328 #define SYS_CLCD_ID_VGA (0x1f << 8)
330 static struct clcd_panel vga = {
344 .vmode = FB_VMODE_NONINTERLACED,
348 .tim2 = TIM2_BCD | TIM2_IPC,
349 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
353 static struct clcd_panel xvga = {
367 .vmode = FB_VMODE_NONINTERLACED,
371 .tim2 = TIM2_BCD | TIM2_IPC,
372 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
376 static struct clcd_panel sanyo_3_8_in = {
378 .name = "Sanyo QVGA",
390 .vmode = FB_VMODE_NONINTERLACED,
395 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
399 static struct clcd_panel sanyo_2_5_in = {
401 .name = "Sanyo QVGA Portrait",
412 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
413 .vmode = FB_VMODE_NONINTERLACED,
417 .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
418 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
422 static struct clcd_panel epson_2_2_in = {
424 .name = "Epson QCIF",
436 .vmode = FB_VMODE_NONINTERLACED,
440 .tim2 = TIM2_BCD | TIM2_IPC,
441 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
446 * Detect which LCD panel is connected, and return the appropriate
447 * clcd_panel structure. Note: we do not have any information on
448 * the required timings for the 8.4in panel, so we presently assume
451 static struct clcd_panel *realview_clcd_panel(void)
453 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
454 struct clcd_panel *vga_panel;
455 struct clcd_panel *panel;
458 if (machine_is_realview_eb())
463 val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
464 if (val == SYS_CLCD_ID_SANYO_3_8)
465 panel = &sanyo_3_8_in;
466 else if (val == SYS_CLCD_ID_SANYO_2_5)
467 panel = &sanyo_2_5_in;
468 else if (val == SYS_CLCD_ID_EPSON_2_2)
469 panel = &epson_2_2_in;
470 else if (val == SYS_CLCD_ID_VGA)
473 printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
482 * Disable all display connectors on the interface module.
484 static void realview_clcd_disable(struct clcd_fb *fb)
486 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
489 val = readl(sys_clcd);
490 val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
491 writel(val, sys_clcd);
495 * Enable the relevant connector on the interface module.
497 static void realview_clcd_enable(struct clcd_fb *fb)
499 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
505 val = readl(sys_clcd);
506 val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
507 writel(val, sys_clcd);
510 static int realview_clcd_setup(struct clcd_fb *fb)
512 unsigned long framesize;
515 if (machine_is_realview_eb())
517 framesize = 640 * 480 * 2;
520 framesize = 1024 * 768 * 2;
522 fb->panel = realview_clcd_panel();
524 fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
526 if (!fb->fb.screen_base) {
527 printk(KERN_ERR "CLCD: unable to map framebuffer\n");
531 fb->fb.fix.smem_start = dma;
532 fb->fb.fix.smem_len = framesize;
537 static int realview_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
539 return dma_mmap_writecombine(&fb->dev->dev, vma,
541 fb->fb.fix.smem_start,
542 fb->fb.fix.smem_len);
545 static void realview_clcd_remove(struct clcd_fb *fb)
547 dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
548 fb->fb.screen_base, fb->fb.fix.smem_start);
551 struct clcd_board clcd_plat_data = {
553 .check = clcdfb_check,
554 .decode = clcdfb_decode,
555 .disable = realview_clcd_disable,
556 .enable = realview_clcd_enable,
557 .setup = realview_clcd_setup,
558 .mmap = realview_clcd_mmap,
559 .remove = realview_clcd_remove,
563 #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
565 void realview_leds_event(led_event_t ledevt)
570 local_irq_save(flags);
571 val = readl(VA_LEDS_BASE);
575 val = val & ~REALVIEW_SYS_LED0;
579 val = val | REALVIEW_SYS_LED0;
583 val = val ^ REALVIEW_SYS_LED1;
594 writel(val, VA_LEDS_BASE);
595 local_irq_restore(flags);
597 #endif /* CONFIG_LEDS */
600 * Where is the timer (VA)?
602 void __iomem *timer0_va_base;
603 void __iomem *timer1_va_base;
604 void __iomem *timer2_va_base;
605 void __iomem *timer3_va_base;
608 * How long is the timer interval?
610 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
611 #if TIMER_INTERVAL >= 0x100000
612 #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
613 #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
614 #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
615 #elif TIMER_INTERVAL >= 0x10000
616 #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
617 #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
618 #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
620 #define TIMER_RELOAD (TIMER_INTERVAL)
621 #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
622 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
625 static void timer_set_mode(enum clock_event_mode mode,
626 struct clock_event_device *clk)
631 case CLOCK_EVT_MODE_PERIODIC:
632 writel(TIMER_RELOAD, timer0_va_base + TIMER_LOAD);
634 ctrl = TIMER_CTRL_PERIODIC;
635 ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_ENABLE;
637 case CLOCK_EVT_MODE_ONESHOT:
638 /* period set, and timer enabled in 'next_event' hook */
639 ctrl = TIMER_CTRL_ONESHOT;
640 ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE;
642 case CLOCK_EVT_MODE_UNUSED:
643 case CLOCK_EVT_MODE_SHUTDOWN:
648 writel(ctrl, timer0_va_base + TIMER_CTRL);
651 static int timer_set_next_event(unsigned long evt,
652 struct clock_event_device *unused)
654 unsigned long ctrl = readl(timer0_va_base + TIMER_CTRL);
656 writel(evt, timer0_va_base + TIMER_LOAD);
657 writel(ctrl | TIMER_CTRL_ENABLE, timer0_va_base + TIMER_CTRL);
662 static struct clock_event_device timer0_clockevent = {
665 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
666 .set_mode = timer_set_mode,
667 .set_next_event = timer_set_next_event,
669 .cpumask = cpu_all_mask,
672 static void __init realview_clockevents_init(unsigned int timer_irq)
674 timer0_clockevent.irq = timer_irq;
675 timer0_clockevent.mult =
676 div_sc(1000000, NSEC_PER_SEC, timer0_clockevent.shift);
677 timer0_clockevent.max_delta_ns =
678 clockevent_delta2ns(0xffffffff, &timer0_clockevent);
679 timer0_clockevent.min_delta_ns =
680 clockevent_delta2ns(0xf, &timer0_clockevent);
682 clockevents_register_device(&timer0_clockevent);
686 * IRQ handler for the timer
688 static irqreturn_t realview_timer_interrupt(int irq, void *dev_id)
690 struct clock_event_device *evt = &timer0_clockevent;
692 /* clear the interrupt */
693 writel(1, timer0_va_base + TIMER_INTCLR);
695 evt->event_handler(evt);
700 static struct irqaction realview_timer_irq = {
701 .name = "RealView Timer Tick",
702 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
703 .handler = realview_timer_interrupt,
706 static cycle_t realview_get_cycles(void)
708 return ~readl(timer3_va_base + TIMER_VALUE);
711 static struct clocksource clocksource_realview = {
714 .read = realview_get_cycles,
715 .mask = CLOCKSOURCE_MASK(32),
717 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
720 static void __init realview_clocksource_init(void)
722 /* setup timer 0 as free-running clocksource */
723 writel(0, timer3_va_base + TIMER_CTRL);
724 writel(0xffffffff, timer3_va_base + TIMER_LOAD);
725 writel(0xffffffff, timer3_va_base + TIMER_VALUE);
726 writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
727 timer3_va_base + TIMER_CTRL);
729 clocksource_realview.mult =
730 clocksource_khz2mult(1000, clocksource_realview.shift);
731 clocksource_register(&clocksource_realview);
735 * Set up the clock source and clock events devices
737 void __init realview_timer_init(unsigned int timer_irq)
741 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
743 * The dummy clock device has to be registered before the main device
744 * so that the latter will broadcast the clock events
750 * set clock frequency:
751 * REALVIEW_REFCLK is 32KHz
752 * REALVIEW_TIMCLK is 1MHz
754 val = readl(__io_address(REALVIEW_SCTL_BASE));
755 writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
756 (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
757 (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
758 (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
759 __io_address(REALVIEW_SCTL_BASE));
762 * Initialise to a known state (all timers off)
764 writel(0, timer0_va_base + TIMER_CTRL);
765 writel(0, timer1_va_base + TIMER_CTRL);
766 writel(0, timer2_va_base + TIMER_CTRL);
767 writel(0, timer3_va_base + TIMER_CTRL);
770 * Make irqs happen for the system timer
772 setup_irq(timer_irq, &realview_timer_irq);
774 realview_clocksource_init();
775 realview_clockevents_init(timer_irq);