blob: 61ef87b1a6887583f456ffd46b0f06b388c4338a [file] [log] [blame]
Tero Kristo3cd4a592013-08-21 19:39:15 +03001/*
2 * OMAP clockdomain support
3 *
4 * Copyright (C) 2013 Texas Instruments, Inc.
5 *
6 * Tero Kristo <t-kristo@ti.com>
7 *
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.
11 *
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.
16 */
17
18#include <linux/clk-provider.h>
19#include <linux/slab.h>
20#include <linux/of.h>
21#include <linux/of_address.h>
22#include <linux/clk/ti.h>
23
24#undef pr_fmt
25#define pr_fmt(fmt) "%s: " fmt, __func__
26
Tero Kristobd86cfd2015-03-03 16:22:50 +020027/**
28 * omap2_clkops_enable_clkdm - increment usecount on clkdm of @hw
29 * @hw: struct clk_hw * of the clock being enabled
30 *
31 * Increment the usecount of the clockdomain of the clock pointed to
32 * by @hw; if the usecount is 1, the clockdomain will be "enabled."
33 * Only needed for clocks that don't use omap2_dflt_clk_enable() as
34 * their enable function pointer. Passes along the return value of
35 * clkdm_clk_enable(), -EINVAL if @hw is not associated with a
36 * clockdomain, or 0 if clock framework-based clockdomain control is
37 * not implemented.
38 */
39int omap2_clkops_enable_clkdm(struct clk_hw *hw)
40{
41 struct clk_hw_omap *clk;
42 int ret = 0;
43
44 clk = to_clk_hw_omap(hw);
45
46 if (unlikely(!clk->clkdm)) {
47 pr_err("%s: %s: no clkdm set ?!\n", __func__,
48 __clk_get_name(hw->clk));
49 return -EINVAL;
50 }
51
52 if (unlikely(clk->enable_reg))
53 pr_err("%s: %s: should use dflt_clk_enable ?!\n", __func__,
54 __clk_get_name(hw->clk));
55
56 if (ti_clk_get_features()->flags & TI_CLK_DISABLE_CLKDM_CONTROL) {
57 pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n",
58 __func__, __clk_get_name(hw->clk));
59 return 0;
60 }
61
62 ret = ti_clk_ll_ops->clkdm_clk_enable(clk->clkdm, hw->clk);
63 WARN(ret, "%s: could not enable %s's clockdomain %s: %d\n",
64 __func__, __clk_get_name(hw->clk), clk->clkdm_name, ret);
65
66 return ret;
67}
68
69/**
70 * omap2_clkops_disable_clkdm - decrement usecount on clkdm of @hw
71 * @hw: struct clk_hw * of the clock being disabled
72 *
73 * Decrement the usecount of the clockdomain of the clock pointed to
74 * by @hw; if the usecount is 0, the clockdomain will be "disabled."
75 * Only needed for clocks that don't use omap2_dflt_clk_disable() as their
76 * disable function pointer. No return value.
77 */
78void omap2_clkops_disable_clkdm(struct clk_hw *hw)
79{
80 struct clk_hw_omap *clk;
81
82 clk = to_clk_hw_omap(hw);
83
84 if (unlikely(!clk->clkdm)) {
85 pr_err("%s: %s: no clkdm set ?!\n", __func__,
86 __clk_get_name(hw->clk));
87 return;
88 }
89
90 if (unlikely(clk->enable_reg))
91 pr_err("%s: %s: should use dflt_clk_disable ?!\n", __func__,
92 __clk_get_name(hw->clk));
93
94 if (ti_clk_get_features()->flags & TI_CLK_DISABLE_CLKDM_CONTROL) {
95 pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n",
96 __func__, __clk_get_name(hw->clk));
97 return;
98 }
99
100 ti_clk_ll_ops->clkdm_clk_disable(clk->clkdm, hw->clk);
101}
102
Tero Kristo3cd4a592013-08-21 19:39:15 +0300103static void __init of_ti_clockdomain_setup(struct device_node *node)
104{
105 struct clk *clk;
106 struct clk_hw *clk_hw;
107 const char *clkdm_name = node->name;
108 int i;
109 int num_clks;
110
111 num_clks = of_count_phandle_with_args(node, "clocks", "#clock-cells");
112
113 for (i = 0; i < num_clks; i++) {
114 clk = of_clk_get(node, i);
Sebastian Andrzej Siewior319f1272014-09-18 16:33:27 +0200115 if (IS_ERR(clk)) {
116 pr_err("%s: Failed get %s' clock nr %d (%ld)\n",
117 __func__, node->full_name, i, PTR_ERR(clk));
118 continue;
119 }
Tero Kristo3cd4a592013-08-21 19:39:15 +0300120 if (__clk_get_flags(clk) & CLK_IS_BASIC) {
121 pr_warn("can't setup clkdm for basic clk %s\n",
122 __clk_get_name(clk));
123 continue;
124 }
125 clk_hw = __clk_get_hw(clk);
126 to_clk_hw_omap(clk_hw)->clkdm_name = clkdm_name;
127 omap2_init_clk_clkdm(clk_hw);
128 }
129}
130
Fabian Frederickf3755732015-03-31 20:50:42 +0200131static const struct of_device_id ti_clkdm_match_table[] __initconst = {
Tero Kristo3cd4a592013-08-21 19:39:15 +0300132 { .compatible = "ti,clockdomain" },
133 { }
134};
135
136/**
137 * ti_dt_clockdomains_setup - setup device tree clockdomains
138 *
139 * Initializes clockdomain nodes for a SoC. This parses through all the
140 * nodes with compatible = "ti,clockdomain", and add the clockdomain
141 * info for all the clocks listed under these. This function shall be
142 * called after rest of the DT clock init has completed and all
143 * clock nodes have been registered.
144 */
145void __init ti_dt_clockdomains_setup(void)
146{
147 struct device_node *np;
148 for_each_matching_node(np, ti_clkdm_match_table) {
149 of_ti_clockdomain_setup(np);
150 }
151}