act8945a-regulator.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Voltage regulation driver for active-semi ACT8945A PMIC
  3. *
  4. * Copyright (C) 2015 Atmel Corporation
  5. *
  6. * Author: Wenyou Yang <wenyou.yang@atmel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of the
  11. * License, or (at your option) any later version.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/of_device.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/regulator/driver.h>
  18. #include <linux/regulator/machine.h>
  19. /**
  20. * ACT8945A Global Register Map.
  21. */
  22. #define ACT8945A_SYS_MODE 0x00
  23. #define ACT8945A_SYS_CTRL 0x01
  24. #define ACT8945A_DCDC1_VSET1 0x20
  25. #define ACT8945A_DCDC1_VSET2 0x21
  26. #define ACT8945A_DCDC1_CTRL 0x22
  27. #define ACT8945A_DCDC2_VSET1 0x30
  28. #define ACT8945A_DCDC2_VSET2 0x31
  29. #define ACT8945A_DCDC2_CTRL 0x32
  30. #define ACT8945A_DCDC3_VSET1 0x40
  31. #define ACT8945A_DCDC3_VSET2 0x41
  32. #define ACT8945A_DCDC3_CTRL 0x42
  33. #define ACT8945A_LDO1_VSET 0x50
  34. #define ACT8945A_LDO1_CTRL 0x51
  35. #define ACT8945A_LDO2_VSET 0x54
  36. #define ACT8945A_LDO2_CTRL 0x55
  37. #define ACT8945A_LDO3_VSET 0x60
  38. #define ACT8945A_LDO3_CTRL 0x61
  39. #define ACT8945A_LDO4_VSET 0x64
  40. #define ACT8945A_LDO4_CTRL 0x65
  41. /**
  42. * Field Definitions.
  43. */
  44. #define ACT8945A_ENA 0x80 /* ON - [7] */
  45. #define ACT8945A_VSEL_MASK 0x3F /* VSET - [5:0] */
  46. /**
  47. * ACT8945A Voltage Number
  48. */
  49. #define ACT8945A_VOLTAGE_NUM 64
  50. enum {
  51. ACT8945A_ID_DCDC1,
  52. ACT8945A_ID_DCDC2,
  53. ACT8945A_ID_DCDC3,
  54. ACT8945A_ID_LDO1,
  55. ACT8945A_ID_LDO2,
  56. ACT8945A_ID_LDO3,
  57. ACT8945A_ID_LDO4,
  58. ACT8945A_REG_NUM,
  59. };
  60. static const struct regulator_linear_range act8945a_voltage_ranges[] = {
  61. REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000),
  62. REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000),
  63. REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000),
  64. };
  65. static struct regulator_ops act8945a_ops = {
  66. .list_voltage = regulator_list_voltage_linear_range,
  67. .map_voltage = regulator_map_voltage_linear_range,
  68. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  69. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  70. .enable = regulator_enable_regmap,
  71. .disable = regulator_disable_regmap,
  72. .is_enabled = regulator_is_enabled_regmap,
  73. };
  74. #define ACT89xx_REG(_name, _family, _id, _vsel_reg, _supply) \
  75. [_family##_ID_##_id] = { \
  76. .name = _name, \
  77. .supply_name = _supply, \
  78. .of_match = of_match_ptr("REG_"#_id), \
  79. .regulators_node = of_match_ptr("regulators"), \
  80. .id = _family##_ID_##_id, \
  81. .type = REGULATOR_VOLTAGE, \
  82. .ops = &act8945a_ops, \
  83. .n_voltages = ACT8945A_VOLTAGE_NUM, \
  84. .linear_ranges = act8945a_voltage_ranges, \
  85. .n_linear_ranges = ARRAY_SIZE(act8945a_voltage_ranges), \
  86. .vsel_reg = _family##_##_id##_##_vsel_reg, \
  87. .vsel_mask = ACT8945A_VSEL_MASK, \
  88. .enable_reg = _family##_##_id##_CTRL, \
  89. .enable_mask = ACT8945A_ENA, \
  90. .owner = THIS_MODULE, \
  91. }
  92. static const struct regulator_desc act8945a_regulators[] = {
  93. ACT89xx_REG("DCDC_REG1", ACT8945A, DCDC1, VSET1, "vp1"),
  94. ACT89xx_REG("DCDC_REG2", ACT8945A, DCDC2, VSET1, "vp2"),
  95. ACT89xx_REG("DCDC_REG3", ACT8945A, DCDC3, VSET1, "vp3"),
  96. ACT89xx_REG("LDO_REG1", ACT8945A, LDO1, VSET, "inl45"),
  97. ACT89xx_REG("LDO_REG2", ACT8945A, LDO2, VSET, "inl45"),
  98. ACT89xx_REG("LDO_REG3", ACT8945A, LDO3, VSET, "inl67"),
  99. ACT89xx_REG("LDO_REG4", ACT8945A, LDO4, VSET, "inl67"),
  100. };
  101. static const struct regulator_desc act8945a_alt_regulators[] = {
  102. ACT89xx_REG("DCDC_REG1", ACT8945A, DCDC1, VSET2, "vp1"),
  103. ACT89xx_REG("DCDC_REG2", ACT8945A, DCDC2, VSET2, "vp2"),
  104. ACT89xx_REG("DCDC_REG3", ACT8945A, DCDC3, VSET2, "vp3"),
  105. ACT89xx_REG("LDO_REG1", ACT8945A, LDO1, VSET, "inl45"),
  106. ACT89xx_REG("LDO_REG2", ACT8945A, LDO2, VSET, "inl45"),
  107. ACT89xx_REG("LDO_REG3", ACT8945A, LDO3, VSET, "inl67"),
  108. ACT89xx_REG("LDO_REG4", ACT8945A, LDO4, VSET, "inl67"),
  109. };
  110. static int act8945a_pmic_probe(struct platform_device *pdev)
  111. {
  112. struct regulator_config config = { };
  113. const struct regulator_desc *regulators;
  114. struct regulator_dev *rdev;
  115. int i, num_regulators;
  116. bool voltage_select;
  117. voltage_select = of_property_read_bool(pdev->dev.parent->of_node,
  118. "active-semi,vsel-high");
  119. if (voltage_select) {
  120. regulators = act8945a_alt_regulators;
  121. num_regulators = ARRAY_SIZE(act8945a_alt_regulators);
  122. } else {
  123. regulators = act8945a_regulators;
  124. num_regulators = ARRAY_SIZE(act8945a_regulators);
  125. }
  126. config.dev = &pdev->dev;
  127. config.dev->of_node = pdev->dev.parent->of_node;
  128. for (i = 0; i < num_regulators; i++) {
  129. rdev = devm_regulator_register(&pdev->dev, &regulators[i], &config);
  130. if (IS_ERR(rdev)) {
  131. dev_err(&pdev->dev,
  132. "failed to register %s regulator\n",
  133. regulators[i].name);
  134. return PTR_ERR(rdev);
  135. }
  136. }
  137. return 0;
  138. }
  139. static struct platform_driver act8945a_pmic_driver = {
  140. .driver = {
  141. .name = "act8945a-regulator",
  142. },
  143. .probe = act8945a_pmic_probe,
  144. };
  145. module_platform_driver(act8945a_pmic_driver);
  146. MODULE_DESCRIPTION("Active-semi ACT8945A voltage regulator driver");
  147. MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>");
  148. MODULE_LICENSE("GPL");