2 * Copyright (C) ST-Ericsson SA 2010
4 * License Terms: GNU General Public License v2
5 * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
6 * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
8 * Power domain regulators on DB8500
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/err.h>
14 #include <linux/spinlock.h>
15 #include <linux/platform_device.h>
16 #include <linux/mfd/dbx500-prcmu.h>
17 #include <linux/regulator/driver.h>
18 #include <linux/regulator/machine.h>
19 #include <linux/regulator/db8500-prcmu.h>
20 #include <linux/module.h>
21 #include "dbx500-prcmu.h"
23 static int db8500_regulator_enable(struct regulator_dev
*rdev
)
25 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
30 dev_vdbg(rdev_get_dev(rdev
), "regulator-%s-enable\n",
33 if (!info
->is_enabled
) {
34 info
->is_enabled
= true;
35 if (!info
->exclude_from_power_state
)
36 power_state_active_enable();
42 static int db8500_regulator_disable(struct regulator_dev
*rdev
)
44 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
50 dev_vdbg(rdev_get_dev(rdev
), "regulator-%s-disable\n",
53 if (info
->is_enabled
) {
54 info
->is_enabled
= false;
55 if (!info
->exclude_from_power_state
)
56 ret
= power_state_active_disable();
62 static int db8500_regulator_is_enabled(struct regulator_dev
*rdev
)
64 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
69 dev_vdbg(rdev_get_dev(rdev
), "regulator-%s-is_enabled (is_enabled):"
70 " %i\n", info
->desc
.name
, info
->is_enabled
);
72 return info
->is_enabled
;
75 /* db8500 regulator operations */
76 static struct regulator_ops db8500_regulator_ops
= {
77 .enable
= db8500_regulator_enable
,
78 .disable
= db8500_regulator_disable
,
79 .is_enabled
= db8500_regulator_is_enabled
,
85 static bool epod_on
[NUM_EPOD_ID
];
86 static bool epod_ramret
[NUM_EPOD_ID
];
88 static int enable_epod(u16 epod_id
, bool ramret
)
93 if (!epod_on
[epod_id
]) {
94 ret
= prcmu_set_epod(epod_id
, EPOD_STATE_RAMRET
);
98 epod_ramret
[epod_id
] = true;
100 ret
= prcmu_set_epod(epod_id
, EPOD_STATE_ON
);
103 epod_on
[epod_id
] = true;
109 static int disable_epod(u16 epod_id
, bool ramret
)
114 if (!epod_on
[epod_id
]) {
115 ret
= prcmu_set_epod(epod_id
, EPOD_STATE_OFF
);
119 epod_ramret
[epod_id
] = false;
121 if (epod_ramret
[epod_id
]) {
122 ret
= prcmu_set_epod(epod_id
, EPOD_STATE_RAMRET
);
126 ret
= prcmu_set_epod(epod_id
, EPOD_STATE_OFF
);
130 epod_on
[epod_id
] = false;
139 static int db8500_regulator_switch_enable(struct regulator_dev
*rdev
)
141 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
147 dev_vdbg(rdev_get_dev(rdev
), "regulator-switch-%s-enable\n",
150 ret
= enable_epod(info
->epod_id
, info
->is_ramret
);
152 dev_err(rdev_get_dev(rdev
),
153 "regulator-switch-%s-enable: prcmu call failed\n",
158 info
->is_enabled
= true;
163 static int db8500_regulator_switch_disable(struct regulator_dev
*rdev
)
165 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
171 dev_vdbg(rdev_get_dev(rdev
), "regulator-switch-%s-disable\n",
174 ret
= disable_epod(info
->epod_id
, info
->is_ramret
);
176 dev_err(rdev_get_dev(rdev
),
177 "regulator_switch-%s-disable: prcmu call failed\n",
182 info
->is_enabled
= 0;
187 static int db8500_regulator_switch_is_enabled(struct regulator_dev
*rdev
)
189 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
194 dev_vdbg(rdev_get_dev(rdev
),
195 "regulator-switch-%s-is_enabled (is_enabled): %i\n",
196 info
->desc
.name
, info
->is_enabled
);
198 return info
->is_enabled
;
201 static struct regulator_ops db8500_regulator_switch_ops
= {
202 .enable
= db8500_regulator_switch_enable
,
203 .disable
= db8500_regulator_switch_disable
,
204 .is_enabled
= db8500_regulator_switch_is_enabled
,
208 * Regulator information
210 static struct dbx500_regulator_info
211 dbx500_regulator_info
[DB8500_NUM_REGULATORS
] = {
212 [DB8500_REGULATOR_VAPE
] = {
214 .name
= "db8500-vape",
215 .id
= DB8500_REGULATOR_VAPE
,
216 .ops
= &db8500_regulator_ops
,
217 .type
= REGULATOR_VOLTAGE
,
218 .owner
= THIS_MODULE
,
221 [DB8500_REGULATOR_VARM
] = {
223 .name
= "db8500-varm",
224 .id
= DB8500_REGULATOR_VARM
,
225 .ops
= &db8500_regulator_ops
,
226 .type
= REGULATOR_VOLTAGE
,
227 .owner
= THIS_MODULE
,
230 [DB8500_REGULATOR_VMODEM
] = {
232 .name
= "db8500-vmodem",
233 .id
= DB8500_REGULATOR_VMODEM
,
234 .ops
= &db8500_regulator_ops
,
235 .type
= REGULATOR_VOLTAGE
,
236 .owner
= THIS_MODULE
,
239 [DB8500_REGULATOR_VPLL
] = {
241 .name
= "db8500-vpll",
242 .id
= DB8500_REGULATOR_VPLL
,
243 .ops
= &db8500_regulator_ops
,
244 .type
= REGULATOR_VOLTAGE
,
245 .owner
= THIS_MODULE
,
248 [DB8500_REGULATOR_VSMPS1
] = {
250 .name
= "db8500-vsmps1",
251 .id
= DB8500_REGULATOR_VSMPS1
,
252 .ops
= &db8500_regulator_ops
,
253 .type
= REGULATOR_VOLTAGE
,
254 .owner
= THIS_MODULE
,
257 [DB8500_REGULATOR_VSMPS2
] = {
259 .name
= "db8500-vsmps2",
260 .id
= DB8500_REGULATOR_VSMPS2
,
261 .ops
= &db8500_regulator_ops
,
262 .type
= REGULATOR_VOLTAGE
,
263 .owner
= THIS_MODULE
,
265 .exclude_from_power_state
= true,
267 [DB8500_REGULATOR_VSMPS3
] = {
269 .name
= "db8500-vsmps3",
270 .id
= DB8500_REGULATOR_VSMPS3
,
271 .ops
= &db8500_regulator_ops
,
272 .type
= REGULATOR_VOLTAGE
,
273 .owner
= THIS_MODULE
,
276 [DB8500_REGULATOR_VRF1
] = {
278 .name
= "db8500-vrf1",
279 .id
= DB8500_REGULATOR_VRF1
,
280 .ops
= &db8500_regulator_ops
,
281 .type
= REGULATOR_VOLTAGE
,
282 .owner
= THIS_MODULE
,
285 [DB8500_REGULATOR_SWITCH_SVAMMDSP
] = {
287 .name
= "db8500-sva-mmdsp",
288 .id
= DB8500_REGULATOR_SWITCH_SVAMMDSP
,
289 .ops
= &db8500_regulator_switch_ops
,
290 .type
= REGULATOR_VOLTAGE
,
291 .owner
= THIS_MODULE
,
293 .epod_id
= EPOD_ID_SVAMMDSP
,
295 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET
] = {
297 .name
= "db8500-sva-mmdsp-ret",
298 .id
= DB8500_REGULATOR_SWITCH_SVAMMDSPRET
,
299 .ops
= &db8500_regulator_switch_ops
,
300 .type
= REGULATOR_VOLTAGE
,
301 .owner
= THIS_MODULE
,
303 .epod_id
= EPOD_ID_SVAMMDSP
,
306 [DB8500_REGULATOR_SWITCH_SVAPIPE
] = {
308 .name
= "db8500-sva-pipe",
309 .id
= DB8500_REGULATOR_SWITCH_SVAPIPE
,
310 .ops
= &db8500_regulator_switch_ops
,
311 .type
= REGULATOR_VOLTAGE
,
312 .owner
= THIS_MODULE
,
314 .epod_id
= EPOD_ID_SVAPIPE
,
316 [DB8500_REGULATOR_SWITCH_SIAMMDSP
] = {
318 .name
= "db8500-sia-mmdsp",
319 .id
= DB8500_REGULATOR_SWITCH_SIAMMDSP
,
320 .ops
= &db8500_regulator_switch_ops
,
321 .type
= REGULATOR_VOLTAGE
,
322 .owner
= THIS_MODULE
,
324 .epod_id
= EPOD_ID_SIAMMDSP
,
326 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET
] = {
328 .name
= "db8500-sia-mmdsp-ret",
329 .id
= DB8500_REGULATOR_SWITCH_SIAMMDSPRET
,
330 .ops
= &db8500_regulator_switch_ops
,
331 .type
= REGULATOR_VOLTAGE
,
332 .owner
= THIS_MODULE
,
334 .epod_id
= EPOD_ID_SIAMMDSP
,
337 [DB8500_REGULATOR_SWITCH_SIAPIPE
] = {
339 .name
= "db8500-sia-pipe",
340 .id
= DB8500_REGULATOR_SWITCH_SIAPIPE
,
341 .ops
= &db8500_regulator_switch_ops
,
342 .type
= REGULATOR_VOLTAGE
,
343 .owner
= THIS_MODULE
,
345 .epod_id
= EPOD_ID_SIAPIPE
,
347 [DB8500_REGULATOR_SWITCH_SGA
] = {
349 .name
= "db8500-sga",
350 .id
= DB8500_REGULATOR_SWITCH_SGA
,
351 .ops
= &db8500_regulator_switch_ops
,
352 .type
= REGULATOR_VOLTAGE
,
353 .owner
= THIS_MODULE
,
355 .epod_id
= EPOD_ID_SGA
,
357 [DB8500_REGULATOR_SWITCH_B2R2_MCDE
] = {
359 .name
= "db8500-b2r2-mcde",
360 .id
= DB8500_REGULATOR_SWITCH_B2R2_MCDE
,
361 .ops
= &db8500_regulator_switch_ops
,
362 .type
= REGULATOR_VOLTAGE
,
363 .owner
= THIS_MODULE
,
365 .epod_id
= EPOD_ID_B2R2_MCDE
,
367 [DB8500_REGULATOR_SWITCH_ESRAM12
] = {
369 .name
= "db8500-esram12",
370 .id
= DB8500_REGULATOR_SWITCH_ESRAM12
,
371 .ops
= &db8500_regulator_switch_ops
,
372 .type
= REGULATOR_VOLTAGE
,
373 .owner
= THIS_MODULE
,
375 .epod_id
= EPOD_ID_ESRAM12
,
378 [DB8500_REGULATOR_SWITCH_ESRAM12RET
] = {
380 .name
= "db8500-esram12-ret",
381 .id
= DB8500_REGULATOR_SWITCH_ESRAM12RET
,
382 .ops
= &db8500_regulator_switch_ops
,
383 .type
= REGULATOR_VOLTAGE
,
384 .owner
= THIS_MODULE
,
386 .epod_id
= EPOD_ID_ESRAM12
,
389 [DB8500_REGULATOR_SWITCH_ESRAM34
] = {
391 .name
= "db8500-esram34",
392 .id
= DB8500_REGULATOR_SWITCH_ESRAM34
,
393 .ops
= &db8500_regulator_switch_ops
,
394 .type
= REGULATOR_VOLTAGE
,
395 .owner
= THIS_MODULE
,
397 .epod_id
= EPOD_ID_ESRAM34
,
400 [DB8500_REGULATOR_SWITCH_ESRAM34RET
] = {
402 .name
= "db8500-esram34-ret",
403 .id
= DB8500_REGULATOR_SWITCH_ESRAM34RET
,
404 .ops
= &db8500_regulator_switch_ops
,
405 .type
= REGULATOR_VOLTAGE
,
406 .owner
= THIS_MODULE
,
408 .epod_id
= EPOD_ID_ESRAM34
,
413 static int __devinit
db8500_regulator_probe(struct platform_device
*pdev
)
415 struct regulator_init_data
*db8500_init_data
=
416 dev_get_platdata(&pdev
->dev
);
419 /* register all regulators */
420 for (i
= 0; i
< ARRAY_SIZE(dbx500_regulator_info
); i
++) {
421 struct dbx500_regulator_info
*info
;
422 struct regulator_init_data
*init_data
= &db8500_init_data
[i
];
424 /* assign per-regulator data */
425 info
= &dbx500_regulator_info
[i
];
426 info
->dev
= &pdev
->dev
;
428 /* register with the regulator framework */
429 info
->rdev
= regulator_register(&info
->desc
, &pdev
->dev
,
430 init_data
, info
, NULL
);
431 if (IS_ERR(info
->rdev
)) {
432 err
= PTR_ERR(info
->rdev
);
433 dev_err(&pdev
->dev
, "failed to register %s: err %i\n",
434 info
->desc
.name
, err
);
436 /* if failing, unregister all earlier regulators */
438 info
= &dbx500_regulator_info
[i
];
439 regulator_unregister(info
->rdev
);
444 dev_dbg(rdev_get_dev(info
->rdev
),
445 "regulator-%s-probed\n", info
->desc
.name
);
447 err
= ux500_regulator_debug_init(pdev
,
448 dbx500_regulator_info
,
449 ARRAY_SIZE(dbx500_regulator_info
));
454 static int __exit
db8500_regulator_remove(struct platform_device
*pdev
)
458 ux500_regulator_debug_exit();
460 for (i
= 0; i
< ARRAY_SIZE(dbx500_regulator_info
); i
++) {
461 struct dbx500_regulator_info
*info
;
462 info
= &dbx500_regulator_info
[i
];
464 dev_vdbg(rdev_get_dev(info
->rdev
),
465 "regulator-%s-remove\n", info
->desc
.name
);
467 regulator_unregister(info
->rdev
);
473 static struct platform_driver db8500_regulator_driver
= {
475 .name
= "db8500-prcmu-regulators",
476 .owner
= THIS_MODULE
,
478 .probe
= db8500_regulator_probe
,
479 .remove
= __exit_p(db8500_regulator_remove
),
482 static int __init
db8500_regulator_init(void)
484 return platform_driver_register(&db8500_regulator_driver
);
487 static void __exit
db8500_regulator_exit(void)
489 platform_driver_unregister(&db8500_regulator_driver
);
492 arch_initcall(db8500_regulator_init
);
493 module_exit(db8500_regulator_exit
);
495 MODULE_AUTHOR("STMicroelectronics/ST-Ericsson");
496 MODULE_DESCRIPTION("DB8500 regulator driver");
497 MODULE_LICENSE("GPL v2");