From a11f16fd7e6423714ad1ec96414d39952974aa81 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Mon, 13 Feb 2006 21:27:22 +0000 Subject: [PATCH] cleanup of multiplexing support and debug output git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16386 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/bus_managers/ps2/ps2_common.c | 159 +++++++++--------- .../kernel/bus_managers/ps2/ps2_common.h | 2 +- src/add-ons/kernel/bus_managers/ps2/ps2_dev.c | 2 +- .../kernel/bus_managers/ps2/ps2_keyboard.c | 6 +- .../kernel/bus_managers/ps2/ps2_mouse.c | 6 +- 5 files changed, 87 insertions(+), 88 deletions(-) diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_common.c b/src/add-ons/kernel/bus_managers/ps2/ps2_common.c index e2e9c79d5d..e7bd6104d0 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ps2_common.c +++ b/src/add-ons/kernel/bus_managers/ps2/ps2_common.c @@ -21,7 +21,7 @@ isa_module_info *gIsa = NULL; static int32 sIgnoreInterrupts = 0; -bool gMultiplexingActive = false; +bool gActiveMultiplexingEnabled = false; sem_id gControllerSem; @@ -109,6 +109,71 @@ ps2_flush(void) } +static status_t +ps2_setup_command_byte() +{ + status_t res; + uint8 cmdbyte; + + res = ps2_command(PS2_CTRL_READ_CMD, NULL, 0, &cmdbyte, 1); + dprintf("ps2: get command byte: res 0x%08lx, cmdbyte 0x%02x\n", res, cmdbyte); + if (res != B_OK) + cmdbyte = 0x47; + + cmdbyte |= PS2_BITS_TRANSLATE_SCANCODES | PS2_BITS_KEYBOARD_INTERRUPT | PS2_BITS_AUX_INTERRUPT; + cmdbyte &= ~(PS2_BITS_KEYBOARD_DISABLED | PS2_BITS_MOUSE_DISABLED); + + res = ps2_command(PS2_CTRL_WRITE_CMD, &cmdbyte, 1, NULL, 0); + dprintf("ps2: set command byte: res 0x%08lx, cmdbyte 0x%02x\n", res, cmdbyte); + + return res; +} + + +static status_t +ps2_setup_active_multiplexing(bool *enabled) +{ + status_t res; + uint8 in, out; + + out = 0xf0; + res = ps2_command(0xd3, &out, 1, &in, 1); + if (res) + return res; + + out = 0x56; + res = ps2_command(0xd3, &out, 1, &in, 1); + if (res) + return res; + + out = 0xa4; + res = ps2_command(0xd3, &out, 1, &in, 1); + if (res) + return res; + + // If the controller doesn't support active multiplexing, + // in data is 0xa4 (or 0xac on some broken USB legacy emulation) + + if (in != 0xa4 && in != 0xac) { + dprintf("ps2: active multiplexing v%d.%d enabled\n", (in >> 4), in & 0xf); + *enabled = true; + ps2_command(0xa8, NULL, 0, NULL, 0); + ps2_command(0x90, NULL, 0, NULL, 0); + ps2_command(0xa8, NULL, 0, NULL, 0); + ps2_command(0x91, NULL, 0, NULL, 0); + ps2_command(0xa8, NULL, 0, NULL, 0); + ps2_command(0x92, NULL, 0, NULL, 0); + ps2_command(0xa8, NULL, 0, NULL, 0); + ps2_command(0x93, NULL, 0, NULL, 0); + ps2_command(0xa8, NULL, 0, NULL, 0); + } else { + dprintf("ps2: active multiplexing not supported\n"); + *enabled = false; + } + return B_OK; +} + + status_t ps2_command(uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count) { @@ -153,22 +218,6 @@ ps2_command(uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count) } -// #pragma mark - - -inline status_t -ps2_get_command_byte(uint8 *byte) -{ - return ps2_command(PS2_CTRL_READ_CMD, NULL, 0, byte, 1); -} - - -inline status_t -ps2_set_command_byte(uint8 byte) -{ - return ps2_command(PS2_CTRL_WRITE_CMD, &byte, 1, NULL, 0); -} - - // #pragma mark - @@ -192,7 +241,7 @@ ps2_interrupt(void* cookie) if (ctrl & PS2_STATUS_AUX_DATA) { uint8 idx; - if (gMultiplexingActive) { + if (gActiveMultiplexingEnabled) { idx = ctrl >> 6; TRACE(("ps2_interrupt: ctrl 0x%02x, data 0x%02x (mouse %d)\n", ctrl, data, idx)); } else { @@ -238,79 +287,27 @@ ps2_init(void) status = install_io_interrupt_handler(INT_PS2_MOUSE, &ps2_interrupt, NULL, 0); if (status) goto err_4; - - { - uint8 d, in, out; - status_t res; - res = ps2_get_command_byte(&d); - dprintf("ps2_get_command_byte: res 0x%08x, d 0x%02x\n", res, d); - - d |= PS2_BITS_TRANSLATE_SCANCODES | PS2_BITS_KEYBOARD_INTERRUPT | PS2_BITS_AUX_INTERRUPT; - d &= ~(PS2_BITS_KEYBOARD_DISABLED | PS2_BITS_MOUSE_DISABLED); - - res = ps2_set_command_byte(d); - dprintf("ps2_set_command_byte: res 0x%08x, d 0x%02x\n", res, d); - - in = 0x00; - out = 0xf0; - res = ps2_command(0xd3, &out, 1, &in, 1); - dprintf("step1: res 0x%08x, out 0x%02x, in 0x%02x\n", res, out, in); + status = ps2_setup_command_byte(); + if (status) { + dprintf("ps2: setting up command byte failed\n"); + goto err_5; + } - in = 0x00; - out = 0x56; - res = ps2_command(0xd3, &out, 1, &in, 1); - dprintf("step2: res 0x%08x, out 0x%02x, in 0x%02x\n", res, out, in); - - in = 0x00; - out = 0xa4; - res = ps2_command(0xd3, &out, 1, &in, 1); - dprintf("step3: res 0x%08x, out 0x%02x, in 0x%02x\n", res, out, in); - - // If the controller doesn't support active multiplexing, - // data is 0xa4 (or 0xac on some broken USB legacy emulation) - - if (res == B_OK && in != 0xa4 && in != 0xac) { - dprintf("ps2: active multiplexing v%d.%d enabled\n", (in >> 4), in & 0xf); - gMultiplexingActive = true; - - res = ps2_command(0xa8, NULL, 0, NULL, 0); - dprintf("step4: res 0x%08x\n", res); - - res = ps2_command(0x90, NULL, 0, NULL, 0); - dprintf("step5: res 0x%08x\n", res); - res = ps2_command(0xa8, NULL, 0, NULL, 0); - dprintf("step6: res 0x%08x\n", res); - - res = ps2_command(0x91, NULL, 0, NULL, 0); - dprintf("step7: res 0x%08x\n", res); - res = ps2_command(0xa8, NULL, 0, NULL, 0); - dprintf("step8: res 0x%08x\n", res); - - res = ps2_command(0x92, NULL, 0, NULL, 0); - dprintf("step9: res 0x%08x\n", res); - res = ps2_command(0xa8, NULL, 0, NULL, 0); - dprintf("step10: res 0x%08x\n", res); - - res = ps2_command(0x93, NULL, 0, NULL, 0); - dprintf("step11: res 0x%08x\n", res); - res = ps2_command(0xa8, NULL, 0, NULL, 0); - dprintf("step12: res 0x%08x\n", res); - } else { - dprintf("ps2: active multiplexing not supported\n"); - } + status = ps2_setup_active_multiplexing(&gActiveMultiplexingEnabled); + if (status) { + dprintf("ps2: setting up active multiplexing failed\n"); + goto err_5; } ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_KEYB]); ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE]); - if (gMultiplexingActive) { + if (gActiveMultiplexingEnabled) { ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE + 1]); ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE + 2]); ps2_service_notify_device_added(&ps2_device[PS2_DEVICE_MOUSE + 3]); } - - //goto err_5; - + TRACE(("ps2_hid: init_driver done!\n")); return B_OK; diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_common.h b/src/add-ons/kernel/bus_managers/ps2/ps2_common.h index 7c5160b3e0..d6530c4baa 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ps2_common.h +++ b/src/add-ons/kernel/bus_managers/ps2/ps2_common.h @@ -36,7 +36,7 @@ extern isa_module_info *gIsa; extern device_hooks gKeyboardDeviceHooks; extern device_hooks gMouseDeviceHooks; -extern bool gMultiplexingActive; +extern bool gActiveMultiplexingEnabled; extern sem_id gControllerSem; // prototypes from common.c diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_dev.c b/src/add-ons/kernel/bus_managers/ps2/ps2_dev.c index 352f125064..18ce7d4577 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ps2_dev.c +++ b/src/add-ons/kernel/bus_managers/ps2/ps2_dev.c @@ -184,7 +184,7 @@ ps2_dev_command(ps2_dev *dev, uint8 cmd, const uint8 *out, int out_count, uint8 if (!(atomic_get(&dev->flags) & PS2_FLAG_KEYB)) { uint8 prefix_cmd; - if (gMultiplexingActive) + if (gActiveMultiplexingEnabled) prefix_cmd = 0x90 + dev->idx; else prefix_cmd = 0xd4; diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.c b/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.c index 10a4056fdf..28d5647def 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.c +++ b/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.c @@ -215,7 +215,7 @@ keyboard_open(const char *name, uint32 flags, void **_cookie) { status_t status; - dprintf("ps2: keyboard_open\n"); + dprintf("ps2: keyboard_open %s\n", name); if (atomic_or(&sKeyboardOpenMask, 1) != 0) return B_BUSY; @@ -242,7 +242,7 @@ keyboard_open(const char *name, uint32 flags, void **_cookie) *_cookie = NULL; - dprintf("ps2: keyboard_open success\n"); + dprintf("ps2: keyboard_open %s success\n", name); return B_OK; err4: @@ -253,7 +253,7 @@ err2: err1: atomic_and(&sKeyboardOpenMask, 0); - dprintf("ps2: keyboard_open failed\n"); + dprintf("ps2: keyboard_open %s failed\n", name); return status; } diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c b/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c index 0f0a1184a9..0c5fcfb20a 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c +++ b/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c @@ -335,7 +335,7 @@ mouse_open(const char *name, uint32 flags, void **_cookie) status_t status; int i; - TRACE(("mouse_open() %s\n", name)); + dprintf("ps2: mouse_open %s\n", name); for (dev = NULL, i = 0; i < PS2_DEVICE_COUNT; i++) { if (0 == strcmp(ps2_device[i].name, name)) { @@ -390,7 +390,7 @@ mouse_open(const char *name, uint32 flags, void **_cookie) atomic_or(&dev->flags, PS2_FLAG_ENABLED); - TRACE(("mouse_open(): mouse succesfully enabled\n")); + dprintf("ps2: mouse_open %s success\n", name); return B_OK; err4: @@ -401,6 +401,8 @@ err2: free(cookie); err1: atomic_and(&dev->flags, ~PS2_FLAG_OPEN); + + dprintf("ps2: mouse_open %s failed\n", name); return B_ERROR; }