raydium_driver.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /* raydium_driver.h
  2. *
  3. * Raydium TouchScreen driver.
  4. *
  5. * Copyright (c) 2021 Raydium tech Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #ifndef __LINUX_RAYDIUM_H
  19. #define __LINUX_RAYDIUM_H
  20. #define RAYDIUM_NAME "raydium_ts"
  21. #define COORDS_ARR_SIZE 4
  22. #define I2C_VTG_MIN_UV 1800000
  23. #define I2C_VTG_MAX_UV 1800000
  24. #define RAD_MAIN_VERSION 0x01
  25. #define RAD_MINOR_VERSION 0x01
  26. #define RAD_CUSTOMER_VERSION 0x0100
  27. #if defined(CONFIG_TOUCHSCREEN_RM_TS)
  28. /* IC timing control arguments */
  29. #define RAYDIUM_POWERON_DELAY_USEC 500
  30. #define RAYDIUM_RESET_INTERVAL_MSEC 5
  31. #define RAYDIUM_RESET_RESTORE_USEC 200
  32. #define RAYDIUM_RESET_DELAY_MSEC 100
  33. /* I2C bus slave address(ID) */
  34. #define RAYDIUM_I2C_EID (0x5A)
  35. #define RAYDIUM_I2C_NID (0x39)
  36. #define RAYDIUM_I2C_PDA_CMD 0x66
  37. /* I2C R/W configuration literal */
  38. #define RAYDIUM_I2C_WRITE I2C_SMBUS_WRITE
  39. #define RAYDIUM_I2C_READ I2C_SMBUS_READ
  40. #define SYN_I2C_RETRY_TIMES 1
  41. #define MAX_WRITE_PACKET_SIZE 128
  42. #define MAX_READ_PACKET_SIZE 128
  43. /* PDA address and bit definition*/
  44. #define RAD_READ_FT_DATA_CMD 0x2000019C
  45. /* 1byte, disable:0x00 ; enable:0x20*/
  46. #define RAD_GESTURE_STATE_CMD 0x200005F4
  47. #define RAD_GESTURE_DISABLE 0x00
  48. #define RAD_GESTURE_ENABLE 0x20
  49. /* 4bytes, [0]:ready ; [1]:type ; [2]:direction*/
  50. #define RAD_GESTURE_RESULT_CMD 0x200005F0
  51. #define RAD_ENABLE_PDA2 0x04
  52. #define RAD_ENABLE_SI2 0x02
  53. /* PDA literal */
  54. #define MASK_8BIT 0xFF
  55. #define RAD_I2C_PDA_ADDRESS_LENGTH 4
  56. #define PDA_MODE 0x01
  57. #define PDA2_MODE 0x02
  58. #define RAD_I2C_PDA_MODE_DISABLE 0x00
  59. #define RAD_I2C_PDA_MODE_ENABLE 0x80
  60. /* Using byte mode due to data might be not word-aligment */
  61. #define RAD_I2C_PDA_MODE_WORD_MODE 0x40
  62. #define RAD_I2C_PDA_2_MODE_DISABLE 0x20
  63. #define I2C_PDA2_BYTE_MODE 0x03
  64. #define I2C_PDA2_WORD_MODE 0x43
  65. #define RAD_PALM_DISABLE 0x00
  66. #define RAD_PALM_ENABLE 0x01
  67. #define RAD_WAKE_UP 0x02
  68. #define RAYDIUM_TEST_FW 0x80
  69. #define RAYDIUM_TEST_PARA 0x40
  70. #define RAYDIUM_BOOTLOADER 0x20
  71. #define RAYDIUM_FIRMWARE 0x10
  72. #define RAYDIUM_PARA 0x08
  73. #define RAYDIUM_COMP 0x04
  74. #define RAYDIUM_BASELINE 0x02
  75. #define RAYDIUM_INIT 0x01
  76. #define FAIL 0
  77. #define ERROR -1
  78. #define SUCCESS 1
  79. #define DISABLE 0
  80. #define ENABLE 1
  81. /* PDA2 setting */
  82. /* Page 0 ~ Page A */
  83. #define MAX_PAGE_AMOUNT 11
  84. /* PDA2 address and setting definition*/
  85. #define RAYDIUM_PDA2_TCH_RPT_STATUS_ADDR 0x00 /* only in Page 0 */
  86. #define RAYDIUM_PDA2_TCH_RPT_ADDR 0x01 /* only in Page 0 */
  87. #define RAYDIUM_PDA2_HOST_CMD_ADDR 0x02 /* only in Page 0 */
  88. #define RAYDIUM_PDA2_PALM_AREA_ADDR 0x03 /* only in Page 0 */
  89. #define RAYDIUM_PDA2_GESTURE_RPT_ADDR 0x04 /* only in Page 0 */
  90. #define RAYDIUM_PDA2_PALM_STATUS_ADDR 0x05 /* only in Page 0 */
  91. #define RAYDIUM_PDA2_FW_VERSION_ADDR 0x06 /* only in Page 0 */
  92. #define RAYDIUM_PDA2_PANEL_VERSION_ADDR 0x07 /* only in Page 0 */
  93. #define RAYDIUM_PDA2_DISPLAY_INFO_ADDR 0x08 /* only in Page 0 */
  94. #define RAYDIUM_PDA2_PDA_CFG_ADDR 0x09 /* only in Page 0 */
  95. #define RAYDIUM_PDA2_RAWDATA_ADDR 0x0B /* only in Page 0 */
  96. /* Page 0 ~ Page 9 will be directed to Page 0 */
  97. #define RAYDIUM_PDA2_PAGE_ADDR 0x0A
  98. #define RAYDIUM_PDA2_PAGE_0 0x00
  99. /* temporary switch to PDA once */
  100. #define RAYDIUM_PDA2_ENABLE_PDA 0x0A
  101. /* permanently switch to PDA mode */
  102. #define RAYDIUM_PDA2_2_PDA (MAX_PAGE_AMOUNT + 2)
  103. /* Raydium host cmd */
  104. #define RAYDIUM_HOST_CMD_NO_OP 0x00
  105. #define RAYDIUM_HOST_CMD_PWR_SLEEP 0x30
  106. #define RAYDIUM_HOST_CMD_DISPLAY_MODE 0x33
  107. #define RAYDIUM_HOST_CMD_CALIBRATION 0x5C
  108. #define RAYDIUM_HOST_CMD_TP_MODE 0x60
  109. #define RAYDIUM_HOST_CMD_FT_MODE 0x61
  110. /* Raydium Register define */
  111. #define RAYDIUM_PDA_BOOTVERSION 0x00000080
  112. #define RAYDIUM_PDA_FIRMWAREADDR 0x00000800
  113. #define RAYDIUM_PDA_PARAADDR 0x00007B00
  114. #define RAYDIUM_PDA_FIRMWARELENGTH 0x00007300
  115. #define RAYDIUM_PDA_PARALENGTH 0x00000178
  116. #define RAYDIUM_PDA_CRCLENGTH 0x00007474
  117. #define RAYDIUM_PDA_SYNCDATA 0x20000200
  118. #define RAYDIUM_PDA_BOOTENG1 0x20000204
  119. #define RAYDIUM_PDA_BOOTENG2 0x20000208
  120. #define RAYDIUM_PDA_BOOTENG3 0x2000020C
  121. #define RAYDIUM_PDA_BOOTENG4 0x20000210
  122. #define RAYDIUM_PDA_BOOTSTATE 0x20000214
  123. #define RAYDIUM_PDA_BOOTMODE 0x20000218
  124. #define RAYDIUM_PDA_BLKEN 0x40000000
  125. #define RAYDIUM_PDA_BLKRST 0x40000004
  126. #define RAYDIUM_PDA_MISCIER 0x40000014
  127. #define RAYDIUM_PDA_I2CENG 0x50000610
  128. #define RAYDIUM_PDA_FLASHPRO 0x50000624
  129. #define RAYDIUM_PDA_I2CREG 0x50000628
  130. #define RAYDIUM_PDA_PRAMLOCK 0x50000900
  131. #define RAYDIUM_PDA_PRAMTYPE 0x50000904
  132. #define RAYDIUM_PDA_PRAMADDR 0x50000908
  133. #define RAYDIUM_PDA_PRAMLENGTH 0x5000090C
  134. #define RAYDIUM_PDA_FLHADDR 0x50000910
  135. #define RAYDIUM_PDA_FLHCTL 0x50000914
  136. #define RAYDIUM_PDA_BOOTREG 0x50000918
  137. #define RAYDIUM_PDA_FLKEY1 0x50000934
  138. #define RAYDIUM_PDA_FLKEY2 0x50000938
  139. #define RAYDIUM_PDA_FLDATA 0x5000093C
  140. #define RAYDIUM_PDA_PRGCHKSUMENG 0x5000094C
  141. #define RAYDIUM_PDA_PRGCHKSUMADDR 0x50000974
  142. #define RAYDIUM_PDA_PRGCHKSUMRESULT 0x50000978
  143. #define RAYDIUM_CHK_I2C_CMD 0x500009BC
  144. #define RAYDIUM_REG_GPIO_DEGLITCH 0x50000E1C
  145. #define I2CTB_LOCK (0x00000001<<6)
  146. #define BOTLR_LOCK (0x00000001<<5)
  147. #define USEFW_LOCK (0x00000001<<4)
  148. #define CONFIG_LOCK (0x00000001<<3)
  149. #define COMP_LOCK (0x00000001<<2)
  150. #define BASEL_LOCK (0x00000001<<1)
  151. #define INICO_LOCK (0x00000001<<0)
  152. /* ['h5000_0904], [32'h0000_0000], Program RAM store type, PRAM_STORE_TYPE */
  153. #define BOTLR_AREA (0x00000001<<5)
  154. #define USEFW_AREA (0x00000001<<4)
  155. #define CONFIG_AREA (0x00000001<<3)
  156. #define COMP_AREA (0x00000001<<2)
  157. #define BASEL_AREA (0x00000001<<1)
  158. #define INICO_AREA (0x00000001<<0)
  159. /* PDA2 literal */
  160. /* entry byte + target page byte */
  161. #define RAYDIUM_I2C_PDA2_PAGE_LENGTH 2
  162. /* Touch report */
  163. #define MAX_TOUCH_NUM 2
  164. #define MAX_REPORT_PACKET_SIZE 35
  165. #define MAX_TCH_STATUS_PACKET_SIZE 4
  166. #define PRESS_MAX 0xFFFF
  167. #define WIDTH_MAX 0xFFFF
  168. #define BYTE_SHIFT 8
  169. #define TOUCH_PRESS 0
  170. #define TOUCH_RELEASE 1
  171. #define TOUCH_MOVE 2
  172. #define TOUCH_COVER 3
  173. #define TOUCH_SHORTCLICK 4
  174. /* FW update literal */
  175. #define RAYDIUM_FW_BIN_PATH_LENGTH 256
  176. #define RAD_BOOT_3X_SIZE 0x800
  177. #define RAD_INIT_3X_SIZE 0x80
  178. #define RAD_FW_3X_SIZE 0x7300
  179. #define RAD_PARA_3X_SIZE 0x174
  180. #define RAD_TESTFW_3X_SIZE (RAD_FW_3X_SIZE + RAD_PARA_3X_SIZE + 4)
  181. #define RAD_CMD_UPDATE_BIN 0x80
  182. #define RAD_CMD_UPDATE_END 0x81
  183. #define RAD_CMD_BURN_FINISH 0x82
  184. /* FT APK literal */
  185. #define RAD_HOST_CMD_POS 0x00
  186. #define RAD_FT_CMD_POS 0x01
  187. #define RAD_FT_CMD_LENGTH 0x02
  188. /* FT APK data type */
  189. #define RAYDIUM_FT_UPDATE 0x00
  190. /*Raydium system flag*/
  191. #define INT_FLAG 0x01
  192. #define ENG_MODE 0x02
  193. #define NORMAL_MODE 0x00
  194. /* define display mode */
  195. #define ACTIVE_MODE 0x00
  196. #define AMBIENT_MODE 0x01
  197. #define SLEEP_MODE 0x02
  198. /* Enable sysfs */
  199. #define CONFIG_RM_SYSFS_DEBUG
  200. /* Gesture switch */
  201. #define GESTURE_EN
  202. /* Enable FW update */
  203. /* #define FW_UPDATE_EN */
  204. /* #define FW_MAPPING_EN */
  205. #define MSM_NEW_VER
  206. /* enable ESD */
  207. /* #define ESD_SOLUTION_EN */
  208. #define RAD_SELFTEST
  209. #define PARA_FW_VERSION_OFFSET 4
  210. #define PINCTRL_STATE_ACTIVE "pmx_ts_active"
  211. #define PINCTRL_STATE_SUSPEND "pmx_ts_suspend"
  212. #define PINCTRL_STATE_RELEASE "pmx_ts_release"
  213. struct raydium_ts_data {
  214. unsigned int irq;
  215. unsigned int irq_gpio;
  216. unsigned int rst_gpio;
  217. unsigned int x_max;
  218. unsigned int y_max;
  219. unsigned int x_pos[2];
  220. unsigned int y_pos[2];
  221. unsigned int pressure;
  222. unsigned int is_suspend;
  223. unsigned int is_sleep;
  224. #ifdef GESTURE_EN
  225. unsigned int is_palm;
  226. #endif
  227. unsigned char u8_max_touchs;
  228. struct i2c_client *client;
  229. struct input_dev *input_dev;
  230. struct mutex lock;
  231. struct work_struct work;
  232. struct workqueue_struct *workqueue;
  233. struct irq_desc *irq_desc;
  234. bool irq_enabled;
  235. bool irq_wake;
  236. #if defined(CONFIG_FB)
  237. struct notifier_block fb_notif;
  238. int blank;
  239. #elif defined(CONFIG_HAS_EARLYSUSPEND)
  240. struct early_suspend early_suspend;
  241. #endif /*end of CONFIG_FB*/
  242. /*struct regulator *vdd;*/
  243. struct regulator *vcc_i2c;
  244. unsigned int fw_version;
  245. unsigned short id;
  246. char *vcc_name;
  247. #ifdef MSM_NEW_VER
  248. struct pinctrl *ts_pinctrl;
  249. struct pinctrl_state *pinctrl_state_active;
  250. struct pinctrl_state *pinctrl_state_suspend;
  251. struct pinctrl_state *pinctrl_state_release;
  252. #endif /*end of MSM_NEW_VER*/
  253. };
  254. struct raydium_platform_data {
  255. char *vdd_name;
  256. int irq_gpio_number;
  257. int reset_gpio_number;
  258. int x_max;
  259. int y_max;
  260. };
  261. struct raydium_ts_platform_data {
  262. char *name;
  263. u32 irqflags;
  264. u32 irq_gpio;
  265. u32 irq_gpio_flags;
  266. u32 reset_gpio;
  267. u32 reset_gpio_flags;
  268. u32 x_max;
  269. u32 y_max;
  270. u32 x_min;
  271. u32 y_min;
  272. u32 hard_rst_dly;
  273. u32 soft_rst_dly;
  274. u32 num_max_touches;
  275. u32 fw_id;
  276. };
  277. /* TODO: Using struct+memcpy instead of array+offset*/
  278. enum raydium_pt_report_status {
  279. POS_SEQ = 0,/*1:touch, 0:no touch*/
  280. POS_PT_AMOUNT,
  281. POS_GES_STATUS,
  282. POS_FW_STATE,
  283. };
  284. enum raydium_pt_report_idx {
  285. POS_PT_ID = 0,
  286. POS_X_L,
  287. POS_X_H,
  288. POS_Y_L,
  289. POS_Y_H,
  290. POS_PRESSURE_L,
  291. POS_PRESSURE_H,
  292. POS_WX_L,
  293. POS_WX_H,
  294. POS_WY_L,
  295. POS_WY_H,
  296. LEN_PT = 11
  297. };
  298. enum raydium_log_level {
  299. LOG_NONE = 0,
  300. LOG_ALERT,
  301. LOG_ERR,
  302. LOG_WARNING,
  303. LOG_INFO,
  304. LOG_DEBUG = 5
  305. };
  306. extern int raydium_read_touchdata(unsigned char *tp_status, unsigned char *buf);
  307. extern int raydium_mem_table_setting(void);
  308. extern int wait_fw_state(struct i2c_client *client, unsigned int u32_addr,
  309. unsigned int u32_state, unsigned long u32_delay_us,
  310. unsigned short u16_retry);
  311. extern int wait_irq_state(struct i2c_client *client,
  312. unsigned int u32_retry_time,
  313. unsigned int u32_delay_us);
  314. extern void raydium_irq_control(bool enable);
  315. extern int raydium_i2c_mode_control(struct i2c_client *client,
  316. unsigned char u8_mode);
  317. extern int raydium_i2c_pda_read(struct i2c_client *client,
  318. unsigned int u32_addr, unsigned char *u8_r_data,
  319. unsigned short u16_length);
  320. extern int raydium_i2c_pda_write(struct i2c_client *client,
  321. unsigned int u32_addr, unsigned char *u8_w_data,
  322. unsigned short u16_length);
  323. extern int handle_i2c_pda_write(struct i2c_client *client,
  324. unsigned int u32_addr, unsigned char *u8_w_data,
  325. unsigned short u16_length);
  326. extern int handle_i2c_pda_read(struct i2c_client *client,
  327. unsigned int u32_addr, unsigned char *u8_r_data,
  328. unsigned short u16_length);
  329. extern int raydium_i2c_pda2_read(struct i2c_client *client,
  330. unsigned char u8_addr,
  331. unsigned char *u8_r_data,
  332. unsigned short u16_length);
  333. extern int raydium_i2c_pda2_write(struct i2c_client *client,
  334. unsigned char u8_addr,
  335. unsigned char *u8_w_data,
  336. unsigned short u16_length);
  337. extern int raydium_i2c_pda2_set_page(struct i2c_client *client,
  338. unsigned int is_suspend,
  339. unsigned char u8_page);
  340. extern int raydium_i2c_write_pda_via_pda2(struct i2c_client *client,
  341. unsigned int u32_addr, unsigned char *u8_w_data,
  342. unsigned short u16_length);
  343. extern int raydium_i2c_read_pda_via_pda2(struct i2c_client *client,
  344. unsigned int u32_addr, unsigned char *u8_r_data,
  345. unsigned short u16_length);
  346. extern unsigned char raydium_disable_i2c_deglitch(void);
  347. extern unsigned char raydium_selftest_stop_mcu(struct i2c_client *client);
  348. extern int raydium_burn_comp(struct i2c_client *client);
  349. extern int raydium_burn_fw(struct i2c_client *client);
  350. extern int raydium_load_test_fw(struct i2c_client *client);
  351. extern int raydium_fw_update_check(unsigned short u16_i2c_data);
  352. extern int raydium_i2c_pda_set_address(unsigned int u32_address,
  353. unsigned char u8_mode);
  354. extern void raydium_mem_table_init(unsigned short u16_id);
  355. extern int raydium_id_init(unsigned char u8_type);
  356. #ifdef RAD_SELFTEST
  357. extern int raydium_do_selftest(struct raydium_ts_data *ts);
  358. #endif
  359. int raydium_esd_check(void);
  360. extern struct attribute *raydium_attributes[];
  361. extern const struct attribute_group raydium_attr_group;
  362. extern unsigned char g_u8_raydium_flag;
  363. extern unsigned char g_u8_addr;
  364. extern unsigned char g_u8_i2c_mode;
  365. extern unsigned char g_u8_upgrade_type;
  366. extern unsigned char g_u8_raw_data_type;
  367. extern unsigned int g_u32_raw_data_len; /* 128 bytes*/
  368. extern unsigned int g_u32_length;
  369. extern unsigned long g_u32_addr;
  370. extern unsigned char *g_rad_fw_image, *g_rad_init_image;
  371. extern unsigned char *g_rad_boot_image, *g_rad_para_image;
  372. extern unsigned char *g_rad_testfw_image, *g_rad_testpara_image;
  373. extern unsigned char g_u8_table_setting, g_u8_table_init;
  374. extern unsigned int g_u32_driver_version;
  375. extern unsigned char g_u8_resetflag;
  376. extern struct raydium_ts_data *g_raydium_ts;
  377. extern unsigned char g_u8_log_level;
  378. #define LOGD(a, fmt, ...) {\
  379. if (a <= g_u8_log_level) {\
  380. pr_info(pr_fmt(fmt), ##__VA_ARGS__);\
  381. } \
  382. }
  383. #endif
  384. #endif /*__LINUX_RAYDIUM_H*/