I2C總線和SPI總線的設備樹節點解析流程

一、設備樹中I2C節點的解析流程

/* i2c 控制器節點 */

i2c0: i2c@2180000 {

compatible = "fsl,vf610-i2c";

                        /*reg = <address1 length1 [address2 length2] [address3 length3]..>*/

#address-cells = <1>; /* address一個32位表示*/

#size-cells = <0>; /* length位空*/

reg = <0x0 0x2180000 0x0 0x10000>;

interrupts = <GIC_SPI 88 IRQ_TYPE_LEVEL_HIGH>;/*GIC_SPI SPI:shared processor interrupts  中斷號 32 ~32+224  88號中斷 IRQ_TYPE_LEVEL_HIGH觸發方式 */

clock-names = "i2c";

clocks = <&platform_clk 1>; /*使用的時鐘*/

status = "disabled";

};

reg = <0x0 0x2180000 0x0 0x10000>解析:

    i2c地址.gif

I2C地址0x2180000物理地址,映射長度0x10000,要使用這個物理地址先要在驅動中將其映射成虛擬地址。

/* i2c設備節點 */

&i2c0 {/* 引用i2c控制器0相當於它的子節點 */

status = "okay";


lm75@49 {

compatible = "ti,lm75";

reg = <0x49>;

};


lm75@4a {

compatible = "ti,lm75";

reg = <0x4a>;

};

};

/i2c0節點一般表示i2c控制器, 它會被轉換爲platform_device, 在內核中有對應的platform_driver;

/i2c0/lm75@49節點不會被轉換爲platform_device, 它被如何處理完全由父節點的platform_driver決定, 一般是被創建爲一個i2c_client。

設備樹的匹配流程:

platform_match:

1、match driver.of_match_table:of_driver_match_device  //設備樹解析

2、match driver.acpi_match_table

3、match platform_driver.id_table

4、match 設備的name和driver.name

上面四個任意匹配成功就算匹配ok。


代碼流程:

static const struct of_device_id i2c_imx_dt_ids[] = {
{ .compatible = "fsl,imx1-i2c", .data = &imx1_i2c_hwdata, },
{ .compatible = "fsl,imx21-i2c", .data = &imx21_i2c_hwdata, },
{ .compatible = "fsl,vf610-i2c",/* 對應設備樹compatible */ .data = &vf610_i2c_hwdata, },
{ /* sentinel */ }
};
static struct platform_driver i2c_imx_driver = {
.probe = i2c_imx_probe,
.remove = i2c_imx_remove,
.driver = {
.name = DRIVER_NAME,
.pm = I2C_IMX_PM_OPS,
.of_match_table = i2c_imx_dt_ids,
},
.id_table = imx_i2c_devtype,
};
/* 將設備樹轉換成platform_device後i2c_imx_probe函數被調用 */
i2c_imx_probe
    i2c_add_numbered_adapter /* 添加I2C控制器 */
        __i2c_add_numbered_adapter
            i2c_register_adapter /* 註冊I2C控制器 */
                device_register /* I2C控制器設備註冊 */
                of_i2c_register_devices /* 查找設備樹控制器下面的從設備 */
                    of_i2c_register_device
                        i2c_new_device
                            client->dev.bus = &i2c_bus_type;
                            device_register /* 添加設備I2C從設備 */
                i2c_scan_static_board_info /* 查找靜態表,有些I2C設備是在代碼中寫死的,不是通過設備樹的形式 */
                    i2c_new_device
                        client->dev.bus = &i2c_bus_type;
                        device_register /* 添加設備I2C從設備 */
/* 添加設備成功後lm75@49幾點的I2C設備將通過i2c_bus_type.i2c_device_match匹配驅動程序。*/
static const struct of_device_id lm75_of_match[] = {
{
.compatible = "ti,tmp75",
.data = (void *)tmp75
},
。。。。
}
static struct i2c_driver lm75_driver = {
.class= I2C_CLASS_HWMON,
.driver = {
.name= "lm75",
.of_match_table = of_match_ptr(lm75_of_match),
.pm= LM75_DEV_PM_OPS,
},
.probe= lm75_probe,
.id_table= lm75_ids,
.detect= lm75_detect,
.address_list= normal_i2c,
};


lm75_probe函數將被調用。

二、SPI設備樹節點處理流程

xx_spi_probe
    spi_bitbang_start
        spi_register_master->spi_register_master
            of_register_spi_devices
                of_register_spi_device
                    spi_add_device  /* 和i2c_new_device處理流程就一樣了匹配設備驅動 */


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章