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

power: supply_core: Pass pointer to battery info

The function to retrieve battery info (from the device tree) assumes
we have a static info struct that gets populated by calling into
power_supply_get_battery_info().

This is awkward since I want to support tables of static battery
info by just assigning a pointer to all info based on e.g. a
compatible value in the device tree.

We also have a mixture of static and dynamically allocated
variables here.

Bite the bullet and let power_supply_get_battery_info() allocate
also the memory used for the very top level
struct power_supply_battery_info container. Pass pointers
around and lifecycle this with the psy device just like the
stuff we allocate inside it.

Change all current users over.

As part of the change, initializers need to be added to some
previously uninitialized fields in struct
power_supply_battery_info.

Reviewed-By: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Linus Walleij and committed by
Sebastian Reichel
25fd3303 be2c0d54

+157 -127
+1 -1
drivers/power/supply/ab8500-bm.h
··· 439 439 * @fg_params fuel gauge parameters 440 440 */ 441 441 struct ab8500_bm_data { 442 - struct power_supply_battery_info bi; 442 + struct power_supply_battery_info *bi; 443 443 int temp_now; 444 444 int temp_interval_chg; 445 445 int temp_interval_nochg;
+4 -3
drivers/power/supply/ab8500_bmdata.c
··· 167 167 int ab8500_bm_of_probe(struct power_supply *psy, 168 168 struct ab8500_bm_data *bm) 169 169 { 170 - struct power_supply_battery_info *bi = &bm->bi; 170 + struct power_supply_battery_info *bi; 171 171 struct device *dev = &psy->dev; 172 172 int ret; 173 173 174 - ret = power_supply_get_battery_info(psy, bi); 174 + ret = power_supply_get_battery_info(psy, &bm->bi); 175 175 if (ret) { 176 176 dev_err(dev, "cannot retrieve battery info\n"); 177 177 return ret; 178 178 } 179 + bi = bm->bi; 179 180 180 181 /* Fill in defaults for any data missing from the device tree */ 181 182 if (bi->charge_full_design_uah < 0) ··· 241 240 void ab8500_bm_of_remove(struct power_supply *psy, 242 241 struct ab8500_bm_data *bm) 243 242 { 244 - power_supply_put_battery_info(psy, &bm->bi); 243 + power_supply_put_battery_info(psy, bm->bi); 245 244 }
+7 -3
drivers/power/supply/ab8500_btemp.c
··· 451 451 */ 452 452 static int ab8500_btemp_measure_temp(struct ab8500_btemp *di) 453 453 { 454 + struct power_supply_battery_info *bi = di->bm->bi; 454 455 int temp, ret; 455 456 static int prev; 456 457 int rbat, rntc, vntc; 457 458 458 459 if ((di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL) && 459 - (di->bm->bi.technology == POWER_SUPPLY_TECHNOLOGY_UNKNOWN)) { 460 + (bi && (bi->technology == POWER_SUPPLY_TECHNOLOGY_UNKNOWN))) { 460 461 461 462 rbat = ab8500_btemp_get_batctrl_res(di); 462 463 if (rbat < 0) { ··· 541 540 * that need it. 542 541 */ 543 542 if ((di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL) && 544 - (di->bm->bi.technology == POWER_SUPPLY_TECHNOLOGY_LIPO) && 543 + (di->bm->bi && (di->bm->bi->technology == POWER_SUPPLY_TECHNOLOGY_LIPO)) && 545 544 (res <= 53407) && (res >= 12500)) { 546 545 dev_dbg(di->dev, "Set BATCTRL current source to 20uA\n"); 547 546 di->curr_source = BTEMP_BATCTRL_CURR_SRC_20UA; ··· 808 807 val->intval = 1; 809 808 break; 810 809 case POWER_SUPPLY_PROP_TECHNOLOGY: 811 - val->intval = di->bm->bi.technology; 810 + if (di->bm->bi) 811 + val->intval = di->bm->bi->technology; 812 + else 813 + val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; 812 814 break; 813 815 case POWER_SUPPLY_PROP_TEMP: 814 816 val->intval = ab8500_btemp_get_temp(di);
+8 -8
drivers/power/supply/ab8500_chargalg.c
··· 352 352 353 353 static int ab8500_chargalg_check_charger_enable(struct ab8500_chargalg *di) 354 354 { 355 - struct power_supply_battery_info *bi = &di->bm->bi; 355 + struct power_supply_battery_info *bi = di->bm->bi; 356 356 357 357 switch (di->charge_state) { 358 358 case STATE_NORMAL: ··· 731 731 */ 732 732 static void ab8500_chargalg_check_temp(struct ab8500_chargalg *di) 733 733 { 734 - struct power_supply_battery_info *bi = &di->bm->bi; 734 + struct power_supply_battery_info *bi = di->bm->bi; 735 735 736 736 if (di->batt_data.temp > (bi->temp_alert_min + di->t_hyst_norm) && 737 737 di->batt_data.temp < (bi->temp_alert_max - di->t_hyst_norm)) { ··· 802 802 if (di->charge_status == POWER_SUPPLY_STATUS_CHARGING && 803 803 di->charge_state == STATE_NORMAL && 804 804 !di->maintenance_chg && (di->batt_data.volt_uv >= 805 - di->bm->bi.overvoltage_limit_uv || 805 + di->bm->bi->overvoltage_limit_uv || 806 806 di->events.usb_cv_active || di->events.ac_cv_active) && 807 807 di->batt_data.avg_curr_ua < 808 - di->bm->bi.charge_term_current_ua && 808 + di->bm->bi->charge_term_current_ua && 809 809 di->batt_data.avg_curr_ua > 0) { 810 810 if (++di->eoc_cnt >= EOC_COND_CNT) { 811 811 di->eoc_cnt = 0; ··· 827 827 828 828 static void init_maxim_chg_curr(struct ab8500_chargalg *di) 829 829 { 830 - struct power_supply_battery_info *bi = &di->bm->bi; 830 + struct power_supply_battery_info *bi = di->bm->bi; 831 831 832 832 di->ccm.original_iset_ua = bi->constant_charge_current_max_ua; 833 833 di->ccm.current_iset_ua = bi->constant_charge_current_max_ua; ··· 920 920 921 921 static void handle_maxim_chg_curr(struct ab8500_chargalg *di) 922 922 { 923 - struct power_supply_battery_info *bi = &di->bm->bi; 923 + struct power_supply_battery_info *bi = di->bm->bi; 924 924 enum maxim_ret ret; 925 925 int result; 926 926 ··· 1299 1299 */ 1300 1300 static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di) 1301 1301 { 1302 - struct power_supply_battery_info *bi = &di->bm->bi; 1302 + struct power_supply_battery_info *bi = di->bm->bi; 1303 1303 int charger_status; 1304 1304 int ret; 1305 1305 int curr_step_lvl_ua; ··· 1723 1723 if (di->events.batt_ovv) { 1724 1724 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; 1725 1725 } else if (di->events.btemp_underover) { 1726 - if (di->batt_data.temp <= di->bm->bi.temp_min) 1726 + if (di->batt_data.temp <= di->bm->bi->temp_min) 1727 1727 val->intval = POWER_SUPPLY_HEALTH_COLD; 1728 1728 else 1729 1729 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
+10 -8
drivers/power/supply/ab8500_fg.c
··· 852 852 */ 853 853 static int ab8500_fg_volt_to_capacity(struct ab8500_fg *di, int voltage_uv) 854 854 { 855 - struct power_supply_battery_info *bi = &di->bm->bi; 855 + struct power_supply_battery_info *bi = di->bm->bi; 856 856 857 857 /* Multiply by 10 because the capacity is tracked in per mille */ 858 858 return power_supply_batinfo_ocv2cap(bi, voltage_uv, di->bat_temp) * 10; ··· 881 881 */ 882 882 static int ab8500_fg_battery_resistance(struct ab8500_fg *di) 883 883 { 884 - struct power_supply_battery_info *bi = &di->bm->bi; 884 + struct power_supply_battery_info *bi = di->bm->bi; 885 885 int resistance_percent = 0; 886 886 int resistance; 887 887 ··· 2140 2140 struct power_supply *ext = dev_get_drvdata(dev); 2141 2141 const char **supplicants = (const char **)ext->supplied_to; 2142 2142 struct ab8500_fg *di; 2143 + struct power_supply_battery_info *bi; 2143 2144 union power_supply_propval ret; 2144 2145 int j; 2145 2146 2146 2147 psy = (struct power_supply *)data; 2147 2148 di = power_supply_get_drvdata(psy); 2149 + bi = di->bm->bi; 2148 2150 2149 2151 /* 2150 2152 * For all psy where the name of your driver ··· 2209 2207 switch (ext->desc->type) { 2210 2208 case POWER_SUPPLY_TYPE_BATTERY: 2211 2209 if (!di->flags.batt_id_received && 2212 - (di->bm->bi.technology != 2213 - POWER_SUPPLY_TECHNOLOGY_UNKNOWN)) { 2210 + (bi && (bi->technology != 2211 + POWER_SUPPLY_TECHNOLOGY_UNKNOWN))) { 2214 2212 const struct ab8500_battery_type *b; 2215 2213 2216 2214 b = di->bm->bat_type; ··· 2218 2216 di->flags.batt_id_received = true; 2219 2217 2220 2218 di->bat_cap.max_mah_design = 2221 - di->bm->bi.charge_full_design_uah; 2219 + di->bm->bi->charge_full_design_uah; 2222 2220 2223 2221 di->bat_cap.max_mah = 2224 2222 di->bat_cap.max_mah_design; 2225 2223 2226 2224 di->vbat_nom_uv = 2227 - di->bm->bi.voltage_max_design_uv; 2225 + di->bm->bi->voltage_max_design_uv; 2228 2226 } 2229 2227 2230 2228 if (ret.intval) ··· 2994 2992 return -ENOMEM; 2995 2993 } 2996 2994 2997 - di->bat_cap.max_mah_design = di->bm->bi.charge_full_design_uah; 2995 + di->bat_cap.max_mah_design = di->bm->bi->charge_full_design_uah; 2998 2996 di->bat_cap.max_mah = di->bat_cap.max_mah_design; 2999 - di->vbat_nom_uv = di->bm->bi.voltage_max_design_uv; 2997 + di->vbat_nom_uv = di->bm->bi->voltage_max_design_uv; 3000 2998 3001 2999 /* Start the coulomb counter */ 3002 3000 ab8500_fg_coulomb_counter(di, true);
+3 -3
drivers/power/supply/axp20x_battery.c
··· 561 561 { 562 562 struct axp20x_batt_ps *axp20x_batt; 563 563 struct power_supply_config psy_cfg = {}; 564 - struct power_supply_battery_info info; 564 + struct power_supply_battery_info *info; 565 565 struct device *dev = &pdev->dev; 566 566 567 567 if (!of_device_is_available(pdev->dev.of_node)) ··· 615 615 } 616 616 617 617 if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) { 618 - int vmin = info.voltage_min_design_uv; 619 - int ccc = info.constant_charge_current_max_ua; 618 + int vmin = info->voltage_min_design_uv; 619 + int ccc = info->constant_charge_current_max_ua; 620 620 621 621 if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt, 622 622 vmin))
+13 -11
drivers/power/supply/bd99954-charger.c
··· 882 882 static int bd9995x_fw_probe(struct bd9995x_device *bd) 883 883 { 884 884 int ret; 885 - struct power_supply_battery_info info; 885 + struct power_supply_battery_info *info; 886 886 u32 property; 887 887 int i; 888 888 int regval; ··· 891 891 struct battery_init battery_inits[] = { 892 892 { 893 893 .name = "trickle-charging current", 894 - .info_data = &info.tricklecharge_current_ua, 895 894 .range = &charging_current_ranges[0], 896 895 .ranges = 2, 897 896 .data = &init->itrich_set, 898 897 }, { 899 898 .name = "pre-charging current", 900 - .info_data = &info.precharge_current_ua, 901 899 .range = &charging_current_ranges[0], 902 900 .ranges = 2, 903 901 .data = &init->iprech_set, 904 902 }, { 905 903 .name = "pre-to-trickle charge voltage threshold", 906 - .info_data = &info.precharge_voltage_max_uv, 907 904 .range = &trickle_to_pre_threshold_ranges[0], 908 905 .ranges = 2, 909 906 .data = &init->vprechg_th_set, 910 907 }, { 911 908 .name = "charging termination current", 912 - .info_data = &info.charge_term_current_ua, 913 909 .range = &charging_current_ranges[0], 914 910 .ranges = 2, 915 911 .data = &init->iterm_set, 916 912 }, { 917 913 .name = "charging re-start voltage", 918 - .info_data = &info.charge_restart_voltage_uv, 919 914 .range = &charge_voltage_regulation_ranges[0], 920 915 .ranges = 2, 921 916 .data = &init->vrechg_set, 922 917 }, { 923 918 .name = "battery overvoltage limit", 924 - .info_data = &info.overvoltage_limit_uv, 925 919 .range = &charge_voltage_regulation_ranges[0], 926 920 .ranges = 2, 927 921 .data = &init->vbatovp_set, 928 922 }, { 929 923 .name = "fast-charging max current", 930 - .info_data = &info.constant_charge_current_max_ua, 931 924 .range = &fast_charge_current_ranges[0], 932 925 .ranges = 1, 933 926 .data = &init->ichg_set, 934 927 }, { 935 928 .name = "fast-charging voltage", 936 - .info_data = &info.constant_charge_voltage_max_uv, 937 929 .range = &charge_voltage_regulation_ranges[0], 938 930 .ranges = 2, 939 931 .data = &init->vfastchg_reg_set1, ··· 958 966 if (ret < 0) 959 967 return ret; 960 968 969 + /* Put pointers to the generic battery info */ 970 + battery_inits[0].info_data = &info->tricklecharge_current_ua; 971 + battery_inits[1].info_data = &info->precharge_current_ua; 972 + battery_inits[2].info_data = &info->precharge_voltage_max_uv; 973 + battery_inits[3].info_data = &info->charge_term_current_ua; 974 + battery_inits[4].info_data = &info->charge_restart_voltage_uv; 975 + battery_inits[5].info_data = &info->overvoltage_limit_uv; 976 + battery_inits[6].info_data = &info->constant_charge_current_max_ua; 977 + battery_inits[7].info_data = &info->constant_charge_voltage_max_uv; 978 + 961 979 for (i = 0; i < ARRAY_SIZE(battery_inits); i++) { 962 980 int val = *battery_inits[i].info_data; 963 981 const struct linear_range *range = battery_inits[i].range; ··· 982 980 dev_err(bd->dev, "Unsupported value for %s\n", 983 981 battery_inits[i].name); 984 982 985 - power_supply_put_battery_info(bd->charger, &info); 983 + power_supply_put_battery_info(bd->charger, info); 986 984 return -EINVAL; 987 985 } 988 986 if (!found) { ··· 993 991 *(battery_inits[i].data) = regval; 994 992 } 995 993 996 - power_supply_put_battery_info(bd->charger, &info); 994 + power_supply_put_battery_info(bd->charger, info); 997 995 998 996 for (i = 0; i < ARRAY_SIZE(props); i++) { 999 997 ret = device_property_read_u32(bd->dev, props[i].prop,
+3 -3
drivers/power/supply/bq24190_charger.c
··· 1670 1670 static int bq24190_get_config(struct bq24190_dev_info *bdi) 1671 1671 { 1672 1672 const char * const s = "ti,system-minimum-microvolt"; 1673 - struct power_supply_battery_info info = {}; 1673 + struct power_supply_battery_info *info; 1674 1674 int v; 1675 1675 1676 1676 if (device_property_read_u32(bdi->dev, s, &v) == 0) { ··· 1684 1684 1685 1685 if (bdi->dev->of_node && 1686 1686 !power_supply_get_battery_info(bdi->charger, &info)) { 1687 - v = info.precharge_current_ua / 1000; 1687 + v = info->precharge_current_ua / 1000; 1688 1688 if (v >= BQ24190_REG_PCTCC_IPRECHG_MIN 1689 1689 && v <= BQ24190_REG_PCTCC_IPRECHG_MAX) 1690 1690 bdi->iprechg = v; ··· 1692 1692 dev_warn(bdi->dev, "invalid value for battery:precharge-current-microamp: %d\n", 1693 1693 v); 1694 1694 1695 - v = info.charge_term_current_ua / 1000; 1695 + v = info->charge_term_current_ua / 1000; 1696 1696 if (v >= BQ24190_REG_PCTCC_ITERM_MIN 1697 1697 && v <= BQ24190_REG_PCTCC_ITERM_MAX) 1698 1698 bdi->iterm = v;
+4 -4
drivers/power/supply/bq2515x_charger.c
··· 945 945 static int bq2515x_hw_init(struct bq2515x_device *bq2515x) 946 946 { 947 947 int ret; 948 - struct power_supply_battery_info bat_info = { }; 948 + struct power_supply_battery_info *bat_info; 949 949 950 950 ret = bq2515x_disable_watchdog_timers(bq2515x); 951 951 if (ret) ··· 969 969 970 970 } else { 971 971 bq2515x->init_data.ichg = 972 - bat_info.constant_charge_current_max_ua; 972 + bat_info->constant_charge_current_max_ua; 973 973 974 974 bq2515x->init_data.vbatreg = 975 - bat_info.constant_charge_voltage_max_uv; 975 + bat_info->constant_charge_voltage_max_uv; 976 976 977 977 bq2515x->init_data.iprechg = 978 - bat_info.precharge_current_ua; 978 + bat_info->precharge_current_ua; 979 979 } 980 980 981 981 ret = bq2515x_set_const_charge_current(bq2515x,
+12 -12
drivers/power/supply/bq256xx_charger.c
··· 1504 1504 1505 1505 static int bq256xx_hw_init(struct bq256xx_device *bq) 1506 1506 { 1507 - struct power_supply_battery_info bat_info = { }; 1507 + struct power_supply_battery_info *bat_info; 1508 1508 int wd_reg_val = BQ256XX_WATCHDOG_DIS; 1509 1509 int ret = 0; 1510 1510 int i; ··· 1526 1526 if (ret) { 1527 1527 dev_warn(bq->dev, "battery info missing, default values will be applied\n"); 1528 1528 1529 - bat_info.constant_charge_current_max_ua = 1529 + bat_info->constant_charge_current_max_ua = 1530 1530 bq->chip_info->bq256xx_def_ichg; 1531 1531 1532 - bat_info.constant_charge_voltage_max_uv = 1532 + bat_info->constant_charge_voltage_max_uv = 1533 1533 bq->chip_info->bq256xx_def_vbatreg; 1534 1534 1535 - bat_info.precharge_current_ua = 1535 + bat_info->precharge_current_ua = 1536 1536 bq->chip_info->bq256xx_def_iprechg; 1537 1537 1538 - bat_info.charge_term_current_ua = 1538 + bat_info->charge_term_current_ua = 1539 1539 bq->chip_info->bq256xx_def_iterm; 1540 1540 1541 1541 bq->init_data.ichg_max = ··· 1545 1545 bq->chip_info->bq256xx_max_vbatreg; 1546 1546 } else { 1547 1547 bq->init_data.ichg_max = 1548 - bat_info.constant_charge_current_max_ua; 1548 + bat_info->constant_charge_current_max_ua; 1549 1549 1550 1550 bq->init_data.vbatreg_max = 1551 - bat_info.constant_charge_voltage_max_uv; 1551 + bat_info->constant_charge_voltage_max_uv; 1552 1552 } 1553 1553 1554 1554 ret = bq->chip_info->bq256xx_set_vindpm(bq, bq->init_data.vindpm); ··· 1560 1560 return ret; 1561 1561 1562 1562 ret = bq->chip_info->bq256xx_set_ichg(bq, 1563 - bat_info.constant_charge_current_max_ua); 1563 + bat_info->constant_charge_current_max_ua); 1564 1564 if (ret) 1565 1565 return ret; 1566 1566 1567 1567 ret = bq->chip_info->bq256xx_set_iprechg(bq, 1568 - bat_info.precharge_current_ua); 1568 + bat_info->precharge_current_ua); 1569 1569 if (ret) 1570 1570 return ret; 1571 1571 1572 1572 ret = bq->chip_info->bq256xx_set_vbatreg(bq, 1573 - bat_info.constant_charge_voltage_max_uv); 1573 + bat_info->constant_charge_voltage_max_uv); 1574 1574 if (ret) 1575 1575 return ret; 1576 1576 1577 1577 ret = bq->chip_info->bq256xx_set_iterm(bq, 1578 - bat_info.charge_term_current_ua); 1578 + bat_info->charge_term_current_ua); 1579 1579 if (ret) 1580 1580 return ret; 1581 1581 1582 - power_supply_put_battery_info(bq->charger, &bat_info); 1582 + power_supply_put_battery_info(bq->charger, bat_info); 1583 1583 1584 1584 return 0; 1585 1585 }
+3 -3
drivers/power/supply/bq25980_charger.c
··· 1079 1079 1080 1080 static int bq25980_hw_init(struct bq25980_device *bq) 1081 1081 { 1082 - struct power_supply_battery_info bat_info = { }; 1082 + struct power_supply_battery_info *bat_info; 1083 1083 int wd_reg_val = BQ25980_WATCHDOG_DIS; 1084 1084 int wd_max_val = BQ25980_NUM_WD_VAL - 1; 1085 1085 int ret = 0; ··· 1112 1112 return -EINVAL; 1113 1113 } 1114 1114 1115 - bq->init_data.ichg_max = bat_info.constant_charge_current_max_ua; 1116 - bq->init_data.vreg_max = bat_info.constant_charge_voltage_max_uv; 1115 + bq->init_data.ichg_max = bat_info->constant_charge_current_max_ua; 1116 + bq->init_data.vreg_max = bat_info->constant_charge_voltage_max_uv; 1117 1117 1118 1118 if (bq->state.bypass) { 1119 1119 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_2,
+19 -19
drivers/power/supply/bq27xxx_battery.c
··· 1474 1474 1475 1475 static void bq27xxx_battery_settings(struct bq27xxx_device_info *di) 1476 1476 { 1477 - struct power_supply_battery_info info = {}; 1477 + struct power_supply_battery_info *info; 1478 1478 unsigned int min, max; 1479 1479 1480 1480 if (power_supply_get_battery_info(di->bat, &info) < 0) ··· 1485 1485 return; 1486 1486 } 1487 1487 1488 - if (info.energy_full_design_uwh != info.charge_full_design_uah) { 1489 - if (info.energy_full_design_uwh == -EINVAL) 1488 + if (info->energy_full_design_uwh != info->charge_full_design_uah) { 1489 + if (info->energy_full_design_uwh == -EINVAL) 1490 1490 dev_warn(di->dev, "missing battery:energy-full-design-microwatt-hours\n"); 1491 - else if (info.charge_full_design_uah == -EINVAL) 1491 + else if (info->charge_full_design_uah == -EINVAL) 1492 1492 dev_warn(di->dev, "missing battery:charge-full-design-microamp-hours\n"); 1493 1493 } 1494 1494 1495 1495 /* assume min == 0 */ 1496 1496 max = di->dm_regs[BQ27XXX_DM_DESIGN_ENERGY].max; 1497 - if (info.energy_full_design_uwh > max * 1000) { 1497 + if (info->energy_full_design_uwh > max * 1000) { 1498 1498 dev_err(di->dev, "invalid battery:energy-full-design-microwatt-hours %d\n", 1499 - info.energy_full_design_uwh); 1500 - info.energy_full_design_uwh = -EINVAL; 1499 + info->energy_full_design_uwh); 1500 + info->energy_full_design_uwh = -EINVAL; 1501 1501 } 1502 1502 1503 1503 /* assume min == 0 */ 1504 1504 max = di->dm_regs[BQ27XXX_DM_DESIGN_CAPACITY].max; 1505 - if (info.charge_full_design_uah > max * 1000) { 1505 + if (info->charge_full_design_uah > max * 1000) { 1506 1506 dev_err(di->dev, "invalid battery:charge-full-design-microamp-hours %d\n", 1507 - info.charge_full_design_uah); 1508 - info.charge_full_design_uah = -EINVAL; 1507 + info->charge_full_design_uah); 1508 + info->charge_full_design_uah = -EINVAL; 1509 1509 } 1510 1510 1511 1511 min = di->dm_regs[BQ27XXX_DM_TERMINATE_VOLTAGE].min; 1512 1512 max = di->dm_regs[BQ27XXX_DM_TERMINATE_VOLTAGE].max; 1513 - if ((info.voltage_min_design_uv < min * 1000 || 1514 - info.voltage_min_design_uv > max * 1000) && 1515 - info.voltage_min_design_uv != -EINVAL) { 1513 + if ((info->voltage_min_design_uv < min * 1000 || 1514 + info->voltage_min_design_uv > max * 1000) && 1515 + info->voltage_min_design_uv != -EINVAL) { 1516 1516 dev_err(di->dev, "invalid battery:voltage-min-design-microvolt %d\n", 1517 - info.voltage_min_design_uv); 1518 - info.voltage_min_design_uv = -EINVAL; 1517 + info->voltage_min_design_uv); 1518 + info->voltage_min_design_uv = -EINVAL; 1519 1519 } 1520 1520 1521 - if ((info.energy_full_design_uwh != -EINVAL && 1522 - info.charge_full_design_uah != -EINVAL) || 1523 - info.voltage_min_design_uv != -EINVAL) 1524 - bq27xxx_battery_set_config(di, &info); 1521 + if ((info->energy_full_design_uwh != -EINVAL && 1522 + info->charge_full_design_uah != -EINVAL) || 1523 + info->voltage_min_design_uv != -EINVAL) 1524 + bq27xxx_battery_set_config(di, info); 1525 1525 } 1526 1526 1527 1527 /*
+13 -7
drivers/power/supply/cw2015_battery.c
··· 61 61 struct delayed_work battery_delay_work; 62 62 struct regmap *regmap; 63 63 struct power_supply *rk_bat; 64 - struct power_supply_battery_info battery; 64 + struct power_supply_battery_info *battery; 65 65 u8 *bat_profile; 66 66 67 67 bool charger_attached; ··· 505 505 506 506 case POWER_SUPPLY_PROP_CHARGE_FULL: 507 507 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 508 - if (cw_bat->battery.charge_full_design_uah > 0) 509 - val->intval = cw_bat->battery.charge_full_design_uah; 508 + if (cw_bat->battery->charge_full_design_uah > 0) 509 + val->intval = cw_bat->battery->charge_full_design_uah; 510 510 else 511 511 val->intval = 0; 512 512 break; 513 513 514 514 case POWER_SUPPLY_PROP_CHARGE_NOW: 515 - val->intval = cw_bat->battery.charge_full_design_uah; 515 + val->intval = cw_bat->battery->charge_full_design_uah; 516 516 val->intval = val->intval * cw_bat->soc / 100; 517 517 break; 518 518 519 519 case POWER_SUPPLY_PROP_CURRENT_NOW: 520 520 if (cw_battery_valid_time_to_empty(cw_bat) && 521 - cw_bat->battery.charge_full_design_uah > 0) { 521 + cw_bat->battery->charge_full_design_uah > 0) { 522 522 /* calculate remaining capacity */ 523 - val->intval = cw_bat->battery.charge_full_design_uah; 523 + val->intval = cw_bat->battery->charge_full_design_uah; 524 524 val->intval = val->intval * cw_bat->soc / 100; 525 525 526 526 /* estimate current based on time to empty */ ··· 687 687 688 688 ret = power_supply_get_battery_info(cw_bat->rk_bat, &cw_bat->battery); 689 689 if (ret) { 690 + /* Allocate an empty battery */ 691 + cw_bat->battery = devm_kzalloc(&client->dev, 692 + sizeof(cw_bat->battery), 693 + GFP_KERNEL); 694 + if (!cw_bat->battery) 695 + return -ENOMEM; 690 696 dev_warn(cw_bat->dev, 691 697 "No monitored battery, some properties will be missing\n"); 692 698 } ··· 730 724 struct cw_battery *cw_bat = i2c_get_clientdata(client); 731 725 732 726 cancel_delayed_work_sync(&cw_bat->battery_delay_work); 733 - power_supply_put_battery_info(cw_bat->rk_bat, &cw_bat->battery); 727 + power_supply_put_battery_info(cw_bat->rk_bat, cw_bat->battery); 734 728 return 0; 735 729 } 736 730
+7 -7
drivers/power/supply/ingenic-battery.c
··· 18 18 struct iio_channel *channel; 19 19 struct power_supply_desc desc; 20 20 struct power_supply *battery; 21 - struct power_supply_battery_info info; 21 + struct power_supply_battery_info *info; 22 22 }; 23 23 24 24 static int ingenic_battery_get_property(struct power_supply *psy, ··· 26 26 union power_supply_propval *val) 27 27 { 28 28 struct ingenic_battery *bat = power_supply_get_drvdata(psy); 29 - struct power_supply_battery_info *info = &bat->info; 29 + struct power_supply_battery_info *info = bat->info; 30 30 int ret; 31 31 32 32 switch (psp) { ··· 80 80 if (ret != IIO_AVAIL_LIST || scale_type != IIO_VAL_FRACTIONAL_LOG2) 81 81 return -EINVAL; 82 82 83 - max_mV = bat->info.voltage_max_design_uv / 1000; 83 + max_mV = bat->info->voltage_max_design_uv / 1000; 84 84 85 85 for (i = 0; i < scale_len; i += 2) { 86 86 u64 scale_mV = (max_raw * scale_raw[i]) >> scale_raw[i + 1]; ··· 156 156 dev_err(dev, "Unable to get battery info: %d\n", ret); 157 157 return ret; 158 158 } 159 - if (bat->info.voltage_min_design_uv < 0) { 159 + if (bat->info->voltage_min_design_uv < 0) { 160 160 dev_err(dev, "Unable to get voltage min design\n"); 161 - return bat->info.voltage_min_design_uv; 161 + return bat->info->voltage_min_design_uv; 162 162 } 163 - if (bat->info.voltage_max_design_uv < 0) { 163 + if (bat->info->voltage_max_design_uv < 0) { 164 164 dev_err(dev, "Unable to get voltage max design\n"); 165 - return bat->info.voltage_max_design_uv; 165 + return bat->info->voltage_max_design_uv; 166 166 } 167 167 168 168 return ingenic_battery_set_scale(bat);
+17 -2
drivers/power/supply/power_supply_core.c
··· 564 564 #endif /* CONFIG_OF */ 565 565 566 566 int power_supply_get_battery_info(struct power_supply *psy, 567 - struct power_supply_battery_info *info) 567 + struct power_supply_battery_info **info_out) 568 568 { 569 569 struct power_supply_resistance_temp_table *resist_table; 570 + struct power_supply_battery_info *info; 570 571 struct device_node *battery_np; 571 572 const char *value; 572 573 int err, len, index; 573 574 const __be32 *list; 575 + 576 + info = devm_kmalloc(&psy->dev, sizeof(*info), GFP_KERNEL); 577 + if (!info) 578 + return -ENOMEM; 574 579 575 580 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; 576 581 info->energy_full_design_uwh = -EINVAL; ··· 586 581 info->charge_term_current_ua = -EINVAL; 587 582 info->constant_charge_current_max_ua = -EINVAL; 588 583 info->constant_charge_voltage_max_uv = -EINVAL; 584 + info->tricklecharge_current_ua = -EINVAL; 585 + info->precharge_voltage_max_uv = -EINVAL; 586 + info->charge_restart_voltage_uv = -EINVAL; 587 + info->overvoltage_limit_uv = -EINVAL; 589 588 info->temp_ambient_alert_min = INT_MIN; 590 589 info->temp_ambient_alert_max = INT_MAX; 591 590 info->temp_alert_min = INT_MIN; ··· 737 728 738 729 list = of_get_property(battery_np, "resistance-temp-table", &len); 739 730 if (!list || !len) 740 - goto out_put_node; 731 + goto out_ret_pointer; 741 732 742 733 info->resist_table_size = len / (2 * sizeof(__be32)); 743 734 resist_table = info->resist_table = devm_kcalloc(&psy->dev, ··· 754 745 resist_table[index].temp = be32_to_cpu(*list++); 755 746 resist_table[index].resistance = be32_to_cpu(*list++); 756 747 } 748 + 749 + out_ret_pointer: 750 + /* Finally return the whole thing */ 751 + *info_out = info; 757 752 758 753 out_put_node: 759 754 of_node_put(battery_np); ··· 777 764 778 765 if (info->resist_table) 779 766 devm_kfree(&psy->dev, info->resist_table); 767 + 768 + devm_kfree(&psy->dev, info); 780 769 } 781 770 EXPORT_SYMBOL_GPL(power_supply_put_battery_info); 782 771
+4 -4
drivers/power/supply/sc2731_charger.c
··· 368 368 369 369 static int sc2731_charger_hw_init(struct sc2731_charger_info *info) 370 370 { 371 - struct power_supply_battery_info bat_info = { }; 371 + struct power_supply_battery_info *bat_info; 372 372 u32 term_currrent, term_voltage, cur_val, vol_val; 373 373 int ret; 374 374 ··· 390 390 cur_val = 0x2; 391 391 vol_val = 0x1; 392 392 } else { 393 - term_currrent = bat_info.charge_term_current_ua / 1000; 393 + term_currrent = bat_info->charge_term_current_ua / 1000; 394 394 395 395 if (term_currrent <= 90) 396 396 cur_val = 0; ··· 399 399 else 400 400 cur_val = ((term_currrent - 90) / 25) + 1; 401 401 402 - term_voltage = bat_info.constant_charge_voltage_max_uv / 1000; 402 + term_voltage = bat_info->constant_charge_voltage_max_uv / 1000; 403 403 404 404 if (term_voltage > 4500) 405 405 term_voltage = 4500; ··· 409 409 else 410 410 vol_val = 0; 411 411 412 - power_supply_put_battery_info(info->psy_usb, &bat_info); 412 + power_supply_put_battery_info(info->psy_usb, bat_info); 413 413 } 414 414 415 415 /* Set charge termination current */
+11 -11
drivers/power/supply/sc27xx_fuel_gauge.c
··· 998 998 999 999 static int sc27xx_fgu_hw_init(struct sc27xx_fgu_data *data) 1000 1000 { 1001 - struct power_supply_battery_info info = { }; 1001 + struct power_supply_battery_info *info; 1002 1002 struct power_supply_battery_ocv_table *table; 1003 1003 int ret, delta_clbcnt, alarm_adc; 1004 1004 ··· 1008 1008 return ret; 1009 1009 } 1010 1010 1011 - data->total_cap = info.charge_full_design_uah / 1000; 1012 - data->max_volt = info.constant_charge_voltage_max_uv / 1000; 1013 - data->internal_resist = info.factory_internal_resistance_uohm / 1000; 1014 - data->min_volt = info.voltage_min_design_uv; 1011 + data->total_cap = info->charge_full_design_uah / 1000; 1012 + data->max_volt = info->constant_charge_voltage_max_uv / 1000; 1013 + data->internal_resist = info->factory_internal_resistance_uohm / 1000; 1014 + data->min_volt = info->voltage_min_design_uv; 1015 1015 1016 1016 /* 1017 1017 * For SC27XX fuel gauge device, we only use one ocv-capacity 1018 1018 * table in normal temperature 20 Celsius. 1019 1019 */ 1020 - table = power_supply_find_ocv2cap_table(&info, 20, &data->table_len); 1020 + table = power_supply_find_ocv2cap_table(info, 20, &data->table_len); 1021 1021 if (!table) 1022 1022 return -EINVAL; 1023 1023 ··· 1025 1025 data->table_len * sizeof(*table), 1026 1026 GFP_KERNEL); 1027 1027 if (!data->cap_table) { 1028 - power_supply_put_battery_info(data->battery, &info); 1028 + power_supply_put_battery_info(data->battery, info); 1029 1029 return -ENOMEM; 1030 1030 } 1031 1031 ··· 1035 1035 if (!data->alarm_cap) 1036 1036 data->alarm_cap += 1; 1037 1037 1038 - data->resist_table_len = info.resist_table_size; 1038 + data->resist_table_len = info->resist_table_size; 1039 1039 if (data->resist_table_len > 0) { 1040 - data->resist_table = devm_kmemdup(data->dev, info.resist_table, 1040 + data->resist_table = devm_kmemdup(data->dev, info->resist_table, 1041 1041 data->resist_table_len * 1042 1042 sizeof(struct power_supply_resistance_temp_table), 1043 1043 GFP_KERNEL); 1044 1044 if (!data->resist_table) { 1045 - power_supply_put_battery_info(data->battery, &info); 1045 + power_supply_put_battery_info(data->battery, info); 1046 1046 return -ENOMEM; 1047 1047 } 1048 1048 } 1049 1049 1050 - power_supply_put_battery_info(data->battery, &info); 1050 + power_supply_put_battery_info(data->battery, info); 1051 1051 1052 1052 ret = sc27xx_fgu_calibration(data); 1053 1053 if (ret)
+17 -17
drivers/power/supply/smb347-charger.c
··· 1281 1281 1282 1282 static int smb347_get_battery_info(struct smb347_charger *smb) 1283 1283 { 1284 - struct power_supply_battery_info info = {}; 1284 + struct power_supply_battery_info *info; 1285 1285 struct power_supply *supply; 1286 1286 int err; 1287 1287 ··· 1296 1296 if (err) 1297 1297 return err; 1298 1298 1299 - if (info.constant_charge_current_max_ua != -EINVAL) 1300 - smb->max_charge_current = info.constant_charge_current_max_ua; 1299 + if (info->constant_charge_current_max_ua != -EINVAL) 1300 + smb->max_charge_current = info->constant_charge_current_max_ua; 1301 1301 1302 - if (info.constant_charge_voltage_max_uv != -EINVAL) 1303 - smb->max_charge_voltage = info.constant_charge_voltage_max_uv; 1302 + if (info->constant_charge_voltage_max_uv != -EINVAL) 1303 + smb->max_charge_voltage = info->constant_charge_voltage_max_uv; 1304 1304 1305 - if (info.precharge_current_ua != -EINVAL) 1306 - smb->pre_charge_current = info.precharge_current_ua; 1305 + if (info->precharge_current_ua != -EINVAL) 1306 + smb->pre_charge_current = info->precharge_current_ua; 1307 1307 1308 - if (info.charge_term_current_ua != -EINVAL) 1309 - smb->termination_current = info.charge_term_current_ua; 1308 + if (info->charge_term_current_ua != -EINVAL) 1309 + smb->termination_current = info->charge_term_current_ua; 1310 1310 1311 - if (info.temp_alert_min != INT_MIN) 1312 - smb->soft_cold_temp_limit = info.temp_alert_min; 1311 + if (info->temp_alert_min != INT_MIN) 1312 + smb->soft_cold_temp_limit = info->temp_alert_min; 1313 1313 1314 - if (info.temp_alert_max != INT_MAX) 1315 - smb->soft_hot_temp_limit = info.temp_alert_max; 1314 + if (info->temp_alert_max != INT_MAX) 1315 + smb->soft_hot_temp_limit = info->temp_alert_max; 1316 1316 1317 - if (info.temp_min != INT_MIN) 1318 - smb->hard_cold_temp_limit = info.temp_min; 1317 + if (info->temp_min != INT_MIN) 1318 + smb->hard_cold_temp_limit = info->temp_min; 1319 1319 1320 - if (info.temp_max != INT_MAX) 1321 - smb->hard_hot_temp_limit = info.temp_max; 1320 + if (info->temp_max != INT_MAX) 1321 + smb->hard_hot_temp_limit = info->temp_max; 1322 1322 1323 1323 /* Suspend when battery temperature is outside hard limits */ 1324 1324 if (smb->hard_cold_temp_limit != SMB3XX_TEMP_USE_DEFAULT ||
+1 -1
include/linux/power_supply.h
··· 575 575 #endif /* CONFIG_OF */ 576 576 577 577 extern int power_supply_get_battery_info(struct power_supply *psy, 578 - struct power_supply_battery_info *info); 578 + struct power_supply_battery_info **info_out); 579 579 extern void power_supply_put_battery_info(struct power_supply *psy, 580 580 struct power_supply_battery_info *info); 581 581 extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table,