blob: 04a5750f1e4eeeee569c53b4610cbde4c551c52f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080013#include <linux/mutex.h>
14#include <linux/types.h>
15#include <linux/wait.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
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 Torokhova2d781f2008-11-19 17:02:24 -050024#define PS2_RET_ERR 0xfc
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#define PS2_FLAG_ACK 1 /* Waiting for ACK/NAK */
27#define PS2_FLAG_CMD 2 /* Waiting for command to finish */
28#define PS2_FLAG_CMD1 4 /* Waiting for the first byte of command response */
29#define PS2_FLAG_WAITID 8 /* Command execiting is GET ID */
Dmitry Torokhova2d781f2008-11-19 17:02:24 -050030#define PS2_FLAG_NAK 16 /* Last transmission was NAKed */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32struct ps2dev {
33 struct serio *serio;
34
35 /* Ensures that only one command is executing at a time */
Arjan van de Venc4e32e92006-02-19 00:21:55 -050036 struct mutex cmd_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 /* Used to signal completion from interrupt handler */
39 wait_queue_head_t wait;
40
41 unsigned long flags;
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080042 u8 cmdbuf[8];
43 u8 cmdcnt;
44 u8 nak;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045};
46
47void ps2_init(struct ps2dev *ps2dev, struct serio *serio);
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080048int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout);
49void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout);
Dmitry Torokhov181d6832009-09-16 01:06:43 -070050void ps2_begin_command(struct ps2dev *ps2dev);
51void ps2_end_command(struct ps2dev *ps2dev);
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080052int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
53int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
54bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data);
55bool ps2_handle_response(struct ps2dev *ps2dev, u8 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056void ps2_cmd_aborted(struct ps2dev *ps2dev);
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080057bool ps2_is_keyboard_id(u8 id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#endif /* _LIBPS2_H */