x86: Make the i8042 driver checkpatch clean

Signed-off-by: Gabe Black <gabeblack@chromium.org>
This commit is contained in:
Gabe Black 2011-11-14 19:24:14 +00:00 committed by Graeme Russ
parent 36b2409a3d
commit dd4a5b2246

View File

@ -32,7 +32,7 @@ extern u8 gt_cpcidvi_in8(u32 offset);
extern void gt_cpcidvi_out8(u32 offset, u8 data); extern void gt_cpcidvi_out8(u32 offset, u8 data);
#define in8(a) gt_cpcidvi_in8(a) #define in8(a) gt_cpcidvi_in8(a)
#define out8(a, b) gt_cpcidvi_out8(a,b) #define out8(a, b) gt_cpcidvi_out8(a, b)
#endif #endif
#include <i8042.h> #include <i8042.h>
@ -40,9 +40,9 @@ extern void gt_cpcidvi_out8(u32 offset, u8 data);
/* defines */ /* defines */
#ifdef CONFIG_CONSOLE_CURSOR #ifdef CONFIG_CONSOLE_CURSOR
extern void console_cursor (int state); extern void console_cursor(int state);
static int blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT; static int blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
static int cursor_state = 0; static int cursor_state;
#endif #endif
/* locals */ /* locals */
@ -50,22 +50,22 @@ static int cursor_state = 0;
static int kbd_input = -1; /* no input yet */ static int kbd_input = -1; /* no input yet */
static int kbd_mapping = KBD_US; /* default US keyboard */ static int kbd_mapping = KBD_US; /* default US keyboard */
static int kbd_flags = NORMAL; /* after reset */ static int kbd_flags = NORMAL; /* after reset */
static int kbd_state = 0; /* unshift code */ static int kbd_state; /* unshift code */
static void kbd_conv_char (unsigned char scan_code); static void kbd_conv_char(unsigned char scan_code);
static void kbd_led_set (void); static void kbd_led_set(void);
static void kbd_normal (unsigned char scan_code); static void kbd_normal(unsigned char scan_code);
static void kbd_shift (unsigned char scan_code); static void kbd_shift(unsigned char scan_code);
static void kbd_ctrl (unsigned char scan_code); static void kbd_ctrl(unsigned char scan_code);
static void kbd_num (unsigned char scan_code); static void kbd_num(unsigned char scan_code);
static void kbd_caps (unsigned char scan_code); static void kbd_caps(unsigned char scan_code);
static void kbd_scroll (unsigned char scan_code); static void kbd_scroll(unsigned char scan_code);
static void kbd_alt (unsigned char scan_code); static void kbd_alt(unsigned char scan_code);
static int kbd_input_empty (void); static int kbd_input_empty(void);
static int kbd_reset (void); static int kbd_reset(void);
static unsigned char kbd_fct_map [144] = static unsigned char kbd_fct_map[144] = {
{ /* kbd_fct_map table for scan code */ /* kbd_fct_map table for scan code */
0, AS, AS, AS, AS, AS, AS, AS, /* scan 0- 7 */ 0, AS, AS, AS, AS, AS, AS, AS, /* scan 0- 7 */
AS, AS, AS, AS, AS, AS, AS, AS, /* scan 8- F */ AS, AS, AS, AS, AS, AS, AS, AS, /* scan 8- F */
AS, AS, AS, AS, AS, AS, AS, AS, /* scan 10-17 */ AS, AS, AS, AS, AS, AS, AS, AS, /* scan 10-17 */
@ -86,8 +86,7 @@ static unsigned char kbd_fct_map [144] =
AS, EX, EX, AS, EX, AS, EX, EX /* enhanced */ AS, EX, EX, AS, EX, AS, EX, EX /* enhanced */
}; };
static unsigned char kbd_key_map [2][5][144] = static unsigned char kbd_key_map[2][5][144] = {
{
{ /* US keyboard */ { /* US keyboard */
{ /* unshift code */ { /* unshift code */
0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */ 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */
@ -294,8 +293,7 @@ static unsigned char kbd_key_map [2][5][144] =
} }
}; };
static unsigned char ext_key_map [] = static unsigned char ext_key_map[] = {
{
0x1c, /* keypad enter */ 0x1c, /* keypad enter */
0x1d, /* right control */ 0x1d, /* right control */
0x35, /* keypad slash */ 0x35, /* keypad slash */
@ -319,30 +317,28 @@ static unsigned char ext_key_map [] =
* *
* i8042_kbd_init - reset keyboard and init state flags * i8042_kbd_init - reset keyboard and init state flags
*/ */
int i8042_kbd_init (void) int i8042_kbd_init(void)
{ {
int keymap, try; int keymap, try;
char *penv; char *penv;
#ifdef CONFIG_USE_CPCIDVI #ifdef CONFIG_USE_CPCIDVI
if ((penv = getenv ("console")) != NULL) { penv = getenv("console");
if (strncmp (penv, "serial", 7) == 0) { if (penv != NULL) {
if (strncmp(penv, "serial", 7) == 0)
return -1; return -1;
} }
}
#endif #endif
/* Init keyboard device (default US layout) */ /* Init keyboard device (default US layout) */
keymap = KBD_US; keymap = KBD_US;
if ((penv = getenv ("keymap")) != NULL) penv = getenv("keymap");
{ if (penv != NULL) {
if (strncmp (penv, "de", 3) == 0) if (strncmp(penv, "de", 3) == 0)
keymap = KBD_GER; keymap = KBD_GER;
} }
for (try = 0; try < KBD_RESET_TRIES; try++) for (try = 0; try < KBD_RESET_TRIES; try++) {
{ if (kbd_reset() == 0) {
if (kbd_reset() == 0)
{
kbd_mapping = keymap; kbd_mapping = keymap;
kbd_flags = NORMAL; kbd_flags = NORMAL;
kbd_state = 0; kbd_state = 0;
@ -359,25 +355,23 @@ int i8042_kbd_init (void)
* i8042_tstc - test if keyboard input is available * i8042_tstc - test if keyboard input is available
* option: cursor blinking if called in a loop * option: cursor blinking if called in a loop
*/ */
int i8042_tstc (void) int i8042_tstc(void)
{ {
unsigned char scan_code = 0; unsigned char scan_code = 0;
#ifdef CONFIG_CONSOLE_CURSOR #ifdef CONFIG_CONSOLE_CURSOR
if (--blinkCount == 0) if (--blinkCount == 0) {
{
cursor_state ^= 1; cursor_state ^= 1;
console_cursor (cursor_state); console_cursor(cursor_state);
blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT; blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
udelay (10); udelay(10);
} }
#endif #endif
if ((in8 (I8042_STATUS_REG) & 0x01) == 0) if ((in8(I8042_STATUS_REG) & 0x01) == 0) {
return 0; return 0;
else } else {
{ scan_code = in8(I8042_DATA_REG);
scan_code = in8 (I8042_DATA_REG);
if (scan_code == 0xfa) if (scan_code == 0xfa)
return 0; return 0;
@ -395,28 +389,23 @@ int i8042_tstc (void)
* i8042_getc - wait till keyboard input is available * i8042_getc - wait till keyboard input is available
* option: turn on/off cursor while waiting * option: turn on/off cursor while waiting
*/ */
int i8042_getc (void) int i8042_getc(void)
{ {
int ret_chr; int ret_chr;
unsigned char scan_code; unsigned char scan_code;
while (kbd_input == -1) while (kbd_input == -1) {
{ while ((in8(I8042_STATUS_REG) & 0x01) == 0) {
while ((in8 (I8042_STATUS_REG) & 0x01) == 0)
{
#ifdef CONFIG_CONSOLE_CURSOR #ifdef CONFIG_CONSOLE_CURSOR
if (--blinkCount==0) if (--blinkCount == 0) {
{
cursor_state ^= 1; cursor_state ^= 1;
console_cursor (cursor_state); console_cursor(cursor_state);
blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT; blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT;
} }
udelay (10); udelay(10);
#endif #endif
} }
scan_code = in8(I8042_DATA_REG);
scan_code = in8 (I8042_DATA_REG);
if (scan_code != 0xfa) if (scan_code != 0xfa)
kbd_conv_char (scan_code); kbd_conv_char (scan_code);
} }
@ -428,10 +417,9 @@ int i8042_getc (void)
/******************************************************************************/ /******************************************************************************/
static void kbd_conv_char (unsigned char scan_code) static void kbd_conv_char(unsigned char scan_code)
{ {
if (scan_code == 0xe0) if (scan_code == 0xe0) {
{
kbd_flags |= EXT; kbd_flags |= EXT;
return; return;
} }
@ -442,10 +430,8 @@ static void kbd_conv_char (unsigned char scan_code)
else else
kbd_flags &= ~BRK; kbd_flags &= ~BRK;
if ((scan_code == 0xe1) || (kbd_flags & E1)) if ((scan_code == 0xe1) || (kbd_flags & E1)) {
{ if (scan_code == 0xe1) {
if (scan_code == 0xe1)
{
kbd_flags ^= BRK; /* reset the break flag */ kbd_flags ^= BRK; /* reset the break flag */
kbd_flags ^= E1; /* bitwise EXOR with E1 flag */ kbd_flags ^= E1; /* bitwise EXOR with E1 flag */
} }
@ -454,15 +440,12 @@ static void kbd_conv_char (unsigned char scan_code)
scan_code &= 0x7f; scan_code &= 0x7f;
if (kbd_flags & EXT) if (kbd_flags & EXT) {
{
int i; int i;
kbd_flags ^= EXT; kbd_flags ^= EXT;
for (i=0; ext_key_map[i]; i++) for (i = 0; ext_key_map[i]; i++) {
{ if (ext_key_map[i] == scan_code) {
if (ext_key_map[i] == scan_code)
{
scan_code = 0x80 + i; scan_code = 0x80 + i;
break; break;
} }
@ -472,21 +455,27 @@ static void kbd_conv_char (unsigned char scan_code)
return; return;
} }
switch (kbd_fct_map [scan_code]) switch (kbd_fct_map[scan_code]) {
{ case AS:
case AS: kbd_normal (scan_code); kbd_normal(scan_code);
break; break;
case SH: kbd_shift (scan_code); case SH:
kbd_shift(scan_code);
break; break;
case CN: kbd_ctrl (scan_code); case CN:
kbd_ctrl(scan_code);
break; break;
case NM: kbd_num (scan_code); case NM:
kbd_num(scan_code);
break; break;
case CP: kbd_caps (scan_code); case CP:
kbd_caps(scan_code);
break; break;
case ST: kbd_scroll (scan_code); case ST:
kbd_scroll(scan_code);
break; break;
case AK: kbd_alt (scan_code); case AK:
kbd_alt(scan_code);
break; break;
} }
return; return;
@ -495,21 +484,18 @@ static void kbd_conv_char (unsigned char scan_code)
/******************************************************************************/ /******************************************************************************/
static void kbd_normal (unsigned char scan_code) static void kbd_normal(unsigned char scan_code)
{ {
unsigned char chr; unsigned char chr;
if ((kbd_flags & BRK) == NORMAL) if ((kbd_flags & BRK) == NORMAL) {
{ chr = kbd_key_map[kbd_mapping][kbd_state][scan_code];
chr = kbd_key_map [kbd_mapping][kbd_state][scan_code];
if ((chr == 0xff) || (chr == 0x00)) if ((chr == 0xff) || (chr == 0x00))
{
return; return;
}
/* if caps lock convert upper to lower */ /* if caps lock convert upper to lower */
if (((kbd_flags & CAPS) == CAPS) && (chr >= 'a' && chr <= 'z')) if (((kbd_flags & CAPS) == CAPS) &&
{ (chr >= 'a' && chr <= 'z')) {
chr -= 'a' - 'A'; chr -= 'a' - 'A';
} }
kbd_input = chr; kbd_input = chr;
@ -519,15 +505,12 @@ static void kbd_normal (unsigned char scan_code)
/******************************************************************************/ /******************************************************************************/
static void kbd_shift (unsigned char scan_code) static void kbd_shift(unsigned char scan_code)
{ {
if ((kbd_flags & BRK) == BRK) if ((kbd_flags & BRK) == BRK) {
{
kbd_state = AS; kbd_state = AS;
kbd_flags &= (~SHIFT); kbd_flags &= (~SHIFT);
} } else {
else
{
kbd_state = SH; kbd_state = SH;
kbd_flags |= SHIFT; kbd_flags |= SHIFT;
} }
@ -536,15 +519,12 @@ static void kbd_shift (unsigned char scan_code)
/******************************************************************************/ /******************************************************************************/
static void kbd_ctrl (unsigned char scan_code) static void kbd_ctrl(unsigned char scan_code)
{ {
if ((kbd_flags & BRK) == BRK) if ((kbd_flags & BRK) == BRK) {
{
kbd_state = AS; kbd_state = AS;
kbd_flags &= (~CTRL); kbd_flags &= (~CTRL);
} } else {
else
{
kbd_state = CN; kbd_state = CN;
kbd_flags |= CTRL; kbd_flags |= CTRL;
} }
@ -553,37 +533,34 @@ static void kbd_ctrl (unsigned char scan_code)
/******************************************************************************/ /******************************************************************************/
static void kbd_caps (unsigned char scan_code) static void kbd_caps(unsigned char scan_code)
{ {
if ((kbd_flags & BRK) == NORMAL) if ((kbd_flags & BRK) == NORMAL) {
{
kbd_flags ^= CAPS; kbd_flags ^= CAPS;
kbd_led_set (); /* update keyboard LED */ kbd_led_set(); /* update keyboard LED */
} }
} }
/******************************************************************************/ /******************************************************************************/
static void kbd_num (unsigned char scan_code) static void kbd_num(unsigned char scan_code)
{ {
if ((kbd_flags & BRK) == NORMAL) if ((kbd_flags & BRK) == NORMAL) {
{
kbd_flags ^= NUM; kbd_flags ^= NUM;
kbd_state = (kbd_flags & NUM) ? AS : NM; kbd_state = (kbd_flags & NUM) ? AS : NM;
kbd_led_set (); /* update keyboard LED */ kbd_led_set(); /* update keyboard LED */
} }
} }
/******************************************************************************/ /******************************************************************************/
static void kbd_scroll (unsigned char scan_code) static void kbd_scroll(unsigned char scan_code)
{ {
if ((kbd_flags & BRK) == NORMAL) if ((kbd_flags & BRK) == NORMAL) {
{
kbd_flags ^= STP; kbd_flags ^= STP;
kbd_led_set (); /* update keyboard LED */ kbd_led_set(); /* update keyboard LED */
if (kbd_flags & STP) if (kbd_flags & STP)
kbd_input = 0x13; kbd_input = 0x13;
else else
@ -593,15 +570,12 @@ static void kbd_scroll (unsigned char scan_code)
/******************************************************************************/ /******************************************************************************/
static void kbd_alt (unsigned char scan_code) static void kbd_alt(unsigned char scan_code)
{ {
if ((kbd_flags & BRK) == BRK) if ((kbd_flags & BRK) == BRK) {
{
kbd_state = AS; kbd_state = AS;
kbd_flags &= (~ALT); kbd_flags &= (~ALT);
} } else {
else
{
kbd_state = AK; kbd_state = AK;
kbd_flags &= ALT; kbd_flags &= ALT;
} }
@ -610,23 +584,23 @@ static void kbd_alt (unsigned char scan_code)
/******************************************************************************/ /******************************************************************************/
static void kbd_led_set (void) static void kbd_led_set(void)
{ {
kbd_input_empty(); kbd_input_empty();
out8 (I8042_DATA_REG, 0xed); /* SET LED command */ out8(I8042_DATA_REG, 0xed); /* SET LED command */
kbd_input_empty(); kbd_input_empty();
out8 (I8042_DATA_REG, (kbd_flags & 0x7)); /* LED bits only */ out8(I8042_DATA_REG, (kbd_flags & 0x7)); /* LED bits only */
} }
/******************************************************************************/ /******************************************************************************/
static int kbd_input_empty (void) static int kbd_input_empty(void)
{ {
int kbdTimeout = KBD_TIMEOUT; int kbdTimeout = KBD_TIMEOUT;
/* wait for input buf empty */ /* wait for input buf empty */
while ((in8 (I8042_STATUS_REG) & 0x02) && kbdTimeout--) while ((in8(I8042_STATUS_REG) & 0x02) && kbdTimeout--)
udelay(1000); udelay(1000);
return kbdTimeout; return kbdTimeout;
@ -634,12 +608,12 @@ static int kbd_input_empty (void)
/******************************************************************************/ /******************************************************************************/
static int kbd_reset (void) static int kbd_reset(void)
{ {
if (kbd_input_empty() == 0) if (kbd_input_empty() == 0)
return -1; return -1;
out8 (I8042_DATA_REG, 0xff); out8(I8042_DATA_REG, 0xff);
udelay(250000); udelay(250000);
@ -647,21 +621,21 @@ static int kbd_reset (void)
return -1; return -1;
#ifdef CONFIG_USE_CPCIDVI #ifdef CONFIG_USE_CPCIDVI
out8 (I8042_COMMAND_REG, 0x60); out8(I8042_COMMAND_REG, 0x60);
#else #else
out8 (I8042_DATA_REG, 0x60); out8(I8042_DATA_REG, 0x60);
#endif #endif
if (kbd_input_empty() == 0) if (kbd_input_empty() == 0)
return -1; return -1;
out8 (I8042_DATA_REG, 0x45); out8(I8042_DATA_REG, 0x45);
if (kbd_input_empty() == 0) if (kbd_input_empty() == 0)
return -1; return -1;
out8 (I8042_COMMAND_REG, 0xae); out8(I8042_COMMAND_REG, 0xae);
if (kbd_input_empty() == 0) if (kbd_input_empty() == 0)
return -1; return -1;