2 * Copyright (C) 2010, Imagis Technology Co. Ltd. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #ifndef __IST30XXC_H__
17 #define __IST30XXC_H__
19 #include <linux/input/tsp_ta_callback.h>
20 #ifdef CONFIG_INPUT_BOOSTER
21 #include <linux/input/input_booster.h>
25 * Support F/W ver : IST30xxC v1.0.0.0
26 * Support IC : IST3026C, IST3032C
27 * Release : 2015.01.05 by Hoony
30 #define USE_TSP_TA_CALLBACKS
32 #define IMAGIS_DD_VERSION ("2.0.0.0")
34 #define IMAGIS_IST3026C (1) /* 3026C */
35 #define IMAGIS_IST3032C (2) /* 3032C */
36 #define IMAGIS_IST3038C (3) /* 3038C */
37 #define IMAGIS_IST3044C (4) /* 3044C */
38 #define IMAGIS_IST3048C (5) /* 3048C */
40 #if defined(CONFIG_SEC_NOVEL_PROJECT)
41 #define IMAGIS_TSP_IC IMAGIS_IST3026C
43 #define IMAGIS_TSP_IC IMAGIS_IST3038C
47 #define FIRMWARE_PATH_LENGTH 64
48 #define FIRMWARE_PATH "tsp_imagis/"
51 #define TSP_CHIP_VENDOR ("IMAGIS")
53 #define IMAGIS_PROTOCOL_A (0xA)
54 #define IMAGIS_PROTOCOL_B (0xB)
55 #define IMAGIS_PROTOCOL_TYPE IMAGIS_PROTOCOL_B
57 #define IST30XXC_DEFAULT_CHIP_ID (0x300C)
58 #define IST3048C_DEFAULT_CHIP_ID (0x3048)
59 #if (IMAGIS_TSP_IC == IMAGIS_IST3026C)
60 #define TSP_CHIP_NAME ("IST3026C")
61 #define IST30XX_CHIP_ID (0x026C)
62 #define IST30XX_NODE_TOTAL_NUM (16 * 16)
63 #elif (IMAGIS_TSP_IC == IMAGIS_IST3032C)
64 #define TSP_CHIP_NAME ("IST3032C")
65 #define IST30XX_CHIP_ID (0x032C)
66 #define IST30XX_NODE_TOTAL_NUM (16 * 16)
67 #elif (IMAGIS_TSP_IC == IMAGIS_IST3038C)
68 #define TSP_CHIP_NAME ("IST3038C")
69 #define IST30XX_CHIP_ID (0x038C)
70 #define IST30XX_NODE_TOTAL_NUM (24 * 24)
71 #elif (IMAGIS_TSP_IC == IMAGIS_IST3044C)
72 #define TSP_CHIP_NAME ("IST3044C")
73 #define IST30XX_CHIP_ID (0x044C)
74 #define IST30XX_NODE_TOTAL_NUM (24 * 24)
75 #elif (IMAGIS_TSP_IC == IMAGIS_IST3048C)
76 #define TSP_CHIP_NAME ("IST3048C")
77 #define IST30XX_CHIP_ID (0x048C)
78 #define IST30XX_NODE_TOTAL_NUM (24 * 24)
80 #define TSP_CHIP_NAME ("IST30XXC")
81 #define IST30XX_CHIP_ID (0x300C)
82 #define IST30XX_NODE_TOTAL_NUM (24 * 24)
85 /* IST30XX FUNCTION ENABLE & DISABLE */
86 #define IST30XX_INTERNAL_BIN (1)
87 #define IST30XX_CHECK_CALIB (0)
88 #if IST30XX_INTERNAL_BIN
89 #if (IMAGIS_TSP_IC < IMAGIS_IST3038C)
90 #if defined(CONFIG_SEC_NOVEL_PROJECT)
91 #define IST30XX_MULTIPLE_TSP (1)
93 #define IST30XX_MULTIPLE_TSP (0)
96 #define IST30XX_UPDATE_BY_WORKQUEUE (0)
97 #define IST30XX_UPDATE_DELAY (3 * HZ)
100 #define IST30XX_EVENT_MODE (1)
101 #if IST30XX_EVENT_MODE
102 #define IST30XX_NOISE_MODE (1)
103 #define IST30XX_TRACKING_MODE (1)
104 #define IST30XX_ALGORITHM_MODE (1)
106 #define IST30XX_NOISE_MODE (0) /* fixed */
107 #define IST30XX_TRACKING_MODE (0) /* fixed */
108 #define IST30XX_ALGORITHM_MODE (0) /* fixed */
111 #define IST30XX_TA_RESET (1)
112 #define IST30XX_USE_KEY (0)
113 #define IST30XX_DEBUG (1)
114 #define IST30XX_CMCS_TEST (1)
115 #define IST30XX_CMCS_JIT_TEST (1)
116 #define IST30XX_GESTURE (0)
117 #define IST30XX_SURFACE_TOUCH (1)
118 #define IST30XX_BLADE_TOUCH (1)
119 #define IST30XX_STATUS_DEBUG (0)
121 #define SEC_FACTORY_MODE (1)
122 /* IST30XX FUNCTION ENABLE & DISABLE */
124 #define IST30XX_ADDR_LEN (4)
125 #define IST30XX_DATA_LEN (4)
127 #define IST30XX_MAX_MT_FINGERS (2)
128 #define IST30XX_MAX_KEYS (5)
130 #if defined(CONFIG_SEC_NOVEL_PROJECT)
131 #define IST30XX_MAX_X (480) /* LCD Resolution */
132 #define IST30XX_MAX_Y (800) /* LCD Resolution */
134 #define IST30XX_MAX_X (720) /* LCD Resolution */
135 #define IST30XX_MAX_Y (1280) /* LCD Resolution */
137 #define IST30XX_MAX_W (15)
139 #define IST30XX_EXCEPT_MASK (0xFFFFFF00)
140 #define IST30XX_EXCEPT_VALUE (0xE11CE900)
141 #define IST30XX_MAX_EXCEPT_SIZE (2)
143 #define IST30XX_JIG_TOUCH (0xC0)
144 #define IST30XX_ENABLE (1)
145 #define IST30XX_DISABLE (0)
148 #define IST30XX_MAX_RETRY_CNT (3)
151 #define TSP_LOCAL_EU (0)
152 #define TSP_LOCAL_EEU (1)
153 #define TSP_LOCAL_TD (11)
154 #define TSP_LOCAL_CMCC (12)
155 #define TSP_LOCAL_CU (13)
156 #define TSP_LOCAL_SPRD (14)
157 #define TSP_LOCAL_CTC (15)
158 #define TSP_LOCAL_INDIA (21)
159 #define TSP_LOCAL_SWASIA (22)
160 #define TSP_LOCAL_NA (31)
161 #define TSP_LOCAL_LA (32)
162 #define TSP_LOCAL_CODE TSP_LOCAL_EU
164 /* Factory Test for Reliability Test Group */
165 enum ist30xx_reliability_commands {
166 TEST_RAW_ALL_DATA = 0,
169 TEST_SLOPE0_ALL_DATA,
170 TEST_SLOPE1_ALL_DATA,
178 #define DEV_DEBUG (5)
181 #define IST30XX_DEBUG_TAG "[ TSP ]"
182 #define IST30XX_DEBUG_LEVEL DEV_NOTI
184 #define tsp_err(fmt, ...) tsp_printk(DEV_ERR, fmt, ## __VA_ARGS__)
185 #define tsp_warn(fmt, ...) tsp_printk(DEV_WARN, fmt, ## __VA_ARGS__)
186 #define tsp_info(fmt, ...) tsp_printk(DEV_DEBUG, fmt, ## __VA_ARGS__)
187 #define tsp_noti(fmt, ...) tsp_printk(DEV_NOTI, fmt, ## __VA_ARGS__)
188 #define tsp_debug(fmt, ...) tsp_printk(DEV_DEBUG, fmt, ## __VA_ARGS__)
189 #define tsp_verb(fmt, ...) tsp_printk(DEV_VERB, fmt, ## __VA_ARGS__)
192 /* I2C Device info */
193 #define IST30XX_DEV_NAME "IST30XX"
194 #define IST30XX_DEV_ID (0xA0 >> 1)
197 #define I2C_BURST_MODE (1)
198 #define I2C_MONOPOLY_MODE (0)
200 /* I2C transfer msg number */
201 #define WRITE_CMD_MSG_LEN (1)
202 #define READ_CMD_MSG_LEN (2)
204 /* I2C address/Data length */
205 #define IST30XX_ADDR_LEN (4) /* bytes */
206 #define IST30XX_DATA_LEN (4) /* bytes */
208 /* I2C transaction size */
209 #define I2C_MAX_WRITE_SIZE (0x0100) /* bytes */
210 #define I2C_MAX_READ_SIZE (0x0080) /* bytes */
212 /* I2C access mode */
213 #define IST30XX_DIRECT_ACCESS (1 << 31)
214 #define IST30XX_BURST_ACCESS (1 << 27)
215 #define IST30XX_HIB_ACCESS (0x800B << 16)
216 #define IST30XX_DA_ADDR(n) (n | IST30XX_DIRECT_ACCESS)
217 #define IST30XX_BA_ADDR(n) (n | IST30XX_BURST_ACCESS)
218 #define IST30XX_HA_ADDR(n) (n | IST30XX_HIB_ACCESS)
222 #define IST30XX_REG_CHIPID IST30XX_DA_ADDR(0x40001000)
223 #define IST30XX_REG_TSPTYPE IST30XX_DA_ADDR(0x40002010)
225 #define IST30XX_REG_XY_RES IST30XX_DA_ADDR(0x40)
226 #define IST30XX_REG_XY_SWAP IST30XX_DA_ADDR(0x5C)
230 #define IST30XX_HIB_BASE (0x30000100)
231 #define IST30XX_HIB_TOUCH_STATUS IST30XX_HA_ADDR(IST30XX_HIB_BASE | 0x00)
232 #define IST30XX_HIB_INTR_MSG IST30XX_HA_ADDR(IST30XX_HIB_BASE | 0x04)
233 #define IST30XX_HIB_COORD IST30XX_HA_ADDR(IST30XX_HIB_BASE | 0x08)
234 #define IST30XX_HIB_CMD IST30XX_HA_ADDR(IST30XX_HIB_BASE | 0x3C)
235 #define IST30XX_HIB_RW_STATUS IST30XX_HA_ADDR(IST30XX_HIB_BASE | 0x40)
237 /* interrupt macro */
238 #define IST30XX_INTR_STATUS (0x00000C00)
239 #define CHECK_INTR_STATUS(n) (((n & IST30XX_INTR_STATUS) == IST30XX_INTR_STATUS) ? 1 : 0)
240 #define PARSE_FINGER_CNT(n) ((n >> 12) & 0xF)
241 #define PARSE_KEY_CNT(n) ((n >> 21) & 0x7)
242 /* Finger status: [9:0] */
243 #define PARSE_FINGER_STATUS(n) (n & 0x3FF)
244 /* Key status: [20:16] */
245 #define PARSE_KEY_STATUS(n) ((n >> 16) & 0x1F)
246 #define PRESSED_FINGER(s, id) ((s & (1 << (id - 1))) ? true : false)
247 #define PRESSED_KEY(s, id) ((s & (1 << (16 + id - 1))) ? true : false)
249 #define IST30XX_MAX_CMD_SIZE (0x20)
250 #define IST30XX_CMD_ADDR(n) (n * 4)
251 #define IST30XX_CMD_VALUE(n) (n / 4)
252 enum ist30xx_read_commands {
253 eHCOM_GET_CHIP_ID = IST30XX_CMD_ADDR(0x00),
254 eHCOM_GET_VER_MAIN = IST30XX_CMD_ADDR(0x01),
255 eHCOM_GET_VER_FW = IST30XX_CMD_ADDR(0x02),
256 eHCOM_GET_VER_CORE = IST30XX_CMD_ADDR(0x03),
257 eHCOM_GET_VER_TEST = IST30XX_CMD_ADDR(0x04),
258 eHCOM_GET_CRC32 = IST30XX_CMD_ADDR(0x05),
259 eHCOM_GET_CRC32_ALL = IST30XX_CMD_ADDR(0x06),
260 eHCOM_GET_CAL_RESULT = IST30XX_CMD_ADDR(0x07),
261 eHCOM_GET_TSP_VENDOR = IST30XX_CMD_ADDR(0x08),
263 eHCOM_GET_LCD_INFO = IST30XX_CMD_ADDR(0x10),
264 eHCOM_GET_TSP_INFO = IST30XX_CMD_ADDR(0x11),
265 eHCOM_GET_KEY_INFO_0 = IST30XX_CMD_ADDR(0x12),
266 eHCOM_GET_KEY_INFO_1 = IST30XX_CMD_ADDR(0x13),
267 eHCOM_GET_KEY_INFO_2 = IST30XX_CMD_ADDR(0x14),
268 eHCOM_GET_SCR_INFO = IST30XX_CMD_ADDR(0x15),
269 eHCOM_GET_GTX_INFO = IST30XX_CMD_ADDR(0x16),
270 eHCOM_GET_SWAP_INFO = IST30XX_CMD_ADDR(0x17),
271 eHCOM_GET_FINGER_INFO = IST30XX_CMD_ADDR(0x18),
272 eHCOM_GET_BASELINE = IST30XX_CMD_ADDR(0x19),
273 eHCOM_GET_TOUCH_TH = IST30XX_CMD_ADDR(0x1A),
275 eHCOM_GET_ZVALUE_BASE = IST30XX_CMD_ADDR(0x1C),
276 eHCOM_GET_CDC_BASE = IST30XX_CMD_ADDR(0x1D),
277 eHCOM_GET_ALGO_BASE = IST30XX_CMD_ADDR(0x1E),
278 eHCOM_GET_COM_CHECKSUM = IST30XX_CMD_ADDR(0x1F),
281 enum ist30xx_write_commands {
282 eHCOM_FW_START = 0x01,
283 eHCOM_FW_HOLD = 0x02,
285 eHCOM_CP_CORRECT_EN = 0x10,
287 eHCOM_GESTURE_EN = 0x12,
288 eHCOM_SCALE_EN = 0x13,
289 eHCOM_NEW_POSITION_DIS = 0x14,
290 eHCOM_SLEEP_MODE_EN = 0x15,
292 eHCOM_SET_TIME_ACTIVE = 0x20,
293 eHCOM_SET_TIME_IDLE = 0x21,
294 eHCOM_SET_MODE_SPECIAL = 0x22,
295 eHCOM_SET_LOCAL_MODEL = 0x23,
297 eHCOM_RUN_RAMCODE = 0x30,
298 eHCOM_RUN_CAL_AUTO = 0x31,
299 eHCOM_RUN_CAL_PARAM = 0x32,
301 eHCOM_SET_JIG_MODE = 0x80,
302 eHCOM_SET_JIG_SENSITI = 0x81,
304 eHCOM_DEFAULT = 0xFF,
317 struct ist30xx_status {
328 struct ist30xx_version {
336 struct ist30xx_version prev;
337 struct ist30xx_version cur;
338 struct ist30xx_version bin;
346 #define IST30XX_TAG_MAGIC "ISTV2TAG"
347 struct ist30xx_tags {
389 struct ist30xx_platform_data {
395 struct regulator *avdd_regulator;
408 struct TSP_NODE_BUF {
409 u16 raw[IST30XX_NODE_TOTAL_NUM];
410 u16 base[IST30XX_NODE_TOTAL_NUM];
411 u16 filter[IST30XX_NODE_TOTAL_NUM];
419 struct TSP_DIRECTION {
425 typedef struct _TSP_INFO {
426 struct CH_NUM ch_num;
427 struct CH_NUM screen;
429 struct TSP_DIRECTION dir;
430 struct TSP_NODE_BUF node;
437 typedef struct _TKEY_INFO {
440 struct CH_NUM ch_num[IST30XX_MAX_KEYS];
445 #include <linux/i2c/ist30xxc_sec.h>
448 #ifdef CONFIG_HAS_EARLYSUSPEND
449 #include <linux/earlysuspend.h>
452 #ifdef USE_TSP_TA_CALLBACKS
453 extern struct tsp_callbacks *ist30xxc_charger_callbacks;
454 struct tsp_callbacks {
455 void (*inform_charger)(struct tsp_callbacks *, int);
459 struct ist30xx_dt_data {
466 const char *tsp_vdd_name;
467 struct regulator *tsp_power;
472 const char *ic_version;
473 const char *project_name;
474 const char *extra_string;
475 char fw_path[FIRMWARE_PATH_LENGTH];
476 char cmcs_path[FIRMWARE_PATH_LENGTH];
479 struct ist30xx_data {
480 struct i2c_client *client;
481 struct input_dev *input_dev;
482 struct ist30xx_dt_data *dt_data;
483 struct ist30xx_platform_data *pdata;
486 #ifdef CONFIG_HAS_EARLYSUSPEND
487 struct early_suspend early_suspend;
489 struct ist30xx_status status;
490 struct ist30xx_fw fw;
491 struct ist30xx_tags tags;
492 struct pinctrl *pinctrl;
494 struct sec_factory sec;
501 finger_info fingers[IST30XX_MAX_MT_FINGERS];
502 u32 lx[IST30XX_MAX_MT_FINGERS];
503 u32 ly[IST30XX_MAX_MT_FINGERS];
504 volatile bool irq_working;
510 u32 z_values[IST30XX_MAX_MT_FINGERS];
517 int touch_pressed_num;
518 #ifdef CONFIG_INPUT_BOOSTER
519 struct input_booster *tsp_booster;
532 struct delayed_work work_reset_check;
533 struct delayed_work work_noise_protect;
534 struct delayed_work work_debug_algorithm;
535 #if IST30XX_INTERNAL_BIN
536 #if IST30XX_UPDATE_BY_WORKQUEUE
537 struct delayed_work work_fw_update;
541 #ifdef USE_TSP_TA_CALLBACKS
542 struct tsp_callbacks callbacks;
544 #ifdef CONFIG_SLEEP_MONITOR
549 extern struct mutex ist30xx_mutex;
550 extern int ist30xx_dbg_level;
551 extern unsigned int system_rev;
553 void tsp_printk(int level, const char *fmt, ...);
554 int ist30xx_intr_wait(struct ist30xx_data *data, long ms);
556 void ist30xx_enable_irq(struct ist30xx_data *data);
557 void ist30xx_disable_irq(struct ist30xx_data *data);
558 void ist30xx_set_ta_mode(bool charging);
559 void ist30xx_set_edge_mode(int mode);
560 void ist30xx_set_cover_mode(int mode);
561 void ist30xx_start(struct ist30xx_data *data);
562 int ist30xx_get_ver_info(struct ist30xx_data *data);
564 int ist30xx_read_reg(struct i2c_client *client, u32 reg, u32 *buf);
565 int ist30xx_read_cmd(struct ist30xx_data *data, u32 cmd, u32 *buf);
566 int ist30xx_write_cmd(struct i2c_client *client, u32 cmd, u32 val);
567 int ist30xx_read_buf(struct i2c_client *client, u32 cmd, u32 *buf, u16 len);
568 int ist30xx_write_buf(struct i2c_client *client, u32 cmd, u32 *buf, u16 len);
569 int ist30xx_burst_read(struct i2c_client *client, u32 addr,
570 u32 *buf32, u16 len, bool bit_en);
571 int ist30xx_burst_write(struct i2c_client *client, u32 addr,
572 u32 *buf32, u16 len);
574 int ist30xx_cmd_start_scan(struct ist30xx_data *data);
575 int ist30xx_cmd_calibrate(struct i2c_client *client);
576 int ist30xx_cmd_check_calib(struct i2c_client *client);
577 int ist30xx_cmd_update(struct i2c_client *client, int cmd);
578 int ist30xx_cmd_hold(struct ist30xx_data *data, int enable);
580 int ist30xx_power_on(struct ist30xx_data *data, bool download);
581 int ist30xx_power_off(struct ist30xx_data *data);
582 int ist30xx_reset(struct ist30xx_data *data, bool download);
584 int ist30xx_internal_suspend(struct ist30xx_data *data);
585 int ist30xx_internal_resume(struct ist30xx_data *data);
587 int ist30xx_init_system(struct ist30xx_data *data);
589 extern struct class *ist30xx_class;
591 extern struct class *sec_class;
592 extern int sec_touch_sysfs(struct ist30xx_data *data);
593 extern int sec_fac_cmd_init(struct ist30xx_data *data);
594 extern void sec_fac_cmd_remove(struct ist30xx_data *data);
595 extern void sec_touch_sysfs_remove(struct ist30xx_data *data);
599 #endif /* __IST30XXC_H__ */