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_TRACKING_MODE (1)
104 #define IST30XX_TRACKING_MODE (0) /* fixed */
107 #define IST30XX_TA_RESET (1)
108 #define IST30XX_USE_KEY (0)
109 #define IST30XX_DEBUG (1)
110 #define IST30XX_CMCS_TEST (1)
111 #define IST30XX_CMCS_JIT_TEST (1)
112 #define IST30XX_GESTURE (0)
113 #define IST30XX_SURFACE_TOUCH (1)
114 #define IST30XX_BLADE_TOUCH (1)
115 #define IST30XX_STATUS_DEBUG (0)
117 #define SEC_FACTORY_MODE (1)
118 /* IST30XX FUNCTION ENABLE & DISABLE */
120 #define IST30XX_ADDR_LEN (4)
121 #define IST30XX_DATA_LEN (4)
123 #define IST30XX_MAX_MT_FINGERS (2)
124 #define IST30XX_MAX_KEYS (5)
126 #if defined(CONFIG_SEC_NOVEL_PROJECT)
127 #define IST30XX_MAX_X (480) /* LCD Resolution */
128 #define IST30XX_MAX_Y (800) /* LCD Resolution */
130 #define IST30XX_MAX_X (720) /* LCD Resolution */
131 #define IST30XX_MAX_Y (1280) /* LCD Resolution */
133 #define IST30XX_MAX_W (15)
135 #define IST30XX_EXCEPT_MASK (0xFFFFFF00)
136 #define IST30XX_EXCEPT_VALUE (0xE11CE900)
137 #define IST30XX_MAX_EXCEPT_SIZE (2)
139 #define IST30XX_JIG_TOUCH (0xC0)
140 #define IST30XX_ENABLE (1)
141 #define IST30XX_DISABLE (0)
144 #define IST30XX_MAX_RETRY_CNT (3)
147 #define TSP_LOCAL_EU (0)
148 #define TSP_LOCAL_EEU (1)
149 #define TSP_LOCAL_TD (11)
150 #define TSP_LOCAL_CMCC (12)
151 #define TSP_LOCAL_CU (13)
152 #define TSP_LOCAL_SPRD (14)
153 #define TSP_LOCAL_CTC (15)
154 #define TSP_LOCAL_INDIA (21)
155 #define TSP_LOCAL_SWASIA (22)
156 #define TSP_LOCAL_NA (31)
157 #define TSP_LOCAL_LA (32)
158 #define TSP_LOCAL_CODE TSP_LOCAL_EU
160 /* Factory Test for Reliability Test Group */
161 enum ist30xx_reliability_commands {
162 TEST_RAW_ALL_DATA = 0,
165 TEST_SLOPE0_ALL_DATA,
166 TEST_SLOPE1_ALL_DATA,
174 #define DEV_DEBUG (5)
177 #define IST30XX_DEBUG_TAG "[TSP]"
178 #define IST30XX_DEBUG_LEVEL DEV_NOTI
180 #define tsp_err(fmt, ...) tsp_printk(DEV_ERR, fmt, ## __VA_ARGS__)
181 #define tsp_warn(fmt, ...) tsp_printk(DEV_WARN, fmt, ## __VA_ARGS__)
182 #define tsp_info(fmt, ...) tsp_printk(DEV_DEBUG, fmt, ## __VA_ARGS__)
183 #define tsp_noti(fmt, ...) tsp_printk(DEV_NOTI, fmt, ## __VA_ARGS__)
184 #define tsp_debug(fmt, ...) tsp_printk(DEV_DEBUG, fmt, ## __VA_ARGS__)
185 #define tsp_verb(fmt, ...) tsp_printk(DEV_VERB, fmt, ## __VA_ARGS__)
188 /* I2C Device info */
189 #define IST30XX_DEV_NAME "IST30XX"
190 #define IST30XX_DEV_ID (0xA0 >> 1)
193 #define I2C_BURST_MODE (1)
194 #define I2C_MONOPOLY_MODE (0)
196 /* I2C transfer msg number */
197 #define WRITE_CMD_MSG_LEN (1)
198 #define READ_CMD_MSG_LEN (2)
200 /* I2C address/Data length */
201 #define IST30XX_ADDR_LEN (4) /* bytes */
202 #define IST30XX_DATA_LEN (4) /* bytes */
204 /* I2C transaction size */
205 #define I2C_MAX_WRITE_SIZE (0x0100) /* bytes */
206 #define I2C_MAX_READ_SIZE (0x0080) /* bytes */
208 /* I2C access mode */
209 #define IST30XX_DIRECT_ACCESS (1 << 31)
210 #define IST30XX_BURST_ACCESS (1 << 27)
211 #define IST30XX_HIB_ACCESS (0x800B << 16)
212 #define IST30XX_DA_ADDR(n) (n | IST30XX_DIRECT_ACCESS)
213 #define IST30XX_BA_ADDR(n) (n | IST30XX_BURST_ACCESS)
214 #define IST30XX_HA_ADDR(n) (n | IST30XX_HIB_ACCESS)
218 #define IST30XX_REG_CHIPID IST30XX_DA_ADDR(0x40001000)
219 #define IST30XX_REG_TSPTYPE IST30XX_DA_ADDR(0x40002010)
221 #define IST30XX_REG_XY_RES IST30XX_DA_ADDR(0x40)
222 #define IST30XX_REG_XY_SWAP IST30XX_DA_ADDR(0x5C)
226 #define IST30XX_HIB_BASE (0x30000100)
227 #define IST30XX_HIB_TOUCH_STATUS IST30XX_HA_ADDR(IST30XX_HIB_BASE | 0x00)
228 #define IST30XX_HIB_INTR_MSG IST30XX_HA_ADDR(IST30XX_HIB_BASE | 0x04)
229 #define IST30XX_HIB_COORD IST30XX_HA_ADDR(IST30XX_HIB_BASE | 0x08)
230 #define IST30XX_HIB_CMD IST30XX_HA_ADDR(IST30XX_HIB_BASE | 0x3C)
231 #define IST30XX_HIB_RW_STATUS IST30XX_HA_ADDR(IST30XX_HIB_BASE | 0x40)
233 /* interrupt macro */
234 #define IST30XX_INTR_STATUS (0x00000C00)
235 #define CHECK_INTR_STATUS(n) (((n & IST30XX_INTR_STATUS) == IST30XX_INTR_STATUS) ? 1 : 0)
236 #define PARSE_FINGER_CNT(n) ((n >> 12) & 0xF)
237 #define PARSE_KEY_CNT(n) ((n >> 21) & 0x7)
238 /* Finger status: [9:0] */
239 #define PARSE_FINGER_STATUS(n) (n & 0x3FF)
240 /* Key status: [20:16] */
241 #define PARSE_KEY_STATUS(n) ((n >> 16) & 0x1F)
242 #define PRESSED_FINGER(s, id) ((s & (1 << (id - 1))) ? true : false)
243 #define PRESSED_KEY(s, id) ((s & (1 << (16 + id - 1))) ? true : false)
245 #define IST30XX_MAX_CMD_SIZE (0x20)
246 #define IST30XX_CMD_ADDR(n) (n * 4)
247 #define IST30XX_CMD_VALUE(n) (n / 4)
248 enum ist30xx_read_commands {
249 eHCOM_GET_CHIP_ID = IST30XX_CMD_ADDR(0x00),
250 eHCOM_GET_VER_MAIN = IST30XX_CMD_ADDR(0x01),
251 eHCOM_GET_VER_FW = IST30XX_CMD_ADDR(0x02),
252 eHCOM_GET_VER_CORE = IST30XX_CMD_ADDR(0x03),
253 eHCOM_GET_VER_TEST = IST30XX_CMD_ADDR(0x04),
254 eHCOM_GET_CRC32 = IST30XX_CMD_ADDR(0x05),
255 eHCOM_GET_CRC32_ALL = IST30XX_CMD_ADDR(0x06),
256 eHCOM_GET_CAL_RESULT = IST30XX_CMD_ADDR(0x07),
257 eHCOM_GET_TSP_VENDOR = IST30XX_CMD_ADDR(0x08),
259 eHCOM_GET_LCD_INFO = IST30XX_CMD_ADDR(0x10),
260 eHCOM_GET_TSP_INFO = IST30XX_CMD_ADDR(0x11),
261 eHCOM_GET_KEY_INFO_0 = IST30XX_CMD_ADDR(0x12),
262 eHCOM_GET_KEY_INFO_1 = IST30XX_CMD_ADDR(0x13),
263 eHCOM_GET_KEY_INFO_2 = IST30XX_CMD_ADDR(0x14),
264 eHCOM_GET_SCR_INFO = IST30XX_CMD_ADDR(0x15),
265 eHCOM_GET_GTX_INFO = IST30XX_CMD_ADDR(0x16),
266 eHCOM_GET_SWAP_INFO = IST30XX_CMD_ADDR(0x17),
267 eHCOM_GET_FINGER_INFO = IST30XX_CMD_ADDR(0x18),
268 eHCOM_GET_BASELINE = IST30XX_CMD_ADDR(0x19),
269 eHCOM_GET_TOUCH_TH = IST30XX_CMD_ADDR(0x1A),
271 eHCOM_GET_ZVALUE_BASE = IST30XX_CMD_ADDR(0x1C),
272 eHCOM_GET_CDC_BASE = IST30XX_CMD_ADDR(0x1D),
273 eHCOM_GET_ALGO_BASE = IST30XX_CMD_ADDR(0x1E),
274 eHCOM_GET_COM_CHECKSUM = IST30XX_CMD_ADDR(0x1F),
277 enum ist30xx_write_commands {
278 eHCOM_FW_START = 0x01,
279 eHCOM_FW_HOLD = 0x02,
281 eHCOM_CP_CORRECT_EN = 0x10,
283 eHCOM_GESTURE_EN = 0x12,
284 eHCOM_SCALE_EN = 0x13,
285 eHCOM_NEW_POSITION_DIS = 0x14,
286 eHCOM_SLEEP_MODE_EN = 0x15,
288 eHCOM_SET_TIME_ACTIVE = 0x20,
289 eHCOM_SET_TIME_IDLE = 0x21,
290 eHCOM_SET_MODE_SPECIAL = 0x22,
291 eHCOM_SET_LOCAL_MODEL = 0x23,
293 eHCOM_RUN_RAMCODE = 0x30,
294 eHCOM_RUN_CAL_AUTO = 0x31,
295 eHCOM_RUN_CAL_PARAM = 0x32,
297 eHCOM_SET_JIG_MODE = 0x80,
298 eHCOM_SET_JIG_SENSITI = 0x81,
300 eHCOM_DEFAULT = 0xFF,
313 struct ist30xx_status {
324 struct ist30xx_version {
332 struct ist30xx_version prev;
333 struct ist30xx_version cur;
334 struct ist30xx_version bin;
342 #define IST30XX_TAG_MAGIC "ISTV2TAG"
343 struct ist30xx_tags {
385 struct ist30xx_platform_data {
391 struct regulator *avdd_regulator;
404 struct TSP_NODE_BUF {
405 u16 raw[IST30XX_NODE_TOTAL_NUM];
406 u16 base[IST30XX_NODE_TOTAL_NUM];
407 u16 filter[IST30XX_NODE_TOTAL_NUM];
415 struct TSP_DIRECTION {
421 typedef struct _TSP_INFO {
422 struct CH_NUM ch_num;
423 struct CH_NUM screen;
425 struct TSP_DIRECTION dir;
426 struct TSP_NODE_BUF node;
433 typedef struct _TKEY_INFO {
436 struct CH_NUM ch_num[IST30XX_MAX_KEYS];
441 #include <linux/i2c/ist30xxc_sec.h>
444 #ifdef CONFIG_HAS_EARLYSUSPEND
445 #include <linux/earlysuspend.h>
448 #ifdef USE_TSP_TA_CALLBACKS
449 extern struct tsp_callbacks *ist30xxc_charger_callbacks;
450 struct tsp_callbacks {
451 void (*inform_charger)(struct tsp_callbacks *, int);
455 struct ist30xx_dt_data {
462 const char *tsp_vdd_name;
463 struct regulator *tsp_power;
468 const char *ic_version;
469 const char *project_name;
470 const char *extra_string;
471 char fw_path[FIRMWARE_PATH_LENGTH];
472 char cmcs_path[FIRMWARE_PATH_LENGTH];
475 struct ist30xx_data {
476 struct i2c_client *client;
477 struct input_dev *input_dev;
478 struct ist30xx_dt_data *dt_data;
479 struct ist30xx_platform_data *pdata;
482 #ifdef CONFIG_HAS_EARLYSUSPEND
483 struct early_suspend early_suspend;
485 struct ist30xx_status status;
486 struct ist30xx_fw fw;
487 struct ist30xx_tags tags;
488 struct pinctrl *pinctrl;
490 struct sec_factory sec;
497 finger_info fingers[IST30XX_MAX_MT_FINGERS];
498 u32 lx[IST30XX_MAX_MT_FINGERS];
499 u32 ly[IST30XX_MAX_MT_FINGERS];
500 bool tsp_touched[IST30XX_MAX_MT_FINGERS];
501 u32 press_cnt[IST30XX_MAX_MT_FINGERS];
502 volatile bool irq_working;
508 u32 z_values[IST30XX_MAX_MT_FINGERS];
515 int touch_pressed_num;
516 #ifdef CONFIG_INPUT_BOOSTER
517 struct input_booster *tsp_booster;
529 u16 press_finger_cnt;
531 struct delayed_work work_reset_check;
532 #if IST30XX_INTERNAL_BIN
533 #if IST30XX_UPDATE_BY_WORKQUEUE
534 struct delayed_work work_fw_update;
538 #ifdef USE_TSP_TA_CALLBACKS
539 struct tsp_callbacks callbacks;
541 #ifdef CONFIG_SLEEP_MONITOR
546 extern struct mutex ist30xx_mutex;
547 extern int ist30xx_dbg_level;
548 extern unsigned int system_rev;
550 void tsp_printk(int level, const char *fmt, ...);
551 int ist30xx_intr_wait(struct ist30xx_data *data, long ms);
553 void ist30xx_enable_irq(struct ist30xx_data *data);
554 void ist30xx_disable_irq(struct ist30xx_data *data);
555 void ist30xx_set_ta_mode(bool charging);
556 void ist30xx_set_edge_mode(int mode);
557 void ist30xx_set_cover_mode(int mode);
558 void ist30xx_start(struct ist30xx_data *data);
559 int ist30xx_get_ver_info(struct ist30xx_data *data);
561 int ist30xx_read_reg(struct i2c_client *client, u32 reg, u32 *buf);
562 int ist30xx_read_cmd(struct ist30xx_data *data, u32 cmd, u32 *buf);
563 int ist30xx_write_cmd(struct i2c_client *client, u32 cmd, u32 val);
564 int ist30xx_read_buf(struct i2c_client *client, u32 cmd, u32 *buf, u16 len);
565 int ist30xx_write_buf(struct i2c_client *client, u32 cmd, u32 *buf, u16 len);
566 int ist30xx_burst_read(struct i2c_client *client, u32 addr,
567 u32 *buf32, u16 len, bool bit_en);
568 int ist30xx_burst_write(struct i2c_client *client, u32 addr,
569 u32 *buf32, u16 len);
571 int ist30xx_cmd_start_scan(struct ist30xx_data *data);
572 int ist30xx_cmd_calibrate(struct i2c_client *client);
573 int ist30xx_cmd_check_calib(struct i2c_client *client);
574 int ist30xx_cmd_update(struct i2c_client *client, int cmd);
575 int ist30xx_cmd_hold(struct ist30xx_data *data, int enable);
577 int ist30xx_power_on(struct ist30xx_data *data, bool download);
578 int ist30xx_power_off(struct ist30xx_data *data);
579 int ist30xx_reset(struct ist30xx_data *data, bool download);
581 int ist30xx_internal_suspend(struct ist30xx_data *data);
582 int ist30xx_internal_resume(struct ist30xx_data *data);
584 int ist30xx_init_system(struct ist30xx_data *data);
586 extern struct class *ist30xx_class;
588 extern struct class *sec_class;
589 extern int sec_touch_sysfs(struct ist30xx_data *data);
590 extern int sec_fac_cmd_init(struct ist30xx_data *data);
591 extern void sec_fac_cmd_remove(struct ist30xx_data *data);
592 extern void sec_touch_sysfs_remove(struct ist30xx_data *data);
596 #endif /* __IST30XXC_H__ */