2 * OMAP clockdomain 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>
21 #include <linux/of_address.h>
22 #include <linux/clk/ti.h>
27 #define pr_fmt(fmt) "%s: " fmt, __func__
30 * omap2_clkops_enable_clkdm - increment usecount on clkdm of @hw
31 * @hw: struct clk_hw * of the clock being enabled
33 * Increment the usecount of the clockdomain of the clock pointed to
34 * by @hw; if the usecount is 1, the clockdomain will be "enabled."
35 * Only needed for clocks that don't use omap2_dflt_clk_enable() as
36 * their enable function pointer. Passes along the return value of
37 * clkdm_clk_enable(), -EINVAL if @hw is not associated with a
38 * clockdomain, or 0 if clock framework-based clockdomain control is
41 int omap2_clkops_enable_clkdm(struct clk_hw *hw)
43 struct clk_hw_omap *clk;
46 clk = to_clk_hw_omap(hw);
48 if (unlikely(!clk->clkdm)) {
49 pr_err("%s: %s: no clkdm set ?!\n", __func__,
50 __clk_get_name(hw->clk));
54 if (unlikely(clk->enable_reg))
55 pr_err("%s: %s: should use dflt_clk_enable ?!\n", __func__,
56 __clk_get_name(hw->clk));
58 if (ti_clk_get_features()->flags & TI_CLK_DISABLE_CLKDM_CONTROL) {
59 pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n",
60 __func__, __clk_get_name(hw->clk));
64 ret = ti_clk_ll_ops->clkdm_clk_enable(clk->clkdm, hw->clk);
65 WARN(ret, "%s: could not enable %s's clockdomain %s: %d\n",
66 __func__, __clk_get_name(hw->clk), clk->clkdm_name, ret);
72 * omap2_clkops_disable_clkdm - decrement usecount on clkdm of @hw
73 * @hw: struct clk_hw * of the clock being disabled
75 * Decrement the usecount of the clockdomain of the clock pointed to
76 * by @hw; if the usecount is 0, the clockdomain will be "disabled."
77 * Only needed for clocks that don't use omap2_dflt_clk_disable() as their
78 * disable function pointer. No return value.
80 void omap2_clkops_disable_clkdm(struct clk_hw *hw)
82 struct clk_hw_omap *clk;
84 clk = to_clk_hw_omap(hw);
86 if (unlikely(!clk->clkdm)) {
87 pr_err("%s: %s: no clkdm set ?!\n", __func__,
88 __clk_get_name(hw->clk));
92 if (unlikely(clk->enable_reg))
93 pr_err("%s: %s: should use dflt_clk_disable ?!\n", __func__,
94 __clk_get_name(hw->clk));
96 if (ti_clk_get_features()->flags & TI_CLK_DISABLE_CLKDM_CONTROL) {
97 pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n",
98 __func__, __clk_get_name(hw->clk));
102 ti_clk_ll_ops->clkdm_clk_disable(clk->clkdm, hw->clk);
105 static void __init of_ti_clockdomain_setup(struct device_node *node)
108 struct clk_hw *clk_hw;
109 const char *clkdm_name = node->name;
113 num_clks = of_clk_get_parent_count(node);
115 for (i = 0; i < num_clks; i++) {
116 clk = of_clk_get(node, i);
118 pr_err("%s: Failed get %s' clock nr %d (%ld)\n",
119 __func__, node->full_name, i, PTR_ERR(clk));
122 if (__clk_get_flags(clk) & CLK_IS_BASIC) {
123 pr_warn("can't setup clkdm for basic clk %s\n",
124 __clk_get_name(clk));
127 clk_hw = __clk_get_hw(clk);
128 to_clk_hw_omap(clk_hw)->clkdm_name = clkdm_name;
129 omap2_init_clk_clkdm(clk_hw);
133 static const struct of_device_id ti_clkdm_match_table[] __initconst = {
134 { .compatible = "ti,clockdomain" },
139 * ti_dt_clockdomains_setup - setup device tree clockdomains
141 * Initializes clockdomain nodes for a SoC. This parses through all the
142 * nodes with compatible = "ti,clockdomain", and add the clockdomain
143 * info for all the clocks listed under these. This function shall be
144 * called after rest of the DT clock init has completed and all
145 * clock nodes have been registered.
147 void __init ti_dt_clockdomains_setup(void)
149 struct device_node *np;
150 for_each_matching_node(np, ti_clkdm_match_table) {
151 of_ti_clockdomain_setup(np);