2019-06-04 15:11:33 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2005-04-17 05:20:36 +07:00
|
|
|
#ifndef _LIBPS2_H
|
|
|
|
#define _LIBPS2_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 1999-2002 Vojtech Pavlik
|
|
|
|
* Copyright (C) 2004 Dmitry Torokhov
|
|
|
|
*/
|
|
|
|
|
2018-01-05 02:27:05 +07:00
|
|
|
#include <linux/bitops.h>
|
2018-01-05 01:58:48 +07:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/wait.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2018-01-03 03:03:02 +07:00
|
|
|
#define PS2_CMD_SETSCALE11 0x00e6
|
|
|
|
#define PS2_CMD_SETRES 0x10e8
|
2005-04-17 05:20:36 +07:00
|
|
|
#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
|
2008-11-20 05:02:24 +07:00
|
|
|
#define PS2_RET_ERR 0xfc
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2018-01-05 02:27:05 +07:00
|
|
|
#define PS2_FLAG_ACK BIT(0) /* Waiting for ACK/NAK */
|
|
|
|
#define PS2_FLAG_CMD BIT(1) /* Waiting for a command to finish */
|
|
|
|
#define PS2_FLAG_CMD1 BIT(2) /* Waiting for the first byte of command response */
|
|
|
|
#define PS2_FLAG_WAITID BIT(3) /* Command executing is GET ID */
|
|
|
|
#define PS2_FLAG_NAK BIT(4) /* Last transmission was NAKed */
|
2018-01-18 03:00:24 +07:00
|
|
|
#define PS2_FLAG_ACK_CMD BIT(5) /* Waiting to ACK the command (first) byte */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
struct ps2dev {
|
|
|
|
struct serio *serio;
|
|
|
|
|
|
|
|
/* Ensures that only one command is executing at a time */
|
2006-02-19 12:21:55 +07:00
|
|
|
struct mutex cmd_mutex;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Used to signal completion from interrupt handler */
|
|
|
|
wait_queue_head_t wait;
|
|
|
|
|
|
|
|
unsigned long flags;
|
2018-01-05 01:58:48 +07:00
|
|
|
u8 cmdbuf[8];
|
|
|
|
u8 cmdcnt;
|
|
|
|
u8 nak;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
void ps2_init(struct ps2dev *ps2dev, struct serio *serio);
|
2018-01-05 01:58:48 +07:00
|
|
|
int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout);
|
|
|
|
void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout);
|
2009-09-16 15:06:43 +07:00
|
|
|
void ps2_begin_command(struct ps2dev *ps2dev);
|
|
|
|
void ps2_end_command(struct ps2dev *ps2dev);
|
2018-01-05 01:58:48 +07:00
|
|
|
int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
|
|
|
|
int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
|
2018-01-03 03:03:02 +07:00
|
|
|
int ps2_sliced_command(struct ps2dev *ps2dev, u8 command);
|
2018-01-05 01:58:48 +07:00
|
|
|
bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data);
|
|
|
|
bool ps2_handle_response(struct ps2dev *ps2dev, u8 data);
|
2005-04-17 05:20:36 +07:00
|
|
|
void ps2_cmd_aborted(struct ps2dev *ps2dev);
|
2018-01-05 01:58:48 +07:00
|
|
|
bool ps2_is_keyboard_id(u8 id);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#endif /* _LIBPS2_H */
|