libpayload/keyboard: Add a detention state

Instead of ignoring keyboards indefinitely when they failed to
initialize, we wait 5s and then start over with the hotplug
detection. As we always assume a present keyboard at first,
we'd otherwise never have a chance to hot plug a device after
the initial 30s timer ran out.

Change-Id: I8dec4921b2e932442d52b5118cdcf27090633498
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/48774
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
diff --git a/payloads/libpayload/drivers/i8042/keyboard.c b/payloads/libpayload/drivers/i8042/keyboard.c
index 6d0cdd1..cc412ac 100644
--- a/payloads/libpayload/drivers/i8042/keyboard.c
+++ b/payloads/libpayload/drivers/i8042/keyboard.c
@@ -259,7 +259,7 @@
 	STATE_ENABLE_SCAN,
 	STATE_RUNNING,
 	STATE_RUNNING_ECHO,
-	STATE_IGNORE,
+	STATE_DETENTION,
 } keyboard_state;
 
 #define STATE_NAMES_ENTRY(name) [STATE_##name] = #name
@@ -279,7 +279,7 @@
 	STATE_NAMES_ENTRY(ENABLE_SCAN),
 	STATE_NAMES_ENTRY(RUNNING),
 	STATE_NAMES_ENTRY(RUNNING_ECHO),
-	STATE_NAMES_ENTRY(IGNORE),
+	STATE_NAMES_ENTRY(DETENTION),
 };
 
 __attribute__((unused))
@@ -455,8 +455,9 @@
 		state_time = timer_us(0);
 		break;
 
-	case STATE_IGNORE:
-		/* TODO: Try again after timeout if it ever seems useful. */
+	case STATE_DETENTION:
+		if (timer_us(state_time) > 5*1000*1000)
+			next_state = STATE_HOTPLUG;
 		break;
 
 	}
@@ -467,11 +468,11 @@
 	case STATE_HOTPLUG_ECHO:
 	case STATE_RUNNING:
 	case STATE_RUNNING_ECHO:
-	case STATE_IGNORE:
+	case STATE_DETENTION:
 		break;
 	default:
 		if (timer_us(keyboard_time) > 30*1000*1000)
-			next_state = STATE_IGNORE;
+			next_state = STATE_DETENTION;
 		break;
 	}