drivers: Counter: Fix LPTMR prescaler setting not work issue

In current code, if timer-mode-sel is 0(Timer Counter Mode),
bypass_prescaler_glitch will be 1, that makes prescaler setting
be bypassed. But this setting is very useful, especially for
long timing count.

In this patch, we update prescale-glitch-filter default value to 0,
to indicate prescaler and glitch filter are disabled, which comply
the existing devices DTS setting (prescaler = 1).
And if user sets prescale-glitch-filter properity other than 0,
we should set bypass_prescaler_glitch to false to make prescaler work,
and the clock frequence should be calculated with prescaler setting.

Update prescaler field in dt-bindings to tell developer should use
prescale-glitch-filter instead.

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
This commit is contained in:
Felix Wang
2025-08-29 18:25:40 +08:00
committed by Chris Friedt
parent fac2034dc1
commit eb785ef63b
2 changed files with 24 additions and 15 deletions

View File

@@ -187,19 +187,21 @@ static DEVICE_API(counter, mcux_lptmr_driver_api) = {
.max_top_value = \
GENMASK(DT_INST_PROP(n, resolution) - 1, 0), \
.freq = DT_INST_PROP(n, clock_frequency) / \
DT_INST_PROP(n, prescaler), \
BIT(DT_INST_PROP(n, prescale_glitch_filter)), \
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
.channels = 0, \
}, \
.base = (LPTMR_Type *)DT_INST_REG_ADDR(n), \
.clk_source = DT_INST_PROP(n, clk_source), \
.bypass_prescaler_glitch = \
1 - DT_INST_PROP(n, timer_mode_sel), \
.bypass_prescaler_glitch = (DT_INST_PROP(n, \
prescale_glitch_filter) == 0), \
.mode = DT_INST_PROP(n, timer_mode_sel), \
.pin = DT_INST_PROP_OR(n, input_pin, 0), \
.polarity = DT_INST_PROP(n, active_low), \
.prescaler_glitch = DT_INST_PROP(n, prescale_glitch_filter) + \
DT_INST_PROP(n, timer_mode_sel) - 1, \
.prescaler_glitch = (DT_INST_PROP(n, \
prescale_glitch_filter) == 0) ? 0 : DT_INST_PROP(n, \
prescale_glitch_filter) + DT_INST_PROP(n, \
timer_mode_sel) - 1, \
.irq_config_func = mcux_lptmr_irq_config_##n, \
}; \
\
@@ -209,5 +211,4 @@ static DEVICE_API(counter, mcux_lptmr_driver_api) = {
POST_KERNEL, CONFIG_COUNTER_INIT_PRIORITY, \
&mcux_lptmr_driver_api);
DT_INST_FOREACH_STATUS_OKAY(COUNTER_MCUX_LPTMR_DEVICE_INIT)

View File

@@ -16,8 +16,12 @@ properties:
description: Counter clock frequency
prescaler:
required: true
description: The frequency of the counter is divided by this value.
type: int
deprecated: true
description: |
This property has been deprecated and replaced by prescale-glitch-filter.
It no longer has any functional impact. Any value assigned to this property
will be disregarded. Consequently, the prescaler will be bypassed.
clk-source:
type: int
@@ -50,15 +54,19 @@ properties:
prescale-glitch-filter:
type: int
default: 1
enum: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
default: 0
enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
description: |
When in prescaler mode, the counter is incremented every
When in prescaler mode, if prescale-glitch-filter is 0, the prescaler
is bypassed, the selected prescaler clock increments Counter (CNR) on every
clock cycle. Otherwise the counter is incremented every
2 ^ [prescaler-glitch-filter] clock cycles.
When in pulse mode, the counter is incremented every
2 ^ [prescaler-glitch-filter] rising edges detected
by the pin configured from the input-pin value.
Note, that the pulse mode cannot be 2 ^ 16.
When in pulse mode, if prescale-glitch-filter is 0, the glitch filter
is bypassed, the selected input source increments the value of Counter(CNR)
every time it asserts. Otherwise the counter is incremented every
2 ^ [prescaler-glitch-filter] rising edges detected by the pin configured
from the input-pin value.
Note, that the pulse mode cannot be 2 ^ 16.
timer-mode-sel:
type: int