Skip to content

Commit

Permalink
thermal: qcom: add support for adc-tm5 PMIC thermal monitor
Browse files Browse the repository at this point in the history
Add support for Thermal Monitoring part of PMIC5. This part is closely
coupled with ADC, using it's channels directly. ADC-TM support
generating interrupts on ADC value crossing low or high voltage bounds,
which is used to support thermal trip points.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210205000118.493610-3-dmitry.baryshkov@linaro.org
  • Loading branch information
Dmitry Baryshkov authored and Daniel Lezcano committed Feb 15, 2021
1 parent e8ffd6c commit ca66dca
Show file tree
Hide file tree
Showing 5 changed files with 688 additions and 0 deletions.
50 changes: 50 additions & 0 deletions drivers/iio/adc/qcom-vadc-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,28 @@ static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
return 0;
}

static s32 qcom_vadc_map_temp_voltage(const struct vadc_map_pt *pts,
u32 tablesize, int input)
{
u32 i = 0;

/*
* Table must be sorted, find the interval of 'y' which contains value
* 'input' and map it to proper 'x' value
*/
while (i < tablesize && pts[i].y < input)
i++;

if (i == 0)
return pts[0].x;
if (i == tablesize)
return pts[tablesize - 1].x;

/* interpolate linearly */
return fixp_linear_interpolate(pts[i - 1].y, pts[i - 1].x,
pts[i].y, pts[i].x, input);
}

static void qcom_vadc_scale_calib(const struct vadc_linear_graph *calib_graph,
u16 adc_code,
bool absolute,
Expand Down Expand Up @@ -463,6 +485,21 @@ static int qcom_vadc_scale_chg_temp(const struct vadc_linear_graph *calib_graph,
return 0;
}

/* convert voltage to ADC code, using 1.875V reference */
static u16 qcom_vadc_scale_voltage_code(s32 voltage,
const struct vadc_prescale_ratio *prescale,
const u32 full_scale_code_volt,
unsigned int factor)
{
s64 volt = voltage;
s64 adc_vdd_ref_mv = 1875; /* reference voltage */

volt *= prescale->num * factor * full_scale_code_volt;
volt = div64_s64(volt, (s64)prescale->den * adc_vdd_ref_mv * 1000);

return volt;
}

static int qcom_vadc_scale_code_voltage_factor(u16 adc_code,
const struct vadc_prescale_ratio *prescale,
const struct adc5_data *data,
Expand Down Expand Up @@ -627,6 +664,19 @@ int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
}
EXPORT_SYMBOL(qcom_vadc_scale);

u16 qcom_adc_tm5_temp_volt_scale(unsigned int prescale_ratio,
u32 full_scale_code_volt, int temp)
{
const struct vadc_prescale_ratio *prescale = &adc5_prescale_ratios[prescale_ratio];
s32 voltage;

voltage = qcom_vadc_map_temp_voltage(adcmap_100k_104ef_104fb_1875_vref,
ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
temp);
return qcom_vadc_scale_voltage_code(voltage, prescale, full_scale_code_volt, 1000);
}
EXPORT_SYMBOL(qcom_adc_tm5_temp_volt_scale);

int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype,
unsigned int prescale_ratio,
const struct adc5_data *data,
Expand Down
11 changes: 11 additions & 0 deletions drivers/thermal/qcom/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ config QCOM_TSENS
Also able to set threshold temperature for both hot and cold and update
when a threshold is reached.

config QCOM_SPMI_ADC_TM5
tristate "Qualcomm SPMI PMIC Thermal Monitor ADC5"
depends on OF && SPMI && IIO
select REGMAP_SPMI
select QCOM_VADC_COMMON
help
This enables the thermal driver for the ADC thermal monitoring
device. It shows up as a thermal zone with multiple trip points.
Thermal client sets threshold temperature for both warm and cool and
gets updated when a threshold is reached.

config QCOM_SPMI_TEMP_ALARM
tristate "Qualcomm SPMI PMIC Temperature Alarm"
depends on OF && SPMI && IIO
Expand Down
1 change: 1 addition & 0 deletions drivers/thermal/qcom/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o

qcom_tsens-y += tsens.o tsens-v2.o tsens-v1.o tsens-v0_1.o \
tsens-8960.o
obj-$(CONFIG_QCOM_SPMI_ADC_TM5) += qcom-spmi-adc-tm5.o
obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.o
Loading

0 comments on commit ca66dca

Please sign in to comment.