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

Commit 6f849716 authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-fg-gen4: Support booting without a battery



There are some requirements to boot without a battery but only
with a strong charger connected for factory testing. Add support
for this by detecting battery missing condition early in the
driver probe and handling it.

While at it, add power_supply_put() for bms psy so that the
ref count for that power supply is decremented correctly.

Change-Id: If33e300874fd0f64dee6ae98ee05ae32ba14930d
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent 51ac4386
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1273,6 +1273,9 @@ static int fg_dma_init(struct fg_dev *fg)

int fg_memif_init(struct fg_dev *fg)
{
	if (fg->battery_missing)
		return 0;

	if (fg->use_dma)
		return fg_dma_init(fg);

+3 −3
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ int fg_get_sram_prop(struct fg_dev *fg, enum fg_sram_param_id id,
		return -EINVAL;

	if (fg->battery_missing)
		return -ENODATA;
		return 0;

	rc = fg_sram_read(fg, fg->sp[id].addr_word, fg->sp[id].addr_byte,
		buf, fg->sp[id].len, FG_IMA_DEFAULT);
@@ -515,7 +515,7 @@ int fg_sram_write(struct fg_dev *fg, u16 address, u8 offset,
		return -ENXIO;

	if (fg->battery_missing)
		return -ENODATA;
		return 0;

	if (!fg_sram_address_valid(fg, address, len))
		return -EFAULT;
@@ -598,7 +598,7 @@ int fg_sram_read(struct fg_dev *fg, u16 address, u8 offset,
		return -ENXIO;

	if (fg->battery_missing)
		return -ENODATA;
		return 0;

	if (!fg_sram_address_valid(fg, address, len))
		return -EFAULT;
+30 −1
Original line number Diff line number Diff line
@@ -2967,6 +2967,11 @@ static void status_change_work(struct work_struct *work)
	int rc, batt_soc, batt_temp;
	bool input_present, qnovo_en;

	if (fg->battery_missing) {
		pm_relax(fg->dev);
		return;
	}

	if (!chip->pl_disable_votable)
		chip->pl_disable_votable = find_votable("PL_DISABLE");

@@ -3093,6 +3098,13 @@ static int fg_sram_dump_sysfs(const char *val, const struct kernel_param *kp)

	chip = power_supply_get_drvdata(bms_psy);
	fg = &chip->fg;

	power_supply_put(bms_psy);
	if (fg->battery_missing) {
		pr_warn("Battery is missing\n");
		return 0;
	}

	if (fg_sram_dump)
		schedule_delayed_work(&fg->sram_dump_work,
				msecs_to_jiffies(fg_sram_dump_period_ms));
@@ -3135,6 +3147,7 @@ static int fg_restart_sysfs(const char *val, const struct kernel_param *kp)

	chip = power_supply_get_drvdata(bms_psy);
	fg = &chip->fg;
	power_supply_put(bms_psy);
	rc = fg_restart(fg, SOC_READY_WAIT_TIME_MS);
	if (rc < 0) {
		pr_err("Error in restarting FG, rc=%d\n", rc);
@@ -3175,6 +3188,8 @@ static int fg_esr_fast_cal_sysfs(const char *val, const struct kernel_param *kp)
	}

	chip = power_supply_get_drvdata(bms_psy);
	power_supply_put(bms_psy);

	if (!chip)
		return -ENODEV;

@@ -3613,6 +3628,19 @@ static int fg_gen4_hw_init(struct fg_gen4_chip *chip)
	int rc;
	u8 buf[4], val, mask;

	rc = fg_read(fg, ADC_RR_INT_RT_STS(fg), &val, 1);
	if (rc < 0) {
		pr_err("failed to read addr=0x%04x, rc=%d\n",
			ADC_RR_INT_RT_STS(fg), rc);
		return rc;
	}
	fg->battery_missing = (val & ADC_RR_BT_MISS_BIT);

	if (fg->battery_missing) {
		pr_warn("Not initializing FG because of battery missing\n");
		return 0;
	}

	fg_encode(fg->sp, FG_SRAM_CUTOFF_VOLT, chip->dt.cutoff_volt_mv, buf);
	rc = fg_sram_write(fg, fg->sp[FG_SRAM_CUTOFF_VOLT].addr_word,
			fg->sp[FG_SRAM_CUTOFF_VOLT].addr_byte, buf,
@@ -4554,6 +4582,7 @@ static int fg_gen4_probe(struct platform_device *pdev)
	}

	device_init_wakeup(fg->dev, true);
	if (!fg->battery_missing)
		schedule_delayed_work(&fg->profile_load_work, 0);

	pr_debug("FG GEN4 driver probed successfully\n");