]> git.sur5r.net Git - u-boot/blobdiff - drivers/input/i8042.c
dm: exynos: Move serial to driver model
[u-boot] / drivers / input / i8042.c
index 3a4c467c59c5f4645e1051f15a53d05bf5ee25d7..ca1604c5401513686699272cb84f879cdb5e01f4 100644 (file)
@@ -2,23 +2,7 @@
  * (C) Copyright 2002 ELTEC Elektronik AG
  * Frank Gottschling <fgottschling@eltec.de>
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /* i8042.c - Intel 8042 keyboard driver routines */
@@ -331,6 +315,44 @@ int __weak board_i8042_skip(void)
        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
@@ -376,7 +398,7 @@ int i8042_kbd_init(void)
  * i8042_tstc - test if keyboard input is available
  *             option: cursor blinking if called in a loop
  */
-int i8042_tstc(void)
+int i8042_tstc(struct stdio_dev *dev)
 {
        unsigned char scan_code = 0;
 
@@ -410,7 +432,7 @@ int i8042_tstc(void)
  * i8042_getc - wait till keyboard input is available
  *             option: turn on/off cursor while waiting
  */
-int i8042_getc(void)
+int i8042_getc(struct stdio_dev *dev)
 {
        int ret_chr;
        unsigned char scan_code;
@@ -628,31 +650,53 @@ static int kbd_input_empty(void)
 
 /******************************************************************************/
 
+static int wait_until_kbd_output_full(void)
+{
+       int kbdTimeout = KBD_TIMEOUT * 1000;
+
+       while (((in8(I8042_STATUS_REG) & 0x01) == 0) && kbdTimeout--)
+               udelay(1);
+
+       return kbdTimeout != -1;
+}
+
+/******************************************************************************/
+
 static int kbd_reset(void)
 {
+       /* KB Reset */
        if (kbd_input_empty() == 0)
                return -1;
 
        out8(I8042_DATA_REG, 0xff);
 
+       if (wait_until_kbd_output_full() == 0)
+               return -1;
+
+       if (in8(I8042_DATA_REG) != 0xfa) /* ACK */
+               return -1;
+
+       if (wait_until_kbd_output_full() == 0)
+               return -1;
+
+       if (in8(I8042_DATA_REG) != 0xaa) /* Test Pass*/
+               return -1;
+
        if (kbd_input_empty() == 0)
                return -1;
 
-#ifdef CONFIG_USE_CPCIDVI
+       /* Set KBC mode */
        out8(I8042_COMMAND_REG, 0x60);
-#else
-       out8(I8042_DATA_REG, 0x60);
-#endif
 
        if (kbd_input_empty() == 0)
                return -1;
 
        out8(I8042_DATA_REG, 0x45);
 
-
        if (kbd_input_empty() == 0)
                return -1;
 
+       /* Enable Keyboard */
        out8(I8042_COMMAND_REG, 0xae);
 
        if (kbd_input_empty() == 0)