Merge "hwmon: qpnp-adc-common: Clamp voltage value"
This commit is contained in:
commit
e7f64f186c
1 changed files with 12 additions and 0 deletions
|
@ -39,6 +39,8 @@
|
||||||
#define PMI_CHG_SCALE_2 391750000000
|
#define PMI_CHG_SCALE_2 391750000000
|
||||||
#define QPNP_VADC_HC_VREF_CODE 0x4000
|
#define QPNP_VADC_HC_VREF_CODE 0x4000
|
||||||
#define QPNP_VADC_HC_VDD_REFERENCE_MV 1875
|
#define QPNP_VADC_HC_VDD_REFERENCE_MV 1875
|
||||||
|
/* Clamp negative ADC code to 0 */
|
||||||
|
#define QPNP_VADC_HC_MAX_CODE 0x7FFF
|
||||||
|
|
||||||
/* Units for temperature below (on x axis) is in 0.1DegC as
|
/* Units for temperature below (on x axis) is in 0.1DegC as
|
||||||
required by the battery driver. Note the resolution used
|
required by the battery driver. Note the resolution used
|
||||||
|
@ -752,6 +754,8 @@ int32_t qpnp_adc_scale_pmic_therm(struct qpnp_vadc_chip *vadc,
|
||||||
|
|
||||||
if (adc_properties->adc_hc) {
|
if (adc_properties->adc_hc) {
|
||||||
/* (ADC code * vref_vadc (1.875V)) / 0x4000 */
|
/* (ADC code * vref_vadc (1.875V)) / 0x4000 */
|
||||||
|
if (adc_code > QPNP_VADC_HC_MAX_CODE)
|
||||||
|
adc_code = 0;
|
||||||
pmic_voltage = (int64_t) adc_code;
|
pmic_voltage = (int64_t) adc_code;
|
||||||
pmic_voltage *= (int64_t) (adc_properties->adc_vdd_reference
|
pmic_voltage *= (int64_t) (adc_properties->adc_vdd_reference
|
||||||
* 1000);
|
* 1000);
|
||||||
|
@ -862,6 +866,8 @@ int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *chip,
|
||||||
|
|
||||||
if (adc_properties->adc_hc) {
|
if (adc_properties->adc_hc) {
|
||||||
/* (ADC code * vref_vadc (1.875V) * 1000) / (0x4000 * 1000) */
|
/* (ADC code * vref_vadc (1.875V) * 1000) / (0x4000 * 1000) */
|
||||||
|
if (adc_code > QPNP_VADC_HC_MAX_CODE)
|
||||||
|
adc_code = 0;
|
||||||
xo_thm_voltage = (int64_t) adc_code;
|
xo_thm_voltage = (int64_t) adc_code;
|
||||||
xo_thm_voltage *= (int64_t) (adc_properties->adc_vdd_reference
|
xo_thm_voltage *= (int64_t) (adc_properties->adc_vdd_reference
|
||||||
* 1000);
|
* 1000);
|
||||||
|
@ -1059,6 +1065,8 @@ int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *chip,
|
||||||
|
|
||||||
if (adc_properties->adc_hc) {
|
if (adc_properties->adc_hc) {
|
||||||
/* (ADC code * vref_vadc (1.875V) * 1000) / (0x4000 * 1000) */
|
/* (ADC code * vref_vadc (1.875V) * 1000) / (0x4000 * 1000) */
|
||||||
|
if (adc_code > QPNP_VADC_HC_MAX_CODE)
|
||||||
|
adc_code = 0;
|
||||||
therm_voltage = (int64_t) adc_code;
|
therm_voltage = (int64_t) adc_code;
|
||||||
therm_voltage *= (int64_t) (adc_properties->adc_vdd_reference
|
therm_voltage *= (int64_t) (adc_properties->adc_vdd_reference
|
||||||
* 1000);
|
* 1000);
|
||||||
|
@ -1094,6 +1102,8 @@ int32_t qpnp_adc_tm_scale_voltage_therm_pu2(struct qpnp_vadc_chip *chip,
|
||||||
|
|
||||||
if (adc_properties->adc_hc) {
|
if (adc_properties->adc_hc) {
|
||||||
/* (ADC code * vref_vadc (1.875V)) / 0x4000 */
|
/* (ADC code * vref_vadc (1.875V)) / 0x4000 */
|
||||||
|
if (reg > QPNP_VADC_HC_MAX_CODE)
|
||||||
|
reg = 0;
|
||||||
adc_voltage = (int64_t) reg;
|
adc_voltage = (int64_t) reg;
|
||||||
adc_voltage *= QPNP_VADC_HC_VDD_REFERENCE_MV;
|
adc_voltage *= QPNP_VADC_HC_VDD_REFERENCE_MV;
|
||||||
adc_voltage = div64_s64(adc_voltage,
|
adc_voltage = div64_s64(adc_voltage,
|
||||||
|
@ -1228,6 +1238,8 @@ int32_t qpnp_adc_scale_default(struct qpnp_vadc_chip *vadc,
|
||||||
|
|
||||||
if (adc_properties->adc_hc) {
|
if (adc_properties->adc_hc) {
|
||||||
/* (ADC code * vref_vadc (1.875V)) / 0x4000 */
|
/* (ADC code * vref_vadc (1.875V)) / 0x4000 */
|
||||||
|
if (adc_code > QPNP_VADC_HC_MAX_CODE)
|
||||||
|
adc_code = 0;
|
||||||
scale_voltage = (int64_t) adc_code;
|
scale_voltage = (int64_t) adc_code;
|
||||||
scale_voltage *= (adc_properties->adc_vdd_reference * 1000);
|
scale_voltage *= (adc_properties->adc_vdd_reference * 1000);
|
||||||
scale_voltage = div64_s64(scale_voltage,
|
scale_voltage = div64_s64(scale_voltage,
|
||||||
|
|
Loading…
Add table
Reference in a new issue