2015年4月29日 星期三

GPIO_Button driver

環境:
Android: 4.4
Kernel:3.0.35
iMX6Q

透過標準gpio button介面kernel/drivers/input/keyboard/gpio_keys.c這個檔案,就能把GPIO端的訊息,註冊為/dev/input/event
CONFIG_LEDS_GPIO=y
CONFIG_LEDS_GPIO_PLATFORM=y
CONFIG_LEDS_TRIGGER=y

input.h

kernel_imx/arch/arm/mach-mx6/board-mx6q_sabresd.c

/* There's a off-by-one betweem the gpio bank number and the gpiochip */
/* range e.g. GPIO_1_5 is gpio 5 under linux */
#define IMX_GPIO_NR(bank, nr)   (((bank) - 1) * 32 + (nr))
#define SABRESD_VOLUME_UP   IMX_GPIO_NR(1, 4)

#define GPIO_BUTTON(gpio_num, ev_code, act_low, descr, wake, debounce) \
{           \
 .gpio  = gpio_num,    \
 .type  = EV_KEY,    \
 .code  = ev_code,    \
 .active_low = act_low,    \
 .desc  = "btn " descr,    \
 .wakeup  = wake,     \
 .debounce_interval = debounce,    \
}

static struct gpio_keys_button gpio_buttons[] =  
{  
    GPIO_BUTTON(SABRESD_VOLUME_UP, KEY_VOLUMEUP, 1, "KEY_UP", 0, 1),
};  
  
static struct gpio_keys_platform_data buttons_platdata =  
{  
    .buttons = gpio_buttons,  
    .nbuttons = ARRAY_SIZE(gpio_buttons),  
}; 

static struct platform_device s500_gpio_buttons= {  
    .name    = "gpio-keys",  
    .id     = -1,  
    .num_resources = 0,  
    .resource = NULL,  
    .dev     = {
        .platform_data = &buttons_platdata,  
    }  
};


static void __init imx6q_add_device_buttons(void)
{
...
    if (mx6q_revision() >= IMX_CHIP_REVISION_1_2 ||
 mx6dl_revision() >= IMX_CHIP_REVISION_1_1)
     platform_device_add_data(&sabresd_button_device,
  &new_sabresd_button_data,
  sizeof(new_sabresd_button_data));
 else
     platform_device_add_data(&sabresd_button_device,
  &sabresd_button_data,
  sizeof(sabresd_button_data));

 platform_device_register(&sabresd_button_device);
...
}

沒有留言:

張貼留言