Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Laxman Dewangan and committed by
Mark Brown
f907a0a9 1aaab348

+20 -7
+20 -7
drivers/regulator/pwm-regulator.c
··· 27 27 28 28 /* Voltage table */ 29 29 struct pwm_voltages *duty_cycle_table; 30 + 31 + /* regulator descriptor */ 32 + struct regulator_desc desc; 33 + 34 + /* Regulator ops */ 35 + struct regulator_ops ops; 36 + 30 37 int state; 31 38 32 39 /* Continuous voltage */ ··· 219 212 } 220 213 221 214 drvdata->duty_cycle_table = duty_cycle_table; 222 - pwm_regulator_desc.ops = &pwm_regulator_voltage_table_ops; 223 - pwm_regulator_desc.n_voltages = length / sizeof(*duty_cycle_table); 215 + memcpy(&drvdata->ops, &pwm_regulator_voltage_table_ops, 216 + sizeof(drvdata->ops)); 217 + drvdata->desc.ops = &drvdata->ops; 218 + drvdata->desc.n_voltages = length / sizeof(*duty_cycle_table); 224 219 225 220 return 0; 226 221 } ··· 230 221 static int pwm_regulator_init_continuous(struct platform_device *pdev, 231 222 struct pwm_regulator_data *drvdata) 232 223 { 233 - pwm_regulator_desc.ops = &pwm_regulator_voltage_continuous_ops; 234 - pwm_regulator_desc.continuous_voltage_range = true; 224 + memcpy(&drvdata->ops, &pwm_regulator_voltage_continuous_ops, 225 + sizeof(drvdata->ops)); 226 + drvdata->desc.ops = &drvdata->ops; 227 + drvdata->desc.continuous_voltage_range = true; 235 228 236 229 return 0; 237 230 } ··· 256 245 if (!drvdata) 257 246 return -ENOMEM; 258 247 248 + memcpy(&drvdata->desc, &pwm_regulator_desc, sizeof(drvdata->desc)); 249 + 259 250 if (of_find_property(np, "voltage-table", NULL)) 260 251 ret = pwm_regulator_init_table(pdev, drvdata); 261 252 else ··· 266 253 return ret; 267 254 268 255 init_data = of_get_regulator_init_data(&pdev->dev, np, 269 - &pwm_regulator_desc); 256 + &drvdata->desc); 270 257 if (!init_data) 271 258 return -ENOMEM; 272 259 ··· 282 269 } 283 270 284 271 regulator = devm_regulator_register(&pdev->dev, 285 - &pwm_regulator_desc, &config); 272 + &drvdata->desc, &config); 286 273 if (IS_ERR(regulator)) { 287 274 dev_err(&pdev->dev, "Failed to register regulator %s\n", 288 - pwm_regulator_desc.name); 275 + drvdata->desc.name); 289 276 return PTR_ERR(regulator); 290 277 } 291 278