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

Commit dc55b6a4 authored by Jishnu Prakash's avatar Jishnu Prakash
Browse files

drivers: hwmon: Add support for bat_therm on adc_tm for QM215



Add reverse scaling function for bat_therm for QM215
which uses 2800mAh battery.

Change-Id: I9bf4ce9aa451d9c363adfd3b4b78093fa1634495
Signed-off-by: default avatarJishnu Prakash <jprakash@codeaurora.org>
parent 2453552b
Loading
Loading
Loading
Loading
+71 −0
Original line number Diff line number Diff line
@@ -1263,6 +1263,19 @@ int32_t qpnp_adc_batt_therm_qrd(struct qpnp_vadc_chip *chip,
		qpnp_adc_map_voltage_temp(adcmap_batt_therm_qrd,
			ARRAY_SIZE(adcmap_batt_therm_qrd),
			batt_thm_voltage, &adc_chan_result->physical);
	} else {

		qpnp_adc_scale_with_calib_param(adc_code,
			adc_properties, chan_properties, &batt_thm_voltage);

		adc_chan_result->measurement = batt_thm_voltage;

		return qpnp_adc_map_voltage_temp(
				adcmap_batt_therm_qrd,
				ARRAY_SIZE(adcmap_batt_therm_qrd),
				batt_thm_voltage,
				&adc_chan_result->physical);

	}
	return 0;
}
@@ -2152,6 +2165,64 @@ int32_t qpnp_adc_qrd_skut1_btm_scaler(struct qpnp_vadc_chip *chip,
}
EXPORT_SYMBOL(qpnp_adc_qrd_skut1_btm_scaler);

int32_t qpnp_adc_qrd_215_btm_scaler(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 btm_param;
	int64_t low_output = 0, high_output = 0;
	int rc = 0;

	if (param->adc_tm_hc) {
		pr_debug("Update scaling for VADC_TM_HC\n");
		return -EINVAL;
	}

	qpnp_get_vadc_gain_and_offset(chip, &btm_param, CALIB_RATIOMETRIC);

	pr_debug("warm_temp:%d and cool_temp:%d\n", param->high_temp,
				param->low_temp);
	rc = qpnp_adc_map_voltage_temp(
		adcmap_batt_therm_qrd,
		ARRAY_SIZE(adcmap_batt_therm_qrd),
		(param->low_temp),
		&low_output);
	if (rc) {
		pr_debug("low_temp mapping failed with %d\n", rc);
		return rc;
	}

	pr_debug("low_output:%lld\n", low_output);
	low_output *= btm_param.dy;
	low_output = div64_s64(low_output, btm_param.adc_vref);
	low_output += btm_param.adc_gnd;

	rc = qpnp_adc_map_voltage_temp(
		adcmap_batt_therm_qrd,
		ARRAY_SIZE(adcmap_batt_therm_qrd),
		(param->high_temp),
		&high_output);
	if (rc) {
		pr_debug("high temp mapping failed with %d\n", rc);
		return rc;
	}

	pr_debug("high_output:%lld\n", high_output);
	high_output *= btm_param.dy;
	high_output = div64_s64(high_output, btm_param.adc_vref);
	high_output += btm_param.adc_gnd;

	/* btm low temperature correspondes to high voltage threshold */
	*low_threshold = high_output;
	/* btm high temperature correspondes to low voltage threshold */
	*high_threshold = low_output;

	pr_debug("high_volt:%d, low_volt:%d\n", *high_threshold,
				*low_threshold);
	return 0;
}
EXPORT_SYMBOL(qpnp_adc_qrd_215_btm_scaler);

int32_t qpnp_adc_smb_btm_rscaler(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
@@ -361,6 +361,7 @@ static struct qpnp_adc_tm_reverse_scale_fn adc_tm_rscale_fn[] = {
	[SCALE_R_ABSOLUTE] = {qpnp_adc_absolute_rthr},
	[SCALE_QRD_SKUH_RBATT_THERM] = {qpnp_adc_qrd_skuh_btm_scaler},
	[SCALE_QRD_SKUT1_RBATT_THERM] = {qpnp_adc_qrd_skut1_btm_scaler},
	[SCALE_QRD_215_RBATT_THERM] = {qpnp_adc_qrd_215_btm_scaler},
};

static int32_t qpnp_adc_tm_read_reg(struct qpnp_adc_tm_chip *chip,
+21 −0
Original line number Diff line number Diff line
@@ -455,6 +455,7 @@ enum qpnp_adc_tm_rscale_fn_type {
	SCALE_R_ABSOLUTE,
	SCALE_QRD_SKUH_RBATT_THERM,
	SCALE_QRD_SKUT1_RBATT_THERM,
	SCALE_QRD_215_RBATT_THERM,
	SCALE_RSCALE_NONE,
};

@@ -1887,6 +1888,22 @@ int32_t qpnp_adc_qrd_skuh_btm_scaler(struct qpnp_vadc_chip *dev,
int32_t qpnp_adc_qrd_skut1_btm_scaler(struct qpnp_vadc_chip *dev,
		struct qpnp_adc_tm_btm_param *param,
		uint32_t *low_threshold, uint32_t *high_threshold);
/**
 * qpnp_adc_qrd_215_btm_scaler() - Performs reverse calibration on the
 *		low/high temperature threshold values passed by the client.
 *		The function maps the temperature to voltage and applies
 *		ratiometric calibration on the voltage values for SKUT1 board.
 * @dev:	Structure device for qpnp vadc
 * @param:	The input parameters that contain the low/high temperature
 *		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_qrd_215_btm_scaler(struct qpnp_vadc_chip *dev,
		struct qpnp_adc_tm_btm_param *param,
		uint32_t *low_threshold, uint32_t *high_threshold);
/**
 * qpnp_adc_tm_scale_therm_voltage_pu2() - Performs reverse calibration
 *		and convert given temperature to voltage on supported
@@ -2279,6 +2296,10 @@ static inline int32_t qpnp_adc_qrd_skut1_btm_scaler(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_qrd_215_btm_scaler(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_scale_millidegc_pmic_voltage_thr(
		struct qpnp_vadc_chip *dev,
		struct qpnp_adc_tm_btm_param *param,