码迷,mamicode.com
首页 > 系统相关 > 详细

linux 输入子系统(2) platform device

时间:2015-10-09 15:17:22      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

 

Input  platform  device 一般是在板级bsp注册了的资源。

以gpio-keys为例:

#####################gpio_key.h##############################

#ifndef _GPIO_KEYS_H
#define _GPIO_KEYS_H

struct gpio_keys_button {
    /* Configuration parameters */
    unsigned int code;    /* input event code (KEY_*, SW_*) */   //上报事件的code
    int gpio;                   /* gpio num*/
    int active_low;         //是否低电平有效
    const char *desc;     /* 功能描述 */
    unsigned int type;    /* input event type (EV_KEY, EV_SW, EV_ABS) */
    int wakeup;        /* configure the button as a wake-up source */
    int debounce_interval;    /* debounce ticks interval in msecs *//* 去抖动间隔,单位微秒*/
    int lock_interval;    /* pause for a moment when the key is pressed */
    bool can_disable;
    int value;        /* axis value for EV_ABS */
};

struct gpio_keys_platform_data {
    struct gpio_keys_button *buttons;
    int nbuttons;
    unsigned int poll_interval;    /* polling interval in msecs -
                       for polling driver only */
    unsigned int rep:1;        /* enable input subsystem auto repeat */
    int (*enable)(struct device *dev);
    void (*disable)(struct device *dev);
    const char *name;        /* input device name */
};

#endif

######################################################################


#ifdef CONFIG_KEYBOARD_GPIO

/*以下表明即将注册五个gpio button信息*/
static struct gpio_keys_button board_buttons[] = {
#ifdef GPIO_RECORD
    {
        .gpio        = GPIO_RECORD,
        .code        = KEY_RECORD,
        .desc        = "record key",
        .active_low    = 1,
    },
#endif
#ifdef GPIO_AP_STA
    {
        .gpio        = GPIO_AP_STA,
        .code        = KEY_MODE,
        .desc        = "ap/sta shift",
        .active_low    = 1,
    },
#endif
#ifdef GPIO_POWER
    {
        .gpio        = GPIO_POWER,
        .code        = KEY_POWER,
        .desc        = "power wakeup",
        .active_low    = 1,
        .wakeup        = 1,
    },
#endif
#ifdef GPIO_VOLUMEDOWN
    {
        .gpio        = GPIO_VOLUMEDOWN,
        .code        = KEY_VOLUMEDOWN,
        .desc        = "volum down key",
        .active_low    = 1,
    },
#endif
#ifdef GPIO_VOLUMEUP
    {
        .gpio        = GPIO_VOLUMEUP,
        .code        = KEY_VOLUMEUP,
        .desc        = "volum up key",
        .active_low    = 1,
    },
#endif
};

static struct gpio_keys_platform_data board_button_data = {
    .buttons    = board_buttons,
    .nbuttons    = ARRAY_SIZE(board_buttons),
};

static struct platform_device button_device = {
    .name        = "gpio-keys",
    .id        = -1,
    .num_resources    = 0,
    .dev        = {
        .platform_data    = &board_button_data,
    }
};
#endif/* CONFIG_KEYBOARD_GPIO */

 

 

//注册platform button device

#ifdef CONFIG_KEYBOARD_GPIO
    platform_device_register(&button_device);
#endif

linux 输入子系统(2) platform device

标签:

原文地址:http://www.cnblogs.com/xuyh/p/4863930.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!