pt_regs.h 49 KB

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