hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/regulator/tps65218-regulator.c
....@@ -3,7 +3,7 @@
33 *
44 * Regulator driver for TPS65218 PMIC
55 *
6
- * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
6
+ * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/
77 *
88 * This program is free software; you can redistribute it and/or
99 * modify it under the terms of the GNU General Public License version 2 as
....@@ -29,7 +29,8 @@
2929 #include <linux/mfd/tps65218.h>
3030
3131 #define TPS65218_REGULATOR(_name, _of, _id, _type, _ops, _n, _vr, _vm, _er, \
32
- _em, _cr, _cm, _lr, _nlr, _delay, _fuv, _sr, _sm) \
32
+ _em, _cr, _cm, _lr, _nlr, _delay, _fuv, _sr, _sm, \
33
+ _ct, _ncl) \
3334 { \
3435 .name = _name, \
3536 .of_match = _of, \
....@@ -42,6 +43,8 @@
4243 .vsel_mask = _vm, \
4344 .csel_reg = _cr, \
4445 .csel_mask = _cm, \
46
+ .curr_table = _ct, \
47
+ .n_current_limits = _ncl, \
4548 .enable_reg = _er, \
4649 .enable_mask = _em, \
4750 .volt_table = NULL, \
....@@ -53,17 +56,17 @@
5356 .bypass_mask = _sm, \
5457 } \
5558
56
-static const struct regulator_linear_range dcdc1_dcdc2_ranges[] = {
59
+static const struct linear_range dcdc1_dcdc2_ranges[] = {
5760 REGULATOR_LINEAR_RANGE(850000, 0x0, 0x32, 10000),
5861 REGULATOR_LINEAR_RANGE(1375000, 0x33, 0x3f, 25000),
5962 };
6063
61
-static const struct regulator_linear_range ldo1_dcdc3_ranges[] = {
64
+static const struct linear_range ldo1_dcdc3_ranges[] = {
6265 REGULATOR_LINEAR_RANGE(900000, 0x0, 0x1a, 25000),
6366 REGULATOR_LINEAR_RANGE(1600000, 0x1b, 0x3f, 50000),
6467 };
6568
66
-static const struct regulator_linear_range dcdc4_ranges[] = {
69
+static const struct linear_range dcdc4_ranges[] = {
6770 REGULATOR_LINEAR_RANGE(1175000, 0x0, 0xf, 25000),
6871 REGULATOR_LINEAR_RANGE(1600000, 0x10, 0x34, 50000),
6972 };
....@@ -125,7 +128,7 @@
125128 struct tps65218 *tps = rdev_get_drvdata(dev);
126129 unsigned int rid = rdev_get_id(dev);
127130
128
- if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1)
131
+ if (rid > TPS65218_LDO_1)
129132 return -EINVAL;
130133
131134 return tps65218_clear_bits(tps, dev->desc->bypass_reg,
....@@ -138,7 +141,7 @@
138141 struct tps65218 *tps = rdev_get_drvdata(dev);
139142 unsigned int rid = rdev_get_id(dev);
140143
141
- if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1)
144
+ if (rid > TPS65218_LDO_1)
142145 return -EINVAL;
143146
144147 /*
....@@ -162,7 +165,7 @@
162165 }
163166
164167 /* Operations permitted on DCDC1, DCDC2 */
165
-static struct regulator_ops tps65218_dcdc12_ops = {
168
+static const struct regulator_ops tps65218_dcdc12_ops = {
166169 .is_enabled = regulator_is_enabled_regmap,
167170 .enable = tps65218_pmic_enable,
168171 .disable = tps65218_pmic_disable,
....@@ -176,7 +179,7 @@
176179 };
177180
178181 /* Operations permitted on DCDC3, DCDC4 and LDO1 */
179
-static struct regulator_ops tps65218_ldo1_dcdc34_ops = {
182
+static const struct regulator_ops tps65218_ldo1_dcdc34_ops = {
180183 .is_enabled = regulator_is_enabled_regmap,
181184 .enable = tps65218_pmic_enable,
182185 .disable = tps65218_pmic_disable,
....@@ -188,7 +191,7 @@
188191 .set_suspend_disable = tps65218_pmic_set_suspend_disable,
189192 };
190193
191
-static const int ls3_currents[] = { 100, 200, 500, 1000 };
194
+static const unsigned int ls3_currents[] = { 100000, 200000, 500000, 1000000 };
192195
193196 static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev,
194197 int lim_uA)
....@@ -204,7 +207,8 @@
204207 return -EINVAL;
205208
206209 return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
207
- index << 2, TPS65218_PROTECT_L1);
210
+ index << __builtin_ctz(dev->desc->csel_mask),
211
+ TPS65218_PROTECT_L1);
208212 }
209213
210214 static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
....@@ -214,7 +218,7 @@
214218 unsigned int num_currents = ARRAY_SIZE(ls3_currents);
215219 struct tps65218 *tps = rdev_get_drvdata(dev);
216220
217
- while (index < num_currents && ls3_currents[index] < max_uA)
221
+ while (index < num_currents && ls3_currents[index] <= max_uA)
218222 index++;
219223
220224 index--;
....@@ -223,35 +227,21 @@
223227 return -EINVAL;
224228
225229 return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
226
- index << 2, TPS65218_PROTECT_L1);
230
+ index << __builtin_ctz(dev->desc->csel_mask),
231
+ TPS65218_PROTECT_L1);
227232 }
228233
229
-static int tps65218_pmic_get_current_limit(struct regulator_dev *dev)
230
-{
231
- int retval;
232
- unsigned int index;
233
- struct tps65218 *tps = rdev_get_drvdata(dev);
234
-
235
- retval = regmap_read(tps->regmap, dev->desc->csel_reg, &index);
236
- if (retval < 0)
237
- return retval;
238
-
239
- index = (index & dev->desc->csel_mask) >> 2;
240
-
241
- return ls3_currents[index];
242
-}
243
-
244
-static struct regulator_ops tps65218_ls3_ops = {
234
+static const struct regulator_ops tps65218_ls23_ops = {
245235 .is_enabled = regulator_is_enabled_regmap,
246236 .enable = tps65218_pmic_enable,
247237 .disable = tps65218_pmic_disable,
248238 .set_input_current_limit = tps65218_pmic_set_input_current_lim,
249239 .set_current_limit = tps65218_pmic_set_current_limit,
250
- .get_current_limit = tps65218_pmic_get_current_limit,
240
+ .get_current_limit = regulator_get_current_limit_regmap,
251241 };
252242
253243 /* Operations permitted on DCDC5, DCDC6 */
254
-static struct regulator_ops tps65218_dcdc56_pmic_ops = {
244
+static const struct regulator_ops tps65218_dcdc56_pmic_ops = {
255245 .is_enabled = regulator_is_enabled_regmap,
256246 .enable = tps65218_pmic_enable,
257247 .disable = tps65218_pmic_disable,
....@@ -266,48 +256,57 @@
266256 TPS65218_CONTROL_DCDC1_MASK, TPS65218_REG_ENABLE1,
267257 TPS65218_ENABLE1_DC1_EN, 0, 0, dcdc1_dcdc2_ranges,
268258 2, 4000, 0, TPS65218_REG_SEQ3,
269
- TPS65218_SEQ3_DC1_SEQ_MASK),
259
+ TPS65218_SEQ3_DC1_SEQ_MASK, NULL, 0),
270260 TPS65218_REGULATOR("DCDC2", "regulator-dcdc2", TPS65218_DCDC_2,
271261 REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64,
272262 TPS65218_REG_CONTROL_DCDC2,
273263 TPS65218_CONTROL_DCDC2_MASK, TPS65218_REG_ENABLE1,
274264 TPS65218_ENABLE1_DC2_EN, 0, 0, dcdc1_dcdc2_ranges,
275265 2, 4000, 0, TPS65218_REG_SEQ3,
276
- TPS65218_SEQ3_DC2_SEQ_MASK),
266
+ TPS65218_SEQ3_DC2_SEQ_MASK, NULL, 0),
277267 TPS65218_REGULATOR("DCDC3", "regulator-dcdc3", TPS65218_DCDC_3,
278268 REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64,
279269 TPS65218_REG_CONTROL_DCDC3,
280270 TPS65218_CONTROL_DCDC3_MASK, TPS65218_REG_ENABLE1,
281271 TPS65218_ENABLE1_DC3_EN, 0, 0, ldo1_dcdc3_ranges, 2,
282
- 0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC3_SEQ_MASK),
272
+ 0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC3_SEQ_MASK,
273
+ NULL, 0),
283274 TPS65218_REGULATOR("DCDC4", "regulator-dcdc4", TPS65218_DCDC_4,
284275 REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 53,
285276 TPS65218_REG_CONTROL_DCDC4,
286277 TPS65218_CONTROL_DCDC4_MASK, TPS65218_REG_ENABLE1,
287278 TPS65218_ENABLE1_DC4_EN, 0, 0, dcdc4_ranges, 2,
288
- 0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC4_SEQ_MASK),
279
+ 0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC4_SEQ_MASK,
280
+ NULL, 0),
289281 TPS65218_REGULATOR("DCDC5", "regulator-dcdc5", TPS65218_DCDC_5,
290282 REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1,
291283 -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC5_EN, 0,
292284 0, NULL, 0, 0, 1000000, TPS65218_REG_SEQ5,
293
- TPS65218_SEQ5_DC5_SEQ_MASK),
285
+ TPS65218_SEQ5_DC5_SEQ_MASK, NULL, 0),
294286 TPS65218_REGULATOR("DCDC6", "regulator-dcdc6", TPS65218_DCDC_6,
295287 REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1,
296288 -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC6_EN, 0,
297289 0, NULL, 0, 0, 1800000, TPS65218_REG_SEQ5,
298
- TPS65218_SEQ5_DC6_SEQ_MASK),
290
+ TPS65218_SEQ5_DC6_SEQ_MASK, NULL, 0),
299291 TPS65218_REGULATOR("LDO1", "regulator-ldo1", TPS65218_LDO_1,
300292 REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64,
301293 TPS65218_REG_CONTROL_LDO1,
302294 TPS65218_CONTROL_LDO1_MASK, TPS65218_REG_ENABLE2,
303295 TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges,
304296 2, 0, 0, TPS65218_REG_SEQ6,
305
- TPS65218_SEQ6_LDO1_SEQ_MASK),
297
+ TPS65218_SEQ6_LDO1_SEQ_MASK, NULL, 0),
298
+ TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,
299
+ REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
300
+ TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN,
301
+ TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK,
302
+ NULL, 0, 0, 0, 0, 0, ls3_currents,
303
+ ARRAY_SIZE(ls3_currents)),
306304 TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3,
307
- REGULATOR_CURRENT, tps65218_ls3_ops, 0, 0, 0,
305
+ REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
308306 TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN,
309307 TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK,
310
- NULL, 0, 0, 0, 0, 0),
308
+ NULL, 0, 0, 0, 0, 0, ls3_currents,
309
+ ARRAY_SIZE(ls3_currents)),
311310 };
312311
313312 static int tps65218_regulator_probe(struct platform_device *pdev)