hwmon: qpnp-adc: Add scaling support for PMI CHG channel
The voltage measured by the HKADC is related to the junction temperature and scaled by the following equation tj = -138.89degC * (v_adc * 2) + 391.75degC Change-Id: Ibd6185c3926f9f5e482b3990adff3eee61e7caa5 Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
This commit is contained in:
parent
cc9702b094
commit
9ed5a165d2
|
@ -35,6 +35,8 @@
|
|||
#define QPNP_VADC_LDO_VOLTAGE_MAX 1800000
|
||||
#define QPNP_VADC_OK_VOLTAGE_MIN 1000000
|
||||
#define QPNP_VADC_OK_VOLTAGE_MAX 1000000
|
||||
#define PMI_CHG_SCALE_1 -138890
|
||||
#define PMI_CHG_SCALE_2 391750000000
|
||||
|
||||
/* Units for temperature below (on x axis) is in 0.1DegC as
|
||||
required by the battery driver. Note the resolution used
|
||||
|
@ -1841,6 +1843,30 @@ int32_t qpnp_adc_smb_btm_rscaler(struct qpnp_vadc_chip *chip,
|
|||
}
|
||||
EXPORT_SYMBOL(qpnp_adc_smb_btm_rscaler);
|
||||
|
||||
int32_t qpnp_adc_scale_pmi_chg_temp(struct qpnp_vadc_chip *vadc,
|
||||
int32_t adc_code,
|
||||
const struct qpnp_adc_properties *adc_properties,
|
||||
const struct qpnp_vadc_chan_properties *chan_properties,
|
||||
struct qpnp_vadc_result *adc_chan_result)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
rc = qpnp_adc_scale_default(vadc, adc_code, adc_properties,
|
||||
chan_properties, adc_chan_result);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
pr_debug("raw_code:%x, v_adc:%lld\n", adc_code,
|
||||
adc_chan_result->physical);
|
||||
adc_chan_result->physical = ((PMI_CHG_SCALE_1) *
|
||||
(adc_chan_result->physical * 2));
|
||||
adc_chan_result->physical += PMI_CHG_SCALE_2;
|
||||
do_div(adc_chan_result->physical, 1000000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(qpnp_adc_scale_pmi_chg_temp);
|
||||
|
||||
int32_t qpnp_adc_enable_voltage(struct qpnp_adc_drv *adc)
|
||||
{
|
||||
int rc = 0;
|
||||
|
|
|
@ -175,6 +175,7 @@ static struct qpnp_vadc_scale_fn vadc_scale_fn[] = {
|
|||
[SCALE_QRD_SKUC_BATT_THERM] = {qpnp_adc_scale_qrd_skuc_batt_therm},
|
||||
[SCALE_QRD_SKUE_BATT_THERM] = {qpnp_adc_scale_qrd_skue_batt_therm},
|
||||
[SCALE_QRD_SKUL_BATT_THERM] = {qpnp_adc_scale_qrd_skul_batt_therm},
|
||||
[SCALE_PMI_CHG_TEMP] = {qpnp_adc_scale_pmi_chg_temp},
|
||||
};
|
||||
|
||||
static struct qpnp_vadc_rscale_fn adc_vadc_rscale_fn[] = {
|
||||
|
|
|
@ -261,6 +261,7 @@ enum qpnp_adc_channel_scaling_param {
|
|||
* btm parameters for SKUE
|
||||
* %SCALE_QRD_SKUL_BATT_THERM: Conversion to temperature(decidegC) based on
|
||||
* btm parameters for SKUL
|
||||
* %SCALE_PMI_CHG_TEMP: Conversion for PMI CHG temp
|
||||
* %SCALE_NONE: Do not use this scaling type.
|
||||
*/
|
||||
enum qpnp_adc_scale_fn_type {
|
||||
|
@ -280,6 +281,7 @@ enum qpnp_adc_scale_fn_type {
|
|||
SCALE_QRD_SKUC_BATT_THERM,
|
||||
SCALE_QRD_SKUE_BATT_THERM,
|
||||
SCALE_QRD_SKUL_BATT_THERM,
|
||||
SCALE_PMI_CHG_TEMP,
|
||||
SCALE_NONE,
|
||||
};
|
||||
|
||||
|
@ -1179,6 +1181,25 @@ int32_t qpnp_adc_scale_pmic_therm(struct qpnp_vadc_chip *dev,
|
|||
const struct qpnp_adc_properties *adc_prop,
|
||||
const struct qpnp_vadc_chan_properties *chan_prop,
|
||||
struct qpnp_vadc_result *chan_rslt);
|
||||
/**
|
||||
* qpnp_adc_scale_pmi_chg_temp() - Scales the pre-calibrated digital output
|
||||
* of an ADC to the ADC reference and compensates for the
|
||||
* gain and offset. The voltage measured by HKADC is related to
|
||||
* the junction temperature according to
|
||||
* Tj = -137.67 degC * (V_adc * 2) + 382.04 degC
|
||||
* @dev: Structure device for qpnp vadc
|
||||
* @adc_code: pre-calibrated digital ouput of the ADC.
|
||||
* @adc_prop: adc properties of the qpnp adc such as bit resolution,
|
||||
* reference voltage.
|
||||
* @chan_prop: Individual channel properties to compensate the i/p scaling,
|
||||
* slope and offset.
|
||||
* @chan_rslt: Physical result to be stored.
|
||||
*/
|
||||
int32_t qpnp_adc_scale_pmi_chg_temp(struct qpnp_vadc_chip *dev,
|
||||
int32_t adc_code,
|
||||
const struct qpnp_adc_properties *adc_prop,
|
||||
const struct qpnp_vadc_chan_properties *chan_prop,
|
||||
struct qpnp_vadc_result *chan_rslt);
|
||||
/**
|
||||
* qpnp_adc_scale_batt_therm() - Scales the pre-calibrated digital output
|
||||
* of an ADC to the ADC reference and compensates for the
|
||||
|
@ -1765,6 +1786,12 @@ static inline int32_t qpnp_adc_scale_pmic_therm(struct qpnp_vadc_chip *vadc,
|
|||
const struct qpnp_vadc_chan_properties *chan_prop,
|
||||
struct qpnp_vadc_result *chan_rslt)
|
||||
{ return -ENXIO; }
|
||||
static inline int32_t qpnp_adc_scale_pmi_chg_temp(struct qpnp_vadc_chip *vadc,
|
||||
int32_t adc_code,
|
||||
const struct qpnp_adc_properties *adc_prop,
|
||||
const struct qpnp_vadc_chan_properties *chan_prop,
|
||||
struct qpnp_vadc_result *chan_rslt)
|
||||
{ return -ENXIO; }
|
||||
static inline int32_t qpnp_adc_scale_batt_therm(struct qpnp_vadc_chip *vadc,
|
||||
int32_t adc_code,
|
||||
const struct qpnp_adc_properties *adc_prop,
|
||||
|
|
Loading…
Reference in New Issue