clocksource: starfive: Add reset control support
authorxingyu.wu <xingyu.wu@starfivetech.com>
Tue, 12 Jul 2022 02:57:13 +0000 (10:57 +0800)
committerxingyu.wu <xingyu.wu@starfivetech.com>
Tue, 12 Jul 2022 02:57:20 +0000 (10:57 +0800)
Reset the timer if the reset control is available.

Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com>
Signed-off-by: Ley Foon Tan <leyfoon.tan@linux.starfivetech.com>
drivers/clocksource/timer-starfive.c
drivers/clocksource/timer-starfive.h [changed mode: 0644->0755]

index fe1d6b4..b7b7e36 100755 (executable)
@@ -20,6 +20,7 @@
 #include <linux/of_irq.h>
 #include <linux/sched_clock.h>
 #include <linux/module.h>
+#include <linux/reset.h>
 #include "timer-starfive.h"
 
 #define CLOCK_SOURCE_RATE      200
@@ -339,6 +340,8 @@ static int __init do_starfive_timer_of_init(struct device_node *np,
        const char *name = NULL;
        struct clk *clk;
        struct clk *pclk;
+       struct reset_control *prst;
+       struct reset_control *rst;
        struct starfive_clkevt *clkevt;
        void __iomem *base;
 
@@ -357,6 +360,12 @@ static int __init do_starfive_timer_of_init(struct device_node *np,
                        pr_warn("pclk for %pOFn is present,"
                                "but could not be activated\n", np);
 
+       prst = of_reset_control_get(np, "apb_rst");
+       if (!IS_ERR(prst)) {
+               reset_control_assert(prst);
+               reset_control_deassert(prst);
+       }
+
        count = of_irq_count(np);
        if (count > NR_TIMERS || count <= 0) {
                ret = -EINVAL;
@@ -388,6 +397,13 @@ static int __init do_starfive_timer_of_init(struct device_node *np,
                                        "but could not be activated\n", np);
                }
 
+               rst = of_reset_control_get(np, name);
+               if (!IS_ERR(rst)) {
+                       clkevt->rst = rst;
+                       reset_control_assert(rst);
+                       reset_control_deassert(rst);
+               }
+
                irq = irq_of_parse_and_map(np, index);
                if (irq < 0) {
                        ret = -EINVAL;
@@ -414,6 +430,10 @@ init_err:
 register_err:
        free_irq(clkevt->irq, &clkevt->evt);
 irq_err:
+       if (!clkevt->rst) {
+               reset_control_assert(clkevt->rst);
+               reset_control_put(clkevt->rst);
+       }
        if (!clkevt->clk) {
                clk_disable_unprepare(clkevt->clk);
                clk_put(clkevt->clk);
old mode 100644 (file)
new mode 100755 (executable)
index 3d702e4..940b7b9
@@ -84,6 +84,7 @@ struct starfive_timer {
 struct starfive_clkevt {
        struct clock_event_device evt;
        struct clk *clk;
+       struct reset_control *rst;
        int irq;
        u64 periodic;
        u64 rate;