Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Nuno Sá" <noname.nuno@gmail.com>
Cc: Guillaume Ranquet <granquet@baylibre.com>,
	Lars-Peter Clausen  <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/2] iio: adc: ad7173: add openwire detection support for single conversions
Date: Sat, 25 Jan 2025 14:45:22 +0000	[thread overview]
Message-ID: <20250125144522.60a9d4e4@jic23-huawei> (raw)
In-Reply-To: <105894947f288f0b877f69d58e5d9b4a095e6e2b.camel@gmail.com>

On Mon, 20 Jan 2025 17:07:24 +0000
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Mon, 2025-01-20 at 15:10 +0100, Guillaume Ranquet wrote:
> > Some chips of the ad7173 family supports open wire detection.
> > 
> > Generate a level fault event whenever an external source is disconnected
> > from the system input on single conversions.
> > 
> > Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>
> > ---  
> 
> LGTM... Just one small nit. In any case:
> 
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> 
> >  drivers/iio/adc/ad7173.c | 166
> > +++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 166 insertions(+)
> > 
> > diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c
> > index
> > 11ff148cb5a315d32485acf04b8d6f7d0fb6e5fa..a2ea8f7ae8e61f1f3cdfba795551de2db96b
> > 8d60 100644
> > --- a/drivers/iio/adc/ad7173.c
> > +++ b/drivers/iio/adc/ad7173.c
> > @@ -35,6 +35,7 @@
> >  #include <linux/units.h>
> >  
> >  #include <linux/iio/buffer.h>
> > +#include <linux/iio/events.h>
> >  #include <linux/iio/iio.h>
> >  #include <linux/iio/trigger_consumer.h>
> >  #include <linux/iio/triggered_buffer.h>
> > @@ -102,6 +103,7 @@
> >  
> >  #define AD7173_GPIO_PDSW	BIT(14)
> >  #define AD7173_GPIO_OP_EN2_3	BIT(13)
> > +#define AD4111_GPIO_GP_OW_EN	BIT(12)
> >  #define AD7173_GPIO_MUX_IO	BIT(12)
> >  #define AD7173_GPIO_SYNC_EN	BIT(11)
> >  #define AD7173_GPIO_ERR_EN	BIT(10)
> > @@ -149,6 +151,7 @@
> >   
> 
> ...
> 
> > 
> > +
> >  static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
> >  {
> >  	struct ad7173_channel *chans_st_arr, *chan_st_priv;
> > @@ -1375,6 +1528,7 @@ static int ad7173_fw_parse_channel_config(struct iio_dev
> > *indio_dev)
> >  		chan_st_priv->cfg.bipolar = false;
> >  		chan_st_priv->cfg.input_buf = st->info->has_input_buf;
> >  		chan_st_priv->cfg.ref_sel = AD7173_SETUP_REF_SEL_INT_REF;
> > +		chan_st_priv->cfg.openwire_comp_chan = -1;
> >  		st->adc_mode |= AD7173_ADC_MODE_REF_EN;
> >  		if (st->info->data_reg_only_16bit)
> >  			chan_arr[chan_index].scan_type = ad4113_scan_type;
> > @@ -1442,6 +1596,7 @@ static int ad7173_fw_parse_channel_config(struct iio_dev
> > *indio_dev)
> >  		chan_st_priv->chan_reg = chan_index;
> >  		chan_st_priv->cfg.input_buf = st->info->has_input_buf;
> >  		chan_st_priv->cfg.odr = 0;
> > +		chan_st_priv->cfg.openwire_comp_chan = -1;
> >  
> >  		chan_st_priv->cfg.bipolar = fwnode_property_read_bool(child,
> > "bipolar");
> >  		if (chan_st_priv->cfg.bipolar)
> > @@ -1456,6 +1611,17 @@ static int ad7173_fw_parse_channel_config(struct
> > iio_dev *indio_dev)
> >  			chan_st_priv->cfg.input_buf = st->info-  
> > >has_input_buf;  
> >  			chan->channel2 = ain[1];
> >  			chan_st_priv->ain = AD7173_CH_ADDRESS(ain[0],
> > ain[1]);
> > +			if (st->info->has_openwire_det &&
> > +			    ad7173_validate_openwire_ain_inputs(st, chan-  
> > >differential, ain[0], ain[1])) {  
> > +				chan->event_spec = ad4111_events;
> > +				chan->num_event_specs =
> > ARRAY_SIZE(ad4111_events);
> > +				chan_st_priv->cfg.openwire_thrsh_raw =
> > +					BIT(chan->scan_type.realbits -
> > !!(chan_st_priv->cfg.bipolar))
> > +					* AD4111_OW_DET_THRSH_MV
> > +					/ ad7173_get_ref_voltage_milli(st,
> > chan_st_priv->cfg.ref_sel);
> > +				if (chan->channel < st->info-  
> > >num_voltage_in_div)  
> > +					chan_st_priv->cfg.openwire_thrsh_raw
> > /= AD4111_DIVIDER_RATIO;
> > +			}  
> 
> If you need to send another version for some reason, might be worth it to
> implement a simple helper for the above to improve code readability.
> 
> Maybe is just me but that 'chan_st_priv->cfg.openwire_thrsh_raw =' is fairly
> unreadable :)
> 
This crossed with a set from David and doesn't apply. Please rebase on top
of my testing branch.  Thanks! If the helper function Nuno suggests makes
sense to you feel free to do that as well.

The two patches I have on this driver that aren't upstream yet are:
iio: adc: ad7173: don't make copy of ad_sigma_delta_info struct 
iio: adc: ad7173: move fwnode_irq_get_byname() call site

Jonathan
> - Nuno Sá
> >   


      reply	other threads:[~2025-01-25 14:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20 14:10 [PATCH v4 0/2] iio: adc: ad7173: add ad4111 openwire detection support Guillaume Ranquet
2025-01-20 14:10 ` [PATCH v4 1/2] iio: introduce the FAULT event type Guillaume Ranquet
2025-01-20 16:50   ` Nuno Sá
2025-01-20 14:10 ` [PATCH v4 2/2] iio: adc: ad7173: add openwire detection support for single conversions Guillaume Ranquet
2025-01-20 17:07   ` Nuno Sá
2025-01-25 14:45     ` Jonathan Cameron [this message]

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=20250125144522.60a9d4e4@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=granquet@baylibre.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=noname.nuno@gmail.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