#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");


extern struct bus_type my_bus;

int my_drv_probe(struct device *dev)
{
    printk("%s\n", dev_name(dev));
    printk("%s-%s\n", __FILE__, __func__);
    return 0;
}

int my_drv_remove(struct device *dev)
{
    printk("%s\n", dev->init_name);
    printk("%s-%s\n", __FILE__, __func__);
    return 0;
}

static struct device_driver my_drv = {
    .name = "my_dev",
    .bus = &my_bus,
    .probe = my_drv_probe,
    .remove = my_drv_remove,
};


char *name = "my_drv";
ssize_t drvname_show(struct device_driver *drv, char *buf)
{
    return sprintf(buf, "%s\n", name);
}

DRIVER_ATTR_RO(drvname);

static __init int my_drv_init(void)
{
    printk("my_drv init\n");
    driver_register(&my_drv);
    driver_create_file(&my_drv, &driver_attr_drvname);
    return 0;
}
module_init(my_drv_init);

static __exit void my_drv_exit(void)
{
    printk("my_drv exit\n");
    driver_remove_file(&my_drv, &driver_attr_drvname);
    driver_unregister(&my_drv);
}
module_exit(my_drv_exit);



