How Linux creates device files under /dev
来源:互联网 发布:淘宝店铺流量分为 编辑:程序博客网 时间:2024/05/29 02:29
This post is used to describe how Linux creates device files under /dev, illustrated with devices attached to TCC8935's DISPLAY bus.
First of all, the "create device file" procedures are device-type specific:
1. Char device. Example: VIQE //drivers/video/tcc/viqe/tcc_vioc_viqe.c
When the driver (module) is loaded in:
static int __init tcc_viqe_init(void)
{
int res;
res = register_chrdev(VIQE_DEV_MAJOR, VIQE_DEV_NAME, &tcc_viqe_fops);
if (res < 0)
return res;
viqe_class = class_create(THIS_MODULE, VIQE_DEV_NAME);
device_create(viqe_class, NULL, MKDEV(VIQE_DEV_MAJOR, VIQE_DEV_MINOR), NULL, VIQE_DEV_NAME);
printk(KERN_INFO "%s\n", __FUNCTION__);
return 0;
}
The routine device_create() creates a node under /dev according to MAJOR / MINOR / NAME parameters, /dev/viqe.
BTW, routine class_create() creates a class "viqe" under /sys/class.
Similar examples include WMIXER / SCALER. //drivers/char/tcc_wmixer.c, tcc_scaler.c
2. Platform device.
According to other blogs, Linux creates device node for platform devices when the DEVICE is registered, rather than the driver is registered.
For example:
platform_device_register(&tcc_lcd_device); (the struct tcc_lcd_device's NAME is "tccfb", which is identical with it's driver's name.
CALLS platform_device_add(dev) -> CALLS device_add()
routine device_add() calls device_create_file() to create files under /sys
and
calls devtmpfs_create_node() to create device node under /dev.
NOTE: see blow blogs for details: http://jieohsong.blog.163.com/blog/static/110530884201343054853424/ and
I'm not sure if it's correct but i do cannot find a "tccfb" node under /dev.
Well, my understanding is totally different. The driver creates device node within PROBE phase, and, the approach isdevice specific.
Example 1: tccfb //drivers/video/tcc/tcc_vioc_fb.c
This is a PLATFORM device since the driver is registered via platform_driver_register().
In routine probe(), calls register_framebuffer() -> do_register_framebuffer() , in do_register_framebuffer(),
fb_info->dev = device_create(fb_class, fb_info->device,
MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
The fb_class is "graphics", FB_MAJOR is 29.
Here, we see device_create() again, exact the same as a char device above. And, there is a node under /dev/graphics, fb0, major number is 29.
Example 2: overlay //drivers/video/tcc/tcc_overlay.c
This is a PLATFORM device.
static struct platform_device tcc_overlay_device = {
.name = "tcc_overlay",
.dev = {
.release = NULL,
},
.id = 0,
};
But also a MISC device.
static struct miscdevice overlay_misc_device =
{
DEV_MINOR,
DEVICE_NAME,
&tcc_overlay_fops,
};
At the end of probe(), within misc_register(&overlay_misc_device), calls
misc->this_device = device_create(misc_class, misc->parent, dev,
misc, "%s", misc->name);
Familiar? That it! It creates /dev/overlay.
- How Linux creates device files under /dev
- How do I open rar archive files under Linux / UNIX operating systems?
- How to root an Android device under Ubuntu
- How to use "chmod" under linux
- How to run scripts under Linux
- how to debug MudOS under linux
- how to get device node name such as /dev/ttyS1.
- linux /dev/fb no such device 解决方法
- A Simple Introduction to Device Drivers under Linux
- How the CLR Creates Runtime Objects
- How to mount remote windows partition (windows share) under Linux
- How to write a simplest wireshark dissector(under Linux)
- How to mount remote windows partition (windows share) under Linux
- How to use JP108 usb lan adapter under SmartQ7 linux.
- How to mount remote windows partition (windows share) under Linux
- How to change Mysql root password under linux ?
- HOW TO SETUP BUMBLEBEE STEREO CAMERA UNDER LINUX
- How To Check and Use Serial Ports Under Linux
- Unity3D 发送消息小技巧
- android 自定义View之 Paint类的介绍
- 护眼郎与您分享各国如何千方百计帮孩子远离近视
- 多继承带来的问题
- java实现动态切换上网IP (ADSL拨号上网)
- How Linux creates device files under /dev
- Android安装SDK无法fetch
- A_完全背包
- c++ 中__declspec 的用法
- fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h
- Java中的ASCII、Unicode和UTF-8字符编码集
- 【精心推荐】20款优秀 jQuery Accordion(手风琴)特效插件
- Cocos2d-JS 游戏引擎新进化:性能狂飙提升50%
- 使用过滤器+反射+枚举,简单模拟sturts2运行方式,编写一个属于自己的框架