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