#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【原创】的更多相关文章

  1. Linux设备树语法详解

    概念 Linux内核从3.x开始引入设备树的概念,用于实现驱动代码与设备信息相分离.在设备树出现以前,所有关于设备的具体信息都要写在驱动里,一旦外围设备变化,驱动代码就要重写.引入了设备树之后,驱动代 ...

  2. Linux设备树语法详解【转】

    转自:http://www.cnblogs.com/xiaojiang1025/p/6131381.html 概念 Linux内核从3.x开始引入设备树的概念,用于实现驱动代码与设备信息相分离.在设备 ...

  3. tiny4412学习(四)之移植linux-设备树(1)设备树基础知识及GPIO中断【转】

    本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74177978 版权声明:本文为博主原创文章,转载请注明http://blog.c ...

  4. Linux 总线、设备、驱动模型 与 设备树

    1.总线.设备.驱动模型 本着高内聚.低耦合的原则,Linux 把设备驱动模型分为了总线.设备和驱动三个实体,这三个实体在内核里的职责分别如下: 设备和驱动向总线进行注册,总线负责把设备和对应的驱动绑 ...

  5. 设备树API

    引子 首先看一个例子,也可参考linux设备树语法中的gpio示例.该示例选自openwrt的gpio-button-hotblug驱动. 设备树code: gpio-keys-polled { co ...

  6. 《linux设备驱动开发详解》笔记——18 ARM linux设备树

    18.1 设备树的起源 linux 2.6及之前,大量板级信息被硬编码到内核里,十分庞大,大量冗余代码: linux 2.6之前,引入了设备树: 设备树源于OpenFirmware,描述硬件的数据结构 ...

  7. 【总结】设备树对platform平台设备驱动带来的变化(史上最强分析)【转】

    本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74375086 版权声明:本文为博主原创文章,转载请注明http://blog.c ...

  8. 【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 ...

  9. Linux内核 设备树操作常用API【转】

    转自:https://www.linuxidc.com/Linux/2017-02/140818.htm 一文中介绍了设备树的语法,这里主要介绍内核中提供的操作设备树的API,这些API通常都在&qu ...

随机推荐

  1. Spring的一些面试题(转)

    一.spring工作原理: 1.spring mvc的所有请求都提交给DispatcherServlet,它会委托应用系统的其他模块负责对请求进行真正的处理工作.2.DispatcherServlet ...

  2. jQuery源码分析--Event模块(2)

    接下来就是触发事件了.事件触发后的处理函数的分发主要靠两个函数,一个jQuery.event.dispatch,一个是jQuery.event.handlers.这个dispatch会调用handle ...

  3. SQL学习笔记三(补充-1)之MySQL存储引擎

    阅读目录 一 什么是存储引擎 二 mysql支持的存储引擎 三 使用存储引擎 一 什么是存储引擎 mysql中建立的库===>文件夹 库中建立的表===>文件 现实生活中我们用来存储数据的 ...

  4. Python3.x:os.chdir(改变当前路径方法)介绍

    Python3.x:os.chdir(改变当前路径方法)介绍 1,os.chdir() import os os.chdir(r'C:\python36\test_chdir') 说明:chdir() ...

  5. 20145122 《Java程序设计》第5周学习总结

    教材学习内容总结 1.在Java中,异常分为受检查的异常,与运行时异常. 两者都在异常类层次结构中. 2.受检查的异常(checked exceptions),其必须被 try{}catch语句块所捕 ...

  6. HeyWeGo第四周项目总结

    HeyWeGo第四周项目总结 项目内容 使用java程序开发一款扫雷游戏 游戏项目规划: 确定游戏中方块格子的个数 确定游戏中地雷的个数(初始10个),完成布雷 计算每个方块周围的雷数,在方块周围本身 ...

  7. Asynchronous Programming Patterns

    Asynchronous Programming Patterns The .NET Framework provides three patterns for performing asynchro ...

  8. adb connect 192.168.1.10 failed to connect to 192.168.1.10:5555

    adb connect 192.168.1.10 输出 failed to connect to 关闭安卓端Wi-Fi,重新打开连接即可

  9. python 返回系统位数

    # For bit it will and bit it will import struct print()

  10. mysql导入source数据库

    首先要确保数据库存在,如果不存在则创建 方法1 source 很智能,很方便,很快捷. # mysql -uroot -p Enter password: Welcome to the MySQL m ...