linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: William Breathitt Gray <william.gray@linaro.org>
To: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Cc: lee@kernel.org, alexandre.torgue@foss.st.com,
	linux-iio@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 10/10] counter: stm32-timer-cnt: add support for capture events
Date: Mon, 8 Jan 2024 22:07:09 +0000	[thread overview]
Message-ID: <ZZxyDbYC9oHNKcGF@ubuntu-server-vm-macos> (raw)
In-Reply-To: <20231220145726.640627-11-fabrice.gasnier@foss.st.com>


[-- Attachment #1.1: Type: text/plain, Size: 3375 bytes --]

On Wed, Dec 20, 2023 at 03:57:26PM +0100, Fabrice Gasnier wrote:
> +	/*
> +	 * configure channel in input capture mode, map channel 1 on TI1, channel2 on TI2...
> +	 * Select both edges / non-inverted to trigger a capture.
> +	 */

I suggest defining a new local variable 'cc' to point to stm32_cc[ch]. I
think that's make the code look nicer here to avoid all the array index
syntax every time you access stm32_cc[ch].

> +	if (enable) {
> +		/* first clear possibly latched capture flag upon enabling */
> +		regmap_read(priv->regmap, TIM_CCER, &ccer);
> +		if (!(ccer & stm32_cc[ch].ccer_bits)) {

Try regmap_test_bits() here instead of using regmap_read().

> +			sr = ~TIM_SR_CC_IF(ch);
> +			regmap_write(priv->regmap, TIM_SR, sr);

Eliminate 'sr' by regmap_write(priv->regmap, TIM_SR, ~TIM_SR_CC_IF(ch)).

> @@ -366,6 +460,12 @@ static int stm32_count_events_configure(struct counter_device *counter)
>  				regmap_write(priv->regmap, TIM_SR, (u32)~TIM_SR_UIF);
>  			dier |= TIM_DIER_UIE;
>  			break;
> +		case COUNTER_EVENT_CAPTURE:
> +			ret = stm32_count_capture_configure(counter, event_node->channel, true);
> +			if (ret)
> +				return ret;
> +			dier |= TIM_DIER_CC_IE(event_node->channel);

Ah, now I understand why the previous patch OR'd TIM_DIER_UIE to dier.
Apologies for the noise.

> @@ -374,6 +474,15 @@ static int stm32_count_events_configure(struct counter_device *counter)
>  
>  	regmap_write(priv->regmap, TIM_DIER, dier);
>  
> +	/* check for disabled capture events */
> +	for (i = 0 ; i < priv->nchannels; i++) {
> +		if (!(dier & TIM_DIER_CC_IE(i))) {
> +			ret = stm32_count_capture_configure(counter, i, false);
> +			if (ret)
> +				return ret;
> +		}

Would for_each_clear_bitrange() in linux/find.h work for this loop?

> @@ -504,7 +620,7 @@ static irqreturn_t stm32_timer_cnt_isr(int irq, void *ptr)
>  	 * Some status bits in SR don't match with the enable bits in DIER. Only take care of
>  	 * the possibly enabled bits in DIER (that matches in between SR and DIER).
>  	 */
> -	dier &= TIM_DIER_UIE;
> +	dier &= (TIM_DIER_UIE | TIM_DIER_CC1IE | TIM_DIER_CC2IE | TIM_DIER_CC3IE | TIM_DIER_CC4IE);

Again, sorry for the noise on the previous patch; this makes sense now.

> @@ -515,6 +631,15 @@ static irqreturn_t stm32_timer_cnt_isr(int irq, void *ptr)
>  		clr &= ~TIM_SR_UIF;
>  	}
>  
> +	/* Check capture events */
> +	for (i = 0 ; i < priv->nchannels; i++) {
> +		if (sr & TIM_SR_CC_IF(i)) {

Would for_each_set_bitrange() in linux/find.h work for this loop?

> +			counter_push_event(counter, COUNTER_EVENT_CAPTURE, i);
> +			clr &= ~TIM_SR_CC_IF(i);

Perhaps u32p_replace_bits(&clr, 0, TIM_SR_CC_IF(i)) is clearer here.

> @@ -627,8 +752,11 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev)
>  		}
>  	} else {
>  		for (i = 0; i < priv->nr_irqs; i++) {
> -			/* Only take care of update IRQ for overflow events */
> -			if (i != STM32_TIMERS_IRQ_UP)
> +			/*
> +			 * Only take care of update IRQ for overflow events, and cc for
> +			 * capture events.
> +			 */
> +			if (i != STM32_TIMERS_IRQ_UP && i != STM32_TIMERS_IRQ_CC)
>  				continue;

Okay, I see now why you have this check. This should be fine as it'll
makes adding support in the future for the other IRQs a less invasive
change.

William Breathitt Gray

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2024-01-08 22:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-20 14:57 [PATCH v3 00/10] counter: Add stm32 timer events support Fabrice Gasnier
2023-12-20 14:57 ` [PATCH v3 01/10] counter: stm32-timer-cnt: rename quadrature signal Fabrice Gasnier
2024-01-08 16:33   ` William Breathitt Gray
2023-12-20 14:57 ` [PATCH v3 02/10] counter: stm32-timer-cnt: rename counter Fabrice Gasnier
2024-01-08 16:34   ` William Breathitt Gray
2023-12-20 14:57 ` [PATCH v3 03/10] counter: stm32-timer-cnt: adopt signal definitions Fabrice Gasnier
2024-01-08 16:34   ` William Breathitt Gray
2023-12-20 14:57 ` [PATCH v3 04/10] counter: stm32-timer-cnt: introduce clock signal Fabrice Gasnier
2024-01-08 16:46   ` William Breathitt Gray
2024-02-27 17:43     ` Fabrice Gasnier
2024-02-29 18:58       ` William Breathitt Gray
2023-12-20 14:57 ` [PATCH v3 05/10] counter: stm32-timer-cnt: add counter prescaler extension Fabrice Gasnier
2024-01-08 16:48   ` William Breathitt Gray
2023-12-20 14:57 ` [PATCH v3 06/10] counter: stm32-timer-cnt: add checks on quadrature encoder capability Fabrice Gasnier
2024-01-08 16:59   ` William Breathitt Gray
2023-12-20 14:57 ` [PATCH v3 07/10] counter: stm32-timer-cnt: introduce channels Fabrice Gasnier
2024-01-08 17:21   ` William Breathitt Gray
2023-12-20 14:57 ` [PATCH v3 08/10] counter: stm32-timer-cnt: probe number of channels from registers Fabrice Gasnier
2024-01-08 17:25   ` William Breathitt Gray
2023-12-20 14:57 ` [PATCH v3 09/10] counter: stm32-timer-cnt: add support for overflow events Fabrice Gasnier
2024-01-08 21:00   ` William Breathitt Gray
2024-02-27 17:43     ` Fabrice Gasnier
2024-01-08 21:06   ` William Breathitt Gray
2023-12-20 14:57 ` [PATCH v3 10/10] counter: stm32-timer-cnt: add support for capture events Fabrice Gasnier
2024-01-08 22:07   ` William Breathitt Gray [this message]
2024-02-27 17:43     ` Fabrice Gasnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZZxyDbYC9oHNKcGF@ubuntu-server-vm-macos \
    --to=william.gray@linaro.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).