From f7797dda8fd6de421cad2b3675580ad00739a5a2 Mon Sep 17 00:00:00 2001 From: Dragos Bogdan Date: Thu, 25 Jan 2018 15:42:21 +0200 Subject: [PATCH] iio: ad9361: Make sure the part is in the desired ENSM ad9361_ensm_force_state() should verify if the part is really in the desired ENSM state before exit. Otherwise, other operations that are executed afterwards may fail. Signed-off-by: Dragos Bogdan --- drivers/iio/adc/ad9361.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ad9361.c b/drivers/iio/adc/ad9361.c index d84c492c62a834..d27670fc975c6a 100644 --- a/drivers/iio/adc/ad9361.c +++ b/drivers/iio/adc/ad9361.c @@ -1582,7 +1582,7 @@ void ad9361_ensm_force_state(struct ad9361_rf_phy *phy, u8 ensm_state) struct spi_device *spi = phy->spi; struct device *dev = &phy->spi->dev; u8 dev_ensm_state; - int rc; + int rc, timeout = 10; u32 val; dev_ensm_state = ad9361_spi_readf(spi, REG_STATE, ENSM_STATE(~0)); @@ -1635,7 +1635,16 @@ void ad9361_ensm_force_state(struct ad9361_rf_phy *phy, u8 ensm_state) ad9361_spi_write(spi, REG_ENSM_CONFIG_1, TO_ALERT | FORCE_ALERT_STATE); rc = ad9361_spi_write(spi, REG_ENSM_CONFIG_1, val); - if (rc) + if (rc) { + dev_err(dev, "Failed to write ENSM_CONFIG_1\n"); + goto out; + } + + while (ad9361_ensm_get_state(phy) != ensm_state && --timeout) { + mdelay(1); + } + + if (timeout == 0) dev_err(dev, "Failed to restore state\n"); out: