 drivers/input/keyboard/locomokbd.c |   61 +++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 22 deletions(-)

Index: linux-2.6.17/drivers/input/keyboard/locomokbd.c
===================================================================
--- linux-2.6.17.orig/drivers/input/keyboard/locomokbd.c	2006-09-03 22:46:35.000000000 +0100
+++ linux-2.6.17/drivers/input/keyboard/locomokbd.c	2006-09-03 22:58:29.000000000 +0100
@@ -44,24 +44,32 @@ MODULE_LICENSE("GPL");
 
 #define LOCOMOKBD_NUMKEYS	128
 
-#define KEY_ACTIVITY		KEY_F16
-#define KEY_CONTACT		KEY_F18
-#define KEY_CENTER		KEY_F15
+
+#define LOCOMO_KEY_CALENDER	KEY_LEFTCTRL
+#define LOCOMO_KEY_ADDRESS	KEY_LEFTALT	/* Needed for SysRQ */
+#define LOCOMO_KEY_HOME		KEY_SYSRQ	/* Needed for SysRQ */
+#define LOCOMO_KEY_MENU		KEY_F12
+#define LOCOMO_KEY_MAIL		KEY_F10
+#define LOCOMO_KEY_OK		KEY_F11		/* Don't hardwire to KEY_RETURN */
+#define LOCOMO_KEY_CANCEL	KEY_POWER
+#define LOCOMO_KEY_CENTER	KEY_F5		/* Don't hardwire to KEY_RETURN */
+
+#define LOCOMO_KEY_FN		KEY_F9
 
 static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
-	0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0,				/* 0 - 9 */
-	0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT,			/* 10 - 19 */
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,						/* 20 - 29 */
-	0, 0, 0, KEY_CENTER, 0, KEY_MAIL, 0, 0, 0, 0,				/* 30 - 39 */
-	0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RIGHT,					/* 40 - 49 */
-	KEY_UP, KEY_LEFT, 0, 0, KEY_P, 0, KEY_O, KEY_I, KEY_Y, KEY_T,		/* 50 - 59 */
-	KEY_E, KEY_W, 0, 0, 0, 0, KEY_DOWN, KEY_ENTER, 0, 0,			/* 60 - 69 */
-	KEY_BACKSPACE, 0, KEY_L, KEY_U, KEY_H, KEY_R, KEY_D, KEY_Q, 0, 0,	/* 70 - 79 */
-	0, 0, 0, 0, 0, 0, KEY_ENTER, KEY_RIGHTSHIFT, KEY_K, KEY_J,		/* 80 - 89 */
-	KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0,				/* 90 - 99 */
-	0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A,		/* 100 - 109 */
-	KEY_LEFTSHIFT, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0,		/* 110 - 119 */
-	KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0		/* 120 - 128 */
+	0, LOCOMO_KEY_CANCEL, LOCOMO_KEY_CALENDER, LOCOMO_KEY_HOME, 0, 0, 0, 0, 0, 0,	/* 0 - 9 */
+	0, 0, 0, 0, 0, 0, 0, LOCOMO_KEY_MENU, 0, LOCOMO_KEY_ADDRESS,			/* 10 - 19 */
+	0, 0, 0, 0, 0, LOCOMO_KEY_MAIL, 0, 0, 0, 0,					/* 20 - 29 */
+	0, 0, 0, LOCOMO_KEY_CENTER, 0, LOCOMO_KEY_MAIL, 0, 0, 0, 0,			/* 30 - 39 */
+	0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RIGHT,						/* 40 - 49 */
+	KEY_UP, KEY_LEFT, 0, 0, KEY_P, 0, KEY_O, KEY_I, KEY_Y, KEY_T,			/* 50 - 59 */
+	KEY_E, KEY_W, 0, 0, 0, 0, KEY_DOWN, LOCOMO_KEY_OK, 0, 0,			/* 60 - 69 */
+	KEY_BACKSPACE, 0, KEY_L, KEY_U, KEY_H, KEY_R, KEY_D, KEY_Q, 0, 0,		/* 70 - 79 */
+	0, 0, 0, 0, 0, 0, KEY_ENTER, KEY_RIGHTSHIFT, KEY_K, KEY_J,			/* 80 - 89 */
+	KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0,					/* 90 - 99 */
+	0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A,			/* 100 - 109 */
+	KEY_LEFTSHIFT, KEY_TAB, LOCOMO_KEY_FN, 0, 0, 0, 0, 0, 0, 0,			/* 110 - 119 */
+	KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0			/* 120 - 128 */
 };
 
 #define KB_ROWS			16
@@ -71,7 +79,7 @@ static unsigned char locomokbd_keycode[L
 #define	NR_SCANCODES		128
 
 #define KB_DELAY		8
-#define SCAN_INTERVAL		(HZ/10)
+#define SCAN_INTERVAL		(HZ/20)
 #define LOCOMOKBD_PRESSED	1
 
 struct locomokbd {
@@ -84,6 +92,7 @@ struct locomokbd {
 	spinlock_t lock;
 
 	struct timer_list timer;
+	unsigned long suspend_jiffies;
 };
 
 /* helper functions for reading the keyboard matrix */
@@ -129,7 +138,7 @@ static inline void locomokbd_reset_col(u
 /* Scan the hardware keyboard and push any changes up through the input layer */
 static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *regs)
 {
-	unsigned int row, col, rowd, scancode;
+	unsigned int row, col, rowd;
 	unsigned long flags;
 	unsigned int num_pressed;
 	unsigned long membase = locomokbd->base;
@@ -148,12 +157,18 @@ static void locomokbd_scankeyboard(struc
 
 		rowd = ~locomo_readl(membase + LOCOMO_KIB);
 		for (row = 0; row < KB_ROWS; row++) {
+			unsigned int scancode, pressed;
+
 			scancode = SCANCODE(col, row);
-			if (rowd & KB_ROWMASK(row)) {
+			pressed = rowd & KB_ROWMASK(row);
+
+			input_report_key(locomokbd->input, locomokbd->keycode[scancode], pressed);
+			if (pressed)
 				num_pressed += 1;
-				input_report_key(locomokbd->input, locomokbd->keycode[scancode], 1);
-			} else {
-				input_report_key(locomokbd->input, locomokbd->keycode[scancode], 0);
+			if (pressed && (locomokbd->keycode[scancode] == KEY_POWER)
+					&& time_after(jiffies, locomokbd->suspend_jiffies + HZ)) {
+				input_event(locomokbd->input, EV_PWR, KEY_POWER, 1);
+				locomokbd->suspend_jiffies = jiffies;
 			}
 		}
 		locomokbd_reset_col(membase, col);
@@ -225,6 +240,8 @@ static int locomokbd_probe(struct locomo
 	locomokbd->timer.function = locomokbd_timer_callback;
 	locomokbd->timer.data = (unsigned long) locomokbd;
 
+	locomokbd->suspend_jiffies = jiffies;
+
 	locomokbd->input = input_dev;
 	strcpy(locomokbd->phys, "locomokbd/input0");
 
