📄 sbc2410_leds.c
字号:
#include <linux/kernel.h>#include <linux/module.h>#include <linux/fs.h>#include <linux/errno.h> #include <linux/ioport.h> #include <linux/init.h> #include <asm/uaccess.h> #include <asm/io.h> #include <asm-arm/arch-s3c2410/S3C2410.h>#include "drv.h"#define BUF_LEN 4#define DEVICE_NAME "cyc_io"static int Device_Open = 0;volatile unsigned long *led_addr; volatile unsigned long *led_con;volatile unsigned long *led_up;int device_ioctl(struct inode *,struct file *,unsigned int ,unsigned long ); static int device_open(struct inode *inode, struct file *file){ led_addr = ioremap(0x56000014,4); led_con = ioremap(0x56000010,4); led_up = ioremap(0x56000018,4); *led_con = 0X15400; *led_up = 0; printk("the address of led_addr is: 0x%p\n",led_addr); printk("Device Open!\n"); if (Device_Open) return -EBUSY; Device_Open++; return 0;}static int device_release(struct inode *inode, struct file *file){ printk(("Device released\n")); Device_Open --; iounmap( (void *)led_addr); return 0;}int device_ioctl(struct inode *inode, struct file *file, unsigned int ioctl_num, unsigned long ioctl_param) { int *data; printk(("Device_\n")); switch(ioctl_num) { case IOCTL_SET_MSG: data = (int *)ioctl_param; printk("Device ioctl SET_MSG %d\n",*data ); *led_addr =~ ((*data)<<7);//输出到led灯 break; case IOCTL_GET_MSG: printk(("Device_ioctl PUT_MSG\n")); break; } return 0;};struct file_operations Fops = { .open = device_open, .release = device_release, .ioctl = device_ioctl };static int __init led_module_init( void ){ int ret_val; ret_val = register_chrdev(MAJOR_NUM, DEVICE_NAME, &Fops); if (ret_val < 0) { printk ("%s failed with %d\n", "Sorry, registering the character device ", ret_val); return ret_val; } printk ("%s The major device number is %d.\n", "Registeration is a success", MAJOR_NUM); printk ("If you want to talk to the device driver,\n"); printk ("you'll have to create a device file. \n"); printk ("We suggest you use:\n"); printk ("mknod /dev/%s c %d 0\n", DEVICE_FILE_NAME,MAJOR_NUM); printk ("The device file name is important, because\n"); printk ("the ioctl program assumes that's the\n"); printk ("file you'll use.\n"); return 0;};static void __exit led_module_cleanup(void){ int ret; ret = unregister_chrdev(MAJOR_NUM, DEVICE_NAME); if (ret < 0) printk("Error in module_unregister_chrdev: %d\n", ret); else printk("Close the char device OK!\n");};module_init(led_module_init); module_exit(led_module_cleanup);MODULE_LICENSE("GPL");MODULE_AUTHOR("Cvtech Co., Ltd <http://www.cvtech.com.cn>");MODULE_DESCRIPTION("LED char driver");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -