Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: max8925: support dt for regulator

Signed-off-by: Qing Xu <qingx@marvell.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

Qing Xu and committed by
Mark Brown
45b6f8e8 3d70f8c6

+98 -3
+29
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 + }
+69 -3
drivers/regulator/max8925-regulator.c
··· 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 ··· 189 187 .enable_reg = MAX8925_LDOCTL##_id, \ 190 188 } 191 189 190 + #ifdef CONFIG_OF 191 + static struct of_regulator_match max8925_regulator_matches[] = { 192 + { .name = "SDV1",}, 193 + { .name = "SDV2",}, 194 + { .name = "SDV3",}, 195 + { .name = "LDO1",}, 196 + { .name = "LDO2",}, 197 + { .name = "LDO3",}, 198 + { .name = "LDO4",}, 199 + { .name = "LDO5",}, 200 + { .name = "LDO6",}, 201 + { .name = "LDO7",}, 202 + { .name = "LDO8",}, 203 + { .name = "LDO9",}, 204 + { .name = "LDO10",}, 205 + { .name = "LDO11",}, 206 + { .name = "LDO12",}, 207 + { .name = "LDO13",}, 208 + { .name = "LDO14",}, 209 + { .name = "LDO15",}, 210 + { .name = "LDO16",}, 211 + { .name = "LDO17",}, 212 + { .name = "LDO18",}, 213 + { .name = "LDO19",}, 214 + { .name = "LDO20",}, 215 + }; 216 + #endif 217 + 192 218 static struct max8925_regulator_info max8925_regulator_info[] = { 193 219 MAX8925_SDV(1, 637.5, 1425, 12.5), 194 220 MAX8925_SDV(2, 650, 2225, 25), ··· 244 214 MAX8925_LDO(20, 750, 3900, 50), 245 215 }; 246 216 217 + #ifdef CONFIG_OF 218 + static int max8925_regulator_dt_init(struct platform_device *pdev, 219 + struct max8925_regulator_info *info, 220 + struct regulator_config *config, 221 + int ridx) 222 + { 223 + struct device_node *nproot, *np; 224 + int rcount; 225 + nproot = pdev->dev.parent->of_node; 226 + if (!nproot) 227 + return -ENODEV; 228 + np = of_find_node_by_name(nproot, "regulators"); 229 + if (!np) { 230 + dev_err(&pdev->dev, "failed to find regulators node\n"); 231 + return -ENODEV; 232 + } 233 + 234 + rcount = of_regulator_match(&pdev->dev, np, 235 + &max8925_regulator_matches[ridx], 1); 236 + if (rcount < 0) 237 + return -ENODEV; 238 + config->init_data = max8925_regulator_matches[ridx].init_data; 239 + config->of_node = max8925_regulator_matches[ridx].of_node; 240 + 241 + return 0; 242 + } 243 + #else 244 + #define max8925_regulator_dt_init(w, x, y, z) (-1) 245 + #endif 246 + 247 247 static int __devinit max8925_regulator_probe(struct platform_device *pdev) 248 248 { 249 249 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); ··· 282 222 struct max8925_regulator_info *ri; 283 223 struct resource *res; 284 224 struct regulator_dev *rdev; 285 - int i; 225 + int i, regulator_idx; 286 226 287 227 res = platform_get_resource(pdev, IORESOURCE_REG, 0); 288 228 if (!res) { ··· 291 231 } 292 232 for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) { 293 233 ri = &max8925_regulator_info[i]; 294 - if (ri->vol_reg == res->start) 234 + if (ri->vol_reg == res->start) { 235 + regulator_idx = i; 295 236 break; 237 + } 296 238 } 239 + 297 240 if (i == ARRAY_SIZE(max8925_regulator_info)) { 298 241 dev_err(&pdev->dev, "Failed to find regulator %llu\n", 299 242 (unsigned long long)res->start); ··· 306 243 ri->chip = chip; 307 244 308 245 config.dev = &pdev->dev; 309 - config.init_data = pdata; 310 246 config.driver_data = ri; 247 + 248 + if (max8925_regulator_dt_init(pdev, ri, &config, regulator_idx)) 249 + if (pdata) 250 + config.init_data = pdata; 311 251 312 252 rdev = regulator_register(&ri->desc, &config); 313 253 if (IS_ERR(rdev)) {