From: "Nuno Sá" <noname.nuno@gmail.com>
To: "Angelo Dureghello" <adureghello@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Jonathan Corbet" <corbet@lwn.net>,
"Olivier Moysan" <olivier.moysan@foss.st.com>,
"Michael Hennerich" <Michael.Hennerich@analog.com>
Cc: linux-iio@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] iio: dac: ad3552r-hs: add support for internal ramp
Date: Fri, 28 Mar 2025 08:28:01 +0000 [thread overview]
Message-ID: <2d12ff156996876e5bd85c793c07bb0c6747981c.camel@gmail.com> (raw)
In-Reply-To: <20250321-wip-bl-ad3552r-fixes-v1-4-3c1aa249d163@baylibre.com>
On Fri, 2025-03-21 at 21:28 +0100, Angelo Dureghello wrote:
> From: Angelo Dureghello <adureghello@baylibre.com>
>
> The ad3552r can be feeded from the HDL controller by an internally
> generated 16bit ramp, useful for debug pourposes. Add debugfs a file
> to enable or disable it.
>
> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
> ---
> drivers/iio/dac/ad3552r-hs.c | 106 ++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 100 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/dac/ad3552r-hs.c b/drivers/iio/dac/ad3552r-hs.c
> index
> 37397e188f225a8099745ec03f7c604da76960b1..41fe78d982a68980db059b095fc27b37ea1a461b
> 100644
> --- a/drivers/iio/dac/ad3552r-hs.c
> +++ b/drivers/iio/dac/ad3552r-hs.c
> @@ -7,6 +7,7 @@
> */
>
> #include <linux/bitfield.h>
> +#include <linux/debugfs.h>
> #include <linux/delay.h>
> #include <linux/gpio/consumer.h>
> #include <linux/iio/backend.h>
> @@ -65,6 +66,18 @@ static int ad3552r_hs_reg_read(struct ad3552r_hs_state *st, u32
> reg, u32 *val,
> return st->data->bus_reg_read(st->back, reg, val, xfer_size);
> }
>
> +static int ad3552r_hs_set_data_source(struct ad3552r_hs_state *st,
> + enum iio_backend_data_source type)
> +{
> + int ret;
> +
> + ret = iio_backend_data_source_set(st->back, 0, type);
> + if (ret)
> + return ret;
> +
> + return iio_backend_data_source_set(st->back, 1, type);
>
I know it's a debug thing but we could use some locking in the above...
> +}
> +
> static int ad3552r_hs_update_reg_bits(struct ad3552r_hs_state *st, u32 reg,
> u32 mask, u32 val, size_t xfer_size)
> {
> @@ -483,6 +496,66 @@ static int ad3552r_hs_reg_access(struct iio_dev *indio_dev,
> unsigned int reg,
> return st->data->bus_reg_write(st->back, reg, writeval, 1);
> }
>
> +static ssize_t ad3552r_hs_show_data_source(struct file *f, char __user *userbuf,
> + size_t count, loff_t *ppos)
> +{
> + struct ad3552r_hs_state *st = file_inode(f)->i_private;
> + enum iio_backend_data_source type;
> + int ret;
> +
> + ret = iio_backend_data_source_get(st->back, 0, &type);
> + if (ret)
> + return ret;
> +
> + switch (type) {
> + case IIO_BACKEND_INTERNAL_RAMP_16BIT:
> + return simple_read_from_buffer(userbuf, count, ppos,
> + "backend-ramp-generator", 22);
> + case IIO_BACKEND_EXTERNAL:
> + return simple_read_from_buffer(userbuf, count, ppos,
> + "iio-buffer", 10);
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static ssize_t ad3552r_hs_write_data_source(struct file *f,
> + const char __user *userbuf,
> + size_t count, loff_t *ppos)
> +{
> + struct ad3552r_hs_state *st = file_inode(f)->i_private;
> + char buf[64];
> + int ret;
> +
> + ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf,
> + count);
> + if (ret < 0)
> + return ret;
> +
> + buf[count] = 0;
> +
> + if (count == 10 && !strncmp(buf, "iio-buffer", 10)) {
> + ret = ad3552r_hs_set_data_source(st, IIO_BACKEND_EXTERNAL);
> + if (ret)
> + return ret;
> + } else if (count == 22 && !strncmp(buf, "backend-ramp-generator", 22)) {
> + ret = ad3552r_hs_set_data_source(st,
> + IIO_BACKEND_INTERNAL_RAMP_16BIT);
> + if (ret)
> + return ret;
> + } else {
> + return -EINVAL;
> + }
Are we expected to add more data types in the future? If not, this could be simply an
enable/disable ramp generator thing... It would be much simpler.
Anyways, you could define a static array and use match_string()?
Lastly, for insterfaces like this, it's always helpful to have an _available kind of
attribute.
- Nuno Sá
>
> static const struct of_device_id ad3552r_hs_of_id[] = {
>
next prev parent reply other threads:[~2025-03-28 8:27 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-21 20:28 [PATCH 0/4] iio: ad3552r-hs: add support for internal ramp generator Angelo Dureghello
2025-03-21 20:28 ` [PATCH 1/4] docs: iio: add documentation for ad3552r driver Angelo Dureghello
2025-03-26 22:28 ` Marcelo Schmitt
2025-03-27 8:52 ` Angelo Dureghello
2025-03-27 12:54 ` Marcelo Schmitt
2025-03-30 16:50 ` Jonathan Cameron
2025-03-21 20:28 ` [PATCH 2/4] iio: backend: add support for data source get Angelo Dureghello
2025-03-21 20:28 ` [PATCH 3/4] iio: dac: adi-axi-dac: add " Angelo Dureghello
2025-03-28 8:15 ` Nuno Sá
2025-03-31 14:40 ` Angelo Dureghello
2025-03-21 20:28 ` [PATCH 4/4] iio: dac: ad3552r-hs: add support for internal ramp Angelo Dureghello
2025-03-26 21:52 ` Marcelo Schmitt
2025-03-27 8:56 ` Angelo Dureghello
2025-03-27 12:09 ` Marcelo Schmitt
2025-03-28 8:09 ` Nuno Sá
2025-03-28 8:28 ` Nuno Sá [this message]
2025-03-28 16:40 ` David Lechner
2025-03-30 17:01 ` Jonathan Cameron
2025-03-30 16:53 ` [PATCH 0/4] iio: ad3552r-hs: add support for internal ramp generator Jonathan Cameron
2025-03-31 19:11 ` Angelo Dureghello
2025-04-01 9:20 ` Nuno Sá
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=2d12ff156996876e5bd85c793c07bb0c6747981c.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=adureghello@baylibre.com \
--cc=corbet@lwn.net \
--cc=jic23@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=nuno.sa@analog.com \
--cc=olivier.moysan@foss.st.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