Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: d0f949e220fd ("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>

authored by

Fabrice Gasnier and committed by
Lee Jones
4917e498 10d82ade

+6 -1
+6 -1
drivers/mfd/stm32-timers.c
··· 158 158 159 159 static void stm32_timers_get_arr_size(struct stm32_timers *ddata) 160 160 { 161 + u32 arr; 162 + 163 + /* Backup ARR to restore it after getting the maximum value */ 164 + regmap_read(ddata->regmap, TIM_ARR, &arr); 165 + 161 166 /* 162 167 * Only the available bits will be written so when readback 163 168 * we get the maximum value of auto reload register 164 169 */ 165 170 regmap_write(ddata->regmap, TIM_ARR, ~0L); 166 171 regmap_read(ddata->regmap, TIM_ARR, &ddata->max_arr); 167 - regmap_write(ddata->regmap, TIM_ARR, 0x0); 172 + regmap_write(ddata->regmap, TIM_ARR, arr); 168 173 } 169 174 170 175 static int stm32_timers_dma_probe(struct device *dev,