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

Commit ea8cd32a authored by Siddartha Mohanadoss's avatar Siddartha Mohanadoss
Browse files

thermal: qpnp-adc-tm: Add reverse scaling



Add reverse scaling to convert voltage in uV using absolute
calibration to raw ADC code written to set high/low threshold
for a specified BTM channel.

Change-Id: Ic56465df5ab60100cffe4303ff983480b71c0c95
Signed-off-by: default avatarSiddartha Mohanadoss <smohanad@codeaurora.org>
parent bc45092a
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -69,14 +69,16 @@ Required properties:
			  Select from the following strings.
			  "absolute" : Uses the 625mv and 1.25V reference channels.
			  "ratiometric" : Uses the reference Voltage/GND for calibration.
- qcom,scale-function : Scaling fuction used to convert raw ADC code to units specific to
- qcom,scale-function : Reverse scaling fuction used to convert raw ADC code to units specific to
			a given channel.
			Select from the following unsigned int.
			0 : Default scaling to convert raw adc code to voltage.
			1 : Conversion to temperature based on btm parameters.
			2 : Returns result in milli degree's Centigrade.
			3 : Returns current across 0.1 ohm resistor.
			4 : Returns XO thermistor voltage in degree's Centigrade.
			0 : Scaling to convert voltage in uV to raw adc code.
			1 : Scaling to convert decidegC to raw adc code.
			2 : Scaling for converting USB_ID reverse scaling.
			3 : Scaling to convert milldegC to raw ADC code.
			4 : Scaling to convert smb_batt_therm values to raw ADC code.
			5 : Scaling to perform reverse calibration for absolute voltage from uV
			    to raw ADC code.
- qcom,hw-settle-time : Settling period for the channel before ADC read.
			Select from the following unsigned int.
			0 : 0us
@@ -108,8 +110,9 @@ Required properties:
			6 : 64
			7 : 128
			8 : 256
- qcom,btm-channel-number : There are 5 BTM channels. The BTM channel numbers are statically
			    allocated to the corresponding channel node.
- qcom,btm-channel-number : Depending on the PMIC version, a max of upto 8 BTM channels.
			    The BTM channel numbers are statically allocated to the
			    corresponding channel node.
- qcom,adc_tm-vadc : phandle to the corresponding VADC device to read the ADC channels.

Client device example:
+41 −0
Original line number Diff line number Diff line
@@ -1028,6 +1028,47 @@ int32_t qpnp_adc_vbatt_rscaler(struct qpnp_vadc_chip *chip,
}
EXPORT_SYMBOL(qpnp_adc_vbatt_rscaler);

int32_t qpnp_adc_absolute_rthr(struct qpnp_vadc_chip *chip,
		struct qpnp_adc_tm_btm_param *param,
		uint32_t *low_threshold, uint32_t *high_threshold)
{
	struct qpnp_vadc_linear_graph vbatt_param;
	int rc = 0, sign = 0;
	int64_t low_thr = 0, high_thr = 0;

	rc = qpnp_get_vadc_gain_and_offset(chip, &vbatt_param, CALIB_ABSOLUTE);
	if (rc < 0)
		return rc;

	low_thr = (((param->low_thr) - QPNP_ADC_625_UV) * vbatt_param.dy);
	if (low_thr < 0) {
		sign = 1;
		low_thr = -low_thr;
	}
	do_div(low_thr, QPNP_ADC_625_UV);
	if (sign)
		low_thr = -low_thr;
	*low_threshold = low_thr + vbatt_param.adc_gnd;

	sign = 0;
	high_thr = (((param->high_thr) - QPNP_ADC_625_UV) * vbatt_param.dy);
	if (high_thr < 0) {
		sign = 1;
		high_thr = -high_thr;
	}
	do_div(high_thr, QPNP_ADC_625_UV);
	if (sign)
		high_thr = -high_thr;
	*high_threshold = high_thr + vbatt_param.adc_gnd;

	pr_debug("high_volt:%d, low_volt:%d\n", param->high_thr,
				param->low_thr);
	pr_debug("adc_code_high:%x, adc_code_low:%x\n", *high_threshold,
				*low_threshold);
	return 0;
}
EXPORT_SYMBOL(qpnp_adc_absolute_rthr);

int32_t qpnp_adc_btm_scaler(struct qpnp_vadc_chip *chip,
		struct qpnp_adc_tm_btm_param *param,
		uint32_t *low_threshold, uint32_t *high_threshold)
+1 −0
Original line number Diff line number Diff line
@@ -283,6 +283,7 @@ static struct qpnp_adc_tm_reverse_scale_fn adc_tm_rscale_fn[] = {
	[SCALE_RBATT_THERM] = {qpnp_adc_btm_scaler},
	[SCALE_R_USB_ID] = {qpnp_adc_usb_scaler},
	[SCALE_RPMIC_THERM] = {qpnp_adc_scale_millidegc_pmic_voltage_thr},
	[SCALE_R_ABSOLUTE] = {qpnp_adc_absolute_rthr},
};

static int32_t qpnp_adc_tm_read_reg(struct qpnp_adc_tm_chip *chip,
+21 −0
Original line number Diff line number Diff line
@@ -265,6 +265,7 @@ enum qpnp_adc_tm_rscale_fn_type {
	SCALE_R_USB_ID,
	SCALE_RPMIC_THERM,
	SCALE_R_SMB_BATT_THERM,
	SCALE_R_ABSOLUTE,
	SCALE_RSCALE_NONE,
};

@@ -1381,6 +1382,22 @@ int32_t qpnp_adc_usb_scaler(struct qpnp_vadc_chip *dev,
int32_t qpnp_adc_vbatt_rscaler(struct qpnp_vadc_chip *dev,
		struct qpnp_adc_tm_btm_param *param,
		uint32_t *low_threshold, uint32_t *high_threshold);
/**
 * qpnp_adc_absolute_rthr() - Performs reverse calibration on the low/high
 *		voltage threshold values passed by the client.
 *		The function applies absolute calibration on the
 *		voltage values.
 * @dev:	Structure device for qpnp vadc
 * @param:	The input parameters that contain the low/high voltage
 *		threshold values.
 * @low_threshold: The low threshold value that needs to be updated with
 *		the above calibrated voltage value.
 * @high_threshold: The low threshold value that needs to be updated with
 *		the above calibrated voltage value.
 */
int32_t qpnp_adc_absolute_rthr(struct qpnp_vadc_chip *dev,
		struct qpnp_adc_tm_btm_param *param,
		uint32_t *low_threshold, uint32_t *high_threshold);
/**
 * qpnp_vadc_iadc_sync_request() - Performs Voltage ADC read and
 *		locks the peripheral. When performing simultaneous
@@ -1506,6 +1523,10 @@ static inline int32_t qpnp_adc_vbatt_rscaler(struct qpnp_vadc_chip *dev,
		struct qpnp_adc_tm_btm_param *param,
		uint32_t *low_threshold, uint32_t *high_threshold)
{ return -ENXIO; }
static inline int32_t qpnp_adc_absolute_rthr(struct qpnp_vadc_chip *dev,
		struct qpnp_adc_tm_btm_param *param,
		uint32_t *low_threshold, uint32_t *high_threshold)
{ return -ENXIO; }
static inline int32_t qpnp_adc_btm_scaler(struct qpnp_vadc_chip *dev,
		struct qpnp_adc_tm_btm_param *param,
		uint32_t *low_threshold, uint32_t *high_threshold)