885-v6.5-regulator-axp20x-Add-support-for-AXP313a-variant.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. From 60fd7eb89670d2636ac3156881acbd103c6eba6a Mon Sep 17 00:00:00 2001
  2. From: Martin Botka <[email protected]>
  3. Date: Wed, 24 May 2023 01:00:11 +0100
  4. Subject: [PATCH] regulator: axp20x: Add support for AXP313a variant
  5. The AXP313a is your typical I2C controlled PMIC, although in a lighter
  6. fashion compared to the other X-Powers PMICs: it has only three DCDC
  7. rails, three LDOs, and no battery charging support.
  8. The AXP313a datasheet does not describe a register to change the DCDC
  9. switching frequency, and talks of it being fixed at 3 MHz. Check that
  10. the property allowing to change that frequency is absent from the DT,
  11. and bail out otherwise.
  12. The third LDO, RTCLDO, is fixed, and cannot even be turned on or off,
  13. programmatically. On top of that, its voltage is customisable (either
  14. 1.8V or 3.3V), which we cannot describe easily using the existing
  15. regulator wrapper functions. This should be fixed properly, using
  16. regulator-{min,max}-microvolt in the DT, but this requires more changes
  17. to the code. As some other PMICs (AXP2xx, AXP803) seem to paper over the
  18. same problem as well, we follow suit here and pretend it's a fixed 1.8V
  19. regulator. A proper fix can follow later. The BSP code seems to ignore
  20. this regulator altogether.
  21. Describe the AXP313A's voltage settings and switch registers, how the
  22. voltages are encoded, and connect this to the MFD device via its
  23. regulator ID.
  24. Signed-off-by: Martin Botka <[email protected]>
  25. Signed-off-by: Andre Przywara <[email protected]>
  26. Reviewed-by: Chen-Yu Tsai <[email protected]>
  27. Reviewed-by: Mark Brown <[email protected]>
  28. Tested-by: Shengyu Qu <[email protected]>
  29. Link: https://lore.kernel.org/r/[email protected]
  30. Signed-off-by: Mark Brown <[email protected]>
  31. ---
  32. drivers/regulator/axp20x-regulator.c | 60 ++++++++++++++++++++++++++++
  33. 1 file changed, 60 insertions(+)
  34. --- a/drivers/regulator/axp20x-regulator.c
  35. +++ b/drivers/regulator/axp20x-regulator.c
  36. @@ -134,6 +134,11 @@
  37. #define AXP22X_PWR_OUT_DLDO4_MASK BIT_MASK(6)
  38. #define AXP22X_PWR_OUT_ALDO3_MASK BIT_MASK(7)
  39. +#define AXP313A_DCDC1_NUM_VOLTAGES 107
  40. +#define AXP313A_DCDC23_NUM_VOLTAGES 88
  41. +#define AXP313A_DCDC_V_OUT_MASK GENMASK(6, 0)
  42. +#define AXP313A_LDO_V_OUT_MASK GENMASK(4, 0)
  43. +
  44. #define AXP803_PWR_OUT_DCDC1_MASK BIT_MASK(0)
  45. #define AXP803_PWR_OUT_DCDC2_MASK BIT_MASK(1)
  46. #define AXP803_PWR_OUT_DCDC3_MASK BIT_MASK(2)
  47. @@ -638,6 +643,48 @@ static const struct regulator_desc axp22
  48. .ops = &axp20x_ops_sw,
  49. };
  50. +static const struct linear_range axp313a_dcdc1_ranges[] = {
  51. + REGULATOR_LINEAR_RANGE(500000, 0, 70, 10000),
  52. + REGULATOR_LINEAR_RANGE(1220000, 71, 87, 20000),
  53. + REGULATOR_LINEAR_RANGE(1600000, 88, 106, 100000),
  54. +};
  55. +
  56. +static const struct linear_range axp313a_dcdc2_ranges[] = {
  57. + REGULATOR_LINEAR_RANGE(500000, 0, 70, 10000),
  58. + REGULATOR_LINEAR_RANGE(1220000, 71, 87, 20000),
  59. +};
  60. +
  61. +/*
  62. + * This is deviating from the datasheet. The values here are taken from the
  63. + * BSP driver and have been confirmed by measurements.
  64. + */
  65. +static const struct linear_range axp313a_dcdc3_ranges[] = {
  66. + REGULATOR_LINEAR_RANGE(500000, 0, 70, 10000),
  67. + REGULATOR_LINEAR_RANGE(1220000, 71, 102, 20000),
  68. +};
  69. +
  70. +static const struct regulator_desc axp313a_regulators[] = {
  71. + AXP_DESC_RANGES(AXP313A, DCDC1, "dcdc1", "vin1",
  72. + axp313a_dcdc1_ranges, AXP313A_DCDC1_NUM_VOLTAGES,
  73. + AXP313A_DCDC1_CONRTOL, AXP313A_DCDC_V_OUT_MASK,
  74. + AXP313A_OUTPUT_CONTROL, BIT(0)),
  75. + AXP_DESC_RANGES(AXP313A, DCDC2, "dcdc2", "vin2",
  76. + axp313a_dcdc2_ranges, AXP313A_DCDC23_NUM_VOLTAGES,
  77. + AXP313A_DCDC2_CONRTOL, AXP313A_DCDC_V_OUT_MASK,
  78. + AXP313A_OUTPUT_CONTROL, BIT(1)),
  79. + AXP_DESC_RANGES(AXP313A, DCDC3, "dcdc3", "vin3",
  80. + axp313a_dcdc3_ranges, AXP313A_DCDC23_NUM_VOLTAGES,
  81. + AXP313A_DCDC3_CONRTOL, AXP313A_DCDC_V_OUT_MASK,
  82. + AXP313A_OUTPUT_CONTROL, BIT(2)),
  83. + AXP_DESC(AXP313A, ALDO1, "aldo1", "vin1", 500, 3500, 100,
  84. + AXP313A_ALDO1_CONRTOL, AXP313A_LDO_V_OUT_MASK,
  85. + AXP313A_OUTPUT_CONTROL, BIT(3)),
  86. + AXP_DESC(AXP313A, DLDO1, "dldo1", "vin1", 500, 3500, 100,
  87. + AXP313A_DLDO1_CONRTOL, AXP313A_LDO_V_OUT_MASK,
  88. + AXP313A_OUTPUT_CONTROL, BIT(4)),
  89. + AXP_DESC_FIXED(AXP313A, RTC_LDO, "rtc-ldo", "vin1", 1800),
  90. +};
  91. +
  92. /* DCDC ranges shared with AXP813 */
  93. static const struct linear_range axp803_dcdc234_ranges[] = {
  94. REGULATOR_LINEAR_RANGE(500000,
  95. @@ -1040,6 +1087,15 @@ static int axp20x_set_dcdc_freq(struct p
  96. def = 3000;
  97. step = 150;
  98. break;
  99. + case AXP313A_ID:
  100. + /* The DCDC PWM frequency seems to be fixed to 3 MHz. */
  101. + if (dcdcfreq != 0) {
  102. + dev_err(&pdev->dev,
  103. + "DCDC frequency on AXP313a is fixed to 3 MHz.\n");
  104. + return -EINVAL;
  105. + }
  106. +
  107. + return 0;
  108. default:
  109. dev_err(&pdev->dev,
  110. "Setting DCDC frequency for unsupported AXP variant\n");
  111. @@ -1232,6 +1288,10 @@ static int axp20x_regulator_probe(struct
  112. drivevbus = of_property_read_bool(pdev->dev.parent->of_node,
  113. "x-powers,drive-vbus-en");
  114. break;
  115. + case AXP313A_ID:
  116. + regulators = axp313a_regulators;
  117. + nregulators = AXP313A_REG_ID_MAX;
  118. + break;
  119. case AXP803_ID:
  120. regulators = axp803_regulators;
  121. nregulators = AXP803_REG_ID_MAX;