• Fabrice Gasnier's avatar
    iio: stm32 trigger: fix sampling_frequency read · 77a9febf
    Fabrice Gasnier authored
    When prescaler (PSC) is 0, it means div factor is 1: counter clock
    frequency is equal to input clk / (PSC + 1).
    When reload value is 8 for example, counter counts 9 cycles, from 0 to 8.
    This is handled in frequency write routine, by writing respectively:
    - prescaler - 1 to PSC
    - reload value - 1 to ARR
    This fix does the opposite when reading the frequency from PSC and ARR:
    - prescaler is PSC + 1
    - reload value is ARR + 1
    
    Thus, PSC may be 0, depending on requested sampling frequency (div 1).
    In this case, reading freq wrongly reports 0, instead of computing and
    reporting correct value.
    Remove test on !psc and !arr.
    
    Small test on stm32f4 (example on tim1_trgo), before this fix:
    $ cd /sys/bus/iio/devices/triggerX
    $ echo 10000 > sampling_frequency
    $ cat sampling_frequency
    0
    
    After this fix:
    $ echo 10000 > sampling_frequency
    $ cat sampling_frequency
    10000
    Signed-off-by: default avatarFabrice Gasnier <fabrice.gasnier@st.com>
    Cc: <Stable@vger.kernel.org>
    Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
    77a9febf
stm32-timer-trigger.c 8.27 KB