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>
33 #include <asm/clkdev.h>
34 #include <asm/system.h>
35 #include <mach/hardware.h>
38 #include <asm/mach-types.h>
39 #include <asm/hardware/arm_timer.h>
40 #include <asm/hardware/icst307.h>
42 #include <asm/mach/arch.h>
43 #include <asm/mach/flash.h>
44 #include <asm/mach/irq.h>
45 #include <asm/mach/map.h>
46 #include <asm/mach/mmc.h>
48 #include <asm/hardware/gic.h>
53 #define REALVIEW_REFCOUNTER (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_24MHz_OFFSET)
55 /* used by entry-macro.S and platsmp.c */
56 void __iomem
*gic_cpu_base_addr
;
59 * This is the RealView sched_clock implementation. This has
60 * a resolution of 41.7ns, and a maximum value of about 179s.
62 unsigned long long sched_clock(void)
66 v
= (unsigned long long)readl(REALVIEW_REFCOUNTER
) * 125;
73 #define REALVIEW_FLASHCTRL (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
75 static int realview_flash_init(void)
79 val
= __raw_readl(REALVIEW_FLASHCTRL
);
80 val
&= ~REALVIEW_FLASHPROG_FLVPPEN
;
81 __raw_writel(val
, REALVIEW_FLASHCTRL
);
86 static void realview_flash_exit(void)
90 val
= __raw_readl(REALVIEW_FLASHCTRL
);
91 val
&= ~REALVIEW_FLASHPROG_FLVPPEN
;
92 __raw_writel(val
, REALVIEW_FLASHCTRL
);
95 static void realview_flash_set_vpp(int on
)
99 val
= __raw_readl(REALVIEW_FLASHCTRL
);
101 val
|= REALVIEW_FLASHPROG_FLVPPEN
;
103 val
&= ~REALVIEW_FLASHPROG_FLVPPEN
;
104 __raw_writel(val
, REALVIEW_FLASHCTRL
);
107 static struct flash_platform_data realview_flash_data
= {
108 .map_name
= "cfi_probe",
110 .init
= realview_flash_init
,
111 .exit
= realview_flash_exit
,
112 .set_vpp
= realview_flash_set_vpp
,
115 struct platform_device realview_flash_device
= {
119 .platform_data
= &realview_flash_data
,
123 int realview_flash_register(struct resource
*res
, u32 num
)
125 realview_flash_device
.resource
= res
;
126 realview_flash_device
.num_resources
= num
;
127 return platform_device_register(&realview_flash_device
);
130 static struct smc911x_platdata realview_smc911x_platdata
= {
131 .flags
= SMC911X_USE_32BIT
,
132 .irq_flags
= IRQF_SHARED
,
136 static struct platform_device realview_eth_device
= {
142 int realview_eth_register(const char *name
, struct resource
*res
)
145 realview_eth_device
.name
= name
;
146 realview_eth_device
.resource
= res
;
147 if (strcmp(realview_eth_device
.name
, "smc911x") == 0)
148 realview_eth_device
.dev
.platform_data
= &realview_smc911x_platdata
;
150 return platform_device_register(&realview_eth_device
);
153 static struct resource realview_i2c_resource
= {
154 .start
= REALVIEW_I2C_BASE
,
155 .end
= REALVIEW_I2C_BASE
+ SZ_4K
- 1,
156 .flags
= IORESOURCE_MEM
,
159 struct platform_device realview_i2c_device
= {
160 .name
= "versatile-i2c",
163 .resource
= &realview_i2c_resource
,
166 #define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
168 static unsigned int realview_mmc_status(struct device
*dev
)
170 struct amba_device
*adev
= container_of(dev
, struct amba_device
, dev
);
173 if (adev
->res
.start
== REALVIEW_MMCI0_BASE
)
178 return readl(REALVIEW_SYSMCI
) & mask
;
181 struct mmc_platform_data realview_mmc0_plat_data
= {
182 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
183 .status
= realview_mmc_status
,
186 struct mmc_platform_data realview_mmc1_plat_data
= {
187 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
188 .status
= realview_mmc_status
,
194 static const struct icst307_params realview_oscvco_params
= {
203 static void realview_oscvco_set(struct clk
*clk
, struct icst307_vco vco
)
205 void __iomem
*sys_lock
= __io_address(REALVIEW_SYS_BASE
) + REALVIEW_SYS_LOCK_OFFSET
;
206 void __iomem
*sys_osc
;
209 if (machine_is_realview_pb1176())
210 sys_osc
= __io_address(REALVIEW_SYS_BASE
) + REALVIEW_SYS_OSC0_OFFSET
;
212 sys_osc
= __io_address(REALVIEW_SYS_BASE
) + REALVIEW_SYS_OSC4_OFFSET
;
214 val
= readl(sys_osc
) & ~0x7ffff;
215 val
|= vco
.v
| (vco
.r
<< 9) | (vco
.s
<< 16);
217 writel(0xa05f, sys_lock
);
218 writel(val
, sys_osc
);
222 static struct clk oscvco_clk
= {
223 .params
= &realview_oscvco_params
,
224 .setvco
= realview_oscvco_set
,
228 * These are fixed clocks.
230 static struct clk ref24_clk
= {
234 static struct clk_lookup lookups
[] = {
265 static int __init
clk_init(void)
269 for (i
= 0; i
< ARRAY_SIZE(lookups
); i
++)
270 clkdev_add(&lookups
[i
]);
273 arch_initcall(clk_init
);
278 #define SYS_CLCD_NLCDIOON (1 << 2)
279 #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
280 #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
281 #define SYS_CLCD_ID_MASK (0x1f << 8)
282 #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
283 #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
284 #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
285 #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
286 #define SYS_CLCD_ID_VGA (0x1f << 8)
288 static struct clcd_panel vga
= {
302 .vmode
= FB_VMODE_NONINTERLACED
,
306 .tim2
= TIM2_BCD
| TIM2_IPC
,
307 .cntl
= CNTL_LCDTFT
| CNTL_BGR
| CNTL_LCDVCOMP(1),
311 static struct clcd_panel xvga
= {
325 .vmode
= FB_VMODE_NONINTERLACED
,
329 .tim2
= TIM2_BCD
| TIM2_IPC
,
330 .cntl
= CNTL_LCDTFT
| CNTL_BGR
| CNTL_LCDVCOMP(1),
334 static struct clcd_panel sanyo_3_8_in
= {
336 .name
= "Sanyo QVGA",
348 .vmode
= FB_VMODE_NONINTERLACED
,
353 .cntl
= CNTL_LCDTFT
| CNTL_BGR
| CNTL_LCDVCOMP(1),
357 static struct clcd_panel sanyo_2_5_in
= {
359 .name
= "Sanyo QVGA Portrait",
370 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
371 .vmode
= FB_VMODE_NONINTERLACED
,
375 .tim2
= TIM2_IVS
| TIM2_IHS
| TIM2_IPC
,
376 .cntl
= CNTL_LCDTFT
| CNTL_BGR
| CNTL_LCDVCOMP(1),
380 static struct clcd_panel epson_2_2_in
= {
382 .name
= "Epson QCIF",
394 .vmode
= FB_VMODE_NONINTERLACED
,
398 .tim2
= TIM2_BCD
| TIM2_IPC
,
399 .cntl
= CNTL_LCDTFT
| CNTL_BGR
| CNTL_LCDVCOMP(1),
404 * Detect which LCD panel is connected, and return the appropriate
405 * clcd_panel structure. Note: we do not have any information on
406 * the required timings for the 8.4in panel, so we presently assume
409 static struct clcd_panel
*realview_clcd_panel(void)
411 void __iomem
*sys_clcd
= __io_address(REALVIEW_SYS_BASE
) + REALVIEW_SYS_CLCD_OFFSET
;
412 struct clcd_panel
*vga_panel
;
413 struct clcd_panel
*panel
;
416 if (machine_is_realview_eb())
421 val
= readl(sys_clcd
) & SYS_CLCD_ID_MASK
;
422 if (val
== SYS_CLCD_ID_SANYO_3_8
)
423 panel
= &sanyo_3_8_in
;
424 else if (val
== SYS_CLCD_ID_SANYO_2_5
)
425 panel
= &sanyo_2_5_in
;
426 else if (val
== SYS_CLCD_ID_EPSON_2_2
)
427 panel
= &epson_2_2_in
;
428 else if (val
== SYS_CLCD_ID_VGA
)
431 printk(KERN_ERR
"CLCD: unknown LCD panel ID 0x%08x, using VGA\n",
440 * Disable all display connectors on the interface module.
442 static void realview_clcd_disable(struct clcd_fb
*fb
)
444 void __iomem
*sys_clcd
= __io_address(REALVIEW_SYS_BASE
) + REALVIEW_SYS_CLCD_OFFSET
;
447 val
= readl(sys_clcd
);
448 val
&= ~SYS_CLCD_NLCDIOON
| SYS_CLCD_PWR3V5SWITCH
;
449 writel(val
, sys_clcd
);
453 * Enable the relevant connector on the interface module.
455 static void realview_clcd_enable(struct clcd_fb
*fb
)
457 void __iomem
*sys_clcd
= __io_address(REALVIEW_SYS_BASE
) + REALVIEW_SYS_CLCD_OFFSET
;
463 val
= readl(sys_clcd
);
464 val
|= SYS_CLCD_NLCDIOON
| SYS_CLCD_PWR3V5SWITCH
;
465 writel(val
, sys_clcd
);
468 static int realview_clcd_setup(struct clcd_fb
*fb
)
470 unsigned long framesize
;
473 if (machine_is_realview_eb())
475 framesize
= 640 * 480 * 2;
478 framesize
= 1024 * 768 * 2;
480 fb
->panel
= realview_clcd_panel();
482 fb
->fb
.screen_base
= dma_alloc_writecombine(&fb
->dev
->dev
, framesize
,
484 if (!fb
->fb
.screen_base
) {
485 printk(KERN_ERR
"CLCD: unable to map framebuffer\n");
489 fb
->fb
.fix
.smem_start
= dma
;
490 fb
->fb
.fix
.smem_len
= framesize
;
495 static int realview_clcd_mmap(struct clcd_fb
*fb
, struct vm_area_struct
*vma
)
497 return dma_mmap_writecombine(&fb
->dev
->dev
, vma
,
499 fb
->fb
.fix
.smem_start
,
500 fb
->fb
.fix
.smem_len
);
503 static void realview_clcd_remove(struct clcd_fb
*fb
)
505 dma_free_writecombine(&fb
->dev
->dev
, fb
->fb
.fix
.smem_len
,
506 fb
->fb
.screen_base
, fb
->fb
.fix
.smem_start
);
509 struct clcd_board clcd_plat_data
= {
511 .check
= clcdfb_check
,
512 .decode
= clcdfb_decode
,
513 .disable
= realview_clcd_disable
,
514 .enable
= realview_clcd_enable
,
515 .setup
= realview_clcd_setup
,
516 .mmap
= realview_clcd_mmap
,
517 .remove
= realview_clcd_remove
,
521 #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
523 void realview_leds_event(led_event_t ledevt
)
528 local_irq_save(flags
);
529 val
= readl(VA_LEDS_BASE
);
533 val
= val
& ~REALVIEW_SYS_LED0
;
537 val
= val
| REALVIEW_SYS_LED0
;
541 val
= val
^ REALVIEW_SYS_LED1
;
552 writel(val
, VA_LEDS_BASE
);
553 local_irq_restore(flags
);
555 #endif /* CONFIG_LEDS */
558 * Where is the timer (VA)?
560 void __iomem
*timer0_va_base
;
561 void __iomem
*timer1_va_base
;
562 void __iomem
*timer2_va_base
;
563 void __iomem
*timer3_va_base
;
566 * How long is the timer interval?
568 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
569 #if TIMER_INTERVAL >= 0x100000
570 #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
571 #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
572 #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
573 #elif TIMER_INTERVAL >= 0x10000
574 #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
575 #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
576 #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
578 #define TIMER_RELOAD (TIMER_INTERVAL)
579 #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
580 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
583 static void timer_set_mode(enum clock_event_mode mode
,
584 struct clock_event_device
*clk
)
589 case CLOCK_EVT_MODE_PERIODIC
:
590 writel(TIMER_RELOAD
, timer0_va_base
+ TIMER_LOAD
);
592 ctrl
= TIMER_CTRL_PERIODIC
;
593 ctrl
|= TIMER_CTRL_32BIT
| TIMER_CTRL_IE
| TIMER_CTRL_ENABLE
;
595 case CLOCK_EVT_MODE_ONESHOT
:
596 /* period set, and timer enabled in 'next_event' hook */
597 ctrl
= TIMER_CTRL_ONESHOT
;
598 ctrl
|= TIMER_CTRL_32BIT
| TIMER_CTRL_IE
;
600 case CLOCK_EVT_MODE_UNUSED
:
601 case CLOCK_EVT_MODE_SHUTDOWN
:
606 writel(ctrl
, timer0_va_base
+ TIMER_CTRL
);
609 static int timer_set_next_event(unsigned long evt
,
610 struct clock_event_device
*unused
)
612 unsigned long ctrl
= readl(timer0_va_base
+ TIMER_CTRL
);
614 writel(evt
, timer0_va_base
+ TIMER_LOAD
);
615 writel(ctrl
| TIMER_CTRL_ENABLE
, timer0_va_base
+ TIMER_CTRL
);
620 static struct clock_event_device timer0_clockevent
= {
623 .features
= CLOCK_EVT_FEAT_PERIODIC
| CLOCK_EVT_FEAT_ONESHOT
,
624 .set_mode
= timer_set_mode
,
625 .set_next_event
= timer_set_next_event
,
627 .cpumask
= cpu_all_mask
,
630 static void __init
realview_clockevents_init(unsigned int timer_irq
)
632 timer0_clockevent
.irq
= timer_irq
;
633 timer0_clockevent
.mult
=
634 div_sc(1000000, NSEC_PER_SEC
, timer0_clockevent
.shift
);
635 timer0_clockevent
.max_delta_ns
=
636 clockevent_delta2ns(0xffffffff, &timer0_clockevent
);
637 timer0_clockevent
.min_delta_ns
=
638 clockevent_delta2ns(0xf, &timer0_clockevent
);
640 clockevents_register_device(&timer0_clockevent
);
644 * IRQ handler for the timer
646 static irqreturn_t
realview_timer_interrupt(int irq
, void *dev_id
)
648 struct clock_event_device
*evt
= &timer0_clockevent
;
650 /* clear the interrupt */
651 writel(1, timer0_va_base
+ TIMER_INTCLR
);
653 evt
->event_handler(evt
);
658 static struct irqaction realview_timer_irq
= {
659 .name
= "RealView Timer Tick",
660 .flags
= IRQF_DISABLED
| IRQF_TIMER
| IRQF_IRQPOLL
,
661 .handler
= realview_timer_interrupt
,
664 static cycle_t
realview_get_cycles(void)
666 return ~readl(timer3_va_base
+ TIMER_VALUE
);
669 static struct clocksource clocksource_realview
= {
672 .read
= realview_get_cycles
,
673 .mask
= CLOCKSOURCE_MASK(32),
675 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
678 static void __init
realview_clocksource_init(void)
680 /* setup timer 0 as free-running clocksource */
681 writel(0, timer3_va_base
+ TIMER_CTRL
);
682 writel(0xffffffff, timer3_va_base
+ TIMER_LOAD
);
683 writel(0xffffffff, timer3_va_base
+ TIMER_VALUE
);
684 writel(TIMER_CTRL_32BIT
| TIMER_CTRL_ENABLE
| TIMER_CTRL_PERIODIC
,
685 timer3_va_base
+ TIMER_CTRL
);
687 clocksource_realview
.mult
=
688 clocksource_khz2mult(1000, clocksource_realview
.shift
);
689 clocksource_register(&clocksource_realview
);
693 * Set up the clock source and clock events devices
695 void __init
realview_timer_init(unsigned int timer_irq
)
699 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
701 * The dummy clock device has to be registered before the main device
702 * so that the latter will broadcast the clock events
708 * set clock frequency:
709 * REALVIEW_REFCLK is 32KHz
710 * REALVIEW_TIMCLK is 1MHz
712 val
= readl(__io_address(REALVIEW_SCTL_BASE
));
713 writel((REALVIEW_TIMCLK
<< REALVIEW_TIMER1_EnSel
) |
714 (REALVIEW_TIMCLK
<< REALVIEW_TIMER2_EnSel
) |
715 (REALVIEW_TIMCLK
<< REALVIEW_TIMER3_EnSel
) |
716 (REALVIEW_TIMCLK
<< REALVIEW_TIMER4_EnSel
) | val
,
717 __io_address(REALVIEW_SCTL_BASE
));
720 * Initialise to a known state (all timers off)
722 writel(0, timer0_va_base
+ TIMER_CTRL
);
723 writel(0, timer1_va_base
+ TIMER_CTRL
);
724 writel(0, timer2_va_base
+ TIMER_CTRL
);
725 writel(0, timer3_va_base
+ TIMER_CTRL
);
728 * Make irqs happen for the system timer
730 setup_irq(timer_irq
, &realview_timer_irq
);
732 realview_clocksource_init();
733 realview_clockevents_init(timer_irq
);