From fb8a44691fcbce1f57b5e5f03a206fc235e48111 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Fri, 13 Jan 2006 11:17:12 +0000 Subject: [PATCH] reimplemented waiting for read/write, added flush function git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15934 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/drivers/input/ps2_hid_new/common.c | 57 ++++++++++--------- .../kernel/drivers/input/ps2_hid_new/ps2.h | 3 + 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/add-ons/kernel/drivers/input/ps2_hid_new/common.c b/src/add-ons/kernel/drivers/input/ps2_hid_new/common.c index a5c73aeed4..ac782aff71 100644 --- a/src/add-ons/kernel/drivers/input/ps2_hid_new/common.c +++ b/src/add-ons/kernel/drivers/input/ps2_hid_new/common.c @@ -90,47 +90,48 @@ ps2_write_data(uint8 data) } - -/** Wait until the specified status bits are cleared or set, depending on the - * second parameter. - * This currently busy waits, but should nonetheless be avoided in interrupt - * handlers. - */ - -static status_t -wait_for_status(int32 bits, bool set) +status_t +ps2_wait_read() { - int8 read; - int32 tries = 100; - - TRACE(("wait_write_ctrl(bits = %lx, %s)\n", bits, set ? "set" : "cleared")); - - while (tries-- > 0) { - read = gIsa->read_io_8(PS2_PORT_CTRL); - if (((read & bits) == bits) == set) + int i; + for (i = 0; i < PS2_CTRL_WAIT_TIMEOUT / 50; i++) { + if (ps2_read_ctrl() & PS2_STATUS_OUTPUT_BUFFER_FULL) return B_OK; - - spin(100); + snooze(50); } - return B_ERROR; } -static inline status_t -wait_for_bits_cleared(int32 bits) +status_t +ps2_wait_write() { - return wait_for_status(bits, false); + int i; + for (i = 0; i < PS2_CTRL_WAIT_TIMEOUT / 50; i++) { + if (!(ps2_read_ctrl() & PS2_STATUS_INPUT_BUFFER_FULL)) + return B_OK; + snooze(50); + } + return B_ERROR; } -static inline status_t -wait_for_bits_set(int32 bits) +void +ps2_flush() { - return wait_for_status(bits, true); + int i; + for (i = 0; i < 64; i++) { + uint8 ctrl; + uint8 data; + ctrl = ps2_read_ctrl(); + if (!(ctrl & PS2_STATUS_OUTPUT_BUFFER_FULL)) + return; + data = ps2_read_data(); + TRACE(("ps2_flush: ctrl 0x%02x, data 0x%02x (%s)\n", ctrl, data, (ctrl & PS2_STATUS_MOUSE_DATA) ? "mouse" : "keyb")); + snooze(100); + } } - /** Reads the command byte from the 8042 controller. * Since the read goes through the data port, this function must not be * called when the keyboard driver is up and running. @@ -355,7 +356,7 @@ init_driver(void) if (status) goto err_3; - status = install_io_interrupt_handler(INT_PS2_MOUSE, &ps2_interrupt, NULL, 0); + status = install_io_interrupt_handler(INT_PS2_MOUSE, &ps2_interrupt, NULL, 0); if (status) goto err_4; diff --git a/src/add-ons/kernel/drivers/input/ps2_hid_new/ps2.h b/src/add-ons/kernel/drivers/input/ps2_hid_new/ps2.h index f5d5c20b35..6657f8435c 100644 --- a/src/add-ons/kernel/drivers/input/ps2_hid_new/ps2.h +++ b/src/add-ons/kernel/drivers/input/ps2_hid_new/ps2.h @@ -74,4 +74,7 @@ #define PS2_MAX_PACKET_SIZE 4 // Should be equal to the biggest packet size +// timeouts +#define PS2_CTRL_WAIT_TIMEOUT 500000 + #endif /* _PS2_H */