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

Merge remote-tracking branches 'regulator/fix/max8907', 'regulator/fix/max8997', 'regulator/fix/tps65910' and 'regulator/topic/mc13892' into regulator-of

+122 -42
+19 -20
drivers/regulator/max8997.c
··· 934 934 }; 935 935 936 936 #ifdef CONFIG_OF 937 - static int max8997_pmic_dt_parse_dvs_gpio(struct max8997_dev *iodev, 937 + static int max8997_pmic_dt_parse_dvs_gpio(struct platform_device *pdev, 938 938 struct max8997_platform_data *pdata, 939 939 struct device_node *pmic_np) 940 940 { ··· 944 944 gpio = of_get_named_gpio(pmic_np, 945 945 "max8997,pmic-buck125-dvs-gpios", i); 946 946 if (!gpio_is_valid(gpio)) { 947 - dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio); 947 + dev_err(&pdev->dev, "invalid gpio[%d]: %d\n", i, gpio); 948 948 return -EINVAL; 949 949 } 950 950 pdata->buck125_gpios[i] = gpio; ··· 952 952 return 0; 953 953 } 954 954 955 - static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev, 955 + static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev, 956 956 struct max8997_platform_data *pdata) 957 957 { 958 + struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); 958 959 struct device_node *pmic_np, *regulators_np, *reg_np; 959 960 struct max8997_regulator_data *rdata; 960 961 unsigned int i, dvs_voltage_nr = 1, ret; 961 962 962 963 pmic_np = iodev->dev->of_node; 963 964 if (!pmic_np) { 964 - dev_err(iodev->dev, "could not find pmic sub-node\n"); 965 + dev_err(&pdev->dev, "could not find pmic sub-node\n"); 965 966 return -ENODEV; 966 967 } 967 968 968 969 regulators_np = of_find_node_by_name(pmic_np, "regulators"); 969 970 if (!regulators_np) { 970 - dev_err(iodev->dev, "could not find regulators sub-node\n"); 971 + dev_err(&pdev->dev, "could not find regulators sub-node\n"); 971 972 return -EINVAL; 972 973 } 973 974 ··· 977 976 for_each_child_of_node(regulators_np, reg_np) 978 977 pdata->num_regulators++; 979 978 980 - rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) * 979 + rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) * 981 980 pdata->num_regulators, GFP_KERNEL); 982 981 if (!rdata) { 983 - dev_err(iodev->dev, "could not allocate memory for " 984 - "regulator data\n"); 982 + dev_err(&pdev->dev, "could not allocate memory for regulator data\n"); 985 983 return -ENOMEM; 986 984 } 987 985 ··· 991 991 break; 992 992 993 993 if (i == ARRAY_SIZE(regulators)) { 994 - dev_warn(iodev->dev, "don't know how to configure " 995 - "regulator %s\n", reg_np->name); 994 + dev_warn(&pdev->dev, "don't know how to configure regulator %s\n", 995 + reg_np->name); 996 996 continue; 997 997 } 998 998 999 999 rdata->id = i; 1000 - rdata->initdata = of_get_regulator_init_data( 1001 - iodev->dev, reg_np); 1000 + rdata->initdata = of_get_regulator_init_data(&pdev->dev, 1001 + reg_np); 1002 1002 rdata->reg_node = reg_np; 1003 1003 rdata++; 1004 1004 } ··· 1014 1014 1015 1015 if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || 1016 1016 pdata->buck5_gpiodvs) { 1017 - ret = max8997_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np); 1017 + ret = max8997_pmic_dt_parse_dvs_gpio(pdev, pdata, pmic_np); 1018 1018 if (ret) 1019 1019 return -EINVAL; 1020 1020 ··· 1025 1025 } else { 1026 1026 if (pdata->buck125_default_idx >= 8) { 1027 1027 pdata->buck125_default_idx = 0; 1028 - dev_info(iodev->dev, "invalid value for " 1029 - "default dvs index, using 0 instead\n"); 1028 + dev_info(&pdev->dev, "invalid value for default dvs index, using 0 instead\n"); 1030 1029 } 1031 1030 } 1032 1031 ··· 1039 1040 if (of_property_read_u32_array(pmic_np, 1040 1041 "max8997,pmic-buck1-dvs-voltage", 1041 1042 pdata->buck1_voltage, dvs_voltage_nr)) { 1042 - dev_err(iodev->dev, "buck1 voltages not specified\n"); 1043 + dev_err(&pdev->dev, "buck1 voltages not specified\n"); 1043 1044 return -EINVAL; 1044 1045 } 1045 1046 1046 1047 if (of_property_read_u32_array(pmic_np, 1047 1048 "max8997,pmic-buck2-dvs-voltage", 1048 1049 pdata->buck2_voltage, dvs_voltage_nr)) { 1049 - dev_err(iodev->dev, "buck2 voltages not specified\n"); 1050 + dev_err(&pdev->dev, "buck2 voltages not specified\n"); 1050 1051 return -EINVAL; 1051 1052 } 1052 1053 1053 1054 if (of_property_read_u32_array(pmic_np, 1054 1055 "max8997,pmic-buck5-dvs-voltage", 1055 1056 pdata->buck5_voltage, dvs_voltage_nr)) { 1056 - dev_err(iodev->dev, "buck5 voltages not specified\n"); 1057 + dev_err(&pdev->dev, "buck5 voltages not specified\n"); 1057 1058 return -EINVAL; 1058 1059 } 1059 1060 1060 1061 return 0; 1061 1062 } 1062 1063 #else 1063 - static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev, 1064 + static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev, 1064 1065 struct max8997_platform_data *pdata) 1065 1066 { 1066 1067 return 0; ··· 1084 1085 } 1085 1086 1086 1087 if (iodev->dev->of_node) { 1087 - ret = max8997_pmic_dt_parse_pdata(iodev, pdata); 1088 + ret = max8997_pmic_dt_parse_pdata(pdev, pdata); 1088 1089 if (ret) 1089 1090 return ret; 1090 1091 }
+92 -17
drivers/regulator/mc13892-regulator.c
··· 164 164 1350000, 1375000 165 165 }; 166 166 167 + /* 168 + * Note: this table is used to derive SWxVSEL by index into 169 + * the array. Offset the values by the index of 1100000uV 170 + * to get the actual register value for that voltage selector 171 + * if the HI bit is to be set as well. 172 + */ 173 + #define MC13892_SWxHI_SEL_OFFSET 20 174 + 167 175 static const unsigned int mc13892_sw[] = { 168 176 600000, 625000, 650000, 675000, 700000, 725000, 169 177 750000, 775000, 800000, 825000, 850000, 875000, ··· 247 239 }; 248 240 249 241 static struct regulator_ops mc13892_gpo_regulator_ops; 250 - /* sw regulators need special care due to the "hi bit" */ 251 242 static struct regulator_ops mc13892_sw_regulator_ops; 252 243 253 244 ··· 403 396 { 404 397 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); 405 398 int ret, id = rdev_get_id(rdev); 406 - unsigned int val; 399 + unsigned int val, selector; 407 400 408 401 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 409 402 ··· 414 407 if (ret) 415 408 return ret; 416 409 417 - val = (val & mc13892_regulators[id].vsel_mask) 418 - >> mc13892_regulators[id].vsel_shift; 410 + /* 411 + * Figure out if the HI bit is set inside the switcher mode register 412 + * since this means the selector value we return is at a different 413 + * offset into the selector table. 414 + * 415 + * According to the MC13892 documentation note 59 (Table 47) the SW1 416 + * buck switcher does not support output range programming therefore 417 + * the HI bit must always remain 0. So do not do anything strange if 418 + * our register is MC13892_SWITCHERS0. 419 + */ 419 420 420 - dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val); 421 + selector = val & mc13892_regulators[id].vsel_mask; 421 422 422 - return val; 423 + if ((mc13892_regulators[id].vsel_reg != MC13892_SWITCHERS0) && 424 + (val & MC13892_SWITCHERS0_SWxHI)) { 425 + selector += MC13892_SWxHI_SEL_OFFSET; 426 + } 427 + 428 + dev_dbg(rdev_get_dev(rdev), "%s id: %d val: 0x%08x selector: %d\n", 429 + __func__, id, val, selector); 430 + 431 + return selector; 423 432 } 424 433 425 434 static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev, ··· 448 425 449 426 volt = rdev->desc->volt_table[selector]; 450 427 mask = mc13892_regulators[id].vsel_mask; 451 - reg_value = selector << mc13892_regulators[id].vsel_shift; 428 + reg_value = selector; 452 429 453 - if (volt > 1375000) { 454 - mask |= MC13892_SWITCHERS0_SWxHI; 455 - reg_value |= MC13892_SWITCHERS0_SWxHI; 456 - } else if (volt < 1100000) { 457 - mask |= MC13892_SWITCHERS0_SWxHI; 458 - reg_value &= ~MC13892_SWITCHERS0_SWxHI; 430 + /* 431 + * Don't mess with the HI bit or support HI voltage offsets for SW1. 432 + * 433 + * Since the get_voltage_sel callback has given a fudged value for 434 + * the selector offset, we need to back out that offset if HI is 435 + * to be set so we write the correct value to the register. 436 + * 437 + * The HI bit addition and selector offset handling COULD be more 438 + * complicated by shifting and masking off the voltage selector part 439 + * of the register then logical OR it back in, but since the selector 440 + * is at bits 4:0 there is very little point. This makes the whole 441 + * thing more readable and we do far less work. 442 + */ 443 + 444 + if (mc13892_regulators[id].vsel_reg != MC13892_SWITCHERS0) { 445 + if (volt > 1375000) { 446 + reg_value -= MC13892_SWxHI_SEL_OFFSET; 447 + reg_value |= MC13892_SWITCHERS0_SWxHI; 448 + mask |= MC13892_SWITCHERS0_SWxHI; 449 + } else if (volt < 1100000) { 450 + reg_value &= ~MC13892_SWITCHERS0_SWxHI; 451 + mask |= MC13892_SWITCHERS0_SWxHI; 452 + } 459 453 } 460 454 461 455 mc13xxx_lock(priv->mc13xxx); 462 - ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].reg, mask, 456 + ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].vsel_reg, mask, 463 457 reg_value); 464 458 mc13xxx_unlock(priv->mc13xxx); 465 459 ··· 535 495 struct mc13xxx_regulator_init_data *mc13xxx_data; 536 496 struct regulator_config config = { }; 537 497 int i, ret; 538 - int num_regulators = 0; 498 + int num_regulators = 0, num_parsed; 539 499 u32 val; 540 500 541 501 num_regulators = mc13xxx_get_num_regulators_dt(pdev); 502 + 542 503 if (num_regulators <= 0 && pdata) 543 504 num_regulators = pdata->num_regulators; 544 505 if (num_regulators <= 0) 545 506 return -EINVAL; 507 + 508 + num_parsed = num_regulators; 546 509 547 510 priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + 548 511 num_regulators * sizeof(priv->regulators[0]), ··· 563 520 if (ret) 564 521 goto err_unlock; 565 522 566 - /* enable switch auto mode */ 523 + /* enable switch auto mode (on 2.0A silicon only) */ 567 524 if ((val & 0x0000FFFF) == 0x45d0) { 568 525 ret = mc13xxx_reg_rmw(mc13892, MC13892_SWITCHERS4, 569 526 MC13892_SWITCHERS4_SW1MODE_M | ··· 589 546 = mc13892_vcam_get_mode; 590 547 591 548 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators, 592 - ARRAY_SIZE(mc13892_regulators)); 549 + ARRAY_SIZE(mc13892_regulators), 550 + &num_parsed); 551 + 552 + /* 553 + * Perform a little sanity check on the regulator tree - if we found 554 + * a number of regulators from mc13xxx_get_num_regulators_dt and 555 + * then parsed a smaller number in mc13xxx_parse_regulators_dt then 556 + * there is a regulator defined in the regulators node which has 557 + * not matched any usable regulator in the driver. In this case, 558 + * there is one missing and what will happen is the first regulator 559 + * will get registered again. 560 + * 561 + * Fix this by basically making our number of registerable regulators 562 + * equal to the number of regulators we parsed. We are allocating 563 + * too much memory for priv, but this is unavoidable at this point. 564 + * 565 + * As an example of how this can happen, try making a typo in your 566 + * regulators node (vviohi {} instead of viohi {}) so that the name 567 + * does not match.. 568 + * 569 + * The check will basically pass for platform data (non-DT) because 570 + * mc13xxx_parse_regulators_dt for !CONFIG_OF will not touch num_parsed. 571 + * 572 + */ 573 + if (num_parsed != num_regulators) { 574 + dev_warn(&pdev->dev, 575 + "parsed %d != regulators %d - check your device tree!\n", 576 + num_parsed, num_regulators); 577 + 578 + num_regulators = num_parsed; 579 + priv->num_regulators = num_regulators; 580 + } 581 + 593 582 for (i = 0; i < num_regulators; i++) { 594 583 struct regulator_init_data *init_data; 595 584 struct regulator_desc *desc;
+8 -2
drivers/regulator/mc13xxx-regulator-core.c
··· 181 181 182 182 struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( 183 183 struct platform_device *pdev, struct mc13xxx_regulator *regulators, 184 - int num_regulators) 184 + int num_regulators, int *num_parsed) 185 185 { 186 186 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev); 187 187 struct mc13xxx_regulator_init_data *data, *p; 188 188 struct device_node *parent, *child; 189 - int i; 189 + int i, parsed = 0; 190 + 191 + *num_parsed = 0; 190 192 191 193 of_node_get(pdev->dev.parent->of_node); 192 194 parent = of_find_node_by_name(pdev->dev.parent->of_node, "regulators"); ··· 205 203 for (i = 0; i < num_regulators; i++) { 206 204 if (!of_node_cmp(child->name, 207 205 regulators[i].desc.name)) { 206 + 208 207 p->id = i; 209 208 p->init_data = of_get_regulator_init_data( 210 209 &pdev->dev, child); 211 210 p->node = child; 212 211 p++; 212 + 213 + parsed++; 213 214 break; 214 215 } 215 216 } 216 217 } 217 218 219 + *num_parsed = parsed; 218 220 return data; 219 221 } 220 222 EXPORT_SYMBOL_GPL(mc13xxx_parse_regulators_dt);
+2 -2
drivers/regulator/mc13xxx.h
··· 39 39 extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev); 40 40 extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( 41 41 struct platform_device *pdev, struct mc13xxx_regulator *regulators, 42 - int num_regulators); 42 + int num_regulators, int *num_parsed); 43 43 #else 44 44 static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev) 45 45 { ··· 48 48 49 49 static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( 50 50 struct platform_device *pdev, struct mc13xxx_regulator *regulators, 51 - int num_regulators) 51 + int num_regulators, int *num_parsed) 52 52 { 53 53 return NULL; 54 54 }
+1 -1
drivers/regulator/tps65910-regulator.c
··· 998 998 return NULL; 999 999 } 1000 1000 1001 - ret = of_regulator_match(pdev->dev.parent, regulators, matches, count); 1001 + ret = of_regulator_match(&pdev->dev, regulators, matches, count); 1002 1002 if (ret < 0) { 1003 1003 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", 1004 1004 ret);