Skip to contentSkip to conversation

Patch "iio: stm32 trigger: fix sampling_frequency read" has been added to the 4.11-stable tree

PATCH [email protected] 1 participant 1 message May 22, 2017

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

iio: stm32 trigger: fix sampling_frequency read

to the 4.11-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
iio-stm32-trigger-fix-sampling_frequency-read.patch
and it can be found in the queue-4.11 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From 77a9febfd81f9e8550d09dc76e8e9c06307b7aca Mon Sep 17 00:00:00 2001

From: Fabrice Gasnier <[email protected]>
Date: Fri, 7 Apr 2017 13:53:46 +0200
Subject: iio: stm32 trigger: fix sampling_frequency read

From: Fabrice Gasnier <[email protected]>

commit 77a9febfd81f9e8550d09dc76e8e9c06307b7aca upstream.

When prescaler (PSC) is 0, it means div factor is 1: counter clock frequency is equal to input clk / (PSC + 1).
When reload value is 8 for example, counter counts 9 cycles, from 0 to 8. This is handled in frequency write routine, by writing respectively:
- prescaler - 1 to PSC
- reload value - 1 to ARR
This fix does the opposite when reading the frequency from PSC and ARR:
- prescaler is PSC + 1
- reload value is ARR + 1

Thus, PSC may be 0, depending on requested sampling frequency (div 1). In this case, reading freq wrongly reports 0, instead of computing and reporting correct value.
Remove test on !psc and !arr.

Small test on stm32f4 (example on tim1_trgo), before this fix:

$ cd /sys/bus/iio/devices/triggerX
$ echo 10000 > sampling_frequency
$ cat sampling_frequency
0

After this fix:

$ echo 10000 > sampling_frequency
$ cat sampling_frequency
10000
---
 drivers/iio/trigger/stm32-timer-trigger.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/trigger/stm32-timer-trigger.c +3 -3
@@ -152,10 +152,10 @@ static ssize_t stm32_tt_read_frequency(s
 	regmap_read(priv->regmap, TIM_PSC, &psc);
 	regmap_read(priv->regmap, TIM_ARR, &arr);
 
-	if (psc && arr && (cr1 & TIM_CR1_CEN)) {
+	if (cr1 & TIM_CR1_CEN) {
 		freq = (unsigned long long)clk_get_rate(priv->clk);
-		do_div(freq, psc);
-		do_div(freq, arr);
+		do_div(freq, psc + 1);
+		do_div(freq, arr + 1);
 	}
 
 	return sprintf(buf, "%d\n", (unsigned int)freq);

Patches currently in stable-queue which might be from [email protected] are

queue-4.11/iio-stm32-trigger-fix-sampling_frequency-read.patch