diff options
author | Qing Xu <qingx@marvell.com> | 2012-11-07 05:09:53 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-11-07 09:12:12 -0500 |
commit | 45b6f8e8fc014fe404d155a657a04b25b861001d (patch) | |
tree | bfa24c27556a7347a80373994bcb2ec7897785c9 /drivers/regulator | |
parent | 3d70f8c617a436c7146ecb81df2265b4626dfe89 (diff) |
regulator: max8925: support dt for regulator
Signed-off-by: Qing Xu <qingx@marvell.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/max8925-regulator.c | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c index 9bb0be37495f..2b549791c975 100644 --- a/drivers/regulator/max8925-regulator.c +++ b/drivers/regulator/max8925-regulator.c | |||
@@ -17,6 +17,8 @@ | |||
17 | #include <linux/regulator/driver.h> | 17 | #include <linux/regulator/driver.h> |
18 | #include <linux/regulator/machine.h> | 18 | #include <linux/regulator/machine.h> |
19 | #include <linux/mfd/max8925.h> | 19 | #include <linux/mfd/max8925.h> |
20 | #include <linux/of.h> | ||
21 | #include <linux/regulator/of_regulator.h> | ||
20 | 22 | ||
21 | #define SD1_DVM_VMIN 850000 | 23 | #define SD1_DVM_VMIN 850000 |
22 | #define SD1_DVM_VMAX 1000000 | 24 | #define SD1_DVM_VMAX 1000000 |
@@ -187,6 +189,34 @@ static struct regulator_ops max8925_regulator_ldo_ops = { | |||
187 | .enable_reg = MAX8925_LDOCTL##_id, \ | 189 | .enable_reg = MAX8925_LDOCTL##_id, \ |
188 | } | 190 | } |
189 | 191 | ||
192 | #ifdef CONFIG_OF | ||
193 | static struct of_regulator_match max8925_regulator_matches[] = { | ||
194 | { .name = "SDV1",}, | ||
195 | { .name = "SDV2",}, | ||
196 | { .name = "SDV3",}, | ||
197 | { .name = "LDO1",}, | ||
198 | { .name = "LDO2",}, | ||
199 | { .name = "LDO3",}, | ||
200 | { .name = "LDO4",}, | ||
201 | { .name = "LDO5",}, | ||
202 | { .name = "LDO6",}, | ||
203 | { .name = "LDO7",}, | ||
204 | { .name = "LDO8",}, | ||
205 | { .name = "LDO9",}, | ||
206 | { .name = "LDO10",}, | ||
207 | { .name = "LDO11",}, | ||
208 | { .name = "LDO12",}, | ||
209 | { .name = "LDO13",}, | ||
210 | { .name = "LDO14",}, | ||
211 | { .name = "LDO15",}, | ||
212 | { .name = "LDO16",}, | ||
213 | { .name = "LDO17",}, | ||
214 | { .name = "LDO18",}, | ||
215 | { .name = "LDO19",}, | ||
216 | { .name = "LDO20",}, | ||
217 | }; | ||
218 | #endif | ||
219 | |||
190 | static struct max8925_regulator_info max8925_regulator_info[] = { | 220 | static struct max8925_regulator_info max8925_regulator_info[] = { |
191 | MAX8925_SDV(1, 637.5, 1425, 12.5), | 221 | MAX8925_SDV(1, 637.5, 1425, 12.5), |
192 | MAX8925_SDV(2, 650, 2225, 25), | 222 | MAX8925_SDV(2, 650, 2225, 25), |
@@ -214,6 +244,36 @@ static struct max8925_regulator_info max8925_regulator_info[] = { | |||
214 | MAX8925_LDO(20, 750, 3900, 50), | 244 | MAX8925_LDO(20, 750, 3900, 50), |
215 | }; | 245 | }; |
216 | 246 | ||
247 | #ifdef CONFIG_OF | ||
248 | static int max8925_regulator_dt_init(struct platform_device *pdev, | ||
249 | struct max8925_regulator_info *info, | ||
250 | struct regulator_config *config, | ||
251 | int ridx) | ||
252 | { | ||
253 | struct device_node *nproot, *np; | ||
254 | int rcount; | ||
255 | nproot = pdev->dev.parent->of_node; | ||
256 | if (!nproot) | ||
257 | return -ENODEV; | ||
258 | np = of_find_node_by_name(nproot, "regulators"); | ||
259 | if (!np) { | ||
260 | dev_err(&pdev->dev, "failed to find regulators node\n"); | ||
261 | return -ENODEV; | ||
262 | } | ||
263 | |||
264 | rcount = of_regulator_match(&pdev->dev, np, | ||
265 | &max8925_regulator_matches[ridx], 1); | ||
266 | if (rcount < 0) | ||
267 | return -ENODEV; | ||
268 | config->init_data = max8925_regulator_matches[ridx].init_data; | ||
269 | config->of_node = max8925_regulator_matches[ridx].of_node; | ||
270 | |||
271 | return 0; | ||
272 | } | ||
273 | #else | ||
274 | #define max8925_regulator_dt_init(w, x, y, z) (-1) | ||
275 | #endif | ||
276 | |||
217 | static int __devinit max8925_regulator_probe(struct platform_device *pdev) | 277 | static int __devinit max8925_regulator_probe(struct platform_device *pdev) |
218 | { | 278 | { |
219 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); | 279 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); |
@@ -222,7 +282,7 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev) | |||
222 | struct max8925_regulator_info *ri; | 282 | struct max8925_regulator_info *ri; |
223 | struct resource *res; | 283 | struct resource *res; |
224 | struct regulator_dev *rdev; | 284 | struct regulator_dev *rdev; |
225 | int i; | 285 | int i, regulator_idx; |
226 | 286 | ||
227 | res = platform_get_resource(pdev, IORESOURCE_REG, 0); | 287 | res = platform_get_resource(pdev, IORESOURCE_REG, 0); |
228 | if (!res) { | 288 | if (!res) { |
@@ -231,9 +291,12 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev) | |||
231 | } | 291 | } |
232 | for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) { | 292 | for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) { |
233 | ri = &max8925_regulator_info[i]; | 293 | ri = &max8925_regulator_info[i]; |
234 | if (ri->vol_reg == res->start) | 294 | if (ri->vol_reg == res->start) { |
295 | regulator_idx = i; | ||
235 | break; | 296 | break; |
297 | } | ||
236 | } | 298 | } |
299 | |||
237 | if (i == ARRAY_SIZE(max8925_regulator_info)) { | 300 | if (i == ARRAY_SIZE(max8925_regulator_info)) { |
238 | dev_err(&pdev->dev, "Failed to find regulator %llu\n", | 301 | dev_err(&pdev->dev, "Failed to find regulator %llu\n", |
239 | (unsigned long long)res->start); | 302 | (unsigned long long)res->start); |
@@ -243,9 +306,12 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev) | |||
243 | ri->chip = chip; | 306 | ri->chip = chip; |
244 | 307 | ||
245 | config.dev = &pdev->dev; | 308 | config.dev = &pdev->dev; |
246 | config.init_data = pdata; | ||
247 | config.driver_data = ri; | 309 | config.driver_data = ri; |
248 | 310 | ||
311 | if (max8925_regulator_dt_init(pdev, ri, &config, regulator_idx)) | ||
312 | if (pdata) | ||
313 | config.init_data = pdata; | ||
314 | |||
249 | rdev = regulator_register(&ri->desc, &config); | 315 | rdev = regulator_register(&ri->desc, &config); |
250 | if (IS_ERR(rdev)) { | 316 | if (IS_ERR(rdev)) { |
251 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 317 | dev_err(&pdev->dev, "failed to register regulator %s\n", |