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

Commit 884f2b39 authored by Anirudh Ghayal's avatar Anirudh Ghayal
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 fe0d7052
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -45,6 +45,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;
@@ -71,6 +72,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 {
@@ -195,9 +197,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
@@ -296,7 +296,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;
@@ -307,6 +309,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;
@@ -731,6 +738,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;
@@ -1194,6 +1217,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);
@@ -3525,6 +3552,7 @@ static int qg_alg_init(struct qpnp_qg *chip)
#define ESR_CHG_MIN_IBAT_UA		(-450000)
#define DEFAULT_SLEEP_TIME_SECS		1800 /* 30 mins */
#define DEFAULT_SYS_MIN_VOLT_MV		2800
#define DEFAULT_FAST_CHG_S2_FIFO_LENGTH	1
static int qg_parse_dt(struct qpnp_qg *chip)
{
	int rc = 0;
@@ -3796,6 +3824,19 @@ static int qg_parse_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;
	}

	chip->dt.qg_ext_sense = of_property_read_bool(node, "qcom,qg-ext-sns");

	chip->dt.use_s7_ocv = of_property_read_bool(node, "qcom,qg-use-s7-ocv");