0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/kernel.h>
0012 #include <linux/init.h>
0013 #include <linux/err.h>
0014 #include <linux/spinlock.h>
0015 #include <linux/platform_device.h>
0016 #include <linux/mfd/dbx500-prcmu.h>
0017 #include <linux/regulator/driver.h>
0018 #include <linux/regulator/machine.h>
0019 #include <linux/regulator/db8500-prcmu.h>
0020 #include <linux/regulator/of_regulator.h>
0021 #include <linux/of.h>
0022 #include <linux/module.h>
0023 #include "dbx500-prcmu.h"
0024
0025 static int db8500_regulator_enable(struct regulator_dev *rdev)
0026 {
0027 struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
0028
0029 if (info == NULL)
0030 return -EINVAL;
0031
0032 dev_vdbg(rdev_get_dev(rdev), "regulator-%s-enable\n",
0033 info->desc.name);
0034
0035 if (!info->is_enabled) {
0036 info->is_enabled = true;
0037 if (!info->exclude_from_power_state)
0038 power_state_active_enable();
0039 }
0040
0041 return 0;
0042 }
0043
0044 static int db8500_regulator_disable(struct regulator_dev *rdev)
0045 {
0046 struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
0047 int ret = 0;
0048
0049 if (info == NULL)
0050 return -EINVAL;
0051
0052 dev_vdbg(rdev_get_dev(rdev), "regulator-%s-disable\n",
0053 info->desc.name);
0054
0055 if (info->is_enabled) {
0056 info->is_enabled = false;
0057 if (!info->exclude_from_power_state)
0058 ret = power_state_active_disable();
0059 }
0060
0061 return ret;
0062 }
0063
0064 static int db8500_regulator_is_enabled(struct regulator_dev *rdev)
0065 {
0066 struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
0067
0068 if (info == NULL)
0069 return -EINVAL;
0070
0071 dev_vdbg(rdev_get_dev(rdev), "regulator-%s-is_enabled (is_enabled):"
0072 " %i\n", info->desc.name, info->is_enabled);
0073
0074 return info->is_enabled;
0075 }
0076
0077
0078 static const struct regulator_ops db8500_regulator_ops = {
0079 .enable = db8500_regulator_enable,
0080 .disable = db8500_regulator_disable,
0081 .is_enabled = db8500_regulator_is_enabled,
0082 };
0083
0084
0085
0086
0087 static bool epod_on[NUM_EPOD_ID];
0088 static bool epod_ramret[NUM_EPOD_ID];
0089
0090 static int enable_epod(u16 epod_id, bool ramret)
0091 {
0092 int ret;
0093
0094 if (ramret) {
0095 if (!epod_on[epod_id]) {
0096 ret = prcmu_set_epod(epod_id, EPOD_STATE_RAMRET);
0097 if (ret < 0)
0098 return ret;
0099 }
0100 epod_ramret[epod_id] = true;
0101 } else {
0102 ret = prcmu_set_epod(epod_id, EPOD_STATE_ON);
0103 if (ret < 0)
0104 return ret;
0105 epod_on[epod_id] = true;
0106 }
0107
0108 return 0;
0109 }
0110
0111 static int disable_epod(u16 epod_id, bool ramret)
0112 {
0113 int ret;
0114
0115 if (ramret) {
0116 if (!epod_on[epod_id]) {
0117 ret = prcmu_set_epod(epod_id, EPOD_STATE_OFF);
0118 if (ret < 0)
0119 return ret;
0120 }
0121 epod_ramret[epod_id] = false;
0122 } else {
0123 if (epod_ramret[epod_id]) {
0124 ret = prcmu_set_epod(epod_id, EPOD_STATE_RAMRET);
0125 if (ret < 0)
0126 return ret;
0127 } else {
0128 ret = prcmu_set_epod(epod_id, EPOD_STATE_OFF);
0129 if (ret < 0)
0130 return ret;
0131 }
0132 epod_on[epod_id] = false;
0133 }
0134
0135 return 0;
0136 }
0137
0138
0139
0140
0141 static int db8500_regulator_switch_enable(struct regulator_dev *rdev)
0142 {
0143 struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
0144 int ret;
0145
0146 if (info == NULL)
0147 return -EINVAL;
0148
0149 dev_vdbg(rdev_get_dev(rdev), "regulator-switch-%s-enable\n",
0150 info->desc.name);
0151
0152 ret = enable_epod(info->epod_id, info->is_ramret);
0153 if (ret < 0) {
0154 dev_err(rdev_get_dev(rdev),
0155 "regulator-switch-%s-enable: prcmu call failed\n",
0156 info->desc.name);
0157 goto out;
0158 }
0159
0160 info->is_enabled = true;
0161 out:
0162 return ret;
0163 }
0164
0165 static int db8500_regulator_switch_disable(struct regulator_dev *rdev)
0166 {
0167 struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
0168 int ret;
0169
0170 if (info == NULL)
0171 return -EINVAL;
0172
0173 dev_vdbg(rdev_get_dev(rdev), "regulator-switch-%s-disable\n",
0174 info->desc.name);
0175
0176 ret = disable_epod(info->epod_id, info->is_ramret);
0177 if (ret < 0) {
0178 dev_err(rdev_get_dev(rdev),
0179 "regulator_switch-%s-disable: prcmu call failed\n",
0180 info->desc.name);
0181 goto out;
0182 }
0183
0184 info->is_enabled = false;
0185 out:
0186 return ret;
0187 }
0188
0189 static int db8500_regulator_switch_is_enabled(struct regulator_dev *rdev)
0190 {
0191 struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
0192
0193 if (info == NULL)
0194 return -EINVAL;
0195
0196 dev_vdbg(rdev_get_dev(rdev),
0197 "regulator-switch-%s-is_enabled (is_enabled): %i\n",
0198 info->desc.name, info->is_enabled);
0199
0200 return info->is_enabled;
0201 }
0202
0203 static const struct regulator_ops db8500_regulator_switch_ops = {
0204 .enable = db8500_regulator_switch_enable,
0205 .disable = db8500_regulator_switch_disable,
0206 .is_enabled = db8500_regulator_switch_is_enabled,
0207 };
0208
0209
0210
0211
0212 static struct dbx500_regulator_info
0213 dbx500_regulator_info[DB8500_NUM_REGULATORS] = {
0214 [DB8500_REGULATOR_VAPE] = {
0215 .desc = {
0216 .name = "db8500-vape",
0217 .of_match = of_match_ptr("db8500_vape"),
0218 .id = DB8500_REGULATOR_VAPE,
0219 .ops = &db8500_regulator_ops,
0220 .type = REGULATOR_VOLTAGE,
0221 .owner = THIS_MODULE,
0222 },
0223 },
0224 [DB8500_REGULATOR_VARM] = {
0225 .desc = {
0226 .name = "db8500-varm",
0227 .of_match = of_match_ptr("db8500_varm"),
0228 .id = DB8500_REGULATOR_VARM,
0229 .ops = &db8500_regulator_ops,
0230 .type = REGULATOR_VOLTAGE,
0231 .owner = THIS_MODULE,
0232 },
0233 },
0234 [DB8500_REGULATOR_VMODEM] = {
0235 .desc = {
0236 .name = "db8500-vmodem",
0237 .of_match = of_match_ptr("db8500_vmodem"),
0238 .id = DB8500_REGULATOR_VMODEM,
0239 .ops = &db8500_regulator_ops,
0240 .type = REGULATOR_VOLTAGE,
0241 .owner = THIS_MODULE,
0242 },
0243 },
0244 [DB8500_REGULATOR_VPLL] = {
0245 .desc = {
0246 .name = "db8500-vpll",
0247 .of_match = of_match_ptr("db8500_vpll"),
0248 .id = DB8500_REGULATOR_VPLL,
0249 .ops = &db8500_regulator_ops,
0250 .type = REGULATOR_VOLTAGE,
0251 .owner = THIS_MODULE,
0252 },
0253 },
0254 [DB8500_REGULATOR_VSMPS1] = {
0255 .desc = {
0256 .name = "db8500-vsmps1",
0257 .of_match = of_match_ptr("db8500_vsmps1"),
0258 .id = DB8500_REGULATOR_VSMPS1,
0259 .ops = &db8500_regulator_ops,
0260 .type = REGULATOR_VOLTAGE,
0261 .owner = THIS_MODULE,
0262 },
0263 },
0264 [DB8500_REGULATOR_VSMPS2] = {
0265 .desc = {
0266 .name = "db8500-vsmps2",
0267 .of_match = of_match_ptr("db8500_vsmps2"),
0268 .id = DB8500_REGULATOR_VSMPS2,
0269 .ops = &db8500_regulator_ops,
0270 .type = REGULATOR_VOLTAGE,
0271 .owner = THIS_MODULE,
0272 .fixed_uV = 1800000,
0273 .n_voltages = 1,
0274 },
0275 .exclude_from_power_state = true,
0276 },
0277 [DB8500_REGULATOR_VSMPS3] = {
0278 .desc = {
0279 .name = "db8500-vsmps3",
0280 .of_match = of_match_ptr("db8500_vsmps3"),
0281 .id = DB8500_REGULATOR_VSMPS3,
0282 .ops = &db8500_regulator_ops,
0283 .type = REGULATOR_VOLTAGE,
0284 .owner = THIS_MODULE,
0285 },
0286 },
0287 [DB8500_REGULATOR_VRF1] = {
0288 .desc = {
0289 .name = "db8500-vrf1",
0290 .of_match = of_match_ptr("db8500_vrf1"),
0291 .id = DB8500_REGULATOR_VRF1,
0292 .ops = &db8500_regulator_ops,
0293 .type = REGULATOR_VOLTAGE,
0294 .owner = THIS_MODULE,
0295 },
0296 },
0297 [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {
0298 .desc = {
0299 .name = "db8500-sva-mmdsp",
0300 .of_match = of_match_ptr("db8500_sva_mmdsp"),
0301 .id = DB8500_REGULATOR_SWITCH_SVAMMDSP,
0302 .ops = &db8500_regulator_switch_ops,
0303 .type = REGULATOR_VOLTAGE,
0304 .owner = THIS_MODULE,
0305 },
0306 .epod_id = EPOD_ID_SVAMMDSP,
0307 },
0308 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
0309 .desc = {
0310 .name = "db8500-sva-mmdsp-ret",
0311 .of_match = of_match_ptr("db8500_sva_mmdsp_ret"),
0312 .id = DB8500_REGULATOR_SWITCH_SVAMMDSPRET,
0313 .ops = &db8500_regulator_switch_ops,
0314 .type = REGULATOR_VOLTAGE,
0315 .owner = THIS_MODULE,
0316 },
0317 .epod_id = EPOD_ID_SVAMMDSP,
0318 .is_ramret = true,
0319 },
0320 [DB8500_REGULATOR_SWITCH_SVAPIPE] = {
0321 .desc = {
0322 .name = "db8500-sva-pipe",
0323 .of_match = of_match_ptr("db8500_sva_pipe"),
0324 .id = DB8500_REGULATOR_SWITCH_SVAPIPE,
0325 .ops = &db8500_regulator_switch_ops,
0326 .type = REGULATOR_VOLTAGE,
0327 .owner = THIS_MODULE,
0328 },
0329 .epod_id = EPOD_ID_SVAPIPE,
0330 },
0331 [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
0332 .desc = {
0333 .name = "db8500-sia-mmdsp",
0334 .of_match = of_match_ptr("db8500_sia_mmdsp"),
0335 .id = DB8500_REGULATOR_SWITCH_SIAMMDSP,
0336 .ops = &db8500_regulator_switch_ops,
0337 .type = REGULATOR_VOLTAGE,
0338 .owner = THIS_MODULE,
0339 },
0340 .epod_id = EPOD_ID_SIAMMDSP,
0341 },
0342 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
0343 .desc = {
0344 .name = "db8500-sia-mmdsp-ret",
0345 .of_match = of_match_ptr("db8500_sia_mmdsp_ret"),
0346 .id = DB8500_REGULATOR_SWITCH_SIAMMDSPRET,
0347 .ops = &db8500_regulator_switch_ops,
0348 .type = REGULATOR_VOLTAGE,
0349 .owner = THIS_MODULE,
0350 },
0351 .epod_id = EPOD_ID_SIAMMDSP,
0352 .is_ramret = true,
0353 },
0354 [DB8500_REGULATOR_SWITCH_SIAPIPE] = {
0355 .desc = {
0356 .name = "db8500-sia-pipe",
0357 .of_match = of_match_ptr("db8500_sia_pipe"),
0358 .id = DB8500_REGULATOR_SWITCH_SIAPIPE,
0359 .ops = &db8500_regulator_switch_ops,
0360 .type = REGULATOR_VOLTAGE,
0361 .owner = THIS_MODULE,
0362 },
0363 .epod_id = EPOD_ID_SIAPIPE,
0364 },
0365 [DB8500_REGULATOR_SWITCH_SGA] = {
0366 .desc = {
0367 .name = "db8500-sga",
0368 .of_match = of_match_ptr("db8500_sga"),
0369 .id = DB8500_REGULATOR_SWITCH_SGA,
0370 .ops = &db8500_regulator_switch_ops,
0371 .type = REGULATOR_VOLTAGE,
0372 .owner = THIS_MODULE,
0373 },
0374 .epod_id = EPOD_ID_SGA,
0375 },
0376 [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
0377 .desc = {
0378 .name = "db8500-b2r2-mcde",
0379 .of_match = of_match_ptr("db8500_b2r2_mcde"),
0380 .id = DB8500_REGULATOR_SWITCH_B2R2_MCDE,
0381 .ops = &db8500_regulator_switch_ops,
0382 .type = REGULATOR_VOLTAGE,
0383 .owner = THIS_MODULE,
0384 },
0385 .epod_id = EPOD_ID_B2R2_MCDE,
0386 },
0387 [DB8500_REGULATOR_SWITCH_ESRAM12] = {
0388 .desc = {
0389 .name = "db8500-esram12",
0390 .of_match = of_match_ptr("db8500_esram12"),
0391 .id = DB8500_REGULATOR_SWITCH_ESRAM12,
0392 .ops = &db8500_regulator_switch_ops,
0393 .type = REGULATOR_VOLTAGE,
0394 .owner = THIS_MODULE,
0395 },
0396 .epod_id = EPOD_ID_ESRAM12,
0397 .is_enabled = true,
0398 },
0399 [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
0400 .desc = {
0401 .name = "db8500-esram12-ret",
0402 .of_match = of_match_ptr("db8500_esram12_ret"),
0403 .id = DB8500_REGULATOR_SWITCH_ESRAM12RET,
0404 .ops = &db8500_regulator_switch_ops,
0405 .type = REGULATOR_VOLTAGE,
0406 .owner = THIS_MODULE,
0407 },
0408 .epod_id = EPOD_ID_ESRAM12,
0409 .is_ramret = true,
0410 },
0411 [DB8500_REGULATOR_SWITCH_ESRAM34] = {
0412 .desc = {
0413 .name = "db8500-esram34",
0414 .of_match = of_match_ptr("db8500_esram34"),
0415 .id = DB8500_REGULATOR_SWITCH_ESRAM34,
0416 .ops = &db8500_regulator_switch_ops,
0417 .type = REGULATOR_VOLTAGE,
0418 .owner = THIS_MODULE,
0419 },
0420 .epod_id = EPOD_ID_ESRAM34,
0421 .is_enabled = true,
0422 },
0423 [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
0424 .desc = {
0425 .name = "db8500-esram34-ret",
0426 .of_match = of_match_ptr("db8500_esram34_ret"),
0427 .id = DB8500_REGULATOR_SWITCH_ESRAM34RET,
0428 .ops = &db8500_regulator_switch_ops,
0429 .type = REGULATOR_VOLTAGE,
0430 .owner = THIS_MODULE,
0431 },
0432 .epod_id = EPOD_ID_ESRAM34,
0433 .is_ramret = true,
0434 },
0435 };
0436
0437 static int db8500_regulator_probe(struct platform_device *pdev)
0438 {
0439 struct regulator_init_data *db8500_init_data;
0440 struct dbx500_regulator_info *info;
0441 struct regulator_config config = { };
0442 struct regulator_dev *rdev;
0443 int err, i;
0444
0445 db8500_init_data = dev_get_platdata(&pdev->dev);
0446
0447 for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
0448
0449 info = &dbx500_regulator_info[i];
0450
0451 config.driver_data = info;
0452 config.dev = &pdev->dev;
0453 if (db8500_init_data)
0454 config.init_data = &db8500_init_data[i];
0455
0456 rdev = devm_regulator_register(&pdev->dev, &info->desc,
0457 &config);
0458 if (IS_ERR(rdev)) {
0459 err = PTR_ERR(rdev);
0460 dev_err(&pdev->dev, "failed to register %s: err %i\n",
0461 info->desc.name, err);
0462 return err;
0463 }
0464 dev_dbg(&pdev->dev, "regulator-%s-probed\n", info->desc.name);
0465 }
0466
0467 ux500_regulator_debug_init(pdev, dbx500_regulator_info,
0468 ARRAY_SIZE(dbx500_regulator_info));
0469 return 0;
0470 }
0471
0472 static int db8500_regulator_remove(struct platform_device *pdev)
0473 {
0474 ux500_regulator_debug_exit();
0475
0476 return 0;
0477 }
0478
0479 static struct platform_driver db8500_regulator_driver = {
0480 .driver = {
0481 .name = "db8500-prcmu-regulators",
0482 },
0483 .probe = db8500_regulator_probe,
0484 .remove = db8500_regulator_remove,
0485 };
0486
0487 static int __init db8500_regulator_init(void)
0488 {
0489 return platform_driver_register(&db8500_regulator_driver);
0490 }
0491
0492 static void __exit db8500_regulator_exit(void)
0493 {
0494 platform_driver_unregister(&db8500_regulator_driver);
0495 }
0496
0497 arch_initcall(db8500_regulator_init);
0498 module_exit(db8500_regulator_exit);
0499
0500 MODULE_AUTHOR("STMicroelectronics/ST-Ericsson");
0501 MODULE_DESCRIPTION("DB8500 regulator driver");
0502 MODULE_LICENSE("GPL v2");