以下内容只能作为我添加SPi平台设备的一点总结。
1、首先在平台设备文件中添加如下内容:
#if defined (CONFIG_MTK_SPI)
static struct resource mt_spi_resources[] =
{
[0]={
.start = IO_VIRT_TO_PHYS(SPI1_BASE),
.end = IO_VIRT_TO_PHYS(SPI1_BASE) + 0x0028,
.flags = IORESOURCE_MEM,
},
[1]={
.start = MT6589_SPI1_IRQ_ID,
.flags = IORESOURCE_IRQ,
},
};
static struct platform_device mt_spi_device = {
.name = "mt-spi",
.num_resources = ARRAY_SIZE(mt_spi_resources),
.resource=mt_spi_resources
};
#endif
2、然后注册平台设备,相当于声明:
#if defined(CONFIG_MTK_SPI)
platform_device_register(&mt_spi_device);
#endif
3、然后再注册平台设备,可以再设备驱动文件中添加:
spi_register_board_info(spi_board_devs, ARRAY_SIZE(spi_board_devs));
static struct spi_board_info spi_board_devs[] __initdata = {
[0] = {
.modalias="spi-ut",
.bus_num = 0,
.chip_select=1,
.mode = SPI_MODE_3,
},
};
4、注册设备驱动
spi_register_driver(&spi_test_driver);
struct spi_device_id spi_id_table = {"spi-ut", 0};
static struct spi_driver spi_test_driver = {
.driver = {
.name = "test_ut",
.bus = &spi_bus_type,
.owner = THIS_MODULE,
},
.probe = spi_test_probe,
.remove=spi_test_remove,
.id_table = &spi_id_table,
};
注:driver.name 和 modalias 名字要一样。
5、设备和驱动match 匹配之后,就执行 probe。
仅供参考之用
/sys/devices/platform/plat_usb_mouse.0
./sys/bus/platform/devices/plat_usb_mouse.0
./sys/bus/platform/drivers/plat_usb_mouse
./sys/bus/platform/drivers/plat_usb_mouse/plat_usb_mouse.0
http://blog.csdn.net/hanchaoman/article/details/7219127