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

Commit cad80cfb authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: qpnp-fg: configure fg termination current



The fuel gauge has a separate termination current from the charger.
This fuel gauge termination current controls when the fuel gauge will
report 100%, while the charger termination current controls when it will
stop charging.

Provide a device tree parameter in order to separately control this
property.

Change-Id: Ide262cd7f4af5c198ec2d55b45d107d6db12fbba
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent e79508d1
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -50,6 +50,13 @@ Parent node optional properties:
					the Rbias needs to be controlled by
					software. If this is not set, it will
					be controlled by hardware (default).
- qcom,fg-current-ma:			Battery current at which the fuel gauge
					will issue end of charge if the charger
					is configured to use the fuel gauge
					ADCs for end of charge detection. This
					property is in milliamps and should be
					positive (e.g. 100mA to terminate at
					-100mA).

qcom,fg-soc node required properties:
- reg : offset and length of the PMIC peripheral register map.
+23 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ enum fg_mem_setting_index {
	FG_MEM_RESUME_SOC,
	FG_MEM_BCL_LM_THRESHOLD,
	FG_MEM_BCL_MH_THRESHOLD,
	FG_MEM_TERM_CURRENT,
	FG_MEM_SETTING_MAX,
};

@@ -149,6 +150,7 @@ static struct fg_mem_setting settings[FG_MEM_SETTING_MAX] = {
	SETTING(RESUME_SOC,      0x45C,   1,      0),
	SETTING(BCL_LM_THRESHOLD, 0x47C,   2,      50),
	SETTING(BCL_MH_THRESHOLD, 0x47C,   3,      752),
	SETTING(TERM_CURRENT,	 0x40C,   2,      250),
};

#define DATA(_idx, _address, _offset, _length,  _value)	\
@@ -1920,6 +1922,25 @@ static void update_bcl_thresholds(struct fg_chip *chip)
			data[lm_offset], data[mh_offset]);
}

#define CURRENT_UA_TO_ADC_RAW(cur_ua)	\
			(cur_ua * LSB_16B_DENMTR / LSB_16B_NUMRTR)
static int update_iterm(struct fg_chip *chip)
{
	u8 data[2];
	u16 converted_current_raw;
	int current_ma = -settings[FG_MEM_TERM_CURRENT].value;

	converted_current_raw = (u16)CURRENT_UA_TO_ADC_RAW(current_ma * 1000);
	data[0] = cpu_to_le16(converted_current_raw) & 0xFF;
	data[1] = cpu_to_le16(converted_current_raw) >> 8;

	if (fg_debug_mask & FG_STATUS)
		pr_info("current = %d, converted_raw = %04x, data = %02x %02x\n",
			current_ma, converted_current_raw, data[0], data[1]);
	return fg_mem_write(chip, data, settings[FG_MEM_TERM_CURRENT].address,
				2, settings[FG_MEM_TERM_CURRENT].offset, 0);
}

static int fg_of_init(struct fg_chip *chip)
{
	int rc = 0, sense_type, len = 0;
@@ -1933,6 +1954,7 @@ static int fg_of_init(struct fg_chip *chip)
		rc, 1);
	OF_READ_SETTING(FG_MEM_BCL_MH_THRESHOLD, "bcl-mh-threshold-ma",
		rc, 1);
	OF_READ_SETTING(FG_MEM_TERM_CURRENT, "fg-iterm-ma", rc, 1);
	data = of_get_property(chip->spmi->dev.of_node,
			"qcom,thermal-coefficients", &len);
	if (data && len == THERMAL_COEFF_N_BYTES) {
@@ -2559,6 +2581,7 @@ static int fg_hw_init(struct fg_chip *chip)
	u8 resume_soc;
	int rc = 0;

	update_iterm(chip);
	update_bcl_thresholds(chip);
	rc = fg_set_auto_recharge(chip);
	if (rc) {