diff options
author | Fabrice Gasnier <fabrice.gasnier@st.com> | 2017-07-27 18:18:57 +0200 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2017-07-30 15:43:10 +0200 |
commit | 50b39608efb1e60f334f9b59128fd6d970bfd5a6 (patch) | |
tree | 7e3403479f4e4fac29105478f9d53b2f08ad3a6b /drivers | |
parent | iio: bmp280: properly initialize device for humidity reading (diff) | |
download | linux-50b39608efb1e60f334f9b59128fd6d970bfd5a6.tar.xz linux-50b39608efb1e60f334f9b59128fd6d970bfd5a6.zip |
iio: trigger: stm32-timer: fix quadrature mode get routine
Fixes: 4adec7da0536 ("iio: stm32 trigger: Add quadrature encoder device")
SMS bitfiled is mode + 1. After reset, upon boot, SMS = 0. When reading
from sysfs, stm32_get_quadrature_mode() returns -1 (e.g. -EPERM) which is
wrong error code here. So, check SMS bitfiled matches valid encoder mode,
or return -EINVAL.
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Acked-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/iio/trigger/stm32-timer-trigger.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c index d22bc56dd9fc..6aa73d6b2882 100644 --- a/drivers/iio/trigger/stm32-timer-trigger.c +++ b/drivers/iio/trigger/stm32-timer-trigger.c @@ -571,11 +571,14 @@ static int stm32_get_quadrature_mode(struct iio_dev *indio_dev, { struct stm32_timer_trigger *priv = iio_priv(indio_dev); u32 smcr; + int mode; regmap_read(priv->regmap, TIM_SMCR, &smcr); - smcr &= TIM_SMCR_SMS; + mode = (smcr & TIM_SMCR_SMS) - 1; + if ((mode < 0) || (mode > ARRAY_SIZE(stm32_quadrature_modes))) + return -EINVAL; - return smcr - 1; + return mode; } static const struct iio_enum stm32_quadrature_mode_enum = { |