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

regulator: virtual: add devicetree support

The reg-virt-consumer is very useful for development and testing of
regulator drivers since it allows voltages and modes to be set from
userspace. However, it currently requires platform data so it cannot be
used without patching the kernel. Add support for probing it from the
devicetree to remedy this.

Since this driver is only meant for testing and is a purely software
construct, no binding documentation is added.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Link: https://lore.kernel.org/r/20220301111831.3742383-4-vincent.whitchurch@axis.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Vincent Whitchurch and committed by
Mark Brown
80c05665 d2fb5487

+18
+18
drivers/regulator/virtual.c
··· 13 13 #include <linux/regulator/consumer.h> 14 14 #include <linux/slab.h> 15 15 #include <linux/module.h> 16 + #include <linux/of.h> 16 17 17 18 struct virtual_consumer_data { 18 19 struct mutex lock; ··· 282 281 .attrs = regulator_virtual_attributes, 283 282 }; 284 283 284 + #ifdef CONFIG_OF 285 + static const struct of_device_id regulator_virtual_consumer_of_match[] = { 286 + { .compatible = "regulator-virtual-consumer" }, 287 + {}, 288 + }; 289 + MODULE_DEVICE_TABLE(of, regulator_virtual_consumer_of_match); 290 + #endif 291 + 285 292 static int regulator_virtual_probe(struct platform_device *pdev) 286 293 { 287 294 char *reg_id = dev_get_platdata(&pdev->dev); ··· 313 304 GFP_KERNEL); 314 305 if (drvdata == NULL) 315 306 return -ENOMEM; 307 + 308 + /* 309 + * This virtual consumer does not have any hardware-defined supply 310 + * name, so just allow the regulator to be specified in a property 311 + * named "default-supply" when we're being probed from devicetree. 312 + */ 313 + if (!reg_id && pdev->dev.of_node) 314 + reg_id = "default"; 316 315 317 316 mutex_init(&drvdata->lock); 318 317 ··· 362 345 .remove = regulator_virtual_remove, 363 346 .driver = { 364 347 .name = "reg-virt-consumer", 348 + .of_match_table = of_match_ptr(regulator_virtual_consumer_of_match), 365 349 }, 366 350 }; 367 351