Skip to content

Commit dc55b6a

Browse files
author
Jishnu Prakash
committed
drivers: hwmon: Add support for bat_therm on adc_tm for QM215
Add reverse scaling function for bat_therm for QM215 which uses 2800mAh battery. Change-Id: I9bf4ce9aa451d9c363adfd3b4b78093fa1634495 Signed-off-by: Jishnu Prakash <[email protected]>
1 parent 2453552 commit dc55b6a

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

drivers/hwmon/qpnp-adc-common.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,19 @@ int32_t qpnp_adc_batt_therm_qrd(struct qpnp_vadc_chip *chip,
12631263
qpnp_adc_map_voltage_temp(adcmap_batt_therm_qrd,
12641264
ARRAY_SIZE(adcmap_batt_therm_qrd),
12651265
batt_thm_voltage, &adc_chan_result->physical);
1266+
} else {
1267+
1268+
qpnp_adc_scale_with_calib_param(adc_code,
1269+
adc_properties, chan_properties, &batt_thm_voltage);
1270+
1271+
adc_chan_result->measurement = batt_thm_voltage;
1272+
1273+
return qpnp_adc_map_voltage_temp(
1274+
adcmap_batt_therm_qrd,
1275+
ARRAY_SIZE(adcmap_batt_therm_qrd),
1276+
batt_thm_voltage,
1277+
&adc_chan_result->physical);
1278+
12661279
}
12671280
return 0;
12681281
}
@@ -2152,6 +2165,64 @@ int32_t qpnp_adc_qrd_skut1_btm_scaler(struct qpnp_vadc_chip *chip,
21522165
}
21532166
EXPORT_SYMBOL(qpnp_adc_qrd_skut1_btm_scaler);
21542167

2168+
int32_t qpnp_adc_qrd_215_btm_scaler(struct qpnp_vadc_chip *chip,
2169+
struct qpnp_adc_tm_btm_param *param,
2170+
uint32_t *low_threshold, uint32_t *high_threshold)
2171+
{
2172+
struct qpnp_vadc_linear_graph btm_param;
2173+
int64_t low_output = 0, high_output = 0;
2174+
int rc = 0;
2175+
2176+
if (param->adc_tm_hc) {
2177+
pr_debug("Update scaling for VADC_TM_HC\n");
2178+
return -EINVAL;
2179+
}
2180+
2181+
qpnp_get_vadc_gain_and_offset(chip, &btm_param, CALIB_RATIOMETRIC);
2182+
2183+
pr_debug("warm_temp:%d and cool_temp:%d\n", param->high_temp,
2184+
param->low_temp);
2185+
rc = qpnp_adc_map_voltage_temp(
2186+
adcmap_batt_therm_qrd,
2187+
ARRAY_SIZE(adcmap_batt_therm_qrd),
2188+
(param->low_temp),
2189+
&low_output);
2190+
if (rc) {
2191+
pr_debug("low_temp mapping failed with %d\n", rc);
2192+
return rc;
2193+
}
2194+
2195+
pr_debug("low_output:%lld\n", low_output);
2196+
low_output *= btm_param.dy;
2197+
low_output = div64_s64(low_output, btm_param.adc_vref);
2198+
low_output += btm_param.adc_gnd;
2199+
2200+
rc = qpnp_adc_map_voltage_temp(
2201+
adcmap_batt_therm_qrd,
2202+
ARRAY_SIZE(adcmap_batt_therm_qrd),
2203+
(param->high_temp),
2204+
&high_output);
2205+
if (rc) {
2206+
pr_debug("high temp mapping failed with %d\n", rc);
2207+
return rc;
2208+
}
2209+
2210+
pr_debug("high_output:%lld\n", high_output);
2211+
high_output *= btm_param.dy;
2212+
high_output = div64_s64(high_output, btm_param.adc_vref);
2213+
high_output += btm_param.adc_gnd;
2214+
2215+
/* btm low temperature correspondes to high voltage threshold */
2216+
*low_threshold = high_output;
2217+
/* btm high temperature correspondes to low voltage threshold */
2218+
*high_threshold = low_output;
2219+
2220+
pr_debug("high_volt:%d, low_volt:%d\n", *high_threshold,
2221+
*low_threshold);
2222+
return 0;
2223+
}
2224+
EXPORT_SYMBOL(qpnp_adc_qrd_215_btm_scaler);
2225+
21552226
int32_t qpnp_adc_smb_btm_rscaler(struct qpnp_vadc_chip *chip,
21562227
struct qpnp_adc_tm_btm_param *param,
21572228
uint32_t *low_threshold, uint32_t *high_threshold)

drivers/thermal/qpnp-adc-tm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ static struct qpnp_adc_tm_reverse_scale_fn adc_tm_rscale_fn[] = {
361361
[SCALE_R_ABSOLUTE] = {qpnp_adc_absolute_rthr},
362362
[SCALE_QRD_SKUH_RBATT_THERM] = {qpnp_adc_qrd_skuh_btm_scaler},
363363
[SCALE_QRD_SKUT1_RBATT_THERM] = {qpnp_adc_qrd_skut1_btm_scaler},
364+
[SCALE_QRD_215_RBATT_THERM] = {qpnp_adc_qrd_215_btm_scaler},
364365
};
365366

366367
static int32_t qpnp_adc_tm_read_reg(struct qpnp_adc_tm_chip *chip,

include/linux/qpnp/qpnp-adc.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ enum qpnp_adc_tm_rscale_fn_type {
455455
SCALE_R_ABSOLUTE,
456456
SCALE_QRD_SKUH_RBATT_THERM,
457457
SCALE_QRD_SKUT1_RBATT_THERM,
458+
SCALE_QRD_215_RBATT_THERM,
458459
SCALE_RSCALE_NONE,
459460
};
460461

@@ -1887,6 +1888,22 @@ int32_t qpnp_adc_qrd_skuh_btm_scaler(struct qpnp_vadc_chip *dev,
18871888
int32_t qpnp_adc_qrd_skut1_btm_scaler(struct qpnp_vadc_chip *dev,
18881889
struct qpnp_adc_tm_btm_param *param,
18891890
uint32_t *low_threshold, uint32_t *high_threshold);
1891+
/**
1892+
* qpnp_adc_qrd_215_btm_scaler() - Performs reverse calibration on the
1893+
* low/high temperature threshold values passed by the client.
1894+
* The function maps the temperature to voltage and applies
1895+
* ratiometric calibration on the voltage values for SKUT1 board.
1896+
* @dev: Structure device for qpnp vadc
1897+
* @param: The input parameters that contain the low/high temperature
1898+
* values.
1899+
* @low_threshold: The low threshold value that needs to be updated with
1900+
* the above calibrated voltage value.
1901+
* @high_threshold: The low threshold value that needs to be updated with
1902+
* the above calibrated voltage value.
1903+
*/
1904+
int32_t qpnp_adc_qrd_215_btm_scaler(struct qpnp_vadc_chip *dev,
1905+
struct qpnp_adc_tm_btm_param *param,
1906+
uint32_t *low_threshold, uint32_t *high_threshold);
18901907
/**
18911908
* qpnp_adc_tm_scale_therm_voltage_pu2() - Performs reverse calibration
18921909
* and convert given temperature to voltage on supported
@@ -2279,6 +2296,10 @@ static inline int32_t qpnp_adc_qrd_skut1_btm_scaler(struct qpnp_vadc_chip *dev,
22792296
struct qpnp_adc_tm_btm_param *param,
22802297
uint32_t *low_threshold, uint32_t *high_threshold)
22812298
{ return -ENXIO; }
2299+
static inline int32_t qpnp_adc_qrd_215_btm_scaler(struct qpnp_vadc_chip *dev,
2300+
struct qpnp_adc_tm_btm_param *param,
2301+
uint32_t *low_threshold, uint32_t *high_threshold)
2302+
{ return -ENXIO; }
22822303
static inline int32_t qpnp_adc_scale_millidegc_pmic_voltage_thr(
22832304
struct qpnp_vadc_chip *dev,
22842305
struct qpnp_adc_tm_btm_param *param,

0 commit comments

Comments
 (0)