From: Jonathan Cameron <jic23@kernel.org>
To: Janani Sunil <janani.sunil@analog.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Alexandru Ardelean <alexandru.ardelean@analog.com>,
"Rob Herring" <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, <linux-iio@vger.kernel.org>,
<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-doc@vger.kernel.org>, <jan.sun97@gmail.com>
Subject: Re: [PATCH v2 2/2] iio: dac: Add MAX22007 DAC driver support
Date: Sun, 11 Jan 2026 16:09:14 +0000 [thread overview]
Message-ID: <20260111160914.72f177e6@jic23-huawei> (raw)
In-Reply-To: <20260108-max22007-dev-v2-2-2506c738784f@analog.com>
On Thu, 8 Jan 2026 13:58:24 +0100
Janani Sunil <janani.sunil@analog.com> wrote:
> Add support for the MAX22007, a 4-channel 12-bit DAC that drives
> voltage or current output on each channel.
>
> Signed-off-by: Janani Sunil <janani.sunil@analog.com>
A few minor things to add to Marcelo's detailed review.
Thanks,
Jonathan
> diff --git a/drivers/iio/dac/max22007.c b/drivers/iio/dac/max22007.c
> new file mode 100644
> index 000000000000..19557c008554
> --- /dev/null
> +++ b/drivers/iio/dac/max22007.c
> +static int max22007_spi_read(void *context, const void *reg, size_t reg_size,
> + void *val, size_t val_size)
> +{
> + struct max22007_state *st = context;
> + u8 reg_byte = *(u8 *)reg;
> + u8 calculated_crc, received_crc;
> + u8 crc_data[3];
> + u8 rx_buf[4];
> + int ret;
> +
> + if (reg_size != 1)
> + return -EINVAL;
> +
> + ret = spi_write_then_read(st->spi, ®_byte, 1, rx_buf,
> + val_size + MAX22007_CRC_OVERHEAD);
> + if (ret) {
> + dev_err(&st->spi->dev, "SPI transfer failed: %d\n", ret);
> + return ret;
> + }
> +
> + crc_data[0] = reg_byte;
> + crc_data[1] = rx_buf[0];
> + crc_data[2] = rx_buf[1];
> +
> + calculated_crc = crc8(max22007_crc8_table, crc_data, 3, 0x00);
I think you can chain CRCs as follows and avoid the need for a local array
just to marshal the data.
calculated_crc = crc8(max22007_crc8_table, ®_byte, 1, 0x00);
calculated_crc = crc8(max22007_crc8_table, rx_buf, 2, caculated_crc);
> + received_crc = rx_buf[val_size];
> +
> + if (calculated_crc != received_crc) {
> + dev_err(&st->spi->dev, "CRC mismatch on read register %02x\n", reg_byte);
> + return -EIO;
> + }
> +
> + memcpy(val, rx_buf, val_size);
> +
> + return 0;
> +}
> +static ssize_t max22007_write_dac_powerdown(struct iio_dev *indio_dev,
> + uintptr_t private,
> + const struct iio_chan_spec *chan,
> + const char *buf, size_t len)
> +{
> + struct max22007_state *st = iio_priv(indio_dev);
> + bool powerdown;
> + int ret;
> +
> + ret = kstrtobool(buf, &powerdown);
> + if (ret)
> + return ret;
> +
> + if (powerdown)
> + ret = regmap_update_bits(st->regmap, MAX22007_CHANNEL_MODE_REG,
> + MAX22007_CH_PWRON_CH_MASK(chan->channel),
> + MAX22007_CH_PWR_VAL(chan->channel, 0));
> + else
> + ret = regmap_update_bits(st->regmap, MAX22007_CHANNEL_MODE_REG,
> + MAX22007_CH_PWRON_CH_MASK(chan->channel),
> + MAX22007_CH_PWR_VAL(chan->channel, 1));
> + if (ret)
> + return ret;
> +
Something like the following reduces duplication:
ret = regmap_update_bits(st->regmap, MAX22007_CHANNEL_MODE_REG,
MAX2207_CH_PWRON_CH_MASK(chan->channel),
MAX2207_CH_PWR_VAL(chan->channel, powerdown ? 1 : 0);
> + return len;
> +}
next prev parent reply other threads:[~2026-01-11 16:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 12:58 [PATCH v2 0/2] Subject: [PATCH v1 0/3] iio: dac: Add support for MAX22007 DAC Janani Sunil
2026-01-08 12:58 ` [PATCH v2 1/2] dt-bindings: iio: dac: Add max22007 Janani Sunil
2026-01-09 8:26 ` Krzysztof Kozlowski
2026-01-09 12:44 ` Marcelo Schmitt
2026-01-09 14:08 ` Janani Sunil
2026-01-08 12:58 ` [PATCH v2 2/2] iio: dac: Add MAX22007 DAC driver support Janani Sunil
2026-01-09 14:11 ` Marcelo Schmitt
2026-01-09 15:36 ` Janani Sunil
2026-01-11 15:56 ` Jonathan Cameron
2026-01-11 16:09 ` Jonathan Cameron [this message]
2026-01-12 20:26 ` Jonathan Cameron
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=20260111160914.72f177e6@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=alexandru.ardelean@analog.com \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=jan.sun97@gmail.com \
--cc=janani.sunil@analog.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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