From: Mika Laitio Date: Mon, 19 Jan 2009 23:11:48 +0000 (+0200) Subject: h63xx: button and joypad support X-Git-Tag: v2.6.16-omap1-h63xx-1~2 X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=1e03ce74496b1229c5e8d582963379013726e421;p=linux-2.6-omap-h63xx.git h63xx: button and joypad support --- diff --git a/arch/arm/mach-omap1/board-h6300.c b/arch/arm/mach-omap1/board-h6300.c index e2e93a2fca5..2bcc34f9e6c 100644 --- a/arch/arm/mach-omap1/board-h6300.c +++ b/arch/arm/mach-omap1/board-h6300.c @@ -27,15 +27,86 @@ #include #include #include +#include #include +#define _h6300_KEY_CALENDAR 67 // xmodmap 75 aka F9 +#define _H6300_KEY_TELEPHONE 68 // xmodmap 76 aka F10 +#define _H6300_KEY_HOMEPAGE 87 // xmodmap 87 aka Num_Lock +#define _H6300_KEY_MAIL 88 // xmodmap 88 aka Scroll_Lock + +/* + * When joypad is pressed on h63xx to up, right, down or left direction, + * it does not send keypress events directly from those directions. + * Instead we receive multiple events from the keypresses on directions + * up_right, down_right, down_left, up_left and ok. + * Therefore we are summing those events in kernel level and then + * making a decision which event is send to userspace. (up, right, down or left) + */ +#define _H6300_JOYPAD_UP_RIGHT 1 // 00001 +#define _H6300_JOYPAD_DOWN_RIGHT 2 // 00010 +#define _h6300_JOYPAD_DOWN_LEFT 4 // 00100 +#define _h6300_JOYPAD_UP_LEFT 8 // 01000 +#define _H6300_JOYPAD_KEY_OK 16 // 10000 + +static int h6300_keymap[] = { + KEY(2, 0, _h6300_KEY_CALENDAR), // address button in the bottom left of iPAQ keypad + KEY(2, 3, _H6300_KEY_TELEPHONE), // start call button in the bottom of iPAQ keypad + KEY(3, 1, _H6300_KEY_HOMEPAGE), // stop call button in the bottom of iPAQ keypad + KEY(3, 4, _H6300_KEY_MAIL), // messaging button in the bottom right of iPAQ keypad + + KEY(0, 0, KEY_VOLUMEUP), // volume up button in the right side of iPAQ keypad + KEY(0, 1, KEY_VOLUMEDOWN), // volume down button in the right side of iPAQ keypad + KEY(3, 2, KEY_RECORD), // record button in the left side of iPAQ keypad + + KEY(1, 0, _h6300_JOYPAD_UP_LEFT), + KEY(1, 1, _h6300_JOYPAD_DOWN_LEFT), + KEY(1, 2, _H6300_JOYPAD_KEY_OK), + KEY(1, 3, _H6300_JOYPAD_DOWN_RIGHT), + KEY(1, 4, _H6300_JOYPAD_UP_RIGHT), + + KEY(4, 0, KEY_RIGHT), + KEY(4, 1, KEY_DOWN), + KEY(4, 2, KEY_LEFT), + KEY(4, 3, KEY_UP), + KEY(4, 4, KEY_ENTER), + + 0 +}; + static struct platform_device h6300_lcd_device = { .name = "lcd_h6300", .id = -1, }; +static struct resource h6300_kp_resources[] = { + [0] = { + .start = INT_KEYBOARD, + .end = INT_KEYBOARD, + .flags = IORESOURCE_IRQ, + }, +}; + +static struct omap_kp_platform_data h6300_kp_data = { + .rows = 8, + .cols = 8, + .keymap = h6300_keymap, + .rep = 1, // turns repeat bit on +}; + +static struct platform_device h6300_kp_device = { + .name = "omap-keypad", + .id = -1, + .dev = { + .platform_data = &h6300_kp_data, + }, + .num_resources = ARRAY_SIZE(h6300_kp_resources), + .resource = h6300_kp_resources, +}; + static struct platform_device *h6300_devices[] __initdata = { &h6300_lcd_device, + &h6300_kp_device, }; static struct omap_lcd_config h6300_lcd_config __initdata = { diff --git a/arch/arm/plat-omap/devices.c b/arch/arm/plat-omap/devices.c index 5d5d6eb222d..d332e746479 100644 --- a/arch/arm/plat-omap/devices.c +++ b/arch/arm/plat-omap/devices.c @@ -92,7 +92,7 @@ static inline void omap_init_i2c(void) {} static void omap_init_kp(void) { - if (machine_is_omap_h2() || machine_is_omap_h3()) { + if (machine_is_omap_h2() || machine_is_omap_h3() || machine_is_omap_h6300()) { omap_cfg_reg(F18_1610_KBC0); omap_cfg_reg(D20_1610_KBC1); omap_cfg_reg(D19_1610_KBC2); diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c index 98bbe976c8d..28950703604 100644 --- a/drivers/input/keyboard/omap-keypad.c +++ b/drivers/input/keyboard/omap-keypad.c @@ -9,6 +9,9 @@ * Added support for H2 & H3 Keypad * Copyright (C) 2004 Texas Instruments * + * Added support for keypad and joypad in HP iPAQ h63xx series of devices. + * Copyright (C) 2005 Mika Laitio + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -44,6 +47,19 @@ #include #undef NEW_BOARD_LEARNING_MODE +//#define NEW_BOARD_LEARNING_MODE 1 + +/* + * Following 5 keypad events are not really sent to userspace. + * Instead if the good combination of them is sent, then that is send. + * (up, right, down, left, enter) + */ +#define _H6300_JOYPAD_UP_RIGHT 1 // 00001 +#define _H6300_JOYPAD_DOWN_RIGHT 2 // 00010 +#define _h6300_JOYPAD_DOWN_LEFT 4 // 00100 +#define _h6300_JOYPAD_UP_LEFT 8 // 01000 +#define _H6300_JOYPAD_KEY_OK 16 // 10000 +#define _H6300_JOYPAD_REPORT_COLUMN 4 static void omap_kp_tasklet(unsigned long); static void omap_kp_timer(unsigned long); @@ -53,6 +69,8 @@ static DEFINE_MUTEX(kp_enable_mutex); static int kp_enable = 1; static int kp_cur_group = -1; +static int prevJoypadKeycodePressEmulated; + struct omap_kp { struct input_dev *input; struct timer_list timer; @@ -139,7 +157,7 @@ static void omap_kp_scan_keypad(struct omap_kp *omap_kp, unsigned char *state) for (col = 0; col < omap_kp->cols; col++) { omap_writew(~(1 << col) & 0xff, OMAP_MPUIO_BASE + OMAP_MPUIO_KBC); - if (machine_is_omap_osk() || machine_is_omap_h2() || machine_is_omap_h3()) { + if (machine_is_omap_osk() || machine_is_omap_h2() || machine_is_omap_h3() || machine_is_omap_h6300()) { udelay(9); } else { udelay(4); @@ -169,17 +187,26 @@ static inline int omap_kp_find_key(int col, int row) return -1; } +int is_key_down(unsigned char new_state[], + int col, + int row) +{ + return (new_state[col] & (1 << row)) ? 1 : 0; +} + static void omap_kp_tasklet(unsigned long data) { struct omap_kp *omap_kp_data = (struct omap_kp *) data; unsigned char new_state[8], changed, key_down = 0; int col, row; int spurious = 0; + int report_key, report_col, report_row, joypad_checked; // h6300-joypad specific variables /* check for any changes */ omap_kp_scan_keypad(omap_kp_data, new_state); /* check for changes and print those */ + joypad_checked = 0; for (col = 0; col < omap_kp_data->cols; col++) { changed = new_state[col] ^ keypad_state[col]; key_down |= new_state[col]; @@ -201,14 +228,177 @@ static void omap_kp_tasklet(unsigned long data) spurious = 1; continue; } - - if (!(kp_cur_group == (key & GROUP_MASK) || - kp_cur_group == -1)) - continue; - - kp_cur_group = key & GROUP_MASK; - input_report_key(omap_kp_data->input, key & ~GROUP_MASK, - !!(new_state[col] & (1 << row))); + if (machine_is_omap_h6300() && + ((col == 1) || (col == _H6300_JOYPAD_REPORT_COLUMN))) + { + if (col == _H6300_JOYPAD_REPORT_COLUMN) + { + continue; + } + if ((joypad_checked == 0) && + ((key == _H6300_JOYPAD_KEY_OK) || + (key == _h6300_JOYPAD_UP_LEFT) || + (key == _H6300_JOYPAD_UP_RIGHT) || + (key == _H6300_JOYPAD_DOWN_RIGHT) || + (key == _h6300_JOYPAD_DOWN_LEFT))) + { + if (is_key_down(new_state, col, row)) + { + /* + * only enter pressed + * 1 0 0 _H6300_JOYPAD_KEY_OK 0 0 + * --> 100100 == 36 + */ + if (new_state[1] == 36) + { + joypad_checked = 1; + prevJoypadKeycodePressEmulated = KEY_ENTER; + new_state[_H6300_JOYPAD_REPORT_COLUMN] = 48; //110000 + report_key = prevJoypadKeycodePressEmulated; + report_col = _H6300_JOYPAD_REPORT_COLUMN; + report_row = 4; + input_report_key(omap_kp_data->input, + report_key, + new_state[report_col] & (1 << report_row)); + } + /* + * enter, up_left and up_right sensors pressed. + * 1 _H6300_JOYPAD_UP_RIGHT 0 _H6300_JOYPAD_KEY_OK 0 _h6300_JOYPAD_UP_LEFT + * --> 110101 == 53 + * OR + * 1 KEY_UP_RIGHT 0 0 0 _h6300_JOYPAD_UP_LEFT + * --> 110001 == 42 + * --> move to up + */ + else if ((new_state[1] == 53) || + (new_state[1] == 49)) + { + joypad_checked = 1; + prevJoypadKeycodePressEmulated = KEY_UP; + new_state[_H6300_JOYPAD_REPORT_COLUMN] = 40; //101000 + report_key = prevJoypadKeycodePressEmulated; + report_col = _H6300_JOYPAD_REPORT_COLUMN; + report_row = 3; + input_report_key(omap_kp_data->input, + report_key, + new_state[report_col] & (1 << report_row)); + } + /* + * enter, down_left and down_right sensors pressed + * --> 101110 == 46 + * OR + * down_left and down_right + * -->101010 == 42 + * --> move to down + */ + else if ((new_state[1] == 46) || + (new_state[1] == 42)) + { + joypad_checked = 1; + prevJoypadKeycodePressEmulated = KEY_DOWN; + new_state[_H6300_JOYPAD_REPORT_COLUMN] = 34; //100010 + report_key = prevJoypadKeycodePressEmulated; + report_col = _H6300_JOYPAD_REPORT_COLUMN; + report_row = 1; + input_report_key(omap_kp_data->input, + report_key, + new_state[report_col] & (1 << report_row)); + } + /* + * enter, up_right and down_right sensors pressed + * --> 111100 == 60 + * or + * down_right and up_right + * --> 111000 == 56 + * --> move to right + */ + else if ((new_state[1] == 60) || + (new_state[1] == 56)) + { + joypad_checked = 1; + prevJoypadKeycodePressEmulated = KEY_RIGHT; + new_state[_H6300_JOYPAD_REPORT_COLUMN] = 33; //100001 + report_key = prevJoypadKeycodePressEmulated; + report_col = _H6300_JOYPAD_REPORT_COLUMN; + report_row = 0; + input_report_key(omap_kp_data->input, + report_key, + new_state[report_col] & (1 << report_row)); + } + /* + * enter, up_left and down_left sensors pressed + * --> 100111 == 39 + * or up_left and down_left + * --> 100011 == 35 + * --> move to left + */ + else if ((new_state[1] == 39) || + (new_state[1] == 35)) + { + joypad_checked = 1; + prevJoypadKeycodePressEmulated = KEY_LEFT; + new_state[_H6300_JOYPAD_REPORT_COLUMN] = 36; //100100 + report_key = prevJoypadKeycodePressEmulated; + report_col = _H6300_JOYPAD_REPORT_COLUMN; + report_row = 2; + input_report_key(omap_kp_data->input, + report_key, + new_state[report_col] & (1 << report_row)); + } + else + { + //printk("missed new_state = %d\n", new_state[1]); + } + } + else + { + if (prevJoypadKeycodePressEmulated != 0) + { + // report key up event + joypad_checked = 1; + new_state[_H6300_JOYPAD_REPORT_COLUMN] = 32; //100000 + report_key = prevJoypadKeycodePressEmulated; + report_col = _H6300_JOYPAD_REPORT_COLUMN; + switch(prevJoypadKeycodePressEmulated) + { + case KEY_RIGHT: + report_row = 0; + break; + case KEY_DOWN: + report_row = 1; + break; + case KEY_LEFT: + report_row = 2; + break; + case KEY_UP: + report_row = 3; + break; + case KEY_ENTER: + report_row = 4; + break; + default: + printk(KERN_WARNING "Unknown iPAQ h6300 column 1 key = %d released. This should newer happen!\n", + key); + report_row = 0; + } + input_report_key(omap_kp_data->input, + report_key, + new_state[report_col] & (1 << report_row)); + prevJoypadKeycodePressEmulated = 0; + } + } + } + } + else + { + if (!(kp_cur_group == (key & GROUP_MASK) || + kp_cur_group == -1)) + continue; + + kp_cur_group = key & GROUP_MASK; + input_report_key(omap_kp_data->input, key & ~GROUP_MASK, + !!(new_state[col] & (1 << row))); + } #endif } } @@ -348,10 +538,11 @@ static int __init omap_kp_probe(struct platform_device *pdev) omap_set_gpio_direction(row_gpios[i], 1); } } + prevJoypadKeycodePressEmulated = 0; init_timer(&omap_kp->timer); omap_kp->timer.function = omap_kp_timer; - omap_kp->timer.data = (unsigned long) omap_kp; + omap_kp->timer.data = (unsigned long)omap_kp; /* get the irq and init timer*/ tasklet_enable(&kp_tasklet); @@ -376,7 +567,7 @@ static int __init omap_kp_probe(struct platform_device *pdev) input_register_device(omap_kp->input); if (machine_is_omap_h2() || machine_is_omap_h3() || - machine_is_omap_perseus2()) { + machine_is_omap_perseus2() || machine_is_omap_h6300()) { omap_writew(0xff, OMAP_MPUIO_BASE + OMAP_MPUIO_GPIO_DEBOUNCING); } /* scan current status and enable interrupt */