hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/regulator/bcm590xx-regulator.c
....@@ -1,13 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Broadcom BCM590xx regulator driver
34 *
45 * Copyright 2014 Linaro Limited
56 * Author: Matt Porter <mporter@linaro.org>
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms of the GNU General Public License as published by the
9
- * Free Software Foundation; either version 2 of the License, or (at your
10
- * option) any later version.
117 */
128
139 #include <linux/err.h>
....@@ -103,10 +99,6 @@
10399 ((n > BCM590XX_REG_VSR) && (n < BCM590XX_REG_VBUS))
104100 #define BCM590XX_REG_IS_VBUS(n) (n == BCM590XX_REG_VBUS)
105101
106
-struct bcm590xx_board {
107
- struct regulator_init_data *bcm590xx_pmu_init_data[BCM590XX_NUM_REGS];
108
-};
109
-
110102 /* LDO group A: supported voltages in microvolts */
111103 static const unsigned int ldo_a_table[] = {
112104 1200000, 1800000, 2500000, 2700000, 2800000,
....@@ -124,14 +116,14 @@
124116 };
125117
126118 /* DCDC group CSR: supported voltages in microvolts */
127
-static const struct regulator_linear_range dcdc_csr_ranges[] = {
119
+static const struct linear_range dcdc_csr_ranges[] = {
128120 REGULATOR_LINEAR_RANGE(860000, 2, 50, 10000),
129121 REGULATOR_LINEAR_RANGE(1360000, 51, 55, 20000),
130122 REGULATOR_LINEAR_RANGE(900000, 56, 63, 0),
131123 };
132124
133125 /* DCDC group IOSR1: supported voltages in microvolts */
134
-static const struct regulator_linear_range dcdc_iosr1_ranges[] = {
126
+static const struct linear_range dcdc_iosr1_ranges[] = {
135127 REGULATOR_LINEAR_RANGE(860000, 2, 51, 10000),
136128 REGULATOR_LINEAR_RANGE(1500000, 52, 52, 0),
137129 REGULATOR_LINEAR_RANGE(1800000, 53, 53, 0),
....@@ -139,7 +131,7 @@
139131 };
140132
141133 /* DCDC group SDSR1: supported voltages in microvolts */
142
-static const struct regulator_linear_range dcdc_sdsr1_ranges[] = {
134
+static const struct linear_range dcdc_sdsr1_ranges[] = {
143135 REGULATOR_LINEAR_RANGE(860000, 2, 50, 10000),
144136 REGULATOR_LINEAR_RANGE(1340000, 51, 51, 0),
145137 REGULATOR_LINEAR_RANGE(900000, 52, 63, 0),
....@@ -151,7 +143,7 @@
151143 u8 n_voltages;
152144 const unsigned int *volt_table;
153145 u8 n_linear_ranges;
154
- const struct regulator_linear_range *linear_ranges;
146
+ const struct linear_range *linear_ranges;
155147 };
156148
157149 #define BCM590XX_REG_TABLE(_name, _table) \
....@@ -242,8 +234,12 @@
242234 case BCM590XX_REG_SDSR2:
243235 reg = BCM590XX_SDSR2PMCTRL1;
244236 break;
237
+ case BCM590XX_REG_VSR:
238
+ reg = BCM590XX_VSRPMCTRL1;
239
+ break;
245240 case BCM590XX_REG_VBUS:
246241 reg = BCM590XX_OTG_CTRL;
242
+ break;
247243 }
248244
249245
....@@ -276,104 +272,14 @@
276272 .disable = regulator_disable_regmap,
277273 };
278274
279
-#define BCM590XX_MATCH(_name, _id) \
280
- { \
281
- .name = #_name, \
282
- .driver_data = (void *)&bcm590xx_regs[BCM590XX_REG_##_id], \
283
- }
284
-
285
-static struct of_regulator_match bcm590xx_matches[] = {
286
- BCM590XX_MATCH(rfldo, RFLDO),
287
- BCM590XX_MATCH(camldo1, CAMLDO1),
288
- BCM590XX_MATCH(camldo2, CAMLDO2),
289
- BCM590XX_MATCH(simldo1, SIMLDO1),
290
- BCM590XX_MATCH(simldo2, SIMLDO2),
291
- BCM590XX_MATCH(sdldo, SDLDO),
292
- BCM590XX_MATCH(sdxldo, SDXLDO),
293
- BCM590XX_MATCH(mmcldo1, MMCLDO1),
294
- BCM590XX_MATCH(mmcldo2, MMCLDO2),
295
- BCM590XX_MATCH(audldo, AUDLDO),
296
- BCM590XX_MATCH(micldo, MICLDO),
297
- BCM590XX_MATCH(usbldo, USBLDO),
298
- BCM590XX_MATCH(vibldo, VIBLDO),
299
- BCM590XX_MATCH(csr, CSR),
300
- BCM590XX_MATCH(iosr1, IOSR1),
301
- BCM590XX_MATCH(iosr2, IOSR2),
302
- BCM590XX_MATCH(msr, MSR),
303
- BCM590XX_MATCH(sdsr1, SDSR1),
304
- BCM590XX_MATCH(sdsr2, SDSR2),
305
- BCM590XX_MATCH(vsr, VSR),
306
- BCM590XX_MATCH(gpldo1, GPLDO1),
307
- BCM590XX_MATCH(gpldo2, GPLDO2),
308
- BCM590XX_MATCH(gpldo3, GPLDO3),
309
- BCM590XX_MATCH(gpldo4, GPLDO4),
310
- BCM590XX_MATCH(gpldo5, GPLDO5),
311
- BCM590XX_MATCH(gpldo6, GPLDO6),
312
- BCM590XX_MATCH(vbus, VBUS),
313
-};
314
-
315
-static struct bcm590xx_board *bcm590xx_parse_dt_reg_data(
316
- struct platform_device *pdev,
317
- struct of_regulator_match **bcm590xx_reg_matches)
318
-{
319
- struct bcm590xx_board *data;
320
- struct device_node *np = pdev->dev.parent->of_node;
321
- struct device_node *regulators;
322
- struct of_regulator_match *matches = bcm590xx_matches;
323
- int count = ARRAY_SIZE(bcm590xx_matches);
324
- int idx = 0;
325
- int ret;
326
-
327
- if (!np) {
328
- dev_err(&pdev->dev, "of node not found\n");
329
- return NULL;
330
- }
331
-
332
- data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
333
- if (!data)
334
- return NULL;
335
-
336
- np = of_node_get(np);
337
- regulators = of_get_child_by_name(np, "regulators");
338
- if (!regulators) {
339
- dev_warn(&pdev->dev, "regulator node not found\n");
340
- return NULL;
341
- }
342
-
343
- ret = of_regulator_match(&pdev->dev, regulators, matches, count);
344
- of_node_put(regulators);
345
- if (ret < 0) {
346
- dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
347
- ret);
348
- return NULL;
349
- }
350
-
351
- *bcm590xx_reg_matches = matches;
352
-
353
- for (idx = 0; idx < count; idx++) {
354
- if (!matches[idx].init_data || !matches[idx].of_node)
355
- continue;
356
-
357
- data->bcm590xx_pmu_init_data[idx] = matches[idx].init_data;
358
- }
359
-
360
- return data;
361
-}
362
-
363275 static int bcm590xx_probe(struct platform_device *pdev)
364276 {
365277 struct bcm590xx *bcm590xx = dev_get_drvdata(pdev->dev.parent);
366
- struct bcm590xx_board *pmu_data = NULL;
367278 struct bcm590xx_reg *pmu;
368279 struct regulator_config config = { };
369280 struct bcm590xx_info *info;
370
- struct regulator_init_data *reg_data;
371281 struct regulator_dev *rdev;
372
- struct of_regulator_match *bcm590xx_reg_matches = NULL;
373282 int i;
374
-
375
- pmu_data = bcm590xx_parse_dt_reg_data(pdev,
376
- &bcm590xx_reg_matches);
377283
378284 pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL);
379285 if (!pmu)
....@@ -393,13 +299,10 @@
393299 info = bcm590xx_regs;
394300
395301 for (i = 0; i < BCM590XX_NUM_REGS; i++, info++) {
396
- if (pmu_data)
397
- reg_data = pmu_data->bcm590xx_pmu_init_data[i];
398
- else
399
- reg_data = NULL;
400
-
401302 /* Register the regulators */
402303 pmu->desc[i].name = info->name;
304
+ pmu->desc[i].of_match = of_match_ptr(info->name);
305
+ pmu->desc[i].regulators_node = of_match_ptr("regulators");
403306 pmu->desc[i].supply_name = info->vin_name;
404307 pmu->desc[i].id = i;
405308 pmu->desc[i].volt_table = info->volt_table;
....@@ -429,15 +332,11 @@
429332 pmu->desc[i].owner = THIS_MODULE;
430333
431334 config.dev = bcm590xx->dev;
432
- config.init_data = reg_data;
433335 config.driver_data = pmu;
434336 if (BCM590XX_REG_IS_GPLDO(i) || BCM590XX_REG_IS_VBUS(i))
435337 config.regmap = bcm590xx->regmap_sec;
436338 else
437339 config.regmap = bcm590xx->regmap_pri;
438
-
439
- if (bcm590xx_reg_matches)
440
- config.of_node = bcm590xx_reg_matches[i].of_node;
441340
442341 rdev = devm_regulator_register(&pdev->dev, &pmu->desc[i],
443342 &config);