1 // SPDX-License-Identifier: GPL-2.0
2 /***************************************************************************/
5 * clk.c -- general ColdFire CPU kernel clk handling
7 * Copyright (C) 2009, Greg Ungerer (gerg@snapgear.com)
10 /***************************************************************************/
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/mutex.h>
16 #include <linux/clk.h>
18 #include <linux/err.h>
19 #include <asm/coldfire.h>
20 #include <asm/mcfsim.h>
21 #include <asm/mcfclk.h>
23 static DEFINE_SPINLOCK(clk_lock);
27 * For more advanced ColdFire parts that have clocks that can be enabled
28 * we supply enable/disable functions. These must properly define their
29 * clocks in their platform specific code.
31 void __clk_init_enabled(struct clk *clk)
34 clk->clk_ops->enable(clk);
37 void __clk_init_disabled(struct clk *clk)
40 clk->clk_ops->disable(clk);
43 static void __clk_enable0(struct clk *clk)
45 __raw_writeb(clk->slot, MCFPM_PPMCR0);
48 static void __clk_disable0(struct clk *clk)
50 __raw_writeb(clk->slot, MCFPM_PPMSR0);
53 struct clk_ops clk_ops0 = {
54 .enable = __clk_enable0,
55 .disable = __clk_disable0,
59 static void __clk_enable1(struct clk *clk)
61 __raw_writeb(clk->slot, MCFPM_PPMCR1);
64 static void __clk_disable1(struct clk *clk)
66 __raw_writeb(clk->slot, MCFPM_PPMSR1);
69 struct clk_ops clk_ops1 = {
70 .enable = __clk_enable1,
71 .disable = __clk_disable1,
73 #endif /* MCFPM_PPMCR1 */
74 #endif /* MCFPM_PPMCR0 */
76 int clk_enable(struct clk *clk)
83 spin_lock_irqsave(&clk_lock, flags);
84 if ((clk->enabled++ == 0) && clk->clk_ops)
85 clk->clk_ops->enable(clk);
86 spin_unlock_irqrestore(&clk_lock, flags);
90 EXPORT_SYMBOL(clk_enable);
92 void clk_disable(struct clk *clk)
99 spin_lock_irqsave(&clk_lock, flags);
100 if ((--clk->enabled == 0) && clk->clk_ops)
101 clk->clk_ops->disable(clk);
102 spin_unlock_irqrestore(&clk_lock, flags);
104 EXPORT_SYMBOL(clk_disable);
106 unsigned long clk_get_rate(struct clk *clk)
113 EXPORT_SYMBOL(clk_get_rate);
115 /* dummy functions, should not be called */
116 long clk_round_rate(struct clk *clk, unsigned long rate)
121 EXPORT_SYMBOL(clk_round_rate);
123 int clk_set_rate(struct clk *clk, unsigned long rate)
128 EXPORT_SYMBOL(clk_set_rate);
130 int clk_set_parent(struct clk *clk, struct clk *parent)
135 EXPORT_SYMBOL(clk_set_parent);
137 struct clk *clk_get_parent(struct clk *clk)
142 EXPORT_SYMBOL(clk_get_parent);
144 /***************************************************************************/