本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74352188

一、DTS编写语法

 

二、常用函数

设备树函数思路是:
uboot启动时将设备树地址传给内核,内核解析设备树,并创建设备,初始化相关属性,驱动中通过of_get_XXX函数去获取设备树加载时创建的设备。想要知道of函数做了什么,就去追踪这个函数最后调用了什么,同时也就知道了内核解析设备树的时候为我们创建了什么。
 
(1)of_get_named_gpio
/**
 * 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);

(2)gpio_to_irq
/**
 * include/gpio.h
 * PIN值转换为相应的IRQ值,中断编号可以传给request_irq()和free_irq()
 * @gpio - gpio口引脚标号 
 * 成功:得到GPIO口编号
 */
static inline int gpio_to_irq(unsigned gpio)

(3)devm_request_any_context_irq
/**
 * 注册中断
 */
devm_request_any_context_irq

(4)of_match_ptr
/**
 * 匹配设备树上的参数,将设备int_demo_dt_ids与驱动int_demo_driver联系起来
 * 系统会根据设备树种定义的compatible参数比较驱动中的int_demo_dt_ids中定义的 .compatible 参数
 */
of_match_ptr(int_demo_dt_ids)
例子:
static const struct of_device_id int_demo_dt_ids[] = {  
    { .compatible = "tiny4412,interrupt_demo", },  
    {},  
};  
  
MODULE_DEVICE_TABLE(of, int_demo_dt_ids);  
  
static struct platform_driver int_demo_driver = {  
    .driver        = {  
        .name      = "interrupt_demo",  
        .of_match_table    = of_match_ptr(int_demo_dt_ids),  
    },  
    .probe         = int_demo_probe,  
    .remove        = int_demo_remove,  
};  

 
(5)of_get_property
/*
 */drivers/of/base.c
 * Find a property with a given name for a given node
 * and return the value.
 * 通过给定的设备节点和属性名字得到value。
 */
const void *of_get_property(const struct device_node *np, const char *name,
int *lenp)
{
struct property *pp = of_find_property(np, name, lenp);

return pp ? pp->value : NULL;
}

 
(6)devm_pinctrl_get
获取一个pinctrl句柄,参数是dev是包含这个pin的device结构体即xxx这个设备的device
获取设备操作句柄(设备模型中的struct device)的pin control state holder(struct pinctrl)
/** 
 * struct devm_pinctrl_get() - Resource managed pinctrl_get() 
 * @dev: the device to obtain the handle for 
 * 
 * If there is a need to explicitly destroy the returned struct pinctrl, 
 * devm_pinctrl_put() should be used, rather than plain pinctrl_put(). 
 */  
struct pinctrl *devm_pinctrl_get(struct device *dev)

(7)pinctrl_lookup_state
获取这个pin对应pin_state(引脚状态-turnon_tes/turnoff_tes)
/** 
 * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle 
 * @p: the pinctrl handle to retrieve the state from 
 * @name: the state name to retrieve 
 */  
struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, const char *name)

(8)pinctrl_select_state
设置引脚为为某个stata -- turnon_tes/turnoff_tes
/** 
 * pinctrl_select_state() - select/activate/program a pinctrl state to HW 
 * @p: the pinctrl handle for the device that requests configuration 
 * @state: the state handle to select/activate/program 
 */  
int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)

(9)of_get_named_gpio
得到GPIO的编号
./**
 * include/of_gpio.h
 * of_get_named_gpio - 从设备树中提取gpio口
 * @np - 设备节点指针
 * @propname - 属性名
 * @index - gpio口引脚标号 
 * 成功:得到GPIO口编号int型;失败:负数,绝对值是错误码
 */
int of_get_named_gpio(struct device_node *np, const char *propname, int index);
of_get_named_gpio:此函数是解析设备树的函数,我们通过这个函数去解析设备树,tiny4412,int_gpio1 = <&gpx3 2 GPIO_ACTIVE_HIGH>; 
跟踪下去会发现这个函数掉用了list = of_get_property(np, "tiny4412,int_gpio2", &size);设备树解析是创界了设备节点,现在通过这个函数去获取属性。

(10)devm_gpio_request_one
获取一个GPIO并初始化属性
/**
 * devm_gpio_request_one - request a single GPIO with initial setup
 * @dev:   device to request for
 * @gpio:  the GPIO number
 * @flags:  GPIO configuration as specified by GPIOF_*
 * @label:  a literal description string of this GPIO
 */
int devm_gpio_request_one(struct device *dev, unsigned gpio,
 unsigned long flags, const char *label)

【总结】设备树语法及常用API函数【转】的更多相关文章

  1. Linux设备树语法详解

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

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

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

  3. linux设备树语法

    设备树语法及绑定 概述 Device Tree是一种用来描述硬件的数据结构,类似板级描述语言,起源于OpenFirmware(OF). 就ARM平台来说,设备树文件存放在arch/arm/boot/d ...

  4. Delphi 常用API 函数

    Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小 AnyPopup 判断屏幕上是否存在任何弹出式窗口 ArrangeIconic ...

  5. Delphi 常用API 函数列表

    Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小AnyPopup 判断屏幕上是否存在任何弹出式窗口ArrangeIconicWi ...

  6. C语言实现单链表,并完成链表常用API函数

    C语言实现单链表,并完成链表常用API函数: 1.链表增.删.改.查. 2.打印链表.反转打印.打印环形链表. 3.链表排序.链表冒泡排序.链表快速排序. 4.求链表节点个数(普通方法.递归方法). ...

  7. C#常用 API函数大全

    常用Windows API1. API之网络函数WNetAddConnection 创建同一个网络资源的永久性连接WNetAddConnection2 创建同一个网络资源的连接WNetAddConne ...

  8. Delphi 常用API 函数(好多都没见过)

    AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小AnyPopup 判断屏幕上是否存在任何弹出式窗口ArrangeIconicWindows 排列一个父窗口的最小 ...

  9. C# 窗体常用API函数 应用程序窗体查找

    常用的处理窗体的API函数如下(注意:API函数必须放在窗体中...): 使用C#语言,要引用DllImport,必须要添加using System.Runtime.InteropServices命名 ...

随机推荐

  1. redis的安装和使用【2】redis的java操作

    修改redis.conf# 配置绑定ip,作者机子为192.168.100.192,请读者根据实际情况设置bind 192.168.100.192#非保护模式protected-mode no保存重启 ...

  2. adb 命令实用

    1.adb安装:adbinstall.bat:原理:将apk文件拖进此bat,install命令会强制(覆盖)安装apk安装包.代码如下: @echo on adb install -r % paus ...

  3. 微服务网关从零搭建——(二)搭建api网关(不带验证)

    环境准备 创建空的core2.1 api项目  演示使用名称APIGateWay  过程参考上一篇 完成后在appsettings.json 添加节点 "Setting": { & ...

  4. Python常用的内建模块

    PS:Python之所以自称“batteries included”,就是因为内置了许多非常有用的模块,无需额外安装和配置,即可直接使用.下面就来看看一些常用的内建模块. 参考原文 廖雪峰常用的内建模 ...

  5. 诊断:Goldengate OGG-01163 Bad column length

    故障现象: OGG- Bad column length () specified . 原因:源端修改了字段长度.虽然源端和目标端的长度已经通过DDL语句修改到一致,在extract进程未重启的情况下 ...

  6. ZOJ - 3985 - String of CCPC (思维 + 暴力)

    题意: 询问一共有有多少个CCPC,每个得1分,可以自己在任意位置添加字母,第i次添加需要耗费i-1分 思路: 既然每次添加需要耗分,添加第二个字母,相当于没有添加,所以只需要添加一次就好 先计算出原 ...

  7. WIndows 系统下的常用命令 和 检测方法

    ### 一.检测硬盘速度(Windows 自带工具) #### 使用windows 系统自带的工具测试硬盘读写速度 > 在使用下面命令前,需要获得管理员权限,才会在Dos窗口上显示(否则,一闪而 ...

  8. (二)Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用

    #!usr/bin/env python # -*- coding: utf-8 -*- def test(): print('hello, world') if __name__ == " ...

  9. * average vector from multiple files--Matlab

    n=359;a=[];b=[];c=[];% for loopfor i=1:n      filename=sprintf('output_%d.dat',i);    fileinfo = imp ...

  10. 模拟退火算fa

    转载:http://www.cnblogs.com/heaad/archive/2010/12/20/1911614.html 优化算法入门系列文章目录(更新中): 1. 模拟退火算法 2. 遗传算法 ...