platform _device和platform_driver注册过程
platform_device_register()注册过程
/* arch/arm/mach-s3c2410/mach-smdk2410.c */
struct platform_device s3c_device_i2c = {
.name = "s3c2410-i2c",
.id = -1,
.num_resources = ARRAY_SIZE(s3c_i2c_resource),
.resource = s3c_i2c_resource,
};
/*
* platform_device_register - add a platform-level device
* @pdev: platform device we're adding
*
*/
int platform_device_register(struct platform_device * pdev)
{
device_initialize(&pdev->dev); //初始化设备结构
return platform_device_add(pdev); //添加一个片上的设备到设备层
}
/**
* platform_device_add - add a platform device to device hierarchy
* @pdev: platform device we're adding
*
* This is part 2 of platform_device_register(), though may be called
* separately _iff_ pdev was allocated by platform_device_alloc().
*/
int platform_device_add(struct platform_device *pdev)
{
int i, ret = 0;
if (!pdev)
return -EINVAL;
if (!pdev->dev.parent)
pdev->dev.parent = &platform_bus;
pdev->dev.bus = &platform_bus_type;
if (pdev->id != -1)
snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s.%d", pdev->name,
pdev->id); /* 若支持同类多个设备,则用pdev->name和pdev->id在总线上标识该设备 */
else
strlcpy(pdev->dev.bus_id, pdev->name, BUS_ID_SIZE); /* 否则,用pdev->name(如"s3c2410-i2c")在总线上标识该设备 */
for (i = 0; i < pdev->num_resources; i++) { /* 遍历资源数,并为各自在总线地址空间请求分配 */
struct resource *p, *r = &pdev->resource[i];
if (r->name == NULL)
r->name = pdev->dev.bus_id;
p = r->parent;
if (!p) {
if (r->flags & IORESOURCE_MEM)
p = &iomem_resource; /* 作为IO内存资源分配 */
else if (r->flags & IORESOURCE_IO)
p = &ioport_resource; /* 作为IO Port资源分配 */
}
if (p && insert_resource(p, r)) { /* 将新的resource插入内核resource tree */
printk(KERN_ERR
"%s: failed to claim resource %d\n",
pdev->dev.bus_id, i);
ret = -EBUSY;
goto failed;
}
}
pr_debug("Registering platform device '%s'. Parent at %s\n",
pdev->dev.bus_id, pdev->dev.parent->bus_id);
ret = device_add(&pdev->dev);
if (ret == 0)
return ret;
failed:
while (--i >= 0)
if (pdev->resource[i].flags & (IORESOURCE_MEM|IORESOURCE_IO))
release_resource(&pdev->resource[i]);
return ret;
}
这里发现,添加device到内核最终还是调用的device_add函数。Platform_device_add和device_add最主要的区别是多了一步insert_resource(p, r)即将platform资源(resource)添加进内核,由内核统一管理。
platform_driver_register()注册过程
--------------------------------------
static struct platform_driver s3c2410_i2c_driver = {
.probe = s3c24xx_i2c_probe,
.remove = s3c24xx_i2c_remove,
.resume = s3c24xx_i2c_resume,
.driver = {
.owner = THIS_MODULE,
.name = "s3c2410-i2c",
},
};
platform_driver_register(&s3c2410fb_driver)----->
driver_register(&drv->driver)----->
bus_add_driver(drv)----->
driver_attach(drv)----->
bus_for_each_dev(drv->bus, NULL, drv, __driver_attach)----->
__driver_attach(struct device * dev, void * data)----->
driver_probe_device(drv, dev)----->
really_probe(dev, drv)----->
在really_probe()中:为设备指派管理该设备的驱动:dev->driver = drv, 调用probe()函数初始化设备:drv->probe(dev)
分享到:
相关推荐
原创的友善之臂的mini6410 linux-2.6.38内核的uart1 串口驱动,使用platform_device方式,压缩包里面有驱动源代码、编译好了的ko文件、使用说明文档、用户例程的源代码和可执行程序,但是并没有给出直接编译驱动和...
通常编写linux 字符设备常接触到的file_operations 以及miscdevice,然后申请...platform_device 和platform_driver 做了些摘录批注。 platform_device 与platform_driver 一直分不清关系。在网上搜了下,做个总结。
Linux Platform Device and DriverLinux Platform Device and DriverLinux Platform Device and DriverLinux Platform Device and DriverLinux Platform Device and DriverLinux Platform Device and DriverLinux ...
I2c的总线方式 platform_device和platform_driver的形式,在platform_device里向内核注册设备资源,在platform_driver里通过name与platform_device进行匹配,如果match,则能够使用该资源,并进行初始化。
bus_for_each_dev(drv->bus, NULL, drv, __driver_attach)函数会遍历总线上所有的设备,并调用__driver_attach函数,判断驱动是否和设备匹配,若匹配则将struct device中的 struct device_driver *driver指向此驱动...
从Linux 2.6起引入了一套新的驱动管理和注册机制:platform_device和platform_driver。Linux中大部分的设备驱动,都可以使用这套机制,设备用platform_device表示,驱动用platform_driver进行注册。 Linux ...
讲解了 关于驱动中platform device 和 platform driver 是怎么通过bus总线进行挂接关连的
Platform driver&device.pptx
从Linux 2.6起引入了一套新的驱动管理和注册机制:Platform_device和Platform_driver。Linux中 大部分的设备驱动,都可以使用这套机制, 设备用Platform_device表示,驱动用Platform_driver 进行注册。
platform linux 嵌入式 ARM, S2C2440, driver
根据源码分析整理的linux platfom driver与device driver的关系,对初学者有较大的帮助
lrwxrwxrwx root root 1970-01-02 10:18 driver -> ../../../../../bus/i2c/drivers/pcf8563 -r--r--r-- root root 4096 1970-01-02 10:18 modalias -r--r--r-- root root 4096 1970-01-02 10:18 name drwxr-xr-x ...
嵌入式Linux系统I2C驱动的研究与应用,邱宏宇,余瑾,从Linux2.6内核起引入了一套全新的驱动管理和注册机制Platform_device和Platform_driver,本文将深入分析I2C总线在Linux中实现的体系结构,阐述I2
首先介绍了Platform总线的基本概念,接着介绍了platform device和platform driver的定义和加载过程,分析了其与基类device 和driver的派生关系及在此过程中面向对象的设计思想。最后以ARM S3C2440中I2C控制器为例...
Generic platform device PATA driver.
设备驱动001_hello_world 2021-01-25完成002_pseudo_char_driver 2021-01-27已完成003_pseudo_char_driver_multiple 2021-01-30已完成004_pcd_platform_driver平台设备,平台驱动程序,设备驱动程序,设备2021-02-08...
Oracle Solaris 8 Platform Notes: The SunHSI/S Device Driver-46
Oracle Solaris 8 Platform Notes: The SunHSI/PTM Device Driver-22
#endif //#ifdef CONFIG_LS1C_PWM_DRIVER上一个文件中,函数 static struct platform_device *l
Oracle Solaris 9 - Platform Notes: The SunHSI/P Device Driver-22