66 lines
1.2 KiB
C
66 lines
1.2 KiB
C
|
#include <linux/module.h>
|
||
|
#include <linux/init.h>
|
||
|
#include <linux/kernel.h>
|
||
|
#include <linux/sched.h>
|
||
|
#include <linux/cdev.h>
|
||
|
#include <linux/fs.h>
|
||
|
#include <linux/wait.h>
|
||
|
#include <linux/errno.h>
|
||
|
#include <linux/slab.h>
|
||
|
#include <linux/uaccess.h>
|
||
|
#include <linux/device.h>
|
||
|
|
||
|
#include "pub.h"
|
||
|
|
||
|
MODULE_LICENSE("GPL");
|
||
|
MODULE_AUTHOR("liuchao");
|
||
|
|
||
|
|
||
|
static int my_bus_match(struct device *dev, struct device_driver *drv){
|
||
|
PDEBUG("%s-%s\n",__FILE__, __func__);
|
||
|
if(!strncmp(dev_name(dev), drv->name, strlen(drv->name)))
|
||
|
{
|
||
|
PDEBUG("dev & drv match\n");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static struct bus_type my_bus = {
|
||
|
.name = "my_bus",
|
||
|
.match = my_bus_match,
|
||
|
};
|
||
|
|
||
|
EXPORT_SYMBOL(my_bus);
|
||
|
|
||
|
static char *version = "$Revision: 1.9 $";
|
||
|
|
||
|
static ssize_t my_bus_test_show(struct bus_type *bus, char *buf)
|
||
|
{
|
||
|
return sprintf(buf, "%s\n", version);
|
||
|
}
|
||
|
|
||
|
static BUS_ATTR(Version, S_IRUSR, my_bus_test_show, NULL);
|
||
|
|
||
|
|
||
|
static __init int my_bus_init(void)
|
||
|
{
|
||
|
printk("my_bus init\n");
|
||
|
|
||
|
bus_register(&my_bus);
|
||
|
bus_create_file(&my_bus, &bus_attr_Version);
|
||
|
return 0;
|
||
|
}
|
||
|
module_init(my_bus_init);
|
||
|
|
||
|
|
||
|
static __exit void my_bus_exit(void)
|
||
|
{
|
||
|
printk("my_bus exit\n");
|
||
|
bus_remove_file(&my_bus, &bus_attr_Version);
|
||
|
bus_unregister(&my_bus);
|
||
|
}
|
||
|
module_exit(my_bus_exit);
|
||
|
|
||
|
|
||
|
|
||
|
|