tps65912-regulator.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Regulator driver for TI TPS65912x PMICs
  3. *
  4. * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
  5. * Andrew F. Davis <afd@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  12. * kind, whether expressed or implied; without even the implied warranty
  13. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License version 2 for more details.
  15. *
  16. * Based on the TPS65218 driver and the previous TPS65912 driver by
  17. * Margarita Olaya Cabrera <magi@slimlogic.co.uk>
  18. */
  19. #include <linux/module.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/regulator/driver.h>
  22. #include <linux/mfd/tps65912.h>
  23. enum tps65912_regulators { DCDC1, DCDC2, DCDC3, DCDC4, LDO1, LDO2, LDO3,
  24. LDO4, LDO5, LDO6, LDO7, LDO8, LDO9, LDO10 };
  25. #define TPS65912_REGULATOR(_name, _id, _of_match, _ops, _vr, _er, _lr) \
  26. [_id] = { \
  27. .name = _name, \
  28. .of_match = _of_match, \
  29. .regulators_node = "regulators", \
  30. .id = _id, \
  31. .ops = &_ops, \
  32. .n_voltages = 64, \
  33. .type = REGULATOR_VOLTAGE, \
  34. .owner = THIS_MODULE, \
  35. .vsel_reg = _vr, \
  36. .vsel_mask = 0x3f, \
  37. .enable_reg = _er, \
  38. .enable_mask = BIT(7), \
  39. .volt_table = NULL, \
  40. .linear_ranges = _lr, \
  41. .n_linear_ranges = ARRAY_SIZE(_lr), \
  42. }
  43. static const struct regulator_linear_range tps65912_dcdc_ranges[] = {
  44. REGULATOR_LINEAR_RANGE(500000, 0x0, 0x3f, 50000),
  45. };
  46. static const struct regulator_linear_range tps65912_ldo_ranges[] = {
  47. REGULATOR_LINEAR_RANGE(800000, 0x0, 0x20, 25000),
  48. REGULATOR_LINEAR_RANGE(1650000, 0x21, 0x3c, 50000),
  49. REGULATOR_LINEAR_RANGE(3100000, 0x3d, 0x3f, 100000),
  50. };
  51. /* Operations permitted on DCDCx */
  52. static struct regulator_ops tps65912_ops_dcdc = {
  53. .is_enabled = regulator_is_enabled_regmap,
  54. .enable = regulator_enable_regmap,
  55. .disable = regulator_disable_regmap,
  56. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  57. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  58. .list_voltage = regulator_list_voltage_linear_range,
  59. };
  60. /* Operations permitted on LDOx */
  61. static struct regulator_ops tps65912_ops_ldo = {
  62. .is_enabled = regulator_is_enabled_regmap,
  63. .enable = regulator_enable_regmap,
  64. .disable = regulator_disable_regmap,
  65. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  66. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  67. .list_voltage = regulator_list_voltage_linear_range,
  68. .map_voltage = regulator_map_voltage_linear_range,
  69. };
  70. static const struct regulator_desc regulators[] = {
  71. TPS65912_REGULATOR("DCDC1", DCDC1, "dcdc1", tps65912_ops_dcdc,
  72. TPS65912_DCDC1_OP, TPS65912_DCDC1_CTRL,
  73. tps65912_dcdc_ranges),
  74. TPS65912_REGULATOR("DCDC2", DCDC2, "dcdc2", tps65912_ops_dcdc,
  75. TPS65912_DCDC2_OP, TPS65912_DCDC2_CTRL,
  76. tps65912_dcdc_ranges),
  77. TPS65912_REGULATOR("DCDC3", DCDC3, "dcdc3", tps65912_ops_dcdc,
  78. TPS65912_DCDC3_OP, TPS65912_DCDC3_CTRL,
  79. tps65912_dcdc_ranges),
  80. TPS65912_REGULATOR("DCDC4", DCDC4, "dcdc4", tps65912_ops_dcdc,
  81. TPS65912_DCDC4_OP, TPS65912_DCDC4_CTRL,
  82. tps65912_dcdc_ranges),
  83. TPS65912_REGULATOR("LDO1", LDO1, "ldo1", tps65912_ops_ldo,
  84. TPS65912_LDO1_OP, TPS65912_LDO1_AVS,
  85. tps65912_ldo_ranges),
  86. TPS65912_REGULATOR("LDO2", LDO2, "ldo2", tps65912_ops_ldo,
  87. TPS65912_LDO2_OP, TPS65912_LDO2_AVS,
  88. tps65912_ldo_ranges),
  89. TPS65912_REGULATOR("LDO3", LDO3, "ldo3", tps65912_ops_ldo,
  90. TPS65912_LDO3_OP, TPS65912_LDO3_AVS,
  91. tps65912_ldo_ranges),
  92. TPS65912_REGULATOR("LDO4", LDO4, "ldo4", tps65912_ops_ldo,
  93. TPS65912_LDO4_OP, TPS65912_LDO4_AVS,
  94. tps65912_ldo_ranges),
  95. TPS65912_REGULATOR("LDO5", LDO5, "ldo5", tps65912_ops_ldo,
  96. TPS65912_LDO5, TPS65912_LDO5,
  97. tps65912_ldo_ranges),
  98. TPS65912_REGULATOR("LDO6", LDO6, "ldo6", tps65912_ops_ldo,
  99. TPS65912_LDO6, TPS65912_LDO6,
  100. tps65912_ldo_ranges),
  101. TPS65912_REGULATOR("LDO7", LDO7, "ldo7", tps65912_ops_ldo,
  102. TPS65912_LDO7, TPS65912_LDO7,
  103. tps65912_ldo_ranges),
  104. TPS65912_REGULATOR("LDO8", LDO8, "ldo8", tps65912_ops_ldo,
  105. TPS65912_LDO8, TPS65912_LDO8,
  106. tps65912_ldo_ranges),
  107. TPS65912_REGULATOR("LDO9", LDO9, "ldo9", tps65912_ops_ldo,
  108. TPS65912_LDO9, TPS65912_LDO9,
  109. tps65912_ldo_ranges),
  110. TPS65912_REGULATOR("LDO10", LDO10, "ldo10", tps65912_ops_ldo,
  111. TPS65912_LDO10, TPS65912_LDO10,
  112. tps65912_ldo_ranges),
  113. };
  114. static int tps65912_regulator_probe(struct platform_device *pdev)
  115. {
  116. struct tps65912 *tps = dev_get_drvdata(pdev->dev.parent);
  117. struct regulator_config config = { };
  118. struct regulator_dev *rdev;
  119. int i;
  120. platform_set_drvdata(pdev, tps);
  121. config.dev = &pdev->dev;
  122. config.driver_data = tps;
  123. config.dev->of_node = tps->dev->of_node;
  124. config.regmap = tps->regmap;
  125. for (i = 0; i < ARRAY_SIZE(regulators); i++) {
  126. rdev = devm_regulator_register(&pdev->dev, &regulators[i],
  127. &config);
  128. if (IS_ERR(rdev)) {
  129. dev_err(tps->dev, "failed to register %s regulator\n",
  130. pdev->name);
  131. return PTR_ERR(rdev);
  132. }
  133. }
  134. return 0;
  135. }
  136. static const struct platform_device_id tps65912_regulator_id_table[] = {
  137. { "tps65912-regulator", },
  138. { /* sentinel */ }
  139. };
  140. MODULE_DEVICE_TABLE(platform, tps65912_regulator_id_table);
  141. static struct platform_driver tps65912_regulator_driver = {
  142. .driver = {
  143. .name = "tps65912-regulator",
  144. },
  145. .probe = tps65912_regulator_probe,
  146. .id_table = tps65912_regulator_id_table,
  147. };
  148. module_platform_driver(tps65912_regulator_driver);
  149. MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
  150. MODULE_DESCRIPTION("TPS65912 voltage regulator driver");
  151. MODULE_LICENSE("GPL v2");