* 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
#include <asm/arch/mux.h>
#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);
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;
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);
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];
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
}
}
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);
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 */