Skip to content

Commit ca66dca

Browse files
lumagdlezcano
authored andcommitted
thermal: qcom: add support for adc-tm5 PMIC thermal monitor
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 <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e8ffd6c commit ca66dca

File tree

5 files changed

+688
-0
lines changed

5 files changed

+688
-0
lines changed

drivers/iio/adc/qcom-vadc-common.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,28 @@ static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
368368
return 0;
369369
}
370370

371+
static s32 qcom_vadc_map_temp_voltage(const struct vadc_map_pt *pts,
372+
u32 tablesize, int input)
373+
{
374+
u32 i = 0;
375+
376+
/*
377+
* Table must be sorted, find the interval of 'y' which contains value
378+
* 'input' and map it to proper 'x' value
379+
*/
380+
while (i < tablesize && pts[i].y < input)
381+
i++;
382+
383+
if (i == 0)
384+
return pts[0].x;
385+
if (i == tablesize)
386+
return pts[tablesize - 1].x;
387+
388+
/* interpolate linearly */
389+
return fixp_linear_interpolate(pts[i - 1].y, pts[i - 1].x,
390+
pts[i].y, pts[i].x, input);
391+
}
392+
371393
static void qcom_vadc_scale_calib(const struct vadc_linear_graph *calib_graph,
372394
u16 adc_code,
373395
bool absolute,
@@ -463,6 +485,21 @@ static int qcom_vadc_scale_chg_temp(const struct vadc_linear_graph *calib_graph,
463485
return 0;
464486
}
465487

488+
/* convert voltage to ADC code, using 1.875V reference */
489+
static u16 qcom_vadc_scale_voltage_code(s32 voltage,
490+
const struct vadc_prescale_ratio *prescale,
491+
const u32 full_scale_code_volt,
492+
unsigned int factor)
493+
{
494+
s64 volt = voltage;
495+
s64 adc_vdd_ref_mv = 1875; /* reference voltage */
496+
497+
volt *= prescale->num * factor * full_scale_code_volt;
498+
volt = div64_s64(volt, (s64)prescale->den * adc_vdd_ref_mv * 1000);
499+
500+
return volt;
501+
}
502+
466503
static int qcom_vadc_scale_code_voltage_factor(u16 adc_code,
467504
const struct vadc_prescale_ratio *prescale,
468505
const struct adc5_data *data,
@@ -627,6 +664,19 @@ int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
627664
}
628665
EXPORT_SYMBOL(qcom_vadc_scale);
629666

667+
u16 qcom_adc_tm5_temp_volt_scale(unsigned int prescale_ratio,
668+
u32 full_scale_code_volt, int temp)
669+
{
670+
const struct vadc_prescale_ratio *prescale = &adc5_prescale_ratios[prescale_ratio];
671+
s32 voltage;
672+
673+
voltage = qcom_vadc_map_temp_voltage(adcmap_100k_104ef_104fb_1875_vref,
674+
ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
675+
temp);
676+
return qcom_vadc_scale_voltage_code(voltage, prescale, full_scale_code_volt, 1000);
677+
}
678+
EXPORT_SYMBOL(qcom_adc_tm5_temp_volt_scale);
679+
630680
int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype,
631681
unsigned int prescale_ratio,
632682
const struct adc5_data *data,

drivers/thermal/qcom/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ config QCOM_TSENS
1010
Also able to set threshold temperature for both hot and cold and update
1111
when a threshold is reached.
1212

13+
config QCOM_SPMI_ADC_TM5
14+
tristate "Qualcomm SPMI PMIC Thermal Monitor ADC5"
15+
depends on OF && SPMI && IIO
16+
select REGMAP_SPMI
17+
select QCOM_VADC_COMMON
18+
help
19+
This enables the thermal driver for the ADC thermal monitoring
20+
device. It shows up as a thermal zone with multiple trip points.
21+
Thermal client sets threshold temperature for both warm and cool and
22+
gets updated when a threshold is reached.
23+
1324
config QCOM_SPMI_TEMP_ALARM
1425
tristate "Qualcomm SPMI PMIC Temperature Alarm"
1526
depends on OF && SPMI && IIO

drivers/thermal/qcom/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o
33

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

0 commit comments

Comments
 (0)