mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-13 07:44:00 +08:00
regulator: tps6507x: Convert to regulator core's simplified DT parsing code
Use regulator core's simplified DT parsing code to simply the driver implementation. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
69c57b97db
commit
f979c08f76
@ -358,66 +358,20 @@ static const struct regulator_ops tps6507x_pmic_ops = {
|
||||
.map_voltage = regulator_map_voltage_ascend,
|
||||
};
|
||||
|
||||
static struct of_regulator_match tps6507x_matches[] = {
|
||||
{ .name = "VDCDC1"},
|
||||
{ .name = "VDCDC2"},
|
||||
{ .name = "VDCDC3"},
|
||||
{ .name = "LDO1"},
|
||||
{ .name = "LDO2"},
|
||||
};
|
||||
|
||||
static struct tps6507x_board *tps6507x_parse_dt_reg_data(
|
||||
struct platform_device *pdev,
|
||||
struct of_regulator_match **tps6507x_reg_matches)
|
||||
static int tps6507x_pmic_of_parse_cb(struct device_node *np,
|
||||
const struct regulator_desc *desc,
|
||||
struct regulator_config *config)
|
||||
{
|
||||
struct tps6507x_board *tps_board;
|
||||
struct device_node *np = pdev->dev.parent->of_node;
|
||||
struct device_node *regulators;
|
||||
struct of_regulator_match *matches;
|
||||
struct regulator_init_data *reg_data;
|
||||
int idx = 0, count, ret;
|
||||
struct tps6507x_pmic *tps = config->driver_data;
|
||||
struct tps_info *info = tps->info[desc->id];
|
||||
u32 prop;
|
||||
int ret;
|
||||
|
||||
tps_board = devm_kzalloc(&pdev->dev, sizeof(*tps_board),
|
||||
GFP_KERNEL);
|
||||
if (!tps_board)
|
||||
return NULL;
|
||||
ret = of_property_read_u32(np, "ti,defdcdc_default", &prop);
|
||||
if (!ret)
|
||||
info->defdcdc_default = prop;
|
||||
|
||||
regulators = of_get_child_by_name(np, "regulators");
|
||||
if (!regulators) {
|
||||
dev_err(&pdev->dev, "regulator node not found\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
count = ARRAY_SIZE(tps6507x_matches);
|
||||
matches = tps6507x_matches;
|
||||
|
||||
ret = of_regulator_match(&pdev->dev, regulators, matches, count);
|
||||
of_node_put(regulators);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
|
||||
ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*tps6507x_reg_matches = matches;
|
||||
|
||||
reg_data = devm_kzalloc(&pdev->dev, (sizeof(struct regulator_init_data)
|
||||
* TPS6507X_NUM_REGULATOR), GFP_KERNEL);
|
||||
if (!reg_data)
|
||||
return NULL;
|
||||
|
||||
tps_board->tps6507x_pmic_init_data = reg_data;
|
||||
|
||||
for (idx = 0; idx < count; idx++) {
|
||||
if (!matches[idx].init_data || !matches[idx].of_node)
|
||||
continue;
|
||||
|
||||
memcpy(®_data[idx], matches[idx].init_data,
|
||||
sizeof(struct regulator_init_data));
|
||||
|
||||
}
|
||||
|
||||
return tps_board;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tps6507x_pmic_probe(struct platform_device *pdev)
|
||||
@ -425,14 +379,11 @@ static int tps6507x_pmic_probe(struct platform_device *pdev)
|
||||
struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
|
||||
struct tps_info *info = &tps6507x_pmic_regs[0];
|
||||
struct regulator_config config = { };
|
||||
struct regulator_init_data *init_data;
|
||||
struct regulator_init_data *init_data = NULL;
|
||||
struct regulator_dev *rdev;
|
||||
struct tps6507x_pmic *tps;
|
||||
struct tps6507x_board *tps_board;
|
||||
struct of_regulator_match *tps6507x_reg_matches = NULL;
|
||||
int i;
|
||||
int error;
|
||||
unsigned int prop;
|
||||
|
||||
/**
|
||||
* tps_board points to pmic related constants
|
||||
@ -440,20 +391,8 @@ static int tps6507x_pmic_probe(struct platform_device *pdev)
|
||||
*/
|
||||
|
||||
tps_board = dev_get_platdata(tps6507x_dev->dev);
|
||||
if (IS_ENABLED(CONFIG_OF) && !tps_board &&
|
||||
tps6507x_dev->dev->of_node)
|
||||
tps_board = tps6507x_parse_dt_reg_data(pdev,
|
||||
&tps6507x_reg_matches);
|
||||
if (!tps_board)
|
||||
return -EINVAL;
|
||||
|
||||
/**
|
||||
* init_data points to array of regulator_init structures
|
||||
* coming from the board-evm file.
|
||||
*/
|
||||
init_data = tps_board->tps6507x_pmic_init_data;
|
||||
if (!init_data)
|
||||
return -EINVAL;
|
||||
if (tps_board)
|
||||
init_data = tps_board->tps6507x_pmic_init_data;
|
||||
|
||||
tps = devm_kzalloc(&pdev->dev, sizeof(*tps), GFP_KERNEL);
|
||||
if (!tps)
|
||||
@ -467,13 +406,16 @@ static int tps6507x_pmic_probe(struct platform_device *pdev)
|
||||
for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) {
|
||||
/* Register the regulators */
|
||||
tps->info[i] = info;
|
||||
if (init_data->driver_data) {
|
||||
if (init_data && init_data->driver_data) {
|
||||
struct tps6507x_reg_platform_data *data =
|
||||
init_data->driver_data;
|
||||
tps->info[i]->defdcdc_default = data->defdcdc_default;
|
||||
info->defdcdc_default = data->defdcdc_default;
|
||||
}
|
||||
|
||||
tps->desc[i].name = info->name;
|
||||
tps->desc[i].of_match = of_match_ptr(info->name);
|
||||
tps->desc[i].regulators_node = of_match_ptr("regulators");
|
||||
tps->desc[i].of_parse_cb = tps6507x_pmic_of_parse_cb;
|
||||
tps->desc[i].id = i;
|
||||
tps->desc[i].n_voltages = info->table_len;
|
||||
tps->desc[i].volt_table = info->table;
|
||||
@ -485,17 +427,6 @@ static int tps6507x_pmic_probe(struct platform_device *pdev)
|
||||
config.init_data = init_data;
|
||||
config.driver_data = tps;
|
||||
|
||||
if (tps6507x_reg_matches) {
|
||||
error = of_property_read_u32(
|
||||
tps6507x_reg_matches[i].of_node,
|
||||
"ti,defdcdc_default", &prop);
|
||||
|
||||
if (!error)
|
||||
tps->info[i]->defdcdc_default = prop;
|
||||
|
||||
config.of_node = tps6507x_reg_matches[i].of_node;
|
||||
}
|
||||
|
||||
rdev = devm_regulator_register(&pdev->dev, &tps->desc[i],
|
||||
&config);
|
||||
if (IS_ERR(rdev)) {
|
||||
|
Loading…
Reference in New Issue
Block a user