zoukankan      html  css  js  c++  java
  • regmap使用介绍【转】

    本文转载自:http://blog.csdn.net/hellowxwworld/article/details/10737569

    内核3.1引入一套新的API regmap,目的是提取出关于I2C SPI irq等相关注册、使能以及读写的公共部分,以提高代码的可重用性,并且使得在使用如上内核基础组件时变得更为简单易用。

    0 基础结构

    [cpp] view plain copy
     
    1. struct regmap_config {  
    2.     int reg_bits; // 寄存器地址的位数,必须配置,例如I2C寄存器地址位数为 8  
    3.     int pad_bits; // 寄存器值的位数,必须配置  
    4.     int val_bits;  
    5.     bool (*writeable_reg)(struct device *dev, unsigned int reg); // 可写寄存器回调,maintain一个可写寄存器表  
    6.     bool (*readable_reg)(struct device *dev, unsigned int reg); // 可读寄存器回调, maintain一个可读寄存器表  
    7.     bool (*volatile_reg)(struct device *dev, unsigned int reg); // 可要求读写立即生效的寄存器回调,不可以被cache,maintain一个可立即生效寄存器表  
    8.     bool (*precious_reg)(struct device *dev, unsigned int reg); // 要求寄存器数值维持在一个数值范围才正确,maintain一个数值准确表  
    9.     unsigned int max_register; // max_register: 最大寄存器地址  
    10.     const struct reg_default *reg_defaults;  
    11.     unsigned int num_reg_defaults;  
    12.     enum regcache_type cache_type;  
    13.     const void *reg_defaults_raw;  
    14.     unsigned int num_reg_defaults_raw;  
    15.     u8 read_flag_mask;  
    16.     u8 write_flag_mask;  
    17. };  

    1 初始化regmap 

    [cpp] view plain copy
     
    1. regmap_init_i2c(struct i2c_client *i2c, struct regmap_config *config);  
    2. regmap_init_spi(struct spi_device *spi, strcut regmap_config *config);  
    3. regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags, int irq_base, struct regmap_irq_chip *chip, struct regmap_irq_chip_data **data);  


    前两个是用来关联i2c或者spi设备和regmap_config的,第三个用来在关联后的regmap上注册 irq

    2 使用regmap

    在初始化好regmap之后,就可以调用regmap提供的read/write/update等操作了。

    [cpp] view plain copy
     
    1. regmap_write(struct regmap *map, int reg, int val); // 向reg写入val  
    2. regmap_raw_write(struct regmap *map, int reg, void *val, size_t val_len);  // 向reg写入指定长度的数据,数据存放在val中  
    3. regmap_read(struct regmap *map, int reg, int *val); // 读取reg的数据到val中  
    4. regmap_raw_read(struct regmap *map, int reg, void *val, size_t val_len); // 读取reg中指定长度的数据  
    5. regmap_bulk_read(struct regmap *map, int reg, void *val, size_t val_count); // 读取从reg开始之后val_count个寄存器的数据到val中  
    6. regmap_update_bits(struct regmap *map, int reg, int mask, int val); // 更新reg寄存器中mask指定的位  
    7. regcache_cache_bypass(arizona->regmap, true); // 设置读写寄存器不通过cache模式而是bypass模式,读写立即生效,一般在audio等确保时序性驱动中用到  

    3 释放regmap    

    [cpp] view plain copy
     
      1. regmap_exit(struct regmap *map);  
  • 相关阅读:
    解读基础设施即代码
    在那江南烈日与阵雨中-江南100赛记
    写在2017年环汶川越野赛之前
    阿里巴巴Java开发手册评述
    一个程序员的2016年总结
    面向对象的思考过程第四版译者序
    以敏捷的方式运作一所大学
    敏捷团队中的QA由来
    Spring Batch在大型企业中的最佳实践
    Java基础 awt Button 鼠标放在按钮上背景颜色改变,鼠标离开背景颜色恢复
  • 原文地址:https://www.cnblogs.com/zzb-Dream-90Time/p/8082270.html
Copyright © 2011-2022 走看看