blob: 5e12bc9d4f580e8beee936dfdc929549ce075567 [file] [log] [blame]
tracychui35151622020-04-29 16:24:36 +08001/* Himax Android Driver Sample Code for common functions
2*
3* Copyright (C) 2017 Himax Corporation.
4*
5* This software is licensed under the terms of the GNU General Public
6* License version 2, as published by the Free Software Foundation, and
7* may be copied, distributed, and modified under those terms.
8*
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.
13*
14*/
15
16#ifndef HIMAX_COMMON_H
17#define HIMAX_COMMON_H
18
19#include <asm/segment.h>
20#include <asm/uaccess.h>
21#include <asm/atomic.h>
22
23#include <linux/delay.h>
24#include <linux/i2c.h>
25#include <linux/input.h>
26#include <linux/interrupt.h>
27#include <linux/module.h>
28#include <linux/async.h>
29#include <linux/platform_device.h>
30#include <linux/slab.h>
31#include <linux/gpio.h>
32#include <linux/input/mt.h>
33#include <linux/firmware.h>
34#include <linux/types.h>
35#include <linux/fs.h>
36#include <linux/buffer_head.h>
37//#include <linux/wakelock.h>
38#include <linux/pm_wakeup.h>
39#include <linux/seq_file.h>
40#include <linux/proc_fs.h>
41#include "himax_platform.h"
42#include <linux/file.h>
43#if defined(CONFIG_FB)
44#include <linux/notifier.h>
45#include <linux/fb.h>
46#include <linux/mutex.h>
47#elif defined(CONFIG_HAS_EARLYSUSPEND)
48#include <linux/earlysuspend.h>
49#endif
50
51#ifdef CONFIG_OF
52#include <linux/of_gpio.h>
53#endif
54//#define HIMAX_DRIVER_VER "0.1.95.0_ABCD1234_01"
55#define HIMAX_DRIVER_VER "1.2.2.69_ABCD1234_01"
56
57#define FLASH_DUMP_FILE "/sdcard/HX_Flash_Dump.bin"
58
59#if defined(CONFIG_TOUCHSCREEN_HIMAX_DEBUG)
60
61#define HX_TP_PROC_DIAG
62#define HX_TP_PROC_REGISTER
63#define HX_TP_PROC_DEBUG
64#define HX_TP_PROC_FLASH_DUMP
65#define HX_TP_PROC_SELF_TEST
66#define HX_TP_PROC_RESET
67#define HX_TP_PROC_SENSE_ON_OFF
68#define HX_TP_PROC_2T2R
69
70#ifdef HX_TP_PROC_SELF_TEST
71//#define HX_TP_SELF_TEST_DRIVER //if enable, selftest works in driver
72#endif
73
74int himax_touch_proc_init(void);
75void himax_touch_proc_deinit(void);
76#endif
77//===========Himax Option function=============
78#define HX_RST_PIN_FUNC
79#define HX_AUTO_UPDATE_FW
80//#define HX_ESD_RECOVERY
81//#define HX_CHIP_STATUS_MONITOR /*for ESD 2nd solution,it does not support incell,default off*/
82//#define HX_SMART_WAKEUP
83//#define HX_GESTURE_TRACK
84//#define HX_HIGH_SENSE
85//#define HX_PALM_REPORT
86#define HX_USB_DETECT_GLOBAL
87//#define HX_USB_DETECT_CALLBACK
88//#define HX_PROTOCOL_A /* for MTK special platform.If turning on,it will report to system by using specific format. */
89//#define HX_RESUME_HW_RESET
90//#define HX_RESUME_SEND_CMD
91#define HX_PROTOCOL_B_3PA
92#define HX_FIX_TOUCH_INFO /* if open, you need to change the touch info in the fix_touch_info*/
93//#define HX_EN_SEL_BUTTON /* Support Self Virtual key ,default is close*/
94//#define HX_EN_MUT_BUTTON /* Support Mutual Virtual Key ,default is close*/
95
96#if defined(HX_EN_SEL_BUTTON) || defined(HX_EN_MUT_BUTTON)
97//#define HX_PLATFOME_DEFINE_KEY /* for specfic platform to set key(button) */
98#endif
99
100#ifdef HX_USB_DETECT_GLOBAL
101#define POWER_SUPPLY_BATTERY_STATUS_PATCH "/sys/class/power_supply/battery/status"
102#endif
103
104#define HX_KEY_MAX_COUNT 4
105#define DEFAULT_RETRY_CNT 3
106
107#define HX_85XX_A_SERIES_PWON 1
108#define HX_85XX_B_SERIES_PWON 2
109#define HX_85XX_C_SERIES_PWON 3
110#define HX_85XX_D_SERIES_PWON 4
111#define HX_85XX_E_SERIES_PWON 5
112#define HX_85XX_ES_SERIES_PWON 6
113#define HX_85XX_F_SERIES_PWON 7
114#define HX_85XX_G_SERIES_PWON 8
115#define HX_85XX_H_SERIES_PWON 9
116#define HX_83100A_SERIES_PWON 10
117#define HX_83102A_SERIES_PWON 11
118#define HX_83102B_SERIES_PWON 12
119#define HX_83110A_SERIES_PWON 13
120#define HX_83110B_SERIES_PWON 14
121#define HX_83111B_SERIES_PWON 15
122#define HX_83112A_SERIES_PWON 16
123#define HX_83112B_SERIES_PWON 17
124
125#define HX_TP_BIN_CHECKSUM_SW 1
126#define HX_TP_BIN_CHECKSUM_HW 2
127#define HX_TP_BIN_CHECKSUM_CRC 3
128
129#define SHIFTBITS 5
130
131#define FW_SIZE_32k 32768
132#define FW_SIZE_60k 61440
133#define FW_SIZE_64k 65536
134#define FW_SIZE_124k 126976
135#define FW_SIZE_128k 131072
136
137#define NO_ERR 0
138#define READY_TO_SERVE 1
139#define WORK_OUT 2
140#define I2C_FAIL -1
141#define MEM_ALLOC_FAIL -2
142#define CHECKSUM_FAIL -3
143#define GESTURE_DETECT_FAIL -4
144#define INPUT_REGISTER_FAIL -5
145#define FW_NOT_READY -6
146#define LENGTH_FAIL -7
147#define OPEN_FILE_FAIL -8
148#define ERR_WORK_OUT -10
149
150#define HX_FINGER_ON 1
151#define HX_FINGER_LEAVE 2
152
153#define HX_REPORT_COORD 1
154#define HX_REPORT_SMWP_EVENT 2
155#ifdef HX_FIX_TOUCH_INFO
156enum fix_touch_info
157{
158 FIX_HX_RX_NUM = 30,
159 FIX_HX_TX_NUM = 18,
160 FIX_HX_BT_NUM = 0,
161 FIX_HX_X_RES = 1080,
162 FIX_HX_Y_RES = 2160,
163 FIX_HX_MAX_PT = 10,
164 FIX_HX_XY_REVERSE = true,
165 FIX_HX_INT_IS_EDGE = false,
166#ifdef HX_TP_PROC_2T2R
167 FIX_HX_RX_NUM_2 = 0,
168 FIX_HX_TX_NUM_2 = 0,
169#endif
170 SEC_FIX_HX_RX_NUM = 36,
171 SEC_FIX_HX_TX_NUM = 18,
172 SEC_FIX_HX_BT_NUM = 0,
173 SEC_FIX_HX_X_RES = 1080,
174 SEC_FIX_HX_Y_RES = 2160,
175 SEC_FIX_HX_MAX_PT = 10,
176 SEC_FIX_HX_XY_REVERSE = true,
177 SEC_FIX_HX_INT_IS_EDGE = false,
178#ifdef HX_TP_PROC_2T2R
179 SEC_FIX_HX_RX_NUM_2 = 0,
180 SEC_FIX_HX_TX_NUM_2 = 0
181#endif
182};
183#endif
184#ifdef HX_ZERO_FLASH
185#define HX_0F_DEBUG
186#endif
187
188struct himax_ic_data
189{
190 int vendor_fw_ver;
191 int vendor_config_ver;
192 int vendor_touch_cfg_ver;
193 int vendor_display_cfg_ver;
194 int vendor_cid_maj_ver;
195 int vendor_cid_min_ver;
196 int vendor_panel_ver;
197 int vendor_sensor_id;
198 int vendor_hx_ic_id;
199 int HX_RX_NUM;
200 int HX_TX_NUM;
201 int HX_BT_NUM;
202 int HX_X_RES;
203 int HX_Y_RES;
204 int HX_MAX_PT;
205 bool HX_XY_REVERSE;
206 bool HX_INT_IS_EDGE;
207#ifdef HX_TP_PROC_2T2R
208 int HX_RX_NUM_2;
209 int HX_TX_NUM_2;
210#endif
211};
212
213struct himax_virtual_key
214{
215 int index;
216 int keycode;
217 int x_range_min;
218 int x_range_max;
219 int y_range_min;
220 int y_range_max;
221};
222
223struct himax_report_data
224{
225 int touch_all_size;
226 int raw_cnt_max;
227 int raw_cnt_rmd;
228 int touch_info_size;
229 uint8_t finger_num;
230 uint8_t finger_on;
231 uint8_t *hx_coord_buf;
232 uint8_t hx_state_info[2];
233#if defined(HX_SMART_WAKEUP)
234 int event_size;
235 uint8_t *hx_event_buf;
236#endif
237#if defined(HX_TP_PROC_DIAG)
238 int rawdata_size;
239 uint8_t diag_cmd;
240 uint8_t *hx_rawdata_buf;
241 uint8_t rawdata_frame_size;
242#endif
243};
244
245struct himax_ts_data
246{
247 bool suspended;
248 atomic_t suspend_mode;
249 uint8_t x_channel;
250 uint8_t y_channel;
251 uint8_t useScreenRes;
252 uint8_t diag_command;
253
254 uint8_t protocol_type;
255 uint8_t first_pressed;
256 uint8_t coord_data_size;
257 uint8_t area_data_size;
258 uint8_t coordInfoSize;
259 uint8_t raw_data_frame_size;
260 uint8_t raw_data_nframes;
261 uint8_t nFinger_support;
262 uint8_t irq_enabled;
263 uint8_t diag_self[50];
264
265 uint16_t finger_pressed;
266 uint16_t last_slot;
267 uint16_t pre_finger_mask;
268
269 uint32_t debug_log_level;
270 uint32_t widthFactor;
271 uint32_t heightFactor;
272 uint32_t tw_x_min;
273 uint32_t tw_x_max;
274 uint32_t tw_y_min;
275 uint32_t tw_y_max;
276 uint32_t pl_x_min;
277 uint32_t pl_x_max;
278 uint32_t pl_y_min;
279 uint32_t pl_y_max;
280
281 int rst_gpio;
282 int use_irq;
283 int (*power)(int on);
284 int pre_finger_data[10][2];
285
286 struct device *dev;
287 struct workqueue_struct *himax_wq;
288 struct work_struct work;
289 struct input_dev *input_dev;
290 struct hrtimer timer;
291 struct i2c_client *client;
292 struct himax_i2c_platform_data *pdata;
293 struct himax_virtual_key *button;
294 struct mutex rw_lock;
295 struct mutex report_mutex;
296
297#if defined(CONFIG_FB)
298 struct notifier_block fb_notif;
299 struct workqueue_struct *himax_att_wq;
300 struct delayed_work work_att;
301 struct mutex ops_lock;
302#elif defined(CONFIG_HAS_EARLYSUSPEND)
303 struct early_suspend early_suspend;
304#endif
305#ifdef HX_CHIP_STATUS_MONITOR
306 struct workqueue_struct *himax_chip_monitor_wq;
307 struct delayed_work himax_chip_monitor;
308#endif
309#ifdef HX_TP_PROC_FLASH_DUMP
310 struct workqueue_struct *flash_wq;
311 struct work_struct flash_work;
312#endif
313
314#ifdef HX_AUTO_UPDATE_FW
315 struct workqueue_struct *himax_update_wq;
316 struct delayed_work work_update;
317#endif
318
319#ifdef HX_ZERO_FLASH
320 struct workqueue_struct *himax_0f_update_wq;
321 struct delayed_work work_0f_update;
322#endif
323
324#ifdef HX_TP_PROC_DIAG
325 struct workqueue_struct *himax_diag_wq;
326 struct delayed_work himax_diag_delay_wrok;
327#endif
328
329#ifdef HX_SMART_WAKEUP
330 uint8_t SMWP_enable;
331 uint8_t gesture_cust_en[16];
332 //struct wake_lock ts_SMWP_wake_lock;
333 struct wakeup_source ts_SMWP_wake_lock;
334#endif
335
336#ifdef HX_HIGH_SENSE
337 uint8_t HSEN_enable;
338#endif
339
340#if defined(HX_USB_DETECT_CALLBACK)||defined(HX_USB_DETECT_GLOBAL)
341 uint8_t usb_connected;
342 uint8_t *cable_config;
343#endif
344
345#if defined(CONFIG_TOUCHSCREEN_HIMAX_ITO_TEST)
346 struct workqueue_struct *ito_test_wq;
347 struct work_struct ito_test_work;
348#endif
349
350};
351
352#ifdef HX_CHIP_STATUS_MONITOR
353struct chip_monitor_data
354{
355 int HX_CHIP_POLLING_COUNT;
356 int HX_POLLING_TIMER;//unit:sec
357 int HX_POLLING_TIMES;//ex:5(timer)x2(times)=10sec(polling time)
358 int HX_ON_HAND_SHAKING;//
359 int HX_CHIP_MONITOR_EN;
360};
361#endif
362
363
364enum input_protocol_type
365{
366 PROTOCOL_TYPE_A = 0x00,
367 PROTOCOL_TYPE_B = 0x01,
368};
369
370#ifdef HX_HIGH_SENSE
371void himax_set_HSEN_func(struct i2c_client *client,uint8_t HSEN_enable);
372#endif
373
374#ifdef HX_SMART_WAKEUP
375#define GEST_PTLG_ID_LEN (4)
376#define GEST_PTLG_HDR_LEN (4)
377#define GEST_PTLG_HDR_ID1 (0xCC)
378#define GEST_PTLG_HDR_ID2 (0x44)
379#define GEST_PT_MAX_NUM (128)
380
381void himax_set_SMWP_func(struct i2c_client *client,uint8_t SMWP_enable);
382extern bool FAKE_POWER_KEY_SEND;
383
384enum gesture_event_type
385{
386 EV_GESTURE_01 = 0x01,
387 EV_GESTURE_02,
388 EV_GESTURE_03,
389 EV_GESTURE_04,
390 EV_GESTURE_05,
391 EV_GESTURE_06,
392 EV_GESTURE_07,
393 EV_GESTURE_08,
394 EV_GESTURE_09,
395 EV_GESTURE_10,
396 EV_GESTURE_11,
397 EV_GESTURE_12,
398 EV_GESTURE_13,
399 EV_GESTURE_14,
400 EV_GESTURE_15,
401 EV_GESTURE_PWR = 0x80,
402};
403
404#define KEY_CUST_01 251
405#define KEY_CUST_02 252
406#define KEY_CUST_03 253
407#define KEY_CUST_04 254
408#define KEY_CUST_05 255
409#define KEY_CUST_06 256
410#define KEY_CUST_07 257
411#define KEY_CUST_08 258
412#define KEY_CUST_09 259
413#define KEY_CUST_10 260
414#define KEY_CUST_11 261
415#define KEY_CUST_12 262
416#define KEY_CUST_13 263
417#define KEY_CUST_14 264
418#define KEY_CUST_15 265
419#endif
420
421#if defined(CONFIG_TOUCHSCREEN_HIMAX_ITO_TEST)
422extern uint8_t himax_ito_test(void);
423#endif
424
425extern int irq_enable_count;
426
427//void himax_HW_reset(uint8_t loadconfig,uint8_t int_off);
428
429#ifdef QCT
430irqreturn_t himax_ts_thread(int irq, void *ptr);
431int himax_input_register(struct himax_ts_data *ts);
432#endif
433
434extern int himax_chip_common_probe(struct i2c_client *client, const struct i2c_device_id *id);
435extern int himax_chip_common_remove(struct i2c_client *client);
436extern int himax_chip_common_suspend(struct himax_ts_data *ts);
437extern int himax_chip_common_resume(struct himax_ts_data *ts);
438
439#endif
440