iio: trigger: stm32-timer: enable clock when in master mode
authorFabrice Gasnier <fabrice.gasnier@st.com>
Fri, 14 Feb 2020 16:23:57 +0000 (17:23 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 8 Mar 2020 17:28:35 +0000 (17:28 +0000)
commit3192ade7b6f6306b66139109e0d455f98a7f695f
tree13e67ca5df29483979999cb0ebd1ff3ec0e91b10
parent9c088c020d8181a0c8376444b740c99366eec04d
iio: trigger: stm32-timer: enable clock when in master mode

Clock should be enabled as soon as using master modes, even before
enabling timer. Or, this may provoke bad behavior on the other end
(slave timer). Then, introduce 'clk_enabled' flag, instead of relying
on CR1 EN bit, to keep track of clock being enabled (balanced refcount).
Propagate this anywhere else in the driver.

Also add 'remove' routine to stop timer and disable clock in case it
has been left enabled. Enforce the user interface has been unregistered
in the remove routine, before disabling the hardware to avoid possible
race. So, remove use of devm_ variant to register triggers and unregister
them before the hardware gets disabled [1].
[1] https://patchwork.kernel.org/patch/9956247/

Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/trigger/stm32-timer-trigger.c