#include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/init.h> #include <linux/delay.h> #include <asm/uaccess.h> #include <asm/irq.h> #include <asm/io.h> #include <asm/arch/regs-gpio.h> #include <asm/hardware.h> MODULE_LICENSE("GPL"); static struct class *led_class; static struct class_device *led_class_device; volatile unsigned long *gpfcon = NULL; volatile unsigned long *gpfdat = NULL; static int led_drv_open(struct inode *inode, struct file *file) { *gpfcon &= ~((4 << 4*2) | (3 << 5*2) | (3 << 6*2)); *gpfcon |= ((1 << 4*2) | (1 << 5*2) | (1 << 6*2)); return 0; } static ssize_t led_drv_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { int val copy_from_user(&val, buf, count); if (val) { *gpfdat |= ((1 << 4*2) | (1 << 5*2) | (1 << 6*2)); } else { *gpfdat &= ~((1 << 4*2) | (1 << 5*2) | (1 << 6*2)); } return 0; } static struct file_operations led_fops = { .owner = THIS_MODULE, .open = led_drv_open, .write = led_drv_write, }; int major; static int led_drv_init(void) { major = register_chrdev(0, "led", &led_fops); led_class = class_create(THIS_MODULE, "led"); led_class_device = class_device_create(led_class, NULL, MKDEV(major, 0), NULL, "abc"); /* 在应用层open("/dev/abc", O_RDWR) */ gpfcon = (volatile unsigned long *)ioremap(0x56000000, 16); gpfdat = gpfcon + 1; return 0; } static int led_drv_exit(void) { unregister_chrdev(major, "led"); class_device_unregister(led_class_device); class_destroy(led_class); iounmap(gpfcon); return 0; } module_init(led_drv_init); module_exit(led_drv_exit);
简易linux驱动_自动创建设备节点
精选 转载gongyuan073 博主文章分类:s3c2440
下一篇:我的友情链接
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Linux下PCI设备驱动开发详解(四)
一般来说,用模块方式编写PCI设备驱动,通常至少要实现以下几个部分:初始化设备模块、设备打开模块、数据读写模块、中断处理模块、设备释放模块、设备卸载模块。
驱动程序 PCI FPGA linux内核 probe -
字符设备驱动之类与节点的创建
目录简介创建设备节点函数设置节点名函数device_create调用过
调用 设备节点 linux 不同版本 -
《Linux设备节点创建》用户空间ueventd创建设备节点规则android #define linux 链表 数组