mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Victor Chernyakin <chernyakin.victor.j@outlook.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"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 v7 4/4] iio: cdc: add Texas Instruments FDC1004 driver
Date: Tue, 10 Nov 2026 01:39:53 +0200	[thread overview]
Message-ID: <avJZyb5S--smaHpX@ashevche-desk.local> (raw)
In-Reply-To: <SN1PR12MB25282CCC3930ABE760956095A5742@SN1PR12MB2528.namprd12.prod.outlook.com>

On Sun, Nov 08, 2026 at 02:08:29PM -0600, Victor Chernyakin wrote:
> The FDC1004 is a high-precision 4-channel capacitive sensor that talks
> over I2C. It can report the values of each of its 4 channels individually,
> as well as the difference between any two of them.
> 
> This initial driver allows performing single reads and configuring
> the sensor's various settings (sample frequency, calibration
> gain/offset, etc.). It could be extended with support for triggered
> buffers, repeated measurement mode, and/or power management.

...

> +static int fdc1004_write_raw(struct iio_dev *indio_dev,
> +			     const struct iio_chan_spec *chan,
> +			     int val, int val2, long mask)
> +{
> +	struct fdc1004_data *data = iio_priv(indio_dev);
> +	struct regmap *map = data->regmap;
> +	s64 val64;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_SAMP_FREQ:
> +		for (unsigned int i = 0; i < ARRAY_SIZE(fdc1004_samp_freqs); i++) {
> +			if (fdc1004_samp_freqs[i] == val) {
> +				guard(mutex)(&data->lock);
> +
> +				data->samp_freq_index = i;
> +				return 0;
> +			}
> +		}
> +
> +		return -EINVAL;
> +	case IIO_CHAN_INFO_OFFSET: {
> +		if (val < fdc1004_offset[0] || val > fdc1004_offset[2] ||
> +		    val % fdc1004_offset[1])
> +			return -EINVAL;
> +
> +		guard(mutex)(&data->lock);
> +
> +		data->offsets[chan->channel] = val / fdc1004_offset[1];

Make a temporary variables to have division and modulo operations coupled
together. The rationale is explained here:
9b3cd5c7099f ("regmap: place foo / 8 and foo % 8 closer to each other")

> +		return 0;
> +	}
> +	case IIO_CHAN_INFO_CALIBBIAS:
> +		val64 = iio_val_s64_compose(val, val2);
> +		if (val64 < fdc1004_calibbias[0] || val64 > fdc1004_calibbias[2])
> +			return -EINVAL;
> +
> +		return regmap_write(map, FDC1004_REG_OFFSET_CAL_CINn(chan->channel),
> +				    (u16)DIV_S64_ROUND_CLOSEST(val64, fdc1004_calibbias[1]));

Why casting? Shouldn't it be handled on the regmap_write() stage based on
the register / field description?

> +	case IIO_CHAN_INFO_CALIBSCALE:
> +		val64 = iio_val_s64_compose(val, val2);
> +		if (val64 < fdc1004_calibscale[0] || val64 > fdc1004_calibscale[2])
> +			return -EINVAL;
> +
> +		return regmap_write(map, FDC1004_REG_GAIN_CAL_CINn(chan->channel),
> +				    DIV64_U64_ROUND_CLOSEST(val64, fdc1004_calibscale[1]));
> +	default:
> +		return -EINVAL;
> +	}
> +}

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-11-09 23:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-08 20:08 [PATCH v7 0/4] " Victor Chernyakin
2026-11-08 20:08 ` [PATCH v7 1/4] iio: prepare iio_format_value to handle higher-precision IIO_VAL_DECIMAL64_* formats Victor Chernyakin
2026-11-08 20:08 ` [PATCH v7 2/4] iio: add IIO_VAL_DECIMAL64_{ATTO,ZEPTO,YOCTO} formats Victor Chernyakin
2026-11-08 20:08 ` [PATCH v7 3/4] dt-bindings: iio: cdc: add Texas Instruments FDC1004 Victor Chernyakin
2026-11-08 20:08 ` [PATCH v7 4/4] iio: cdc: add Texas Instruments FDC1004 driver Victor Chernyakin
2026-11-09 23:39   ` Andy Shevchenko [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=avJZyb5S--smaHpX@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=chernyakin.victor.j@outlook.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --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®