• Fabrice Gasnier's avatar
    iio: adc: stm32-adc: fix runtime autosuspend delay when slow polling · c537d345
    Fabrice Gasnier authored
    When the ADC is runtime suspended and starting a conversion, the stm32-adc
    driver calls pm_runtime_get_sync() that gets cascaded to the parent
    (e.g. runtime resume of stm32-adc-core driver). This also kicks the
    autosuspend delay (e.g. 2s) of the parent.
    Once the ADC is active, calling pm_runtime_get_sync() again (upon a new
    capture) won't kick the autosuspend delay for the parent (stm32-adc-core
    driver) as already active.
    
    Currently, this makes the stm32-adc-core driver go in suspend state
    every 2s when doing slow polling. As an example, doing a capture, e.g.
    cat in_voltageY_raw at a 0.2s rate, the auto suspend delay for the parent
    isn't refreshed. Once it expires, the parent immediately falls into
    runtime suspended state, in between two captures, as soon as the child
    driver falls into runtime suspend state:
    - e.g. after 2s, + child calls pm_runtime_put_autosuspend() + 100ms
      autosuspend delay of the child.
    - stm32-adc-core switches off regulators, clocks and so on.
    - They get switched on back again 100ms later in this example (at 2.2s).
    
    So, use runtime_idle() callback in stm32-adc-core driver to call
    pm_runtime_mark_last_busy() for the parent driver (stm32-adc-core),
    to avoid this.
    
    Fixes: 9bdbb113 ("iio: adc: stm32-adc: add power management support")
    Signed-off-by: default avatarFabrice Gasnier <fabrice.gasnier@st.com>
    Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
    Link: https://lore.kernel.org/r/1593615328-5180-1-git-send-email-fabrice.gasnier@st.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
    c537d345
stm32-adc-core.c 22.1 KB