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.

Subscribe to Technicalities

Sign up now to get access to the library of members-only issues.
Jamie Larson
Subscribe