timestamp.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: "Csókás Bence" <csokas.bence@prolan.hu>
To: <linux-iio@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<timestamp@lists.linux.dev>
Cc: William Breathitt Gray <wbg@kernel.org>,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Dipen Patel" <dipenp@nvidia.com>
Subject: [Q] Frequency & duty cycle measurement?
Date: Tue, 21 Jan 2025 16:19:27 +0100	[thread overview]
Message-ID: <f2ec8a55-42ad-498a-b793-072444dcb92e@prolan.hu> (raw)

Hi all,

we want to measure the frequency and duty cycle of a signal (relating to 
power consumption) using a hardware timer in our SoC (Microchip 
SAMA5D2). The hardware is capable of taking a snapshot of the timer 
value into another dedicated register pair (RA, RB) on the 
rising/falling edges, and a small `devmem`-based userspace utility was 
created as a working PoC. Now we want to move to a "proper" kernelspace 
solution.

However, none of the existing drivers seem to be able to do this; the 
closest was `drivers/counter/microchip-tcb-capture.c`, but that only 
seems to count one type of edge (rising/falling), and cannot give us the 
time between them, which would be needed for duty cycle calculation. The 
only other driver I could find was 
`drivers/clocksource/timer-atmel-tcb.c`, which again seems incapable of 
such measurements. Therefore, a new module will probably be needed; the 
question then becomes: which API to implement.

As `microchip-tcb-capture.c` uses the Generic Counter Interface, that 
was obviously a first stop. However, from what I could see, you can only 
represent (1) the number of times an edge has been encountered, and (2) 
rotary encodings (quadrature and direction-step decoders); and not the 
time between edges.

IIO_ALTVOLTAGE and IIO_CHAN_INFO_FREQUENCY/_PHASE also seemed promising 
(although the lack of IIO_CHAN_INFO_DUTY_CYCLE already posed a problem), 
until I saw that all current drivers are frequency *generators*, and not 
measurers, the latter seems to be completely unimplemented.

The only other contender I could find was the Hardware Timestamping 
Engine (HTE), but again, it's not clear whether (1) the API is even 
capable of relaying duty cycle information to userspace and (2) if it 
is, how would one go about implementing it.

It is also entirely possible I missed a driver or API that could handle 
this better, if so, please don't keep it to yourselves.

So, how could one go about implementing such a driver?

Bence


             reply	other threads:[~2025-01-21 15:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-21 15:19 Csókás Bence [this message]
2025-01-21 17:45 ` [Q] Frequency & duty cycle measurement? David Lechner
2025-01-27 15:00 ` William Breathitt Gray
2025-01-30 13:59   ` Csókás Bence
2025-02-04 23:37     ` William Breathitt Gray
2025-02-05  9:30       ` Csókás Bence
2025-02-05  9:58         ` Csókás Bence
2025-02-19 22:32 ` Dipen Patel
2025-02-26 13:56   ` Csókás Bence

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=f2ec8a55-42ad-498a-b793-072444dcb92e@prolan.hu \
    --to=csokas.bence@prolan.hu \
    --cc=daniel.lezcano@linaro.org \
    --cc=dipenp@nvidia.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=timestamp@lists.linux.dev \
    --cc=wbg@kernel.org \
    /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).