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

Commit bed8ba95 authored by Chunmei Cai's avatar Chunmei Cai Committed by Ashay Jaiswal
Browse files

power: qpnp-smbcharger: Add support for detecting damaged battery



Detect safety timer expired condition from charger and notify it to FG
through safety_timer_expired property. This can be used for PMi8952 V2.0
and future PMi chips. While at it, rename the safety-timeout irq to
wdog-timeout irq.

CRs-Fixed: 866074
Change-Id: I3a0f1f053a0038349bf5f704cf29eb5b84de2601
Signed-off-by: default avatarChunmei Cai <ccai@codeaurora.org>
parent 1989201a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ end of this file.
			limiting configuration.
- qcom,dc-chgpth:	DC charge path detection and input current
			limiting configuration.
- qcom,chg-misc:	Miscellaneous features such as safety timers
- qcom,chg-misc:	Miscellaneous features such as watchdog timers
			and SYSOK pin control
- qcom,chg-otg:		OTG configuration control.

@@ -86,7 +86,7 @@ Sub node required properties:
						valid threshold.

			qcom,chgr-misc:
			 - safety-timeout-mins:	Charger watchdog timer
			 - wdog-timeout-mins:	Charger watchdog timer
						interrupt.
			 - temp-shutdown:	Triggers when charger goes
						overtemp and causes a shutdown.
@@ -370,7 +370,7 @@ Example:

			interrupt-names =	"power-ok",
						"temp-shutdown",
						"safety-timeout",
						"wdog-timeout",
						"flash-fail",
						"otst2",
						"otst3";
+1 −1
Original line number Diff line number Diff line
@@ -290,7 +290,7 @@

				interrupt-names =	"power-ok",
							"temp-shutdown",
							"safety-timeout",
							"wdog-timeout",
							"flash-fail",
							"otst2",
							"otst3";
+1 −1
Original line number Diff line number Diff line
@@ -301,7 +301,7 @@

				interrupt-names =	"power-ok",
							"temp-shutdown",
							"safety-timeout",
							"wdog-timeout",
							"flash-fail",
							"otst2",
							"otst3";
+22 −7
Original line number Diff line number Diff line
@@ -196,7 +196,7 @@ struct smbchg_chip {
	struct mutex			taper_irq_lock;
	int				recharge_irq;
	int				fastchg_irq;
	int				safety_timeout_irq;
	int				wdog_timeout_irq;
	int				power_ok_irq;
	int				dcin_uv_irq;
	int				usbin_uv_irq;
@@ -5101,11 +5101,26 @@ static irqreturn_t vbat_low_handler(int irq, void *_chip)
	return IRQ_HANDLED;
}

#define CHG_COMP_SFT_BIT	BIT(3)
static irqreturn_t chg_error_handler(int irq, void *_chip)
{
	struct smbchg_chip *chip = _chip;
	int rc = 0;
	u8 reg;

	pr_smb(PR_INTERRUPT, "chg-error triggered\n");

	rc = smbchg_read(chip, &reg, chip->chgr_base + RT_STS, 1);
	if (rc < 0) {
		dev_err(chip->dev, "Unable to read RT_STS rc = %d\n", rc);
	} else {
		pr_smb(PR_INTERRUPT, "triggered: 0x%02x\n", reg);
		if (reg & CHG_COMP_SFT_BIT)
			set_property_on_fg(chip,
					POWER_SUPPLY_PROP_SAFETY_TIMER_EXPIRED,
					1);
	}

	smbchg_parallel_usb_check_ok(chip);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);
@@ -5179,13 +5194,13 @@ static irqreturn_t recharge_handler(int irq, void *_chip)
	return IRQ_HANDLED;
}

static irqreturn_t safety_timeout_handler(int irq, void *_chip)
static irqreturn_t wdog_timeout_handler(int irq, void *_chip)
{
	struct smbchg_chip *chip = _chip;
	u8 reg = 0;

	smbchg_read(chip, &reg, chip->misc_base + RT_STS, 1);
	pr_warn_ratelimited("safety timeout rt_stat = 0x%02x\n", reg);
	pr_warn_ratelimited("wdog timeout rt_stat = 0x%02x\n", reg);
	if (chip->psy_registered)
		power_supply_changed(&chip->batt_psy);
	smbchg_charging_status_change(chip);
@@ -6492,11 +6507,11 @@ static int smbchg_request_irqs(struct smbchg_chip *chip)
			REQUEST_IRQ(chip, spmi_resource, chip->chg_hot_irq,
				"temp-shutdown", chg_hot_handler, flags, rc);
			REQUEST_IRQ(chip, spmi_resource,
				chip->safety_timeout_irq,
				"safety-timeout",
				safety_timeout_handler, flags, rc);
				chip->wdog_timeout_irq,
				"wdog-timeout",
				wdog_timeout_handler, flags, rc);
			enable_irq_wake(chip->chg_hot_irq);
			enable_irq_wake(chip->safety_timeout_irq);
			enable_irq_wake(chip->wdog_timeout_irq);
			break;
		case SMBCHG_OTG_SUBTYPE:
			break;