This source file includes following definitions.
- voltdm_get_voltage
- voltdm_scale
- voltdm_reset
- omap_voltage_get_volttable
- omap_voltage_get_voltdata
- omap_voltage_register_pmic
- omap_voltage_late_init
- _voltdm_lookup
- _voltdm_register
- voltdm_lookup
- voltdm_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <linux/delay.h>
20 #include <linux/io.h>
21 #include <linux/err.h>
22 #include <linux/export.h>
23 #include <linux/debugfs.h>
24 #include <linux/slab.h>
25 #include <linux/clk.h>
26
27 #include "common.h"
28
29 #include "prm-regbits-34xx.h"
30 #include "prm-regbits-44xx.h"
31 #include "prm44xx.h"
32 #include "prcm44xx.h"
33 #include "prminst44xx.h"
34 #include "control.h"
35
36 #include "voltage.h"
37 #include "powerdomain.h"
38
39 #include "vc.h"
40 #include "vp.h"
41
42 static LIST_HEAD(voltdm_list);
43
44
45
46
47
48
49
50
51
52 unsigned long voltdm_get_voltage(struct voltagedomain *voltdm)
53 {
54 if (!voltdm || IS_ERR(voltdm)) {
55 pr_warn("%s: VDD specified does not exist!\n", __func__);
56 return 0;
57 }
58
59 return voltdm->nominal_volt;
60 }
61
62
63
64
65
66
67
68
69
70 int voltdm_scale(struct voltagedomain *voltdm,
71 unsigned long target_volt)
72 {
73 int ret, i;
74 unsigned long volt = 0;
75
76 if (!voltdm || IS_ERR(voltdm)) {
77 pr_warn("%s: VDD specified does not exist!\n", __func__);
78 return -EINVAL;
79 }
80
81 if (!voltdm->scale) {
82 pr_err("%s: No voltage scale API registered for vdd_%s\n",
83 __func__, voltdm->name);
84 return -ENODATA;
85 }
86
87 if (!voltdm->volt_data) {
88 pr_err("%s: No voltage data defined for vdd_%s\n",
89 __func__, voltdm->name);
90 return -ENODATA;
91 }
92
93
94 for (i = 0; voltdm->volt_data[i].volt_nominal != 0; i++) {
95 if (voltdm->volt_data[i].volt_nominal >= target_volt) {
96 volt = voltdm->volt_data[i].volt_nominal;
97 break;
98 }
99 }
100
101 if (!volt) {
102 pr_warn("%s: not scaling. OPP voltage for %lu, not found.\n",
103 __func__, target_volt);
104 return -EINVAL;
105 }
106
107 ret = voltdm->scale(voltdm, volt);
108 if (!ret)
109 voltdm->nominal_volt = volt;
110
111 return ret;
112 }
113
114
115
116
117
118
119
120
121
122
123 void voltdm_reset(struct voltagedomain *voltdm)
124 {
125 unsigned long target_volt;
126
127 if (!voltdm || IS_ERR(voltdm)) {
128 pr_warn("%s: VDD specified does not exist!\n", __func__);
129 return;
130 }
131
132 target_volt = voltdm_get_voltage(voltdm);
133 if (!target_volt) {
134 pr_err("%s: unable to find current voltage for vdd_%s\n",
135 __func__, voltdm->name);
136 return;
137 }
138
139 voltdm_scale(voltdm, target_volt);
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
155 struct omap_volt_data **volt_data)
156 {
157 if (!voltdm || IS_ERR(voltdm)) {
158 pr_warn("%s: VDD specified does not exist!\n", __func__);
159 return;
160 }
161
162 *volt_data = voltdm->volt_data;
163 }
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
181 unsigned long volt)
182 {
183 int i;
184
185 if (!voltdm || IS_ERR(voltdm)) {
186 pr_warn("%s: VDD specified does not exist!\n", __func__);
187 return ERR_PTR(-EINVAL);
188 }
189
190 if (!voltdm->volt_data) {
191 pr_warn("%s: voltage table does not exist for vdd_%s\n",
192 __func__, voltdm->name);
193 return ERR_PTR(-ENODATA);
194 }
195
196 for (i = 0; voltdm->volt_data[i].volt_nominal != 0; i++) {
197 if (voltdm->volt_data[i].volt_nominal == volt)
198 return &voltdm->volt_data[i];
199 }
200
201 pr_notice("%s: Unable to match the current voltage with the voltage table for vdd_%s\n",
202 __func__, voltdm->name);
203
204 return ERR_PTR(-ENODATA);
205 }
206
207
208
209
210
211
212
213
214
215
216 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
217 struct omap_voltdm_pmic *pmic)
218 {
219 if (!voltdm || IS_ERR(voltdm)) {
220 pr_warn("%s: VDD specified does not exist!\n", __func__);
221 return -EINVAL;
222 }
223
224 voltdm->pmic = pmic;
225
226 return 0;
227 }
228
229
230
231
232
233
234
235
236 int __init omap_voltage_late_init(void)
237 {
238 struct voltagedomain *voltdm;
239
240 if (list_empty(&voltdm_list)) {
241 pr_err("%s: Voltage driver support not added\n",
242 __func__);
243 return -EINVAL;
244 }
245
246 list_for_each_entry(voltdm, &voltdm_list, node) {
247 struct clk *sys_ck;
248
249 if (!voltdm->scalable)
250 continue;
251
252 sys_ck = clk_get(NULL, voltdm->sys_clk.name);
253 if (IS_ERR(sys_ck)) {
254 pr_warn("%s: Could not get sys clk.\n", __func__);
255 return -EINVAL;
256 }
257 voltdm->sys_clk.rate = clk_get_rate(sys_ck);
258 WARN_ON(!voltdm->sys_clk.rate);
259 clk_put(sys_ck);
260
261 if (voltdm->vc) {
262 voltdm->scale = omap_vc_bypass_scale;
263 omap_vc_init_channel(voltdm);
264 }
265
266 if (voltdm->vp) {
267 voltdm->scale = omap_vp_forceupdate_scale;
268 omap_vp_init(voltdm);
269 }
270 }
271
272 return 0;
273 }
274
275 static struct voltagedomain *_voltdm_lookup(const char *name)
276 {
277 struct voltagedomain *voltdm, *temp_voltdm;
278
279 voltdm = NULL;
280
281 list_for_each_entry(temp_voltdm, &voltdm_list, node) {
282 if (!strcmp(name, temp_voltdm->name)) {
283 voltdm = temp_voltdm;
284 break;
285 }
286 }
287
288 return voltdm;
289 }
290
291 static int _voltdm_register(struct voltagedomain *voltdm)
292 {
293 if (!voltdm || !voltdm->name)
294 return -EINVAL;
295
296 list_add(&voltdm->node, &voltdm_list);
297
298 pr_debug("voltagedomain: registered %s\n", voltdm->name);
299
300 return 0;
301 }
302
303
304
305
306
307
308
309
310 struct voltagedomain *voltdm_lookup(const char *name)
311 {
312 struct voltagedomain *voltdm ;
313
314 if (!name)
315 return NULL;
316
317 voltdm = _voltdm_lookup(name);
318
319 return voltdm;
320 }
321
322
323
324
325
326
327
328
329
330
331 void voltdm_init(struct voltagedomain **voltdms)
332 {
333 struct voltagedomain **v;
334
335 if (voltdms) {
336 for (v = voltdms; *v; v++)
337 _voltdm_register(*v);
338 }
339 }