pt_regs.h 50 KB

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