mfd: stm32-timers: Avoid clearing auto reload register

The ARR register is cleared unconditionally upon probing, after the maximum
value has been read. This initial condition is rather not intuitive, when
considering the counter child driver. It rather expects the maximum value
by default:
- The counter interface shows a zero value by default for 'ceiling'
  attribute.
- Enabling the counter without any prior configuration makes it doesn't
  count.

The reset value of ARR register is the maximum. So Choice here
is to backup it, and restore it then, instead of clearing its value.
It also fixes the initial condition seen by the counter driver.

Fixes: d0f949e220 ("mfd: Add STM32 Timers driver")
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
This commit is contained in:
Fabrice Gasnier 2021-03-03 18:51:35 +01:00 committed by Lee Jones
parent 10d82ade4f
commit 4917e498c6

View File

@ -158,13 +158,18 @@ static const struct regmap_config stm32_timers_regmap_cfg = {
static void stm32_timers_get_arr_size(struct stm32_timers *ddata) static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
{ {
u32 arr;
/* Backup ARR to restore it after getting the maximum value */
regmap_read(ddata->regmap, TIM_ARR, &arr);
/* /*
* Only the available bits will be written so when readback * Only the available bits will be written so when readback
* we get the maximum value of auto reload register * we get the maximum value of auto reload register
*/ */
regmap_write(ddata->regmap, TIM_ARR, ~0L); regmap_write(ddata->regmap, TIM_ARR, ~0L);
regmap_read(ddata->regmap, TIM_ARR, &ddata->max_arr); regmap_read(ddata->regmap, TIM_ARR, &ddata->max_arr);
regmap_write(ddata->regmap, TIM_ARR, 0x0); regmap_write(ddata->regmap, TIM_ARR, arr);
} }
static int stm32_timers_dma_probe(struct device *dev, static int stm32_timers_dma_probe(struct device *dev,