Commit f907a0a9 authored by Laxman Dewangan's avatar Laxman Dewangan Committed by Mark Brown

regulator: pwm: Add support to have multiple instance of pwm regulator

Some of platforms like Nvidia's Tegra210 Jetson-TX1 platform has
multiple PMW based regulators. Add support to have multiple instances
of the driver by not changing any global data of pwm regulator and
if required, making instance specific copy and then making changes.
Signed-off-by: default avatarLaxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 1aaab348
...@@ -27,6 +27,13 @@ struct pwm_regulator_data { ...@@ -27,6 +27,13 @@ struct pwm_regulator_data {
/* Voltage table */ /* Voltage table */
struct pwm_voltages *duty_cycle_table; struct pwm_voltages *duty_cycle_table;
/* regulator descriptor */
struct regulator_desc desc;
/* Regulator ops */
struct regulator_ops ops;
int state; int state;
/* Continuous voltage */ /* Continuous voltage */
...@@ -212,8 +219,10 @@ static int pwm_regulator_init_table(struct platform_device *pdev, ...@@ -212,8 +219,10 @@ static int pwm_regulator_init_table(struct platform_device *pdev,
} }
drvdata->duty_cycle_table = duty_cycle_table; drvdata->duty_cycle_table = duty_cycle_table;
pwm_regulator_desc.ops = &pwm_regulator_voltage_table_ops; memcpy(&drvdata->ops, &pwm_regulator_voltage_table_ops,
pwm_regulator_desc.n_voltages = length / sizeof(*duty_cycle_table); sizeof(drvdata->ops));
drvdata->desc.ops = &drvdata->ops;
drvdata->desc.n_voltages = length / sizeof(*duty_cycle_table);
return 0; return 0;
} }
...@@ -221,8 +230,10 @@ static int pwm_regulator_init_table(struct platform_device *pdev, ...@@ -221,8 +230,10 @@ static int pwm_regulator_init_table(struct platform_device *pdev,
static int pwm_regulator_init_continuous(struct platform_device *pdev, static int pwm_regulator_init_continuous(struct platform_device *pdev,
struct pwm_regulator_data *drvdata) struct pwm_regulator_data *drvdata)
{ {
pwm_regulator_desc.ops = &pwm_regulator_voltage_continuous_ops; memcpy(&drvdata->ops, &pwm_regulator_voltage_continuous_ops,
pwm_regulator_desc.continuous_voltage_range = true; sizeof(drvdata->ops));
drvdata->desc.ops = &drvdata->ops;
drvdata->desc.continuous_voltage_range = true;
return 0; return 0;
} }
...@@ -245,6 +256,8 @@ static int pwm_regulator_probe(struct platform_device *pdev) ...@@ -245,6 +256,8 @@ static int pwm_regulator_probe(struct platform_device *pdev)
if (!drvdata) if (!drvdata)
return -ENOMEM; return -ENOMEM;
memcpy(&drvdata->desc, &pwm_regulator_desc, sizeof(drvdata->desc));
if (of_find_property(np, "voltage-table", NULL)) if (of_find_property(np, "voltage-table", NULL))
ret = pwm_regulator_init_table(pdev, drvdata); ret = pwm_regulator_init_table(pdev, drvdata);
else else
...@@ -253,7 +266,7 @@ static int pwm_regulator_probe(struct platform_device *pdev) ...@@ -253,7 +266,7 @@ static int pwm_regulator_probe(struct platform_device *pdev)
return ret; return ret;
init_data = of_get_regulator_init_data(&pdev->dev, np, init_data = of_get_regulator_init_data(&pdev->dev, np,
&pwm_regulator_desc); &drvdata->desc);
if (!init_data) if (!init_data)
return -ENOMEM; return -ENOMEM;
...@@ -269,10 +282,10 @@ static int pwm_regulator_probe(struct platform_device *pdev) ...@@ -269,10 +282,10 @@ static int pwm_regulator_probe(struct platform_device *pdev)
} }
regulator = devm_regulator_register(&pdev->dev, regulator = devm_regulator_register(&pdev->dev,
&pwm_regulator_desc, &config); &drvdata->desc, &config);
if (IS_ERR(regulator)) { if (IS_ERR(regulator)) {
dev_err(&pdev->dev, "Failed to register regulator %s\n", dev_err(&pdev->dev, "Failed to register regulator %s\n",
pwm_regulator_desc.name); drvdata->desc.name);
return PTR_ERR(regulator); return PTR_ERR(regulator);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment