.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * linux/arch/arm/mach-mmp/time.c |
---|
3 | 4 | * |
---|
.. | .. |
---|
12 | 13 | * The timers module actually includes three timers, each timer with up to |
---|
13 | 14 | * three match comparators. Timer #0 is used here in free-running mode as |
---|
14 | 15 | * the clock source, and match comparator #1 used as clock event device. |
---|
15 | | - * |
---|
16 | | - * This program is free software; you can redistribute it and/or modify |
---|
17 | | - * it under the terms of the GNU General Public License version 2 as |
---|
18 | | - * published by the Free Software Foundation. |
---|
19 | 16 | */ |
---|
20 | 17 | |
---|
21 | 18 | #include <linux/init.h> |
---|
22 | 19 | #include <linux/kernel.h> |
---|
23 | 20 | #include <linux/interrupt.h> |
---|
24 | 21 | #include <linux/clockchips.h> |
---|
| 22 | +#include <linux/clk.h> |
---|
25 | 23 | |
---|
26 | 24 | #include <linux/io.h> |
---|
27 | 25 | #include <linux/irq.h> |
---|
.. | .. |
---|
35 | 33 | #include "regs-timers.h" |
---|
36 | 34 | #include "regs-apbc.h" |
---|
37 | 35 | #include "irqs.h" |
---|
38 | | -#include "cputype.h" |
---|
39 | | -#include "clock.h" |
---|
40 | | - |
---|
41 | | -#ifdef CONFIG_CPU_MMP2 |
---|
42 | | -#define MMP_CLOCK_FREQ 6500000 |
---|
43 | | -#else |
---|
44 | | -#define MMP_CLOCK_FREQ 3250000 |
---|
45 | | -#endif |
---|
| 36 | +#include <linux/soc/mmp/cputype.h> |
---|
46 | 37 | |
---|
47 | 38 | #define TIMERS_VIRT_BASE TIMERS1_VIRT_BASE |
---|
48 | 39 | |
---|
.. | .. |
---|
163 | 154 | |
---|
164 | 155 | __raw_writel(0x0, mmp_timer_base + TMR_CER); /* disable */ |
---|
165 | 156 | |
---|
166 | | - ccr &= (cpu_is_mmp2()) ? (TMR_CCR_CS_0(0) | TMR_CCR_CS_1(0)) : |
---|
| 157 | + ccr &= (cpu_is_mmp2() || cpu_is_mmp3()) ? |
---|
| 158 | + (TMR_CCR_CS_0(0) | TMR_CCR_CS_1(0)) : |
---|
167 | 159 | (TMR_CCR_CS_0(3) | TMR_CCR_CS_1(3)); |
---|
168 | 160 | __raw_writel(ccr, mmp_timer_base + TMR_CCR); |
---|
169 | 161 | |
---|
.. | .. |
---|
182 | 174 | __raw_writel(0x2, mmp_timer_base + TMR_CER); |
---|
183 | 175 | } |
---|
184 | 176 | |
---|
185 | | -static struct irqaction timer_irq = { |
---|
186 | | - .name = "timer", |
---|
187 | | - .flags = IRQF_TIMER | IRQF_IRQPOLL, |
---|
188 | | - .handler = timer_interrupt, |
---|
189 | | - .dev_id = &ckevt, |
---|
190 | | -}; |
---|
191 | | - |
---|
192 | | -void __init timer_init(int irq) |
---|
| 177 | +void __init mmp_timer_init(int irq, unsigned long rate) |
---|
193 | 178 | { |
---|
194 | 179 | timer_config(); |
---|
195 | 180 | |
---|
196 | | - sched_clock_register(mmp_read_sched_clock, 32, MMP_CLOCK_FREQ); |
---|
| 181 | + sched_clock_register(mmp_read_sched_clock, 32, rate); |
---|
197 | 182 | |
---|
198 | 183 | ckevt.cpumask = cpumask_of(0); |
---|
199 | 184 | |
---|
200 | | - setup_irq(irq, &timer_irq); |
---|
| 185 | + if (request_irq(irq, timer_interrupt, IRQF_TIMER | IRQF_IRQPOLL, |
---|
| 186 | + "timer", &ckevt)) |
---|
| 187 | + pr_err("Failed to request irq %d (timer)\n", irq); |
---|
201 | 188 | |
---|
202 | | - clocksource_register_hz(&cksrc, MMP_CLOCK_FREQ); |
---|
203 | | - clockevents_config_and_register(&ckevt, MMP_CLOCK_FREQ, |
---|
204 | | - MIN_DELTA, MAX_DELTA); |
---|
| 189 | + clocksource_register_hz(&cksrc, rate); |
---|
| 190 | + clockevents_config_and_register(&ckevt, rate, MIN_DELTA, MAX_DELTA); |
---|
205 | 191 | } |
---|
206 | 192 | |
---|
207 | | -#ifdef CONFIG_OF |
---|
208 | | -static const struct of_device_id mmp_timer_dt_ids[] = { |
---|
209 | | - { .compatible = "mrvl,mmp-timer", }, |
---|
210 | | - {} |
---|
211 | | -}; |
---|
212 | | - |
---|
213 | | -void __init mmp_dt_init_timer(void) |
---|
| 193 | +static int __init mmp_dt_init_timer(struct device_node *np) |
---|
214 | 194 | { |
---|
215 | | - struct device_node *np; |
---|
| 195 | + struct clk *clk; |
---|
216 | 196 | int irq, ret; |
---|
| 197 | + unsigned long rate; |
---|
217 | 198 | |
---|
218 | | - np = of_find_matching_node(NULL, mmp_timer_dt_ids); |
---|
219 | | - if (!np) { |
---|
220 | | - ret = -ENODEV; |
---|
221 | | - goto out; |
---|
| 199 | + clk = of_clk_get(np, 0); |
---|
| 200 | + if (!IS_ERR(clk)) { |
---|
| 201 | + ret = clk_prepare_enable(clk); |
---|
| 202 | + if (ret) |
---|
| 203 | + return ret; |
---|
| 204 | + rate = clk_get_rate(clk); |
---|
| 205 | + } else if (cpu_is_pj4()) { |
---|
| 206 | + rate = 6500000; |
---|
| 207 | + } else { |
---|
| 208 | + rate = 3250000; |
---|
222 | 209 | } |
---|
223 | 210 | |
---|
224 | 211 | irq = irq_of_parse_and_map(np, 0); |
---|
225 | | - if (!irq) { |
---|
226 | | - ret = -EINVAL; |
---|
227 | | - goto out; |
---|
228 | | - } |
---|
| 212 | + if (!irq) |
---|
| 213 | + return -EINVAL; |
---|
| 214 | + |
---|
229 | 215 | mmp_timer_base = of_iomap(np, 0); |
---|
230 | | - if (!mmp_timer_base) { |
---|
231 | | - ret = -ENOMEM; |
---|
232 | | - goto out; |
---|
233 | | - } |
---|
234 | | - timer_init(irq); |
---|
235 | | - return; |
---|
236 | | -out: |
---|
237 | | - pr_err("Failed to get timer from device tree with error:%d\n", ret); |
---|
| 216 | + if (!mmp_timer_base) |
---|
| 217 | + return -ENOMEM; |
---|
| 218 | + |
---|
| 219 | + mmp_timer_init(irq, rate); |
---|
| 220 | + return 0; |
---|
238 | 221 | } |
---|
239 | | -#endif |
---|
| 222 | + |
---|
| 223 | +TIMER_OF_DECLARE(mmp_timer, "mrvl,mmp-timer", mmp_dt_init_timer); |
---|