diff mbox series

[v1,1/3] iio: adc: ad_sigma_delta: Add CS assert function

Message ID 20241221155926.81954-2-alisa.roman@analog.com (mailing list archive)
State New
Headers show
Series Add support for AD7191 | expand

Commit Message

Alisa-Dariana Roman Dec. 21, 2024, 3:56 p.m. UTC
Some sigma-delta ADCs, such as AD7191 and AD7780, have no registers and
start conversion when CS is asserted. Add helper function to support
this use case by allowing devices to assert CS without performing
register operations.

This function can be used by drivers through their set_mode callback.

Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com>
---
 drivers/iio/adc/ad_sigma_delta.c       | 24 ++++++++++++++++++++++++
 include/linux/iio/adc/ad_sigma_delta.h |  1 +
 2 files changed, 25 insertions(+)

Comments

Jonathan Cameron Dec. 22, 2024, 6:07 p.m. UTC | #1
On Sat, 21 Dec 2024 17:56:00 +0200
Alisa-Dariana Roman <alisadariana@gmail.com> wrote:

> Some sigma-delta ADCs, such as AD7191 and AD7780, have no registers and
> start conversion when CS is asserted. Add helper function to support
> this use case by allowing devices to assert CS without performing
> register operations.
Hi Alisa-Dariana,

I had a look at the ad7191 datasheet. Given this description,
I was expecting to see it do a pre pulse of the chip select to trigger
the acquisition.  However, what I see is a power down line (which is more
or less a chip select) but it just has a specified t1 delay before the
DOUT will change to the state for the first bit and the host
can start driving the clock.

That can be done by setting spi_device->cs_setup to whatever delay is
needed.  The text is spi_device docs are a little vague,
but I'd take it as t1 + t2 (maybe t3 to be safe).

That is going to be more reliable than trying to hold the cs across
messages / spi_sync() calls, particularly if the bus might not be
locked (which the code below suggests).

Jonathan


> 
> This function can be used by drivers through their set_mode callback.
> 
> Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com>
> ---
>  drivers/iio/adc/ad_sigma_delta.c       | 24 ++++++++++++++++++++++++
>  include/linux/iio/adc/ad_sigma_delta.h |  1 +
>  2 files changed, 25 insertions(+)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index 0f355dac7813..c0f33d4baddf 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -48,6 +48,30 @@ void ad_sd_set_comm(struct ad_sigma_delta *sigma_delta, uint8_t comm)
>  }
>  EXPORT_SYMBOL_NS_GPL(ad_sd_set_comm, "IIO_AD_SIGMA_DELTA");
>  
> +/**
> + * ad_sd_assert_cs() - Assert chip select line
> + *
> + * @sigma_delta: The sigma delta device
> + *
> + * Returns 0 on success, an error code otherwise.
> + **/
> +int ad_sd_assert_cs(struct ad_sigma_delta *sigma_delta)
> +{
> +	struct spi_transfer t = {
> +		.len = 0,
> +		.cs_change = sigma_delta->keep_cs_asserted,
> +	};
> +	struct spi_message m;
> +
> +	spi_message_init(&m);
> +	spi_message_add_tail(&t, &m);
> +
> +	if (sigma_delta->bus_locked)
> +		return spi_sync_locked(sigma_delta->spi, &m);
> +	return spi_sync(sigma_delta->spi, &m);
> +}
> +EXPORT_SYMBOL_NS_GPL(ad_sd_assert_cs, IIO_AD_SIGMA_DELTA);
> +
>  /**
>   * ad_sd_write_reg() - Write a register
>   *
> diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> index 417073c52380..99ab56d04793 100644
> --- a/include/linux/iio/adc/ad_sigma_delta.h
> +++ b/include/linux/iio/adc/ad_sigma_delta.h
> @@ -178,6 +178,7 @@ static inline int ad_sigma_delta_postprocess_sample(struct ad_sigma_delta *sd,
>  }
>  
>  void ad_sd_set_comm(struct ad_sigma_delta *sigma_delta, uint8_t comm);
> +int ad_sd_assert_cs(struct ad_sigma_delta *sigma_delta);
>  int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
>  	unsigned int size, unsigned int val);
>  int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 0f355dac7813..c0f33d4baddf 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -48,6 +48,30 @@  void ad_sd_set_comm(struct ad_sigma_delta *sigma_delta, uint8_t comm)
 }
 EXPORT_SYMBOL_NS_GPL(ad_sd_set_comm, "IIO_AD_SIGMA_DELTA");
 
+/**
+ * ad_sd_assert_cs() - Assert chip select line
+ *
+ * @sigma_delta: The sigma delta device
+ *
+ * Returns 0 on success, an error code otherwise.
+ **/
+int ad_sd_assert_cs(struct ad_sigma_delta *sigma_delta)
+{
+	struct spi_transfer t = {
+		.len = 0,
+		.cs_change = sigma_delta->keep_cs_asserted,
+	};
+	struct spi_message m;
+
+	spi_message_init(&m);
+	spi_message_add_tail(&t, &m);
+
+	if (sigma_delta->bus_locked)
+		return spi_sync_locked(sigma_delta->spi, &m);
+	return spi_sync(sigma_delta->spi, &m);
+}
+EXPORT_SYMBOL_NS_GPL(ad_sd_assert_cs, IIO_AD_SIGMA_DELTA);
+
 /**
  * ad_sd_write_reg() - Write a register
  *
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 417073c52380..99ab56d04793 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -178,6 +178,7 @@  static inline int ad_sigma_delta_postprocess_sample(struct ad_sigma_delta *sd,
 }
 
 void ad_sd_set_comm(struct ad_sigma_delta *sigma_delta, uint8_t comm);
+int ad_sd_assert_cs(struct ad_sigma_delta *sigma_delta);
 int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
 	unsigned int size, unsigned int val);
 int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,