Linux设备驱动之platform总线.doc
文本预览下载声明
LINUX设备驱动之platform总线
--------------------------------------------------------------
分析linux内核源码,版本号为2.6.32.3
-------------------------------------------------------------
阅读本文之前,如果你对设备驱动模型还不了解,请先阅读本站设备驱动模型相关文章。
Platform总线是kernel中的一种虚拟总线,2.6版本很多驱动都用它来实现。
一.Platform初始化
系统启动时初始化时创建了platform_bus设备和platform_bus_type总线:
内核初始化函数
/*
* Ok, the machine is now initialized. None of the devices
* have been touched yet, but the CPU subsystem is up and
* running, and memory and process management works.
*
* Now we can finally start doing some real work..
*/
static void __init do_basic_setup(void)
{
cpuset_init_smp();
usermodehelper_init();
init_tmpfs();
driver_init(); //go in.
init_irq_proc();
do_ctors();
do_initcalls();
}
/**
* driver_init - initialize driver model.
*
* Call the driver model init functions to initialize their
* subsystems. Called early from init/main.c.
*/
void __init driver_init(void)
{
/* These are the core pieces */
devtmpfs_init();
devices_init();
buses_init();
classes_init();
firmware_init();
hypervisor_init();
/* These are also core pieces, but must come after the
* core core pieces.
*/
platform_bus_init(); //hackson,goin.
system_bus_init();
cpu_dev_init();
memory_dev_init();
}
我们看看platform_bus_init()函数:
int __init platform_bus_init(void)
{
int error;
early_platform_cleanup();
error = device_register(platform_bus);
if (error)
return error;
error = bus_register(platform_bus_type);
if (error)
device_unregister(platform_bus);
return error;
}
device_register(platform_bus)中的platform_bus如下:
struct device platform_bus = {
.init_name = platform,
};
改函数把设备名为platform 的设备platform_bus注册到系统中,其他的platform的设备都会以它为parent。它在sysfs中目录下.即 /sys/devices/platform。
接着bus_register(platform_bus_type)注册了platform_bus_type总线,看一下改总线的定义:
struct bus_type platform_bus_type = {
.name = platform,
.dev_attrs = platform_dev_attr
显示全部