Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LIBPS2_H |
| 2 | #define _LIBPS2_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 1999-2002 Vojtech Pavlik |
| 6 | * Copyright (C) 2004 Dmitry Torokhov |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License version 2 as published by |
| 10 | * the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #define PS2_CMD_GETID 0x02f2 |
| 15 | #define PS2_CMD_RESET_BAT 0x02ff |
| 16 | |
| 17 | #define PS2_RET_BAT 0xaa |
| 18 | #define PS2_RET_ID 0x00 |
| 19 | #define PS2_RET_ACK 0xfa |
| 20 | #define PS2_RET_NAK 0xfe |
Dmitry Torokhov | a2d781f | 2008-11-19 17:02:24 -0500 | [diff] [blame] | 21 | #define PS2_RET_ERR 0xfc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #define PS2_FLAG_ACK 1 /* Waiting for ACK/NAK */ |
| 24 | #define PS2_FLAG_CMD 2 /* Waiting for command to finish */ |
| 25 | #define PS2_FLAG_CMD1 4 /* Waiting for the first byte of command response */ |
| 26 | #define PS2_FLAG_WAITID 8 /* Command execiting is GET ID */ |
Dmitry Torokhov | a2d781f | 2008-11-19 17:02:24 -0500 | [diff] [blame] | 27 | #define PS2_FLAG_NAK 16 /* Last transmission was NAKed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | struct ps2dev { |
| 30 | struct serio *serio; |
| 31 | |
| 32 | /* Ensures that only one command is executing at a time */ |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 33 | struct mutex cmd_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | /* Used to signal completion from interrupt handler */ |
| 36 | wait_queue_head_t wait; |
| 37 | |
| 38 | unsigned long flags; |
| 39 | unsigned char cmdbuf[6]; |
| 40 | unsigned char cmdcnt; |
| 41 | unsigned char nak; |
| 42 | }; |
| 43 | |
| 44 | void ps2_init(struct ps2dev *ps2dev, struct serio *serio); |
| 45 | int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout); |
Dmitry Torokhov | c611763 | 2005-06-01 02:39:51 -0500 | [diff] [blame] | 46 | void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout); |
Tai-hwa Liang | fc69f4a | 2009-05-10 18:15:39 -0700 | [diff] [blame^] | 47 | int __ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data); |
| 50 | int ps2_handle_response(struct ps2dev *ps2dev, unsigned char data); |
| 51 | void ps2_cmd_aborted(struct ps2dev *ps2dev); |
Dmitry Torokhov | 9807879 | 2006-09-14 01:31:27 -0400 | [diff] [blame] | 52 | int ps2_is_keyboard_id(char id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | #endif /* _LIBPS2_H */ |