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

Commit 30e3afea authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-fg-gen3: Use votable for controlling delta_bsoc irq



Instead of using a flag to retain the interrupt enabled status
of delta_bsoc interrupt, switch it to use a votable instead. This
improves the readability of code by not worrying about the flag.

While at it, fix cleaning up the resources in some error paths
during driver probe.

Change-Id: I2c17a9d90c7b549435caa75da81f4c4779ea3344
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent 664cdd33
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@
#define PROFILE_LOAD		"fg_profile_load"
#define DELTA_SOC		"fg_delta_soc"

/* Delta BSOC votable reasons */
#define DELTA_BSOC_IRQ_VOTER	"fg_delta_bsoc_irq"

#define DEBUG_PRINT_BUFFER_SIZE		64
/* 3 byte address + 1 space character */
#define ADDR_LEN			4
@@ -330,6 +333,7 @@ struct fg_chip {
	struct fg_memif		*sram;
	struct fg_irq_info	*irqs;
	struct votable		*awake_votable;
	struct votable		*delta_bsoc_irq_en_votable;
	struct fg_sram_param	*sp;
	struct fg_alg_flag	*alg_flags;
	int			*debug_mask;
@@ -370,7 +374,6 @@ struct fg_chip {
	bool			esr_fcc_ctrl_en;
	bool			soc_reporting_ready;
	bool			esr_flt_cold_temp_en;
	bool			bsoc_delta_irq_en;
	bool			slope_limit_en;
	struct completion	soc_update;
	struct completion	soc_ready;
+35 −17
Original line number Diff line number Diff line
@@ -1054,6 +1054,25 @@ static void fg_notify_charger(struct fg_chip *chip)
	fg_dbg(chip, FG_STATUS, "Notified charger on float voltage and FCC\n");
}

static int fg_delta_bsoc_irq_en_cb(struct votable *votable, void *data,
					int enable, const char *client)
{
	struct fg_chip *chip = data;

	if (!chip->irqs[BSOC_DELTA_IRQ].irq)
		return 0;

	if (enable) {
		enable_irq(chip->irqs[BSOC_DELTA_IRQ].irq);
		enable_irq_wake(chip->irqs[BSOC_DELTA_IRQ].irq);
	} else {
		disable_irq_wake(chip->irqs[BSOC_DELTA_IRQ].irq);
		disable_irq(chip->irqs[BSOC_DELTA_IRQ].irq);
	}

	return 0;
}

static int fg_awake_cb(struct votable *votable, void *data, int awake,
			const char *client)
{
@@ -1477,16 +1496,8 @@ static int fg_charge_full_update(struct fg_chip *chip)
		return 0;

	mutex_lock(&chip->charge_full_lock);
	if (!chip->charge_done && chip->bsoc_delta_irq_en) {
		disable_irq_wake(fg_irqs[BSOC_DELTA_IRQ].irq);
		disable_irq_nosync(fg_irqs[BSOC_DELTA_IRQ].irq);
		chip->bsoc_delta_irq_en = false;
	} else if (chip->charge_done && !chip->bsoc_delta_irq_en) {
		enable_irq(fg_irqs[BSOC_DELTA_IRQ].irq);
		enable_irq_wake(fg_irqs[BSOC_DELTA_IRQ].irq);
		chip->bsoc_delta_irq_en = true;
	}

	vote(chip->delta_bsoc_irq_en_votable, DELTA_BSOC_IRQ_VOTER,
		chip->charge_done, 0);
	rc = power_supply_get_property(chip->batt_psy, POWER_SUPPLY_PROP_HEALTH,
		&prop);
	if (rc < 0) {
@@ -4022,6 +4033,9 @@ static void fg_cleanup(struct fg_chip *chip)
	if (chip->awake_votable)
		destroy_votable(chip->awake_votable);

	if (chip->delta_bsoc_irq_en_votable)
		destroy_votable(chip->delta_bsoc_irq_en_votable);

	if (chip->batt_id_chan)
		iio_channel_release(chip->batt_id_chan);

@@ -4063,7 +4077,15 @@ static int fg_gen3_probe(struct platform_device *pdev)
					chip);
	if (IS_ERR(chip->awake_votable)) {
		rc = PTR_ERR(chip->awake_votable);
		return rc;
		goto exit;
	}

	chip->delta_bsoc_irq_en_votable = create_votable("FG_DELTA_BSOC_IRQ",
						VOTE_SET_ANY,
						fg_delta_bsoc_irq_en_cb, chip);
	if (IS_ERR(chip->delta_bsoc_irq_en_votable)) {
		rc = PTR_ERR(chip->delta_bsoc_irq_en_votable);
		goto exit;
	}

	rc = fg_parse_dt(chip);
@@ -4090,7 +4112,7 @@ static int fg_gen3_probe(struct platform_device *pdev)
	rc = fg_get_batt_id(chip);
	if (rc < 0) {
		pr_err("Error in getting battery id, rc:%d\n", rc);
		return rc;
		goto exit;
	}

	rc = fg_get_batt_profile(chip);
@@ -4148,11 +4170,7 @@ static int fg_gen3_probe(struct platform_device *pdev)
		disable_irq_nosync(fg_irqs[SOC_UPDATE_IRQ].irq);

	/* Keep BSOC_DELTA_IRQ irq disabled until we require it */
	if (fg_irqs[BSOC_DELTA_IRQ].irq) {
		disable_irq_wake(fg_irqs[BSOC_DELTA_IRQ].irq);
		disable_irq_nosync(fg_irqs[BSOC_DELTA_IRQ].irq);
		chip->bsoc_delta_irq_en = false;
	}
	rerun_election(chip->delta_bsoc_irq_en_votable);

	rc = fg_debugfs_create(chip);
	if (rc < 0) {