From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Kim Seer Paller" <kimseer.paller@analog.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Nuno Sá" <noname.nuno@gmail.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v4 3/3] iio: dac: ad3530r: Add driver for AD3530R and AD3531R
Date: Fri, 18 Apr 2025 15:37:14 +0100 [thread overview]
Message-ID: <20250418153714.501d3cb0@jic23-huawei> (raw)
In-Reply-To: <ef90f91a-c5eb-46ce-934f-93ff1a18af14@baylibre.com>
On Wed, 16 Apr 2025 14:23:11 -0500
David Lechner <dlechner@baylibre.com> wrote:
> On 4/12/25 12:57 AM, Kim Seer Paller wrote:
> > The AD3530/AD3530R (8-channel) and AD3531/AD3531R (4-channel) are
> > low-power, 16-bit, buffered voltage output DACs with software-
> > programmable gain controls, providing full-scale output spans of 2.5V or
> > 5V for reference voltages of 2.5V. These devices operate from a single
> > 2.7V to 5.5V supply and are guaranteed monotonic by design. The "R"
> > variants include a 2.5V, 5ppm/°C internal reference, which is disabled
> > by default.
> >
> > Support for monitoring internal die temperature, output voltages, and
> > current of a selected channel via the MUXOUT pin using an external ADC
> > is currently not implemented.
> >
> > Signed-off-by: Kim Seer Paller <kimseer.paller@analog.com>
> > ---
>
> Looks very good now. :-)
>
> A made a few comments but maybe nothing serious enough to require a v5.
We have plenty of time in the cycle, so I think I would prefer a v5
just tidying up these last few bits.
Thanks,
Jonathan
>
> > diff --git a/drivers/iio/dac/ad3530r.c b/drivers/iio/dac/ad3530r.c
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..ffa04f678b86d8da6f5e47c35c265b6648121843
> > --- /dev/null
> > +++ b/drivers/iio/dac/ad3530r.c
> > @@ -0,0 +1,506 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * AD3530R/AD3530 8-channel, 16-bit Voltage Output DAC Driver
> > + * AD3531R/AD3531 4-channel, 16-bit Voltage Output DAC Driver
> > + *
> > + * Copyright 2025 Analog Devices Inc.
> > + */
> > +
> > +#include <linux/bitfield.h>
> > +#include <linux/bits.h>
> > +#include <linux/cleanup.h>
> > +#include <linux/delay.h>
> > +#include <linux/device.h>
> > +#include <linux/gpio/consumer.h>
> > +#include <linux/iio/iio.h>
> > +#include <linux/kernel.h>
>
> Usually, we try to avoid including kernel.h - it includes too much.
>
> > +#include <linux/module.h>
> > +#include <linux/mod_devicetable.h>
> > +#include <linux/mutex.h>
> > +#include <linux/property.h>
> > +#include <linux/regmap.h>
> > +#include <linux/regulator/consumer.h>
> > +#include <linux/spi/spi.h>
> > +
> ...
>
> > +
> > +static int ad3530r_setup(struct ad3530r_state *st, int vref,
> > + bool has_external_vref)
> > +{
> > + struct device *dev = regmap_get_device(st->regmap);
> > + struct gpio_desc *reset_gpio;
> > + int i, ret;
> > + bool has_range_multiplier;
> > +
> > + reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> > + if (IS_ERR(reset_gpio))
> > + return dev_err_probe(dev, PTR_ERR(reset_gpio),
> > + "Failed to get reset GPIO\n");
> > +
> > + if (reset_gpio) {
> > + /* Perform hardware reset */
> > + fsleep(1000);
> > + gpiod_set_value_cansleep(reset_gpio, 0);
> > + } else {
> > + /* Perform software reset */
> > + ret = regmap_update_bits(st->regmap, AD3530R_INTERFACE_CONFIG_A,
> > + AD3530R_SW_RESET, AD3530R_SW_RESET);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + fsleep(10000);
> > +
> > + has_range_multiplier = false;
> > + if (device_property_present(dev, "adi,range-double")) {
>
> Since this is a flag, I think device_property_read_bool() is preferred.
>
> > + ret = regmap_set_bits(st->regmap, AD3530R_OUTPUT_CONTROL_0,
> > + AD3530R_OUTPUT_CONTROL_RANGE);
> > + if (ret)
> > + return ret;
> > +
> > + has_range_multiplier = true;
> > + }
> > +
> > + if (!has_external_vref && st->chip_info->internal_ref_support) {
> > + ret = regmap_set_bits(st->regmap, AD3530R_REFERENCE_CONTROL_0,
> > + AD3530R_REFERENCE_CONTROL_SEL);
> > + if (ret)
> > + return ret;
> > +
> > + st->vref_mv = has_range_multiplier ?
> > + 2 * AD3530R_INTERNAL_VREF_MV :
> > + AD3530R_INTERNAL_VREF_MV;
> > + }
> > +
> > + if (has_external_vref)
> > + st->vref_mv = has_range_multiplier ? 2 * vref / 1000 : vref / 1000;
> > +
>
> I think this would be simpler as:
>
> st->vref_mv = range_multiplier * vref / 1000;
>
> where range_multiplier is 1 or 2.
>
> > + /* Set operating mode to normal operation. */
> > + ret = regmap_write(st->regmap, AD3530R_OUTPUT_OPERATING_MODE_0,
> > + AD3530R_NORMAL_OPERATION);
> > + if (ret)
> > + return ret;
> > +
> > + if (st->chip_info->num_channels > AD3531R_MAX_CHANNELS) {
> > + ret = regmap_write(st->regmap, AD3530R_OUTPUT_OPERATING_MODE_1,
> > + AD3530R_NORMAL_OPERATION);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + for (i = 0; i < st->chip_info->num_channels; i++)
> > + st->chan[i].powerdown_mode = AD3530R_POWERDOWN_32K;
> > +
> > + st->ldac_gpio = devm_gpiod_get_optional(dev, "ldac", GPIOD_OUT_HIGH);
>
> I guess it doesn't matter which state this starts in but GPIOD_OUT_LOW seems
> more natural since we toggle it high the low later.
>
> > + if (IS_ERR(st->ldac_gpio))
> > + return dev_err_probe(dev, PTR_ERR(st->ldac_gpio),
> > + "Failed to get ldac GPIO\n");
> > +
> > + return 0;
> > +}
> > +
next prev parent reply other threads:[~2025-04-18 14:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-12 5:57 [PATCH v4 0/3] Add driver for AD3530R and AD3531R DACs Kim Seer Paller
2025-04-12 5:57 ` [PATCH v4 1/3] iio: ABI: add new DAC powerdown mode Kim Seer Paller
2025-04-12 5:57 ` [PATCH v4 2/3] dt-bindings: iio: dac: Add adi,ad3530r.yaml Kim Seer Paller
2025-04-12 5:57 ` [PATCH v4 3/3] iio: dac: ad3530r: Add driver for AD3530R and AD3531R Kim Seer Paller
2025-04-12 17:44 ` Jonathan Cameron
2025-04-16 19:23 ` David Lechner
2025-04-18 14:37 ` Jonathan Cameron [this message]
2025-04-16 19:24 ` [PATCH v4 0/3] Add driver for AD3530R and AD3531R DACs David Lechner
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=20250418153714.501d3cb0@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=kimseer.paller@analog.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=noname.nuno@gmail.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