/** @file
PS2 Mouse Communication Interface.
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Ps2Mouse.h"
#include "CommPs2.h"
/**
Issue self test command via IsaIo interface.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@return EFI_SUCCESS Success to do keyboard self testing.
@return others Fail to do keyboard self testing.
**/
)
{
//
// Keyboard controller self test
//
return Status;
}
//
// Read return code
//
return Status;
}
if (Data != 0x55) {
return EFI_DEVICE_ERROR;
}
//
// Set system flag
//
return Status;
}
return Status;
}
return Status;
}
Data |= CMD_SYS_FLAG;
return Status;
}
return EFI_SUCCESS;
}
/**
Issue command to enable keyboard AUX functionality.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@return Status of command issuing.
**/
)
{
//
// Send 8042 enable mouse command
//
}
/**
Issue command to disable keyboard AUX functionality.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@return Status of command issuing.
**/
)
{
//
// Send 8042 disable mouse command
//
}
/**
Issue command to enable keyboard.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@return Status of command issuing.
**/
)
{
//
// Send 8042 enable keyboard command
//
}
/**
Issue command to disable keyboard.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@return Status of command issuing.
**/
)
{
//
// Send 8042 disable keyboard command
//
}
/**
Issue command to check keyboard status.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param KeyboardEnable return whether keyboard is enable.
@return Status of command issuing.
**/
)
{
//
// Send command to read KBC command byte
//
return Status;
}
return Status;
}
//
// Check keyboard enable or not
//
*KeyboardEnable = FALSE;
} else {
*KeyboardEnable = TRUE;
}
return EFI_SUCCESS;
}
/**
Issue command to reset keyboard.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@return Status of command issuing.
**/
)
{
return Status;
}
return Status;
}
//
// Check BAT Complete Code
//
if (Data != PS2MOUSE_BAT1) {
return EFI_DEVICE_ERROR;
}
return Status;
}
//
// Check BAT Complete Code
//
if (Data != PS2MOUSE_BAT2) {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
Issue command to set mouse's sample rate
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param SampleRate value of sample rate
@return Status of command issuing.
**/
)
{
//
// Send auxiliary command to set mouse sample rate
//
return Status;
}
return Status;
}
/**
Issue command to set mouse's resolution.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Resolution value of resolution
@return Status of command issuing.
**/
)
{
//
// Send auxiliary command to set mouse resolution
//
return Status;
}
return Status;
}
/**
Issue command to set mouse's scaling.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Scaling value of scaling
@return Status of command issuing.
**/
)
{
//
// Send auxiliary command to set mouse scaling data
//
}
/**
Issue command to enable Ps2 mouse.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@return Status of command issuing.
**/
)
{
//
// Send auxiliary command to enable mouse
//
}
/**
Get mouse packet . Only care first 3 bytes
@param MouseDev Pointer of PS2 Mouse Private Data Structure
@retval EFI_NOT_READY Mouse Device not ready to input data packet, or some error happened during getting the packet
@retval EFI_SUCCESS The data packet is gotten successfully.
**/
)
{
Count = 1;
//
// State machine to get mouse packet
//
while (1) {
switch (State) {
case PS2_READ_BYTE_ONE:
//
// Read mouse first byte data, if failed, immediately return
//
return EFI_NOT_READY;
}
if (Count != 1) {
return EFI_NOT_READY;
}
if (IS_PS2_SYNC_BYTE (Data)) {
}
break;
case PS2_READ_DATA_BYTE:
Count = 2;
if (KeyboardEnable) {
}
return EFI_NOT_READY;
}
if (Count != 2) {
if (KeyboardEnable) {
}
return EFI_NOT_READY;
}
break;
case PS2_PROCESS_PACKET:
if (KeyboardEnable) {
}
//
// Decode the packet
//
//
// Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0
// Byte 0 | Y overflow | X overflow | Y sign bit | X sign bit | Always 1 | Middle Btn | Right Btn | Left Btn
// Byte 1 | 8 bit X Movement
// Byte 2 | 8 bit Y Movement
//
// X sign bit + 8 bit X Movement : 9-bit signed twos complement integer that presents the relative displacement of the device in the X direction since the last data transmission.
// Y sign bit + 8 bit Y Movement : Same as X sign bit + 8 bit X Movement.
//
//
// First, Clear X and Y high 8 bits
//
//
// Second, if the 9-bit signed twos complement integer is negative, set the high 8 bit 0xff
//
if ((Packet[0] & 0x10) != 0) {
}
if ((Packet[0] & 0x20) != 0) {
}
//
// Update mouse state
//
return EFI_SUCCESS;
}
}
}
/**
Read data via IsaIo protocol with given number.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Buffer Buffer receive data of mouse
@param BufSize The size of buffer
@param State Check input or read data
@return status of reading mouse data.
**/
)
{
BytesRead = 0;
if (State == PS2_READ_BYTE_ONE) {
//
// Check input for mouse
//
return Status;
}
}
break;
}
BytesRead++;
}
//
// Verify the correct number of bytes read
//
}
return Status;
}
//
// 8042 I/O function
//
/**
I/O work flow of outing 8042 command.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Command I/O command.
@retval EFI_SUCCESS Success to excute I/O work flow
@retval EFI_TIMEOUT Keyboard controller time out.
**/
)
{
//
// Wait keyboard controller input buffer empty
//
return Status;
}
//
// Send command
//
return Status;
}
return EFI_SUCCESS;
}
/**
I/O work flow of outing 8042 data.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Data Data value
@retval EFI_SUCCESS Success to excute I/O work flow
@retval EFI_TIMEOUT Keyboard controller time out.
**/
)
{
//
// Wait keyboard controller input buffer empty
//
return Status;
}
return Status;
}
return EFI_SUCCESS;
}
/**
I/O work flow of in 8042 data.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Data Data value
@retval EFI_SUCCESS Success to excute I/O work flow
@retval EFI_TIMEOUT Keyboard controller time out.
**/
)
{
do {
//
// Check keyboard controller status bit 0(output buffer status)
//
break;
}
Delay--;
} while (Delay != 0);
if (Delay == 0) {
return EFI_TIMEOUT;
}
return EFI_SUCCESS;
}
/**
I/O work flow of outing 8042 Aux command.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Command Aux I/O command
@param Resend Whether need resend the Aux command.
@retval EFI_SUCCESS Success to excute I/O work flow
@retval EFI_TIMEOUT Keyboard controller time out.
**/
)
{
//
// Wait keyboard controller input buffer empty
//
return Status;
}
//
// Send write to auxiliary device command
//
return Status;
}
//
// Send auxiliary device command
//
//
// Read return code
//
return Status;
}
//
// Receive mouse acknowledge, command send success
//
return EFI_SUCCESS;
} else if (Resend) {
//
// Resend fail
//
return EFI_DEVICE_ERROR;
} else if (Data == PS2_RESEND) {
//
// Resend command
//
return Status;
}
} else {
//
// Invalid return code
//
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
I/O work flow of outing 8042 Aux data.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Data Buffer holding return value
@retval EFI_SUCCESS Success to excute I/O work flow
@retval EFI_TIMEOUT Keyboard controller time out.
**/
)
{
//
// Wait keyboard controller input buffer empty
//
return Status;
}
//
// Send write to auxiliary device command
//
return Status;
}
return Status;
}
return EFI_SUCCESS;
}
/**
I/O work flow of in 8042 Aux data.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Data Buffer holding return value.
@retval EFI_SUCCESS Success to excute I/O work flow
@retval EFI_TIMEOUT Keyboard controller time out.
**/
)
{
//
// wait for output data
//
return Status;
}
return EFI_SUCCESS;
}
/**
Check keyboard controller status, if it is output buffer full and for auxiliary device.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@retval EFI_SUCCESS Keyboard controller is ready
@retval EFI_NOT_READY Keyboard controller is not ready
**/
)
{
//
// Check keyboard controller status, if it is output buffer full and for auxiliary device
//
return EFI_NOT_READY;
}
return EFI_SUCCESS;
}
/**
I/O work flow to wait input buffer empty in given time.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Timeout Wating time.
@retval EFI_TIMEOUT if input is still not empty in given time.
@retval EFI_SUCCESS input is empty.
**/
)
{
do {
//
// Check keyboard controller status bit 1(input buffer status)
//
break;
}
Delay--;
} while (Delay != 0);
if (Delay == 0) {
return EFI_TIMEOUT;
}
return EFI_SUCCESS;
}
/**
I/O work flow to wait output buffer full in given time.
@param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
@param Timeout given time
@retval EFI_TIMEOUT output is not full in given time
@retval EFI_SUCCESS output is full in given time.
**/
)
{
do {
//
// Check keyboard controller status bit 0(output buffer status)
// & bit5(output buffer for auxiliary device)
//
break;
}
Delay--;
} while (Delay != 0);
if (Delay == 0) {
return EFI_TIMEOUT;
}
return EFI_SUCCESS;
}