Commit | Line | Data |
---|---|---|
3cd4a596 TK |
1 | /* |
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 | ||
1b29e601 | 18 | #include <linux/clk.h> |
3cd4a596 TK |
19 | #include <linux/clk-provider.h> |
20 | #include <linux/slab.h> | |
21 | #include <linux/of.h> | |
22 | #include <linux/of_address.h> | |
23 | #include <linux/clk/ti.h> | |
24 | ||
e9e63088 TK |
25 | #include "clock.h" |
26 | ||
3cd4a596 TK |
27 | #undef pr_fmt |
28 | #define pr_fmt(fmt) "%s: " fmt, __func__ | |
29 | ||
bd86cfdc TK |
30 | /** |
31 | * omap2_clkops_enable_clkdm - increment usecount on clkdm of @hw | |
32 | * @hw: struct clk_hw * of the clock being enabled | |
33 | * | |
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 | |
40 | * not implemented. | |
41 | */ | |
42 | int omap2_clkops_enable_clkdm(struct clk_hw *hw) | |
43 | { | |
44 | struct clk_hw_omap *clk; | |
45 | int ret = 0; | |
46 | ||
47 | clk = to_clk_hw_omap(hw); | |
48 | ||
49 | if (unlikely(!clk->clkdm)) { | |
50 | pr_err("%s: %s: no clkdm set ?!\n", __func__, | |
836ee0f7 | 51 | clk_hw_get_name(hw)); |
bd86cfdc TK |
52 | return -EINVAL; |
53 | } | |
54 | ||
bd86cfdc TK |
55 | if (ti_clk_get_features()->flags & TI_CLK_DISABLE_CLKDM_CONTROL) { |
56 | pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n", | |
836ee0f7 | 57 | __func__, clk_hw_get_name(hw)); |
bd86cfdc TK |
58 | return 0; |
59 | } | |
60 | ||
61 | ret = ti_clk_ll_ops->clkdm_clk_enable(clk->clkdm, hw->clk); | |
62 | WARN(ret, "%s: could not enable %s's clockdomain %s: %d\n", | |
836ee0f7 | 63 | __func__, clk_hw_get_name(hw), clk->clkdm_name, ret); |
bd86cfdc TK |
64 | |
65 | return ret; | |
66 | } | |
67 | ||
68 | /** | |
69 | * omap2_clkops_disable_clkdm - decrement usecount on clkdm of @hw | |
70 | * @hw: struct clk_hw * of the clock being disabled | |
71 | * | |
72 | * Decrement the usecount of the clockdomain of the clock pointed to | |
73 | * by @hw; if the usecount is 0, the clockdomain will be "disabled." | |
74 | * Only needed for clocks that don't use omap2_dflt_clk_disable() as their | |
75 | * disable function pointer. No return value. | |
76 | */ | |
77 | void omap2_clkops_disable_clkdm(struct clk_hw *hw) | |
78 | { | |
79 | struct clk_hw_omap *clk; | |
80 | ||
81 | clk = to_clk_hw_omap(hw); | |
82 | ||
83 | if (unlikely(!clk->clkdm)) { | |
84 | pr_err("%s: %s: no clkdm set ?!\n", __func__, | |
836ee0f7 | 85 | clk_hw_get_name(hw)); |
bd86cfdc TK |
86 | return; |
87 | } | |
88 | ||
bd86cfdc TK |
89 | if (ti_clk_get_features()->flags & TI_CLK_DISABLE_CLKDM_CONTROL) { |
90 | pr_err("%s: %s: clkfw-based clockdomain control disabled ?!\n", | |
836ee0f7 | 91 | __func__, clk_hw_get_name(hw)); |
bd86cfdc TK |
92 | return; |
93 | } | |
94 | ||
95 | ti_clk_ll_ops->clkdm_clk_disable(clk->clkdm, hw->clk); | |
96 | } | |
97 | ||
2e1a294c TK |
98 | /** |
99 | * omap2_init_clk_clkdm - look up a clockdomain name, store pointer in clk | |
60b185f1 | 100 | * @hw: Pointer to clk_hw_omap used to obtain OMAP clock struct ptr to use |
2e1a294c TK |
101 | * |
102 | * Convert a clockdomain name stored in a struct clk 'clk' into a | |
103 | * clockdomain pointer, and save it into the struct clk. Intended to be | |
89d079dc | 104 | * called during clk_register(). Returns 0 on success, -EERROR otherwise. |
2e1a294c | 105 | */ |
89d079dc | 106 | int omap2_init_clk_clkdm(struct clk_hw *hw) |
2e1a294c TK |
107 | { |
108 | struct clk_hw_omap *clk = to_clk_hw_omap(hw); | |
109 | struct clockdomain *clkdm; | |
110 | const char *clk_name; | |
111 | ||
112 | if (!clk->clkdm_name) | |
89d079dc | 113 | return 0; |
2e1a294c TK |
114 | |
115 | clk_name = __clk_get_name(hw->clk); | |
116 | ||
117 | clkdm = ti_clk_ll_ops->clkdm_lookup(clk->clkdm_name); | |
118 | if (clkdm) { | |
119 | pr_debug("clock: associated clk %s to clkdm %s\n", | |
120 | clk_name, clk->clkdm_name); | |
121 | clk->clkdm = clkdm; | |
122 | } else { | |
123 | pr_debug("clock: could not associate clk %s to clkdm %s\n", | |
124 | clk_name, clk->clkdm_name); | |
125 | } | |
89d079dc JB |
126 | |
127 | return 0; | |
2e1a294c TK |
128 | } |
129 | ||
3cd4a596 TK |
130 | static void __init of_ti_clockdomain_setup(struct device_node *node) |
131 | { | |
132 | struct clk *clk; | |
133 | struct clk_hw *clk_hw; | |
9e56a7d4 | 134 | const char *clkdm_name = ti_dt_clk_name(node); |
3cd4a596 | 135 | int i; |
921bacfa | 136 | unsigned int num_clks; |
3cd4a596 | 137 | |
f71355b3 | 138 | num_clks = of_clk_get_parent_count(node); |
3cd4a596 TK |
139 | |
140 | for (i = 0; i < num_clks; i++) { | |
141 | clk = of_clk_get(node, i); | |
319f1276 | 142 | if (IS_ERR(clk)) { |
16673931 RH |
143 | pr_err("%s: Failed get %pOF' clock nr %d (%ld)\n", |
144 | __func__, node, i, PTR_ERR(clk)); | |
319f1276 SAS |
145 | continue; |
146 | } | |
98d8a60e | 147 | clk_hw = __clk_get_hw(clk); |
8aa09cf3 | 148 | if (!omap2_clk_is_hw_omap(clk_hw)) { |
3cd4a596 TK |
149 | pr_warn("can't setup clkdm for basic clk %s\n", |
150 | __clk_get_name(clk)); | |
b7a7943f | 151 | clk_put(clk); |
3cd4a596 TK |
152 | continue; |
153 | } | |
3cd4a596 TK |
154 | to_clk_hw_omap(clk_hw)->clkdm_name = clkdm_name; |
155 | omap2_init_clk_clkdm(clk_hw); | |
b7a7943f | 156 | clk_put(clk); |
3cd4a596 TK |
157 | } |
158 | } | |
159 | ||
f375573c | 160 | static const struct of_device_id ti_clkdm_match_table[] __initconst = { |
3cd4a596 TK |
161 | { .compatible = "ti,clockdomain" }, |
162 | { } | |
163 | }; | |
164 | ||
165 | /** | |
166 | * ti_dt_clockdomains_setup - setup device tree clockdomains | |
167 | * | |
168 | * Initializes clockdomain nodes for a SoC. This parses through all the | |
169 | * nodes with compatible = "ti,clockdomain", and add the clockdomain | |
170 | * info for all the clocks listed under these. This function shall be | |
171 | * called after rest of the DT clock init has completed and all | |
172 | * clock nodes have been registered. | |
173 | */ | |
174 | void __init ti_dt_clockdomains_setup(void) | |
175 | { | |
176 | struct device_node *np; | |
177 | for_each_matching_node(np, ti_clkdm_match_table) { | |
178 | of_ti_clockdomain_setup(np); | |
179 | } | |
180 | } |