hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/regulator/tps6507x-regulator.c
....@@ -3,7 +3,7 @@
33 *
44 * Regulator driver for TPS65073 PMIC
55 *
6
- * Copyright (C) 2009 Texas Instrument Incorporated - http://www.ti.com/
6
+ * Copyright (C) 2009 Texas Instrument 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 as
....@@ -115,7 +115,6 @@
115115 struct tps6507x_pmic {
116116 struct regulator_desc desc[TPS6507X_NUM_REGULATOR];
117117 struct tps6507x_dev *mfd;
118
- struct regulator_dev *rdev[TPS6507X_NUM_REGULATOR];
119118 struct tps_info *info[TPS6507X_NUM_REGULATOR];
120119 struct mutex io_lock;
121120 };
....@@ -349,7 +348,7 @@
349348 return tps6507x_pmic_reg_write(tps, reg, data);
350349 }
351350
352
-static struct regulator_ops tps6507x_pmic_ops = {
351
+static const struct regulator_ops tps6507x_pmic_ops = {
353352 .is_enabled = tps6507x_pmic_is_enabled,
354353 .enable = tps6507x_pmic_enable,
355354 .disable = tps6507x_pmic_disable,
....@@ -359,66 +358,20 @@
359358 .map_voltage = regulator_map_voltage_ascend,
360359 };
361360
362
-static struct of_regulator_match tps6507x_matches[] = {
363
- { .name = "VDCDC1"},
364
- { .name = "VDCDC2"},
365
- { .name = "VDCDC3"},
366
- { .name = "LDO1"},
367
- { .name = "LDO2"},
368
-};
369
-
370
-static struct tps6507x_board *tps6507x_parse_dt_reg_data(
371
- struct platform_device *pdev,
372
- struct of_regulator_match **tps6507x_reg_matches)
361
+static int tps6507x_pmic_of_parse_cb(struct device_node *np,
362
+ const struct regulator_desc *desc,
363
+ struct regulator_config *config)
373364 {
374
- struct tps6507x_board *tps_board;
375
- struct device_node *np = pdev->dev.parent->of_node;
376
- struct device_node *regulators;
377
- struct of_regulator_match *matches;
378
- struct regulator_init_data *reg_data;
379
- int idx = 0, count, ret;
365
+ struct tps6507x_pmic *tps = config->driver_data;
366
+ struct tps_info *info = tps->info[desc->id];
367
+ u32 prop;
368
+ int ret;
380369
381
- tps_board = devm_kzalloc(&pdev->dev, sizeof(*tps_board),
382
- GFP_KERNEL);
383
- if (!tps_board)
384
- return NULL;
370
+ ret = of_property_read_u32(np, "ti,defdcdc_default", &prop);
371
+ if (!ret)
372
+ info->defdcdc_default = prop;
385373
386
- regulators = of_get_child_by_name(np, "regulators");
387
- if (!regulators) {
388
- dev_err(&pdev->dev, "regulator node not found\n");
389
- return NULL;
390
- }
391
-
392
- count = ARRAY_SIZE(tps6507x_matches);
393
- matches = tps6507x_matches;
394
-
395
- ret = of_regulator_match(&pdev->dev, regulators, matches, count);
396
- of_node_put(regulators);
397
- if (ret < 0) {
398
- dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
399
- ret);
400
- return NULL;
401
- }
402
-
403
- *tps6507x_reg_matches = matches;
404
-
405
- reg_data = devm_kzalloc(&pdev->dev, (sizeof(struct regulator_init_data)
406
- * TPS6507X_NUM_REGULATOR), GFP_KERNEL);
407
- if (!reg_data)
408
- return NULL;
409
-
410
- tps_board->tps6507x_pmic_init_data = reg_data;
411
-
412
- for (idx = 0; idx < count; idx++) {
413
- if (!matches[idx].init_data || !matches[idx].of_node)
414
- continue;
415
-
416
- memcpy(&reg_data[idx], matches[idx].init_data,
417
- sizeof(struct regulator_init_data));
418
-
419
- }
420
-
421
- return tps_board;
374
+ return 0;
422375 }
423376
424377 static int tps6507x_pmic_probe(struct platform_device *pdev)
....@@ -426,14 +379,11 @@
426379 struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
427380 struct tps_info *info = &tps6507x_pmic_regs[0];
428381 struct regulator_config config = { };
429
- struct regulator_init_data *init_data;
382
+ struct regulator_init_data *init_data = NULL;
430383 struct regulator_dev *rdev;
431384 struct tps6507x_pmic *tps;
432385 struct tps6507x_board *tps_board;
433
- struct of_regulator_match *tps6507x_reg_matches = NULL;
434386 int i;
435
- int error;
436
- unsigned int prop;
437387
438388 /**
439389 * tps_board points to pmic related constants
....@@ -441,20 +391,8 @@
441391 */
442392
443393 tps_board = dev_get_platdata(tps6507x_dev->dev);
444
- if (IS_ENABLED(CONFIG_OF) && !tps_board &&
445
- tps6507x_dev->dev->of_node)
446
- tps_board = tps6507x_parse_dt_reg_data(pdev,
447
- &tps6507x_reg_matches);
448
- if (!tps_board)
449
- return -EINVAL;
450
-
451
- /**
452
- * init_data points to array of regulator_init structures
453
- * coming from the board-evm file.
454
- */
455
- init_data = tps_board->tps6507x_pmic_init_data;
456
- if (!init_data)
457
- return -EINVAL;
394
+ if (tps_board)
395
+ init_data = tps_board->tps6507x_pmic_init_data;
458396
459397 tps = devm_kzalloc(&pdev->dev, sizeof(*tps), GFP_KERNEL);
460398 if (!tps)
....@@ -465,16 +403,19 @@
465403 /* common for all regulators */
466404 tps->mfd = tps6507x_dev;
467405
468
- for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) {
406
+ for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++) {
469407 /* Register the regulators */
470408 tps->info[i] = info;
471
- if (init_data->driver_data) {
409
+ if (init_data && init_data[i].driver_data) {
472410 struct tps6507x_reg_platform_data *data =
473
- init_data->driver_data;
474
- tps->info[i]->defdcdc_default = data->defdcdc_default;
411
+ init_data[i].driver_data;
412
+ info->defdcdc_default = data->defdcdc_default;
475413 }
476414
477415 tps->desc[i].name = info->name;
416
+ tps->desc[i].of_match = of_match_ptr(info->name);
417
+ tps->desc[i].regulators_node = of_match_ptr("regulators");
418
+ tps->desc[i].of_parse_cb = tps6507x_pmic_of_parse_cb;
478419 tps->desc[i].id = i;
479420 tps->desc[i].n_voltages = info->table_len;
480421 tps->desc[i].volt_table = info->table;
....@@ -486,17 +427,6 @@
486427 config.init_data = init_data;
487428 config.driver_data = tps;
488429
489
- if (tps6507x_reg_matches) {
490
- error = of_property_read_u32(
491
- tps6507x_reg_matches[i].of_node,
492
- "ti,defdcdc_default", &prop);
493
-
494
- if (!error)
495
- tps->info[i]->defdcdc_default = prop;
496
-
497
- config.of_node = tps6507x_reg_matches[i].of_node;
498
- }
499
-
500430 rdev = devm_regulator_register(&pdev->dev, &tps->desc[i],
501431 &config);
502432 if (IS_ERR(rdev)) {
....@@ -505,9 +435,6 @@
505435 pdev->name);
506436 return PTR_ERR(rdev);
507437 }
508
-
509
- /* Save regulator for cleanup */
510
- tps->rdev[i] = rdev;
511438 }
512439
513440 tps6507x_dev->pmic = tps;