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

Commit 76f88c58 authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: qpnp-bms: disable sw_cc_thresh interrupt after it fires



Currently in the BMS driver, when the software coulomb counter threshold
is reached, only a soc recalculation is scheduled in the irq handler.
This can cause issues where the BMS hardware fires another sw_cc_thresh
irq because the coulomb counter is still over threshold.

Instead, disable the sw_cc_thresh irq when it is handled and renable it
after adjusting the software coulomb counter threshold registers.

Change-Id: I70791fdae1835c8d24b7c045831d22fe86e83fdb
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent df7598c4
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -2268,6 +2268,8 @@ static void configure_soc_wakeup(struct qpnp_bms_chip *chip,
	qpnp_write_wrapper(chip, (u8 *)&ocv_raw,
			chip->base + BMS1_OCV_THR0, 2);

	enable_bms_irq(&chip->ocv_thr_irq);
	enable_bms_irq(&chip->sw_cc_thr_irq);
	pr_debug("current sw_cc_raw = 0x%llx, current ocv = 0x%hx\n",
			current_shdw_cc_raw, (uint16_t)current_ocv_raw);
	pr_debug("target_cc_uah = %lld, raw64 = 0x%llx, raw 36 = 0x%llx, ocv_raw = 0x%hx\n",
@@ -2399,9 +2401,13 @@ static int calculate_state_of_charge(struct qpnp_bms_chip *chip,
	 * If the battery is full, configure the cc threshold so the system
	 * wakes up after SoC changes
	 */
	if (is_battery_full(chip))
	if (is_battery_full(chip)) {
		configure_soc_wakeup(chip, &params,
				batt_temp, bound_soc(new_calculated_soc - 1));
	} else {
		disable_bms_irq(&chip->ocv_thr_irq);
		disable_bms_irq(&chip->sw_cc_thr_irq);
	}
done_calculating:
	mutex_lock(&chip->last_soc_mutex);
	previous_soc = chip->calculated_soc;
@@ -3243,8 +3249,6 @@ static void battery_status_check(struct qpnp_bms_chip *chip)

		if (status == POWER_SUPPLY_STATUS_FULL) {
			pr_debug("battery full\n");
			enable_bms_irq(&chip->ocv_thr_irq);
			enable_bms_irq(&chip->sw_cc_thr_irq);
			recalculate_soc(chip);
		} else if (chip->battery_status
				== POWER_SUPPLY_STATUS_FULL) {
@@ -3543,6 +3547,7 @@ static irqreturn_t bms_sw_cc_thr_irq_handler(int irq, void *_chip)
	struct qpnp_bms_chip *chip = _chip;

	pr_debug("sw_cc_thr irq triggered\n");
	disable_bms_irq(&chip->sw_cc_thr_irq);
	bms_stay_awake(&chip->soc_wake_source);
	schedule_work(&chip->recalc_work);
	return IRQ_HANDLED;