1 Star 2 Fork 2

e665107/Linux-Device-Drivers-Development

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Platform device and driver

This code consists of converting the driver in chapter 4 into a platform driver. After running make command, there will be two modules:

  • platform-dummy-char.ko
  • platform-dummy-ins.ko

The fist module is our platform driver. The second one is a basic module whose aim is to create a platform device that will match the platform-dummy-char driver.

Prior to testing our driver, one should load the following modules:

# insmod platform-dummy-char.ko
# insmod platform-dummy-ins.ko

Once the modules loaded, one can see below message in debug output:

$ dmesg
[...]
[33117.715597] dummy_char major number = 241
[33117.715662] dummy char module loaded
[33117.715670] platform-dummy-char device added

One can print additional information by listing the sysfs content of the device:

$ ls -l /sys/devices/platform/platform-dummy-char.0/
total 0
lrwxrwxrwx 1 root root    0 oct.  12 16:40 driver -> ../../../bus/platform/drivers/platform-dummy-char
-rw-r--r-- 1 root root 4096 oct.  12 16:42 driver_override
-r--r--r-- 1 root root 4096 oct.  12 16:42 modalias
drwxr-xr-x 2 root root    0 oct.  12 16:42 power
lrwxrwxrwx 1 root root    0 oct.  12 16:42 subsystem -> ../../../bus/platform
-rw-r--r-- 1 root root 4096 oct.  12 16:40 uevent

Or by using udevadm tool:

$ udevadm info /dev/dummy_char 
P: /devices/platform/platform-dummy-char.0/dummy_char_class/dummy_char
N: dummy_char
E: DEVNAME=/dev/dummy_char
E: DEVPATH=/devices/platform/platform-dummy-char.0/dummy_char_class/dummy_char
E: MAJOR=241
E: MINOR=0
E: SUBSYSTEM=dummy_char_class

Of course, the behaviour remains the same as the char device tested on chapter :

# cat /dev/dummy_char 
# echo "blabla" > /dev/dummy_char 
# rmmod dummy-char.ko 

$ dmesg
[...]
[ 6753.573560] dummy_char major number = 241
[ 6753.573611] dummy char module loaded
[ 6753.573622] platform-dummy-char device added
[ 7081.034607] Someone tried to open me
[ 7081.034641] Can't accept any data guy
[ 7081.034649] Someone closed me
[ 7084.861861] Someone tried to open me
[ 7084.861887] Nothing to read guy
[ 7084.861906] Someone closed me
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/e665107/Linux-Device-Drivers-Development.git
git@gitee.com:e665107/Linux-Device-Drivers-Development.git
e665107
Linux-Device-Drivers-Development
Linux-Device-Drivers-Development
master

搜索帮助