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 7035399cfd..b83331db7a 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 @@ -117,6 +117,8 @@ ps2_wait_write() } +// #pragma mark - + void ps2_flush() { @@ -174,20 +176,38 @@ ps2_command(uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count) status_t +ps2_keyboard_command(uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count) +{ + + return B_OK; +} + + +status_t +ps2_mouse_command(uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count) +{ + + return B_OK; +} + + +// #pragma mark - + +inline status_t ps2_get_command_byte(uint8 *byte) { return ps2_command(PS2_CTRL_READ_CMD, NULL, 0, byte, 1); } -status_t +inline status_t ps2_set_command_byte(uint8 byte) { return ps2_command(PS2_CTRL_WRITE_CMD, &byte, 1, NULL, 0); } -// #pragma mark - +// #pragma mark - static int32 @@ -286,7 +306,7 @@ init_driver(void) uint8 d; status_t res; - res = ps2_get_command_byte(&d) + 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; diff --git a/src/add-ons/kernel/drivers/input/ps2_hid_new/common.h b/src/add-ons/kernel/drivers/input/ps2_hid_new/common.h index 9e1393ec32..b1f518041d 100644 --- a/src/add-ons/kernel/drivers/input/ps2_hid_new/common.h +++ b/src/add-ons/kernel/drivers/input/ps2_hid_new/common.h @@ -32,13 +32,19 @@ extern isa_module_info *gIsa; extern sem_id gDeviceOpenSemaphore; // prototypes from common.c -extern status_t ps2_write_ctrl(uint8 data); -extern status_t ps2_write_data(uint8 data); -extern status_t ps2_read_data(uint8 *data); -extern status_t ps2_write_aux_byte(uint8 data); -extern uint8 ps2_get_command_byte(void); -extern status_t ps2_set_command_byte(uint8 command); +extern status_t ps2_wait_read(); +extern status_t ps2_wait_write(); + +extern void ps2_flush(); + +extern status_t ps2_command(uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count); + +extern status_t ps2_keyboard_command(uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count); +extern status_t ps2_mouse_command(uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count); + +extern status_t ps2_get_command_byte(uint8 *byte); +extern status_t ps2_set_command_byte(uint8 byte); extern void ps2_claim_result(uint8 *buffer, size_t bytes); extern void ps2_unclaim_result(void); diff --git a/src/add-ons/kernel/drivers/input/ps2_hid_new/keyboard.c b/src/add-ons/kernel/drivers/input/ps2_hid_new/keyboard.c index b74af20926..3d10abc490 100644 --- a/src/add-ons/kernel/drivers/input/ps2_hid_new/keyboard.c +++ b/src/add-ons/kernel/drivers/input/ps2_hid_new/keyboard.c @@ -39,80 +39,6 @@ static int32 sKeyboardOpenMask; static sem_id sKeyboardSem; static struct packet_buffer *sKeyBuffer; static bool sIsExtended = false; -static bool sInterruptHandlerInstalled = false; - - -static status_t -keyboard_write_byte(uint8 byte) -{ - uint8 acknowledged = 0; - - TRACE(("keyboard_write_byte(byte = %u)\n", byte)); - - if (sInterruptHandlerInstalled) { - ps2_claim_result(&acknowledged, 1); - - if (ps2_write_data(byte) != B_OK) { - ps2_unclaim_result(); - return B_TIMED_OUT; - } - - ps2_wait_for_result(); - } else { - status_t status = ps2_write_data(byte); - if (status == B_OK) - status = ps2_read_data(&acknowledged); - - if (status != B_OK) - return status; - } - - return acknowledged == PS2_REPLY_ACK ? B_OK : B_ERROR; -} - - -static status_t -keyboard_read_bytes(uint8 *buffer, size_t bufferSize) -{ - uint32 i; - - TRACE(("keyboard_read_bytes(bufferSize = %lu)\n", bufferSize)); - - if (sInterruptHandlerInstalled) { - ps2_claim_result(buffer, bufferSize); - return ps2_wait_for_result(); - } - - for (i = 0; i < bufferSize; i++) { - status_t status = ps2_read_data(&buffer[i]); - if (status != B_OK) - return status; - } - - return B_OK; -} - - -static status_t -keyboard_command(uint8 command, uint8 *buffer, size_t bufferSize) -{ - status_t status; - uint32 i; - - TRACE(("keyboard_command(command = %u, bufferSize = %lu)\n", command, bufferSize)); - - status = keyboard_write_byte(command); - if (status != B_OK) - return status; - - for (i = 0; i < bufferSize; i++) { - status = keyboard_write_byte(buffer[i]); - if (status != B_OK) - return status; - } - - return B_OK; -} static status_t @@ -129,18 +55,19 @@ set_leds(led_info *ledInfo) if (ledInfo->caps_lock) leds |= LED_CAPS; - return keyboard_command(PS2_DATA_SET_LEDS, &leds, sizeof(leds)); + return ps2_keyboard_command(PS2_DATA_SET_LEDS, &leds, 1, NULL, 0); } int32 keyboard_handle_int(uint8 data) { + at_kbd_io keyInfo; + uint8 scancode; + if (atomic_and(&sKeyboardOpenMask, 1) == 0) return B_HANDLED_INTERRUPT; - at_kbd_io keyInfo; - uint8 scancode; // TODO: Handle braindead "pause" key special case @@ -214,9 +141,9 @@ enable_keyboard(void) uint32 tries = 3; while (tries-- > 0) { - keyboard_empty_data(); +// keyboard_empty_data(); - if (keyboard_command(PS2_ENABLE_KEYBOARD, NULL, 0) == B_OK) + if (ps2_keyboard_command(PS2_ENABLE_KEYBOARD, NULL, 0, NULL, 0) == B_OK) return B_OK; } @@ -272,7 +199,6 @@ probe_keyboard(void) status_t keyboard_open(const char *name, uint32 flags, void **_cookie) { - uint8 commandByte; status_t status; TRACE(("keyboard open()\n")); diff --git a/src/add-ons/kernel/drivers/input/ps2_hid_new/mouse.c b/src/add-ons/kernel/drivers/input/ps2_hid_new/mouse.c index 4048a2c5ed..70714bf7c8 100644 --- a/src/add-ons/kernel/drivers/input/ps2_hid_new/mouse.c +++ b/src/add-ons/kernel/drivers/input/ps2_hid_new/mouse.c @@ -83,40 +83,22 @@ static size_t sPacketIndex; static uint8 sPacketBuffer[PS2_MAX_PACKET_SIZE]; -/** Writes a byte to the mouse device. Uses the control port to indicate - * that the byte is sent to the auxiliary device (mouse), instead of the - * keyboard. - */ -status_t -ps2_write_aux_byte(uint8 data) -{ - TRACE(("ps2_write_aux_byte(data = %u)\n", data)); - - if (ps2_write_ctrl(PS2_CTRL_WRITE_AUX) == B_OK - && ps2_write_data(data) == B_OK - && ps2_read_data(&data) == B_OK) - return data == PS2_REPLY_ACK ? B_OK : B_TIMED_OUT; - - return B_ERROR; -} - - -/* static status_t ps2_reset_mouse() { - int8 read; + uint8 read; + status_t status; TRACE(("ps2_reset_mouse()\n")); - write_aux_byte(PS2_CMD_RESET_MOUSE); - read = read_data_byte(); + status = ps2_mouse_command(PS2_CMD_RESET_MOUSE, NULL, 0, &read, 1); + + TRACE(("reset mouse: status 0x%08x, data 0x%02x\n", status, read)); - TRACE(("reset mouse: %2x\n", read)); return B_OK; } -*/ + /** Set sampling rate of the ps2 port. @@ -128,9 +110,8 @@ ps2_set_sample_rate(uint32 rate) int32 tries = 5; while (--tries > 0) { - status_t status = ps2_write_aux_byte(PS2_CMD_SET_SAMPLE_RATE); - if (status == B_OK) - status = ps2_write_aux_byte(rate); + uint8 d = rate; + status_t status = ps2_mouse_command(PS2_CMD_SET_SAMPLE_RATE, &d, 1, NULL, 0); if (status == B_OK) return B_OK; @@ -196,13 +177,13 @@ ps2_packet_to_movement(uint8 packet[], mouse_movement *pos) */ static status_t -ps2_mouse_read(mouse_movement *userMovement) +mouse_read_event(mouse_movement *userMovement) { uint8 packet[PS2_MAX_PACKET_SIZE]; mouse_movement movement; status_t status; - TRACE(("ps2_mouse_read()\n")); + TRACE(("mouse_read_event()\n")); status = acquire_sem_etc(sMouseSem, 1, B_CAN_INTERRUPT, 0); if (status < B_OK) return status; @@ -230,8 +211,7 @@ set_mouse_enabled(bool enable) int32 tries = 5; while (true) { - if (ps2_write_aux_byte(enable ? - PS2_CMD_ENABLE_MOUSE : PS2_CMD_DISABLE_MOUSE) == B_OK) + if (ps2_mouse_command(enable ? PS2_CMD_ENABLE_MOUSE : PS2_CMD_DISABLE_MOUSE, NULL, 0, NULL, 0) == B_OK) return B_OK; if (--tries <= 0) @@ -251,7 +231,7 @@ set_mouse_enabled(bool enable) int32 mouse_handle_int(uint8 data) { - if (atomic_and(&sMouseOpenMask, 1) == 0) + if (atomic_and(&sOpenMask, 1) == 0) return B_HANDLED_INTERRUPT; if (sPacketIndex == 0 && !(data & 8)) { @@ -286,11 +266,10 @@ int32 mouse_handle_int(uint8 data) status_t probe_mouse(size_t *probed_packet_size) { - int8 deviceId = -1; + uint8 deviceId = 0; // get device id - if (ps2_write_aux_byte(PS2_CMD_GET_DEVICE_ID) == B_OK) - ps2_read_data(&deviceId); + ps2_mouse_command(PS2_CMD_GET_DEVICE_ID, NULL, 0, &deviceId, 1); TRACE(("probe_mouse(): device id: %2x\n", deviceId)); @@ -303,8 +282,7 @@ probe_mouse(size_t *probed_packet_size) && ps2_set_sample_rate(100) == B_OK && ps2_set_sample_rate(80) == B_OK) { // get device id, again - if (ps2_write_aux_byte(PS2_CMD_GET_DEVICE_ID) == B_OK) - ps2_read_data(&deviceId); + ps2_mouse_command(PS2_CMD_GET_DEVICE_ID, NULL, 0, &deviceId, 1); break; } } @@ -350,10 +328,6 @@ mouse_open(const char *name, uint32 flags, void **_cookie) sPacketIndex = 0; - status = ps2_common_initialize(); - if (status != B_OK) - goto err1; - sMouseBuffer = create_packet_buffer(MOUSE_HISTORY_SIZE * sPacketSize); if (sMouseBuffer == NULL) { TRACE(("can't allocate mouse actions buffer\n")); @@ -378,13 +352,6 @@ mouse_open(const char *name, uint32 flags, void **_cookie) goto err4; } - status = install_io_interrupt_handler(INT_PS2_MOUSE, - handle_mouse_interrupt, NULL, 0); - if (status < B_OK) { - TRACE(("mouse_open(): cannot install interrupt handler\n")); - goto err4; - } - release_sem(gDeviceOpenSemaphore); TRACE(("mouse_open(): mouse succesfully enabled\n")); @@ -395,7 +362,6 @@ err4: err3: delete_packet_buffer(sMouseBuffer); err2: - ps2_common_uninitialize(); err1: atomic_and(&sOpenMask, 0); release_sem(gDeviceOpenSemaphore); @@ -414,9 +380,6 @@ mouse_close(void *cookie) delete_packet_buffer(sMouseBuffer); delete_sem(sMouseSem); - remove_io_interrupt_handler(INT_PS2_MOUSE, handle_mouse_interrupt, NULL); - - ps2_common_uninitialize(); atomic_and(&sOpenMask, 0); return B_OK; @@ -460,7 +423,7 @@ mouse_ioctl(void *cookie, uint32 op, void *buffer, size_t length) case MS_READ: TRACE(("MS_READ\n")); - return ps2_mouse_read((mouse_movement *)buffer); + return mouse_read_event((mouse_movement *)buffer); case MS_SET_TYPE: TRACE(("MS_SET_TYPE not implemented\n"));