1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/mach-mmp/clock.c
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>
13 #include "regs-apbc.h"
16 static void apbc_clk_enable(struct clk
*clk
)
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
)
55 spin_lock_irqsave(&clocks_lock
, flags
);
56 if (clk
->enabled
++ == 0)
57 clk
->ops
->enable(clk
);
58 spin_unlock_irqrestore(&clocks_lock
, flags
);
61 EXPORT_SYMBOL(clk_enable
);
63 void clk_disable(struct clk
*clk
)
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
)
83 if (clk
->ops
->getrate
)
84 rate
= clk
->ops
->getrate(clk
);
90 EXPORT_SYMBOL(clk_get_rate
);
92 int clk_set_rate(struct clk
*clk
, unsigned long rate
)
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
);
105 EXPORT_SYMBOL(clk_set_rate
);