[U-Boot] [PATCH v2 3/7] x86: i8042: Reorder static functions

Bin Meng bmeng.cn at gmail.com
Fri Aug 21 09:18:53 CEST 2015


Reorder those static function so that their declarations
can be removed.

Signed-off-by: Bin Meng <bmeng.cn at gmail.com>
Acked-by: Simon Glass <sjg at chromium.org>

---

Changes in v2:
- Split of reordering static functions into this patch

 drivers/input/i8042.c | 417 ++++++++++++++++++++++----------------------------
 1 file changed, 186 insertions(+), 231 deletions(-)

diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c
index 8401181..0ade077 100644
--- a/drivers/input/i8042.c
+++ b/drivers/input/i8042.c
@@ -27,18 +27,6 @@ static int  kbd_mapping	 = KBD_US;	/* default US keyboard */
 static int  kbd_flags	 = NORMAL;	/* after reset */
 static int  kbd_state;			/* unshift code */
 
-static void kbd_conv_char(unsigned char scan_code);
-static void kbd_led_set(void);
-static void kbd_normal(unsigned char scan_code);
-static void kbd_shift(unsigned char scan_code);
-static void kbd_ctrl(unsigned char scan_code);
-static void kbd_num(unsigned char scan_code);
-static void kbd_caps(unsigned char scan_code);
-static void kbd_scroll(unsigned char scan_code);
-static void kbd_alt(unsigned char scan_code);
-static int  kbd_input_empty(void);
-static int  kbd_reset(void);
-
 static unsigned char kbd_fct_map[144] = {
 	/* kbd_fct_map table for scan code */
 	 0,  AS,  AS,  AS,  AS,  AS,  AS,  AS, /* scan  0- 7 */
@@ -288,180 +276,34 @@ static unsigned char ext_key_map[] = {
 	0x00  /* map end */
 	};
 
-/******************************************************************************/
-
-static int kbd_controller_present(void)
-{
-	return in8(I8042_STATUS_REG) != 0xff;
-}
-
-/*******************************************************************************
- *
- * i8042_kbd_init - reset keyboard and init state flags
- */
-int i8042_kbd_init(void)
+static int kbd_input_empty(void)
 {
-	int keymap, try;
-	char *penv;
-
-	if (!kbd_controller_present())
-		return -1;
+	int kbdTimeout = KBD_TIMEOUT * 1000;
 
-	/* Init keyboard device (default US layout) */
-	keymap = KBD_US;
-	penv = getenv("keymap");
-	if (penv != NULL) {
-		if (strncmp(penv, "de", 3) == 0)
-			keymap = KBD_GER;
-	}
+	while ((in8(I8042_STATUS_REG) & I8042_STATUS_IN_DATA) && kbdTimeout--)
+		udelay(1);
 
-	for (try = 0; try < KBD_RESET_TRIES; try++) {
-		if (kbd_reset() == 0) {
-			kbd_mapping = keymap;
-			kbd_flags   = NORMAL;
-			kbd_state   = 0;
-			kbd_led_set();
-			return 0;
-		}
-	}
-	return -1;
+	return kbdTimeout != -1;
 }
 
-
-/*******************************************************************************
- *
- * i8042_tstc - test if keyboard input is available
- *		option: cursor blinking if called in a loop
- */
-int i8042_tstc(struct stdio_dev *dev)
+static int wait_until_kbd_output_full(void)
 {
-	unsigned char scan_code = 0;
-
-#ifdef CONFIG_CONSOLE_CURSOR
-	if (--blinkCount == 0) {
-		cursor_state ^= 1;
-		console_cursor(cursor_state);
-		blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
-		udelay(10);
-	}
-#endif
-
-	if ((in8(I8042_STATUS_REG) & 0x01) == 0) {
-		return 0;
-	} else {
-		scan_code = in8(I8042_DATA_REG);
-		if (scan_code == 0xfa)
-			return 0;
-
-		kbd_conv_char(scan_code);
-
-		if (kbd_input != -1)
-			return 1;
-	}
-	return 0;
-}
-
+	int kbdTimeout = KBD_TIMEOUT * 1000;
 
-/*******************************************************************************
- *
- * i8042_getc - wait till keyboard input is available
- *		option: turn on/off cursor while waiting
- */
-int i8042_getc(struct stdio_dev *dev)
-{
-	int ret_chr;
-	unsigned char scan_code;
+	while (((in8(I8042_STATUS_REG) & 0x01) == 0) && kbdTimeout--)
+		udelay(1);
 
-	while (kbd_input == -1) {
-		while ((in8(I8042_STATUS_REG) & 0x01) == 0) {
-#ifdef CONFIG_CONSOLE_CURSOR
-			if (--blinkCount == 0) {
-				cursor_state ^= 1;
-				console_cursor(cursor_state);
-				blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
-			}
-			udelay(10);
-#endif
-		}
-		scan_code = in8(I8042_DATA_REG);
-		if (scan_code != 0xfa)
-			kbd_conv_char (scan_code);
-	}
-	ret_chr = kbd_input;
-	kbd_input = -1;
-	return ret_chr;
+	return kbdTimeout != -1;
 }
 
-
-/******************************************************************************/
-
-static void kbd_conv_char(unsigned char scan_code)
+static void kbd_led_set(void)
 {
-	if (scan_code == 0xe0) {
-		kbd_flags |= EXT;
-		return;
-	}
-
-	/* if high bit of scan_code, set break flag */
-	if (scan_code & 0x80)
-		kbd_flags |=  BRK;
-	else
-		kbd_flags &= ~BRK;
-
-	if ((scan_code == 0xe1) || (kbd_flags & E1)) {
-		if (scan_code == 0xe1) {
-			kbd_flags ^= BRK;    /* reset the break flag */
-			kbd_flags ^= E1;     /* bitwise EXOR with E1 flag */
-		}
-		return;
-	}
-
-	scan_code &= 0x7f;
-
-	if (kbd_flags & EXT) {
-		int i;
-
-		kbd_flags ^= EXT;
-		for (i = 0; ext_key_map[i]; i++) {
-			if (ext_key_map[i] == scan_code) {
-				scan_code = 0x80 + i;
-				break;
-			}
-		}
-		/* not found ? */
-		if (!ext_key_map[i])
-			return;
-	}
-
-	switch (kbd_fct_map[scan_code]) {
-	case AS:
-		kbd_normal(scan_code);
-		break;
-	case SH:
-		kbd_shift(scan_code);
-		break;
-	case CN:
-		kbd_ctrl(scan_code);
-		break;
-	case NM:
-		kbd_num(scan_code);
-		break;
-	case CP:
-		kbd_caps(scan_code);
-		break;
-	case ST:
-		kbd_scroll(scan_code);
-		break;
-	case AK:
-		kbd_alt(scan_code);
-		break;
-	}
-	return;
+	kbd_input_empty();
+	out8(I8042_DATA_REG, 0xed);    /* SET LED command */
+	kbd_input_empty();
+	out8(I8042_DATA_REG, (kbd_flags & 0x7));    /* LED bits only */
 }
 
-
-/******************************************************************************/
-
 static void kbd_normal(unsigned char scan_code)
 {
 	unsigned char chr;
@@ -480,9 +322,6 @@ static void kbd_normal(unsigned char scan_code)
 	}
 }
 
-
-/******************************************************************************/
-
 static void kbd_shift(unsigned char scan_code)
 {
 	if ((kbd_flags & BRK) == BRK) {
@@ -494,9 +333,6 @@ static void kbd_shift(unsigned char scan_code)
 	}
 }
 
-
-/******************************************************************************/
-
 static void kbd_ctrl(unsigned char scan_code)
 {
 	if ((kbd_flags & BRK) == BRK) {
@@ -508,32 +344,34 @@ static void kbd_ctrl(unsigned char scan_code)
 	}
 }
 
-
-/******************************************************************************/
-
-static void kbd_caps(unsigned char scan_code)
+static void kbd_num(unsigned char scan_code)
 {
 	if ((kbd_flags & BRK) == NORMAL) {
-		kbd_flags ^= CAPS;
+		kbd_flags ^= NUM;
+		kbd_state = (kbd_flags & NUM) ? AS : NM;
 		kbd_led_set();    /* update keyboard LED */
 	}
 }
 
+static void kbd_alt(unsigned char scan_code)
+{
+	if ((kbd_flags & BRK) == BRK) {
+		kbd_state = AS;
+		kbd_flags &= (~ALT);
+	} else {
+		kbd_state = AK;
+		kbd_flags &= ALT;
+	}
+}
 
-/******************************************************************************/
-
-static void kbd_num(unsigned char scan_code)
+static void kbd_caps(unsigned char scan_code)
 {
 	if ((kbd_flags & BRK) == NORMAL) {
-		kbd_flags ^= NUM;
-		kbd_state = (kbd_flags & NUM) ? AS : NM;
+		kbd_flags ^= CAPS;
 		kbd_led_set();    /* update keyboard LED */
 	}
 }
 
-
-/******************************************************************************/
-
 static void kbd_scroll(unsigned char scan_code)
 {
 	if ((kbd_flags & BRK) == NORMAL) {
@@ -546,53 +384,68 @@ static void kbd_scroll(unsigned char scan_code)
 	}
 }
 
-/******************************************************************************/
-
-static void kbd_alt(unsigned char scan_code)
+static void kbd_conv_char(unsigned char scan_code)
 {
-	if ((kbd_flags & BRK) == BRK) {
-		kbd_state = AS;
-		kbd_flags &= (~ALT);
-	} else {
-		kbd_state = AK;
-		kbd_flags &= ALT;
+	if (scan_code == 0xe0) {
+		kbd_flags |= EXT;
+		return;
 	}
-}
-
 
-/******************************************************************************/
-
-static void kbd_led_set(void)
-{
-	kbd_input_empty();
-	out8(I8042_DATA_REG, 0xed);    /* SET LED command */
-	kbd_input_empty();
-	out8(I8042_DATA_REG, (kbd_flags & 0x7));    /* LED bits only */
-}
-
-
-/******************************************************************************/
-
-static int kbd_input_empty(void)
-{
-	int kbdTimeout = KBD_TIMEOUT * 1000;
-
-	while ((in8(I8042_STATUS_REG) & I8042_STATUS_IN_DATA) && kbdTimeout--)
-		udelay(1);
+	/* if high bit of scan_code, set break flag */
+	if (scan_code & 0x80)
+		kbd_flags |=  BRK;
+	else
+		kbd_flags &= ~BRK;
 
-	return kbdTimeout != -1;
-}
+	if ((scan_code == 0xe1) || (kbd_flags & E1)) {
+		if (scan_code == 0xe1) {
+			kbd_flags ^= BRK;    /* reset the break flag */
+			kbd_flags ^= E1;     /* bitwise EXOR with E1 flag */
+		}
+		return;
+	}
 
-/******************************************************************************/
+	scan_code &= 0x7f;
 
-static int wait_until_kbd_output_full(void)
-{
-	int kbdTimeout = KBD_TIMEOUT * 1000;
+	if (kbd_flags & EXT) {
+		int i;
 
-	while (((in8(I8042_STATUS_REG) & 0x01) == 0) && kbdTimeout--)
-		udelay(1);
+		kbd_flags ^= EXT;
+		for (i = 0; ext_key_map[i]; i++) {
+			if (ext_key_map[i] == scan_code) {
+				scan_code = 0x80 + i;
+				break;
+			}
+		}
+		/* not found ? */
+		if (!ext_key_map[i])
+			return;
+	}
 
-	return kbdTimeout != -1;
+	switch (kbd_fct_map[scan_code]) {
+	case AS:
+		kbd_normal(scan_code);
+		break;
+	case SH:
+		kbd_shift(scan_code);
+		break;
+	case CN:
+		kbd_ctrl(scan_code);
+		break;
+	case NM:
+		kbd_num(scan_code);
+		break;
+	case AK:
+		kbd_alt(scan_code);
+		break;
+	case CP:
+		kbd_caps(scan_code);
+		break;
+	case ST:
+		kbd_scroll(scan_code);
+		break;
+	}
+	return;
 }
 
 /******************************************************************************/
@@ -646,3 +499,105 @@ static int kbd_reset(void)
 
 	return 0;
 }
+
+static int kbd_controller_present(void)
+{
+	return in8(I8042_STATUS_REG) != 0xff;
+}
+
+/*******************************************************************************
+ *
+ * i8042_kbd_init - reset keyboard and init state flags
+ */
+int i8042_kbd_init(void)
+{
+	int keymap, try;
+	char *penv;
+
+	if (!kbd_controller_present())
+		return -1;
+
+	/* Init keyboard device (default US layout) */
+	keymap = KBD_US;
+	penv = getenv("keymap");
+	if (penv != NULL) {
+		if (strncmp(penv, "de", 3) == 0)
+			keymap = KBD_GER;
+	}
+
+	for (try = 0; try < KBD_RESET_TRIES; try++) {
+		if (kbd_reset() == 0) {
+			kbd_mapping = keymap;
+			kbd_flags   = NORMAL;
+			kbd_state   = 0;
+			kbd_led_set();
+			return 0;
+		}
+	}
+	return -1;
+}
+
+
+/*******************************************************************************
+ *
+ * i8042_tstc - test if keyboard input is available
+ *		option: cursor blinking if called in a loop
+ */
+int i8042_tstc(struct stdio_dev *dev)
+{
+	unsigned char scan_code = 0;
+
+#ifdef CONFIG_CONSOLE_CURSOR
+	if (--blinkCount == 0) {
+		cursor_state ^= 1;
+		console_cursor(cursor_state);
+		blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
+		udelay(10);
+	}
+#endif
+
+	if ((in8(I8042_STATUS_REG) & 0x01) == 0) {
+		return 0;
+	} else {
+		scan_code = in8(I8042_DATA_REG);
+		if (scan_code == 0xfa)
+			return 0;
+
+		kbd_conv_char(scan_code);
+
+		if (kbd_input != -1)
+			return 1;
+	}
+	return 0;
+}
+
+
+/*******************************************************************************
+ *
+ * i8042_getc - wait till keyboard input is available
+ *		option: turn on/off cursor while waiting
+ */
+int i8042_getc(struct stdio_dev *dev)
+{
+	int ret_chr;
+	unsigned char scan_code;
+
+	while (kbd_input == -1) {
+		while ((in8(I8042_STATUS_REG) & 0x01) == 0) {
+#ifdef CONFIG_CONSOLE_CURSOR
+			if (--blinkCount == 0) {
+				cursor_state ^= 1;
+				console_cursor(cursor_state);
+				blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
+			}
+			udelay(10);
+#endif
+		}
+		scan_code = in8(I8042_DATA_REG);
+		if (scan_code != 0xfa)
+			kbd_conv_char (scan_code);
+	}
+	ret_chr = kbd_input;
+	kbd_input = -1;
+	return ret_chr;
+}
-- 
1.8.2.1



More information about the U-Boot mailing list