alps.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * ALPS touchpad PS/2 mouse driver
  3. *
  4. * Copyright (c) 2003 Peter Osterlund <petero2@telia.com>
  5. * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. */
  11. #ifndef _ALPS_H
  12. #define _ALPS_H
  13. #include <linux/input/mt.h>
  14. #define ALPS_PROTO_V1 0x100
  15. #define ALPS_PROTO_V2 0x200
  16. #define ALPS_PROTO_V3 0x300
  17. #define ALPS_PROTO_V3_RUSHMORE 0x310
  18. #define ALPS_PROTO_V4 0x400
  19. #define ALPS_PROTO_V5 0x500
  20. #define ALPS_PROTO_V6 0x600
  21. #define ALPS_PROTO_V7 0x700 /* t3btl t4s */
  22. #define ALPS_PROTO_V8 0x800 /* SS4btl SS4s */
  23. #define ALPS_PROTO_V9 0x900 /* ss3btl */
  24. #define MAX_TOUCHES 4
  25. #define DOLPHIN_COUNT_PER_ELECTRODE 64
  26. #define DOLPHIN_PROFILE_XOFFSET 8 /* x-electrode offset */
  27. #define DOLPHIN_PROFILE_YOFFSET 1 /* y-electrode offset */
  28. /*
  29. * enum SS4_PACKET_ID - defines the packet type for V8
  30. * SS4_PACKET_ID_IDLE: There's no finger and no button activity.
  31. * SS4_PACKET_ID_ONE: There's one finger on touchpad
  32. * or there's button activities.
  33. * SS4_PACKET_ID_TWO: There's two or more fingers on touchpad
  34. * SS4_PACKET_ID_MULTI: There's three or more fingers on touchpad
  35. * SS4_PACKET_ID_STICK: A stick pointer packet
  36. */
  37. enum SS4_PACKET_ID {
  38. SS4_PACKET_ID_IDLE = 0,
  39. SS4_PACKET_ID_ONE,
  40. SS4_PACKET_ID_TWO,
  41. SS4_PACKET_ID_MULTI,
  42. SS4_PACKET_ID_STICK,
  43. };
  44. #define SS4_COUNT_PER_ELECTRODE 256
  45. #define SS4_NUMSENSOR_XOFFSET 7
  46. #define SS4_NUMSENSOR_YOFFSET 7
  47. #define SS4_MIN_PITCH_MM 50
  48. #define SS4_MASK_NORMAL_BUTTONS 0x07
  49. #define SS4PLUS_COUNT_PER_ELECTRODE 128
  50. #define SS4PLUS_NUMSENSOR_XOFFSET 16
  51. #define SS4PLUS_NUMSENSOR_YOFFSET 5
  52. #define SS4PLUS_MIN_PITCH_MM 37
  53. #define IS_SS4PLUS_DEV(_b) (((_b[0]) == 0x73) && \
  54. ((_b[1]) == 0x03) && \
  55. ((_b[2]) == 0x28) \
  56. )
  57. #define SS4_IS_IDLE_V2(_b) (((_b[0]) == 0x18) && \
  58. ((_b[1]) == 0x10) && \
  59. ((_b[2]) == 0x00) && \
  60. ((_b[3] & 0x88) == 0x08) && \
  61. ((_b[4]) == 0x10) && \
  62. ((_b[5]) == 0x00) \
  63. )
  64. #define SS4_1F_X_V2(_b) (((_b[0]) & 0x0007) | \
  65. ((_b[1] << 3) & 0x0078) | \
  66. ((_b[1] << 2) & 0x0380) | \
  67. ((_b[2] << 5) & 0x1C00) \
  68. )
  69. #define SS4_1F_Y_V2(_b) (((_b[2]) & 0x000F) | \
  70. ((_b[3] >> 2) & 0x0030) | \
  71. ((_b[4] << 6) & 0x03C0) | \
  72. ((_b[4] << 5) & 0x0C00) \
  73. )
  74. #define SS4_1F_Z_V2(_b) (((_b[5]) & 0x0F) | \
  75. ((_b[5] >> 1) & 0x70) | \
  76. ((_b[4]) & 0x80) \
  77. )
  78. #define SS4_1F_LFB_V2(_b) (((_b[2] >> 4) & 0x01) == 0x01)
  79. #define SS4_MF_LF_V2(_b, _i) ((_b[1 + (_i) * 3] & 0x0004) == 0x0004)
  80. #define SS4_BTN_V2(_b) ((_b[0] >> 5) & SS4_MASK_NORMAL_BUTTONS)
  81. #define SS4_STD_MF_X_V2(_b, _i) (((_b[0 + (_i) * 3] << 5) & 0x00E0) | \
  82. ((_b[1 + _i * 3] << 5) & 0x1F00) \
  83. )
  84. #define SS4_PLUS_STD_MF_X_V2(_b, _i) (((_b[0 + (_i) * 3] << 4) & 0x0070) | \
  85. ((_b[1 + (_i) * 3] << 4) & 0x0F80) \
  86. )
  87. #define SS4_STD_MF_Y_V2(_b, _i) (((_b[1 + (_i) * 3] << 3) & 0x0010) | \
  88. ((_b[2 + (_i) * 3] << 5) & 0x01E0) | \
  89. ((_b[2 + (_i) * 3] << 4) & 0x0E00) \
  90. )
  91. #define SS4_BTL_MF_X_V2(_b, _i) (SS4_STD_MF_X_V2(_b, _i) | \
  92. ((_b[0 + (_i) * 3] >> 3) & 0x0010) \
  93. )
  94. #define SS4_PLUS_BTL_MF_X_V2(_b, _i) (SS4_PLUS_STD_MF_X_V2(_b, _i) | \
  95. ((_b[0 + (_i) * 3] >> 4) & 0x0008) \
  96. )
  97. #define SS4_BTL_MF_Y_V2(_b, _i) (SS4_STD_MF_Y_V2(_b, _i) | \
  98. ((_b[0 + (_i) * 3] >> 3) & 0x0008) \
  99. )
  100. #define SS4_MF_Z_V2(_b, _i) (((_b[1 + (_i) * 3]) & 0x0001) | \
  101. ((_b[1 + (_i) * 3] >> 1) & 0x0002) \
  102. )
  103. #define SS4_IS_MF_CONTINUE(_b) ((_b[2] & 0x10) == 0x10)
  104. #define SS4_IS_5F_DETECTED(_b) ((_b[2] & 0x10) == 0x10)
  105. #define SS4_TS_X_V2(_b) (s8)( \
  106. ((_b[0] & 0x01) << 7) | \
  107. (_b[1] & 0x7F) \
  108. )
  109. #define SS4_TS_Y_V2(_b) -(s8)( \
  110. ((_b[3] & 0x01) << 7) | \
  111. (_b[2] & 0x7F) \
  112. )
  113. #define SS4_TS_Z_V2(_b) (s8)(_b[4] & 0x7F)
  114. #define SS4_MFPACKET_NO_AX 8160 /* X-Coordinate value */
  115. #define SS4_MFPACKET_NO_AY 4080 /* Y-Coordinate value */
  116. #define SS4_MFPACKET_NO_AX_BL 8176 /* Buttonless X-Coord value */
  117. #define SS4_MFPACKET_NO_AY_BL 4088 /* Buttonless Y-Coord value */
  118. #define SS4_PLUS_MFPACKET_NO_AX 4080 /* SS4 PLUS, X */
  119. #define SS4_PLUS_MFPACKET_NO_AX_BL 4088 /* Buttonless SS4 PLUS, X */
  120. /*
  121. * enum V7_PACKET_ID - defines the packet type for V7
  122. * V7_PACKET_ID_IDLE: There's no finger and no button activity.
  123. * V7_PACKET_ID_TWO: There's one or two non-resting fingers on touchpad
  124. * or there's button activities.
  125. * V7_PACKET_ID_MULTI: There are at least three non-resting fingers.
  126. * V7_PACKET_ID_NEW: The finger position in slot is not continues from
  127. * previous packet.
  128. */
  129. enum V7_PACKET_ID {
  130. V7_PACKET_ID_IDLE,
  131. V7_PACKET_ID_TWO,
  132. V7_PACKET_ID_MULTI,
  133. V7_PACKET_ID_NEW,
  134. V7_PACKET_ID_UNKNOWN,
  135. };
  136. /**
  137. * struct alps_protocol_info - information about protocol used by a device
  138. * @version: Indicates V1/V2/V3/...
  139. * @byte0: Helps figure out whether a position report packet matches the
  140. * known format for this model. The first byte of the report, ANDed with
  141. * mask0, should match byte0.
  142. * @mask0: The mask used to check the first byte of the report.
  143. * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
  144. */
  145. struct alps_protocol_info {
  146. u16 version;
  147. u8 byte0, mask0;
  148. unsigned int flags;
  149. };
  150. /**
  151. * struct alps_model_info - touchpad ID table
  152. * @signature: E7 response string to match.
  153. * @protocol_info: information about protocol used by the device.
  154. *
  155. * Many (but not all) ALPS touchpads can be identified by looking at the
  156. * values returned in the "E7 report" and/or the "EC report." This table
  157. * lists a number of such touchpads.
  158. */
  159. struct alps_model_info {
  160. u8 signature[3];
  161. struct alps_protocol_info protocol_info;
  162. };
  163. /**
  164. * struct alps_nibble_commands - encodings for register accesses
  165. * @command: PS/2 command used for the nibble
  166. * @data: Data supplied as an argument to the PS/2 command, if applicable
  167. *
  168. * The ALPS protocol uses magic sequences to transmit binary data to the
  169. * touchpad, as it is generally not OK to send arbitrary bytes out the
  170. * PS/2 port. Each of the sequences in this table sends one nibble of the
  171. * register address or (write) data. Different versions of the ALPS protocol
  172. * use slightly different encodings.
  173. */
  174. struct alps_nibble_commands {
  175. int command;
  176. unsigned char data;
  177. };
  178. struct alps_bitmap_point {
  179. int start_bit;
  180. int num_bits;
  181. };
  182. /**
  183. * struct alps_fields - decoded version of the report packet
  184. * @x_map: Bitmap of active X positions for MT.
  185. * @y_map: Bitmap of active Y positions for MT.
  186. * @fingers: Number of fingers for MT.
  187. * @pressure: Pressure.
  188. * @st: position for ST.
  189. * @mt: position for MT.
  190. * @first_mp: Packet is the first of a multi-packet report.
  191. * @is_mp: Packet is part of a multi-packet report.
  192. * @left: Left touchpad button is active.
  193. * @right: Right touchpad button is active.
  194. * @middle: Middle touchpad button is active.
  195. * @ts_left: Left trackstick button is active.
  196. * @ts_right: Right trackstick button is active.
  197. * @ts_middle: Middle trackstick button is active.
  198. */
  199. struct alps_fields {
  200. unsigned int x_map;
  201. unsigned int y_map;
  202. unsigned int fingers;
  203. int pressure;
  204. struct input_mt_pos st;
  205. struct input_mt_pos mt[MAX_TOUCHES];
  206. unsigned int first_mp:1;
  207. unsigned int is_mp:1;
  208. unsigned int left:1;
  209. unsigned int right:1;
  210. unsigned int middle:1;
  211. unsigned int ts_left:1;
  212. unsigned int ts_right:1;
  213. unsigned int ts_middle:1;
  214. };
  215. /**
  216. * struct alps_data - private data structure for the ALPS driver
  217. * @psmouse: Pointer to parent psmouse device
  218. * @dev2: Trackstick device (can be NULL).
  219. * @dev3: Generic PS/2 mouse (can be NULL, delayed registering).
  220. * @phys2: Physical path for the trackstick device.
  221. * @phys3: Physical path for the generic PS/2 mouse.
  222. * @dev3_register_work: Delayed work for registering PS/2 mouse.
  223. * @nibble_commands: Command mapping used for touchpad register accesses.
  224. * @addr_command: Command used to tell the touchpad that a register address
  225. * follows.
  226. * @proto_version: Indicates V1/V2/V3/...
  227. * @byte0: Helps figure out whether a position report packet matches the
  228. * known format for this model. The first byte of the report, ANDed with
  229. * mask0, should match byte0.
  230. * @mask0: The mask used to check the first byte of the report.
  231. * @fw_ver: cached copy of firmware version (EC report)
  232. * @flags: Additional device capabilities (passthrough port, trackstick, etc.).
  233. * @x_max: Largest possible X position value.
  234. * @y_max: Largest possible Y position value.
  235. * @x_bits: Number of X bits in the MT bitmap.
  236. * @y_bits: Number of Y bits in the MT bitmap.
  237. * @hw_init: Protocol-specific hardware init function.
  238. * @process_packet: Protocol-specific function to process a report packet.
  239. * @decode_fields: Protocol-specific function to read packet bitfields.
  240. * @set_abs_params: Protocol-specific function to configure the input_dev.
  241. * @prev_fin: Finger bit from previous packet.
  242. * @multi_packet: Multi-packet data in progress.
  243. * @multi_data: Saved multi-packet data.
  244. * @f: Decoded packet data fields.
  245. * @quirks: Bitmap of ALPS_QUIRK_*.
  246. * @timer: Timer for flushing out the final report packet in the stream.
  247. */
  248. struct alps_data {
  249. struct psmouse *psmouse;
  250. struct input_dev *dev2;
  251. struct input_dev *dev3;
  252. char phys2[32];
  253. char phys3[32];
  254. struct delayed_work dev3_register_work;
  255. /* these are autodetected when the device is identified */
  256. const struct alps_nibble_commands *nibble_commands;
  257. int addr_command;
  258. u16 proto_version;
  259. u8 byte0, mask0;
  260. u8 dev_id[3];
  261. u8 fw_ver[3];
  262. int flags;
  263. int x_max;
  264. int y_max;
  265. int x_bits;
  266. int y_bits;
  267. unsigned int x_res;
  268. unsigned int y_res;
  269. int (*hw_init)(struct psmouse *psmouse);
  270. void (*process_packet)(struct psmouse *psmouse);
  271. int (*decode_fields)(struct alps_fields *f, unsigned char *p,
  272. struct psmouse *psmouse);
  273. void (*set_abs_params)(struct alps_data *priv, struct input_dev *dev1);
  274. int prev_fin;
  275. int multi_packet;
  276. int second_touch;
  277. unsigned char multi_data[6];
  278. struct alps_fields f;
  279. u8 quirks;
  280. struct timer_list timer;
  281. };
  282. #define ALPS_QUIRK_TRACKSTICK_BUTTONS 1 /* trakcstick buttons in trackstick packet */
  283. #ifdef CONFIG_MOUSE_PS2_ALPS
  284. int alps_detect(struct psmouse *psmouse, bool set_properties);
  285. int alps_init(struct psmouse *psmouse);
  286. #else
  287. inline int alps_detect(struct psmouse *psmouse, bool set_properties)
  288. {
  289. return -ENOSYS;
  290. }
  291. inline int alps_init(struct psmouse *psmouse)
  292. {
  293. return -ENOSYS;
  294. }
  295. #endif /* CONFIG_MOUSE_PS2_ALPS */
  296. #endif