synaptics_i2c_rmi.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. /* Synaptics Register Mapped Interface (RMI4) I2C Physical Layer Driver.
  2. * Copyright (c) 2007-2012, Synaptics Incorporated
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. */
  14. #ifndef _SYNAPTICS_RMI4_H_
  15. #define _SYNAPTICS_RMI4_H_
  16. #define SYNAPTICS_RMI4_DRIVER_VERSION "DS5 1.0"
  17. #define DRIVER_NAME "synaptics_rmi4_i2c"
  18. #define SYNAPTICS_DEVICE_NAME "SM-W2015"
  19. #include <linux/device.h>
  20. #include <linux/err.h>
  21. #include <linux/delay.h>
  22. #include <linux/gpio.h>
  23. #include <linux/firmware.h>
  24. #include <linux/regulator/consumer.h>
  25. #include <linux/clk.h>
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <asm/unaligned.h>
  29. #include <linux/slab.h>
  30. #include <linux/i2c.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/delay.h>
  33. #include <linux/input.h>
  34. #include <linux/input/mt.h>
  35. #include <linux/of_gpio.h>
  36. #include <linux/uaccess.h>
  37. #include <linux/cdev.h>
  38. #include <linux/extcon.h>
  39. #define PROXIMITY
  40. #define TYPE_B_PROTOCOL
  41. #define TSP_BOOSTER
  42. #define CONFIG_GLOVE_TOUCH
  43. #define USE_OPEN_CLOSE
  44. #define TSP_PATTERN_TRACKING_METHOD
  45. #define PATTERN_TRACKING_FOR_FULLSCREEN
  46. #define REPORT_2D_W
  47. #define CHARGER_NOTIFIER
  48. #ifdef CHARGER_NOTIFIER
  49. #define GPIO_TSP_TA 63
  50. #endif
  51. enum tsp_target{
  52. TSP_MAIN = 0,
  53. TSP_SUB,
  54. };
  55. /* DVFS feature : TOUCH BOOSTER */
  56. #define DVFS_STAGE_TRIPLE 3
  57. #ifdef TSP_BOOSTER
  58. #define DVFS_STAGE_DUAL 2
  59. #define DVFS_STAGE_SINGLE 1
  60. #define DVFS_STAGE_NONE 0
  61. #include <linux/cpufreq.h>
  62. #define TOUCH_BOOSTER_OFF_TIME 300
  63. #define TOUCH_BOOSTER_CHG_TIME 200
  64. #endif
  65. #ifdef USE_OPEN_CLOSE
  66. /*#define USE_OPEN_DWORK*/
  67. #endif
  68. #ifdef USE_OPEN_DWORK
  69. #define TOUCH_OPEN_DWORK_TIME 10
  70. #endif
  71. /* TSP_PATTERN_TRACKING : This is protection code for ghost touch
  72. * such as stucked single postion and frequently pressed and released
  73. * touch into specific area.
  74. * Almost these kind of ghost touch can be treated into firmware level.
  75. * But some hardware or some regional project might be needed this feature.
  76. * Basically this define is not recommeded.
  77. */
  78. /* To recovery the device from ghost touch */
  79. #ifdef TSP_PATTERN_TRACKING_METHOD
  80. #define TSP_PT_MAX_GHOSTCHECK_FINGER 10
  81. #define MAX_GHOSTCHECK_FINGER 10
  82. #define MAX_GHOSTTOUCH_COUNT 5
  83. #define MAX_COUNT_TOUCHSYSREBOOT 4
  84. #define MAX_GHOSTTOUCH_BY_PATTERNTRACKING 3
  85. #define PATTERN_TRACKING_DISTANCE 4
  86. #define TSP_REBOOT_PENDING_TIME 50
  87. #define MOVE_COUNT_TH 100
  88. #define MIN_X_EDGE 17
  89. #define MAX_X_EDGE 1060 //1062
  90. #define MIN_Y_EDGE 17
  91. #define MAX_Y_EDGE 1900 // 1902
  92. #endif
  93. #define F12_FINGERS_TO_SUPPORT 10
  94. #define INVALID_X 65535
  95. #define INVALID_Y 65535
  96. #define RPT_TYPE (1 << 0)
  97. #define RPT_X_LSB (1 << 1)
  98. #define RPT_X_MSB (1 << 2)
  99. #define RPT_Y_LSB (1 << 3)
  100. #define RPT_Y_MSB (1 << 4)
  101. #define RPT_Z (1 << 5)
  102. #define RPT_WX (1 << 6)
  103. #define RPT_WY (1 << 7)
  104. #define RPT_DEFAULT (RPT_TYPE | RPT_X_LSB | RPT_X_MSB |\
  105. RPT_Y_LSB | RPT_Y_MSB)
  106. #ifdef CONFIG_GLOVE_TOUCH
  107. #define GLOVE_FEATURE_EN 0x20
  108. #define GLOVE_CLEAR_DEFAULT 0x00
  109. #endif
  110. #ifdef PROXIMITY
  111. #define USE_CUSTOM_REZERO
  112. #define HOVER_Z_MAX (255)
  113. #define FINGER_HOVER_EN (1 << 0)
  114. #define FINGER_HOVER_DIS (0 << 0)
  115. #define AIR_SWIPE_EN (1 << 1)
  116. #define LARGE_OBJ_EN (1 << 2)
  117. #define HOVER_PINCH_EN (1 << 3)
  118. #define NO_PROXIMITY_ON_TOUCH_EN (1 << 5)
  119. #define CONTINUOUS_LOAD_REPORT_EN (1 << 6)
  120. #define SLEEP_PROXIMITY (1 << 7)
  121. #define PROXIMITY_DEFAULT (NO_PROXIMITY_ON_TOUCH_EN)
  122. #define PROXIMITY_ENABLE (PROXIMITY_DEFAULT | FINGER_HOVER_EN)
  123. #define HAS_FINGER_HOVER (1 << 0)
  124. #define HAS_AIR_SWIPE (1 << 1)
  125. #define HAS_LARGE_OBJ (1 << 2)
  126. #define HAS_HOVER_PINCH (1 << 3)
  127. #define HAS_EDGE_SWIPE (1 << 4)
  128. #define HAS_SINGLE_FINGER (1 << 5) //removable
  129. #define F51_VERSION 0x41
  130. #define F51_PROXIMITY_ENABLES_OFFSET 0
  131. #define F51_CTRL54_OFFSET 99
  132. #ifdef USE_CUSTOM_REZERO
  133. #define F51_GENERAL_CONTROL_OFFSET 1
  134. #define F51_CTRL78_OFFSET 115
  135. #endif
  136. #define F51_FINGER_TIMEOUT 50 /* ms */
  137. #endif
  138. #define POLLING_PERIOD 1 /* ms */
  139. #define SYN_I2C_RETRY_TIMES 3
  140. #define CHECK_STATUS_TIMEOUT_MS 200
  141. #define STATUS_NO_ERROR 0x00
  142. #define STATUS_RESET_OCCURRED 0x01
  143. #define STATUS_INVALID_CONFIG 0x02
  144. #define STATUS_DEVICE_FAILURE 0x03
  145. #define STATUS_CONFIG_CRC_FAILURE 0x04
  146. #define STATUS_FIRMWARE_CRC_FAILURE 0x05
  147. #define STATUS_CRC_IN_PROGRESS 0x06
  148. #define F01_STD_QUERY_LEN 21
  149. #define F01_BUID_ID_OFFSET 18
  150. #define NORMAL_OPERATION (0 << 0)
  151. #define SENSOR_SLEEP (1 << 0)
  152. #define NO_SLEEP_OFF (0 << 2)
  153. #define NO_SLEEP_ON (1 << 2)
  154. #define CHARGER_CONNECTED (1 << 5)
  155. #define CHARGER_DISCONNECTED 0xDF
  156. #define CONFIGURED (1 << 7)
  157. #define TSP_NEEDTO_REBOOT (-ECONNREFUSED)
  158. #define MAX_TSP_REBOOT 3
  159. #define SYNAPTICS_MAX_X_SIZE 1079
  160. #define SYNAPTICS_MAX_Y_SIZE 1919
  161. #define SYNAPTICS_MAX_WIDTH SYNAPTICS_MAX_Y_SIZE
  162. #if defined(CONFIG_MACH_JACTIVESKT)
  163. #define NUM_RX 16
  164. #define NUM_TX 28
  165. #else
  166. #define NUM_RX 28
  167. #define NUM_TX 16
  168. #endif
  169. #define SYNAPTICS_HW_RESET_TIME 80
  170. #define SYNAPTICS_REZERO_TIME 100
  171. #define SYNAPTICS_POWER_MARGIN_TIME 150
  172. #define SYNAPTICS_PRODUCT_ID_B0 "SY 01"
  173. #define SYNAPTICS_PRODUCT_ID_B0_SPAIR "S5000B"
  174. #define FPGA_FW_PATH "ice40xx/fpga_sdio_patek.fw"
  175. /* after B'd rev 06 */
  176. /* User firmware */
  177. #define FW_IMAGE_NAME_PATEK "tsp_synaptics/synaptics_patek.fw"
  178. /* Factory firmware */
  179. #define FAC_FWIMAGE_NAME_PATEK "tsp_synaptics/synaptics_patek_fac.fw"
  180. /* until B'd rev 05 */
  181. /* User firmware */
  182. #define FW_IMAGE_NAME_PATEK_OLD "tsp_synaptics/synaptics_patek_old.fw"
  183. /* Factory firmware */
  184. #define FAC_FWIMAGE_NAME_PATEK_OLD "tsp_synaptics/synaptics_patek_fac_old.fw"
  185. #define SYNAPTICS_MAX_FW_PATH 64
  186. #define SYNAPTICS_DEFAULT_UMS_FW "/sdcard/synaptics.fw"
  187. #define DATE_OF_FIRMWARE_BIN_OFFSET 0xEF00
  188. #define IC_REVISION_BIN_OFFSET 0xEF02
  189. #define FW_VERSION_BIN_OFFSET 0xEF03
  190. #define PDT_PROPS (0X00EF)
  191. #define PDT_START (0x00E9)
  192. #define PDT_END (0x000A)
  193. #define PDT_ENTRY_SIZE (0x0006)
  194. #define PAGES_TO_SERVICE (10)
  195. #define PAGE_SELECT_LEN (2)
  196. #define SYNAPTICS_RMI4_F01 (0x01)
  197. #define SYNAPTICS_RMI4_F12 (0x12)
  198. #define SYNAPTICS_RMI4_F34 (0x34)
  199. #define SYNAPTICS_RMI4_F51 (0x51)
  200. #define SYNAPTICS_RMI4_F54 (0x54)
  201. #define SYNAPTICS_RMI4_PRODUCT_INFO_SIZE 2
  202. #define SYNAPTICS_RMI4_DATE_CODE_SIZE 3
  203. #define SYNAPTICS_RMI4_PRODUCT_ID_SIZE 10
  204. #define SYNAPTICS_RMI4_BUILD_ID_SIZE 3
  205. #define SYNAPTICS_RMI4_PRODUCT_ID_LENGTH 10
  206. #define MAX_INTR_REGISTERS 4
  207. #define MAX_NUMBER_OF_FINGERS 10
  208. #define MASK_16BIT 0xFFFF
  209. #define MASK_8BIT 0xFF
  210. #define MASK_7BIT 0x7F
  211. #define MASK_6BIT 0x3F
  212. #define MASK_5BIT 0x1F
  213. #define MASK_4BIT 0x0F
  214. #define MASK_3BIT 0x07
  215. #define MASK_2BIT 0x03
  216. #define MASK_1BIT 0x01
  217. /*
  218. * struct synaptics_rmi4_fn_desc - function descriptor fields in PDT
  219. * @query_base_addr: base address for query registers
  220. * @cmd_base_addr: base address for command registers
  221. * @ctrl_base_addr: base address for control registers
  222. * @data_base_addr: base address for data registers
  223. * @intr_src_count: number of interrupt sources
  224. * @fn_number: function number
  225. */
  226. struct synaptics_rmi4_fn_desc {
  227. unsigned char query_base_addr;
  228. unsigned char cmd_base_addr;
  229. unsigned char ctrl_base_addr;
  230. unsigned char data_base_addr;
  231. unsigned char intr_src_count;
  232. unsigned char fn_number;
  233. };
  234. /*
  235. * synaptics_rmi4_fn_full_addr - full 16-bit base addresses
  236. * @query_base: 16-bit base address for query registers
  237. * @cmd_base: 16-bit base address for data registers
  238. * @ctrl_base: 16-bit base address for command registers
  239. * @data_base: 16-bit base address for control registers
  240. */
  241. struct synaptics_rmi4_fn_full_addr {
  242. unsigned short query_base;
  243. unsigned short cmd_base;
  244. unsigned short ctrl_base;
  245. unsigned short data_base;
  246. };
  247. /*
  248. * struct synaptics_rmi4_fn - function handler data structure
  249. * @fn_number: function number
  250. * @num_of_data_sources: number of data sources
  251. * @num_of_data_points: maximum number of fingers supported
  252. * @size_of_data_register_block: data register block size
  253. * @data1_offset: offset to data1 register from data base address
  254. * @intr_reg_num: index to associated interrupt register
  255. * @intr_mask: interrupt mask
  256. * @full_addr: full 16-bit base addresses of function registers
  257. * @link: linked list for function handlers
  258. * @data_size: size of private data
  259. * @data: pointer to private data
  260. */
  261. struct synaptics_rmi4_fn {
  262. unsigned char fn_number;
  263. unsigned char num_of_data_sources;
  264. unsigned char num_of_data_points;
  265. unsigned char size_of_data_register_block;
  266. unsigned char data1_offset;
  267. unsigned char intr_reg_num;
  268. unsigned char intr_mask;
  269. struct synaptics_rmi4_fn_full_addr full_addr;
  270. struct list_head link;
  271. int data_size;
  272. void *data;
  273. };
  274. struct synaptics_rmi4_device_tree_data {
  275. int tsp_int;
  276. int num_of_supply;
  277. const char **name_of_supply;
  278. struct regulator_bulk_data *supplies;
  279. int tsp_sel;
  280. int tsp_scl;
  281. int tsp_sda;
  282. int hall_ic;
  283. int fpga_mainclk;
  284. int cresetb;
  285. int cdone;
  286. char x_flip;
  287. char y_flip;
  288. };
  289. /*
  290. * struct synaptics_rmi4_device_info - device information
  291. * @version_major: rmi protocol major version number
  292. * @version_minor: rmi protocol minor version number
  293. * @manufacturer_id: manufacturer id
  294. * @product_props: product properties information
  295. * @product_info: product info array
  296. * @date_code: device manufacture date
  297. * @tester_id: tester id array
  298. * @serial_number: device serial number
  299. * @product_id_string: device product id
  300. * @support_fn_list: linked list for function handlers
  301. */
  302. struct synaptics_rmi4_device_info {
  303. unsigned int version_major;
  304. unsigned int version_minor;
  305. unsigned char manufacturer_id;
  306. unsigned char product_props;
  307. unsigned char product_info[SYNAPTICS_RMI4_PRODUCT_INFO_SIZE];
  308. unsigned char date_code[SYNAPTICS_RMI4_DATE_CODE_SIZE];
  309. unsigned short tester_id;
  310. unsigned short serial_number;
  311. unsigned char product_id_string[SYNAPTICS_RMI4_PRODUCT_ID_SIZE + 1];
  312. unsigned char build_id[SYNAPTICS_RMI4_BUILD_ID_SIZE];
  313. struct list_head support_fn_list;
  314. };
  315. /**
  316. * struct synaptics_finger - Represents fingers.
  317. * @ state: finger status.
  318. * @ mcount: moving counter for debug.
  319. */
  320. struct synaptics_finger {
  321. unsigned char state;
  322. unsigned short mcount;
  323. };
  324. #if defined(TSP_PATTERN_TRACKING_METHOD)
  325. struct pattern_tracking {
  326. int tcount_finger[TSP_PT_MAX_GHOSTCHECK_FINGER];
  327. int touchbx[TSP_PT_MAX_GHOSTCHECK_FINGER];
  328. int touchby[TSP_PT_MAX_GHOSTCHECK_FINGER];
  329. int ghosttouchcount;
  330. bool is_working;
  331. };
  332. #endif
  333. #ifdef CHARGER_NOTIFIER
  334. struct synaptics_cable {
  335. struct work_struct work;
  336. struct notifier_block nb;
  337. struct extcon_specific_cable_nb extcon_nb;
  338. struct extcon_dev *edev;
  339. enum extcon_cable_name cable_type;
  340. unsigned long cable_state;
  341. };
  342. #endif
  343. /*
  344. * struct synaptics_rmi4_data - rmi4 device instance data
  345. * @i2c_client: pointer to associated i2c client
  346. * @input_dev: pointer to associated input device
  347. * @board: constant pointer to platform data
  348. * @rmi4_mod_info: device information
  349. * @regulator: pointer to associated regulator
  350. * @rmi4_io_ctrl_mutex: mutex for i2c i/o control
  351. * @early_suspend: instance to support early suspend power management
  352. * @current_page: current page in sensor to acess
  353. * @full_pm_cycle: flag for full power management cycle in early suspend stage
  354. * @num_of_intr_regs: number of interrupt registers
  355. * @f01_query_base_addr: query base address for f01
  356. * @f01_cmd_base_addr: command base address for f01
  357. * @f01_ctrl_base_addr: control base address for f01
  358. * @f01_data_base_addr: data base address for f01
  359. * @irq: attention interrupt
  360. * @sensor_max_x: sensor maximum x value
  361. * @sensor_max_y: sensor maximum y value
  362. * @irq_enabled: flag for indicating interrupt enable status
  363. * @touch_stopped: flag to stop interrupt thread processing
  364. * @fingers_on_2d: flag to indicate presence of fingers in 2d area
  365. * @sensor_sleep: flag to indicate sleep state of sensor
  366. * @wait: wait queue for touch data polling in interrupt thread
  367. * @i2c_read: pointer to i2c read function
  368. * @i2c_write: pointer to i2c write function
  369. * @irq_enable: pointer to irq enable function
  370. */
  371. struct synaptics_rmi4_data {
  372. struct i2c_client *i2c_client;
  373. struct input_dev *input_dev;
  374. struct synaptics_rmi4_device_tree_data *dt_data;
  375. struct synaptics_rmi4_device_info rmi4_mod_info;
  376. struct regulator *regulator;
  377. struct mutex rmi4_reset_mutex;
  378. struct mutex rmi4_io_ctrl_mutex;
  379. struct mutex rmi4_reflash_mutex;
  380. struct timer_list f51_finger_timer;
  381. struct completion init_done;
  382. struct synaptics_finger finger[MAX_NUMBER_OF_FINGERS];
  383. unsigned char current_page;
  384. unsigned char full_pm_cycle;
  385. unsigned char num_of_rx;
  386. unsigned char num_of_tx;
  387. unsigned char num_of_node;
  388. unsigned char num_of_fingers;
  389. unsigned char max_touch_width;
  390. unsigned char intr_mask[MAX_INTR_REGISTERS];
  391. unsigned short num_of_intr_regs;
  392. unsigned short f01_query_base_addr;
  393. unsigned short f01_cmd_base_addr;
  394. unsigned short f01_ctrl_base_addr;
  395. unsigned short f01_data_base_addr;
  396. int irq;
  397. int sensor_max_x;
  398. int sensor_max_y;
  399. int touch_threshold;
  400. int gloved_sensitivity;
  401. int ta_status;
  402. bool flash_prog_mode;
  403. bool irq_enabled;
  404. bool touch_stopped;
  405. bool fingers_on_2d;
  406. bool f51_finger;
  407. bool f51_finger_is_hover;
  408. bool sensor_sleep;
  409. bool stay_awake;
  410. bool staying_awake;
  411. bool tsp_probe;
  412. #ifdef CHARGER_NOTIFIER
  413. bool cable_state;
  414. #endif
  415. const char *firmware_name;
  416. const char *fac_firmware_name;
  417. int ic_revision_of_ic; /* revision of reading from IC */
  418. int fw_version_of_ic; /* firmware version of IC */
  419. int ic_revision_of_bin; /* revision of reading from binary */
  420. int fw_version_of_bin; /* firmware version of binary */
  421. int fw_release_date_of_ic; /* Config release data from IC */
  422. bool doing_reflash;
  423. int rebootcount;
  424. #ifdef CONFIG_DUAL_LCD
  425. int flip_status;
  426. #endif
  427. #ifdef TSP_PATTERN_TRACKING_METHOD
  428. struct pattern_tracking pattern_data;
  429. #endif
  430. struct regulator *vreg_2p5;
  431. struct regulator *vreg_2p95;
  432. const struct firmware *fpga_fw;
  433. int Is_clk_enabled;
  434. int enable_counte;
  435. #ifdef TSP_BOOSTER
  436. struct delayed_work work_dvfs_off;
  437. struct delayed_work work_dvfs_chg;
  438. struct mutex dvfs_lock;
  439. bool dvfs_lock_status;
  440. int dvfs_old_stauts;
  441. int dvfs_boost_mode;
  442. int dvfs_freq;
  443. #endif
  444. bool hover_status_in_normal_mode;
  445. bool hover_called;
  446. bool hover_ic;
  447. #ifdef CONFIG_GLOVE_TOUCH
  448. unsigned char glove_mode_feature;
  449. unsigned char glove_mode_enables;
  450. unsigned short glove_mode_enables_addr;
  451. bool fast_glove_state;
  452. bool touchkey_glove_mode_status;
  453. #endif
  454. #ifdef USE_OPEN_DWORK
  455. struct delayed_work open_work;
  456. #endif
  457. struct delayed_work rezero_work;
  458. #ifdef TSP_PATTERN_TRACKING_METHOD
  459. struct delayed_work reboot_work;
  460. #endif
  461. struct mutex rmi4_device_mutex;
  462. int (*i2c_read)(struct synaptics_rmi4_data *pdata, unsigned short addr,
  463. unsigned char *data, unsigned short length);
  464. int (*i2c_write)(struct synaptics_rmi4_data *pdata, unsigned short addr,
  465. unsigned char *data, unsigned short length);
  466. int (*irq_enable)(struct synaptics_rmi4_data *rmi4_data, bool enable);
  467. int (*reset_device)(struct synaptics_rmi4_data *rmi4_data);
  468. int (*stop_device)(struct synaptics_rmi4_data *rmi4_data);
  469. int (*start_device)(struct synaptics_rmi4_data *rmi4_data);
  470. };
  471. enum exp_fn {
  472. RMI_DEV = 0,
  473. RMI_F54,
  474. RMI_FW_UPDATER,
  475. RMI_LAST,
  476. };
  477. struct synaptics_rmi4_exp_fn_ptr {
  478. int (*read)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr,
  479. unsigned char *data, unsigned short length);
  480. int (*write)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr,
  481. unsigned char *data, unsigned short length);
  482. int (*enable)(struct synaptics_rmi4_data *rmi4_data, bool enable);
  483. };
  484. struct synaptics_rmi4_f01_device_status {
  485. union {
  486. struct {
  487. unsigned char status_code:4;
  488. unsigned char reserved:2;
  489. unsigned char flash_prog:1;
  490. unsigned char unconfigured:1;
  491. } __packed;
  492. unsigned char data[1];
  493. };
  494. };
  495. struct synaptics_rmi4_f12_query_5 {
  496. union {
  497. struct {
  498. unsigned char size_of_query6;
  499. struct {
  500. unsigned char ctrl0_is_present:1;
  501. unsigned char ctrl1_is_present:1;
  502. unsigned char ctrl2_is_present:1;
  503. unsigned char ctrl3_is_present:1;
  504. unsigned char ctrl4_is_present:1;
  505. unsigned char ctrl5_is_present:1;
  506. unsigned char ctrl6_is_present:1;
  507. unsigned char ctrl7_is_present:1;
  508. } __packed;
  509. struct {
  510. unsigned char ctrl8_is_present:1;
  511. unsigned char ctrl9_is_present:1;
  512. unsigned char ctrl10_is_present:1;
  513. unsigned char ctrl11_is_present:1;
  514. unsigned char ctrl12_is_present:1;
  515. unsigned char ctrl13_is_present:1;
  516. unsigned char ctrl14_is_present:1;
  517. unsigned char ctrl15_is_present:1;
  518. } __packed;
  519. struct {
  520. unsigned char ctrl16_is_present:1;
  521. unsigned char ctrl17_is_present:1;
  522. unsigned char ctrl18_is_present:1;
  523. unsigned char ctrl19_is_present:1;
  524. unsigned char ctrl20_is_present:1;
  525. unsigned char ctrl21_is_present:1;
  526. unsigned char ctrl22_is_present:1;
  527. unsigned char ctrl23_is_present:1;
  528. } __packed;
  529. struct {
  530. unsigned char ctrl24_is_present:1;
  531. unsigned char ctrl25_is_present:1;
  532. unsigned char ctrl26_is_present:1;
  533. unsigned char ctrl27_is_present:1;
  534. unsigned char ctrl28_is_present:1;
  535. unsigned char ctrl29_is_present:1;
  536. unsigned char ctrl30_is_present:1;
  537. unsigned char ctrl31_is_present:1;
  538. } __packed;
  539. };
  540. unsigned char data[5];
  541. };
  542. };
  543. struct synaptics_rmi4_f12_query_8 {
  544. union {
  545. struct {
  546. unsigned char size_of_query9;
  547. struct {
  548. unsigned char data0_is_present:1;
  549. unsigned char data1_is_present:1;
  550. unsigned char data2_is_present:1;
  551. unsigned char data3_is_present:1;
  552. unsigned char data4_is_present:1;
  553. unsigned char data5_is_present:1;
  554. unsigned char data6_is_present:1;
  555. unsigned char data7_is_present:1;
  556. } __packed;
  557. };
  558. unsigned char data[2];
  559. };
  560. };
  561. struct synaptics_rmi4_f12_ctrl_8 {
  562. union {
  563. struct {
  564. unsigned char max_x_coord_lsb;
  565. unsigned char max_x_coord_msb;
  566. unsigned char max_y_coord_lsb;
  567. unsigned char max_y_coord_msb;
  568. unsigned char rx_pitch_lsb;
  569. unsigned char rx_pitch_msb;
  570. unsigned char tx_pitch_lsb;
  571. unsigned char tx_pitch_msb;
  572. unsigned char low_rx_clip;
  573. unsigned char high_rx_clip;
  574. unsigned char low_tx_clip;
  575. unsigned char high_tx_clip;
  576. unsigned char num_of_rx;
  577. unsigned char num_of_tx;
  578. };
  579. unsigned char data[14];
  580. };
  581. };
  582. struct synaptics_rmi4_f12_ctrl_9 {
  583. union {
  584. struct {
  585. unsigned char touch_threshold;
  586. unsigned char lift_hysteresis;
  587. unsigned char small_z_scale_factor_lsb;
  588. unsigned char small_z_scale_factor_msb;
  589. unsigned char large_z_scale_factor_lsb;
  590. unsigned char large_z_scale_factor_msb;
  591. unsigned char small_large_boundary;
  592. unsigned char wx_scale;
  593. unsigned char wx_offset;
  594. unsigned char wy_scale;
  595. unsigned char wy_offset;
  596. unsigned char x_size_lsb;
  597. unsigned char x_size_msb;
  598. unsigned char y_size_lsb;
  599. unsigned char y_size_msb;
  600. unsigned char gloved_finger;
  601. };
  602. unsigned char data[16];
  603. };
  604. };
  605. struct synaptics_rmi4_f12_ctrl_23 {
  606. union {
  607. struct {
  608. unsigned char obj_type_enable;
  609. unsigned char max_reported_objects;
  610. };
  611. unsigned char data[2];
  612. };
  613. };
  614. #ifdef CONFIG_GLOVE_TOUCH
  615. struct synaptics_rmi4_f12_ctrl_26 {
  616. union {
  617. struct {
  618. unsigned char glove_feature_enable;
  619. };
  620. unsigned char data[1];
  621. };
  622. };
  623. #endif
  624. struct synaptics_rmi4_f12_finger_data {
  625. unsigned char object_type_and_status;
  626. unsigned char x_lsb;
  627. unsigned char x_msb;
  628. unsigned char y_lsb;
  629. unsigned char y_msb;
  630. #ifdef REPORT_2D_Z
  631. unsigned char z;
  632. #endif
  633. #ifdef REPORT_2D_W
  634. unsigned char wx;
  635. unsigned char wy;
  636. #endif
  637. };
  638. struct synaptics_rmi4_f34_ctrl_3 {
  639. union {
  640. struct {
  641. unsigned char fw_release_month;
  642. unsigned char fw_release_date;
  643. unsigned char fw_release_revision;
  644. unsigned char fw_release_version;
  645. };
  646. unsigned char data[4];
  647. };
  648. };
  649. struct synaptics_rmi4_f34_fn_ptr {
  650. int (*read)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr,
  651. unsigned char *data, unsigned short length);
  652. int (*write)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr,
  653. unsigned char *data, unsigned short length);
  654. int (*enable)(struct synaptics_rmi4_data *rmi4_data, bool enable);
  655. };
  656. struct synaptics_rmi4_f34_handle {
  657. unsigned char status;
  658. unsigned char cmd;
  659. unsigned short bootloaderid;
  660. unsigned short blocksize;
  661. unsigned short imageblockcount;
  662. unsigned short configblockcount;
  663. unsigned short blocknum;
  664. unsigned short query_base_addr;
  665. unsigned short control_base_addr;
  666. unsigned short data_base_addr;
  667. bool inflashprogmode;
  668. unsigned char intr_mask;
  669. struct mutex attn_mutex;
  670. struct synaptics_rmi4_f34_fn_ptr *fn_ptr;
  671. };
  672. #ifdef PROXIMITY
  673. struct synaptics_rmi4_f51_query {
  674. union {
  675. struct {
  676. unsigned char query_register_count;
  677. unsigned char data_register_count;
  678. unsigned char control_register_count;
  679. unsigned char command_register_count;
  680. unsigned char proximity_controls;
  681. };
  682. unsigned char data[5];
  683. };
  684. };
  685. struct synaptics_rmi4_f51_data {
  686. union {
  687. struct {
  688. unsigned char finger_hover_det:1;
  689. unsigned char air_swipe_det:1;
  690. unsigned char large_obj_det:1;
  691. unsigned char hover_pinch_det:1;
  692. unsigned char hover_finger_x_4__11;
  693. unsigned char hover_finger_y_4__11;
  694. unsigned char hover_finger_xy_0__3;
  695. unsigned char hover_finger_z;
  696. unsigned char air_swipe_dir_0:1;
  697. unsigned char air_swipe_dir_1:1;
  698. unsigned char object_present:1;
  699. unsigned char large_obj_act:2;
  700. } __packed;
  701. unsigned char proximity_data[6];
  702. };
  703. };
  704. struct synaptics_rmi4_f51_handle {
  705. unsigned char proximity_enables;
  706. unsigned short proximity_enables_addr;
  707. unsigned char num_of_data_sources;
  708. #ifdef USE_CUSTOM_REZERO
  709. unsigned short proximity_custom_rezero_addr;
  710. #endif
  711. unsigned char proximity_controls;
  712. struct synaptics_rmi4_data *rmi4_data;
  713. };
  714. #endif
  715. struct synaptics_rmi4_exp_fn {
  716. enum exp_fn fn_type;
  717. bool initialized;
  718. int (*func_init)(struct synaptics_rmi4_data *rmi4_data);
  719. void (*func_remove)(struct synaptics_rmi4_data *rmi4_data);
  720. void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
  721. unsigned char intr_mask);
  722. struct list_head link;
  723. };
  724. int synaptics_rmi4_new_function(enum exp_fn fn_type,
  725. int (*func_init)(struct synaptics_rmi4_data *rmi4_data),
  726. void (*func_remove)(struct synaptics_rmi4_data *rmi4_data),
  727. void (*func_attn)(struct synaptics_rmi4_data *rmi4_data,
  728. unsigned char intr_mask));
  729. int rmidev_module_register(void);
  730. int rmi4_f54_module_register(void);
  731. int synaptics_rmi4_f54_set_control(struct synaptics_rmi4_data *rmi4_data);
  732. int rmi4_fw_update_module_register(void);
  733. int synaptics_fw_updater(unsigned char *fw_data);
  734. int synaptics_rmi4_fw_update_on_probe(struct synaptics_rmi4_data *rmi4_data);
  735. int synaptics_rmi4_proximity_enables(unsigned char enables);
  736. int synaptics_rmi4_glove_mode_enables(struct synaptics_rmi4_data *rmi4_data);
  737. int synaptics_proximity_no_sleep_set(bool enables);
  738. int synaptics_rmi4_force_calibration(void);
  739. void ice40_fpga_firmware_update(struct synaptics_rmi4_data *rmi4_data);
  740. void fpga_enable(struct synaptics_rmi4_data *rmi4_data, int enable_clk);
  741. extern struct class *sec_class;
  742. extern int get_lcd_attached(void);
  743. static inline ssize_t synaptics_rmi4_show_error(struct device *dev,
  744. struct device_attribute *attr, char *buf)
  745. {
  746. dev_warn(dev, "%s Attempted to read from write-only attribute %s\n",
  747. __func__, attr->attr.name);
  748. return -EPERM;
  749. }
  750. static inline ssize_t synaptics_rmi4_store_error(struct device *dev,
  751. struct device_attribute *attr, const char *buf, size_t count)
  752. {
  753. dev_warn(dev, "%s Attempted to write to read-only attribute %s\n",
  754. __func__, attr->attr.name);
  755. return -EPERM;
  756. }
  757. static inline void batohs(unsigned short *dest, unsigned char *src)
  758. {
  759. *dest = src[1] * 0x100 + src[0];
  760. }
  761. static inline void hstoba(unsigned char *dest, unsigned short src)
  762. {
  763. dest[0] = src % 0x100;
  764. dest[1] = src / 0x100;
  765. }
  766. #endif