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

Commit 416ddbdb authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

qpnp-smb2: add support to configure charge inhibit



Currently charge inhibit feature is enabled by default and the
charge inhibit threshold is not configurable. Add a device tree
parameter "qcom,chg-inhibit-threshold-mv" through which the
charge inhibit threshold can be configured. If the property is
not specified, then charge inhibit feature is kept disabled.

Change-Id: I464d720abc138e8cd9ba8d7f1704cd91f4408bee
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent c15a8e24
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -129,6 +129,15 @@ Charger specific properties:
		happen but the adapter won't be asked to switch to a higher
		voltage point.

- qcom,chg-inhibit-threshold-mv
  Usage:      optional
  Value type: <u32>
  Definition: Charge inhibit threshold in milli-volts. Charging will be
		inhibited when the battery voltage is within this threshold
		from Vfloat at charger insertion. If this is not specified
		then charge inhibit will be disabled by default.
		Allowed values are: 50, 100, 200, 300.

=============================================
Second Level Nodes - SMB2 Charger Peripherals
=============================================
+43 −0
Original line number Diff line number Diff line
@@ -225,6 +225,7 @@ struct smb_dt_props {
	s32	step_cc_delta[STEP_CHARGING_MAX_STEPS];
	struct	device_node *revid_dev_node;
	int	float_option;
	int	chg_inhibit_thr_mv;
	bool	hvdcp_disable;
};

@@ -335,6 +336,14 @@ static int smb2_parse_dt(struct smb2 *chip)
	chip->dt.hvdcp_disable = of_property_read_bool(node,
						"qcom,hvdcp-disable");

	of_property_read_u32(node, "qcom,chg-inhibit-threshold-mv",
				&chip->dt.chg_inhibit_thr_mv);
	if ((chip->dt.chg_inhibit_thr_mv < 0 ||
		chip->dt.chg_inhibit_thr_mv > 300)) {
		pr_err("qcom,chg-inhibit-threshold-mv is incorrect\n");
		return -EINVAL;
	}

	return 0;
}

@@ -1213,6 +1222,40 @@ static int smb2_init_hw(struct smb2 *chip)
		return rc;
	}

	switch (chip->dt.chg_inhibit_thr_mv) {
	case 50:
		rc = smblib_masked_write(chg, CHARGE_INHIBIT_THRESHOLD_CFG_REG,
				CHARGE_INHIBIT_THRESHOLD_MASK,
				CHARGE_INHIBIT_THRESHOLD_50MV);
		break;
	case 100:
		rc = smblib_masked_write(chg, CHARGE_INHIBIT_THRESHOLD_CFG_REG,
				CHARGE_INHIBIT_THRESHOLD_MASK,
				CHARGE_INHIBIT_THRESHOLD_100MV);
		break;
	case 200:
		rc = smblib_masked_write(chg, CHARGE_INHIBIT_THRESHOLD_CFG_REG,
				CHARGE_INHIBIT_THRESHOLD_MASK,
				CHARGE_INHIBIT_THRESHOLD_200MV);
		break;
	case 300:
		rc = smblib_masked_write(chg, CHARGE_INHIBIT_THRESHOLD_CFG_REG,
				CHARGE_INHIBIT_THRESHOLD_MASK,
				CHARGE_INHIBIT_THRESHOLD_300MV);
		break;
	case 0:
		rc = smblib_masked_write(chg, CHGR_CFG2_REG,
				CHARGER_INHIBIT_BIT, 0);
	default:
		break;
	}

	if (rc < 0) {
		dev_err(chg->dev, "Couldn't configure charge inhibit threshold rc=%d\n",
			rc);
		return rc;
	}

	return rc;
}

+4 −0
Original line number Diff line number Diff line
@@ -184,6 +184,10 @@ enum {

#define CHARGE_INHIBIT_THRESHOLD_CFG_REG		(CHGR_BASE + 0x72)
#define CHARGE_INHIBIT_THRESHOLD_MASK			GENMASK(1, 0)
#define CHARGE_INHIBIT_THRESHOLD_50MV			0
#define CHARGE_INHIBIT_THRESHOLD_100MV			1
#define CHARGE_INHIBIT_THRESHOLD_200MV			2
#define CHARGE_INHIBIT_THRESHOLD_300MV			3

#define RECHARGE_THRESHOLD_CFG_REG			(CHGR_BASE + 0x73)
#define RECHARGE_THRESHOLD_MASK				GENMASK(1, 0)