1 /* SPDX-License-Identifier: GPL-2.0-only */
6 * Copyright (C) 1999-2002 Vojtech Pavlik
7 * Copyright (C) 2004 Dmitry Torokhov
10 #include <linux/bitops.h>
11 #include <linux/interrupt.h>
12 #include <linux/mutex.h>
13 #include <linux/types.h>
14 #include <linux/wait.h>
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
24 enum ps2_disposition {
30 typedef enum ps2_disposition (*ps2_pre_receive_handler_t)(struct ps2dev *, u8,
32 typedef void (*ps2_receive_handler_t)(struct ps2dev *, u8);
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
50 struct mutex cmd_mutex;
51 wait_queue_head_t wait;
57 ps2_pre_receive_handler_t pre_receive_handler;
58 ps2_receive_handler_t receive_handler;
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);
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);
66 void ps2_begin_command(struct ps2dev *ps2dev);
67 void ps2_end_command(struct ps2dev *ps2dev);
68 int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
69 int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
70 int ps2_sliced_command(struct ps2dev *ps2dev, u8 command);
71 bool ps2_is_keyboard_id(u8 id);
73 irqreturn_t ps2_interrupt(struct serio *serio, u8 data, unsigned int flags);
75 #endif /* _LIBPS2_H */