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 c
= to_clk_hw_omap(__clk_get_hw(clk
));
51 if (c
->ops
&& c
->ops
->deny_idle
)
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
);
72 static void _allow_autoidle(struct clk_ti_autoidle
*clk
)
76 val
= ti_clk_ll_ops
->clk_readl(clk
->reg
);
78 if (clk
->flags
& AUTOIDLE_LOW
)
79 val
&= ~(1 << clk
->shift
);
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
)
90 val
= ti_clk_ll_ops
->clk_readl(clk
->reg
);
92 if (clk
->flags
& AUTOIDLE_LOW
)
93 val
|= (1 << clk
->shift
);
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
106 static void _clk_generic_allow_autoidle_all(void)
108 struct clk_ti_autoidle
*c
;
110 list_for_each_entry(c
, &autoidle_clks
, node
)
115 * _clk_generic_deny_autoidle_all - disable autoidle for all clocks
117 * Disables hardware autoidle for all registered DT clocks, which have
120 static void _clk_generic_deny_autoidle_all(void)
122 struct clk_ti_autoidle
*c
;
124 list_for_each_entry(c
, &autoidle_clks
, node
)
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
)
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
))
148 clk
= kzalloc(sizeof(*clk
), GFP_KERNEL
);
154 clk
->name
= node
->name
;
155 clk
->reg
= ti_clk_get_reg_addr(node
, 0);
157 if (IS_ERR(clk
->reg
)) {
162 if (of_property_read_bool(node
, "ti,invert-autoidle-bit"))
163 clk
->flags
|= AUTOIDLE_LOW
;
165 list_add(&clk
->node
, &autoidle_clks
);
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
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
)
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
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
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();
213 * omap2_clk_disable_autoidle_all - disable autoidle on all OMAP clocks that
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
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();