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>
23 #include <linux/clockchips.h>
26 #include <asm/clkdev.h>
27 #include <mach/clkdev.h>
28 #include <mach/hardware.h>
29 #include <mach/platform.h>
31 #include <asm/hardware/arm_timer.h>
33 #include <asm/system.h>
35 #include <asm/mach/time.h>
39 static struct amba_pl010_data integrator_uart_data;
41 static struct amba_device rtc_device = {
46 .start = INTEGRATOR_RTC_BASE,
47 .end = INTEGRATOR_RTC_BASE + SZ_4K - 1,
48 .flags = IORESOURCE_MEM,
50 .irq = { IRQ_RTCINT, NO_IRQ },
51 .periphid = 0x00041030,
54 static struct amba_device uart0_device = {
57 .platform_data = &integrator_uart_data,
60 .start = INTEGRATOR_UART0_BASE,
61 .end = INTEGRATOR_UART0_BASE + SZ_4K - 1,
62 .flags = IORESOURCE_MEM,
64 .irq = { IRQ_UARTINT0, NO_IRQ },
65 .periphid = 0x0041010,
68 static struct amba_device uart1_device = {
71 .platform_data = &integrator_uart_data,
74 .start = INTEGRATOR_UART1_BASE,
75 .end = INTEGRATOR_UART1_BASE + SZ_4K - 1,
76 .flags = IORESOURCE_MEM,
78 .irq = { IRQ_UARTINT1, NO_IRQ },
79 .periphid = 0x0041010,
82 static struct amba_device kmi0_device = {
88 .end = KMI0_BASE + SZ_4K - 1,
89 .flags = IORESOURCE_MEM,
91 .irq = { IRQ_KMIINT0, NO_IRQ },
92 .periphid = 0x00041050,
95 static struct amba_device kmi1_device = {
101 .end = KMI1_BASE + SZ_4K - 1,
102 .flags = IORESOURCE_MEM,
104 .irq = { IRQ_KMIINT1, NO_IRQ },
105 .periphid = 0x00041050,
108 static struct amba_device *amba_devs[] __initdata = {
117 * These are fixed clocks.
119 static struct clk clk24mhz = {
123 static struct clk uartclk = {
127 static struct clk_lookup lookups[] = {
140 }, { /* MMCI - IntegratorCP */
146 static int __init integrator_init(void)
150 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
152 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
153 struct amba_device *d = amba_devs[i];
154 amba_device_register(d, &iomem_resource);
160 arch_initcall(integrator_init);
163 * On the Integrator platform, the port RTS and DTR are provided by
164 * bits in the following SC_CTRLS register bits:
169 #define SC_CTRLC (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
170 #define SC_CTRLS (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
172 static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
174 unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
176 if (dev == &uart0_device) {
184 if (mctrl & TIOCM_RTS)
189 if (mctrl & TIOCM_DTR)
194 __raw_writel(ctrls, SC_CTRLS);
195 __raw_writel(ctrlc, SC_CTRLC);
198 static struct amba_pl010_data integrator_uart_data = {
199 .set_mctrl = integrator_uart_set_mctrl,
202 #define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_CTRL_OFFSET
204 static DEFINE_SPINLOCK(cm_lock);
207 * cm_control - update the CM_CTRL register.
208 * @mask: bits to change
211 void cm_control(u32 mask, u32 set)
216 spin_lock_irqsave(&cm_lock, flags);
217 val = readl(CM_CTRL) & ~mask;
218 writel(val | set, CM_CTRL);
219 spin_unlock_irqrestore(&cm_lock, flags);
222 EXPORT_SYMBOL(cm_control);
225 * Where is the timer (VA)?
227 #define TIMER0_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000000)
228 #define TIMER1_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000100)
229 #define TIMER2_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000200)
232 * How long is the timer interval?
234 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
235 #if TIMER_INTERVAL >= 0x100000
236 #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
237 #elif TIMER_INTERVAL >= 0x10000
238 #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
240 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
243 static unsigned long timer_reload;
245 static void __iomem * const clksrc_base = (void __iomem *)TIMER2_VA_BASE;
247 static cycle_t timersp_read(struct clocksource *cs)
249 return ~(readl(clksrc_base + TIMER_VALUE) & 0xffff);
252 static struct clocksource clocksource_timersp = {
255 .read = timersp_read,
256 .mask = CLOCKSOURCE_MASK(16),
258 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
261 static void integrator_clocksource_init(u32 khz)
263 struct clocksource *cs = &clocksource_timersp;
264 void __iomem *base = clksrc_base;
265 u32 ctrl = TIMER_CTRL_ENABLE;
269 ctrl = TIMER_CTRL_DIV16;
272 writel(ctrl, base + TIMER_CTRL);
273 writel(0xffff, base + TIMER_LOAD);
275 cs->mult = clocksource_khz2mult(khz, cs->shift);
276 clocksource_register(cs);
279 static void __iomem * const clkevt_base = (void __iomem *)TIMER1_VA_BASE;
282 * IRQ handler for the timer
284 static irqreturn_t integrator_timer_interrupt(int irq, void *dev_id)
286 struct clock_event_device *evt = dev_id;
288 /* clear the interrupt */
289 writel(1, clkevt_base + TIMER_INTCLR);
291 evt->event_handler(evt);
296 static void clkevt_set_mode(enum clock_event_mode mode, struct clock_event_device *evt)
298 u32 ctrl = readl(clkevt_base + TIMER_CTRL) & ~TIMER_CTRL_ENABLE;
300 BUG_ON(mode == CLOCK_EVT_MODE_ONESHOT);
302 if (mode == CLOCK_EVT_MODE_PERIODIC) {
303 writel(ctrl, clkevt_base + TIMER_CTRL);
304 writel(timer_reload, clkevt_base + TIMER_LOAD);
305 ctrl |= TIMER_CTRL_PERIODIC | TIMER_CTRL_ENABLE;
308 writel(ctrl, clkevt_base + TIMER_CTRL);
311 static int clkevt_set_next_event(unsigned long next, struct clock_event_device *evt)
313 unsigned long ctrl = readl(clkevt_base + TIMER_CTRL);
315 writel(ctrl & ~TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL);
316 writel(next, clkevt_base + TIMER_LOAD);
317 writel(ctrl | TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL);
322 static struct clock_event_device integrator_clockevent = {
325 .features = CLOCK_EVT_FEAT_PERIODIC,
326 .set_mode = clkevt_set_mode,
327 .set_next_event = clkevt_set_next_event,
329 .cpumask = cpu_all_mask,
332 static struct irqaction integrator_timer_irq = {
334 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
335 .handler = integrator_timer_interrupt,
336 .dev_id = &integrator_clockevent,
339 static void integrator_clockevent_init(u32 khz, unsigned int ctrl)
341 struct clock_event_device *evt = &integrator_clockevent;
343 if (khz * 1000 > 0x100000 * HZ) {
345 ctrl |= TIMER_CTRL_DIV256;
346 } else if (khz * 1000 > 0x10000 * HZ) {
348 ctrl |= TIMER_CTRL_DIV16;
351 timer_reload = khz * 1000 / HZ;
352 writel(ctrl, clkevt_base + TIMER_CTRL);
354 evt->irq = IRQ_TIMERINT1;
355 evt->mult = div_sc(khz, NSEC_PER_MSEC, evt->shift);
356 evt->max_delta_ns = clockevent_delta2ns(0xffff, evt);
357 evt->min_delta_ns = clockevent_delta2ns(0xf, evt);
359 setup_irq(IRQ_TIMERINT1, &integrator_timer_irq);
360 clockevents_register_device(evt);
366 void __init integrator_time_init(u32 khz, unsigned int ctrl)
368 writel(0, TIMER0_VA_BASE + TIMER_CTRL);
369 writel(0, TIMER1_VA_BASE + TIMER_CTRL);
370 writel(0, TIMER2_VA_BASE + TIMER_CTRL);
372 integrator_clocksource_init(khz);
373 integrator_clockevent_init(khz, ctrl);