hwmon: qpnp-adc-current: Add div0 error checks during calibration
Add error checks to avoid div0 condition during periodic
gain/offset calibration and print more debug info
of the gain and offet while we are here.
Change-Id: I2b8431efa21eb9fe685455286f32fc825b924bee
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
diff --git a/drivers/hwmon/qpnp-adc-current.c b/drivers/hwmon/qpnp-adc-current.c
index e4a9e30..2017c8d 100644
--- a/drivers/hwmon/qpnp-adc-current.c
+++ b/drivers/hwmon/qpnp-adc-current.c
@@ -391,10 +391,13 @@
struct qpnp_iadc_drv *iadc = qpnp_iadc;
uint32_t num = 0;
- num = iadc->adc->calib.offset_raw - iadc->adc->calib.offset_raw;
+ if ((iadc->adc->calib.gain_raw - iadc->adc->calib.offset_raw) == 0) {
+ pr_err("raw offset errors! raw_gain:0x%x and raw_offset:0x%x\n",
+ iadc->adc->calib.gain_raw, iadc->adc->calib.offset_raw);
+ return -EINVAL;
+ }
- iadc->adc->calib.offset_uv = (num * QPNP_ADC_GAIN_NV)/
- (iadc->adc->calib.gain_raw - iadc->adc->calib.offset_raw);
+ iadc->adc->calib.offset_uv = 0;
num = iadc->adc->calib.gain_raw - iadc->adc->calib.offset_raw;
@@ -437,6 +440,10 @@
}
rc = qpnp_convert_raw_offset_voltage();
+ if (rc < 0) {
+ pr_err("qpnp raw_voltage conversion failed\n");
+ goto fail;
+ }
rslt_msb = (raw_data & QPNP_RAW_CODE_16_BIT_MSB_MASK) >>
QPNP_BIT_SHIFT_8;
@@ -558,7 +565,7 @@
{
struct qpnp_iadc_drv *iadc = qpnp_iadc;
struct qpnp_vadc_result result_pmic_therm;
- int rc;
+ int rc = 0;
rc = qpnp_vadc_read(DIE_TEMP, &result_pmic_therm);
if (rc < 0)
@@ -572,7 +579,7 @@
pr_err("periodic IADC calibration failed\n");
}
- return 0;
+ return rc;
}
int32_t qpnp_iadc_read(enum qpnp_iadc_channels channel,