Re: [PATCH v7 4/4] iio: cdc: add Texas Instruments FDC1004 driver
From: Andy Shevchenko
Date: Tue Nov 10 2026 - 05:00:17 EST
On Mon, Nov 09, 2026 at 09:56:44PM -0600, Victor Chernyakin wrote:
...
> > > + 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?
>
> This was prompted by this sashiko review:
>
> https://lore.kernel.org/SN1PR12MB252888B43D53AB1723952D21A5742@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> TLDR I'm not certain the cast is necessary, but I'm also not certain
> it's not necessary (if regmap does handle it, I couldn't figure out
> where), so I've added it out of caution.
Yes, regmap core code is tricky in many places. So, as far as I read it,
the I2C default bus with val_bits == 16 (if you have no custom regmap IO
accessors) uses internal format operation regmap_format_16_be() along
with format_write kept at NULL and hence defer_cache set to true (cache
after formatting). The default working buffer for the data is work_buf,
to which the above formatter puts the data, it doesn't put anything outside
16 LSBs.
Since the code is tricky, please double check my way of understanding the code
and confirm or point out any mistakes I made.
--
With Best Regards,
Andy Shevchenko