📄 magic-leds.c
字号:
/*****************************************Copyright (c)**************************************************** Guangzhou Zhiyuan Electronic Co.,LTD.** graduate school** http://www.zyinside.com****------------------------------------- File Info ------------------------------------------------------** File name: magic-leds.c** Last modified Date: 2005-12-28** Last Version: 1.0** Descriptions: Driver for LEDs and BEEP on MagicARM2410.** Based on Linux 2.4.18. **------------------------------------------------------------------------------------------------------** Created by: Chenxibing** Created date: 2005-12-27** Version: 1.0** Descriptions: Preliminary version.****------------------------------------------------------------------------------------------------------** Modified by:** Modified date:** Version:** Descriptions:***********************************************************************************************************/#ifndef __KERNEL__ #define __KERNEL__#endif#ifndef MODULE #define MODULE#endif#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/sched.h>//#include <linux/poll.h>//#include <linux/spinlock.h>//#include <linux/irq.h>//#include <linux/miscdevice.h>//#include <linux/delay.h>#include <asm/hardware.h>#define DEVICE_NAME "magic-leds"//#define LED_MAJOR 231 //can be 231~239 or 240~254MODULE_LICENSE("Proprietary");MODULE_DESCRIPTION("Guangzhou Zhiyuan Electronic Co.,LTD.\ngraduate school\nhttp://www.zyinside.com");MODULE_SUPPORTED_DEVICE("Linux 2.4.18 & MagicARM2410");MODULE_AUTHOR("Chenxibing");/********************************************************************************************************** LEDs' informations.********************************************************************************************************/static unsigned long leds_table [] = { GPIO_E11, GPIO_E12, GPIO_H4, GPIO_H6, GPIO_H10,};/********************************************************************************************************** Function name: magic_leds_ioctl()** Descriptions : IO control function** Input:** inode : information of device** filp : pointer of file** cmd : command** arg : additive parameter** Output:** 0 : OK** other : not OK** Created by : Chenxibing** Created Date : 2005-12-27**-----------------------------------------------------------------------------------------------------** Modified by :** Modified Date: **-----------------------------------------------------------------------------------------------------********************************************************************************************************/static int magic_leds_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg){ if (arg > 4) return -EINVAL; switch(cmd) { case 0: case 1: write_gpio_bit(leds_table[arg], cmd); default: return -EINVAL; }}/********************************************************************************************************** Function name: magic_leds_open()** Descriptions : open leds** Input:** inode : information of device** filp : pointer of file** Output:** 0 : OK** other : not OK** Created by : Chenxibing** Created Date : 2005-12-27**-----------------------------------------------------------------------------------------------------** Modified by :** Modified Date: **-----------------------------------------------------------------------------------------------------********************************************************************************************************/static int magic_leds_open(struct inode *inode, struct file *filp){ int i; for (i = 0; i < 5; i++) { set_gpio_ctrl (leds_table[i] | GPIO_PULLUP_EN | GPIO_MODE_OUT); write_gpio_bit(leds_table[i], 1); } MOD_INC_USE_COUNT; printk(KERN_INFO DEVICE_NAME ": opened.\n"); return 0;}/********************************************************************************************************** Function name: magic_leds_release()** Descriptions : release leds** Input:** inode : information of device** filp : pointer of file** Output:** 0 : OK** other : not OK** Created by : Chenxibing** Created Date : 2005-12-27**-----------------------------------------------------------------------------------------------------** Modified by :** Modified Date: **-----------------------------------------------------------------------------------------------------********************************************************************************************************/static int magic_leds_release(struct inode *inode, struct file *filp){ MOD_DEC_USE_COUNT; printk(KERN_INFO DEVICE_NAME ": released.\n"); return 0;}/********************************************************************************************************** operations of the driver********************************************************************************************************/static struct file_operations magic_leds_fops = { owner: THIS_MODULE, ioctl: magic_leds_ioctl, open: magic_leds_open, release: magic_leds_release,};/********************************************************************************************************** Function name: magic_leds_init()** Descriptions : register driver** Input:** : NONE** Output:** 0 : OK** other : not OK** Created by : Chenxibing** Created Date : 2005-12-27**-----------------------------------------------------------------------------------------------------** Modified by :** Modified Date: **-----------------------------------------------------------------------------------------------------********************************************************************************************************/static devfs_handle_t devfs_handle;static int __init magic_leds_init(void){// int result;// result = register_chrdev(0, DEVICE_NAME, &magic_leds_fops);// if (result < 0) // {// printk(KERN_ERR DEVICE_NAME ": Failed to register major.\n");// return result;// } devfs_handle = devfs_register(NULL, DEVICE_NAME, DEVFS_FL_AUTO_DEVNUM, 0, 0, S_IFCHR | S_IRUSR | S_IWUSR, &magic_leds_fops, NULL); printk(KERN_INFO DEVICE_NAME ": Initialize OK.\n"); return 0;}/********************************************************************************************************** Function name: magic_leds_exit()** Descriptions : unregister driver** Input:** : NONE** Output:** 0 : OK** other : not OK** Created by : Chenxibing** Created Date : 2005-12-27**-----------------------------------------------------------------------------------------------------** Modified by :** Modified Date: **-----------------------------------------------------------------------------------------------------********************************************************************************************************/static void __exit magic_leds_exit(void){ devfs_unregister(devfs_handle);// unregister_chrdev(0, DEVICE_NAME);}module_init(magic_leds_init);module_exit(magic_leds_exit);/*********************************************************************************************************** End of File*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -