diff options
author | Vincent Whitchurch <vincent.whitchurch@axis.com> | 2022-03-01 12:18:31 +0100 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2022-03-02 13:45:31 +0000 |
commit | 80c056656d46ffbece6125dee3f25adbc36d1486 (patch) | |
tree | 6fa2fe92d188920a130c3f87effb4bf0269ef3b2 /drivers/regulator | |
parent | d2fb5487ecb2a28b61ff261ae18488afc98d24a6 (diff) | |
download | linux-80c056656d46ffbece6125dee3f25adbc36d1486.tar.bz2 |
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>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/virtual.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c index 9e0abbee1df5..5d32628a5011 100644 --- a/drivers/regulator/virtual.c +++ b/drivers/regulator/virtual.c @@ -13,6 +13,7 @@ #include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/module.h> +#include <linux/of.h> struct virtual_consumer_data { struct mutex lock; @@ -281,6 +282,14 @@ static const struct attribute_group regulator_virtual_attr_group = { .attrs = regulator_virtual_attributes, }; +#ifdef CONFIG_OF +static const struct of_device_id regulator_virtual_consumer_of_match[] = { + { .compatible = "regulator-virtual-consumer" }, + {}, +}; +MODULE_DEVICE_TABLE(of, regulator_virtual_consumer_of_match); +#endif + static int regulator_virtual_probe(struct platform_device *pdev) { char *reg_id = dev_get_platdata(&pdev->dev); @@ -305,6 +314,14 @@ static int regulator_virtual_probe(struct platform_device *pdev) if (drvdata == NULL) return -ENOMEM; + /* + * This virtual consumer does not have any hardware-defined supply + * name, so just allow the regulator to be specified in a property + * named "default-supply" when we're being probed from devicetree. + */ + if (!reg_id && pdev->dev.of_node) + reg_id = "default"; + mutex_init(&drvdata->lock); drvdata->regulator = devm_regulator_get(&pdev->dev, reg_id); @@ -345,6 +362,7 @@ static struct platform_driver regulator_virtual_consumer_driver = { .remove = regulator_virtual_remove, .driver = { .name = "reg-virt-consumer", + .of_match_table = of_match_ptr(regulator_virtual_consumer_of_match), }, }; |