x86: superio: Add keyboard controller support to smsc_lpc47m driver
Subsystems (4)
PATCH v2 1/7 x86: superio: Add keyboard controller support to smsc_lpc47m driver
Add an api to enable and configure the integrated keyboard controller on SMSC LPC47m superio chipset. It also adds several macros to help future extension.
---
Changes in v2:
- Change parameter type to uint
arch/x86/include/asm/ibmpc.h | 3 +++ drivers/misc/smsc_lpc47m.c | 13 ++++++++++++- include/smsc_lpc47m.h | 29 +++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 5 deletions(-)
arch/x86/include/asm/ibmpc.h +3 -0
@@ -24,4 +24,7 @@#define UART0_IRQ 4#define UART1_IRQ 3 +#define KBD_IRQ 1 +#define MSE_IRQ 12 +#endif
drivers/misc/smsc_lpc47m.c +12 -1
@@ -22,7 +22,7 @@ static void pnp_exit_conf_state(u16 dev)outb (0xaa , port); } -void lpc47m_enable_serial (u16 dev,u16 iobase,u8 irq) +void lpc47m_enable_serial (uint dev,uint iobase,uint irq) {pnp_enter_conf_state (dev);pnp_set_logical_device (dev);
@@ -32,3 +32,14 @@ void lpc47m_enable_serial(u16 dev, u16 iobase, u8 irq)pnp_set_enable (dev,1 );pnp_exit_conf_state (dev); } + +void lpc47m_enable_kbc (uint dev,uint irq0,uint irq1) +{ +pnp_enter_conf_state (dev); +pnp_set_logical_device (dev); +pnp_set_enable (dev,0 ); +pnp_set_irq (dev,PNP_IDX_IRQ0 , irq0); +pnp_set_irq (dev,PNP_IDX_IRQ1 , irq1); +pnp_set_enable (dev,1 ); +pnp_exit_conf_state (dev); +}
include/smsc_lpc47m.h +25 -4
@@ -7,14 +7,35 @@#ifndef _SMSC_LPC47M_H_#define _SMSC_LPC47M_H_ +/* I/O address of LPC47M */ +#define LPC47M_IO_PORT 0x2e + +/* Logical device number */ +#define LPC47M_FDC 0/* Floppy */ +#define LPC47M_SP2 2/* Serial Port 2 */ +#define LPC47M_PP 3/* Parallel Port */ +#define LPC47M_SP1 4/* Serial Port 1 */ +#define LPC47M_KBC 7/* Keyboard & Mouse */ +#define LPC47M_PME 10/* Power Control */ +/** * Configure the base I/O port of the specified serial device and enable the * serial device. * -* @dev: High 8 bits = Super I/O port, low 8 bits = logical device number. -* @iobase: Processor I/O port address to assign to this serial device. -* @irq: Processor IRQ number to assign to this serial device. +* @dev: high 8 bits = super I/O port, low 8 bits = logical device number +* @iobase: processor I/O port address to assign to this serial device +* @irq: processor IRQ number to assign to this serial device +*/ +void lpc47m_enable_serial (uint dev,uint iobase,uint irq); + +/** +* Configure the specified keyboard controller device and enable the keyboard +* controller device. +* +* @dev: high 8 bits = Super I/O port, low 8 bits = logical device number +* @irq0: processor IRQ number to assign to keyboard +* @irq1: processor IRQ number to assign to mouse */ -void lpc47m_enable_serial (u16 dev,u16 iobase,u8 irq); +void lpc47m_enable_kbc (uint dev,uint irq0,uint irq1);#endif /* _SMSC_LPC47M_H_ */
Signature · 1 line
1.8.2.1
PATCH v2 2/7 x86: i8042: Remove unused codes
- Remove unused routines i8042_flush() and i8042_disable()
- Remove unused CONFIG_USE_CPCIDVI wrapped codes
- Remove __weak board_i8042_skip()
---
Changes in v2:
- Split the removing of unused codes into this patch
drivers/input/i8042.c | 67 +-------------------------------------------------- include/i8042.h | 13 ---------- 2 files changed, 1 insertion(+), 79 deletions(-)
drivers/input/i8042.c +1 -66
@@ -10,16 +10,6 @@/* includes */ #include <common.h> -#include <linux/compiler.h> - -#ifdef CONFIG_USE_CPCIDVI -extern u8 gt_cpcidvi_in8 (u32 offset); -extern void gt_cpcidvi_out8 (u32 offset,u8 data); - -#define in8 (a) gt_cpcidvi_in8(a) -#define out8 (a, b) gt_cpcidvi_out8(a, b) -#endif -#include <i8042.h> /* defines */
@@ -305,54 +295,6 @@ static int kbd_controller_present(void)return in8 (I8042_STATUS_REG ) !=0xff ; } -/* -* Implement a weak default function for boards that optionally -* need to skip the i8042 initialization. -*/ -int __weak board_i8042_skip (void ) -{ -/* As default, don't skip */ -return 0 ; -} - -void i8042_flush (void ) -{ -int timeout; - -/* -* The delay is to give the keyboard controller some time to fill the -* next byte. -*/ -while (1 ) { - timeout =100 ;/* wait for no longer than 100us */ -while (timeout >0 && !(in8 (I8042_STATUS_REG ) &0x01 )) { -udelay (1 ); - timeout--; - } - -/* Try to pull next byte if not timeout. */ -if (in8 (I8042_STATUS_REG ) &0x01 ) -in8 (I8042_DATA_REG ); -else -break ; - } -} - -int i8042_disable (void ) -{ -if (kbd_input_empty () ==0 ) -return -1 ; - -/* Disable keyboard */ -out8 (I8042_COMMAND_REG ,0xad ); - -if (kbd_input_empty () ==0 ) -return -1 ; - -return 0 ; -} - -/******************************************************************************* * * i8042_kbd_init - reset keyboard and init state flags
@@ -362,16 +304,9 @@ int i8042_kbd_init(void)int keymap, try;char *penv; -if (!kbd_controller_present () ||board_i8042_skip ()) +if (!kbd_controller_present ())return -1 ; -#ifdef CONFIG_USE_CPCIDVI - penv =getenv ("console" ); -if (penv !=NULL ) { -if (strncmp (penv,"serial" ,7 ) ==0 ) -return -1 ; - } -#endif /* Init keyboard device (default US layout) */ keymap =KBD_US ; penv =getenv ("keymap" );
include/i8042.h +0 -13
@@ -59,19 +59,6 @@ enum {/* exports */ -/** -* Flush all buffer from keyboard controller to host. -*/ -void i8042_flush (void ); - -/** -* Disables the keyboard so that key strokes no longer generate scancodes to -* the host. -* -* @return 0 if ok, -1 if keyboard input was found while disabling -*/ -int i8042_disable (void ); -struct stdio_dev ;int i8042_kbd_init (void );
Signature · 1 line
1.8.2.1
PATCH v2 3/7 x86: i8042: Reorder static functions
In reply to Bin MengReorder those static function so that their declarations can be removed.
---
Changes in v2:
- Split of reordering static functions into this patch
drivers/input/i8042.c | 417 ++++++++++++++++++++++---------------------------- 1 file changed, 186 insertions(+), 231 deletions(-)
drivers/input/i8042.c +186 -231
@@ -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; +}
Signature · 1 line
1.8.2.1
PATCH v2 4/7 x86: i8042: Clean up the driver per coding convention
In reply to Bin Meng- Rename CamelCase variables to conform U-Boot coding convention
- Rename wait_until_kbd_output_full() to kbd_output_full()
- Change to use macros for i8042 command and control register bits
---
Changes in v2:
- Split the original single patch into 3 patches
drivers/input/i8042.c | 216 ++++++++++++++++++++++++++------------------------ include/i8042.h | 102 ++++++++++++++---------- 2 files changed, 169 insertions(+), 149 deletions(-)
drivers/input/i8042.c +111 -105
@@ -10,27 +10,30 @@/* includes */ #include <common.h> +#include <asm/io.h> #include <i8042.h> /* defines */ +#define in8 (p) inb(p) +#define out8 (p, v) outb(v, p)#ifdef CONFIG_CONSOLE_CURSOR extern void console_cursor (int state); -static int blinkCount =CONFIG_SYS_CONSOLE_BLINK_COUNT ; +static int blink_count =CONFIG_SYS_CONSOLE_BLINK_COUNT ;static int cursor_state;#endif /* locals */ -static int kbd_input =-1 ;/* no input yet */ -static int kbd_mapping =KBD_US ;/* default US keyboard */ -static int kbd_flags =NORMAL ;/* after reset */ -static int kbd_state;/* unshift code */ +static int kbd_input =-1 ;/* no input yet */ +static int kbd_mapping =KBD_US ;/* default US keyboard */ +static int kbd_flags =NORMAL ;/* after reset */ +static int kbd_state;/* unshift code */ 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 */ -AS ,AS ,AS ,AS ,AS ,AS ,AS ,AS ,/* scan 8- F */ +0 ,AS ,AS ,AS ,AS ,AS ,AS ,AS ,/* scan 00-07 */ +AS ,AS ,AS ,AS ,AS ,AS ,AS ,AS ,/* scan 08-0F */ AS ,AS ,AS ,AS ,AS ,AS ,AS ,AS ,/* scan 10-17 */ AS ,AS ,AS ,AS ,AS ,CN ,AS ,AS ,/* scan 18-1F */ AS ,AS ,AS ,AS ,AS ,AS ,AS ,AS ,/* scan 20-27 */
@@ -52,8 +55,8 @@ static unsigned char kbd_fct_map[144] = {static unsigned char kbd_key_map[2 ][5 ][144 ] = { {/* US keyboard */ {/* unshift code */ -0 ,0x1b ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,/* scan 0- 7 */ -'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,0x08 ,'\t' ,/* scan 8- F */ +0 ,0x1b ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,/* scan 00-07 */ +'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,0x08 ,'\t' ,/* scan 08-0F */ 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,/* scan 10-17 */ 'o' ,'p' ,'[' ,']' ,'\r' ,CN ,'a' ,'s' ,/* scan 18-1F */ 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,/* scan 20-27 */
@@ -72,8 +75,8 @@ static unsigned char kbd_key_map[2][5][144] = {0 ,'D' ,'C' ,0 ,'B' ,0 ,'@' ,'P' /* extended */ }, { /* shift code */ -0 ,0x1b ,'!' ,'@' ,'#' ,'$' ,'%' ,'^' ,/* scan 0- 7 */ -'&' ,'*' ,'(' ,')' ,'_' ,'+' ,0x08 ,'\t' ,/* scan 8- F */ +0 ,0x1b ,'!' ,'@' ,'#' ,'$' ,'%' ,'^' ,/* scan 00-07 */ +'&' ,'*' ,'(' ,')' ,'_' ,'+' ,0x08 ,'\t' ,/* scan 08-0F */ 'Q' ,'W' ,'E' ,'R' ,'T' ,'Y' ,'U' ,'I' ,/* scan 10-17 */ 'O' ,'P' ,'{' ,'}' ,'\r' ,CN ,'A' ,'S' ,/* scan 18-1F */ 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', /* scan 20-27 */
@@ -92,8 +95,8 @@ static unsigned char kbd_key_map[2][5][144] = {0 ,'D' ,'C' ,0 ,'B' ,0 ,'@' ,'P' /* extended */ }, { /* control code */ -0xff ,0x1b ,0xff ,0x00 ,0xff ,0xff ,0xff ,0xff ,/* scan 0- 7 */ -0x1e ,0xff ,0xff ,0xff ,0x1f ,0xff ,0xff ,'\t' ,/* scan 8- F */ +0xff ,0x1b ,0xff ,0x00 ,0xff ,0xff ,0xff ,0xff ,/* scan 00-07 */ +0x1e ,0xff ,0xff ,0xff ,0x1f ,0xff ,0xff ,'\t' ,/* scan 08-0F */ 0x11 ,0x17 ,0x05 ,0x12 ,0x14 ,0x19 ,0x15 ,0x09 ,/* scan 10-17 */ 0x0f ,0x10 ,0x1b ,0x1d ,'\r' ,CN ,0x01 ,0x13 ,/* scan 18-1F */ 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */
@@ -112,8 +115,8 @@ static unsigned char kbd_key_map[2][5][144] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff /* extended */ }, { /* non numeric code */ -0 ,0x1b ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,/* scan 0- 7 */ -'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,0x08 ,'\t' ,/* scan 8- F */ +0 ,0x1b ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,/* scan 00-07 */ +'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,0x08 ,'\t' ,/* scan 08-0F */ 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,/* scan 10-17 */ 'o' ,'p' ,'[' ,']' ,'\r' ,CN ,'a' ,'s' ,/* scan 18-1F */ 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */
@@ -132,30 +135,30 @@ static unsigned char kbd_key_map[2][5][144] = {0 ,'D' ,'C' ,0 ,'B' ,0 ,'@' ,'P' /* extended */ }, { /* right alt mode - not used in US keyboard */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 0 - 7 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 8 - F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 10 -17 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 18 -1F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 20 -27 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 28 -2F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 30 -37 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 38 -3F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 40 -47 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 48 -4F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 50 -57 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 58 -5F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 60 -67 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 68 -6F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 70 -77 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 78 -7F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 00-07 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 08-0F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 10-17 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 18-1F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 20-27 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 28-2F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 30-37 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 38-3F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 40-47 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 48-4F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 50-57 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 58-5F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 60-67 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 68-6F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 70-77 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 78-7F */ 0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* extended */ 0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff /* extended */ } }, - { /* german keyboard */ + { /* German keyboard */ { /* unshift code */ -0 ,0x1b ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,/* scan 0- 7 */ -'7' ,'8' ,'9' ,'0' ,0xe1 ,'\'' ,0x08 ,'\t' ,/* scan 8- F */ +0 ,0x1b ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,/* scan 00-07 */ +'7' ,'8' ,'9' ,'0' ,0xe1 ,'\'' ,0x08 ,'\t' ,/* scan 08-0F */ 'q' ,'w' ,'e' ,'r' ,'t' ,'z' ,'u' ,'i' ,/* scan 10-17 */ 'o' ,'p' ,0x81 ,'+' ,'\r' ,CN ,'a' ,'s' ,/* scan 18-1F */ 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */
@@ -174,8 +177,8 @@ static unsigned char kbd_key_map[2][5][144] = {0 ,'D' ,'C' ,0 ,'B' ,0 ,'@' ,'P' /* extended */ }, { /* shift code */ -0 ,0x1b ,'!' ,'"' ,0x15 ,'$' ,'%' ,'&' ,/* scan 0- 7 */ -'/' ,'(' ,')' ,'=' ,'?' ,'`' ,0x08 ,'\t' ,/* scan 8- F */ +0 ,0x1b ,'!' ,'"' ,0x15 ,'$' ,'%' ,'&' ,/* scan 00-07 */ +'/' ,'(' ,')' ,'=' ,'?' ,'`' ,0x08 ,'\t' ,/* scan 08-0F */ 'Q' ,'W' ,'E' ,'R' ,'T' ,'Z' ,'U' ,'I' ,/* scan 10-17 */ 'O' ,'P' ,0x9a ,'*' ,'\r' ,CN ,'A' ,'S' ,/* scan 18-1F */ 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0x99, /* scan 20-27 */
@@ -194,8 +197,8 @@ static unsigned char kbd_key_map[2][5][144] = {0 ,'D' ,'C' ,0 ,'B' ,0 ,'@' ,'P' /* extended */ }, { /* control code */ -0xff ,0x1b ,0xff ,0x00 ,0xff ,0xff ,0xff ,0xff ,/* scan 0- 7 */ -0x1e ,0xff ,0xff ,0xff ,0x1f ,0xff ,0xff ,'\t' ,/* scan 8- F */ +0xff ,0x1b ,0xff ,0x00 ,0xff ,0xff ,0xff ,0xff ,/* scan 00-07 */ +0x1e ,0xff ,0xff ,0xff ,0x1f ,0xff ,0xff ,'\t' ,/* scan 08-0F */ 0x11 ,0x17 ,0x05 ,0x12 ,0x14 ,0x19 ,0x15 ,0x09 ,/* scan 10-17 */ 0x0f ,0x10 ,0x1b ,0x1d ,'\r' ,CN ,0x01 ,0x13 ,/* scan 18-1F */ 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */
@@ -214,8 +217,8 @@ static unsigned char kbd_key_map[2][5][144] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff /* extended */ }, { /* non numeric code */ -0 ,0x1b ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,/* scan 0- 7 */ -'7' ,'8' ,'9' ,'0' ,0xe1 ,'\'' ,0x08 ,'\t' ,/* scan 8- F */ +0 ,0x1b ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,/* scan 00-07 */ +'7' ,'8' ,'9' ,'0' ,0xe1 ,'\'' ,0x08 ,'\t' ,/* scan 08-0F */ 'q' ,'w' ,'e' ,'r' ,'t' ,'z' ,'u' ,'i' ,/* scan 10-17 */ 'o' ,'p' ,0x81 ,'+' ,'\r' ,CN ,'a' ,'s' ,/* scan 18-1F */ 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */
@@ -233,23 +236,23 @@ static unsigned char kbd_key_map[2][5][144] = {'\r' ,CN ,'/' ,'*' ,' ' ,ST ,'F' ,'A' ,/* extended */ 0 ,'D' ,'C' ,0 ,'B' ,0 ,'@' ,'P' /* extended */ }, - { /* Right alt mode - is used in German keyboard */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 0 - 7 */ -'{' ,'[' ,']' ,'}' ,'\\' ,0xff ,0xff ,0xff ,/* scan 8 - F */ -'@' ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 10 -17 */ -0xff ,0xff ,0xff ,'~' ,0xff ,0xff ,0xff ,0xff ,/* scan 18 -1F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 20 -27 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 28 -2F */ -0xff ,0xff ,0xe6 ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 30 -37 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 38 -3F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 40 -47 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 48 -4F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,'|' ,0xff ,/* scan 50 -57 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 58 -5F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 60 -67 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 68 -6F */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 70 -77 */ -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 78 -7F */ + { /* right alt mode - is used in German keyboard */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 00-07 */ +'{' ,'[' ,']' ,'}' ,'\\' ,0xff ,0xff ,0xff ,/* scan 08-0F */ +'@' ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 10-17 */ +0xff ,0xff ,0xff ,'~' ,0xff ,0xff ,0xff ,0xff ,/* scan 18-1F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 20-27 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 28-2F */ +0xff ,0xff ,0xe6 ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 30-37 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 38-3F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 40-47 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 48-4F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,'|' ,0xff ,/* scan 50-57 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 58-5F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 60-67 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 68-6F */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 70-77 */ +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* scan 78-7F */ 0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,/* extended */ 0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff /* extended */ }
@@ -278,30 +281,30 @@ static unsigned char ext_key_map[] = {static int kbd_input_empty (void ) { -int kbdTimeout =KBD_TIMEOUT *1000 ; +int kbd_timeout =KBD_TIMEOUT *1000 ; -while ((in8 (I8042_STATUS_REG ) &I8042_STATUS_IN_DATA ) && kbdTimeout--) +while ((in8 (I8042_STS_REG ) &STATUS_IBF ) && kbd_timeout--)udelay (1 ); -return kbdTimeout !=-1 ; +return kbd_timeout !=-1 ; } -static int wait_until_kbd_output_full (void ) +static int kbd_output_full (void ) { -int kbdTimeout =KBD_TIMEOUT *1000 ; +int kbd_timeout =KBD_TIMEOUT *1000 ; -while (((in8 (I8042_STATUS_REG ) &0x01 ) ==0 ) && kbdTimeout--) +while (((in8 (I8042_STS_REG ) &STATUS_OBF ) ==0 ) && kbd_timeout--)udelay (1 ); -return kbdTimeout !=-1 ; +return kbd_timeout !=-1 ; }static void kbd_led_set (void ) {kbd_input_empty (); -out8 (I8042_DATA_REG ,0xed );/* SET LED command */ +out8 (I8042_DATA_REG ,CMD_SET_KBD_LED );kbd_input_empty (); -out8 (I8042_DATA_REG , (kbd_flags &0x7 ));/* LED bits only */ +out8 (I8042_DATA_REG , (kbd_flags &0x7 )); }static void kbd_normal (unsigned char scan_code)
@@ -315,7 +318,7 @@ static void kbd_normal(unsigned char scan_code)/* if caps lock convert upper to lower */ if (((kbd_flags &CAPS ) ==CAPS ) && - (chr >='a' && chr <='z' )) { + (chr >='a' && chr <='z' )) { chr -='a' -'A' ; } kbd_input = chr;
@@ -349,7 +352,7 @@ static void kbd_num(unsigned char scan_code)if ((kbd_flags &BRK ) ==NORMAL ) { kbd_flags ^=NUM ; kbd_state = (kbd_flags &NUM ) ?AS :NM ; -kbd_led_set ();/* update keyboard LED */ +kbd_led_set (); } }
@@ -368,7 +371,7 @@ static void kbd_caps(unsigned char scan_code) {if ((kbd_flags &BRK ) ==NORMAL ) { kbd_flags ^=CAPS ; -kbd_led_set ();/* update keyboard LED */ +kbd_led_set (); } }
@@ -376,7 +379,7 @@ static void kbd_scroll(unsigned char scan_code) {if ((kbd_flags &BRK ) ==NORMAL ) { kbd_flags ^=STP ; -kbd_led_set ();/* update keyboard LED */ +kbd_led_set ();if (kbd_flags &STP ) kbd_input =0x13 ;else
@@ -399,8 +402,8 @@ static void kbd_conv_char(unsigned char scan_code)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 */ + kbd_flags ^=BRK ;/* reset the break flag */ + kbd_flags ^=E1 ;/* bitwise EXOR with E1 flag */ }return ; }
@@ -445,55 +448,57 @@ static void kbd_conv_char(unsigned char scan_code)kbd_scroll (scan_code);break ; } +return ; } -/******************************************************************************/ -static int kbd_reset (void ) {/* KB Reset */ if (kbd_input_empty () ==0 )return -1 ; -out8 (I8042_DATA_REG ,0xff ); +out8 (I8042_DATA_REG ,CMD_RESET_KBD ); -if (wait_until_kbd_output_full () ==0 ) +if (kbd_output_full () ==0 )return -1 ; -if (in8 (I8042_DATA_REG ) !=0xfa )/* ACK */ +if (in8 (I8042_DATA_REG ) !=KBD_ACK )return -1 ; -if (wait_until_kbd_output_full () ==0 ) +if (kbd_output_full () ==0 )return -1 ; -if (in8 (I8042_DATA_REG ) !=0xaa )/* Test Pass*/ +if (in8 (I8042_DATA_REG ) !=KBD_POR )return -1 ;if (kbd_input_empty () ==0 )return -1 ;/* Set KBC mode */ -out8 (I8042_COMMAND_REG ,0x60 ); +out8 (I8042_CMD_REG ,CMD_WR_CONFIG );if (kbd_input_empty () ==0 )return -1 ; -out8 (I8042_DATA_REG ,0x45 ); +out8 (I8042_DATA_REG , +CONFIG_AT_TRANS |CONFIG_SET_BIST |CONFIG_KIRQ_EN );if (kbd_input_empty () ==0 )return -1 ;/* Enable Keyboard */ -out8 (I8042_COMMAND_REG ,0xae ); +out8 (I8042_CMD_REG ,CMD_KBD_EN );if (kbd_input_empty () ==0 )return -1 ; -out8 (I8042_COMMAND_REG ,0x60 ); +out8 (I8042_CMD_REG ,CMD_WR_CONFIG );if (kbd_input_empty () ==0 )return -1 ; -out8 (I8042_DATA_REG ,0xf4 ); +out8 (I8042_DATA_REG , +CONFIG_AT_TRANS |CONFIG_MCLK_DIS | +CONFIG_KCLK_DIS |CONFIG_SET_BIST );if (kbd_input_empty () ==0 )return -1 ;
@@ -502,20 +507,19 @@ static int kbd_reset(void)static int kbd_controller_present (void ) { -return in8 (I8042_STATUS_REG ) !=0xff ; +return in8 (I8042_STS_REG ) !=0xff ; } -/******************************************************************************* -* -* i8042_kbd_init - reset keyboard and init state flags -*/ +/* i8042_kbd_init - reset keyboard and init state flags */ int i8042_kbd_init (void ) {int keymap, try;char *penv; -if (!kbd_controller_present ()) +if (!kbd_controller_present ()) { +debug ("i8042 keyboard controller is not present\n" );return -1 ; + }/* Init keyboard device (default US layout) */ keymap =KBD_US ;
@@ -531,32 +535,33 @@ int i8042_kbd_init(void) 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 +* +* 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 ) { +if (--blink_count ==0 ) { cursor_state ^=1 ;console_cursor (cursor_state); - blinkCount =CONFIG_SYS_CONSOLE_BLINK_COUNT ; + blink_count =CONFIG_SYS_CONSOLE_BLINK_COUNT ;udelay (10 ); }#endif -if ((in8 (I8042_STATUS_REG ) &0x01 ) ==0 ) { +if ((in8 (I8042_STS_REG ) &STATUS_OBF ) ==0 ) {return 0 ; }else { scan_code =in8 (I8042_DATA_REG );
@@ -568,14 +573,14 @@ int i8042_tstc(struct stdio_dev *dev)if (kbd_input !=-1 )return 1 ; } +return 0 ; } - -/******************************************************************************* -* +/* * 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 (struct stdio_dev *dev) {
@@ -583,21 +588,22 @@ int i8042_getc(struct stdio_dev *dev)unsigned char scan_code;while (kbd_input ==-1 ) { -while ((in8 (I8042_STATUS_REG ) &0x01 ) ==0 ) { +while ((in8 (I8042_STS_REG ) &STATUS_OBF ) ==0 ) {#ifdef CONFIG_CONSOLE_CURSOR -if (--blinkCount ==0 ) { +if (--blink_count ==0 ) { cursor_state ^=1 ;console_cursor (cursor_state); - blinkCount =CONFIG_SYS_CONSOLE_BLINK_COUNT ; + blink_count =CONFIG_SYS_CONSOLE_BLINK_COUNT ; }udelay (10 );#endif } scan_code =in8 (I8042_DATA_REG );if (scan_code !=0xfa ) -kbd_conv_char (scan_code); +kbd_conv_char (scan_code); } ret_chr = kbd_input; kbd_input =-1 ; +return ret_chr; }
include/i8042.h +58 -44
110 lines not on this page · raw message
Signature · 1 line
1.8.2.1
PATCH v2 5/7 x86: i8042: Correctly initialize the controller
In reply to Bin MengThe existing i8042 keyboard controller driver has some issues. First of all, it does not issue a self-test command (0xaa) to the controller at the very beginning. Without this, the controller does not respond any command at all. Secondly, it initializes the configuration byte reigster to turn on keyboard's interrupt, which is not allowed as U-Boot we don't normally enable interrupt. Finally, at the end of the initialization routine, it wrongly sets the controller to disable all interfaces including both keyboard and mouse.
---
Changes in v2:
- Reorder this patch to follow the i8042 driver clean up patches
drivers/input/i8042.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-)
drivers/input/i8042.c +21 -22
@@ -454,51 +454,50 @@ static void kbd_conv_char(unsigned char scan_code)static int kbd_reset (void ) { -/* KB Reset */ +u8 config; + +/* controller self test */ if (kbd_input_empty () ==0 )return -1 ; +out8 (I8042_CMD_REG ,CMD_SELF_TEST ); +if (kbd_output_full () ==0 ) +return -1 ; +if (in8 (I8042_DATA_REG ) !=KBC_TEST_OK ) +return -1 ; +/* keyboard reset */ +if (kbd_input_empty () ==0 ) +return -1 ;out8 (I8042_DATA_REG ,CMD_RESET_KBD ); -if (kbd_output_full () ==0 )return -1 ; -if (in8 (I8042_DATA_REG ) !=KBD_ACK )return -1 ; -if (kbd_output_full () ==0 )return -1 ; -if (in8 (I8042_DATA_REG ) !=KBD_POR )return -1 ; +/* set AT translation and disable irq */ if (kbd_input_empty () ==0 )return -1 ; - -/* Set KBC mode */ -out8 (I8042_CMD_REG ,CMD_WR_CONFIG ); - -if (kbd_input_empty () ==0 ) +out8 (I8042_CMD_REG ,CMD_RD_CONFIG ); +if (kbd_output_full () ==0 )return -1 ; - -out8 (I8042_DATA_REG , -CONFIG_AT_TRANS |CONFIG_SET_BIST |CONFIG_KIRQ_EN ); - + config =in8 (I8042_DATA_REG ); + config |=CONFIG_AT_TRANS ; + config &= ~(CONFIG_KIRQ_EN |CONFIG_MIRQ_EN );if (kbd_input_empty () ==0 )return -1 ; - -/* Enable Keyboard */ -out8 (I8042_CMD_REG ,CMD_KBD_EN ); +out8 (I8042_CMD_REG ,CMD_WR_CONFIG );if (kbd_input_empty () ==0 )return -1 ; +out8 (I8042_DATA_REG , config); -out8 (I8042_CMD_REG ,CMD_WR_CONFIG ); +/* enable keyboard */ if (kbd_input_empty () ==0 )return -1 ; - -out8 (I8042_DATA_REG , -CONFIG_AT_TRANS |CONFIG_MCLK_DIS | -CONFIG_KCLK_DIS |CONFIG_SET_BIST ); +out8 (I8042_CMD_REG ,CMD_KBD_EN );if (kbd_input_empty () ==0 )return -1 ;
Signature · 1 line
1.8.2.1
PATCH v2 6/7 video: cfb_console: Allow VGA device to work without i8042 keyboard
In reply to Bin MengSo far if CONFIG_VGA_AS_SINGLE_DEVICE is not defined, the VGA device will try to initialize a keyboard device (for x86, it is i8042). But if i8042 controller initialization fails (eg: there is no keyboard connected to the PS/2 port), drv_video_init() just simply returns. This kills the opportunity of using a usb keyboard later with the vga console, as the vga initialization part is actually ok, only keyboard part fails. Change the code logic to allow this.
---
In the long term, we should remove CONFIG_VGA_AS_SINGLE_DEVICE and treat the cfb_concole an output device only. The keyboard part should be moved out of cfb_console driver and be as a input device driver separately.
Changes in v2: None
drivers/video/cfb_console.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/video/cfb_console.c +5 -6
@@ -2247,16 +2247,17 @@ __weak int board_video_skip(void)int drv_video_init (void ) { -int skip_dev_init;struct stdio_dev console_dev;bool have_keyboard; +bool __maybe_unused keyboard_ok = false;/* Check if video initialization should be skipped */ if (board_video_skip ())return 0 ;/* Init video chip - returns with framebuffer cleared */ - skip_dev_init = (video_init () ==-1 ); +if (video_init () ==-1 ) +return 0 ;if (board_cfb_skip ())return 0 ;
@@ -2272,11 +2273,9 @@ int drv_video_init(void)if (have_keyboard) {debug ("KBD: Keyboard init ...\n" );#if !defined(CONFIG_VGA_AS_SINGLE_DEVICE ) - skip_dev_init |= (VIDEO_KBD_INIT_FCT ==-1 ); + keyboard_ok = !(VIDEO_KBD_INIT_FCT ==-1 );#endif } -if (skip_dev_init) -return 0 ;/* Init vga device */ memset (&console_dev,0 ,sizeof (console_dev));
@@ -2287,7 +2286,7 @@ int drv_video_init(void) console_dev.puts = video_puts;/* 'puts' function */ #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE ) -if (have_keyboard) { +if (have_keyboard && keyboard_ok) {/* Also init console device */ console_dev.flags |=DEV_FLAGS_INPUT ; console_dev.tstc =VIDEO_TSTC_FCT ;/* 'tstc' function */
Signature · 1 line
1.8.2.1
PATCH v2 7/7 x86: crownbay: Enable on-board SMSC superio keyboard controller
In reply to Bin MengSo far we only enabled one legacy serial port on the SMSC LPC47m superio chipset on Intel Crown Bay board. As the board also has dual PS/2 ports routed out, enable the keyboard controller which is i8042 compatible so that we can use PS/2 keyboard and mouse.
In order to make PS/2 keyboard work with the VGA console, remove CONFIG_VGA_AS_SINGLE_DEVICE. To boot Linux kernel with PIC mode using PIRQ routing table, adjust the mask in the device tree to reserve irq12 which is used by PS/2 mouse.
---
Changes in v2: None
arch/x86/dts/crownbay.dts | 2 +- board/intel/crownbay/crownbay.c | 7 ++++--- include/configs/crownbay.h | 3 --- 3 files changed, 5 insertions(+), 7 deletions(-)
arch/x86/dts/crownbay.dts +1 -1
@@ -168,7 +168,7 @@ compatible = "intel,irq-router"; intel,pirq-config = "pci"; intel,pirq-link = <0x60 8>; - intel,pirq-mask = <0xdee0>; + intel,pirq-mask = <0xcee0>; intel,pirq-routing = < /* TunnelCreek PCI devices */ PCI_BDF(0, 2, 0) INTA PIRQE
board/intel/crownbay/crownbay.c +4 -3
@@ -10,11 +10,12 @@#include <netdev.h> #include <smsc_lpc47m.h> -#define SERIAL_DEV PNP_DEV(0x2e, 4) -int board_early_init_f (void ) { -lpc47m_enable_serial (SERIAL_DEV ,UART0_BASE ,UART0_IRQ ); +lpc47m_enable_serial (PNP_DEV (LPC47M_IO_PORT ,LPC47M_SP1 ), +UART0_BASE ,UART0_IRQ ); +lpc47m_enable_kbc (PNP_DEV (LPC47M_IO_PORT ,LPC47M_KBC ), +KBD_IRQ ,MSE_IRQ );return 0 ; }
include/configs/crownbay.h +0 -3
@@ -54,9 +54,6 @@#define CONFIG_PCH_GBE #define CONFIG_PHYLIB -/* TunnelCreek IGD support */ -#define CONFIG_VGA_AS_SINGLE_DEVICE -/* Environment configuration */ #define CONFIG_ENV_SECT_SIZE 0x1000#define CONFIG_ENV_OFFSET 0
Signature · 1 line
1.8.2.1
PATCH v2 1/7 x86: superio: Add keyboard controller support to smsc_lpc47m driver
In reply to Bin MengHi Bin,
Quoted 8 lines · Bin Meng
Add an api to enable and configure the integrated keyboard controller on SMSC LPC47m superio chipset. It also adds several macros to help future extension.
Signed-off-by Bin Meng <[email protected]>---
Quoted 8 lines
Changes in v2:
- Change parameter type to uintarch/x86/include/asm/ibmpc.h | 3 +++ drivers/misc/smsc_lpc47m.c | 13 ++++++++++++- include/smsc_lpc47m.h | 29 +++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 5 deletions(-)
Quoted 17 lines
arch/x86/include/asm/ibmpc.h +3
-0@@ -24,4 +24,7 @@#define UART0_IRQ 4#define UART1_IRQ 3 +#define KBD_IRQ 1 +#define MSE_IRQ 12 +#endif drivers/misc/smsc_lpc47m.c +0
-0
drivers/misc/smsc_lpc47m.c static void pnp_exit_conf_state(u16 dev) · line 25
Quoted 5 lines
drivers/misc/smsc_lpc47m.c +1
-1@@ -22,7 +22,7 @@ static void pnp_exit_conf_state(u16 dev)outb (0xaa , port); } -void lpc47m_enable_serial (u16 dev,u16 iobase,u8 irq) +void lpc47m_enable_serial (uint dev,uint iobase,uint irq)
For future reference: I think a tidy-up patch should be separate from adding a new feature - i.e. this sort of patch should really be split into two. But it's only a minor point.
Quoted 63 lines
drivers/misc/smsc_lpc47m.c +11
-0{pnp_enter_conf_state (dev);pnp_set_logical_device (dev);@@ -32,3 +32,14 @@ void lpc47m_enable_serial(u16 dev, u16 iobase, u8 irq)pnp_set_enable (dev,1 );pnp_exit_conf_state (dev); } + +void lpc47m_enable_kbc (uint dev,uint irq0,uint irq1) +{ +pnp_enter_conf_state (dev); +pnp_set_logical_device (dev); +pnp_set_enable (dev,0 ); +pnp_set_irq (dev,PNP_IDX_IRQ0 , irq0); +pnp_set_irq (dev,PNP_IDX_IRQ1 , irq1); +pnp_set_enable (dev,1 ); +pnp_exit_conf_state (dev); +}include/smsc_lpc47m.h +25
-5@@ -7,14 +7,35 @@#ifndef _SMSC_LPC47M_H_#define _SMSC_LPC47M_H_ +/* I/O address of LPC47M */ +#define LPC47M_IO_PORT 0x2e + +/* Logical device number */ +#define LPC47M_FDC 0/* Floppy */ +#define LPC47M_SP2 2/* Serial Port 2 */ +#define LPC47M_PP 3/* Parallel Port */ +#define LPC47M_SP1 4/* Serial Port 1 */ +#define LPC47M_KBC 7/* Keyboard & Mouse */ +#define LPC47M_PME 10/* Power Control */ +/** * Configure the base I/O port of the specified serial device and enable the * serial device. * -* @dev: High 8 bits = Super I/O port, low 8 bits = logical device number. -* @iobase: Processor I/O port address to assign to this serial device. -* @irq: Processor IRQ number to assign to this serial device. +* @dev: high 8 bits = super I/O port, low 8 bits = logical device number +* @iobase: processor I/O port address to assign to this serial device +* @irq: processor IRQ number to assign to this serial device +*/ +void lpc47m_enable_serial (uint dev,uint iobase,uint irq); + +/** +* Configure the specified keyboard controller device and enable the keyboard +* controller device. +* +* @dev: high 8 bits = Super I/O port, low 8 bits = logical device number +* @irq0: processor IRQ number to assign to keyboard +* @irq1: processor IRQ number to assign to mouse */ -void lpc47m_enable_serial (u16 dev,u16 iobase,u8 irq); +void lpc47m_enable_kbc (uint dev,uint irq0,uint irq1);#endif /* _SMSC_LPC47M_H_ */ --
Quoted 2 lines
1.8.2.1
Regards,
Simon
PATCH v2 2/7 x86: i8042: Remove unused codes
In reply to Bin MengHi Bin,
Quoted 23 lines · Bin Meng
- Remove unused routines
i8042_flush()andi8042_disable()
- Remove unusedCONFIG_USE_CPCIDVIwrapped codes
- Remove__weakboard_i8042_skip()Signed-off-by Bin Meng <[email protected]>Acked-by Simon Glass <[email protected]>---
Changes in v2:
- Split the removing of unused codes into this patchdrivers/input/i8042.c | 67 +-------------------------------------------------- include/i8042.h | 13 ---------- 2 files changed, 1 insertion(+), 79 deletions(-)drivers/input/i8042.c +0
-0@@ -10,16 +10,6 @@/* includes */
drivers/input/i8042.c line 21
Quoted 10 lines
drivers/input/i8042.c +0
-9#include <common.h> -#include <linux/compiler.h> - -#ifdef CONFIG_USE_CPCIDVI -extern u8 gt_cpcidvi_in8 (u32 offset); -extern void gt_cpcidvi_out8 (u32 offset,u8 data); - -#define in8 (a) gt_cpcidvi_in8(a) -#define out8 (a, b) gt_cpcidvi_out8(a, b) -#endif
Yes good to drop that. Can you also please drop it (perhaps separate patch) in drivers/video/ct69000.c?
Quoted 102 lines
drivers/input/i8042.c +1
-57-#include <i8042.h> /* defines */ @@ -305,54 +295,6 @@ static int kbd_controller_present(void)return in8 (I8042_STATUS_REG ) !=0xff ; } -/* -* Implement a weak default function for boards that optionally -* need to skip the i8042 initialization. -*/ -int __weak board_i8042_skip (void ) -{ -/* As default, don't skip */ -return 0 ; -} - -void i8042_flush (void ) -{ -int timeout; - -/* -* The delay is to give the keyboard controller some time to fill the -* next byte. -*/ -while (1 ) { - timeout =100 ;/* wait for no longer than 100us */ -while (timeout >0 && !(in8 (I8042_STATUS_REG ) &0x01 )) { -udelay (1 ); - timeout--; - } - -/* Try to pull next byte if not timeout. */ -if (in8 (I8042_STATUS_REG ) &0x01 ) -in8 (I8042_DATA_REG ); -else -break ; - } -} - -int i8042_disable (void ) -{ -if (kbd_input_empty () ==0 ) -return -1 ; - -/* Disable keyboard */ -out8 (I8042_COMMAND_REG ,0xad ); - -if (kbd_input_empty () ==0 ) -return -1 ; - -return 0 ; -} - -/******************************************************************************* * * i8042_kbd_init - reset keyboard and init state flags @@ -362,16 +304,9 @@ int i8042_kbd_init(void)int keymap, try;char *penv; -if (!kbd_controller_present () ||board_i8042_skip ()) +if (!kbd_controller_present ())return -1 ; -#ifdef CONFIG_USE_CPCIDVI - penv =getenv ("console" ); -if (penv !=NULL ) { -if (strncmp (penv,"serial" ,7 ) ==0 ) -return -1 ; - } -#endif /* Init keyboard device (default US layout) */ keymap =KBD_US ; penv =getenv ("keymap" );include/i8042.h +0
-14@@ -59,19 +59,6 @@ enum {/* exports */ -/** -* Flush all buffer from keyboard controller to host. -*/ -void i8042_flush (void ); - -/** -* Disables the keyboard so that key strokes no longer generate scancodes to -* the host. -* -* @return 0 if ok, -1 if keyboard input was found while disabling -*/ -int i8042_disable (void ); -struct stdio_dev ;int i8042_kbd_init (void ); --
Quoted 2 lines
1.8.2.1
For the moment I'd like to keep these functions. They are used for Chrome OS:
/* Disable keyboard and flush buffer so that further key strokes
* won't interfere kernel driver init. */
#ifdef CONFIG_I8042_KBD
if (i8042_disable())
VBDEBUG("i8042_disable() failed. fine, continue.\n"); i8042_flush();
#endif
int board_i8042_skip(void)
{
struct vboot_flag_details devsw;
vboot_flag_fetch(VBOOT_FLAG_DEVELOPER, &devsw);
if (devsw.value)
return 0;
return fdtdec_get_config_int(gd->fdt_blob, "skip-i8042", 0); }
I'm sure these can be done in a better way at some point, and in the meantime I'll add some code to use them in coreboot (looks like there are a few patches I did not upstream).
Regards,
Simon
PATCH v2 5/7 x86: i8042: Correctly initialize the controller
In reply to Bin MengHi Bin,
Quoted 4 lines · Bin Meng
The existing i8042 keyboard controller driver has some issues. First of all, it does not issue a self-test command (
0xaa) to the controller at the very beginning. Without this, the controller does not respond any command at all. Secondly, it initializes
a few nits
"does not response to any command"
Quoted 1 line
the configuration byte reigster to turn on keyboard's interrupt,
turn on the keyboard's interrupt
Quoted 1 line
which is not allowed as U-Boot we don't normally enable interrupt.
as U-Boot does not normally allow interrupts to be processed.
Quoted 7 lines
Finally, at the end of the initialization routine, it wrongly sets the controller to disable all interfaces including both keyboard and mouse.
Signed-off-by Bin Meng <[email protected]>Acked-by Simon Glass <[email protected]>
Quoted 7 lines
---
Changes in v2:
- Reorder this patch to follow the i8042 driver clean up patchesdrivers/input/i8042.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-)
I am amazed this code actually works! But at least on chromebook_link, it does.
Regards,
Simon
PATCH v2 1/7 x86: superio: Add keyboard controller support to smsc_lpc47m driver
In reply to Simon GlassQuoted 14 lines · Simon Glass
Hi Bin,
Quoted 11 lines · Bin Meng
Add an api to enable and configure the integrated keyboard controller on SMSC LPC47m superio chipset. It also adds several macros to help future extension.
Signed-off-by Bin Meng <[email protected]>---
Changes in v2:
- Change parameter type to uint
Quoted 7 lines
Quoted 5 lines
arch/x86/include/asm/ibmpc.h | 3 +++ drivers/misc/smsc_lpc47m.c | 13 ++++++++++++- include/smsc_lpc47m.h | 29 +++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 5 deletions(-)Acked-by Simon Glass <[email protected]>
Applied to u-boot-x86, thanks!
PATCH v2 2/7 x86: i8042: Remove unused codes
In reply to Simon GlassHi Simon,
Quoted 26 lines · Simon Glass
Hi Bin,
Quoted 23 lines · Bin Meng
- Remove unused routines
i8042_flush()andi8042_disable()
- Remove unusedCONFIG_USE_CPCIDVIwrapped codes
- Remove__weakboard_i8042_skip()Signed-off-by Bin Meng <[email protected]>Acked-by Simon Glass <[email protected]>---
Changes in v2:
- Split the removing of unused codes into this patchdrivers/input/i8042.c | 67 +-------------------------------------------------- include/i8042.h | 13 ---------- 2 files changed, 1 insertion(+), 79 deletions(-)drivers/input/i8042.c +0
-0@@ -10,16 +10,6 @@/* includes */
Quoted 13 lines
drivers/input/i8042.c line 21
Quoted 10 lines
drivers/input/i8042.c +0
-9#include <common.h> -#include <linux/compiler.h> - -#ifdef CONFIG_USE_CPCIDVI -extern u8 gt_cpcidvi_in8 (u32 offset); -extern void gt_cpcidvi_out8 (u32 offset,u8 data); - -#define in8 (a) gt_cpcidvi_in8(a) -#define out8 (a, b) gt_cpcidvi_out8(a, b) -#endif Yes good to drop that. Can you also please drop it (perhaps separate patch) in
drivers/video/ct69000.c?
Yes, will do in v3.
Quoted 101 lines
Quoted 101 lines
drivers/input/i8042.c +1
-57-#include <i8042.h> /* defines */ @@ -305,54 +295,6 @@ static int kbd_controller_present(void)return in8 (I8042_STATUS_REG ) !=0xff ; } -/* -* Implement a weak default function for boards that optionally -* need to skip the i8042 initialization. -*/ -int __weak board_i8042_skip (void ) -{ -/* As default, don't skip */ -return 0 ; -} - -void i8042_flush (void ) -{ -int timeout; - -/* -* The delay is to give the keyboard controller some time to fill the -* next byte. -*/ -while (1 ) { - timeout =100 ;/* wait for no longer than 100us */ -while (timeout >0 && !(in8 (I8042_STATUS_REG ) &0x01 )) { -udelay (1 ); - timeout--; - } - -/* Try to pull next byte if not timeout. */ -if (in8 (I8042_STATUS_REG ) &0x01 ) -in8 (I8042_DATA_REG ); -else -break ; - } -} - -int i8042_disable (void ) -{ -if (kbd_input_empty () ==0 ) -return -1 ; - -/* Disable keyboard */ -out8 (I8042_COMMAND_REG ,0xad ); - -if (kbd_input_empty () ==0 ) -return -1 ; - -return 0 ; -} - -/******************************************************************************* * * i8042_kbd_init - reset keyboard and init state flags @@ -362,16 +304,9 @@ int i8042_kbd_init(void)int keymap, try;char *penv; -if (!kbd_controller_present () ||board_i8042_skip ()) +if (!kbd_controller_present ())return -1 ; -#ifdef CONFIG_USE_CPCIDVI - penv =getenv ("console" ); -if (penv !=NULL ) { -if (strncmp (penv,"serial" ,7 ) ==0 ) -return -1 ; - } -#endif /* Init keyboard device (default US layout) */ keymap =KBD_US ; penv =getenv ("keymap" );include/i8042.h +0
-13@@ -59,19 +59,6 @@ enum {/* exports */ -/** -* Flush all buffer from keyboard controller to host. -*/ -void i8042_flush (void ); - -/** -* Disables the keyboard so that key strokes no longer generate scancodes to -* the host. -* -* @return 0 if ok, -1 if keyboard input was found while disabling -*/ -int i8042_disable (void ); -struct stdio_dev ;
Quoted 6 lines
Quoted 4 lines
include/i8042.h +0
-1int i8042_kbd_init (void ); --1.8.2.1
For the moment I'd like to keep these functions. They are used for Chrome OS:
I will keep i8042_flush() and i8042_disable() in v3.
Quoted 10 lines
/* Disable keyboard and flush buffer so that further key strokes
* won't interfere kernel driver init. */
#ifdefCONFIG_I8042_KBD
if (i8042_disable())
VBDEBUG("i8042_disable() failed. fine, continue.\n");i8042_flush();
#endifint
board_i8042_skip(void)
Would you also like to keep board_i8042_skip()?
Quoted 7 lines
{
structvboot_flag_detailsdevsw;
vboot_flag_fetch(VBOOT_FLAG_DEVELOPER, &devsw);
if (devsw.value)
return 0;
Quoted 7 lines
return
fdtdec_get_config_int(gd->fdt_blob, "skip-i8042", 0); }I'm sure these can be done in a better way at some point, and in the meantime I'll add some code to use them in coreboot (looks like there are a few patches I did not upstream).
Regards,
Bin
PATCH v2 5/7 x86: i8042: Correctly initialize the controller
In reply to Simon GlassHi Simon,
Quoted 11 lines · Simon Glass
Hi Bin,
Quoted 4 lines · Bin Meng
The existing i8042 keyboard controller driver has some issues. First of all, it does not issue a self-test command (
0xaa) to the controller at the very beginning. Without this, the controller does not respond any command at all. Secondly, it initializesa few nits
"does not response to any command"
OK
Quoted 4 lines
Quoted 2 lines
the configuration byte reigster to turn on keyboard's interrupt,
turn on the keyboard's interrupt
OK
Quoted 4 lines
Quoted 2 lines
which is not allowed as U-Boot we don't normally enable interrupt.
as U-Boot does not normally allow interrupts to be processed.
OK
Quoted 10 lines
Quoted 10 lines
Finally, at the end of the initialization routine, it wrongly sets the controller to disable all interfaces including both keyboard and mouse.
Signed-off-by Bin Meng <[email protected]>Acked-by Simon Glass <[email protected]>---
Quoted 8 lines
Quoted 5 lines
Changes in v2:
- Reorder this patch to follow the i8042 driver clean up patchesdrivers/input/i8042.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-)I am amazed this code actually works! But at least on
chromebook_link, it does.
Me either. The old codes could work on QEMU too, but I believe that is because QEMU does not emulate hardware exactly (like does not have to issue self-test command before any command). As for chromebook_link, is i8042 implemented in the EC? I suspect some EC firmware may be quite of forgiveness :-)
Regards,
Bin
PATCH v2 2/7 x86: i8042: Remove unused codes
In reply to Bin MengHi Bin,
Quoted 164 lines · Bin Meng
Hi Simon,
Quoted 26 lines · Simon Glass
Hi Bin,
Quoted 23 lines · Bin Meng
- Remove unused routines
i8042_flush()andi8042_disable()
- Remove unusedCONFIG_USE_CPCIDVIwrapped codes
- Remove__weakboard_i8042_skip()Signed-off-by Bin Meng <[email protected]>Acked-by Simon Glass <[email protected]>---
Changes in v2:
- Split the removing of unused codes into this patchdrivers/input/i8042.c | 67 +-------------------------------------------------- include/i8042.h | 13 ---------- 2 files changed, 1 insertion(+), 79 deletions(-)drivers/input/i8042.c +0
-0@@ -10,16 +10,6 @@/* includes */ Quoted 13 lines
drivers/input/i8042.c line 21
Quoted 10 lines
drivers/input/i8042.c +0
-9#include <common.h> -#include <linux/compiler.h> - -#ifdef CONFIG_USE_CPCIDVI -extern u8 gt_cpcidvi_in8 (u32 offset); -extern void gt_cpcidvi_out8 (u32 offset,u8 data); - -#define in8 (a) gt_cpcidvi_in8(a) -#define out8 (a, b) gt_cpcidvi_out8(a, b) -#endif Yes good to drop that. Can you also please drop it (perhaps separate patch) in
drivers/video/ct69000.c?Yes, will do in v3.
Quoted 101 lines
Quoted 101 lines
drivers/input/i8042.c +1
-57-#include <i8042.h> /* defines */ @@ -305,54 +295,6 @@ static int kbd_controller_present(void)return in8 (I8042_STATUS_REG ) !=0xff ; } -/* -* Implement a weak default function for boards that optionally -* need to skip the i8042 initialization. -*/ -int __weak board_i8042_skip (void ) -{ -/* As default, don't skip */ -return 0 ; -} - -void i8042_flush (void ) -{ -int timeout; - -/* -* The delay is to give the keyboard controller some time to fill the -* next byte. -*/ -while (1 ) { - timeout =100 ;/* wait for no longer than 100us */ -while (timeout >0 && !(in8 (I8042_STATUS_REG ) &0x01 )) { -udelay (1 ); - timeout--; - } - -/* Try to pull next byte if not timeout. */ -if (in8 (I8042_STATUS_REG ) &0x01 ) -in8 (I8042_DATA_REG ); -else -break ; - } -} - -int i8042_disable (void ) -{ -if (kbd_input_empty () ==0 ) -return -1 ; - -/* Disable keyboard */ -out8 (I8042_COMMAND_REG ,0xad ); - -if (kbd_input_empty () ==0 ) -return -1 ; - -return 0 ; -} - -/******************************************************************************* * * i8042_kbd_init - reset keyboard and init state flags @@ -362,16 +304,9 @@ int i8042_kbd_init(void)int keymap, try;char *penv; -if (!kbd_controller_present () ||board_i8042_skip ()) +if (!kbd_controller_present ())return -1 ; -#ifdef CONFIG_USE_CPCIDVI - penv =getenv ("console" ); -if (penv !=NULL ) { -if (strncmp (penv,"serial" ,7 ) ==0 ) -return -1 ; - } -#endif /* Init keyboard device (default US layout) */ keymap =KBD_US ; penv =getenv ("keymap" );include/i8042.h +0
-13@@ -59,19 +59,6 @@ enum {/* exports */ -/** -* Flush all buffer from keyboard controller to host. -*/ -void i8042_flush (void ); - -/** -* Disables the keyboard so that key strokes no longer generate scancodes to -* the host. -* -* @return 0 if ok, -1 if keyboard input was found while disabling -*/ -int i8042_disable (void ); -struct stdio_dev ;Quoted 6 lines
Quoted 4 lines
include/i8042.h +0
-1int i8042_kbd_init (void ); --1.8.2.1
For the moment I'd like to keep these functions. They are used for Chrome OS:
I will keep
i8042_flush()andi8042_disable()in v3.Quoted 9 lines
/* Disable keyboard and flush buffer so that further key strokes
* won't interfere kernel driver init. */
#ifdefCONFIG_I8042_KBD
if (i8042_disable())
VBDEBUG("i8042_disable() failed. fine, continue.\n");i8042_flush();
#endif
Quoted 3 lines
Quoted 1 line
int
board_i8042_skip(void)Would you also like to keep
board_i8042_skip()?
Yes at least for now.
Quoted 11 lines
Quoted 11 lines
{
structvboot_flag_detailsdevsw;
vboot_flag_fetch(VBOOT_FLAG_DEVELOPER, &devsw);
if (devsw.value)
return 0;return
fdtdec_get_config_int(gd->fdt_blob, "skip-i8042", 0); }
Quoted 7 lines
Quoted 4 lines
I'm sure these can be done in a better way at some point, and in the meantime I'll add some code to use them in coreboot (looks like there are a few patches I did not upstream).
Regards,
Bin
Regards,
Simon
PATCH v2 5/7 x86: i8042: Correctly initialize the controller
In reply to Bin MengHi Bin,
Quoted 47 lines · Bin Meng
Hi Simon,
Quoted 11 lines · Simon Glass
Hi Bin,
Quoted 4 lines · Bin Meng
The existing i8042 keyboard controller driver has some issues. First of all, it does not issue a self-test command (
0xaa) to the controller at the very beginning. Without this, the controller does not respond any command at all. Secondly, it initializesa few nits
"does not response to any command"
OK
Quoted 4 lines
Quoted 2 lines
the configuration byte reigster to turn on keyboard's interrupt,
turn on the keyboard's interrupt
OK
Quoted 4 lines
Quoted 2 lines
which is not allowed as U-Boot we don't normally enable interrupt.
as U-Boot does not normally allow interrupts to be processed.
OK
Quoted 16 lines
Quoted 15 lines
Finally, at the end of the initialization routine, it wrongly sets the controller to disable all interfaces including both keyboard and mouse.
Signed-off-by Bin Meng <[email protected]>Acked-by Simon Glass <[email protected]>---
Changes in v2:
- Reorder this patch to follow the i8042 driver clean up patchesdrivers/input/i8042.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-)
Quoted 8 lines
Quoted 2 lines
I am amazed this code actually works! But at least on
chromebook_link, it does.Me either. The old codes could work on QEMU too, but I believe that is because QEMU does not emulate hardware exactly (like does not have to issue self-test command before any command). As for
chromebook_link, is i8042 implemented in the EC? I suspect some EC firmware may be quite of forgiveness :-)
Yes that explains it, I think. Anyway it's good to have it correct now!
Regards,
Simon