Commit 45b6f8e8fc014fe404d155a657a04b25b861001d
Committed by
Mark Brown
1 parent
3d70f8c617
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
regulator: max8925: support dt for regulator
Signed-off-by: Qing Xu <qingx@marvell.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Showing 2 changed files with 98 additions and 3 deletions Side-by-side Diff
Documentation/devicetree/bindings/regulator/max8925-regulator.txt
1 | +Max8925 Voltage regulators | |
2 | + | |
3 | +max8925 regulator device register is still handled by mfd_add_devices, not by | |
4 | +of_xxx, so, it is not necessary to add compatible name. Also, those reg | |
5 | +offset and id info is stored in mfd_cell(see max8925-core.c), as a result | |
6 | +there is not private properties in dts. | |
7 | + | |
8 | +node's name should match with the definition in max8925_regulator_matches | |
9 | +(see max8925-regulator.c) | |
10 | + | |
11 | + | |
12 | +Optional properties: | |
13 | +- Any optional property defined in bindings/regulator/regulator.txt | |
14 | + | |
15 | + | |
16 | +Example: | |
17 | + | |
18 | + | |
19 | + regulators { | |
20 | + SDV1 { | |
21 | + regulator-min-microvolt = <637500>; | |
22 | + regulator-max-microvolt = <1425000>; | |
23 | + regulator-boot-on; | |
24 | + regulator-always-on; | |
25 | + }; | |
26 | + | |
27 | + ... | |
28 | + ... | |
29 | + } |
drivers/regulator/max8925-regulator.c
... | ... | @@ -17,6 +17,8 @@ |
17 | 17 | #include <linux/regulator/driver.h> |
18 | 18 | #include <linux/regulator/machine.h> |
19 | 19 | #include <linux/mfd/max8925.h> |
20 | +#include <linux/of.h> | |
21 | +#include <linux/regulator/of_regulator.h> | |
20 | 22 | |
21 | 23 | #define SD1_DVM_VMIN 850000 |
22 | 24 | #define SD1_DVM_VMAX 1000000 |
... | ... | @@ -187,6 +189,34 @@ |
187 | 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 | 220 | static struct max8925_regulator_info max8925_regulator_info[] = { |
191 | 221 | MAX8925_SDV(1, 637.5, 1425, 12.5), |
192 | 222 | MAX8925_SDV(2, 650, 2225, 25), |
... | ... | @@ -214,6 +244,36 @@ |
214 | 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 | 277 | static int __devinit max8925_regulator_probe(struct platform_device *pdev) |
218 | 278 | { |
219 | 279 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); |
... | ... | @@ -222,7 +282,7 @@ |
222 | 282 | struct max8925_regulator_info *ri; |
223 | 283 | struct resource *res; |
224 | 284 | struct regulator_dev *rdev; |
225 | - int i; | |
285 | + int i, regulator_idx; | |
226 | 286 | |
227 | 287 | res = platform_get_resource(pdev, IORESOURCE_REG, 0); |
228 | 288 | if (!res) { |
229 | 289 | |
230 | 290 | |
... | ... | @@ -231,9 +291,12 @@ |
231 | 291 | } |
232 | 292 | for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) { |
233 | 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 | 296 | break; |
297 | + } | |
236 | 298 | } |
299 | + | |
237 | 300 | if (i == ARRAY_SIZE(max8925_regulator_info)) { |
238 | 301 | dev_err(&pdev->dev, "Failed to find regulator %llu\n", |
239 | 302 | (unsigned long long)res->start); |
240 | 303 | |
... | ... | @@ -243,8 +306,11 @@ |
243 | 306 | ri->chip = chip; |
244 | 307 | |
245 | 308 | config.dev = &pdev->dev; |
246 | - config.init_data = pdata; | |
247 | 309 | config.driver_data = ri; |
310 | + | |
311 | + if (max8925_regulator_dt_init(pdev, ri, &config, regulator_idx)) | |
312 | + if (pdata) | |
313 | + config.init_data = pdata; | |
248 | 314 | |
249 | 315 | rdev = regulator_register(&ri->desc, &config); |
250 | 316 | if (IS_ERR(rdev)) { |