public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* Counter device Interface for reading out input capture
@ 2020-11-05 18:46 Ahmad Fatoum
  2020-11-06  9:11 ` Fabrice Gasnier
  2020-11-06 12:42 ` William Breathitt Gray
  0 siblings, 2 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2020-11-05 18:46 UTC (permalink / raw)
  To: Benjamin Gaignard, Fabrice Gasnier
  Cc: Pengutronix Kernel Team, Holger Assmann,
	linux-stm32@st-md-mailman.stormreply.com, Alexandre Torgue,
	linux-iio, William Breathitt Gray

Hello Benjamin,
Hello Fabrice,

In the stm32-timer-cnt driver I find unused #defines for TIM_CCMR_MASK and
TIM_CCER_MASK, which to me hint that support for the "input capture mode"[1]
was implemented but removed prior to upstreaming.

It doesn't look like the counter device API is yet made to support such
an input capture mode (latching a counter value on an external event, e.g.
to timestamp incoming rising edges to measure jitter between pulses).

I am still very new to this, so I figured I ask whether you already have
thoughts (or maybe code to share) on how to best integrate this with the
counter device API.

I've added linux-iio/linux-stm32 to the CC as well, so if someone else
has an idea how to best do this, please share.

[1]: 40.3.7 in RM0436 rev 3

Cheers,
Ahmad

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Counter device Interface for reading out input capture
  2020-11-05 18:46 Counter device Interface for reading out input capture Ahmad Fatoum
@ 2020-11-06  9:11 ` Fabrice Gasnier
  2020-11-06 17:16   ` Holger Assmann
  2020-11-06 12:42 ` William Breathitt Gray
  1 sibling, 1 reply; 6+ messages in thread
From: Fabrice Gasnier @ 2020-11-06  9:11 UTC (permalink / raw)
  To: Ahmad Fatoum
  Cc: Pengutronix Kernel Team, Holger Assmann,
	linux-stm32@st-md-mailman.stormreply.com, Alexandre Torgue,
	linux-iio, William Breathitt Gray

Hi Ahmad,

On 11/5/20 7:46 PM, Ahmad Fatoum wrote:
> Hello Benjamin,
> Hello Fabrice,
> 
> In the stm32-timer-cnt driver I find unused #defines for TIM_CCMR_MASK and
> TIM_CCER_MASK, which to me hint that support for the "input capture mode"[1]
> was implemented but removed prior to upstreaming.

Indeed, I'm not sure why such defines have been added in
stm32-timer-cnt. They could probably be removed (and are possibly
redundant with other definitions in STM32 PWM/capture driver...)

> 
> It doesn't look like the counter device API is yet made to support such
> an input capture mode (latching a counter value on an external event, e.g.
> to timestamp incoming rising edges to measure jitter between pulses).

Regarding recent updates for the counter device API, maybe William could
bring some hints (I haven't checked or had time to follow this up :-().

> 
> I am still very new to this, so I figured I ask whether you already have
> thoughts (or maybe code to share) on how to best integrate this with the
> counter device API.

FYI, The only use of the STM32 timer input capture mode currently
implemented (in STM32 timer Linux drivers) is through the PWM capture
interface (drivers/pwm/pwm-stm32.c).
It's using 40.3.8 PWM input mode which is a particular case of input
capture mode you point in [1].
Not sure if this can help for time-stamping (at best as code example?).

One though I have is: a particular timer will be able to do either
quadrature encoder or input capture... So likely timestamping would
require an additional timer. But I haven't really checked how this could
be implemented in the hardware or driver.

May I ask a bit more information regarding your needs here?

Regards,
Fabrice
> 
> I've added linux-iio/linux-stm32 to the CC as well, so if someone else
> has an idea how to best do this, please share.
> 
> [1]: 40.3.7 in RM0436 rev 3
> 
> Cheers,
> Ahmad
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Counter device Interface for reading out input capture
  2020-11-05 18:46 Counter device Interface for reading out input capture Ahmad Fatoum
  2020-11-06  9:11 ` Fabrice Gasnier
@ 2020-11-06 12:42 ` William Breathitt Gray
  2020-11-17 10:54   ` Ahmad Fatoum
  1 sibling, 1 reply; 6+ messages in thread
From: William Breathitt Gray @ 2020-11-06 12:42 UTC (permalink / raw)
  To: Ahmad Fatoum
  Cc: Benjamin Gaignard, Fabrice Gasnier, Pengutronix Kernel Team,
	Holger Assmann, linux-stm32@st-md-mailman.stormreply.com,
	Alexandre Torgue, linux-iio

[-- Attachment #1: Type: text/plain, Size: 1942 bytes --]

On Thu, Nov 05, 2020 at 07:46:14PM +0100, Ahmad Fatoum wrote:
> Hello Benjamin,
> Hello Fabrice,
> 
> In the stm32-timer-cnt driver I find unused #defines for TIM_CCMR_MASK and
> TIM_CCER_MASK, which to me hint that support for the "input capture mode"[1]
> was implemented but removed prior to upstreaming.
> 
> It doesn't look like the counter device API is yet made to support such
> an input capture mode (latching a counter value on an external event, e.g.
> to timestamp incoming rising edges to measure jitter between pulses).
> 
> I am still very new to this, so I figured I ask whether you already have
> thoughts (or maybe code to share) on how to best integrate this with the
> counter device API.
> 
> I've added linux-iio/linux-stm32 to the CC as well, so if someone else
> has an idea how to best do this, please share.
> 
> [1]: 40.3.7 in RM0436 rev 3
> 
> Cheers,
> Ahmad
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

Hi Ahmad,

Regarding the Counter subsystem, I'm developing a Counter character
device API that supports timestamps for counter devices:
https://lore.kernel.org/linux-arm-kernel/157d1edf-feec-33b5-7ad5-94f99316ca6e@lechnology.com/T/

My aim is to get this functionality picked up for the Linux 5.11 merge
window. I have one more revision at least that should be ready in a
couple weeks -- I'll CC you for that patchset to keep you in the loop;
I force-push periodically to my personal repo when as I develop, so you
can take a look at the current state of this next revision if you're
curious:
https://gitlab.com/vilhelmgray/iio/-/tree/counter_chrdev_v6

Sincerely,

William Breathitt Gray

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Counter device Interface for reading out input capture
  2020-11-06  9:11 ` Fabrice Gasnier
@ 2020-11-06 17:16   ` Holger Assmann
  0 siblings, 0 replies; 6+ messages in thread
From: Holger Assmann @ 2020-11-06 17:16 UTC (permalink / raw)
  To: Fabrice Gasnier, Ahmad Fatoum
  Cc: Pengutronix Kernel Team, linux-stm32@st-md-mailman.stormreply.com,
	Alexandre Torgue, linux-iio, William Breathitt Gray

Hello Fabrice,

On Fri, Nov 06, 2020 at 10:11:07 +0100, Fabrice Gasnier wrote:
> May I ask a bit more information regarding your needs here?

We basically want to latch the current counter value into the
respective Capture/Compare Register when a pulse occurs at the
corresponding ICx input.
Our goal is to measure the jitter (and timing offset) between two or
more data lines which are supposed to carry the same signal at the
same time. Every line is thus connected to one of the four channels.

 From my understanding the PWM capture interface already goes into the
right direction, although we obviously require to utilize more than
one channel of the timer (and in return only need one C/C Register
per channel). I will therefore take your hint and have a closer look
at the pwm-stm32.c - thanks!

Regards,
Holger

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Counter device Interface for reading out input capture
  2020-11-06 12:42 ` William Breathitt Gray
@ 2020-11-17 10:54   ` Ahmad Fatoum
  2020-11-17 12:25     ` William Breathitt Gray
  0 siblings, 1 reply; 6+ messages in thread
From: Ahmad Fatoum @ 2020-11-17 10:54 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Benjamin Gaignard, Fabrice Gasnier, Pengutronix Kernel Team,
	Holger Assmann, linux-stm32@st-md-mailman.stormreply.com,
	Alexandre Torgue, linux-iio

Hello William,

On 06.11.20 13:42, William Breathitt Gray wrote:
> On Thu, Nov 05, 2020 at 07:46:14PM +0100, Ahmad Fatoum wrote:
>> It doesn't look like the counter device API is yet made to support such
>> an input capture mode (latching a counter value on an external event, e.g.
>> to timestamp incoming rising edges to measure jitter between pulses).
>
> Regarding the Counter subsystem, I'm developing a Counter character
> device API that supports timestamps for counter devices:
> https://lore.kernel.org/linux-arm-kernel/157d1edf-feec-33b5-7ad5-94f99316ca6e@lechnology.com/T/

Any chance we could have a "raw" timestamp as well like the network
stack offers (cf. SOF_TIMESTAMPING_{RAW,SYS}_HARDWARE)?

The API currently only exposes a ktime (i.e. CLOCK_MONOTONIC), which the
raw timer count can't be readily converted to. For our use case of
measuring jitter, the raw value is sufficient.

> My aim is to get this functionality picked up for the Linux 5.11 merge
> window. I have one more revision at least that should be ready in a
> couple weeks -- I'll CC you for that patchset to keep you in the loop;
> I force-push periodically to my personal repo when as I develop, so you
> can take a look at the current state of this next revision if you're
> curious:
> https://gitlab.com/vilhelmgray/iio/-/tree/counter_chrdev_v6

Great. Looking forward to see this merged.

Thanks,
Ahmad

> 
> Sincerely,
> 
> William Breathitt Gray
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Counter device Interface for reading out input capture
  2020-11-17 10:54   ` Ahmad Fatoum
@ 2020-11-17 12:25     ` William Breathitt Gray
  0 siblings, 0 replies; 6+ messages in thread
From: William Breathitt Gray @ 2020-11-17 12:25 UTC (permalink / raw)
  To: Ahmad Fatoum
  Cc: Benjamin Gaignard, Fabrice Gasnier, Pengutronix Kernel Team,
	Holger Assmann, linux-stm32@st-md-mailman.stormreply.com,
	Alexandre Torgue, linux-iio

[-- Attachment #1: Type: text/plain, Size: 1298 bytes --]

On Tue, Nov 17, 2020 at 11:54:17AM +0100, Ahmad Fatoum wrote:
> Hello William,
> 
> On 06.11.20 13:42, William Breathitt Gray wrote:
> > On Thu, Nov 05, 2020 at 07:46:14PM +0100, Ahmad Fatoum wrote:
> >> It doesn't look like the counter device API is yet made to support such
> >> an input capture mode (latching a counter value on an external event, e.g.
> >> to timestamp incoming rising edges to measure jitter between pulses).
> >
> > Regarding the Counter subsystem, I'm developing a Counter character
> > device API that supports timestamps for counter devices:
> > https://lore.kernel.org/linux-arm-kernel/157d1edf-feec-33b5-7ad5-94f99316ca6e@lechnology.com/T/
> 
> Any chance we could have a "raw" timestamp as well like the network
> stack offers (cf. SOF_TIMESTAMPING_{RAW,SYS}_HARDWARE)?
> 
> The API currently only exposes a ktime (i.e. CLOCK_MONOTONIC), which the
> raw timer count can't be readily converted to. For our use case of
> measuring jitter, the raw value is sufficient.

Sure, we can add support for a "raw" timestamp. I can see how this could
be more useful in certain circumstances rather than the ktime value.
I'll open a discussion about it when I submit the next revision of the
Counter character device patchset. :-)

William Breathitt Gray

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-17 12:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-05 18:46 Counter device Interface for reading out input capture Ahmad Fatoum
2020-11-06  9:11 ` Fabrice Gasnier
2020-11-06 17:16   ` Holger Assmann
2020-11-06 12:42 ` William Breathitt Gray
2020-11-17 10:54   ` Ahmad Fatoum
2020-11-17 12:25     ` William Breathitt Gray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox