forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/regulator/db8500-prcmu.c
....@@ -1,7 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) ST-Ericsson SA 2010
34 *
4
- * License Terms: GNU General Public License v2
55 * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
66 * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
77 *
....@@ -75,7 +75,7 @@
7575 }
7676
7777 /* db8500 regulator operations */
78
-static struct regulator_ops db8500_regulator_ops = {
78
+static const struct regulator_ops db8500_regulator_ops = {
7979 .enable = db8500_regulator_enable,
8080 .disable = db8500_regulator_disable,
8181 .is_enabled = db8500_regulator_is_enabled,
....@@ -181,7 +181,7 @@
181181 goto out;
182182 }
183183
184
- info->is_enabled = 0;
184
+ info->is_enabled = false;
185185 out:
186186 return ret;
187187 }
....@@ -200,7 +200,7 @@
200200 return info->is_enabled;
201201 }
202202
203
-static struct regulator_ops db8500_regulator_switch_ops = {
203
+static const struct regulator_ops db8500_regulator_switch_ops = {
204204 .enable = db8500_regulator_switch_enable,
205205 .disable = db8500_regulator_switch_disable,
206206 .is_enabled = db8500_regulator_switch_is_enabled,
....@@ -214,6 +214,7 @@
214214 [DB8500_REGULATOR_VAPE] = {
215215 .desc = {
216216 .name = "db8500-vape",
217
+ .of_match = of_match_ptr("db8500_vape"),
217218 .id = DB8500_REGULATOR_VAPE,
218219 .ops = &db8500_regulator_ops,
219220 .type = REGULATOR_VOLTAGE,
....@@ -223,6 +224,7 @@
223224 [DB8500_REGULATOR_VARM] = {
224225 .desc = {
225226 .name = "db8500-varm",
227
+ .of_match = of_match_ptr("db8500_varm"),
226228 .id = DB8500_REGULATOR_VARM,
227229 .ops = &db8500_regulator_ops,
228230 .type = REGULATOR_VOLTAGE,
....@@ -232,6 +234,7 @@
232234 [DB8500_REGULATOR_VMODEM] = {
233235 .desc = {
234236 .name = "db8500-vmodem",
237
+ .of_match = of_match_ptr("db8500_vmodem"),
235238 .id = DB8500_REGULATOR_VMODEM,
236239 .ops = &db8500_regulator_ops,
237240 .type = REGULATOR_VOLTAGE,
....@@ -241,6 +244,7 @@
241244 [DB8500_REGULATOR_VPLL] = {
242245 .desc = {
243246 .name = "db8500-vpll",
247
+ .of_match = of_match_ptr("db8500_vpll"),
244248 .id = DB8500_REGULATOR_VPLL,
245249 .ops = &db8500_regulator_ops,
246250 .type = REGULATOR_VOLTAGE,
....@@ -250,6 +254,7 @@
250254 [DB8500_REGULATOR_VSMPS1] = {
251255 .desc = {
252256 .name = "db8500-vsmps1",
257
+ .of_match = of_match_ptr("db8500_vsmps1"),
253258 .id = DB8500_REGULATOR_VSMPS1,
254259 .ops = &db8500_regulator_ops,
255260 .type = REGULATOR_VOLTAGE,
....@@ -259,6 +264,7 @@
259264 [DB8500_REGULATOR_VSMPS2] = {
260265 .desc = {
261266 .name = "db8500-vsmps2",
267
+ .of_match = of_match_ptr("db8500_vsmps2"),
262268 .id = DB8500_REGULATOR_VSMPS2,
263269 .ops = &db8500_regulator_ops,
264270 .type = REGULATOR_VOLTAGE,
....@@ -271,6 +277,7 @@
271277 [DB8500_REGULATOR_VSMPS3] = {
272278 .desc = {
273279 .name = "db8500-vsmps3",
280
+ .of_match = of_match_ptr("db8500_vsmps3"),
274281 .id = DB8500_REGULATOR_VSMPS3,
275282 .ops = &db8500_regulator_ops,
276283 .type = REGULATOR_VOLTAGE,
....@@ -280,6 +287,7 @@
280287 [DB8500_REGULATOR_VRF1] = {
281288 .desc = {
282289 .name = "db8500-vrf1",
290
+ .of_match = of_match_ptr("db8500_vrf1"),
283291 .id = DB8500_REGULATOR_VRF1,
284292 .ops = &db8500_regulator_ops,
285293 .type = REGULATOR_VOLTAGE,
....@@ -289,6 +297,7 @@
289297 [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {
290298 .desc = {
291299 .name = "db8500-sva-mmdsp",
300
+ .of_match = of_match_ptr("db8500_sva_mmdsp"),
292301 .id = DB8500_REGULATOR_SWITCH_SVAMMDSP,
293302 .ops = &db8500_regulator_switch_ops,
294303 .type = REGULATOR_VOLTAGE,
....@@ -299,6 +308,7 @@
299308 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
300309 .desc = {
301310 .name = "db8500-sva-mmdsp-ret",
311
+ .of_match = of_match_ptr("db8500_sva_mmdsp_ret"),
302312 .id = DB8500_REGULATOR_SWITCH_SVAMMDSPRET,
303313 .ops = &db8500_regulator_switch_ops,
304314 .type = REGULATOR_VOLTAGE,
....@@ -310,6 +320,7 @@
310320 [DB8500_REGULATOR_SWITCH_SVAPIPE] = {
311321 .desc = {
312322 .name = "db8500-sva-pipe",
323
+ .of_match = of_match_ptr("db8500_sva_pipe"),
313324 .id = DB8500_REGULATOR_SWITCH_SVAPIPE,
314325 .ops = &db8500_regulator_switch_ops,
315326 .type = REGULATOR_VOLTAGE,
....@@ -320,6 +331,7 @@
320331 [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
321332 .desc = {
322333 .name = "db8500-sia-mmdsp",
334
+ .of_match = of_match_ptr("db8500_sia_mmdsp"),
323335 .id = DB8500_REGULATOR_SWITCH_SIAMMDSP,
324336 .ops = &db8500_regulator_switch_ops,
325337 .type = REGULATOR_VOLTAGE,
....@@ -330,6 +342,7 @@
330342 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
331343 .desc = {
332344 .name = "db8500-sia-mmdsp-ret",
345
+ .of_match = of_match_ptr("db8500_sia_mmdsp_ret"),
333346 .id = DB8500_REGULATOR_SWITCH_SIAMMDSPRET,
334347 .ops = &db8500_regulator_switch_ops,
335348 .type = REGULATOR_VOLTAGE,
....@@ -341,6 +354,7 @@
341354 [DB8500_REGULATOR_SWITCH_SIAPIPE] = {
342355 .desc = {
343356 .name = "db8500-sia-pipe",
357
+ .of_match = of_match_ptr("db8500_sia_pipe"),
344358 .id = DB8500_REGULATOR_SWITCH_SIAPIPE,
345359 .ops = &db8500_regulator_switch_ops,
346360 .type = REGULATOR_VOLTAGE,
....@@ -351,6 +365,7 @@
351365 [DB8500_REGULATOR_SWITCH_SGA] = {
352366 .desc = {
353367 .name = "db8500-sga",
368
+ .of_match = of_match_ptr("db8500_sga"),
354369 .id = DB8500_REGULATOR_SWITCH_SGA,
355370 .ops = &db8500_regulator_switch_ops,
356371 .type = REGULATOR_VOLTAGE,
....@@ -361,6 +376,7 @@
361376 [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
362377 .desc = {
363378 .name = "db8500-b2r2-mcde",
379
+ .of_match = of_match_ptr("db8500_b2r2_mcde"),
364380 .id = DB8500_REGULATOR_SWITCH_B2R2_MCDE,
365381 .ops = &db8500_regulator_switch_ops,
366382 .type = REGULATOR_VOLTAGE,
....@@ -371,6 +387,7 @@
371387 [DB8500_REGULATOR_SWITCH_ESRAM12] = {
372388 .desc = {
373389 .name = "db8500-esram12",
390
+ .of_match = of_match_ptr("db8500_esram12"),
374391 .id = DB8500_REGULATOR_SWITCH_ESRAM12,
375392 .ops = &db8500_regulator_switch_ops,
376393 .type = REGULATOR_VOLTAGE,
....@@ -382,6 +399,7 @@
382399 [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
383400 .desc = {
384401 .name = "db8500-esram12-ret",
402
+ .of_match = of_match_ptr("db8500_esram12_ret"),
385403 .id = DB8500_REGULATOR_SWITCH_ESRAM12RET,
386404 .ops = &db8500_regulator_switch_ops,
387405 .type = REGULATOR_VOLTAGE,
....@@ -393,6 +411,7 @@
393411 [DB8500_REGULATOR_SWITCH_ESRAM34] = {
394412 .desc = {
395413 .name = "db8500-esram34",
414
+ .of_match = of_match_ptr("db8500_esram34"),
396415 .id = DB8500_REGULATOR_SWITCH_ESRAM34,
397416 .ops = &db8500_regulator_switch_ops,
398417 .type = REGULATOR_VOLTAGE,
....@@ -404,6 +423,7 @@
404423 [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
405424 .desc = {
406425 .name = "db8500-esram34-ret",
426
+ .of_match = of_match_ptr("db8500_esram34_ret"),
407427 .id = DB8500_REGULATOR_SWITCH_ESRAM34RET,
408428 .ops = &db8500_regulator_switch_ops,
409429 .type = REGULATOR_VOLTAGE,
....@@ -414,113 +434,38 @@
414434 },
415435 };
416436
417
-static int db8500_regulator_register(struct platform_device *pdev,
418
- struct regulator_init_data *init_data,
419
- int id,
420
- struct device_node *np)
421
-{
422
- struct dbx500_regulator_info *info;
423
- struct regulator_config config = { };
424
- int err;
425
-
426
- /* assign per-regulator data */
427
- info = &dbx500_regulator_info[id];
428
- info->dev = &pdev->dev;
429
-
430
- config.dev = &pdev->dev;
431
- config.init_data = init_data;
432
- config.driver_data = info;
433
- config.of_node = np;
434
-
435
- /* register with the regulator framework */
436
- info->rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
437
- if (IS_ERR(info->rdev)) {
438
- err = PTR_ERR(info->rdev);
439
- dev_err(&pdev->dev, "failed to register %s: err %i\n",
440
- info->desc.name, err);
441
- return err;
442
- }
443
-
444
- dev_dbg(rdev_get_dev(info->rdev),
445
- "regulator-%s-probed\n", info->desc.name);
446
-
447
- return 0;
448
-}
449
-
450
-static struct of_regulator_match db8500_regulator_matches[] = {
451
- { .name = "db8500_vape", .driver_data = (void *) DB8500_REGULATOR_VAPE, },
452
- { .name = "db8500_varm", .driver_data = (void *) DB8500_REGULATOR_VARM, },
453
- { .name = "db8500_vmodem", .driver_data = (void *) DB8500_REGULATOR_VMODEM, },
454
- { .name = "db8500_vpll", .driver_data = (void *) DB8500_REGULATOR_VPLL, },
455
- { .name = "db8500_vsmps1", .driver_data = (void *) DB8500_REGULATOR_VSMPS1, },
456
- { .name = "db8500_vsmps2", .driver_data = (void *) DB8500_REGULATOR_VSMPS2, },
457
- { .name = "db8500_vsmps3", .driver_data = (void *) DB8500_REGULATOR_VSMPS3, },
458
- { .name = "db8500_vrf1", .driver_data = (void *) DB8500_REGULATOR_VRF1, },
459
- { .name = "db8500_sva_mmdsp", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAMMDSP, },
460
- { .name = "db8500_sva_mmdsp_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAMMDSPRET, },
461
- { .name = "db8500_sva_pipe", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAPIPE, },
462
- { .name = "db8500_sia_mmdsp", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAMMDSP, },
463
- { .name = "db8500_sia_mmdsp_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAMMDSPRET, },
464
- { .name = "db8500_sia_pipe", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAPIPE, },
465
- { .name = "db8500_sga", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SGA, },
466
- { .name = "db8500_b2r2_mcde", .driver_data = (void *) DB8500_REGULATOR_SWITCH_B2R2_MCDE, },
467
- { .name = "db8500_esram12", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM12, },
468
- { .name = "db8500_esram12_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM12RET, },
469
- { .name = "db8500_esram34", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM34, },
470
- { .name = "db8500_esram34_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM34RET, },
471
-};
472
-
473
-static int
474
-db8500_regulator_of_probe(struct platform_device *pdev,
475
- struct device_node *np)
476
-{
477
- int i, err;
478
-
479
- for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
480
- err = db8500_regulator_register(
481
- pdev, db8500_regulator_matches[i].init_data,
482
- i, db8500_regulator_matches[i].of_node);
483
- if (err)
484
- return err;
485
- }
486
-
487
- return 0;
488
-}
489
-
490437 static int db8500_regulator_probe(struct platform_device *pdev)
491438 {
492
- struct regulator_init_data *db8500_init_data =
493
- dev_get_platdata(&pdev->dev);
494
- struct device_node *np = pdev->dev.of_node;
495
- int i, err;
439
+ struct regulator_init_data *db8500_init_data;
440
+ struct dbx500_regulator_info *info;
441
+ struct regulator_config config = { };
442
+ struct regulator_dev *rdev;
443
+ int err, i;
496444
497
- /* register all regulators */
498
- if (np) {
499
- err = of_regulator_match(&pdev->dev, np,
500
- db8500_regulator_matches,
501
- ARRAY_SIZE(db8500_regulator_matches));
502
- if (err < 0) {
503
- dev_err(&pdev->dev,
504
- "Error parsing regulator init data: %d\n", err);
445
+ db8500_init_data = dev_get_platdata(&pdev->dev);
446
+
447
+ for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
448
+ /* assign per-regulator data */
449
+ info = &dbx500_regulator_info[i];
450
+
451
+ config.driver_data = info;
452
+ config.dev = &pdev->dev;
453
+ if (db8500_init_data)
454
+ config.init_data = &db8500_init_data[i];
455
+
456
+ rdev = devm_regulator_register(&pdev->dev, &info->desc,
457
+ &config);
458
+ if (IS_ERR(rdev)) {
459
+ err = PTR_ERR(rdev);
460
+ dev_err(&pdev->dev, "failed to register %s: err %i\n",
461
+ info->desc.name, err);
505462 return err;
506463 }
507
-
508
- err = db8500_regulator_of_probe(pdev, np);
509
- if (err)
510
- return err;
511
- } else {
512
- for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
513
- err = db8500_regulator_register(pdev,
514
- &db8500_init_data[i],
515
- i, NULL);
516
- if (err)
517
- return err;
518
- }
464
+ dev_dbg(&pdev->dev, "regulator-%s-probed\n", info->desc.name);
519465 }
520466
521
- err = ux500_regulator_debug_init(pdev,
522
- dbx500_regulator_info,
523
- ARRAY_SIZE(dbx500_regulator_info));
467
+ ux500_regulator_debug_init(pdev, dbx500_regulator_info,
468
+ ARRAY_SIZE(dbx500_regulator_info));
524469 return 0;
525470 }
526471