blob: 3c69cd796f48b4e85479ce43ae5fa39d08eb80a1 [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 Torokhov3a92dd32018-01-04 11:27:05 -080013#include <linux/bitops.h>
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080014#include <linux/mutex.h>
15#include <linux/types.h>
16#include <linux/wait.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Dmitry Torokhov08be9542018-01-02 12:03:02 -080018#define PS2_CMD_SETSCALE11 0x00e6
19#define PS2_CMD_SETRES 0x10e8
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#define PS2_CMD_GETID 0x02f2
21#define PS2_CMD_RESET_BAT 0x02ff
22
23#define PS2_RET_BAT 0xaa
24#define PS2_RET_ID 0x00
25#define PS2_RET_ACK 0xfa
26#define PS2_RET_NAK 0xfe
Dmitry Torokhova2d781f2008-11-19 17:02:24 -050027#define PS2_RET_ERR 0xfc
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Dmitry Torokhov3a92dd32018-01-04 11:27:05 -080029#define PS2_FLAG_ACK BIT(0) /* Waiting for ACK/NAK */
30#define PS2_FLAG_CMD BIT(1) /* Waiting for a command to finish */
31#define PS2_FLAG_CMD1 BIT(2) /* Waiting for the first byte of command response */
32#define PS2_FLAG_WAITID BIT(3) /* Command executing is GET ID */
33#define PS2_FLAG_NAK BIT(4) /* Last transmission was NAKed */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35struct ps2dev {
36 struct serio *serio;
37
38 /* Ensures that only one command is executing at a time */
Arjan van de Venc4e32e92006-02-19 00:21:55 -050039 struct mutex cmd_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41 /* Used to signal completion from interrupt handler */
42 wait_queue_head_t wait;
43
44 unsigned long flags;
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080045 u8 cmdbuf[8];
46 u8 cmdcnt;
47 u8 nak;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048};
49
50void ps2_init(struct ps2dev *ps2dev, struct serio *serio);
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080051int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout);
52void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout);
Dmitry Torokhov181d6832009-09-16 01:06:43 -070053void ps2_begin_command(struct ps2dev *ps2dev);
54void ps2_end_command(struct ps2dev *ps2dev);
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080055int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
56int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
Dmitry Torokhov08be9542018-01-02 12:03:02 -080057int ps2_sliced_command(struct ps2dev *ps2dev, u8 command);
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080058bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data);
59bool ps2_handle_response(struct ps2dev *ps2dev, u8 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060void ps2_cmd_aborted(struct ps2dev *ps2dev);
Dmitry Torokhovb28bad62018-01-04 10:58:48 -080061bool ps2_is_keyboard_id(u8 id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#endif /* _LIBPS2_H */