All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: ad_sigma_delta: Introduce prepare_channel callback
@ 2019-03-19  9:53 Alexandru Ardelean
  2019-03-24 17:49 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandru Ardelean @ 2019-03-19  9:53 UTC (permalink / raw)
  To: linux-iio; +Cc: Lars-Peter Clausen, Alexandru Ardelean

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

The prepare channel callback will be called before starting a conversion and
can be used by the driver to configure the chip according to the selected
channel.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/adc/ad_sigma_delta.c       |  5 +++++
 include/linux/iio/adc/ad_sigma_delta.h | 13 +++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index ff5f2da2e1b1..00808838edd8 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -285,6 +285,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 		return -EBUSY;
 
 	mutex_lock(&indio_dev->mlock);
+	ad_sigma_delta_prepare_channel(sigma_delta, chan);
 	ad_sigma_delta_set_channel(sigma_delta, chan->address);
 
 	spi_bus_lock(sigma_delta->spi->master);
@@ -351,6 +352,10 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
 
 	channel = find_first_bit(indio_dev->active_scan_mask,
 				 indio_dev->masklength);
+	ret = ad_sigma_delta_prepare_channel(sigma_delta,
+		&indio_dev->channels[channel]);
+	if (ret)
+		goto err_predisable;
 	ret = ad_sigma_delta_set_channel(sigma_delta,
 		indio_dev->channels[channel].address);
 	if (ret)
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 7e84351fa2c0..21ee12543bdd 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -31,6 +31,8 @@ struct iio_dev;
 
 /**
  * struct ad_sigma_delta_info - Sigma Delta driver specific callbacks and options
+ * @prepare_channel: Will be called to prepare and configure a channel, may be
+ *                   NULL.
  * @set_channel: Will be called to select the current channel, may be NULL.
  * @set_mode: Will be called to select the current mode, may be NULL.
  * @postprocess_sample: Is called for each sampled data word, can be used to
@@ -43,6 +45,8 @@ struct iio_dev;
  *   be used.
  */
 struct ad_sigma_delta_info {
+	int (*prepare_channel)(struct ad_sigma_delta *,
+		const struct iio_chan_spec *);
 	int (*set_channel)(struct ad_sigma_delta *, unsigned int channel);
 	int (*set_mode)(struct ad_sigma_delta *, enum ad_sigma_delta_mode mode);
 	int (*postprocess_sample)(struct ad_sigma_delta *, unsigned int raw_sample);
@@ -81,6 +85,15 @@ struct ad_sigma_delta {
 	uint8_t				data[4] ____cacheline_aligned;
 };
 
+static inline int ad_sigma_delta_prepare_channel(struct ad_sigma_delta *sd,
+	const struct iio_chan_spec *chan)
+{
+	if (sd->info->prepare_channel)
+		return sd->info->prepare_channel(sd, chan);
+
+	return 0;
+}
+
 static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,
 	unsigned int channel)
 {
-- 
2.17.1


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

* Re: [PATCH] iio: ad_sigma_delta: Introduce prepare_channel callback
  2019-03-19  9:53 [PATCH] iio: ad_sigma_delta: Introduce prepare_channel callback Alexandru Ardelean
@ 2019-03-24 17:49 ` Jonathan Cameron
  2019-03-26  6:53   ` Ardelean, Alexandru
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2019-03-24 17:49 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, Lars-Peter Clausen

On Tue, 19 Mar 2019 11:53:06 +0200
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> From: Lars-Peter Clausen <lars@metafoo.de>
> 
> The prepare channel callback will be called before starting a conversion and
> can be used by the driver to configure the chip according to the selected
> channel.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

Hi Alexandru,

Not without a user....  I.e. I want to see a driver using this before
I apply it. In of itself, it is fine but right now I can't answer the
'why?' question!

Jonathan

> ---
>  drivers/iio/adc/ad_sigma_delta.c       |  5 +++++
>  include/linux/iio/adc/ad_sigma_delta.h | 13 +++++++++++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index ff5f2da2e1b1..00808838edd8 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -285,6 +285,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
>  		return -EBUSY;
>  
>  	mutex_lock(&indio_dev->mlock);
> +	ad_sigma_delta_prepare_channel(sigma_delta, chan);
>  	ad_sigma_delta_set_channel(sigma_delta, chan->address);
>  
>  	spi_bus_lock(sigma_delta->spi->master);
> @@ -351,6 +352,10 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
>  
>  	channel = find_first_bit(indio_dev->active_scan_mask,
>  				 indio_dev->masklength);
> +	ret = ad_sigma_delta_prepare_channel(sigma_delta,
> +		&indio_dev->channels[channel]);
> +	if (ret)
> +		goto err_predisable;
>  	ret = ad_sigma_delta_set_channel(sigma_delta,
>  		indio_dev->channels[channel].address);
>  	if (ret)
> diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> index 7e84351fa2c0..21ee12543bdd 100644
> --- a/include/linux/iio/adc/ad_sigma_delta.h
> +++ b/include/linux/iio/adc/ad_sigma_delta.h
> @@ -31,6 +31,8 @@ struct iio_dev;
>  
>  /**
>   * struct ad_sigma_delta_info - Sigma Delta driver specific callbacks and options
> + * @prepare_channel: Will be called to prepare and configure a channel, may be
> + *                   NULL.
>   * @set_channel: Will be called to select the current channel, may be NULL.
>   * @set_mode: Will be called to select the current mode, may be NULL.
>   * @postprocess_sample: Is called for each sampled data word, can be used to
> @@ -43,6 +45,8 @@ struct iio_dev;
>   *   be used.
>   */
>  struct ad_sigma_delta_info {
> +	int (*prepare_channel)(struct ad_sigma_delta *,
> +		const struct iio_chan_spec *);
>  	int (*set_channel)(struct ad_sigma_delta *, unsigned int channel);
>  	int (*set_mode)(struct ad_sigma_delta *, enum ad_sigma_delta_mode mode);
>  	int (*postprocess_sample)(struct ad_sigma_delta *, unsigned int raw_sample);
> @@ -81,6 +85,15 @@ struct ad_sigma_delta {
>  	uint8_t				data[4] ____cacheline_aligned;
>  };
>  
> +static inline int ad_sigma_delta_prepare_channel(struct ad_sigma_delta *sd,
> +	const struct iio_chan_spec *chan)
> +{
> +	if (sd->info->prepare_channel)
> +		return sd->info->prepare_channel(sd, chan);
> +
> +	return 0;
> +}
> +
>  static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,
>  	unsigned int channel)
>  {


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

* Re: [PATCH] iio: ad_sigma_delta: Introduce prepare_channel callback
  2019-03-24 17:49 ` Jonathan Cameron
@ 2019-03-26  6:53   ` Ardelean, Alexandru
  0 siblings, 0 replies; 3+ messages in thread
From: Ardelean, Alexandru @ 2019-03-26  6:53 UTC (permalink / raw)
  To: jic23; +Cc: lars, linux-iio

On Sun, 2019-03-24 at 17:49 +0000, Jonathan Cameron wrote:
> [External]
> 
> 
> On Tue, 19 Mar 2019 11:53:06 +0200
> Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> 
> > From: Lars-Peter Clausen <lars@metafoo.de>
> > 
> > The prepare channel callback will be called before starting a
> > conversion and
> > can be used by the driver to configure the chip according to the
> > selected
> > channel.
> > 
> > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> 
> Hi Alexandru,
> 
> Not without a user....  I.e. I want to see a driver using this before
> I apply it. In of itself, it is fine but right now I can't answer the
> 'why?' question!

Ack.
Will put this into a series that adds a user for this to make it clearer.

At the moment I was just cherry-picking patches from our tree, sending bits
that were easier to apply, and deferring bits that are more complicated to
re-apply.

Thanks
Alex

> 
> Jonathan
> 
> > ---
> >  drivers/iio/adc/ad_sigma_delta.c       |  5 +++++
> >  include/linux/iio/adc/ad_sigma_delta.h | 13 +++++++++++++
> >  2 files changed, 18 insertions(+)
> > 
> > diff --git a/drivers/iio/adc/ad_sigma_delta.c
> > b/drivers/iio/adc/ad_sigma_delta.c
> > index ff5f2da2e1b1..00808838edd8 100644
> > --- a/drivers/iio/adc/ad_sigma_delta.c
> > +++ b/drivers/iio/adc/ad_sigma_delta.c
> > @@ -285,6 +285,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev
> > *indio_dev,
> >               return -EBUSY;
> > 
> >       mutex_lock(&indio_dev->mlock);
> > +     ad_sigma_delta_prepare_channel(sigma_delta, chan);
> >       ad_sigma_delta_set_channel(sigma_delta, chan->address);
> > 
> >       spi_bus_lock(sigma_delta->spi->master);
> > @@ -351,6 +352,10 @@ static int ad_sd_buffer_postenable(struct iio_dev
> > *indio_dev)
> > 
> >       channel = find_first_bit(indio_dev->active_scan_mask,
> >                                indio_dev->masklength);
> > +     ret = ad_sigma_delta_prepare_channel(sigma_delta,
> > +             &indio_dev->channels[channel]);
> > +     if (ret)
> > +             goto err_predisable;
> >       ret = ad_sigma_delta_set_channel(sigma_delta,
> >               indio_dev->channels[channel].address);
> >       if (ret)
> > diff --git a/include/linux/iio/adc/ad_sigma_delta.h
> > b/include/linux/iio/adc/ad_sigma_delta.h
> > index 7e84351fa2c0..21ee12543bdd 100644
> > --- a/include/linux/iio/adc/ad_sigma_delta.h
> > +++ b/include/linux/iio/adc/ad_sigma_delta.h
> > @@ -31,6 +31,8 @@ struct iio_dev;
> > 
> >  /**
> >   * struct ad_sigma_delta_info - Sigma Delta driver specific callbacks
> > and options
> > + * @prepare_channel: Will be called to prepare and configure a
> > channel, may be
> > + *                   NULL.
> >   * @set_channel: Will be called to select the current channel, may be
> > NULL.
> >   * @set_mode: Will be called to select the current mode, may be NULL.
> >   * @postprocess_sample: Is called for each sampled data word, can be
> > used to
> > @@ -43,6 +45,8 @@ struct iio_dev;
> >   *   be used.
> >   */
> >  struct ad_sigma_delta_info {
> > +     int (*prepare_channel)(struct ad_sigma_delta *,
> > +             const struct iio_chan_spec *);
> >       int (*set_channel)(struct ad_sigma_delta *, unsigned int
> > channel);
> >       int (*set_mode)(struct ad_sigma_delta *, enum ad_sigma_delta_mode
> > mode);
> >       int (*postprocess_sample)(struct ad_sigma_delta *, unsigned int
> > raw_sample);
> > @@ -81,6 +85,15 @@ struct ad_sigma_delta {
> >       uint8_t                         data[4] ____cacheline_aligned;
> >  };
> > 
> > +static inline int ad_sigma_delta_prepare_channel(struct ad_sigma_delta
> > *sd,
> > +     const struct iio_chan_spec *chan)
> > +{
> > +     if (sd->info->prepare_channel)
> > +             return sd->info->prepare_channel(sd, chan);
> > +
> > +     return 0;
> > +}
> > +
> >  static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta
> > *sd,
> >       unsigned int channel)
> >  {
> 
> 

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

end of thread, other threads:[~2019-03-26  6:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-19  9:53 [PATCH] iio: ad_sigma_delta: Introduce prepare_channel callback Alexandru Ardelean
2019-03-24 17:49 ` Jonathan Cameron
2019-03-26  6:53   ` Ardelean, Alexandru

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.