From 7e7b081cba47e60c1221ea44f2e78551b1616285 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Tue, 11 Oct 2005 12:02:58 +0000 Subject: [PATCH] This should fix hanging keyboards when no ps2 mouse is connected. We also stop publishing devices we didn't explicitly find. This disables the questionable hot-plug support but keeps the input_server from stalling the keyboard by probing the non-present mouse. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14349 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/drivers/input/ps2_hid/common.c | 31 +++++++++++++------ .../kernel/drivers/input/ps2_hid/keyboard.c | 8 +++-- .../kernel/drivers/input/ps2_hid/mouse.c | 1 - 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/add-ons/kernel/drivers/input/ps2_hid/common.c b/src/add-ons/kernel/drivers/input/ps2_hid/common.c index f32ca2e12d..8966d9209b 100644 --- a/src/add-ons/kernel/drivers/input/ps2_hid/common.c +++ b/src/add-ons/kernel/drivers/input/ps2_hid/common.c @@ -54,6 +54,7 @@ sem_id gDeviceOpenSemaphore; static int32 sInitialized = 0; static uint8 sCommandByte = 0; static bool sKeyboardDetected = false; +static bool sMouseDetected = false; static sem_id sResultSemaphore; static sem_id sResultOwnerSemaphore; @@ -77,7 +78,7 @@ wait_for_status(int32 bits, bool set) while (tries-- > 0) { read = gIsa->read_io_8(PS2_PORT_CTRL); - if (((read & bits) != 0) == set) + if (((read & bits) == bits) == set) return B_OK; spin(100); @@ -299,14 +300,15 @@ const char ** publish_devices(void) { static char *kDevices[3]; - - kDevices[0] = DEVICE_MOUSE_NAME; + int index = 0; - if (sKeyboardDetected) { - kDevices[1] = DEVICE_KEYBOARD_NAME; - kDevices[2] = NULL; - } else - kDevices[1] = NULL; + if (sMouseDetected) + kDevices[index++] = DEVICE_MOUSE_NAME; + + if (sKeyboardDetected) + kDevices[index++] = DEVICE_KEYBOARD_NAME; + + kDevices[index++] = NULL; return (const char **)kDevices; } @@ -335,14 +337,23 @@ init_driver(void) return status; } - // If there is no keyboard or mouse, we don't need to publish ourselves + // Try to probe for the mouse first, as this can hang the keyboard if no + // mouse is found. + // Probing the mouse first and initializing the keyboard later appearantly + // clears the keyboard stall. + + if (probe_mouse() == B_OK) + sMouseDetected = true; + else + dprintf("ps2_hid: no mouse detected!\n"); if (probe_keyboard() == B_OK) sKeyboardDetected = true; else dprintf("ps2_hid: no keyboard detected!\n"); - if (!sKeyboardDetected && probe_mouse() != B_OK) { + // If there is no keyboard or mouse, we don't need to publish ourselves + if (!sKeyboardDetected && !sMouseDetected) { put_module(B_ISA_MODULE_NAME); return B_ERROR; } diff --git a/src/add-ons/kernel/drivers/input/ps2_hid/keyboard.c b/src/add-ons/kernel/drivers/input/ps2_hid/keyboard.c index 7b02fab33d..f13f17d989 100644 --- a/src/add-ons/kernel/drivers/input/ps2_hid/keyboard.c +++ b/src/add-ons/kernel/drivers/input/ps2_hid/keyboard.c @@ -254,7 +254,7 @@ enable_keyboard(void) status_t probe_keyboard(void) { - uint32 tries; + int32 tries; // ToDo: for now there just is a keyboard ready to be used... @@ -271,8 +271,10 @@ probe_keyboard(void) if (ps2_read_data(&acknowledged) == B_OK && acknowledged == PS2_REPLY_ACK) break; } - if (tries < 0) - return B_ERROR; + + // This selftest appears to fail quite frequently we'll just disable it + /*if (tries < 0) + return B_ERROR;*/ // Activate keyboard diff --git a/src/add-ons/kernel/drivers/input/ps2_hid/mouse.c b/src/add-ons/kernel/drivers/input/ps2_hid/mouse.c index c193e24268..895a2f6cae 100644 --- a/src/add-ons/kernel/drivers/input/ps2_hid/mouse.c +++ b/src/add-ons/kernel/drivers/input/ps2_hid/mouse.c @@ -320,7 +320,6 @@ probe_mouse(void) TRACE(("Extended PS/2 mouse found\n")); } else { // Something's wrong. Better quit - dprintf("ps2_hid: No mouse found\n"); return B_ERROR; }