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

Commit 833a52b5 authored by Fenglin Wu's avatar Fenglin Wu
Browse files

iio: spmi-adc5: Add option to specify scale-fun-type in devicetree



There are chances that some signals would share the same ADC channel
but have different scale functions, such as the SMB1398 TEMP and SMB1390
TEMP use the same ADC channel but have a different voltage to
temperature calculation. Add an option to specify scale-fun-type in
devicetree to handle such kind of requirement.

Change-Id: I04ed618829f460164643c63943993ff2c522852b
Signed-off-by: default avatarFenglin Wu <fenglinw@codeaurora.org>
parent 78327398
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -849,6 +849,11 @@ static int adc_get_dt_channel_data(struct device *dev,
		prop->avg_samples = VADC_DEF_AVG_SAMPLES;
	}

	prop->scale_fn_type = -EINVAL;
	ret = of_property_read_u32(node, "qcom,scale-fn-type", &value);
	if (!ret && value < SCALE_HW_CALIB_MAX)
		prop->scale_fn_type = value;

	prop->lut_index = VADC_DEF_LUT_INDEX;

	ret = of_property_read_u32(node, "qcom,lut-index", &value);
@@ -942,8 +947,10 @@ static int adc_get_dt_data(struct adc_chip *adc, struct device_node *node)
			return ret;
		}

		if (prop.scale_fn_type == -EINVAL)
			prop.scale_fn_type =
				data->adc_chans[prop.channel].scale_fn_type;

		adc->chan_props[index] = prop;

		adc_chan = &data->adc_chans[prop.channel];
+32 −0
Original line number Diff line number Diff line
@@ -925,6 +925,35 @@ static int qcom_vadc_scale_hw_smb_temp(
	return 0;
}

static int qcom_vadc_scale_hw_smb1398_temp(
				const struct vadc_prescale_ratio *prescale,
				const struct adc_data *data,
				u16 adc_code, int *result_mdec)
{
	s64 voltage = 0, adc_vdd_ref_mv = 1875;
	u64 temp;

	if (adc_code > VADC5_MAX_CODE)
		adc_code = 0;

	/* (ADC code * vref_vadc (1.875V)) / full_scale_code */
	voltage = (s64) adc_code * adc_vdd_ref_mv * 1000;
	voltage = div64_s64(voltage, data->full_scale_code_volt);
	if (voltage > 0) {
		temp = voltage * prescale->den;
		temp *= 100;
		do_div(temp, prescale->num * PMIC5_SMB1398_TEMP_SCALE_FACTOR);
		voltage = temp;
	} else {
		voltage = 0;
	}

	voltage = voltage - PMIC5_SMB1398_TEMP_CONSTANT;
	*result_mdec = voltage;

	return 0;
}

static int qcom_vadc_scale_hw_chg5_temp(
				const struct vadc_prescale_ratio *prescale,
				const struct adc_data *data,
@@ -1043,6 +1072,9 @@ int qcom_vadc_hw_scale(enum vadc_scale_fn_type scaletype,
	case SCALE_HW_CALIB_PM5_SMB_TEMP:
		return qcom_vadc_scale_hw_smb_temp(prescale, data,
						adc_code, result);
	case SCALE_HW_CALIB_PM5_SMB1398_TEMP:
		return qcom_vadc_scale_hw_smb1398_temp(prescale, data,
						adc_code, result);
	default:
		return -EINVAL;
	}
+4 −0
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@
#define PMIC5_CHG_TEMP_SCALE_FACTOR		377500
#define PMIC5_SMB_TEMP_CONSTANT			419400
#define PMIC5_SMB_TEMP_SCALE_FACTOR		356
#define PMIC5_SMB1398_TEMP_SCALE_FACTOR	340
#define PMIC5_SMB1398_TEMP_CONSTANT		268235

#define PMI_CHG_SCALE_1				-138890
#define PMI_CHG_SCALE_2				391750000000LL
@@ -175,6 +177,8 @@ enum vadc_scale_fn_type {
	SCALE_HW_CALIB_BATT_THERM_100K,
	SCALE_HW_CALIB_BATT_THERM_30K,
	SCALE_HW_CALIB_BATT_THERM_400K,
	SCALE_HW_CALIB_PM5_SMB1398_TEMP,
	SCALE_HW_CALIB_MAX,
};

struct adc_data {