From: "Nuno Sá" <noname.nuno@gmail.com>
To: "Pop Ioan Daniel" <pop.ioan-daniel@analog.com>,
"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>,
"Sergiu Cuciurean" <sergiu.cuciurean@analog.com>,
"Dragos Bogdan" <dragos.bogdan@analog.com>,
"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
"Olivier Moysan" <olivier.moysan@foss.st.com>,
"Javier Carrasco" <javier.carrasco.cruz@gmail.com>,
"Matti Vaittinen" <mazziesaccount@gmail.com>,
"Angelo Dureghello" <adureghello@baylibre.com>,
"Guillaume Stols" <gstols@baylibre.com>,
"Tobias Sperling" <tobias.sperling@softing.com>,
"Marcelo Schmitt" <marcelo.schmitt@analog.com>,
"Trevor Gamblin" <tgamblin@baylibre.com>,
"Alisa-Dariana Roman" <alisadariana@gmail.com>,
"Ramona Alexandra Nechita" <ramona.nechita@analog.com>,
"Herve Codina" <herve.codina@bootlin.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
"Thomas Bonnefille" <thomas.bonnefille@bootlin.com>,
"João Paulo Gonçalves" <joao.goncalves@toradex.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 5/5] iio: adc: ad7405: add ad7405 driver
Date: Mon, 09 Jun 2025 09:05:48 +0100 [thread overview]
Message-ID: <930768920f83bf720f660f65050ef61d16610766.camel@gmail.com> (raw)
In-Reply-To: <20250605150948.3091827-6-pop.ioan-daniel@analog.com>
On Thu, 2025-06-05 at 18:09 +0300, Pop Ioan Daniel wrote:
> Add support for the AD7405/ADUM770x, a high performance isolated ADC,
> 1-channel, 16-bit with a second-order Σ-Δ modulator that converts an
> analog input signal into a high speed, single-bit data stream.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
Looks good. Just one thing that I guess Jonathan can tweak. With it,
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> changes in v7:
> - replace kernel.h with math64.h that define DIV_ROUND_CLOSEST_ULL()
> - restructure ad7405_set_dec_rate function
> - fix indentation
> drivers/iio/adc/Kconfig | 10 ++
> drivers/iio/adc/Makefile | 1 +
> drivers/iio/adc/ad7405.c | 259 +++++++++++++++++++++++++++++++++++++++
> 3 files changed, 270 insertions(+)
> create mode 100644 drivers/iio/adc/ad7405.c
>
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index ad06cf556785..43af2070e27f 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -251,6 +251,16 @@ config AD7380
> To compile this driver as a module, choose M here: the module will
> be
> called ad7380.
>
> +config AD7405
> + tristate "Analog Device AD7405 ADC Driver"
> + depends on IIO_BACKEND
> + help
> + Say yes here to build support for Analog Devices AD7405, ADUM7701,
> + ADUM7702, ADUM7703 analog to digital converters (ADC).
> +
> + To compile this driver as a module, choose M here: the module will
> be
> + called ad7405.
> +
> config AD7476
> tristate "Analog Devices AD7476 1-channel ADCs driver and other
> similar devices from AD and TI"
> depends on SPI
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index 07d4b832c42e..8115f30b7862 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -26,6 +26,7 @@ obj-$(CONFIG_AD7291) += ad7291.o
> obj-$(CONFIG_AD7292) += ad7292.o
> obj-$(CONFIG_AD7298) += ad7298.o
> obj-$(CONFIG_AD7380) += ad7380.o
> +obj-$(CONFIG_AD7405) += ad7405.o
> obj-$(CONFIG_AD7476) += ad7476.o
> obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
> obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
> diff --git a/drivers/iio/adc/ad7405.c b/drivers/iio/adc/ad7405.c
> new file mode 100644
> index 000000000000..c07b90fbd429
> --- /dev/null
> +++ b/drivers/iio/adc/ad7405.c
> @@ -0,0 +1,259 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Analog Devices AD7405 driver
> + *
> + * Copyright 2025 Analog Devices Inc.
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/math64.h>
> +#include <linux/module.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/platform_device.h>
> +#include <linux/property.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/util_macros.h>
> +
> +#include <linux/iio/backend.h>
> +#include <linux/iio/iio.h>
> +
> +static const unsigned int ad7405_dec_rates_range[] = {
> + 32, 1, 4096,
> +};
> +
> +struct ad7405_chip_info {
> + const char *name;
> + struct iio_chan_spec channel;
> + const unsigned int full_scale_mv;
> +};
> +
> +struct ad7405_state {
> + struct iio_backend *back;
> + const struct ad7405_chip_info *info;
> + unsigned int ref_frequency;
> + unsigned int dec_rate;
> +};
> +
> +static int ad7405_set_dec_rate(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + unsigned int dec_rate)
> +{
> + struct ad7405_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + if (dec_rate > 4096 || dec_rate < 32)
> + return -EINVAL;
> +
> + if (!iio_device_claim_direct(indio_dev))
> + return -EBUSY;
> +
> + ret = iio_backend_oversampling_ratio_set(st->back, chan->scan_index,
> dec_rate);
> + iio_device_release_direct(indio_dev);
> +
> + if (ret < 0)
> + return ret;
> +
> + st->dec_rate = dec_rate;
> +
> + return 0;
> +}
> +
> +static int ad7405_read_raw(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan, int *val,
> + int *val2, long info)
> +{
> + struct ad7405_state *st = iio_priv(indio_dev);
> +
> + switch (info) {
> + case IIO_CHAN_INFO_SCALE:
> + *val = st->info->full_scale_mv;
> + *val2 = st->info->channel.scan_type.realbits - 1;
> + return IIO_VAL_FRACTIONAL_LOG2;
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> + *val = st->dec_rate;
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + *val = DIV_ROUND_CLOSEST_ULL(st->ref_frequency, st-
> >dec_rate);
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_OFFSET:
> + *val = -(1 << (st->info->channel.scan_type.realbits - 1));
> + return IIO_VAL_INT;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int ad7405_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int val,
> + int val2, long info)
> +{
> + switch (info) {
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> + if (val < 0)
> + return -EINVAL;
> + return ad7405_set_dec_rate(indio_dev, chan, val);
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int ad7405_read_avail(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + const int **vals, int *type, int *length,
> + long info)
> +{
> + switch (info) {
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> + *vals = ad7405_dec_rates_range;
> + *type = IIO_VAL_INT;
> + return IIO_AVAIL_RANGE;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static const struct iio_info ad7405_iio_info = {
> + .read_raw = &ad7405_read_raw,
> + .write_raw = &ad7405_write_raw,
> + .read_avail = &ad7405_read_avail,
> +};
> +
> +#define AD7405_IIO_CHANNEL { \
> + .type = IIO_VOLTAGE, \
> + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
> + BIT(IIO_CHAN_INFO_OFFSET), \
> + .info_mask_shared_by_all = IIO_CHAN_INFO_SAMP_FREQ | \
> + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
> + .info_mask_shared_by_all_available = \
> + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
> + .indexed = 1, \
> + .channel = 0, \
> + .channel2 = 1, \
> + .differential = 1, \
> + .scan_index = 0, \
> + .scan_type = { \
> + .sign = 'u', \
> + .realbits = 16, \
> + .storagebits = 16, \
> + }, \
> +}
> +
> +static const struct ad7405_chip_info ad7405_chip_info = {
> + .name = "ad7405",
> + .full_scale_mv = 320,
> + .channel = AD7405_IIO_CHANNEL,
> +};
> +
> +static const struct ad7405_chip_info adum7701_chip_info = {
> + .name = "adum7701",
> + .full_scale_mv = 320,
> + .channel = AD7405_IIO_CHANNEL,
> +};
> +
> +static const struct ad7405_chip_info adum7702_chip_info = {
> + .name = "adum7702",
> + .full_scale_mv = 64,
> + .channel = AD7405_IIO_CHANNEL,
> +};
> +
> +static const struct ad7405_chip_info adum7703_chip_info = {
> + .name = "adum7703",
> + .full_scale_mv = 320,
> + .channel = AD7405_IIO_CHANNEL,
> +};
> +
> +static const char * const ad7405_power_supplies[] = {
> + "vdd1", "vdd2",
> +};
> +
> +static int ad7405_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct iio_dev *indio_dev;
> + struct ad7405_state *st;
> + struct clk *clk;
> + int ret;
> +
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + st = iio_priv(indio_dev);
> +
> + st->info = device_get_match_data(dev);
> + if (!st->info)
> + return dev_err_probe(dev, -EINVAL, "no chip info\n");
> +
> + ret = devm_regulator_bulk_get_enable(dev,
> ARRAY_SIZE(ad7405_power_supplies),
> + ad7405_power_supplies);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to get and enable
> supplies");
> +
> + clk = devm_clk_get_enabled(dev, NULL);
> + if (IS_ERR(clk))
> + return PTR_ERR(clk);
> +
> + st->ref_frequency = clk_get_rate(clk);
> + if (!st->ref_frequency)
> + return -EINVAL;
> +
> + indio_dev->name = st->info->name;
> + indio_dev->channels = &st->info->channel;
> + indio_dev->num_channels = 1;
> + indio_dev->info = &ad7405_iio_info;
> +
> + st->back = devm_iio_backend_get(dev, NULL);
> + if (IS_ERR(st->back))
> + return dev_err_probe(dev, PTR_ERR(st->back),
> + "failed to get IIO backend");
> +
> + ret = iio_backend_chan_enable(st->back, 0);
> + if (ret)
> + return ret;
> +
> + ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
> + if (ret)
> + return ret;
> +
> + ret = devm_iio_backend_enable(dev, st->back);
> + if (ret)
> + return ret;
> +
> + /*
> + * Set 256 decimation rate. The default value in the AXI_ADC register
> + * is 0, so we set the register with a decimation rate value that is
> + * functional for all parts.
> + */
> + ret = ad7405_set_dec_rate(indio_dev, &indio_dev->channels[0], 256);
> + if (ret)
> + return ret;
> +
> + return devm_iio_device_register(dev, indio_dev);
> +}
> +
> +static const struct of_device_id ad7405_of_match[] = {
> + { .compatible = "adi,ad7405", .data = &ad7405_chip_info, },
> + { .compatible = "adi,adum7701", .data = &adum7701_chip_info, },
> + { .compatible = "adi,adum7702", .data = &adum7702_chip_info, },
> + { .compatible = "adi,adum7703", .data = &adum7703_chip_info, },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, ad7405_of_match);
> +
> +static struct platform_driver ad7405_driver = {
> + .driver = {
> + .name = "ad7405",
> + .owner = THIS_MODULE,
Drop the above.
> + .of_match_table = ad7405_of_match,
> + },
> + .probe = ad7405_probe,
> +};
> +module_platform_driver(ad7405_driver);
> +
> +MODULE_AUTHOR("Dragos Bogdan <dragos.bogdan@analog.com>");
> +MODULE_AUTHOR("Pop Ioan Daniel <pop.ioan-daniel@analog.com>");
> +MODULE_DESCRIPTION("Analog Devices AD7405 driver");
> +MODULE_LICENSE("GPL");
> +MODULE_IMPORT_NS("IIO_BACKEND");
prev parent reply other threads:[~2025-06-09 8:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 15:09 [PATCH v7 0/5] Add support for AD7405/ADUM770x Pop Ioan Daniel
2025-06-05 15:09 ` [PATCH v7 1/5] iio: adc: ad4851: ad4851_set_oversampling_ratio parameters update Pop Ioan Daniel
2025-06-05 15:09 ` [PATCH v7 2/5] iio: backend: update iio_backend_oversampling_ratio_set Pop Ioan Daniel
2025-06-05 15:09 ` [PATCH v7 3/5] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set Pop Ioan Daniel
2025-06-05 15:09 ` [PATCH v7 4/5] dt-bindings: iio: adc: add ad7405 Pop Ioan Daniel
2025-06-05 15:09 ` [PATCH v7 5/5] iio: adc: ad7405: add ad7405 driver Pop Ioan Daniel
2025-06-07 15:44 ` Jonathan Cameron
2025-06-10 12:09 ` Ioan-daniel, Pop
2025-06-11 15:25 ` Jonathan Cameron
2025-06-12 7:38 ` Ioan-daniel, Pop
2025-06-09 8:05 ` Nuno Sá [this message]
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=930768920f83bf720f660f65050ef61d16610766.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=adureghello@baylibre.com \
--cc=alisadariana@gmail.com \
--cc=andy@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=antoniu.miclaus@analog.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=dragos.bogdan@analog.com \
--cc=gstols@baylibre.com \
--cc=herve.codina@bootlin.com \
--cc=javier.carrasco.cruz@gmail.com \
--cc=jic23@kernel.org \
--cc=joao.goncalves@toradex.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt@analog.com \
--cc=mazziesaccount@gmail.com \
--cc=nuno.sa@analog.com \
--cc=olivier.moysan@foss.st.com \
--cc=pop.ioan-daniel@analog.com \
--cc=ramona.nechita@analog.com \
--cc=robh@kernel.org \
--cc=sergiu.cuciurean@analog.com \
--cc=tgamblin@baylibre.com \
--cc=thomas.bonnefille@bootlin.com \
--cc=tobias.sperling@softing.com \
/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;
as well as URLs for NNTP newsgroup(s).