Linux Documentation
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <ukleinek@kernel.org>
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>,
	 Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	 Randy Dunlap <rdunlap@infradead.org>
Subject: Re: [PATCH 06/10] iio: frequency: ad9910: add axi backend driver
Date: Tue, 20 Oct 2026 14:39:18 +0200	[thread overview]
Message-ID: <atddZ9KZkXwgv2IA@monoceros> (raw)
In-Reply-To: <20261015-ad9910-backend-support-v1-6-3c21648c8e26@analog.com>

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

Hello,

On Thu, Oct 15, 2026 at 01:49:46PM -0300, Rodrigo Alencar via B4 Relay wrote:
> +static int ad9910_axi_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> +				const struct pwm_state *state)
> +{
> +	struct ad9910_axi_state *st = pwmchip_get_drvdata(chip);
> +	u64 period, duty;
> +	int ret;
> +
> +	guard(mutex)(&st->lock);
> +
> +	period = mul_u64_u64_div_u64(state->period, st->pd_clk_freq_uhz,
> +				     1ULL * NANO * MICROHZ_PER_HZ);

Does st->lock protect st->pd_clk_freq_uhz? If not, the lock can be taken
later.

> +	period = min(period, U32_MAX);
> +	duty = mul_u64_u64_div_u64(state->duty_cycle, st->pd_clk_freq_uhz,
> +				   1ULL * NANO * MICROHZ_PER_HZ);
> +	duty = min(duty, period);
> +
> +	if (state->polarity == PWM_POLARITY_INVERSED)
> +		duty = period - duty;
> +
> +	ret = regmap_write(st->regmap, AD9910_AXI_REG_DRCTL_PERIOD, period);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_write(st->regmap, AD9910_AXI_REG_DRCTL_WIDTH, duty);
> +	if (ret)
> +		return ret;
> +
> +	st->pwm_polarity = state->polarity;

An inversed polarity waveform isn't the same as just inverting the
duty length. So this is cheating. The right thing to implement here
might be inconvenient, but you shouldn't implement .apply() anyhow and
the waveform stuff has saner semantics.

> +	if (state->enabled)
> +		return regmap_set_bits(st->regmap, AD9910_AXI_REG_DRG,
> +				       AD9910_AXI_REG_DRG_TOGGLE_EN_MSK);
> +
> +	return regmap_clear_bits(st->regmap, AD9910_AXI_REG_DRG,
> +				 AD9910_AXI_REG_DRG_TOGGLE_EN_MSK);
> +}
> +
> [...]
> +static const struct pwm_ops ad9910_axi_pwm_ops = {
> +	.apply = ad9910_axi_pwm_apply,
> +	.get_state = ad9910_axi_pwm_get_state,

Please use the waveform callbacks instead of .apply() and .get_state().

> +};
> +
> +static int ad9910_axi_setup(struct ad9910_axi_state *st)
> +{
> +	int ret;
> +
> +	st->pd_clk_freq_uhz = AD9910_AXI_PD_CLK_MAX_FREQ_HZ * MICROHZ_PER_HZ;
> +
> +	ret = regmap_set_bits(st->regmap, AD9910_AXI_REG_RESET,
> +			      AD9910_AXI_REG_RESET_CORE_MSK);
> +	if (ret)
> +		return ret;
> +
> +	return regmap_clear_bits(st->regmap, AD9910_AXI_REG_RESET,
> +				 AD9910_AXI_REG_RESET_CORE_MSK);
> +}
> +
> +static int ad9910_axi_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct ad9910_axi_state *st;
> +	struct pwm_chip *pwm;

the name `pwm` is usually only used for variables of type struct
pwm_chip *. Please call this `chip` as it is done in the rest of the
driver.

> +	void __iomem *base;
> +	struct clk *clk;
> +	int ret;
> +
> +	pwm = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*st));
> +	if (IS_ERR(pwm))
> +		return PTR_ERR(pwm);
> +
> +	st = pwmchip_get_drvdata(pwm);
> +
> +	base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(base))
> +		return PTR_ERR(base);
> +
> +	clk = devm_clk_get_enabled(dev, NULL);
> +	if (IS_ERR(clk))
> +		return dev_err_probe(dev, PTR_ERR(clk), "failed to get clock\n");
> +
> +	st->dev = dev;
> +	st->regmap = devm_regmap_init_mmio(dev, base,
> +					   &ad9910_axi_regmap_config);
> +	if (IS_ERR(st->regmap))
> +		return dev_err_probe(dev, PTR_ERR(st->regmap),
> +				     "failed to init register map\n");
> +
> +	ret = devm_mutex_init(dev, &st->lock);
> +	if (ret)
> +		return ret;
> +
> +	ret = ad9910_axi_setup(st);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to setup device\n");
> +
> +	pwm->ops = &ad9910_axi_pwm_ops;
> +
> +	ret = devm_pwmchip_add(dev, pwm);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Could not register PWM chip\n");
> +
> +	return devm_iio_backend_register(dev, &ad9910_axi_back_info, st);

It's unclear to me what is the relation between that iio backend and the
PWM. If .set_sample_rate() is called for the iio device, does that
change the output of the PWM? If yes, that's bad and needs fixing.

> +}

Best regards
Uwe

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

  parent reply	other threads:[~2026-10-20 12:39 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 16:49 [PATCH 00/10] iio: frequency: ad9910: add IIO backend support Rodrigo Alencar via B4 Relay
2026-10-15 16:49 ` [PATCH 01/10] iio: frequency: ad9910: powerdown fix Rodrigo Alencar via B4 Relay
2026-10-16  9:22   ` Nuno Sá
2026-10-15 16:49 ` [PATCH 02/10] iio: backend: add devm_iio_backend_get_optional() Rodrigo Alencar via B4 Relay
2026-10-15 18:41   ` Andy Shevchenko
2026-10-16  8:45     ` Nuno Sá
2026-10-16 11:18       ` Rodrigo Alencar
2026-10-16 13:01         ` Nuno Sá
2026-10-16 13:21           ` Andy Shevchenko
2026-10-16 13:19         ` Andy Shevchenko
2026-10-16 13:32           ` Rodrigo Alencar
2026-10-16 14:07           ` Nuno Sá
2026-10-17 20:28             ` Jonathan Cameron
2026-10-19  6:07               ` Nuno Sá
2026-10-16  8:46   ` Nuno Sá
2026-10-15 16:49 ` [PATCH 03/10] dt-bindings: iio: frequency: add adi,ad9910-axi-backend Rodrigo Alencar via B4 Relay
2026-10-15 18:59   ` Conor Dooley
2026-10-15 16:49 ` [PATCH 04/10] dt-bindings: iio: frequency: ad9910: add io-backends property Rodrigo Alencar via B4 Relay
2026-10-15 19:00   ` Conor Dooley
2026-10-15 16:49 ` [PATCH 05/10] iio: frequency: ad9910: move channel indexes into a shared header Rodrigo Alencar via B4 Relay
2026-10-16  9:22   ` Nuno Sá
2026-10-15 16:49 ` [PATCH 06/10] iio: frequency: ad9910: add axi backend driver Rodrigo Alencar via B4 Relay
2026-10-16  9:22   ` Nuno Sá
2026-10-20 12:39   ` Uwe Kleine-König [this message]
2026-10-15 16:49 ` [PATCH 07/10] iio: frequency: ad9910: support drctl control Rodrigo Alencar via B4 Relay
2026-10-16  9:22   ` Nuno Sá
2026-10-20 12:23   ` Uwe Kleine-König
2026-10-20 12:43     ` Rodrigo Alencar
2026-10-15 16:49 ` [PATCH 08/10] iio: frequency: ad9910: support iio backend Rodrigo Alencar via B4 Relay
2026-10-16  9:22   ` Nuno Sá
2026-10-17 20:39   ` Jonathan Cameron
2026-10-15 16:49 ` [PATCH 09/10] iio: ABI: add integration_time for output channels Rodrigo Alencar via B4 Relay
2026-10-15 18:38   ` Andy Shevchenko
2026-10-16  9:22   ` Nuno Sá
2026-10-17 20:43   ` Jonathan Cameron
2026-10-15 16:49 ` [PATCH 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=atddZ9KZkXwgv2IA@monoceros \
    --to=ukleinek@kernel.org \
    --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 \
    /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