采用linux 2.4版的架构函数设计led驱动,将qq2440的gpio直接做成流水灯。
linux2.4版的字符型设备简单的驱动构成:
1、定义设备名和设备号:
#define DEVICE_NAME "gh_leds"
#define LED_MAJOR 200
2、定义设备驱动操作的函数:
定义open、read、write、ioctl、close时对设备进行哪些操作。这些函数实体可用户自定义,函数名也可自定义,但函数的参数要与标准的open、read、write、ioctl、close的参数一致。
本文仅用到了ioctl,因此自定义ioctl的功能。
static int qq2440_leds_ioctl(
struct inode *inode,
struct file *file,
unsigned int cmd,
unsigned long arg)
{
switch(cmd) {
case 0:
case 1:
if (arg > 4) {
return -EINVAL;
}
s3c2410_gpio_setpin(led_table[arg], !cmd);
return 0;
default:
return -EINVAL;
}
}
3、将自定义的设备操作函数绑定到一个固定结构体中:
static struct file_operations qq2440_leds_fops = {
.owner = THIS_MODULE,
//.open = ghled_open,
.ioctl = qq2440_leds_ioctl,
};