libps2.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef _LIBPS2_H
  3. #define _LIBPS2_H
  4. /*
  5. * Copyright (C) 1999-2002 Vojtech Pavlik
  6. * Copyright (C) 2004 Dmitry Torokhov
  7. */
  8. #include <linux/bitops.h>
  9. #include <linux/mutex.h>
  10. #include <linux/types.h>
  11. #include <linux/wait.h>
  12. #define PS2_CMD_SETSCALE11 0x00e6
  13. #define PS2_CMD_SETRES 0x10e8
  14. #define PS2_CMD_GETID 0x02f2
  15. #define PS2_CMD_RESET_BAT 0x02ff
  16. #define PS2_RET_BAT 0xaa
  17. #define PS2_RET_ID 0x00
  18. #define PS2_RET_ACK 0xfa
  19. #define PS2_RET_NAK 0xfe
  20. #define PS2_RET_ERR 0xfc
  21. #define PS2_FLAG_ACK BIT(0) /* Waiting for ACK/NAK */
  22. #define PS2_FLAG_CMD BIT(1) /* Waiting for a command to finish */
  23. #define PS2_FLAG_CMD1 BIT(2) /* Waiting for the first byte of command response */
  24. #define PS2_FLAG_WAITID BIT(3) /* Command executing is GET ID */
  25. #define PS2_FLAG_NAK BIT(4) /* Last transmission was NAKed */
  26. #define PS2_FLAG_ACK_CMD BIT(5) /* Waiting to ACK the command (first) byte */
  27. struct ps2dev {
  28. struct serio *serio;
  29. /* Ensures that only one command is executing at a time */
  30. struct mutex cmd_mutex;
  31. /* Used to signal completion from interrupt handler */
  32. wait_queue_head_t wait;
  33. unsigned long flags;
  34. u8 cmdbuf[8];
  35. u8 cmdcnt;
  36. u8 nak;
  37. };
  38. void ps2_init(struct ps2dev *ps2dev, struct serio *serio);
  39. int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout);
  40. void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout);
  41. void ps2_begin_command(struct ps2dev *ps2dev);
  42. void ps2_end_command(struct ps2dev *ps2dev);
  43. int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
  44. int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command);
  45. int ps2_sliced_command(struct ps2dev *ps2dev, u8 command);
  46. bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data);
  47. bool ps2_handle_response(struct ps2dev *ps2dev, u8 data);
  48. void ps2_cmd_aborted(struct ps2dev *ps2dev);
  49. bool ps2_is_keyboard_id(u8 id);
  50. #endif /* _LIBPS2_H */