hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/regulator/88pm8607.c
....@@ -1,17 +1,13 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Regulators driver for Marvell 88PM8607
34 *
45 * Copyright (C) 2009 Marvell International Ltd.
56 * Haojian Zhuang <haojian.zhuang@marvell.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 */
118 #include <linux/kernel.h>
129 #include <linux/init.h>
1310 #include <linux/err.h>
14
-#include <linux/i2c.h>
1511 #include <linux/of.h>
1612 #include <linux/regulator/of_regulator.h>
1713 #include <linux/platform_device.h>
....@@ -22,12 +18,7 @@
2218
2319 struct pm8607_regulator_info {
2420 struct regulator_desc desc;
25
- struct pm860x_chip *chip;
26
- struct regulator_dev *regulator;
27
- struct i2c_client *i2c;
28
- struct i2c_client *i2c_8606;
2921
30
- unsigned int *vol_table;
3122 unsigned int *vol_suspend;
3223
3324 int slope_double;
....@@ -210,13 +201,15 @@
210201 static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index)
211202 {
212203 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
213
- int ret = -EINVAL;
204
+ int ret;
214205
215
- if (info->vol_table && (index < rdev->desc->n_voltages)) {
216
- ret = info->vol_table[index];
217
- if (info->slope_double)
218
- ret <<= 1;
219
- }
206
+ ret = regulator_list_voltage_table(rdev, index);
207
+ if (ret < 0)
208
+ return ret;
209
+
210
+ if (info->slope_double)
211
+ ret <<= 1;
212
+
220213 return ret;
221214 }
222215
....@@ -239,6 +232,8 @@
239232 { \
240233 .desc = { \
241234 .name = "PREG", \
235
+ .of_match = of_match_ptr("PREG"), \
236
+ .regulators_node = of_match_ptr("regulators"), \
242237 .ops = &pm8606_preg_ops, \
243238 .type = REGULATOR_CURRENT, \
244239 .id = PM8606_ID_PREG, \
....@@ -253,10 +248,13 @@
253248 { \
254249 .desc = { \
255250 .name = #vreg, \
251
+ .of_match = of_match_ptr(#vreg), \
252
+ .regulators_node = of_match_ptr("regulators"), \
256253 .ops = &pm8607_regulator_ops, \
257254 .type = REGULATOR_VOLTAGE, \
258255 .id = PM8607_ID_##vreg, \
259256 .owner = THIS_MODULE, \
257
+ .volt_table = vreg##_table, \
260258 .n_voltages = ARRAY_SIZE(vreg##_table), \
261259 .vsel_reg = PM8607_##vreg, \
262260 .vsel_mask = ARRAY_SIZE(vreg##_table) - 1, \
....@@ -266,7 +264,6 @@
266264 .enable_mask = 1 << (ebit), \
267265 }, \
268266 .slope_double = (0), \
269
- .vol_table = (unsigned int *)&vreg##_table, \
270267 .vol_suspend = (unsigned int *)&vreg##_suspend_table, \
271268 }
272269
....@@ -274,10 +271,13 @@
274271 { \
275272 .desc = { \
276273 .name = "LDO" #_id, \
274
+ .of_match = of_match_ptr("LDO" #_id), \
275
+ .regulators_node = of_match_ptr("regulators"), \
277276 .ops = &pm8607_regulator_ops, \
278277 .type = REGULATOR_VOLTAGE, \
279278 .id = PM8607_ID_LDO##_id, \
280279 .owner = THIS_MODULE, \
280
+ .volt_table = LDO##_id##_table, \
281281 .n_voltages = ARRAY_SIZE(LDO##_id##_table), \
282282 .vsel_reg = PM8607_##vreg, \
283283 .vsel_mask = (ARRAY_SIZE(LDO##_id##_table) - 1) << (shift), \
....@@ -285,7 +285,6 @@
285285 .enable_mask = 1 << (ebit), \
286286 }, \
287287 .slope_double = (0), \
288
- .vol_table = (unsigned int *)&LDO##_id##_table, \
289288 .vol_suspend = (unsigned int *)&LDO##_id##_suspend_table, \
290289 }
291290
....@@ -313,42 +312,13 @@
313312 PM8606_PREG(PREREGULATORB, 5),
314313 };
315314
316
-#ifdef CONFIG_OF
317
-static int pm8607_regulator_dt_init(struct platform_device *pdev,
318
- struct pm8607_regulator_info *info,
319
- struct regulator_config *config)
320
-{
321
- struct device_node *nproot, *np;
322
- nproot = pdev->dev.parent->of_node;
323
- if (!nproot)
324
- return -ENODEV;
325
- nproot = of_get_child_by_name(nproot, "regulators");
326
- if (!nproot) {
327
- dev_err(&pdev->dev, "failed to find regulators node\n");
328
- return -ENODEV;
329
- }
330
- for_each_child_of_node(nproot, np) {
331
- if (!of_node_cmp(np->name, info->desc.name)) {
332
- config->init_data =
333
- of_get_regulator_init_data(&pdev->dev, np,
334
- &info->desc);
335
- config->of_node = np;
336
- break;
337
- }
338
- }
339
- of_node_put(nproot);
340
- return 0;
341
-}
342
-#else
343
-#define pm8607_regulator_dt_init(x, y, z) (-1)
344
-#endif
345
-
346315 static int pm8607_regulator_probe(struct platform_device *pdev)
347316 {
348317 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
349318 struct pm8607_regulator_info *info = NULL;
350319 struct regulator_init_data *pdata = dev_get_platdata(&pdev->dev);
351320 struct regulator_config config = { };
321
+ struct regulator_dev *rdev;
352322 struct resource *res;
353323 int i;
354324
....@@ -371,33 +341,27 @@
371341 /* i is used to check regulator ID */
372342 i = -1;
373343 }
374
- info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
375
- info->i2c_8606 = (chip->id == CHIP_PM8607) ? chip->companion :
376
- chip->client;
377
- info->chip = chip;
378344
379345 /* check DVC ramp slope double */
380
- if ((i == PM8607_ID_BUCK3) && info->chip->buck3_double)
346
+ if ((i == PM8607_ID_BUCK3) && chip->buck3_double)
381347 info->slope_double = 1;
382348
383
- config.dev = &pdev->dev;
349
+ config.dev = chip->dev;
384350 config.driver_data = info;
385351
386
- if (pm8607_regulator_dt_init(pdev, info, &config))
387
- if (pdata)
388
- config.init_data = pdata;
352
+ if (pdata)
353
+ config.init_data = pdata;
389354
390355 if (chip->id == CHIP_PM8607)
391356 config.regmap = chip->regmap;
392357 else
393358 config.regmap = chip->regmap_companion;
394359
395
- info->regulator = devm_regulator_register(&pdev->dev, &info->desc,
396
- &config);
397
- if (IS_ERR(info->regulator)) {
360
+ rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
361
+ if (IS_ERR(rdev)) {
398362 dev_err(&pdev->dev, "failed to register regulator %s\n",
399363 info->desc.name);
400
- return PTR_ERR(info->regulator);
364
+ return PTR_ERR(rdev);
401365 }
402366
403367 platform_set_drvdata(pdev, info);