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/smsc911x.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 smsc911x_platform_config smsc911x_config = {
132 .flags = SMSC911X_USE_32BIT,
133 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
134 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
135 .phy_interface = PHY_INTERFACE_MODE_MII,
138 static struct platform_device realview_eth_device = {
144 int realview_eth_register(const char *name, struct resource *res)
147 realview_eth_device.name = name;
148 realview_eth_device.resource = res;
149 if (strcmp(realview_eth_device.name, "smsc911x") == 0)
150 realview_eth_device.dev.platform_data = &smsc911x_config;
152 return platform_device_register(&realview_eth_device);
155 struct platform_device realview_usb_device = {
160 int realview_usb_register(struct resource *res)
162 realview_usb_device.resource = res;
163 return platform_device_register(&realview_usb_device);
166 static struct pata_platform_info pata_platform_data = {
170 static struct resource pata_resources[] = {
172 .start = REALVIEW_CF_BASE,
173 .end = REALVIEW_CF_BASE + 0xff,
174 .flags = IORESOURCE_MEM,
177 .start = REALVIEW_CF_BASE + 0x100,
178 .end = REALVIEW_CF_BASE + SZ_4K - 1,
179 .flags = IORESOURCE_MEM,
183 struct platform_device realview_cf_device = {
184 .name = "pata_platform",
186 .num_resources = ARRAY_SIZE(pata_resources),
187 .resource = pata_resources,
189 .platform_data = &pata_platform_data,
193 static struct resource realview_i2c_resource = {
194 .start = REALVIEW_I2C_BASE,
195 .end = REALVIEW_I2C_BASE + SZ_4K - 1,
196 .flags = IORESOURCE_MEM,
199 struct platform_device realview_i2c_device = {
200 .name = "versatile-i2c",
203 .resource = &realview_i2c_resource,
206 static struct i2c_board_info realview_i2c_board_info[] = {
208 I2C_BOARD_INFO("rtc-ds1307", 0xd0 >> 1),
213 static int __init realview_i2c_init(void)
215 return i2c_register_board_info(0, realview_i2c_board_info,
216 ARRAY_SIZE(realview_i2c_board_info));
218 arch_initcall(realview_i2c_init);
220 #define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
222 static unsigned int realview_mmc_status(struct device *dev)
224 struct amba_device *adev = container_of(dev, struct amba_device, dev);
227 if (adev->res.start == REALVIEW_MMCI0_BASE)
232 return readl(REALVIEW_SYSMCI) & mask;
235 struct mmc_platform_data realview_mmc0_plat_data = {
236 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
237 .status = realview_mmc_status,
240 struct mmc_platform_data realview_mmc1_plat_data = {
241 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
242 .status = realview_mmc_status,
248 static const struct icst307_params realview_oscvco_params = {
257 static void realview_oscvco_set(struct clk *clk, struct icst307_vco vco)
259 void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
260 void __iomem *sys_osc;
263 if (machine_is_realview_pb1176())
264 sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC0_OFFSET;
266 sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC4_OFFSET;
268 val = readl(sys_osc) & ~0x7ffff;
269 val |= vco.v | (vco.r << 9) | (vco.s << 16);
271 writel(0xa05f, sys_lock);
272 writel(val, sys_osc);
276 static struct clk oscvco_clk = {
277 .params = &realview_oscvco_params,
278 .setvco = realview_oscvco_set,
282 * These are fixed clocks.
284 static struct clk ref24_clk = {
288 static struct clk_lookup lookups[] = {
319 static int __init clk_init(void)
323 for (i = 0; i < ARRAY_SIZE(lookups); i++)
324 clkdev_add(&lookups[i]);
327 arch_initcall(clk_init);
332 #define SYS_CLCD_NLCDIOON (1 << 2)
333 #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
334 #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
335 #define SYS_CLCD_ID_MASK (0x1f << 8)
336 #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
337 #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
338 #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
339 #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
340 #define SYS_CLCD_ID_VGA (0x1f << 8)
342 static struct clcd_panel vga = {
356 .vmode = FB_VMODE_NONINTERLACED,
360 .tim2 = TIM2_BCD | TIM2_IPC,
361 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
365 static struct clcd_panel xvga = {
379 .vmode = FB_VMODE_NONINTERLACED,
383 .tim2 = TIM2_BCD | TIM2_IPC,
384 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
388 static struct clcd_panel sanyo_3_8_in = {
390 .name = "Sanyo QVGA",
402 .vmode = FB_VMODE_NONINTERLACED,
407 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
411 static struct clcd_panel sanyo_2_5_in = {
413 .name = "Sanyo QVGA Portrait",
424 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
425 .vmode = FB_VMODE_NONINTERLACED,
429 .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
430 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
434 static struct clcd_panel epson_2_2_in = {
436 .name = "Epson QCIF",
448 .vmode = FB_VMODE_NONINTERLACED,
452 .tim2 = TIM2_BCD | TIM2_IPC,
453 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
458 * Detect which LCD panel is connected, and return the appropriate
459 * clcd_panel structure. Note: we do not have any information on
460 * the required timings for the 8.4in panel, so we presently assume
463 static struct clcd_panel *realview_clcd_panel(void)
465 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
466 struct clcd_panel *vga_panel;
467 struct clcd_panel *panel;
470 if (machine_is_realview_eb())
475 val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
476 if (val == SYS_CLCD_ID_SANYO_3_8)
477 panel = &sanyo_3_8_in;
478 else if (val == SYS_CLCD_ID_SANYO_2_5)
479 panel = &sanyo_2_5_in;
480 else if (val == SYS_CLCD_ID_EPSON_2_2)
481 panel = &epson_2_2_in;
482 else if (val == SYS_CLCD_ID_VGA)
485 printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
494 * Disable all display connectors on the interface module.
496 static void realview_clcd_disable(struct clcd_fb *fb)
498 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
501 val = readl(sys_clcd);
502 val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
503 writel(val, sys_clcd);
507 * Enable the relevant connector on the interface module.
509 static void realview_clcd_enable(struct clcd_fb *fb)
511 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
517 val = readl(sys_clcd);
518 val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
519 writel(val, sys_clcd);
522 static int realview_clcd_setup(struct clcd_fb *fb)
524 unsigned long framesize;
527 if (machine_is_realview_eb())
529 framesize = 640 * 480 * 2;
532 framesize = 1024 * 768 * 2;
534 fb->panel = realview_clcd_panel();
536 fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
538 if (!fb->fb.screen_base) {
539 printk(KERN_ERR "CLCD: unable to map framebuffer\n");
543 fb->fb.fix.smem_start = dma;
544 fb->fb.fix.smem_len = framesize;
549 static int realview_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
551 return dma_mmap_writecombine(&fb->dev->dev, vma,
553 fb->fb.fix.smem_start,
554 fb->fb.fix.smem_len);
557 static void realview_clcd_remove(struct clcd_fb *fb)
559 dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
560 fb->fb.screen_base, fb->fb.fix.smem_start);
563 struct clcd_board clcd_plat_data = {
565 .check = clcdfb_check,
566 .decode = clcdfb_decode,
567 .disable = realview_clcd_disable,
568 .enable = realview_clcd_enable,
569 .setup = realview_clcd_setup,
570 .mmap = realview_clcd_mmap,
571 .remove = realview_clcd_remove,
575 #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
577 void realview_leds_event(led_event_t ledevt)
582 local_irq_save(flags);
583 val = readl(VA_LEDS_BASE);
587 val = val & ~REALVIEW_SYS_LED0;
591 val = val | REALVIEW_SYS_LED0;
595 val = val ^ REALVIEW_SYS_LED1;
606 writel(val, VA_LEDS_BASE);
607 local_irq_restore(flags);
609 #endif /* CONFIG_LEDS */
612 * Where is the timer (VA)?
614 void __iomem *timer0_va_base;
615 void __iomem *timer1_va_base;
616 void __iomem *timer2_va_base;
617 void __iomem *timer3_va_base;
620 * How long is the timer interval?
622 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
623 #if TIMER_INTERVAL >= 0x100000
624 #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
625 #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
626 #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
627 #elif TIMER_INTERVAL >= 0x10000
628 #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
629 #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
630 #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
632 #define TIMER_RELOAD (TIMER_INTERVAL)
633 #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
634 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
637 static void timer_set_mode(enum clock_event_mode mode,
638 struct clock_event_device *clk)
643 case CLOCK_EVT_MODE_PERIODIC:
644 writel(TIMER_RELOAD, timer0_va_base + TIMER_LOAD);
646 ctrl = TIMER_CTRL_PERIODIC;
647 ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_ENABLE;
649 case CLOCK_EVT_MODE_ONESHOT:
650 /* period set, and timer enabled in 'next_event' hook */
651 ctrl = TIMER_CTRL_ONESHOT;
652 ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE;
654 case CLOCK_EVT_MODE_UNUSED:
655 case CLOCK_EVT_MODE_SHUTDOWN:
660 writel(ctrl, timer0_va_base + TIMER_CTRL);
663 static int timer_set_next_event(unsigned long evt,
664 struct clock_event_device *unused)
666 unsigned long ctrl = readl(timer0_va_base + TIMER_CTRL);
668 writel(evt, timer0_va_base + TIMER_LOAD);
669 writel(ctrl | TIMER_CTRL_ENABLE, timer0_va_base + TIMER_CTRL);
674 static struct clock_event_device timer0_clockevent = {
677 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
678 .set_mode = timer_set_mode,
679 .set_next_event = timer_set_next_event,
681 .cpumask = cpu_all_mask,
684 static void __init realview_clockevents_init(unsigned int timer_irq)
686 timer0_clockevent.irq = timer_irq;
687 timer0_clockevent.mult =
688 div_sc(1000000, NSEC_PER_SEC, timer0_clockevent.shift);
689 timer0_clockevent.max_delta_ns =
690 clockevent_delta2ns(0xffffffff, &timer0_clockevent);
691 timer0_clockevent.min_delta_ns =
692 clockevent_delta2ns(0xf, &timer0_clockevent);
694 clockevents_register_device(&timer0_clockevent);
698 * IRQ handler for the timer
700 static irqreturn_t realview_timer_interrupt(int irq, void *dev_id)
702 struct clock_event_device *evt = &timer0_clockevent;
704 /* clear the interrupt */
705 writel(1, timer0_va_base + TIMER_INTCLR);
707 evt->event_handler(evt);
712 static struct irqaction realview_timer_irq = {
713 .name = "RealView Timer Tick",
714 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
715 .handler = realview_timer_interrupt,
718 static cycle_t realview_get_cycles(struct clocksource *cs)
720 return ~readl(timer3_va_base + TIMER_VALUE);
723 static struct clocksource clocksource_realview = {
726 .read = realview_get_cycles,
727 .mask = CLOCKSOURCE_MASK(32),
729 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
732 static void __init realview_clocksource_init(void)
734 /* setup timer 0 as free-running clocksource */
735 writel(0, timer3_va_base + TIMER_CTRL);
736 writel(0xffffffff, timer3_va_base + TIMER_LOAD);
737 writel(0xffffffff, timer3_va_base + TIMER_VALUE);
738 writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
739 timer3_va_base + TIMER_CTRL);
741 clocksource_realview.mult =
742 clocksource_khz2mult(1000, clocksource_realview.shift);
743 clocksource_register(&clocksource_realview);
747 * Set up the clock source and clock events devices
749 void __init realview_timer_init(unsigned int timer_irq)
754 * set clock frequency:
755 * REALVIEW_REFCLK is 32KHz
756 * REALVIEW_TIMCLK is 1MHz
758 val = readl(__io_address(REALVIEW_SCTL_BASE));
759 writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
760 (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
761 (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
762 (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
763 __io_address(REALVIEW_SCTL_BASE));
766 * Initialise to a known state (all timers off)
768 writel(0, timer0_va_base + TIMER_CTRL);
769 writel(0, timer1_va_base + TIMER_CTRL);
770 writel(0, timer2_va_base + TIMER_CTRL);
771 writel(0, timer3_va_base + TIMER_CTRL);
774 * Make irqs happen for the system timer
776 setup_irq(timer_irq, &realview_timer_irq);
778 realview_clocksource_init();
779 realview_clockevents_init(timer_irq);