mini2440上LEDS的驱动程序(含测试程序)
leds_drv.h
- #ifndef _MEMDEV_H_
- #define _MEMDEV_H_
- #include <linux/ioctl.h>
- /* 定义幻数 */
- #define MEMDEV_IOC_MAGIC 'k'
- /* 定义命令 */
- #define MEMDEV_IOC_ON _IO(MEMDEV_IOC_MAGIC, 1)
- #define MEMDEV_IOC_OFF _IO(MEMDEV_IOC_MAGIC, 2)
- #define MEMDEV_IOC_MAXNR 2
- #define LED_ON 0
- #define LED_OFF 1
- #endif /* _MEMDEV_H_ */
- #include <linux/miscdevice.h>
- #include <linux/delay.h>
- #include <asm/irq.h>
- #include <mach/regs-gpio.h>
- #include <mach/hardware.h>
- #include <linux/kernel.h>
- #include <linux/miscdevice.h>
- #include <linux/delay.h>
- #include <asm/irq.h>
- #include <mach/regs-gpio.h>
- #include <mach/hardware.h>
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/mm.h>
- #include <linux/fs.h>
- #include <linux/types.h>
- #include <linux/delay.h>
- #include <linux/moduleparam.h>
- #include <linux/slab.h>
- #include <linux/errno.h>
- #include <linux/ioctl.h>
- #include <linux/cdev.h>
- #include <linux/string.h>
- #include <linux/list.h>
- #include <linux/pci.h>
- #include <linux/gpio.h>
- #include <asm/uaccess.h>
- #include <asm/atomic.h>
- #include <asm/unistd.h>
- #include "leds_drv.h"
- #define DEVICE_NAME "leds"
- static unsigned long led_table[] = {
- S3C2410_GPB(5),
- S3C2410_GPB(6),
- S3C2410_GPB(7),
- S3C2410_GPB(8),
- };
- static unsigned int led_cfg_table[] = {
- S3C2410_GPIO_OUTPUT,
- S3C2410_GPIO_OUTPUT,
- S3C2410_GPIO_OUTPUT,
- S3C2410_GPIO_OUTPUT,
- };
- static int s3c2440_leds_ioctl(struct inode *inode,
- struct file *file, unsigned int cmd, unsigned long arg)
- {
- /* 检测命令的有效性 */
- if (_IOC_TYPE(cmd) != MEMDEV_IOC_MAGIC)
- return -EINVAL;
- if (_IOC_NR(cmd) > MEMDEV_IOC_MAXNR)
- return -EINVAL;
- /* 根据命令,执行相应的操作 */
- switch (cmd)
- {
- case MEMDEV_IOC_OFF:
- s3c2410_gpio_setpin(led_table[arg], LED_OFF);
- return 0;
- case MEMDEV_IOC_ON:
- s3c2410_gpio_setpin(led_table[arg], LED_ON);
- return 0;
- default:
- return -EINVAL;
- }
- }
- /*文件操作结构体*/
- static struct file_operations dev_fops = {
- .owner = THIS_MODULE,
- .ioctl = s3c2440_leds_ioctl,
- };
- static struct miscdevice misc = {
- .minor = MISC_DYNAMIC_MINOR,
- .name = DEVICE_NAME,
- .fops = &dev_fops,
- };
- static int __init dev_init(void)
- {
- int ret;
- int i;
- /*设置GPIO控制寄存器,GPIO设置为输出模式,默认下灯全灭 */
- for (i = 0; i < 4; i++)
- {
- s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]);
- s3c2410_gpio_setpin(led_table[i], 1);
- }
- /*注册混杂型字符设备驱动 */
- ret = misc_register(&misc);
- printk(DEVICE_NAME "\tinitialized\n");
- return ret;
- }
- static void __exit dev_exit(void)
- {
- /*注销混杂型字符设备驱动 */
- misc_deregister(&misc);
- }
- module_init(dev_init);
- module_exit(dev_exit);
- MODULE_AUTHOR("Cried Devil");
- MODULE_LICENSE("GPL");
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20