diff options
author | Rajendra Nayak <rnayak@ti.com> | 2011-11-18 06:17:18 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-11-23 13:47:00 -0500 |
commit | cef49102c1d6b1e7adcb3f8b706757e0731e955c (patch) | |
tree | b0768529f9f01b44c10bcf1f6c431d708870a72a /drivers/regulator | |
parent | 8f446e6fa1d506be2cb80f91c214f1705327c7f9 (diff) |
regulator: adapt fixed regulator driver to dt
The fixed regulator driver uses of_get_fixed_voltage_config()
to extract fixed_voltage_config structure contents from device tree.
Also add documenation for additional bindings for fixed
regulators that can be passed through dt.
Signed-off-by: Rajendra Nayak <rnayak@ti.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/fixed.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 21ecf212a522..0650856b93cb 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 | ||
31 | struct fixed_voltage_data { | 35 | struct 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 | */ | ||
54 | struct 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 | |||
41 | static int fixed_voltage_is_enabled(struct regulator_dev *dev) | 92 | static 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); |
@@ -109,6 +160,9 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | |||
109 | struct fixed_voltage_data *drvdata; | 160 | struct fixed_voltage_data *drvdata; |
110 | int ret; | 161 | int ret; |
111 | 162 | ||
163 | if (pdev->dev.of_node) | ||
164 | config = of_get_fixed_voltage_config(&pdev->dev); | ||
165 | |||
112 | drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); | 166 | drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); |
113 | if (drvdata == NULL) { | 167 | if (drvdata == NULL) { |
114 | dev_err(&pdev->dev, "Failed to allocate device data\n"); | 168 | dev_err(&pdev->dev, "Failed to allocate device data\n"); |
@@ -217,12 +271,23 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev) | |||
217 | return 0; | 271 | return 0; |
218 | } | 272 | } |
219 | 273 | ||
274 | #if defined(CONFIG_OF) | ||
275 | static const struct of_device_id fixed_of_match[] __devinitconst = { | ||
276 | { .compatible = "regulator-fixed", }, | ||
277 | {}, | ||
278 | }; | ||
279 | MODULE_DEVICE_TABLE(of, fixed_of_match); | ||
280 | #else | ||
281 | #define fixed_of_match NULL | ||
282 | #endif | ||
283 | |||
220 | static struct platform_driver regulator_fixed_voltage_driver = { | 284 | static struct platform_driver regulator_fixed_voltage_driver = { |
221 | .probe = reg_fixed_voltage_probe, | 285 | .probe = reg_fixed_voltage_probe, |
222 | .remove = __devexit_p(reg_fixed_voltage_remove), | 286 | .remove = __devexit_p(reg_fixed_voltage_remove), |
223 | .driver = { | 287 | .driver = { |
224 | .name = "reg-fixed-voltage", | 288 | .name = "reg-fixed-voltage", |
225 | .owner = THIS_MODULE, | 289 | .owner = THIS_MODULE, |
290 | .of_match_table = fixed_of_match, | ||
226 | }, | 291 | }, |
227 | }; | 292 | }; |
228 | 293 | ||