设备树DTS 学习:3-驱动开发中常用的 DTS api
背景
本章的内容是为了实现在驱动中的开发,通过调用有关的api来寻找设备树节点熟悉,从而达到使用设备树进行驱动开发的目的。
Linux设备树语法详解一文中介绍了设备树的语法,这里主要
"include/of.h"介绍内核中提供的操作设备树的API
drivers/of.h是内核源码中关于设备树的内部实现。
device_node
内核中用下面的这个结构描述设备树中的一个节点,后面的API都需要一个device_node对象作为参数传入。
//include/of.h
46 struct device_node {
47 const char *name;
48 const char *type;
49 phandle phandle;
50 const char *full_name;
51
52 struct property *properties;
53 struct property *deadprops; /* removed properties */
54 struct device_node *parent;
55 struct device_node *child;
56 struct device_node *sibling;
57 struct device_node *next; /* next device of same type */
58 struct device_node *allnext; /* next in list of all nodes */
59 struct proc_dir_entry *pde; /* this node's proc directory */
60 struct kref kref;
61 unsigned long _flags;
62 void *data;
63 #if defined(CONFIG_SPARC)
64 const char *path_component_name;
65 unsigned int unique_id;
66 struct of_irq_controller *irq_trans;
67 #endif
68 };
struct device_node
--47-->节点名
--48-->设备类型
--50-->全路径节点名
--54-->父节点指针
--55-->子节点指针
查找节点API
/**
* of_find_compatible_node - 通过compatible属性查找指定节点
* @from - 指向开始路径的节点,如果为NULL,则从根节点开始
* @type - device_type设备类型,可以为NULL
* @compat - 指向节点的compatible属性的值(字符串)的首地址
* 成功:得到节点的首地址;失败:NULL
*/
struct device_node *of_find_compatible_node(struct device_node *from,const char *type, const char *compat);
/**
* of_find_matching_node - 通过compatible属性查找指定节点
* @from - 指向开始路径的节点,如果为NULL,则从根节点开始
* @matches - 指向设备ID表,注意ID表必须以NULL结束
* 范例: const struct of_device_id mydemo_of_match[] = {
{ .compatible = "fs4412,mydemo", },
{}
};
* 成功:得到节点的首地址;失败:NULL
*/
struct device_node *of_find_matching_node(struct device_node *from,const struct of_device_id *matches);
/**
* of_find_node_by_path - 通过路径查找指定节点
* @path - 带全路径的节点名,也可以是节点的别名
* 成功:得到节点的首地址;失败:NULL
*/
struct device_node *of_find_node_by_path(const char *path);
/**
* of_find_node_by_name - 通过节点名查找指定节点
* @from - 开始查找节点,如果为NULL,则从根节点开始
* @name- 节点名
* 成功:得到节点的首地址;失败:NULL
*/
struct device_node *of_find_node_by_name(struct device_node *from,const char *name);
提取通用属性API
/**
* of_find_property - 提取指定属性的值
* @np - 设备节点指针
* @name - 属性名称
* @lenp - 属性值的字节数
* 成功:属性值的首地址;失败:NULL
*/
struct property *of_find_property(const struct device_node *np, const char *name, int *lenp);
/**
* of_property_count_elems_of_size - 得到属性值中数据的数量
* @np - 设备节点指针
* @propname - 属性名称
* @elem_size - 每个数据的单位(字节数)
* 成功:属性值的数据个数;失败:负数,绝对值是错误码
*/
int of_property_count_elems_of_size(const struct device_node *np,const char *propname, int elem_size);
/**
* of_property_read_u32_index - 得到属性值中指定标号的32位数据值
* @np - 设备节点指针
* @propname - 属性名称
* @index - 属性值中指定数据的标号
* @out_value - 输出参数,得到指定数据的值
* 成功:0;失败:负数,绝对值是错误码
*/
int of_property_read_u32_index(const struct device_node *np, const char *propname, u32 index, u32 *out_value);
/**
* of_property_read_string - 提取字符串(属性值)
* @np - 设备节点指针
* @propname - 属性名称
* @out_string - 输出参数,指向字符串(属性值)
* 成功:0;失败:负数,绝对值是错误码
*/
int of_property_read_string(struct device_node *np, const char *propname, const char **out_string);
提取addr属性API
/**
* of_n_addr_cells - 提取默认属性“#address-cells”的值
* @np - 设备节点指针
* 成功:地址的数量;失败:负数,绝对值是错误码
*/
int of_n_addr_cells(struct device_node *np);
/**
* of_n_size_cells - 提取默认属性“#size-cells”的值
* @np - 设备节点指针
* 成功:地址长度的数量;失败:负数,绝对值是错误码
*/
int of_n_size_cells(struct device_node *np);
/**
* of_get_address - 提取I/O口地址
* @np - 设备节点指针
* @index - 地址的标号
* @size - 输出参数,I/O口地址的长度
* @flags - 输出参数,类型(IORESOURCE_IO、IORESOURCE_MEM)
* 成功:I/O口地址的首地址;失败:NULL
*/
__be32 *of_get_address(struct device_node *dev, int index, u64 *size, unsigned int *flags);
/**
* of_translate_address - 从设备树中提取I/O口地址转换成物理地址
* @np - 设备节点指针
* @in_addr - 设备树提取的I/O地址
* 成功:物理地址;失败:OF_BAD_ADDR
*/
u64 of_translate_address(struct device_node *dev, const __be32 *in_addr);
/**
* of_iomap - 提取I/O口地址并映射成虚拟地址
* @np - 设备节点指针
* @index - I/O地址的标号
* 成功:映射好虚拟地址;失败:NULL
*/
void __iomem *of_iomap(struct device_node *np, int index);
/**
* 功能:提取I/O口地址并申请I/O资源及映射成虚拟地址
* @np - 设备节点指针
* @index - I/O地址的标号
* @name - 设备名,申请I/O地址时使用
* 成功:映射好虚拟地址;失败:NULL
*/
void __iomem *of_io_request_and_map(struct device_node *np, int index, const char *name);
提取resource属性API
/**
* of_address_to_resource - 从设备树中提取资源resource(I/O地址)
* @np - 设备节点指针
* @index - I/O地址资源的标号
* @r - 输出参数,指向资源resource(I/O地址)
* 成功:0;失败:负数,绝对值是错误码
*/
int of_address_to_resource(struct device_node *dev, int index, struct resource *r);
提取GPIO属性API
/**
* include/of_gpio.h
* of_get_named_gpio - 从设备树中提取gpio口
* @np - 设备节点指针
* @propname - 属性名
* @index - gpio口引脚标号
* 成功:得到GPIO口编号;失败:负数,绝对值是错误码
*/
int of_get_named_gpio(struct device_node *np, const char *propname, int index);
提取irq属性API
/**
* of_irq_count从设备树中提取中断的数量
* @np - 设备节点指针
* 成功:大于等于0,实际中断数量,0则表示没有中断
*/
int of_irq_count(struct device_node *dev);
/**
* of_irq_get - 从设备树中提取中断号
* @np - 设备节点指针
* @index - 要提取的中断号的标号
* 成功:中断号;失败:负数,其绝对值是错误码
int of_irq_get(struct device_node *dev, int index);
提取其他属性API
/**
* of_get_mac_address - 从设备树中提取MAC地址
* @np - 设备节点指针
* @成功:MAC(6字节)的首地址;失败:NULL
*/
void *of_get_mac_address(struct device_node *np);
设备树DTS 学习:3-驱动开发中常用的 DTS api的更多相关文章
- Linux内核(17) - 高效学习Linux驱动开发
这本<Linux内核修炼之道>已经开卖(网上的链接为: 卓越.当当.china-pub ),虽然是严肃文学,但为了保证流畅性,大部分文字我还都是斟词灼句,反复的念几遍才写上去的,尽量考虑到 ...
- Android源码浅析(四)——我在Android开发中常用到的adb命令,Linux命令,源码编译命令
Android源码浅析(四)--我在Android开发中常用到的adb命令,Linux命令,源码编译命令 我自己平时开发的时候积累的一些命令,希望对你有所帮助 adb是什么?: adb的全称为Andr ...
- .net开发中常用的第三方组件
.net开发中常用的第三方组件 2013-05-09 09:33:32| 分类: dotnet |举报 |字号 订阅 下载LOFTER 我的照片书 | RSS.NET.dll RSS. ...
- 依赖注入及AOP简述(十)——Web开发中常用Scope简介 .
1.2. Web开发中常用Scope简介 这里主要介绍基于Servlet的Web开发中常用的Scope. l 第一个比较常用的就是Application级Scope,通常我们会将一 ...
- spring注解开发中常用注解以及简单配置
一.spring注解开发中常用注解以及简单配置 1.为什么要用注解开发:spring的核心是Ioc容器和Aop,对于传统的Ioc编程来说我们需要在spring的配置文件中邪大量的bean来向sprin ...
- 2019-2-20C#开发中常用加密解密方法解析
C#开发中常用加密解密方法解析 一.MD5加密算法 我想这是大家都常听过的算法,可能也用的比较多.那么什么是MD5算法呢?MD5全称是 message-digest algorithm 5[|ˈmes ...
- 开发中常用的es6知识
结合实际开发,开发中常用的es6的知识: 1.新增let和const命令: ES6 新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效: cons ...
- Android开发中常用的库总结(持续更新)
这篇文章用来收集Android开发中常用的库,都是实际使用过的.持续更新... 1.消息提示的小红点 微信,微博消息提示的小红点. 开源库地址:https://github.com/stefanjau ...
- iOS开发中常用的数学函数
iOS开发中常用的数学函数 /*---- 常用数学公式 ----*/ //指数运算 3^2 3^3 NSLog(,)); //result 9 NSLog(,)); //result 27 //开平方 ...
- Struts2页面开发中常用标签使用说明
1. Struts2页面开发中常用标签使用说明 1.1.往action里传值的使用方式: <input name="userName" type="text&quo ...
随机推荐
- js部分数组方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- SpringBoot获取配置:@Value、@ConfigurationProperties方式
配置文件yml # phantomjs的位置地址 phantomjs: binPath: windows: binPath-win linux: binPath-linux jsPath: windo ...
- Mybatis学习一(介绍/举例/优化)
MyBatis介绍: MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis ...
- 19、python 脚本
1.python 安装及配置 下载地址 python2 和 python3 共存安装 2.python 可视化 import turtle turtle.pensize(2) #画一个小圆 turtl ...
- SpringBoot-EasyExcel导出数据(带图片)
前言 EasyExcel 是阿里巴巴开源的一个Java操作Excel的技术,和EasyPoi一样是封装Poi的工具类. 但是不同的地方在于,在EasyExcel中解决了Poi技术读取大批量数据耗费内存 ...
- python交教程4:文件操作
文件操作流程 人类操作一个word流程: 1.找到文件.双击打开 2. 读或修改 3. 保存&关闭 ⽤python操作⽂件也差不多: 只读模式 创建模式 追加模式 遍历文件 图片视频- ...
- 海康iSC综合安防平台-视频web插件调试
综合安防管理平台 视频WEB插件 1.demo_window_simple_playback.html.demo_window_simple_preview.html为简化版demo,可在此基础上开发 ...
- 每天上一当系列之vue修饰符.number
今天使用number修饰符去处理el-input的内容为数字做校验原本以为省事不少,没想到,为0开头无法输入第二位以后,并且输入的比较多的时候会出现Infinity 很神奇,网上查了说是element ...
- C语言:快速排序(详解)
快速排序采用的是两头对比交换 http://t.csdn.cn/TXcAK 上面这个连接大家可以点进去看看博客李小白大大的图文解释,我觉得这个是对我启发比较大的,对刚接触快速排序的人来说非常友好,很快 ...
- Vue+springboot集成PageOffice实现在线编辑Word、excel文档
说明: PageOffice是一款在线的office编辑软件,帮助Web应用系统或Web网站实现用户在线编辑Word.Excel.PowerPoint文档.可以完美实现在线公文流转,领导批阅,盖章.可 ...