Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1 | /* drivers/input/touchscreen/gt9xx.h |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2 | * |
| 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 Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 8 | * 2010 - 2013 Goodix Technology. |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 9 | * |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 10 | * 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 Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 14 | * |
| 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 Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 19 | * General Public License for more details. |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 20 | * |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #ifndef _GOODIX_GT9XX_H_ |
| 24 | #define _GOODIX_GT9XX_H_ |
| 25 | |
| 26 | #include <linux/kernel.h> |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 27 | #include <linux/i2c.h> |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 28 | #include <linux/irq.h> |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 29 | #include <linux/input.h> |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 30 | #include <linux/slab.h> |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 31 | #include <linux/interrupt.h> |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 32 | #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 Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 39 | |
| 40 | #if defined(CONFIG_FB) |
| 41 | #include <linux/notifier.h> |
| 42 | #include <linux/fb.h> |
| 43 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 44 | #include <linux/earlysuspend.h> |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 45 | #define GOODIX_SUSPEND_LEVEL 1 |
| 46 | #endif |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 47 | |
Bingzhe Cai | 15d1446 | 2013-09-11 18:52:17 +0800 | [diff] [blame] | 48 | #define GOODIX_MAX_CFG_GROUP 6 |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 49 | struct goodix_ts_platform_data { |
| 50 | int irq_gpio; |
| 51 | u32 irq_gpio_flags; |
| 52 | int reset_gpio; |
| 53 | u32 reset_gpio_flags; |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame] | 54 | const char *product_id; |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 55 | 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 Cai | 15d1446 | 2013-09-11 18:52:17 +0800 | [diff] [blame] | 65 | size_t config_data_len[GOODIX_MAX_CFG_GROUP]; |
| 66 | u8 *config_data[GOODIX_MAX_CFG_GROUP]; |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 67 | }; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 68 | struct goodix_ts_data { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 69 | 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 Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 76 | 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 Cai | c68e611 | 2013-07-22 00:12:48 +0800 | [diff] [blame] | 92 | struct regulator *avdd; |
| 93 | struct regulator *vdd; |
| 94 | struct regulator *vcc_i2c; |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 95 | #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 Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | extern u16 show_len; |
| 103 | extern u16 total_len; |
| 104 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 105 | /***************************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 Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 110 | #define GTP_POWER_CTRL_SLEEP 0 |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 111 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 112 | /* 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 Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 117 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 118 | #define GTP_CREATE_WR_NODE 0 |
| 119 | #define GTP_ESD_PROTECT 0 |
| 120 | #define GTP_WITH_PEN 0 |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 121 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 122 | #define GTP_SLIDE_WAKEUP 0 |
| 123 | /* double-click wakeup, function together with GTP_SLIDE_WAKEUP */ |
| 124 | #define GTP_DBL_CLK_WAKEUP 0 |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 125 | |
Shantanu Jain | 7dc2b47 | 2013-09-27 11:55:09 +0530 | [diff] [blame] | 126 | #define GTP_DEBUG_ON 0 |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 127 | #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 Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 133 | /* sensor_opt1 sensor_opt2 Sensor_ID |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 134 | * 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 Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 140 | */ |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 141 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 142 | #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 Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 148 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 149 | /* 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 Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 152 | #if GTP_CUSTOM_CFG |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 153 | #define GTP_MAX_HEIGHT 800 |
| 154 | #define GTP_MAX_WIDTH 480 |
| 155 | #define GTP_INT_TRIGGER GTP_IRQ_TAB_RISING |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 156 | #else |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 157 | #define GTP_MAX_HEIGHT 4096 |
| 158 | #define GTP_MAX_WIDTH 4096 |
| 159 | #define GTP_INT_TRIGGER GTP_IRQ_TAB_FALLING |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 160 | #endif |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 161 | |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame] | 162 | #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 Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 167 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 168 | /***************************PART3:OTHER define*********************************/ |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame] | 169 | #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 Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 173 | #define GTP_CONFIG_MIN_LENGTH 186 |
| 174 | #define GTP_CONFIG_MAX_LENGTH 240 |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame] | 175 | #define FAIL 0 |
| 176 | #define SUCCESS 1 |
| 177 | #define SWITCH_OFF 0 |
| 178 | #define SWITCH_ON 1 |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 179 | |
| 180 | /* Registers define */ |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame] | 181 | #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 Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 187 | |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame] | 188 | #define RESOLUTION_LOC 3 |
| 189 | #define TRIGGER_LOC 8 |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 190 | |
| 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 | |
| 227 | void gtp_esd_switch(struct i2c_client *client, int on); |
| 228 | |
| 229 | #if GTP_CREATE_WR_NODE |
| 230 | extern s32 init_wr_node(struct i2c_client *client); |
| 231 | extern void uninit_wr_node(void); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 232 | #endif |
| 233 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 234 | #if GTP_AUTO_UPDATE |
| 235 | extern u8 gup_init_update_proc(struct goodix_ts_data *ts); |
| 236 | #endif |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 237 | #endif /* _GOODIX_GT9XX_H_ */ |