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