2 * TI clock autoidle support
4 * Copyright (C) 2013 Texas Instruments, Inc.
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>
25 struct clk_ti_autoidle {
30 struct list_head node;
33 #define AUTOIDLE_LOW 0x1
35 static LIST_HEAD(autoidle_clks);
37 static void ti_allow_autoidle(struct clk_ti_autoidle *clk)
41 val = ti_clk_ll_ops->clk_readl(clk->reg);
43 if (clk->flags & AUTOIDLE_LOW)
44 val &= ~(1 << clk->shift);
46 val |= (1 << clk->shift);
48 ti_clk_ll_ops->clk_writel(val, clk->reg);
51 static void ti_deny_autoidle(struct clk_ti_autoidle *clk)
55 val = ti_clk_ll_ops->clk_readl(clk->reg);
57 if (clk->flags & AUTOIDLE_LOW)
58 val |= (1 << clk->shift);
60 val &= ~(1 << clk->shift);
62 ti_clk_ll_ops->clk_writel(val, clk->reg);
66 * of_ti_clk_allow_autoidle_all - enable autoidle for all clocks
68 * Enables hardware autoidle for all registered DT clocks, which have
71 void of_ti_clk_allow_autoidle_all(void)
73 struct clk_ti_autoidle *c;
75 list_for_each_entry(c, &autoidle_clks, node)
80 * of_ti_clk_deny_autoidle_all - disable autoidle for all clocks
82 * Disables hardware autoidle for all registered DT clocks, which have
85 void of_ti_clk_deny_autoidle_all(void)
87 struct clk_ti_autoidle *c;
89 list_for_each_entry(c, &autoidle_clks, node)
94 * of_ti_clk_autoidle_setup - sets up hardware autoidle for a clock
95 * @node: pointer to the clock device node
97 * Checks if a clock has hardware autoidle support or not (check
98 * for presence of 'ti,autoidle-shift' property in the device tree
99 * node) and sets up the hardware autoidle feature for the clock
100 * if available. If autoidle is available, the clock is also added
101 * to the autoidle list for later processing. Returns 0 on success,
102 * negative error value on failure.
104 int __init of_ti_clk_autoidle_setup(struct device_node *node)
107 struct clk_ti_autoidle *clk;
109 /* Check if this clock has autoidle support or not */
110 if (of_property_read_u32(node, "ti,autoidle-shift", &shift))
113 clk = kzalloc(sizeof(*clk), GFP_KERNEL);
119 clk->name = node->name;
120 clk->reg = ti_clk_get_reg_addr(node, 0);
127 if (of_property_read_bool(node, "ti,invert-autoidle-bit"))
128 clk->flags |= AUTOIDLE_LOW;
130 list_add(&clk->node, &autoidle_clks);