Skip to contentSkip to conversation

iio: magnetometer: mlx90393 - regmap vs command-based access

RFC Nikhil Gautam 3 participants 5 messages Apr 23 – Apr 24 IIO

lore
Share & tools
lore
#0 lore raw

Hi,

I am working on adding support for the MLX90393 magnetometer.

The device uses a command-based protocol (e.g. SM, RM, RR) rather than a traditional register map.

Before proceeding, I wanted to clarify the preferred design:

- Should regmap be used in such cases, even without a linear register map?

- Or is it acceptable to implement a custom command-based abstraction layer?

My understanding is that regmap may not be a good fit here, but I would appreciate guidance before implementing.

Also, pointers to similar IIO drivers would be helpful.

Thanks,
Nikhil Gautam

#1 lore raw

Hi,

Apologies for missing a few details in the previous mail.

The MLX90393 supports both I2C and SPI interfaces.

Commands include, for example:
- SM (Start Measurement)
- RM (Read Measurement)
- RR (Read Register)

Given this command-oriented interface over both I2C and SPI, I wanted to confirm whether a custom command abstraction layer would still be the preferred approach instead of regmap.

Thanks,
Nikhil Gautam

#2 lore raw
Quoted 5 lines · Nikhil Gautam

Apologies for missing a few details in the previous mail.

The MLX90393 supports both I2C and SPI interfaces.

Quoted 8 lines

Commands include, for example:
- SM (Start Measurement)
- RM (Read Measurement)
- RR (Read Register)

Given this command-oriented interface over both I2C and SPI, I wanted to confirm whether a custom command abstraction layer would still be the preferred approach instead of regmap.

I found only 4 drivers for this vendor in the kernel and they seem either register based or eeprom based. Perhaps the latter is the case here? Have you checked existing implementations?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw
Quoted 11 lines · On Thu, 23 Apr 2026 20:43:55 +0300 Andy Shevchenko…
Quoted 10 lines · Nikhil Gautam

Apologies for missing a few details in the previous mail.

The MLX90393 supports both I2C and SPI interfaces.

Commands include, for example:
- SM (Start Measurement)
- RM (Read Measurement)
- RR (Read Register)

Quoted 8 lines
Quoted 3 lines

Given this command-oriented interface over both I2C and SPI, I wanted to confirm whether a custom command abstraction layer would still be the preferred approach instead of regmap.

I found only 4 drivers for this vendor in the kernel and they seem either register based or eeprom based. Perhaps the latter is the case here? Have you checked existing implementations?

If it doesn't match up with an existing case.

I took a look at the datasheet and this is a weird mix of a register driven and command driven device. As such you could do regmap for the registers, buy you'd need to bypass that for the command only stuff. I don't think it's worth the mess of creating some virtual registers to deal with the commands.

Hence I think in this particular case regmap doesn't look suitable and a custom bus abstraction layer makes sense. Some of that is going to look regmap like, but with some other callbacks as well.

Jonathan

#4 lore raw

Hi Andy, Jonathan,

Thanks for taking a look and for the guidance.

The MLX90393 does indeed expose a mix of command-based operations (SM, RM, etc.) along with limited register access (RR/WR), so it does not map cleanly to a purely register-based model.

Based on your feedback, I will proceed with a custom command abstraction layer instead of using regmap. The idea is to keep a clean separation between command handling, register access, and bus transport (I2C/SPI), while keeping the structure somewhat regmap-like where it makes sense.

I will put together an RFC patch with the initial implementation (I2C support first) and share it shortly for review.

Thanks again for the feedback.

Best regards,
Nikhil Gautam