设为首页 加入收藏

TOP

Linux系统ioctl使用示例 ioctl实验(二)
2014-11-24 07:34:55 来源: 作者: 【 】 浏览:1
Tags:Linux 系统 ioctl 使用 示例 实验
default:
pr_err("Invalid ioctl command.\n");
return -ENOTTY;
}

return err;
}

static const struct file_operations gpio_test_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = gpio_test_ioctl,
.open = gpio_test_open,
.release = gpio_test_release
};

static struct miscdevice gpio_test_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "gpio_test",
.fops = &gpio_test_fops
};


static int gpio_test_probe(struct platform_device *pdev)
{
int ret = 0;

printk("gpio_test_probe 0\n");

/* Initialize */
gpio_priv = kzalloc(sizeof(struct gpio_priv_t), GFP_KERNEL);

if (gpio_priv == NULL) {
pr_alert("Not enough memory to initialize device\n");
return -ENOMEM;
}

ret = misc_register(&gpio_test_dev);

if (ret < 0)
goto err;
return 0;

err:
printk("gpio_test register failed\n");


kfree(gpio_priv);
gpio_priv = NULL;

return ret;

}

static int __devexit gpio_test_remove(struct platform_device *plat)
{

kfree(gpio_priv);
gpio_priv = NULL;

misc_deregister(&gpio_test_dev);
printk("gpio_test remove\n");
return 0;
}

static struct platform_driver gpio_test_driver = {
.probe = gpio_test_probe,
.remove = gpio_test_remove,
.driver = {
.name = "gpio_test",
.owner = THIS_MODULE,
},
};

static int __init gpio_test_init(void)

{
printk("gpio_test_init \n");
return platform_driver_register(&gpio_test_driver);
}

static void __exit gpio_test_exit(void)
{
platform_driver_unregister(&gpio_test_driver);
}



module_init(gpio_test_init);
module_exit(gpio_test_exit);


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux 运用debugfs调试方法 下一篇Linux debugfs使用分享 软件查看g..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis 分布式锁全解 (2025-12-25 17:19:51)
·SpringBoot 整合 Red (2025-12-25 17:19:48)
·MongoDB 索引 - 菜鸟 (2025-12-25 17:19:45)
·What Is Linux (2025-12-25 16:57:17)
·Linux小白必备:超全 (2025-12-25 16:57:14)