thermal: adc-tm: Add support for PMIC7 ADC_TM
Add support for PMIC7 ADC_TM peripheral in ADC_TM common driver files. Add main ADC_TM driver file for PMIC7. As register offsets and SW flows have changed significantly for ADC_TM due to ADC architecture change, this new driver is required for ADC_TM on PMIC7. Change-Id: I9211552317955c503b7287876e11cd161c37f706 Signed-off-by: Jishnu Prakash <jprakash@codeaurora.org>
This commit is contained in:
parent
6bb0d0ab97
commit
bfdf14029c
7 changed files with 1233 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
|||
obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o
|
||||
qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o tsens-8974.o tsens-8960.o tsens-v2.o
|
||||
obj-$(CONFIG_QTI_ADC_TM) += adc-tm.o adc-tm-common.o adc-tm5.o
|
||||
obj-$(CONFIG_QTI_ADC_TM) += adc-tm.o adc-tm-common.o adc-tm5.o adc-tm7.o
|
||||
obj-$(CONFIG_QTI_VIRTUAL_SENSOR) += qti_virtual_sensor.o
|
||||
obj-$(CONFIG_QTI_QMI_SENSOR) += thermal_sensor_service_v01.o qmi_sensors.o
|
||||
obj-$(CONFIG_QTI_BCL_PMIC5) += bcl_pmic5.o
|
||||
|
|
|
@ -47,6 +47,181 @@ static const struct adc_tm_map_pt adcmap_100k_104ef_104fb_1875_vref[] = {
|
|||
{ 46000, 125000 },
|
||||
};
|
||||
|
||||
/*
|
||||
* Resistance to temperature table for NTCG104EF104 thermistor with
|
||||
* 100k pull-up.
|
||||
*/
|
||||
static const struct adc_tm_map_pt adcmap_100k_adc7[] = {
|
||||
{ 4250657, -40960 },
|
||||
{ 3962085, -39936 },
|
||||
{ 3694875, -38912 },
|
||||
{ 3447322, -37888 },
|
||||
{ 3217867, -36864 },
|
||||
{ 3005082, -35840 },
|
||||
{ 2807660, -34816 },
|
||||
{ 2624405, -33792 },
|
||||
{ 2454218, -32768 },
|
||||
{ 2296094, -31744 },
|
||||
{ 2149108, -30720 },
|
||||
{ 2012414, -29696 },
|
||||
{ 1885232, -28672 },
|
||||
{ 1766846, -27648 },
|
||||
{ 1656598, -26624 },
|
||||
{ 1553884, -25600 },
|
||||
{ 1458147, -24576 },
|
||||
{ 1368873, -23552 },
|
||||
{ 1285590, -22528 },
|
||||
{ 1207863, -21504 },
|
||||
{ 1135290, -20480 },
|
||||
{ 1067501, -19456 },
|
||||
{ 1004155, -18432 },
|
||||
{ 944935, -17408 },
|
||||
{ 889550, -16384 },
|
||||
{ 837731, -15360 },
|
||||
{ 789229, -14336 },
|
||||
{ 743813, -13312 },
|
||||
{ 701271, -12288 },
|
||||
{ 661405, -11264 },
|
||||
{ 624032, -10240 },
|
||||
{ 588982, -9216 },
|
||||
{ 556100, -8192 },
|
||||
{ 525239, -7168 },
|
||||
{ 496264, -6144 },
|
||||
{ 469050, -5120 },
|
||||
{ 443480, -4096 },
|
||||
{ 419448, -3072 },
|
||||
{ 396851, -2048 },
|
||||
{ 375597, -1024 },
|
||||
{ 355598, 0 },
|
||||
{ 336775, 1024 },
|
||||
{ 319052, 2048 },
|
||||
{ 302359, 3072 },
|
||||
{ 286630, 4096 },
|
||||
{ 271806, 5120 },
|
||||
{ 257829, 6144 },
|
||||
{ 244646, 7168 },
|
||||
{ 232209, 8192 },
|
||||
{ 220471, 9216 },
|
||||
{ 209390, 10240 },
|
||||
{ 198926, 11264 },
|
||||
{ 189040, 12288 },
|
||||
{ 179698, 13312 },
|
||||
{ 170868, 14336 },
|
||||
{ 162519, 15360 },
|
||||
{ 154622, 16384 },
|
||||
{ 147150, 17408 },
|
||||
{ 140079, 18432 },
|
||||
{ 133385, 19456 },
|
||||
{ 127046, 20480 },
|
||||
{ 121042, 21504 },
|
||||
{ 115352, 22528 },
|
||||
{ 109960, 23552 },
|
||||
{ 104848, 24576 },
|
||||
{ 100000, 25600 },
|
||||
{ 95402, 26624 },
|
||||
{ 91038, 27648 },
|
||||
{ 86897, 28672 },
|
||||
{ 82965, 29696 },
|
||||
{ 79232, 30720 },
|
||||
{ 75686, 31744 },
|
||||
{ 72316, 32768 },
|
||||
{ 69114, 33792 },
|
||||
{ 66070, 34816 },
|
||||
{ 63176, 35840 },
|
||||
{ 60423, 36864 },
|
||||
{ 57804, 37888 },
|
||||
{ 55312, 38912 },
|
||||
{ 52940, 39936 },
|
||||
{ 50681, 40960 },
|
||||
{ 48531, 41984 },
|
||||
{ 46482, 43008 },
|
||||
{ 44530, 44032 },
|
||||
{ 42670, 45056 },
|
||||
{ 40897, 46080 },
|
||||
{ 39207, 47104 },
|
||||
{ 37595, 48128 },
|
||||
{ 36057, 49152 },
|
||||
{ 34590, 50176 },
|
||||
{ 33190, 51200 },
|
||||
{ 31853, 52224 },
|
||||
{ 30577, 53248 },
|
||||
{ 29358, 54272 },
|
||||
{ 28194, 55296 },
|
||||
{ 27082, 56320 },
|
||||
{ 26020, 57344 },
|
||||
{ 25004, 58368 },
|
||||
{ 24033, 59392 },
|
||||
{ 23104, 60416 },
|
||||
{ 22216, 61440 },
|
||||
{ 21367, 62464 },
|
||||
{ 20554, 63488 },
|
||||
{ 19776, 64512 },
|
||||
{ 19031, 65536 },
|
||||
{ 18318, 66560 },
|
||||
{ 17636, 67584 },
|
||||
{ 16982, 68608 },
|
||||
{ 16355, 69632 },
|
||||
{ 15755, 70656 },
|
||||
{ 15180, 71680 },
|
||||
{ 14628, 72704 },
|
||||
{ 14099, 73728 },
|
||||
{ 13592, 74752 },
|
||||
{ 13106, 75776 },
|
||||
{ 12640, 76800 },
|
||||
{ 12192, 77824 },
|
||||
{ 11762, 78848 },
|
||||
{ 11350, 79872 },
|
||||
{ 10954, 80896 },
|
||||
{ 10574, 81920 },
|
||||
{ 10209, 82944 },
|
||||
{ 9858, 83968 },
|
||||
{ 9521, 84992 },
|
||||
{ 9197, 86016 },
|
||||
{ 8886, 87040 },
|
||||
{ 8587, 88064 },
|
||||
{ 8299, 89088 },
|
||||
{ 8023, 90112 },
|
||||
{ 7757, 91136 },
|
||||
{ 7501, 92160 },
|
||||
{ 7254, 93184 },
|
||||
{ 7017, 94208 },
|
||||
{ 6789, 95232 },
|
||||
{ 6570, 96256 },
|
||||
{ 6358, 97280 },
|
||||
{ 6155, 98304 },
|
||||
{ 5959, 99328 },
|
||||
{ 5770, 100352 },
|
||||
{ 5588, 101376 },
|
||||
{ 5412, 102400 },
|
||||
{ 5243, 103424 },
|
||||
{ 5080, 104448 },
|
||||
{ 4923, 105472 },
|
||||
{ 4771, 106496 },
|
||||
{ 4625, 107520 },
|
||||
{ 4484, 108544 },
|
||||
{ 4348, 109568 },
|
||||
{ 4217, 110592 },
|
||||
{ 4090, 111616 },
|
||||
{ 3968, 112640 },
|
||||
{ 3850, 113664 },
|
||||
{ 3736, 114688 },
|
||||
{ 3626, 115712 },
|
||||
{ 3519, 116736 },
|
||||
{ 3417, 117760 },
|
||||
{ 3317, 118784 },
|
||||
{ 3221, 119808 },
|
||||
{ 3129, 120832 },
|
||||
{ 3039, 121856 },
|
||||
{ 2952, 122880 },
|
||||
{ 2868, 123904 },
|
||||
{ 2787, 124928 },
|
||||
{ 2709, 125952 },
|
||||
{ 2633, 126976 },
|
||||
{ 2560, 128000 },
|
||||
{ 2489, 129024 },
|
||||
{ 2420, 130048 }
|
||||
};
|
||||
|
||||
static void adc_tm_map_voltage_temp(const struct adc_tm_map_pt *pts,
|
||||
size_t tablesize, int input, int *output)
|
||||
{
|
||||
|
@ -140,6 +315,7 @@ int therm_fwd_scale(int64_t code, uint32_t adc_hc_vdd_ref_mv,
|
|||
volt = (s64) code * adc_hc_vdd_ref_mv;
|
||||
volt = div64_s64(volt, (data->full_scale_code_volt));
|
||||
|
||||
/* Same API can be used for resistance-temperature table */
|
||||
adc_tm_map_voltage_temp(adcmap_100k_104ef_104fb_1875_vref,
|
||||
ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
|
||||
(int) volt, &result);
|
||||
|
@ -148,6 +324,25 @@ int therm_fwd_scale(int64_t code, uint32_t adc_hc_vdd_ref_mv,
|
|||
}
|
||||
EXPORT_SYMBOL(therm_fwd_scale);
|
||||
|
||||
int therm_fwd_scale_adc7(int64_t code)
|
||||
{
|
||||
int64_t resistance = 0;
|
||||
int result = 0;
|
||||
|
||||
if (code >= RATIO_MAX_ADC7)
|
||||
return -EINVAL;
|
||||
|
||||
resistance = (s64) code * R_PU_100K;
|
||||
resistance = div64_s64(resistance, (RATIO_MAX_ADC7 - code));
|
||||
|
||||
adc_tm_map_voltage_temp(adcmap_100k_adc7,
|
||||
ARRAY_SIZE(adcmap_100k_adc7),
|
||||
(int) resistance, &result);
|
||||
|
||||
return result;
|
||||
}
|
||||
EXPORT_SYMBOL(therm_fwd_scale_adc7);
|
||||
|
||||
void adc_tm_scale_therm_voltage_100k(struct adc_tm_config *param,
|
||||
const struct adc_tm_data *data)
|
||||
{
|
||||
|
@ -188,6 +383,47 @@ void adc_tm_scale_therm_voltage_100k(struct adc_tm_config *param,
|
|||
}
|
||||
EXPORT_SYMBOL(adc_tm_scale_therm_voltage_100k);
|
||||
|
||||
void adc_tm_scale_therm_voltage_100k_adc7(struct adc_tm_config *param)
|
||||
{
|
||||
int temp;
|
||||
int64_t resistance = 0;
|
||||
|
||||
/* High temperature maps to lower threshold voltage */
|
||||
/* Same API can be used for resistance-temperature table */
|
||||
adc_tm_map_temp_voltage(
|
||||
adcmap_100k_adc7,
|
||||
ARRAY_SIZE(adcmap_100k_adc7),
|
||||
param->high_thr_temp, &resistance);
|
||||
|
||||
param->low_thr_voltage = resistance * RATIO_MAX_ADC7;
|
||||
param->low_thr_voltage = div64_s64(param->low_thr_voltage,
|
||||
(resistance + R_PU_100K));
|
||||
|
||||
temp = therm_fwd_scale_adc7(param->low_thr_voltage);
|
||||
if (temp == -EINVAL)
|
||||
return;
|
||||
|
||||
if (temp < param->high_thr_temp)
|
||||
param->low_thr_voltage--;
|
||||
|
||||
/* Low temperature maps to higher threshold voltage */
|
||||
/* Same API can be used for resistance-temperature table */
|
||||
adc_tm_map_temp_voltage(
|
||||
adcmap_100k_adc7,
|
||||
ARRAY_SIZE(adcmap_100k_adc7),
|
||||
param->low_thr_temp, &resistance);
|
||||
|
||||
param->high_thr_voltage = resistance * RATIO_MAX_ADC7;
|
||||
param->high_thr_voltage = div64_s64(param->high_thr_voltage,
|
||||
(resistance + R_PU_100K));
|
||||
|
||||
temp = therm_fwd_scale_adc7(param->high_thr_voltage);
|
||||
|
||||
if (temp > param->low_thr_temp)
|
||||
param->high_thr_voltage++;
|
||||
}
|
||||
EXPORT_SYMBOL(adc_tm_scale_therm_voltage_100k_adc7);
|
||||
|
||||
int32_t adc_tm_absolute_rthr(const struct adc_tm_data *data,
|
||||
struct adc_tm_config *tm_config)
|
||||
{
|
||||
|
@ -195,11 +431,13 @@ int32_t adc_tm_absolute_rthr(const struct adc_tm_data *data,
|
|||
|
||||
low_thr = div_s64(tm_config->low_thr_voltage, tm_config->prescal);
|
||||
low_thr *= data->full_scale_code_volt;
|
||||
|
||||
low_thr = div64_s64(low_thr, ADC_HC_VDD_REF);
|
||||
tm_config->low_thr_voltage = low_thr;
|
||||
|
||||
high_thr = div_s64(tm_config->high_thr_voltage, tm_config->prescal);
|
||||
high_thr *= data->full_scale_code_volt;
|
||||
|
||||
high_thr = div64_s64(high_thr, ADC_HC_VDD_REF);
|
||||
tm_config->high_thr_voltage = high_thr;
|
||||
|
||||
|
@ -207,5 +445,25 @@ int32_t adc_tm_absolute_rthr(const struct adc_tm_data *data,
|
|||
}
|
||||
EXPORT_SYMBOL(adc_tm_absolute_rthr);
|
||||
|
||||
int32_t adc_tm_absolute_rthr_adc7(struct adc_tm_config *tm_config)
|
||||
{
|
||||
int64_t low_thr = 0, high_thr = 0;
|
||||
|
||||
low_thr = div_s64(tm_config->low_thr_voltage, tm_config->prescal);
|
||||
low_thr *= MAX_CODE_VOLT;
|
||||
|
||||
low_thr = div64_s64(low_thr, ADC_HC_VDD_REF);
|
||||
tm_config->low_thr_voltage = low_thr;
|
||||
|
||||
high_thr = div_s64(tm_config->high_thr_voltage, tm_config->prescal);
|
||||
high_thr *= MAX_CODE_VOLT;
|
||||
|
||||
high_thr = div64_s64(high_thr, ADC_HC_VDD_REF);
|
||||
tm_config->high_thr_voltage = high_thr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(adc_tm_absolute_rthr_adc7);
|
||||
|
||||
MODULE_DESCRIPTION("Qualcomm Technologies Inc. PMIC ADC_TM common driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
|
|
@ -51,6 +51,35 @@ static int adc_tm_init(struct adc_tm_chip *adc_tm, uint32_t dt_chans)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t adc_tm5_channel_measure(struct adc_tm_chip *adc_tm,
|
||||
struct adc_tm_param *param)
|
||||
{
|
||||
if (adc_tm->ops->channel_measure)
|
||||
return adc_tm->ops->channel_measure(adc_tm, param);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(adc_tm5_channel_measure);
|
||||
|
||||
int32_t adc_tm5_disable_chan_meas(struct adc_tm_chip *adc_tm,
|
||||
struct adc_tm_param *param)
|
||||
{
|
||||
if (adc_tm->ops->disable_chan)
|
||||
return adc_tm->ops->disable_chan(adc_tm, param);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(adc_tm5_disable_chan_meas);
|
||||
|
||||
static void notify_adc_tm_fn(struct work_struct *work)
|
||||
{
|
||||
struct adc_tm_sensor *adc_tm = container_of(work,
|
||||
struct adc_tm_sensor, work);
|
||||
|
||||
if (adc_tm->chip->ops->notify)
|
||||
adc_tm->chip->ops->notify(adc_tm);
|
||||
}
|
||||
|
||||
static struct thermal_zone_of_device_ops adc_tm_ops = {
|
||||
.get_temp = adc_tm_get_temp,
|
||||
.set_trips = adc_tm_set_trip_temp,
|
||||
|
@ -63,19 +92,24 @@ static struct thermal_zone_of_device_ops adc_tm_ops_iio = {
|
|||
static int adc_tm_register_tzd(struct adc_tm_chip *adc_tm, int dt_chan_num,
|
||||
bool set_trips)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int i, channel;
|
||||
struct thermal_zone_device *tzd;
|
||||
|
||||
for (i = 0; i < dt_chan_num; i++) {
|
||||
adc_tm->sensor[i].chip = adc_tm;
|
||||
if (adc_tm->data == &data_adc_tm7)
|
||||
channel = V_CHAN(adc_tm->sensor[i]);
|
||||
else
|
||||
channel = adc_tm->sensor[i].adc_ch;
|
||||
|
||||
if (!adc_tm->sensor[i].non_thermal) {
|
||||
if (set_trips)
|
||||
tzd = devm_thermal_zone_of_sensor_register(
|
||||
adc_tm->dev, adc_tm->sensor[i].adc_ch,
|
||||
&adc_tm->sensor[i], &adc_tm_ops);
|
||||
adc_tm->dev, channel,
|
||||
&adc_tm->sensor[i], &adc_tm_ops);
|
||||
else
|
||||
tzd = devm_thermal_zone_of_sensor_register(
|
||||
adc_tm->dev, adc_tm->sensor[i].adc_ch,
|
||||
adc_tm->dev, channel,
|
||||
&adc_tm->sensor[i], &adc_tm_ops_iio);
|
||||
|
||||
if (IS_ERR(tzd)) {
|
||||
|
@ -136,7 +170,6 @@ struct adc_tm_chip *get_adc_tm(struct device *dev, const char *name)
|
|||
node = of_parse_phandle(dev->of_node, prop_name, 0);
|
||||
if (node == NULL)
|
||||
return ERR_PTR(-ENODEV);
|
||||
|
||||
list_for_each_entry(chip, &adc_tm_device_list, list) {
|
||||
pdev = to_platform_device(chip->dev);
|
||||
if (pdev->dev.of_node == node)
|
||||
|
@ -165,6 +198,9 @@ static const struct of_device_id adc_tm_match_table[] = {
|
|||
{
|
||||
.compatible = "qcom,adc-tm5-iio",
|
||||
.data = &data_adc_tm5,
|
||||
|
||||
.compatible = "qcom,adc-tm7",
|
||||
.data = &data_adc_tm7,
|
||||
},
|
||||
{}
|
||||
};
|
||||
|
@ -224,7 +260,9 @@ static int adc_tm_get_dt_data(struct platform_device *pdev,
|
|||
for_each_child_of_node(node, child) {
|
||||
int channel_num, i = 0, adc_rscale_fn = 0;
|
||||
int calib_type = 0, ret, hw_settle_time = 0;
|
||||
int decimation, fast_avg_samples;
|
||||
int prescal = 0;
|
||||
u32 sid = 0;
|
||||
struct iio_channel *chan_adc;
|
||||
bool non_thermal = false;
|
||||
|
||||
|
@ -234,6 +272,11 @@ static int adc_tm_get_dt_data(struct platform_device *pdev,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (data == &data_adc_tm7) {
|
||||
sid = (channel_num >> ADC_CHANNEL_OFFSET);
|
||||
channel_num &= ADC_CHANNEL_MASK;
|
||||
}
|
||||
|
||||
ret = of_property_read_u32(child, "qcom,hw-settle-time",
|
||||
&hw_settle_time);
|
||||
if (!ret) {
|
||||
|
@ -244,9 +287,34 @@ static int adc_tm_get_dt_data(struct platform_device *pdev,
|
|||
return ret;
|
||||
}
|
||||
hw_settle_time = ret;
|
||||
} else {
|
||||
} else
|
||||
hw_settle_time = ADC_TM_DEF_HW_SETTLE_TIME;
|
||||
}
|
||||
|
||||
ret = of_property_read_u32(child, "qcom,decimation",
|
||||
&decimation);
|
||||
if (!ret) {
|
||||
ret = adc_tm_decimation_from_dt(decimation,
|
||||
data->decimation);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "Invalid decimation value\n");
|
||||
return ret;
|
||||
}
|
||||
decimation = ret;
|
||||
} else
|
||||
decimation = ADC_TM_DECIMATION_DEFAULT;
|
||||
|
||||
ret = of_property_read_u32(child, "qcom,avg-samples",
|
||||
&fast_avg_samples);
|
||||
if (!ret) {
|
||||
ret = adc_tm_avg_samples_from_dt(fast_avg_samples);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "Invalid fast average with %d\n",
|
||||
ret);
|
||||
return -EINVAL;
|
||||
}
|
||||
fast_avg_samples = ret;
|
||||
} else
|
||||
fast_avg_samples = ADC_TM_DEF_AVG_SAMPLES;
|
||||
|
||||
if (of_property_read_bool(child, "qcom,ratiometric"))
|
||||
calib_type = ADC_RATIO_CAL;
|
||||
|
@ -271,6 +339,16 @@ static int adc_tm_get_dt_data(struct platform_device *pdev,
|
|||
/* Default to 1 second timer select */
|
||||
adc_tm->sensor[idx].timer_select = ADC_TIMER_SEL_2;
|
||||
adc_tm->sensor[idx].hw_settle_time = hw_settle_time;
|
||||
|
||||
if (data == &data_adc_tm7) {
|
||||
/* Default to 1 second time select */
|
||||
adc_tm->sensor[idx].meas_time = MEAS_INT_1S;
|
||||
adc_tm->sensor[idx].fast_avg_samples = fast_avg_samples;
|
||||
adc_tm->sensor[idx].decimation = decimation;
|
||||
adc_tm->sensor[idx].sid = sid;
|
||||
adc_tm->sensor[idx].btm_ch = idx;
|
||||
}
|
||||
|
||||
adc_tm->sensor[idx].adc_rscale_fn = adc_rscale_fn;
|
||||
adc_tm->sensor[idx].non_thermal = non_thermal;
|
||||
adc_tm->sensor[idx].prescaling = prescal;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <linux/qpnp/qpnp-revid.h>
|
||||
#include <linux/adc-tm-clients.h>
|
||||
|
||||
#define ADC_TM_DECIMATION_DEFAULT 840
|
||||
#define ADC_TM_DECIMATION_DEFAULT 2
|
||||
#define ADC_TM_DECIMATION_SAMPLES_MAX 3
|
||||
#define ADC_TM_DEF_AVG_SAMPLES 0 /* 1 sample */
|
||||
#define ADC_TM_DEF_HW_SETTLE_TIME 0 /* 15 us */
|
||||
|
@ -25,7 +25,13 @@
|
|||
#define ADC_TM_TIMER2 10 /* 1 second */
|
||||
#define ADC_TM_TIMER3 4 /* 4 second */
|
||||
#define ADC_HC_VDD_REF 1875000
|
||||
#define MAX_PROP_NAME_LEN 32
|
||||
#define MAX_PROP_NAME_LEN 32
|
||||
#define R_PU_100K 100000
|
||||
#define RATIO_MAX_ADC7 0x4000
|
||||
#define MAX_CODE_VOLT 0x70e4
|
||||
#define ADC_CHANNEL_OFFSET 8
|
||||
#define V_CHAN(x) (((x).sid << ADC_CHANNEL_OFFSET) | (x).adc_ch)
|
||||
#define ADC_CHANNEL_MASK 0xff
|
||||
|
||||
enum adc_cal_method {
|
||||
ADC_NO_CAL = 0,
|
||||
|
@ -47,6 +53,14 @@ enum adc_timer_select {
|
|||
ADC_TIMER_SEL_NONE,
|
||||
};
|
||||
|
||||
enum adc_time_select {
|
||||
MEAS_INT_50MS = 0,
|
||||
MEAS_INT_100MS,
|
||||
MEAS_INT_1S,
|
||||
MEAS_INT_SET,
|
||||
MEAS_INT_NONE,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum adc_tm_rscale_fn_type - Scaling function used to convert the
|
||||
* channels input voltage/temperature to corresponding ADC code that is
|
||||
|
@ -73,12 +87,21 @@ struct adc_tm_sensor {
|
|||
unsigned int btm_ch;
|
||||
unsigned int prescaling;
|
||||
unsigned int timer_select;
|
||||
unsigned int decimation; /* PMIC7 */
|
||||
unsigned int fast_avg_samples; /* PMIC7 */
|
||||
unsigned int sid; /* PMIC7 */
|
||||
unsigned int meas_time; /* PMIC7 */
|
||||
int64_t high_thr_voltage; /* PMIC7 */
|
||||
int64_t low_thr_voltage; /* PMIC7 */
|
||||
enum adc_tm_rscale_fn_type adc_rscale_fn;
|
||||
struct iio_channel *adc;
|
||||
struct list_head thr_list;
|
||||
bool non_thermal;
|
||||
bool non_thermal;
|
||||
bool high_thr_triggered;
|
||||
bool low_thr_triggered;
|
||||
int high_thr_en; /* PMIC7 */
|
||||
int low_thr_en; /* PMIC7 */
|
||||
int meas_en; /* PMIC7 */
|
||||
struct workqueue_struct *req_wq;
|
||||
struct work_struct work;
|
||||
};
|
||||
|
@ -108,6 +131,11 @@ struct adc_tm_ops {
|
|||
int (*init)(struct adc_tm_chip *chip, uint32_t dt_chans);
|
||||
int (*set_trips)(struct adc_tm_sensor *sensor, int low_temp,
|
||||
int high_temp);
|
||||
int32_t (*channel_measure)(struct adc_tm_chip *chip,
|
||||
struct adc_tm_param *param);
|
||||
int32_t (*disable_chan)(struct adc_tm_chip *chip,
|
||||
struct adc_tm_param *param);
|
||||
void (*notify)(struct adc_tm_sensor *adc_tm);
|
||||
int (*interrupts_reg)(struct adc_tm_chip *chip);
|
||||
int (*shutdown)(struct adc_tm_chip *chip);
|
||||
};
|
||||
|
@ -135,6 +163,8 @@ struct adc_tm_data {
|
|||
};
|
||||
|
||||
extern const struct adc_tm_data data_adc_tm5;
|
||||
extern const struct adc_tm_data data_adc_tm7;
|
||||
|
||||
/**
|
||||
* Channel index for the corresponding index to adc_tm_channel_select
|
||||
*/
|
||||
|
@ -230,6 +260,10 @@ struct adc_tm_reverse_scale_fn {
|
|||
struct adc_tm_config *tm_config);
|
||||
};
|
||||
|
||||
struct adc_tm_reverse_scale_fn_adc7 {
|
||||
int32_t (*chan)(struct adc_tm_config *tm_config);
|
||||
};
|
||||
|
||||
/**
|
||||
* struct adc_map_pt - Map the graph representation for ADC channel
|
||||
* @x: Represent the ADC digitized code.
|
||||
|
@ -265,7 +299,11 @@ void adc_tm_scale_therm_voltage_100k(struct adc_tm_config *param,
|
|||
int32_t adc_tm_absolute_rthr(const struct adc_tm_data *data,
|
||||
struct adc_tm_config *tm_config);
|
||||
|
||||
void notify_adc_tm_fn(struct work_struct *work);
|
||||
int therm_fwd_scale_adc7(int64_t code);
|
||||
|
||||
void adc_tm_scale_therm_voltage_100k_adc7(struct adc_tm_config *param);
|
||||
|
||||
int32_t adc_tm_absolute_rthr_adc7(struct adc_tm_config *tm_config);
|
||||
|
||||
int adc_tm_is_valid(struct adc_tm_chip *chip);
|
||||
|
||||
|
|
|
@ -418,7 +418,8 @@ static int32_t adc_tm5_manage_thresholds(struct adc_tm_sensor *sensor)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void notify_adc_tm_fn(struct work_struct *work)
|
||||
/* Used to notify non-thermal clients of threshold crossing */
|
||||
void notify_adc_tm5_fn(struct adc_tm_sensor *adc_tm)
|
||||
{
|
||||
struct adc_tm_client_info *client_info = NULL;
|
||||
struct adc_tm_chip *chip;
|
||||
|
@ -426,9 +427,6 @@ void notify_adc_tm_fn(struct work_struct *work)
|
|||
uint32_t btm_chan_num = 0, btm_chan_idx = 0;
|
||||
int ret = 0;
|
||||
|
||||
struct adc_tm_sensor *adc_tm = container_of(work,
|
||||
struct adc_tm_sensor, work);
|
||||
|
||||
chip = adc_tm->chip;
|
||||
|
||||
btm_chan_num = adc_tm->btm_ch;
|
||||
|
@ -510,7 +508,8 @@ void notify_adc_tm_fn(struct work_struct *work)
|
|||
}
|
||||
}
|
||||
|
||||
int32_t adc_tm5_channel_measure(struct adc_tm_chip *chip,
|
||||
/* Used by non-thermal clients to configure an ADC_TM channel */
|
||||
static int32_t adc_tm_5_channel_measure(struct adc_tm_chip *chip,
|
||||
struct adc_tm_param *param)
|
||||
|
||||
{
|
||||
|
@ -612,9 +611,9 @@ int32_t adc_tm5_channel_measure(struct adc_tm_chip *chip,
|
|||
mutex_unlock(&chip->adc_mutex_lock);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(adc_tm5_channel_measure);
|
||||
|
||||
int32_t adc_tm5_disable_chan_meas(struct adc_tm_chip *chip,
|
||||
/* Used by non-thermal clients to release an ADC_TM channel */
|
||||
static int32_t adc_tm_5_disable_chan_meas(struct adc_tm_chip *chip,
|
||||
struct adc_tm_param *param)
|
||||
{
|
||||
int ret = 0, i = 0;
|
||||
|
@ -672,7 +671,6 @@ int32_t adc_tm5_disable_chan_meas(struct adc_tm_chip *chip,
|
|||
spin_unlock_irqrestore(&chip->adc_tm_lock, flags);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(adc_tm5_disable_chan_meas);
|
||||
|
||||
static int adc_tm5_set_mode(struct adc_tm_sensor *sensor,
|
||||
enum thermal_device_mode mode)
|
||||
|
@ -1110,6 +1108,9 @@ static const struct adc_tm_ops ops_adc_tm5 = {
|
|||
.set_trips = adc_tm5_set_trip_temp,
|
||||
.interrupts_reg = adc_tm5_register_interrupts,
|
||||
.get_temp = adc_tm5_get_temp,
|
||||
.channel_measure = adc_tm_5_channel_measure,
|
||||
.disable_chan = adc_tm_5_disable_chan_meas,
|
||||
.notify = notify_adc_tm5_fn,
|
||||
};
|
||||
|
||||
const struct adc_tm_data data_adc_tm5 = {
|
||||
|
|
834
drivers/thermal/qcom/adc-tm7.c
Normal file
834
drivers/thermal/qcom/adc-tm7.c
Normal file
|
@ -0,0 +1,834 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/spmi.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/iio/consumer.h>
|
||||
#include "adc-tm.h"
|
||||
#include "../thermal_core.h"
|
||||
|
||||
#define ADC_TM_STATUS1 0x08
|
||||
#define ADC_TM_STATUS_LOW_SET 0x09
|
||||
#define ADC_TM_STATUS_LOW_CLR 0x0a
|
||||
#define ADC_TM_STATUS_HIGH_SET 0x0b
|
||||
#define ADC_TM_STATUS_HIGH_CLR 0x0c
|
||||
|
||||
#define ADC_TM_CFG_HS_SET 0x0d
|
||||
#define ADC_TM_CFG_HS_FLAG BIT(0)
|
||||
#define ADC_TM_CFG_HS_CLR 0x0e
|
||||
|
||||
#define ADC_TM_NUM_BTM_CHAN 0x0f
|
||||
|
||||
#define ADC_TM_SID 0x40
|
||||
|
||||
#define ADC_TM_CH_CTL 0x41
|
||||
#define ADC_TM_TM_CH_SEL GENMASK(7, 5)
|
||||
#define ADC_TM_TM_CH_SEL_MASK_SHIFT 5
|
||||
#define ADC_TM_MEAS_INT_SEL GENMASK(3, 2)
|
||||
#define ADC_TM_MEAS_INT_SEL_MASK_SHIFT 2
|
||||
|
||||
#define ADC_TM_ADC_DIG_PARAM 0x42
|
||||
#define ADC_TM_CTL_DEC_RATIO_MASK GENMASK(3, 2)
|
||||
#define ADC_TM_CTL_DEC_RATIO_SHIFT 2
|
||||
#define ADC_TM_CTL_CAL_SEL GENMASK(5, 4)
|
||||
#define ADC_TM_CTL_CAL_SEL_MASK_SHIFT 4
|
||||
|
||||
#define ADC_TM_FAST_AVG_CTL 0x43
|
||||
#define ADC_TM_FAST_AVG_EN BIT(7)
|
||||
|
||||
#define ADC_TM_ADC_CH_SEL_CTL 0x44
|
||||
|
||||
#define ADC_TM_DELAY_CTL 0x45
|
||||
|
||||
#define ADC_TM_EN_CTL1 0x46
|
||||
#define ADC_TM_EN BIT(7)
|
||||
|
||||
#define ADC_TM_CONV_REQ 0x47
|
||||
#define ADC_TM_CONV_REQ_EN BIT(7)
|
||||
|
||||
#define ADC_TM_DATA_HOLD_CTL 0x48
|
||||
|
||||
#define ADC_TM_LOW_THR0 0x49
|
||||
#define ADC_TM_LOW_THR1 0x4a
|
||||
#define ADC_TM_HIGH_THR0 0x4b
|
||||
#define ADC_TM_HIGH_THR1 0x4c
|
||||
#define ADC_TM_LOWER_MASK(n) ((n) & GENMASK(7, 0))
|
||||
#define ADC_TM_UPPER_MASK(n) (((n) & GENMASK(15, 8)) >> 8)
|
||||
|
||||
#define ADC_TM_MEAS_IRQ_EN 0x4d
|
||||
#define ADC_TM_MEAS_EN BIT(7)
|
||||
|
||||
#define ADC_TM_MEAS_INT_LSB 0x50
|
||||
#define ADC_TM_MEAS_INT_MSB 0x51
|
||||
#define ADC_TM_MEAS_INT_MODE 0x52
|
||||
|
||||
#define ADC_TM_Mn_DATA0(n) ((n * 2) + 0xa0)
|
||||
#define ADC_TM_Mn_DATA1(n) ((n * 2) + 0xa1)
|
||||
#define ADC_TM_DATA_SHIFT 8
|
||||
|
||||
#define ADC_TM_POLL_DELAY_MIN_US 100
|
||||
#define ADC_TM_POLL_DELAY_MAX_US 110
|
||||
#define ADC_TM_POLL_RETRY_COUNT 3
|
||||
|
||||
static struct adc_tm_reverse_scale_fn_adc7 adc_tm_rscale_fn[] = {
|
||||
[SCALE_R_ABSOLUTE] = {adc_tm_absolute_rthr_adc7},
|
||||
};
|
||||
|
||||
static int adc_tm_get_temp(struct adc_tm_sensor *sensor, int *temp)
|
||||
{
|
||||
int ret, milli_celsius;
|
||||
|
||||
if (!sensor || !sensor->adc)
|
||||
return -EINVAL;
|
||||
|
||||
ret = iio_read_channel_processed(sensor->adc, &milli_celsius);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
*temp = milli_celsius;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t adc_tm_read_reg(struct adc_tm_chip *chip,
|
||||
int16_t reg, u8 *data, int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = regmap_bulk_read(chip->regmap, (chip->base + reg), data, len);
|
||||
if (ret < 0)
|
||||
pr_err("adc-tm read reg %d failed with %d\n", reg, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t adc_tm_write_reg(struct adc_tm_chip *chip,
|
||||
int16_t reg, u8 *data, int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = regmap_bulk_write(chip->regmap, (chip->base + reg), data, len);
|
||||
if (ret < 0)
|
||||
pr_err("adc-tm write reg %d failed with %d\n", reg, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t adc_tm7_conv_req(struct adc_tm_chip *chip)
|
||||
{
|
||||
int rc = 0;
|
||||
u8 data = 0;
|
||||
unsigned int count;
|
||||
|
||||
data = ADC_TM_EN;
|
||||
rc = adc_tm_write_reg(chip, ADC_TM_EN_CTL1, &data, 1);
|
||||
if (rc < 0) {
|
||||
pr_err("adc-tm enable failed with %d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
data = ADC_TM_CFG_HS_FLAG;
|
||||
rc = adc_tm_write_reg(chip, ADC_TM_CFG_HS_SET, &data, 1);
|
||||
if (rc < 0) {
|
||||
pr_err("adc-tm handshake failed with %d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
data = ADC_TM_CONV_REQ_EN;
|
||||
rc = adc_tm_write_reg(chip, ADC_TM_CONV_REQ, &data, 1);
|
||||
if (rc < 0) {
|
||||
pr_err("adc-tm request conversion failed with %d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
for (count = 0; count < ADC_TM_POLL_RETRY_COUNT; count++) {
|
||||
rc = adc_tm_read_reg(chip, ADC_TM_CFG_HS_SET, &data, 1);
|
||||
if (rc < 0) {
|
||||
pr_err("adc-tm read failed with %d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!(data & ADC_TM_CFG_HS_FLAG))
|
||||
return rc;
|
||||
usleep_range(ADC_TM_POLL_DELAY_MIN_US,
|
||||
ADC_TM_POLL_DELAY_MAX_US);
|
||||
}
|
||||
|
||||
pr_err("adc-tm conversion request handshake timed out\n");
|
||||
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
static int adc_tm7_configure(struct adc_tm_sensor *sensor)
|
||||
{
|
||||
struct adc_tm_chip *chip = sensor->chip;
|
||||
u8 buf[14];
|
||||
uint32_t mask = 0;
|
||||
int ret;
|
||||
|
||||
ret = adc_tm_read_reg(chip, ADC_TM_SID, buf, 14);
|
||||
if (ret < 0) {
|
||||
pr_err("adc-tm block read failed with %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
buf[0] = sensor->sid;
|
||||
buf[1] &= ~ADC_TM_TM_CH_SEL;
|
||||
buf[1] |= sensor->btm_ch << ADC_TM_TM_CH_SEL_MASK_SHIFT;
|
||||
buf[1] &= ~ADC_TM_MEAS_INT_SEL;
|
||||
buf[1] |= sensor->meas_time << ADC_TM_MEAS_INT_SEL_MASK_SHIFT;
|
||||
|
||||
/* Set calibration select, hw_settle delay */
|
||||
buf[2] &= ~ADC_TM_CTL_DEC_RATIO_MASK;
|
||||
buf[2] |= sensor->decimation << ADC_TM_CTL_DEC_RATIO_SHIFT;
|
||||
buf[2] &= ~ADC_TM_CTL_CAL_SEL;
|
||||
buf[2] |= sensor->cal_sel << ADC_TM_CTL_CAL_SEL_MASK_SHIFT;
|
||||
|
||||
buf[3] = sensor->fast_avg_samples | ADC_TM_FAST_AVG_EN;
|
||||
|
||||
buf[4] = sensor->adc_ch;
|
||||
|
||||
buf[5] = sensor->hw_settle_time;
|
||||
|
||||
mask = lower_32_bits(sensor->low_thr_voltage);
|
||||
buf[9] = ADC_TM_LOWER_MASK(mask);
|
||||
buf[10] = ADC_TM_UPPER_MASK(mask);
|
||||
|
||||
mask = lower_32_bits(sensor->high_thr_voltage);
|
||||
buf[11] = ADC_TM_LOWER_MASK(mask);
|
||||
buf[12] = ADC_TM_UPPER_MASK(mask);
|
||||
|
||||
buf[13] |= (sensor->meas_en | sensor->high_thr_en << 1 |
|
||||
sensor->low_thr_en);
|
||||
|
||||
ret = adc_tm_write_reg(chip, ADC_TM_SID, buf, 14);
|
||||
if (ret < 0)
|
||||
pr_err("adc-tm block write failed with %d\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t adc_tm_add_to_list(struct adc_tm_chip *chip,
|
||||
uint32_t dt_index,
|
||||
struct adc_tm_param *param)
|
||||
{
|
||||
struct adc_tm_client_info *client_info = NULL;
|
||||
bool client_info_exists = false;
|
||||
|
||||
list_for_each_entry(client_info,
|
||||
&chip->sensor[dt_index].thr_list, list) {
|
||||
if (client_info->param->id == param->id) {
|
||||
client_info->low_thr_requested = param->low_thr;
|
||||
client_info->high_thr_requested = param->high_thr;
|
||||
client_info->state_request = param->state_request;
|
||||
client_info->notify_low_thr = false;
|
||||
client_info->notify_high_thr = false;
|
||||
client_info_exists = true;
|
||||
pr_debug("client found\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!client_info_exists) {
|
||||
client_info = devm_kzalloc(chip->dev,
|
||||
sizeof(struct adc_tm_client_info), GFP_KERNEL);
|
||||
if (!client_info)
|
||||
return -ENOMEM;
|
||||
|
||||
pr_debug("new client\n");
|
||||
client_info->param->id = (uintptr_t) client_info;
|
||||
client_info->low_thr_requested = param->low_thr;
|
||||
client_info->high_thr_requested = param->high_thr;
|
||||
client_info->state_request = param->state_request;
|
||||
|
||||
list_add_tail(&client_info->list,
|
||||
&chip->sensor[dt_index].thr_list);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t adc_tm7_manage_thresholds(struct adc_tm_sensor *sensor)
|
||||
{
|
||||
int high_thr = INT_MAX, low_thr = INT_MIN;
|
||||
struct adc_tm_client_info *client_info = NULL;
|
||||
struct list_head *thr_list;
|
||||
uint32_t scale_type = 0;
|
||||
struct adc_tm_config tm_config;
|
||||
|
||||
sensor->high_thr_en = 0;
|
||||
sensor->low_thr_en = 0;
|
||||
|
||||
/*
|
||||
* Reset the high_thr_set and low_thr_set of all
|
||||
* clients since the thresholds will be recomputed.
|
||||
*/
|
||||
list_for_each(thr_list, &sensor->thr_list) {
|
||||
client_info = list_entry(thr_list,
|
||||
struct adc_tm_client_info, list);
|
||||
client_info->high_thr_set = false;
|
||||
client_info->low_thr_set = false;
|
||||
}
|
||||
|
||||
/* Find the min of high_thr and max of low_thr */
|
||||
list_for_each(thr_list, &sensor->thr_list) {
|
||||
client_info = list_entry(thr_list,
|
||||
struct adc_tm_client_info, list);
|
||||
|
||||
if ((client_info->state_request == ADC_TM_HIGH_THR_ENABLE) ||
|
||||
(client_info->state_request ==
|
||||
ADC_TM_HIGH_LOW_THR_ENABLE))
|
||||
if (client_info->high_thr_requested < high_thr)
|
||||
high_thr = client_info->high_thr_requested;
|
||||
|
||||
if ((client_info->state_request == ADC_TM_LOW_THR_ENABLE) ||
|
||||
(client_info->state_request ==
|
||||
ADC_TM_HIGH_LOW_THR_ENABLE))
|
||||
if (client_info->low_thr_requested > low_thr)
|
||||
low_thr = client_info->low_thr_requested;
|
||||
|
||||
pr_debug("threshold compared is high:%d and low:%d\n",
|
||||
client_info->high_thr_requested,
|
||||
client_info->low_thr_requested);
|
||||
pr_debug("current threshold is high:%d and low:%d\n",
|
||||
high_thr, low_thr);
|
||||
}
|
||||
|
||||
/* Check which of the high_thr and low_thr got set */
|
||||
list_for_each(thr_list, &sensor->thr_list) {
|
||||
client_info = list_entry(thr_list,
|
||||
struct adc_tm_client_info, list);
|
||||
|
||||
if ((client_info->state_request == ADC_TM_HIGH_THR_ENABLE) ||
|
||||
(client_info->state_request ==
|
||||
ADC_TM_HIGH_LOW_THR_ENABLE))
|
||||
if (high_thr == client_info->high_thr_requested) {
|
||||
sensor->high_thr_en = 1;
|
||||
client_info->high_thr_set = true;
|
||||
}
|
||||
|
||||
if ((client_info->state_request == ADC_TM_LOW_THR_ENABLE) ||
|
||||
(client_info->state_request ==
|
||||
ADC_TM_HIGH_LOW_THR_ENABLE))
|
||||
if (low_thr == client_info->low_thr_requested) {
|
||||
sensor->low_thr_en = 1;
|
||||
client_info->low_thr_set = true;
|
||||
}
|
||||
}
|
||||
|
||||
tm_config.high_thr_voltage = (int64_t)high_thr;
|
||||
tm_config.low_thr_voltage = (int64_t)low_thr;
|
||||
tm_config.prescal = sensor->prescaling;
|
||||
|
||||
scale_type = sensor->adc_rscale_fn;
|
||||
if (scale_type >= SCALE_RSCALE_NONE)
|
||||
return -EBADF;
|
||||
|
||||
adc_tm_rscale_fn[scale_type].chan(&tm_config);
|
||||
|
||||
sensor->low_thr_voltage = tm_config.low_thr_voltage;
|
||||
sensor->high_thr_voltage = tm_config.high_thr_voltage;
|
||||
|
||||
pr_debug("threshold written is high:%d and low:%d\n",
|
||||
high_thr, low_thr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Used to notify non-thermal clients of threshold crossing */
|
||||
void notify_adc_tm7_fn(struct adc_tm_sensor *adc_tm)
|
||||
{
|
||||
struct adc_tm_client_info *client_info = NULL;
|
||||
struct adc_tm_chip *chip;
|
||||
struct list_head *thr_list;
|
||||
int ret;
|
||||
|
||||
chip = adc_tm->chip;
|
||||
|
||||
mutex_lock(&chip->adc_mutex_lock);
|
||||
if (adc_tm->low_thr_triggered) {
|
||||
/* adjust thr, calling manage_thr */
|
||||
list_for_each(thr_list, &adc_tm->thr_list) {
|
||||
client_info = list_entry(thr_list,
|
||||
struct adc_tm_client_info, list);
|
||||
if (client_info->low_thr_set) {
|
||||
client_info->low_thr_set = false;
|
||||
client_info->notify_low_thr = true;
|
||||
if (client_info->state_request ==
|
||||
ADC_TM_HIGH_LOW_THR_ENABLE)
|
||||
client_info->state_request =
|
||||
ADC_TM_HIGH_THR_ENABLE;
|
||||
else
|
||||
client_info->state_request =
|
||||
ADC_TM_LOW_THR_DISABLE;
|
||||
}
|
||||
}
|
||||
adc_tm->low_thr_triggered = false;
|
||||
}
|
||||
|
||||
if (adc_tm->high_thr_triggered) {
|
||||
/* adjust thr, calling manage_thr */
|
||||
list_for_each(thr_list, &adc_tm->thr_list) {
|
||||
client_info = list_entry(thr_list,
|
||||
struct adc_tm_client_info, list);
|
||||
if (client_info->high_thr_set) {
|
||||
client_info->high_thr_set = false;
|
||||
client_info->notify_high_thr = true;
|
||||
if (client_info->state_request ==
|
||||
ADC_TM_HIGH_LOW_THR_ENABLE)
|
||||
client_info->state_request =
|
||||
ADC_TM_LOW_THR_ENABLE;
|
||||
else
|
||||
client_info->state_request =
|
||||
ADC_TM_HIGH_THR_DISABLE;
|
||||
}
|
||||
}
|
||||
adc_tm->high_thr_triggered = false;
|
||||
}
|
||||
ret = adc_tm7_manage_thresholds(adc_tm);
|
||||
if (ret < 0)
|
||||
pr_err("Error in reverse scaling:%d\n", ret);
|
||||
|
||||
ret = adc_tm7_configure(adc_tm);
|
||||
if (ret < 0)
|
||||
pr_err("Error during adc-tm configure:%d\n", ret);
|
||||
|
||||
ret = adc_tm7_conv_req(chip);
|
||||
if (ret < 0)
|
||||
pr_err("Error enabling adc-tm with %d\n", ret);
|
||||
|
||||
mutex_unlock(&chip->adc_mutex_lock);
|
||||
|
||||
list_for_each_entry(client_info, &adc_tm->thr_list, list) {
|
||||
if (client_info->notify_low_thr) {
|
||||
if (client_info->param->threshold_notification
|
||||
!= NULL) {
|
||||
pr_debug("notify kernel with low state\n");
|
||||
client_info->param->threshold_notification(
|
||||
ADC_TM_LOW_STATE,
|
||||
client_info->param->btm_ctx);
|
||||
client_info->notify_low_thr = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (client_info->notify_high_thr) {
|
||||
if (client_info->param->threshold_notification
|
||||
!= NULL) {
|
||||
pr_debug("notify kernel with high state\n");
|
||||
client_info->param->threshold_notification(
|
||||
ADC_TM_HIGH_STATE,
|
||||
client_info->param->btm_ctx);
|
||||
client_info->notify_high_thr = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Used by non-thermal clients to configure an ADC_TM channel */
|
||||
static int32_t adc_tm7_channel_measure(struct adc_tm_chip *chip,
|
||||
struct adc_tm_param *param)
|
||||
|
||||
{
|
||||
int ret, i;
|
||||
uint32_t v_channel, dt_index = 0;
|
||||
bool chan_found = false;
|
||||
|
||||
ret = adc_tm_is_valid(chip);
|
||||
if (ret || (param == NULL))
|
||||
return -EINVAL;
|
||||
|
||||
if (param->threshold_notification == NULL) {
|
||||
pr_debug("No notification for high/low temp\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < chip->dt_channels; i++) {
|
||||
v_channel = V_CHAN(chip->sensor[i]);
|
||||
if (v_channel == param->channel) {
|
||||
dt_index = i;
|
||||
chan_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!chan_found) {
|
||||
pr_err("not a valid ADC_TM channel\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mutex_lock(&chip->adc_mutex_lock);
|
||||
|
||||
/* add channel client to channel list */
|
||||
adc_tm_add_to_list(chip, dt_index, param);
|
||||
|
||||
/* set right thresholds for the sensor */
|
||||
ret = adc_tm7_manage_thresholds(&chip->sensor[dt_index]);
|
||||
if (ret < 0)
|
||||
pr_err("Error in reverse scaling:%d\n", ret);
|
||||
|
||||
chip->sensor[dt_index].meas_en = ADC_TM_MEAS_EN;
|
||||
|
||||
/* configure channel */
|
||||
ret = adc_tm7_configure(&chip->sensor[dt_index]);
|
||||
if (ret < 0) {
|
||||
pr_err("Error during adc-tm configure:%d\n", ret);
|
||||
goto fail_unlock;
|
||||
}
|
||||
|
||||
ret = adc_tm7_conv_req(chip);
|
||||
if (ret < 0)
|
||||
pr_err("Error enabling adc-tm with %d\n", ret);
|
||||
|
||||
fail_unlock:
|
||||
mutex_unlock(&chip->adc_mutex_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Used by non-thermal clients to release an ADC_TM channel */
|
||||
static int32_t adc_tm7_disable_chan_meas(struct adc_tm_chip *chip,
|
||||
struct adc_tm_param *param)
|
||||
{
|
||||
int ret, i;
|
||||
uint32_t dt_index = 0, v_channel;
|
||||
struct adc_tm_client_info *client_info = NULL;
|
||||
|
||||
ret = adc_tm_is_valid(chip);
|
||||
if (ret || (param == NULL))
|
||||
return -EINVAL;
|
||||
|
||||
for (i = 0; i < chip->dt_channels; i++) {
|
||||
v_channel = V_CHAN(chip->sensor[i]);
|
||||
if (v_channel == param->channel) {
|
||||
dt_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == chip->dt_channels) {
|
||||
pr_err("not a valid ADC_TM channel\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mutex_lock(&chip->adc_mutex_lock);
|
||||
list_for_each_entry(client_info,
|
||||
&chip->sensor[i].thr_list, list) {
|
||||
if (client_info->param->id == param->id) {
|
||||
client_info->state_request =
|
||||
ADC_TM_HIGH_LOW_THR_DISABLE;
|
||||
ret = adc_tm7_manage_thresholds(&chip->sensor[i]);
|
||||
if (ret < 0) {
|
||||
pr_err("Error in reverse scaling:%d\n",
|
||||
ret);
|
||||
goto fail;
|
||||
}
|
||||
ret = adc_tm7_configure(&chip->sensor[i]);
|
||||
if (ret < 0) {
|
||||
pr_err("Error during adc-tm configure:%d\n",
|
||||
ret);
|
||||
goto fail;
|
||||
}
|
||||
ret = adc_tm7_conv_req(chip);
|
||||
if (ret < 0) {
|
||||
pr_err("Error enabling adc-tm with %d\n", ret);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
mutex_unlock(&chip->adc_mutex_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int adc_tm7_set_trip_temp(struct adc_tm_sensor *sensor,
|
||||
int low_temp, int high_temp)
|
||||
{
|
||||
struct adc_tm_chip *chip;
|
||||
struct adc_tm_config tm_config;
|
||||
int ret;
|
||||
|
||||
if (!sensor)
|
||||
return -EINVAL;
|
||||
|
||||
pr_debug("%s:low_temp(mdegC):%d, high_temp(mdegC):%d\n", __func__,
|
||||
low_temp, high_temp);
|
||||
|
||||
chip = sensor->chip;
|
||||
tm_config.high_thr_temp = tm_config.low_thr_temp = 0;
|
||||
if (high_temp != INT_MAX)
|
||||
tm_config.high_thr_temp = high_temp;
|
||||
if (low_temp != INT_MIN)
|
||||
tm_config.low_thr_temp = low_temp;
|
||||
|
||||
if ((high_temp == INT_MAX) && (low_temp == INT_MIN)) {
|
||||
pr_err("No trips to set\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
pr_debug("requested a low temp- %d and high temp- %d\n",
|
||||
tm_config.low_thr_temp, tm_config.high_thr_temp);
|
||||
adc_tm_scale_therm_voltage_100k_adc7(&tm_config);
|
||||
|
||||
pr_debug("high_thr:0x%llx, low_thr:0x%llx\n",
|
||||
tm_config.high_thr_voltage, tm_config.low_thr_voltage);
|
||||
|
||||
mutex_lock(&chip->adc_mutex_lock);
|
||||
|
||||
if (high_temp != INT_MAX) {
|
||||
sensor->low_thr_voltage = tm_config.low_thr_voltage;
|
||||
sensor->low_thr_en = 1;
|
||||
} else
|
||||
sensor->low_thr_en = 0;
|
||||
|
||||
if (low_temp != INT_MIN) {
|
||||
sensor->high_thr_voltage = tm_config.high_thr_voltage;
|
||||
sensor->high_thr_en = 1;
|
||||
} else
|
||||
sensor->high_thr_en = 0;
|
||||
|
||||
sensor->meas_en = ADC_TM_MEAS_EN;
|
||||
|
||||
ret = adc_tm7_configure(sensor);
|
||||
if (ret < 0) {
|
||||
pr_err("Error during adc-tm configure:%d\n", ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = adc_tm7_conv_req(chip);
|
||||
if (ret < 0) {
|
||||
pr_err("Error enabling adc-tm with %d\n", ret);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fail:
|
||||
mutex_unlock(&chip->adc_mutex_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static irqreturn_t adc_tm7_handler(int irq, void *data)
|
||||
{
|
||||
struct adc_tm_chip *chip = data;
|
||||
u8 status_low, status_high, buf[16], val;
|
||||
int ret, i;
|
||||
|
||||
ret = adc_tm_read_reg(chip, ADC_TM_STATUS_LOW_CLR, &status_low, 1);
|
||||
if (ret < 0) {
|
||||
pr_err("adc-tm read status low failed with %d\n", ret);
|
||||
goto handler_end;
|
||||
}
|
||||
|
||||
ret = adc_tm_read_reg(chip, ADC_TM_STATUS_HIGH_CLR, &status_high, 1);
|
||||
if (ret < 0) {
|
||||
pr_err("adc-tm read status high failed with %d\n", ret);
|
||||
goto handler_end;
|
||||
}
|
||||
|
||||
ret = adc_tm_write_reg(chip, ADC_TM_STATUS_LOW_CLR, &status_low, 1);
|
||||
if (ret < 0) {
|
||||
pr_err("adc-tm clear status low failed with %d\n", ret);
|
||||
goto handler_end;
|
||||
}
|
||||
|
||||
ret = adc_tm_write_reg(chip, ADC_TM_STATUS_HIGH_CLR, &status_high, 1);
|
||||
if (ret < 0) {
|
||||
pr_err("adc-tm clear status high failed with %d\n", ret);
|
||||
goto handler_end;
|
||||
}
|
||||
|
||||
val = BIT(0);
|
||||
ret = adc_tm_write_reg(chip, ADC_TM_DATA_HOLD_CTL, &val, 1);
|
||||
if (ret < 0) {
|
||||
pr_err("adc-tm set hold failed with %d\n", ret);
|
||||
goto handler_end;
|
||||
}
|
||||
|
||||
ret = adc_tm_read_reg(chip, ADC_TM_Mn_DATA0(0), buf, 16);
|
||||
if (ret < 0) {
|
||||
pr_err("adc-tm read conversion data failed with %d\n", ret);
|
||||
goto handler_end;
|
||||
}
|
||||
|
||||
val = 0;
|
||||
ret = adc_tm_write_reg(chip, ADC_TM_DATA_HOLD_CTL, &val, 1);
|
||||
if (ret < 0) {
|
||||
pr_err("adc-tm clear hold failed with %d\n", ret);
|
||||
goto handler_end;
|
||||
}
|
||||
|
||||
for (i = 0; i < chip->dt_channels; i++) {
|
||||
bool upper_set = false, lower_set = false;
|
||||
u8 data_low = 0, data_high = 0;
|
||||
u16 code = 0;
|
||||
int temp;
|
||||
|
||||
if (!chip->sensor[i].non_thermal &&
|
||||
IS_ERR(chip->sensor[i].tzd)) {
|
||||
pr_err("thermal device not found\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!chip->sensor[i].non_thermal) {
|
||||
data_low = buf[2 * i];
|
||||
data_high = buf[2 * i + 1];
|
||||
code = ((data_high << ADC_TM_DATA_SHIFT) | data_low);
|
||||
}
|
||||
|
||||
mutex_lock(&chip->adc_mutex_lock);
|
||||
|
||||
if ((status_low & 0x1) && (chip->sensor[i].meas_en)
|
||||
&& (chip->sensor[i].low_thr_en))
|
||||
lower_set = true;
|
||||
|
||||
if ((status_high & 0x1) && (chip->sensor[i].meas_en) &&
|
||||
(chip->sensor[i].high_thr_en))
|
||||
upper_set = true;
|
||||
|
||||
status_low >>= 1;
|
||||
status_high >>= 1;
|
||||
mutex_unlock(&chip->adc_mutex_lock);
|
||||
if (!(upper_set || lower_set))
|
||||
continue;
|
||||
|
||||
if (!chip->sensor[i].non_thermal) {
|
||||
/*
|
||||
* Expected behavior is while notifying
|
||||
* of_thermal, thermal core will call set_trips
|
||||
* with new thresholds and activate/disable
|
||||
* the appropriate trips.
|
||||
*/
|
||||
pr_debug("notifying of_thermal\n");
|
||||
temp = therm_fwd_scale_adc7((int64_t)code);
|
||||
if (temp == -EINVAL) {
|
||||
pr_err("Invalid temperature reading\n");
|
||||
continue;
|
||||
}
|
||||
of_thermal_handle_trip_temp(chip->sensor[i].tzd,
|
||||
temp);
|
||||
} else {
|
||||
if (lower_set) {
|
||||
mutex_lock(&chip->adc_mutex_lock);
|
||||
chip->sensor[i].low_thr_en = 0;
|
||||
chip->sensor[i].low_thr_triggered = true;
|
||||
mutex_unlock(&chip->adc_mutex_lock);
|
||||
queue_work(chip->sensor[i].req_wq,
|
||||
&chip->sensor[i].work);
|
||||
}
|
||||
|
||||
if (upper_set) {
|
||||
mutex_lock(&chip->adc_mutex_lock);
|
||||
chip->sensor[i].high_thr_en = 0;
|
||||
chip->sensor[i].high_thr_triggered = true;
|
||||
mutex_unlock(&chip->adc_mutex_lock);
|
||||
queue_work(chip->sensor[i].req_wq,
|
||||
&chip->sensor[i].work);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handler_end:
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int adc_tm7_register_interrupts(struct adc_tm_chip *chip)
|
||||
{
|
||||
struct platform_device *pdev;
|
||||
int ret, irq;
|
||||
|
||||
if (!chip)
|
||||
return -EINVAL;
|
||||
|
||||
pdev = to_platform_device(chip->dev);
|
||||
|
||||
irq = platform_get_irq_byname(pdev, "thr-int-en");
|
||||
if (irq < 0) {
|
||||
dev_err(&pdev->dev, "failed to get irq %s\n",
|
||||
"thr-int-en");
|
||||
return irq;
|
||||
}
|
||||
|
||||
ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
|
||||
adc_tm7_handler,
|
||||
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
|
||||
"thr-int-en", chip);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "failed to get irq %s\n",
|
||||
"thr-int-en");
|
||||
return ret;
|
||||
}
|
||||
|
||||
enable_irq_wake(irq);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int adc_tm7_init(struct adc_tm_chip *chip, uint32_t dt_chans)
|
||||
{
|
||||
u8 channels_available;
|
||||
int ret;
|
||||
|
||||
ret = adc_tm_read_reg(chip, ADC_TM_NUM_BTM_CHAN,
|
||||
&channels_available, 1);
|
||||
if (ret < 0) {
|
||||
pr_err("read failed for BTM channels\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (dt_chans > channels_available) {
|
||||
pr_err("Number of nodes greater than channels supported:%d\n",
|
||||
channels_available);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mutex_init(&chip->adc_mutex_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int adc_tm7_shutdown(struct adc_tm_chip *chip)
|
||||
{
|
||||
u8 data = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < chip->dt_channels; i++)
|
||||
if (chip->sensor[i].req_wq)
|
||||
destroy_workqueue(chip->sensor[i].req_wq);
|
||||
|
||||
mutex_lock(&chip->adc_mutex_lock);
|
||||
|
||||
adc_tm_write_reg(chip, ADC_TM_EN_CTL1, &data, 1);
|
||||
data = ADC_TM_CONV_REQ_EN;
|
||||
adc_tm_write_reg(chip, ADC_TM_CONV_REQ, &data, 1);
|
||||
|
||||
mutex_unlock(&chip->adc_mutex_lock);
|
||||
|
||||
mutex_destroy(&chip->adc_mutex_lock);
|
||||
|
||||
list_del(&chip->list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct adc_tm_ops ops_adc_tm7 = {
|
||||
.init = adc_tm7_init,
|
||||
.set_trips = adc_tm7_set_trip_temp,
|
||||
.interrupts_reg = adc_tm7_register_interrupts,
|
||||
.get_temp = adc_tm_get_temp,
|
||||
.channel_measure = adc_tm7_channel_measure,
|
||||
.disable_chan = adc_tm7_disable_chan_meas,
|
||||
.notify = notify_adc_tm7_fn,
|
||||
.shutdown = adc_tm7_shutdown,
|
||||
};
|
||||
|
||||
const struct adc_tm_data data_adc_tm7 = {
|
||||
.ops = &ops_adc_tm7,
|
||||
.decimation = (unsigned int []) {85, 340, 1360},
|
||||
.hw_settle = (unsigned int []) {15, 100, 200, 300, 400, 500, 600, 700,
|
||||
1000, 2000, 4000, 8000, 16000, 32000,
|
||||
64000, 128000},
|
||||
};
|
|
@ -59,6 +59,7 @@ enum adc_tm_state_request {
|
|||
};
|
||||
|
||||
struct adc_tm_param {
|
||||
unsigned long id;
|
||||
int low_thr;
|
||||
int high_thr;
|
||||
uint32_t channel;
|
||||
|
@ -75,10 +76,12 @@ int32_t adc_tm5_channel_measure(struct adc_tm_chip *chip,
|
|||
struct adc_tm_param *param);
|
||||
int32_t adc_tm5_disable_chan_meas(struct adc_tm_chip *chip,
|
||||
struct adc_tm_param *param);
|
||||
|
||||
#else
|
||||
static inline struct adc_tm_chip *get_adc_tm(
|
||||
struct device *dev, const char *name)
|
||||
{ return ERR_PTR(-ENXIO); }
|
||||
|
||||
static inline int32_t adc_tm5_channel_measure(
|
||||
struct adc_tm_chip *chip,
|
||||
struct adc_tm_param *param)
|
||||
|
@ -87,6 +90,7 @@ static inline int32_t adc_tm5_disable_chan_meas(
|
|||
struct adc_tm_chip *chip,
|
||||
struct adc_tm_param *param)
|
||||
{ return -ENXIO; }
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __QCOM_ADC_TM_H_CLIENTS__ */
|
||||
|
|
Loading…
Reference in a new issue