linux 设备模型(二 driver)
来源:互联网 发布:美微网络柠檬视频tv 编辑:程序博客网 时间:2024/05/20 05:30
#include <linux/device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/string.h>
MODULE_AUTHOR("David Xie");
MODULE_LICENSE("Dual BSD/GPL");
extern struct bus_type my_bus_type;
static int my_probe(struct device *dev)
{
printk("Driver found device which my driver can handle!\n");
return 0;
}
static int my_remove(struct device *dev)
{
printk("Driver found device unpluged!\n");
return 0;
}
struct device_driver my_driver = {
.name = "my_dev",
.bus = &my_bus_type,
.probe = my_probe,
.remove = my_remove,
};
/*
* Export a simple attribute.
*/
static ssize_t mydriver_show(struct device_driver *driver, char *buf)
{
return sprintf(buf, "%s\n", "This is my driver!");
}
static DRIVER_ATTR(drv, S_IRUGO, mydriver_show, NULL);
static int __init my_driver_init(void)
{
int ret = 0;
/*注册驱动*/
driver_register(&my_driver);
/*创建属性文件*/
driver_create_file(&my_driver, &driver_attr_drv);
return ret;
}
static void my_driver_exit(void)
{
driver_unregister(&my_driver);
}
module_init(my_driver_init);
module_exit(my_driver_exit);
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/string.h>
MODULE_AUTHOR("David Xie");
MODULE_LICENSE("Dual BSD/GPL");
extern struct bus_type my_bus_type;
static int my_probe(struct device *dev)
{
printk("Driver found device which my driver can handle!\n");
return 0;
}
static int my_remove(struct device *dev)
{
printk("Driver found device unpluged!\n");
return 0;
}
struct device_driver my_driver = {
.name = "my_dev",
.bus = &my_bus_type,
.probe = my_probe,
.remove = my_remove,
};
/*
* Export a simple attribute.
*/
static ssize_t mydriver_show(struct device_driver *driver, char *buf)
{
return sprintf(buf, "%s\n", "This is my driver!");
}
static DRIVER_ATTR(drv, S_IRUGO, mydriver_show, NULL);
static int __init my_driver_init(void)
{
int ret = 0;
/*注册驱动*/
driver_register(&my_driver);
/*创建属性文件*/
driver_create_file(&my_driver, &driver_attr_drv);
return ret;
}
static void my_driver_exit(void)
{
driver_unregister(&my_driver);
}
module_init(my_driver_init);
module_exit(my_driver_exit);
0 0
- linux 设备模型(二 driver)
- LINUX设备驱动之设备模型四--device&driver&bus(二)
- LINUX设备驱动之设备模型四--device&driver&bus(二)
- LINUX设备驱动之设备模型四--device&driver&bus(二)
- linux设备模型之bus,device,driver分析二
- linux设备模型之bus,device,driver分析二
- linux ------ 设备驱动模型之二(bus, device, driver)
- linux设备模型之bus,device,driver分析二
- Linux设备驱动模型-Driver
- linux设备模型bus,device,driver(超级推荐)
- linux设备模型bus,device,driver
- linux设备模型bus,device,driver
- LINUX设备模型BUS,DEVICE,DRIVER
- LINUX设备模型BUS,DEVICE,DRIVER
- linux设备模型bus,device,driver
- linux设备驱动模型七之driver
- linux设备模型bus,device,driver
- LINUX设备模型BUS,DEVICE,DRIVER
- HDU 5385
- 应用程序的makefile编写例程
- 2015.08.13
- foj Problem 1894 志愿者选拔---单调队列
- 读书笔记_高质量程序设计指南C++/C语言_10_文件结构和版式
- linux 设备模型(二 driver)
- 黑马程序员———API之Object、String和Scanner
- 倒立三角形
- noip1997 棋盘 (数列求和)
- SDL事件查询函数:SDL_PeepEvents()
- 清汤的重要启示
- 《STL源码剖析》--next_permutation函数
- JAVA开篇——思路与工具
- 进程的三种基本状态及其转换