blob: 286d6e6d5f5a9d69ed57fc0d914497213c4c34c9 [file] [log] [blame]
Russell King3a083222011-11-05 17:38:32 +00001/*
2 * linux/arch/arm/mach-clps711x/core.c
3 *
4 * Core support for the CLPS711x-based machines.
5 *
6 * Copyright (C) 2001,2011 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 */
Alexander Shiyan61ae48c2012-08-21 20:59:35 +040022#include <linux/io.h>
Russell King3a083222011-11-05 17:38:32 +000023#include <linux/init.h>
Alexander Shiyan4a8355c2012-10-10 19:45:27 +040024#include <linux/sizes.h>
Russell King3a083222011-11-05 17:38:32 +000025#include <linux/interrupt.h>
Russell King3a083222011-11-05 17:38:32 +000026#include <linux/irq.h>
Alexander Shiyan61ae48c2012-08-21 20:59:35 +040027#include <linux/clk.h>
28#include <linux/clkdev.h>
Alexander Shiyan4a8355c2012-10-10 19:45:27 +040029#include <linux/clockchips.h>
Alexander Shiyan61ae48c2012-08-21 20:59:35 +040030#include <linux/clk-provider.h>
Russell King3a083222011-11-05 17:38:32 +000031
Russell King3a083222011-11-05 17:38:32 +000032#include <asm/mach/map.h>
33#include <asm/mach/time.h>
David Howells9f97da72012-03-28 18:30:01 +010034#include <asm/system_misc.h>
Russell King3a083222011-11-05 17:38:32 +000035
Alexander Shiyan61ae48c2012-08-21 20:59:35 +040036#include <mach/hardware.h>
37
38static struct clk *clk_pll, *clk_bus, *clk_uart, *clk_timerl, *clk_timerh,
39 *clk_tint, *clk_spi;
Alexander Shiyan61ae48c2012-08-21 20:59:35 +040040
Russell King3a083222011-11-05 17:38:32 +000041/*
42 * This maps the generic CLPS711x registers
43 */
44static struct map_desc clps711x_io_desc[] __initdata = {
45 {
Alexander Shiyan304b2c62012-05-06 09:21:57 +040046 .virtual = (unsigned long)CLPS711X_VIRT_BASE,
47 .pfn = __phys_to_pfn(CLPS711X_PHYS_BASE),
Alexander Shiyan6cb1b142012-10-10 19:45:31 +040048 .length = SZ_64K,
Russell King3a083222011-11-05 17:38:32 +000049 .type = MT_DEVICE
50 }
51};
52
53void __init clps711x_map_io(void)
54{
55 iotable_init(clps711x_io_desc, ARRAY_SIZE(clps711x_io_desc));
56}
57
58static void int1_mask(struct irq_data *d)
59{
60 u32 intmr1;
61
62 intmr1 = clps_readl(INTMR1);
63 intmr1 &= ~(1 << d->irq);
64 clps_writel(intmr1, INTMR1);
65}
66
67static void int1_ack(struct irq_data *d)
68{
Alexander Shiyan74fde6d2012-10-10 19:45:29 +040069}
70
71static void int1_eoi(struct irq_data *d)
72{
Russell King3a083222011-11-05 17:38:32 +000073 switch (d->irq) {
74 case IRQ_CSINT: clps_writel(0, COEOI); break;
75 case IRQ_TC1OI: clps_writel(0, TC1EOI); break;
76 case IRQ_TC2OI: clps_writel(0, TC2EOI); break;
77 case IRQ_RTCMI: clps_writel(0, RTCEOI); break;
78 case IRQ_TINT: clps_writel(0, TEOI); break;
79 case IRQ_UMSINT: clps_writel(0, UMSEOI); break;
80 }
81}
82
83static void int1_unmask(struct irq_data *d)
84{
85 u32 intmr1;
86
87 intmr1 = clps_readl(INTMR1);
88 intmr1 |= 1 << d->irq;
89 clps_writel(intmr1, INTMR1);
90}
91
92static struct irq_chip int1_chip = {
Alexander Shiyan74fde6d2012-10-10 19:45:29 +040093 .name = "Interrupt Vector 1 ",
Russell King3a083222011-11-05 17:38:32 +000094 .irq_ack = int1_ack,
Alexander Shiyan74fde6d2012-10-10 19:45:29 +040095 .irq_eoi = int1_eoi,
Russell King3a083222011-11-05 17:38:32 +000096 .irq_mask = int1_mask,
97 .irq_unmask = int1_unmask,
98};
99
100static void int2_mask(struct irq_data *d)
101{
102 u32 intmr2;
103
104 intmr2 = clps_readl(INTMR2);
105 intmr2 &= ~(1 << (d->irq - 16));
106 clps_writel(intmr2, INTMR2);
107}
108
109static void int2_ack(struct irq_data *d)
110{
Alexander Shiyan74fde6d2012-10-10 19:45:29 +0400111}
112
113static void int2_eoi(struct irq_data *d)
114{
Russell King3a083222011-11-05 17:38:32 +0000115 switch (d->irq) {
116 case IRQ_KBDINT: clps_writel(0, KBDEOI); break;
117 }
118}
119
120static void int2_unmask(struct irq_data *d)
121{
122 u32 intmr2;
123
124 intmr2 = clps_readl(INTMR2);
125 intmr2 |= 1 << (d->irq - 16);
126 clps_writel(intmr2, INTMR2);
127}
128
129static struct irq_chip int2_chip = {
Alexander Shiyan74fde6d2012-10-10 19:45:29 +0400130 .name = "Interrupt Vector 2 ",
Russell King3a083222011-11-05 17:38:32 +0000131 .irq_ack = int2_ack,
Alexander Shiyan74fde6d2012-10-10 19:45:29 +0400132 .irq_eoi = int2_eoi,
Russell King3a083222011-11-05 17:38:32 +0000133 .irq_mask = int2_mask,
134 .irq_unmask = int2_unmask,
135};
136
Alexander Shiyan74fde6d2012-10-10 19:45:29 +0400137struct clps711x_irqdesc {
138 int nr;
139 struct irq_chip *chip;
140 irq_flow_handler_t handle;
141};
142
143static struct clps711x_irqdesc clps711x_irqdescs[] __initdata = {
144 { IRQ_CSINT, &int1_chip, handle_fasteoi_irq, },
145 { IRQ_EINT1, &int1_chip, handle_level_irq, },
146 { IRQ_EINT2, &int1_chip, handle_level_irq, },
147 { IRQ_EINT3, &int1_chip, handle_level_irq, },
148 { IRQ_TC1OI, &int1_chip, handle_fasteoi_irq, },
149 { IRQ_TC2OI, &int1_chip, handle_fasteoi_irq, },
150 { IRQ_RTCMI, &int1_chip, handle_fasteoi_irq, },
151 { IRQ_TINT, &int1_chip, handle_fasteoi_irq, },
152 { IRQ_UTXINT1, &int1_chip, handle_level_irq, },
153 { IRQ_URXINT1, &int1_chip, handle_level_irq, },
154 { IRQ_UMSINT, &int1_chip, handle_fasteoi_irq, },
155 { IRQ_SSEOTI, &int1_chip, handle_level_irq, },
156 { IRQ_KBDINT, &int2_chip, handle_fasteoi_irq, },
157 { IRQ_SS2RX, &int2_chip, handle_level_irq, },
158 { IRQ_SS2TX, &int2_chip, handle_level_irq, },
159 { IRQ_UTXINT2, &int2_chip, handle_level_irq, },
160 { IRQ_URXINT2, &int2_chip, handle_level_irq, },
161};
162
Russell King3a083222011-11-05 17:38:32 +0000163void __init clps711x_init_irq(void)
164{
165 unsigned int i;
166
Alexander Shiyan74fde6d2012-10-10 19:45:29 +0400167 /* Disable interrupts */
Russell King3a083222011-11-05 17:38:32 +0000168 clps_writel(0, INTMR1);
169 clps_writel(0, INTMR2);
Alexander Shiyan74fde6d2012-10-10 19:45:29 +0400170 clps_writel(0, INTMR3);
Russell King3a083222011-11-05 17:38:32 +0000171
Alexander Shiyan74fde6d2012-10-10 19:45:29 +0400172 /* Clear down any pending interrupts */
173 clps_writel(0, BLEOI);
174 clps_writel(0, MCEOI);
Russell King3a083222011-11-05 17:38:32 +0000175 clps_writel(0, COEOI);
176 clps_writel(0, TC1EOI);
177 clps_writel(0, TC2EOI);
178 clps_writel(0, RTCEOI);
179 clps_writel(0, TEOI);
180 clps_writel(0, UMSEOI);
Russell King3a083222011-11-05 17:38:32 +0000181 clps_writel(0, KBDEOI);
Alexander Shiyan74fde6d2012-10-10 19:45:29 +0400182 clps_writel(0, SRXEOF);
183 clps_writel(0xffffffff, DAISR);
184
185 for (i = 0; i < ARRAY_SIZE(clps711x_irqdescs); i++) {
186 irq_set_chip_and_handler(clps711x_irqdescs[i].nr,
187 clps711x_irqdescs[i].chip,
188 clps711x_irqdescs[i].handle);
189 set_irq_flags(clps711x_irqdescs[i].nr,
190 IRQF_VALID | IRQF_PROBE);
191 }
Russell King3a083222011-11-05 17:38:32 +0000192}
193
Alexander Shiyan4a8355c2012-10-10 19:45:27 +0400194static void clps711x_clockevent_set_mode(enum clock_event_mode mode,
195 struct clock_event_device *evt)
Russell King3a083222011-11-05 17:38:32 +0000196{
Russell King3a083222011-11-05 17:38:32 +0000197}
198
Alexander Shiyan4a8355c2012-10-10 19:45:27 +0400199static struct clock_event_device clockevent_clps711x = {
200 .name = "CLPS711x Clockevents",
201 .rating = 300,
202 .features = CLOCK_EVT_FEAT_PERIODIC,
203 .set_mode = clps711x_clockevent_set_mode,
204};
205
206static irqreturn_t clps711x_timer_interrupt(int irq, void *dev_id)
Russell King3a083222011-11-05 17:38:32 +0000207{
Alexander Shiyan4a8355c2012-10-10 19:45:27 +0400208 clockevent_clps711x.event_handler(&clockevent_clps711x);
209
Russell King3a083222011-11-05 17:38:32 +0000210 return IRQ_HANDLED;
211}
212
213static struct irqaction clps711x_timer_irq = {
214 .name = "CLPS711x Timer Tick",
215 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
Alexander Shiyan4a8355c2012-10-10 19:45:27 +0400216 .handler = clps711x_timer_interrupt,
Russell King3a083222011-11-05 17:38:32 +0000217};
218
Alexander Shiyan61ae48c2012-08-21 20:59:35 +0400219static void add_fixed_clk(struct clk *clk, const char *name, int rate)
220{
221 clk = clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT, rate);
222 clk_register_clkdev(clk, name, NULL);
223}
224
Russell King3a083222011-11-05 17:38:32 +0000225static void __init clps711x_timer_init(void)
226{
Alexander Shiyan61ae48c2012-08-21 20:59:35 +0400227 int osc, ext, pll, cpu, bus, timl, timh, uart, spi;
228 u32 tmp;
Russell King3a083222011-11-05 17:38:32 +0000229
Alexander Shiyan61ae48c2012-08-21 20:59:35 +0400230 osc = 3686400;
231 ext = 13000000;
Russell King3a083222011-11-05 17:38:32 +0000232
Alexander Shiyan61ae48c2012-08-21 20:59:35 +0400233 tmp = clps_readl(PLLR) >> 24;
234 if (tmp)
235 pll = (osc * tmp) / 2;
236 else
237 pll = 73728000; /* Default value */
238
239 tmp = clps_readl(SYSFLG2);
240 if (tmp & SYSFLG2_CKMODE) {
241 cpu = ext;
242 bus = cpu;
243 spi = 135400;
244 } else {
245 cpu = pll;
246 if (cpu >= 36864000)
247 bus = cpu / 2;
248 else
249 bus = 36864000 / 2;
250 spi = cpu / 576;
251 }
252
253 uart = bus / 10;
254
255 if (tmp & SYSFLG2_CKMODE) {
256 tmp = clps_readl(SYSCON2);
257 if (tmp & SYSCON2_OSTB)
258 timh = ext / 26;
259 else
260 timh = 541440;
261 } else
262 timh = cpu / 144;
263
264 timl = timh / 256;
265
266 /* All clocks are fixed */
267 add_fixed_clk(clk_pll, "pll", pll);
268 add_fixed_clk(clk_bus, "bus", bus);
269 add_fixed_clk(clk_uart, "uart", uart);
270 add_fixed_clk(clk_timerl, "timer_lf", timl);
271 add_fixed_clk(clk_timerh, "timer_hf", timh);
272 add_fixed_clk(clk_tint, "tint", 64);
273 add_fixed_clk(clk_spi, "spi", spi);
274
275 pr_info("CPU frequency set at %i Hz.\n", cpu);
276
Alexander Shiyan4a8355c2012-10-10 19:45:27 +0400277 clps_writew(DIV_ROUND_CLOSEST(timh, HZ), TC2D);
Alexander Shiyan61ae48c2012-08-21 20:59:35 +0400278
279 tmp = clps_readl(SYSCON1);
280 tmp |= SYSCON1_TC2S | SYSCON1_TC2M;
281 clps_writel(tmp, SYSCON1);
282
Alexander Shiyan4a8355c2012-10-10 19:45:27 +0400283 clockevents_config_and_register(&clockevent_clps711x, timh, 1, 0xffff);
Russell King3a083222011-11-05 17:38:32 +0000284
285 setup_irq(IRQ_TC2OI, &clps711x_timer_irq);
Russell King3a083222011-11-05 17:38:32 +0000286}
287
288struct sys_timer clps711x_timer = {
289 .init = clps711x_timer_init,
Russell King3a083222011-11-05 17:38:32 +0000290};
Russell King6c000712011-11-05 17:41:52 +0000291
292void clps711x_restart(char mode, const char *cmd)
293{
294 soft_restart(0);
295}
Nicolas Pitre71e256c2011-08-02 12:22:48 -0400296
297static void clps711x_idle(void)
298{
299 clps_writel(1, HALT);
300 __asm__ __volatile__(
301 "mov r0, r0\n\
302 mov r0, r0");
303}
304
305static int __init clps711x_idle_init(void)
306{
307 arm_pm_idle = clps711x_idle;
308 return 0;
309}
310
311arch_initcall(clps711x_idle_init);