update keys driver: adc key's gpio_value = INVALID_GPIO

This commit is contained in:
kfx
2011-03-28 14:48:57 +08:00
parent 4d2c237101
commit 37c10cfe0c
2 changed files with 19 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
#include <mach/key.h>
#include <mach/gpio.h>
#include <mach/board.h>
#define EV_ENCALL KEY_F4
#define EV_MENU KEY_F1
@@ -55,6 +56,7 @@ static struct rk29_keys_button key_button[] = {
.code = KEY_POWER,
.gpio = RK29_PIN6_PA7,
.active_low = PRESS_LEV_LOW,
//.code_long_press = EV_ENCALL,
.wakeup = 1,
},
#if 0
@@ -62,18 +64,21 @@ static struct rk29_keys_button key_button[] = {
.desc = "vol+",
.code = KEY_VOLUMEDOWN,
.adc_value = 95,
.gpio = INVALID_GPIO,
.active_low = PRESS_LEV_LOW,
},
{
.desc = "vol-",
.code = KEY_VOLUMEUP,
.adc_value = 249,
.gpio = INVALID_GPIO,
.active_low = PRESS_LEV_LOW,
},
{
.desc = "menu",
.code = EV_MENU,
.adc_value = 406,
.gpio = INVALID_GPIO,
.active_low = PRESS_LEV_LOW,
},
{
@@ -81,12 +86,14 @@ static struct rk29_keys_button key_button[] = {
.code = KEY_HOME,
.code_long_press = KEY_F4,
.adc_value = 561,
.gpio = INVALID_GPIO,
.active_low = PRESS_LEV_LOW,
},
{
.desc = "esc",
.code = KEY_ESC,
.adc_value = 726,
.gpio = INVALID_GPIO,
.active_low = PRESS_LEV_LOW,
},
{
@@ -94,6 +101,7 @@ static struct rk29_keys_button key_button[] = {
.code = KEY_BACK,
.code_long_press = EV_ENCALL,
.adc_value = 899,
.gpio = INVALID_GPIO,
.active_low = PRESS_LEV_LOW,
},
#endif

View File

@@ -25,6 +25,8 @@
#include <asm/gpio.h>
#include <mach/key.h>
#include <mach/board.h>
#define EMPTY_ADVALUE 950
#define DRIFT_ADVALUE 70
@@ -62,7 +64,7 @@ static void keys_long_press_timer(unsigned long _data)
struct rk29_keys_button *button = bdata->button;
struct input_dev *input = bdata->input;
unsigned int type = EV_KEY;
if(button->gpio)
if(button->gpio != INVALID_GPIO )
state = !!((gpio_get_value(button->gpio) ? 1 : 0) ^ button->active_low);
else
state = !!button->adc_state;
@@ -70,13 +72,13 @@ static void keys_long_press_timer(unsigned long _data)
if(bdata->long_press_count != 0) {
if(bdata->long_press_count % (LONG_PRESS_COUNT+ONE_SEC_COUNT) == 0){
key_dbg(bdata, "%skey[%s]: report ev[%d] state[0]\n",
(!button->gpio)?"ad":"io", button->desc, button->code_long_press);
(button->gpio == INVALID_GPIO)?"ad":"io", button->desc, button->code_long_press);
input_event(input, type, button->code_long_press, 0);
input_sync(input);
}
else if(bdata->long_press_count%LONG_PRESS_COUNT == 0) {
key_dbg(bdata, "%skey[%s]: report ev[%d] state[1]\n",
(!button->gpio)?"ad":"io", button->desc, button->code_long_press);
(button->gpio == INVALID_GPIO)?"ad":"io", button->desc, button->code_long_press);
input_event(input, type, button->code_long_press, 1);
input_sync(input);
}
@@ -89,16 +91,15 @@ static void keys_long_press_timer(unsigned long _data)
if(bdata->long_press_count <= LONG_PRESS_COUNT) {
bdata->long_press_count = 0;
key_dbg(bdata, "%skey[%s]: report ev[%d] state[1], report ev[%d] state[0]\n",
(!button->gpio)?"ad":"io", button->desc, button->code, button->code);
(button->gpio == INVALID_GPIO)?"ad":"io", button->desc, button->code, button->code);
input_event(input, type, button->code, 1);
input_sync(input);
input_event(input, type, button->code, 0);
input_sync(input);
}
else {
if(bdata->state != state)
else if(bdata->state != state) {
key_dbg(bdata, "%skey[%s]: report ev[%d] state[0]\n",
(!button->gpio)?"ad":"io", button->desc, button->code_long_press);
(button->gpio == INVALID_GPIO)?"ad":"io", button->desc, button->code_long_press);
input_event(input, type, button->code_long_press, 0);
input_sync(input);
}
@@ -113,14 +114,14 @@ static void keys_timer(unsigned long _data)
struct input_dev *input = bdata->input;
unsigned int type = EV_KEY;
if(button->gpio)
if(button->gpio != INVALID_GPIO)
state = !!((gpio_get_value(button->gpio) ? 1 : 0) ^ button->active_low);
else
state = !!button->adc_state;
if(bdata->state != state) {
bdata->state = state;
key_dbg(bdata, "%skey[%s]: report ev[%d] state[%d]\n",
(!button->gpio)?"ad":"io", button->desc, button->code, bdata->state);
(button->gpio == INVALID_GPIO)?"ad":"io", button->desc, button->code, bdata->state);
input_event(input, type, button->code, bdata->state);
input_sync(input);
}
@@ -237,7 +238,7 @@ static int __devinit keys_probe(struct platform_device *pdev)
else if(button->code)
setup_timer(&bdata->timer,
keys_timer, (unsigned long)bdata);
if(button->gpio) {
if(button->gpio != INVALID_GPIO) {
error = gpio_request(button->gpio, button->desc ?: "keys");
if (error < 0) {
pr_err("gpio-keys: failed to request GPIO %d,"