From: Jonathan Cameron <jic23@kernel.org>
To: Guillaume Stols <gstols@baylibre.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Nuno Sa <nuno.sa@analog.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, dlechner@baylibre.com,
jstephan@baylibre.com, aardelean@baylibre.com,
adureghello@baylibre.com
Subject: Re: [PATCH v2 6/9] iio: adc: adi-axi-adc: Add support for AD7606 register writing
Date: Sun, 15 Dec 2024 12:05:23 +0000 [thread overview]
Message-ID: <20241215120523.1b60ed43@jic23-huawei> (raw)
In-Reply-To: <20241210-ad7606_add_iio_backend_software_mode-v2-6-6619c3e50d81@baylibre.com>
On Tue, 10 Dec 2024 10:46:46 +0000
Guillaume Stols <gstols@baylibre.com> wrote:
> Since we must access the bus parallel bus using a custom procedure,
> let's add a specialized compatible, and define specialized callbacks for
> writing the registers using the parallel interface.
>
> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
Hi Guillaume,
A few comments inline.
Thanks,
Jonathan
> ---
> drivers/iio/adc/ad7606_bi.h | 16 +++++++
> drivers/iio/adc/adi-axi-adc.c | 100 ++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 116 insertions(+)
>
> diff --git a/drivers/iio/adc/ad7606_bi.h b/drivers/iio/adc/ad7606_bi.h
> new file mode 100644
> index 000000000000..9ade23ec61dd
> --- /dev/null
> +++ b/drivers/iio/adc/ad7606_bi.h
Why bi? Bus interface? I'd spell it out. Header name lengths don't
usually need to be quite this short.
> @@ -0,0 +1,16 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (c) 2010-2024 Analog Devices Inc.
> + * Copyright (c) 2024 Baylibre, SAS
> + */
> +#ifndef __LINUX_PLATFORM_DATA_AD7606_H__
> +#define __LINUX_PLATFORM_DATA_AD7606_H__
> +
> +#include <linux/iio/backend.h>
Only a pointer type needed, so a forward def better than an include
(which costs some trivial amount of compile time).
struct iio_backend;
> +
> +struct ad7606_platform_data {
> + int (*bus_reg_read)(struct iio_backend *back, u32 reg, u32 *val);
> + int (*bus_reg_write)(struct iio_backend *back, u32 reg, u32 val);
> +};
> +
> +#endif /* __LINUX_PLATFORM_DATA_AD7606_H__ */
> diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
> index 7ff636643e56..b8bcf89417b0 100644
> --- a/drivers/iio/adc/adi-axi-adc.c
> +++ b/drivers/iio/adc/adi-axi-adc.c
> @@ -27,6 +27,7 @@
> #include <linux/iio/buffer.h>
> #include <linux/iio/iio.h>
>
> +#include "ad7606_bi.h"
> /*
> * Register definitions:
> * https://wiki.analog.com/resources/fpga/docs/axi_adc_ip#register_map
> @@ -73,6 +74,12 @@
> #define ADI_AXI_ADC_REG_DELAY(l) (0x0800 + (l) * 0x4)
> #define AXI_ADC_DELAY_CTRL_MASK GENMASK(4, 0)
>
> +#define ADI_AXI_REG_CONFIG_WR 0x0080
> +#define ADI_AXI_REG_CONFIG_RD 0x0084
> +#define ADI_AXI_REG_CONFIG_CTRL 0x008c
> +#define ADI_AXI_REG_CONFIG_CTRL_READ 0x03
> +#define ADI_AXI_REG_CONFIG_CTRL_WRITE 0x01
> +
> #define ADI_AXI_ADC_MAX_IO_NUM_LANES 15
>
> #define ADI_AXI_REG_CHAN_CTRL_DEFAULTS \
> @@ -80,6 +87,11 @@
> ADI_AXI_REG_CHAN_CTRL_FMT_EN | \
> ADI_AXI_REG_CHAN_CTRL_ENABLE)
>
> +/* AD7606's specific */
> +#define AD7606_REG_READ_BIT 0x8000
> +#define AD7606_REG_ADDRESS_MASK 0xff00
> +#define AD7606_REG_VALUE_MASK 0x00ff
> +
Maybe name these to keep the ADI_AXI_ prefix as well. Otherwise it might get
a little confusing wrt to registers in teh deivce. They are nice short
names currently so that shouldn't make the code to messy.
> struct axi_adc_info {
> unsigned int version;
> const struct iio_backend_info *backend_info;
> @@ -313,6 +325,80 @@ static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
> return iio_dmaengine_buffer_setup(st->dev, indio_dev, dma_name);
> }
>
> +static int axi_adc_raw_write(struct iio_backend *back, void *buf, unsigned int len)
> +{
> + struct adi_axi_adc_state *st = iio_backend_get_priv(back);
> + u32 data;
> + u32 *bdata = buf;
data = *(u32)(buf);
Is fine here I think rather than the extra local variable that is just
used to do the type cast.
> +
> + data = *bdata;
> + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_WR, data);
> + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_CTRL,
> + ADI_AXI_REG_CONFIG_CTRL_WRITE);
> + usleep_range(50, 100);
> + regmap_write(st->regmap, ADI_AXI_REG_CONFIG_CTRL, 0x00);
> + usleep_range(50, 100);
> +
> + return 0;
> +}
...
> +
> +static int ad7606_bi_reg_write(struct iio_backend *back, u32 reg, u32 val)
> +{
> + struct adi_axi_adc_state *st = iio_backend_get_priv(back);
> + u32 buf;
> +
> + guard(mutex)(&st->lock);
> +
> + /* Read any register to switch to register mode */
What follows looks like a write...
> + buf = 0xaf00;
> + axi_adc_raw_write(back, &buf, sizeof(buf));
> +
> + buf = FIELD_PREP(AD7606_REG_ADDRESS_MASK, reg) | FIELD_PREP(AD7606_REG_VALUE_MASK, val);
> + axi_adc_raw_write(back, &buf, sizeof(buf));
> +
> + /* Write 0x0 on the bus to get back to ADC mode */
> + buf = 0;
> + axi_adc_raw_write(back, &buf, sizeof(buf));
> +
> + return 0;
> +}
next prev parent reply other threads:[~2024-12-15 12:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 10:46 [PATCH v2 0/9] Add support for Software mode on AD7606's iio backend driver Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 1/9] iio: adc: ad7606: Fix hardcoded offset in the ADC channels Guillaume Stols
2024-12-14 18:26 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 2/9] dt-bindings: iio: dac: adi-axi-adc: Add ad7606 variant Guillaume Stols
2024-12-10 12:31 ` Rob Herring (Arm)
2024-12-11 22:01 ` David Lechner
2024-12-10 10:46 ` [PATCH v2 3/9] iio:adc: ad7606: Move the software mode configuration Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 4/9] iio: adc: ad7606: Move software functions into common file Guillaume Stols
2024-12-15 11:51 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 5/9] iio: adc: adi-axi-adc: Add platform children support Guillaume Stols
2024-12-15 11:57 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 6/9] iio: adc: adi-axi-adc: Add support for AD7606 register writing Guillaume Stols
2024-12-15 12:05 ` Jonathan Cameron [this message]
2024-12-10 10:46 ` [PATCH v2 7/9] iio: adc: ad7606: change r/w_register signature Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 8/9] iio: adc: ad7606: Change channel macros parameters Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 9/9] iio: adc: ad7606: Add support for writing registers when using backend Guillaume Stols
2024-12-15 12:12 ` 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=20241215120523.1b60ed43@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=aardelean@baylibre.com \
--cc=adureghello@baylibre.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=gstols@baylibre.com \
--cc=jstephan@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@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