1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) ST-Ericsson SA 2010
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 const 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 const 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 .of_match
= of_match_ptr("db8500_vape"),
218 .id
= DB8500_REGULATOR_VAPE
,
219 .ops
= &db8500_regulator_ops
,
220 .type
= REGULATOR_VOLTAGE
,
221 .owner
= THIS_MODULE
,
224 [DB8500_REGULATOR_VARM
] = {
226 .name
= "db8500-varm",
227 .of_match
= of_match_ptr("db8500_varm"),
228 .id
= DB8500_REGULATOR_VARM
,
229 .ops
= &db8500_regulator_ops
,
230 .type
= REGULATOR_VOLTAGE
,
231 .owner
= THIS_MODULE
,
234 [DB8500_REGULATOR_VMODEM
] = {
236 .name
= "db8500-vmodem",
237 .of_match
= of_match_ptr("db8500_vmodem"),
238 .id
= DB8500_REGULATOR_VMODEM
,
239 .ops
= &db8500_regulator_ops
,
240 .type
= REGULATOR_VOLTAGE
,
241 .owner
= THIS_MODULE
,
244 [DB8500_REGULATOR_VPLL
] = {
246 .name
= "db8500-vpll",
247 .of_match
= of_match_ptr("db8500_vpll"),
248 .id
= DB8500_REGULATOR_VPLL
,
249 .ops
= &db8500_regulator_ops
,
250 .type
= REGULATOR_VOLTAGE
,
251 .owner
= THIS_MODULE
,
254 [DB8500_REGULATOR_VSMPS1
] = {
256 .name
= "db8500-vsmps1",
257 .of_match
= of_match_ptr("db8500_vsmps1"),
258 .id
= DB8500_REGULATOR_VSMPS1
,
259 .ops
= &db8500_regulator_ops
,
260 .type
= REGULATOR_VOLTAGE
,
261 .owner
= THIS_MODULE
,
264 [DB8500_REGULATOR_VSMPS2
] = {
266 .name
= "db8500-vsmps2",
267 .of_match
= of_match_ptr("db8500_vsmps2"),
268 .id
= DB8500_REGULATOR_VSMPS2
,
269 .ops
= &db8500_regulator_ops
,
270 .type
= REGULATOR_VOLTAGE
,
271 .owner
= THIS_MODULE
,
275 .exclude_from_power_state
= true,
277 [DB8500_REGULATOR_VSMPS3
] = {
279 .name
= "db8500-vsmps3",
280 .of_match
= of_match_ptr("db8500_vsmps3"),
281 .id
= DB8500_REGULATOR_VSMPS3
,
282 .ops
= &db8500_regulator_ops
,
283 .type
= REGULATOR_VOLTAGE
,
284 .owner
= THIS_MODULE
,
287 [DB8500_REGULATOR_VRF1
] = {
289 .name
= "db8500-vrf1",
290 .of_match
= of_match_ptr("db8500_vrf1"),
291 .id
= DB8500_REGULATOR_VRF1
,
292 .ops
= &db8500_regulator_ops
,
293 .type
= REGULATOR_VOLTAGE
,
294 .owner
= THIS_MODULE
,
297 [DB8500_REGULATOR_SWITCH_SVAMMDSP
] = {
299 .name
= "db8500-sva-mmdsp",
300 .of_match
= of_match_ptr("db8500_sva_mmdsp"),
301 .id
= DB8500_REGULATOR_SWITCH_SVAMMDSP
,
302 .ops
= &db8500_regulator_switch_ops
,
303 .type
= REGULATOR_VOLTAGE
,
304 .owner
= THIS_MODULE
,
306 .epod_id
= EPOD_ID_SVAMMDSP
,
308 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET
] = {
310 .name
= "db8500-sva-mmdsp-ret",
311 .of_match
= of_match_ptr("db8500_sva_mmdsp_ret"),
312 .id
= DB8500_REGULATOR_SWITCH_SVAMMDSPRET
,
313 .ops
= &db8500_regulator_switch_ops
,
314 .type
= REGULATOR_VOLTAGE
,
315 .owner
= THIS_MODULE
,
317 .epod_id
= EPOD_ID_SVAMMDSP
,
320 [DB8500_REGULATOR_SWITCH_SVAPIPE
] = {
322 .name
= "db8500-sva-pipe",
323 .of_match
= of_match_ptr("db8500_sva_pipe"),
324 .id
= DB8500_REGULATOR_SWITCH_SVAPIPE
,
325 .ops
= &db8500_regulator_switch_ops
,
326 .type
= REGULATOR_VOLTAGE
,
327 .owner
= THIS_MODULE
,
329 .epod_id
= EPOD_ID_SVAPIPE
,
331 [DB8500_REGULATOR_SWITCH_SIAMMDSP
] = {
333 .name
= "db8500-sia-mmdsp",
334 .of_match
= of_match_ptr("db8500_sia_mmdsp"),
335 .id
= DB8500_REGULATOR_SWITCH_SIAMMDSP
,
336 .ops
= &db8500_regulator_switch_ops
,
337 .type
= REGULATOR_VOLTAGE
,
338 .owner
= THIS_MODULE
,
340 .epod_id
= EPOD_ID_SIAMMDSP
,
342 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET
] = {
344 .name
= "db8500-sia-mmdsp-ret",
345 .of_match
= of_match_ptr("db8500_sia_mmdsp_ret"),
346 .id
= DB8500_REGULATOR_SWITCH_SIAMMDSPRET
,
347 .ops
= &db8500_regulator_switch_ops
,
348 .type
= REGULATOR_VOLTAGE
,
349 .owner
= THIS_MODULE
,
351 .epod_id
= EPOD_ID_SIAMMDSP
,
354 [DB8500_REGULATOR_SWITCH_SIAPIPE
] = {
356 .name
= "db8500-sia-pipe",
357 .of_match
= of_match_ptr("db8500_sia_pipe"),
358 .id
= DB8500_REGULATOR_SWITCH_SIAPIPE
,
359 .ops
= &db8500_regulator_switch_ops
,
360 .type
= REGULATOR_VOLTAGE
,
361 .owner
= THIS_MODULE
,
363 .epod_id
= EPOD_ID_SIAPIPE
,
365 [DB8500_REGULATOR_SWITCH_SGA
] = {
367 .name
= "db8500-sga",
368 .of_match
= of_match_ptr("db8500_sga"),
369 .id
= DB8500_REGULATOR_SWITCH_SGA
,
370 .ops
= &db8500_regulator_switch_ops
,
371 .type
= REGULATOR_VOLTAGE
,
372 .owner
= THIS_MODULE
,
374 .epod_id
= EPOD_ID_SGA
,
376 [DB8500_REGULATOR_SWITCH_B2R2_MCDE
] = {
378 .name
= "db8500-b2r2-mcde",
379 .of_match
= of_match_ptr("db8500_b2r2_mcde"),
380 .id
= DB8500_REGULATOR_SWITCH_B2R2_MCDE
,
381 .ops
= &db8500_regulator_switch_ops
,
382 .type
= REGULATOR_VOLTAGE
,
383 .owner
= THIS_MODULE
,
385 .epod_id
= EPOD_ID_B2R2_MCDE
,
387 [DB8500_REGULATOR_SWITCH_ESRAM12
] = {
389 .name
= "db8500-esram12",
390 .of_match
= of_match_ptr("db8500_esram12"),
391 .id
= DB8500_REGULATOR_SWITCH_ESRAM12
,
392 .ops
= &db8500_regulator_switch_ops
,
393 .type
= REGULATOR_VOLTAGE
,
394 .owner
= THIS_MODULE
,
396 .epod_id
= EPOD_ID_ESRAM12
,
399 [DB8500_REGULATOR_SWITCH_ESRAM12RET
] = {
401 .name
= "db8500-esram12-ret",
402 .of_match
= of_match_ptr("db8500_esram12_ret"),
403 .id
= DB8500_REGULATOR_SWITCH_ESRAM12RET
,
404 .ops
= &db8500_regulator_switch_ops
,
405 .type
= REGULATOR_VOLTAGE
,
406 .owner
= THIS_MODULE
,
408 .epod_id
= EPOD_ID_ESRAM12
,
411 [DB8500_REGULATOR_SWITCH_ESRAM34
] = {
413 .name
= "db8500-esram34",
414 .of_match
= of_match_ptr("db8500_esram34"),
415 .id
= DB8500_REGULATOR_SWITCH_ESRAM34
,
416 .ops
= &db8500_regulator_switch_ops
,
417 .type
= REGULATOR_VOLTAGE
,
418 .owner
= THIS_MODULE
,
420 .epod_id
= EPOD_ID_ESRAM34
,
423 [DB8500_REGULATOR_SWITCH_ESRAM34RET
] = {
425 .name
= "db8500-esram34-ret",
426 .of_match
= of_match_ptr("db8500_esram34_ret"),
427 .id
= DB8500_REGULATOR_SWITCH_ESRAM34RET
,
428 .ops
= &db8500_regulator_switch_ops
,
429 .type
= REGULATOR_VOLTAGE
,
430 .owner
= THIS_MODULE
,
432 .epod_id
= EPOD_ID_ESRAM34
,
437 static int db8500_regulator_probe(struct platform_device
*pdev
)
439 struct regulator_init_data
*db8500_init_data
;
440 struct dbx500_regulator_info
*info
;
441 struct regulator_config config
= { };
442 struct regulator_dev
*rdev
;
445 db8500_init_data
= dev_get_platdata(&pdev
->dev
);
447 for (i
= 0; i
< ARRAY_SIZE(dbx500_regulator_info
); i
++) {
448 /* assign per-regulator data */
449 info
= &dbx500_regulator_info
[i
];
451 config
.driver_data
= info
;
452 config
.dev
= &pdev
->dev
;
453 if (db8500_init_data
)
454 config
.init_data
= &db8500_init_data
[i
];
456 rdev
= devm_regulator_register(&pdev
->dev
, &info
->desc
,
460 dev_err(&pdev
->dev
, "failed to register %s: err %i\n",
461 info
->desc
.name
, err
);
464 dev_dbg(&pdev
->dev
, "regulator-%s-probed\n", info
->desc
.name
);
467 ux500_regulator_debug_init(pdev
, dbx500_regulator_info
,
468 ARRAY_SIZE(dbx500_regulator_info
));
472 static int db8500_regulator_remove(struct platform_device
*pdev
)
474 ux500_regulator_debug_exit();
479 static struct platform_driver db8500_regulator_driver
= {
481 .name
= "db8500-prcmu-regulators",
483 .probe
= db8500_regulator_probe
,
484 .remove
= db8500_regulator_remove
,
487 static int __init
db8500_regulator_init(void)
489 return platform_driver_register(&db8500_regulator_driver
);
492 static void __exit
db8500_regulator_exit(void)
494 platform_driver_unregister(&db8500_regulator_driver
);
497 arch_initcall(db8500_regulator_init
);
498 module_exit(db8500_regulator_exit
);
500 MODULE_AUTHOR("STMicroelectronics/ST-Ericsson");
501 MODULE_DESCRIPTION("DB8500 regulator driver");
502 MODULE_LICENSE("GPL v2");