reimplemented waiting for read/write, added flush function
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15934 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -90,47 +90,48 @@ ps2_write_data(uint8 data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
/** Wait until the specified status bits are cleared or set, depending on the
|
ps2_wait_read()
|
||||||
* second parameter.
|
|
||||||
* This currently busy waits, but should nonetheless be avoided in interrupt
|
|
||||||
* handlers.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static status_t
|
|
||||||
wait_for_status(int32 bits, bool set)
|
|
||||||
{
|
{
|
||||||
int8 read;
|
int i;
|
||||||
int32 tries = 100;
|
for (i = 0; i < PS2_CTRL_WAIT_TIMEOUT / 50; i++) {
|
||||||
|
if (ps2_read_ctrl() & PS2_STATUS_OUTPUT_BUFFER_FULL)
|
||||||
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)
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
snooze(50);
|
||||||
spin(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline status_t
|
status_t
|
||||||
wait_for_bits_cleared(int32 bits)
|
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
|
void
|
||||||
wait_for_bits_set(int32 bits)
|
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.
|
/** Reads the command byte from the 8042 controller.
|
||||||
* Since the read goes through the data port, this function must not be
|
* Since the read goes through the data port, this function must not be
|
||||||
* called when the keyboard driver is up and running.
|
* called when the keyboard driver is up and running.
|
||||||
@@ -355,7 +356,7 @@ init_driver(void)
|
|||||||
if (status)
|
if (status)
|
||||||
goto err_3;
|
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)
|
if (status)
|
||||||
goto err_4;
|
goto err_4;
|
||||||
|
|
||||||
|
|||||||
@@ -74,4 +74,7 @@
|
|||||||
#define PS2_MAX_PACKET_SIZE 4
|
#define PS2_MAX_PACKET_SIZE 4
|
||||||
// Should be equal to the biggest packet size
|
// Should be equal to the biggest packet size
|
||||||
|
|
||||||
|
// timeouts
|
||||||
|
#define PS2_CTRL_WAIT_TIMEOUT 500000
|
||||||
|
|
||||||
#endif /* _PS2_H */
|
#endif /* _PS2_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user