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

Commit 4aad4b58 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "iio: spmi-vadc: Add option to specify scale-fn-type in devicetree"

parents 2461e66b 89c07b9b
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * Copyright (c) 2012-2016,2021, The Linux Foundation. All rights reserved.
 */

#include <linux/bitops.h>
@@ -560,19 +552,19 @@ static const struct vadc_channels vadc_chans[] = {
	VADC_CHAN_NO_SCALE(SPARE1_03, 1)
	VADC_CHAN_NO_SCALE(USB_ID_MV, 1)
	VADC_CHAN_VOLT(VCOIN, 1, SCALE_DEFAULT)
	VADC_CHAN_NO_SCALE(VBAT_SNS, 1)
	VADC_CHAN_VOLT(VBAT_SNS, 1, SCALE_DEFAULT)
	VADC_CHAN_VOLT(VSYS, 1, SCALE_DEFAULT)
	VADC_CHAN_TEMP(DIE_TEMP, 0, SCALE_PMIC_THERM)
	VADC_CHAN_VOLT(REF_625MV, 0, SCALE_DEFAULT)
	VADC_CHAN_VOLT(REF_1250MV, 0, SCALE_DEFAULT)
	VADC_CHAN_NO_SCALE(CHG_TEMP, 0)
	VADC_CHAN_NO_SCALE(SPARE1, 0)
	VADC_CHAN_VOLT(SPARE1, 0, SCALE_DEFAULT)
	VADC_CHAN_TEMP(SPARE2, 0, SCALE_PMI_CHG_TEMP)
	VADC_CHAN_VOLT(GND_REF, 0, SCALE_DEFAULT)
	VADC_CHAN_VOLT(VDD_VADC, 0, SCALE_DEFAULT)

	VADC_CHAN_NO_SCALE(P_MUX1_1_1, 0)
	VADC_CHAN_NO_SCALE(P_MUX2_1_1, 0)
	VADC_CHAN_TEMP(P_MUX2_1_1, 0, SCALE_THERM_100K_PULLUP)
	VADC_CHAN_NO_SCALE(P_MUX3_1_1, 0)
	VADC_CHAN_NO_SCALE(P_MUX4_1_1, 0)
	VADC_CHAN_NO_SCALE(P_MUX5_1_1, 0)
@@ -606,18 +598,18 @@ static const struct vadc_channels vadc_chans[] = {
	VADC_CHAN_NO_SCALE(P_MUX16_1_3, 1)

	VADC_CHAN_NO_SCALE(LR_MUX1_BAT_THERM, 0)
	VADC_CHAN_NO_SCALE(LR_MUX2_BAT_ID, 0)
	VADC_CHAN_NO_SCALE(LR_MUX3_XO_THERM, 0)
	VADC_CHAN_VOLT(LR_MUX2_BAT_ID, 0, SCALE_DEFAULT)
	VADC_CHAN_TEMP(LR_MUX3_XO_THERM, 0, SCALE_THERM_100K_PULLUP)
	VADC_CHAN_NO_SCALE(LR_MUX4_AMUX_THM1, 0)
	VADC_CHAN_NO_SCALE(LR_MUX5_AMUX_THM2, 0)
	VADC_CHAN_NO_SCALE(LR_MUX6_AMUX_THM3, 0)
	VADC_CHAN_NO_SCALE(LR_MUX7_HW_ID, 0)
	VADC_CHAN_TEMP(LR_MUX7_HW_ID, 0, SCALE_THERM_100K_PULLUP)
	VADC_CHAN_NO_SCALE(LR_MUX8_AMUX_THM4, 0)
	VADC_CHAN_NO_SCALE(LR_MUX9_AMUX_THM5, 0)
	VADC_CHAN_NO_SCALE(LR_MUX10_USB_ID, 0)
	VADC_CHAN_NO_SCALE(AMUX_PU1, 0)
	VADC_CHAN_NO_SCALE(AMUX_PU2, 0)
	VADC_CHAN_NO_SCALE(LR_MUX3_BUF_XO_THERM, 0)
	VADC_CHAN_TEMP(LR_MUX3_BUF_XO_THERM, 0, SCALE_THERM_100K_PULLUP)

	VADC_CHAN_NO_SCALE(LR_MUX1_PU1_BAT_THERM, 0)
	VADC_CHAN_NO_SCALE(LR_MUX2_PU1_BAT_ID, 0)
@@ -735,6 +727,12 @@ static int vadc_get_dt_channel_data(struct device *dev,
	else
		prop->calibration = VADC_CALIB_ABSOLUTE;

	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;

	dev_dbg(dev, "%02x name %s\n", chan, name);

	return 0;
@@ -747,6 +745,7 @@ static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)
	struct vadc_channel_prop prop;
	struct device_node *child;
	unsigned int index = 0;
	bool scale_fn_type_from_dt = false;
	int ret;

	vadc->nchannels = of_get_available_child_count(node);
@@ -772,14 +771,24 @@ static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)
			return ret;
		}

		prop.scale_fn_type = vadc_chans[prop.channel].scale_fn_type;
		if (prop.scale_fn_type == -EINVAL) {
			prop.scale_fn_type =
				vadc_chans[prop.channel].scale_fn_type;
		} else {
			scale_fn_type_from_dt = true;
		}

		vadc->chan_props[index] = prop;

		vadc_chan = &vadc_chans[prop.channel];

		iio_chan->channel = prop.channel;
		iio_chan->datasheet_name = vadc_chan->datasheet_name;
		if (!scale_fn_type_from_dt)
			iio_chan->info_mask_separate = vadc_chan->info_mask;
		else
			iio_chan->info_mask_separate =
			  vadc_chan->info_mask | BIT(IIO_CHAN_INFO_PROCESSED);
		iio_chan->type = vadc_chan->type;
		iio_chan->indexed = 1;
		iio_chan->address = index++;
+86 −0
Original line number Diff line number Diff line
@@ -759,6 +759,61 @@ static const struct vadc_map_pt adcmap7_100k[] = {
	{ 2420, 130048 }
};

/* Voltage to temperature */
static const struct vadc_map_pt adcmap_batt_therm_qrd_215[] = {
	{1575,  -200},
	{1549,  -180},
	{1522,  -160},
	{1493,  -140},
	{1463,  -120},
	{1431,  -100},
	{1398,  -80},
	{1364,  -60},
	{1329,  -40},
	{1294,  -20},
	{1258,  0},
	{1222,  20},
	{1187,  40},
	{1151,  60},
	{1116,  80},
	{1082,  100},
	{1049,  120},
	{1016,  140},
	{985,   160},
	{955,   180},
	{926,   200},
	{899,   220},
	{873,   240},
	{849,   260},
	{825,   280},
	{804,   300},
	{783,   320},
	{764,   340},
	{746,   360},
	{729,   380},
	{714,   400},
	{699,   420},
	{686,   440},
	{673,   460},
	{662,   480},
	{651,   500},
	{641,   520},
	{632,   540},
	{623,   560},
	{615,   580},
	{608,   600},
	{601,   620},
	{595,   640},
	{589,   660},
	{583,   680},
	{578,   700},
	{574,   720},
	{569,   740},
	{565,   760},
	{562,   780},
	{558,   800}
};

static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
				      u32 tablesize, s32 input, s64 *output)
{
@@ -830,6 +885,10 @@ static int qcom_vadc_scale_volt(const struct vadc_linear_graph *calib_graph,

	voltage = voltage * prescale->den;
	result = div64_s64(voltage, prescale->num);

	if (!absolute)
		result *= 1000;

	*result_uv = result;

	return 0;
@@ -860,6 +919,29 @@ static int qcom_vadc_scale_therm(const struct vadc_linear_graph *calib_graph,
	return 0;
}

static int qcom_vadc_scale_therm_qrd_215(
				const struct vadc_linear_graph *calib_graph,
				const struct vadc_prescale_ratio *prescale,
				bool absolute, u16 adc_code,
				int *result_mdec)
{
	s64 voltage = 0, result = 0;
	int ret;

	qcom_vadc_scale_calib(calib_graph, adc_code, absolute, &voltage);

	ret = qcom_vadc_map_voltage_temp(adcmap_batt_therm_qrd_215,
					 ARRAY_SIZE(adcmap_batt_therm_qrd_215),
					 voltage, &result);
	if (ret)
		return ret;

	*result_mdec = result;

	return 0;
}


static int qcom_vadc_scale_die_temp(const struct vadc_linear_graph *calib_graph,
				    const struct vadc_prescale_ratio *prescale,
				    bool absolute,
@@ -1307,6 +1389,10 @@ int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
		return qcom_vadc_scale_therm(calib_graph, prescale,
					     absolute, adc_code,
					     result);
	case SCALE_BATT_THERM_QRD_215:
		return qcom_vadc_scale_therm_qrd_215(calib_graph, prescale,
					     absolute, adc_code,
					     result);
	case SCALE_PMIC_THERM:
		return qcom_vadc_scale_die_temp(calib_graph, prescale,
						absolute, adc_code,
+1 −0
Original line number Diff line number Diff line
@@ -198,6 +198,7 @@ enum vadc_scale_fn_type {
	SCALE_HW_CALIB_PM2250_S3_DIE_TEMP,
	SCALE_HW_CALIB_THERM_100K_PU_PM7,
	SCALE_HW_CALIB_PMIC_THERM_PM7,
	SCALE_BATT_THERM_QRD_215,
	SCALE_HW_CALIB_MAX,
};