linux核心筆記-binding屬性資訊和of函式

裝置樹bindings文件

1 在核心document資料夾下的bindings資料夾內,

linux-imx-rel_imx_4。1。15_2。1。0_ga\Documentation\devicetree\bindings有各種裝置繫結屬性規範。

例子: IMX PWM繫結資訊規範

Freescale i。MX PWM controller

Required properties:

- compatible : should be “fsl,-pwm” and one of the following

compatible strings:

- “fsl,imx1-pwm” for PWM compatible with the one integrated on i。MX1

- “fsl,imx27-pwm” for PWM compatible with the one integrated on i。MX27

- reg: physical base address and length of the controller‘s registers

- #pwm-cells: should be 2。 See pwm。txt in this directory for a description of

the cells format。

- clocks : Clock specifiers for both ipg and per clocks。

- clock-names : Clock names should include both “ipg” and “per”

See the clock consumer binding,

Documentation/devicetree/bindings/clock/clock-bindings。txt

- interrupts: The interrupt for the pwm controller

Example:

pwm1: pwm@53fb4000 {

#pwm-cells = <2>;

compatible = “fsl,imx53-pwm”, “fsl,imx27-pwm”;

reg = <0x53fb4000 0x4000>;

clocks = <&clks IMX5_CLK_PWM1_IPG_GATE>,

<&clks IMX5_CLK_PWM1_HF_GATE>;

clock-names = “ipg”, “per”;

interrupts = <61>;

};

Linux核心的OF操作函式

1、驅動如何獲取到裝置樹中節點資訊。在驅動中使用OF函式獲取裝置樹屬性內容。

Linux/of。h中存在很多of函式,如下:

static inline int of_node_to_nid(struct device_node *device)

{

return NUMA_NO_NODE;

}

#endif

static inline struct device_node *of_find_matching_node(

struct device_node *from,

const struct of_device_id *matches)

{

return of_find_matching_node_and_match(from, matches, NULL);

}

2,驅動要想獲取到裝置樹節點內容,首先要找到節點。

可以透過節點的名字,型別,路徑等等方式查詢節點。

linux核心筆記-binding屬性資訊和of函式