aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/fixed.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2011-11-23 13:50:59 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-11-23 13:50:59 -0500
commit924ee2c9621b65df9dffa8218af5ee9a9b892bba (patch)
tree316d72848181d4198dad3407ba5441083708ab7e /drivers/regulator/fixed.c
parent68aaa37d0e8232d62a7e9411699e0dc005750186 (diff)
parent69511a452e6dc6b74fe4f3671a51b1b44b9c57e3 (diff)
Merge remote-tracking branch 'regulator/topic/dt' into regulator-next
Diffstat (limited to 'drivers/regulator/fixed.c')
-rw-r--r--drivers/regulator/fixed.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index ccbead06c8f3..716ea375f50f 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -27,6 +27,10 @@
27#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/of.h>
31#include <linux/of_gpio.h>
32#include <linux/regulator/of_regulator.h>
33#include <linux/regulator/machine.h>
30 34
31struct fixed_voltage_data { 35struct fixed_voltage_data {
32 struct regulator_desc desc; 36 struct regulator_desc desc;
@@ -38,6 +42,53 @@ struct fixed_voltage_data {
38 bool is_enabled; 42 bool is_enabled;
39}; 43};
40 44
45
46/**
47 * of_get_fixed_voltage_config - extract fixed_voltage_config structure info
48 * @dev: device requesting for fixed_voltage_config
49 *
50 * Populates fixed_voltage_config structure by extracting data from device
51 * tree node, returns a pointer to the populated structure of NULL if memory
52 * alloc fails.
53 */
54struct fixed_voltage_config *of_get_fixed_voltage_config(struct device *dev)
55{
56 struct fixed_voltage_config *config;
57 struct device_node *np = dev->of_node;
58 const __be32 *delay;
59 struct regulator_init_data *init_data;
60
61 config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config),
62 GFP_KERNEL);
63 if (!config)
64 return NULL;
65
66 config->init_data = of_get_regulator_init_data(dev);
67 init_data = config->init_data;
68
69 config->supply_name = init_data->constraints.name;
70 if (init_data->constraints.min_uV == init_data->constraints.max_uV) {
71 config->microvolts = init_data->constraints.min_uV;
72 } else {
73 dev_err(dev,
74 "Fixed regulator specified with variable voltages\n");
75 return NULL;
76 }
77
78 if (init_data->constraints.boot_on)
79 config->enabled_at_boot = true;
80
81 config->gpio = of_get_named_gpio(np, "gpio", 0);
82 delay = of_get_property(np, "startup-delay-us", NULL);
83 if (delay)
84 config->startup_delay = be32_to_cpu(*delay);
85
86 if (of_find_property(np, "enable-active-high", NULL))
87 config->enable_high = true;
88
89 return config;
90}
91
41static int fixed_voltage_is_enabled(struct regulator_dev *dev) 92static int fixed_voltage_is_enabled(struct regulator_dev *dev)
42{ 93{
43 struct fixed_voltage_data *data = rdev_get_drvdata(dev); 94 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
@@ -112,6 +163,9 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
112 struct fixed_voltage_data *drvdata; 163 struct fixed_voltage_data *drvdata;
113 int ret; 164 int ret;
114 165
166 if (pdev->dev.of_node)
167 config = of_get_fixed_voltage_config(&pdev->dev);
168
115 drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); 169 drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
116 if (drvdata == NULL) { 170 if (drvdata == NULL) {
117 dev_err(&pdev->dev, "Failed to allocate device data\n"); 171 dev_err(&pdev->dev, "Failed to allocate device data\n");
@@ -183,7 +237,7 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
183 } 237 }
184 238
185 drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, 239 drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev,
186 config->init_data, drvdata); 240 config->init_data, drvdata, NULL);
187 if (IS_ERR(drvdata->dev)) { 241 if (IS_ERR(drvdata->dev)) {
188 ret = PTR_ERR(drvdata->dev); 242 ret = PTR_ERR(drvdata->dev);
189 dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); 243 dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
@@ -220,12 +274,23 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev)
220 return 0; 274 return 0;
221} 275}
222 276
277#if defined(CONFIG_OF)
278static const struct of_device_id fixed_of_match[] __devinitconst = {
279 { .compatible = "regulator-fixed", },
280 {},
281};
282MODULE_DEVICE_TABLE(of, fixed_of_match);
283#else
284#define fixed_of_match NULL
285#endif
286
223static struct platform_driver regulator_fixed_voltage_driver = { 287static struct platform_driver regulator_fixed_voltage_driver = {
224 .probe = reg_fixed_voltage_probe, 288 .probe = reg_fixed_voltage_probe,
225 .remove = __devexit_p(reg_fixed_voltage_remove), 289 .remove = __devexit_p(reg_fixed_voltage_remove),
226 .driver = { 290 .driver = {
227 .name = "reg-fixed-voltage", 291 .name = "reg-fixed-voltage",
228 .owner = THIS_MODULE, 292 .owner = THIS_MODULE,
293 .of_match_table = fixed_of_match,
229 }, 294 },
230}; 295};
231 296