From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: rodrigo.alencar@analog.com
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux@analog.com, devicetree@vger.kernel.org,
linux-pwm@vger.kernel.org, linux-doc@vger.kernel.org,
"Jonathan Cameron" <jonathan.cameron@oss.qualcomm.com>,
"Olivier Moysan" <olivier.moysan@foss.st.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>
Subject: Re: [PATCH v3 07/10] iio: frequency: ad9910: support drctl control
Date: Tue, 3 Nov 2026 18:47:37 +0200 [thread overview]
Message-ID: <auoQKX4CNb0sWkWH@ashevche-desk.local> (raw)
In-Reply-To: <20261103-ad9910-backend-support-v3-7-0e9224ddf7b7@analog.com>
On Tue, Nov 03, 2026 at 11:53:03AM -0300, Rodrigo Alencar via B4 Relay wrote:
>
> The DRCTL pin controls the slope direction of the AD9910 digital ramp
> generator (DRG). When dwell is enabled at a ramp limit, the DRG holds
> that limit until the next DRCTL transition, so the sweep pattern is
> defined by the waveform applied to that pin, which can be generated by
> a PWM.
>
> Get the optional "drctl" PWM and expose the integration_time attribute
> in the DRG ramp up and ramp down channels, which sets the time interval
> assigned to each ramp direction while the sweep parameter is accumulating.
>
> The DRCTL waveform is described with the PWM waveform API, using the duty
> offset when DRCTL needs to start low. The PWM is disabled when the
> resulting period is zero. The waveform is rounded by the PWM provider
> before being applied, so that integration_time reports the intervals
> achieved by it. Writing to integration_time fails with -EOPNOTSUPP when
> no DRCTL PWM is available. As the waveform API has no stubs, the driver
> now depends on PWM.
...
> + if (!ndh && ndl) {
> + /* DRCTL low on the first half, so that it ramps down first */
> + wf.period_length_ns = st->ramp_down_time_ns;
> + wf.duty_offset_ns = st->ramp_down_time_ns / 2;
> + wf.duty_length_ns = wf.period_length_ns - wf.duty_offset_ns;
> + } else if (ndh && !ndl) {
> + wf.period_length_ns = st->ramp_up_time_ns;
> + wf.duty_length_ns = st->ramp_up_time_ns / 2;
> + } else if (!ndh && !ndl) {
> + wf.period_length_ns = st->ramp_up_time_ns + st->ramp_down_time_ns;
> + wf.duty_length_ns = st->ramp_up_time_ns;
> + } else {
> + wf.period_length_ns = st->ramp_up_time_ns + st->ramp_down_time_ns;
> + }
> +
> + /* a zero period disables the PWM, nothing to round */
> + if (wf.period_length_ns) {
> + ret = pwm_round_waveform_might_sleep(st->drctl_pwm, &wf);
> + if (ret < 0)
> + return ret;
> + }
> +
> + ret = pwm_set_waveform_might_sleep(st->drctl_pwm, &wf, false);
> + if (ret)
> + return ret;
> +
> + if (!ndh && ndl) {
> + st->ramp_down_time_ns = wf.period_length_ns;
> + } else if (ndh && !ndl) {
> + st->ramp_up_time_ns = wf.period_length_ns;
> + } else if (!ndh && !ndl) {
> + st->ramp_up_time_ns = wf.duty_length_ns;
> + st->ramp_down_time_ns = wf.period_length_ns - wf.duty_length_ns;
> + }
This and above if-else-if chain can be simplified
if (!ndh && !ndl) {
st->ramp_up_time_ns = wf.duty_length_ns;
st->ramp_down_time_ns = wf.period_length_ns - wf.duty_length_ns;
} else if (!ndh) {
st->ramp_down_time_ns = wf.period_length_ns;
} else if (!ndl) {
st->ramp_up_time_ns = wf.period_length_ns;
} else { // for the above case
... //
}
Or with inverted logic.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-03 16:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 14:52 [PATCH v3 00/10] iio: frequency: ad9910: add IIO backend support Rodrigo Alencar via B4 Relay
2026-11-03 14:52 ` [PATCH v3 01/10] iio: frequency: ad9910: powerdown fix Rodrigo Alencar via B4 Relay
2026-11-03 14:52 ` [PATCH v3 02/10] iio: backend: add devm_iio_backend_get_optional() Rodrigo Alencar via B4 Relay
2026-11-03 14:52 ` [PATCH v3 03/10] dt-bindings: iio: frequency: add adi,ad9910-axi-backend Rodrigo Alencar via B4 Relay
2026-11-03 14:53 ` [PATCH v3 04/10] dt-bindings: iio: frequency: ad9910: add io-backends property Rodrigo Alencar via B4 Relay
2026-11-03 14:53 ` [PATCH v3 05/10] iio: frequency: ad9910: move channel indexes into a shared header Rodrigo Alencar via B4 Relay
2026-11-03 14:53 ` [PATCH v3 06/10] iio: frequency: ad9910: add axi backend driver Rodrigo Alencar via B4 Relay
2026-11-03 14:53 ` [PATCH v3 07/10] iio: frequency: ad9910: support drctl control Rodrigo Alencar via B4 Relay
2026-11-03 16:47 ` Andy Shevchenko [this message]
2026-11-03 14:53 ` [PATCH v3 08/10] iio: frequency: ad9910: support iio backend Rodrigo Alencar via B4 Relay
2026-11-03 16:52 ` Andy Shevchenko
2026-11-03 14:53 ` [PATCH v3 09/10] iio: ABI: add integration_time for output channels Rodrigo Alencar via B4 Relay
2026-11-03 14:53 ` [PATCH v3 10/10] docs: iio: ad9910: document DRCTL pin control Rodrigo Alencar via B4 Relay
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=auoQKX4CNb0sWkWH@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=jonathan.cameron@oss.qualcomm.com \
--cc=krzk+dt@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux@analog.com \
--cc=olivier.moysan@foss.st.com \
--cc=rdunlap@infradead.org \
--cc=robh@kernel.org \
--cc=rodrigo.alencar@analog.com \
--cc=skhan@linuxfoundation.org \
--cc=ukleinek@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
all inboxes | Powered by JetHome®