总线_设备_驱动注册流程
总线
查看总线
ls /sys/bus/
查找设备号
cat proc/devices
// 杂项设备
cat /proc/misc
platform 是虚拟总线,挂载着Driver,Device
设备Device
设备是挂载在虚拟总线Platform上的
//platform
//位于include/linux/platform_device.h
struct platform_device
{
int id;
const char * name;
...
}
// driver
struct platform_driver
{
probe();
...
}
驱动注册流程
- 挂载设备
- 通过platform_match 做对比,成功调用probe并做初始化工作,调用gpio 申请
- 打开平台文件arch/arm/mach-xx/match-xx.c
#ifdef CONFIG_HELLO_CTL
struct platform_device s3c_devices_hello_ctl = {
.name = "hello_ctl",
.id = -1,
};
#endif
------------------------------------------------
#ifdef CONFIG_HELLO_CTL
&s3c_devices_hello_ctl,
#endif
- 将设备结构体放到平台文件中,会自动注册设备,不用调用设备的注册函数
- 在Kconfig中添加编译HELLO设备的宏定义
- 配置.config 并编译生成新zImage
- 注册成功后可以在虚拟平台总线上查到注册的设备
ls /sys/devices/platform