clk: renesas: rcar-gen3: Add spinlock
authorSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Tue, 22 Jan 2019 19:58:38 +0000 (22:58 +0300)
committerGeert Uytterhoeven <geert+renesas@glider.be>
Fri, 25 Jan 2019 10:26:22 +0000 (11:26 +0100)
Protect the CPG register read-modify-write sequence with a spinlock.

Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
drivers/clk/renesas/rcar-gen3-cpg.c

index 80d0808..0818691 100644 (file)
 
 #define CPG_RCKCR_CKSEL        BIT(15) /* RCLK Clock Source Select */
 
+static spinlock_t cpg_lock;
+
 static void cpg_reg_modify(void __iomem *reg, u32 clear, u32 set)
 {
+       unsigned long flags;
        u32 val;
 
+       spin_lock_irqsave(&cpg_lock, flags);
        val = readl(reg);
        val &= ~clear;
        val |= set;
        writel(val, reg);
+       spin_unlock_irqrestore(&cpg_lock, flags);
 };
 
 struct cpg_simple_notifier {
@@ -615,5 +620,8 @@ int __init rcar_gen3_cpg_init(const struct rcar_gen3_cpg_pll_config *config,
        if (attr)
                cpg_quirks = (uintptr_t)attr->data;
        pr_debug("%s: mode = 0x%x quirks = 0x%x\n", __func__, mode, cpg_quirks);
+
+       spin_lock_init(&cpg_lock);
+
        return 0;
 }