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

Commit abd9b8be authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy Committed by Gerrit - the friendly Code Review server
Browse files

power: qpnp-fg: update SRAM data when the charging status changes



Currently, FG SRAM parameters are updated once every 30 seconds.
However, there are cases where the user wants to see the SRAM
parameters getting updated as soon as the charging status
changes e.g. from charging to discharging. Update the SRAM
parameters if the status changes and the last update of SRAM
parameters was done 5 seconds before.

While at it, remove the prev_status defined under learning data
as it is not used at all.

CRs-Fixed: 860061
Change-Id: Id5b97a29cf7d67a317d71726a126060852fba913
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent af677bba
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -112,7 +112,6 @@ struct fg_mem_data {
};

struct fg_learning_data {
	int			prev_status;
	int64_t			cc_uah;
	int64_t			learned_cc_uah;
	bool			active;
@@ -431,6 +430,7 @@ struct fg_chip {
	int			nom_cap_uah;
	int			actual_cap_uah;
	int			status;
	int			prev_status;
	int			health;
	enum fg_batt_aging_mode	batt_aging_mode;
	/* capacity learning */
@@ -2886,7 +2886,6 @@ static int fg_cap_learning_check(struct fg_chip *chip)
	}

fail:
	chip->learning_data.prev_status = chip->status;
	mutex_unlock(&chip->learning_data.learning_lock);
	return rc;
}
@@ -2925,6 +2924,7 @@ static void status_change_work(struct work_struct *work)
	struct fg_chip *chip = container_of(work,
				struct fg_chip,
				status_change_work);
	unsigned long current_time = 0;

	if (chip->status == POWER_SUPPLY_STATUS_FULL ||
			chip->status == POWER_SUPPLY_STATUS_CHARGING) {
@@ -2944,6 +2944,18 @@ static void status_change_work(struct work_struct *work)
	}
	fg_cap_learning_check(chip);
	schedule_work(&chip->update_esr_work);
	if (chip->prev_status != chip->status) {
		get_current_time(&current_time);
		/*
		 * When charging status changes, update SRAM parameters if it
		 * was not updated before 5 seconds from now.
		 */
		if (chip->last_sram_update_time + 5 < current_time) {
			cancel_delayed_work(&chip->update_sram_data);
			schedule_delayed_work(&chip->update_sram_data,
				msecs_to_jiffies(0));
		}
	}
}

static int fg_power_set_property(struct power_supply *psy,
@@ -2965,6 +2977,7 @@ static int fg_power_set_property(struct power_supply *psy,
			update_sram_data(chip, &unused);
		break;
	case POWER_SUPPLY_PROP_STATUS:
		chip->prev_status = chip->status;
		chip->status = val->intval;
		schedule_work(&chip->status_change_work);
		break;