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

Commit f1af45a9 authored by Rama Krishna Phani A's avatar Rama Krishna Phani A Committed by Gerrit - the friendly Code Review server
Browse files

hwmon: qpnp-adc-voltage: Add version check for VADC thermistor channels



pa-therm, xo_therm channels are used for reading the temperature.
Calibration type for above thermistor channels has to be absolute
for PM8950 1.0 and ratiometric for PM8950 2.0. Add version check to
detect the PMIC used and update the calibration type accordingly.

Change-Id: Iec4ed2ee5895feb91f74051a5ef060a19acb7ec0
Signed-off-by: default avatarRama Krishna Phani A <rphani@codeaurora.org>
parent 6326f417
Loading
Loading
Loading
Loading
+47 −4
Original line number Diff line number Diff line
@@ -673,6 +673,35 @@ static int32_t qpnp_adc_map_temp_voltage(const struct qpnp_vadc_map_pt *pts,
	return 0;
}

static int64_t qpnp_adc_scale_absolute_calib(int32_t adc_code,
		const struct qpnp_adc_properties *adc_properties,
		const struct qpnp_vadc_chan_properties *chan_properties)
{
	int64_t adc_voltage = 0;
	bool negative_offset = 0;

	if (!chan_properties || !chan_properties->offset_gain_numerator ||
		!chan_properties->offset_gain_denominator || !adc_properties)
		return -EINVAL;

	adc_voltage = (adc_code -
		chan_properties->adc_graph[CALIB_ABSOLUTE].adc_gnd)
		* chan_properties->adc_graph[chan_properties->calib_type].dx;
	if (adc_voltage < 0) {
		negative_offset = 1;
		adc_voltage = -adc_voltage;
	}
	do_div(adc_voltage,
		chan_properties->adc_graph[CALIB_ABSOLUTE].dy);

	if (negative_offset)
		adc_voltage = -adc_voltage;
	adc_voltage +=
		chan_properties->adc_graph[CALIB_ABSOLUTE].dx;

	return adc_voltage;
}

static int64_t qpnp_adc_scale_ratiometric_calib(int32_t adc_code,
		const struct qpnp_adc_properties *adc_properties,
		const struct qpnp_vadc_chan_properties *chan_properties)
@@ -813,9 +842,14 @@ int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *chip,
		|| !adc_chan_result)
		return -EINVAL;

	if (chan_properties->calib_type == CALIB_ABSOLUTE) {
		xo_thm = qpnp_adc_scale_absolute_calib(adc_code,
			adc_properties, chan_properties);
		do_div(xo_thm , 1000);
	} else {
		xo_thm = qpnp_adc_scale_ratiometric_calib(adc_code,
			adc_properties, chan_properties);

	}
	qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb,
		ARRAY_SIZE(adcmap_100k_104ef_104fb),
		xo_thm, &adc_chan_result->physical);
@@ -992,9 +1026,14 @@ int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *chip,
{
	int64_t therm_voltage = 0;

	if (chan_properties->calib_type == CALIB_ABSOLUTE) {
		therm_voltage = qpnp_adc_scale_absolute_calib(adc_code,
			adc_properties, chan_properties);
		do_div(therm_voltage , 1000);
	} else {
		therm_voltage = qpnp_adc_scale_ratiometric_calib(adc_code,
			adc_properties, chan_properties);

	}
	qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb,
		ARRAY_SIZE(adcmap_100k_104ef_104fb),
		therm_voltage, &adc_chan_result->physical);
@@ -1690,6 +1729,10 @@ int qpnp_adc_get_revid_version(struct device *dev)
		(revid_data->pmic_type == PM8909_V1P1_TYPE) &&
		(revid_data->pmic_subtype == PM8909_V1P1_SUBTYPE))
			return QPNP_REV_ID_8909_1_1;
	else if ((revid_data->rev4 == PM8950_V1P0_REV4) &&
		(revid_data->pmic_type == PM8950_V1P0_TYPE) &&
		(revid_data->pmic_subtype == PM8950_V1P0_SUBTYPE))
			return QPNP_REV_ID_PM8950_1_0;
	else
		return -EINVAL;
}
+25 −0
Original line number Diff line number Diff line
@@ -659,6 +659,28 @@ static int32_t qpnp_vadc_version_check(struct qpnp_vadc_chip *dev)
	return 0;
}

static int32_t
	qpnp_vadc_channel_post_scaling_calib_check(struct qpnp_vadc_chip *vadc,
								int channel)
{
	int version, rc = 0;

	version = qpnp_adc_get_revid_version(vadc->dev);

	if (version == QPNP_REV_ID_PM8950_1_0) {
		if ((channel == LR_MUX7_HW_ID) ||
			(channel == P_MUX2_1_1) ||
			(channel == LR_MUX3_XO_THERM) ||
			(channel == LR_MUX3_BUF_XO_THERM_BUF)) {
			vadc->adc->amux_prop->chan_prop->calib_type =
								CALIB_ABSOLUTE;
			return rc;
		}
	}

	return -EINVAL;
}

#define QPNP_VBAT_COEFF_1	3000
#define QPNP_VBAT_COEFF_2	45810000
#define QPNP_VBAT_COEFF_3	100000
@@ -1707,6 +1729,9 @@ recalibrate:
		goto fail_unlock;
	}

	if ((qpnp_vadc_channel_post_scaling_calib_check(vadc, channel)) < 0)
		pr_debug("Post scaling calib type not updated\n");

	vadc_scale_fn[scale_type].chan(vadc, result->adc_code,
		vadc->adc->adc_prop, vadc->adc->amux_prop->chan_prop, result);

+1 −0
Original line number Diff line number Diff line
@@ -1098,6 +1098,7 @@ struct qpnp_adc_amux_properties {
#define QPNP_REV_ID_8916_2_0	12
#define QPNP_REV_ID_8909_1_0	13
#define QPNP_REV_ID_8909_1_1	14
#define QPNP_REV_ID_PM8950_1_0	16

/* Public API */
#if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE)				\