From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: Nicolae-Daniel Deaconescu <Nicolae-daniel.Deaconescu@analog.com>
Cc: "Conor Dooley" <conor@kernel.org>,
"Jonathan Cameron" <jic23@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>,
"Michael Hennerich" <michael.hennerich@analog.com>,
"Trevor Gamblin" <tgamblin@baylibre.com>,
"David Lechner" <dlechner@baylibre.com>,
linux-pwm@vger.kernel.org, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v4 1/6] pwm: core: add pwm_get_waveform_step_might_sleep()
Date: Tue, 24 Nov 2026 12:08:46 +0100 [thread overview]
Message-ID: <awVki6lC3SxGfqSl@monoceros> (raw)
In-Reply-To: <20261123165522.336249-1-Nicolae-daniel.Deaconescu@analog.com>
[-- Attachment #1: Type: text/plain, Size: 2311 bytes --]
Hello Daniel,
On Mon, Nov 23, 2026 at 06:55:22PM +0200, Nicolae-Daniel Deaconescu wrote:
> The driver has to know the clock rate the PWMs run from. CNV and the CLK
> gate are one burst of whole clock cycles after each conversion, and I have
> to place the end of the burst relative to the next CNV. The gate has to pass
> exactly the number of clock pulses the ADC shifts out, so I need the exact
> number of clock pulses in the window to place its edges.
I don't understand that, but it sounds a bit like
https://en.wikipedia.org/wiki/XY_problem. I suspect you need a pattern
like this (just one period depicted; 12 is just an example):
_ _ _ _
___________...____/ \_/ \_/ \_..._/ \__
---- 12 pulses ----
and the idea is to create that from two signals, a clk and a PWM:
_ _ _ _ _ _ _ _
/ \_/ \_/ \.../ \_/ \_/ \_/ \_..._/ \__
---- 12 pulses ----
__________________
___________...____/ \_
and OR them together to make the PWM mask the unwanted clk pulses.
And then with a 2nd PWM that does:
_
____/ \____..._________________________
to trigger a conversion.
> The existing rounding functions give me the rounded nanoseconds, but not how
> many clock cycles that is. For example, 4 pulses of a 120 MHz clock last
> 33.3 ns, so 33 ns is rounded down to 3 cycles and only 34 to 41 ns give
> exactly 4. At 100 MHz the range for 4 cycles is 40 to 49 ns. If the driver
> doesn't know the rate, it can't pick a number in the right window, and would
> either run into the next conversion or corrupt the data with a shift.
Unless the clk is very fast, the nanosecond resolution should be
finegrained enough!? With the clk running at 120 MHz[1] and 4 desired
pulses the masking PWM needs a duty cycle between 29.16667 ns and
33.33333 ns, i.e. between 3.5 and 4 ticks (and a common rising edge with
the clk signal).
Assuming a sane hardware composition and seeing that requesting
.duty_length_ns = 33 yields 25 ns, .duty_length_ns = 34 is the right
choice.
The same calculation with clk rate = 100 MHz yields: duty_length in
[3.5; 4] clk ticks = [35; 40] ns and 40 ns gives an exact match.
Does that fit your problem and make sense?
Best regards
Uwe
[1] assuming a 50% clk duty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2026-11-24 11:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 11:24 [PATCH v4 0/6] iio: adc: ad7625: add LTC2387 and ADAQ2387x support Nicolae-Daniel Deaconescu
2026-11-19 11:24 ` [PATCH v4 1/6] pwm: core: add pwm_get_waveform_step_might_sleep() Nicolae-Daniel Deaconescu
2026-11-21 23:35 ` Jonathan Cameron
2026-11-23 13:41 ` Uwe Kleine-König
2026-11-23 16:55 ` Nicolae-Daniel Deaconescu
2026-11-24 11:08 ` Uwe Kleine-König [this message]
2026-11-19 11:24 ` [PATCH v4 2/6] pwm: axi-pwmgen: report the waveform step Nicolae-Daniel Deaconescu
2026-11-19 11:24 ` [PATCH v4 3/6] iio: adc: ad7625: fix sampling frequency handling Nicolae-Daniel Deaconescu
2026-11-19 11:24 ` [PATCH v4 4/6] iio: adc: ad7625: move initial mode setup Nicolae-Daniel Deaconescu
2026-11-21 23:40 ` Jonathan Cameron
2026-11-19 11:24 ` [PATCH v4 5/6] dt-bindings: iio: adc: add adi,ltc2387 Nicolae-Daniel Deaconescu
2026-11-19 11:24 ` [PATCH v4 6/6] iio: adc: ad7625: add LTC2387 and ADAQ2387x support Nicolae-Daniel Deaconescu
2026-11-21 23:48 ` Jonathan Cameron
2026-11-23 11:53 ` Nicolae-Daniel Deaconescu
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=awVki6lC3SxGfqSl@monoceros \
--to=ukleinek@kernel.org \
--cc=Nicolae-daniel.Deaconescu@analog.com \
--cc=conor@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=michael.hennerich@analog.com \
--cc=nuno.sa@analog.com \
--cc=tgamblin@baylibre.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