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

Commit 2e6b1e59 authored by Fenglin Wu's avatar Fenglin Wu Committed by Gerrit - the friendly Code Review server
Browse files

power: smb1360: Add a DT property to configure recharge SOC threshold



Add a device tree property to configure the auto-recharge SOC threshold.
This implements a SOC based resume charging strategy, device will
recharge after system SOC drops to the configured threshold.

Change-Id: I4165c119269e131cce66a1fb9d09908f13bb47f4
Signed-off-by: default avatarFenglin Wu <fenglinw@codeaurora.org>
parent 012018f2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ Optional Properties:
- qcom,otg-batt-curr-limit	This property defines the current threshold draw
				from battery when device working at OTG mode.
				The possible values are: 350, 550, 950, 1500mA.
- qcom,fg-auto-recharge-soc	This property defines the auto recharging SOC threshold.

Example:
	i2c@f9967000 {
@@ -135,6 +136,7 @@ Example:
			qcom,recharge-thresh-mv = <100>;
			qcom,fg-soc-max = <85>;
			qcom,fg-soc-min = <15>;
			qcom,fg-auto-recharge-soc = <99>;
			qcom,thermal-mitigation = <1500 700 300 0>;

			qcom,otg-batt-curr-limit = <950>;
+36 −1
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@
#define CFG_AUTO_RECHG_DIS_BIT		BIT(2)
#define CFG_CHG_INHIBIT_EN_BIT		BIT(0)

#define CFG_CHG_FUNC_CTRL_REG		0x08
#define CHG_RECHG_THRESH_FG_SRC_BIT	BIT(1)

#define CFG_STAT_CTRL_REG		0x09
#define CHG_STAT_IRQ_ONLY_BIT		BIT(4)
#define CHG_TEMP_CHG_ERR_BLINK_BIT	BIT(3)
@@ -202,6 +205,7 @@
#define CC_TO_SOC_COEFF			0xBA
#define NOMINAL_CAPACITY_REG		0xBC
#define ACTUAL_CAPACITY_REG		0xBE
#define FG_AUTO_RECHARGE_SOC		0xD2
#define FG_SYS_CUTOFF_V_REG		0xD3
#define FG_CC_TO_CV_V_REG		0xD5
#define FG_ITERM_REG			0xD9
@@ -288,6 +292,7 @@ struct smb1360_chip {
	int				fg_ibatt_standby_ma;
	int				fg_thermistor_c1_coeff;
	int				fg_cc_to_cv_mv;
	int				fg_auto_recharge_soc;

	/* status tracking */
	bool				usb_present;
@@ -2533,7 +2538,8 @@ static int smb1360_fg_config(struct smb1360_chip *chip)
		|| chip->fg_iterm_ma != -EINVAL
		|| chip->fg_ibatt_standby_ma != -EINVAL
		|| chip->fg_thermistor_c1_coeff != -EINVAL
		|| chip->fg_cc_to_cv_mv != -EINVAL) {
		|| chip->fg_cc_to_cv_mv != -EINVAL
		|| chip->fg_auto_recharge_soc != -EINVAL) {

		rc = smb1360_enable_fg_access(chip);
		if (rc) {
@@ -2663,6 +2669,30 @@ static int smb1360_fg_config(struct smb1360_chip *chip)
				goto disable_fg;
			}
		}

		/* Update SoC based resume charging threshold */
		if (chip->fg_auto_recharge_soc != -EINVAL) {
			rc = smb1360_masked_write(chip, CFG_CHG_FUNC_CTRL_REG,
						CHG_RECHG_THRESH_FG_SRC_BIT,
						CHG_RECHG_THRESH_FG_SRC_BIT);
			if (rc) {
				dev_err(chip->dev, "Couldn't write to CFG_CHG_FUNC_CTRL_REG rc=%d\n",
									rc);
				goto disable_fg;
			}

			reg = DIV_ROUND_UP(chip->fg_auto_recharge_soc *
							MAX_8_BITS, 100);
			pr_debug("fg_auto_recharge_soc=%d reg=%x\n",
					chip->fg_auto_recharge_soc, reg);
			rc = smb1360_write(chip, FG_AUTO_RECHARGE_SOC, reg);
			if (rc) {
				dev_err(chip->dev, "Couldn't write to FG_AUTO_RECHARGE_SOC rc=%d\n",
									rc);
				goto disable_fg;
			}
		}

disable_fg:
		/* disable FG access */
		smb1360_disable_fg_access(chip);
@@ -3248,6 +3278,11 @@ static int smb_parse_dt(struct smb1360_chip *chip)
	if (rc < 0)
		chip->otg_batt_curr_limit = -EINVAL;

	rc = of_property_read_u32(node, "qcom,fg-auto-recharge-soc",
					&chip->fg_auto_recharge_soc);
	if (rc < 0)
		chip->fg_auto_recharge_soc = -EINVAL;

	return 0;
}