import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / input / touchscreen / mediatek / synaptics_7020 / synaptics_ts.h
1 /*
2 * Copyright (C) 2013 LG Electironics, Inc.
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
15
16 #define MAX_NUM_OF_BUTTON 4
17 #define MAX_NUM_OF_FINGER 10
18 #define DESCRIPTION_TABLE_START 0xE9
19 #define PAGE_SELECT_REG 0xFF
20 #define PAGE_MAX_NUM 4
21
22 #define REG_X_POSITION 0
23 #define REG_Y_POSITION 1
24 #define REG_YX_POSITION 2
25 #define REG_WY_WX 3
26 #define REG_Z 4
27 #define NUM_OF_EACH_FINGER_DATA_REG 5
28
29 /* Define for Area based key button */
30 #define BUTTON_MARGIN 50
31 #define TOUCH_BUTTON_PRESSED 2
32
33 /* Debug Mask setting */
34 #define SYNAPTICS_RMI4_I2C_DEBUG_PRINT 1
35 #define SYNAPTICS_RMI4_I2C_ERROR_PRINT 1
36 #define SYNAPTICS_RMI4_I2C_INFO_PRINT 1
37
38 #if defined(SYNAPTICS_RMI4_I2C_INFO_PRINT)
39 #define SYNAPTICS_INFO_MSG(fmt, args...) printk(KERN_ERR "[Touch] " fmt, ##args);
40 #else
41 #define SYNAPTICS_INFO_MSG(fmt, args...) {};
42 #endif
43
44 #if defined(SYNAPTICS_RMI4_I2C_DEBUG_PRINT)
45 #define SYNAPTICS_DEBUG_MSG(fmt, args...) printk(KERN_ERR "[Touch D] [%s %d] " fmt, __FUNCTION__, __LINE__, ##args);
46 #else
47 #define SYNAPTICS_DEBUG_MSG(fmt, args...) {};
48 #endif
49
50 #if defined(SYNAPTICS_RMI4_I2C_ERROR_PRINT)
51 #define SYNAPTICS_ERR_MSG(fmt, args...) printk(KERN_ERR "[Touch E] [%s %d] " fmt, __FUNCTION__, __LINE__, ##args);
52 #else
53 #define SYNAPTICS_ERR_MSG(fmt, args...) {};
54 #endif
55
56
57 enum {
58 SYNAPTICS_RMI4_I2C_DEBUG_NONE = 0,
59 SYNAPTICS_RMI4_I2C_DEBUG_FUNC_TRACE = 1U << 0, /* 1 */
60 SYNAPTICS_RMI4_I2C_DEBUG_INT_STATUS = 1U << 1, /* 2 */
61 SYNAPTICS_RMI4_I2C_DEBUG_FINGER_STATUS = 1U << 2, /* 4 */
62 SYNAPTICS_RMI4_I2C_DEBUG_FINGER_POSITION = 1U << 3, /* 8 */
63 SYNAPTICS_RMI4_I2C_DEBUG_FINGER_REG = 1U << 4, /* 16 */
64 SYNAPTICS_RMI4_I2C_DEBUG_BUTTON_STATUS = 1U << 5, /* 32 */
65 SYNAPTICS_RMI4_I2C_DEBUG_BUTTON_REG = 1U << 6, /* 64 */
66 SYNAPTICS_RMI4_I2C_DEBUG_INT_INTERVAL = 1U << 7, /* 128 */
67 SYNAPTICS_RMI4_I2C_DEBUG_INT_ISR_DELAY = 1U << 8, /* 256 */
68 SYNAPTICS_RMI4_I2C_DEBUG_FINGER_HANDLE_TIME = 1U << 9, /* 512 */
69 SYNAPTICS_RMI4_I2C_DEBUG_BUTTON_HANDLE_TIME = 1U << 10, /* 1024 */
70 SYNAPTICS_RMI4_I2C_DEBUG_UPGRADE_DELAY = 1U << 11, /* 2048 */
71 };
72
73 enum {
74 IC_CTRL_CODE_NONE = 0,
75 IC_CTRL_BASELINE,
76 IC_CTRL_READ,
77 IC_CTRL_WRITE,
78 IC_CTRL_RESET_CMD,
79 IC_CTRL_REPORT_MODE,
80 };
81
82 enum {
83 BASELINE_OPEN = 0,
84 BASELINE_FIX,
85 BASELINE_REBASE,
86 };
87
88 enum {
89 TIME_EX_INIT_TIME,
90 TIME_EX_FIRST_INT_TIME,
91 TIME_EX_PREV_PRESS_TIME,
92 TIME_EX_CURR_PRESS_TIME,
93 TIME_EX_BUTTON_PRESS_START_TIME,
94 TIME_EX_BUTTON_PRESS_END_TIME,
95 TIME_EX_FIRST_GHOST_DETECT_TIME,
96 TIME_EX_SECOND_GHOST_DETECT_TIME,
97 TIME_EX_CURR_INT_TIME,
98 TIME_EX_PROFILE_MAX
99 };
100
101 enum{
102 IGNORE_INTERRUPT = 100,
103 NEED_TO_OUT,
104 NEED_TO_INIT,
105 };
106
107
108 struct synaptics_ts_platform_data {
109 bool use_irq;
110 unsigned long irqflags;
111 unsigned short irq_num;
112 //jhee//unsigned short int_gpio;
113 unsigned int int_gpio;
114 //jhee//unsigned short reset_gpio;
115 unsigned int reset_gpio;
116 int (*power)(int on);
117 unsigned short ic_booting_delay; /* ms */
118 unsigned long report_period; /* ns */
119 unsigned char num_of_finger;
120 unsigned char num_of_button;
121 unsigned short button[MAX_NUM_OF_BUTTON];
122 int x_max;
123 int y_max;
124 unsigned char fw_ver;
125 unsigned int palm_threshold;
126 unsigned int delta_pos_threshold;
127 int use_ghost_detection;
128 int report_mode;
129 };
130
131 typedef struct {
132 u8 query_base;
133 u8 command_base;
134 u8 control_base;
135 u8 data_base;
136 u8 int_source_count;
137 u8 id;
138 } ts_function_descriptor;
139
140 typedef struct {
141 unsigned int pos_x[MAX_NUM_OF_FINGER];
142 unsigned int pos_y[MAX_NUM_OF_FINGER];
143 unsigned char pressure[MAX_NUM_OF_FINGER];
144 int total_num;
145 char palm;
146 } ts_finger_data;
147
148 struct synaptics_ts_timestamp {
149 u64 start;
150 u64 end;
151 u64 result_t;
152 unsigned long rem;
153 atomic_t ready;
154 };
155
156 /* Device data structure */
157 struct synaptics_ts_data {
158 struct i2c_client *client;
159 struct input_dev *input_dev;
160 struct synaptics_ts_platform_data *pdata;
161 bool is_downloading; /* avoid power off during F/W upgrade */
162 bool is_suspended; /* avoid power off during F/W upgrade */
163 unsigned int button_width;
164 char button_prestate[MAX_NUM_OF_BUTTON];
165 char finger_prestate[MAX_NUM_OF_FINGER];
166 bool ic_init;
167 bool is_probed;
168 atomic_t interrupt_handled;
169 ts_function_descriptor common_dsc;
170 ts_function_descriptor finger_dsc;
171 ts_function_descriptor button_dsc;
172 ts_function_descriptor analog_dsc;
173 ts_function_descriptor flash_dsc;
174 u8 common_page;
175 u8 finger_page;
176 u8 button_page;
177 u8 analog_page;
178 u8 flash_page;
179 unsigned char int_status_reg_asb0_bit;
180 unsigned char int_status_reg_button_bit;
181 unsigned char curr_int_mask;
182 struct hrtimer timer;
183 struct delayed_work work;
184 struct delayed_work button_lock_work;
185 struct synaptics_ts_timestamp int_delay;
186 ts_finger_data pre_ts_data;
187 char fw_rev;
188 char manufcturer_id;
189 char config_id[5];
190 char product_id[11];
191 char fw_path[256];
192 unsigned char *fw_start;
193 unsigned long fw_size;
194 char fw_config_id[5];
195 char fw_product_id[11];
196 bool fw_force_upgrade;
197 };
198
199 typedef struct {
200 unsigned char device_status_reg;
201 unsigned char interrupt_status_reg;
202 unsigned char button_data_reg;
203 } ts_sensor_ctrl;
204
205 typedef struct {
206 unsigned char finger_state_reg[3];
207 unsigned char finger_data[MAX_NUM_OF_FINGER][NUM_OF_EACH_FINGER_DATA_REG];
208 } ts_sensor_data;
209