From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org
Subject: Re: [PATCH 2/3] iio: dac: ad5706r: Add support for AD5706R DAC
Date: Fri, 20 Feb 2026 11:51:49 +0100 [thread overview]
Message-ID: <aZg51rcxck6AyYUm@monoceros> (raw)
In-Reply-To: <20260220-dev_ad5706r-v1-2-7253bbd74889@analog.com>
[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]
Hello,
On Fri, Feb 20, 2026 at 04:02:57PM +0800, Alexis Czezar Torreno wrote:
> +static int _set_pwm_duty_cycle(struct ad5706r_state *st, int duty_cycle)
> +{
> + struct pwm_state ldacb_pwm_state;
> + int ret;
> +
> + pwm_get_state(st->ldacb_pwm, &ldacb_pwm_state);
> +
> + ldacb_pwm_state.duty_cycle = duty_cycle == 0 ? 0 :
> + DIV_ROUND_CLOSEST_ULL(NANO, st->sampling_frequency * 100 / duty_cycle);
This being integer math it would benefit when simplifying that to
10000000 * duty_cycle / st->sampling_frequency
. Consider st->sampling_frequency = 667 and duty_cycle = 99:
NANO / (st->sampling_frequency * 100 / duty_cycle) = 1484257.8710644676
DIV_ROUND_CLOSEST_ULL(NANO, st->sampling_frequency * 100 / duty_cycle) = 1485884
DIV_ROUND_CLOSEST_ULL(10000000 * duty_cycle, st->sampling_frequency) = 1484258
With duty_cycle <= 100 this doesn't even overflow.
> + ret = pwm_apply_might_sleep(st->ldacb_pwm, &ldacb_pwm_state);
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
> +
> +/* Device Attributes */
> +static ssize_t ad5706r_dev_addr_write(struct iio_dev *indio_dev,
> + uintptr_t private, const struct iio_chan_spec *chan,
> + const char *buf, size_t len)
> +{
> + struct ad5706r_state *st = iio_priv(indio_dev);
> + unsigned int reg_val;
> + int ret;
> +
> + ret = kstrtou32(buf, 10, ®_val);
> + if (ret)
> + return ret;
> +
> + st->dev_addr = AD5706R_MASK_DEV_ADDR(reg_val);
> +
> + return ret ? ret : len;
This can be written as:
return ret ?: len;
It's a matter of taste which one you like better.
> +}
> +
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2026-02-20 10:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-20 8:02 [PATCH 0/3] Add support for AD5706R DAC Alexis Czezar Torreno
2026-02-20 8:02 ` [PATCH 1/3] dt-bindings: iio: dac: Add binding for AD5706R Alexis Czezar Torreno
2026-02-21 10:45 ` Krzysztof Kozlowski
2026-02-21 16:05 ` David Lechner
2026-02-20 8:02 ` [PATCH 2/3] iio: dac: ad5706r: Add support for AD5706R DAC Alexis Czezar Torreno
2026-02-20 10:48 ` Nuno Sá
2026-02-20 11:00 ` Andy Shevchenko
2026-02-20 15:02 ` Nuno Sá
2026-02-20 16:56 ` Andy Shevchenko
2026-02-23 10:10 ` Nuno Sá
2026-02-20 10:51 ` Uwe Kleine-König [this message]
2026-02-21 16:19 ` David Lechner
2026-02-22 18:57 ` Jonathan Cameron
2026-02-23 4:49 ` Torreno, Alexis Czezar
2026-02-23 8:47 ` Andy Shevchenko
2026-02-20 8:02 ` [PATCH 3/3] MAINTAINERS: Add entry for AD5706R DAC driver Alexis Czezar Torreno
2026-02-20 10:18 ` Nuno Sá
2026-02-20 10:31 ` [PATCH 0/3] Add support for AD5706R DAC Andy Shevchenko
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=aZg51rcxck6AyYUm@monoceros \
--to=ukleinek@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=alexisczezar.torreno@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@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