regmap – a register map abstraction for the Linux kernel

A good proportion of I2C and SPI device drivers in the kernel contain some very similar code for accessing the register maps of hardware connected to those buses – most hardware designers have solved the problem of providing very similar ways. Linux 3.1 introduces a new kernel API called regmap which factors out this code from the drivers, saving code and making it much easier to share infrastructure. There’s been an implementation of this in ASoC for some time now, the regmap API makes it available to all drivers.

The version of this API in version 3.1 is very simple, just factoring out the simplest level of physical I/O from the devices. Devices register with the regmap API by providing a struct regmap_config (which currently only allows the sizes of the register addresses and values to be specified) and the bus-specific structure to it. They can then use simple read and write operations on the device:

int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);

The API handles everything to do with formatting the data for transmission and parsing data coming back from the device. Block functions are also provided to allow multiple registers to be read or written simultaneously. Even with this basic level of support we end up saving quite a bit of code as drivers are converted to use the API.

The changes sitting in -next for version 3.2 take this a step further, adding support for more variations on SPI registers, a debugfs interface for dumping the device registers, register cache support courtesy of my colleague Dimitris Papastamos and trace points for dynamic instrumentation of the system.

3 thoughts on “regmap – a register map abstraction for the Linux kernel

  1. I am using the 2.6.37 kernel, and my kernel haven’t got the remgmap patch. When I want to add a new device which only has the driver in 3.x and it has the regmap interface , is there any method to patch my 2.6.37 kernel with the asoc patch which have regmap interface? Thank you!

    1. I’d expect that the patches should cherry pick back fairly easily, perhaps with a few dependencies – regmap itself you can just copy into an older kernel for the most part, it’s not using anything too modern, and the ASoC ones don’t touch anything that changes a lot.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.