diff mbox series

iio: ad_sigma_delta: Introduce prepare_channel callback

Message ID 20190319095306.16010-1-alexandru.ardelean@analog.com (mailing list archive)
State New, archived
Headers show
Series iio: ad_sigma_delta: Introduce prepare_channel callback | expand

Commit Message

Alexandru Ardelean March 19, 2019, 9:53 a.m. UTC
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(+)

Comments

Jonathan Cameron March 24, 2019, 5:49 p.m. UTC | #1
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)
>  {
Alexandru Ardelean March 26, 2019, 6:53 a.m. UTC | #2
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)
> >  {
> 
>
diff mbox series

Patch

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)
 {