以下为ut-s3c6410开发板的键盘驱动,如果是其他板要做相应的改动。包括arch/arm/machs-3c6410/mach-smdk6410.c的static struct gpio_keys_button smdk6410_buttons[]结构体和drivers/input/keyboard/gpio_keys.c文件下的int s3c_gpio_keys[]结构体。
1、 添加添加 platform 信息
在arch/arm/machs-3c6410/mach-smdk6410.c添加 platform 信息
static struct gpio_keys_button smdk6410_buttons[] = {
{
.gpio = S3C64XX_GPN(0),
.code = 158,
.desc = "Down",
.active_low = 1,
.wakeup = 0,
},
{
.gpio = S3C64XX_GPN(1),
.code = KEY_ENTER,
.desc = "Enter",
.active_low = 1,
.wakeup = 0,
},
{
.gpio = S3C64XX_GPN(2),
.code = KEY_HOME,
.desc = "Home",
.active_low = 1,
.wakeup = 0,
},
{
.gpio = S3C64XX_GPN(3),
.code = KEY_POWER,
.desc = "Power",
.active_low = 1,
.wakeup = 0,
},
{
.gpio = S3C64XX_GPN(4),
.code = KEY_TAB,
.desc = "Tab",
.active_low = 1,
.wakeup = 0,
},
{
.gpio = S3C64XX_GPN(5),
.code = 139,
.desc = "Menu",
.active_low = 1,
.wakeup = 0,
},
};
static struct gpio_keys_platform_data smdk6410_button_data = {
.buttons = smdk6410_buttons,
.nbuttons = ARRAY_SIZE(smdk6410_buttons),
};
static struct platform_device smdk6410_device_button = {
.name = "gpio-keys",
.id = 1,
.dev = {
.platform_data = &smdk6410_button_data,
},
};
并将“&ldd6410_device_button,”语句填入 struct platform_device *ldd6410_devices[]数组,作为该数组的一个成员。
如果要修改按键对应的GPIO和键值,只需要简单的修改ldd6410_buttons[]数组中的内容。
2、 修改代码drivers/input/keyboard/gpio_keys.c
添加结构体:
int s3c_gpio_keys[]=
{
IRQ_EINT(0),
IRQ_EINT(1),
IRQ_EINT(2),
IRQ_EINT(3),
IRQ_EINT(4),
IRQ_EINT(5),
};
修改函数static int __devinit gpio_keys_probe(struct platform_device *pdev)为:
static int __devinit gpio_keys_probe(struct platform_device *pdev)
{
……
#if 0
irq = gpio_to_irq(button->gpio);
if (irq < 0) {
error = irq;
pr_err("gpio-keys: Unable to get irq number"
" for GPIO %d, error %d\n",
button->gpio, error);
gpio_free(button->gpio);
goto fail2;
}
#endif
irq = s3c_gpio_keys[i];
……
}
修改函数static irqreturn_t gpio_keys_isr(int irq, void *dev_id)为:
static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
{
struct gpio_button_data *bdata = dev_id;
struct gpio_keys_button *button = bdata->button;
//BUG_ON(irq != gpio_to_irq(button->gpio));
if (button->debounce_interval)
mod_timer(&bdata->timer,
jiffies + msecs_to_jiffies(button->debounce_interval));
else
gpio_keys_report_event(bdata);
return IRQ_HANDLED;
}
编译内核时选择:
Device Drivers -> Input device support -> [*] Keyboards -> <*> GPIO Buttons
3、 添加数码相框的关机按键驱动
arch/arm/machs-3c6410/mach-smdk6410.c文件修改
static struct gpio_keys_button smdk6410_buttons[] = {
{
{
.gpio = S3C64XX_GPN(15),
.code = KEY_POWER,
.desc = "Power",
.active_low = 1,
.wakeup = 0,
},
};
drivers/input/keyboard/gpio_keys.c文件修改:
int s3c_gpio_keys[]=
{
IRQ_EINT(15),
};