summaryrefslogtreecommitdiff
path: root/include/linux/libps2.h
blob: 04a5750f1e4eeeee569c53b4610cbde4c551c52f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef _LIBPS2_H
#define _LIBPS2_H

/*
 * Copyright (C) 1999-2002 Vojtech Pavlik
 * Copyright (C) 2004 Dmitry Torokhov
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 */

#include <linux/mutex.h>
#include <linux/types.h>
#include <linux/wait.h>

#define PS2_CMD_GETID		0x02f2
#define PS2_CMD_RESET_BAT	0x02ff

#define PS2_RET_BAT		0xaa
#define PS2_RET_ID		0x00
#define PS2_RET_ACK		0xfa
#define PS2_RET_NAK		0xfe
#define PS2_RET_ERR		0xfc

#define PS2_FLAG_ACK		1	/* Waiting for ACK/NAK */
#define PS2_FLAG_CMD		2	/* Waiting for command to finish */
#define PS2_FLAG_CMD1		4	/* Waiting for the first byte of command response */
#define PS2_FLAG_WAITID		8	/* Command execiting is GET ID */
#define PS2_FLAG_NAK		16	/* Last transmission was NAKed */

struct ps2dev {
	struct serio *serio;

	/* Ensures that only one command is executing at a time */
	struct mutex cmd_mutex;

	/* Used to signal completion from interrupt handler */
	wait_queue_head_t wait;

	unsigned long flags;
	u8 cmdbuf[8];
	u8 cmdcnt;
	u8 nak;
};

void ps2_init(struct ps2dev *ps2dev, struct serio *serio);
int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout);
void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout);
void ps2_begin_command(struct ps2dev *ps2dev);
void ps2_end_command(struct ps2dev *ps2dev);
int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data);
bool ps2_handle_response(struct ps2dev *ps2dev, u8 data);
void ps2_cmd_aborted(struct ps2dev *ps2dev);
bool ps2_is_keyboard_id(u8 id);

#endif /* _LIBPS2_H */