#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. VS2010/MFC编程入门之二十六(常用控件:滚动条控件Scroll Bar)

    回顾上一节,鸡啄米讲的是组合框控件Combo Box的使用.本节详解滚动条控件Scroll Bar的相关内容. 滚动条控件简介 滚动条大家也很熟悉了,Windows窗口中很多都有滚动条.前面讲的列表框 ...

  2. 端口安全检查shell脚本

    #!/bin/bash #This script name is scan_analyse.sh . /etc/profile echo "start time is $(date)&quo ...

  3. LS1021ATWR开发板启动日志分析

    一.背景 LS1021ATWR开发板运行官方的openwrt系统 二.日志分析 2.1 linux相关日志 root@OpenWrt:/# reboot  重启 root@OpenWrt:/# [ 2 ...

  4. 如何表示各个时区的时间DateTime.ToString()

    使用sqlite进行时间的插入的时候,使用了 DateTime.ToString("s")  //s: 2008-06-15T21:15:07 插入到数据库之后,发现时间被加了8个 ...

  5. win10下安装lxml

    最近在windows平台下开发,用的python3.6,安装lxml遇到点问题,现已解决.特意记下,以供以后再遇到. 解决方法: 1.打开cmd终端,查看pip版本,pip --version,如不是 ...

  6. Today's harvest !!!

    今天将Mybatis的视频看到了第60集,其之前讲解了自表的主外键查询.例如一个新闻表中,有一级栏目,二级栏目,三级栏目,其中二级栏目的pid为一级栏目的id,如此种种. 而今天做的小项目中使用了 e ...

  7. windows下hadoop安装配置(转载)

    Windows平台安装配置Hadoop 步骤: 1. JDK安装(不会的戳这) 2. 下载hadoop2.5.2.tar.gz,或者自行去百度下载. 3. 下载hadooponwindows-mast ...

  8. css 基础-1

    css 基础-1 一. HTML框架 (frameset) 属性:  noresize(不可移动), border(边框线的大小),            rows(分割成行), cols(分割列) ...

  9. Symmetric Tree,对称树

    问题描述: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). ...

  10. nohup 不生成 nohup.out的方法

    nohup java -jar /xxx/xxx/xxx.jar >/dev/>& & 关键在于最后的 >/dev/>& 部分,/dev/null是一个 ...