设备树驱动API【原创】
#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/interrupt.h> #define U32_DATA_LEN 4 static int is_good;
static int irqno; irqreturn_t key_irq_handler(int irqno, void *devid)
{
printk("------------------------key pressed \n");
return IRQ_HANDLED;
} static int __init dt_drv_init(void)
{
/*
test_nod@12345678{
compatible = "farsight,test";
reg = <0x12345678 0x24
0x87654321 0x24>;
testprop,mytest;
test_list_string = "red fish","fly fish", "blue fish";
interrupt-parent = <&gpx1>;
interrupts = <1 4>; };
*/ // 在代码中获取节点的所有信息
//先把节点获取到
struct device_node *np = NULL; np = of_find_node_by_path("/test_nod@12345678");
if(np){
printk("find test node ok\n");
printk("node name = %s\n", np->name);
printk("node full name = %s\n", np->full_name); }else{
printk("find test node failed\n"); } //获取到节点中的属性
struct property *prop = NULL;
prop = of_find_property(np, "compatible",NULL);
if(prop)
{
printk("find compatible ok\n");
printk("compatible value = %s\n", prop->value);
printk("compatible name = %s\n", prop->name);
}else{
printk("find compatible failed\n"); } if(of_device_is_compatible(np, "farsight,test"))
{
printk("we have a compatible named farsight,test\n");
} //读取到属性中的整数的数组 u32 regdata[U32_DATA_LEN];
int ret; ret = of_property_read_u32_array(np, "reg", regdata, U32_DATA_LEN);
if(!ret)
{
int i;
for(i=; i<U32_DATA_LEN; i++)
printk("----regdata[%d] = 0x%x\n", i,regdata[i]); }else{
printk("get reg data failed\n");
} //读取到属性中的字符串的数组
const char *pstr[]; int i;
for(i=; i<; i++)
{
ret = of_property_read_string_index(np, "test_list_string", i, &pstr[i]);
if(!ret)
{
printk("----pstr[%d] = %s\n", i,pstr[i]);
}else{
printk("get pstr data failed\n");
}
} // 属性的值为空,实际可以用于设置标志
if(of_find_property(np, "testprop,mytest", NULL))
{
is_good = ;
printk("is_good = %d\n", is_good);
} // 获取到中断的号码
irqno = irq_of_parse_and_map(np, );
printk("-----irqno = %d\n", irqno); //验证中断号码是否有效
ret = request_irq(irqno, key_irq_handler, IRQF_TRIGGER_FALLING|IRQF_TRIGGER_RISING,
"key_irq", NULL);
if(ret)
{
printk("request_irq error\n");
return -EBUSY;
} return ; } static void __exit dt_drv_exit(void)
{
free_irq(irqno, NULL); } module_init(dt_drv_init);
module_exit(dt_drv_exit);
MODULE_LICENSE("GPL");
设备树驱动API【原创】的更多相关文章
- Linux设备树语法详解
概念 Linux内核从3.x开始引入设备树的概念,用于实现驱动代码与设备信息相分离.在设备树出现以前,所有关于设备的具体信息都要写在驱动里,一旦外围设备变化,驱动代码就要重写.引入了设备树之后,驱动代 ...
- Linux设备树语法详解【转】
转自:http://www.cnblogs.com/xiaojiang1025/p/6131381.html 概念 Linux内核从3.x开始引入设备树的概念,用于实现驱动代码与设备信息相分离.在设备 ...
- tiny4412学习(四)之移植linux-设备树(1)设备树基础知识及GPIO中断【转】
本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74177978 版权声明:本文为博主原创文章,转载请注明http://blog.c ...
- Linux 总线、设备、驱动模型 与 设备树
1.总线.设备.驱动模型 本着高内聚.低耦合的原则,Linux 把设备驱动模型分为了总线.设备和驱动三个实体,这三个实体在内核里的职责分别如下: 设备和驱动向总线进行注册,总线负责把设备和对应的驱动绑 ...
- 设备树API
引子 首先看一个例子,也可参考linux设备树语法中的gpio示例.该示例选自openwrt的gpio-button-hotblug驱动. 设备树code: gpio-keys-polled { co ...
- 《linux设备驱动开发详解》笔记——18 ARM linux设备树
18.1 设备树的起源 linux 2.6及之前,大量板级信息被硬编码到内核里,十分庞大,大量冗余代码: linux 2.6之前,引入了设备树: 设备树源于OpenFirmware,描述硬件的数据结构 ...
- 【总结】设备树对platform平台设备驱动带来的变化(史上最强分析)【转】
本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74375086 版权声明:本文为博主原创文章,转载请注明http://blog.c ...
- 【linux】驱动-8-一文解决设备树
目录 前言 8. Linux设备树 8.1 设备树简介 8.2 设备树框架 8.2.1 设备树格式 8.2.1.1 DTS 文件布局 8.2.1.2 node 格式 8.2.1.3 propertie ...
- Linux内核 设备树操作常用API【转】
转自:https://www.linuxidc.com/Linux/2017-02/140818.htm 一文中介绍了设备树的语法,这里主要介绍内核中提供的操作设备树的API,这些API通常都在&qu ...
随机推荐
- hdu4758 Walk Through Squares
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=4758 题目: Walk Through Squares Time Limit: 4000/20 ...
- redis未授权访问漏洞总结
Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. 漏洞介绍: Redis 默认情况下,会绑定在 0.0.0.0 ...
- Cooperation.GTST团队第二周项目总结
项目进展 这周我们把工作主要放在了UI界面的实现上,为了让整款APP看上去能够更加高大上,我们决定采用Android 5.0开始推出的一个Material Design风格的导航控件Toolbar. ...
- lucas 快速求大数组合数
根据公式就是 对每次C(n,m) = C(n%p,m%p) * C(n/p,m/p); ll pow(ll x,ll n) { ll res = ; x%=mod; while (n) { ) re ...
- tomcat跟目录下work文件夹的作用
work目录只是tomcat的工作目录,也就是tomcat把jsp转换为class文件的工作目录. jsp,tomcat的工作原理:当浏览器访问某个jsp页面时,tomcat会在work目录里把这个j ...
- R中的sample函数
今天介绍一些运算函数,它们的使用很简单,没有什么难度,但是也会用的着. 在医学统计学或者流行病学里的现场调查.样本选择经常会提到一个词:随机抽样.随机抽样是为了保证各比较组之间均衡性的一个很重要的方法 ...
- Codeforces Round #398 (Div. 2) A,B,C,D
A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- css3 导入字体
在CSS中导入字体或是字体ICON @font-face{ src: url("具体的字体地址"), url("具体的字体地址"); }
- 字符编码_Windows资料
1. 1.1.MSDN 函数WideCharToMultiByte(...) https://msdn.microsoft.com/en-us/library/windows/desktop/dd37 ...
- QtWebKit_cookie
1.百度搜索“qtwebkit cookie” 2. 2.1.qtwebkit 里 cookie 信息的保存 http://blog.tianya.cn/post-227188-33378112-1. ...