Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Cc: linux-iio@vger.kernel.org, Nuno Sa <Nuno.Sa@analog.com>,
	lars@metafoo.de, Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Michael Hennerich <michael.hennerich@analog.com>
Subject: Re: [PATCH v2 14/17] staging:iio:adc:ad7280a: Use device properties to replace platform data.
Date: Sun, 6 Feb 2022 18:06:07 +0000	[thread overview]
Message-ID: <20220206180607.65af4b76@jic23-huawei> (raw)
In-Reply-To: <20220130202459.00a1be01@jic23-huawei>

On Sun, 30 Jan 2022 20:24:59 +0000
Jonathan Cameron <jic23@kernel.org> wrote:

> On Sat, 18 Dec 2021 18:06:58 -0300
> Marcelo Schmitt <marcelo.schmitt1@gmail.com> wrote:
> 
> > Removing AUX channels from alert detection is a bit tricky.
> > According to a note from datasheet page 27:
> > To remove AUX5 or AUX5 and AUX3 from the alert detection, conversions on
> > three auxiliary ADC input channels only must be selected in the control register.  
> 
> Hmm. Always hide the important stuff in foot notes. I missed that entirely it seems
> though honestly I can only vaguely remember how this works at all.
> 
> > 
> > We can check the AUX alert configuration and write to control register HB at
> > probe but it would not last for long since every other device read sets D15:D14
> > to 0x00 again. Can't think of any reasonable way to ensure only AUX1,3,5 without
> > keeping ctrl_hb again. However, AUX selection should not bother if we drop AUX
> > alert removal support for now.  
> 
> Agreed. This is a pain.  Dropping the support is probably a better plan than
> getting stuck figuring this out.  I'll give it a bit more thought when I get
> back to this driver properly.

I'm going to add an extra patch to drop this support - mostly to give us
a clear description of why it is dropped.

I just checked the original code and that never supported the mode
to read 1,3 and 5 either so we aren't making anything worse by just
dropping the pretence of it being supported.

I also just realised I haven't been cc'ing Michael on the series and
definitely should have been! Sorry about that Michael.  I'm guessing 
you can't recall this subtle detail from many years ago though!

> 
> > 
> > Few other bits and thoughts inline.
> > 
> > On 12/05, Jonathan Cameron wrote:  
> > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > > 
> > > Convert all the device specific info that was previously in platform data
> > > over to generic firmware query interfaces.
> > > 
> > > dt-bindings to follow shortly.
> > > 
> > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > > ---
> > >  drivers/staging/iio/adc/ad7280a.c | 100 +++++++++++++++++++++++++-----
> > >  drivers/staging/iio/adc/ad7280a.h |  31 ---------
> > >  2 files changed, 86 insertions(+), 45 deletions(-)
> > > 
> > > diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
> > > index acaae1b33986..0806238debe3 100644
> > > --- a/drivers/staging/iio/adc/ad7280a.c
> > > +++ b/drivers/staging/iio/adc/ad7280a.c
> > > @@ -23,8 +23,6 @@
> > >  #include <linux/iio/events.h>
> > >  #include <linux/iio/iio.h>
> > >  
> > > -#include "ad7280a.h"
> > > -
> > >  /* Registers */
> > >  
> > >  #define AD7280A_CELL_VOLTAGE_1_REG		0x0  /* D11 to D0, Read only */
> > > @@ -81,6 +79,11 @@
> > >  #define AD7280A_AUX_ADC_UNDERVOLTAGE_REG	0x12 /* D7 to D0, Read/write */
> > >  
> > >  #define AD7280A_ALERT_REG			0x13 /* D7 to D0, Read/write */
> > > +#define   AD7280A_ALERT_REMOVE_MSK			GENMASK(3, 0)
> > > +#define     AD7280A_ALERT_REMOVE_AUX5			BIT(0)
> > > +#define     AD7280A_ALERT_REMOVE_AUX4_AUX5		BIT(1)    
> > typo, according to datasheet this bit disables AUX5 and AUX3 so it would be
> > #define     AD7280A_ALERT_REMOVE_AUX3_AUX5		BIT(1)  
> 
> Ah.  I'd missed that which rather makes a mess of using the 'last' channel
> in the dt binding.  Will need a rethink.  Sometimes if feels like the
> hardware folks design this stuff just to make it hard to put a nice
> simple software description in place!
> 
> >   
> > > +#define     AD7280A_ALERT_REMOVE_VIN5			BIT(2)
> > > +#define     AD7280A_ALERT_REMOVE_VIN4_VIN5		BIT(3)
> > >  #define   AD7280A_ALERT_GEN_STATIC_HIGH			BIT(6)
> > >  #define   AD7280A_ALERT_RELAY_SIG_CHAIN_DOWN		(BIT(7) | BIT(6))
> > >  
> > > @@ -163,6 +166,8 @@ static unsigned int ad7280a_devaddr(unsigned int addr)
> > >  struct ad7280_state {
> > >  	struct spi_device		*spi;
> > >  	struct iio_chan_spec		*channels;
> > > +	unsigned int			chain_last_alert_ignore;
> > > +	bool				thermistor_term_en;
> > >  	int				slave_num;
> > >  	int				scan_cnt;
> > >  	int				readback_delay_us;
> > > @@ -932,14 +937,8 @@ static const struct iio_info ad7280_info_no_irq = {
> > >  	.write_event_value = &ad7280a_write_thresh,
> > >  };
> > >  
> > > -static const struct ad7280_platform_data ad7793_default_pdata = {
> > > -	.acquisition_time = AD7280A_ACQ_TIME_400ns,
> > > -	.thermistor_term_en = true,
> > > -};
> > > -
> > >  static int ad7280_probe(struct spi_device *spi)
> > >  {
> > > -	const struct ad7280_platform_data *pdata = dev_get_platdata(&spi->dev);
> > >  	struct device *dev = &spi->dev;
> > >  	struct ad7280_state *st;
> > >  	int ret;
> > > @@ -954,17 +953,90 @@ static int ad7280_probe(struct spi_device *spi)
> > >  	st->spi = spi;
> > >  	mutex_init(&st->lock);
> > >  
> > > -	if (!pdata)
> > > -		pdata = &ad7793_default_pdata;
> > > +	st->thermistor_term_en =
> > > +		device_property_read_bool(dev, "adi,thermistor-termination");
> > > +
> > > +	if (device_property_present(dev, "adi,acquistion-time-ns")) {    
> > typo, adi,acquistion-time-ns -> adi,acquisition-time-ns
> >   
> > > +		u32 val;
> > > +
> > > +		ret = device_property_read_u32(dev, "adi,acquisition-time-ns", &val);
> > > +		if (ret)
> > > +			return ret;
> > > +
> > > +		switch (val) {
> > > +		case 400:
> > > +			st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_400ns;
> > > +			break;
> > > +		case 800:
> > > +			st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_800ns;
> > > +			break;
> > > +		case 1200:
> > > +			st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_1200ns;
> > > +			break;
> > > +		case 1600:
> > > +			st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_1600ns;
> > > +			break;
> > > +		default:
> > > +			dev_err(dev, "Firmware provided acquisition time is invalid\n");
> > > +			return -EINVAL;
> > > +		}
> > > +	} else {
> > > +		st->acquisition_time = AD7280A_CTRL_LB_ACQ_TIME_400ns;
> > > +	}
> > > +
> > > +	/* Alert masks are intended for when particular inputs are not wired up */
> > > +	if (device_property_present(dev, "adi,voltage-alert-last-chan")) {
> > > +		u8 val;
> > >  
> > > +		ret = device_property_read_u8(dev, "adi,voltage-alert-last-chan", &val);    
> > I added some extra configuration to the ad7280a qemu emulation stuff to test
> > cases where we would have voltage and temperature channels removed from alert
> > generation. On my setup, these device_property_read_u8 reads gave me zeros all
> > the time while the u32 reads gave me the expected values.
> > Not sure if this is something with qemu or even some misconfiguration from my side.
> > Would be good if someone else could check it out.  
> 
> I'll check it out.  Thanks for the heads up that it might be an issue.
> Digging in the implementation it looks like it might need a specific format
> for the device property.
> https://elixir.bootlin.com/linux/latest/source/include/linux/of.h#L439
> 
> ``property = /bits/ 8 <0x50 0x60 0x70>;`
> 
> So it might be that. Given we don't care better to just use
> 32 bit reads.
I've changed them all to 32 bit reads.

Thanks,

Jonathan

  reply	other threads:[~2022-02-06 17:59 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-05 20:26 [PATCH v2 00/17] iio:adc:ad7280a Cleanup and proposed staging graduation Jonathan Cameron
2021-12-05 20:26 ` [PATCH v2 01/17] staging:iio:adc:ad7280a: Fix handing of device address bit reversing Jonathan Cameron
2021-12-13 12:26   ` Marcelo Schmitt
2021-12-05 20:26 ` [PATCH v2 02/17] staging:iio:adc:ad7280a: Register define cleanup Jonathan Cameron
2021-12-13 12:41   ` Marcelo Schmitt
2022-02-06 17:01     ` Jonathan Cameron
2021-12-05 20:26 ` [PATCH v2 03/17] staging:iio:adc:ad7280a: rename _read() to _read_reg() Jonathan Cameron
2021-12-14 17:05   ` Marcelo Schmitt
2021-12-05 20:26 ` [PATCH v2 04/17] staging:iio:adc:ad7280a: Split buff[2] into tx and rx parts Jonathan Cameron
2021-12-14 17:05   ` Marcelo Schmitt
2021-12-05 20:26 ` [PATCH v2 05/17] staging:iio:adc:ad7280a: Use bitfield ops to managed fields in transfers Jonathan Cameron
2021-12-14 17:12   ` Marcelo Schmitt
2022-02-06 17:14     ` Jonathan Cameron
2022-02-06 18:02       ` Marcelo Schmitt
2021-12-05 20:26 ` [PATCH v2 06/17] staging:iio:adc:ad7280a: Switch to standard event control Jonathan Cameron
2021-12-14 17:41   ` Marcelo Schmitt
2022-02-06 17:34     ` Jonathan Cameron
2021-12-05 20:27 ` [PATCH v2 07/17] staging:iio:adc:ad7280a: Standardize extended ABI naming Jonathan Cameron
2021-12-18 20:17   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 08/17] staging:iio:adc:ad7280a: Drop unused timestamp channel Jonathan Cameron
2021-12-18 20:18   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 09/17] staging:iio:adc:ad7280a: Trivial comment formatting cleanup Jonathan Cameron
2021-12-18 20:21   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 10/17] staging:iio:adc:ad7280a: Make oversampling_ratio a runtime control Jonathan Cameron
2021-12-18 20:22   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 11/17] staging:iio:adc:ad7280a: Cleanup includes Jonathan Cameron
2021-12-18 20:22   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 12/17] staging:iio:ad7280a: Reflect optionality of irq in ABI Jonathan Cameron
2021-12-18 20:30   ` Marcelo Schmitt
2022-01-30 20:05     ` Jonathan Cameron
2021-12-05 20:27 ` [PATCH v2 13/17] staging:iio:adc:ad7280a: Use a local dev pointer to avoid &spi->dev Jonathan Cameron
2021-12-18 20:31   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 14/17] staging:iio:adc:ad7280a: Use device properties to replace platform data Jonathan Cameron
2021-12-18 21:06   ` Marcelo Schmitt
2022-01-30 20:24     ` Jonathan Cameron
2022-02-06 18:06       ` Jonathan Cameron [this message]
2021-12-05 20:27 ` [PATCH v2 15/17] dt-bindings:iio:adc:ad7280a: Add binding Jonathan Cameron
2021-12-18 21:18   ` Marcelo Schmitt
2022-01-30 20:29     ` Jonathan Cameron
2022-02-06  2:31       ` Marcelo Schmitt
2022-02-06 18:13         ` Jonathan Cameron
2021-12-05 20:27 ` [PATCH v2 16/17] iio:adc:ad7280a: Document ABI for cell balance switches Jonathan Cameron
2021-12-18 21:20   ` Marcelo Schmitt
2021-12-05 20:27 ` [PATCH v2 17/17] iio:adc:ad7280a: Move out of staging Jonathan Cameron
2021-12-18 22:08   ` Marcelo Schmitt
2022-01-30 20:46     ` Jonathan Cameron
2022-02-06 18:45       ` Jonathan Cameron
2021-12-13 12:51 ` [PATCH v2 00/17] iio:adc:ad7280a Cleanup and proposed staging graduation Marcelo Schmitt
2021-12-16 11:46   ` Jonathan Cameron

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=20220206180607.65af4b76@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Nuno.Sa@analog.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=michael.hennerich@analog.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