0001
0002 #ifndef _LIBPS2_H
0003 #define _LIBPS2_H
0004
0005
0006
0007
0008
0009
0010 #include <linux/bitops.h>
0011 #include <linux/mutex.h>
0012 #include <linux/types.h>
0013 #include <linux/wait.h>
0014
0015 #define PS2_CMD_SETSCALE11 0x00e6
0016 #define PS2_CMD_SETRES 0x10e8
0017 #define PS2_CMD_GETID 0x02f2
0018 #define PS2_CMD_RESET_BAT 0x02ff
0019
0020 #define PS2_RET_BAT 0xaa
0021 #define PS2_RET_ID 0x00
0022 #define PS2_RET_ACK 0xfa
0023 #define PS2_RET_NAK 0xfe
0024 #define PS2_RET_ERR 0xfc
0025
0026 #define PS2_FLAG_ACK BIT(0)
0027 #define PS2_FLAG_CMD BIT(1)
0028 #define PS2_FLAG_CMD1 BIT(2)
0029 #define PS2_FLAG_WAITID BIT(3)
0030 #define PS2_FLAG_NAK BIT(4)
0031 #define PS2_FLAG_ACK_CMD BIT(5)
0032
0033 struct ps2dev {
0034 struct serio *serio;
0035
0036
0037 struct mutex cmd_mutex;
0038
0039
0040 wait_queue_head_t wait;
0041
0042 unsigned long flags;
0043 u8 cmdbuf[8];
0044 u8 cmdcnt;
0045 u8 nak;
0046 };
0047
0048 void ps2_init(struct ps2dev *ps2dev, struct serio *serio);
0049 int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout);
0050 void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout);
0051 void ps2_begin_command(struct ps2dev *ps2dev);
0052 void ps2_end_command(struct ps2dev *ps2dev);
0053 int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
0054 int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
0055 int ps2_sliced_command(struct ps2dev *ps2dev, u8 command);
0056 bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data);
0057 bool ps2_handle_response(struct ps2dev *ps2dev, u8 data);
0058 void ps2_cmd_aborted(struct ps2dev *ps2dev);
0059 bool ps2_is_keyboard_id(u8 id);
0060
0061 #endif