GPIO Driver

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GPIO Driver

860 Views
embed_wu
Contributor II

I want to add a GPIO drive in to realize the GPIO button functions, who can give suggestions?

Tags (1)
0 Kudos
1 Reply

433 Views
qiang_li-mpu_se
NXP Employee
NXP Employee

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,
};

0 Kudos