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.h>
19 #include <linux/clk-provider.h>
20 #include <linux/slab.h>
22 #include <linux/of_address.h>
23 #include <linux/clk/ti.h>
28 #define pr_fmt(fmt) "%s: " fmt, __func__
31 * omap2_clkops_enable_clkdm - increment usecount on clkdm of @hw
32 * @hw: struct clk_hw * of the clock being enabled
34 * Increment the usecount of the clockdomain of the clock pointed to
35 * by @hw; if the usecount is 1, the clockdomain will be "enabled."
36 * Only needed for clocks that don't use omap2_dflt_clk_enable() as
37 * their enable function pointer. Passes along the return value of
38 * clkdm_clk_enable(), -EINVAL if @hw is not associated with a
39 * clockdomain, or 0 if clock framework-based clockdomain control is
42 int omap2_clkops_enable_clkdm(struct clk_hw *hw)
44 struct clk_hw_omap *clk;
47 clk = to_clk_hw_omap(hw);
49 if (unlikely(!clk->clkdm)) {
50 pr_err("%s: %s: no clkdm set ?!\n", __func__,
55 if (unlikely(clk->enable_reg))
56 pr_err("%s: %s: should use dflt_clk_enable ?!\n", __func__,
59 if (ti_clk_get_features()->flags & TI_CLK_DISABLE_CLKDM_CONTROL) {
60 pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n",
61 __func__, clk_hw_get_name(hw));
65 ret = ti_clk_ll_ops->clkdm_clk_enable(clk->clkdm, hw->clk);
66 WARN(ret, "%s: could not enable %s's clockdomain %s: %d\n",
67 __func__, clk_hw_get_name(hw), clk->clkdm_name, ret);
73 * omap2_clkops_disable_clkdm - decrement usecount on clkdm of @hw
74 * @hw: struct clk_hw * of the clock being disabled
76 * Decrement the usecount of the clockdomain of the clock pointed to
77 * by @hw; if the usecount is 0, the clockdomain will be "disabled."
78 * Only needed for clocks that don't use omap2_dflt_clk_disable() as their
79 * disable function pointer. No return value.
81 void omap2_clkops_disable_clkdm(struct clk_hw *hw)
83 struct clk_hw_omap *clk;
85 clk = to_clk_hw_omap(hw);
87 if (unlikely(!clk->clkdm)) {
88 pr_err("%s: %s: no clkdm set ?!\n", __func__,
93 if (unlikely(clk->enable_reg))
94 pr_err("%s: %s: should use dflt_clk_disable ?!\n", __func__,
97 if (ti_clk_get_features()->flags & TI_CLK_DISABLE_CLKDM_CONTROL) {
98 pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n",
99 __func__, clk_hw_get_name(hw));
103 ti_clk_ll_ops->clkdm_clk_disable(clk->clkdm, hw->clk);
107 * omap2_init_clk_clkdm - look up a clockdomain name, store pointer in clk
108 * @clk: OMAP clock struct ptr to use
110 * Convert a clockdomain name stored in a struct clk 'clk' into a
111 * clockdomain pointer, and save it into the struct clk. Intended to be
112 * called during clk_register(). No return value.
114 void omap2_init_clk_clkdm(struct clk_hw *hw)
116 struct clk_hw_omap *clk = to_clk_hw_omap(hw);
117 struct clockdomain *clkdm;
118 const char *clk_name;
120 if (!clk->clkdm_name)
123 clk_name = __clk_get_name(hw->clk);
125 clkdm = ti_clk_ll_ops->clkdm_lookup(clk->clkdm_name);
127 pr_debug("clock: associated clk %s to clkdm %s\n",
128 clk_name, clk->clkdm_name);
131 pr_debug("clock: could not associate clk %s to clkdm %s\n",
132 clk_name, clk->clkdm_name);
136 static void __init of_ti_clockdomain_setup(struct device_node *node)
139 struct clk_hw *clk_hw;
140 const char *clkdm_name = node->name;
142 unsigned int num_clks;
144 num_clks = of_clk_get_parent_count(node);
146 for (i = 0; i < num_clks; i++) {
147 clk = of_clk_get(node, i);
149 pr_err("%s: Failed get %s' clock nr %d (%ld)\n",
150 __func__, node->full_name, i, PTR_ERR(clk));
153 clk_hw = __clk_get_hw(clk);
154 if (clk_hw_get_flags(clk_hw) & CLK_IS_BASIC) {
155 pr_warn("can't setup clkdm for basic clk %s\n",
156 __clk_get_name(clk));
159 to_clk_hw_omap(clk_hw)->clkdm_name = clkdm_name;
160 omap2_init_clk_clkdm(clk_hw);
164 static const struct of_device_id ti_clkdm_match_table[] __initconst = {
165 { .compatible = "ti,clockdomain" },
170 * ti_dt_clockdomains_setup - setup device tree clockdomains
172 * Initializes clockdomain nodes for a SoC. This parses through all the
173 * nodes with compatible = "ti,clockdomain", and add the clockdomain
174 * info for all the clocks listed under these. This function shall be
175 * called after rest of the DT clock init has completed and all
176 * clock nodes have been registered.
178 void __init ti_dt_clockdomains_setup(void)
180 struct device_node *np;
181 for_each_matching_node(np, ti_clkdm_match_table) {
182 of_ti_clockdomain_setup(np);