All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kanak Shilledar <Kanak.Shilledar@axis.com>
To: "andriy.shevchenko@intel.com" <andriy.shevchenko@intel.com>
Cc: "andy@kernel.org" <andy@kernel.org>,
	"robh@kernel.org" <robh@kernel.org>, Kernel <Kernel@axis.com>,
	"macromorgan@hotmail.com" <macromorgan@hotmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"conor+dt@kernel.org" <conor+dt@kernel.org>,
	"joshua.crofts1@gmail.com" <joshua.crofts1@gmail.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"jean-baptiste.maneyrol@tdk.com" <jean-baptiste.maneyrol@tdk.com>,
	"dlechner@baylibre.com" <dlechner@baylibre.com>,
	"nuno.sa@analog.com" <nuno.sa@analog.com>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"jic23@kernel.org" <jic23@kernel.org>,
	"marcelo.schmitt1@gmail.com" <marcelo.schmitt1@gmail.com>,
	Henrik Grimler <Henrik.Grimler@axis.com>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>
Subject: Re: [PATCH v5 5/6] iio: imu: inv_icm42607: Implement MREGx register access
Date: Fri, 2 Oct 2026 14:25:48 +0000	[thread overview]
Message-ID: <afde7beb4019d8090d3df30bb4e0a1b7ca00ad4a.camel@axis.com> (raw)
In-Reply-To: <ar-tpjenoxMloYq1@ashevche-desk.local>

[-- Attachment #1: Type: text/plain, Size: 5541 bytes --]

Hi Andy,

On Fri, 2026-10-02 at 16:12 +0300, Andy Shevchenko wrote:
> On Fri, Oct 02, 2026 at 01:54:29PM +0200, Kanak Shilledar wrote:
> > The device supports indirect register access to different banks. A
> > specific routine needs to be followed when accessing the registers
> > in
> > another bank as documented in the datasheet (section 13). This is
> > required for accessing registers configured via the user and
> > implementing buffer support. The implementation is inspired from
> > the
> > icm45600 driver. The banks are defined based on their initial bank
> > access code which are written to the BLK_SEL_* regs. However, there
> > is a
> > variation for MREG1 as User Bank 0 and MREG1 both share the same
> > 0x00,
> > so User Bank 1 has 0x00 and MREG1 has 0x01. When MREG1 register is
> > accessed, then BLK_SEL_* is written with 0x00 instead of 0x01. All
> > the
> > register access goes through the 16 bit virtual regmap layered on
> > top of
> > the 8bit bus regmap. Bank id in the upper byte and the register
> > address
> > in the lower byte. Bank 0 accesses are forwarded to the bus regmap
> > with
> > the bank field stripped, while MREG accesses are forwarded to bank
> > switching sequence.
> 
> ...
> 
> > +	unsigned int val;
> > +	int ret, ret2;
> > +
> > +	*idle_set = false;
> > +
> > +	ret = regmap_read(map, INV_ICM42607_REG_MCLK_RDY, &val);
> > +	if (ret)
> > +		return ret;
> > +
> > +	if (val & INV_ICM42607_MCLK_RDY_BIT)
> > +		return 0;
> 
> Why not regmap_test_bits()?

I will fix it.

> > +	/*
> > +	 * Clock isn't running: we're either in Sleep mode or in
> > Accel LP mode
> > +	 * running on WUOSC. Force the RC oscillator on via IDLE
> > and wait for
> > +	 * MCLK_RDY. Datasheet gives 10us (accel startup) to 200us
> > (accel
> > +	 * transition from OFF) for this to complete.
> > +	 */
> > +	ret = regmap_set_bits(map, INV_ICM42607_REG_PWR_MGMT0,
> > +			      INV_ICM42607_PWR_MGMT0_IDLE);
> > +	if (ret)
> > +		return ret;
> > +
> > +	*idle_set = true;
> > +
> > +	ret = regmap_read_poll_timeout(map,
> > INV_ICM42607_REG_MCLK_RDY, val,
> > +				       val &
> > INV_ICM42607_MCLK_RDY_BIT, 10, 200);
> > +	if (ret) {
> > +		ret2 = regmap_clear_bits(map,
> > INV_ICM42607_REG_PWR_MGMT0,
> > +					
> > INV_ICM42607_PWR_MGMT0_IDLE);
> > +		if (ret2)
> > +			dev_err(regmap_get_device(map),
> > +					"failed to clear IDLE
> > after MCLK timeout: %d\n", ret2);
> 
> Broken indentation.
> Is it really important message?

It is useful for indicating failure in MCLK, but I will lower the
priority to either _info or _debug and fix the indentation.

> > +		else
> > +			*idle_set = false;
> >  	}
> 
> ...
> 
> > +static void inv_icm42607_mclk_put(struct regmap *map, bool
> > idle_set)
> >  {
> > +	if (idle_set)
> > +		regmap_clear_bits(map, INV_ICM42607_REG_PWR_MGMT0,
> > +				  INV_ICM42607_PWR_MGMT0_IDLE);
> > +}
> 
> What about
> 
> 	if (!idle_set)
> 		return;
> 
> 	regmap_clear_bits(map, INV_ICM42607_REG_PWR_MGMT0,
> INV_ICM42607_PWR_MGMT0_IDLE);
> 
> ?

Will incorporate the suggestion.

> ...
> 
> > +static int inv_icm42607_mreg_read(struct regmap *map, unsigned int
> > reg,
> > +				  u8 *data, size_t count)
> > +{
> > +	unsigned int val;
> > +	bool idle_set;
> > +	u8 blk_sel;
> > +	int ret;
> > +
> > +	/* MREG access is one byte per transaction, no burst
> > support. */
> > +	if (count != 1)
> > +		return -EINVAL;
> > +
> > +	ret = inv_icm42607_blk_sel(reg, &blk_sel);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = inv_icm42607_mclk_get(map, &idle_set);
> > +	if (ret)
> > +		return ret;
> 
> > +	ret = regmap_write(map, INV_ICM42607_REG_BLK_SEL_R,
> > blk_sel);
> > +	if (ret)
> > +		goto out;
> 
> So, can we use regmap ranges instead?

We can't use regmap ranges because the register accesses for different
banks guarded by a specific routine of writing the bank selector, the
address pointer and then finally accessing the value along with
checking for timings and clocks. There is also a limitation that,
accessing the registers in banks other than USER BANK 0 can only be
done serially. It doesn't support bulk reads. This is documented in
section 13 of the datasheet [1].

> > +	ret = regmap_write(map, INV_ICM42607_REG_MADDR_R,
> > +			   FIELD_GET(INV_ICM42607_REG_ADDR_MASK,
> > reg));
> > +	if (ret)
> > +		goto out;
> > +
> > +	fsleep(INV_ICM42607_MREG_ACCESS_DELAY_US);
> > +
> > +	ret = regmap_read(map, INV_ICM42607_REG_M_R, &val);
> > +	if (ret)
> > +		goto out;
> > +
> > +	fsleep(INV_ICM42607_MREG_ACCESS_DELAY_US);
> > +
> > +	*data = val;
> > +out:
> > +	/* Restore direct access. */
> > +	ret = regmap_write(map, INV_ICM42607_REG_BLK_SEL_R, 0);
> > +	inv_icm42607_mclk_put(map, idle_set);
> > +
> > +	return ret;
> >  }
> 
> ...
> 
> > +static const struct regmap_config inv_icm42607_regmap_config = {
> > +	.reg_bits = 8,
> > +	.val_bits = 8,
> 
> No cache? Why?
As the virtual regmap config has some caching for USER BANK 0 registers
only. The indirect banks doesn't support caching [1].

> > +};
> 
> ...
> 
> > +static const struct regmap_config inv_icm42607_regmap_config = {
> > +	.reg_bits = 8,
> > +	.val_bits = 8,
> > +};
> 
> Ditto. And why they can't be deduplicated?

I will remove the duplication of these regmap_configs.

Thanks and Regards,
Kanak Shilledar

[1] Datasheet: https://www.lcsc.com/product-detail/C5129967.html

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-10-02 14:25 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 11:54 [PATCH v5 0/6] Add support for InvenSense ICM-42370-P accelerometer Kanak Shilledar
2026-10-02 11:54 ` [PATCH v5 1/6] dt-bindings: iio: imu: icm42600: Add ICM-42670-P Kanak Shilledar
2026-10-02 12:01   ` sashiko-bot
2026-10-02 17:11   ` Conor Dooley
2026-10-02 17:11     ` Conor Dooley
2026-10-02 11:54 ` [PATCH v5 2/6] iio: imu: inv_icm42607: Simplify IIO channel macros Kanak Shilledar
2026-10-05  0:25   ` Marcelo Schmitt
2026-10-02 11:54 ` [PATCH v5 3/6] iio: imu: inv_icm42607: Initialize gyro based on chip_info Kanak Shilledar
2026-10-02 13:03   ` Andy Shevchenko
2026-10-05  0:39   ` Marcelo Schmitt
2026-10-02 11:54 ` [PATCH v5 4/6] iio: imu: inv_icm42607: Add support for ICM-42370-P Kanak Shilledar
2026-10-02 13:04   ` Andy Shevchenko
2026-10-05  0:43   ` Marcelo Schmitt
2026-10-02 11:54 ` [PATCH v5 5/6] iio: imu: inv_icm42607: Implement MREGx register access Kanak Shilledar
2026-10-02 12:03   ` sashiko-bot
2026-10-02 13:12   ` Andy Shevchenko
2026-10-02 14:25     ` Kanak Shilledar [this message]
2026-10-03 15:02       ` andriy.shevchenko
2026-10-05 15:02         ` Kanak Shilledar
2026-10-02 11:54 ` [PATCH v5 6/6] iio: imu: inv_icm42607: Add accelerometer calibbias support Kanak Shilledar
2026-10-02 13:18   ` Andy Shevchenko
2026-10-02 14:03     ` Kanak Shilledar
2026-10-03 14:57       ` andriy.shevchenko
2026-10-05  0:51   ` Marcelo Schmitt

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=afde7beb4019d8090d3df30bb4e0a1b7ca00ad4a.camel@axis.com \
    --to=kanak.shilledar@axis.com \
    --cc=Henrik.Grimler@axis.com \
    --cc=Kernel@axis.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jean-baptiste.maneyrol@tdk.com \
    --cc=jic23@kernel.org \
    --cc=joshua.crofts1@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=macromorgan@hotmail.com \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.