blob: 1fdbfa3254c7f378ec8997671673a0464fabead8 [file] [log] [blame]
Andrew Huangab45aab2013-06-27 10:06:56 +00001/* drivers/input/touchscreen/gt9xx.h
Bingzhe Cai83caeea2013-07-16 17:57:37 +08002 *
3 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4 *
5 * Linux Foundation chooses to take subject only to the GPLv2 license
6 * terms, and distributes only under these terms.
7 *
Andrew Huangab45aab2013-06-27 10:06:56 +00008 * 2010 - 2013 Goodix Technology.
Bingzhe Cai83caeea2013-07-16 17:57:37 +08009 *
Andrew Huangab45aab2013-06-27 10:06:56 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
Bingzhe Cai83caeea2013-07-16 17:57:37 +080014 *
15 * This program is distributed in the hope that it will be a reference
16 * to you, when you are integrating the GOODiX's CTP IC into your system,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Andrew Huangab45aab2013-06-27 10:06:56 +000019 * General Public License for more details.
Bingzhe Cai83caeea2013-07-16 17:57:37 +080020 *
Andrew Huangab45aab2013-06-27 10:06:56 +000021 */
22
23#ifndef _GOODIX_GT9XX_H_
24#define _GOODIX_GT9XX_H_
25
26#include <linux/kernel.h>
Andrew Huangab45aab2013-06-27 10:06:56 +000027#include <linux/i2c.h>
Bingzhe Cai83caeea2013-07-16 17:57:37 +080028#include <linux/irq.h>
Andrew Huangab45aab2013-06-27 10:06:56 +000029#include <linux/input.h>
Bingzhe Cai83caeea2013-07-16 17:57:37 +080030#include <linux/slab.h>
Andrew Huangab45aab2013-06-27 10:06:56 +000031#include <linux/interrupt.h>
Bingzhe Cai83caeea2013-07-16 17:57:37 +080032#include <linux/delay.h>
33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/gpio.h>
36#include <linux/regulator/consumer.h>
37#include <linux/firmware.h>
38#include <linux/debugfs.h>
Bingzhe Cai7d49bb32013-07-22 18:23:20 +080039
40#if defined(CONFIG_FB)
41#include <linux/notifier.h>
42#include <linux/fb.h>
43#elif defined(CONFIG_HAS_EARLYSUSPEND)
Andrew Huangab45aab2013-06-27 10:06:56 +000044#include <linux/earlysuspend.h>
Bingzhe Cai83caeea2013-07-16 17:57:37 +080045#define GOODIX_SUSPEND_LEVEL 1
46#endif
Andrew Huangab45aab2013-06-27 10:06:56 +000047
Bingzhe Cai15d14462013-09-11 18:52:17 +080048#define GOODIX_MAX_CFG_GROUP 6
Bingzhe Cai83caeea2013-07-16 17:57:37 +080049struct goodix_ts_platform_data {
50 int irq_gpio;
51 u32 irq_gpio_flags;
52 int reset_gpio;
53 u32 reset_gpio_flags;
Shantanu Jain3f80bef2013-09-18 12:05:02 +053054 const char *product_id;
Bingzhe Cai83caeea2013-07-16 17:57:37 +080055 u32 x_max;
56 u32 y_max;
57 u32 x_min;
58 u32 y_min;
59 u32 panel_minx;
60 u32 panel_miny;
61 u32 panel_maxx;
62 u32 panel_maxy;
63 bool no_force_update;
64 bool i2c_pull_up;
Bingzhe Cai15d14462013-09-11 18:52:17 +080065 size_t config_data_len[GOODIX_MAX_CFG_GROUP];
66 u8 *config_data[GOODIX_MAX_CFG_GROUP];
Bingzhe Cai83caeea2013-07-16 17:57:37 +080067};
Andrew Huangab45aab2013-06-27 10:06:56 +000068struct goodix_ts_data {
Bingzhe Cai83caeea2013-07-16 17:57:37 +080069 spinlock_t irq_lock;
70 struct i2c_client *client;
71 struct input_dev *input_dev;
72 struct goodix_ts_platform_data *pdata;
73 struct hrtimer timer;
74 struct workqueue_struct *goodix_wq;
75 struct work_struct work;
Bingzhe Cai83caeea2013-07-16 17:57:37 +080076 s32 irq_is_disabled;
77 s32 use_irq;
78 u16 abs_x_max;
79 u16 abs_y_max;
80 u8 max_touch_num;
81 u8 int_trigger_type;
82 u8 green_wake_mode;
83 u8 chip_type;
84 u8 *config_data;
85 u8 enter_update;
86 u8 gtp_is_suspend;
87 u8 gtp_rawdiff_mode;
88 u8 gtp_cfg_len;
89 u8 fixed_cfg;
90 u8 esd_running;
91 u8 fw_error;
Bingzhe Caic68e6112013-07-22 00:12:48 +080092 struct regulator *avdd;
93 struct regulator *vdd;
94 struct regulator *vcc_i2c;
Bingzhe Cai7d49bb32013-07-22 18:23:20 +080095#if defined(CONFIG_FB)
96 struct notifier_block fb_notif;
97#elif defined(CONFIG_HAS_EARLYSUSPEND)
98 struct early_suspend early_suspend;
99#endif
Andrew Huangab45aab2013-06-27 10:06:56 +0000100};
101
102extern u16 show_len;
103extern u16 total_len;
104
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800105/***************************PART1:ON/OFF define*******************************/
106#define GTP_CUSTOM_CFG 0
107#define GTP_CHANGE_X2Y 0
108#define GTP_DRIVER_SEND_CFG 1
109#define GTP_HAVE_TOUCH_KEY 1
Bingzhe Cai7d49bb32013-07-22 18:23:20 +0800110#define GTP_POWER_CTRL_SLEEP 0
Andrew Huangab45aab2013-06-27 10:06:56 +0000111
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800112/* auto updated by .bin file as default */
113#define GTP_AUTO_UPDATE 0
114/* auto updated by head_fw_array in gt9xx_firmware.h,
115 * function together with GTP_AUTO_UPDATE */
116#define GTP_HEADER_FW_UPDATE 0
Andrew Huangab45aab2013-06-27 10:06:56 +0000117
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800118#define GTP_CREATE_WR_NODE 0
119#define GTP_ESD_PROTECT 0
120#define GTP_WITH_PEN 0
Andrew Huangab45aab2013-06-27 10:06:56 +0000121
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800122#define GTP_SLIDE_WAKEUP 0
123/* double-click wakeup, function together with GTP_SLIDE_WAKEUP */
124#define GTP_DBL_CLK_WAKEUP 0
Andrew Huangab45aab2013-06-27 10:06:56 +0000125
Shantanu Jain7dc2b472013-09-27 11:55:09 +0530126#define GTP_DEBUG_ON 0
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800127#define GTP_DEBUG_ARRAY_ON 0
128#define GTP_DEBUG_FUNC_ON 0
129
130/*************************** PART2:TODO define *******************************/
131/* STEP_1(REQUIRED): Define Configuration Information Group(s) */
132/* Sensor_ID Map: */
Andrew Huangab45aab2013-06-27 10:06:56 +0000133/* sensor_opt1 sensor_opt2 Sensor_ID
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800134 * GND GND 0
135 * VDDIO GND 1
136 * NC GND 2
137 * GND NC/300K 3
138 * VDDIO NC/300K 4
139 * NC NC/300K 5
Andrew Huangab45aab2013-06-27 10:06:56 +0000140*/
Andrew Huangab45aab2013-06-27 10:06:56 +0000141
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800142#define GTP_IRQ_TAB {\
143 IRQ_TYPE_EDGE_RISING,\
144 IRQ_TYPE_EDGE_FALLING,\
145 IRQ_TYPE_LEVEL_LOW,\
146 IRQ_TYPE_LEVEL_HIGH\
147 }
Andrew Huangab45aab2013-06-27 10:06:56 +0000148
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800149/* STEP_3(optional): Specify your special config info if needed */
150#define GTP_IRQ_TAB_RISING 0
151#define GTP_IRQ_TAB_FALLING 1
Andrew Huangab45aab2013-06-27 10:06:56 +0000152#if GTP_CUSTOM_CFG
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800153#define GTP_MAX_HEIGHT 800
154#define GTP_MAX_WIDTH 480
155#define GTP_INT_TRIGGER GTP_IRQ_TAB_RISING
Andrew Huangab45aab2013-06-27 10:06:56 +0000156#else
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800157#define GTP_MAX_HEIGHT 4096
158#define GTP_MAX_WIDTH 4096
159#define GTP_INT_TRIGGER GTP_IRQ_TAB_FALLING
Andrew Huangab45aab2013-06-27 10:06:56 +0000160#endif
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800161
Shantanu Jain3f80bef2013-09-18 12:05:02 +0530162#define GTP_PRODUCT_ID_MAXSIZE 5
163#define GTP_PRODUCT_ID_BUFFER_MAXSIZE 6
164#define GTP_FW_VERSION_BUFFER_MAXSIZE 4
165#define GTP_MAX_TOUCH 5
166#define GTP_ESD_CHECK_CIRCLE 2000 /* jiffy: ms */
Andrew Huangab45aab2013-06-27 10:06:56 +0000167
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800168/***************************PART3:OTHER define*********************************/
Shantanu Jain3f80bef2013-09-18 12:05:02 +0530169#define GTP_DRIVER_VERSION "V1.8.1<2013/09/01>"
170#define GTP_I2C_NAME "Goodix-TS"
171#define GTP_POLL_TIME 10 /* jiffy: ms*/
172#define GTP_ADDR_LENGTH 2
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800173#define GTP_CONFIG_MIN_LENGTH 186
174#define GTP_CONFIG_MAX_LENGTH 240
Shantanu Jain3f80bef2013-09-18 12:05:02 +0530175#define FAIL 0
176#define SUCCESS 1
177#define SWITCH_OFF 0
178#define SWITCH_ON 1
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800179
180/* Registers define */
Shantanu Jain3f80bef2013-09-18 12:05:02 +0530181#define GTP_READ_COOR_ADDR 0x814E
182#define GTP_REG_SLEEP 0x8040
183#define GTP_REG_SENSOR_ID 0x814A
184#define GTP_REG_CONFIG_DATA 0x8047
185#define GTP_REG_FW_VERSION 0x8144
186#define GTP_REG_PRODUCT_ID 0x8140
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800187
Shantanu Jain3f80bef2013-09-18 12:05:02 +0530188#define RESOLUTION_LOC 3
189#define TRIGGER_LOC 8
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800190
191#define CFG_GROUP_LEN(p_cfg_grp) (sizeof(p_cfg_grp) / sizeof(p_cfg_grp[0]))
192/* Log define */
193#define GTP_DEBUG(fmt, arg...) do {\
194 if (GTP_DEBUG_ON) {\
195 pr_debug("<<-GTP-DEBUG->> [%d]"fmt"\n",\
196 __LINE__, ##arg); } \
197 } while (0)
198
199#define GTP_DEBUG_ARRAY(array, num) do {\
200 s32 i; \
201 u8 *a = array; \
202 if (GTP_DEBUG_ARRAY_ON) {\
203 pr_debug("<<-GTP-DEBUG-ARRAY->>\n");\
204 for (i = 0; i < (num); i++) { \
205 pr_debug("%02x ", (a)[i]);\
206 if ((i + 1) % 10 == 0) { \
207 pr_debug("\n");\
208 } \
209 } \
210 pr_debug("\n");\
211 } \
212 } while (0)
213
214#define GTP_DEBUG_FUNC() do {\
215 if (GTP_DEBUG_FUNC_ON)\
216 pr_debug("<<-GTP-FUNC->> Func:%s@Line:%d\n",\
217 __func__, __LINE__);\
218 } while (0)
219
220#define GTP_SWAP(x, y) do {\
221 typeof(x) z = x;\
222 x = y;\
223 y = z;\
224 } while (0)
225/*****************************End of Part III********************************/
226
227void gtp_esd_switch(struct i2c_client *client, int on);
228
229#if GTP_CREATE_WR_NODE
230extern s32 init_wr_node(struct i2c_client *client);
231extern void uninit_wr_node(void);
Andrew Huangab45aab2013-06-27 10:06:56 +0000232#endif
233
Bingzhe Cai83caeea2013-07-16 17:57:37 +0800234#if GTP_AUTO_UPDATE
235extern u8 gup_init_update_proc(struct goodix_ts_data *ts);
236#endif
Andrew Huangab45aab2013-06-27 10:06:56 +0000237#endif /* _GOODIX_GT9XX_H_ */