diff options
Diffstat (limited to 'drivers/iio/trigger/stm32-timer-trigger.c')
-rw-r--r-- | drivers/iio/trigger/stm32-timer-trigger.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c index 107918b3a90b..d28aa02b85e8 100644 --- a/drivers/iio/trigger/stm32-timer-trigger.c +++ b/drivers/iio/trigger/stm32-timer-trigger.c | |||
@@ -594,13 +594,20 @@ static const char *const stm32_count_direction_states[] = { | |||
594 | 594 | ||
595 | static int stm32_set_count_direction(struct iio_dev *indio_dev, | 595 | static int stm32_set_count_direction(struct iio_dev *indio_dev, |
596 | const struct iio_chan_spec *chan, | 596 | const struct iio_chan_spec *chan, |
597 | unsigned int mode) | 597 | unsigned int dir) |
598 | { | 598 | { |
599 | struct stm32_timer_trigger *priv = iio_priv(indio_dev); | 599 | struct stm32_timer_trigger *priv = iio_priv(indio_dev); |
600 | u32 val; | ||
601 | int mode; | ||
600 | 602 | ||
601 | regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_DIR, mode); | 603 | /* In encoder mode, direction is RO (given by TI1/TI2 signals) */ |
604 | regmap_read(priv->regmap, TIM_SMCR, &val); | ||
605 | mode = (val & TIM_SMCR_SMS) - 1; | ||
606 | if ((mode >= 0) || (mode < ARRAY_SIZE(stm32_quadrature_modes))) | ||
607 | return -EBUSY; | ||
602 | 608 | ||
603 | return 0; | 609 | return regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_DIR, |
610 | dir ? TIM_CR1_DIR : 0); | ||
604 | } | 611 | } |
605 | 612 | ||
606 | static int stm32_get_count_direction(struct iio_dev *indio_dev, | 613 | static int stm32_get_count_direction(struct iio_dev *indio_dev, |
@@ -611,7 +618,7 @@ static int stm32_get_count_direction(struct iio_dev *indio_dev, | |||
611 | 618 | ||
612 | regmap_read(priv->regmap, TIM_CR1, &cr1); | 619 | regmap_read(priv->regmap, TIM_CR1, &cr1); |
613 | 620 | ||
614 | return (cr1 & TIM_CR1_DIR); | 621 | return ((cr1 & TIM_CR1_DIR) ? 1 : 0); |
615 | } | 622 | } |
616 | 623 | ||
617 | static const struct iio_enum stm32_count_direction_enum = { | 624 | static const struct iio_enum stm32_count_direction_enum = { |