884-v6.5-mfd-axp20x-Add-support-for-AXP313a-PMIC.patch 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. From 75c8cb2f4cb218aaf4ea68cab08d6dbc96eeae15 Mon Sep 17 00:00:00 2001
  2. From: Martin Botka <[email protected]>
  3. Date: Wed, 24 May 2023 01:00:10 +0100
  4. Subject: [PATCH] mfd: axp20x: Add support for AXP313a PMIC
  5. The AXP313a is a PMIC chip produced by X-Powers, it can be connected via
  6. an I2C bus.
  7. The name AXP1530 seems to appear as well, and this is what is used in
  8. the BSP driver. From all we know it's the same chip, just a different
  9. name. However we have only seen AXP313a chips in the wild, so go with
  10. this name.
  11. Compared to the other AXP PMICs it's a rather simple affair: just three
  12. DCDC converters, three LDOs, and no battery charging support.
  13. Describe the regmap and the MFD bits, along with the registers exposed
  14. via I2C. Aside from the various regulators, also describe the power key
  15. interrupts, and adjust the shutdown handler routine to use a different
  16. register than the other PMICs.
  17. Eventually advertise the device using the new compatible string.
  18. Signed-off-by: Martin Botka <[email protected]>
  19. Signed-off-by: Andre Przywara <[email protected]>
  20. Reviewed-by: Chen-Yu Tsai <[email protected]>
  21. Link: https://lore.kernel.org/r/[email protected]
  22. Signed-off-by: Lee Jones <[email protected]>
  23. ---
  24. drivers/mfd/axp20x-i2c.c | 2 +
  25. drivers/mfd/axp20x.c | 78 +++++++++++++++++++++++++++++++++++++-
  26. include/linux/mfd/axp20x.h | 32 ++++++++++++++++
  27. 3 files changed, 111 insertions(+), 1 deletion(-)
  28. --- a/drivers/mfd/axp20x-i2c.c
  29. +++ b/drivers/mfd/axp20x-i2c.c
  30. @@ -64,6 +64,7 @@ static const struct of_device_id axp20x_
  31. { .compatible = "x-powers,axp209", .data = (void *)AXP209_ID },
  32. { .compatible = "x-powers,axp221", .data = (void *)AXP221_ID },
  33. { .compatible = "x-powers,axp223", .data = (void *)AXP223_ID },
  34. + { .compatible = "x-powers,axp313a", .data = (void *)AXP313A_ID },
  35. { .compatible = "x-powers,axp803", .data = (void *)AXP803_ID },
  36. { .compatible = "x-powers,axp806", .data = (void *)AXP806_ID },
  37. { .compatible = "x-powers,axp15060", .data = (void *)AXP15060_ID },
  38. @@ -78,6 +79,7 @@ static const struct i2c_device_id axp20x
  39. { "axp209", 0 },
  40. { "axp221", 0 },
  41. { "axp223", 0 },
  42. + { "axp313a", 0 },
  43. { "axp803", 0 },
  44. { "axp806", 0 },
  45. { "axp15060", 0 },
  46. --- a/drivers/mfd/axp20x.c
  47. +++ b/drivers/mfd/axp20x.c
  48. @@ -39,6 +39,7 @@ static const char * const axp20x_model_n
  49. "AXP221",
  50. "AXP223",
  51. "AXP288",
  52. + "AXP313a",
  53. "AXP803",
  54. "AXP806",
  55. "AXP809",
  56. @@ -156,6 +157,25 @@ static const struct regmap_range axp806_
  57. regmap_reg_range(AXP806_REG_ADDR_EXT, AXP806_REG_ADDR_EXT),
  58. };
  59. +static const struct regmap_range axp313a_writeable_ranges[] = {
  60. + regmap_reg_range(AXP313A_ON_INDICATE, AXP313A_IRQ_STATE),
  61. +};
  62. +
  63. +static const struct regmap_range axp313a_volatile_ranges[] = {
  64. + regmap_reg_range(AXP313A_SHUTDOWN_CTRL, AXP313A_SHUTDOWN_CTRL),
  65. + regmap_reg_range(AXP313A_IRQ_STATE, AXP313A_IRQ_STATE),
  66. +};
  67. +
  68. +static const struct regmap_access_table axp313a_writeable_table = {
  69. + .yes_ranges = axp313a_writeable_ranges,
  70. + .n_yes_ranges = ARRAY_SIZE(axp313a_writeable_ranges),
  71. +};
  72. +
  73. +static const struct regmap_access_table axp313a_volatile_table = {
  74. + .yes_ranges = axp313a_volatile_ranges,
  75. + .n_yes_ranges = ARRAY_SIZE(axp313a_volatile_ranges),
  76. +};
  77. +
  78. static const struct regmap_range axp806_volatile_ranges[] = {
  79. regmap_reg_range(AXP20X_IRQ1_STATE, AXP20X_IRQ2_STATE),
  80. };
  81. @@ -248,6 +268,11 @@ static const struct resource axp288_fuel
  82. DEFINE_RES_IRQ(AXP288_IRQ_WL1),
  83. };
  84. +static const struct resource axp313a_pek_resources[] = {
  85. + DEFINE_RES_IRQ_NAMED(AXP313A_IRQ_PEK_RIS_EDGE, "PEK_DBR"),
  86. + DEFINE_RES_IRQ_NAMED(AXP313A_IRQ_PEK_FAL_EDGE, "PEK_DBF"),
  87. +};
  88. +
  89. static const struct resource axp803_pek_resources[] = {
  90. DEFINE_RES_IRQ_NAMED(AXP803_IRQ_PEK_RIS_EDGE, "PEK_DBR"),
  91. DEFINE_RES_IRQ_NAMED(AXP803_IRQ_PEK_FAL_EDGE, "PEK_DBF"),
  92. @@ -304,6 +329,15 @@ static const struct regmap_config axp288
  93. .cache_type = REGCACHE_RBTREE,
  94. };
  95. +static const struct regmap_config axp313a_regmap_config = {
  96. + .reg_bits = 8,
  97. + .val_bits = 8,
  98. + .wr_table = &axp313a_writeable_table,
  99. + .volatile_table = &axp313a_volatile_table,
  100. + .max_register = AXP313A_IRQ_STATE,
  101. + .cache_type = REGCACHE_RBTREE,
  102. +};
  103. +
  104. static const struct regmap_config axp806_regmap_config = {
  105. .reg_bits = 8,
  106. .val_bits = 8,
  107. @@ -456,6 +490,16 @@ static const struct regmap_irq axp288_re
  108. INIT_REGMAP_IRQ(AXP288, BC_USB_CHNG, 5, 1),
  109. };
  110. +static const struct regmap_irq axp313a_regmap_irqs[] = {
  111. + INIT_REGMAP_IRQ(AXP313A, PEK_RIS_EDGE, 0, 7),
  112. + INIT_REGMAP_IRQ(AXP313A, PEK_FAL_EDGE, 0, 6),
  113. + INIT_REGMAP_IRQ(AXP313A, PEK_SHORT, 0, 5),
  114. + INIT_REGMAP_IRQ(AXP313A, PEK_LONG, 0, 4),
  115. + INIT_REGMAP_IRQ(AXP313A, DCDC3_V_LOW, 0, 3),
  116. + INIT_REGMAP_IRQ(AXP313A, DCDC2_V_LOW, 0, 2),
  117. + INIT_REGMAP_IRQ(AXP313A, DIE_TEMP_HIGH, 0, 0),
  118. +};
  119. +
  120. static const struct regmap_irq axp803_regmap_irqs[] = {
  121. INIT_REGMAP_IRQ(AXP803, ACIN_OVER_V, 0, 7),
  122. INIT_REGMAP_IRQ(AXP803, ACIN_PLUGIN, 0, 6),
  123. @@ -610,6 +654,17 @@ static const struct regmap_irq_chip axp2
  124. };
  125. +static const struct regmap_irq_chip axp313a_regmap_irq_chip = {
  126. + .name = "axp313a_irq_chip",
  127. + .status_base = AXP313A_IRQ_STATE,
  128. + .ack_base = AXP313A_IRQ_STATE,
  129. + .unmask_base = AXP313A_IRQ_EN,
  130. + .init_ack_masked = true,
  131. + .irqs = axp313a_regmap_irqs,
  132. + .num_irqs = ARRAY_SIZE(axp313a_regmap_irqs),
  133. + .num_regs = 1,
  134. +};
  135. +
  136. static const struct regmap_irq_chip axp803_regmap_irq_chip = {
  137. .name = "axp803",
  138. .status_base = AXP20X_IRQ1_STATE,
  139. @@ -752,6 +807,11 @@ static const struct mfd_cell axp152_cell
  140. },
  141. };
  142. +static struct mfd_cell axp313a_cells[] = {
  143. + MFD_CELL_NAME("axp20x-regulator"),
  144. + MFD_CELL_RES("axp313a-pek", axp313a_pek_resources),
  145. +};
  146. +
  147. static const struct resource axp288_adc_resources[] = {
  148. DEFINE_RES_IRQ_NAMED(AXP288_IRQ_GPADC, "GPADC"),
  149. };
  150. @@ -921,8 +981,18 @@ static const struct mfd_cell axp_regulat
  151. static int axp20x_power_off(struct sys_off_data *data)
  152. {
  153. struct axp20x_dev *axp20x = data->cb_data;
  154. + unsigned int shutdown_reg;
  155. - regmap_write(axp20x->regmap, AXP20X_OFF_CTRL, AXP20X_OFF);
  156. + switch (axp20x->variant) {
  157. + case AXP313A_ID:
  158. + shutdown_reg = AXP313A_SHUTDOWN_CTRL;
  159. + break;
  160. + default:
  161. + shutdown_reg = AXP20X_OFF_CTRL;
  162. + break;
  163. + }
  164. +
  165. + regmap_write(axp20x->regmap, shutdown_reg, AXP20X_OFF);
  166. /* Give capacitors etc. time to drain to avoid kernel panic msg. */
  167. mdelay(500);
  168. @@ -985,6 +1055,12 @@ int axp20x_match_device(struct axp20x_de
  169. axp20x->regmap_irq_chip = &axp288_regmap_irq_chip;
  170. axp20x->irq_flags = IRQF_TRIGGER_LOW;
  171. break;
  172. + case AXP313A_ID:
  173. + axp20x->nr_cells = ARRAY_SIZE(axp313a_cells);
  174. + axp20x->cells = axp313a_cells;
  175. + axp20x->regmap_cfg = &axp313a_regmap_config;
  176. + axp20x->regmap_irq_chip = &axp313a_regmap_irq_chip;
  177. + break;
  178. case AXP803_ID:
  179. axp20x->nr_cells = ARRAY_SIZE(axp803_cells);
  180. axp20x->cells = axp803_cells;
  181. --- a/include/linux/mfd/axp20x.h
  182. +++ b/include/linux/mfd/axp20x.h
  183. @@ -17,6 +17,7 @@ enum axp20x_variants {
  184. AXP221_ID,
  185. AXP223_ID,
  186. AXP288_ID,
  187. + AXP313A_ID,
  188. AXP803_ID,
  189. AXP806_ID,
  190. AXP809_ID,
  191. @@ -92,6 +93,17 @@ enum axp20x_variants {
  192. #define AXP22X_ALDO3_V_OUT 0x2a
  193. #define AXP22X_CHRG_CTRL3 0x35
  194. +#define AXP313A_ON_INDICATE 0x00
  195. +#define AXP313A_OUTPUT_CONTROL 0x10
  196. +#define AXP313A_DCDC1_CONRTOL 0x13
  197. +#define AXP313A_DCDC2_CONRTOL 0x14
  198. +#define AXP313A_DCDC3_CONRTOL 0x15
  199. +#define AXP313A_ALDO1_CONRTOL 0x16
  200. +#define AXP313A_DLDO1_CONRTOL 0x17
  201. +#define AXP313A_SHUTDOWN_CTRL 0x1a
  202. +#define AXP313A_IRQ_EN 0x20
  203. +#define AXP313A_IRQ_STATE 0x21
  204. +
  205. #define AXP806_STARTUP_SRC 0x00
  206. #define AXP806_CHIP_ID 0x03
  207. #define AXP806_PWR_OUT_CTRL1 0x10
  208. @@ -364,6 +376,16 @@ enum {
  209. };
  210. enum {
  211. + AXP313A_DCDC1 = 0,
  212. + AXP313A_DCDC2,
  213. + AXP313A_DCDC3,
  214. + AXP313A_ALDO1,
  215. + AXP313A_DLDO1,
  216. + AXP313A_RTC_LDO,
  217. + AXP313A_REG_ID_MAX,
  218. +};
  219. +
  220. +enum {
  221. AXP806_DCDCA = 0,
  222. AXP806_DCDCB,
  223. AXP806_DCDCC,
  224. @@ -616,6 +638,16 @@ enum axp288_irqs {
  225. AXP288_IRQ_BC_USB_CHNG,
  226. };
  227. +enum axp313a_irqs {
  228. + AXP313A_IRQ_DIE_TEMP_HIGH,
  229. + AXP313A_IRQ_DCDC2_V_LOW = 2,
  230. + AXP313A_IRQ_DCDC3_V_LOW,
  231. + AXP313A_IRQ_PEK_LONG,
  232. + AXP313A_IRQ_PEK_SHORT,
  233. + AXP313A_IRQ_PEK_FAL_EDGE,
  234. + AXP313A_IRQ_PEK_RIS_EDGE,
  235. +};
  236. +
  237. enum axp803_irqs {
  238. AXP803_IRQ_ACIN_OVER_V = 1,
  239. AXP803_IRQ_ACIN_PLUGIN,