Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1212259
  • 博文数量: 261
  • 博客积分: 4196
  • 博客等级: 上校
  • 技术积分: 3410
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-17 17:05
文章分类

全部博文(261)

文章存档

2018年(1)

2017年(22)

2016年(2)

2015年(8)

2014年(27)

2013年(40)

2012年(161)

分类: LINUX

2013-03-13 16:26:05

将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");
阅读(1074) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~