hwmon: qpnp-adc-current: Disable IADC bank on the error path
Disable the IADC bank on the error path. If the end of conversion
bit is not set some of the status registers are collected. After
collecting them, disable the bank to avoid keeping the bank
enabled all the time. The bank is disabled on the success path
when the result is read.
Change-Id: Ie3e7497bc4b1497e5db5c7b4374debaf8dbd9f5c
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 8071687e..760b164 100644
--- a/drivers/hwmon/qpnp-adc-current.c
+++ b/drivers/hwmon/qpnp-adc-current.c
@@ -171,6 +171,48 @@
return 0;
}
+static void trigger_iadc_completion(struct work_struct *work)
+{
+ struct qpnp_iadc_drv *iadc = qpnp_iadc;
+
+ complete(&iadc->adc->adc_rslt_completion);
+
+ return;
+}
+DECLARE_WORK(trigger_iadc_completion_work, trigger_iadc_completion);
+
+static irqreturn_t qpnp_iadc_isr(int irq, void *dev_id)
+{
+ schedule_work(&trigger_iadc_completion_work);
+
+ return IRQ_HANDLED;
+}
+
+static int32_t qpnp_iadc_enable(bool state)
+{
+ int rc = 0;
+ u8 data = 0;
+
+ data = QPNP_IADC_ADC_EN;
+ if (state) {
+ rc = qpnp_iadc_write_reg(QPNP_IADC_EN_CTL1,
+ data);
+ if (rc < 0) {
+ pr_err("IADC enable failed\n");
+ return rc;
+ }
+ } else {
+ rc = qpnp_iadc_write_reg(QPNP_IADC_EN_CTL1,
+ (~data & QPNP_IADC_ADC_EN));
+ if (rc < 0) {
+ pr_err("IADC disable failed\n");
+ return rc;
+ }
+ }
+
+ return 0;
+}
+
static int32_t qpnp_iadc_status_debug(void)
{
int rc = 0;
@@ -209,46 +251,10 @@
pr_err("EOC not set with status:%x, dig:%x, ch:%x, mode:%x, en:%x\n",
status1, dig, chan, mode, en);
- return 0;
-}
-
-static void trigger_iadc_completion(struct work_struct *work)
-{
- struct qpnp_iadc_drv *iadc = qpnp_iadc;
-
- complete(&iadc->adc->adc_rslt_completion);
-
- return;
-}
-DECLARE_WORK(trigger_iadc_completion_work, trigger_iadc_completion);
-
-static irqreturn_t qpnp_iadc_isr(int irq, void *dev_id)
-{
- schedule_work(&trigger_iadc_completion_work);
-
- return IRQ_HANDLED;
-}
-
-static int32_t qpnp_iadc_enable(bool state)
-{
- int rc = 0;
- u8 data = 0;
-
- data = QPNP_IADC_ADC_EN;
- if (state) {
- rc = qpnp_iadc_write_reg(QPNP_IADC_EN_CTL1,
- data);
- if (rc < 0) {
- pr_err("IADC enable failed\n");
- return rc;
- }
- } else {
- rc = qpnp_iadc_write_reg(QPNP_IADC_EN_CTL1,
- (~data & QPNP_IADC_ADC_EN));
- if (rc < 0) {
- pr_err("IADC disable failed\n");
- return rc;
- }
+ rc = qpnp_iadc_enable(false);
+ if (rc < 0) {
+ pr_err("IADC disable failed with %d\n", rc);
+ return rc;
}
return 0;