MTK SPI设备驱动分析

一.MTK测试的SPI驱动

Spi-dev.c (kernel-3.18\drivers\spi\mediatek\mt6735)
 
struct spi_device_id spi_id_table = { "spi-ut", 0 };
static struct spi_driver spi_test_driver = {
.driver = {
.name = "test_spi",
.bus = &spi_bus_type,
.owner = THIS_MODULE,
},
.probe = spi_test_probe,
.remove = spi_test_remove,
.id_table = &spi_id_table,
};
 
static struct spi_board_info spi_board_devs[] __initdata = {
[0] = {
.modalias = "spi-ut",
.bus_num = 0,
.chip_select = 1,
.mode = SPI_MODE_3,
},
};
 
spi_dev_init
    spi_register_board_info(spi_board_devs, ARRAY_SIZE(spi_board_devs)); //注册spi设备的信息
        list_add_tail(&bi->list, &board_list);
list_for_each_entry(master, &spi_master_list, list)
spi_match_master_to_boardinfo(master, &bi->board_info); //如果有SPI控制器就NEW一个设备,见MTK SPI控制器驱动分析章节
    spi_register_driver(&spi_test_driver); //注册spi设备驱动
        sdrv->driver.bus = &spi_bus_type;
        driver_register(&sdrv->driver);
 
 
spi_driver的device_driver中的name字段肯定为"spi-ut".只有这样才能在SPI核心层的spi_match_device函数中匹配.
 
 
static DEVICE_ATTR(spi, 0200, NULL, spi_store);
static DEVICE_ATTR(spi_msg, 0200, NULL, spi_msg_store);
 
static struct device_attribute *spi_attribute[] = {
&dev_attr_spi,
&dev_attr_spi_msg,
};
 
spi_test_probe
   spi->mode = SPI_MODE_3;
    spi->bits_per_word = 32;
    return spi_create_attribute(&spi->dev);
        device_create_file(dev, spi_attribute[idx]);
            spi_msg
            spi_msg_store
 
        
posted @ 2020-11-25 15:29  luoyuna  阅读(1055)  评论(0编辑  收藏  举报