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

Commit 4a9d84bf authored by Shiju Mathew's avatar Shiju Mathew Committed by Jeff Bernard
Browse files

power: bcl_peripheral: Update ibat and vbat formula



Update the formula to calculate ibat and vbat. This
was required since the threshold was trigger by an
offset of 200 mV to 300 mV. Basically improve the
accuracy by 200-300mV. Below is the new calculation.

vbat = (vbat_raw * 39000) * (100 + v_gain * 32 / 128) / 100
vbat_raw = (vbat * 100 / ( 100 + v_gain * 32 / 128 )) / 39000

ibat = (ibat_raw * 39000 + i_offset *  1200) *
	(100 + i_gain * 32 / 128) / 100
ibat_raw = (ibat * 100 / ( 100 + i_gain * 32 / 128 ) -
	 i_offset * 1200) / 39000

Change-Id: I7af772e20de09b9a0767d217c0424be9a75d89c4
Signed-off-by: default avatarShiju Mathew <shijum@codeaurora.org>
parent dd876531
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@
#define BCL_VBAT_TRIP           0x68
#define BCL_IBAT_TRIP           0x69

#define BCL_CONSTANT_NUM        32

#define READ_CONV_FACTOR(_node, _key, _val, _ret, _dest) do { \
		_ret = of_property_read_u32(_node, _key, &_val); \
		if (_ret) { \
@@ -144,7 +146,10 @@ static void convert_vbat_to_adc_val(int *val)
	if (!bcl_perph)
		return;
	perph_data = &bcl_perph->param[BCL_PARAM_VOLTAGE];
	*val = *val / perph_data->scaling_factor;
	*val = (*val * 100 / (100 + perph_data->gain_factor_num
		* BCL_CONSTANT_NUM
		/ perph_data->gain_factor_den))
		/ perph_data->scaling_factor;
	return;
}

@@ -156,8 +161,9 @@ static void convert_adc_to_vbat_val(int *val)
		return;
	perph_data = &bcl_perph->param[BCL_PARAM_VOLTAGE];
	*val = (*val * perph_data->scaling_factor)
		* (1 + perph_data->gain_factor_num
		/ perph_data->gain_factor_den);
		* (100 + perph_data->gain_factor_num
		* BCL_CONSTANT_NUM  / perph_data->gain_factor_den)
		/ 100;
	return;
}

@@ -168,7 +174,11 @@ static void convert_ibat_to_adc_val(int *val)
	if (!bcl_perph)
		return;
	perph_data = &bcl_perph->param[BCL_PARAM_CURRENT];
	*val /= perph_data->scaling_factor;
	*val /= (*val * 100 / (100 + perph_data->gain_factor_num
		* BCL_CONSTANT_NUM / perph_data->offset_factor_den)
		- perph_data->offset_factor_num
		/ perph_data->offset_factor_den)
		/  perph_data->scaling_factor;
	return;
}

@@ -179,10 +189,11 @@ static void convert_adc_to_ibat_val(int *val)
	if (!bcl_perph)
		return;
	perph_data = &bcl_perph->param[BCL_PARAM_CURRENT];
	*val = (*val * perph_data->scaling_factor +
		perph_data->offset_factor_num / perph_data->offset_factor_den)
		* (1 + perph_data->gain_factor_num
		/ perph_data->gain_factor_den);
	*val = (*val * perph_data->scaling_factor
		+ perph_data->offset_factor_num
		/ perph_data->offset_factor_den)
		* (100 + perph_data->gain_factor_num
		* BCL_CONSTANT_NUM / perph_data->offset_factor_den) / 100;
	return;
}