atmel_maxtouch.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * Atmel maXTouch header file
  3. *
  4. * Copyright (c) 2010 Atmel Corporation
  5. * Copyright (C) 2010 Ulf Samuelsson (ulf@atmel.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. * See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. *
  13. */
  14. #define MXT224_I2C_ADDR1 0x4A
  15. #define MXT224_I2C_ADDR2 0x4B
  16. #define MXT1386_I2C_ADDR1 0x4C
  17. #define MXT1386_I2C_ADDR2 0x4D
  18. #define MXT1386_I2C_ADDR3 0x5A
  19. #define MXT1386_I2C_ADDR4 0x5B
  20. /*
  21. * Select this address from above depending on what maXTouch
  22. * chip you have and how it's address pins are configured;
  23. * see datasheet.
  24. */
  25. #define MXT_I2C_ADDRESS MXT224_I2C_ADDR2
  26. #define MXT_BL_ADDRESS 0x25
  27. #define MXT224_FAMILYID 0x80
  28. #define MXT1386_FAMILYID 0xA0
  29. #define MXT224_CAL_VARIANTID 0x01
  30. #define MXT224_UNCAL_VARIANTID 0x00
  31. #define MXT1386_CAL_VARIANTID 0x00
  32. #define MXT_MAX_REPORTED_WIDTH 255
  33. #define MXT_MAX_REPORTED_PRESSURE 255
  34. #define MXT_MAX_TOUCH_SIZE 255
  35. #define MXT_MAX_NUM_TOUCHES 10
  36. /* Fixed addresses inside maXTouch device */
  37. #define MXT_ADDR_INFO_BLOCK 0
  38. #define MXT_ADDR_OBJECT_TABLE 7
  39. #define MXT_ID_BLOCK_SIZE 7
  40. #define MXT_OBJECT_TABLE_ELEMENT_SIZE 6
  41. /* Object types */
  42. #define MXT_DEBUG_DELTAS_T2 2
  43. #define MXT_DEBUG_REFERENCES_T3 3
  44. #define MXT_GEN_MESSAGEPROCESSOR_T5 5
  45. #define MXT_GEN_COMMANDPROCESSOR_T6 6
  46. #define MXT_GEN_POWERCONFIG_T7 7
  47. #define MXT_GEN_ACQUIRECONFIG_T8 8
  48. #define MXT_TOUCH_MULTITOUCHSCREEN_T9 9
  49. #define MXT_TOUCH_SINGLETOUCHSCREEN_T10 10
  50. #define MXT_TOUCH_XSLIDER_T11 11
  51. #define MXT_TOUCH_YSLIDER_T12 12
  52. #define MXT_TOUCH_XWHEEL_T13 13
  53. #define MXT_TOUCH_YWHEEL_T14 14
  54. #define MXT_TOUCH_KEYARRAY_T15 15
  55. #define MXT_SPT_GPIOPWM_T19 19
  56. #define MXT_PROCI_GRIPFACESUPPRESSION_T20 20
  57. #define MXT_PROCG_NOISESUPPRESSION_T22 22
  58. #define MXT_TOUCH_PROXIMITY_T23 23
  59. #define MXT_PROCI_ONETOUCHGESTUREPROCESSOR_T24 24
  60. #define MXT_SPT_SELFTEST_T25 25
  61. #define MXT_DEBUG_CTERANGE_T26 26
  62. #define MXT_PROCI_TWOTOUCHGESTUREPROCESSOR_T27 27
  63. #define MXT_SPT_CTECONFIG_T28 28
  64. #define MXT_TOUCH_KEYSET_T31 31
  65. #define MXT_TOUCH_XSLIDERSET_T32 32
  66. #define MXT_DEBUG_DIAGNOSTIC_T37 37
  67. #define MXT_USER_INFO_T38 38
  68. /*
  69. * If a message is read from mXT when there's no new messages available,
  70. * the report ID of the message will be 0xFF.
  71. */
  72. #define MXT_END_OF_MESSAGES 0xFF
  73. /* GEN_COMMANDPROCESSOR_T6 Register offsets from T6 base address */
  74. #define MXT_ADR_T6_RESET 0x00
  75. #define MXT_ADR_T6_BACKUPNV 0x01
  76. #define MXT_ADR_T6_CALIBRATE 0x02
  77. #define MXT_ADR_T6_REPORTALL 0x03
  78. #define MXT_ADR_T6_RESERVED 0x04
  79. #define MXT_ADR_T6_DIAGNOSTIC 0x05
  80. /* T6 Debug Diagnostics Commands */
  81. #define MXT_CMD_T6_PAGE_UP 0x01
  82. #define MXT_CMD_T6_PAGE_DOWN 0x02
  83. #define MXT_CMD_T6_DELTAS_MODE 0x10
  84. #define MXT_CMD_T6_REFERENCES_MODE 0x11
  85. #define MXT_CMD_T6_CTE_MODE 0x31
  86. /* T6 Backup Command */
  87. #define MXT_CMD_T6_BACKUP 0x55
  88. /* SPT_DEBUG_DIAGNOSTIC_T37 Register offsets from T37 base address */
  89. #define MXT_ADR_T37_PAGE 0x01
  90. #define MXT_ADR_T37_DATA 0x02
  91. /************************************************************************
  92. * MESSAGE OBJECTS ADDRESS FIELDS
  93. *
  94. ************************************************************************/
  95. #define MXT_MSG_REPORTID 0x00
  96. /* MXT_GEN_MESSAGEPROCESSOR_T5 Message address definitions */
  97. #define MXT_MSG_T5_REPORTID 0x00
  98. #define MXT_MSG_T5_MESSAGE 0x01
  99. #define MXT_MSG_T5_CHECKSUM 0x08
  100. /* MXT_GEN_COMMANDPROCESSOR_T6 Message address definitions */
  101. #define MXT_MSG_T6_STATUS 0x01
  102. #define MXT_MSGB_T6_COMSERR 0x04
  103. #define MXT_MSGB_T6_CFGERR 0x08
  104. #define MXT_MSGB_T6_CAL 0x10
  105. #define MXT_MSGB_T6_SIGERR 0x20
  106. #define MXT_MSGB_T6_OFL 0x40
  107. #define MXT_MSGB_T6_RESET 0x80
  108. /* Three bytes */
  109. #define MXT_MSG_T6_CHECKSUM 0x02
  110. /* MXT_GEN_POWERCONFIG_T7 NO Message address definitions */
  111. /* MXT_GEN_ACQUIRECONFIG_T8 Message address definitions */
  112. /* MXT_TOUCH_MULTITOUCHSCREEN_T9 Message address definitions */
  113. #define MXT_MSG_T9_STATUS 0x01
  114. /* Status bit field */
  115. #define MXT_MSGB_T9_SUPPRESS 0x02
  116. #define MXT_MSGB_T9_AMP 0x04
  117. #define MXT_MSGB_T9_VECTOR 0x08
  118. #define MXT_MSGB_T9_MOVE 0x10
  119. #define MXT_MSGB_T9_RELEASE 0x20
  120. #define MXT_MSGB_T9_PRESS 0x40
  121. #define MXT_MSGB_T9_DETECT 0x80
  122. #define MXT_MSG_T9_XPOSMSB 0x02
  123. #define MXT_MSG_T9_YPOSMSB 0x03
  124. #define MXT_MSG_T9_XYPOSLSB 0x04
  125. #define MXT_MSG_T9_TCHAREA 0x05
  126. #define MXT_MSG_T9_TCHAMPLITUDE 0x06
  127. #define MXT_MSG_T9_TCHVECTOR 0x07
  128. /* MXT_SPT_GPIOPWM_T19 Message address definitions */
  129. #define MXT_MSG_T19_STATUS 0x01
  130. /* MXT_PROCI_GRIPFACESUPPRESSION_T20 Message address definitions */
  131. #define MXT_MSG_T20_STATUS 0x01
  132. #define MXT_MSGB_T20_FACE_SUPPRESS 0x01
  133. /* MXT_PROCG_NOISESUPPRESSION_T22 Message address definitions */
  134. #define MXT_MSG_T22_STATUS 0x01
  135. #define MXT_MSGB_T22_FHCHG 0x01
  136. #define MXT_MSGB_T22_GCAFERR 0x04
  137. #define MXT_MSGB_T22_FHERR 0x08
  138. #define MXT_MSG_T22_GCAFDEPTH 0x02
  139. /* MXT_TOUCH_PROXIMITY_T23 Message address definitions */
  140. #define MXT_MSG_T23_STATUS 0x01
  141. #define MXT_MSGB_T23_FALL 0x20
  142. #define MXT_MSGB_T23_RISE 0x40
  143. #define MXT_MSGB_T23_DETECT 0x80
  144. /* 16 bit */
  145. #define MXT_MSG_T23_PROXDELTA 0x02
  146. /* MXT_PROCI_ONETOUCHGESTUREPROCESSOR_T24 Message address definitions */
  147. #define MXT_MSG_T24_STATUS 0x01
  148. #define MXT_MSG_T24_XPOSMSB 0x02
  149. #define MXT_MSG_T24_YPOSMSB 0x03
  150. #define MXT_MSG_T24_XYPOSLSB 0x04
  151. #define MXT_MSG_T24_DIR 0x05
  152. /* 16 bit */
  153. #define MXT_MSG_T24_DIST 0x06
  154. /* MXT_SPT_SELFTEST_T25 Message address definitions */
  155. #define MXT_MSG_T25_STATUS 0x01
  156. /* 5 Bytes */
  157. #define MXT_MSGR_T25_OK 0xFE
  158. #define MXT_MSGR_T25_INVALID_TEST 0xFD
  159. #define MXT_MSGR_T25_PIN_FAULT 0x11
  160. #define MXT_MSGR_T25_SIGNAL_LIMIT_FAULT 0x17
  161. #define MXT_MSGR_T25_GAIN_ERROR 0x20
  162. #define MXT_MSG_T25_INFO 0x02
  163. /* MXT_PROCI_TWOTOUCHGESTUREPROCESSOR_T27 Message address definitions */
  164. #define MXT_MSG_T27_STATUS 0x01
  165. #define MXT_MSGB_T27_ROTATEDIR 0x10
  166. #define MXT_MSGB_T27_PINCH 0x20
  167. #define MXT_MSGB_T27_ROTATE 0x40
  168. #define MXT_MSGB_T27_STRETCH 0x80
  169. #define MXT_MSG_T27_XPOSMSB 0x02
  170. #define MXT_MSG_T27_YPOSMSB 0x03
  171. #define MXT_MSG_T27_XYPOSLSB 0x04
  172. #define MXT_MSG_T27_ANGLE 0x05
  173. /* 16 bit */
  174. #define MXT_MSG_T27_SEPARATION 0x06
  175. /* MXT_SPT_CTECONFIG_T28 Message address definitions */
  176. #define MXT_MSG_T28_STATUS 0x01
  177. #define MXT_MSGB_T28_CHKERR 0x01
  178. /* One Touch Events */
  179. #define MXT_GESTURE_RESERVED 0x00
  180. #define MXT_GESTURE_PRESS 0x01
  181. #define MXT_GESTURE_RELEASE 0x02
  182. #define MXT_GESTURE_TAP 0x03
  183. #define MXT_GESTURE_DOUBLE_TAP 0x04
  184. #define MXT_GESTURE_FLICK 0x05
  185. #define MXT_GESTURE_DRAG 0x06
  186. #define MXT_GESTURE_SHORT_PRESS 0x07
  187. #define MXT_GESTURE_LONG_PRESS 0x08
  188. #define MXT_GESTURE_REPEAT_PRESS 0x09
  189. #define MXT_GESTURE_TAP_AND_PRESS 0x0a
  190. #define MXT_GESTURE_THROW 0x0b
  191. /* Two-touch events */
  192. #define MXT_GESTURE_STRETCH (1 << 7)
  193. #define MXT_GESTURE_ROTATE (1 << 6)
  194. #define MXT_GESTURE_PINCH (1 << 5)
  195. #define MXT_GESTURE_ROTATEDIR (1 << 4)
  196. /* Bootloader states */
  197. #define WAITING_BOOTLOAD_COMMAND 0xC0
  198. #define WAITING_FRAME_DATA 0x80
  199. #define APP_CRC_FAIL 0x40
  200. #define FRAME_CRC_CHECK 0x02
  201. #define FRAME_CRC_PASS 0x04
  202. #define FRAME_CRC_FAIL 0x03
  203. #define MXT_MAX_FRAME_SIZE 276
  204. /* Debug levels */
  205. #define DEBUG_INFO 1
  206. #define DEBUG_VERBOSE 2
  207. #define DEBUG_MESSAGES 5
  208. #define DEBUG_RAW 8
  209. #define DEBUG_TRACE 10
  210. /* IOCTL commands */
  211. /* TODO: get correct numbers! */
  212. #define MXT_SET_ADDRESS_IOCTL ('x' + 1) /* Sets the internal address pointer */
  213. #define MXT_RESET_IOCTL ('x' + 2) /* Resets the device */
  214. #define MXT_CALIBRATE_IOCTL ('x' + 3) /* Calibrates the device */
  215. /* Backups the current state of registers to NVM */
  216. #define MXT_BACKUP_IOCTL ('x' + 4)
  217. /*
  218. * Only non-touch messages can be read from the message buffer
  219. * (/dev/maXTouch_messages)
  220. */
  221. #define MXT_NONTOUCH_MSG_IOCTL ('x' + 5)
  222. /* All messages can be read from the message buffer */
  223. #define MXT_ALL_MSG_IOCTL ('x' + 6)
  224. /* Message buffer size. This is a ring buffer, and when full, the oldest entry
  225. will be overwritten. */
  226. #define MXT_MESSAGE_BUFFER_SIZE 128
  227. /* Routines for memory access within a 16 bit address space */
  228. /* TODO: - won't compile if functions aren't defined*/
  229. /* Bootloader specific function prototypes. */
  230. #if 0
  231. static int mxt_read_byte_bl(struct i2c_client *client, u8 *value);
  232. static int mxt_read_block_bl(struct i2c_client *client, u16 length, u8 *value);
  233. static int mxt_write_byte_bl(struct i2c_client *client, u8 value);
  234. static int mxt_write_block_bl(struct i2c_client *client, u16 length, u8 *value);
  235. #endif
  236. /**
  237. * struct maxtouch_platform_data - includes platform specific informatio
  238. * related to Atmel maXTouch touchscreen controller.
  239. *
  240. * @numtouch: Number of simultaneous touches supported
  241. * @init_platform_hw(): Initialization function, which can for example
  242. * trigger a hardware reset by toggling a GPIO pin
  243. * @exit_platform_hw(): Function to run when the driver is unloaded.
  244. * @valid_interrupt(): Function that checks the validity of the interrupt -
  245. * function that check the validity of a interrupt (by
  246. * reading the changeline interrupt pin and checking that
  247. * it really is low for example).
  248. * @max_x: Reported X range
  249. * @max_y: Reported Y range
  250. */
  251. struct maxtouch_platform_data {
  252. u8 numtouch; /* Number of touches to report */
  253. int (*init_platform_hw)(struct i2c_client *client);
  254. int (*exit_platform_hw)(struct i2c_client *client);
  255. int display_res_x;
  256. int display_res_y;
  257. int min_x;
  258. int min_y;
  259. int max_x; /* The default reported X range */
  260. int max_y; /* The default reported Y range */
  261. u8 (*valid_interrupt) (void);
  262. u8 (*read_chg) (void);
  263. bool wakeup;
  264. int (*power_on)(bool on);
  265. };
  266. void mxt_hw_reset(void);