1
2
3
4
5
6
7
8
9
10
11
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/clk.h>
15#include <linux/io.h>
16#include <linux/bitops.h>
17
18#include "clock.h"
19
20
21
22
23
24
25
26#define OMAP4_DPLL_LP_FINT_MAX 1000000
27#define OMAP4_DPLL_LP_FOUT_MAX 100000000
28
29
30
31
32#define OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK (1 << 8)
33#define OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK (1 << 10)
34#define OMAP4430_DPLL_REGM4XEN_MASK (1 << 11)
35
36
37#define OMAP4430_REGM4XEN_MULT 4
38
39void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk)
40{
41 u32 v;
42 u32 mask;
43
44 if (!clk || !clk->clksel_reg)
45 return;
46
47 mask = clk->flags & CLOCK_CLKOUTX2 ?
48 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
49 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
50
51 v = omap2_clk_readl(clk, clk->clksel_reg);
52
53 v &= ~mask;
54 omap2_clk_writel(v, clk, clk->clksel_reg);
55}
56
57void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk)
58{
59 u32 v;
60 u32 mask;
61
62 if (!clk || !clk->clksel_reg)
63 return;
64
65 mask = clk->flags & CLOCK_CLKOUTX2 ?
66 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
67 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
68
69 v = omap2_clk_readl(clk, clk->clksel_reg);
70
71 v |= mask;
72 omap2_clk_writel(v, clk, clk->clksel_reg);
73}
74
75const struct clk_hw_omap_ops clkhwops_omap4_dpllmx = {
76 .allow_idle = omap4_dpllmx_allow_gatectrl,
77 .deny_idle = omap4_dpllmx_deny_gatectrl,
78};
79
80
81
82
83
84
85
86
87
88
89
90
91
92static void omap4_dpll_lpmode_recalc(struct dpll_data *dd)
93{
94 long fint, fout;
95
96 fint = __clk_get_rate(dd->clk_ref) / (dd->last_rounded_n + 1);
97 fout = fint * dd->last_rounded_m;
98
99 if ((fint < OMAP4_DPLL_LP_FINT_MAX) && (fout < OMAP4_DPLL_LP_FOUT_MAX))
100 dd->last_rounded_lpmode = 1;
101 else
102 dd->last_rounded_lpmode = 0;
103}
104
105
106
107
108
109
110
111
112
113
114unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
115 unsigned long parent_rate)
116{
117 struct clk_hw_omap *clk = to_clk_hw_omap(hw);
118 u32 v;
119 unsigned long rate;
120 struct dpll_data *dd;
121
122 if (!clk || !clk->dpll_data)
123 return 0;
124
125 dd = clk->dpll_data;
126
127 rate = omap2_get_dpll_rate(clk);
128
129
130 v = omap2_clk_readl(clk, dd->control_reg);
131 if (v & OMAP4430_DPLL_REGM4XEN_MASK)
132 rate *= OMAP4430_REGM4XEN_MULT;
133
134 return rate;
135}
136
137
138
139
140
141
142
143
144
145
146
147
148
149long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
150 unsigned long target_rate,
151 unsigned long *parent_rate)
152{
153 struct clk_hw_omap *clk = to_clk_hw_omap(hw);
154 struct dpll_data *dd;
155 long r;
156
157 if (!clk || !clk->dpll_data)
158 return -EINVAL;
159
160 dd = clk->dpll_data;
161
162 dd->last_rounded_m4xen = 0;
163
164
165
166
167
168 r = omap2_dpll_round_rate(hw, target_rate, NULL);
169 if (r != ~0)
170 goto out;
171
172
173
174
175
176
177 r = omap2_dpll_round_rate(hw, target_rate / OMAP4430_REGM4XEN_MULT,
178 NULL);
179 if (r == ~0)
180 return r;
181
182 dd->last_rounded_rate *= OMAP4430_REGM4XEN_MULT;
183 dd->last_rounded_m4xen = 1;
184
185out:
186 omap4_dpll_lpmode_recalc(dd);
187
188 return dd->last_rounded_rate;
189}
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204long omap4_dpll_regm4xen_determine_rate(struct clk_hw *hw, unsigned long rate,
205 unsigned long min_rate,
206 unsigned long max_rate,
207 unsigned long *best_parent_rate,
208 struct clk_hw **best_parent_clk)
209{
210 struct clk_hw_omap *clk = to_clk_hw_omap(hw);
211 struct dpll_data *dd;
212
213 if (!hw || !rate)
214 return -EINVAL;
215
216 dd = clk->dpll_data;
217 if (!dd)
218 return -EINVAL;
219
220 if (__clk_get_rate(dd->clk_bypass) == rate &&
221 (dd->modes & (1 << DPLL_LOW_POWER_BYPASS))) {
222 *best_parent_clk = __clk_get_hw(dd->clk_bypass);
223 } else {
224 rate = omap4_dpll_regm4xen_round_rate(hw, rate,
225 best_parent_rate);
226 *best_parent_clk = __clk_get_hw(dd->clk_ref);
227 }
228
229 *best_parent_rate = rate;
230
231 return rate;
232}
233