[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <93ce1511-53f6-42a3-b1a5-b6732105e87d@prolan.hu>
Date: Wed, 5 Mar 2025 11:50:27 +0100
From: Csókás Bence <csokas.bence@...lan.hu>
To: William Breathitt Gray <wbg@...nel.org>, Kamel Bouhara
<kamel.bouhara@...tlin.com>
CC: <linux-arm-kernel@...ts.infradead.org>, <linux-iio@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] counter: microchip-tcb-capture: Fix undefined counter
channel state on probe
Hi,
thanks for fixing this up!
On 2025. 03. 05. 11:01, William Breathitt Gray wrote:
> Hardware initialize of the timer counter channel does not occur on probe
> thus leaving the Count in an undefined state until the first
> function_write() callback is executed. Fix this by performing the proper
> hardware initialization during probe.
>
> Fixes: 106b104137fd ("counter: Add microchip TCB capture counter")
> Reported-by: Csókás Bence <csokas.bence@...lan.hu>
> Closes: https://lore.kernel.org/all/bfa70e78-3cc3-4295-820b-3925c26135cb@prolan.hu/
> Signed-off-by: William Breathitt Gray <wbg@...nel.org>
> ---
> This should fix the issue where a user needs to set the count function
> before they can use the counter. I don't have this hardware in person,
> so please test this patch and let me know whether it works for you.
> ---
> drivers/counter/microchip-tcb-capture.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c
> index 2f096a5b973d18edf5de5a2b33f2f72571deefb7..c391ac38b990939c6764a9120a4bd03289f68469 100644
> --- a/drivers/counter/microchip-tcb-capture.c
> +++ b/drivers/counter/microchip-tcb-capture.c
> @@ -368,6 +368,25 @@ static int mchp_tc_probe(struct platform_device *pdev)
> channel);
> }
>
> + /* Disable Quadrature Decoder and position measure */
> + ret = regmap_update_bits(regmap, ATMEL_TC_BMR, ATMEL_TC_QDEN | ATMEL_TC_POSEN, 0);
> + if (ret)
> + return ret;
> +
> + /* Setup the period capture mode */
> + ret = regmap_update_bits(regmap, ATMEL_TC_REG(priv->channel[0], CMR),
> + ATMEL_TC_WAVE | ATMEL_TC_ABETRG | ATMEL_TC_CMR_MASK |
> + ATMEL_TC_TCCLKS,
> + ATMEL_TC_CMR_MASK);
> + if (ret)
> + return ret;
> +
> + /* Enable clock and trigger counter */
> + ret = regmap_write(regmap, ATMEL_TC_REG(priv->channel[0], CCR),
> + ATMEL_TC_CLKEN | ATMEL_TC_SWTRG);
> + if (ret)
> + return ret;
> +
This duplicates a lot of `mchp_tc_count_function_write()`. I'd much
rather have this code in a separate function called something like
`mchp_tc_setup_channels()`, that, depending on `priv->qdec_mode`, sets
up the BMR, CCR and CMRs, and then have both probe() and
function_write() call it. Or alternatively, have probe() call
function_write() at the end, but that's not as nice.
> ---
> base-commit: 8744dcd4fc7800de2eb9369410470bb2930d4c14
> change-id: 20250305-preset-capture-mode-microchip-tcb-capture-fa31550ef594
>
> Best regards,
Bence
Powered by blists - more mailing lists