Merge branch 'drm-fixes' of git://people.freedesktop.org/~airlied/linux
[linux/fpc-iii.git] / arch / m68k / platform / coldfire / clk.c
blob75f9ee967ea71cc696c3ed9cc5efb390b4ed209a
1 /***************************************************************************/
3 /*
4 * clk.c -- general ColdFire CPU kernel clk handling
6 * Copyright (C) 2009, Greg Ungerer (gerg@snapgear.com)
7 */
9 /***************************************************************************/
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/mutex.h>
15 #include <linux/clk.h>
16 #include <linux/io.h>
17 #include <linux/err.h>
18 #include <asm/coldfire.h>
19 #include <asm/mcfsim.h>
20 #include <asm/mcfclk.h>
22 /***************************************************************************/
23 #ifndef MCFPM_PPMCR0
24 struct clk *clk_get(struct device *dev, const char *id)
26 return NULL;
28 EXPORT_SYMBOL(clk_get);
30 int clk_enable(struct clk *clk)
32 return 0;
34 EXPORT_SYMBOL(clk_enable);
36 void clk_disable(struct clk *clk)
39 EXPORT_SYMBOL(clk_disable);
41 void clk_put(struct clk *clk)
44 EXPORT_SYMBOL(clk_put);
46 unsigned long clk_get_rate(struct clk *clk)
48 return MCF_CLK;
50 EXPORT_SYMBOL(clk_get_rate);
51 #else
52 static DEFINE_SPINLOCK(clk_lock);
54 struct clk *clk_get(struct device *dev, const char *id)
56 const char *clk_name = dev ? dev_name(dev) : id ? id : NULL;
57 struct clk *clk;
58 unsigned i;
60 for (i = 0; (clk = mcf_clks[i]) != NULL; ++i)
61 if (!strcmp(clk->name, clk_name))
62 return clk;
63 pr_warn("clk_get: didn't find clock %s\n", clk_name);
64 return ERR_PTR(-ENOENT);
66 EXPORT_SYMBOL(clk_get);
68 int clk_enable(struct clk *clk)
70 unsigned long flags;
71 spin_lock_irqsave(&clk_lock, flags);
72 if ((clk->enabled++ == 0) && clk->clk_ops)
73 clk->clk_ops->enable(clk);
74 spin_unlock_irqrestore(&clk_lock, flags);
76 return 0;
78 EXPORT_SYMBOL(clk_enable);
80 void clk_disable(struct clk *clk)
82 unsigned long flags;
83 spin_lock_irqsave(&clk_lock, flags);
84 if ((--clk->enabled == 0) && clk->clk_ops)
85 clk->clk_ops->disable(clk);
86 spin_unlock_irqrestore(&clk_lock, flags);
88 EXPORT_SYMBOL(clk_disable);
90 void clk_put(struct clk *clk)
92 if (clk->enabled != 0)
93 pr_warn("clk_put %s still enabled\n", clk->name);
95 EXPORT_SYMBOL(clk_put);
97 unsigned long clk_get_rate(struct clk *clk)
99 return clk->rate;
101 EXPORT_SYMBOL(clk_get_rate);
103 /***************************************************************************/
105 void __clk_init_enabled(struct clk *clk)
107 clk->enabled = 1;
108 clk->clk_ops->enable(clk);
111 void __clk_init_disabled(struct clk *clk)
113 clk->enabled = 0;
114 clk->clk_ops->disable(clk);
117 static void __clk_enable0(struct clk *clk)
119 __raw_writeb(clk->slot, MCFPM_PPMCR0);
122 static void __clk_disable0(struct clk *clk)
124 __raw_writeb(clk->slot, MCFPM_PPMSR0);
127 struct clk_ops clk_ops0 = {
128 .enable = __clk_enable0,
129 .disable = __clk_disable0,
132 #ifdef MCFPM_PPMCR1
133 static void __clk_enable1(struct clk *clk)
135 __raw_writeb(clk->slot, MCFPM_PPMCR1);
138 static void __clk_disable1(struct clk *clk)
140 __raw_writeb(clk->slot, MCFPM_PPMSR1);
143 struct clk_ops clk_ops1 = {
144 .enable = __clk_enable1,
145 .disable = __clk_disable1,
147 #endif /* MCFPM_PPMCR1 */
148 #endif /* MCFPM_PPMCR0 */
150 struct clk *devm_clk_get(struct device *dev, const char *id)
152 return NULL;
154 EXPORT_SYMBOL(devm_clk_get);