2 * derived from linux/arch/arm/mach-versatile/core.c
3 * linux/arch/arm/mach-bcmring/core.c
5 * Copyright (C) 1999 - 2003 ARM Limited
6 * Copyright (C) 2000 Deep Blue Solutions Ltd
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* Portions copyright Broadcom 2008 */
24 #include <linux/init.h>
25 #include <linux/device.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/platform_device.h>
28 #include <linux/sysdev.h>
29 #include <linux/interrupt.h>
30 #include <linux/amba/bus.h>
31 #include <linux/clocksource.h>
32 #include <linux/clockchips.h>
34 #include <linux/amba/bus.h>
35 #include <mach/csp/mm_addr.h>
36 #include <mach/hardware.h>
37 #include <asm/clkdev.h>
40 #include <asm/hardware/arm_timer.h>
41 #include <asm/mach-types.h>
43 #include <asm/mach/arch.h>
44 #include <asm/mach/flash.h>
45 #include <asm/mach/irq.h>
46 #include <asm/mach/time.h>
47 #include <asm/mach/map.h>
48 #include <asm/mach/mmc.h>
50 #include <cfg_global.h>
54 #include <csp/secHw.h>
55 #include <mach/csp/secHw_def.h>
56 #include <mach/csp/chipcHw_inline.h>
57 #include <mach/csp/tmrHw_reg.h>
59 #define AMBA_DEVICE(name, initname, base, plat, size) \
60 static struct amba_device name##_device = { \
62 .coherent_dma_mask = ~0, \
63 .init_name = initname, \
64 .platform_data = plat \
67 .start = MM_ADDR_IO_##base, \
68 .end = MM_ADDR_IO_##base + (size) - 1, \
69 .flags = IORESOURCE_MEM \
78 AMBA_DEVICE(uartA
, "uarta", UARTA
, NULL
, SZ_4K
);
79 AMBA_DEVICE(uartB
, "uartb", UARTB
, NULL
, SZ_4K
);
81 static struct clk pll1_clk
= {
83 .type
= CLK_TYPE_PRIMARY
| CLK_TYPE_PLL1
,
84 .rate_hz
= 2000000000,
88 static struct clk uart_clk
= {
90 .type
= CLK_TYPE_PROGRAMMABLE
,
91 .csp_id
= chipcHw_CLOCK_UART
,
92 .rate_hz
= HW_CFG_UART_CLK_HZ
,
96 static struct clk_lookup lookups
[] = {
106 static struct amba_device
*amba_devs
[] __initdata
= {
111 void __init
bcmring_amba_init(void)
116 /* Linux is run initially in non-secure mode. Secure peripherals */
117 /* generate FIQ, and must be handled in secure mode. Until we have */
118 /* a linux security monitor implementation, keep everything in */
119 /* non-secure mode. */
120 chipcHw_busInterfaceClockEnable(chipcHw_REG_BUS_CLOCK_SPU
);
121 secHw_setUnsecure(secHw_BLK_MASK_CHIP_CONTROL
|
122 secHw_BLK_MASK_KEY_SCAN
|
123 secHw_BLK_MASK_TOUCH_SCREEN
|
124 secHw_BLK_MASK_UART0
|
125 secHw_BLK_MASK_UART1
|
126 secHw_BLK_MASK_WATCHDOG
|
127 secHw_BLK_MASK_SPUM
|
128 secHw_BLK_MASK_DDR2
|
134 secHw_BLK_MASK_BOOT
|
136 secHw_BLK_MASK_TZCTRL
| secHw_BLK_MASK_INTR
);
138 /* Only the devices attached to the AMBA bus are enabled just before the bus is */
139 /* scanned and the drivers are loaded. The clocks need to be on for the AMBA bus */
140 /* driver to access these blocks. The bus is probed, and the drivers are loaded. */
141 /* FIXME Need to remove enable of PIF once CLCD clock enable used properly in FPGA. */
142 bus_clock
= chipcHw_REG_BUS_CLOCK_GE
143 | chipcHw_REG_BUS_CLOCK_SDIO0
| chipcHw_REG_BUS_CLOCK_SDIO1
;
145 chipcHw_busInterfaceClockEnable(bus_clock
);
147 for (i
= 0; i
< ARRAY_SIZE(lookups
); i
++)
148 clkdev_add(&lookups
[i
]);
150 for (i
= 0; i
< ARRAY_SIZE(amba_devs
); i
++) {
151 struct amba_device
*d
= amba_devs
[i
];
152 amba_device_register(d
, &iomem_resource
);
157 * Where is the timer (VA)?
159 #define TIMER0_VA_BASE MM_IO_BASE_TMR
160 #define TIMER1_VA_BASE (MM_IO_BASE_TMR + 0x20)
161 #define TIMER2_VA_BASE (MM_IO_BASE_TMR + 0x40)
162 #define TIMER3_VA_BASE (MM_IO_BASE_TMR + 0x60)
164 /* Timer 0 - 25 MHz, Timer3 at bus clock rate, typically 150-166 MHz */
165 #if defined(CONFIG_ARCH_FPGA11107)
166 /* fpga cpu/bus are currently 30 times slower so scale frequency as well to */
167 /* slow down Linux's sense of time */
168 #define TIMER0_FREQUENCY_MHZ (tmrHw_LOW_FREQUENCY_MHZ * 30)
169 #define TIMER1_FREQUENCY_MHZ (tmrHw_LOW_FREQUENCY_MHZ * 30)
170 #define TIMER3_FREQUENCY_MHZ (tmrHw_HIGH_FREQUENCY_MHZ * 30)
171 #define TIMER3_FREQUENCY_KHZ (tmrHw_HIGH_FREQUENCY_HZ / 1000 * 30)
173 #define TIMER0_FREQUENCY_MHZ tmrHw_LOW_FREQUENCY_MHZ
174 #define TIMER1_FREQUENCY_MHZ tmrHw_LOW_FREQUENCY_MHZ
175 #define TIMER3_FREQUENCY_MHZ tmrHw_HIGH_FREQUENCY_MHZ
176 #define TIMER3_FREQUENCY_KHZ (tmrHw_HIGH_FREQUENCY_HZ / 1000)
179 #define TICKS_PER_uSEC TIMER0_FREQUENCY_MHZ
182 * These are useconds NOT ticks.
186 #define mSEC_5 (mSEC_1 * 5)
187 #define mSEC_10 (mSEC_1 * 10)
188 #define mSEC_25 (mSEC_1 * 25)
189 #define SEC_1 (mSEC_1 * 1000)
192 * How long is the timer interval?
194 #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
195 #if TIMER_INTERVAL >= 0x100000
196 #define TIMER_RELOAD (TIMER_INTERVAL >> 8)
197 #define TIMER_DIVISOR (TIMER_CTRL_DIV256)
198 #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
199 #elif TIMER_INTERVAL >= 0x10000
200 #define TIMER_RELOAD (TIMER_INTERVAL >> 4) /* Divide by 16 */
201 #define TIMER_DIVISOR (TIMER_CTRL_DIV16)
202 #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
204 #define TIMER_RELOAD (TIMER_INTERVAL)
205 #define TIMER_DIVISOR (TIMER_CTRL_DIV1)
206 #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
209 static void timer_set_mode(enum clock_event_mode mode
,
210 struct clock_event_device
*clk
)
215 case CLOCK_EVT_MODE_PERIODIC
:
216 writel(TIMER_RELOAD
, TIMER0_VA_BASE
+ TIMER_LOAD
);
218 ctrl
= TIMER_CTRL_PERIODIC
;
220 TIMER_DIVISOR
| TIMER_CTRL_32BIT
| TIMER_CTRL_IE
|
223 case CLOCK_EVT_MODE_ONESHOT
:
224 /* period set, and timer enabled in 'next_event' hook */
225 ctrl
= TIMER_CTRL_ONESHOT
;
226 ctrl
|= TIMER_DIVISOR
| TIMER_CTRL_32BIT
| TIMER_CTRL_IE
;
228 case CLOCK_EVT_MODE_UNUSED
:
229 case CLOCK_EVT_MODE_SHUTDOWN
:
234 writel(ctrl
, TIMER0_VA_BASE
+ TIMER_CTRL
);
237 static int timer_set_next_event(unsigned long evt
,
238 struct clock_event_device
*unused
)
240 unsigned long ctrl
= readl(TIMER0_VA_BASE
+ TIMER_CTRL
);
242 writel(evt
, TIMER0_VA_BASE
+ TIMER_LOAD
);
243 writel(ctrl
| TIMER_CTRL_ENABLE
, TIMER0_VA_BASE
+ TIMER_CTRL
);
248 static struct clock_event_device timer0_clockevent
= {
251 .features
= CLOCK_EVT_FEAT_PERIODIC
| CLOCK_EVT_FEAT_ONESHOT
,
252 .set_mode
= timer_set_mode
,
253 .set_next_event
= timer_set_next_event
,
257 * IRQ handler for the timer
259 static irqreturn_t
bcmring_timer_interrupt(int irq
, void *dev_id
)
261 struct clock_event_device
*evt
= &timer0_clockevent
;
263 writel(1, TIMER0_VA_BASE
+ TIMER_INTCLR
);
265 evt
->event_handler(evt
);
270 static struct irqaction bcmring_timer_irq
= {
271 .name
= "bcmring Timer Tick",
272 .flags
= IRQF_DISABLED
| IRQF_TIMER
| IRQF_IRQPOLL
,
273 .handler
= bcmring_timer_interrupt
,
276 static cycle_t
bcmring_get_cycles_timer1(void)
278 return ~readl(TIMER1_VA_BASE
+ TIMER_VALUE
);
281 static cycle_t
bcmring_get_cycles_timer3(void)
283 return ~readl(TIMER3_VA_BASE
+ TIMER_VALUE
);
286 static struct clocksource clocksource_bcmring_timer1
= {
289 .read
= bcmring_get_cycles_timer1
,
290 .mask
= CLOCKSOURCE_MASK(32),
292 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
295 static struct clocksource clocksource_bcmring_timer3
= {
298 .read
= bcmring_get_cycles_timer3
,
299 .mask
= CLOCKSOURCE_MASK(32),
301 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
304 static int __init
bcmring_clocksource_init(void)
306 /* setup timer1 as free-running clocksource */
307 writel(0, TIMER1_VA_BASE
+ TIMER_CTRL
);
308 writel(0xffffffff, TIMER1_VA_BASE
+ TIMER_LOAD
);
309 writel(0xffffffff, TIMER1_VA_BASE
+ TIMER_VALUE
);
310 writel(TIMER_CTRL_32BIT
| TIMER_CTRL_ENABLE
| TIMER_CTRL_PERIODIC
,
311 TIMER1_VA_BASE
+ TIMER_CTRL
);
313 clocksource_bcmring_timer1
.mult
=
314 clocksource_khz2mult(TIMER1_FREQUENCY_MHZ
* 1000,
315 clocksource_bcmring_timer1
.shift
);
316 clocksource_register(&clocksource_bcmring_timer1
);
318 /* setup timer3 as free-running clocksource */
319 writel(0, TIMER3_VA_BASE
+ TIMER_CTRL
);
320 writel(0xffffffff, TIMER3_VA_BASE
+ TIMER_LOAD
);
321 writel(0xffffffff, TIMER3_VA_BASE
+ TIMER_VALUE
);
322 writel(TIMER_CTRL_32BIT
| TIMER_CTRL_ENABLE
| TIMER_CTRL_PERIODIC
,
323 TIMER3_VA_BASE
+ TIMER_CTRL
);
325 clocksource_bcmring_timer3
.mult
=
326 clocksource_khz2mult(TIMER3_FREQUENCY_KHZ
,
327 clocksource_bcmring_timer3
.shift
);
328 clocksource_register(&clocksource_bcmring_timer3
);
334 * Set up timer interrupt, and return the current time in seconds.
336 void __init
bcmring_init_timer(void)
338 printk(KERN_INFO
"bcmring_init_timer\n");
340 * Initialise to a known state (all timers off)
342 writel(0, TIMER0_VA_BASE
+ TIMER_CTRL
);
343 writel(0, TIMER1_VA_BASE
+ TIMER_CTRL
);
344 writel(0, TIMER2_VA_BASE
+ TIMER_CTRL
);
345 writel(0, TIMER3_VA_BASE
+ TIMER_CTRL
);
348 * Make irqs happen for the system timer
350 setup_irq(IRQ_TIMER0
, &bcmring_timer_irq
);
352 bcmring_clocksource_init();
354 timer0_clockevent
.mult
=
355 div_sc(1000000, NSEC_PER_SEC
, timer0_clockevent
.shift
);
356 timer0_clockevent
.max_delta_ns
=
357 clockevent_delta2ns(0xffffffff, &timer0_clockevent
);
358 timer0_clockevent
.min_delta_ns
=
359 clockevent_delta2ns(0xf, &timer0_clockevent
);
361 timer0_clockevent
.cpumask
= cpumask_of(0);
362 clockevents_register_device(&timer0_clockevent
);
365 struct sys_timer bcmring_timer
= {
366 .init
= bcmring_init_timer
,