pt_regs.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  1. /*
  2. * pt_regs.h
  3. * Parade TrueTouch(TM) Standard Product Registers.
  4. * For use with Parade touchscreen controllers.
  5. * Supported parts include:
  6. * TMA5XX
  7. * TMA448
  8. * TMA445A
  9. * TT21XXX
  10. * TT31XXX
  11. * TT4XXXX
  12. * TT7XXX
  13. * TC3XXX
  14. *
  15. * Copyright (C) 2015-2020 Parade Technologies
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. * version 2, and only version 2, as published by the
  20. * Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * Contact Parade Technologies at www.paradetech.com <[email protected]>
  28. *
  29. */
  30. #ifndef _PT_REGS_H
  31. #define _PT_REGS_H
  32. #define PT_PANEL_ID_DEFAULT 0
  33. #define PT_MAX_PATH_SIZE 128
  34. #define PT_PIP2_BIN_FILE_PATH "/data/ttdl/pt_fw.bin"
  35. #define PT_SUPPRESS_AUTO_BL 0
  36. #define PT_ALLOW_AUTO_BL 1
  37. #define PT_PIP2_MAX_FILE_SIZE 0x18000
  38. #define PT_PIP2_FILE_SECTOR_SIZE 0x1000
  39. #ifndef CONFIG_DRM
  40. #define CONFIG_DRM
  41. #endif
  42. #include <linux/device.h>
  43. #include <linux/fb.h>
  44. #include <linux/notifier.h>
  45. #ifdef CONFIG_HAS_EARLYSUSPEND
  46. #include <linux/earlysuspend.h>
  47. #elif defined(CONFIG_DRM)
  48. #include <drm/drm_panel.h>
  49. #endif
  50. #include <asm/unaligned.h>
  51. #include <linux/debugfs.h>
  52. #include <linux/delay.h>
  53. #include <linux/err.h>
  54. #include <linux/gpio.h>
  55. #include <linux/hid.h>
  56. #include <linux/input.h>
  57. #include <linux/interrupt.h>
  58. #include <linux/irq.h>
  59. #include <linux/kernel.h>
  60. #include <linux/limits.h>
  61. #include <linux/module.h>
  62. #include <linux/of_device.h>
  63. #include <linux/of.h>
  64. #include <linux/pm_runtime.h>
  65. #include <linux/sched.h>
  66. #include <linux/slab.h>
  67. #include <linux/suspend.h>
  68. #include <linux/stringify.h>
  69. #include <linux/types.h>
  70. #include <linux/uaccess.h>
  71. #include <linux/workqueue.h>
  72. #include <linux/version.h>
  73. #include <linux/pt_core.h>
  74. #include <linux/i2c.h>
  75. #include <linux/of_gpio.h>
  76. #include <linux/timer.h>
  77. #include <linux/timex.h>
  78. #include <linux/rtc.h>
  79. #include <linux/regulator/consumer.h>
  80. #define STATUS_SUCCESS 0
  81. #define STATUS_FAIL -1
  82. #define PT_FW_FILE_PREFIX "tt_fw"
  83. #define PT_FW_FILE_SUFFIX ".bin"
  84. #define PT_FW_FILE_NAME "tt_fw.bin"
  85. #define PT_FW_RAM_FILE_NAME "tt_fw_ram.bin"
  86. /* Enable special TTDL features */
  87. #ifndef TTHE_TUNER_SUPPORT
  88. #define TTHE_TUNER_SUPPORT
  89. #endif
  90. #ifndef TTDL_DIAGNOSTICS
  91. #define TTDL_DIAGNOSTICS
  92. #endif
  93. #ifndef EASYWAKE_TSG6
  94. #define EASYWAKE_TSG6
  95. #endif
  96. #ifdef TTHE_TUNER_SUPPORT
  97. #define PT_TTHE_TUNER_FILE_NAME "tthe_tuner"
  98. #endif
  99. #define PT_MAX_PRBUF_SIZE PIPE_BUF
  100. #define PT_PR_TRUNCATED " truncated..."
  101. #define PT_DEFAULT_CORE_ID "pt_core0"
  102. #define PT_MAX_NUM_CORE_DEVS 5
  103. #define PT_IRQ_ASSERTED_VALUE 0
  104. #ifdef PT_ENABLE_MAX_ELEN
  105. #define PT_MAX_ELEN 100
  106. #endif
  107. /* Power Management Macros Enablement */
  108. #ifndef CONFIG_PM
  109. #define CONFIG_PM
  110. #endif
  111. #ifndef CONFIG_PM_RUNTIME
  112. #define CONFIG_PM_RUNTIME
  113. #endif
  114. #ifndef CONFIG_PM_SLEEP
  115. #define CONFIG_PM_SLEEP
  116. #endif
  117. /* Pin Control Macro Enablement */
  118. #ifndef PT_PINCTRL_EN
  119. #define PT_PINCTRL_EN
  120. #endif
  121. #ifndef TT7XXX_EXAMPLE
  122. #define TT7XXX_EXAMPLE
  123. #endif
  124. /*
  125. * The largest PIP message is the PIP2 FILE_WRITE which has:
  126. * 2 byte register
  127. * 4 byte header
  128. * 256 byte payload
  129. * 2 byte CRC
  130. */
  131. #define PT_MAX_PIP2_MSG_SIZE 264
  132. #define PT_MAX_PIP1_MSG_SIZE 255
  133. /*
  134. * The minimun size of PIP2 packet includes:
  135. * 2 byte length
  136. * 1 byte sequence
  137. * 1 byte command ID
  138. * 2 byte CRC
  139. */
  140. #define PT_MIN_PIP2_PACKET_SIZE 6
  141. static const u8 pt_data_block_security_key[] = {
  142. 0xA5, 0x01, 0x02, 0x03, 0xFF, 0xFE, 0xFD, 0x5A
  143. };
  144. /* Enum for debug reporting levels */
  145. enum PT_DEBUG_LEVEL {
  146. DL_QUIET = 0,
  147. DL_ERROR = 1,
  148. DL_WARN = 2,
  149. DL_INFO = 3,
  150. DL_DEBUG = 4,
  151. DL_MAX
  152. };
  153. #define PT_INITIAL_DEBUG_LEVEL DL_WARN
  154. /* Startup DUT enum status bitmask */
  155. enum PT_STARTUP_STATUS {
  156. STARTUP_STATUS_START = 0,
  157. STARTUP_STATUS_BL_RESET_SENTINEL = 0x001,
  158. STARTUP_STATUS_FW_RESET_SENTINEL = 0x002,
  159. STARTUP_STATUS_GET_DESC = 0x004,
  160. STARTUP_STATUS_FW_OUT_OF_BOOT = 0x008,
  161. STARTUP_STATUS_GET_RPT_DESC = 0x010,
  162. STARTUP_STATUS_GET_SYS_INFO = 0x020,
  163. STARTUP_STATUS_GET_CFG_CRC = 0x040,
  164. STARTUP_STATUS_RESTORE_PARM = 0x080,
  165. STARTUP_STATUS_COMPLETE = 0x100,
  166. STARTUP_STATUS_FULL = 0x1FF
  167. };
  168. #define PT_INITIAL_SHOW_TIME_STAMP 0
  169. /*
  170. * Print out all debug prints that are less then or equal to set level.
  171. */
  172. #define pt_debug(dev, dlevel, format, arg...) \
  173. do { \
  174. struct pt_core_data *cd_tmp = dev_get_drvdata(dev);\
  175. if (cd_tmp->debug_level >= dlevel) {\
  176. if (dlevel == DL_ERROR)\
  177. dev_err(dev, "[%d] "format, dlevel, ##arg);\
  178. else\
  179. dev_info(dev, "[%d] "format, dlevel, ##arg);\
  180. } \
  181. } while (0)
  182. enum PT_PIP_REPORT_ID {
  183. PT_PIP_INVALID_REPORT_ID = 0x00,
  184. PT_PIP_TOUCH_REPORT_ID = 0x01,
  185. PT_PIP_TOUCH_REPORT_WIN8_ID = 0x02,
  186. PT_PIP_CAPSENSE_BTN_REPORT_ID = 0x03,
  187. PT_PIP_WAKEUP_REPORT_ID = 0x04,
  188. PT_PIP_NOISE_METRIC_REPORT_ID = 0x05,
  189. PT_PIP_PUSH_BUTTON_REPORT_ID = 0x06,
  190. PT_PIP_SELFCAP_INPUT_REPORT_ID = 0x0D,
  191. PT_PIP_TRACKING_HEATMAP_REPORT_ID = 0x0E,
  192. PT_PIP_SENSOR_DATA_REPORT_ID = 0x0F,
  193. PT_PIP_NON_HID_RESPONSE_ID = 0x1F,
  194. PT_PIP_NON_HID_COMMAND_ID = 0x2F,
  195. PT_PIP_BL_RESPONSE_REPORT_ID = 0x30,
  196. PT_PIP_BL_COMMAND_REPORT_ID = 0x40
  197. };
  198. enum PT_HID_REPORT_ID {
  199. PT_HID_FINGER_REPORT_ID = 0x01,
  200. PT_HID_PEN_REPORT_ID = 0x02
  201. };
  202. /* HID IDs and commands */
  203. #define HID_VENDOR_ID 0x04B4
  204. #define HID_APP_PRODUCT_ID 0xC101
  205. #define HID_VERSION 0x0100
  206. #define HID_APP_REPORT_ID 0xF7
  207. #define HID_BL_REPORT_ID 0xFF
  208. #define HID_RESPONSE_REPORT_ID 0xF0
  209. #define HID_POWER_ON 0x0
  210. #define HID_POWER_SLEEP 0x1
  211. #define HID_POWER_STANDBY 0x2
  212. /* PIP1 offsets and masks */
  213. #define PIP1_RESP_REPORT_ID_OFFSET 2
  214. #define PIP1_RESP_COMMAND_ID_OFFSET 4
  215. #define PIP1_RESP_COMMAND_ID_MASK 0x7F
  216. #define PIP1_CMD_COMMAND_ID_OFFSET 6
  217. #define PIP1_CMD_COMMAND_ID_MASK 0x7F
  218. #define PIP1_SYSINFO_TTDATA_OFFSET 5
  219. #define PIP1_SYSINFO_SENSING_OFFSET 33
  220. #define PIP1_SYSINFO_BTN_OFFSET 48
  221. #define PIP1_SYSINFO_BTN_MASK 0xFF
  222. #define PIP1_SYSINFO_MAX_BTN 8
  223. /* Timeouts in ms */
  224. #define PT_PTSBC_INIT_WATCHDOG_TIMEOUT 20000
  225. #define PT_REQUEST_EXCLUSIVE_TIMEOUT 8000
  226. #define PT_WATCHDOG_TIMEOUT 2000
  227. #define PT_FW_EXIT_BOOT_MODE_TIMEOUT 1000
  228. #define PT_BL_WAIT_FOR_SENTINEL 500
  229. #define PT_REQUEST_ENUM_TIMEOUT 4000
  230. #define PT_GET_HID_DESCRIPTOR_TIMEOUT 500
  231. #define PT_HID_CMD_DEFAULT_TIMEOUT 500
  232. #define PT_PIP_CMD_DEFAULT_TIMEOUT 2000
  233. #define PT_PIP1_CMD_DEFAULT_TIMEOUT 1000
  234. #define PT_PIP1_START_BOOTLOADER_TIMEOUT 2000
  235. #define PT_PIP1_CMD_GET_SYSINFO_TIMEOUT 500
  236. #define PT_PIP1_CMD_CALIBRATE_IDAC_TIMEOUT 5000
  237. #define PT_PIP1_CMD_CALIBRATE_EXT_TIMEOUT 5000
  238. #define PT_PIP1_CMD_WRITE_CONF_BLOCK_TIMEOUT 400
  239. #define PT_PIP1_CMD_RUN_SELF_TEST_TIMEOUT 10000
  240. #define PT_PIP1_CMD_INITIATE_BL_TIMEOUT 20000
  241. #define PT_PIP1_CMD_PROGRAM_AND_VERIFY_TIMEOUT 400
  242. #define PT_PIP2_CMD_FILE_ERASE_TIMEOUT 3000
  243. /* Max counts */
  244. #define PT_WATCHDOG_RETRY_COUNT 30
  245. #define PT_BUS_READ_INPUT_RETRY_COUNT 2
  246. #define PT_FLUSH_BUS_BASED_ON_LEN 0
  247. #define PT_FLUSH_BUS_FULL_256_READ 1
  248. /* maximum number of concurrent tracks */
  249. #define TOUCH_REPORT_SIZE 10
  250. #define TOUCH_INPUT_HEADER_SIZE 7
  251. #define TOUCH_COUNT_BYTE_OFFSET 5
  252. #define BTN_REPORT_SIZE 9
  253. #define BTN_INPUT_HEADER_SIZE 5
  254. #define SENSOR_REPORT_SIZE 150
  255. #define SENSOR_HEADER_SIZE 4
  256. /* helpers */
  257. #define GET_NUM_TOUCHES(x) ((x) & 0x1F)
  258. #define IS_LARGE_AREA(x) ((x) & 0x20)
  259. #define IS_BAD_PKT(x) ((x) & 0x20)
  260. #define IS_TMO(t) ((t) == 0)
  261. #define HI_BYTE(x) (u8)(((x) >> 8) & 0xFF)
  262. #define LOW_BYTE(x) (u8)((x) & 0xFF)
  263. #define SET_CMD_LOW(byte, bits) \
  264. ((byte) = (((byte) & 0xF0) | ((bits) & 0x0F)))
  265. #define SET_CMD_HIGH(byte, bits)\
  266. ((byte) = (((byte) & 0x0F) | ((bits) & 0xF0)))
  267. #define GET_MASK(length) \
  268. ((1 << length) - 1)
  269. #define GET_FIELD(name, length, shift) \
  270. ((name >> shift) & GET_MASK(length))
  271. #define _base(x) ((x >= '0' && x <= '9') ? '0' : \
  272. (x >= 'a' && x <= 'f') ? 'a' - 10 : \
  273. (x >= 'A' && x <= 'F') ? 'A' - 10 : \
  274. '\255')
  275. #define HEXOF(x) (x - _base(x))
  276. #define IS_EASY_WAKE_CONFIGURED(x) \
  277. ((x) != 0 && (x) != 0xFF)
  278. #define IS_PIP_VER_GE(p, maj, min) \
  279. ((p)->ttdata.pip_ver_major > (maj) ? \
  280. 1 : \
  281. (((p)->ttdata.pip_ver_major == (maj) ? \
  282. ((p)->ttdata.pip_ver_minor >= (min) ? \
  283. 1 : 0) : \
  284. 0)))
  285. #define IS_PIP_VER_EQ(p, maj, min) \
  286. ((p)->ttdata.pip_ver_major == (maj) ? \
  287. ((p)->ttdata.pip_ver_minor == (min) ? \
  288. 1 : \
  289. 0 : \
  290. 0))
  291. #define PT_PANEL_ID_BITMASK 0x0000000C
  292. #define PT_PANEL_ID_SHIFT 2
  293. #define TTDL_PTVIRTDUT_SUPPORT 1
  294. /* DUT Debug commands (dut_debug sysfs) */
  295. #define PT_DUT_DBG_HID_RESET 50
  296. #define PT_DUT_DBG_HID_GET_REPORT 51 /* depricated */
  297. #define PT_DUT_DBG_HID_SET_REPORT 52 /* depricated */
  298. #define PT_DUT_DBG_HID_SET_POWER_ON 53
  299. #define PT_DUT_DBG_HID_SET_POWER_SLEEP 54
  300. #define PT_DUT_DBG_HID_SET_POWER_STANDBY 55
  301. #define PT_DUT_DBG_PIP_SOFT_RESET 97
  302. #define PT_DUT_DBG_RESET 98
  303. #define PT_DUT_DBG_PIP_NULL 100
  304. #define PT_DUT_DBG_PIP_ENTER_BL 101
  305. #define PT_DUT_DBG_HID_SYSINFO 102
  306. #define PT_DUT_DBG_PIP_SUSPEND_SCAN 103
  307. #define PT_DUT_DBG_PIP_RESUME_SCAN 104
  308. #define PT_DUT_DBG_HID_DESC 109
  309. /* Driver Debug commands (drv_debug sysfs) */
  310. #define PT_DRV_DBG_SUSPEND 4
  311. #define PT_DRV_DBG_RESUME 5
  312. #define PT_DRV_DBG_STOP_WD 105
  313. #define PT_DRV_DBG_START_WD 106
  314. #define PT_DRV_DBG_TTHE_TUNER_EXIT 107
  315. #define PT_DRV_DBG_TTHE_BUF_CLEAN 108
  316. #define PT_DRV_DBG_CLEAR_PARM_LIST 110
  317. #define PT_DRV_DBG_FORCE_BUS_READ 111
  318. #define PT_DRV_DBG_CLEAR_CAL_DATA 112
  319. /*
  320. * Commands that require additional parameters
  321. * will be in the 200 range. Commands that do not
  322. * require additional parameters remain below 200.
  323. */
  324. #define PT_DRV_DBG_REPORT_LEVEL 200
  325. #define PT_DRV_DBG_WATCHDOG_INTERVAL 201
  326. #define PT_DRV_DBG_SHOW_TIMESTAMP 202
  327. #define PT_DRV_DBG_SET_GENERATION 210
  328. #ifdef TTDL_DIAGNOSTICS
  329. #define PT_DRV_DBG_FLUSH_BUS 204 /* deprecated */
  330. #define PT_DRV_DBG_SETUP_PWR 205
  331. #define PT_DRV_DBG_GET_PUT_SYNC 206
  332. #define PT_DRV_DBG_SET_PIP2_LAUNCH_APP 207 /* deprecated */
  333. #define PT_DRV_DBG_SET_TT_DATA 208
  334. #define PT_DRV_DBG_SET_RUN_FW_PIN 209 /* deprecated */
  335. #define PT_DRV_DBG_SET_BRIDGE_MODE 211
  336. #define PT_DRV_DBG_SET_I2C_ADDRESS 212
  337. #define PT_DRV_DBG_SET_FLASHLESS_DUT 213
  338. #define PT_DRV_DBG_SET_FORCE_SEQ 214
  339. #define PT_DRV_DBG_BL_WITH_NO_INT 215
  340. #define PT_DRV_DBG_CAL_CACHE_IN_HOST 216
  341. #define PT_DRV_DBG_MULTI_CHIP 217
  342. #define PT_DRV_DBG_SET_PANEL_ID_TYPE 218
  343. #define PT_DRV_DBG_PIP_TIMEOUT 219
  344. #define PT_DRV_DBG_TTHE_HID_USB_FORMAT 220
  345. #ifdef TTDL_PTVIRTDUT_SUPPORT
  346. #define PT_DRV_DBG_SET_HW_DETECT 298
  347. #define PT_DRV_DBG_VIRTUAL_I2C_DUT 299
  348. #endif /* TTDL_PTVIRTDUT_SUPPORT */
  349. /* TTDL Built In Self Test selection bit masks */
  350. #define PT_TTDL_BIST_BUS_TEST 0x01
  351. #define PT_TTDL_BIST_IRQ_TEST 0x02
  352. #define PT_TTDL_BIST_TP_XRES_TEST 0x04
  353. #define PT_TTDL_BIST_SLAVE_BUS_TEST 0x08
  354. #define PT_TTDL_BIST_SLAVE_IRQ_TEST 0x10
  355. #define PT_TTDL_BIST_SLAVE_XRES_TEST 0x20
  356. #define SLAVE_DETECT_MASK 0x01
  357. #define VIRT_MAX_IRQ_RELEASE_TIME_US 500000
  358. #endif /* TTDL DIAGNOSTICS */
  359. /* Recognized usages */
  360. /* undef them first for possible redefinition in Linux */
  361. #undef HID_DI_PRESSURE
  362. #undef HID_DI_TIP
  363. #undef HID_DI_CONTACTID
  364. #undef HID_DI_CONTACTCOUNT
  365. #undef HID_DI_SCANTIME
  366. #define HID_DI_PRESSURE 0x000d0030
  367. #define HID_DI_TIP 0x000d0042
  368. #define HID_DI_CONTACTID 0x000d0051
  369. #define HID_DI_CONTACTCOUNT 0x000d0054
  370. #define HID_DI_SCANTIME 0x000d0056
  371. /* Parade vendor specific usages */
  372. #define HID_PT_UNDEFINED 0xff010000
  373. #define HID_PT_BOOTLOADER 0xff010001
  374. #define HID_PT_TOUCHAPPLICATION 0xff010002
  375. #define HID_PT_BUTTONS 0xff010020
  376. #define HID_PT_GENERICITEM 0xff010030
  377. #define HID_PT_LARGEOBJECT 0xff010040
  378. #define HID_PT_NOISEEFFECTS 0xff010041
  379. #define HID_PT_REPORTCOUNTER 0xff010042
  380. #define HID_PT_TOUCHTYPE 0xff010060
  381. #define HID_PT_EVENTID 0xff010061
  382. #define HID_PT_MAJORAXISLENGTH 0xff010062
  383. #define HID_PT_MINORAXISLENGTH 0xff010063
  384. #define HID_PT_ORIENTATION 0xff010064
  385. #define HID_PT_BUTTONSIGNAL 0xff010065
  386. #define HID_PT_MAJOR_CONTACT_AXIS_LENGTH 0xff010066
  387. #define HID_PT_MINOR_CONTACT_AXIS_LENGTH 0xff010067
  388. #define HID_PT_TCH_COL_USAGE_PG 0x000D0022
  389. #define HID_PT_BTN_COL_USAGE_PG 0xFF010020
  390. #define PANEL_ID_NOT_ENABLED 0xFF
  391. #ifdef EASYWAKE_TSG6
  392. #define GESTURE_DOUBLE_TAP (1)
  393. #define GESTURE_TWO_FINGERS_SLIDE (2)
  394. #define GESTURE_TOUCH_DETECTED (3)
  395. #define GESTURE_PUSH_BUTTON (4)
  396. #define GESTURE_SINGLE_SLIDE_DE_TX (5)
  397. #define GESTURE_SINGLE_SLIDE_IN_TX (6)
  398. #define GESTURE_SINGLE_SLIDE_DE_RX (7)
  399. #define GESTURE_SINGLE_SLIDE_IN_RX (8)
  400. #endif
  401. /* FW RAM parameters */
  402. #define PT_RAM_ID_TOUCHMODE_ENABLED 0x02
  403. #define PT_RAM_ID_PROXIMITY_ENABLE 0x20
  404. #define PT_RAM_ID_TOUCHMODE_ENABLED_SIZE 1
  405. #define PT_RAM_ID_PROXIMITY_ENABLE_SIZE 1
  406. /* abs signal capabilities offsets in the frameworks array */
  407. enum pt_sig_caps {
  408. PT_SIGNAL_OST,
  409. PT_MIN_OST,
  410. PT_MAX_OST,
  411. PT_FUZZ_OST,
  412. PT_FLAT_OST,
  413. PT_NUM_ABS_SET /* number of signal capability fields */
  414. };
  415. /* helpers */
  416. #define NUM_SIGNALS(frmwrk) ((frmwrk)->size / PT_NUM_ABS_SET)
  417. #define PARAM(frmwrk, sig_ost, cap_ost) \
  418. ((frmwrk)->abs[((sig_ost) * PT_NUM_ABS_SET) + (cap_ost)])
  419. #define PARAM_SIGNAL(frmwrk, sig_ost) PARAM(frmwrk, sig_ost, PT_SIGNAL_OST)
  420. #define PARAM_MIN(frmwrk, sig_ost) PARAM(frmwrk, sig_ost, PT_MIN_OST)
  421. #define PARAM_MAX(frmwrk, sig_ost) PARAM(frmwrk, sig_ost, PT_MAX_OST)
  422. #define PARAM_FUZZ(frmwrk, sig_ost) PARAM(frmwrk, sig_ost, PT_FUZZ_OST)
  423. #define PARAM_FLAT(frmwrk, sig_ost) PARAM(frmwrk, sig_ost, PT_FLAT_OST)
  424. /* abs axis signal offsets in the framworks array */
  425. enum pt_sig_ost {
  426. PT_ABS_X_OST,
  427. PT_ABS_Y_OST,
  428. PT_ABS_P_OST,
  429. PT_ABS_W_OST,
  430. PT_ABS_ID_OST,
  431. PT_ABS_MAJ_OST,
  432. PT_ABS_MIN_OST,
  433. PT_ABS_OR_OST,
  434. PT_ABS_TOOL_OST,
  435. PT_ABS_D_OST,
  436. PT_NUM_ABS_OST /* number of abs signals */
  437. };
  438. enum hid_command {
  439. HID_CMD_RESERVED = 0x0,
  440. HID_CMD_RESET = 0x1,
  441. HID_CMD_GET_REPORT = 0x2,
  442. HID_CMD_SET_REPORT = 0x3,
  443. HID_CMD_GET_IDLE = 0x4,
  444. HID_CMD_SET_IDLE = 0x5,
  445. HID_CMD_GET_PROTOCOL = 0x6,
  446. HID_CMD_SET_PROTOCOL = 0x7,
  447. HID_CMD_SET_POWER = 0x8,
  448. HID_CMD_VENDOR = 0xE,
  449. };
  450. enum PIP1_cmd_type {
  451. PIP1_CMD_TYPE_FW,
  452. PIP1_CMD_TYPE_BL,
  453. };
  454. /* PIP BL cmd IDs and input for dut_debug sysfs */
  455. enum pip1_bl_cmd_id {
  456. PIP1_BL_CMD_ID_VERIFY_APP_INTEGRITY = 0x31, /* 49 */
  457. PIP1_BL_CMD_ID_GET_INFO = 0x38, /* 56 */
  458. PIP1_BL_CMD_ID_PROGRAM_AND_VERIFY = 0x39, /* 57 */
  459. PIP1_BL_CMD_ID_LAUNCH_APP = 0x3B, /* 59 */
  460. PIP1_BL_CMD_ID_GET_PANEL_ID = 0x3E, /* 62 */
  461. PIP1_BL_CMD_ID_INITIATE_BL = 0x48, /* 72 */
  462. PIP1_BL_CMD_ID_LAST,
  463. };
  464. #define PIP1_BL_SOP 0x1
  465. #define PIP1_BL_EOP 0x17
  466. /* PIP1 Command/Response IDs */
  467. enum PIP1_CMD_ID {
  468. PIP1_CMD_ID_NULL = 0x00,
  469. PIP1_CMD_ID_START_BOOTLOADER = 0x01,
  470. PIP1_CMD_ID_GET_SYSINFO = 0x02,
  471. PIP1_CMD_ID_SUSPEND_SCANNING = 0x03,
  472. PIP1_CMD_ID_RESUME_SCANNING = 0x04,
  473. PIP1_CMD_ID_GET_PARAM = 0x05,
  474. PIP1_CMD_ID_SET_PARAM = 0x06,
  475. PIP1_CMD_ID_GET_NOISE_METRICS = 0x07,
  476. PIP1_CMD_ID_RESERVED = 0x08,
  477. PIP1_CMD_ID_ENTER_EASYWAKE_STATE = 0x09,
  478. PIP1_CMD_ID_VERIFY_CONFIG_BLOCK_CRC = 0x20,
  479. PIP1_CMD_ID_GET_CONFIG_ROW_SIZE = 0x21,
  480. PIP1_CMD_ID_READ_DATA_BLOCK = 0x22,
  481. PIP1_CMD_ID_WRITE_DATA_BLOCK = 0x23,
  482. PIP1_CMD_ID_GET_DATA_STRUCTURE = 0x24,
  483. PIP1_CMD_ID_LOAD_SELF_TEST_PARAM = 0x25,
  484. PIP1_CMD_ID_RUN_SELF_TEST = 0x26,
  485. PIP1_CMD_ID_GET_SELF_TEST_RESULT = 0x27,
  486. PIP1_CMD_ID_CALIBRATE_IDACS = 0x28,
  487. PIP1_CMD_ID_INITIALIZE_BASELINES = 0x29,
  488. PIP1_CMD_ID_EXEC_PANEL_SCAN = 0x2A,
  489. PIP1_CMD_ID_RETRIEVE_PANEL_SCAN = 0x2B,
  490. PIP1_CMD_ID_START_SENSOR_DATA_MODE = 0x2C,
  491. PIP1_CMD_ID_STOP_SENSOR_DATA_MODE = 0x2D,
  492. PIP1_CMD_ID_START_TRACKING_HEATMAP_MODE = 0x2E,
  493. PIP1_CMD_ID_START_SELF_CAP_RPT_MODE = 0x2F,
  494. PIP1_CMD_ID_CALIBRATE_DEVICE_EXTENDED = 0x30,
  495. PIP1_CMD_ID_INT_PIN_OVERRIDE = 0x40,
  496. PIP1_CMD_ID_STORE_PANEL_SCAN = 0x60,
  497. PIP1_CMD_ID_PROCESS_PANEL_SCAN = 0x61,
  498. PIP1_CMD_ID_DISCARD_INPUT_REPORT,
  499. PIP1_CMD_ID_LAST,
  500. PIP1_CMD_ID_USER_CMD,
  501. };
  502. /* PIP2 Command/Response data and structures */
  503. enum PIP2_CMD_ID {
  504. PIP2_CMD_ID_PING = 0x00,
  505. PIP2_CMD_ID_STATUS = 0x01,
  506. PIP2_CMD_ID_CTRL = 0x02,
  507. PIP2_CMD_ID_CONFIG = 0x03,
  508. PIP2_CMD_ID_RESERVE = 0x04,
  509. PIP2_CMD_ID_CLEAR = 0x05,
  510. PIP2_CMD_ID_RESET = 0x06,
  511. PIP2_CMD_ID_VERSION = 0x07,
  512. PIP2_CMD_ID_FILE_OPEN = 0x10,
  513. PIP2_CMD_ID_FILE_CLOSE = 0x11,
  514. PIP2_CMD_ID_FILE_READ = 0x12,
  515. PIP2_CMD_ID_FILE_WRITE = 0x13,
  516. PIP2_CMD_ID_FILE_IOCTL = 0x14,
  517. PIP2_CMD_ID_FLASH_INFO = 0x15,
  518. PIP2_CMD_ID_EXECUTE = 0x16,
  519. PIP2_CMD_ID_GET_LAST_ERRNO = 0x17,
  520. PIP2_CMD_ID_EXIT_HOST_MODE = 0x18,
  521. PIP2_CMD_ID_READ_GPIO = 0x19,
  522. PIP2_CMD_EXECUTE_SCAN = 0x21,
  523. PIP2_CMD_SET_PARAMETER = 0x40,
  524. PIP2_CMD_GET_PARAMETER = 0x41,
  525. PIP2_CMD_SET_DDI_REG = 0x42,
  526. PIP2_CMD_GET_DDI_REG = 0x43,
  527. PIP2_CMD_ID_END = 0x7F
  528. };
  529. enum PIP2_STATUS_EXEC_RUNNING {
  530. PIP2_STATUS_BOOT_EXEC = 0x00,
  531. PIP2_STATUS_APP_EXEC = 0x01,
  532. };
  533. /* FW_SYS_MODE_UNDEFINED must be 1 greater than FW_SYS_MODE_MAX */
  534. enum PIP2_FW_SYSTEM_MODE {
  535. FW_SYS_MODE_BOOT = 0x00,
  536. FW_SYS_MODE_SCANNING = 0x01,
  537. FW_SYS_MODE_DEEP_SLEEP = 0x02,
  538. FW_SYS_MODE_TEST = 0x03,
  539. FW_SYS_MODE_DEEP_STANDBY = 0x04,
  540. FW_SYS_MODE_MAX = FW_SYS_MODE_DEEP_STANDBY,
  541. FW_SYS_MODE_UNDEFINED = FW_SYS_MODE_MAX + 1,
  542. };
  543. /* PIP2 Command/Response data and structures */
  544. enum PIP2_FILE_ID {
  545. PIP2_RAM_FILE = 0x00,
  546. PIP2_FW_FILE = 0x01,
  547. PIP2_CONFIG_FILE = 0x02,
  548. PIP2_FILE_3 = 0x03,
  549. PIP2_FILE_4 = 0x04,
  550. PIP2_FILE_5 = 0x05,
  551. PIP2_FILE_6 = 0x06,
  552. PIP2_FILE_7 = 0x07,
  553. PIP2_FILE_MAX = PIP2_FILE_7,
  554. };
  555. /* Optimize packet sizes per Allwinner H3 bus drivers */
  556. #define PIP2_FILE_WRITE_LEN_PER_PACKET 245
  557. #define PIP2_BL_I2C_FILE_WRITE_LEN_PER_PACKET 245
  558. #define PIP2_BL_SPI_FILE_WRITE_LEN_PER_PACKET 256
  559. enum DUT_GENERATION {
  560. DUT_UNKNOWN = 0x00,
  561. DUT_PIP1_ONLY = 0x01,
  562. DUT_PIP2_CAPABLE = 0x02,
  563. };
  564. enum PIP2_RSP_ERR {
  565. PIP2_RSP_ERR_NONE = 0x00,
  566. PIP2_RSP_ERR_BUSY = 0x01,
  567. PIP2_RSP_ERR_INIT_FAILURE = 0x02,
  568. PIP2_RSP_ERR_ALREADY_OPEN = 0x03,
  569. PIP2_RSP_ERR_NOT_OPEN = 0x04,
  570. PIP2_RSP_ERR_IO_FAILURE = 0x05,
  571. PIP2_RSP_ERR_UNKNOWN_IOCTL = 0x06,
  572. PIP2_RSP_ERR_BAD_ADDRESS = 0x07,
  573. PIP2_RSP_ERR_BAD_FILE = 0x08,
  574. PIP2_RSP_ERR_END_OF_FILE = 0x09,
  575. PIP2_RSP_ERR_TOO_MANY_FILES = 0x0A,
  576. PIP2_RSP_ERR_TIMEOUT = 0x0B,
  577. PIP2_RSP_ERR_ABORTED = 0x0C,
  578. PIP2_RSP_ERR_CRC = 0x0D,
  579. PIP2_RSP_ERR_UNKNOWN_REC_TYPE = 0x0E,
  580. PIP2_RSP_ERR_BAD_FRAME = 0x0F,
  581. PIP2_RSP_ERR_NO_PERMISSION = 0x10,
  582. PIP2_RSP_ERR_UNKNOWN_COMMAND = 0x11,
  583. PIP2_RSP_ERR_INVALID_PARAM = 0x12,
  584. PIP2_RSP_ERR_IO_ALREADY_ACTIVE = 0x13,
  585. PIP2_RSP_ERR_SHUTDOWN = 0x14,
  586. PIP2_RSP_ERR_INVALID_IMAGE = 0x15,
  587. PIP2_RSP_ERR_UNKNOWN_REGISTER = 0x16,
  588. PIP2_RSP_ERR_BAD_LENGTH = 0x17,
  589. PIP2_RSP_ERR_TRIM_FAILURE = 0x18,
  590. };
  591. /*
  592. * Extra bytes for PIP2 = 4 + 2:
  593. * 4 byte header - (len_lsb, len_msb, report ID, Tag, Sequence)
  594. * 2 byte footer - (crc_lsb, crc_msb)
  595. */
  596. #define PIP2_CMD_COMMAND_ID_OFFSET 5
  597. #define PIP2_CMD_COMMAND_ID_MASK 0x7F
  598. #define PIP2_RESP_COMMAND_ID_OFFSET 3
  599. #define PIP2_RESP_SEQUENCE_OFFSET 2
  600. #define PIP2_RESP_SEQUENCE_MASK 0x0F
  601. #define PIP2_RESP_REPORT_ID_OFFSET 3
  602. #define PIP2_RESP_STATUS_OFFSET 4
  603. #define PIP2_RESP_BODY_OFFSET 5
  604. #define PIP2_CRC_SIZE 2
  605. #define PIP2_LEN_FIELD_SIZE 2
  606. #define PIP2_VERSION_CHIP_REV_OFFSET 14
  607. #define PIP2_EXTRA_BYTES_NUM (PIP2_RESP_STATUS_OFFSET + PIP2_CRC_SIZE)
  608. /* File IOCTL commands */
  609. #define PIP2_FILE_IOCTL_CODE_ERASE_FILE 0
  610. #define PIP2_FILE_IOCTL_CODE_SEEK_POINTER 1
  611. #define PIP2_FILE_IOCTL_CODE_AES_CONTROL 2
  612. #define PIP2_FILE_IOCTL_CODE_FILE_STATS 3
  613. #define PIP2_FILE_IOCTL_CODE_FILE_CRC 4
  614. struct pip2_cmd_structure {
  615. u8 reg[2];
  616. u16 len;
  617. u8 id;
  618. u8 seq;
  619. u8 *data;
  620. u8 crc[2]; /* MSB:crc[0], LSB:crc[1] */
  621. };
  622. struct pip2_cmd_response_structure {
  623. u8 id;
  624. u16 response_len;
  625. u32 response_time_min;
  626. u32 response_time_max;
  627. };
  628. enum pip1_bl_status {
  629. ERROR_SUCCESS,
  630. ERROR_KEY,
  631. ERROR_VERIFICATION,
  632. ERROR_LENGTH,
  633. ERROR_DATA,
  634. ERROR_COMMAND,
  635. ERROR_CRC = 8,
  636. ERROR_FLASH_ARRAY,
  637. ERROR_FLASH_ROW,
  638. ERROR_FLASH_PROTECTION,
  639. ERROR_UNKNOWN = 15,
  640. ERROR_INVALID,
  641. };
  642. enum pt_mode {
  643. PT_MODE_UNKNOWN = 0,
  644. PT_MODE_BOOTLOADER = 1,
  645. PT_MODE_OPERATIONAL = 2,
  646. PT_MODE_IGNORE = 255,
  647. };
  648. enum PT_ENTER_BL_RESULT {
  649. PT_ENTER_BL_PASS = 0,
  650. PT_ENTER_BL_ERROR = 1,
  651. PT_ENTER_BL_RESET_FAIL = 2,
  652. PT_ENTER_BL_HID_START_BL_FAIL = 3,
  653. PT_ENTER_BL_CONFIRM_FAIL = 4,
  654. PT_ENTER_BL_GET_FLASH_INFO_FAIL = 5,
  655. };
  656. enum TTDL_EXTENDED_ERROR_CODES {
  657. EX_ERR_FREAD = 400,
  658. EX_ERR_FWRITE = 401,
  659. EX_ERR_FOPEN = 402,
  660. EX_ERR_FCLOSE = 403,
  661. EX_ERR_FLEN = 404,
  662. };
  663. enum pt_cmd_status {
  664. PT_CMD_STATUS_SUCCESS = 0,
  665. PT_CMD_STATUS_FAILURE = 1,
  666. };
  667. enum {
  668. PT_IC_GRPNUM_RESERVED,
  669. PT_IC_GRPNUM_CMD_REGS,
  670. PT_IC_GRPNUM_TCH_REP,
  671. PT_IC_GRPNUM_DATA_REC,
  672. PT_IC_GRPNUM_TEST_REC,
  673. PT_IC_GRPNUM_PCFG_REC,
  674. PT_IC_GRPNUM_TCH_PARM_VAL,
  675. PT_IC_GRPNUM_TCH_PARM_SIZE,
  676. PT_IC_GRPNUM_RESERVED1,
  677. PT_IC_GRPNUM_RESERVED2,
  678. PT_IC_GRPNUM_OPCFG_REC,
  679. PT_IC_GRPNUM_DDATA_REC,
  680. PT_IC_GRPNUM_MDATA_REC,
  681. PT_IC_GRPNUM_TEST_REGS,
  682. PT_IC_GRPNUM_BTN_KEYS,
  683. PT_IC_GRPNUM_TTHE_REGS,
  684. PT_IC_GRPNUM_SENSING_CONF,
  685. PT_IC_GRPNUM_NUM,
  686. };
  687. enum pt_event_id {
  688. PT_EV_NO_EVENT,
  689. PT_EV_TOUCHDOWN,
  690. PT_EV_MOVE, /* significant displacement (> act dist) */
  691. PT_EV_LIFTOFF, /* record reports last position */
  692. };
  693. enum pt_object_id {
  694. PT_OBJ_STANDARD_FINGER,
  695. PT_OBJ_PROXIMITY,
  696. PT_OBJ_STYLUS,
  697. PT_OBJ_GLOVE,
  698. };
  699. enum pt_self_test_result {
  700. PT_ST_RESULT_PASS = 0,
  701. PT_ST_RESULT_FAIL = 1,
  702. PT_ST_RESULT_ABORTED = 2,
  703. PT_ST_RESULT_PARAM_ERR = 3,
  704. PT_ST_RESULT_CFG_ERR = 4,
  705. PT_ST_RESULT_CAL_ERR = 5,
  706. PT_ST_RESULT_DDI_STATE_ERR = 6,
  707. PT_ST_RESULT_HOST_MUST_INTERPRET = 0xFF,
  708. };
  709. #define PT_ST_PRINT_RESULTS true
  710. #define PT_ST_NOPRINT false
  711. #define PT_ST_GET_RESULTS true
  712. #define PT_ST_DONT_GET_RESULTS false
  713. /*
  714. * Maximum number of parameters for the fw_self_test sysfs (255 - 12 + 2)
  715. * 255 - Max PIP message size
  716. * 12 - Header size for PIP message 0x25 (Load Self Test Parameters)
  717. * 2 - Additional parameters for fw_self_test for test_id and format
  718. */
  719. #define PT_FW_SELF_TEST_MAX_PARM 245
  720. enum pt_self_test_id {
  721. PT_ST_ID_NULL = 0,
  722. PT_ST_ID_BIST = 1,
  723. PT_ST_ID_SHORTS = 2,
  724. PT_ST_ID_OPENS = 3,
  725. PT_ST_ID_AUTOSHORTS = 4,
  726. PT_ST_ID_CM_PANEL = 5,
  727. PT_ST_ID_CP_PANEL = 6,
  728. PT_ST_ID_CM_BUTTON = 7,
  729. PT_ST_ID_CP_BUTTON = 8,
  730. PT_ST_ID_FORCE = 9,
  731. PT_ST_ID_OPENS_HIZ = 10,
  732. PT_ST_ID_OPENS_GND = 11,
  733. PT_ST_ID_CP_LFT = 12,
  734. PT_ST_ID_SC_NOISE = 13,
  735. PT_ST_ID_LFT_NOISE = 14,
  736. PT_ST_ID_CP_CHIP_ROUTE_PARASITIC_CAP = 15,
  737. PT_ST_ID_NORMALIZED_RAW_CNT_PANEL = 16,
  738. PT_ST_ID_NORMALIZED_RAW_CNT_LFT = 17,
  739. PT_ST_ID_INVALID = 255
  740. };
  741. enum pt_scan_state {
  742. PT_SCAN_STATE_UNKNOWN = 0,
  743. PT_SCAN_STATE_ACTIVE = 1,
  744. PT_SCAN_STATE_INACTIVE = 2,
  745. };
  746. #define PT_CAL_DATA_MAX_SIZE 2048
  747. #define PT_CAL_DATA_ROW_SIZE 128
  748. #define PT_WAFER_LOT_SIZE 5
  749. #define PT_UID_SIZE 12
  750. enum pt_cal_data_actions {
  751. PT_CAL_DATA_SAVE = 0,
  752. PT_CAL_DATA_RESTORE = 1,
  753. PT_CAL_DATA_CLEAR = 2,
  754. PT_CAL_DATA_INFO = 3
  755. };
  756. enum pt_feature_enable_state {
  757. PT_FEATURE_DISABLE = 0,
  758. PT_FEATURE_ENABLE = 1
  759. };
  760. #define PT_NUM_MFGID 8
  761. /* System Information interface definitions */
  762. struct pt_ttdata_dev {
  763. u8 pip_ver_major;
  764. u8 pip_ver_minor;
  765. __le16 fw_pid;
  766. u8 fw_ver_major;
  767. u8 fw_ver_minor;
  768. __le32 revctrl;
  769. __le16 fw_ver_conf;
  770. u8 bl_ver_major;
  771. u8 bl_ver_minor;
  772. __le16 jtag_si_id_l;
  773. __le16 jtag_si_id_h;
  774. u8 mfg_id[PT_NUM_MFGID];
  775. __le16 post_code;
  776. } __packed;
  777. /* Struct to cast over PIP2 VERSION response */
  778. struct pt_pip2_version_full {
  779. u8 status_code;
  780. u8 pip2_version_lsb;
  781. u8 pip2_version_msb;
  782. u8 fw_version_lsb;
  783. u8 fw_version_msb;
  784. u8 bl_version_lsb;
  785. u8 bl_version_msb;
  786. __le16 chip_rev;
  787. __le16 chip_id;
  788. u8 uid[PT_UID_SIZE];
  789. } __packed;
  790. struct pt_pip2_version {
  791. u8 status_code;
  792. u8 pip2_version_lsb;
  793. u8 pip2_version_msb;
  794. u8 bl_version_lsb;
  795. u8 bl_version_msb;
  796. u8 fw_version_lsb;
  797. u8 fw_version_msb;
  798. __le16 chip_id;
  799. __le16 chip_rev;
  800. } __packed;
  801. struct pt_sensing_conf_data_dev {
  802. u8 electrodes_x;
  803. u8 electrodes_y;
  804. __le16 len_x;
  805. __le16 len_y;
  806. __le16 res_x;
  807. __le16 res_y;
  808. __le16 max_z;
  809. u8 origin_x;
  810. u8 origin_y;
  811. u8 panel_id;
  812. u8 btn;
  813. u8 scan_mode;
  814. u8 max_num_of_tch_per_refresh_cycle;
  815. } __packed;
  816. struct pt_ttdata {
  817. u8 pip_ver_major;
  818. u8 pip_ver_minor;
  819. u8 bl_ver_major;
  820. u8 bl_ver_minor;
  821. u8 fw_ver_major;
  822. u8 fw_ver_minor;
  823. u16 fw_pid;
  824. u16 fw_ver_conf;
  825. u16 post_code;
  826. u32 revctrl;
  827. u16 jtag_id_l;
  828. u16 jtag_id_h;
  829. u8 mfg_id[PT_NUM_MFGID];
  830. u16 chip_rev;
  831. u16 chip_id;
  832. u8 uid[PT_UID_SIZE];
  833. };
  834. struct pt_sensing_conf_data {
  835. u16 res_x;
  836. u16 res_y;
  837. u16 max_z;
  838. u16 len_x;
  839. u16 len_y;
  840. u8 electrodes_x;
  841. u8 electrodes_y;
  842. u8 origin_x;
  843. u8 origin_y;
  844. u8 panel_id;
  845. u8 btn;
  846. u8 scan_mode;
  847. u8 max_tch;
  848. u8 rx_num;
  849. u8 tx_num;
  850. };
  851. enum pt_tch_abs { /* for ordering within the extracted touch data array */
  852. PT_TCH_X, /* X */
  853. PT_TCH_Y, /* Y */
  854. PT_TCH_P, /* P (Z) */
  855. PT_TCH_T, /* TOUCH ID */
  856. PT_TCH_E, /* EVENT ID */
  857. PT_TCH_O, /* OBJECT ID */
  858. PT_TCH_TIP, /* OBJECT ID */
  859. PT_TCH_MAJ, /* TOUCH_MAJOR */
  860. PT_TCH_MIN, /* TOUCH_MINOR */
  861. PT_TCH_OR, /* ORIENTATION */
  862. PT_TCH_NUM_ABS,
  863. };
  864. enum pt_tch_hdr {
  865. PT_TCH_TIME, /* SCAN TIME */
  866. PT_TCH_NUM, /* NUMBER OF RECORDS */
  867. PT_TCH_LO, /* LARGE OBJECT */
  868. PT_TCH_NOISE, /* NOISE EFFECT */
  869. PT_TCH_COUNTER, /* REPORT_COUNTER */
  870. PT_TCH_NUM_HDR,
  871. };
  872. static const char * const pt_tch_abs_string[] = {
  873. [PT_TCH_X] = "X",
  874. [PT_TCH_Y] = "Y",
  875. [PT_TCH_P] = "P",
  876. [PT_TCH_T] = "T",
  877. [PT_TCH_E] = "E",
  878. [PT_TCH_O] = "O",
  879. [PT_TCH_TIP] = "TIP",
  880. [PT_TCH_MAJ] = "MAJ",
  881. [PT_TCH_MIN] = "MIN",
  882. [PT_TCH_OR] = "OR",
  883. [PT_TCH_NUM_ABS] = "INVALID",
  884. };
  885. static const char * const pt_tch_hdr_string[] = {
  886. [PT_TCH_TIME] = "SCAN TIME",
  887. [PT_TCH_NUM] = "NUMBER OF RECORDS",
  888. [PT_TCH_LO] = "LARGE OBJECT",
  889. [PT_TCH_NOISE] = "NOISE EFFECT",
  890. [PT_TCH_COUNTER] = "REPORT_COUNTER",
  891. [PT_TCH_NUM_HDR] = "INVALID",
  892. };
  893. static const int pt_tch_abs_field_map[] = {
  894. [PT_TCH_X] = 0x00010030 /* HID_GD_X */,
  895. [PT_TCH_Y] = 0x00010031 /* HID_GD_Y */,
  896. [PT_TCH_P] = HID_DI_PRESSURE,
  897. [PT_TCH_T] = HID_DI_CONTACTID,
  898. [PT_TCH_E] = HID_PT_EVENTID,
  899. [PT_TCH_O] = HID_PT_TOUCHTYPE,
  900. [PT_TCH_TIP] = HID_DI_TIP,
  901. [PT_TCH_MAJ] = HID_PT_MAJORAXISLENGTH,
  902. [PT_TCH_MIN] = HID_PT_MINORAXISLENGTH,
  903. [PT_TCH_OR] = HID_PT_ORIENTATION,
  904. [PT_TCH_NUM_ABS] = 0,
  905. };
  906. static const int pt_tch_hdr_field_map[] = {
  907. [PT_TCH_TIME] = HID_DI_SCANTIME,
  908. [PT_TCH_NUM] = HID_DI_CONTACTCOUNT,
  909. [PT_TCH_LO] = HID_PT_LARGEOBJECT,
  910. [PT_TCH_NOISE] = HID_PT_NOISEEFFECTS,
  911. [PT_TCH_COUNTER] = HID_PT_REPORTCOUNTER,
  912. [PT_TCH_NUM_HDR] = 0,
  913. };
  914. #define PT_TOUCH_ID_MAX 32
  915. #define PT_NUM_EXT_TCH_FIELDS 3
  916. struct pt_tch_abs_params {
  917. size_t ofs; /* abs byte offset */
  918. size_t size; /* size in bits */
  919. size_t min; /* min value */
  920. size_t max; /* max value */
  921. size_t bofs; /* bit offset */
  922. u8 report;
  923. };
  924. struct pt_touch {
  925. int hdr[PT_TCH_NUM_HDR];
  926. int abs[PT_TCH_NUM_ABS];
  927. };
  928. /* button to keycode support */
  929. #define PT_BITS_PER_BTN 1
  930. #define PT_NUM_BTN_EVENT_ID ((1 << PT_BITS_PER_BTN) - 1)
  931. enum pt_btn_state {
  932. PT_BTN_RELEASED = 0,
  933. PT_BTN_PRESSED = 1,
  934. PT_BTN_NUM_STATE
  935. };
  936. struct pt_btn {
  937. bool enabled;
  938. int state; /* PT_BTN_PRESSED, PT_BTN_RELEASED */
  939. int key_code;
  940. };
  941. enum pt_ic_ebid {
  942. PT_TCH_PARM_EBID = 0x00,
  943. PT_MDATA_EBID = 0x01,
  944. PT_DDATA_EBID = 0x02,
  945. PT_CAL_EBID = 0xF0,
  946. };
  947. /* ttconfig block */
  948. #define PT_TTCONFIG_VERSION_OFFSET 8
  949. #define PT_TTCONFIG_VERSION_SIZE 2
  950. #define PT_TTCONFIG_VERSION_ROW 0
  951. struct pt_ttconfig {
  952. u16 version;
  953. u16 crc;
  954. };
  955. struct pt_report_desc_data {
  956. u16 tch_report_id;
  957. u16 tch_record_size;
  958. u16 tch_header_size;
  959. u16 btn_report_id;
  960. };
  961. struct pt_sysinfo {
  962. bool ready;
  963. struct pt_ttdata ttdata;
  964. struct pt_sensing_conf_data sensing_conf_data;
  965. struct pt_report_desc_data desc;
  966. int num_btns;
  967. struct pt_btn *btn;
  968. struct pt_ttconfig ttconfig;
  969. struct pt_tch_abs_params tch_hdr[PT_TCH_NUM_HDR];
  970. struct pt_tch_abs_params tch_abs[PT_TCH_NUM_ABS];
  971. u8 *xy_mode;
  972. u8 *xy_data;
  973. };
  974. struct pt_bl_info {
  975. bool ready;
  976. u16 chip_id;
  977. };
  978. enum pt_atten_type {
  979. PT_ATTEN_IRQ,
  980. PT_ATTEN_STARTUP,
  981. PT_ATTEN_EXCLUSIVE,
  982. PT_ATTEN_WAKE,
  983. PT_ATTEN_LOADER,
  984. PT_ATTEN_SUSPEND,
  985. PT_ATTEN_RESUME,
  986. PT_ATTEN_CANCEL_LOADER,
  987. PT_ATTEN_NUM_ATTEN,
  988. };
  989. enum pt_sleep_state {
  990. SS_SLEEP_OFF,
  991. SS_SLEEP_ON,
  992. SS_SLEEPING,
  993. SS_WAKING,
  994. };
  995. enum pt_fb_state {
  996. FB_ON,
  997. FB_OFF,
  998. };
  999. enum pt_startup_state {
  1000. STARTUP_NONE,
  1001. STARTUP_QUEUED,
  1002. STARTUP_RUNNING,
  1003. STARTUP_ILLEGAL,
  1004. };
  1005. struct pt_hid_desc {
  1006. __le16 hid_desc_len;
  1007. u8 packet_id;
  1008. u8 reserved_byte;
  1009. __le16 bcd_version;
  1010. __le16 report_desc_len;
  1011. __le16 report_desc_register;
  1012. __le16 input_register;
  1013. __le16 max_input_len;
  1014. __le16 output_register;
  1015. __le16 max_output_len;
  1016. __le16 command_register;
  1017. __le16 data_register;
  1018. __le16 vendor_id;
  1019. __le16 product_id;
  1020. __le16 version_id;
  1021. u8 reserved[4];
  1022. } __packed;
  1023. struct pt_hid_core {
  1024. u16 hid_vendor_id;
  1025. u16 hid_product_id;
  1026. __le16 hid_desc_register;
  1027. u16 hid_report_desc_len;
  1028. u16 hid_max_input_len;
  1029. u16 hid_max_output_len;
  1030. };
  1031. #define PT_HID_MAX_REPORTS 8
  1032. #define PT_HID_MAX_FIELDS 128
  1033. #define PT_HID_MAX_COLLECTIONS 3
  1034. #define PT_HID_MAX_NESTED_COLLECTIONS PT_HID_MAX_COLLECTIONS
  1035. /* Max input is for ASCII representation of hex characters */
  1036. #define PT_MAX_INPUT (PT_MAX_PIP2_MSG_SIZE * 2)
  1037. #define PT_PIP_1P7_EMPTY_BUF 0xFF00
  1038. enum pt_module_id {
  1039. PT_MODULE_MT,
  1040. PT_MODULE_BTN,
  1041. PT_MODULE_PROX,
  1042. PT_MODULE_LAST,
  1043. };
  1044. struct pt_mt_data;
  1045. struct pt_mt_function {
  1046. int (*mt_release)(struct device *dev);
  1047. int (*mt_probe)(struct device *dev, struct pt_mt_data *md);
  1048. void (*report_slot_liftoff)(struct pt_mt_data *md, int max_slots);
  1049. void (*input_sync)(struct input_dev *input);
  1050. void (*input_report)(struct input_dev *input, int sig, int t, int type);
  1051. void (*final_sync)(struct input_dev *input, int max_slots,
  1052. int mt_sync_count, unsigned long *ids);
  1053. int (*input_register_device)(struct input_dev *input, int max_slots);
  1054. };
  1055. struct pt_mt_data {
  1056. struct device *dev;
  1057. struct pt_mt_platform_data *pdata;
  1058. struct pt_sysinfo *si;
  1059. struct input_dev *input;
  1060. struct pt_mt_function mt_function;
  1061. struct mutex mt_lock;
  1062. bool is_suspended;
  1063. bool input_device_registered;
  1064. bool input_device_allocated;
  1065. char phys[NAME_MAX];
  1066. int num_prv_rec;
  1067. int or_min;
  1068. int or_max;
  1069. int t_min;
  1070. int t_max;
  1071. };
  1072. struct pt_btn_data {
  1073. struct device *dev;
  1074. struct pt_btn_platform_data *pdata;
  1075. struct pt_sysinfo *si;
  1076. struct input_dev *input;
  1077. struct mutex btn_lock;
  1078. bool is_suspended;
  1079. bool input_device_registered;
  1080. bool input_device_allocated;
  1081. char phys[NAME_MAX];
  1082. };
  1083. struct pt_proximity_data {
  1084. struct device *dev;
  1085. struct pt_proximity_platform_data *pdata;
  1086. struct pt_sysinfo *si;
  1087. struct input_dev *input;
  1088. struct mutex prox_lock;
  1089. struct mutex sysfs_lock;
  1090. int enable_count;
  1091. bool input_device_registered;
  1092. bool input_device_allocated;
  1093. char phys[NAME_MAX];
  1094. };
  1095. enum pt_calibrate_idacs_sensing_mode {
  1096. PT_CI_SM_MUTCAP_FINE,
  1097. PT_CI_SM_MUTCAP_BUTTON,
  1098. PT_CI_SM_SELFCAP,
  1099. };
  1100. enum pt_initialize_baselines_sensing_mode {
  1101. PT_IB_SM_MUTCAP = 1,
  1102. PT_IB_SM_BUTTON = 2,
  1103. PT_IB_SM_SELFCAP = 4,
  1104. PT_IB_SM_BALANCED = 8,
  1105. };
  1106. /* parameters for extended calibrate command(0x30)*/
  1107. struct pt_cal_ext_data {
  1108. u8 mode;
  1109. u8 data0;
  1110. u8 data1;
  1111. u8 data2;
  1112. } __packed;
  1113. #define PT_CAL_EXT_MODE_UNDEFINED 0xFF
  1114. #define PT_BIN_FILE_MIN_HDR_LENGTH 14
  1115. #define PT_BIN_FILE_MAX_HDR_LENGTH 18
  1116. struct pt_bin_file_hdr {
  1117. u8 length;
  1118. u16 ttpid;
  1119. u8 fw_major;
  1120. u8 fw_minor;
  1121. u32 fw_rev_ctrl;
  1122. u32 fw_crc;
  1123. u16 si_rev;
  1124. u16 si_id;
  1125. u16 config_ver;
  1126. u32 hex_file_size;
  1127. };
  1128. struct pt_core_nonhid_cmd {
  1129. int (*start_bl)(struct device *dev, int protect);
  1130. int (*suspend_scanning)(struct device *dev, int protect);
  1131. int (*resume_scanning)(struct device *dev, int protect);
  1132. int (*get_param)(struct device *dev, int protect, u8 param_id,
  1133. u32 *value);
  1134. int (*set_param)(struct device *dev, int protect, u8 param_id,
  1135. u32 value, u8 size);
  1136. int (*verify_cfg_block_crc)(struct device *dev, int protect,
  1137. u8 ebid, u8 *status, u16 *calculated_crc,
  1138. u16 *stored_crc);
  1139. int (*get_config_row_size)(struct device *dev, int protect,
  1140. u16 *row_size);
  1141. int (*get_data_structure)(struct device *dev, int protect,
  1142. u16 read_offset, u16 read_length, u8 data_id,
  1143. u8 *status, u8 *data_format, u16 *actual_read_len,
  1144. u8 *data);
  1145. int (*run_selftest)(struct device *dev, int protect, u8 test_id,
  1146. u8 write_idacs_to_flash, u8 *status, u8 *summary_result,
  1147. u8 *results_available);
  1148. int (*get_selftest_result)(struct device *dev, int protect,
  1149. u16 read_offset, u16 read_length, u8 test_id, u8 *status,
  1150. u16 *actual_read_len, u8 *data);
  1151. int (*load_self_test_param)(struct device *dev, int protect,
  1152. u8 self_test_id, u16 load_offset, u16 load_length,
  1153. u8 *parameters, u8 *status, u8 *ret_test_id, u16 *act_load_len);
  1154. int (*calibrate_idacs)(struct device *dev, int protect, u8 mode,
  1155. u8 *status);
  1156. int (*calibrate_ext)(struct device *dev,
  1157. int protect, struct pt_cal_ext_data *cal_data, u8 *status);
  1158. int (*initialize_baselines)(struct device *dev, int protect,
  1159. u8 test_id, u8 *status);
  1160. int (*exec_panel_scan)(struct device *dev, int protect, u8 scan_type);
  1161. int (*retrieve_panel_scan)(struct device *dev, int protect,
  1162. u16 read_offset, u16 read_count, u8 data_id,
  1163. u8 *response, u8 *config, u16 *actual_read_len,
  1164. u8 *read_buf);
  1165. int (*read_data_block)(struct device *dev, u16 row_number,
  1166. u16 length, u8 ebid, u16 *actual_read_len,
  1167. u8 *read_buf, u16 read_buf_size, u16 *crc);
  1168. int (*write_data_block)(struct device *dev, u16 row_number,
  1169. u16 write_length, u8 ebid, u8 *write_buf,
  1170. u8 *security_key, u16 *actual_write_len);
  1171. int (*user_cmd)(struct device *dev, int protect, u16 read_len,
  1172. u8 *read_buf, u16 write_len, u8 *write_buf,
  1173. u16 *actual_read_len);
  1174. int (*get_bl_info)(struct device *dev, int protect, u8 *return_data);
  1175. int (*initiate_bl)(struct device *dev, int protect, u16 key_size,
  1176. u8 *key_buf, u16 row_size, u8 *metadata_row_buf);
  1177. int (*launch_app)(struct device *dev, int protect);
  1178. int (*prog_and_verify)(struct device *dev, int protect, u16 data_len,
  1179. u8 *data_buf);
  1180. int (*verify_app_integrity)(struct device *dev, int protect,
  1181. u8 *result);
  1182. int (*get_panel_id)(struct device *dev, int protect, u8 *panel_id);
  1183. int (*pip2_send_cmd)(struct device *dev, int protect,
  1184. u8 id, u8 *data, u16 report_body_len, u8 *read_buf,
  1185. u16 *actual_read_len);
  1186. int (*pip2_send_cmd_no_int)(struct device *dev, int protect,
  1187. u8 id, u8 *data, u16 report_body_len, u8 *read_buf,
  1188. u16 *actual_read_len);
  1189. int (*get_bl_pip2_version)(struct device *dev);
  1190. int (*pip2_file_open)(struct device *dev, u8 file_no);
  1191. int (*pip2_file_close)(struct device *dev, u8 file_no);
  1192. int (*pip2_file_erase)(struct device *dev, u8 file_no, int *status);
  1193. int (*read_us_file)(struct device *dev, u8 *file_path, u8 *buf,
  1194. int *size);
  1195. int (*pip2_file_read)(struct device *dev, u8 file_no,
  1196. u16 num_bytes, u8 *read_buf);
  1197. int (*pip2_file_seek_offset)(struct device *dev, u8 file_no,
  1198. u32 read_offset, u32 write_offset);
  1199. int (*pip2_file_get_stats)(struct device *dev, u8 file_no,
  1200. u32 *address, u32 *file_size);
  1201. int (*pip2_file_crc)(struct device *dev, u8 file_no,
  1202. u32 offset, u32 length, u8 *read_buf);
  1203. int (*manage_cal_data)(struct device *dev, u8 action, u16 *size,
  1204. unsigned short *crc);
  1205. unsigned short (*calc_crc)(unsigned char *q, int len);
  1206. };
  1207. typedef int (*pt_atten_func) (struct device *);
  1208. struct pt_core_commands {
  1209. int (*subscribe_attention)(struct device *dev,
  1210. enum pt_atten_type type, char *id,
  1211. pt_atten_func func, int flags);
  1212. int (*unsubscribe_attention)(struct device *dev,
  1213. enum pt_atten_type type, char *id,
  1214. pt_atten_func func, int flags);
  1215. int (*request_exclusive)(struct device *dev, int timeout_ms);
  1216. int (*release_exclusive)(struct device *dev);
  1217. int (*request_reset)(struct device *dev, int protect);
  1218. int (*request_pip2_launch_app)(struct device *dev, int protect);
  1219. int (*request_enum)(struct device *dev, bool wait);
  1220. struct pt_sysinfo * (*request_sysinfo)(struct device *dev);
  1221. struct pt_loader_platform_data
  1222. *(*request_loader_pdata)(struct device *dev);
  1223. int (*request_stop_wd)(struct device *dev);
  1224. int (*request_start_wd)(struct device *dev);
  1225. int (*request_get_mode)(struct device *dev, int protect, u8 *mode);
  1226. int (*request_pip2_get_mode_sysmode)(struct device *dev, int protect,
  1227. u8 *mode, u8 *sys_mode);
  1228. int (*request_active_pip_prot)(struct device *dev, int protect,
  1229. u8 *pip_version_major, u8 *pip_version_minor);
  1230. int (*request_enable_scan_type)(struct device *dev, u8 scan_type);
  1231. int (*request_disable_scan_type)(struct device *dev, u8 scan_type);
  1232. int (*request_pip2_enter_bl)(struct device *dev, u8 *start_mode,
  1233. int *result);
  1234. int (*request_pip2_bin_hdr)(struct device *dev,
  1235. struct pt_bin_file_hdr *hdr);
  1236. int (*request_dut_generation)(struct device *dev);
  1237. int (*request_hw_version)(struct device *dev, char *hw_version);
  1238. int (*parse_sysfs_input)(struct device *dev,
  1239. const char *buf, size_t buf_size,
  1240. u32 *out_buf, size_t out_buf_size);
  1241. #ifdef TTHE_TUNER_SUPPORT
  1242. int (*request_tthe_print)(struct device *dev, u8 *buf, int buf_len,
  1243. const u8 *data_name);
  1244. #endif
  1245. #ifdef TTDL_DIAGNOSTICS
  1246. void (*request_toggle_err_gpio)(struct device *dev, u8 type);
  1247. #endif
  1248. struct pt_core_nonhid_cmd *nonhid_cmd;
  1249. int (*request_get_fw_mode)(struct device *dev, int protect,
  1250. u8 *sys_mode, u8 *mode);
  1251. };
  1252. enum core_command_protected_status {
  1253. PT_CORE_CMD_UNPROTECTED = 0,
  1254. PT_CORE_CMD_PROTECTED = 1
  1255. };
  1256. enum pt_err_gpio_type {
  1257. PT_ERR_GPIO_NONE = 0,
  1258. PT_ERR_GPIO_I2C_TRANS = 1,
  1259. PT_ERR_GPIO_IRQ_STUCK = 2,
  1260. PT_ERR_GPIO_EXCLUSIVE_ACCESS = 3,
  1261. PT_ERR_GPIO_EMPTY_PACKET = 4,
  1262. PT_ERR_GPIO_BL_RETRY_PACKET = 5,
  1263. PT_ERR_GPIO_MAX_TYPE = PT_ERR_GPIO_BL_RETRY_PACKET,
  1264. };
  1265. struct pt_features {
  1266. uint8_t easywake;
  1267. uint8_t noise_metric;
  1268. uint8_t tracking_heatmap;
  1269. uint8_t sensor_data;
  1270. };
  1271. #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_PM_RUNTIME)
  1272. #if (KERNEL_VERSION(3, 3, 0) > LINUX_VERSION_CODE)
  1273. #define NEED_SUSPEND_NOTIFIER
  1274. #endif /* CONFIG_PM_SLEEP && CONFIG_PM_RUNTIME */
  1275. #endif /* LINUX_VERSION_CODE */
  1276. struct pt_module {
  1277. struct list_head node;
  1278. char *name;
  1279. int (*probe)(struct device *dev, void **data);
  1280. void (*release)(struct device *dev, void *data);
  1281. };
  1282. struct pt_bus_ops {
  1283. u16 bustype;
  1284. int (*read_default)(struct device *dev, void *buf, int size);
  1285. int (*read_default_nosize)(struct device *dev, u8 *buf, u32 max);
  1286. int (*write_read_specific)(struct device *dev, u16 write_len,
  1287. u8 *write_buf, u8 *read_buf);
  1288. };
  1289. struct pt_core_data {
  1290. struct pinctrl *ts_pinctrl;
  1291. struct pinctrl_state *pinctrl_state_active;
  1292. struct pinctrl_state *pinctrl_state_suspend;
  1293. struct pinctrl_state *pinctrl_state_release;
  1294. struct regulator *vdd;
  1295. struct regulator *vcc_i2c;
  1296. struct list_head node;
  1297. struct list_head module_list; /* List of probed modules */
  1298. char core_id[20];
  1299. struct device *dev;
  1300. struct list_head atten_list[PT_ATTEN_NUM_ATTEN];
  1301. struct list_head param_list;
  1302. struct mutex module_list_lock;
  1303. struct mutex system_lock;
  1304. struct mutex sysfs_lock;
  1305. struct mutex ttdl_restart_lock;
  1306. struct mutex firmware_class_lock;
  1307. enum pt_mode mode;
  1308. spinlock_t spinlock;
  1309. struct pt_mt_data md;
  1310. struct pt_btn_data bd;
  1311. struct pt_proximity_data pd;
  1312. int phys_num;
  1313. int pip_cmd_timeout;
  1314. int pip_cmd_timeout_default;
  1315. void *pt_dynamic_data[PT_MODULE_LAST];
  1316. struct pt_platform_data *pdata;
  1317. struct pt_core_platform_data *cpdata;
  1318. const struct pt_bus_ops *bus_ops;
  1319. wait_queue_head_t wait_q;
  1320. enum pt_sleep_state sleep_state;
  1321. enum pt_startup_state startup_state;
  1322. int irq;
  1323. bool irq_enabled;
  1324. bool irq_wake;
  1325. bool irq_disabled;
  1326. bool hw_detected;
  1327. bool runtime;
  1328. u8 easy_wakeup_gesture;
  1329. #ifdef EASYWAKE_TSG6
  1330. u8 gesture_id;
  1331. u8 gesture_data_length;
  1332. u8 gesture_data[80];
  1333. #endif
  1334. bool wait_until_wake;
  1335. u8 pid_for_loader;
  1336. char hw_version[13];
  1337. #ifdef NEED_SUSPEND_NOTIFIER
  1338. /*
  1339. * This notifier is used to receive suspend prepare events
  1340. * When device is PM runtime suspended, pm_generic_suspend()
  1341. * does not call our PM suspend callback for kernels with
  1342. * version less than 3.3.0.
  1343. */
  1344. struct notifier_block pm_notifier;
  1345. #endif
  1346. struct pt_sysinfo sysinfo;
  1347. struct pt_bl_info bl_info;
  1348. void *exclusive_dev;
  1349. int exclusive_waits;
  1350. struct timer_list watchdog_timer;
  1351. struct work_struct watchdog_work;
  1352. struct work_struct enum_work;
  1353. struct work_struct ttdl_restart_work;
  1354. u16 startup_retry_count;
  1355. struct pt_hid_core hid_core;
  1356. int hid_cmd_state;
  1357. int hid_reset_cmd_state; /* reset can happen any time */
  1358. struct pt_hid_desc hid_desc;
  1359. struct pt_features features;
  1360. #define PT_PREALLOCATED_CMD_BUFFER 32
  1361. u8 cmd_buf[PT_PREALLOCATED_CMD_BUFFER];
  1362. u8 input_buf[PT_MAX_INPUT];
  1363. u8 response_buf[PT_MAX_INPUT];
  1364. u8 cmd_rsp_buf[PT_MAX_INPUT];
  1365. u16 cmd_rsp_buf_len;
  1366. int raw_cmd_status;
  1367. #ifdef CONFIG_HAS_EARLYSUSPEND
  1368. struct early_suspend es;
  1369. #elif defined(CONFIG_FB) || defined(CONFIG_DRM)
  1370. struct notifier_block fb_notifier;
  1371. enum pt_fb_state fb_state;
  1372. #endif
  1373. #ifdef TTHE_TUNER_SUPPORT
  1374. struct dentry *tthe_debugfs;
  1375. u8 *tthe_buf;
  1376. u32 tthe_buf_len;
  1377. u32 tthe_buf_size;
  1378. struct mutex tthe_lock;
  1379. u8 tthe_exit;
  1380. #endif
  1381. u8 debug_level;
  1382. u8 watchdog_enabled;
  1383. bool watchdog_force_stop;
  1384. u32 watchdog_interval;
  1385. u8 show_timestamp;
  1386. u32 startup_status;
  1387. u8 pip2_cmd_tag_seq;
  1388. u8 pip2_prot_active;
  1389. u8 pip2_send_user_cmd;
  1390. u8 get_param_id;
  1391. bool bl_pip_ver_ready;
  1392. bool app_pip_ver_ready;
  1393. u8 core_probe_complete;
  1394. u8 active_dut_generation;
  1395. bool set_dut_generation;
  1396. u8 fw_system_mode;
  1397. u8 flashless_dut;
  1398. u8 bl_with_no_int;
  1399. u8 cal_cache_in_host;
  1400. u8 multi_chip;
  1401. u8 tthe_hid_usb_format;
  1402. u8 flashless_auto_bl;
  1403. u8 pip2_us_file_path[PT_MAX_PATH_SIZE];
  1404. bool fw_updating;
  1405. bool fw_sys_mode_in_standby_state;
  1406. #ifdef TTDL_PTVIRTDUT_SUPPORT
  1407. u8 route_bus_virt_dut;
  1408. #endif /* TTDL_PTVIRTDUT_SUPPORT */
  1409. u8 panel_id_support;
  1410. #ifdef TTDL_DIAGNOSTICS
  1411. u8 t_refresh_active;
  1412. u8 flush_bus_type;
  1413. u8 ttdl_bist_select;
  1414. u8 force_pip2_seq;
  1415. u16 ping_test_size;
  1416. u16 pip2_crc_error_count;
  1417. u16 t_refresh_count;
  1418. u16 t_refresh_total;
  1419. u16 wd_xres_count;
  1420. u32 watchdog_count;
  1421. u32 watchdog_irq_stuck_count;
  1422. u32 watchdog_failed_access_count;
  1423. u32 bus_transmit_error_count;
  1424. u32 irq_count;
  1425. u32 bl_retry_packet_count;
  1426. u32 file_erase_timeout_count;
  1427. unsigned long t_refresh_time;
  1428. u16 err_gpio;
  1429. u16 err_gpio_type;
  1430. bool show_tt_data;
  1431. bool bridge_mode;
  1432. bool hw_detect_enabled;
  1433. #endif
  1434. };
  1435. struct gd_sensor {
  1436. int32_t cm_min;
  1437. int32_t cm_max;
  1438. int32_t cm_ave;
  1439. int32_t cm_min_exclude_edge;
  1440. int32_t cm_max_exclude_edge;
  1441. int32_t cm_ave_exclude_edge;
  1442. int32_t gradient_val;
  1443. };
  1444. #ifdef TTHE_TUNER_SUPPORT
  1445. #define PT_CMD_RET_PANEL_IN_DATA_OFFSET 0
  1446. #define PT_CMD_RET_PANEL_ELMNT_SZ_MASK 0x07
  1447. #define PT_CMD_RET_PANEL_HDR 0x0A
  1448. #define PT_CMD_RET_PANEL_ELMNT_SZ_MAX 0x2
  1449. enum scan_data_type_list {
  1450. PT_MUT_RAW,
  1451. PT_MUT_BASE,
  1452. PT_MUT_DIFF,
  1453. PT_SELF_RAW,
  1454. PT_SELF_BASE,
  1455. PT_SELF_DIFF,
  1456. PT_BAL_RAW,
  1457. PT_BAL_BASE,
  1458. PT_BAL_DIFF,
  1459. };
  1460. #endif
  1461. static inline int pt_adap_read_default(struct pt_core_data *cd,
  1462. void *buf, int size)
  1463. {
  1464. return cd->bus_ops->read_default(cd->dev, buf, size);
  1465. }
  1466. static inline int pt_adap_read_default_nosize(struct pt_core_data *cd,
  1467. void *buf, int max)
  1468. {
  1469. return cd->bus_ops->read_default_nosize(cd->dev, buf, max);
  1470. }
  1471. static inline int pt_adap_write_read_specific(struct pt_core_data *cd,
  1472. u16 write_len, u8 *write_buf, u8 *read_buf)
  1473. {
  1474. return cd->bus_ops->write_read_specific(cd->dev, write_len, write_buf,
  1475. read_buf);
  1476. }
  1477. static inline void *pt_get_dynamic_data(struct device *dev, int id)
  1478. {
  1479. struct pt_core_data *cd = dev_get_drvdata(dev);
  1480. return cd->pt_dynamic_data[id];
  1481. }
  1482. int request_exclusive(struct pt_core_data *cd, void *ownptr,
  1483. int timeout_ms);
  1484. int release_exclusive(struct pt_core_data *cd, void *ownptr);
  1485. int _pt_request_pip_get_param(struct device *dev,
  1486. int protect, u8 param_id, u32 *value);
  1487. int _pt_request_pip_set_param(struct device *dev,
  1488. int protect, u8 param_id, u32 value, u8 size);
  1489. static inline int pt_request_exclusive(struct device *dev, int timeout_ms)
  1490. {
  1491. struct pt_core_data *cd = dev_get_drvdata(dev);
  1492. return request_exclusive(cd, dev, timeout_ms);
  1493. }
  1494. static inline int pt_release_exclusive(struct device *dev)
  1495. {
  1496. struct pt_core_data *cd = dev_get_drvdata(dev);
  1497. return release_exclusive(cd, dev);
  1498. }
  1499. static inline int pt_request_nonhid_get_param(struct device *dev,
  1500. int protect, u8 param_id, u32 *value)
  1501. {
  1502. return _pt_request_pip_get_param(dev, protect, param_id,
  1503. value);
  1504. }
  1505. static inline int pt_request_nonhid_set_param(struct device *dev,
  1506. int protect, u8 param_id, u32 value, u8 size)
  1507. {
  1508. return _pt_request_pip_set_param(dev, protect, param_id,
  1509. value, size);
  1510. }
  1511. void pt_pr_buf(struct device *dev, u8 debug_level, u8 *buf,
  1512. u16 buf_len, const char *data_name);
  1513. #ifdef CONFIG_TOUCHSCREEN_PARADE_DEVICETREE_SUPPORT
  1514. int pt_devtree_create_and_get_pdata(struct device *adap_dev);
  1515. int pt_devtree_clean_pdata(struct device *adap_dev);
  1516. #else
  1517. static inline int pt_devtree_create_and_get_pdata(struct device *adap_dev)
  1518. {
  1519. return 0;
  1520. }
  1521. static inline int pt_devtree_clean_pdata(struct device *adap_dev)
  1522. {
  1523. return 0;
  1524. }
  1525. #endif
  1526. int pt_probe(const struct pt_bus_ops *ops, struct device *dev,
  1527. u16 irq, size_t xfer_buf_size);
  1528. int pt_release(struct pt_core_data *cd);
  1529. struct pt_core_commands *pt_get_commands(void);
  1530. struct pt_core_data *pt_get_core_data(char *id);
  1531. int pt_mt_release(struct device *dev);
  1532. int pt_mt_probe(struct device *dev);
  1533. #ifdef CONFIG_TOUCHSCREEN_PARADE_BUTTON
  1534. int pt_btn_probe(struct device *dev);
  1535. int pt_btn_release(struct device *dev);
  1536. #else
  1537. static inline int pt_btn_probe(struct device *dev) { return 0; }
  1538. static inline int pt_btn_release(struct device *dev) { return 0; }
  1539. #endif
  1540. #ifdef CONFIG_TOUCHSCREEN_PARADE_PROXIMITY
  1541. int pt_proximity_probe(struct device *dev);
  1542. int pt_proximity_release(struct device *dev);
  1543. #else
  1544. static inline int pt_proximity_probe(struct device *dev) { return 0; }
  1545. static inline int pt_proximity_release(struct device *dev) { return 0; }
  1546. #endif
  1547. static inline unsigned int pt_get_time_stamp(void)
  1548. {
  1549. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
  1550. struct timespec ts;
  1551. getnstimeofday(&ts);
  1552. return (ts.tv_sec*1000 + ts.tv_nsec/1000000);
  1553. #else
  1554. struct timeval tv;
  1555. do_gettimeofday(&tv);
  1556. return (tv.tv_sec*1000 + tv.tv_usec/1000);
  1557. #endif
  1558. }
  1559. void pt_init_function_ptrs(struct pt_mt_data *md);
  1560. int _pt_subscribe_attention(struct device *dev,
  1561. enum pt_atten_type type, char *id, int (*func)(struct device *),
  1562. int mode);
  1563. int _pt_unsubscribe_attention(struct device *dev,
  1564. enum pt_atten_type type, char *id, int (*func)(struct device *),
  1565. int mode);
  1566. struct pt_sysinfo *_pt_request_sysinfo(struct device *dev);
  1567. extern const struct dev_pm_ops pt_pm_ops;
  1568. int pt_register_module(struct pt_module *module);
  1569. void pt_unregister_module(struct pt_module *module);
  1570. void *pt_get_module_data(struct device *dev,
  1571. struct pt_module *module);
  1572. #endif /* _PT_REGS_H */