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