]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
iio: adc: xilinx-ams: Fix single channel switching sequence
authorRobert Hancock <robert.hancock@calian.com>
Thu, 27 Jan 2022 17:34:50 +0000 (11:34 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 11:57:15 +0000 (13:57 +0200)
commit 0bf126163c3e7e6d722622073046aed567a5551e upstream.

Some of the AMS channels need to be read by switching into single-channel
mode from the normal polling sequence. There was a logic issue in this
switching code that could cause the first read of these channels to read
back as zero.

It appears that the sequencer should be set back to default mode before
changing the channel selection, and the channel should be set before
switching the sequencer back into single-channel mode.

Also, write 1 to the EOC bit in the status register to clear it before
waiting for it to become set, so that we actually wait for a new
conversion to complete, and don't proceed based on a previous conversion
completing.

Fixes: d5c70627a794 ("iio: adc: Add Xilinx AMS driver")
Signed-off-by: Robert Hancock <robert.hancock@calian.com>
Acked-by: Michal Simek <michal.simek@xilinx.com>
Link: https://lore.kernel.org/r/20220127173450.3684318-5-robert.hancock@calian.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iio/adc/xilinx-ams.c

index 8343c5f74121ec7f9baf6524a6268908894c80cd..14f852fd4d880add43ac7fd4d3a5e25f09b3370a 100644 (file)
@@ -530,14 +530,18 @@ static int ams_enable_single_channel(struct ams *ams, unsigned int offset)
                return -EINVAL;
        }
 
-       /* set single channel, sequencer off mode */
+       /* put sysmon in a soft reset to change the sequence */
        ams_ps_update_reg(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MASK,
-                         AMS_CONF1_SEQ_SINGLE_CHANNEL);
+                         AMS_CONF1_SEQ_DEFAULT);
 
        /* write the channel number */
        ams_ps_update_reg(ams, AMS_REG_CONFIG0, AMS_CONF0_CHANNEL_NUM_MASK,
                          channel_num);
 
+       /* set single channel, sequencer off mode */
+       ams_ps_update_reg(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MASK,
+                         AMS_CONF1_SEQ_SINGLE_CHANNEL);
+
        return 0;
 }
 
@@ -551,6 +555,8 @@ static int ams_read_vcc_reg(struct ams *ams, unsigned int offset, u32 *data)
        if (ret)
                return ret;
 
+       /* clear end-of-conversion flag, wait for next conversion to complete */
+       writel(expect, ams->base + AMS_ISR_1);
        ret = readl_poll_timeout(ams->base + AMS_ISR_1, reg, (reg & expect),
                                 AMS_INIT_POLL_TIME_US, AMS_INIT_TIMEOUT_US);
        if (ret)