CONFIG_OF 此内核配置启用设备树,使用相关 api 需要包含:
#include <linux/of.h>
#include <linux/of_device.h>
查看API: https://docs.kernel.org/devicetree/kernel-api.html
An introduction to the concept of aliases, labels, phandles, and paths
When using of_find_node_by_path() or of_find_node_opts_by_ path() to find a node given its path, if the supplied path does not start with /, then the first element of the path must be a property name in the /aliases node. That element is replaced with the full path from the alias.
Labeling a node is only useful if the node is intended to be referenced from the property of another node. You can consider a label as a pointer to a node, either by the path or by the reference.
Understanding overwriting nodes and properties #操 这也有重载吗?
比如以上的,后面的 I2C1 的status 值会覆盖前面的值。
Device tree sources and compilers
The device tree (also referred to as DT) comes in two forms. The first is the textual form, which represents the sources (also referred to as DTS). And the second is the binary blob form, which represents the compiled device tree, also referred to as DTB (for device tree blob) or FDT (for flattened device tree). Source files have a .dts extension, while the binary forms have either a .dtb or .dtbo extension. .dtbo is a particular extension that is used for compiled device tree overlays (DTBO means device tree blob for overlay), as we will see in the next section. There are also .dtsi text files (where the i at the end means "include"). These host SoC-level definitions and are intended to be included in .dts files, hosting the board-level definitions.
dtsi 用法?把soc的相关写在一个文件比如 rk3588.dtsi, 其他开发板也用了 3588 的,就可以直接include 这个rk3588.dtsi;
dts在源码中的位置:arch/arm/boot/dts/ arch/arm64/boot/dts/
DTC 在源码中的位置: scripts/dtc/
make dtbs,
The device tree overlay
可以在运行时在线修改添加更新节点或节点数据,只是不能删除节点
Building device tree overlays
Loading device tree overlays via configfs
Representing and addressing devices
设备地址 reg
#address-cells and #size-cells
Handling SPI and I2C device addressing
SPI 和 I2C 都是非内存映射设备,其父节点是 bus 每一个spi或i2c设备 都是 i2c控制器或 spi控制器的子节点
non-memory-mapped device, the #size-cells property is 0;and the size element in the addressing tuple is empty. This means that the reg property for this kind of device is always one cell. The following is an example:
Documentation/devicetree/ bindings/spi.
Memory-mapped devices and device addressing
reg = <base0 length0 [base1 length1] [address2 length2] ... >. Here, each tuple represents an address range used by the device.
The struct resource
struct resource *platform_get_resource( struct platform_device *dev, unsigned int type, unsigned int num)
struct resource *platform_get_resource_byname( struct platform_device *dev, unsigned int type, const char *name)
The concept of named resources
Extracting string properties
Reading cells and unsigned 32-bit integers
Handling Boolean properties
Extracting and parsing sub-nodes
标签:node,resource,struct,18,tree,2023.7,linux,device,path From: https://www.cnblogs.com/yangdinshan/p/17562151.html