psmouse.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #ifndef _PSMOUSE_H
  2. #define _PSMOUSE_H
  3. #define PSMOUSE_CMD_SETSCALE11 0x00e6
  4. #define PSMOUSE_CMD_SETSCALE21 0x00e7
  5. #define PSMOUSE_CMD_SETRES 0x10e8
  6. #define PSMOUSE_CMD_GETINFO 0x03e9
  7. #define PSMOUSE_CMD_SETSTREAM 0x00ea
  8. #define PSMOUSE_CMD_SETPOLL 0x00f0
  9. #define PSMOUSE_CMD_POLL 0x00eb /* caller sets number of bytes to receive */
  10. #define PSMOUSE_CMD_RESET_WRAP 0x00ec
  11. #define PSMOUSE_CMD_GETID 0x02f2
  12. #define PSMOUSE_CMD_SETRATE 0x10f3
  13. #define PSMOUSE_CMD_ENABLE 0x00f4
  14. #define PSMOUSE_CMD_DISABLE 0x00f5
  15. #define PSMOUSE_CMD_RESET_DIS 0x00f6
  16. #define PSMOUSE_CMD_RESET_BAT 0x02ff
  17. #define PSMOUSE_RET_BAT 0xaa
  18. #define PSMOUSE_RET_ID 0x00
  19. #define PSMOUSE_RET_ACK 0xfa
  20. #define PSMOUSE_RET_NAK 0xfe
  21. enum psmouse_state {
  22. PSMOUSE_IGNORE,
  23. PSMOUSE_INITIALIZING,
  24. PSMOUSE_RESYNCING,
  25. PSMOUSE_CMD_MODE,
  26. PSMOUSE_ACTIVATED,
  27. };
  28. /* psmouse protocol handler return codes */
  29. typedef enum {
  30. PSMOUSE_BAD_DATA,
  31. PSMOUSE_GOOD_DATA,
  32. PSMOUSE_FULL_PACKET
  33. } psmouse_ret_t;
  34. enum psmouse_scale {
  35. PSMOUSE_SCALE11,
  36. PSMOUSE_SCALE21
  37. };
  38. struct psmouse {
  39. void *private;
  40. struct input_dev *dev;
  41. struct ps2dev ps2dev;
  42. struct delayed_work resync_work;
  43. char *vendor;
  44. char *name;
  45. unsigned char packet[8];
  46. unsigned char badbyte;
  47. unsigned char pktcnt;
  48. unsigned char pktsize;
  49. unsigned char type;
  50. bool ignore_parity;
  51. bool acks_disable_command;
  52. unsigned int model;
  53. unsigned long last;
  54. unsigned long out_of_sync_cnt;
  55. unsigned long num_resyncs;
  56. enum psmouse_state state;
  57. char devname[64];
  58. char phys[32];
  59. unsigned int rate;
  60. unsigned int resolution;
  61. unsigned int resetafter;
  62. unsigned int resync_time;
  63. bool smartscroll; /* Logitech only */
  64. psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse);
  65. void (*set_rate)(struct psmouse *psmouse, unsigned int rate);
  66. void (*set_resolution)(struct psmouse *psmouse, unsigned int resolution);
  67. void (*set_scale)(struct psmouse *psmouse, enum psmouse_scale scale);
  68. int (*reconnect)(struct psmouse *psmouse);
  69. void (*disconnect)(struct psmouse *psmouse);
  70. void (*cleanup)(struct psmouse *psmouse);
  71. int (*poll)(struct psmouse *psmouse);
  72. void (*pt_activate)(struct psmouse *psmouse);
  73. void (*pt_deactivate)(struct psmouse *psmouse);
  74. };
  75. enum psmouse_type {
  76. PSMOUSE_NONE,
  77. PSMOUSE_PS2,
  78. PSMOUSE_PS2PP,
  79. PSMOUSE_THINKPS,
  80. PSMOUSE_GENPS,
  81. PSMOUSE_IMPS,
  82. PSMOUSE_IMEX,
  83. PSMOUSE_SYNAPTICS,
  84. PSMOUSE_ALPS,
  85. PSMOUSE_LIFEBOOK,
  86. PSMOUSE_TRACKPOINT,
  87. PSMOUSE_TOUCHKIT_PS2,
  88. PSMOUSE_CORTRON,
  89. PSMOUSE_HGPK,
  90. PSMOUSE_ELANTECH,
  91. PSMOUSE_FSP,
  92. PSMOUSE_SYNAPTICS_RELATIVE,
  93. PSMOUSE_CYPRESS,
  94. PSMOUSE_FOCALTECH,
  95. PSMOUSE_VMMOUSE,
  96. PSMOUSE_AUTO /* This one should always be last */
  97. };
  98. void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
  99. unsigned long delay);
  100. int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
  101. int psmouse_reset(struct psmouse *psmouse);
  102. void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state);
  103. void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);
  104. psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse);
  105. int psmouse_activate(struct psmouse *psmouse);
  106. int psmouse_deactivate(struct psmouse *psmouse);
  107. bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[]);
  108. struct psmouse_attribute {
  109. struct device_attribute dattr;
  110. void *data;
  111. ssize_t (*show)(struct psmouse *psmouse, void *data, char *buf);
  112. ssize_t (*set)(struct psmouse *psmouse, void *data,
  113. const char *buf, size_t count);
  114. bool protect;
  115. };
  116. #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
  117. ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
  118. char *buf);
  119. ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *attr,
  120. const char *buf, size_t count);
  121. #define __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect) \
  122. static struct psmouse_attribute psmouse_attr_##_name = { \
  123. .dattr = { \
  124. .attr = { \
  125. .name = __stringify(_name), \
  126. .mode = _mode, \
  127. }, \
  128. .show = psmouse_attr_show_helper, \
  129. .store = psmouse_attr_set_helper, \
  130. }, \
  131. .data = _data, \
  132. .show = _show, \
  133. .set = _set, \
  134. .protect = _protect, \
  135. }
  136. #define __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, _protect) \
  137. static ssize_t _show(struct psmouse *, void *, char *); \
  138. static ssize_t _set(struct psmouse *, void *, const char *, size_t); \
  139. __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, _set, _protect)
  140. #define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set) \
  141. __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, true)
  142. #define PSMOUSE_DEFINE_RO_ATTR(_name, _mode, _data, _show) \
  143. static ssize_t _show(struct psmouse *, void *, char *); \
  144. __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, _show, NULL, true)
  145. #define PSMOUSE_DEFINE_WO_ATTR(_name, _mode, _data, _set) \
  146. static ssize_t _set(struct psmouse *, void *, const char *, size_t); \
  147. __PSMOUSE_DEFINE_ATTR_VAR(_name, _mode, _data, NULL, _set, true)
  148. #ifndef psmouse_fmt
  149. #define psmouse_fmt(fmt) KBUILD_BASENAME ": " fmt
  150. #endif
  151. #define psmouse_dbg(psmouse, format, ...) \
  152. dev_dbg(&(psmouse)->ps2dev.serio->dev, \
  153. psmouse_fmt(format), ##__VA_ARGS__)
  154. #define psmouse_info(psmouse, format, ...) \
  155. dev_info(&(psmouse)->ps2dev.serio->dev, \
  156. psmouse_fmt(format), ##__VA_ARGS__)
  157. #define psmouse_warn(psmouse, format, ...) \
  158. dev_warn(&(psmouse)->ps2dev.serio->dev, \
  159. psmouse_fmt(format), ##__VA_ARGS__)
  160. #define psmouse_err(psmouse, format, ...) \
  161. dev_err(&(psmouse)->ps2dev.serio->dev, \
  162. psmouse_fmt(format), ##__VA_ARGS__)
  163. #define psmouse_notice(psmouse, format, ...) \
  164. dev_notice(&(psmouse)->ps2dev.serio->dev, \
  165. psmouse_fmt(format), ##__VA_ARGS__)
  166. #define psmouse_printk(level, psmouse, format, ...) \
  167. dev_printk(level, \
  168. &(psmouse)->ps2dev.serio->dev, \
  169. psmouse_fmt(format), ##__VA_ARGS__)
  170. #endif /* _PSMOUSE_H */