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