forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/arch/arm/mach-mmp/time.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/arch/arm/mach-mmp/time.c
34 *
....@@ -12,16 +13,13 @@
1213 * The timers module actually includes three timers, each timer with up to
1314 * three match comparators. Timer #0 is used here in free-running mode as
1415 * 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.
1916 */
2017
2118 #include <linux/init.h>
2219 #include <linux/kernel.h>
2320 #include <linux/interrupt.h>
2421 #include <linux/clockchips.h>
22
+#include <linux/clk.h>
2523
2624 #include <linux/io.h>
2725 #include <linux/irq.h>
....@@ -35,14 +33,7 @@
3533 #include "regs-timers.h"
3634 #include "regs-apbc.h"
3735 #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>
4637
4738 #define TIMERS_VIRT_BASE TIMERS1_VIRT_BASE
4839
....@@ -163,7 +154,8 @@
163154
164155 __raw_writel(0x0, mmp_timer_base + TMR_CER); /* disable */
165156
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)) :
167159 (TMR_CCR_CS_0(3) | TMR_CCR_CS_1(3));
168160 __raw_writel(ccr, mmp_timer_base + TMR_CCR);
169161
....@@ -182,58 +174,50 @@
182174 __raw_writel(0x2, mmp_timer_base + TMR_CER);
183175 }
184176
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)
193178 {
194179 timer_config();
195180
196
- sched_clock_register(mmp_read_sched_clock, 32, MMP_CLOCK_FREQ);
181
+ sched_clock_register(mmp_read_sched_clock, 32, rate);
197182
198183 ckevt.cpumask = cpumask_of(0);
199184
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);
201188
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);
205191 }
206192
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)
214194 {
215
- struct device_node *np;
195
+ struct clk *clk;
216196 int irq, ret;
197
+ unsigned long rate;
217198
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;
222209 }
223210
224211 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
+
229215 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;
238221 }
239
-#endif
222
+
223
+TIMER_OF_DECLARE(mmp_timer, "mrvl,mmp-timer", mmp_dt_init_timer);