Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 83033633 authored by Xiaozhe Shi's avatar Xiaozhe Shi Committed by Nicholas Troast
Browse files

power: qpnp-fg: load the same batt temp after a restart



Currently, when the software rbias feature is enabled, the battery
temperature remains at 25 degrees C for a long time after a fuel gauge
restart. This is because until the next software temperature update
occurs, the default battery temperature in the fuel gauge will be
25 degrees C.

Fix this by writing in the old battery temperature after a restart if
the software rbias control is enabled.

CRs-Fixed: 867716
Change-Id: I6f5f2b125ae53c3ca89b5d4a67890b689e4d74ab
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent 6dba09ce
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -4145,9 +4145,26 @@ static int fg_do_restart(struct fg_chip *chip, bool write_profile)
	int rc;
	int tries = 0;
	u8 reg = 0;
	u8 buf[2];

	if (fg_debug_mask & FG_STATUS)
		pr_info("restarting fuel gauge...\n");

	/*
	 * save the temperature if the sw rbias control is active so that there
	 * is no gap of time when there is no valid temperature read after the
	 * restart
	 */
	if (chip->sw_rbias_ctrl) {
		rc = fg_mem_read(chip, buf,
				fg_data[FG_DATA_BATT_TEMP].address,
				fg_data[FG_DATA_BATT_TEMP].len,
				fg_data[FG_DATA_BATT_TEMP].offset, 0);
		if (rc) {
			pr_err("failed to read batt temp rc=%d\n", rc);
			goto sub_and_fail;
		}
	}
	/*
	 * release the sram access and configure the correct settings
	 * before re-requesting access.
@@ -4275,6 +4292,21 @@ static int fg_do_restart(struct fg_chip *chip, bool write_profile)
		goto fail;
	}

	/* restore the battery temperature reading here */
	if (chip->sw_rbias_ctrl) {
		if (fg_debug_mask & FG_STATUS)
			pr_info("reloaded 0x%02x%02x into batt temp",
					buf[0], buf[1]);
		rc = fg_mem_write(chip, buf,
				fg_data[FG_DATA_BATT_TEMP].address,
				fg_data[FG_DATA_BATT_TEMP].len,
				fg_data[FG_DATA_BATT_TEMP].offset, 0);
		if (rc) {
			pr_err("failed to write batt temp rc=%d\n", rc);
			goto fail;
		}
	}

	if (fg_debug_mask & FG_STATUS)
		pr_info("done!\n");
	return 0;