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/sched.h>
17 #include <linux/smp.h>
18 #include <linux/amba/bus.h>
20 #include <asm/hardware.h>
23 #include <asm/hardware/arm_timer.h>
24 #include <asm/arch/cm.h>
25 #include <asm/system.h>
27 #include <asm/mach/time.h>
31 static struct amba_device rtc_device = {
36 .start = INTEGRATOR_RTC_BASE,
37 .end = INTEGRATOR_RTC_BASE + SZ_4K - 1,
38 .flags = IORESOURCE_MEM,
40 .irq = { IRQ_RTCINT, NO_IRQ },
41 .periphid = 0x00041030,
44 static struct amba_device uart0_device = {
49 .start = INTEGRATOR_UART0_BASE,
50 .end = INTEGRATOR_UART0_BASE + SZ_4K - 1,
51 .flags = IORESOURCE_MEM,
53 .irq = { IRQ_UARTINT0, NO_IRQ },
54 .periphid = 0x0041010,
57 static struct amba_device uart1_device = {
62 .start = INTEGRATOR_UART1_BASE,
63 .end = INTEGRATOR_UART1_BASE + SZ_4K - 1,
64 .flags = IORESOURCE_MEM,
66 .irq = { IRQ_UARTINT1, NO_IRQ },
67 .periphid = 0x0041010,
70 static struct amba_device kmi0_device = {
76 .end = KMI0_BASE + SZ_4K - 1,
77 .flags = IORESOURCE_MEM,
79 .irq = { IRQ_KMIINT0, NO_IRQ },
80 .periphid = 0x00041050,
83 static struct amba_device kmi1_device = {
89 .end = KMI1_BASE + SZ_4K - 1,
90 .flags = IORESOURCE_MEM,
92 .irq = { IRQ_KMIINT1, NO_IRQ },
93 .periphid = 0x00041050,
96 static struct amba_device *amba_devs[] __initdata = {
104 static int __init integrator_init(void)
108 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
109 struct amba_device *d = amba_devs[i];
110 amba_device_register(d, &iomem_resource);
116 arch_initcall(integrator_init);
118 #define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_CTRL_OFFSET
120 static DEFINE_SPINLOCK(cm_lock);
123 * cm_control - update the CM_CTRL register.
124 * @mask: bits to change
127 void cm_control(u32 mask, u32 set)
132 spin_lock_irqsave(&cm_lock, flags);
133 val = readl(CM_CTRL) & ~mask;
134 writel(val | set, CM_CTRL);
135 spin_unlock_irqrestore(&cm_lock, flags);
138 EXPORT_SYMBOL(cm_control);
141 * Where is the timer (VA)?
143 #define TIMER0_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000000)
144 #define TIMER1_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000100)
145 #define TIMER2_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000200)
146 #define VA_IC_BASE IO_ADDRESS(INTEGRATOR_IC_BASE)
149 * How long is the timer interval?
151 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
152 #if TIMER_INTERVAL >= 0x100000
153 #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
154 #elif TIMER_INTERVAL >= 0x10000
155 #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
157 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
160 static unsigned long timer_reload;
163 * Returns number of ms since last clock interrupt. Note that interrupts
164 * will have been disabled by do_gettimeoffset()
166 unsigned long integrator_gettimeoffset(void)
168 unsigned long ticks1, ticks2, status;
171 * Get the current number of ticks. Note that there is a race
172 * condition between us reading the timer and checking for
173 * an interrupt. We get around this by ensuring that the
174 * counter has not reloaded between our two reads.
176 ticks2 = readl(TIMER1_VA_BASE + TIMER_VALUE) & 0xffff;
179 status = __raw_readl(VA_IC_BASE + IRQ_RAW_STATUS);
180 ticks2 = readl(TIMER1_VA_BASE + TIMER_VALUE) & 0xffff;
181 } while (ticks2 > ticks1);
184 * Number of ticks since last interrupt.
186 ticks1 = timer_reload - ticks2;
189 * Interrupt pending? If so, we've reloaded once already.
191 if (status & (1 << IRQ_TIMERINT1))
192 ticks1 += timer_reload;
195 * Convert the ticks to usecs
197 return TICKS2USECS(ticks1);
201 * IRQ handler for the timer
204 integrator_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
206 write_seqlock(&xtime_lock);
209 * clear the interrupt
211 writel(1, TIMER1_VA_BASE + TIMER_INTCLR);
214 * the clock tick routines are only processed on the
217 if (hard_smp_processor_id() == 0) {
226 * this is the ARM equivalent of the APIC timer interrupt
228 update_process_times(user_mode(regs));
229 #endif /* CONFIG_SMP */
231 write_sequnlock(&xtime_lock);
236 static struct irqaction integrator_timer_irq = {
237 .name = "Integrator Timer Tick",
238 .flags = SA_INTERRUPT | SA_TIMER,
239 .handler = integrator_timer_interrupt,
243 * Set up timer interrupt, and return the current time in seconds.
245 void __init integrator_time_init(unsigned long reload, unsigned int ctrl)
247 unsigned int timer_ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
249 timer_reload = reload;
252 if (timer_reload > 0x100000) {
254 timer_ctrl |= TIMER_CTRL_DIV256;
255 } else if (timer_reload > 0x010000) {
257 timer_ctrl |= TIMER_CTRL_DIV16;
261 * Initialise to a known state (all timers off)
263 writel(0, TIMER0_VA_BASE + TIMER_CTRL);
264 writel(0, TIMER1_VA_BASE + TIMER_CTRL);
265 writel(0, TIMER2_VA_BASE + TIMER_CTRL);
267 writel(timer_reload, TIMER1_VA_BASE + TIMER_LOAD);
268 writel(timer_reload, TIMER1_VA_BASE + TIMER_VALUE);
269 writel(timer_ctrl, TIMER1_VA_BASE + TIMER_CTRL);
272 * Make irqs happen for the system timer
274 setup_irq(IRQ_TIMERINT1, &integrator_timer_irq);