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>
24 #include <asm/clkdev.h>
25 #include <mach/clkdev.h>
26 #include <mach/hardware.h>
28 #include <asm/hardware/arm_timer.h>
30 #include <asm/system.h>
32 #include <asm/mach/time.h>
36 static struct amba_pl010_data integrator_uart_data
;
38 static struct amba_device rtc_device
= {
43 .start
= INTEGRATOR_RTC_BASE
,
44 .end
= INTEGRATOR_RTC_BASE
+ SZ_4K
- 1,
45 .flags
= IORESOURCE_MEM
,
47 .irq
= { IRQ_RTCINT
, NO_IRQ
},
48 .periphid
= 0x00041030,
51 static struct amba_device uart0_device
= {
54 .platform_data
= &integrator_uart_data
,
57 .start
= INTEGRATOR_UART0_BASE
,
58 .end
= INTEGRATOR_UART0_BASE
+ SZ_4K
- 1,
59 .flags
= IORESOURCE_MEM
,
61 .irq
= { IRQ_UARTINT0
, NO_IRQ
},
62 .periphid
= 0x0041010,
65 static struct amba_device uart1_device
= {
68 .platform_data
= &integrator_uart_data
,
71 .start
= INTEGRATOR_UART1_BASE
,
72 .end
= INTEGRATOR_UART1_BASE
+ SZ_4K
- 1,
73 .flags
= IORESOURCE_MEM
,
75 .irq
= { IRQ_UARTINT1
, NO_IRQ
},
76 .periphid
= 0x0041010,
79 static struct amba_device kmi0_device
= {
85 .end
= KMI0_BASE
+ SZ_4K
- 1,
86 .flags
= IORESOURCE_MEM
,
88 .irq
= { IRQ_KMIINT0
, NO_IRQ
},
89 .periphid
= 0x00041050,
92 static struct amba_device kmi1_device
= {
98 .end
= KMI1_BASE
+ SZ_4K
- 1,
99 .flags
= IORESOURCE_MEM
,
101 .irq
= { IRQ_KMIINT1
, NO_IRQ
},
102 .periphid
= 0x00041050,
105 static struct amba_device
*amba_devs
[] __initdata
= {
114 * These are fixed clocks.
116 static struct clk clk24mhz
= {
120 static struct clk uartclk
= {
124 static struct clk_lookup lookups
[] = {
137 }, { /* MMCI - IntegratorCP */
143 static int __init
integrator_init(void)
147 clkdev_add_table(lookups
, ARRAY_SIZE(lookups
));
149 for (i
= 0; i
< ARRAY_SIZE(amba_devs
); i
++) {
150 struct amba_device
*d
= amba_devs
[i
];
151 amba_device_register(d
, &iomem_resource
);
157 arch_initcall(integrator_init
);
160 * On the Integrator platform, the port RTS and DTR are provided by
161 * bits in the following SC_CTRLS register bits:
166 #define SC_CTRLC (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
167 #define SC_CTRLS (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
169 static void integrator_uart_set_mctrl(struct amba_device
*dev
, void __iomem
*base
, unsigned int mctrl
)
171 unsigned int ctrls
= 0, ctrlc
= 0, rts_mask
, dtr_mask
;
173 if (dev
== &uart0_device
) {
181 if (mctrl
& TIOCM_RTS
)
186 if (mctrl
& TIOCM_DTR
)
191 __raw_writel(ctrls
, SC_CTRLS
);
192 __raw_writel(ctrlc
, SC_CTRLC
);
195 static struct amba_pl010_data integrator_uart_data
= {
196 .set_mctrl
= integrator_uart_set_mctrl
,
199 #define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_CTRL_OFFSET
201 static DEFINE_SPINLOCK(cm_lock
);
204 * cm_control - update the CM_CTRL register.
205 * @mask: bits to change
208 void cm_control(u32 mask
, u32 set
)
213 spin_lock_irqsave(&cm_lock
, flags
);
214 val
= readl(CM_CTRL
) & ~mask
;
215 writel(val
| set
, CM_CTRL
);
216 spin_unlock_irqrestore(&cm_lock
, flags
);
219 EXPORT_SYMBOL(cm_control
);
222 * Where is the timer (VA)?
224 #define TIMER0_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000000)
225 #define TIMER1_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000100)
226 #define TIMER2_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000200)
227 #define VA_IC_BASE IO_ADDRESS(INTEGRATOR_IC_BASE)
230 * How long is the timer interval?
232 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
233 #if TIMER_INTERVAL >= 0x100000
234 #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
235 #elif TIMER_INTERVAL >= 0x10000
236 #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
238 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
241 static unsigned long timer_reload
;
244 * Returns number of ms since last clock interrupt. Note that interrupts
245 * will have been disabled by do_gettimeoffset()
247 unsigned long integrator_gettimeoffset(void)
249 unsigned long ticks1
, ticks2
, status
;
252 * Get the current number of ticks. Note that there is a race
253 * condition between us reading the timer and checking for
254 * an interrupt. We get around this by ensuring that the
255 * counter has not reloaded between our two reads.
257 ticks2
= readl(TIMER1_VA_BASE
+ TIMER_VALUE
) & 0xffff;
260 status
= __raw_readl(VA_IC_BASE
+ IRQ_RAW_STATUS
);
261 ticks2
= readl(TIMER1_VA_BASE
+ TIMER_VALUE
) & 0xffff;
262 } while (ticks2
> ticks1
);
265 * Number of ticks since last interrupt.
267 ticks1
= timer_reload
- ticks2
;
270 * Interrupt pending? If so, we've reloaded once already.
272 if (status
& (1 << IRQ_TIMERINT1
))
273 ticks1
+= timer_reload
;
276 * Convert the ticks to usecs
278 return TICKS2USECS(ticks1
);
282 * IRQ handler for the timer
285 integrator_timer_interrupt(int irq
, void *dev_id
)
288 * clear the interrupt
290 writel(1, TIMER1_VA_BASE
+ TIMER_INTCLR
);
297 static struct irqaction integrator_timer_irq
= {
298 .name
= "Integrator Timer Tick",
299 .flags
= IRQF_DISABLED
| IRQF_TIMER
| IRQF_IRQPOLL
,
300 .handler
= integrator_timer_interrupt
,
304 * Set up timer interrupt, and return the current time in seconds.
306 void __init
integrator_time_init(unsigned long reload
, unsigned int ctrl
)
308 unsigned int timer_ctrl
= TIMER_CTRL_ENABLE
| TIMER_CTRL_PERIODIC
;
310 timer_reload
= reload
;
313 if (timer_reload
> 0x100000) {
315 timer_ctrl
|= TIMER_CTRL_DIV256
;
316 } else if (timer_reload
> 0x010000) {
318 timer_ctrl
|= TIMER_CTRL_DIV16
;
322 * Initialise to a known state (all timers off)
324 writel(0, TIMER0_VA_BASE
+ TIMER_CTRL
);
325 writel(0, TIMER1_VA_BASE
+ TIMER_CTRL
);
326 writel(0, TIMER2_VA_BASE
+ TIMER_CTRL
);
328 writel(timer_reload
, TIMER1_VA_BASE
+ TIMER_LOAD
);
329 writel(timer_reload
, TIMER1_VA_BASE
+ TIMER_VALUE
);
330 writel(timer_ctrl
, TIMER1_VA_BASE
+ TIMER_CTRL
);
333 * Make irqs happen for the system timer
335 setup_irq(IRQ_TIMERINT1
, &integrator_timer_irq
);