blob: 6b67b7e8426ce8d313b84b910237b9848f5b7c23 [file] [log] [blame]
Leo Chen278a6752009-08-07 19:58:26 +01001/*
2 * derived from linux/arch/arm/mach-versatile/core.c
3 * linux/arch/arm/mach-bcmring/core.c
4 *
5 * Copyright (C) 1999 - 2003 ARM Limited
6 * Copyright (C) 2000 Deep Blue Solutions Ltd
7 *
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.
12 *
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.
17 *
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
21 */
22/* Portions copyright Broadcom 2008 */
23
24#include <linux/init.h>
25#include <linux/device.h>
26#include <linux/dma-mapping.h>
27#include <linux/platform_device.h>
Leo Chen278a6752009-08-07 19:58:26 +010028#include <linux/interrupt.h>
29#include <linux/amba/bus.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010030#include <linux/clkdev.h>
Leo Chen278a6752009-08-07 19:58:26 +010031
Leo Chen278a6752009-08-07 19:58:26 +010032#include <mach/csp/mm_addr.h>
33#include <mach/hardware.h>
Leo Chen278a6752009-08-07 19:58:26 +010034#include <linux/io.h>
35#include <asm/irq.h>
36#include <asm/hardware/arm_timer.h>
Russell King82d63732011-05-12 13:43:39 +010037#include <asm/hardware/timer-sp.h>
Leo Chen278a6752009-08-07 19:58:26 +010038#include <asm/mach-types.h>
39
40#include <asm/mach/arch.h>
41#include <asm/mach/flash.h>
42#include <asm/mach/irq.h>
43#include <asm/mach/time.h>
44#include <asm/mach/map.h>
Leo Chen278a6752009-08-07 19:58:26 +010045
46#include <cfg_global.h>
47
48#include "clock.h"
49
50#include <csp/secHw.h>
51#include <mach/csp/secHw_def.h>
52#include <mach/csp/chipcHw_inline.h>
53#include <mach/csp/tmrHw_reg.h>
54
55#define AMBA_DEVICE(name, initname, base, plat, size) \
56static struct amba_device name##_device = { \
57 .dev = { \
58 .coherent_dma_mask = ~0, \
59 .init_name = initname, \
60 .platform_data = plat \
61 }, \
62 .res = { \
63 .start = MM_ADDR_IO_##base, \
64 .end = MM_ADDR_IO_##base + (size) - 1, \
65 .flags = IORESOURCE_MEM \
66 }, \
67 .dma_mask = ~0, \
68 .irq = { \
69 IRQ_##base \
70 } \
71}
72
73
74AMBA_DEVICE(uartA, "uarta", UARTA, NULL, SZ_4K);
75AMBA_DEVICE(uartB, "uartb", UARTB, NULL, SZ_4K);
76
77static struct clk pll1_clk = {
78 .name = "PLL1",
79 .type = CLK_TYPE_PRIMARY | CLK_TYPE_PLL1,
80 .rate_hz = 2000000000,
81 .use_cnt = 7,
82};
83
84static struct clk uart_clk = {
85 .name = "UART",
86 .type = CLK_TYPE_PROGRAMMABLE,
87 .csp_id = chipcHw_CLOCK_UART,
88 .rate_hz = HW_CFG_UART_CLK_HZ,
89 .parent = &pll1_clk,
90};
91
Russell King3126c7b2010-07-15 11:01:17 +010092static struct clk dummy_apb_pclk = {
93 .name = "BUSCLK",
94 .type = CLK_TYPE_PRIMARY,
95 .mode = CLK_MODE_XTAL,
96};
97
Russell King82d63732011-05-12 13:43:39 +010098/* Timer 0 - 25 MHz, Timer3 at bus clock rate, typically 150-166 MHz */
99#if defined(CONFIG_ARCH_FPGA11107)
100/* fpga cpu/bus are currently 30 times slower so scale frequency as well to */
101/* slow down Linux's sense of time */
102#define TIMER0_FREQUENCY_MHZ (tmrHw_LOW_FREQUENCY_MHZ * 30)
103#define TIMER1_FREQUENCY_MHZ (tmrHw_LOW_FREQUENCY_MHZ * 30)
104#define TIMER3_FREQUENCY_MHZ (tmrHw_HIGH_FREQUENCY_MHZ * 30)
105#define TIMER3_FREQUENCY_KHZ (tmrHw_HIGH_FREQUENCY_HZ / 1000 * 30)
106#else
107#define TIMER0_FREQUENCY_MHZ tmrHw_LOW_FREQUENCY_MHZ
108#define TIMER1_FREQUENCY_MHZ tmrHw_LOW_FREQUENCY_MHZ
109#define TIMER3_FREQUENCY_MHZ tmrHw_HIGH_FREQUENCY_MHZ
110#define TIMER3_FREQUENCY_KHZ (tmrHw_HIGH_FREQUENCY_HZ / 1000)
111#endif
112
Russell Kinge8765af2011-05-12 15:51:29 +0100113static struct clk sp804_timer012_clk = {
114 .name = "sp804-timer-0,1,2",
Russell King82d63732011-05-12 13:43:39 +0100115 .type = CLK_TYPE_PRIMARY,
116 .mode = CLK_MODE_XTAL,
117 .rate_hz = TIMER1_FREQUENCY_MHZ * 1000000,
118};
119
120static struct clk sp804_timer3_clk = {
121 .name = "sp804-timer-3",
122 .type = CLK_TYPE_PRIMARY,
123 .mode = CLK_MODE_XTAL,
124 .rate_hz = TIMER3_FREQUENCY_KHZ * 1000,
125};
126
Leo Chen278a6752009-08-07 19:58:26 +0100127static struct clk_lookup lookups[] = {
Russell King3126c7b2010-07-15 11:01:17 +0100128 { /* Bus clock */
129 .con_id = "apb_pclk",
130 .clk = &dummy_apb_pclk,
131 }, { /* UART0 */
132 .dev_id = "uarta",
133 .clk = &uart_clk,
134 }, { /* UART1 */
135 .dev_id = "uartb",
136 .clk = &uart_clk,
Russell Kinge8765af2011-05-12 15:51:29 +0100137 }, { /* SP804 timer 0 */
138 .dev_id = "sp804",
139 .con_id = "timer0",
140 .clk = &sp804_timer012_clk,
Russell King82d63732011-05-12 13:43:39 +0100141 }, { /* SP804 timer 1 */
142 .dev_id = "sp804",
143 .con_id = "timer1",
Russell Kinge8765af2011-05-12 15:51:29 +0100144 .clk = &sp804_timer012_clk,
Russell King82d63732011-05-12 13:43:39 +0100145 }, { /* SP804 timer 3 */
146 .dev_id = "sp804",
147 .con_id = "timer3",
148 .clk = &sp804_timer3_clk,
Russell King3126c7b2010-07-15 11:01:17 +0100149 }
Leo Chen278a6752009-08-07 19:58:26 +0100150};
151
152static struct amba_device *amba_devs[] __initdata = {
153 &uartA_device,
154 &uartB_device,
155};
156
157void __init bcmring_amba_init(void)
158{
159 int i;
160 u32 bus_clock;
161
162/* Linux is run initially in non-secure mode. Secure peripherals */
163/* generate FIQ, and must be handled in secure mode. Until we have */
164/* a linux security monitor implementation, keep everything in */
165/* non-secure mode. */
166 chipcHw_busInterfaceClockEnable(chipcHw_REG_BUS_CLOCK_SPU);
167 secHw_setUnsecure(secHw_BLK_MASK_CHIP_CONTROL |
168 secHw_BLK_MASK_KEY_SCAN |
169 secHw_BLK_MASK_TOUCH_SCREEN |
170 secHw_BLK_MASK_UART0 |
171 secHw_BLK_MASK_UART1 |
172 secHw_BLK_MASK_WATCHDOG |
173 secHw_BLK_MASK_SPUM |
174 secHw_BLK_MASK_DDR2 |
175 secHw_BLK_MASK_SPU |
176 secHw_BLK_MASK_PKA |
177 secHw_BLK_MASK_RNG |
178 secHw_BLK_MASK_RTC |
179 secHw_BLK_MASK_OTP |
180 secHw_BLK_MASK_BOOT |
181 secHw_BLK_MASK_MPU |
182 secHw_BLK_MASK_TZCTRL | secHw_BLK_MASK_INTR);
183
184 /* Only the devices attached to the AMBA bus are enabled just before the bus is */
185 /* scanned and the drivers are loaded. The clocks need to be on for the AMBA bus */
186 /* driver to access these blocks. The bus is probed, and the drivers are loaded. */
187 /* FIXME Need to remove enable of PIF once CLCD clock enable used properly in FPGA. */
188 bus_clock = chipcHw_REG_BUS_CLOCK_GE
189 | chipcHw_REG_BUS_CLOCK_SDIO0 | chipcHw_REG_BUS_CLOCK_SDIO1;
190
191 chipcHw_busInterfaceClockEnable(bus_clock);
192
Leo Chen278a6752009-08-07 19:58:26 +0100193 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
194 struct amba_device *d = amba_devs[i];
195 amba_device_register(d, &iomem_resource);
196 }
197}
198
199/*
200 * Where is the timer (VA)?
201 */
Russell King82d63732011-05-12 13:43:39 +0100202#define TIMER0_VA_BASE ((void __iomem *)MM_IO_BASE_TMR)
203#define TIMER1_VA_BASE ((void __iomem *)(MM_IO_BASE_TMR + 0x20))
204#define TIMER2_VA_BASE ((void __iomem *)(MM_IO_BASE_TMR + 0x40))
205#define TIMER3_VA_BASE ((void __iomem *)(MM_IO_BASE_TMR + 0x60))
Leo Chen278a6752009-08-07 19:58:26 +0100206
Leo Chen278a6752009-08-07 19:58:26 +0100207static int __init bcmring_clocksource_init(void)
208{
209 /* setup timer1 as free-running clocksource */
Russell King82d63732011-05-12 13:43:39 +0100210 sp804_clocksource_init(TIMER1_VA_BASE, "timer1");
Leo Chen278a6752009-08-07 19:58:26 +0100211
212 /* setup timer3 as free-running clocksource */
Russell King82d63732011-05-12 13:43:39 +0100213 sp804_clocksource_init(TIMER3_VA_BASE, "timer3");
Leo Chen278a6752009-08-07 19:58:26 +0100214
215 return 0;
216}
217
218/*
219 * Set up timer interrupt, and return the current time in seconds.
220 */
221void __init bcmring_init_timer(void)
222{
223 printk(KERN_INFO "bcmring_init_timer\n");
224 /*
225 * Initialise to a known state (all timers off)
226 */
227 writel(0, TIMER0_VA_BASE + TIMER_CTRL);
228 writel(0, TIMER1_VA_BASE + TIMER_CTRL);
229 writel(0, TIMER2_VA_BASE + TIMER_CTRL);
230 writel(0, TIMER3_VA_BASE + TIMER_CTRL);
231
232 /*
233 * Make irqs happen for the system timer
234 */
Leo Chen278a6752009-08-07 19:58:26 +0100235 bcmring_clocksource_init();
236
Maxin B. John8658ca72011-11-09 11:12:58 +0100237 sp804_clockevents_init(TIMER0_VA_BASE, IRQ_TIMER0, "timer0");
Leo Chen278a6752009-08-07 19:58:26 +0100238}
239
240struct sys_timer bcmring_timer = {
241 .init = bcmring_init_timer,
242};
Jiandong Zhengede2e232011-05-19 00:36:57 +0100243
244void __init bcmring_init_early(void)
245{
246 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
247}