linux3.0 spi-s3c64xx.c
最近写一个spi dma的程序,不得已要先改在linux3.0上面
有dts支持的情况下一般是dts 的devnode 跟platform driver的of_match_table 的compatible
属性match然后probe
3.0的时候还不支持dts,那用来match的属性各自在何处定义的呢
static int platform_match(struct device *dev, struct device_driver *drv)
{
struct platform_device *pdev = to_platform_device(dev);
struct platform_driver *pdrv = to_platform_driver(drv);
/* Attempt an OF style match first */
if (of_driver_match_device(dev, drv))
return 1;
//对比device dts node和driver of_match_table de compatibel属性
/* Then try to match against the id table */
if (pdrv->id_table)
return platform_match_id(pdrv->id_table, pdev) != NULL;
//对比driver的id_table与device的name是否匹配
/* fall-back to driver name match */
return (strcmp(pdev->name, drv->name) == 0);
//直接对比device的name和driver的name
}
platform_driver结构体定义了driver的name
static struct platform_driver s3c64xx_spi_driver = {
.driver = {
.name = "s3c64xx-spi",
.owner = THIS_MODULE,
},
没有match table 也没有id_table 也没有明显的看到有device name,这时候driver和device是如何match的呢
linux3.18 4.9 版本支持dts,platform device加入的方法是通过of_platform_populate根据dts的dev node 添加进platform device list,如果没有dts的话是在哪个阶段把platform device 添加进来的呢,mach-init!
在mach-s3c64xx.c中找到了spi的platform device的定义
struct platform_device s3c64xx_device_spi0 = {
.name = "s3c64xx-spi",
.id = 0,
.num_resources = ARRAY_SIZE(s3c64xx_spi0_resource),
.resource = s3c64xx_spi0_resource,
.dev = {
.dma_mask = &spi_dmamask,
.coherent_dma_mask = DMA_BIT_MASK(32),
.platform_data = &s3c64xx_spi0_pdata,
},
};
EXPORT_SYMBOL(s3c64xx_device_spi0);
static struct platform_device *smdk6410_devices[] __initdata = {
&s3c64xx_device_spi0,
}
static void __init smdk6410_machine_init(void)
{
s3c_ide_set_platdata(&smdk6410_ide_pdata);
platform_add_devices(smdk6410_devices, ARRAY_SIZE(smdk6410_devices));
}
在machine_init里建立platform device,spi init的时候注册了driver后probe就会执行