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/regulator/of_regulator.h>
22 #include <linux/module.h>
23 #include "dbx500-prcmu.h"
25 static int db8500_regulator_enable(struct regulator_dev
*rdev
)
27 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
32 dev_vdbg(rdev_get_dev(rdev
), "regulator-%s-enable\n",
35 if (!info
->is_enabled
) {
36 info
->is_enabled
= true;
37 if (!info
->exclude_from_power_state
)
38 power_state_active_enable();
44 static int db8500_regulator_disable(struct regulator_dev
*rdev
)
46 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
52 dev_vdbg(rdev_get_dev(rdev
), "regulator-%s-disable\n",
55 if (info
->is_enabled
) {
56 info
->is_enabled
= false;
57 if (!info
->exclude_from_power_state
)
58 ret
= power_state_active_disable();
64 static int db8500_regulator_is_enabled(struct regulator_dev
*rdev
)
66 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
71 dev_vdbg(rdev_get_dev(rdev
), "regulator-%s-is_enabled (is_enabled):"
72 " %i\n", info
->desc
.name
, info
->is_enabled
);
74 return info
->is_enabled
;
77 /* db8500 regulator operations */
78 static struct regulator_ops db8500_regulator_ops
= {
79 .enable
= db8500_regulator_enable
,
80 .disable
= db8500_regulator_disable
,
81 .is_enabled
= db8500_regulator_is_enabled
,
87 static bool epod_on
[NUM_EPOD_ID
];
88 static bool epod_ramret
[NUM_EPOD_ID
];
90 static int enable_epod(u16 epod_id
, bool ramret
)
95 if (!epod_on
[epod_id
]) {
96 ret
= prcmu_set_epod(epod_id
, EPOD_STATE_RAMRET
);
100 epod_ramret
[epod_id
] = true;
102 ret
= prcmu_set_epod(epod_id
, EPOD_STATE_ON
);
105 epod_on
[epod_id
] = true;
111 static int disable_epod(u16 epod_id
, bool ramret
)
116 if (!epod_on
[epod_id
]) {
117 ret
= prcmu_set_epod(epod_id
, EPOD_STATE_OFF
);
121 epod_ramret
[epod_id
] = false;
123 if (epod_ramret
[epod_id
]) {
124 ret
= prcmu_set_epod(epod_id
, EPOD_STATE_RAMRET
);
128 ret
= prcmu_set_epod(epod_id
, EPOD_STATE_OFF
);
132 epod_on
[epod_id
] = false;
141 static int db8500_regulator_switch_enable(struct regulator_dev
*rdev
)
143 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
149 dev_vdbg(rdev_get_dev(rdev
), "regulator-switch-%s-enable\n",
152 ret
= enable_epod(info
->epod_id
, info
->is_ramret
);
154 dev_err(rdev_get_dev(rdev
),
155 "regulator-switch-%s-enable: prcmu call failed\n",
160 info
->is_enabled
= true;
165 static int db8500_regulator_switch_disable(struct regulator_dev
*rdev
)
167 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
173 dev_vdbg(rdev_get_dev(rdev
), "regulator-switch-%s-disable\n",
176 ret
= disable_epod(info
->epod_id
, info
->is_ramret
);
178 dev_err(rdev_get_dev(rdev
),
179 "regulator_switch-%s-disable: prcmu call failed\n",
184 info
->is_enabled
= 0;
189 static int db8500_regulator_switch_is_enabled(struct regulator_dev
*rdev
)
191 struct dbx500_regulator_info
*info
= rdev_get_drvdata(rdev
);
196 dev_vdbg(rdev_get_dev(rdev
),
197 "regulator-switch-%s-is_enabled (is_enabled): %i\n",
198 info
->desc
.name
, info
->is_enabled
);
200 return info
->is_enabled
;
203 static struct regulator_ops db8500_regulator_switch_ops
= {
204 .enable
= db8500_regulator_switch_enable
,
205 .disable
= db8500_regulator_switch_disable
,
206 .is_enabled
= db8500_regulator_switch_is_enabled
,
210 * Regulator information
212 static struct dbx500_regulator_info
213 dbx500_regulator_info
[DB8500_NUM_REGULATORS
] = {
214 [DB8500_REGULATOR_VAPE
] = {
216 .name
= "db8500-vape",
217 .id
= DB8500_REGULATOR_VAPE
,
218 .ops
= &db8500_regulator_ops
,
219 .type
= REGULATOR_VOLTAGE
,
220 .owner
= THIS_MODULE
,
223 [DB8500_REGULATOR_VARM
] = {
225 .name
= "db8500-varm",
226 .id
= DB8500_REGULATOR_VARM
,
227 .ops
= &db8500_regulator_ops
,
228 .type
= REGULATOR_VOLTAGE
,
229 .owner
= THIS_MODULE
,
232 [DB8500_REGULATOR_VMODEM
] = {
234 .name
= "db8500-vmodem",
235 .id
= DB8500_REGULATOR_VMODEM
,
236 .ops
= &db8500_regulator_ops
,
237 .type
= REGULATOR_VOLTAGE
,
238 .owner
= THIS_MODULE
,
241 [DB8500_REGULATOR_VPLL
] = {
243 .name
= "db8500-vpll",
244 .id
= DB8500_REGULATOR_VPLL
,
245 .ops
= &db8500_regulator_ops
,
246 .type
= REGULATOR_VOLTAGE
,
247 .owner
= THIS_MODULE
,
250 [DB8500_REGULATOR_VSMPS1
] = {
252 .name
= "db8500-vsmps1",
253 .id
= DB8500_REGULATOR_VSMPS1
,
254 .ops
= &db8500_regulator_ops
,
255 .type
= REGULATOR_VOLTAGE
,
256 .owner
= THIS_MODULE
,
259 [DB8500_REGULATOR_VSMPS2
] = {
261 .name
= "db8500-vsmps2",
262 .id
= DB8500_REGULATOR_VSMPS2
,
263 .ops
= &db8500_regulator_ops
,
264 .type
= REGULATOR_VOLTAGE
,
265 .owner
= THIS_MODULE
,
267 .exclude_from_power_state
= true,
269 [DB8500_REGULATOR_VSMPS3
] = {
271 .name
= "db8500-vsmps3",
272 .id
= DB8500_REGULATOR_VSMPS3
,
273 .ops
= &db8500_regulator_ops
,
274 .type
= REGULATOR_VOLTAGE
,
275 .owner
= THIS_MODULE
,
278 [DB8500_REGULATOR_VRF1
] = {
280 .name
= "db8500-vrf1",
281 .id
= DB8500_REGULATOR_VRF1
,
282 .ops
= &db8500_regulator_ops
,
283 .type
= REGULATOR_VOLTAGE
,
284 .owner
= THIS_MODULE
,
287 [DB8500_REGULATOR_SWITCH_SVAMMDSP
] = {
289 .name
= "db8500-sva-mmdsp",
290 .id
= DB8500_REGULATOR_SWITCH_SVAMMDSP
,
291 .ops
= &db8500_regulator_switch_ops
,
292 .type
= REGULATOR_VOLTAGE
,
293 .owner
= THIS_MODULE
,
295 .epod_id
= EPOD_ID_SVAMMDSP
,
297 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET
] = {
299 .name
= "db8500-sva-mmdsp-ret",
300 .id
= DB8500_REGULATOR_SWITCH_SVAMMDSPRET
,
301 .ops
= &db8500_regulator_switch_ops
,
302 .type
= REGULATOR_VOLTAGE
,
303 .owner
= THIS_MODULE
,
305 .epod_id
= EPOD_ID_SVAMMDSP
,
308 [DB8500_REGULATOR_SWITCH_SVAPIPE
] = {
310 .name
= "db8500-sva-pipe",
311 .id
= DB8500_REGULATOR_SWITCH_SVAPIPE
,
312 .ops
= &db8500_regulator_switch_ops
,
313 .type
= REGULATOR_VOLTAGE
,
314 .owner
= THIS_MODULE
,
316 .epod_id
= EPOD_ID_SVAPIPE
,
318 [DB8500_REGULATOR_SWITCH_SIAMMDSP
] = {
320 .name
= "db8500-sia-mmdsp",
321 .id
= DB8500_REGULATOR_SWITCH_SIAMMDSP
,
322 .ops
= &db8500_regulator_switch_ops
,
323 .type
= REGULATOR_VOLTAGE
,
324 .owner
= THIS_MODULE
,
326 .epod_id
= EPOD_ID_SIAMMDSP
,
328 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET
] = {
330 .name
= "db8500-sia-mmdsp-ret",
331 .id
= DB8500_REGULATOR_SWITCH_SIAMMDSPRET
,
332 .ops
= &db8500_regulator_switch_ops
,
333 .type
= REGULATOR_VOLTAGE
,
334 .owner
= THIS_MODULE
,
336 .epod_id
= EPOD_ID_SIAMMDSP
,
339 [DB8500_REGULATOR_SWITCH_SIAPIPE
] = {
341 .name
= "db8500-sia-pipe",
342 .id
= DB8500_REGULATOR_SWITCH_SIAPIPE
,
343 .ops
= &db8500_regulator_switch_ops
,
344 .type
= REGULATOR_VOLTAGE
,
345 .owner
= THIS_MODULE
,
347 .epod_id
= EPOD_ID_SIAPIPE
,
349 [DB8500_REGULATOR_SWITCH_SGA
] = {
351 .name
= "db8500-sga",
352 .id
= DB8500_REGULATOR_SWITCH_SGA
,
353 .ops
= &db8500_regulator_switch_ops
,
354 .type
= REGULATOR_VOLTAGE
,
355 .owner
= THIS_MODULE
,
357 .epod_id
= EPOD_ID_SGA
,
359 [DB8500_REGULATOR_SWITCH_B2R2_MCDE
] = {
361 .name
= "db8500-b2r2-mcde",
362 .id
= DB8500_REGULATOR_SWITCH_B2R2_MCDE
,
363 .ops
= &db8500_regulator_switch_ops
,
364 .type
= REGULATOR_VOLTAGE
,
365 .owner
= THIS_MODULE
,
367 .epod_id
= EPOD_ID_B2R2_MCDE
,
369 [DB8500_REGULATOR_SWITCH_ESRAM12
] = {
371 .name
= "db8500-esram12",
372 .id
= DB8500_REGULATOR_SWITCH_ESRAM12
,
373 .ops
= &db8500_regulator_switch_ops
,
374 .type
= REGULATOR_VOLTAGE
,
375 .owner
= THIS_MODULE
,
377 .epod_id
= EPOD_ID_ESRAM12
,
380 [DB8500_REGULATOR_SWITCH_ESRAM12RET
] = {
382 .name
= "db8500-esram12-ret",
383 .id
= DB8500_REGULATOR_SWITCH_ESRAM12RET
,
384 .ops
= &db8500_regulator_switch_ops
,
385 .type
= REGULATOR_VOLTAGE
,
386 .owner
= THIS_MODULE
,
388 .epod_id
= EPOD_ID_ESRAM12
,
391 [DB8500_REGULATOR_SWITCH_ESRAM34
] = {
393 .name
= "db8500-esram34",
394 .id
= DB8500_REGULATOR_SWITCH_ESRAM34
,
395 .ops
= &db8500_regulator_switch_ops
,
396 .type
= REGULATOR_VOLTAGE
,
397 .owner
= THIS_MODULE
,
399 .epod_id
= EPOD_ID_ESRAM34
,
402 [DB8500_REGULATOR_SWITCH_ESRAM34RET
] = {
404 .name
= "db8500-esram34-ret",
405 .id
= DB8500_REGULATOR_SWITCH_ESRAM34RET
,
406 .ops
= &db8500_regulator_switch_ops
,
407 .type
= REGULATOR_VOLTAGE
,
408 .owner
= THIS_MODULE
,
410 .epod_id
= EPOD_ID_ESRAM34
,
415 static int db8500_regulator_register(struct platform_device
*pdev
,
416 struct regulator_init_data
*init_data
,
418 struct device_node
*np
)
420 struct dbx500_regulator_info
*info
;
421 struct regulator_config config
= { };
424 /* assign per-regulator data */
425 info
= &dbx500_regulator_info
[id
];
426 info
->dev
= &pdev
->dev
;
428 config
.dev
= &pdev
->dev
;
429 config
.init_data
= init_data
;
430 config
.driver_data
= info
;
433 /* register with the regulator framework */
434 info
->rdev
= regulator_register(&info
->desc
, &config
);
435 if (IS_ERR(info
->rdev
)) {
436 err
= PTR_ERR(info
->rdev
);
437 dev_err(&pdev
->dev
, "failed to register %s: err %i\n",
438 info
->desc
.name
, err
);
440 /* if failing, unregister all earlier regulators */
442 info
= &dbx500_regulator_info
[id
];
443 regulator_unregister(info
->rdev
);
448 dev_dbg(rdev_get_dev(info
->rdev
),
449 "regulator-%s-probed\n", info
->desc
.name
);
454 static struct of_regulator_match db8500_regulator_matches
[] = {
455 { .name
= "db8500_vape", .driver_data
= (void *) DB8500_REGULATOR_VAPE
, },
456 { .name
= "db8500_varm", .driver_data
= (void *) DB8500_REGULATOR_VARM
, },
457 { .name
= "db8500_vmodem", .driver_data
= (void *) DB8500_REGULATOR_VMODEM
, },
458 { .name
= "db8500_vpll", .driver_data
= (void *) DB8500_REGULATOR_VPLL
, },
459 { .name
= "db8500_vsmps1", .driver_data
= (void *) DB8500_REGULATOR_VSMPS1
, },
460 { .name
= "db8500_vsmps2", .driver_data
= (void *) DB8500_REGULATOR_VSMPS2
, },
461 { .name
= "db8500_vsmps3", .driver_data
= (void *) DB8500_REGULATOR_VSMPS3
, },
462 { .name
= "db8500_vrf1", .driver_data
= (void *) DB8500_REGULATOR_VRF1
, },
463 { .name
= "db8500_sva_mmdsp", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_SVAMMDSP
, },
464 { .name
= "db8500_sva_mmdsp_ret", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_SVAMMDSPRET
, },
465 { .name
= "db8500_sva_pipe", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_SVAPIPE
, },
466 { .name
= "db8500_sia_mmdsp", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_SIAMMDSP
, },
467 { .name
= "db8500_sia_mmdsp_ret", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_SIAMMDSPRET
, },
468 { .name
= "db8500_sia_pipe", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_SIAPIPE
, },
469 { .name
= "db8500_sga", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_SGA
, },
470 { .name
= "db8500_b2r2_mcde", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_B2R2_MCDE
, },
471 { .name
= "db8500_esram12", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_ESRAM12
, },
472 { .name
= "db8500_esram12_ret", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_ESRAM12RET
, },
473 { .name
= "db8500_esram34", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_ESRAM34
, },
474 { .name
= "db8500_esram34_ret", .driver_data
= (void *) DB8500_REGULATOR_SWITCH_ESRAM34RET
, },
478 db8500_regulator_of_probe(struct platform_device
*pdev
,
479 struct device_node
*np
)
483 for (i
= 0; i
< ARRAY_SIZE(dbx500_regulator_info
); i
++) {
484 err
= db8500_regulator_register(
485 pdev
, db8500_regulator_matches
[i
].init_data
,
486 i
, db8500_regulator_matches
[i
].of_node
);
494 static int db8500_regulator_probe(struct platform_device
*pdev
)
496 struct regulator_init_data
*db8500_init_data
=
497 dev_get_platdata(&pdev
->dev
);
498 struct device_node
*np
= pdev
->dev
.of_node
;
501 /* register all regulators */
503 err
= of_regulator_match(&pdev
->dev
, np
,
504 db8500_regulator_matches
,
505 ARRAY_SIZE(db8500_regulator_matches
));
508 "Error parsing regulator init data: %d\n", err
);
512 err
= db8500_regulator_of_probe(pdev
, np
);
516 for (i
= 0; i
< ARRAY_SIZE(dbx500_regulator_info
); i
++) {
517 err
= db8500_regulator_register(pdev
,
518 &db8500_init_data
[i
],
525 err
= ux500_regulator_debug_init(pdev
,
526 dbx500_regulator_info
,
527 ARRAY_SIZE(dbx500_regulator_info
));
531 static int db8500_regulator_remove(struct platform_device
*pdev
)
535 ux500_regulator_debug_exit();
537 for (i
= 0; i
< ARRAY_SIZE(dbx500_regulator_info
); i
++) {
538 struct dbx500_regulator_info
*info
;
539 info
= &dbx500_regulator_info
[i
];
541 dev_vdbg(rdev_get_dev(info
->rdev
),
542 "regulator-%s-remove\n", info
->desc
.name
);
544 regulator_unregister(info
->rdev
);
550 static struct platform_driver db8500_regulator_driver
= {
552 .name
= "db8500-prcmu-regulators",
553 .owner
= THIS_MODULE
,
555 .probe
= db8500_regulator_probe
,
556 .remove
= db8500_regulator_remove
,
559 static int __init
db8500_regulator_init(void)
561 return platform_driver_register(&db8500_regulator_driver
);
564 static void __exit
db8500_regulator_exit(void)
566 platform_driver_unregister(&db8500_regulator_driver
);
569 arch_initcall(db8500_regulator_init
);
570 module_exit(db8500_regulator_exit
);
572 MODULE_AUTHOR("STMicroelectronics/ST-Ericsson");
573 MODULE_DESCRIPTION("DB8500 regulator driver");
574 MODULE_LICENSE("GPL v2");