drm/omap: Fix error handling path in 'omap_dmm_probe()'
[linux/fpc-iii.git] / drivers / clk / ti / autoidle.c
blob345af43465f0f9a27aeedc431b51d0733bc4b896
1 /*
2 * TI clock autoidle support
4 * Copyright (C) 2013 Texas Instruments, Inc.
6 * Tero Kristo <t-kristo@ti.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/clk-provider.h>
19 #include <linux/slab.h>
20 #include <linux/io.h>
21 #include <linux/of.h>
22 #include <linux/of_address.h>
23 #include <linux/clk/ti.h>
25 #include "clock.h"
27 struct clk_ti_autoidle {
28 void __iomem *reg;
29 u8 shift;
30 u8 flags;
31 const char *name;
32 struct list_head node;
35 #define AUTOIDLE_LOW 0x1
37 static LIST_HEAD(autoidle_clks);
38 static LIST_HEAD(clk_hw_omap_clocks);
40 /**
41 * omap2_clk_deny_idle - disable autoidle on an OMAP clock
42 * @clk: struct clk * to disable autoidle for
44 * Disable autoidle on an OMAP clock.
46 int omap2_clk_deny_idle(struct clk *clk)
48 struct clk_hw_omap *c;
50 c = to_clk_hw_omap(__clk_get_hw(clk));
51 if (c->ops && c->ops->deny_idle)
52 c->ops->deny_idle(c);
53 return 0;
56 /**
57 * omap2_clk_allow_idle - enable autoidle on an OMAP clock
58 * @clk: struct clk * to enable autoidle for
60 * Enable autoidle on an OMAP clock.
62 int omap2_clk_allow_idle(struct clk *clk)
64 struct clk_hw_omap *c;
66 c = to_clk_hw_omap(__clk_get_hw(clk));
67 if (c->ops && c->ops->allow_idle)
68 c->ops->allow_idle(c);
69 return 0;
72 static void _allow_autoidle(struct clk_ti_autoidle *clk)
74 u32 val;
76 val = ti_clk_ll_ops->clk_readl(clk->reg);
78 if (clk->flags & AUTOIDLE_LOW)
79 val &= ~(1 << clk->shift);
80 else
81 val |= (1 << clk->shift);
83 ti_clk_ll_ops->clk_writel(val, clk->reg);
86 static void _deny_autoidle(struct clk_ti_autoidle *clk)
88 u32 val;
90 val = ti_clk_ll_ops->clk_readl(clk->reg);
92 if (clk->flags & AUTOIDLE_LOW)
93 val |= (1 << clk->shift);
94 else
95 val &= ~(1 << clk->shift);
97 ti_clk_ll_ops->clk_writel(val, clk->reg);
101 * _clk_generic_allow_autoidle_all - enable autoidle for all clocks
103 * Enables hardware autoidle for all registered DT clocks, which have
104 * the feature.
106 static void _clk_generic_allow_autoidle_all(void)
108 struct clk_ti_autoidle *c;
110 list_for_each_entry(c, &autoidle_clks, node)
111 _allow_autoidle(c);
115 * _clk_generic_deny_autoidle_all - disable autoidle for all clocks
117 * Disables hardware autoidle for all registered DT clocks, which have
118 * the feature.
120 static void _clk_generic_deny_autoidle_all(void)
122 struct clk_ti_autoidle *c;
124 list_for_each_entry(c, &autoidle_clks, node)
125 _deny_autoidle(c);
129 * of_ti_clk_autoidle_setup - sets up hardware autoidle for a clock
130 * @node: pointer to the clock device node
132 * Checks if a clock has hardware autoidle support or not (check
133 * for presence of 'ti,autoidle-shift' property in the device tree
134 * node) and sets up the hardware autoidle feature for the clock
135 * if available. If autoidle is available, the clock is also added
136 * to the autoidle list for later processing. Returns 0 on success,
137 * negative error value on failure.
139 int __init of_ti_clk_autoidle_setup(struct device_node *node)
141 u32 shift;
142 struct clk_ti_autoidle *clk;
144 /* Check if this clock has autoidle support or not */
145 if (of_property_read_u32(node, "ti,autoidle-shift", &shift))
146 return 0;
148 clk = kzalloc(sizeof(*clk), GFP_KERNEL);
150 if (!clk)
151 return -ENOMEM;
153 clk->shift = shift;
154 clk->name = node->name;
155 clk->reg = ti_clk_get_reg_addr(node, 0);
157 if (IS_ERR(clk->reg)) {
158 kfree(clk);
159 return -EINVAL;
162 if (of_property_read_bool(node, "ti,invert-autoidle-bit"))
163 clk->flags |= AUTOIDLE_LOW;
165 list_add(&clk->node, &autoidle_clks);
167 return 0;
171 * omap2_init_clk_hw_omap_clocks - initialize an OMAP clock
172 * @hw: struct clk_hw * to initialize
174 * Add an OMAP clock @clk to the internal list of OMAP clocks. Used
175 * temporarily for autoidle handling, until this support can be
176 * integrated into the common clock framework code in some way. No
177 * return value.
179 void omap2_init_clk_hw_omap_clocks(struct clk_hw *hw)
181 struct clk_hw_omap *c;
183 if (clk_hw_get_flags(hw) & CLK_IS_BASIC)
184 return;
186 c = to_clk_hw_omap(hw);
187 list_add(&c->node, &clk_hw_omap_clocks);
191 * omap2_clk_enable_autoidle_all - enable autoidle on all OMAP clocks that
192 * support it
194 * Enable clock autoidle on all OMAP clocks that have allow_idle
195 * function pointers associated with them. This function is intended
196 * to be temporary until support for this is added to the common clock
197 * code. Returns 0.
199 int omap2_clk_enable_autoidle_all(void)
201 struct clk_hw_omap *c;
203 list_for_each_entry(c, &clk_hw_omap_clocks, node)
204 if (c->ops && c->ops->allow_idle)
205 c->ops->allow_idle(c);
207 _clk_generic_allow_autoidle_all();
209 return 0;
213 * omap2_clk_disable_autoidle_all - disable autoidle on all OMAP clocks that
214 * support it
216 * Disable clock autoidle on all OMAP clocks that have allow_idle
217 * function pointers associated with them. This function is intended
218 * to be temporary until support for this is added to the common clock
219 * code. Returns 0.
221 int omap2_clk_disable_autoidle_all(void)
223 struct clk_hw_omap *c;
225 list_for_each_entry(c, &clk_hw_omap_clocks, node)
226 if (c->ops && c->ops->deny_idle)
227 c->ops->deny_idle(c);
229 _clk_generic_deny_autoidle_all();
231 return 0;