Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _LIBPS2_H |
| 3 | #define _LIBPS2_H |
| 4 | |
| 5 | /* |
| 6 | * Copyright (C) 1999-2002 Vojtech Pavlik |
| 7 | * Copyright (C) 2004 Dmitry Torokhov |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Dmitry Torokhov | 3a92dd3 | 2018-01-04 11:27:05 -0800 | [diff] [blame] | 10 | #include <linux/bitops.h> |
Dmitry Torokhov | b28bad6 | 2018-01-04 10:58:48 -0800 | [diff] [blame] | 11 | #include <linux/mutex.h> |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/wait.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Dmitry Torokhov | 08be954 | 2018-01-02 12:03:02 -0800 | [diff] [blame] | 15 | #define PS2_CMD_SETSCALE11 0x00e6 |
| 16 | #define PS2_CMD_SETRES 0x10e8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #define PS2_CMD_GETID 0x02f2 |
| 18 | #define PS2_CMD_RESET_BAT 0x02ff |
| 19 | |
| 20 | #define PS2_RET_BAT 0xaa |
| 21 | #define PS2_RET_ID 0x00 |
| 22 | #define PS2_RET_ACK 0xfa |
| 23 | #define PS2_RET_NAK 0xfe |
Dmitry Torokhov | a2d781f | 2008-11-19 17:02:24 -0500 | [diff] [blame] | 24 | #define PS2_RET_ERR 0xfc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Dmitry Torokhov | 3a92dd3 | 2018-01-04 11:27:05 -0800 | [diff] [blame] | 26 | #define PS2_FLAG_ACK BIT(0) /* Waiting for ACK/NAK */ |
| 27 | #define PS2_FLAG_CMD BIT(1) /* Waiting for a command to finish */ |
| 28 | #define PS2_FLAG_CMD1 BIT(2) /* Waiting for the first byte of command response */ |
| 29 | #define PS2_FLAG_WAITID BIT(3) /* Command executing is GET ID */ |
| 30 | #define PS2_FLAG_NAK BIT(4) /* Last transmission was NAKed */ |
Dmitry Torokhov | 29acc42 | 2018-01-17 12:00:24 -0800 | [diff] [blame] | 31 | #define PS2_FLAG_ACK_CMD BIT(5) /* Waiting to ACK the command (first) byte */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | struct ps2dev { |
| 34 | struct serio *serio; |
| 35 | |
| 36 | /* Ensures that only one command is executing at a time */ |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 37 | struct mutex cmd_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | /* Used to signal completion from interrupt handler */ |
| 40 | wait_queue_head_t wait; |
| 41 | |
| 42 | unsigned long flags; |
Dmitry Torokhov | b28bad6 | 2018-01-04 10:58:48 -0800 | [diff] [blame] | 43 | u8 cmdbuf[8]; |
| 44 | u8 cmdcnt; |
| 45 | u8 nak; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | void ps2_init(struct ps2dev *ps2dev, struct serio *serio); |
Dmitry Torokhov | b28bad6 | 2018-01-04 10:58:48 -0800 | [diff] [blame] | 49 | int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout); |
| 50 | void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout); |
Dmitry Torokhov | 181d683 | 2009-09-16 01:06:43 -0700 | [diff] [blame] | 51 | void ps2_begin_command(struct ps2dev *ps2dev); |
| 52 | void ps2_end_command(struct ps2dev *ps2dev); |
Dmitry Torokhov | b28bad6 | 2018-01-04 10:58:48 -0800 | [diff] [blame] | 53 | int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command); |
| 54 | int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command); |
Dmitry Torokhov | 08be954 | 2018-01-02 12:03:02 -0800 | [diff] [blame] | 55 | int ps2_sliced_command(struct ps2dev *ps2dev, u8 command); |
Dmitry Torokhov | b28bad6 | 2018-01-04 10:58:48 -0800 | [diff] [blame] | 56 | bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data); |
| 57 | bool ps2_handle_response(struct ps2dev *ps2dev, u8 data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | void ps2_cmd_aborted(struct ps2dev *ps2dev); |
Dmitry Torokhov | b28bad6 | 2018-01-04 10:58:48 -0800 | [diff] [blame] | 59 | bool ps2_is_keyboard_id(u8 id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | #endif /* _LIBPS2_H */ |