elantech.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Elantech Touchpad driver (v6)
  3. *
  4. * Copyright (C) 2007-2009 Arjan Opmeer <arjan@opmeer.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. *
  10. * Trademarks are the property of their respective owners.
  11. */
  12. #ifndef _ELANTECH_H
  13. #define _ELANTECH_H
  14. /*
  15. * Command values for Synaptics style queries
  16. */
  17. #define ETP_FW_ID_QUERY 0x00
  18. #define ETP_FW_VERSION_QUERY 0x01
  19. #define ETP_CAPABILITIES_QUERY 0x02
  20. #define ETP_SAMPLE_QUERY 0x03
  21. #define ETP_RESOLUTION_QUERY 0x04
  22. /*
  23. * Command values for register reading or writing
  24. */
  25. #define ETP_REGISTER_READ 0x10
  26. #define ETP_REGISTER_WRITE 0x11
  27. #define ETP_REGISTER_READWRITE 0x00
  28. /*
  29. * Hardware version 2 custom PS/2 command value
  30. */
  31. #define ETP_PS2_CUSTOM_COMMAND 0xf8
  32. /*
  33. * Times to retry a ps2_command and millisecond delay between tries
  34. */
  35. #define ETP_PS2_COMMAND_TRIES 3
  36. #define ETP_PS2_COMMAND_DELAY 500
  37. /*
  38. * Times to try to read back a register and millisecond delay between tries
  39. */
  40. #define ETP_READ_BACK_TRIES 5
  41. #define ETP_READ_BACK_DELAY 2000
  42. /*
  43. * Register bitmasks for hardware version 1
  44. */
  45. #define ETP_R10_ABSOLUTE_MODE 0x04
  46. #define ETP_R11_4_BYTE_MODE 0x02
  47. /*
  48. * Capability bitmasks
  49. */
  50. #define ETP_CAP_HAS_ROCKER 0x04
  51. /*
  52. * One hard to find application note states that X axis range is 0 to 576
  53. * and Y axis range is 0 to 384 for harware version 1.
  54. * Edge fuzz might be necessary because of bezel around the touchpad
  55. */
  56. #define ETP_EDGE_FUZZ_V1 32
  57. #define ETP_XMIN_V1 ( 0 + ETP_EDGE_FUZZ_V1)
  58. #define ETP_XMAX_V1 (576 - ETP_EDGE_FUZZ_V1)
  59. #define ETP_YMIN_V1 ( 0 + ETP_EDGE_FUZZ_V1)
  60. #define ETP_YMAX_V1 (384 - ETP_EDGE_FUZZ_V1)
  61. /*
  62. * The resolution for older v2 hardware doubled.
  63. * (newer v2's firmware provides command so we can query)
  64. */
  65. #define ETP_XMIN_V2 0
  66. #define ETP_XMAX_V2 1152
  67. #define ETP_YMIN_V2 0
  68. #define ETP_YMAX_V2 768
  69. #define ETP_PMIN_V2 0
  70. #define ETP_PMAX_V2 255
  71. #define ETP_WMIN_V2 0
  72. #define ETP_WMAX_V2 15
  73. /*
  74. * v3 hardware has 2 kinds of packet types,
  75. * v4 hardware has 3.
  76. */
  77. #define PACKET_UNKNOWN 0x01
  78. #define PACKET_DEBOUNCE 0x02
  79. #define PACKET_V3_HEAD 0x03
  80. #define PACKET_V3_TAIL 0x04
  81. #define PACKET_V4_HEAD 0x05
  82. #define PACKET_V4_MOTION 0x06
  83. #define PACKET_V4_STATUS 0x07
  84. #define PACKET_TRACKPOINT 0x08
  85. /*
  86. * track up to 5 fingers for v4 hardware
  87. */
  88. #define ETP_MAX_FINGERS 5
  89. /*
  90. * weight value for v4 hardware
  91. */
  92. #define ETP_WEIGHT_VALUE 5
  93. /*
  94. * Bus information on 3rd byte of query ETP_RESOLUTION_QUERY(0x04)
  95. */
  96. #define ETP_BUS_PS2_ONLY 0
  97. #define ETP_BUS_SMB_ALERT_ONLY 1
  98. #define ETP_BUS_SMB_HST_NTFY_ONLY 2
  99. #define ETP_BUS_PS2_SMB_ALERT 3
  100. #define ETP_BUS_PS2_SMB_HST_NTFY 4
  101. /*
  102. * New ICs are either using SMBus Host Notify or just plain PS2.
  103. *
  104. * ETP_FW_VERSION_QUERY is:
  105. * Byte 1:
  106. * - bit 0..3: IC BODY
  107. * Byte 2:
  108. * - bit 4: HiddenButton
  109. * - bit 5: PS2_SMBUS_NOTIFY
  110. * - bit 6: PS2CRCCheck
  111. */
  112. #define ETP_NEW_IC_SMBUS_HOST_NOTIFY(fw_version) \
  113. ((((fw_version) & 0x0f2000) == 0x0f2000) && \
  114. ((fw_version) & 0x0000ff) > 0)
  115. /*
  116. * The base position for one finger, v4 hardware
  117. */
  118. struct finger_pos {
  119. unsigned int x;
  120. unsigned int y;
  121. };
  122. struct elantech_device_info {
  123. unsigned char capabilities[3];
  124. unsigned char samples[3];
  125. unsigned char debug;
  126. unsigned char hw_version;
  127. unsigned int fw_version;
  128. unsigned int x_res;
  129. unsigned int y_res;
  130. unsigned int bus;
  131. bool paritycheck;
  132. bool jumpy_cursor;
  133. bool reports_pressure;
  134. bool crc_enabled;
  135. bool set_hw_resolution;
  136. bool has_trackpoint;
  137. int (*send_cmd)(struct psmouse *psmouse, unsigned char c,
  138. unsigned char *param);
  139. };
  140. struct elantech_data {
  141. struct input_dev *tp_dev; /* Relative device for trackpoint */
  142. char tp_phys[32];
  143. unsigned char reg_07;
  144. unsigned char reg_10;
  145. unsigned char reg_11;
  146. unsigned char reg_20;
  147. unsigned char reg_21;
  148. unsigned char reg_22;
  149. unsigned char reg_23;
  150. unsigned char reg_24;
  151. unsigned char reg_25;
  152. unsigned char reg_26;
  153. unsigned int single_finger_reports;
  154. unsigned int y_max;
  155. unsigned int width;
  156. struct finger_pos mt[ETP_MAX_FINGERS];
  157. unsigned char parity[256];
  158. struct elantech_device_info info;
  159. void (*original_set_rate)(struct psmouse *psmouse, unsigned int rate);
  160. };
  161. #ifdef CONFIG_MOUSE_PS2_ELANTECH
  162. int elantech_detect(struct psmouse *psmouse, bool set_properties);
  163. int elantech_init_ps2(struct psmouse *psmouse);
  164. int elantech_init(struct psmouse *psmouse);
  165. #else
  166. static inline int elantech_detect(struct psmouse *psmouse, bool set_properties)
  167. {
  168. return -ENOSYS;
  169. }
  170. static inline int elantech_init(struct psmouse *psmouse)
  171. {
  172. return -ENOSYS;
  173. }
  174. static inline int elantech_init_ps2(struct psmouse *psmouse)
  175. {
  176. return -ENOSYS;
  177. }
  178. #endif /* CONFIG_MOUSE_PS2_ELANTECH */
  179. #if defined(CONFIG_MOUSE_PS2_ELANTECH_SMBUS)
  180. int elantech_init_smbus(struct psmouse *psmouse);
  181. #else
  182. static inline int elantech_init_smbus(struct psmouse *psmouse)
  183. {
  184. return -ENOSYS;
  185. }
  186. #endif /* CONFIG_MOUSE_PS2_ELANTECH_SMBUS */
  187. #endif