Blame view
drivers/regulator/db8500-prcmu.c
11.9 KB
0376148f3
|
1 |
// SPDX-License-Identifier: GPL-2.0-only |
1032fbfd7
|
2 3 4 |
/* * Copyright (C) ST-Ericsson SA 2010 * |
1032fbfd7
|
5 6 7 8 9 10 11 12 13 14 15 |
* Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson * * Power domain regulators on DB8500 */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/err.h> #include <linux/spinlock.h> #include <linux/platform_device.h> |
73180f85f
|
16 |
#include <linux/mfd/dbx500-prcmu.h> |
1032fbfd7
|
17 18 19 |
#include <linux/regulator/driver.h> #include <linux/regulator/machine.h> #include <linux/regulator/db8500-prcmu.h> |
1bdd670a3
|
20 21 |
#include <linux/regulator/of_regulator.h> #include <linux/of.h> |
65602c32e
|
22 |
#include <linux/module.h> |
38e968380
|
23 |
#include "dbx500-prcmu.h" |
1032fbfd7
|
24 25 26 |
static int db8500_regulator_enable(struct regulator_dev *rdev) { |
38e968380
|
27 |
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); |
1032fbfd7
|
28 29 30 31 32 33 34 |
if (info == NULL) return -EINVAL; dev_vdbg(rdev_get_dev(rdev), "regulator-%s-enable ", info->desc.name); |
38e968380
|
35 36 37 38 39 |
if (!info->is_enabled) { info->is_enabled = true; if (!info->exclude_from_power_state) power_state_active_enable(); } |
1032fbfd7
|
40 41 42 43 44 45 |
return 0; } static int db8500_regulator_disable(struct regulator_dev *rdev) { |
38e968380
|
46 |
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); |
1032fbfd7
|
47 48 49 50 51 52 53 54 |
int ret = 0; if (info == NULL) return -EINVAL; dev_vdbg(rdev_get_dev(rdev), "regulator-%s-disable ", info->desc.name); |
38e968380
|
55 56 57 58 59 |
if (info->is_enabled) { info->is_enabled = false; if (!info->exclude_from_power_state) ret = power_state_active_disable(); } |
1032fbfd7
|
60 61 62 63 64 65 |
return ret; } static int db8500_regulator_is_enabled(struct regulator_dev *rdev) { |
38e968380
|
66 |
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); |
1032fbfd7
|
67 68 69 70 71 72 73 74 75 76 77 78 |
if (info == NULL) return -EINVAL; dev_vdbg(rdev_get_dev(rdev), "regulator-%s-is_enabled (is_enabled):" " %i ", info->desc.name, info->is_enabled); return info->is_enabled; } /* db8500 regulator operations */ |
1a18195a2
|
79 |
static const struct regulator_ops db8500_regulator_ops = { |
1032fbfd7
|
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
.enable = db8500_regulator_enable, .disable = db8500_regulator_disable, .is_enabled = db8500_regulator_is_enabled, }; /* * EPOD control */ static bool epod_on[NUM_EPOD_ID]; static bool epod_ramret[NUM_EPOD_ID]; static int enable_epod(u16 epod_id, bool ramret) { int ret; if (ramret) { if (!epod_on[epod_id]) { ret = prcmu_set_epod(epod_id, EPOD_STATE_RAMRET); if (ret < 0) return ret; } epod_ramret[epod_id] = true; } else { ret = prcmu_set_epod(epod_id, EPOD_STATE_ON); if (ret < 0) return ret; epod_on[epod_id] = true; } return 0; } static int disable_epod(u16 epod_id, bool ramret) { int ret; if (ramret) { if (!epod_on[epod_id]) { ret = prcmu_set_epod(epod_id, EPOD_STATE_OFF); if (ret < 0) return ret; } epod_ramret[epod_id] = false; } else { if (epod_ramret[epod_id]) { ret = prcmu_set_epod(epod_id, EPOD_STATE_RAMRET); if (ret < 0) return ret; } else { ret = prcmu_set_epod(epod_id, EPOD_STATE_OFF); if (ret < 0) return ret; } epod_on[epod_id] = false; } return 0; } /* * Regulator switch */ static int db8500_regulator_switch_enable(struct regulator_dev *rdev) { |
38e968380
|
144 |
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); |
1032fbfd7
|
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
int ret; if (info == NULL) return -EINVAL; dev_vdbg(rdev_get_dev(rdev), "regulator-switch-%s-enable ", info->desc.name); ret = enable_epod(info->epod_id, info->is_ramret); if (ret < 0) { dev_err(rdev_get_dev(rdev), "regulator-switch-%s-enable: prcmu call failed ", info->desc.name); goto out; } info->is_enabled = true; out: return ret; } static int db8500_regulator_switch_disable(struct regulator_dev *rdev) { |
38e968380
|
170 |
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); |
1032fbfd7
|
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
int ret; if (info == NULL) return -EINVAL; dev_vdbg(rdev_get_dev(rdev), "regulator-switch-%s-disable ", info->desc.name); ret = disable_epod(info->epod_id, info->is_ramret); if (ret < 0) { dev_err(rdev_get_dev(rdev), "regulator_switch-%s-disable: prcmu call failed ", info->desc.name); goto out; } info->is_enabled = 0; out: return ret; } static int db8500_regulator_switch_is_enabled(struct regulator_dev *rdev) { |
38e968380
|
196 |
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev); |
1032fbfd7
|
197 198 199 200 201 202 203 204 205 206 207 |
if (info == NULL) return -EINVAL; dev_vdbg(rdev_get_dev(rdev), "regulator-switch-%s-is_enabled (is_enabled): %i ", info->desc.name, info->is_enabled); return info->is_enabled; } |
1a18195a2
|
208 |
static const struct regulator_ops db8500_regulator_switch_ops = { |
1032fbfd7
|
209 210 211 212 213 214 215 216 |
.enable = db8500_regulator_switch_enable, .disable = db8500_regulator_switch_disable, .is_enabled = db8500_regulator_switch_is_enabled, }; /* * Regulator information */ |
38e968380
|
217 218 |
static struct dbx500_regulator_info dbx500_regulator_info[DB8500_NUM_REGULATORS] = { |
1032fbfd7
|
219 220 221 |
[DB8500_REGULATOR_VAPE] = { .desc = { .name = "db8500-vape", |
92722a8fa
|
222 |
.of_match = of_match_ptr("db8500_vape"), |
1032fbfd7
|
223 224 225 226 227 228 229 230 231 |
.id = DB8500_REGULATOR_VAPE, .ops = &db8500_regulator_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, }, [DB8500_REGULATOR_VARM] = { .desc = { .name = "db8500-varm", |
92722a8fa
|
232 |
.of_match = of_match_ptr("db8500_varm"), |
1032fbfd7
|
233 234 235 236 237 238 239 240 241 |
.id = DB8500_REGULATOR_VARM, .ops = &db8500_regulator_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, }, [DB8500_REGULATOR_VMODEM] = { .desc = { .name = "db8500-vmodem", |
92722a8fa
|
242 |
.of_match = of_match_ptr("db8500_vmodem"), |
1032fbfd7
|
243 244 245 246 247 248 249 250 251 |
.id = DB8500_REGULATOR_VMODEM, .ops = &db8500_regulator_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, }, [DB8500_REGULATOR_VPLL] = { .desc = { .name = "db8500-vpll", |
92722a8fa
|
252 |
.of_match = of_match_ptr("db8500_vpll"), |
1032fbfd7
|
253 254 255 256 257 258 259 260 261 |
.id = DB8500_REGULATOR_VPLL, .ops = &db8500_regulator_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, }, [DB8500_REGULATOR_VSMPS1] = { .desc = { .name = "db8500-vsmps1", |
92722a8fa
|
262 |
.of_match = of_match_ptr("db8500_vsmps1"), |
1032fbfd7
|
263 264 265 266 267 268 269 270 271 |
.id = DB8500_REGULATOR_VSMPS1, .ops = &db8500_regulator_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, }, [DB8500_REGULATOR_VSMPS2] = { .desc = { .name = "db8500-vsmps2", |
92722a8fa
|
272 |
.of_match = of_match_ptr("db8500_vsmps2"), |
1032fbfd7
|
273 274 275 276 |
.id = DB8500_REGULATOR_VSMPS2, .ops = &db8500_regulator_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, |
eced9d5e9
|
277 278 |
.fixed_uV = 1800000, .n_voltages = 1, |
1032fbfd7
|
279 280 281 282 283 284 |
}, .exclude_from_power_state = true, }, [DB8500_REGULATOR_VSMPS3] = { .desc = { .name = "db8500-vsmps3", |
92722a8fa
|
285 |
.of_match = of_match_ptr("db8500_vsmps3"), |
1032fbfd7
|
286 287 288 289 290 291 292 293 294 |
.id = DB8500_REGULATOR_VSMPS3, .ops = &db8500_regulator_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, }, [DB8500_REGULATOR_VRF1] = { .desc = { .name = "db8500-vrf1", |
92722a8fa
|
295 |
.of_match = of_match_ptr("db8500_vrf1"), |
1032fbfd7
|
296 297 298 299 300 301 302 303 304 |
.id = DB8500_REGULATOR_VRF1, .ops = &db8500_regulator_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, }, [DB8500_REGULATOR_SWITCH_SVAMMDSP] = { .desc = { .name = "db8500-sva-mmdsp", |
92722a8fa
|
305 |
.of_match = of_match_ptr("db8500_sva_mmdsp"), |
1032fbfd7
|
306 307 308 309 310 311 312 313 314 315 |
.id = DB8500_REGULATOR_SWITCH_SVAMMDSP, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_SVAMMDSP, }, [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = { .desc = { .name = "db8500-sva-mmdsp-ret", |
92722a8fa
|
316 |
.of_match = of_match_ptr("db8500_sva_mmdsp_ret"), |
1032fbfd7
|
317 318 319 320 321 322 323 324 325 326 327 |
.id = DB8500_REGULATOR_SWITCH_SVAMMDSPRET, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_SVAMMDSP, .is_ramret = true, }, [DB8500_REGULATOR_SWITCH_SVAPIPE] = { .desc = { .name = "db8500-sva-pipe", |
92722a8fa
|
328 |
.of_match = of_match_ptr("db8500_sva_pipe"), |
1032fbfd7
|
329 330 331 332 333 334 335 336 337 338 |
.id = DB8500_REGULATOR_SWITCH_SVAPIPE, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_SVAPIPE, }, [DB8500_REGULATOR_SWITCH_SIAMMDSP] = { .desc = { .name = "db8500-sia-mmdsp", |
92722a8fa
|
339 |
.of_match = of_match_ptr("db8500_sia_mmdsp"), |
1032fbfd7
|
340 341 342 343 344 345 346 347 348 349 |
.id = DB8500_REGULATOR_SWITCH_SIAMMDSP, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_SIAMMDSP, }, [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = { .desc = { .name = "db8500-sia-mmdsp-ret", |
92722a8fa
|
350 |
.of_match = of_match_ptr("db8500_sia_mmdsp_ret"), |
1032fbfd7
|
351 352 353 354 355 356 357 358 359 360 361 |
.id = DB8500_REGULATOR_SWITCH_SIAMMDSPRET, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_SIAMMDSP, .is_ramret = true, }, [DB8500_REGULATOR_SWITCH_SIAPIPE] = { .desc = { .name = "db8500-sia-pipe", |
92722a8fa
|
362 |
.of_match = of_match_ptr("db8500_sia_pipe"), |
1032fbfd7
|
363 364 365 366 367 368 369 370 371 372 |
.id = DB8500_REGULATOR_SWITCH_SIAPIPE, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_SIAPIPE, }, [DB8500_REGULATOR_SWITCH_SGA] = { .desc = { .name = "db8500-sga", |
92722a8fa
|
373 |
.of_match = of_match_ptr("db8500_sga"), |
1032fbfd7
|
374 375 376 377 378 379 380 381 382 383 |
.id = DB8500_REGULATOR_SWITCH_SGA, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_SGA, }, [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = { .desc = { .name = "db8500-b2r2-mcde", |
92722a8fa
|
384 |
.of_match = of_match_ptr("db8500_b2r2_mcde"), |
1032fbfd7
|
385 386 387 388 389 390 391 392 393 394 |
.id = DB8500_REGULATOR_SWITCH_B2R2_MCDE, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_B2R2_MCDE, }, [DB8500_REGULATOR_SWITCH_ESRAM12] = { .desc = { .name = "db8500-esram12", |
92722a8fa
|
395 |
.of_match = of_match_ptr("db8500_esram12"), |
1032fbfd7
|
396 397 398 399 400 401 402 403 404 405 406 |
.id = DB8500_REGULATOR_SWITCH_ESRAM12, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_ESRAM12, .is_enabled = true, }, [DB8500_REGULATOR_SWITCH_ESRAM12RET] = { .desc = { .name = "db8500-esram12-ret", |
92722a8fa
|
407 |
.of_match = of_match_ptr("db8500_esram12_ret"), |
1032fbfd7
|
408 409 410 411 412 413 414 415 416 417 418 |
.id = DB8500_REGULATOR_SWITCH_ESRAM12RET, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_ESRAM12, .is_ramret = true, }, [DB8500_REGULATOR_SWITCH_ESRAM34] = { .desc = { .name = "db8500-esram34", |
92722a8fa
|
419 |
.of_match = of_match_ptr("db8500_esram34"), |
1032fbfd7
|
420 421 422 423 424 425 426 427 428 429 430 |
.id = DB8500_REGULATOR_SWITCH_ESRAM34, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_ESRAM34, .is_enabled = true, }, [DB8500_REGULATOR_SWITCH_ESRAM34RET] = { .desc = { .name = "db8500-esram34-ret", |
92722a8fa
|
431 |
.of_match = of_match_ptr("db8500_esram34_ret"), |
1032fbfd7
|
432 433 434 435 436 437 438 439 440 |
.id = DB8500_REGULATOR_SWITCH_ESRAM34RET, .ops = &db8500_regulator_switch_ops, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }, .epod_id = EPOD_ID_ESRAM34, .is_ramret = true, }, }; |
92722a8fa
|
441 |
static int db8500_regulator_probe(struct platform_device *pdev) |
8986cf885
|
442 |
{ |
92722a8fa
|
443 |
struct regulator_init_data *db8500_init_data; |
8986cf885
|
444 445 |
struct dbx500_regulator_info *info; struct regulator_config config = { }; |
2564002ab
|
446 |
struct regulator_dev *rdev; |
92722a8fa
|
447 |
int err, i; |
8986cf885
|
448 |
|
92722a8fa
|
449 |
db8500_init_data = dev_get_platdata(&pdev->dev); |
1bdd670a3
|
450 451 |
for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { |
92722a8fa
|
452 453 |
/* assign per-regulator data */ info = &dbx500_regulator_info[i]; |
92722a8fa
|
454 455 456 457 458 |
config.driver_data = info; config.dev = &pdev->dev; if (db8500_init_data) config.init_data = &db8500_init_data[i]; |
2564002ab
|
459 460 461 462 |
rdev = devm_regulator_register(&pdev->dev, &info->desc, &config); if (IS_ERR(rdev)) { err = PTR_ERR(rdev); |
92722a8fa
|
463 464 465 |
dev_err(&pdev->dev, "failed to register %s: err %i ", info->desc.name, err); |
1bdd670a3
|
466 |
return err; |
1bdd670a3
|
467 |
} |
92722a8fa
|
468 469 |
dev_dbg(&pdev->dev, "regulator-%s-probed ", info->desc.name); |
1032fbfd7
|
470 |
} |
1bdd670a3
|
471 |
|
92722a8fa
|
472 473 |
ux500_regulator_debug_init(pdev, dbx500_regulator_info, ARRAY_SIZE(dbx500_regulator_info)); |
8986cf885
|
474 |
return 0; |
1032fbfd7
|
475 |
} |
4ceb73ae5
|
476 |
static int db8500_regulator_remove(struct platform_device *pdev) |
1032fbfd7
|
477 |
{ |
38e968380
|
478 |
ux500_regulator_debug_exit(); |
1032fbfd7
|
479 480 481 482 483 484 |
return 0; } static struct platform_driver db8500_regulator_driver = { .driver = { .name = "db8500-prcmu-regulators", |
1032fbfd7
|
485 486 |
}, .probe = db8500_regulator_probe, |
4ceb73ae5
|
487 |
.remove = db8500_regulator_remove, |
1032fbfd7
|
488 489 490 491 |
}; static int __init db8500_regulator_init(void) { |
90609503b
|
492 |
return platform_driver_register(&db8500_regulator_driver); |
1032fbfd7
|
493 494 495 496 497 498 499 500 501 502 503 504 505 |
} static void __exit db8500_regulator_exit(void) { platform_driver_unregister(&db8500_regulator_driver); } arch_initcall(db8500_regulator_init); module_exit(db8500_regulator_exit); MODULE_AUTHOR("STMicroelectronics/ST-Ericsson"); MODULE_DESCRIPTION("DB8500 regulator driver"); MODULE_LICENSE("GPL v2"); |