Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
1da177e4 LT |
2 | #ifndef _LIBPS2_H |
3 | #define _LIBPS2_H | |
4 | ||
5 | /* | |
6 | * Copyright (C) 1999-2002 Vojtech Pavlik | |
7 | * Copyright (C) 2004 Dmitry Torokhov | |
1da177e4 LT |
8 | */ |
9 | ||
3a92dd33 | 10 | #include <linux/bitops.h> |
c4c7eac8 | 11 | #include <linux/interrupt.h> |
b28bad65 DT |
12 | #include <linux/mutex.h> |
13 | #include <linux/types.h> | |
14 | #include <linux/wait.h> | |
1da177e4 | 15 | |
c4c7eac8 | 16 | struct ps2dev; |
1da177e4 | 17 | |
c4c7eac8 DT |
18 | /** |
19 | * enum ps2_disposition - indicates how received byte should be handled | |
20 | * @PS2_PROCESS: pass to the main protocol handler, process normally | |
21 | * @PS2_IGNORE: skip the byte | |
22 | * @PS2_ERROR: do not process the byte, abort command in progress | |
23 | */ | |
24 | enum ps2_disposition { | |
25 | PS2_PROCESS, | |
26 | PS2_IGNORE, | |
27 | PS2_ERROR, | |
28 | }; | |
1da177e4 | 29 | |
c4c7eac8 DT |
30 | typedef enum ps2_disposition (*ps2_pre_receive_handler_t)(struct ps2dev *, u8, |
31 | unsigned int); | |
32 | typedef void (*ps2_receive_handler_t)(struct ps2dev *, u8); | |
1da177e4 | 33 | |
c4c7eac8 DT |
34 | /** |
35 | * struct ps2dev - represents a device using PS/2 protocol | |
36 | * @serio: a serio port used by the PS/2 device | |
37 | * @cmd_mutex: a mutex ensuring that only one command is executing at a time | |
38 | * @wait: a waitqueue used to signal completion from the serio interrupt handler | |
39 | * @flags: various internal flags indicating stages of PS/2 command execution | |
40 | * @cmdbuf: buffer holding command response | |
41 | * @cmdcnt: outstanding number of bytes of the command response | |
42 | * @nak: a byte transmitted by the device when it refuses command | |
43 | * @pre_receive_handler: checks communication errors and returns disposition | |
44 | * (&enum ps2_disposition) of the received data byte | |
45 | * @receive_handler: main handler of particular PS/2 protocol, such as keyboard | |
46 | * or mouse protocol | |
47 | */ | |
1da177e4 LT |
48 | struct ps2dev { |
49 | struct serio *serio; | |
c4e32e9f | 50 | struct mutex cmd_mutex; |
1da177e4 | 51 | wait_queue_head_t wait; |
1da177e4 | 52 | unsigned long flags; |
b28bad65 DT |
53 | u8 cmdbuf[8]; |
54 | u8 cmdcnt; | |
55 | u8 nak; | |
c4c7eac8 DT |
56 | |
57 | ps2_pre_receive_handler_t pre_receive_handler; | |
58 | ps2_receive_handler_t receive_handler; | |
1da177e4 LT |
59 | }; |
60 | ||
c4c7eac8 DT |
61 | void ps2_init(struct ps2dev *ps2dev, struct serio *serio, |
62 | ps2_pre_receive_handler_t pre_receive_handler, | |
63 | ps2_receive_handler_t receive_handler); | |
b28bad65 DT |
64 | int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout); |
65 | void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout); | |
181d683d DT |
66 | void ps2_begin_command(struct ps2dev *ps2dev); |
67 | void ps2_end_command(struct ps2dev *ps2dev); | |
b28bad65 DT |
68 | int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command); |
69 | int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command); | |
08be954b | 70 | int ps2_sliced_command(struct ps2dev *ps2dev, u8 command); |
b28bad65 | 71 | bool ps2_is_keyboard_id(u8 id); |
1da177e4 | 72 | |
c4c7eac8 DT |
73 | irqreturn_t ps2_interrupt(struct serio *serio, u8 data, unsigned int flags); |
74 | ||
1da177e4 | 75 | #endif /* _LIBPS2_H */ |