Loading drivers/power/supply/qcom/qpnp-fg-gen3.c +63 −27 Original line number Diff line number Diff line Loading @@ -1687,12 +1687,38 @@ static int fg_set_recharge_voltage(struct fg_chip *chip, int voltage_mv) return 0; } static int fg_configure_full_soc(struct fg_chip *chip, int bsoc) { int rc; u8 full_soc[2] = {0xFF, 0xFF}; /* * Once SOC masking condition is cleared, FULL_SOC and MONOTONIC_SOC * needs to be updated to reflect the same. Write battery SOC to * FULL_SOC and write a full value to MONOTONIC_SOC. */ rc = fg_sram_write(chip, FULL_SOC_WORD, FULL_SOC_OFFSET, (u8 *)&bsoc, 2, FG_IMA_ATOMIC); if (rc < 0) { pr_err("failed to write full_soc rc=%d\n", rc); return rc; } rc = fg_sram_write(chip, MONOTONIC_SOC_WORD, MONOTONIC_SOC_OFFSET, full_soc, 2, FG_IMA_ATOMIC); if (rc < 0) { pr_err("failed to write monotonic_soc rc=%d\n", rc); return rc; } return 0; } #define AUTO_RECHG_VOLT_LOW_LIMIT_MV 3700 static int fg_charge_full_update(struct fg_chip *chip) { union power_supply_propval prop = {0, }; int rc, msoc, bsoc, recharge_soc, msoc_raw; u8 full_soc[2] = {0xFF, 0xFF}; if (!chip->dt.hold_soc_while_full) return 0; Loading Loading @@ -1769,8 +1795,6 @@ static int fg_charge_full_update(struct fg_chip *chip) } } chip->charge_full = false; /* * Raise the recharge voltage so that VBAT_LT_RECHG signal * will be asserted soon as battery SOC had dropped below Loading @@ -1783,35 +1807,23 @@ static int fg_charge_full_update(struct fg_chip *chip) rc); goto out; } fg_dbg(chip, FG_STATUS, "msoc_raw = %d bsoc: %d recharge_soc: %d delta_soc: %d\n", msoc_raw, bsoc >> 8, recharge_soc, chip->delta_soc); } else { goto out; } if (!chip->charge_full) goto out; /* * During JEITA conditions, charge_full can happen early. FULL_SOC * and MONOTONIC_SOC needs to be updated to reflect the same. Write * battery SOC to FULL_SOC and write a full value to MONOTONIC_SOC. * If charge_done is still set, wait for recharging or * discharging to happen. */ rc = fg_sram_write(chip, FULL_SOC_WORD, FULL_SOC_OFFSET, (u8 *)&bsoc, 2, FG_IMA_ATOMIC); if (rc < 0) { pr_err("failed to write full_soc rc=%d\n", rc); if (chip->charge_done) goto out; } rc = fg_sram_write(chip, MONOTONIC_SOC_WORD, MONOTONIC_SOC_OFFSET, full_soc, 2, FG_IMA_ATOMIC); if (rc < 0) { pr_err("failed to write monotonic_soc rc=%d\n", rc); rc = fg_configure_full_soc(chip, bsoc); if (rc < 0) goto out; chip->charge_full = false; fg_dbg(chip, FG_STATUS, "msoc_raw = %d bsoc: %d recharge_soc: %d delta_soc: %d\n", msoc_raw, bsoc >> 8, recharge_soc, chip->delta_soc); } fg_dbg(chip, FG_STATUS, "Set charge_full to true @ soc %d\n", msoc); out: mutex_unlock(&chip->charge_full_lock); return rc; Loading Loading @@ -5126,6 +5138,29 @@ static int fg_gen3_remove(struct platform_device *pdev) return 0; } static void fg_gen3_shutdown(struct platform_device *pdev) { struct fg_chip *chip = dev_get_drvdata(&pdev->dev); int rc, bsoc; if (chip->charge_full) { rc = fg_get_sram_prop(chip, FG_SRAM_BATT_SOC, &bsoc); if (rc < 0) { pr_err("Error in getting BATT_SOC, rc=%d\n", rc); return; } /* We need 2 most significant bytes here */ bsoc = (u32)bsoc >> 16; rc = fg_configure_full_soc(chip, bsoc); if (rc < 0) { pr_err("Error in configuring full_soc, rc=%d\n", rc); return; } } } static const struct of_device_id fg_gen3_match_table[] = { {.compatible = FG_GEN3_DEV_NAME}, {}, Loading @@ -5140,6 +5175,7 @@ static struct platform_driver fg_gen3_driver = { }, .probe = fg_gen3_probe, .remove = fg_gen3_remove, .shutdown = fg_gen3_shutdown, }; static int __init fg_gen3_init(void) Loading Loading
drivers/power/supply/qcom/qpnp-fg-gen3.c +63 −27 Original line number Diff line number Diff line Loading @@ -1687,12 +1687,38 @@ static int fg_set_recharge_voltage(struct fg_chip *chip, int voltage_mv) return 0; } static int fg_configure_full_soc(struct fg_chip *chip, int bsoc) { int rc; u8 full_soc[2] = {0xFF, 0xFF}; /* * Once SOC masking condition is cleared, FULL_SOC and MONOTONIC_SOC * needs to be updated to reflect the same. Write battery SOC to * FULL_SOC and write a full value to MONOTONIC_SOC. */ rc = fg_sram_write(chip, FULL_SOC_WORD, FULL_SOC_OFFSET, (u8 *)&bsoc, 2, FG_IMA_ATOMIC); if (rc < 0) { pr_err("failed to write full_soc rc=%d\n", rc); return rc; } rc = fg_sram_write(chip, MONOTONIC_SOC_WORD, MONOTONIC_SOC_OFFSET, full_soc, 2, FG_IMA_ATOMIC); if (rc < 0) { pr_err("failed to write monotonic_soc rc=%d\n", rc); return rc; } return 0; } #define AUTO_RECHG_VOLT_LOW_LIMIT_MV 3700 static int fg_charge_full_update(struct fg_chip *chip) { union power_supply_propval prop = {0, }; int rc, msoc, bsoc, recharge_soc, msoc_raw; u8 full_soc[2] = {0xFF, 0xFF}; if (!chip->dt.hold_soc_while_full) return 0; Loading Loading @@ -1769,8 +1795,6 @@ static int fg_charge_full_update(struct fg_chip *chip) } } chip->charge_full = false; /* * Raise the recharge voltage so that VBAT_LT_RECHG signal * will be asserted soon as battery SOC had dropped below Loading @@ -1783,35 +1807,23 @@ static int fg_charge_full_update(struct fg_chip *chip) rc); goto out; } fg_dbg(chip, FG_STATUS, "msoc_raw = %d bsoc: %d recharge_soc: %d delta_soc: %d\n", msoc_raw, bsoc >> 8, recharge_soc, chip->delta_soc); } else { goto out; } if (!chip->charge_full) goto out; /* * During JEITA conditions, charge_full can happen early. FULL_SOC * and MONOTONIC_SOC needs to be updated to reflect the same. Write * battery SOC to FULL_SOC and write a full value to MONOTONIC_SOC. * If charge_done is still set, wait for recharging or * discharging to happen. */ rc = fg_sram_write(chip, FULL_SOC_WORD, FULL_SOC_OFFSET, (u8 *)&bsoc, 2, FG_IMA_ATOMIC); if (rc < 0) { pr_err("failed to write full_soc rc=%d\n", rc); if (chip->charge_done) goto out; } rc = fg_sram_write(chip, MONOTONIC_SOC_WORD, MONOTONIC_SOC_OFFSET, full_soc, 2, FG_IMA_ATOMIC); if (rc < 0) { pr_err("failed to write monotonic_soc rc=%d\n", rc); rc = fg_configure_full_soc(chip, bsoc); if (rc < 0) goto out; chip->charge_full = false; fg_dbg(chip, FG_STATUS, "msoc_raw = %d bsoc: %d recharge_soc: %d delta_soc: %d\n", msoc_raw, bsoc >> 8, recharge_soc, chip->delta_soc); } fg_dbg(chip, FG_STATUS, "Set charge_full to true @ soc %d\n", msoc); out: mutex_unlock(&chip->charge_full_lock); return rc; Loading Loading @@ -5126,6 +5138,29 @@ static int fg_gen3_remove(struct platform_device *pdev) return 0; } static void fg_gen3_shutdown(struct platform_device *pdev) { struct fg_chip *chip = dev_get_drvdata(&pdev->dev); int rc, bsoc; if (chip->charge_full) { rc = fg_get_sram_prop(chip, FG_SRAM_BATT_SOC, &bsoc); if (rc < 0) { pr_err("Error in getting BATT_SOC, rc=%d\n", rc); return; } /* We need 2 most significant bytes here */ bsoc = (u32)bsoc >> 16; rc = fg_configure_full_soc(chip, bsoc); if (rc < 0) { pr_err("Error in configuring full_soc, rc=%d\n", rc); return; } } } static const struct of_device_id fg_gen3_match_table[] = { {.compatible = FG_GEN3_DEV_NAME}, {}, Loading @@ -5140,6 +5175,7 @@ static struct platform_driver fg_gen3_driver = { }, .probe = fg_gen3_probe, .remove = fg_gen3_remove, .shutdown = fg_gen3_shutdown, }; static int __init fg_gen3_init(void) Loading