首页 > 编程知识 正文

ip classless,8253初始化程序

时间:2023-05-06 06:59:48 阅读:27505 作者:2232

内核对设备树的处理从源代码dts文件开始。

dts在PC上编译为dtb文件的u-boot将dtb文件传递到内核以分析dtb文件,并将每个节点转换为device_node结构。 在某些device_node结构中,platform_device结构中的哪个设备树节点将转换为platform_device结构

具有特定兼容性属性的节点的子节点。

如果节点属性包含" simple-bus "、" simpile-mfd "、" isa "、" arm、armba-bus ",

必须包含compatible属性的子节点也可以转换为platform_device。

总线I2C、SPI节点下的子节点:不转换为platform_device。

一条总线应该下到子节点,交给相应的总线驱动器处理,而他们不应该被转换为platform_device。

//platform_devicemytest//yes (条件1 ) compatile='mytest ',' simple-bus '; mytest@0 {//Yes (条件2 ) compatile='mytest_0'; (; (; i2c {//Yes (条件1 ) compatile='samsung,i2c '; at24c02 {//No (条件3 ) compatile='at24c02 '; (; (; spi {//Yes (条件1 ) compatile='samsung,spi '; flash@0 {//No (条件3 ) compatible='winbond,w25q32dw '; spi-max-frequency=25000000; reg=0; (; (; (; 转换为platform_device platform_device中包含的resource数组的方法来自device_node的reg,interrupts属性。 platform_device.dev.of_node指向device_node,从中可以检索其他属性。 staticintplatform _ match (结构设备* dev,结构设备_驱动程序* drv ) struct平台_设备* pdev=to _ platfform /* When driver_override is set,onlybindtothematchingdriver */if (pdev-driver _ override )/1 .首先强制驱动程序恢复设置driver_override以获取platform _ driver/* attemptanofstylematchfirst */if (of _ driver _ match _ device (dev, //platfrom _ driver.driver.of _ match _ table/* thentryacpistylematch */if (acpi _ driver _ match _ device2/) 3 .然后比较platform_device.name与platform _ driver.id=null; //id_table包含多个/* fall-backtodrivernamematch */return (strcmp (pdev-name,drv-name )==0); //4 .最后,如果platfrom_device.name和platform _ driver.driver.name }//platform _ driver支持设备树,则为该平台structof _ device _ id { charname [ 32 ]; //3 .最后,dev的name属性和chartype[32]; //2 .如果[128] //1.of_match_table包含compatible值,则比较type值,比较dev的device_type属性与charcompatible 返回常数语音*数据成功或失败; (; //设备树中不再建议使用device_type和name属性。 dtb中的每个节点都将转换为device_node结构stru

ct device_node {const char *name;//来自设备树节点的name属性const char *type;//来自设备树节点的type属性phandle phandle;const char *full_name;struct fwnode_handle fwnode;structproperty *properties;//含有compatible属性structproperty *deadprops;/* removed properties */structdevice_node *parent;structdevice_node *child;structdevice_node *sibling;structkobject kobj;unsigned long _flags;void*data;#if defined(CONFIG_SPARC)const char *path_component_name;unsigned int unique_id;struct of_irq_controller *irq_trans;#endif};struct property {bool deleted;char *name;struct data val;struct property *next;struct label *labels;}; 类型头文件说明处理DTBof_fdt.h dtbof_fdt.h dtb文件相关操作函数,一般用不到。内核中已经转换成device_node树处理device_nodeof.h提供设备树的一般处理函数, 比如 of_property_read_u32, of_get_child_count-of_address.h地址相关的函数, 比如 of_get_address ,of_match_device-of_dma.h设备树中 DMA 相关属性的函数-of_gpio.hGPIO 相关的函数-of_graph.hGPU 相关驱动中用到的函数, 从设备树中获得 GPU 信息-of_iommu.h很少用到-of_irq.h中断相关的函数-of_mdio.hMDIO (Ethernet PHY) API-of_net.hOF helpers for network devices.-of_pci.hPCI 相关函数-of_pdt.h很少用到-of_reserved_mem.hreserved_mem 的相关函数处理platform_deviceof_platform.h把 device_node 转换为 platform_device 时用到的函数, 比如 of_device_alloc, of_find_device_by_node-of_device.h设备相关的函数, 比如 of_match_deviceplatform_device相关函数 //of_platform.hextern struct platform_device *of_find_device_by_node(struct device_node *np);//知道device_node找platform_devicestruct resource *platform_get_resource(struct platform_device *dev, unsigned int type, unsigned int num); //对于设备树节点中的 reg 属性,它对应 IORESOURCE_MEM 类型的资源; //对于设备树节点中的 interrupts 属性,它对应 IORESOURCE_IRQ 类型的资源。 找节点 //incldue/linux/of.h//根据路径找节点static inline struct device_node *of_find_node_by_path(const char *path);//根据name找节点extern struct device_node *of_find_node_by_name(struct device_node *from, const char *name);//根据type找节点extern struct device_node *of_find_node_by_type(struct device_node *from,const char *type);//根据compatible找节点,from开始节点,type可以为NULL,指定device_type值,compat指定compatible的值extern struct device_node *of_find_compatible_node(struct device_node *from,const char *type, const char *compat);//根据phandle找节点,每个节点都有一个数字idextern struct device_node *of_find_node_by_phandle(phandle handle);//根据节点找父节点extern struct device_node *of_get_parent(const struct device_node *node);//根据节点找父节点,多调用了of_node_put(node)extern struct device_node *of_get_next_parent(struct device_node *node);//取出下一个子节点,prev是上一个子节点如果为NULL就找第一个extern struct device_node *of_get_next_child(const struct device_node *node,struct device_node *prev);//取出下一个可用子节点,status是"disabled"就会被跳过extern struct device_node *of_get_next_available_child(const struct device_node *node, struct device_node *prev);//根据名字取出子节点extern struct device_node *of_get_child_by_name(const struct device_node *node, const char *name); 找属性 //incldue/linux/of.h//找到节点中的属性,np表示节点,name表示名字,lenp用来保存这个属性的长度值//xxx_pp_name = "hello";那么它的属性值是6extern struct property *of_find_property(const struct device_node *np, const char *name, int *lenp);//根据名字找到节点的属性,np表示节点,name表示名字,lenp用来保存这个属性的长度值extern const void *of_get_property(const struct device_node *node, const char *name, int *lenp);//根据名字找到节点的属性,确定它有多少个元素//np表示节点,找到propname的属性,返回pro->length/elem_size// xxx_pp_name = <0x50000000 1024> <0x60000000 2048>// 调用 of_property_count_elems_of_size(np, "xxx_pp_name", 8)时,返回值是 2// 调用 of_property_count_elems_of_size(np, "xxx_pp_name", 4)时,返回值是 4extern int of_property_count_elems_of_size(const struct device_node *np, const char *propname, int elem_size); // 读整数u32/u64// name1 = <0x50000000>;// name2 = <0x50000000 0x60000000>;// 调用 of_property_read_u32 (np, “name1”, &val)时,val 将得到值 0x50000000// 调用 of_property_read_u64 (np, “name2”, &val)时,val 将得到值 0x0x6000000050000000static inline int of_property_read_u32(const struct device_node *np, const char *propname, u32 *out_value);extern int of_property_read_u64(const struct device_node *np, const char *propname, u64 *out_value);// 读整数u32/u64,index为序号// 调用 of_property_read_u32 (np, "name2", 1, &val)时,val 将得到值 0x0x60000000extern int of_property_read_u32_index(const struct device_node *np, const char *propname, u32 index, u32 *out_value);// 读数组// name2 = <0x50000012 0x60000034>;// 调用 of_property_read_variable_u8_array (np, “name2”, out_values, 1, 10)时,out_values 中将会保存这 8 个字节: 0x12,0x00,0x00,0x50,0x34,0x00,0x00,0x60// 调用 of_property_read_variable_u16_array (np, “name2”, out_values, 1, 10)时,out_values中将会保存这 4 个 16 位数值: 0x0012, 0x5000,0x0034,0x6000// 会返回全部数值,要么没有。长度介于sz_min和sz_max之间int of_property_read_variable_u8_array(const struct device_node *np, const char *propname, u8 *out_values, size_t sz_min, size_t sz_max);// 读字符串// 返回np的propname的名字的值,(*out_string)指向这个值extern int of_property_read_string(struct device_node *np, const char *propname, const char **out_string); 修改设备树文件方法 使用芯片厂家提供的工具看绑定文档参考同类型单板的设备树文件网上搜索实在没办法时, 只能去研究驱动源码

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。