102-regulator-axp20x-add-support-for-axp22.patch 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. From c3f89434c9d778572cf09e8327bd047b11d48b90 Mon Sep 17 00:00:00 2001
  2. From: Boris BREZILLON <boris.brezillon@free-electrons.com>
  3. Date: Fri, 10 Apr 2015 12:09:04 +0800
  4. Subject: [PATCH] regulator: axp20x: Add support for AXP22X regulators
  5. Add AXP22X regulator definitions and variant id associations.
  6. This introduces a new "switch" type output for one of the regulators.
  7. It is a switchable secondary output of one regulator, with the same
  8. voltage level as the primary output.
  9. Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
  10. [wens@csie.org: Moved variant choosing to multi family support patch]
  11. [wens@csie.org: Add dc-dc work frequency range]
  12. [wens@csie.org: Add "switch" type output regulator DC1SW]
  13. Signed-off-by: Chen-Yu Tsai <wens@csie.org>
  14. Reviewed-by: Mark Brown <broonie@kernel.org>
  15. Signed-off-by: Lee Jones <lee.jones@linaro.org>
  16. ---
  17. drivers/regulator/axp20x-regulator.c | 96 ++++++++++++++++++++++++++++++++++++
  18. 1 file changed, 96 insertions(+)
  19. --- a/drivers/regulator/axp20x-regulator.c
  20. +++ b/drivers/regulator/axp20x-regulator.c
  21. @@ -27,8 +27,12 @@
  22. #define AXP20X_IO_ENABLED 0x03
  23. #define AXP20X_IO_DISABLED 0x07
  24. +#define AXP22X_IO_ENABLED 0x04
  25. +#define AXP22X_IO_DISABLED 0x03
  26. +
  27. #define AXP20X_WORKMODE_DCDC2_MASK BIT(2)
  28. #define AXP20X_WORKMODE_DCDC3_MASK BIT(1)
  29. +#define AXP22X_WORKMODE_DCDCX_MASK(x) BIT(x)
  30. #define AXP20X_FREQ_DCDC_MASK 0x0f
  31. @@ -74,6 +78,26 @@
  32. .ops = &axp20x_ops, \
  33. }
  34. +#define AXP_DESC_SW(_family, _id, _match, _supply, _min, _max, _step, _vreg, \
  35. + _vmask, _ereg, _emask) \
  36. + [_family##_##_id] = { \
  37. + .name = #_id, \
  38. + .supply_name = (_supply), \
  39. + .of_match = of_match_ptr(_match), \
  40. + .regulators_node = of_match_ptr("regulators"), \
  41. + .type = REGULATOR_VOLTAGE, \
  42. + .id = _family##_##_id, \
  43. + .n_voltages = (((_max) - (_min)) / (_step) + 1), \
  44. + .owner = THIS_MODULE, \
  45. + .min_uV = (_min) * 1000, \
  46. + .uV_step = (_step) * 1000, \
  47. + .vsel_reg = (_vreg), \
  48. + .vsel_mask = (_vmask), \
  49. + .enable_reg = (_ereg), \
  50. + .enable_mask = (_emask), \
  51. + .ops = &axp20x_ops_sw, \
  52. + }
  53. +
  54. #define AXP_DESC_FIXED(_family, _id, _match, _supply, _volt) \
  55. [_family##_##_id] = { \
  56. .name = #_id, \
  57. @@ -135,6 +159,14 @@ static struct regulator_ops axp20x_ops =
  58. .is_enabled = regulator_is_enabled_regmap,
  59. };
  60. +static struct regulator_ops axp20x_ops_sw = {
  61. + .get_voltage_sel = regulator_get_voltage_sel_regmap,
  62. + .list_voltage = regulator_list_voltage_linear,
  63. + .enable = regulator_enable_regmap,
  64. + .disable = regulator_disable_regmap,
  65. + .is_enabled = regulator_is_enabled_regmap,
  66. +};
  67. +
  68. static const struct regulator_desc axp20x_regulators[] = {
  69. AXP_DESC(AXP20X, DCDC2, "dcdc2", "vin2", 700, 2275, 25,
  70. AXP20X_DCDC2_V_OUT, 0x3f, AXP20X_PWR_OUT_CTRL, 0x10),
  71. @@ -152,6 +184,52 @@ static const struct regulator_desc axp20
  72. AXP20X_IO_ENABLED, AXP20X_IO_DISABLED),
  73. };
  74. +static const struct regulator_desc axp22x_regulators[] = {
  75. + AXP_DESC(AXP22X, DCDC1, "dcdc1", "vin1", 1600, 3400, 100,
  76. + AXP22X_DCDC1_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL1, BIT(1)),
  77. + AXP_DESC(AXP22X, DCDC2, "dcdc2", "vin2", 600, 1540, 20,
  78. + AXP22X_DCDC2_V_OUT, 0x3f, AXP22X_PWR_OUT_CTRL1, BIT(2)),
  79. + AXP_DESC(AXP22X, DCDC3, "dcdc3", "vin3", 600, 1860, 20,
  80. + AXP22X_DCDC3_V_OUT, 0x3f, AXP22X_PWR_OUT_CTRL1, BIT(3)),
  81. + AXP_DESC(AXP22X, DCDC4, "dcdc4", "vin4", 600, 1540, 20,
  82. + AXP22X_DCDC4_V_OUT, 0x3f, AXP22X_PWR_OUT_CTRL1, BIT(3)),
  83. + AXP_DESC(AXP22X, DCDC5, "dcdc5", "vin5", 1000, 2550, 50,
  84. + AXP22X_DCDC5_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL1, BIT(4)),
  85. + /* secondary switchable output of DCDC1 */
  86. + AXP_DESC_SW(AXP22X, DC1SW, "dc1sw", "dcdc1", 1600, 3400, 100,
  87. + AXP22X_DCDC1_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL2, BIT(7)),
  88. + /* LDO regulator internally chained to DCDC5 */
  89. + AXP_DESC(AXP22X, DC5LDO, "dc5ldo", "dcdc5", 700, 1400, 100,
  90. + AXP22X_DC5LDO_V_OUT, 0x7, AXP22X_PWR_OUT_CTRL1, BIT(0)),
  91. + AXP_DESC(AXP22X, ALDO1, "aldo1", "aldoin", 700, 3300, 100,
  92. + AXP22X_ALDO1_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL1, BIT(6)),
  93. + AXP_DESC(AXP22X, ALDO2, "aldo2", "aldoin", 700, 3300, 100,
  94. + AXP22X_ALDO2_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL1, BIT(7)),
  95. + AXP_DESC(AXP22X, ALDO3, "aldo3", "aldoin", 700, 3300, 100,
  96. + AXP22X_ALDO3_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL3, BIT(7)),
  97. + AXP_DESC(AXP22X, DLDO1, "dldo1", "dldoin", 700, 3300, 100,
  98. + AXP22X_DLDO1_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL2, BIT(3)),
  99. + AXP_DESC(AXP22X, DLDO2, "dldo2", "dldoin", 700, 3300, 100,
  100. + AXP22X_DLDO2_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL2, BIT(4)),
  101. + AXP_DESC(AXP22X, DLDO3, "dldo3", "dldoin", 700, 3300, 100,
  102. + AXP22X_DLDO3_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL2, BIT(5)),
  103. + AXP_DESC(AXP22X, DLDO4, "dldo4", "dldoin", 700, 3300, 100,
  104. + AXP22X_DLDO4_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL2, BIT(6)),
  105. + AXP_DESC(AXP22X, ELDO1, "eldo1", "eldoin", 700, 3300, 100,
  106. + AXP22X_ELDO1_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL2, BIT(0)),
  107. + AXP_DESC(AXP22X, ELDO2, "eldo2", "eldoin", 700, 3300, 100,
  108. + AXP22X_ELDO2_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL2, BIT(1)),
  109. + AXP_DESC(AXP22X, ELDO3, "eldo3", "eldoin", 700, 3300, 100,
  110. + AXP22X_ELDO3_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL2, BIT(2)),
  111. + AXP_DESC_IO(AXP22X, LDO_IO0, "ldo_io0", "ips", 1800, 3300, 100,
  112. + AXP22X_LDO_IO0_V_OUT, 0x1f, AXP20X_GPIO0_CTRL, 0x07,
  113. + AXP22X_IO_ENABLED, AXP22X_IO_DISABLED),
  114. + AXP_DESC_IO(AXP22X, LDO_IO1, "ldo_io1", "ips", 1800, 3300, 100,
  115. + AXP22X_LDO_IO1_V_OUT, 0x1f, AXP20X_GPIO1_CTRL, 0x07,
  116. + AXP22X_IO_ENABLED, AXP22X_IO_DISABLED),
  117. + AXP_DESC_FIXED(AXP22X, RTC_LDO, "rtc_ldo", "ips", 3000),
  118. +};
  119. +
  120. static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq)
  121. {
  122. struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
  123. @@ -165,6 +243,12 @@ static int axp20x_set_dcdc_freq(struct p
  124. def = 1500;
  125. step = 75;
  126. break;
  127. + case AXP221_ID:
  128. + min = 1800;
  129. + max = 4050;
  130. + def = 3000;
  131. + step = 150;
  132. + break;
  133. default:
  134. dev_err(&pdev->dev,
  135. "Setting DCDC frequency for unsupported AXP variant\n");
  136. @@ -237,6 +321,14 @@ static int axp20x_set_dcdc_workmode(stru
  137. workmode <<= ffs(mask) - 1;
  138. break;
  139. + case AXP221_ID:
  140. + if (id < AXP22X_DCDC1 || id > AXP22X_DCDC5)
  141. + return -EINVAL;
  142. +
  143. + mask = AXP22X_WORKMODE_DCDCX_MASK(id - AXP22X_DCDC1);
  144. + workmode <<= id - AXP22X_DCDC1;
  145. + break;
  146. +
  147. default:
  148. /* should not happen */
  149. WARN_ON(1);
  150. @@ -265,6 +357,10 @@ static int axp20x_regulator_probe(struct
  151. regulators = axp20x_regulators;
  152. nregulators = AXP20X_REG_ID_MAX;
  153. break;
  154. + case AXP221_ID:
  155. + regulators = axp22x_regulators;
  156. + nregulators = AXP22X_REG_ID_MAX;
  157. + break;
  158. default:
  159. dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n",
  160. axp20x->variant);