提交 c7993147 编写于 作者: L Linus Torvalds

Merge tag 'for-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply

Pull power supply and reset updates from Sebastian Reichel:
 "Not much from the power-supply subsystem this time around, since I was
  busy most of the cycle. This also contains some fixes that I
  originally planned to send for 5.18. Apart from this there is nothing
  noteworthy.

  Power-supply core:

   - init power_supply_info struct to zero

  Drivers:

   - bq27xxx: expose data for uncalibrated battery

   - bq24190-charger: use pm_runtime_resume_and_get

   - ab8500_fg: allocate wq in probe

   - axp288_fuel_gauge: drop BIOS version from 'T3 MRD' quirk

   - axp288_fuel_gauge: modify 'T3 MRD' quirk to also fix 'One Mix 1'"

* tag 'for-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply:
  power: supply: bq24190_charger: using pm_runtime_resume_and_get instead of pm_runtime_get_sync
  power: supply: bq27xxx: expose battery data when CI=1
  power: supply: ab8500_fg: Allocate wq in probe
  power: supply: axp288_fuel_gauge: Drop BIOS version check from "T3 MRD" DMI quirk
  power: supply: axp288_fuel_gauge: Fix battery reporting on the One Mix 1
  power: supply: core: Initialize struct to zero
...@@ -3037,13 +3037,6 @@ static int ab8500_fg_bind(struct device *dev, struct device *master, ...@@ -3037,13 +3037,6 @@ static int ab8500_fg_bind(struct device *dev, struct device *master,
{ {
struct ab8500_fg *di = dev_get_drvdata(dev); struct ab8500_fg *di = dev_get_drvdata(dev);
/* Create a work queue for running the FG algorithm */
di->fg_wq = alloc_ordered_workqueue("ab8500_fg_wq", WQ_MEM_RECLAIM);
if (di->fg_wq == NULL) {
dev_err(dev, "failed to create work queue\n");
return -ENOMEM;
}
di->bat_cap.max_mah_design = di->bm->bi->charge_full_design_uah; di->bat_cap.max_mah_design = di->bm->bi->charge_full_design_uah;
di->bat_cap.max_mah = di->bat_cap.max_mah_design; di->bat_cap.max_mah = di->bat_cap.max_mah_design;
di->vbat_nom_uv = di->bm->bi->voltage_max_design_uv; di->vbat_nom_uv = di->bm->bi->voltage_max_design_uv;
...@@ -3067,8 +3060,7 @@ static void ab8500_fg_unbind(struct device *dev, struct device *master, ...@@ -3067,8 +3060,7 @@ static void ab8500_fg_unbind(struct device *dev, struct device *master,
if (ret) if (ret)
dev_err(dev, "failed to disable coulomb counter\n"); dev_err(dev, "failed to disable coulomb counter\n");
destroy_workqueue(di->fg_wq); flush_workqueue(di->fg_wq);
flush_scheduled_work();
} }
static const struct component_ops ab8500_fg_component_ops = { static const struct component_ops ab8500_fg_component_ops = {
...@@ -3117,6 +3109,13 @@ static int ab8500_fg_probe(struct platform_device *pdev) ...@@ -3117,6 +3109,13 @@ static int ab8500_fg_probe(struct platform_device *pdev)
ab8500_fg_charge_state_to(di, AB8500_FG_CHARGE_INIT); ab8500_fg_charge_state_to(di, AB8500_FG_CHARGE_INIT);
ab8500_fg_discharge_state_to(di, AB8500_FG_DISCHARGE_INIT); ab8500_fg_discharge_state_to(di, AB8500_FG_DISCHARGE_INIT);
/* Create a work queue for running the FG algorithm */
di->fg_wq = alloc_ordered_workqueue("ab8500_fg_wq", WQ_MEM_RECLAIM);
if (di->fg_wq == NULL) {
dev_err(dev, "failed to create work queue\n");
return -ENOMEM;
}
/* Init work for running the fg algorithm instantly */ /* Init work for running the fg algorithm instantly */
INIT_WORK(&di->fg_work, ab8500_fg_instant_work); INIT_WORK(&di->fg_work, ab8500_fg_instant_work);
...@@ -3227,6 +3226,8 @@ static int ab8500_fg_remove(struct platform_device *pdev) ...@@ -3227,6 +3226,8 @@ static int ab8500_fg_remove(struct platform_device *pdev)
{ {
struct ab8500_fg *di = platform_get_drvdata(pdev); struct ab8500_fg *di = platform_get_drvdata(pdev);
destroy_workqueue(di->fg_wq);
flush_scheduled_work();
component_del(&pdev->dev, &ab8500_fg_component_ops); component_del(&pdev->dev, &ab8500_fg_component_ops);
list_del(&di->node); list_del(&di->node);
ab8500_fg_sysfs_exit(di); ab8500_fg_sysfs_exit(di);
......
...@@ -90,6 +90,8 @@ ...@@ -90,6 +90,8 @@
#define AXP288_REG_UPDATE_INTERVAL (60 * HZ) #define AXP288_REG_UPDATE_INTERVAL (60 * HZ)
#define AXP288_FG_INTR_NUM 6 #define AXP288_FG_INTR_NUM 6
#define AXP288_QUIRK_NO_BATTERY BIT(0)
static bool no_current_sense_res; static bool no_current_sense_res;
module_param(no_current_sense_res, bool, 0444); module_param(no_current_sense_res, bool, 0444);
MODULE_PARM_DESC(no_current_sense_res, "No (or broken) current sense resistor"); MODULE_PARM_DESC(no_current_sense_res, "No (or broken) current sense resistor");
...@@ -524,7 +526,7 @@ static struct power_supply_desc fuel_gauge_desc = { ...@@ -524,7 +526,7 @@ static struct power_supply_desc fuel_gauge_desc = {
* detection reports one despite it not being there. * detection reports one despite it not being there.
* Please keep this listed sorted alphabetically. * Please keep this listed sorted alphabetically.
*/ */
static const struct dmi_system_id axp288_no_battery_list[] = { static const struct dmi_system_id axp288_quirks[] = {
{ {
/* ACEPC T8 Cherry Trail Z8350 mini PC */ /* ACEPC T8 Cherry Trail Z8350 mini PC */
.matches = { .matches = {
...@@ -534,6 +536,7 @@ static const struct dmi_system_id axp288_no_battery_list[] = { ...@@ -534,6 +536,7 @@ static const struct dmi_system_id axp288_no_battery_list[] = {
/* also match on somewhat unique bios-version */ /* also match on somewhat unique bios-version */
DMI_EXACT_MATCH(DMI_BIOS_VERSION, "1.000"), DMI_EXACT_MATCH(DMI_BIOS_VERSION, "1.000"),
}, },
.driver_data = (void *)AXP288_QUIRK_NO_BATTERY,
}, },
{ {
/* ACEPC T11 Cherry Trail Z8350 mini PC */ /* ACEPC T11 Cherry Trail Z8350 mini PC */
...@@ -544,6 +547,7 @@ static const struct dmi_system_id axp288_no_battery_list[] = { ...@@ -544,6 +547,7 @@ static const struct dmi_system_id axp288_no_battery_list[] = {
/* also match on somewhat unique bios-version */ /* also match on somewhat unique bios-version */
DMI_EXACT_MATCH(DMI_BIOS_VERSION, "1.000"), DMI_EXACT_MATCH(DMI_BIOS_VERSION, "1.000"),
}, },
.driver_data = (void *)AXP288_QUIRK_NO_BATTERY,
}, },
{ {
/* Intel Cherry Trail Compute Stick, Windows version */ /* Intel Cherry Trail Compute Stick, Windows version */
...@@ -551,6 +555,7 @@ static const struct dmi_system_id axp288_no_battery_list[] = { ...@@ -551,6 +555,7 @@ static const struct dmi_system_id axp288_no_battery_list[] = {
DMI_MATCH(DMI_SYS_VENDOR, "Intel"), DMI_MATCH(DMI_SYS_VENDOR, "Intel"),
DMI_MATCH(DMI_PRODUCT_NAME, "STK1AW32SC"), DMI_MATCH(DMI_PRODUCT_NAME, "STK1AW32SC"),
}, },
.driver_data = (void *)AXP288_QUIRK_NO_BATTERY,
}, },
{ {
/* Intel Cherry Trail Compute Stick, version without an OS */ /* Intel Cherry Trail Compute Stick, version without an OS */
...@@ -558,34 +563,54 @@ static const struct dmi_system_id axp288_no_battery_list[] = { ...@@ -558,34 +563,54 @@ static const struct dmi_system_id axp288_no_battery_list[] = {
DMI_MATCH(DMI_SYS_VENDOR, "Intel"), DMI_MATCH(DMI_SYS_VENDOR, "Intel"),
DMI_MATCH(DMI_PRODUCT_NAME, "STK1A32SC"), DMI_MATCH(DMI_PRODUCT_NAME, "STK1A32SC"),
}, },
.driver_data = (void *)AXP288_QUIRK_NO_BATTERY,
}, },
{ {
/* Meegopad T02 */ /* Meegopad T02 */
.matches = { .matches = {
DMI_MATCH(DMI_PRODUCT_NAME, "MEEGOPAD T02"), DMI_MATCH(DMI_PRODUCT_NAME, "MEEGOPAD T02"),
}, },
.driver_data = (void *)AXP288_QUIRK_NO_BATTERY,
}, },
{ /* Mele PCG03 Mini PC */ { /* Mele PCG03 Mini PC */
.matches = { .matches = {
DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Mini PC"), DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Mini PC"),
DMI_EXACT_MATCH(DMI_BOARD_NAME, "Mini PC"), DMI_EXACT_MATCH(DMI_BOARD_NAME, "Mini PC"),
}, },
.driver_data = (void *)AXP288_QUIRK_NO_BATTERY,
}, },
{ {
/* Minix Neo Z83-4 mini PC */ /* Minix Neo Z83-4 mini PC */
.matches = { .matches = {
DMI_MATCH(DMI_SYS_VENDOR, "MINIX"), DMI_MATCH(DMI_SYS_VENDOR, "MINIX"),
DMI_MATCH(DMI_PRODUCT_NAME, "Z83-4"), DMI_MATCH(DMI_PRODUCT_NAME, "Z83-4"),
} },
.driver_data = (void *)AXP288_QUIRK_NO_BATTERY,
}, },
{ {
/* Various Ace PC/Meegopad/MinisForum/Wintel Mini-PCs/HDMI-sticks */ /*
* One Mix 1, this uses the "T3 MRD" boardname used by
* generic mini PCs, but it is a mini laptop so it does
* actually have a battery!
*/
.matches = {
DMI_MATCH(DMI_BOARD_NAME, "T3 MRD"),
DMI_MATCH(DMI_BIOS_DATE, "06/14/2018"),
},
.driver_data = NULL,
},
{
/*
* Various Ace PC/Meegopad/MinisForum/Wintel Mini-PCs/HDMI-sticks
* This entry must be last because it is generic, this allows
* adding more specifuc quirks overriding this generic entry.
*/
.matches = { .matches = {
DMI_MATCH(DMI_BOARD_NAME, "T3 MRD"), DMI_MATCH(DMI_BOARD_NAME, "T3 MRD"),
DMI_MATCH(DMI_CHASSIS_TYPE, "3"), DMI_MATCH(DMI_CHASSIS_TYPE, "3"),
DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."), DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
DMI_MATCH(DMI_BIOS_VERSION, "5.11"),
}, },
.driver_data = (void *)AXP288_QUIRK_NO_BATTERY,
}, },
{} {}
}; };
...@@ -665,7 +690,9 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev) ...@@ -665,7 +690,9 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev)
[BAT_D_CURR] = "axp288-chrg-d-curr", [BAT_D_CURR] = "axp288-chrg-d-curr",
[BAT_VOLT] = "axp288-batt-volt", [BAT_VOLT] = "axp288-batt-volt",
}; };
const struct dmi_system_id *dmi_id;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
unsigned long quirks = 0;
int i, pirq, ret; int i, pirq, ret;
/* /*
...@@ -675,7 +702,11 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev) ...@@ -675,7 +702,11 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev)
if (!acpi_quirk_skip_acpi_ac_and_battery()) if (!acpi_quirk_skip_acpi_ac_and_battery())
return -ENODEV; return -ENODEV;
if (dmi_check_system(axp288_no_battery_list)) dmi_id = dmi_first_match(axp288_quirks);
if (dmi_id)
quirks = (unsigned long)dmi_id->driver_data;
if (quirks & AXP288_QUIRK_NO_BATTERY)
return -ENODEV; return -ENODEV;
info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
......
...@@ -455,11 +455,9 @@ static ssize_t bq24190_sysfs_show(struct device *dev, ...@@ -455,11 +455,9 @@ static ssize_t bq24190_sysfs_show(struct device *dev,
if (!info) if (!info)
return -EINVAL; return -EINVAL;
ret = pm_runtime_get_sync(bdi->dev); ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0) { if (ret < 0)
pm_runtime_put_noidle(bdi->dev);
return ret; return ret;
}
ret = bq24190_read_mask(bdi, info->reg, info->mask, info->shift, &v); ret = bq24190_read_mask(bdi, info->reg, info->mask, info->shift, &v);
if (ret) if (ret)
...@@ -490,11 +488,9 @@ static ssize_t bq24190_sysfs_store(struct device *dev, ...@@ -490,11 +488,9 @@ static ssize_t bq24190_sysfs_store(struct device *dev,
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = pm_runtime_get_sync(bdi->dev); ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0) { if (ret < 0)
pm_runtime_put_noidle(bdi->dev);
return ret; return ret;
}
ret = bq24190_write_mask(bdi, info->reg, info->mask, info->shift, v); ret = bq24190_write_mask(bdi, info->reg, info->mask, info->shift, v);
if (ret) if (ret)
...@@ -512,10 +508,9 @@ static int bq24190_set_otg_vbus(struct bq24190_dev_info *bdi, bool enable) ...@@ -512,10 +508,9 @@ static int bq24190_set_otg_vbus(struct bq24190_dev_info *bdi, bool enable)
union power_supply_propval val = { .intval = bdi->charge_type }; union power_supply_propval val = { .intval = bdi->charge_type };
int ret; int ret;
ret = pm_runtime_get_sync(bdi->dev); ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0) { if (ret < 0) {
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret); dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
pm_runtime_put_noidle(bdi->dev);
return ret; return ret;
} }
...@@ -551,10 +546,9 @@ static int bq24190_vbus_is_enabled(struct regulator_dev *dev) ...@@ -551,10 +546,9 @@ static int bq24190_vbus_is_enabled(struct regulator_dev *dev)
int ret; int ret;
u8 val; u8 val;
ret = pm_runtime_get_sync(bdi->dev); ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0) { if (ret < 0) {
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret); dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
pm_runtime_put_noidle(bdi->dev);
return ret; return ret;
} }
...@@ -1128,11 +1122,9 @@ static int bq24190_charger_get_property(struct power_supply *psy, ...@@ -1128,11 +1122,9 @@ static int bq24190_charger_get_property(struct power_supply *psy,
dev_dbg(bdi->dev, "prop: %d\n", psp); dev_dbg(bdi->dev, "prop: %d\n", psp);
ret = pm_runtime_get_sync(bdi->dev); ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0) { if (ret < 0)
pm_runtime_put_noidle(bdi->dev);
return ret; return ret;
}
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_CHARGE_TYPE: case POWER_SUPPLY_PROP_CHARGE_TYPE:
...@@ -1204,11 +1196,9 @@ static int bq24190_charger_set_property(struct power_supply *psy, ...@@ -1204,11 +1196,9 @@ static int bq24190_charger_set_property(struct power_supply *psy,
dev_dbg(bdi->dev, "prop: %d\n", psp); dev_dbg(bdi->dev, "prop: %d\n", psp);
ret = pm_runtime_get_sync(bdi->dev); ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0) { if (ret < 0)
pm_runtime_put_noidle(bdi->dev);
return ret; return ret;
}
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_ONLINE: case POWER_SUPPLY_PROP_ONLINE:
...@@ -1477,11 +1467,9 @@ static int bq24190_battery_get_property(struct power_supply *psy, ...@@ -1477,11 +1467,9 @@ static int bq24190_battery_get_property(struct power_supply *psy,
dev_warn(bdi->dev, "warning: /sys/class/power_supply/bq24190-battery is deprecated\n"); dev_warn(bdi->dev, "warning: /sys/class/power_supply/bq24190-battery is deprecated\n");
dev_dbg(bdi->dev, "prop: %d\n", psp); dev_dbg(bdi->dev, "prop: %d\n", psp);
ret = pm_runtime_get_sync(bdi->dev); ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0) { if (ret < 0)
pm_runtime_put_noidle(bdi->dev);
return ret; return ret;
}
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_STATUS: case POWER_SUPPLY_PROP_STATUS:
...@@ -1525,11 +1513,9 @@ static int bq24190_battery_set_property(struct power_supply *psy, ...@@ -1525,11 +1513,9 @@ static int bq24190_battery_set_property(struct power_supply *psy,
dev_warn(bdi->dev, "warning: /sys/class/power_supply/bq24190-battery is deprecated\n"); dev_warn(bdi->dev, "warning: /sys/class/power_supply/bq24190-battery is deprecated\n");
dev_dbg(bdi->dev, "prop: %d\n", psp); dev_dbg(bdi->dev, "prop: %d\n", psp);
ret = pm_runtime_get_sync(bdi->dev); ret = pm_runtime_resume_and_get(bdi->dev);
if (ret < 0) { if (ret < 0)
pm_runtime_put_noidle(bdi->dev);
return ret; return ret;
}
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_ONLINE: case POWER_SUPPLY_PROP_ONLINE:
...@@ -1683,10 +1669,9 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data) ...@@ -1683,10 +1669,9 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
int error; int error;
bdi->irq_event = true; bdi->irq_event = true;
error = pm_runtime_get_sync(bdi->dev); error = pm_runtime_resume_and_get(bdi->dev);
if (error < 0) { if (error < 0) {
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
pm_runtime_put_noidle(bdi->dev);
return IRQ_NONE; return IRQ_NONE;
} }
bq24190_check_status(bdi); bq24190_check_status(bdi);
...@@ -1921,11 +1906,9 @@ static int bq24190_remove(struct i2c_client *client) ...@@ -1921,11 +1906,9 @@ static int bq24190_remove(struct i2c_client *client)
struct bq24190_dev_info *bdi = i2c_get_clientdata(client); struct bq24190_dev_info *bdi = i2c_get_clientdata(client);
int error; int error;
error = pm_runtime_get_sync(bdi->dev); error = pm_runtime_resume_and_get(bdi->dev);
if (error < 0) { if (error < 0)
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
pm_runtime_put_noidle(bdi->dev);
}
bq24190_register_reset(bdi); bq24190_register_reset(bdi);
if (bdi->battery) if (bdi->battery)
...@@ -1982,11 +1965,9 @@ static __maybe_unused int bq24190_pm_suspend(struct device *dev) ...@@ -1982,11 +1965,9 @@ static __maybe_unused int bq24190_pm_suspend(struct device *dev)
struct bq24190_dev_info *bdi = i2c_get_clientdata(client); struct bq24190_dev_info *bdi = i2c_get_clientdata(client);
int error; int error;
error = pm_runtime_get_sync(bdi->dev); error = pm_runtime_resume_and_get(bdi->dev);
if (error < 0) { if (error < 0)
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
pm_runtime_put_noidle(bdi->dev);
}
bq24190_register_reset(bdi); bq24190_register_reset(bdi);
...@@ -2007,11 +1988,9 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev) ...@@ -2007,11 +1988,9 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)
bdi->f_reg = 0; bdi->f_reg = 0;
bdi->ss_reg = BQ24190_REG_SS_VBUS_STAT_MASK; /* impossible state */ bdi->ss_reg = BQ24190_REG_SS_VBUS_STAT_MASK; /* impossible state */
error = pm_runtime_get_sync(bdi->dev); error = pm_runtime_resume_and_get(bdi->dev);
if (error < 0) { if (error < 0)
dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error);
pm_runtime_put_noidle(bdi->dev);
}
bq24190_register_reset(bdi); bq24190_register_reset(bdi);
bq24190_set_config(bdi); bq24190_set_config(bdi);
......
...@@ -1572,14 +1572,6 @@ static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg) ...@@ -1572,14 +1572,6 @@ static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
*/ */
static inline int bq27xxx_battery_read_nac(struct bq27xxx_device_info *di) static inline int bq27xxx_battery_read_nac(struct bq27xxx_device_info *di)
{ {
int flags;
if (di->opts & BQ27XXX_O_ZERO) {
flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true);
if (flags >= 0 && (flags & BQ27000_FLAG_CI))
return -ENODATA;
}
return bq27xxx_battery_read_charge(di, BQ27XXX_REG_NAC); return bq27xxx_battery_read_charge(di, BQ27XXX_REG_NAC);
} }
...@@ -1742,6 +1734,18 @@ static bool bq27xxx_battery_dead(struct bq27xxx_device_info *di, u16 flags) ...@@ -1742,6 +1734,18 @@ static bool bq27xxx_battery_dead(struct bq27xxx_device_info *di, u16 flags)
return flags & (BQ27XXX_FLAG_SOC1 | BQ27XXX_FLAG_SOCF); return flags & (BQ27XXX_FLAG_SOC1 | BQ27XXX_FLAG_SOCF);
} }
/*
* Returns true if reported battery capacity is inaccurate
*/
static bool bq27xxx_battery_capacity_inaccurate(struct bq27xxx_device_info *di,
u16 flags)
{
if (di->opts & BQ27XXX_O_HAS_CI)
return (flags & BQ27000_FLAG_CI);
else
return false;
}
static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di) static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
{ {
/* Unlikely but important to return first */ /* Unlikely but important to return first */
...@@ -1751,6 +1755,8 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di) ...@@ -1751,6 +1755,8 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
return POWER_SUPPLY_HEALTH_COLD; return POWER_SUPPLY_HEALTH_COLD;
if (unlikely(bq27xxx_battery_dead(di, di->cache.flags))) if (unlikely(bq27xxx_battery_dead(di, di->cache.flags)))
return POWER_SUPPLY_HEALTH_DEAD; return POWER_SUPPLY_HEALTH_DEAD;
if (unlikely(bq27xxx_battery_capacity_inaccurate(di, di->cache.flags)))
return POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
return POWER_SUPPLY_HEALTH_GOOD; return POWER_SUPPLY_HEALTH_GOOD;
} }
...@@ -1758,7 +1764,6 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di) ...@@ -1758,7 +1764,6 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
void bq27xxx_battery_update(struct bq27xxx_device_info *di) void bq27xxx_battery_update(struct bq27xxx_device_info *di)
{ {
struct bq27xxx_reg_cache cache = {0, }; struct bq27xxx_reg_cache cache = {0, };
bool has_ci_flag = di->opts & BQ27XXX_O_HAS_CI;
bool has_singe_flag = di->opts & BQ27XXX_O_ZERO; bool has_singe_flag = di->opts & BQ27XXX_O_ZERO;
cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag); cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag);
...@@ -1766,30 +1771,19 @@ void bq27xxx_battery_update(struct bq27xxx_device_info *di) ...@@ -1766,30 +1771,19 @@ void bq27xxx_battery_update(struct bq27xxx_device_info *di)
cache.flags = -1; /* read error */ cache.flags = -1; /* read error */
if (cache.flags >= 0) { if (cache.flags >= 0) {
cache.temperature = bq27xxx_battery_read_temperature(di); cache.temperature = bq27xxx_battery_read_temperature(di);
if (has_ci_flag && (cache.flags & BQ27000_FLAG_CI)) { if (di->regs[BQ27XXX_REG_TTE] != INVALID_REG_ADDR)
dev_info_once(di->dev, "battery is not calibrated! ignoring capacity values\n"); cache.time_to_empty = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTE);
cache.capacity = -ENODATA; if (di->regs[BQ27XXX_REG_TTECP] != INVALID_REG_ADDR)
cache.energy = -ENODATA; cache.time_to_empty_avg = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTECP);
cache.time_to_empty = -ENODATA; if (di->regs[BQ27XXX_REG_TTF] != INVALID_REG_ADDR)
cache.time_to_empty_avg = -ENODATA; cache.time_to_full = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTF);
cache.time_to_full = -ENODATA;
cache.charge_full = -ENODATA; cache.charge_full = bq27xxx_battery_read_fcc(di);
cache.health = -ENODATA; cache.capacity = bq27xxx_battery_read_soc(di);
} else { if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR)
if (di->regs[BQ27XXX_REG_TTE] != INVALID_REG_ADDR) cache.energy = bq27xxx_battery_read_energy(di);
cache.time_to_empty = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTE); di->cache.flags = cache.flags;
if (di->regs[BQ27XXX_REG_TTECP] != INVALID_REG_ADDR) cache.health = bq27xxx_battery_read_health(di);
cache.time_to_empty_avg = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTECP);
if (di->regs[BQ27XXX_REG_TTF] != INVALID_REG_ADDR)
cache.time_to_full = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTF);
cache.charge_full = bq27xxx_battery_read_fcc(di);
cache.capacity = bq27xxx_battery_read_soc(di);
if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR)
cache.energy = bq27xxx_battery_read_energy(di);
di->cache.flags = cache.flags;
cache.health = bq27xxx_battery_read_health(di);
}
if (di->regs[BQ27XXX_REG_CYCT] != INVALID_REG_ADDR) if (di->regs[BQ27XXX_REG_CYCT] != INVALID_REG_ADDR)
cache.cycle_count = bq27xxx_battery_read_cyct(di); cache.cycle_count = bq27xxx_battery_read_cyct(di);
......
...@@ -616,7 +616,7 @@ int power_supply_get_battery_info(struct power_supply *psy, ...@@ -616,7 +616,7 @@ int power_supply_get_battery_info(struct power_supply *psy,
goto out_put_node; goto out_put_node;
} }
info = devm_kmalloc(&psy->dev, sizeof(*info), GFP_KERNEL); info = devm_kzalloc(&psy->dev, sizeof(*info), GFP_KERNEL);
if (!info) { if (!info) {
err = -ENOMEM; err = -ENOMEM;
goto out_put_node; goto out_put_node;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册