Skip to content
Snippets Groups Projects
Commit 9d59e0d4 authored by Davide Cardillo's avatar Davide Cardillo
Browse files

Add dt_node interface for usege through device-tree

Originally, the driver works only via the old platform-driver interface.
Now it uses also the device tree interface. A possible node is:

	rs232-consumer {
		compatible          = "reg-userspace-consumer";
		regulator-name      = "rs232-consumer";
		regulator-supplies  = "reg_rs232_en";
		reg_rs232_en-supply = <&reg_rs232_en>;
		regulator-boot-on;
	};

Where:
- regulator-name: name of the particular istance, used also to create
  the file descriptor at user-space level;
- regulator0supplies : name of the regulator it uses as interface;
- <regulator-supplies>-supply = variable node name. It is the node of
  the regulator that the particular istance uses;
- regulator-boot-on : (default state: off) used to turn on the regulator
  at boot.
parent e45eeb03
No related branches found
No related tags found
1 merge request!90Add dt_node interface for usage through device-tree and fix SPI-NOR core
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/regulator/userspace-consumer.h> #include <linux/regulator/userspace-consumer.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/of.h>
struct userspace_consumer_data { struct userspace_consumer_data {
const char *name; const char *name;
...@@ -100,6 +101,43 @@ static const struct attribute_group attr_group = { ...@@ -100,6 +101,43 @@ static const struct attribute_group attr_group = {
.attrs = attributes, .attrs = attributes,
}; };
static struct regulator_userspace_consumer_data *get_pdata_from_dt_node(
struct platform_device *pdev)
{
struct regulator_userspace_consumer_data *pdata;
struct device_node *np = pdev->dev.of_node;
struct property *prop;
const char *supply;
int num_supplies;
int count = 0;
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return ERR_PTR(-ENOMEM);
pdata->name = of_get_property(np, "regulator-name", NULL);
pdata->init_on = of_property_read_bool(np, "regulator-boot-on");
num_supplies = of_property_count_strings(np, "regulator-supplies");
if (num_supplies < 0) {
dev_err(&pdev->dev,
"could not parse property regulator-supplies\n");
return ERR_PTR(-EINVAL);
}
pdata->num_supplies = num_supplies;
pdata->supplies = devm_kzalloc(&pdev->dev, num_supplies *
sizeof(*pdata->supplies), GFP_KERNEL);
if (!pdata->supplies)
return ERR_PTR(-ENOMEM);
of_property_for_each_string(np, "regulator-supplies", prop, supply)
pdata->supplies[count++].supply = supply;
return pdata;
}
static int regulator_userspace_consumer_probe(struct platform_device *pdev) static int regulator_userspace_consumer_probe(struct platform_device *pdev)
{ {
struct regulator_userspace_consumer_data *pdata; struct regulator_userspace_consumer_data *pdata;
...@@ -107,6 +145,11 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev) ...@@ -107,6 +145,11 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
int ret; int ret;
pdata = dev_get_platdata(&pdev->dev); pdata = dev_get_platdata(&pdev->dev);
if (!pdata && pdev->dev.of_node) {
pdata = get_pdata_from_dt_node(pdev);
if (IS_ERR(pdata))
return PTR_ERR(pdata);
}
if (!pdata) if (!pdata)
return -EINVAL; return -EINVAL;
...@@ -166,10 +209,18 @@ static int regulator_userspace_consumer_remove(struct platform_device *pdev) ...@@ -166,10 +209,18 @@ static int regulator_userspace_consumer_remove(struct platform_device *pdev)
return 0; return 0;
} }
static const struct of_device_id regulator_userspace_consumer_of_match[] = {
{ .compatible = "reg-userspace-consumer", },
{},
};
MODULE_DEVICE_TABLE(of, regulator_userspace_consumer_of_match);
static struct platform_driver regulator_userspace_consumer_driver = { static struct platform_driver regulator_userspace_consumer_driver = {
.probe = regulator_userspace_consumer_probe, .probe = regulator_userspace_consumer_probe,
.remove = regulator_userspace_consumer_remove, .remove = regulator_userspace_consumer_remove,
.driver = { .driver = {
.of_match_table = regulator_userspace_consumer_of_match,
.name = "reg-userspace-consumer", .name = "reg-userspace-consumer",
}, },
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment