tps65912-regulator.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/mod_devicetable.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/regulator/driver.h>
  23. #include <linux/mfd/tps65912.h>
  24. enum tps65912_regulators { DCDC1, DCDC2, DCDC3, DCDC4, LDO1, LDO2, LDO3,
  25. LDO4, LDO5, LDO6, LDO7, LDO8, LDO9, LDO10 };
  26. #define TPS65912_REGULATOR(_name, _id, _of_match, _ops, _vr, _er, _lr) \
  27. [_id] = { \
  28. .name = _name, \
  29. .of_match = _of_match, \
  30. .regulators_node = "regulators", \
  31. .id = _id, \
  32. .ops = &_ops, \
  33. .n_voltages = 64, \
  34. .type = REGULATOR_VOLTAGE, \
  35. .owner = THIS_MODULE, \
  36. .vsel_reg = _vr, \
  37. .vsel_mask = 0x3f, \
  38. .enable_reg = _er, \
  39. .enable_mask = BIT(7), \
  40. .volt_table = NULL, \
  41. .linear_ranges = _lr, \
  42. .n_linear_ranges = ARRAY_SIZE(_lr), \
  43. }
  44. static const struct regulator_linear_range tps65912_dcdc_ranges[] = {
  45. REGULATOR_LINEAR_RANGE(500000, 0x0, 0x3f, 50000),
  46. };
  47. static const struct regulator_linear_range tps65912_ldo_ranges[] = {
  48. REGULATOR_LINEAR_RANGE(800000, 0x0, 0x20, 25000),
  49. REGULATOR_LINEAR_RANGE(1650000, 0x21, 0x3c, 50000),
  50. REGULATOR_LINEAR_RANGE(3100000, 0x3d, 0x3f, 100000),
  51. };
  52. /* Operations permitted on DCDCx */
  53. static struct regulator_ops tps65912_ops_dcdc = {
  54. .is_enabled = regulator_is_enabled_regmap,
  55. .enable = regulator_enable_regmap,
  56. .disable = regulator_disable_regmap,
  57. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  58. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  59. .list_voltage = regulator_list_voltage_linear_range,
  60. };
  61. /* Operations permitted on LDOx */
  62. static struct regulator_ops tps65912_ops_ldo = {
  63. .is_enabled = regulator_is_enabled_regmap,
  64. .enable = regulator_enable_regmap,
  65. .disable = regulator_disable_regmap,
  66. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  67. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  68. .list_voltage = regulator_list_voltage_linear_range,
  69. .map_voltage = regulator_map_voltage_linear_range,
  70. };
  71. static const struct regulator_desc regulators[] = {
  72. TPS65912_REGULATOR("DCDC1", DCDC1, "dcdc1", tps65912_ops_dcdc,
  73. TPS65912_DCDC1_OP, TPS65912_DCDC1_CTRL,
  74. tps65912_dcdc_ranges),
  75. TPS65912_REGULATOR("DCDC2", DCDC2, "dcdc2", tps65912_ops_dcdc,
  76. TPS65912_DCDC2_OP, TPS65912_DCDC2_CTRL,
  77. tps65912_dcdc_ranges),
  78. TPS65912_REGULATOR("DCDC3", DCDC3, "dcdc3", tps65912_ops_dcdc,
  79. TPS65912_DCDC3_OP, TPS65912_DCDC3_CTRL,
  80. tps65912_dcdc_ranges),
  81. TPS65912_REGULATOR("DCDC4", DCDC4, "dcdc4", tps65912_ops_dcdc,
  82. TPS65912_DCDC4_OP, TPS65912_DCDC4_CTRL,
  83. tps65912_dcdc_ranges),
  84. TPS65912_REGULATOR("LDO1", LDO1, "ldo1", tps65912_ops_ldo,
  85. TPS65912_LDO1_OP, TPS65912_LDO1_AVS,
  86. tps65912_ldo_ranges),
  87. TPS65912_REGULATOR("LDO2", LDO2, "ldo2", tps65912_ops_ldo,
  88. TPS65912_LDO2_OP, TPS65912_LDO2_AVS,
  89. tps65912_ldo_ranges),
  90. TPS65912_REGULATOR("LDO3", LDO3, "ldo3", tps65912_ops_ldo,
  91. TPS65912_LDO3_OP, TPS65912_LDO3_AVS,
  92. tps65912_ldo_ranges),
  93. TPS65912_REGULATOR("LDO4", LDO4, "ldo4", tps65912_ops_ldo,
  94. TPS65912_LDO4_OP, TPS65912_LDO4_AVS,
  95. tps65912_ldo_ranges),
  96. TPS65912_REGULATOR("LDO5", LDO5, "ldo5", tps65912_ops_ldo,
  97. TPS65912_LDO5, TPS65912_LDO5,
  98. tps65912_ldo_ranges),
  99. TPS65912_REGULATOR("LDO6", LDO6, "ldo6", tps65912_ops_ldo,
  100. TPS65912_LDO6, TPS65912_LDO6,
  101. tps65912_ldo_ranges),
  102. TPS65912_REGULATOR("LDO7", LDO7, "ldo7", tps65912_ops_ldo,
  103. TPS65912_LDO7, TPS65912_LDO7,
  104. tps65912_ldo_ranges),
  105. TPS65912_REGULATOR("LDO8", LDO8, "ldo8", tps65912_ops_ldo,
  106. TPS65912_LDO8, TPS65912_LDO8,
  107. tps65912_ldo_ranges),
  108. TPS65912_REGULATOR("LDO9", LDO9, "ldo9", tps65912_ops_ldo,
  109. TPS65912_LDO9, TPS65912_LDO9,
  110. tps65912_ldo_ranges),
  111. TPS65912_REGULATOR("LDO10", LDO10, "ldo10", tps65912_ops_ldo,
  112. TPS65912_LDO10, TPS65912_LDO10,
  113. tps65912_ldo_ranges),
  114. };
  115. static int tps65912_regulator_probe(struct platform_device *pdev)
  116. {
  117. struct tps65912 *tps = dev_get_drvdata(pdev->dev.parent);
  118. struct regulator_config config = { };
  119. struct regulator_dev *rdev;
  120. int i;
  121. platform_set_drvdata(pdev, tps);
  122. config.dev = &pdev->dev;
  123. config.driver_data = tps;
  124. config.dev->of_node = tps->dev->of_node;
  125. config.regmap = tps->regmap;
  126. for (i = 0; i < ARRAY_SIZE(regulators); i++) {
  127. rdev = devm_regulator_register(&pdev->dev, &regulators[i],
  128. &config);
  129. if (IS_ERR(rdev)) {
  130. dev_err(tps->dev, "failed to register %s regulator\n",
  131. pdev->name);
  132. return PTR_ERR(rdev);
  133. }
  134. }
  135. return 0;
  136. }
  137. static const struct platform_device_id tps65912_regulator_id_table[] = {
  138. { "tps65912-regulator", },
  139. { /* sentinel */ }
  140. };
  141. MODULE_DEVICE_TABLE(platform, tps65912_regulator_id_table);
  142. static struct platform_driver tps65912_regulator_driver = {
  143. .driver = {
  144. .name = "tps65912-regulator",
  145. },
  146. .probe = tps65912_regulator_probe,
  147. .id_table = tps65912_regulator_id_table,
  148. };
  149. module_platform_driver(tps65912_regulator_driver);
  150. MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
  151. MODULE_DESCRIPTION("TPS65912 voltage regulator driver");
  152. MODULE_LICENSE("GPL v2");