这次学习了fl2440驱动代码,本代码比较复杂,在此逐一分析,各函数实现功能作为回顾。
#include "s3c_driver.h"
#define DRV_AUTHOR "Guo Wenxue <guowenxue@gmail.com>"
#define DRV_DESC "S3C24XX button driver"
/* Driver version*/
#define DRV_MAJOR_VER 1
#define DRV_MINOR_VER 0
#define DRV_REVER_VER 0
#define DEV_NAME DEV_BUTTON_NAME
//#define DEV_MAJOR DEV_BUTTON_MAJOR
#ifndef DEV_MAJOR
#define DEV_MAJOR 0 /* dynamic major by default */
#endif
#define BUTTON_UP 0 /* Button status is up */
#define BUTTON_DOWN 1 /* Button status is pushed down */
#define BUTTON_UNCERTAIN 2 /* Button status uncerntain */
#define TIMER_DELAY_DOWN (HZ/50) /*Remove button push down dithering timer delay 20ms */
#define TIMER_DELAY_UP (HZ/10) /*Remove button up dithering timer delay 100ms */
static int debug = DISABLE;
static int dev_major = DEV_MAJOR;
static int dev_minor = 0;
/*============================ Platform Device part ===============================*/
/* Button hardware informtation structure*/
struct s3c_button_info
{
unsigned char num; /*Button nubmer */
char * name; /*Button nubmer */
int nIRQ; /*Button IRQ number*/
unsigned int setting; /*Button IRQ Pin Setting*/
unsigned int gpio; /*Button GPIO port */
};
/* The button plaotform device private data structure */
struct s3c_button_platform_data
{
struct s3c_button_info *buttons;
int nbuttons;
};
/* Button hardware informtation data*/
static struct s3c_button_info s3c_buttons[] = {
[0] = {
.num = 1,
.name = "KEY1",
.nIRQ = IRQ_EINT0,
.gpio = S3C2410_GPF(0),
.setting = S3C2410_GPF0_EINT0,
},
[1] = {
.num = 2,
.name = "KEY2",
.nIRQ = IRQ_EINT2,
.gpio = S3C2410_GPF(2),
.setting = S3C2410_GPF2_EINT2,
},
[2] = {
.num = 3,
.name = "KEY3",
.nIRQ = IRQ_EINT3,
.gpio = S3C2410_GPF(3),
.setting = S3C2410_GPF3_EINT3,
},
[3] = {
.num = 4,
.name = "KEY4",
.nIRQ = IRQ_EINT4,
.gpio = S3C2410_GPF(4),
.setting = S3C2410_GPF4_EINT4,
},
};
/* The button platform device private data */
static struct s3c_button_platform_data s3c_button_data = {
.buttons = s3c_buttons,
.nbuttons = ARRAY_SIZE(s3c_buttons), //ARRAY_SIZE是个宏,读取数组成员的个数
};
struct button_device
{
unsigned char *status; /* The buttons Push down or up status */
struct s3c_button_platform_data *data;