From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Michael Hennerich" <michael.hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Jonathan Corbet" <corbet@lwn.net>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
"Ramona Gradinariu" <ramona.gradinariu@analog.com>
Subject: Re: [PATCH v3 2/3] iio: adc: ad4695: Add driver for AD4695 and similar ADCs
Date: Sat, 29 Jun 2024 20:20:03 +0100 [thread overview]
Message-ID: <20240629202003.1b72f0d0@jic23-huawei> (raw)
In-Reply-To: <20240624-iio-adc-ad4695-v3-2-a22c302f06bf@baylibre.com>
On Mon, 24 Jun 2024 17:01:54 -0500
David Lechner <dlechner@baylibre.com> wrote:
> This is a new driver for Analog Devices Inc. AD4695 and similar ADCs.
> The initial driver supports initializing the chip including configuring
> all possible LDO and reference voltage sources as well as any possible
> voltage input channel wiring configuration.
>
> Only the 4-wire SPI wiring mode where the CNV pin is tied to the CS pin
> is supported at this time. And reading sample data from the ADC can only
> be done in direct mode for now.
>
> Co-developed-by: Ramona Gradinariu <ramona.gradinariu@analog.com>
> Signed-off-by: Ramona Gradinariu <ramona.gradinariu@analog.com>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
Some minor bits an pieces from me.
> diff --git a/drivers/iio/adc/ad4695.c b/drivers/iio/adc/ad4695.c
> new file mode 100644
> index 000000000000..72ab5b997f6e
> --- /dev/null
> +++ b/drivers/iio/adc/ad4695.c
> @@ -0,0 +1,730 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * SPI ADC driver for Analog Devices Inc. AD4695 and similar chips
> + *
> + * https://www.analog.com/en/products/ad4695.html
> + * https://www.analog.com/en/products/ad4696.html
> + * https://www.analog.com/en/products/ad4697.html
> + * https://www.analog.com/en/products/ad4698.html
> + *
> + * Copyright 2024 Analog Devices Inc.
> + * Copyright 2024 BayLibre, SAS
> + */
> +
> +#include <dt-bindings/iio/adi,ad4695.h>
Stick driver specific includes after linux ones.
Probably a blank line in between as well.
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
> +#include <linux/compiler.h>
> +#include <linux/delay.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/iio/iio.h>
> +#include <linux/property.h>
> +#include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/spi/spi.h>
> +#include <linux/units.h>
> +
> +
> +/**
> + * ad4695_read_one_sample - Read a single sample using single-cycle mode
> + * @st: The AD4695 state
> + * @address: The address of the channel to read
> + *
> + * Upon return, the sample will be stored in the raw_data field of @st.
> + *
> + * Context: can sleep, must be called with iio_device_claim_direct held
> + * Return: 0 on success, a negative error code on failure
> + */
> +static int ad4695_read_one_sample(struct ad4695_state *st, unsigned int address)
> +{
> + struct spi_transfer xfer[2] = { };
> + int ret;
> +
> + ret = ad4695_set_single_cycle_mode(st, address);
> + if (ret)
> + return ret;
> +
> + /*
> + * Setting the first channel to the temperature channel isn't supported
> + * in single-cycle mode, so we have to do an extra xfer to read the
> + * temperature.
> + */
> + if (address == AD4695_CMD_TEMP_CHAN) {
> + /* We aren't reading, so we can make this a short xfer. */
I'd be tempted to let the compiler figure out it can combine storage for xfer and
do something like
struct spi_transfer xfer[2] = {
{
.bits_per_word = 8,
.tx_buf = ...
}, {
},
};
st->cnv_cmd2 = ...
etc
Advantage is that it is clearly structured data. Up to you though to
decide if this is worth doing. I don't care that much!
> + st->cnv_cmd2 = AD4695_CMD_TEMP_CHAN << 3;
> + xfer[0].bits_per_word = 8;
> + xfer[0].tx_buf = &st->cnv_cmd2;
> + xfer[0].len = 1;
> + xfer[0].cs_change = 1;
> + xfer[0].cs_change_delay.value = AD4695_T_CONVERT_NS;
> + xfer[0].cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
> +
> + /* Then read the result and exit conversion mode. */
> + st->cnv_cmd = AD4695_CMD_EXIT_CNV_MODE << 11;
> + xfer[1].bits_per_word = 16;
> + xfer[1].tx_buf = &st->cnv_cmd;
> + xfer[1].rx_buf = &st->raw_data;
> + xfer[1].len = 2;
> +
> + return spi_sync_transfer(st->spi, xfer, 2);
> + }
then an else here to reduce the scope of another xfer structure.
> +
> + /*
> + * The conversion has already been done and we just have to read the
> + * result and exit conversion mode.
> + */
> + st->cnv_cmd = AD4695_CMD_EXIT_CNV_MODE << 11;
> + xfer[0].bits_per_word = 16;
> + xfer[0].tx_buf = &st->cnv_cmd;
> + xfer[0].rx_buf = &st->raw_data;
> + xfer[0].len = 2;
> +
> + return spi_sync_transfer(st->spi, xfer, 1);
> +}
next prev parent reply other threads:[~2024-06-29 19:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-24 22:01 [PATCH v3 0/3] iio: adc: ad4695: new driver for AD4695 and similar ADCs David Lechner
2024-06-24 22:01 ` [PATCH v3 1/3] dt-bindings: iio: adc: add " David Lechner
2024-06-24 23:28 ` Rob Herring (Arm)
2024-06-25 15:49 ` Conor Dooley
2024-06-24 22:01 ` [PATCH v3 2/3] iio: adc: ad4695: Add driver for " David Lechner
2024-06-26 11:47 ` Nuno Sá
2024-06-26 14:42 ` David Lechner
2024-06-26 15:05 ` Nuno Sá
2024-06-29 19:20 ` Jonathan Cameron [this message]
2024-07-11 16:11 ` David Lechner
2024-06-24 22:01 ` [PATCH v3 3/3] Documentation: iio: Document ad4695 driver 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=20240629202003.1b72f0d0@jic23-huawei \
--to=jic23@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.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=michael.hennerich@analog.com \
--cc=nuno.sa@analog.com \
--cc=ramona.gradinariu@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;
as well as URLs for NNTP newsgroup(s).