diff options
Diffstat (limited to 'drivers/regulator/fixed.c')
-rw-r--r-- | drivers/regulator/fixed.c | 83 |
1 files changed, 80 insertions, 3 deletions
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 21ecf212a522..72abbf5507a6 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,57 @@ 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 | static struct fixed_voltage_config * | ||
55 | of_get_fixed_voltage_config(struct device *dev) | ||
56 | { | ||
57 | struct fixed_voltage_config *config; | ||
58 | struct device_node *np = dev->of_node; | ||
59 | const __be32 *delay; | ||
60 | struct regulator_init_data *init_data; | ||
61 | |||
62 | config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config), | ||
63 | GFP_KERNEL); | ||
64 | if (!config) | ||
65 | return NULL; | ||
66 | |||
67 | config->init_data = of_get_regulator_init_data(dev); | ||
68 | if (!config->init_data) | ||
69 | return NULL; | ||
70 | |||
71 | init_data = config->init_data; | ||
72 | |||
73 | config->supply_name = init_data->constraints.name; | ||
74 | if (init_data->constraints.min_uV == init_data->constraints.max_uV) { | ||
75 | config->microvolts = init_data->constraints.min_uV; | ||
76 | } else { | ||
77 | dev_err(dev, | ||
78 | "Fixed regulator specified with variable voltages\n"); | ||
79 | return NULL; | ||
80 | } | ||
81 | |||
82 | if (init_data->constraints.boot_on) | ||
83 | config->enabled_at_boot = true; | ||
84 | |||
85 | config->gpio = of_get_named_gpio(np, "gpio", 0); | ||
86 | delay = of_get_property(np, "startup-delay-us", NULL); | ||
87 | if (delay) | ||
88 | config->startup_delay = be32_to_cpu(*delay); | ||
89 | |||
90 | if (of_find_property(np, "enable-active-high", NULL)) | ||
91 | config->enable_high = true; | ||
92 | |||
93 | return config; | ||
94 | } | ||
95 | |||
41 | static int fixed_voltage_is_enabled(struct regulator_dev *dev) | 96 | static int fixed_voltage_is_enabled(struct regulator_dev *dev) |
42 | { | 97 | { |
43 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | 98 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); |
@@ -80,7 +135,10 @@ static int fixed_voltage_get_voltage(struct regulator_dev *dev) | |||
80 | { | 135 | { |
81 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | 136 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); |
82 | 137 | ||
83 | return data->microvolts; | 138 | if (data->microvolts) |
139 | return data->microvolts; | ||
140 | else | ||
141 | return -EINVAL; | ||
84 | } | 142 | } |
85 | 143 | ||
86 | static int fixed_voltage_list_voltage(struct regulator_dev *dev, | 144 | static int fixed_voltage_list_voltage(struct regulator_dev *dev, |
@@ -105,10 +163,18 @@ static struct regulator_ops fixed_voltage_ops = { | |||
105 | 163 | ||
106 | static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | 164 | static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) |
107 | { | 165 | { |
108 | struct fixed_voltage_config *config = pdev->dev.platform_data; | 166 | struct fixed_voltage_config *config; |
109 | struct fixed_voltage_data *drvdata; | 167 | struct fixed_voltage_data *drvdata; |
110 | int ret; | 168 | int ret; |
111 | 169 | ||
170 | if (pdev->dev.of_node) | ||
171 | config = of_get_fixed_voltage_config(&pdev->dev); | ||
172 | else | ||
173 | config = pdev->dev.platform_data; | ||
174 | |||
175 | if (!config) | ||
176 | return -ENOMEM; | ||
177 | |||
112 | drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); | 178 | drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); |
113 | if (drvdata == NULL) { | 179 | if (drvdata == NULL) { |
114 | dev_err(&pdev->dev, "Failed to allocate device data\n"); | 180 | dev_err(&pdev->dev, "Failed to allocate device data\n"); |
@@ -180,7 +246,7 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | |||
180 | } | 246 | } |
181 | 247 | ||
182 | drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, | 248 | drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, |
183 | config->init_data, drvdata); | 249 | config->init_data, drvdata, NULL); |
184 | if (IS_ERR(drvdata->dev)) { | 250 | if (IS_ERR(drvdata->dev)) { |
185 | ret = PTR_ERR(drvdata->dev); | 251 | ret = PTR_ERR(drvdata->dev); |
186 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); | 252 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); |
@@ -217,12 +283,23 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev) | |||
217 | return 0; | 283 | return 0; |
218 | } | 284 | } |
219 | 285 | ||
286 | #if defined(CONFIG_OF) | ||
287 | static const struct of_device_id fixed_of_match[] __devinitconst = { | ||
288 | { .compatible = "regulator-fixed", }, | ||
289 | {}, | ||
290 | }; | ||
291 | MODULE_DEVICE_TABLE(of, fixed_of_match); | ||
292 | #else | ||
293 | #define fixed_of_match NULL | ||
294 | #endif | ||
295 | |||
220 | static struct platform_driver regulator_fixed_voltage_driver = { | 296 | static struct platform_driver regulator_fixed_voltage_driver = { |
221 | .probe = reg_fixed_voltage_probe, | 297 | .probe = reg_fixed_voltage_probe, |
222 | .remove = __devexit_p(reg_fixed_voltage_remove), | 298 | .remove = __devexit_p(reg_fixed_voltage_remove), |
223 | .driver = { | 299 | .driver = { |
224 | .name = "reg-fixed-voltage", | 300 | .name = "reg-fixed-voltage", |
225 | .owner = THIS_MODULE, | 301 | .owner = THIS_MODULE, |
302 | .of_match_table = fixed_of_match, | ||
226 | }, | 303 | }, |
227 | }; | 304 | }; |
228 | 305 | ||