/*
****************************************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~254
MODULE_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
********************************************************************************************************
*/
led-drvier.rar_2410_2410 linux 驱动_led-2.6.12_led-drvier
版权申诉
10 浏览量
2022-09-19
13:07:45
上传
评论
收藏 5KB RAR 举报
APei
- 粉丝: 63
- 资源: 1万+
最新资源
- 2010-2019年分省技术市场成交额面板数据(万元)
- 2008-2022年上市公司对外投资情况数据.zip
- Rust开发安装与启动的教程与代码实例.txt
- 环境工程原理+环境监测+环境微生物学+仪器分析-上交
- 世界各国2022年ICT基础设施-互联网使用-固定宽带订阅-电信服务的收入-移动网络收入
- 寿光蔬菜产量数据.xlsx寿光蔬菜产量数据.xlsx寿光蔬菜产量数据.xlsx
- 全国62个主要城市建筑轮廓矢量数据(全国62个城市模型)
- Object-C开发安装与启动的教程与代码实例.txt
- 全国297个地级市城市2003-2021科学研究试验发展R&D人员数R&D内部经费支出
- LP方法上市公司全要素生产率TFP计算Stata代码(附2000-2019年数据和结果)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈