rn5t618-regulator.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Regulator driver for Ricoh RN5T618 PMIC
  3. *
  4. * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * You should have received a copy of the GNU General Public License
  11. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include <linux/mfd/rn5t618.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/regmap.h>
  18. #include <linux/regulator/driver.h>
  19. #include <linux/regulator/of_regulator.h>
  20. static const struct regulator_ops rn5t618_reg_ops = {
  21. .enable = regulator_enable_regmap,
  22. .disable = regulator_disable_regmap,
  23. .is_enabled = regulator_is_enabled_regmap,
  24. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  25. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  26. .list_voltage = regulator_list_voltage_linear,
  27. };
  28. #define REG(rid, ereg, emask, vreg, vmask, min, max, step) \
  29. { \
  30. .name = #rid, \
  31. .of_match = of_match_ptr(#rid), \
  32. .regulators_node = of_match_ptr("regulators"), \
  33. .id = RN5T618_##rid, \
  34. .type = REGULATOR_VOLTAGE, \
  35. .owner = THIS_MODULE, \
  36. .ops = &rn5t618_reg_ops, \
  37. .n_voltages = ((max) - (min)) / (step) + 1, \
  38. .min_uV = (min), \
  39. .uV_step = (step), \
  40. .enable_reg = RN5T618_##ereg, \
  41. .enable_mask = (emask), \
  42. .vsel_reg = RN5T618_##vreg, \
  43. .vsel_mask = (vmask), \
  44. }
  45. static struct regulator_desc rn5t567_regulators[] = {
  46. /* DCDC */
  47. REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
  48. REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
  49. REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500),
  50. REG(DCDC4, DC4CTL, BIT(0), DC4DAC, 0xff, 600000, 3500000, 12500),
  51. /* LDO */
  52. REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000),
  53. REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000),
  54. REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 600000, 3500000, 25000),
  55. REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000),
  56. REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 900000, 3500000, 25000),
  57. /* LDO RTC */
  58. REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1200000, 3500000, 25000),
  59. REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
  60. };
  61. static struct regulator_desc rn5t618_regulators[] = {
  62. /* DCDC */
  63. REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
  64. REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
  65. REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500),
  66. /* LDO */
  67. REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000),
  68. REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000),
  69. REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 600000, 3500000, 25000),
  70. REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000),
  71. REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 900000, 3500000, 25000),
  72. /* LDO RTC */
  73. REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1700000, 3500000, 25000),
  74. REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
  75. };
  76. static struct regulator_desc rc5t619_regulators[] = {
  77. /* DCDC */
  78. REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
  79. REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
  80. REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500),
  81. REG(DCDC4, DC4CTL, BIT(0), DC4DAC, 0xff, 600000, 3500000, 12500),
  82. REG(DCDC5, DC5CTL, BIT(0), DC5DAC, 0xff, 600000, 3500000, 12500),
  83. /* LDO */
  84. REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000),
  85. REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000),
  86. REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 900000, 3500000, 25000),
  87. REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000),
  88. REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 600000, 3500000, 25000),
  89. REG(LDO6, LDOEN1, BIT(5), LDO6DAC, 0x7f, 600000, 3500000, 25000),
  90. REG(LDO7, LDOEN1, BIT(6), LDO7DAC, 0x7f, 900000, 3500000, 25000),
  91. REG(LDO8, LDOEN1, BIT(7), LDO8DAC, 0x7f, 900000, 3500000, 25000),
  92. REG(LDO9, LDOEN2, BIT(0), LDO9DAC, 0x7f, 900000, 3500000, 25000),
  93. REG(LDO10, LDOEN2, BIT(0), LDO10DAC, 0x7f, 900000, 3500000, 25000),
  94. /* LDO RTC */
  95. REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1700000, 3500000, 25000),
  96. REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
  97. };
  98. static int rn5t618_regulator_probe(struct platform_device *pdev)
  99. {
  100. struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
  101. struct regulator_config config = { };
  102. struct regulator_dev *rdev;
  103. struct regulator_desc *regulators;
  104. int i;
  105. int num_regulators = 0;
  106. switch (rn5t618->variant) {
  107. case RN5T567:
  108. regulators = rn5t567_regulators;
  109. num_regulators = ARRAY_SIZE(rn5t567_regulators);
  110. break;
  111. case RN5T618:
  112. regulators = rn5t618_regulators;
  113. num_regulators = ARRAY_SIZE(rn5t618_regulators);
  114. break;
  115. case RC5T619:
  116. regulators = rc5t619_regulators;
  117. num_regulators = ARRAY_SIZE(rc5t619_regulators);
  118. break;
  119. default:
  120. return -EINVAL;
  121. }
  122. config.dev = pdev->dev.parent;
  123. config.regmap = rn5t618->regmap;
  124. for (i = 0; i < num_regulators; i++) {
  125. rdev = devm_regulator_register(&pdev->dev,
  126. &regulators[i],
  127. &config);
  128. if (IS_ERR(rdev)) {
  129. dev_err(&pdev->dev, "failed to register %s regulator\n",
  130. regulators[i].name);
  131. return PTR_ERR(rdev);
  132. }
  133. }
  134. return 0;
  135. }
  136. static struct platform_driver rn5t618_regulator_driver = {
  137. .probe = rn5t618_regulator_probe,
  138. .driver = {
  139. .name = "rn5t618-regulator",
  140. },
  141. };
  142. module_platform_driver(rn5t618_regulator_driver);
  143. MODULE_ALIAS("platform:rn5t618-regulator");
  144. MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
  145. MODULE_DESCRIPTION("RN5T618 regulator driver");
  146. MODULE_LICENSE("GPL v2");