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

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

power: qpnp-fg: fix issues with iterm configuration



For high values of termination current, the calculation from microamp
values to adc raw values can overflow, causing the fuel gauge driver to
set unrealistic values. Also, the device tree property for this
termination current was named incorrectly in the bindings documentation.

Fix these two issues in order for correct iterm configuration.

CRs-Fixed: 771380
Change-Id: Ib9be3b92e44eedeaad0fda36a79bc8f8b787ea15
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent defce213
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ 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
- qcom,fg-iterm-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
+5 −5
Original line number Diff line number Diff line
@@ -1977,20 +1977,20 @@ static int update_irq_volt_empty(struct fg_chip *chip)
			settings[FG_MEM_IRQ_VOLT_EMPTY].offset, 0);
}

#define CURRENT_UA_TO_ADC_RAW(cur_ua)	\
			(cur_ua * LSB_16B_DENMTR / LSB_16B_NUMRTR)
#define MICROUNITS_TO_ADC_RAW(units)	\
			div64_s64(units * 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;
	s64 current_ma = -settings[FG_MEM_TERM_CURRENT].value;

	converted_current_raw = (u16)CURRENT_UA_TO_ADC_RAW(current_ma * 1000);
	converted_current_raw = (s16)MICROUNITS_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",
		pr_info("current = %lld, 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);