将led驱动整合成misc设备添加到platform 平台下
================================================================================================
.c文件:
……(省略部分,和(三)中代码一样)
static struct file_operations light_fops = {
.owner = THIS_MODULE,
.ioctl = light_ioctl,
.open = light_open,
.release = light_release,
};
static struct miscdevice light_misdev =
{
.minor = 53,
.name = "hyy_led",
.fops = &light_fops,
};
static int __devinit light_probe (struct platform_device * pdev)
{
int ret = 0;
int i, GpioId ;
pdeg(" my_led debug message: ");
ret = misc_register(&light_misdev);
if (ret < 0 ) {
printk("misc register fail! ret = %d\n",ret);
return ret;
}
for (i = 0 ; i <5 ; i++ ) {
GpioId = mfp_to_gpio(led_table[i]);
gpio_direction_output(GpioId,LED_OFF);
}
return 0;
}
static int __devexit light_remove (struct platform_device * pdev)
{
pdeg(" my_led debug message: ");
misc_deregister(&light_misdev);
// free the kthread
if (led_th ) {
kthread_stop(led_th);
led_th = NULL;
}
}
static struct platform_driver light_driver = {
.driver = {
.name = "hyy_led",
.owner = THIS_MODULE,
},
.probe = light_probe,
.remove = light_remove,
};
static int __init light_init(void)
{
pdeg(" my_led debug message: ");
return platform_driver_register(&light_driver);
}
static void __exit light_exit (void)
{
platform_driver_unregister(&light_driver);
pdeg(" my_led debug message: ");
}
module_init(light_init);
module_exit(light_exit);
MODULE_AUTHOR("hyy");
MODULE_LICENSE("GPL");
阅读(1192) | 评论(0) | 转发(0) |