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

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

hwmon: qpnp-adc: Update VADC property



Update VADC property to obtain the code for the full scale
voltage instead of the number of bits for the ADC. The
full scale code is more useful for scaling code to voltage.
Update the property as an optional property and use default
full scale code of 0x4000 for 1.875V.

Change-Id: I81b88ac2205f9e0753353230aa71c73711c378da
Signed-off-by: default avatarSiddartha Mohanadoss <smohanad@codeaurora.org>
parent 9c9a0530
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ Required properties:
		"high-thr-en-set" for high threshold interrupts and
		"high-thr-en-set" for high threshold interrupts and
		"low-thr-en-set" for low threshold interrupts. High and low threshold
		"low-thr-en-set" for low threshold interrupts. High and low threshold
		interrupts are to be enabled if VADC_USR needs to support recurring measurement.
		interrupts are to be enabled if VADC_USR needs to support recurring measurement.
- qcom,adc-bit-resolution : Bit resolution of the ADC.
- qcom,adc-vdd-reference : Voltage reference used by the ADC.
- qcom,adc-vdd-reference : Voltage reference used by the ADC.


Channel nodes
Channel nodes
@@ -46,6 +45,7 @@ Optional properties:
		    0 : The calibration values used for measurement are from a timer.
		    0 : The calibration values used for measurement are from a timer.
		    1 : Forces a fresh measurement for calibration values at the same time
		    1 : Forces a fresh measurement for calibration values at the same time
			measurement is taken.
			measurement is taken.
- qcom,adc-full-scale-code: Full scale code with offset removed.


Client required property:
Client required property:
- qcom,<consumer name>-vadc : The phandle to the corresponding vadc device.
- qcom,<consumer name>-vadc : The phandle to the corresponding vadc device.
+20 −20
Original line number Original line Diff line number Diff line
@@ -757,14 +757,14 @@ int32_t qpnp_adc_scale_pmic_therm(struct qpnp_vadc_chip *vadc,
		return -EINVAL;
		return -EINVAL;


	if (adc_properties->adc_hc) {
	if (adc_properties->adc_hc) {
		/* (ADC code * vref_vadc (1.875V)) / 0x4000 */
		/* (ADC code * vref_vadc (1.875V)) / scale_code */
		if (adc_code > QPNP_VADC_HC_MAX_CODE)
		if (adc_code > QPNP_VADC_HC_MAX_CODE)
			adc_code = 0;
			adc_code = 0;
		pmic_voltage = (int64_t) adc_code;
		pmic_voltage = (int64_t) adc_code;
		pmic_voltage *= (int64_t) (adc_properties->adc_vdd_reference
		pmic_voltage *= (int64_t) (adc_properties->adc_vdd_reference
							* 1000);
							* 1000);
		pmic_voltage = div64_s64(pmic_voltage,
		pmic_voltage = div64_s64(pmic_voltage,
					QPNP_VADC_HC_VREF_CODE);
					adc_properties->full_scale_code);
	} else {
	} else {
		if (!chan_properties->adc_graph[CALIB_ABSOLUTE].dy)
		if (!chan_properties->adc_graph[CALIB_ABSOLUTE].dy)
			return -EINVAL;
			return -EINVAL;
@@ -804,9 +804,9 @@ int32_t qpnp_adc_scale_millidegc_pmic_voltage_thr(struct qpnp_vadc_chip *chip,
	high_output = (param->high_temp + KELVINMIL_DEGMIL) * 2;
	high_output = (param->high_temp + KELVINMIL_DEGMIL) * 2;


	if (param->adc_tm_hc) {
	if (param->adc_tm_hc) {
		low_output *= QPNP_VADC_HC_VREF_CODE;
		low_output *= param->full_scale_code;
		do_div(low_output, (QPNP_VADC_HC_VDD_REFERENCE_MV * 1000));
		do_div(low_output, (QPNP_VADC_HC_VDD_REFERENCE_MV * 1000));
		high_output *= QPNP_VADC_HC_VREF_CODE;
		high_output *= param->full_scale_code;
		do_div(high_output, (QPNP_VADC_HC_VDD_REFERENCE_MV * 1000));
		do_div(high_output, (QPNP_VADC_HC_VDD_REFERENCE_MV * 1000));
	} else {
	} else {
		rc = qpnp_get_vadc_gain_and_offset(chip, &btm_param,
		rc = qpnp_get_vadc_gain_and_offset(chip, &btm_param,
@@ -869,14 +869,14 @@ int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *chip,
		return -EINVAL;
		return -EINVAL;


	if (adc_properties->adc_hc) {
	if (adc_properties->adc_hc) {
		/* (ADC code * vref_vadc (1.875V) * 1000) / (0x4000 * 1000) */
		/* (code * vref_vadc (1.875V) * 1000) / (scale_code * 1000) */
		if (adc_code > QPNP_VADC_HC_MAX_CODE)
		if (adc_code > QPNP_VADC_HC_MAX_CODE)
			adc_code = 0;
			adc_code = 0;
		xo_thm_voltage = (int64_t) adc_code;
		xo_thm_voltage = (int64_t) adc_code;
		xo_thm_voltage *= (int64_t) (adc_properties->adc_vdd_reference
		xo_thm_voltage *= (int64_t) (adc_properties->adc_vdd_reference
							* 1000);
							* 1000);
		xo_thm_voltage = div64_s64(xo_thm_voltage,
		xo_thm_voltage = div64_s64(xo_thm_voltage,
					QPNP_VADC_HC_VREF_CODE * 1000);
				adc_properties->full_scale_code * 1000);
		qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb_1875_vref,
		qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb_1875_vref,
			ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
			ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
			xo_thm_voltage, &adc_chan_result->physical);
			xo_thm_voltage, &adc_chan_result->physical);
@@ -1068,14 +1068,14 @@ int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *chip,
		return -EINVAL;
		return -EINVAL;


	if (adc_properties->adc_hc) {
	if (adc_properties->adc_hc) {
		/* (ADC code * vref_vadc (1.875V) * 1000) / (0x4000 * 1000) */
		/* (code * vref_vadc (1.875V) * 1000) / (scale code * 1000) */
		if (adc_code > QPNP_VADC_HC_MAX_CODE)
		if (adc_code > QPNP_VADC_HC_MAX_CODE)
			adc_code = 0;
			adc_code = 0;
		therm_voltage = (int64_t) adc_code;
		therm_voltage = (int64_t) adc_code;
		therm_voltage *= (int64_t) (adc_properties->adc_vdd_reference
		therm_voltage *= (int64_t) (adc_properties->adc_vdd_reference
							* 1000);
							* 1000);
		therm_voltage = div64_s64(therm_voltage,
		therm_voltage = div64_s64(therm_voltage,
					(QPNP_VADC_HC_VREF_CODE * 1000));
				(adc_properties->full_scale_code * 1000));


		qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb_1875_vref,
		qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb_1875_vref,
			ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
			ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
@@ -1105,13 +1105,13 @@ int32_t qpnp_adc_tm_scale_voltage_therm_pu2(struct qpnp_vadc_chip *chip,
	int negative_offset = 0;
	int negative_offset = 0;


	if (adc_properties->adc_hc) {
	if (adc_properties->adc_hc) {
		/* (ADC code * vref_vadc (1.875V)) / 0x4000 */
		/* (ADC code * vref_vadc (1.875V)) / full_scale_code */
		if (reg > QPNP_VADC_HC_MAX_CODE)
		if (reg > QPNP_VADC_HC_MAX_CODE)
			reg = 0;
			reg = 0;
		adc_voltage = (int64_t) reg;
		adc_voltage = (int64_t) reg;
		adc_voltage *= QPNP_VADC_HC_VDD_REFERENCE_MV;
		adc_voltage *= QPNP_VADC_HC_VDD_REFERENCE_MV;
		adc_voltage = div64_s64(adc_voltage,
		adc_voltage = div64_s64(adc_voltage,
					QPNP_VADC_HC_VREF_CODE);
				adc_properties->full_scale_code);
		qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb_1875_vref,
		qpnp_adc_map_voltage_temp(adcmap_100k_104ef_104fb_1875_vref,
			ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
			ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
			adc_voltage, result);
			adc_voltage, result);
@@ -1151,7 +1151,7 @@ int32_t qpnp_adc_tm_scale_therm_voltage_pu2(struct qpnp_vadc_chip *chip,
			param->low_thr_temp, &param->low_thr_voltage);
			param->low_thr_temp, &param->low_thr_voltage);
		if (rc)
		if (rc)
			return rc;
			return rc;
		param->low_thr_voltage *= QPNP_VADC_HC_VREF_CODE;
		param->low_thr_voltage *= adc_properties->full_scale_code;
		do_div(param->low_thr_voltage, QPNP_VADC_HC_VDD_REFERENCE_MV);
		do_div(param->low_thr_voltage, QPNP_VADC_HC_VDD_REFERENCE_MV);


		rc = qpnp_adc_map_temp_voltage(
		rc = qpnp_adc_map_temp_voltage(
@@ -1160,7 +1160,7 @@ int32_t qpnp_adc_tm_scale_therm_voltage_pu2(struct qpnp_vadc_chip *chip,
			param->high_thr_temp, &param->high_thr_voltage);
			param->high_thr_temp, &param->high_thr_voltage);
		if (rc)
		if (rc)
			return rc;
			return rc;
		param->high_thr_voltage *= QPNP_VADC_HC_VREF_CODE;
		param->high_thr_voltage *= adc_properties->full_scale_code;
		do_div(param->high_thr_voltage, QPNP_VADC_HC_VDD_REFERENCE_MV);
		do_div(param->high_thr_voltage, QPNP_VADC_HC_VDD_REFERENCE_MV);
	} else {
	} else {
		qpnp_get_vadc_gain_and_offset(chip, &param1, CALIB_RATIOMETRIC);
		qpnp_get_vadc_gain_and_offset(chip, &param1, CALIB_RATIOMETRIC);
@@ -1241,13 +1241,13 @@ int32_t qpnp_adc_scale_default(struct qpnp_vadc_chip *vadc,
		return -EINVAL;
		return -EINVAL;


	if (adc_properties->adc_hc) {
	if (adc_properties->adc_hc) {
		/* (ADC code * vref_vadc (1.875V)) / 0x4000 */
		/* (ADC code * vref_vadc (1.875V)) / full_scale_code */
		if (adc_code > QPNP_VADC_HC_MAX_CODE)
		if (adc_code > QPNP_VADC_HC_MAX_CODE)
			adc_code = 0;
			adc_code = 0;
		scale_voltage = (int64_t) adc_code;
		scale_voltage = (int64_t) adc_code;
		scale_voltage *= (adc_properties->adc_vdd_reference * 1000);
		scale_voltage *= (adc_properties->adc_vdd_reference * 1000);
		scale_voltage = div64_s64(scale_voltage,
		scale_voltage = div64_s64(scale_voltage,
						QPNP_VADC_HC_VREF_CODE);
				adc_properties->full_scale_code);
	} else {
	} else {
		qpnp_adc_scale_with_calib_param(adc_code, adc_properties,
		qpnp_adc_scale_with_calib_param(adc_code, adc_properties,
					chan_properties, &scale_voltage);
					chan_properties, &scale_voltage);
@@ -1305,13 +1305,13 @@ int32_t qpnp_adc_absolute_rthr(struct qpnp_vadc_chip *chip,
	if (param->adc_tm_hc) {
	if (param->adc_tm_hc) {
		low_thr = (param->low_thr/param->gain_den);
		low_thr = (param->low_thr/param->gain_den);
		low_thr *= param->gain_num;
		low_thr *= param->gain_num;
		low_thr *= QPNP_VADC_HC_VREF_CODE;
		low_thr *= param->full_scale_code;
		do_div(low_thr, (QPNP_VADC_HC_VDD_REFERENCE_MV * 1000));
		do_div(low_thr, (QPNP_VADC_HC_VDD_REFERENCE_MV * 1000));
		*low_threshold = low_thr;
		*low_threshold = low_thr;


		high_thr = (param->high_thr/param->gain_den);
		high_thr = (param->high_thr/param->gain_den);
		high_thr *= param->gain_num;
		high_thr *= param->gain_num;
		high_thr *= QPNP_VADC_HC_VREF_CODE;
		high_thr *= param->full_scale_code;
		do_div(high_thr, (QPNP_VADC_HC_VDD_REFERENCE_MV * 1000));
		do_div(high_thr, (QPNP_VADC_HC_VDD_REFERENCE_MV * 1000));
		*high_threshold = high_thr;
		*high_threshold = high_thr;
	} else {
	} else {
@@ -2027,11 +2027,11 @@ int32_t qpnp_adc_get_devicetree_data(struct platform_device *pdev,
		pr_err("Invalid adc vdd reference property\n");
		pr_err("Invalid adc vdd reference property\n");
		return -EINVAL;
		return -EINVAL;
	}
	}
	rc = of_property_read_u32(node, "qcom,adc-bit-resolution",
	rc = of_property_read_u32(node, "qcom,adc-full-scale-code",
			&adc_prop->bitresolution);
			&adc_prop->full_scale_code);
	if (rc) {
	if (rc) {
		pr_err("Invalid adc bit resolution property\n");
		pr_debug("Use default value of 0x4000 for full scale\n");
		return -EINVAL;
		adc_prop->full_scale_code = QPNP_VADC_HC_VREF_CODE;
	}
	}
	adc_qpnp->adc_prop = adc_prop;
	adc_qpnp->adc_prop = adc_prop;


+1 −0
Original line number Original line Diff line number Diff line
@@ -1730,6 +1730,7 @@ int32_t qpnp_adc_tm_channel_measure(struct qpnp_adc_tm_chip *chip,
	param->gain_num = qpnp_vadc_amux_scaling_ratio[amux_prescaling].num;
	param->gain_num = qpnp_vadc_amux_scaling_ratio[amux_prescaling].num;
	param->gain_den = qpnp_vadc_amux_scaling_ratio[amux_prescaling].den;
	param->gain_den = qpnp_vadc_amux_scaling_ratio[amux_prescaling].den;
	param->adc_tm_hc = chip->adc_tm_hc;
	param->adc_tm_hc = chip->adc_tm_hc;
	param->full_scale_code = chip->adc->adc_prop->full_scale_code;
	chip->adc->amux_prop->amux_channel = channel;
	chip->adc->amux_prop->amux_channel = channel;
	chip->adc->amux_prop->decimation =
	chip->adc->amux_prop->decimation =
			chip->adc->adc_channels[dt_index].adc_decimation;
			chip->adc->adc_channels[dt_index].adc_decimation;
+3 −2
Original line number Original line Diff line number Diff line
@@ -968,6 +968,7 @@ enum qpnp_state_request {
 * @PMIC_THERM inputs the units in millidegC.
 * @PMIC_THERM inputs the units in millidegC.
 */
 */
struct qpnp_adc_tm_btm_param {
struct qpnp_adc_tm_btm_param {
	uint32_t				full_scale_code;
	int32_t					high_temp;
	int32_t					high_temp;
	int32_t					low_temp;
	int32_t					low_temp;
	int32_t					high_thr;
	int32_t					high_thr;
@@ -1026,13 +1027,13 @@ struct qpnp_vadc_scaling_ratio {
/**
/**
 * struct qpnp_adc_properties - Represent the ADC properties.
 * struct qpnp_adc_properties - Represent the ADC properties.
 * @adc_reference: Reference voltage for QPNP ADC.
 * @adc_reference: Reference voltage for QPNP ADC.
 * @bitresolution: ADC bit resolution for QPNP ADC.
 * @full_scale_code: Full scale value with intrinsic offset removed.
 * @biploar: Polarity for QPNP ADC.
 * @biploar: Polarity for QPNP ADC.
 * @adc_hc: Represents using HC variant of the ADC controller.
 * @adc_hc: Represents using HC variant of the ADC controller.
 */
 */
struct qpnp_adc_properties {
struct qpnp_adc_properties {
	uint32_t	adc_vdd_reference;
	uint32_t	adc_vdd_reference;
	uint32_t	bitresolution;
	uint32_t	full_scale_code;
	bool		bipolar;
	bool		bipolar;
	bool		adc_hc;
	bool		adc_hc;
};
};