• Martin Blumenstingl's avatar
    iio: adc: meson-saradc: fix the bit_idx of the adc_en clock · 7a6b0420
    Martin Blumenstingl authored
    Meson8 and Meson8b SoCs use the the SAR ADC gate clock provided by the
    MESON_SAR_ADC_REG3 register within the SAR ADC register area.
    According to the datasheet (and the existing MESON_SAR_ADC_REG3_CLK_EN
    definition) the gate is on bit 30.
    The fls() function returns the last set bit, which is "bit index + 1"
    (fls(MESON_SAR_ADC_REG3_CLK_EN) returns 31). Fix this by switching to
    __ffs() which returns the first set bit, which is bit 30 in our case.
    
    This off by one error results in the ADC not being usable on devices
    where the bootloader did not enable the clock.
    
    Fixes: 3adbf342 ("iio: adc: add a driver for the SAR ADC found in Amlogic Meson SoCs")
    Signed-off-by: default avatarMartin Blumenstingl <martin.blumenstingl@googlemail.com>
    Cc: <Stable@vger.kernel.org>
    Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
    7a6b0420
meson_saradc.c 31.6 KB