mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Victor Chernyakin" <chernyakin.victor.j@outlook.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 4/4] iio: cdc: add Texas Instruments FDC1004 driver
Date: Sun, 1 Nov 2026 18:35:23 +0000	[thread overview]
Message-ID: <20261101183523.693e4b48@jic23-hlaptop> (raw)
In-Reply-To: <at-0cXiBV0RM-Att@ashevche-desk.local>


> > +		/*
> > +		 * Now read the two registers making up the measurement.
> > +		 * The datasheet says to read MSB first, LSB second.
> > +		 */
> > +		ret = regmap_bulk_read(map, FDC1004_REG_MEASn_MSB(0),
> > +				       reg_vals, ARRAY_SIZE(reg_vals));
> > +		if (ret)
> > +			return ret;
> > +
> > +		*val = (sign_extend32(reg_vals[0], 15) << 8) | (reg_vals[1] >> 8);  
> 
> We still have two shift operators, so it might be not a bad idea after all to
> have a combined variable with wordswap done in case of LITTLE_ENDIAN
> architecture. Jonathan, what do you think about this? Reading the whole set as
> 32-bit value and convert it if required
> 
> 		// also note in this case we don't need to have _MSB in the name
> 		ret = regmap_bulk_read(map, FDC1004_REG_MEASn(0), reg_val, sizeof(reg_val));
> 		if (ret)
> 			return ret;
> 
> #ifdef __LITTLE_ENDIAN
> 		reg_val = swahw32(reg_val);
> #endif
> 
> 		*val = sign_extend32(reg_val >> 8, 23);
> 
> 		// I assume the following is also possible in this case
> 		// *val = (int)reg_val >> 8;
> 		// but usually we use sign_extend32() in IIO even when simple
> 		// casting is okay
> 
> This also reduces stack usage.

To esoteric for me.  We'd have to add comments on why it worked to limit
the future blast radius.  Now, what could we do that didn't need that...
The problem is that the regmap_bulk_read is feeding us two native endian
16 bit values.  Well, you could 'fix' that...

		u8 be_temp[4];

		ret = regmap_bulk_read(map, FDC1004_REG_MEAS_n_MSB(0),
				       reg_vals, ARRAY_SIZE(reg_vals));
		put_unaligned_be16(reg_vals[0], &be_temp[0]);
		put_unaligned_be16(reg_vals[1], &be_temp[2]);
		*val = sign_extgend32(get_unaligned_be32(be_temp) >> 8, 23);

Or something along those lines...  I'd rather something explicit like that
than Andy's suggestion, but I'm not convinced on this either.

> 
> > +		return IIO_VAL_INT;
> > +	}

Jonathan



  parent reply	other threads:[~2026-11-01 18:35 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26 16:51 [PATCH v3 0/4] " Victor Chernyakin
2026-10-26 16:51 ` [PATCH v3 1/4] iio: prepare iio_format_value to handle higher-precision IIO_VAL_DECIMAL64_* formats Victor Chernyakin
2026-10-26 20:17   ` Andy Shevchenko
2026-10-27  1:51     ` Victor Chernyakin
2026-10-27  7:29       ` Andy Shevchenko
2026-10-27  8:36         ` Victor Chernyakin
2026-10-27 18:56   ` Rodrigo Alencar
2026-10-28  8:11     ` Andy Shevchenko
2026-10-28 10:31       ` David Laight
2026-10-28 11:16       ` David Laight
2026-10-26 16:51 ` [PATCH v3 2/4] iio: add IIO_VAL_DECIMAL64_{ATTO,ZEPTO,YOCTO} formats Victor Chernyakin
2026-10-26 16:51 ` [PATCH v3 3/4] dt-bindings: iio: cdc: add Texas Instruments FDC1004 Victor Chernyakin
2026-10-26 16:51 ` [PATCH v3 4/4] iio: cdc: add Texas Instruments FDC1004 driver Victor Chernyakin
2026-10-26 20:13   ` Andy Shevchenko
2026-10-27  2:13     ` Victor Chernyakin
2026-10-27  7:33       ` Andy Shevchenko
2026-10-27 10:04         ` Victor Chernyakin
2026-11-01 18:53           ` Jonathan Cameron
2026-10-31 15:22         ` Victor Chernyakin
2026-11-01 18:35     ` Jonathan Cameron [this message]
2026-10-27  8:17   ` Joshua Crofts
2026-10-27 10:06     ` Victor Chernyakin

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=20261101183523.693e4b48@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=chernyakin.victor.j@outlook.com \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@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

all inboxes | Powered by JetHome®