gpio-nct5104d: fix compilation with kernel 6.6
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 887-v6.5-mfd-axp20x-Add-support-for-AXP192.patch
1 From 63eeabbc9dbddd7381409feccd9082e5ffabfe59 Mon Sep 17 00:00:00 2001
2 From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
3 Date: Thu, 11 May 2023 10:26:08 +0100
4 Subject: [PATCH] mfd: axp20x: Add support for AXP192
5
6 The AXP192 PMIC is similar to the AXP202/AXP209, but with different
7 regulators, additional GPIOs, and a different IRQ register layout.
8
9 Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
10 Link: https://lore.kernel.org/r/20230511092609.76183-1-aidanmacdonald.0x0@gmail.com
11 Signed-off-by: Lee Jones <lee@kernel.org>
12 ---
13 drivers/mfd/axp20x-i2c.c | 2 +
14 drivers/mfd/axp20x.c | 141 +++++++++++++++++++++++++++++++++++++
15 include/linux/mfd/axp20x.h | 84 ++++++++++++++++++++++
16 3 files changed, 227 insertions(+)
17
18 --- a/drivers/mfd/axp20x-i2c.c
19 +++ b/drivers/mfd/axp20x-i2c.c
20 @@ -60,6 +60,7 @@ static void axp20x_i2c_remove(struct i2c
21 #ifdef CONFIG_OF
22 static const struct of_device_id axp20x_i2c_of_match[] = {
23 { .compatible = "x-powers,axp152", .data = (void *)AXP152_ID },
24 + { .compatible = "x-powers,axp192", .data = (void *)AXP192_ID },
25 { .compatible = "x-powers,axp202", .data = (void *)AXP202_ID },
26 { .compatible = "x-powers,axp209", .data = (void *)AXP209_ID },
27 { .compatible = "x-powers,axp221", .data = (void *)AXP221_ID },
28 @@ -75,6 +76,7 @@ MODULE_DEVICE_TABLE(of, axp20x_i2c_of_ma
29
30 static const struct i2c_device_id axp20x_i2c_id[] = {
31 { "axp152", 0 },
32 + { "axp192", 0 },
33 { "axp202", 0 },
34 { "axp209", 0 },
35 { "axp221", 0 },
36 --- a/drivers/mfd/axp20x.c
37 +++ b/drivers/mfd/axp20x.c
38 @@ -34,6 +34,7 @@
39
40 static const char * const axp20x_model_names[] = {
41 "AXP152",
42 + "AXP192",
43 "AXP202",
44 "AXP209",
45 "AXP221",
46 @@ -94,6 +95,35 @@ static const struct regmap_access_table
47 .n_yes_ranges = ARRAY_SIZE(axp20x_volatile_ranges),
48 };
49
50 +static const struct regmap_range axp192_writeable_ranges[] = {
51 + regmap_reg_range(AXP192_DATACACHE(0), AXP192_DATACACHE(5)),
52 + regmap_reg_range(AXP192_PWR_OUT_CTRL, AXP192_IRQ5_STATE),
53 + regmap_reg_range(AXP20X_DCDC_MODE, AXP192_N_RSTO_CTRL),
54 + regmap_reg_range(AXP20X_CC_CTRL, AXP20X_CC_CTRL),
55 +};
56 +
57 +static const struct regmap_range axp192_volatile_ranges[] = {
58 + regmap_reg_range(AXP20X_PWR_INPUT_STATUS, AXP192_USB_OTG_STATUS),
59 + regmap_reg_range(AXP192_IRQ1_STATE, AXP192_IRQ4_STATE),
60 + regmap_reg_range(AXP192_IRQ5_STATE, AXP192_IRQ5_STATE),
61 + regmap_reg_range(AXP20X_ACIN_V_ADC_H, AXP20X_IPSOUT_V_HIGH_L),
62 + regmap_reg_range(AXP20X_TIMER_CTRL, AXP20X_TIMER_CTRL),
63 + regmap_reg_range(AXP192_GPIO2_0_STATE, AXP192_GPIO2_0_STATE),
64 + regmap_reg_range(AXP192_GPIO4_3_STATE, AXP192_GPIO4_3_STATE),
65 + regmap_reg_range(AXP192_N_RSTO_CTRL, AXP192_N_RSTO_CTRL),
66 + regmap_reg_range(AXP20X_CHRG_CC_31_24, AXP20X_CC_CTRL),
67 +};
68 +
69 +static const struct regmap_access_table axp192_writeable_table = {
70 + .yes_ranges = axp192_writeable_ranges,
71 + .n_yes_ranges = ARRAY_SIZE(axp192_writeable_ranges),
72 +};
73 +
74 +static const struct regmap_access_table axp192_volatile_table = {
75 + .yes_ranges = axp192_volatile_ranges,
76 + .n_yes_ranges = ARRAY_SIZE(axp192_volatile_ranges),
77 +};
78 +
79 /* AXP22x ranges are shared with the AXP809, as they cover the same range */
80 static const struct regmap_range axp22x_writeable_ranges[] = {
81 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE),
82 @@ -220,6 +250,19 @@ static const struct resource axp152_pek_
83 DEFINE_RES_IRQ_NAMED(AXP152_IRQ_PEK_FAL_EDGE, "PEK_DBF"),
84 };
85
86 +static const struct resource axp192_ac_power_supply_resources[] = {
87 + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_ACIN_PLUGIN, "ACIN_PLUGIN"),
88 + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_ACIN_REMOVAL, "ACIN_REMOVAL"),
89 + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_ACIN_OVER_V, "ACIN_OVER_V"),
90 +};
91 +
92 +static const struct resource axp192_usb_power_supply_resources[] = {
93 + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_PLUGIN, "VBUS_PLUGIN"),
94 + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_REMOVAL, "VBUS_REMOVAL"),
95 + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_VALID, "VBUS_VALID"),
96 + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_NOT_VALID, "VBUS_NOT_VALID"),
97 +};
98 +
99 static const struct resource axp20x_ac_power_supply_resources[] = {
100 DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_ACIN_PLUGIN, "ACIN_PLUGIN"),
101 DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_ACIN_REMOVAL, "ACIN_REMOVAL"),
102 @@ -302,6 +345,15 @@ static const struct regmap_config axp152
103 .cache_type = REGCACHE_RBTREE,
104 };
105
106 +static const struct regmap_config axp192_regmap_config = {
107 + .reg_bits = 8,
108 + .val_bits = 8,
109 + .wr_table = &axp192_writeable_table,
110 + .volatile_table = &axp192_volatile_table,
111 + .max_register = AXP20X_CC_CTRL,
112 + .cache_type = REGCACHE_RBTREE,
113 +};
114 +
115 static const struct regmap_config axp20x_regmap_config = {
116 .reg_bits = 8,
117 .val_bits = 8,
118 @@ -379,6 +431,42 @@ static const struct regmap_irq axp152_re
119 INIT_REGMAP_IRQ(AXP152, GPIO0_INPUT, 2, 0),
120 };
121
122 +static const struct regmap_irq axp192_regmap_irqs[] = {
123 + INIT_REGMAP_IRQ(AXP192, ACIN_OVER_V, 0, 7),
124 + INIT_REGMAP_IRQ(AXP192, ACIN_PLUGIN, 0, 6),
125 + INIT_REGMAP_IRQ(AXP192, ACIN_REMOVAL, 0, 5),
126 + INIT_REGMAP_IRQ(AXP192, VBUS_OVER_V, 0, 4),
127 + INIT_REGMAP_IRQ(AXP192, VBUS_PLUGIN, 0, 3),
128 + INIT_REGMAP_IRQ(AXP192, VBUS_REMOVAL, 0, 2),
129 + INIT_REGMAP_IRQ(AXP192, VBUS_V_LOW, 0, 1),
130 + INIT_REGMAP_IRQ(AXP192, BATT_PLUGIN, 1, 7),
131 + INIT_REGMAP_IRQ(AXP192, BATT_REMOVAL, 1, 6),
132 + INIT_REGMAP_IRQ(AXP192, BATT_ENT_ACT_MODE, 1, 5),
133 + INIT_REGMAP_IRQ(AXP192, BATT_EXIT_ACT_MODE, 1, 4),
134 + INIT_REGMAP_IRQ(AXP192, CHARG, 1, 3),
135 + INIT_REGMAP_IRQ(AXP192, CHARG_DONE, 1, 2),
136 + INIT_REGMAP_IRQ(AXP192, BATT_TEMP_HIGH, 1, 1),
137 + INIT_REGMAP_IRQ(AXP192, BATT_TEMP_LOW, 1, 0),
138 + INIT_REGMAP_IRQ(AXP192, DIE_TEMP_HIGH, 2, 7),
139 + INIT_REGMAP_IRQ(AXP192, CHARG_I_LOW, 2, 6),
140 + INIT_REGMAP_IRQ(AXP192, DCDC1_V_LONG, 2, 5),
141 + INIT_REGMAP_IRQ(AXP192, DCDC2_V_LONG, 2, 4),
142 + INIT_REGMAP_IRQ(AXP192, DCDC3_V_LONG, 2, 3),
143 + INIT_REGMAP_IRQ(AXP192, PEK_SHORT, 2, 1),
144 + INIT_REGMAP_IRQ(AXP192, PEK_LONG, 2, 0),
145 + INIT_REGMAP_IRQ(AXP192, N_OE_PWR_ON, 3, 7),
146 + INIT_REGMAP_IRQ(AXP192, N_OE_PWR_OFF, 3, 6),
147 + INIT_REGMAP_IRQ(AXP192, VBUS_VALID, 3, 5),
148 + INIT_REGMAP_IRQ(AXP192, VBUS_NOT_VALID, 3, 4),
149 + INIT_REGMAP_IRQ(AXP192, VBUS_SESS_VALID, 3, 3),
150 + INIT_REGMAP_IRQ(AXP192, VBUS_SESS_END, 3, 2),
151 + INIT_REGMAP_IRQ(AXP192, LOW_PWR_LVL, 3, 0),
152 + INIT_REGMAP_IRQ(AXP192, TIMER, 4, 7),
153 + INIT_REGMAP_IRQ(AXP192, GPIO2_INPUT, 4, 2),
154 + INIT_REGMAP_IRQ(AXP192, GPIO1_INPUT, 4, 1),
155 + INIT_REGMAP_IRQ(AXP192, GPIO0_INPUT, 4, 0),
156 +};
157 +
158 static const struct regmap_irq axp20x_regmap_irqs[] = {
159 INIT_REGMAP_IRQ(AXP20X, ACIN_OVER_V, 0, 7),
160 INIT_REGMAP_IRQ(AXP20X, ACIN_PLUGIN, 0, 6),
161 @@ -616,6 +704,32 @@ static const struct regmap_irq_chip axp1
162 .num_regs = 3,
163 };
164
165 +static unsigned int axp192_get_irq_reg(struct regmap_irq_chip_data *data,
166 + unsigned int base, int index)
167 +{
168 + /* linear mapping for IRQ1 to IRQ4 */
169 + if (index < 4)
170 + return base + index;
171 +
172 + /* handle IRQ5 separately */
173 + if (base == AXP192_IRQ1_EN)
174 + return AXP192_IRQ5_EN;
175 +
176 + return AXP192_IRQ5_STATE;
177 +}
178 +
179 +static const struct regmap_irq_chip axp192_regmap_irq_chip = {
180 + .name = "axp192_irq_chip",
181 + .status_base = AXP192_IRQ1_STATE,
182 + .ack_base = AXP192_IRQ1_STATE,
183 + .unmask_base = AXP192_IRQ1_EN,
184 + .init_ack_masked = true,
185 + .irqs = axp192_regmap_irqs,
186 + .num_irqs = ARRAY_SIZE(axp192_regmap_irqs),
187 + .num_regs = 5,
188 + .get_irq_reg = axp192_get_irq_reg,
189 +};
190 +
191 static const struct regmap_irq_chip axp20x_regmap_irq_chip = {
192 .name = "axp20x_irq_chip",
193 .status_base = AXP20X_IRQ1_STATE,
194 @@ -712,6 +826,27 @@ static const struct regmap_irq_chip axp1
195 .num_regs = 2,
196 };
197
198 +static const struct mfd_cell axp192_cells[] = {
199 + {
200 + .name = "axp192-adc",
201 + .of_compatible = "x-powers,axp192-adc",
202 + }, {
203 + .name = "axp20x-battery-power-supply",
204 + .of_compatible = "x-powers,axp192-battery-power-supply",
205 + }, {
206 + .name = "axp20x-ac-power-supply",
207 + .of_compatible = "x-powers,axp202-ac-power-supply",
208 + .num_resources = ARRAY_SIZE(axp192_ac_power_supply_resources),
209 + .resources = axp192_ac_power_supply_resources,
210 + }, {
211 + .name = "axp20x-usb-power-supply",
212 + .of_compatible = "x-powers,axp192-usb-power-supply",
213 + .num_resources = ARRAY_SIZE(axp192_usb_power_supply_resources),
214 + .resources = axp192_usb_power_supply_resources,
215 + },
216 + { .name = "axp20x-regulator" },
217 +};
218 +
219 static const struct mfd_cell axp20x_cells[] = {
220 {
221 .name = "axp20x-gpio",
222 @@ -1029,6 +1164,12 @@ int axp20x_match_device(struct axp20x_de
223 axp20x->regmap_cfg = &axp152_regmap_config;
224 axp20x->regmap_irq_chip = &axp152_regmap_irq_chip;
225 break;
226 + case AXP192_ID:
227 + axp20x->nr_cells = ARRAY_SIZE(axp192_cells);
228 + axp20x->cells = axp192_cells;
229 + axp20x->regmap_cfg = &axp192_regmap_config;
230 + axp20x->regmap_irq_chip = &axp192_regmap_irq_chip;
231 + break;
232 case AXP202_ID:
233 case AXP209_ID:
234 axp20x->nr_cells = ARRAY_SIZE(axp20x_cells);
235 --- a/include/linux/mfd/axp20x.h
236 +++ b/include/linux/mfd/axp20x.h
237 @@ -12,6 +12,7 @@
238
239 enum axp20x_variants {
240 AXP152_ID = 0,
241 + AXP192_ID,
242 AXP202_ID,
243 AXP209_ID,
244 AXP221_ID,
245 @@ -26,6 +27,7 @@ enum axp20x_variants {
246 NR_AXP20X_VARIANTS,
247 };
248
249 +#define AXP192_DATACACHE(m) (0x06 + (m))
250 #define AXP20X_DATACACHE(m) (0x04 + (m))
251
252 /* Power supply */
253 @@ -47,6 +49,13 @@ enum axp20x_variants {
254 #define AXP152_DCDC_FREQ 0x37
255 #define AXP152_DCDC_MODE 0x80
256
257 +#define AXP192_USB_OTG_STATUS 0x04
258 +#define AXP192_PWR_OUT_CTRL 0x12
259 +#define AXP192_DCDC2_V_OUT 0x23
260 +#define AXP192_DCDC1_V_OUT 0x26
261 +#define AXP192_DCDC3_V_OUT 0x27
262 +#define AXP192_LDO2_3_V_OUT 0x28
263 +
264 #define AXP20X_PWR_INPUT_STATUS 0x00
265 #define AXP20X_PWR_OP_MODE 0x01
266 #define AXP20X_USB_OTG_STATUS 0x02
267 @@ -185,6 +194,17 @@ enum axp20x_variants {
268 #define AXP152_IRQ2_STATE 0x49
269 #define AXP152_IRQ3_STATE 0x4a
270
271 +#define AXP192_IRQ1_EN 0x40
272 +#define AXP192_IRQ2_EN 0x41
273 +#define AXP192_IRQ3_EN 0x42
274 +#define AXP192_IRQ4_EN 0x43
275 +#define AXP192_IRQ1_STATE 0x44
276 +#define AXP192_IRQ2_STATE 0x45
277 +#define AXP192_IRQ3_STATE 0x46
278 +#define AXP192_IRQ4_STATE 0x47
279 +#define AXP192_IRQ5_EN 0x4a
280 +#define AXP192_IRQ5_STATE 0x4d
281 +
282 #define AXP20X_IRQ1_EN 0x40
283 #define AXP20X_IRQ2_EN 0x41
284 #define AXP20X_IRQ3_EN 0x42
285 @@ -204,6 +224,11 @@ enum axp20x_variants {
286 #define AXP15060_IRQ2_STATE 0x49
287
288 /* ADC */
289 +#define AXP192_GPIO2_V_ADC_H 0x68
290 +#define AXP192_GPIO2_V_ADC_L 0x69
291 +#define AXP192_GPIO3_V_ADC_H 0x6a
292 +#define AXP192_GPIO3_V_ADC_L 0x6b
293 +
294 #define AXP20X_ACIN_V_ADC_H 0x56
295 #define AXP20X_ACIN_V_ADC_L 0x57
296 #define AXP20X_ACIN_I_ADC_H 0x58
297 @@ -233,6 +258,8 @@ enum axp20x_variants {
298 #define AXP20X_IPSOUT_V_HIGH_L 0x7f
299
300 /* Power supply */
301 +#define AXP192_GPIO30_IN_RANGE 0x85
302 +
303 #define AXP20X_DCDC_MODE 0x80
304 #define AXP20X_ADC_EN1 0x82
305 #define AXP20X_ADC_EN2 0x83
306 @@ -261,6 +288,16 @@ enum axp20x_variants {
307 #define AXP152_PWM1_FREQ_Y 0x9c
308 #define AXP152_PWM1_DUTY_CYCLE 0x9d
309
310 +#define AXP192_GPIO0_CTRL 0x90
311 +#define AXP192_LDO_IO0_V_OUT 0x91
312 +#define AXP192_GPIO1_CTRL 0x92
313 +#define AXP192_GPIO2_CTRL 0x93
314 +#define AXP192_GPIO2_0_STATE 0x94
315 +#define AXP192_GPIO4_3_CTRL 0x95
316 +#define AXP192_GPIO4_3_STATE 0x96
317 +#define AXP192_GPIO2_0_PULL 0x97
318 +#define AXP192_N_RSTO_CTRL 0x9e
319 +
320 #define AXP20X_GPIO0_CTRL 0x90
321 #define AXP20X_LDO5_V_OUT 0x91
322 #define AXP20X_GPIO1_CTRL 0x92
323 @@ -341,6 +378,17 @@ enum axp20x_variants {
324
325 /* Regulators IDs */
326 enum {
327 + AXP192_DCDC1 = 0,
328 + AXP192_DCDC2,
329 + AXP192_DCDC3,
330 + AXP192_LDO1,
331 + AXP192_LDO2,
332 + AXP192_LDO3,
333 + AXP192_LDO_IO0,
334 + AXP192_REG_ID_MAX
335 +};
336 +
337 +enum {
338 AXP20X_LDO1 = 0,
339 AXP20X_LDO2,
340 AXP20X_LDO3,
341 @@ -531,6 +579,42 @@ enum {
342 AXP152_IRQ_GPIO0_INPUT,
343 };
344
345 +enum axp192_irqs {
346 + AXP192_IRQ_ACIN_OVER_V = 1,
347 + AXP192_IRQ_ACIN_PLUGIN,
348 + AXP192_IRQ_ACIN_REMOVAL,
349 + AXP192_IRQ_VBUS_OVER_V,
350 + AXP192_IRQ_VBUS_PLUGIN,
351 + AXP192_IRQ_VBUS_REMOVAL,
352 + AXP192_IRQ_VBUS_V_LOW,
353 + AXP192_IRQ_BATT_PLUGIN,
354 + AXP192_IRQ_BATT_REMOVAL,
355 + AXP192_IRQ_BATT_ENT_ACT_MODE,
356 + AXP192_IRQ_BATT_EXIT_ACT_MODE,
357 + AXP192_IRQ_CHARG,
358 + AXP192_IRQ_CHARG_DONE,
359 + AXP192_IRQ_BATT_TEMP_HIGH,
360 + AXP192_IRQ_BATT_TEMP_LOW,
361 + AXP192_IRQ_DIE_TEMP_HIGH,
362 + AXP192_IRQ_CHARG_I_LOW,
363 + AXP192_IRQ_DCDC1_V_LONG,
364 + AXP192_IRQ_DCDC2_V_LONG,
365 + AXP192_IRQ_DCDC3_V_LONG,
366 + AXP192_IRQ_PEK_SHORT = 22,
367 + AXP192_IRQ_PEK_LONG,
368 + AXP192_IRQ_N_OE_PWR_ON,
369 + AXP192_IRQ_N_OE_PWR_OFF,
370 + AXP192_IRQ_VBUS_VALID,
371 + AXP192_IRQ_VBUS_NOT_VALID,
372 + AXP192_IRQ_VBUS_SESS_VALID,
373 + AXP192_IRQ_VBUS_SESS_END,
374 + AXP192_IRQ_LOW_PWR_LVL = 31,
375 + AXP192_IRQ_TIMER,
376 + AXP192_IRQ_GPIO2_INPUT = 37,
377 + AXP192_IRQ_GPIO1_INPUT,
378 + AXP192_IRQ_GPIO0_INPUT,
379 +};
380 +
381 enum {
382 AXP20X_IRQ_ACIN_OVER_V = 1,
383 AXP20X_IRQ_ACIN_PLUGIN,