]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
counter: stm32-lptimer-cnt: fix error handling when enabling
authorFabrice Gasnier <fabrice.gasnier@foss.st.com>
Mon, 24 Feb 2025 17:06:57 +0000 (18:06 +0100)
committerWilliam Breathitt Gray <wbg@kernel.org>
Tue, 4 Mar 2025 10:23:02 +0000 (19:23 +0900)
commit8744dcd4fc7800de2eb9369410470bb2930d4c14
tree5d7870b02c72dffdcaa1b7c1e5a63f0e5fd6cab6
parent2014c95afecee3e76ca4a56956a936e23283f05b
counter: stm32-lptimer-cnt: fix error handling when enabling

In case the stm32_lptim_set_enable_state() fails to update CMP and ARR,
a timeout error is raised, by regmap_read_poll_timeout. It may happen,
when the lptimer runs on a slow clock, and the clock is gated only
few times during the polling.

Badly, when this happen, STM32_LPTIM_ENABLE in CR register has been set.
So the 'enable' state in sysfs wrongly lies on the counter being
correctly enabled, due to CR is read as one in stm32_lptim_is_enabled().

To fix both issues:
- enable the clock before writing CMP, ARR and polling ISR bits. It will
avoid the possible timeout error.
- clear the ENABLE bit in CR and disable the clock in the error path.

Fixes: d8958824cf07 ("iio: counter: Add support for STM32 LPTimer")
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Link: https://lore.kernel.org/r/20250224170657.3368236-1-fabrice.gasnier@foss.st.com
Signed-off-by: William Breathitt Gray <wbg@kernel.org>
drivers/counter/stm32-lptimer-cnt.c