pcf50633-regulator.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* NXP PCF50633 PMIC Driver
  3. *
  4. * (C) 2006-2008 by Openmoko, Inc.
  5. * Author: Balaji Rao <balajirrao@openmoko.org>
  6. * All rights reserved.
  7. *
  8. * Broken down from monstrous PCF50633 driver mainly by
  9. * Harald Welte and Andy Green and Werner Almesberger
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/device.h>
  15. #include <linux/err.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mfd/pcf50633/core.h>
  18. #include <linux/mfd/pcf50633/pmic.h>
  19. #define PCF50633_REGULATOR(_name, _id, _min_uV, _uV_step, _min_sel, _n) \
  20. { \
  21. .name = _name, \
  22. .id = PCF50633_REGULATOR_##_id, \
  23. .ops = &pcf50633_regulator_ops, \
  24. .n_voltages = _n, \
  25. .min_uV = _min_uV, \
  26. .uV_step = _uV_step, \
  27. .linear_min_sel = _min_sel, \
  28. .type = REGULATOR_VOLTAGE, \
  29. .owner = THIS_MODULE, \
  30. .vsel_reg = PCF50633_REG_##_id##OUT, \
  31. .vsel_mask = 0xff, \
  32. .enable_reg = PCF50633_REG_##_id##OUT + 1, \
  33. .enable_mask = PCF50633_REGULATOR_ON, \
  34. }
  35. static const struct regulator_ops pcf50633_regulator_ops = {
  36. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  37. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  38. .list_voltage = regulator_list_voltage_linear,
  39. .map_voltage = regulator_map_voltage_linear,
  40. .enable = regulator_enable_regmap,
  41. .disable = regulator_disable_regmap,
  42. .is_enabled = regulator_is_enabled_regmap,
  43. };
  44. static const struct regulator_desc regulators[] = {
  45. [PCF50633_REGULATOR_AUTO] =
  46. PCF50633_REGULATOR("auto", AUTO, 1800000, 25000, 0x2f, 128),
  47. [PCF50633_REGULATOR_DOWN1] =
  48. PCF50633_REGULATOR("down1", DOWN1, 625000, 25000, 0, 96),
  49. [PCF50633_REGULATOR_DOWN2] =
  50. PCF50633_REGULATOR("down2", DOWN2, 625000, 25000, 0, 96),
  51. [PCF50633_REGULATOR_LDO1] =
  52. PCF50633_REGULATOR("ldo1", LDO1, 900000, 100000, 0, 28),
  53. [PCF50633_REGULATOR_LDO2] =
  54. PCF50633_REGULATOR("ldo2", LDO2, 900000, 100000, 0, 28),
  55. [PCF50633_REGULATOR_LDO3] =
  56. PCF50633_REGULATOR("ldo3", LDO3, 900000, 100000, 0, 28),
  57. [PCF50633_REGULATOR_LDO4] =
  58. PCF50633_REGULATOR("ldo4", LDO4, 900000, 100000, 0, 28),
  59. [PCF50633_REGULATOR_LDO5] =
  60. PCF50633_REGULATOR("ldo5", LDO5, 900000, 100000, 0, 28),
  61. [PCF50633_REGULATOR_LDO6] =
  62. PCF50633_REGULATOR("ldo6", LDO6, 900000, 100000, 0, 28),
  63. [PCF50633_REGULATOR_HCLDO] =
  64. PCF50633_REGULATOR("hcldo", HCLDO, 900000, 100000, 0, 28),
  65. [PCF50633_REGULATOR_MEMLDO] =
  66. PCF50633_REGULATOR("memldo", MEMLDO, 900000, 100000, 0, 28),
  67. };
  68. static int pcf50633_regulator_probe(struct platform_device *pdev)
  69. {
  70. struct regulator_dev *rdev;
  71. struct pcf50633 *pcf;
  72. struct regulator_config config = { };
  73. /* Already set by core driver */
  74. pcf = dev_to_pcf50633(pdev->dev.parent);
  75. config.dev = &pdev->dev;
  76. config.init_data = dev_get_platdata(&pdev->dev);
  77. config.driver_data = pcf;
  78. config.regmap = pcf->regmap;
  79. rdev = devm_regulator_register(&pdev->dev, &regulators[pdev->id],
  80. &config);
  81. if (IS_ERR(rdev))
  82. return PTR_ERR(rdev);
  83. platform_set_drvdata(pdev, rdev);
  84. if (pcf->pdata->regulator_registered)
  85. pcf->pdata->regulator_registered(pcf, pdev->id);
  86. return 0;
  87. }
  88. static struct platform_driver pcf50633_regulator_driver = {
  89. .driver = {
  90. .name = "pcf50633-regulator",
  91. },
  92. .probe = pcf50633_regulator_probe,
  93. };
  94. static int __init pcf50633_regulator_init(void)
  95. {
  96. return platform_driver_register(&pcf50633_regulator_driver);
  97. }
  98. subsys_initcall(pcf50633_regulator_init);
  99. static void __exit pcf50633_regulator_exit(void)
  100. {
  101. platform_driver_unregister(&pcf50633_regulator_driver);
  102. }
  103. module_exit(pcf50633_regulator_exit);
  104. MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
  105. MODULE_DESCRIPTION("PCF50633 regulator driver");
  106. MODULE_LICENSE("GPL");
  107. MODULE_ALIAS("platform:pcf50633-regulator");