Skip to content

Commit 80c0566

Browse files
vwaxbroonie
authored andcommitted
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>
1 parent d2fb548 commit 80c0566

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

drivers/regulator/virtual.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/regulator/consumer.h>
1414
#include <linux/slab.h>
1515
#include <linux/module.h>
16+
#include <linux/of.h>
1617

1718
struct virtual_consumer_data {
1819
struct mutex lock;
@@ -281,6 +282,14 @@ static const struct attribute_group regulator_virtual_attr_group = {
281282
.attrs = regulator_virtual_attributes,
282283
};
283284

285+
#ifdef CONFIG_OF
286+
static const struct of_device_id regulator_virtual_consumer_of_match[] = {
287+
{ .compatible = "regulator-virtual-consumer" },
288+
{},
289+
};
290+
MODULE_DEVICE_TABLE(of, regulator_virtual_consumer_of_match);
291+
#endif
292+
284293
static int regulator_virtual_probe(struct platform_device *pdev)
285294
{
286295
char *reg_id = dev_get_platdata(&pdev->dev);
@@ -305,6 +314,14 @@ static int regulator_virtual_probe(struct platform_device *pdev)
305314
if (drvdata == NULL)
306315
return -ENOMEM;
307316

317+
/*
318+
* This virtual consumer does not have any hardware-defined supply
319+
* name, so just allow the regulator to be specified in a property
320+
* named "default-supply" when we're being probed from devicetree.
321+
*/
322+
if (!reg_id && pdev->dev.of_node)
323+
reg_id = "default";
324+
308325
mutex_init(&drvdata->lock);
309326

310327
drvdata->regulator = devm_regulator_get(&pdev->dev, reg_id);
@@ -345,6 +362,7 @@ static struct platform_driver regulator_virtual_consumer_driver = {
345362
.remove = regulator_virtual_remove,
346363
.driver = {
347364
.name = "reg-virt-consumer",
365+
.of_match_table = of_match_ptr(regulator_virtual_consumer_of_match),
348366
},
349367
};
350368

0 commit comments

Comments
 (0)