Regmap-based SPI driver example – putting it all together
All the steps involved in setting up Regmap, from configuration to device register access, can be enumerated as follows:
- Setting up a
struct regmap_config
object according to the device characteristics. Defining the register range if needed, default values if any,cache_type
if needed, and so on. If custom read/write functions are needed, pass them to thereg_read
/reg_write
fields. - In the
probe
function, allocating a register map usingdevm_regmap_init_i2c()
,devm_regmap_init_spi()
, ordevm_regmap_init_mmio()
depending on the connection with the underlying device – I2C, SPI, or memory-mapped. - Whenever you need to read/write from/into registers, calling
remap_[read|write]
functions. - When done with the register map, assuming you used resource-managed APIs, you have nothing else to do as devres core will take care of releasing the Regmap resources; otherwise, you'll have to call
regmap_exit...