设备树驱动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 ...
随机推荐
- import static
import static(静态导入)是JDK1.5中的新特性,一般我们导入一个类都用 import com.....ClassName;而静态导入是这样:import static com..... ...
- python使用cx_Oracle连接oracle
1.使用pip命令安装cx_Oracle $ pip install cx_Oracle 2.安装oracle客户端,并添加到path 下载路径: http://www.oracle.com/tech ...
- .net core 2.2 & Mongodb
.net core 2.2 API项目中使用Mongodb 简单的CRUD封装 创建FoodPlan.Core 项目 创建IEntityBase.cs 接口约束 创建Single.cs 实体 IEnt ...
- PowerDesigner教程系列
文章转载至:http://www.cnblogs.com/yxonline/archive/2007/04/09/705479.html PowerDesigner教程系列(一)概念数据模型 目标:本 ...
- Vue学习笔记之Vue介绍
vue的作者叫尤雨溪,中国人.自认为很牛逼的人物,也是我的崇拜之神. 关于他本人的认知,希望大家读一下这篇关于他的文章,或许你会对语言,技术,产生浓厚的兴趣.https://mp.weixin.qq. ...
- linux下递归删除指定后缀名的文件
以删除当前目录到所有子目录下的后缀名为rej的文件为例: find . -name "*.rej" |xargs rm -f
- BootStrap iCheck插件全选与获取value值的解决方法
这篇文章主要介绍了BootStrap iCheck插件全选与获取value值的解决方法,解决方法其实很简单,下面小编给大家分享下这方面的知识 在使用jQuery iCheck 插件的时候遇到了一个问题 ...
- TCGA下载神器--TCGAbiolinks
http://bioconductor.org/packages/devel/bioc/vignettes/TCGAbiolinks/inst/doc/tcgaBiolinks.html#gdcque ...
- codeforces 55 div2 C.Title 模拟
C. Title time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- 【Python】远离 Python 最差实践,避免挖坑
原文链接:http://blog.guoyb.com/2016/12/03/bad-py-style/ 最近在看一些陈年老系统,其中有一些不好的代码习惯遗留下来的坑:加上最近自己也写了一段烂代码导致服 ...