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>
51 #include <mach/platform.h>
52 #include <mach/irqs.h>
57 #define REALVIEW_REFCOUNTER (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_24MHz_OFFSET)
59 /* used by entry-macro.S and platsmp.c */
60 void __iomem *gic_cpu_base_addr;
63 * This is the RealView sched_clock implementation. This has
64 * a resolution of 41.7ns, and a maximum value of about 179s.
66 unsigned long long sched_clock(void)
70 v = (unsigned long long)readl(REALVIEW_REFCOUNTER) * 125;
77 #define REALVIEW_FLASHCTRL (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
79 static int realview_flash_init(void)
83 val = __raw_readl(REALVIEW_FLASHCTRL);
84 val &= ~REALVIEW_FLASHPROG_FLVPPEN;
85 __raw_writel(val, REALVIEW_FLASHCTRL);
90 static void realview_flash_exit(void)
94 val = __raw_readl(REALVIEW_FLASHCTRL);
95 val &= ~REALVIEW_FLASHPROG_FLVPPEN;
96 __raw_writel(val, REALVIEW_FLASHCTRL);
99 static void realview_flash_set_vpp(int on)
103 val = __raw_readl(REALVIEW_FLASHCTRL);
105 val |= REALVIEW_FLASHPROG_FLVPPEN;
107 val &= ~REALVIEW_FLASHPROG_FLVPPEN;
108 __raw_writel(val, REALVIEW_FLASHCTRL);
111 static struct flash_platform_data realview_flash_data = {
112 .map_name = "cfi_probe",
114 .init = realview_flash_init,
115 .exit = realview_flash_exit,
116 .set_vpp = realview_flash_set_vpp,
119 struct platform_device realview_flash_device = {
123 .platform_data = &realview_flash_data,
127 int realview_flash_register(struct resource *res, u32 num)
129 realview_flash_device.resource = res;
130 realview_flash_device.num_resources = num;
131 return platform_device_register(&realview_flash_device);
134 static struct smsc911x_platform_config smsc911x_config = {
135 .flags = SMSC911X_USE_32BIT,
136 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
137 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
138 .phy_interface = PHY_INTERFACE_MODE_MII,
141 static struct platform_device realview_eth_device = {
147 int realview_eth_register(const char *name, struct resource *res)
150 realview_eth_device.name = name;
151 realview_eth_device.resource = res;
152 if (strcmp(realview_eth_device.name, "smsc911x") == 0)
153 realview_eth_device.dev.platform_data = &smsc911x_config;
155 return platform_device_register(&realview_eth_device);
158 struct platform_device realview_usb_device = {
163 int realview_usb_register(struct resource *res)
165 realview_usb_device.resource = res;
166 return platform_device_register(&realview_usb_device);
169 static struct pata_platform_info pata_platform_data = {
173 static struct resource pata_resources[] = {
175 .start = REALVIEW_CF_BASE,
176 .end = REALVIEW_CF_BASE + 0xff,
177 .flags = IORESOURCE_MEM,
180 .start = REALVIEW_CF_BASE + 0x100,
181 .end = REALVIEW_CF_BASE + SZ_4K - 1,
182 .flags = IORESOURCE_MEM,
186 struct platform_device realview_cf_device = {
187 .name = "pata_platform",
189 .num_resources = ARRAY_SIZE(pata_resources),
190 .resource = pata_resources,
192 .platform_data = &pata_platform_data,
196 static struct resource realview_i2c_resource = {
197 .start = REALVIEW_I2C_BASE,
198 .end = REALVIEW_I2C_BASE + SZ_4K - 1,
199 .flags = IORESOURCE_MEM,
202 struct platform_device realview_i2c_device = {
203 .name = "versatile-i2c",
206 .resource = &realview_i2c_resource,
209 static struct i2c_board_info realview_i2c_board_info[] = {
211 I2C_BOARD_INFO("ds1338", 0xd0 >> 1),
215 static int __init realview_i2c_init(void)
217 return i2c_register_board_info(0, realview_i2c_board_info,
218 ARRAY_SIZE(realview_i2c_board_info));
220 arch_initcall(realview_i2c_init);
222 #define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
224 static unsigned int realview_mmc_status(struct device *dev)
226 struct amba_device *adev = container_of(dev, struct amba_device, dev);
229 if (adev->res.start == REALVIEW_MMCI0_BASE)
234 return readl(REALVIEW_SYSMCI) & mask;
237 struct mmc_platform_data realview_mmc0_plat_data = {
238 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
239 .status = realview_mmc_status,
242 struct mmc_platform_data realview_mmc1_plat_data = {
243 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
244 .status = realview_mmc_status,
250 static const struct icst307_params realview_oscvco_params = {
259 static void realview_oscvco_set(struct clk *clk, struct icst307_vco vco)
261 void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
262 void __iomem *sys_osc;
265 if (machine_is_realview_pb1176())
266 sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC0_OFFSET;
268 sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC4_OFFSET;
270 val = readl(sys_osc) & ~0x7ffff;
271 val |= vco.v | (vco.r << 9) | (vco.s << 16);
273 writel(0xa05f, sys_lock);
274 writel(val, sys_osc);
278 static struct clk oscvco_clk = {
279 .params = &realview_oscvco_params,
280 .setvco = realview_oscvco_set,
284 * These are fixed clocks.
286 static struct clk ref24_clk = {
290 static struct clk_lookup lookups[] = {
321 static int __init clk_init(void)
325 for (i = 0; i < ARRAY_SIZE(lookups); i++)
326 clkdev_add(&lookups[i]);
329 arch_initcall(clk_init);
334 #define SYS_CLCD_NLCDIOON (1 << 2)
335 #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
336 #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
337 #define SYS_CLCD_ID_MASK (0x1f << 8)
338 #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
339 #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
340 #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
341 #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
342 #define SYS_CLCD_ID_VGA (0x1f << 8)
344 static struct clcd_panel vga = {
358 .vmode = FB_VMODE_NONINTERLACED,
362 .tim2 = TIM2_BCD | TIM2_IPC,
363 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
367 static struct clcd_panel xvga = {
381 .vmode = FB_VMODE_NONINTERLACED,
385 .tim2 = TIM2_BCD | TIM2_IPC,
386 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
390 static struct clcd_panel sanyo_3_8_in = {
392 .name = "Sanyo QVGA",
404 .vmode = FB_VMODE_NONINTERLACED,
409 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
413 static struct clcd_panel sanyo_2_5_in = {
415 .name = "Sanyo QVGA Portrait",
426 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
427 .vmode = FB_VMODE_NONINTERLACED,
431 .tim2 = TIM2_IVS | TIM2_IHS | TIM2_IPC,
432 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
436 static struct clcd_panel epson_2_2_in = {
438 .name = "Epson QCIF",
450 .vmode = FB_VMODE_NONINTERLACED,
454 .tim2 = TIM2_BCD | TIM2_IPC,
455 .cntl = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
460 * Detect which LCD panel is connected, and return the appropriate
461 * clcd_panel structure. Note: we do not have any information on
462 * the required timings for the 8.4in panel, so we presently assume
465 static struct clcd_panel *realview_clcd_panel(void)
467 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
468 struct clcd_panel *vga_panel;
469 struct clcd_panel *panel;
472 if (machine_is_realview_eb())
477 val = readl(sys_clcd) & SYS_CLCD_ID_MASK;
478 if (val == SYS_CLCD_ID_SANYO_3_8)
479 panel = &sanyo_3_8_in;
480 else if (val == SYS_CLCD_ID_SANYO_2_5)
481 panel = &sanyo_2_5_in;
482 else if (val == SYS_CLCD_ID_EPSON_2_2)
483 panel = &epson_2_2_in;
484 else if (val == SYS_CLCD_ID_VGA)
487 printk(KERN_ERR "CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
496 * Disable all display connectors on the interface module.
498 static void realview_clcd_disable(struct clcd_fb *fb)
500 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
503 val = readl(sys_clcd);
504 val &= ~SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
505 writel(val, sys_clcd);
509 * Enable the relevant connector on the interface module.
511 static void realview_clcd_enable(struct clcd_fb *fb)
513 void __iomem *sys_clcd = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_CLCD_OFFSET;
519 val = readl(sys_clcd);
520 val |= SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH;
521 writel(val, sys_clcd);
524 static int realview_clcd_setup(struct clcd_fb *fb)
526 unsigned long framesize;
529 if (machine_is_realview_eb())
531 framesize = 640 * 480 * 2;
534 framesize = 1024 * 768 * 2;
536 fb->panel = realview_clcd_panel();
538 fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
540 if (!fb->fb.screen_base) {
541 printk(KERN_ERR "CLCD: unable to map framebuffer\n");
545 fb->fb.fix.smem_start = dma;
546 fb->fb.fix.smem_len = framesize;
551 static int realview_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
553 return dma_mmap_writecombine(&fb->dev->dev, vma,
555 fb->fb.fix.smem_start,
556 fb->fb.fix.smem_len);
559 static void realview_clcd_remove(struct clcd_fb *fb)
561 dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
562 fb->fb.screen_base, fb->fb.fix.smem_start);
565 struct clcd_board clcd_plat_data = {
567 .check = clcdfb_check,
568 .decode = clcdfb_decode,
569 .disable = realview_clcd_disable,
570 .enable = realview_clcd_enable,
571 .setup = realview_clcd_setup,
572 .mmap = realview_clcd_mmap,
573 .remove = realview_clcd_remove,
577 #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
579 void realview_leds_event(led_event_t ledevt)
583 u32 led = 1 << smp_processor_id();
585 local_irq_save(flags);
586 val = readl(VA_LEDS_BASE);
598 val = val ^ REALVIEW_SYS_LED7;
609 writel(val, VA_LEDS_BASE);
610 local_irq_restore(flags);
612 #endif /* CONFIG_LEDS */
615 * Where is the timer (VA)?
617 void __iomem *timer0_va_base;
618 void __iomem *timer1_va_base;
619 void __iomem *timer2_va_base;
620 void __iomem *timer3_va_base;
623 * How long is the timer interval?
625 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
626 #if TIMER_INTERVAL >= 0x100000
627 #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
628 #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
629 #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
630 #elif TIMER_INTERVAL >= 0x10000
631 #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
632 #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
633 #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
635 #define TIMER_RELOAD (TIMER_INTERVAL)
636 #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
637 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
640 static void timer_set_mode(enum clock_event_mode mode,
641 struct clock_event_device *clk)
646 case CLOCK_EVT_MODE_PERIODIC:
647 writel(TIMER_RELOAD, timer0_va_base + TIMER_LOAD);
649 ctrl = TIMER_CTRL_PERIODIC;
650 ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_ENABLE;
652 case CLOCK_EVT_MODE_ONESHOT:
653 /* period set, and timer enabled in 'next_event' hook */
654 ctrl = TIMER_CTRL_ONESHOT;
655 ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE;
657 case CLOCK_EVT_MODE_UNUSED:
658 case CLOCK_EVT_MODE_SHUTDOWN:
663 writel(ctrl, timer0_va_base + TIMER_CTRL);
666 static int timer_set_next_event(unsigned long evt,
667 struct clock_event_device *unused)
669 unsigned long ctrl = readl(timer0_va_base + TIMER_CTRL);
671 writel(evt, timer0_va_base + TIMER_LOAD);
672 writel(ctrl | TIMER_CTRL_ENABLE, timer0_va_base + TIMER_CTRL);
677 static struct clock_event_device timer0_clockevent = {
680 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
681 .set_mode = timer_set_mode,
682 .set_next_event = timer_set_next_event,
684 .cpumask = cpu_all_mask,
687 static void __init realview_clockevents_init(unsigned int timer_irq)
689 timer0_clockevent.irq = timer_irq;
690 timer0_clockevent.mult =
691 div_sc(1000000, NSEC_PER_SEC, timer0_clockevent.shift);
692 timer0_clockevent.max_delta_ns =
693 clockevent_delta2ns(0xffffffff, &timer0_clockevent);
694 timer0_clockevent.min_delta_ns =
695 clockevent_delta2ns(0xf, &timer0_clockevent);
697 clockevents_register_device(&timer0_clockevent);
701 * IRQ handler for the timer
703 static irqreturn_t realview_timer_interrupt(int irq, void *dev_id)
705 struct clock_event_device *evt = &timer0_clockevent;
707 /* clear the interrupt */
708 writel(1, timer0_va_base + TIMER_INTCLR);
710 evt->event_handler(evt);
715 static struct irqaction realview_timer_irq = {
716 .name = "RealView Timer Tick",
717 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
718 .handler = realview_timer_interrupt,
721 static cycle_t realview_get_cycles(struct clocksource *cs)
723 return ~readl(timer3_va_base + TIMER_VALUE);
726 static struct clocksource clocksource_realview = {
729 .read = realview_get_cycles,
730 .mask = CLOCKSOURCE_MASK(32),
732 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
735 static void __init realview_clocksource_init(void)
737 /* setup timer 0 as free-running clocksource */
738 writel(0, timer3_va_base + TIMER_CTRL);
739 writel(0xffffffff, timer3_va_base + TIMER_LOAD);
740 writel(0xffffffff, timer3_va_base + TIMER_VALUE);
741 writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
742 timer3_va_base + TIMER_CTRL);
744 clocksource_realview.mult =
745 clocksource_khz2mult(1000, clocksource_realview.shift);
746 clocksource_register(&clocksource_realview);
750 * Set up the clock source and clock events devices
752 void __init realview_timer_init(unsigned int timer_irq)
757 * set clock frequency:
758 * REALVIEW_REFCLK is 32KHz
759 * REALVIEW_TIMCLK is 1MHz
761 val = readl(__io_address(REALVIEW_SCTL_BASE));
762 writel((REALVIEW_TIMCLK << REALVIEW_TIMER1_EnSel) |
763 (REALVIEW_TIMCLK << REALVIEW_TIMER2_EnSel) |
764 (REALVIEW_TIMCLK << REALVIEW_TIMER3_EnSel) |
765 (REALVIEW_TIMCLK << REALVIEW_TIMER4_EnSel) | val,
766 __io_address(REALVIEW_SCTL_BASE));
769 * Initialise to a known state (all timers off)
771 writel(0, timer0_va_base + TIMER_CTRL);
772 writel(0, timer1_va_base + TIMER_CTRL);
773 writel(0, timer2_va_base + TIMER_CTRL);
774 writel(0, timer3_va_base + TIMER_CTRL);
777 * Make irqs happen for the system timer
779 setup_irq(timer_irq, &realview_timer_irq);
781 realview_clocksource_init();
782 realview_clockevents_init(timer_irq);