Linux 5.7.6
[linux/fpc-iii.git] / arch / arm / mach-mmp / clock.c
blob291fe41e3547bd6dfd8c50f8bd175acadcde967f
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/arch/arm/mach-mmp/clock.c
4 */
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/list.h>
9 #include <linux/spinlock.h>
10 #include <linux/clk.h>
11 #include <linux/io.h>
13 #include "regs-apbc.h"
14 #include "clock.h"
16 static void apbc_clk_enable(struct clk *clk)
18 uint32_t clk_rst;
20 clk_rst = APBC_APBCLK | APBC_FNCLK | APBC_FNCLKSEL(clk->fnclksel);
21 __raw_writel(clk_rst, clk->clk_rst);
24 static void apbc_clk_disable(struct clk *clk)
26 __raw_writel(0, clk->clk_rst);
29 struct clkops apbc_clk_ops = {
30 .enable = apbc_clk_enable,
31 .disable = apbc_clk_disable,
34 static void apmu_clk_enable(struct clk *clk)
36 __raw_writel(clk->enable_val, clk->clk_rst);
39 static void apmu_clk_disable(struct clk *clk)
41 __raw_writel(0, clk->clk_rst);
44 struct clkops apmu_clk_ops = {
45 .enable = apmu_clk_enable,
46 .disable = apmu_clk_disable,
49 static DEFINE_SPINLOCK(clocks_lock);
51 int clk_enable(struct clk *clk)
53 unsigned long flags;
55 spin_lock_irqsave(&clocks_lock, flags);
56 if (clk->enabled++ == 0)
57 clk->ops->enable(clk);
58 spin_unlock_irqrestore(&clocks_lock, flags);
59 return 0;
61 EXPORT_SYMBOL(clk_enable);
63 void clk_disable(struct clk *clk)
65 unsigned long flags;
67 if (!clk)
68 return;
70 WARN_ON(clk->enabled == 0);
72 spin_lock_irqsave(&clocks_lock, flags);
73 if (--clk->enabled == 0)
74 clk->ops->disable(clk);
75 spin_unlock_irqrestore(&clocks_lock, flags);
77 EXPORT_SYMBOL(clk_disable);
79 unsigned long clk_get_rate(struct clk *clk)
81 unsigned long rate;
83 if (clk->ops->getrate)
84 rate = clk->ops->getrate(clk);
85 else
86 rate = clk->rate;
88 return rate;
90 EXPORT_SYMBOL(clk_get_rate);
92 int clk_set_rate(struct clk *clk, unsigned long rate)
94 unsigned long flags;
95 int ret = -EINVAL;
97 if (clk->ops->setrate) {
98 spin_lock_irqsave(&clocks_lock, flags);
99 ret = clk->ops->setrate(clk, rate);
100 spin_unlock_irqrestore(&clocks_lock, flags);
103 return ret;
105 EXPORT_SYMBOL(clk_set_rate);