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

Commit 4e5c3775 authored by Anirudh Ghayal's avatar Anirudh Ghayal Committed by Gerrit - the friendly Code Review server
Browse files

power: qpnp-qg: Add support for fast-charge config



Add logic to allow re-configuring the FIFO length
based on charging status. This may be required
for fast-charging cases where SOC needs to be
tracked fine-grain.

Change-Id: I3e51dc34cea5c97a7f901d9981f908e35b8b0fb4
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
parent 959a5bc8
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ struct qg_dt {
	int			sleep_s2_fifo_length;
	int			sleep_s2_acc_length;
	int			sleep_s2_acc_intvl_ms;
	int			fast_chg_s2_fifo_length;
	int			ocv_timer_expiry_min;
	int			ocv_tol_threshold_uv;
	int			s3_entry_fifo_length;
@@ -65,6 +66,7 @@ struct qg_dt {
	bool			qg_ext_sense;
	bool			use_s7_ocv;
	bool			qg_sleep_config;
	bool			qg_fast_chg_cfg;
};

struct qg_esr_data {
@@ -190,9 +192,10 @@ enum ocv_type {
};

enum s2_state {
	S2_LOW_VBAT = BIT(0),
	S2_SLEEP = BIT(1),
	S2_DEFAULT = BIT(2),
	S2_FAST_CHARGING = BIT(0),
	S2_LOW_VBAT = BIT(1),
	S2_SLEEP = BIT(2),
	S2_DEFAULT = BIT(3),
};

enum debug_mask {
+42 −1
Original line number Diff line number Diff line
@@ -329,7 +329,9 @@ static int qg_config_s2_state(struct qpnp_qg *chip,
		chip->s2_state_mask &= ~requested_state;

	/* define the priority of the states */
	if (chip->s2_state_mask & S2_LOW_VBAT)
	if (chip->s2_state_mask & S2_FAST_CHARGING)
		state = S2_FAST_CHARGING;
	else if (chip->s2_state_mask & S2_LOW_VBAT)
		state = S2_LOW_VBAT;
	else if (chip->s2_state_mask & S2_SLEEP)
		state = S2_SLEEP;
@@ -340,6 +342,11 @@ static int qg_config_s2_state(struct qpnp_qg *chip,
		return 0;

	switch (state) {
	case S2_FAST_CHARGING:
		fifo_length = chip->dt.fast_chg_s2_fifo_length;
		acc_interval = chip->dt.s2_acc_intvl_ms;
		acc_length = chip->dt.s2_acc_length;
		break;
	case S2_LOW_VBAT:
		fifo_length = chip->dt.s2_vbat_low_fifo_length;
		acc_interval = chip->dt.s2_acc_intvl_ms;
@@ -764,6 +771,22 @@ static int qg_vbat_thresholds_config(struct qpnp_qg *chip)
	return rc;
}

static int qg_fast_charge_config(struct qpnp_qg *chip)
{
	int rc = 0;

	if (!chip->dt.qg_fast_chg_cfg)
		return 0;

	rc = qg_config_s2_state(chip, S2_FAST_CHARGING,
			(chip->charge_status == POWER_SUPPLY_STATUS_CHARGING)
			? true : false, false);
	if (rc < 0)
		pr_err("Failed to exit S2_SLEEP rc=%d\n", rc);

	return rc;
}

static void qg_retrieve_esr_params(struct qpnp_qg *chip)
{
	u32 data = 0;
@@ -1227,6 +1250,10 @@ static irqreturn_t qg_fifo_update_done_handler(int irq, void *data)
	if (rc < 0)
		pr_err("Failed to apply VBAT EMPTY config rc=%d\n", rc);

	rc = qg_fast_charge_config(chip);
	if (rc < 0)
		pr_err("Failed to apply fast-charge config rc=%d\n", rc);

	rc = qg_vbat_low_wa(chip);
	if (rc < 0) {
		pr_err("Failed to apply VBAT LOW WA, rc=%d\n", rc);
@@ -3559,6 +3586,7 @@ static void qg_create_debugfs(struct qpnp_qg *chip)
#define DEFAULT_SLEEP_S2_FIFO_LENGTH	8
#define DEFAULT_SLEEP_S2_ACC_LENGTH	256
#define DEFAULT_SLEEP_S2_ACC_INTVL_MS	200
#define DEFAULT_FAST_CHG_S2_FIFO_LENGTH	1
static int qg_parse_s2_dt(struct qpnp_qg *chip)
{
	int rc;
@@ -3623,6 +3651,19 @@ static int qg_parse_s2_dt(struct qpnp_qg *chip)
			chip->dt.sleep_s2_acc_intvl_ms = temp;
	}

	if (of_property_read_bool(node, "qcom,qg-fast-chg-config")) {

		chip->dt.qg_fast_chg_cfg = true;

		rc = of_property_read_u32(node,
				"qcom,fast-chg-s2-fifo-length", &temp);
		if (rc < 0)
			chip->dt.fast_chg_s2_fifo_length =
					DEFAULT_FAST_CHG_S2_FIFO_LENGTH;
		else
			chip->dt.fast_chg_s2_fifo_length = temp;
	}

	return 0;
}