All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] iio: ad_sigma_delta: Implement a dedicated reset function
@ 2017-09-05 12:14 Dragos Bogdan
  2017-09-05 12:16 ` Lars-Peter Clausen
  0 siblings, 1 reply; 3+ messages in thread
From: Dragos Bogdan @ 2017-09-05 12:14 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron
  Cc: Hartmut Knaack, Peter Meerwald-Stadler, linux-iio, linux-kernel,
	Dragos Bogdan

Since most of the SD ADCs have the option of reseting the serial
interface by sending a number of SCLKs with CS = 0 and DIN = 1,
a dedicated function that can do this is usefull.

Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
---
 drivers/iio/adc/ad_sigma_delta.c       | 28 ++++++++++++++++++++++++++++
 include/linux/iio/adc/ad_sigma_delta.h |  3 +++
 2 files changed, 31 insertions(+)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index d10bd0c97233..22c4c17cd996 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -177,6 +177,34 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
 }
 EXPORT_SYMBOL_GPL(ad_sd_read_reg);
 
+/**
+ * ad_sd_reset() - Reset the serial interface
+ *
+ * @sigma_delta: The sigma delta device
+ * @reset_length: Number of SCLKs with DIN = 1
+ *
+ * Returns 0 on success, an error code otherwise.
+ **/
+int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
+	unsigned int reset_length)
+{
+	uint8_t *buf;
+	unsigned int size;
+	int ret;
+
+	size = DIV_ROUND_UP(reset_length, 8);
+	buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	memset(buf, 0xff, size);
+	ret = spi_write(sigma_delta->spi, buf, size);
+	kfree(buf);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ad_sd_reset);
+
 static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
 	unsigned int mode, unsigned int channel)
 {
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 5ba430cc9a87..1fc7abd28b0b 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -111,6 +111,9 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
 int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
 	unsigned int size, unsigned int *val);
 
+int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
+	unsigned int reset_length);
+
 int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 	const struct iio_chan_spec *chan, int *val);
 int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] iio: ad_sigma_delta: Implement a dedicated reset function
  2017-09-05 12:14 [PATCH 1/2] iio: ad_sigma_delta: Implement a dedicated reset function Dragos Bogdan
@ 2017-09-05 12:16 ` Lars-Peter Clausen
  2017-09-10 15:22   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Lars-Peter Clausen @ 2017-09-05 12:16 UTC (permalink / raw)
  To: Dragos Bogdan, Michael Hennerich, Jonathan Cameron
  Cc: Hartmut Knaack, Peter Meerwald-Stadler, linux-iio, linux-kernel

On 09/05/2017 02:14 PM, Dragos Bogdan wrote:
> Since most of the SD ADCs have the option of reseting the serial
> interface by sending a number of SCLKs with CS = 0 and DIN = 1,
> a dedicated function that can do this is usefull.
> 
> Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>

Acked-by: Lars-Peter Clausen <lars@metafoo.de>

> ---
>  drivers/iio/adc/ad_sigma_delta.c       | 28 ++++++++++++++++++++++++++++
>  include/linux/iio/adc/ad_sigma_delta.h |  3 +++
>  2 files changed, 31 insertions(+)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index d10bd0c97233..22c4c17cd996 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -177,6 +177,34 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
>  }
>  EXPORT_SYMBOL_GPL(ad_sd_read_reg);
>  
> +/**
> + * ad_sd_reset() - Reset the serial interface
> + *
> + * @sigma_delta: The sigma delta device
> + * @reset_length: Number of SCLKs with DIN = 1
> + *
> + * Returns 0 on success, an error code otherwise.
> + **/
> +int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
> +	unsigned int reset_length)
> +{
> +	uint8_t *buf;
> +	unsigned int size;
> +	int ret;
> +
> +	size = DIV_ROUND_UP(reset_length, 8);
> +	buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
> +	memset(buf, 0xff, size);
> +	ret = spi_write(sigma_delta->spi, buf, size);
> +	kfree(buf);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(ad_sd_reset);
> +
>  static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
>  	unsigned int mode, unsigned int channel)
>  {
> diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> index 5ba430cc9a87..1fc7abd28b0b 100644
> --- a/include/linux/iio/adc/ad_sigma_delta.h
> +++ b/include/linux/iio/adc/ad_sigma_delta.h
> @@ -111,6 +111,9 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
>  int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
>  	unsigned int size, unsigned int *val);
>  
> +int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
> +	unsigned int reset_length);
> +
>  int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
>  	const struct iio_chan_spec *chan, int *val);
>  int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] iio: ad_sigma_delta: Implement a dedicated reset function
  2017-09-05 12:16 ` Lars-Peter Clausen
@ 2017-09-10 15:22   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2017-09-10 15:22 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Dragos Bogdan, Michael Hennerich, Hartmut Knaack,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Tue, 5 Sep 2017 14:16:42 +0200
Lars-Peter Clausen <lars@metafoo.de> wrote:

> On 09/05/2017 02:14 PM, Dragos Bogdan wrote:
> > Since most of the SD ADCs have the option of reseting the serial
> > interface by sending a number of SCLKs with CS = 0 and DIN = 1,
> > a dedicated function that can do this is usefull.
> > 
> > Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>  
> 
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>

Applied to the fixes-togreg branch of iio.git and marked
for stable.  I added a note that this was a precursor for
the following patch to justify the stable cc.

Jonathan
> 
> > ---
> >  drivers/iio/adc/ad_sigma_delta.c       | 28 ++++++++++++++++++++++++++++
> >  include/linux/iio/adc/ad_sigma_delta.h |  3 +++
> >  2 files changed, 31 insertions(+)
> > 
> > diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> > index d10bd0c97233..22c4c17cd996 100644
> > --- a/drivers/iio/adc/ad_sigma_delta.c
> > +++ b/drivers/iio/adc/ad_sigma_delta.c
> > @@ -177,6 +177,34 @@ int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta,
> >  }
> >  EXPORT_SYMBOL_GPL(ad_sd_read_reg);
> >  
> > +/**
> > + * ad_sd_reset() - Reset the serial interface
> > + *
> > + * @sigma_delta: The sigma delta device
> > + * @reset_length: Number of SCLKs with DIN = 1
> > + *
> > + * Returns 0 on success, an error code otherwise.
> > + **/
> > +int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
> > +	unsigned int reset_length)
> > +{
> > +	uint8_t *buf;
> > +	unsigned int size;
> > +	int ret;
> > +
> > +	size = DIV_ROUND_UP(reset_length, 8);
> > +	buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
> > +	if (!buf)
> > +		return -ENOMEM;
> > +
> > +	memset(buf, 0xff, size);
> > +	ret = spi_write(sigma_delta->spi, buf, size);
> > +	kfree(buf);
> > +
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(ad_sd_reset);
> > +
> >  static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
> >  	unsigned int mode, unsigned int channel)
> >  {
> > diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> > index 5ba430cc9a87..1fc7abd28b0b 100644
> > --- a/include/linux/iio/adc/ad_sigma_delta.h
> > +++ b/include/linux/iio/adc/ad_sigma_delta.h
> > @@ -111,6 +111,9 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
> >  int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
> >  	unsigned int size, unsigned int *val);
> >  
> > +int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
> > +	unsigned int reset_length);
> > +
> >  int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
> >  	const struct iio_chan_spec *chan, int *val);
> >  int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,
> >   
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-09-10 15:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-05 12:14 [PATCH 1/2] iio: ad_sigma_delta: Implement a dedicated reset function Dragos Bogdan
2017-09-05 12:16 ` Lars-Peter Clausen
2017-09-10 15:22   ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.