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>
22 #include <linux/of_address.h>
23 #include <linux/clk/ti.h>
27 struct clk_ti_autoidle {
32 struct list_head node;
35 #define AUTOIDLE_LOW 0x1
37 static LIST_HEAD(autoidle_clks);
38 static LIST_HEAD(clk_hw_omap_clocks);
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 if (__clk_get_flags(clk) & CLK_IS_BASIC)
53 c = to_clk_hw_omap(__clk_get_hw(clk));
54 if (c->ops && c->ops->deny_idle)
60 * omap2_clk_allow_idle - enable autoidle on an OMAP clock
61 * @clk: struct clk * to enable autoidle for
63 * Enable autoidle on an OMAP clock.
65 int omap2_clk_allow_idle(struct clk *clk)
67 struct clk_hw_omap *c;
69 if (__clk_get_flags(clk) & CLK_IS_BASIC)
72 c = to_clk_hw_omap(__clk_get_hw(clk));
73 if (c->ops && c->ops->allow_idle)
74 c->ops->allow_idle(c);
78 static void _allow_autoidle(struct clk_ti_autoidle *clk)
82 val = ti_clk_ll_ops->clk_readl(clk->reg);
84 if (clk->flags & AUTOIDLE_LOW)
85 val &= ~(1 << clk->shift);
87 val |= (1 << clk->shift);
89 ti_clk_ll_ops->clk_writel(val, clk->reg);
92 static void _deny_autoidle(struct clk_ti_autoidle *clk)
96 val = ti_clk_ll_ops->clk_readl(clk->reg);
98 if (clk->flags & AUTOIDLE_LOW)
99 val |= (1 << clk->shift);
101 val &= ~(1 << clk->shift);
103 ti_clk_ll_ops->clk_writel(val, clk->reg);
107 * _clk_generic_allow_autoidle_all - enable autoidle for all clocks
109 * Enables hardware autoidle for all registered DT clocks, which have
112 static void _clk_generic_allow_autoidle_all(void)
114 struct clk_ti_autoidle *c;
116 list_for_each_entry(c, &autoidle_clks, node)
121 * _clk_generic_deny_autoidle_all - disable autoidle for all clocks
123 * Disables hardware autoidle for all registered DT clocks, which have
126 static void _clk_generic_deny_autoidle_all(void)
128 struct clk_ti_autoidle *c;
130 list_for_each_entry(c, &autoidle_clks, node)
135 * of_ti_clk_autoidle_setup - sets up hardware autoidle for a clock
136 * @node: pointer to the clock device node
138 * Checks if a clock has hardware autoidle support or not (check
139 * for presence of 'ti,autoidle-shift' property in the device tree
140 * node) and sets up the hardware autoidle feature for the clock
141 * if available. If autoidle is available, the clock is also added
142 * to the autoidle list for later processing. Returns 0 on success,
143 * negative error value on failure.
145 int __init of_ti_clk_autoidle_setup(struct device_node *node)
148 struct clk_ti_autoidle *clk;
150 /* Check if this clock has autoidle support or not */
151 if (of_property_read_u32(node, "ti,autoidle-shift", &shift))
154 clk = kzalloc(sizeof(*clk), GFP_KERNEL);
160 clk->name = node->name;
161 clk->reg = ti_clk_get_reg_addr(node, 0);
163 if (IS_ERR(clk->reg)) {
168 if (of_property_read_bool(node, "ti,invert-autoidle-bit"))
169 clk->flags |= AUTOIDLE_LOW;
171 list_add(&clk->node, &autoidle_clks);
177 * omap2_init_clk_hw_omap_clocks - initialize an OMAP clock
178 * @clk: struct clk * to initialize
180 * Add an OMAP clock @clk to the internal list of OMAP clocks. Used
181 * temporarily for autoidle handling, until this support can be
182 * integrated into the common clock framework code in some way. No
185 void omap2_init_clk_hw_omap_clocks(struct clk *clk)
187 struct clk_hw_omap *c;
189 if (__clk_get_flags(clk) & CLK_IS_BASIC)
192 c = to_clk_hw_omap(__clk_get_hw(clk));
193 list_add(&c->node, &clk_hw_omap_clocks);
197 * omap2_clk_enable_autoidle_all - enable autoidle on all OMAP clocks that
200 * Enable clock autoidle on all OMAP clocks that have allow_idle
201 * function pointers associated with them. This function is intended
202 * to be temporary until support for this is added to the common clock
205 int omap2_clk_enable_autoidle_all(void)
207 struct clk_hw_omap *c;
209 list_for_each_entry(c, &clk_hw_omap_clocks, node)
210 if (c->ops && c->ops->allow_idle)
211 c->ops->allow_idle(c);
213 _clk_generic_allow_autoidle_all();
219 * omap2_clk_disable_autoidle_all - disable autoidle on all OMAP clocks that
222 * Disable clock autoidle on all OMAP clocks that have allow_idle
223 * function pointers associated with them. This function is intended
224 * to be temporary until support for this is added to the common clock
227 int omap2_clk_disable_autoidle_all(void)
229 struct clk_hw_omap *c;
231 list_for_each_entry(c, &clk_hw_omap_clocks, node)
232 if (c->ops && c->ops->deny_idle)
233 c->ops->deny_idle(c);
235 _clk_generic_deny_autoidle_all();