1. spi master设备相关数据
static struct resource ninja_platform_resources[] = {
};
static struct platform_device ninja_platform_device = {
};
2. spi master设备注册
platform_device_register()
--> device_initialize()
--> platform_device_add()
----> insert_resource()
------> __insert_resource()
--------> __request_resource()
----> device_add()
------> platform_match()
--------> platform_match_id()
--------> strcmp(pdev->name, drv->name)
匹配条件设备名字和驱动名字相同,pdev->name = spi-altera, drv->name = spi-altera => driver = spi-altera.c
3. spi master驱动注册
driver - spi-altera.c
altera_spi_init()
--> platform_driver_register()
----> driver_register()
------> driver_attach()
--------> __driver_attach()
----------> driver_match_device()
------------> platform_match()
--------------> strcmp(pdev->name, drv->name)
匹配条件设备名字和驱动名字相同
----------> driver_probe_device()
------------> really_probe()
--------------> altera_spi_probe()
运行probe函数
altera_spi_probe()
--> spi_alloc_master()
--> platform_get_resource()
--> devm_ioremap_nocache()
--> platform_get_irq()
--> spi_bitbang_start()
----> INIT_WORK(&bitbang->work, bitbang_work)
------> bitbang->txrx_bufs(spi, t)
--------> altera_spi_txrx()
----> spi_register_master()
------> scan_boardinfo()
--------> if (chip->bus_num != master->bus_num) continue;
匹配条件bus_num相同
master->bus_num = pdev->id = 0, chip = bi->board_info, chip->bus_num = 0
--------> spi_new_device()
----------> spi_alloc_device()
----------> spi_add_device()
4. spi flash设备相关数据
static struct mtd_partition ninja_spi_flash_partitions[] = {
};
static struct flash_platform_data ninja_spi_flash_data = {
};
static struct spi_board_info ninja_spi_board_info[] __initdata = {
};
5. spi flash设备注册
spi_register_board_info()
--> list_add_tail(&bi->list, &board_list)
add to list board_list
6. spi flash驱动
m25p80_init()
--> spi_register_driver()
----> match : strcmp(spi->modalias, drv->name) == 0
匹配条件spi->modalias和drv->name相同
运行probe
----> m25p_probe()
------> spi->dev.platform_data->type == plat_id->name
软件支持设备型号
------> jedec_probe()
从硬件获取设备型号,要与软件相匹配
------> add_mtd_partitions()
--------> add_one_partition()
------> add_mtd_device()
写函数
write_sr()
--> spi_message_init()
--> spi_message_add_tail()
--> spi_sync()
读函数
read_sr()
--> spi_write_then_read()
----> spi_message_init()
----> spi_message_add_tail()
----> spi_sync()
------> spi_async()
--------> master->transfer()
----------> spi_bitbang_transfer()
------------> queue_work()
--------------> bitbang_work()
----------------> altera_spi_txrx()
------> wait_for_completion()
7. 提供的mtd接口
flash->mtd.erase = m25p80_erase;
flash->mtd.read = m25p80_read;
if (info->jedec_id >> 16 == 0xbf)
else
文件系统操作顺序
fs->vfs->dev->mtd->ops