cyttsp4_core.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /*
  2. * cyttsp4_core.h
  3. * Cypress TrueTouch(TM) Standard Product V4 Core driver module.
  4. * For use with Cypress Txx4xx parts.
  5. * Supported parts include:
  6. * TMA4XX
  7. * TMA1036
  8. *
  9. * Copyright (C) 2012 Cypress Semiconductor
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * version 2, and only version 2, as published by the
  14. * Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
  22. *
  23. */
  24. #ifndef _LINUX_CYTTSP4_CORE_H
  25. #define _LINUX_CYTTSP4_CORE_H
  26. #include <linux/device.h>
  27. #include <linux/err.h>
  28. #include <linux/input.h>
  29. #include <linux/kernel.h>
  30. #include <linux/limits.h>
  31. #include <linux/module.h>
  32. #include <linux/stringify.h>
  33. #include <linux/types.h>
  34. #include <linux/platform_data/cyttsp4.h>
  35. #define CY_REG_BASE 0x00
  36. #define CY_POST_CODEL_WDG_RST 0x01
  37. #define CY_POST_CODEL_CFG_DATA_CRC_FAIL 0x02
  38. #define CY_POST_CODEL_PANEL_TEST_FAIL 0x04
  39. #define CY_NUM_BTN_PER_REG 4
  40. /* touch record system information offset masks and shifts */
  41. #define CY_BYTE_OFS_MASK 0x1F
  42. #define CY_BOFS_MASK 0xE0
  43. #define CY_BOFS_SHIFT 5
  44. #define CY_TMA1036_TCH_REC_SIZE 6
  45. #define CY_TMA4XX_TCH_REC_SIZE 9
  46. #define CY_TMA1036_MAX_TCH 0x0E
  47. #define CY_TMA4XX_MAX_TCH 0x1E
  48. #define CY_NORMAL_ORIGIN 0 /* upper, left corner */
  49. #define CY_INVERT_ORIGIN 1 /* lower, right corner */
  50. /* helpers */
  51. #define GET_NUM_TOUCHES(x) ((x) & 0x1F)
  52. #define IS_LARGE_AREA(x) ((x) & 0x20)
  53. #define IS_BAD_PKT(x) ((x) & 0x20)
  54. #define IS_BOOTLOADER(hst_mode, reset_detect) \
  55. ((hst_mode) & 0x01 || (reset_detect) != 0)
  56. #define IS_TMO(t) ((t) == 0)
  57. enum cyttsp_cmd_bits {
  58. CY_CMD_COMPLETE = (1 << 6),
  59. };
  60. /* Timeout in ms. */
  61. #define CY_WATCHDOG_TIMEOUT 1000
  62. #define CY_MAX_PRINT_SIZE 512
  63. #ifdef VERBOSE_DEBUG
  64. #define CY_MAX_PRBUF_SIZE PIPE_BUF
  65. #define CY_PR_TRUNCATED " truncated..."
  66. #endif
  67. enum cyttsp4_ic_grpnum {
  68. CY_IC_GRPNUM_RESERVED,
  69. CY_IC_GRPNUM_CMD_REGS,
  70. CY_IC_GRPNUM_TCH_REP,
  71. CY_IC_GRPNUM_DATA_REC,
  72. CY_IC_GRPNUM_TEST_REC,
  73. CY_IC_GRPNUM_PCFG_REC,
  74. CY_IC_GRPNUM_TCH_PARM_VAL,
  75. CY_IC_GRPNUM_TCH_PARM_SIZE,
  76. CY_IC_GRPNUM_RESERVED1,
  77. CY_IC_GRPNUM_RESERVED2,
  78. CY_IC_GRPNUM_OPCFG_REC,
  79. CY_IC_GRPNUM_DDATA_REC,
  80. CY_IC_GRPNUM_MDATA_REC,
  81. CY_IC_GRPNUM_TEST_REGS,
  82. CY_IC_GRPNUM_BTN_KEYS,
  83. CY_IC_GRPNUM_TTHE_REGS,
  84. CY_IC_GRPNUM_NUM
  85. };
  86. enum cyttsp4_int_state {
  87. CY_INT_NONE,
  88. CY_INT_IGNORE = (1 << 0),
  89. CY_INT_MODE_CHANGE = (1 << 1),
  90. CY_INT_EXEC_CMD = (1 << 2),
  91. CY_INT_AWAKE = (1 << 3),
  92. };
  93. enum cyttsp4_mode {
  94. CY_MODE_UNKNOWN,
  95. CY_MODE_BOOTLOADER = (1 << 1),
  96. CY_MODE_OPERATIONAL = (1 << 2),
  97. CY_MODE_SYSINFO = (1 << 3),
  98. CY_MODE_CAT = (1 << 4),
  99. CY_MODE_STARTUP = (1 << 5),
  100. CY_MODE_LOADER = (1 << 6),
  101. CY_MODE_CHANGE_MODE = (1 << 7),
  102. CY_MODE_CHANGED = (1 << 8),
  103. CY_MODE_CMD_COMPLETE = (1 << 9),
  104. };
  105. enum cyttsp4_sleep_state {
  106. SS_SLEEP_OFF,
  107. SS_SLEEP_ON,
  108. SS_SLEEPING,
  109. SS_WAKING,
  110. };
  111. enum cyttsp4_startup_state {
  112. STARTUP_NONE,
  113. STARTUP_QUEUED,
  114. STARTUP_RUNNING,
  115. };
  116. #define CY_NUM_REVCTRL 8
  117. struct cyttsp4_cydata {
  118. u8 ttpidh;
  119. u8 ttpidl;
  120. u8 fw_ver_major;
  121. u8 fw_ver_minor;
  122. u8 revctrl[CY_NUM_REVCTRL];
  123. u8 blver_major;
  124. u8 blver_minor;
  125. u8 jtag_si_id3;
  126. u8 jtag_si_id2;
  127. u8 jtag_si_id1;
  128. u8 jtag_si_id0;
  129. u8 mfgid_sz;
  130. u8 cyito_idh;
  131. u8 cyito_idl;
  132. u8 cyito_verh;
  133. u8 cyito_verl;
  134. u8 ttsp_ver_major;
  135. u8 ttsp_ver_minor;
  136. u8 device_info;
  137. u8 mfg_id[];
  138. } __packed;
  139. struct cyttsp4_test {
  140. u8 post_codeh;
  141. u8 post_codel;
  142. } __packed;
  143. struct cyttsp4_pcfg {
  144. u8 electrodes_x;
  145. u8 electrodes_y;
  146. u8 len_xh;
  147. u8 len_xl;
  148. u8 len_yh;
  149. u8 len_yl;
  150. u8 res_xh;
  151. u8 res_xl;
  152. u8 res_yh;
  153. u8 res_yl;
  154. u8 max_zh;
  155. u8 max_zl;
  156. u8 panel_info0;
  157. } __packed;
  158. struct cyttsp4_tch_rec_params {
  159. u8 loc;
  160. u8 size;
  161. } __packed;
  162. #define CY_NUM_TCH_FIELDS 7
  163. #define CY_NUM_EXT_TCH_FIELDS 3
  164. struct cyttsp4_opcfg {
  165. u8 cmd_ofs;
  166. u8 rep_ofs;
  167. u8 rep_szh;
  168. u8 rep_szl;
  169. u8 num_btns;
  170. u8 tt_stat_ofs;
  171. u8 obj_cfg0;
  172. u8 max_tchs;
  173. u8 tch_rec_size;
  174. struct cyttsp4_tch_rec_params tch_rec_old[CY_NUM_TCH_FIELDS];
  175. u8 btn_rec_size; /* btn record size (in bytes) */
  176. u8 btn_diff_ofs; /* btn data loc, diff counts */
  177. u8 btn_diff_size; /* btn size of diff counts (in bits) */
  178. struct cyttsp4_tch_rec_params tch_rec_new[CY_NUM_EXT_TCH_FIELDS];
  179. } __packed;
  180. struct cyttsp4_sysinfo_ptr {
  181. struct cyttsp4_cydata *cydata;
  182. struct cyttsp4_test *test;
  183. struct cyttsp4_pcfg *pcfg;
  184. struct cyttsp4_opcfg *opcfg;
  185. struct cyttsp4_ddata *ddata;
  186. struct cyttsp4_mdata *mdata;
  187. } __packed;
  188. struct cyttsp4_sysinfo_data {
  189. u8 hst_mode;
  190. u8 reserved;
  191. u8 map_szh;
  192. u8 map_szl;
  193. u8 cydata_ofsh;
  194. u8 cydata_ofsl;
  195. u8 test_ofsh;
  196. u8 test_ofsl;
  197. u8 pcfg_ofsh;
  198. u8 pcfg_ofsl;
  199. u8 opcfg_ofsh;
  200. u8 opcfg_ofsl;
  201. u8 ddata_ofsh;
  202. u8 ddata_ofsl;
  203. u8 mdata_ofsh;
  204. u8 mdata_ofsl;
  205. } __packed;
  206. enum cyttsp4_tch_abs { /* for ordering within the extracted touch data array */
  207. CY_TCH_X, /* X */
  208. CY_TCH_Y, /* Y */
  209. CY_TCH_P, /* P (Z) */
  210. CY_TCH_T, /* TOUCH ID */
  211. CY_TCH_E, /* EVENT ID */
  212. CY_TCH_O, /* OBJECT ID */
  213. CY_TCH_W, /* SIZE */
  214. CY_TCH_MAJ, /* TOUCH_MAJOR */
  215. CY_TCH_MIN, /* TOUCH_MINOR */
  216. CY_TCH_OR, /* ORIENTATION */
  217. CY_TCH_NUM_ABS
  218. };
  219. static const char * const cyttsp4_tch_abs_string[] = {
  220. [CY_TCH_X] = "X",
  221. [CY_TCH_Y] = "Y",
  222. [CY_TCH_P] = "P",
  223. [CY_TCH_T] = "T",
  224. [CY_TCH_E] = "E",
  225. [CY_TCH_O] = "O",
  226. [CY_TCH_W] = "W",
  227. [CY_TCH_MAJ] = "MAJ",
  228. [CY_TCH_MIN] = "MIN",
  229. [CY_TCH_OR] = "OR",
  230. [CY_TCH_NUM_ABS] = "INVALID"
  231. };
  232. struct cyttsp4_touch {
  233. int abs[CY_TCH_NUM_ABS];
  234. };
  235. struct cyttsp4_tch_abs_params {
  236. size_t ofs; /* abs byte offset */
  237. size_t size; /* size in bits */
  238. size_t max; /* max value */
  239. size_t bofs; /* bit offset */
  240. };
  241. struct cyttsp4_sysinfo_ofs {
  242. size_t chip_type;
  243. size_t cmd_ofs;
  244. size_t rep_ofs;
  245. size_t rep_sz;
  246. size_t num_btns;
  247. size_t num_btn_regs; /* ceil(num_btns/4) */
  248. size_t tt_stat_ofs;
  249. size_t tch_rec_size;
  250. size_t obj_cfg0;
  251. size_t max_tchs;
  252. size_t mode_size;
  253. size_t data_size;
  254. size_t map_sz;
  255. size_t max_x;
  256. size_t x_origin; /* left or right corner */
  257. size_t max_y;
  258. size_t y_origin; /* upper or lower corner */
  259. size_t max_p;
  260. size_t cydata_ofs;
  261. size_t test_ofs;
  262. size_t pcfg_ofs;
  263. size_t opcfg_ofs;
  264. size_t ddata_ofs;
  265. size_t mdata_ofs;
  266. size_t cydata_size;
  267. size_t test_size;
  268. size_t pcfg_size;
  269. size_t opcfg_size;
  270. size_t ddata_size;
  271. size_t mdata_size;
  272. size_t btn_keys_size;
  273. struct cyttsp4_tch_abs_params tch_abs[CY_TCH_NUM_ABS];
  274. size_t btn_rec_size; /* btn record size (in bytes) */
  275. size_t btn_diff_ofs;/* btn data loc ,diff counts, (Op-Mode byte ofs) */
  276. size_t btn_diff_size;/* btn size of diff counts (in bits) */
  277. };
  278. enum cyttsp4_btn_state {
  279. CY_BTN_RELEASED,
  280. CY_BTN_PRESSED,
  281. CY_BTN_NUM_STATE
  282. };
  283. struct cyttsp4_btn {
  284. bool enabled;
  285. int state; /* CY_BTN_PRESSED, CY_BTN_RELEASED */
  286. int key_code;
  287. };
  288. struct cyttsp4_sysinfo {
  289. bool ready;
  290. struct cyttsp4_sysinfo_data si_data;
  291. struct cyttsp4_sysinfo_ptr si_ptrs;
  292. struct cyttsp4_sysinfo_ofs si_ofs;
  293. struct cyttsp4_btn *btn; /* button states */
  294. u8 *btn_rec_data; /* button diff count data */
  295. u8 *xy_mode; /* operational mode and status regs */
  296. u8 *xy_data; /* operational touch regs */
  297. };
  298. struct cyttsp4_mt_data {
  299. struct cyttsp4_mt_platform_data *pdata;
  300. struct cyttsp4_sysinfo *si;
  301. struct input_dev *input;
  302. struct mutex report_lock;
  303. bool is_suspended;
  304. char phys[NAME_MAX];
  305. int num_prv_tch;
  306. };
  307. struct cyttsp4 {
  308. struct device *dev;
  309. struct mutex system_lock;
  310. struct mutex adap_lock;
  311. enum cyttsp4_mode mode;
  312. enum cyttsp4_sleep_state sleep_state;
  313. enum cyttsp4_startup_state startup_state;
  314. int int_status;
  315. wait_queue_head_t wait_q;
  316. int irq;
  317. struct work_struct startup_work;
  318. struct work_struct watchdog_work;
  319. struct timer_list watchdog_timer;
  320. struct cyttsp4_sysinfo sysinfo;
  321. void *exclusive_dev;
  322. int exclusive_waits;
  323. atomic_t ignore_irq;
  324. bool invalid_touch_app;
  325. struct cyttsp4_mt_data md;
  326. struct cyttsp4_platform_data *pdata;
  327. struct cyttsp4_core_platform_data *cpdata;
  328. const struct cyttsp4_bus_ops *bus_ops;
  329. u8 *xfer_buf;
  330. #ifdef VERBOSE_DEBUG
  331. u8 pr_buf[CY_MAX_PRBUF_SIZE];
  332. #endif
  333. };
  334. struct cyttsp4_bus_ops {
  335. u16 bustype;
  336. int (*write)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
  337. const void *values);
  338. int (*read)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
  339. void *values);
  340. };
  341. enum cyttsp4_hst_mode_bits {
  342. CY_HST_TOGGLE = (1 << 7),
  343. CY_HST_MODE_CHANGE = (1 << 3),
  344. CY_HST_MODE = (7 << 4),
  345. CY_HST_OPERATE = (0 << 4),
  346. CY_HST_SYSINFO = (1 << 4),
  347. CY_HST_CAT = (2 << 4),
  348. CY_HST_LOWPOW = (1 << 2),
  349. CY_HST_SLEEP = (1 << 1),
  350. CY_HST_RESET = (1 << 0),
  351. };
  352. /* abs settings */
  353. #define CY_IGNORE_VALUE 0xFFFF
  354. /* abs signal capabilities offsets in the frameworks array */
  355. enum cyttsp4_sig_caps {
  356. CY_SIGNAL_OST,
  357. CY_MIN_OST,
  358. CY_MAX_OST,
  359. CY_FUZZ_OST,
  360. CY_FLAT_OST,
  361. CY_NUM_ABS_SET /* number of signal capability fields */
  362. };
  363. /* abs axis signal offsets in the framworks array */
  364. enum cyttsp4_sig_ost {
  365. CY_ABS_X_OST,
  366. CY_ABS_Y_OST,
  367. CY_ABS_P_OST,
  368. CY_ABS_W_OST,
  369. CY_ABS_ID_OST,
  370. CY_ABS_MAJ_OST,
  371. CY_ABS_MIN_OST,
  372. CY_ABS_OR_OST,
  373. CY_NUM_ABS_OST /* number of abs signals */
  374. };
  375. enum cyttsp4_flags {
  376. CY_FLAG_NONE = 0x00,
  377. CY_FLAG_HOVER = 0x04,
  378. CY_FLAG_FLIP = 0x08,
  379. CY_FLAG_INV_X = 0x10,
  380. CY_FLAG_INV_Y = 0x20,
  381. CY_FLAG_VKEYS = 0x40,
  382. };
  383. enum cyttsp4_object_id {
  384. CY_OBJ_STANDARD_FINGER,
  385. CY_OBJ_LARGE_OBJECT,
  386. CY_OBJ_STYLUS,
  387. CY_OBJ_HOVER,
  388. };
  389. enum cyttsp4_event_id {
  390. CY_EV_NO_EVENT,
  391. CY_EV_TOUCHDOWN,
  392. CY_EV_MOVE, /* significant displacement (> act dist) */
  393. CY_EV_LIFTOFF, /* record reports last position */
  394. };
  395. /* x-axis resolution of panel in pixels */
  396. #define CY_PCFG_RESOLUTION_X_MASK 0x7F
  397. /* y-axis resolution of panel in pixels */
  398. #define CY_PCFG_RESOLUTION_Y_MASK 0x7F
  399. /* x-axis, 0:origin is on left side of panel, 1: right */
  400. #define CY_PCFG_ORIGIN_X_MASK 0x80
  401. /* y-axis, 0:origin is on top side of panel, 1: bottom */
  402. #define CY_PCFG_ORIGIN_Y_MASK 0x80
  403. static inline int cyttsp4_adap_read(struct cyttsp4 *ts, u16 addr, int size,
  404. void *buf)
  405. {
  406. return ts->bus_ops->read(ts->dev, ts->xfer_buf, addr, size, buf);
  407. }
  408. static inline int cyttsp4_adap_write(struct cyttsp4 *ts, u16 addr, int size,
  409. const void *buf)
  410. {
  411. return ts->bus_ops->write(ts->dev, ts->xfer_buf, addr, size, buf);
  412. }
  413. extern struct cyttsp4 *cyttsp4_probe(const struct cyttsp4_bus_ops *ops,
  414. struct device *dev, u16 irq, size_t xfer_buf_size);
  415. extern int cyttsp4_remove(struct cyttsp4 *ts);
  416. int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
  417. u8 length, const void *values);
  418. int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
  419. u8 length, void *values);
  420. extern const struct dev_pm_ops cyttsp4_pm_ops;
  421. #endif /* _LINUX_CYTTSP4_CORE_H */