2 * linux/arch/arm/mach-integrator/core.c
4 * Copyright (C) 2000-2003 Deep Blue Solutions Ltd
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/device.h>
14 #include <linux/spinlock.h>
15 #include <linux/interrupt.h>
16 #include <linux/irq.h>
17 #include <linux/sched.h>
18 #include <linux/smp.h>
19 #include <linux/termios.h>
20 #include <linux/amba/bus.h>
21 #include <linux/amba/serial.h>
22 #include <linux/clocksource.h>
25 #include <asm/clkdev.h>
26 #include <mach/clkdev.h>
27 #include <mach/hardware.h>
28 #include <mach/platform.h>
30 #include <asm/hardware/arm_timer.h>
32 #include <asm/system.h>
34 #include <asm/mach/time.h>
38 static struct amba_pl010_data integrator_uart_data;
40 static struct amba_device rtc_device = {
45 .start = INTEGRATOR_RTC_BASE,
46 .end = INTEGRATOR_RTC_BASE + SZ_4K - 1,
47 .flags = IORESOURCE_MEM,
49 .irq = { IRQ_RTCINT, NO_IRQ },
50 .periphid = 0x00041030,
53 static struct amba_device uart0_device = {
56 .platform_data = &integrator_uart_data,
59 .start = INTEGRATOR_UART0_BASE,
60 .end = INTEGRATOR_UART0_BASE + SZ_4K - 1,
61 .flags = IORESOURCE_MEM,
63 .irq = { IRQ_UARTINT0, NO_IRQ },
64 .periphid = 0x0041010,
67 static struct amba_device uart1_device = {
70 .platform_data = &integrator_uart_data,
73 .start = INTEGRATOR_UART1_BASE,
74 .end = INTEGRATOR_UART1_BASE + SZ_4K - 1,
75 .flags = IORESOURCE_MEM,
77 .irq = { IRQ_UARTINT1, NO_IRQ },
78 .periphid = 0x0041010,
81 static struct amba_device kmi0_device = {
87 .end = KMI0_BASE + SZ_4K - 1,
88 .flags = IORESOURCE_MEM,
90 .irq = { IRQ_KMIINT0, NO_IRQ },
91 .periphid = 0x00041050,
94 static struct amba_device kmi1_device = {
100 .end = KMI1_BASE + SZ_4K - 1,
101 .flags = IORESOURCE_MEM,
103 .irq = { IRQ_KMIINT1, NO_IRQ },
104 .periphid = 0x00041050,
107 static struct amba_device *amba_devs[] __initdata = {
116 * These are fixed clocks.
118 static struct clk clk24mhz = {
122 static struct clk uartclk = {
126 static struct clk_lookup lookups[] = {
139 }, { /* MMCI - IntegratorCP */
145 static int __init integrator_init(void)
149 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
151 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
152 struct amba_device *d = amba_devs[i];
153 amba_device_register(d, &iomem_resource);
159 arch_initcall(integrator_init);
162 * On the Integrator platform, the port RTS and DTR are provided by
163 * bits in the following SC_CTRLS register bits:
168 #define SC_CTRLC (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
169 #define SC_CTRLS (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
171 static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
173 unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
175 if (dev == &uart0_device) {
183 if (mctrl & TIOCM_RTS)
188 if (mctrl & TIOCM_DTR)
193 __raw_writel(ctrls, SC_CTRLS);
194 __raw_writel(ctrlc, SC_CTRLC);
197 static struct amba_pl010_data integrator_uart_data = {
198 .set_mctrl = integrator_uart_set_mctrl,
201 #define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_CTRL_OFFSET
203 static DEFINE_SPINLOCK(cm_lock);
206 * cm_control - update the CM_CTRL register.
207 * @mask: bits to change
210 void cm_control(u32 mask, u32 set)
215 spin_lock_irqsave(&cm_lock, flags);
216 val = readl(CM_CTRL) & ~mask;
217 writel(val | set, CM_CTRL);
218 spin_unlock_irqrestore(&cm_lock, flags);
221 EXPORT_SYMBOL(cm_control);
224 * Where is the timer (VA)?
226 #define TIMER0_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000000)
227 #define TIMER1_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000100)
228 #define TIMER2_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000200)
231 * How long is the timer interval?
233 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
234 #if TIMER_INTERVAL >= 0x100000
235 #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
236 #elif TIMER_INTERVAL >= 0x10000
237 #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
239 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
242 static unsigned long timer_reload;
244 static void __iomem * const clksrc_base = (void __iomem *)TIMER2_VA_BASE;
246 static cycle_t timersp_read(struct clocksource *cs)
248 return ~(readl(clksrc_base + TIMER_VALUE) & 0xffff);
251 static struct clocksource clocksource_timersp = {
254 .read = timersp_read,
255 .mask = CLOCKSOURCE_MASK(16),
257 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
260 static void integrator_clocksource_init(u32 khz)
262 struct clocksource *cs = &clocksource_timersp;
263 void __iomem *base = clksrc_base;
264 u32 ctrl = TIMER_CTRL_ENABLE;
268 ctrl = TIMER_CTRL_DIV16;
271 writel(ctrl, base + TIMER_CTRL);
272 writel(0xffff, base + TIMER_LOAD);
274 cs->mult = clocksource_khz2mult(khz, cs->shift);
275 clocksource_register(cs);
279 * IRQ handler for the timer
282 integrator_timer_interrupt(int irq, void *dev_id)
285 * clear the interrupt
287 writel(1, TIMER1_VA_BASE + TIMER_INTCLR);
294 static struct irqaction integrator_timer_irq = {
295 .name = "Integrator Timer Tick",
296 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
297 .handler = integrator_timer_interrupt,
301 * Set up timer interrupt, and return the current time in seconds.
303 void __init integrator_time_init(unsigned long reload, unsigned int ctrl)
305 unsigned int timer_ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
307 integrator_clocksource_init(reload * HZ / 1000);
309 timer_reload = reload;
312 if (timer_reload > 0x100000) {
314 timer_ctrl |= TIMER_CTRL_DIV256;
315 } else if (timer_reload > 0x010000) {
317 timer_ctrl |= TIMER_CTRL_DIV16;
321 * Initialise to a known state (all timers off)
323 writel(0, TIMER0_VA_BASE + TIMER_CTRL);
324 writel(0, TIMER1_VA_BASE + TIMER_CTRL);
325 writel(0, TIMER2_VA_BASE + TIMER_CTRL);
327 writel(timer_reload, TIMER1_VA_BASE + TIMER_LOAD);
328 writel(timer_reload, TIMER1_VA_BASE + TIMER_VALUE);
329 writel(timer_ctrl, TIMER1_VA_BASE + TIMER_CTRL);
332 * Make irqs happen for the system timer
334 setup_irq(IRQ_TIMERINT1, &integrator_timer_irq);