📄 led.c
字号:
/* * led EBI interface for Linux on Atmel AT91RM9200 * Copyright (c) 2006 Ligang Wang * wangzitan@163.com *//* include some file */ #include <linux/module.h>#include <linux/sched.h>#include <linux/slab.h>#include <linux/ioport.h>#include <linux/errno.h>#include <linux/kernel.h>#include <linux/fs.h>#include <linux/string.h>#include <linux/poll.h>#include <linux/init.h>#include <asm/io.h>#include <asm/system.h>#include <asm/arch/hardware.h>#include <asm/segment.h>//#include "led.h"/* define some macro for this module*/#define DEV_MEM_SIZE 8 //define memory size for device#define DEV_MAJOR 250 //major of led#define LED_PHY_ADDR 0x80000000static AT91PS_SYS AT91_SYS1 = (AT91PS_SYS) AT91C_VA_BASE_SYS;static void * led_vit_addr;/* * Read funcation for vfs */ssize_t at91_led_read(struct file * file, char *buf, size_t count, loff_t * ppos){ return 0;}/* * Write funcation for vfs */ssize_t at91_led_write(struct file * file, const char * buf, size_t count, loff_t * ppos){ char tmp_data[2]; char * port; int retval = 0; retval = copy_from_user((char *)tmp_data,buf,sizeof(unsigned char)*2); if (retval) return retval; if(tmp_data[0] == 0) port = (char *)led_vit_addr; else port = (char *)(led_vit_addr+1); *port = tmp_data[1]; return 0;} /* open a device */static int at91_led_open(struct inode* inode,struct file* file){ MOD_INC_USE_COUNT;
return 0; }/* * Handle commands from user-space. */static int at91_led_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ return 0; }/* * setup led hardware */ static void at91_led_setup(void){ //Setup bus access time width. AT91_SYS1->EBI_SMC2_CSR[7] = (AT91C_SMC2_NWS & 0x8) | AT91C_SMC2_WSEN
| (AT91C_SMC2_TDF & 0x300) | AT91C_SMC2_BAT | AT91C_SMC2_DBW_8;
}static int at91_led_release(struct inode* inode,struct file* file){ MOD_DEC_USE_COUNT; return 0;}struct file_operations at91_led_fops = { owner: THIS_MODULE,
write: at91_led_write,
read: at91_led_read, open: at91_led_open, ioctl: at91_led_ioctl, release: at91_led_release,};/* * Initialize and install led driver */static int __init at91_led_init(void){ at91_led_setup(); led_vit_addr = (unsigned long)(ioremap(LED_PHY_ADDR, DEV_MEM_SIZE)); if (check_region(led_vit_addr, DEV_MEM_SIZE)<0) return -1; request_region(led_vit_addr, DEV_MEM_SIZE,"led"); if(register_chrdev(DEV_MAJOR,"led",&at91_led_fops))
{ printk("LED: Can not register led driver \n");
return -1;
} printk("led: the led is working now\n"); return 0;}/* * Disable and remove the led driver */static void __exit at91_led_exit(void){ printk("led: at91_led_exit has been called\n"); unregister_chrdev(DEV_MAJOR,"led"); iounmap(led_vit_addr); return;}module_init(at91_led_init);module_exit(at91_led_exit);MODULE_AUTHOR("Ligang Wang");MODULE_DESCRIPTION("AT91 rm9200 led driver");MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -