tps65912-regulator.c 5.2 KB

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