Re: [PATCH 07/10] iio: frequency: ad9910: support drctl control
From: Rodrigo Alencar
Date: Tue Oct 20 2026 - 08:44:19 EST
On 20/10/26 14:23, Uwe Kleine-König wrote:
> On Thu, Oct 15, 2026 at 01:49:47PM -0300, Rodrigo Alencar via B4 Relay wrote:
> > +static int ad9910_drctl_sync(struct ad9910_state *st)
> > +{
> > + struct pwm_state state;
> > + bool ndh, ndl;
> > + int ret;
> > +
> > + if (!st->drctl_pwm)
> > + return 0;
> > +
> > + ndh = FIELD_GET(AD9910_CFR2_DRG_NO_DWELL_HIGH_MSK,
> > + st->reg[AD9910_REG_CFR2].val32);
> > + ndl = FIELD_GET(AD9910_CFR2_DRG_NO_DWELL_LOW_MSK,
> > + st->reg[AD9910_REG_CFR2].val32);
> > +
> > + pwm_init_state(st->drctl_pwm, &state);
> > +
> > + if (!ndh && ndl) {
> > + state.duty_cycle = st->ramp_down_time_ns / 2;
> > + state.period = st->ramp_down_time_ns;
> > + state.polarity = PWM_POLARITY_INVERSED;
> > + } else if (ndh && !ndl) {
> > + state.duty_cycle = st->ramp_up_time_ns / 2;
> > + state.period = st->ramp_up_time_ns;
> > + state.polarity = PWM_POLARITY_NORMAL;
> > + } else if (!ndh && !ndl) {
> > + state.duty_cycle = st->ramp_up_time_ns;
> > + state.period = st->ramp_up_time_ns + st->ramp_down_time_ns;
> > + state.polarity = PWM_POLARITY_NORMAL;
> > + } else {
> > + state.duty_cycle = 0;
> > + state.period = st->ramp_up_time_ns + st->ramp_down_time_ns;
> > + state.polarity = PWM_POLARITY_NORMAL;
> > + }
> > +
> > + if (!state.period) {
> > + pwm_disable(st->drctl_pwm);
> > + return 0;
> > + }
> > +
> > + state.enabled = true;
> > + ret = pwm_apply_might_sleep(st->drctl_pwm, &state);
> > + if (ret)
> > + return ret;
> > +
> > + ret = pwm_get_state_hw(st->drctl_pwm, &state);
> > + if (ret)
> > + return ret;
>
> Does enabling the PWM have any side effects? Are you doing that only to
> be able to call pwm_get_state_hw() and thus find out what the resulting
> output looks like? In that case, pwm_round_waveform_might_sleep() might
> be your friend.
Thanks for pointing this out, will look into that.
>
> > +
> > + if (!ndh && ndl) {
> > + st->ramp_down_time_ns = state.period;
> > + } else if (ndh && !ndl) {
> > + st->ramp_up_time_ns = state.period;
> > + } else if (!ndh && !ndl) {
> > + st->ramp_up_time_ns = state.duty_cycle;
> > + st->ramp_down_time_ns = state.period - st->ramp_up_time_ns;
> > + }
>
> So the configuration depends on the previous state of the
> AD9910_REG_CFR2 register? That's a recipe for surprises?!
Expect not surprises. It depends on the current state of the
no-dwell modes, which defines bidirectional, ramp-up or
ramp-down behavior.
That is documented in a later patch. ad9910_drctl_sync() is
called when dwell_en or integration_time attributes are changed.
--
Kind regards,
Rodrigo Alencar