I want to add a GPIO drive in to realize the GPIO button functions, who can give suggestions?
You can reference to the iMX pwrkey driver "linux\drivers\input\keyboard\mxc_pwrkey.c", and the machine code can be found from "linux\arch\arm\mach-mx5\mx51_babbage.c", it used an GPIO to work as power key.
static void mxc_register_powerkey(pwrkey_callback pk_cb)
{
/* Set power key as wakeup resource */
int irq, ret;
irq = gpio_to_irq(BABBAGE_POWER_KEY);
if (gpio_get_value(BABBAGE_POWER_KEY))
set_irq_type(irq, IRQF_TRIGGER_FALLING);
else
set_irq_type(irq, IRQF_TRIGGER_RISING);
ret = request_irq(irq, power_key_int, 0, "power_key", pk_cb);
if (ret)
pr_info("register on-off key interrupt failed\n");
else
enable_irq_wake(irq);
}
static int mxc_pwrkey_getstatus(int id)
{
return gpio_get_value(BABBAGE_POWER_KEY);
}
static struct power_key_platform_data pwrkey_data = {
.key_value = KEY_F4,
.register_pwrkey = mxc_register_powerkey,
.get_key_status = mxc_pwrkey_getstatus,
};