Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1 | /* drivers/input/touchscreen/gt9xx.c |
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 | * Version: 1.8 |
| 22 | * Authors: andrew@goodix.com, meta@goodix.com |
| 23 | * Release Date: 2013/04/25 |
| 24 | * Revision record: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 25 | * V1.0: |
| 26 | * first Release. By Andrew, 2012/08/31 |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 27 | * V1.2: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 28 | * modify gtp_reset_guitar,slot report,tracking_id & 0x0F. |
| 29 | * By Andrew, 2012/10/15 |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 30 | * V1.4: |
| 31 | * modify gt9xx_update.c. By Andrew, 2012/12/12 |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 32 | * V1.6: |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 33 | * 1. new heartbeat/esd_protect mechanism(add external watchdog) |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 34 | * 2. doze mode, sliding wakeup |
| 35 | * 3. 3 more cfg_group(GT9 Sensor_ID: 0~5) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 36 | * 3. config length verification |
| 37 | * 4. names & comments |
| 38 | * By Meta, 2013/03/11 |
| 39 | * V1.8: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 40 | * 1. pen/stylus identification |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 41 | * 2. read double check & fixed config support |
| 42 | * 2. new esd & slide wakeup optimization |
| 43 | * By Meta, 2013/06/08 |
| 44 | */ |
| 45 | |
Bingzhe Cai | c68e611 | 2013-07-22 00:12:48 +0800 | [diff] [blame] | 46 | #include <linux/regulator/consumer.h> |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 47 | #include "gt9xx.h" |
| 48 | |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 49 | #include <linux/of_gpio.h> |
| 50 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 51 | #include <linux/input/mt.h> |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 52 | |
Bingzhe Cai | 6beb011 | 2013-08-27 00:27:26 +0800 | [diff] [blame] | 53 | #define GOODIX_DEV_NAME "Goodix-CTP" |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 54 | #define CFG_MAX_TOUCH_POINTS 5 |
| 55 | #define GOODIX_COORDS_ARR_SIZE 4 |
| 56 | #define MAX_BUTTONS 4 |
| 57 | |
| 58 | /* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */ |
| 59 | #define GTP_I2C_ADDRESS_HIGH 0x14 |
| 60 | #define GTP_I2C_ADDRESS_LOW 0x5D |
| 61 | #define CFG_GROUP_LEN(p_cfg_grp) (sizeof(p_cfg_grp) / sizeof(p_cfg_grp[0])) |
| 62 | |
Bingzhe Cai | c68e611 | 2013-07-22 00:12:48 +0800 | [diff] [blame] | 63 | #define GOODIX_VTG_MIN_UV 2600000 |
| 64 | #define GOODIX_VTG_MAX_UV 3300000 |
| 65 | #define GOODIX_I2C_VTG_MIN_UV 1800000 |
| 66 | #define GOODIX_I2C_VTG_MAX_UV 1800000 |
| 67 | #define GOODIX_VDD_LOAD_MIN_UA 0 |
| 68 | #define GOODIX_VDD_LOAD_MAX_UA 10000 |
| 69 | #define GOODIX_VIO_LOAD_MIN_UA 0 |
| 70 | #define GOODIX_VIO_LOAD_MAX_UA 10000 |
| 71 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 72 | #define RESET_DELAY_T3_US 200 /* T3: > 100us */ |
| 73 | #define RESET_DELAY_T4 20 /* T4: > 5ms */ |
| 74 | |
| 75 | #define PHY_BUF_SIZE 32 |
| 76 | |
| 77 | #define GTP_MAX_TOUCH 5 |
| 78 | #define GTP_ESD_CHECK_CIRCLE_MS 2000 |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 79 | |
| 80 | #if GTP_HAVE_TOUCH_KEY |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 81 | static const u16 touch_key_array[] = {KEY_MENU, KEY_HOMEPAGE, KEY_BACK}; |
| 82 | #define GTP_MAX_KEY_NUM (sizeof(touch_key_array)/sizeof(touch_key_array[0])) |
| 83 | |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 84 | #if GTP_DEBUG_ON |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 85 | static const int key_codes[] = { |
| 86 | KEY_HOME, KEY_BACK, KEY_MENU, KEY_SEARCH |
| 87 | }; |
| 88 | static const char *const key_names[] = { |
| 89 | "Key_Home", "Key_Back", "Key_Menu", "Key_Search" |
| 90 | }; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 91 | #endif |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 92 | #endif |
| 93 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 94 | static void gtp_reset_guitar(struct goodix_ts_data *ts, int ms); |
| 95 | static void gtp_int_sync(struct goodix_ts_data *ts, int ms); |
| 96 | static int gtp_i2c_test(struct i2c_client *client); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 97 | |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 98 | #if defined(CONFIG_FB) |
| 99 | static int fb_notifier_callback(struct notifier_block *self, |
| 100 | unsigned long event, void *data); |
| 101 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 102 | static void goodix_ts_early_suspend(struct early_suspend *h); |
| 103 | static void goodix_ts_late_resume(struct early_suspend *h); |
| 104 | #endif |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 105 | |
| 106 | #if GTP_ESD_PROTECT |
| 107 | static struct delayed_work gtp_esd_check_work; |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 108 | static struct workqueue_struct *gtp_esd_check_workqueue; |
| 109 | static void gtp_esd_check_func(struct work_struct *work); |
| 110 | static int gtp_init_ext_watchdog(struct i2c_client *client); |
| 111 | struct i2c_client *i2c_connect_client; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 112 | #endif |
| 113 | |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 114 | #if GTP_SLIDE_WAKEUP |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 115 | enum doze_status { |
| 116 | DOZE_DISABLED = 0, |
| 117 | DOZE_ENABLED = 1, |
| 118 | DOZE_WAKEUP = 2, |
| 119 | }; |
| 120 | static enum doze_status = DOZE_DISABLED; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 121 | static s8 gtp_enter_doze(struct goodix_ts_data *ts); |
| 122 | #endif |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 123 | bool init_done; |
| 124 | static u8 chip_gt9xxs; /* true if ic is gt9xxs, like gt915s */ |
| 125 | u8 grp_cfg_version; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 126 | |
| 127 | /******************************************************* |
| 128 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 129 | Read data from the i2c slave device. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 130 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 131 | client: i2c device. |
| 132 | buf[0~1]: read start address. |
| 133 | buf[2~len-1]: read data buffer. |
| 134 | len: GTP_ADDR_LENGTH + read bytes count |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 135 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 136 | numbers of i2c_msgs to transfer: |
| 137 | 2: succeed, otherwise: failed |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 138 | *********************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 139 | int gtp_i2c_read(struct i2c_client *client, u8 *buf, int len) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 140 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 141 | struct goodix_ts_data *ts = i2c_get_clientdata(client); |
| 142 | struct i2c_msg msgs[2]; |
| 143 | int ret = -EIO; |
| 144 | int retries = 0; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 145 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 146 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 147 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 148 | msgs[0].flags = !I2C_M_RD; |
| 149 | msgs[0].addr = client->addr; |
| 150 | msgs[0].len = GTP_ADDR_LENGTH; |
| 151 | msgs[0].buf = &buf[0]; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 152 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 153 | msgs[1].flags = I2C_M_RD; |
| 154 | msgs[1].addr = client->addr; |
| 155 | msgs[1].len = len - GTP_ADDR_LENGTH; |
| 156 | msgs[1].buf = &buf[GTP_ADDR_LENGTH]; |
| 157 | |
| 158 | while (retries < 5) { |
| 159 | ret = i2c_transfer(client->adapter, msgs, 2); |
| 160 | if (ret == 2) |
| 161 | break; |
| 162 | retries++; |
| 163 | } |
| 164 | if (retries >= 5) { |
| 165 | #if GTP_SLIDE_WAKEUP |
| 166 | /* reset chip would quit doze mode */ |
| 167 | if (DOZE_ENABLED == doze_status) |
| 168 | return ret; |
| 169 | #endif |
| 170 | GTP_DEBUG("I2C communication timeout, resetting chip..."); |
| 171 | if (init_done) |
| 172 | gtp_reset_guitar(ts, 10); |
| 173 | else |
| 174 | dev_warn(&client->dev, |
| 175 | "<GTP> gtp_reset_guitar exit init_done=%d:\n", |
| 176 | init_done); |
| 177 | } |
| 178 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /******************************************************* |
| 182 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 183 | Write data to the i2c slave device. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 184 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 185 | client: i2c device. |
| 186 | buf[0~1]: write start address. |
| 187 | buf[2~len-1]: data buffer |
| 188 | len: GTP_ADDR_LENGTH + write bytes count |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 189 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 190 | numbers of i2c_msgs to transfer: |
| 191 | 1: succeed, otherwise: failed |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 192 | *********************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 193 | int gtp_i2c_write(struct i2c_client *client, u8 *buf, int len) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 194 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 195 | struct goodix_ts_data *ts = i2c_get_clientdata(client); |
| 196 | struct i2c_msg msg; |
| 197 | int ret = -EIO; |
| 198 | int retries = 0; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 199 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 200 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 201 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 202 | msg.flags = !I2C_M_RD; |
| 203 | msg.addr = client->addr; |
| 204 | msg.len = len; |
| 205 | msg.buf = buf; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 206 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 207 | while (retries < 5) { |
| 208 | ret = i2c_transfer(client->adapter, &msg, 1); |
| 209 | if (ret == 1) |
| 210 | break; |
| 211 | retries++; |
| 212 | } |
| 213 | if ((retries >= 5)) { |
| 214 | #if GTP_SLIDE_WAKEUP |
| 215 | if (DOZE_ENABLED == doze_status) |
| 216 | return ret; |
| 217 | #endif |
| 218 | GTP_DEBUG("I2C communication timeout, resetting chip..."); |
| 219 | if (init_done) |
| 220 | gtp_reset_guitar(ts, 10); |
| 221 | else |
| 222 | dev_warn(&client->dev, |
| 223 | "<GTP> gtp_reset_guitar exit init_done=%d:\n", |
| 224 | init_done); |
| 225 | } |
| 226 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 227 | } |
| 228 | /******************************************************* |
| 229 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 230 | i2c read twice, compare the results |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 231 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 232 | client: i2c device |
| 233 | addr: operate address |
| 234 | rxbuf: read data to store, if compare successful |
| 235 | len: bytes to read |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 236 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 237 | FAIL: read failed |
| 238 | SUCCESS: read successful |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 239 | *********************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 240 | int gtp_i2c_read_dbl_check(struct i2c_client *client, |
| 241 | u16 addr, u8 *rxbuf, int len) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 242 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 243 | u8 buf[16] = {0}; |
| 244 | u8 confirm_buf[16] = {0}; |
| 245 | u8 retry = 0; |
| 246 | |
| 247 | while (retry++ < 3) { |
| 248 | memset(buf, 0xAA, 16); |
| 249 | buf[0] = (u8)(addr >> 8); |
| 250 | buf[1] = (u8)(addr & 0xFF); |
| 251 | gtp_i2c_read(client, buf, len + 2); |
| 252 | |
| 253 | memset(confirm_buf, 0xAB, 16); |
| 254 | confirm_buf[0] = (u8)(addr >> 8); |
| 255 | confirm_buf[1] = (u8)(addr & 0xFF); |
| 256 | gtp_i2c_read(client, confirm_buf, len + 2); |
| 257 | |
| 258 | if (!memcmp(buf, confirm_buf, len + 2)) |
| 259 | break; |
| 260 | } |
| 261 | if (retry < 3) { |
| 262 | memcpy(rxbuf, confirm_buf + 2, len); |
| 263 | return SUCCESS; |
| 264 | } else { |
| 265 | dev_err(&client->dev, |
| 266 | "i2c read 0x%04X, %d bytes, double check failed!", |
| 267 | addr, len); |
| 268 | return FAIL; |
| 269 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /******************************************************* |
| 273 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 274 | Send config data. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 275 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 276 | client: i2c device. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 277 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 278 | result of i2c write operation. |
| 279 | > 0: succeed, otherwise: failed |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 280 | *********************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 281 | static int gtp_send_cfg(struct goodix_ts_data *ts) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 282 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 283 | int ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 284 | #if GTP_DRIVER_SEND_CFG |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 285 | int retry = 0; |
| 286 | |
| 287 | if (ts->fixed_cfg) { |
| 288 | dev_dbg(&ts->client->dev, |
| 289 | "Ic fixed config, no config sent!"); |
| 290 | ret = 2; |
| 291 | } else { |
| 292 | for (retry = 0; retry < 5; retry++) { |
| 293 | ret = gtp_i2c_write(ts->client, |
| 294 | ts->config_data, |
| 295 | GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); |
| 296 | if (ret > 0) |
| 297 | break; |
| 298 | } |
| 299 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 300 | #endif |
| 301 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 302 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /******************************************************* |
| 306 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 307 | Disable irq function |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 308 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 309 | ts: goodix i2c_client private data |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 310 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 311 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 312 | *********************************************************/ |
| 313 | void gtp_irq_disable(struct goodix_ts_data *ts) |
| 314 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 315 | unsigned long irqflags; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 316 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 317 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 318 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 319 | spin_lock_irqsave(&ts->irq_lock, irqflags); |
| 320 | if (!ts->irq_is_disabled) { |
| 321 | ts->irq_is_disabled = true; |
| 322 | disable_irq_nosync(ts->client->irq); |
| 323 | } |
| 324 | spin_unlock_irqrestore(&ts->irq_lock, irqflags); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /******************************************************* |
| 328 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 329 | Enable irq function |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 330 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 331 | ts: goodix i2c_client private data |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 332 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 333 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 334 | *********************************************************/ |
| 335 | void gtp_irq_enable(struct goodix_ts_data *ts) |
| 336 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 337 | unsigned long irqflags = 0; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 338 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 339 | GTP_DEBUG_FUNC(); |
| 340 | |
| 341 | spin_lock_irqsave(&ts->irq_lock, irqflags); |
| 342 | if (ts->irq_is_disabled) { |
| 343 | enable_irq(ts->client->irq); |
| 344 | ts->irq_is_disabled = false; |
| 345 | } |
| 346 | spin_unlock_irqrestore(&ts->irq_lock, irqflags); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 349 | /******************************************************* |
| 350 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 351 | Report touch point event |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 352 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 353 | ts: goodix i2c_client private data |
| 354 | id: trackId |
| 355 | x: input x coordinate |
| 356 | y: input y coordinate |
| 357 | w: input pressure |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 358 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 359 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 360 | *********************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 361 | static void gtp_touch_down(struct goodix_ts_data *ts, int id, int x, int y, |
| 362 | int w) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 363 | { |
| 364 | #if GTP_CHANGE_X2Y |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 365 | GTP_SWAP(x, y); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 366 | #endif |
| 367 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 368 | input_mt_slot(ts->input_dev, id); |
Bingzhe Cai | 6beb011 | 2013-08-27 00:27:26 +0800 | [diff] [blame] | 369 | input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 370 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x); |
| 371 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y); |
| 372 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w); |
| 373 | input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 374 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 375 | GTP_DEBUG("ID:%d, X:%d, Y:%d, W:%d", id, x, y, w); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /******************************************************* |
| 379 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 380 | Report touch release event |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 381 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 382 | ts: goodix i2c_client private data |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 383 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 384 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 385 | *********************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 386 | static void gtp_touch_up(struct goodix_ts_data *ts, int id) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 387 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 388 | input_mt_slot(ts->input_dev, id); |
Bingzhe Cai | 6beb011 | 2013-08-27 00:27:26 +0800 | [diff] [blame] | 389 | input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 390 | GTP_DEBUG("Touch id[%2d] release!", id); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 394 | |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 395 | /******************************************************* |
| 396 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 397 | Goodix touchscreen work function |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 398 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 399 | work: work struct of goodix_workqueue |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 400 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 401 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 402 | *********************************************************/ |
| 403 | static void goodix_ts_work_func(struct work_struct *work) |
| 404 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 405 | u8 end_cmd[3] = { GTP_READ_COOR_ADDR >> 8, |
| 406 | GTP_READ_COOR_ADDR & 0xFF, 0}; |
| 407 | u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1] = { |
| 408 | GTP_READ_COOR_ADDR >> 8, |
| 409 | GTP_READ_COOR_ADDR & 0xFF}; |
| 410 | u8 touch_num = 0; |
| 411 | u8 finger = 0; |
| 412 | static u16 pre_touch; |
| 413 | static u8 pre_key; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 414 | #if GTP_WITH_PEN |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 415 | static u8 pre_pen; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 416 | #endif |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 417 | u8 key_value = 0; |
| 418 | u8 *coor_data = NULL; |
| 419 | s32 input_x = 0; |
| 420 | s32 input_y = 0; |
| 421 | s32 input_w = 0; |
| 422 | s32 id = 0; |
| 423 | s32 i = 0; |
| 424 | int ret = -1; |
| 425 | struct goodix_ts_data *ts = NULL; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 426 | |
| 427 | #if GTP_SLIDE_WAKEUP |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 428 | u8 doze_buf[3] = {0x81, 0x4B}; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 429 | #endif |
| 430 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 431 | GTP_DEBUG_FUNC(); |
| 432 | |
| 433 | ts = container_of(work, struct goodix_ts_data, work); |
| 434 | #ifdef CONFIG_GT9XX_TOUCHPANEL_UPDATE |
| 435 | if (ts->enter_update) |
| 436 | return; |
| 437 | #endif |
| 438 | |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 439 | #if GTP_SLIDE_WAKEUP |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 440 | if (DOZE_ENABLED == doze_status) { |
| 441 | ret = gtp_i2c_read(ts->client, doze_buf, 3); |
| 442 | GTP_DEBUG("0x814B = 0x%02X", doze_buf[2]); |
| 443 | if (ret > 0) { |
| 444 | if (doze_buf[2] == 0xAA) { |
| 445 | dev_dbg(&ts->client->dev, |
| 446 | "Slide(0xAA) To Light up the screen!"); |
| 447 | doze_status = DOZE_WAKEUP; |
| 448 | input_report_key( |
| 449 | ts->input_dev, KEY_POWER, 1); |
| 450 | input_sync(ts->input_dev); |
| 451 | input_report_key( |
| 452 | ts->input_dev, KEY_POWER, 0); |
| 453 | input_sync(ts->input_dev); |
| 454 | /* clear 0x814B */ |
| 455 | doze_buf[2] = 0x00; |
| 456 | gtp_i2c_write(ts->client, doze_buf, 3); |
| 457 | } else if (doze_buf[2] == 0xBB) { |
| 458 | dev_dbg(&ts->client->dev, |
| 459 | "Slide(0xBB) To Light up the screen!"); |
| 460 | doze_status = DOZE_WAKEUP; |
| 461 | input_report_key(ts->input_dev, KEY_POWER, 1); |
| 462 | input_sync(ts->input_dev); |
| 463 | input_report_key(ts->input_dev, KEY_POWER, 0); |
| 464 | input_sync(ts->input_dev); |
| 465 | /* clear 0x814B*/ |
| 466 | doze_buf[2] = 0x00; |
| 467 | gtp_i2c_write(ts->client, doze_buf, 3); |
| 468 | } else if (0xC0 == (doze_buf[2] & 0xC0)) { |
| 469 | dev_dbg(&ts->client->dev, |
| 470 | "double click to light up the screen!"); |
| 471 | doze_status = DOZE_WAKEUP; |
| 472 | input_report_key(ts->input_dev, KEY_POWER, 1); |
| 473 | input_sync(ts->input_dev); |
| 474 | input_report_key(ts->input_dev, KEY_POWER, 0); |
| 475 | input_sync(ts->input_dev); |
| 476 | /* clear 0x814B */ |
| 477 | doze_buf[2] = 0x00; |
| 478 | gtp_i2c_write(ts->client, doze_buf, 3); |
| 479 | } else { |
| 480 | gtp_enter_doze(ts); |
| 481 | } |
| 482 | } |
| 483 | if (ts->use_irq) |
| 484 | gtp_irq_enable(ts); |
| 485 | |
| 486 | return; |
| 487 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 488 | #endif |
| 489 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 490 | ret = gtp_i2c_read(ts->client, point_data, 12); |
| 491 | if (ret < 0) { |
| 492 | dev_err(&ts->client->dev, |
| 493 | "I2C transfer error. errno:%d\n ", ret); |
| 494 | goto exit_work_func; |
| 495 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 496 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 497 | finger = point_data[GTP_ADDR_LENGTH]; |
| 498 | if ((finger & 0x80) == 0) |
| 499 | goto exit_work_func; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 500 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 501 | touch_num = finger & 0x0f; |
| 502 | if (touch_num > GTP_MAX_TOUCH) |
| 503 | goto exit_work_func; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 504 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 505 | if (touch_num > 1) { |
| 506 | u8 buf[8 * GTP_MAX_TOUCH] = { (GTP_READ_COOR_ADDR + 10) >> 8, |
| 507 | (GTP_READ_COOR_ADDR + 10) & 0xff }; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 508 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 509 | ret = gtp_i2c_read(ts->client, buf, |
| 510 | 2 + 8 * (touch_num - 1)); |
| 511 | memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1)); |
| 512 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 513 | |
| 514 | #if GTP_HAVE_TOUCH_KEY |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 515 | key_value = point_data[3 + 8 * touch_num]; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 516 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 517 | if (key_value || pre_key) { |
| 518 | for (i = 0; i < GTP_MAX_KEY_NUM; i++) { |
| 519 | #if GTP_DEBUG_ON |
| 520 | for (ret = 0; ret < 4; ++ret) { |
| 521 | if (key_codes[ret] == touch_key_array[i]) { |
| 522 | GTP_DEBUG("Key: %s %s", |
| 523 | key_names[ret], |
| 524 | (key_value & (0x01 << i)) |
| 525 | ? "Down" : "Up"); |
| 526 | break; |
| 527 | } |
| 528 | } |
| 529 | #endif |
| 530 | |
| 531 | input_report_key(ts->input_dev, |
| 532 | touch_key_array[i], key_value & (0x01<<i)); |
| 533 | } |
| 534 | touch_num = 0; |
| 535 | pre_touch = 0; |
| 536 | } |
| 537 | #endif |
| 538 | pre_key = key_value; |
| 539 | |
| 540 | GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 541 | |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 542 | #if GTP_WITH_PEN |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 543 | if (pre_pen && (touch_num == 0)) { |
| 544 | GTP_DEBUG("Pen touch UP(Slot)!"); |
| 545 | input_report_key(ts->input_dev, BTN_TOOL_PEN, 0); |
| 546 | input_mt_slot(ts->input_dev, 5); |
| 547 | input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1); |
| 548 | pre_pen = 0; |
| 549 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 550 | #endif |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 551 | if (pre_touch || touch_num) { |
| 552 | s32 pos = 0; |
| 553 | u16 touch_index = 0; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 554 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 555 | coor_data = &point_data[3]; |
| 556 | if (touch_num) { |
| 557 | id = coor_data[pos] & 0x0F; |
| 558 | #if GTP_WITH_PEN |
| 559 | id = coor_data[pos]; |
| 560 | if (id == 128) { |
| 561 | GTP_DEBUG("Pen touch DOWN(Slot)!"); |
| 562 | input_x = coor_data[pos + 1] |
| 563 | | (coor_data[pos + 2] << 8); |
| 564 | input_y = coor_data[pos + 3] |
| 565 | | (coor_data[pos + 4] << 8); |
| 566 | input_w = coor_data[pos + 5] |
| 567 | | (coor_data[pos + 6] << 8); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 568 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 569 | input_report_key(ts->input_dev, |
| 570 | BTN_TOOL_PEN, 1); |
| 571 | input_mt_slot(ts->input_dev, 5); |
| 572 | input_report_abs(ts->input_dev, |
| 573 | ABS_MT_TRACKING_ID, 5); |
| 574 | input_report_abs(ts->input_dev, |
| 575 | ABS_MT_POSITION_X, input_x); |
| 576 | input_report_abs(ts->input_dev, |
| 577 | ABS_MT_POSITION_Y, input_y); |
| 578 | input_report_abs(ts->input_dev, |
| 579 | ABS_MT_TOUCH_MAJOR, input_w); |
| 580 | GTP_DEBUG("Pen/Stylus: (%d, %d)[%d]", |
| 581 | input_x, input_y, input_w); |
| 582 | pre_pen = 1; |
| 583 | pre_touch = 0; |
| 584 | } |
| 585 | #endif |
| 586 | |
| 587 | touch_index |= (0x01<<id); |
| 588 | } |
| 589 | |
| 590 | GTP_DEBUG("id = %d,touch_index = 0x%x, pre_touch = 0x%x\n", |
| 591 | id, touch_index, pre_touch); |
| 592 | for (i = 0; i < GTP_MAX_TOUCH; i++) { |
| 593 | #if GTP_WITH_PEN |
| 594 | if (pre_pen == 1) |
| 595 | break; |
| 596 | #endif |
| 597 | if (touch_index & (0x01<<i)) { |
| 598 | input_x = coor_data[pos + 1] | |
| 599 | coor_data[pos + 2] << 8; |
| 600 | input_y = coor_data[pos + 3] | |
| 601 | coor_data[pos + 4] << 8; |
| 602 | input_w = coor_data[pos + 5] | |
| 603 | coor_data[pos + 6] << 8; |
| 604 | |
| 605 | gtp_touch_down(ts, id, |
| 606 | input_x, input_y, input_w); |
| 607 | pre_touch |= 0x01 << i; |
| 608 | |
| 609 | pos += 8; |
| 610 | id = coor_data[pos] & 0x0F; |
| 611 | touch_index |= (0x01<<id); |
| 612 | } else { |
| 613 | gtp_touch_up(ts, i); |
| 614 | pre_touch &= ~(0x01 << i); |
| 615 | } |
| 616 | } |
| 617 | } |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 618 | input_sync(ts->input_dev); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 619 | |
| 620 | exit_work_func: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 621 | if (!ts->gtp_rawdiff_mode) { |
| 622 | ret = gtp_i2c_write(ts->client, end_cmd, 3); |
| 623 | if (ret < 0) |
| 624 | dev_warn(&ts->client->dev, "I2C write end_cmd error!\n"); |
| 625 | |
| 626 | } |
| 627 | if (ts->use_irq) |
| 628 | gtp_irq_enable(ts); |
| 629 | |
| 630 | return; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /******************************************************* |
| 634 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 635 | Timer interrupt service routine for polling mode. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 636 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 637 | timer: timer struct pointer |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 638 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 639 | Timer work mode. |
| 640 | HRTIMER_NORESTART: no restart mode |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 641 | *********************************************************/ |
| 642 | static enum hrtimer_restart goodix_ts_timer_handler(struct hrtimer *timer) |
| 643 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 644 | struct goodix_ts_data |
| 645 | *ts = container_of(timer, struct goodix_ts_data, timer); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 646 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 647 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 648 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 649 | queue_work(ts->goodix_wq, &ts->work); |
| 650 | hrtimer_start(&ts->timer, ktime_set(0, (GTP_POLL_TIME + 6) * 1000000), |
| 651 | HRTIMER_MODE_REL); |
| 652 | return HRTIMER_NORESTART; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | /******************************************************* |
| 656 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 657 | External interrupt service routine for interrupt mode. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 658 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 659 | irq: interrupt number. |
| 660 | dev_id: private data pointer |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 661 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 662 | Handle Result. |
| 663 | IRQ_HANDLED: interrupt handled successfully |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 664 | *********************************************************/ |
| 665 | static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id) |
| 666 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 667 | struct goodix_ts_data *ts = dev_id; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 668 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 669 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 670 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 671 | gtp_irq_disable(ts); |
| 672 | |
| 673 | queue_work(ts->goodix_wq, &ts->work); |
| 674 | |
| 675 | return IRQ_HANDLED; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 676 | } |
| 677 | /******************************************************* |
| 678 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 679 | Synchronization. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 680 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 681 | ms: synchronization time in millisecond. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 682 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 683 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 684 | *******************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 685 | void gtp_int_sync(struct goodix_ts_data *ts, int ms) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 686 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 687 | gpio_direction_output(ts->pdata->irq_gpio, 0); |
| 688 | msleep(ms); |
| 689 | gpio_direction_input(ts->pdata->irq_gpio); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /******************************************************* |
| 693 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 694 | Reset chip. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 695 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 696 | ms: reset time in millisecond, must >10ms |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 697 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 698 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 699 | *******************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 700 | static void gtp_reset_guitar(struct goodix_ts_data *ts, int ms) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 701 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 702 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 703 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 704 | /* This reset sequence will selcet I2C slave address */ |
| 705 | gpio_direction_output(ts->pdata->reset_gpio, 0); |
| 706 | msleep(ms); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 707 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 708 | if (ts->client->addr == GTP_I2C_ADDRESS_HIGH) |
| 709 | gpio_direction_output(ts->pdata->irq_gpio, 1); |
| 710 | else |
| 711 | gpio_direction_output(ts->pdata->irq_gpio, 0); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 712 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 713 | usleep(RESET_DELAY_T3_US); |
| 714 | gpio_direction_output(ts->pdata->reset_gpio, 1); |
| 715 | msleep(RESET_DELAY_T4); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 716 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 717 | gpio_direction_input(ts->pdata->reset_gpio); |
| 718 | |
| 719 | gtp_int_sync(ts, 50); |
| 720 | |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 721 | #if GTP_ESD_PROTECT |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 722 | gtp_init_ext_watchdog(ts->client); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 723 | #endif |
| 724 | } |
| 725 | |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 726 | #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_FB) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 727 | #if GTP_SLIDE_WAKEUP |
| 728 | /******************************************************* |
| 729 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 730 | Enter doze mode for sliding wakeup. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 731 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 732 | ts: goodix tp private data |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 733 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 734 | 1: succeed, otherwise failed |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 735 | *******************************************************/ |
| 736 | static s8 gtp_enter_doze(struct goodix_ts_data *ts) |
| 737 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 738 | int ret = -1; |
| 739 | s8 retry = 0; |
| 740 | u8 i2c_control_buf[3] = { |
| 741 | (u8)(GTP_REG_SLEEP >> 8), |
| 742 | (u8)GTP_REG_SLEEP, 8}; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 743 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 744 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 745 | |
| 746 | #if GTP_DBL_CLK_WAKEUP |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 747 | i2c_control_buf[2] = 0x09; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 748 | #endif |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 749 | gtp_irq_disable(ts); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 750 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 751 | GTP_DEBUG("entering doze mode..."); |
| 752 | while (retry++ < 5) { |
| 753 | i2c_control_buf[0] = 0x80; |
| 754 | i2c_control_buf[1] = 0x46; |
| 755 | ret = gtp_i2c_write(ts->client, i2c_control_buf, 3); |
| 756 | if (ret < 0) { |
| 757 | GTP_DEBUG( |
| 758 | "failed to set doze flag into 0x8046, %d", |
| 759 | retry); |
| 760 | continue; |
| 761 | } |
| 762 | i2c_control_buf[0] = 0x80; |
| 763 | i2c_control_buf[1] = 0x40; |
| 764 | ret = gtp_i2c_write(ts->client, i2c_control_buf, 3); |
| 765 | if (ret > 0) { |
| 766 | doze_status = DOZE_ENABLED; |
| 767 | dev_dbg(&ts->client->dev, |
| 768 | "GTP has been working in doze mode!"); |
| 769 | gtp_irq_enable(ts); |
| 770 | return ret; |
| 771 | } |
| 772 | msleep(20); |
| 773 | } |
| 774 | dev_err(&ts->client->dev, "GTP send doze cmd failed.\n"); |
| 775 | gtp_irq_enable(ts); |
| 776 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 777 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 778 | #else |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 779 | /******************************************************* |
| 780 | Function: |
| 781 | Enter sleep mode. |
| 782 | Input: |
| 783 | ts: private data. |
| 784 | Output: |
| 785 | Executive outcomes. |
| 786 | 1: succeed, otherwise failed. |
| 787 | *******************************************************/ |
| 788 | static s8 gtp_enter_sleep(struct goodix_ts_data *ts) |
| 789 | { |
| 790 | int ret = -1; |
| 791 | s8 retry = 0; |
| 792 | u8 i2c_control_buf[3] = { |
| 793 | (u8)(GTP_REG_SLEEP >> 8), |
| 794 | (u8)GTP_REG_SLEEP, 5}; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 795 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 796 | GTP_DEBUG_FUNC(); |
| 797 | |
| 798 | ret = gpio_direction_output(ts->pdata->irq_gpio, 0); |
| 799 | usleep(5000); |
| 800 | while (retry++ < 5) { |
| 801 | ret = gtp_i2c_write(ts->client, i2c_control_buf, 3); |
| 802 | if (ret > 0) { |
| 803 | dev_dbg(&ts->client->dev, |
| 804 | "GTP enter sleep!"); |
| 805 | return ret; |
| 806 | } |
| 807 | msleep(20); |
| 808 | } |
| 809 | dev_err(&ts->client->dev, "GTP send sleep cmd failed.\n"); |
| 810 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 811 | } |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 812 | #endif |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 813 | |
| 814 | /******************************************************* |
| 815 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 816 | Wakeup from sleep. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 817 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 818 | ts: private data. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 819 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 820 | Executive outcomes. |
| 821 | >0: succeed, otherwise: failed. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 822 | *******************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 823 | static s8 gtp_wakeup_sleep(struct goodix_ts_data *ts) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 824 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 825 | u8 retry = 0; |
| 826 | s8 ret = -1; |
| 827 | |
| 828 | GTP_DEBUG_FUNC(); |
| 829 | |
| 830 | #if GTP_POWER_CTRL_SLEEP |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 831 | gtp_reset_guitar(ts, 20); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 832 | |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 833 | ret = gtp_send_cfg(ts); |
| 834 | if (ret > 0) { |
| 835 | dev_dbg(&ts->client->dev, |
| 836 | "Wakeup sleep send config success."); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 837 | return 1; |
| 838 | } |
| 839 | #else |
| 840 | while (retry++ < 10) { |
| 841 | #if GTP_SLIDE_WAKEUP |
| 842 | /* wakeup not by slide */ |
| 843 | if (DOZE_WAKEUP != doze_status) |
| 844 | gtp_reset_guitar(ts, 10); |
| 845 | else |
| 846 | /* wakeup by slide */ |
| 847 | doze_status = DOZE_DISABLED; |
| 848 | #else |
| 849 | if (chip_gt9xxs == 1) { |
| 850 | gtp_reset_guitar(ts, 10); |
| 851 | } else { |
| 852 | ret = gpio_direction_output(ts->pdata->irq_gpio, 1); |
| 853 | usleep(5000); |
| 854 | } |
| 855 | #endif |
| 856 | ret = gtp_i2c_test(ts->client); |
| 857 | if (ret > 0) { |
| 858 | dev_dbg(&ts->client->dev, "GTP wakeup sleep."); |
| 859 | #if (!GTP_SLIDE_WAKEUP) |
| 860 | if (chip_gt9xxs == 0) { |
| 861 | gtp_int_sync(ts, 25); |
| 862 | msleep(20); |
| 863 | #if GTP_ESD_PROTECT |
| 864 | gtp_init_ext_watchdog(ts->client); |
| 865 | #endif |
| 866 | } |
| 867 | #endif |
| 868 | return ret; |
| 869 | } |
| 870 | gtp_reset_guitar(ts, 20); |
| 871 | } |
| 872 | #endif |
| 873 | |
| 874 | dev_err(&ts->client->dev, "GTP wakeup sleep failed.\n"); |
| 875 | return ret; |
| 876 | } |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 877 | #endif /* !CONFIG_HAS_EARLYSUSPEND && !CONFIG_FB*/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 878 | |
| 879 | /******************************************************* |
| 880 | Function: |
| 881 | Initialize gtp. |
| 882 | Input: |
| 883 | ts: goodix private data |
| 884 | Output: |
| 885 | Executive outcomes. |
| 886 | > =0: succeed, otherwise: failed |
| 887 | *******************************************************/ |
| 888 | static int gtp_init_panel(struct goodix_ts_data *ts) |
| 889 | { |
| 890 | struct i2c_client *client = ts->client; |
| 891 | unsigned char *config_data; |
| 892 | int ret = -EIO; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 893 | |
| 894 | #if GTP_DRIVER_SEND_CFG |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 895 | int i; |
| 896 | u8 check_sum = 0; |
| 897 | u8 opr_buf[16]; |
| 898 | u8 sensor_id = 0; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 899 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 900 | u8 cfg_info_group1[] = CTP_CFG_GROUP1; |
| 901 | u8 cfg_info_group2[] = CTP_CFG_GROUP2; |
| 902 | u8 cfg_info_group3[] = CTP_CFG_GROUP3; |
| 903 | u8 cfg_info_group4[] = CTP_CFG_GROUP4; |
| 904 | u8 cfg_info_group5[] = CTP_CFG_GROUP5; |
| 905 | u8 cfg_info_group6[] = CTP_CFG_GROUP6; |
| 906 | u8 *send_cfg_buf[] = {cfg_info_group1, cfg_info_group2, |
| 907 | cfg_info_group3, cfg_info_group4, |
| 908 | cfg_info_group5, cfg_info_group6}; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 909 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 910 | u8 cfg_info_len[] = {CFG_GROUP_LEN(cfg_info_group1), |
| 911 | CFG_GROUP_LEN(cfg_info_group2), |
| 912 | CFG_GROUP_LEN(cfg_info_group3), |
| 913 | CFG_GROUP_LEN(cfg_info_group4), |
| 914 | CFG_GROUP_LEN(cfg_info_group5), |
| 915 | CFG_GROUP_LEN(cfg_info_group6)}; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 916 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 917 | GTP_DEBUG("Config Groups\' Lengths: %d, %d, %d, %d, %d, %d", |
| 918 | cfg_info_len[0], cfg_info_len[1], cfg_info_len[2], |
| 919 | cfg_info_len[3], cfg_info_len[4], cfg_info_len[5]); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 920 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 921 | ret = gtp_i2c_read_dbl_check(ts->client, 0x41E4, opr_buf, 1); |
| 922 | if (SUCCESS == ret) { |
| 923 | if (opr_buf[0] != 0xBE) { |
| 924 | ts->fw_error = 1; |
| 925 | dev_err(&client->dev, |
| 926 | "Firmware error, no config sent!"); |
| 927 | return -EINVAL; |
| 928 | } |
| 929 | } |
| 930 | if ((!cfg_info_len[1]) && (!cfg_info_len[2]) && (!cfg_info_len[3]) |
| 931 | && (!cfg_info_len[4]) && (!cfg_info_len[5])) { |
| 932 | sensor_id = 0; |
| 933 | } else { |
| 934 | ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID, |
| 935 | &sensor_id, 1); |
| 936 | if (SUCCESS == ret) { |
| 937 | if (sensor_id >= 0x06) { |
| 938 | dev_err(&client->dev, |
| 939 | "Invalid sensor_id(0x%02X), No Config Sent!", |
| 940 | sensor_id); |
| 941 | return -EINVAL; |
| 942 | } |
| 943 | } else { |
| 944 | dev_err(&client->dev, |
| 945 | "Failed to get sensor_id, No config sent!"); |
| 946 | return -EINVAL; |
| 947 | } |
| 948 | } |
| 949 | GTP_DEBUG("Sensor_ID: %d", sensor_id); |
| 950 | |
| 951 | ts->gtp_cfg_len = cfg_info_len[sensor_id]; |
| 952 | |
| 953 | if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH) { |
| 954 | dev_err(&client->dev, |
| 955 | "Sensor_ID(%d) matches with NULL or INVALID CONFIG GROUP! NO Config Sent! You need to check you header file CFG_GROUP section!\n", |
| 956 | sensor_id); |
| 957 | return -EINVAL; |
| 958 | } |
| 959 | ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA, |
| 960 | &opr_buf[0], 1); |
| 961 | |
| 962 | if (ret == SUCCESS) { |
| 963 | if (opr_buf[0] < 90) { |
| 964 | /* backup group config version */ |
| 965 | grp_cfg_version = send_cfg_buf[sensor_id][0]; |
| 966 | send_cfg_buf[sensor_id][0] = 0x00; |
| 967 | ts->fixed_cfg = 0; |
| 968 | } else { |
| 969 | /* treated as fixed config, not send config */ |
| 970 | dev_warn(&client->dev, |
| 971 | "Ic fixed config with config version(%d, 0x%02X)", |
| 972 | opr_buf[0], opr_buf[0]); |
| 973 | ts->fixed_cfg = 1; |
| 974 | } |
| 975 | } else { |
| 976 | dev_err(&client->dev, |
| 977 | "Failed to get ic config version!No config sent!"); |
| 978 | return -EINVAL; |
| 979 | } |
| 980 | |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 981 | if (ts->pdata->gtp_cfg_len) { |
| 982 | config_data = ts->pdata->config_data; |
| 983 | ts->config_data = ts->pdata->config_data; |
| 984 | ts->gtp_cfg_len = ts->pdata->gtp_cfg_len; |
| 985 | } else { |
| 986 | config_data = devm_kzalloc(&client->dev, |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 987 | GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH, |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 988 | GFP_KERNEL); |
| 989 | if (!config_data) { |
| 990 | dev_err(&client->dev, |
| 991 | "Not enough memory for panel config data\n"); |
| 992 | return -ENOMEM; |
| 993 | } |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 994 | |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 995 | ts->config_data = config_data; |
| 996 | config_data[0] = GTP_REG_CONFIG_DATA >> 8; |
| 997 | config_data[1] = GTP_REG_CONFIG_DATA & 0xff; |
| 998 | memset(&config_data[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); |
| 999 | memcpy(&config_data[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], |
| 1000 | ts->gtp_cfg_len); |
| 1001 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1002 | |
| 1003 | #if GTP_CUSTOM_CFG |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1004 | config_data[RESOLUTION_LOC] = |
| 1005 | (unsigned char)(GTP_MAX_WIDTH && 0xFF); |
| 1006 | config_data[RESOLUTION_LOC + 1] = |
| 1007 | (unsigned char)(GTP_MAX_WIDTH >> 8); |
| 1008 | config_data[RESOLUTION_LOC + 2] = |
| 1009 | (unsigned char)(GTP_MAX_HEIGHT && 0xFF); |
| 1010 | config_data[RESOLUTION_LOC + 3] = |
| 1011 | (unsigned char)(GTP_MAX_HEIGHT >> 8); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1012 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1013 | if (GTP_INT_TRIGGER == 0) |
| 1014 | config_data[TRIGGER_LOC] &= 0xfe; |
| 1015 | else if (GTP_INT_TRIGGER == 1) |
| 1016 | config_data[TRIGGER_LOC] |= 0x01; |
| 1017 | #endif /* !GTP_CUSTOM_CFG */ |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1018 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1019 | check_sum = 0; |
| 1020 | for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++) |
| 1021 | check_sum += config_data[i]; |
| 1022 | |
| 1023 | config_data[ts->gtp_cfg_len] = (~check_sum) + 1; |
| 1024 | |
| 1025 | #else /* DRIVER NOT SEND CONFIG */ |
| 1026 | ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH; |
| 1027 | ret = gtp_i2c_read(ts->client, config_data, |
| 1028 | ts->gtp_cfg_len + GTP_ADDR_LENGTH); |
| 1029 | if (ret < 0) { |
| 1030 | dev_err(&client->dev, |
| 1031 | "Read Config Failed, Using DEFAULT Resolution & INT Trigger!\n"); |
| 1032 | ts->abs_x_max = GTP_MAX_WIDTH; |
| 1033 | ts->abs_y_max = GTP_MAX_HEIGHT; |
| 1034 | ts->int_trigger_type = GTP_INT_TRIGGER; |
| 1035 | } |
| 1036 | #endif /* !DRIVER NOT SEND CONFIG */ |
| 1037 | |
| 1038 | GTP_DEBUG_FUNC(); |
| 1039 | if ((ts->abs_x_max == 0) && (ts->abs_y_max == 0)) { |
| 1040 | ts->abs_x_max = (config_data[RESOLUTION_LOC + 1] << 8) |
| 1041 | + config_data[RESOLUTION_LOC]; |
| 1042 | ts->abs_y_max = (config_data[RESOLUTION_LOC + 3] << 8) |
| 1043 | + config_data[RESOLUTION_LOC + 2]; |
| 1044 | ts->int_trigger_type = (config_data[TRIGGER_LOC]) & 0x03; |
| 1045 | } |
| 1046 | ret = gtp_send_cfg(ts); |
| 1047 | if (ret < 0) |
| 1048 | dev_err(&client->dev, "%s: Send config error.\n", __func__); |
| 1049 | |
| 1050 | GTP_DEBUG("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x", |
| 1051 | ts->abs_x_max, ts->abs_y_max, |
| 1052 | ts->int_trigger_type); |
| 1053 | |
| 1054 | msleep(20); |
| 1055 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | /******************************************************* |
| 1059 | Function: |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1060 | Read firmware version |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1061 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1062 | client: i2c device |
| 1063 | version: buffer to keep ic firmware version |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1064 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1065 | read operation return. |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1066 | 0: succeed, otherwise: failed |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1067 | *******************************************************/ |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1068 | static int gtp_read_fw_version(struct i2c_client *client, u16 *version) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1069 | { |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1070 | int ret = 0; |
| 1071 | u8 buf[GTP_FW_VERSION_BUFFER_MAXSIZE] = { |
| 1072 | GTP_REG_FW_VERSION >> 8, GTP_REG_FW_VERSION & 0xff }; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1073 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1074 | ret = gtp_i2c_read(client, buf, sizeof(buf)); |
| 1075 | if (ret < 0) { |
| 1076 | dev_err(&client->dev, "GTP read version failed.\n"); |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1077 | return -EIO; |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1078 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1079 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1080 | if (version) |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1081 | *version = (buf[3] << 8) | buf[2]; |
| 1082 | |
| 1083 | return ret; |
| 1084 | } |
| 1085 | /******************************************************* |
| 1086 | Function: |
| 1087 | Read and check chip id. |
| 1088 | Input: |
| 1089 | client: i2c device |
| 1090 | Output: |
| 1091 | read operation return. |
| 1092 | 0: succeed, otherwise: failed |
| 1093 | *******************************************************/ |
| 1094 | static int gtp_check_product_id(struct i2c_client *client) |
| 1095 | { |
| 1096 | int ret = 0; |
| 1097 | char product_id[GTP_PRODUCT_ID_MAXSIZE]; |
| 1098 | struct goodix_ts_data *ts = i2c_get_clientdata(client); |
| 1099 | /* 04 bytes are used for the Product-id in the register space.*/ |
| 1100 | u8 buf[GTP_PRODUCT_ID_BUFFER_MAXSIZE] = { |
| 1101 | GTP_REG_PRODUCT_ID >> 8, GTP_REG_PRODUCT_ID & 0xff }; |
| 1102 | |
| 1103 | ret = gtp_i2c_read(client, buf, sizeof(buf)); |
| 1104 | if (ret < 0) { |
| 1105 | dev_err(&client->dev, "GTP read version failed.\n"); |
| 1106 | return -EIO; |
| 1107 | } |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1108 | |
| 1109 | if (buf[5] == 0x00) { |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1110 | /* copy (GTP_PRODUCT_ID_MAXSIZE - 1) from buffer. Ex: 915 */ |
| 1111 | strlcpy(product_id, &buf[2], GTP_PRODUCT_ID_MAXSIZE - 1); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1112 | } else { |
| 1113 | if (buf[5] == 'S' || buf[5] == 's') |
| 1114 | chip_gt9xxs = 1; |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1115 | /* copy GTP_PRODUCT_ID_MAXSIZE from buffer. Ex: 915s */ |
| 1116 | strlcpy(product_id, &buf[2], GTP_PRODUCT_ID_MAXSIZE); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1117 | } |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1118 | |
| 1119 | dev_info(&client->dev, "Goodix Product ID = %s\n", product_id); |
| 1120 | |
| 1121 | if (!IS_ERR(ts->pdata->product_id)) |
| 1122 | ret = strcmp(product_id, ts->pdata->product_id); |
| 1123 | |
| 1124 | if (ret != 0) |
| 1125 | return -EINVAL; |
| 1126 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1127 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | /******************************************************* |
| 1131 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1132 | I2c test Function. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1133 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1134 | client:i2c client. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1135 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1136 | Executive outcomes. |
| 1137 | 2: succeed, otherwise failed. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1138 | *******************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1139 | static int gtp_i2c_test(struct i2c_client *client) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1140 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1141 | u8 buf[3] = { GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff }; |
| 1142 | int retry = 5; |
| 1143 | int ret = -EIO; |
| 1144 | |
| 1145 | GTP_DEBUG_FUNC(); |
| 1146 | |
| 1147 | while (retry--) { |
| 1148 | ret = gtp_i2c_read(client, buf, 3); |
| 1149 | if (ret > 0) |
| 1150 | return ret; |
| 1151 | dev_err(&client->dev, "GTP i2c test failed time %d.\n", retry); |
| 1152 | msleep(20); |
| 1153 | } |
| 1154 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | /******************************************************* |
| 1158 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1159 | Request gpio(INT & RST) ports. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1160 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1161 | ts: private data. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1162 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1163 | Executive outcomes. |
| 1164 | = 0: succeed, != 0: failed |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1165 | *******************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1166 | static int gtp_request_io_port(struct goodix_ts_data *ts) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1167 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1168 | struct i2c_client *client = ts->client; |
| 1169 | struct goodix_ts_platform_data *pdata = ts->pdata; |
| 1170 | int ret; |
| 1171 | if (gpio_is_valid(pdata->irq_gpio)) { |
| 1172 | ret = gpio_request(pdata->irq_gpio, "goodix_ts_irq_gpio"); |
| 1173 | if (ret) { |
| 1174 | dev_err(&client->dev, "irq gpio request failed\n"); |
| 1175 | goto pwr_off; |
| 1176 | } |
| 1177 | ret = gpio_direction_input(pdata->irq_gpio); |
| 1178 | if (ret) { |
| 1179 | dev_err(&client->dev, |
| 1180 | "set_direction for irq gpio failed\n"); |
| 1181 | goto free_irq_gpio; |
| 1182 | } |
| 1183 | } else { |
| 1184 | dev_err(&client->dev, "irq gpio is invalid!\n"); |
| 1185 | ret = -EINVAL; |
| 1186 | goto free_irq_gpio; |
| 1187 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1188 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1189 | if (gpio_is_valid(pdata->reset_gpio)) { |
| 1190 | ret = gpio_request(pdata->reset_gpio, "goodix_ts__reset_gpio"); |
| 1191 | if (ret) { |
| 1192 | dev_err(&client->dev, "reset gpio request failed\n"); |
| 1193 | goto free_irq_gpio; |
| 1194 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1195 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1196 | ret = gpio_direction_output(pdata->reset_gpio, 0); |
| 1197 | if (ret) { |
| 1198 | dev_err(&client->dev, |
| 1199 | "set_direction for reset gpio failed\n"); |
| 1200 | goto free_reset_gpio; |
| 1201 | } |
| 1202 | } else { |
| 1203 | dev_err(&client->dev, "reset gpio is invalid!\n"); |
| 1204 | ret = -EINVAL; |
| 1205 | goto free_reset_gpio; |
| 1206 | } |
| 1207 | gpio_direction_input(pdata->reset_gpio); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1208 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1209 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1210 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1211 | free_reset_gpio: |
| 1212 | if (gpio_is_valid(pdata->reset_gpio)) |
| 1213 | gpio_free(pdata->reset_gpio); |
| 1214 | free_irq_gpio: |
| 1215 | if (gpio_is_valid(pdata->irq_gpio)) |
| 1216 | gpio_free(pdata->irq_gpio); |
| 1217 | pwr_off: |
| 1218 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | /******************************************************* |
| 1222 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1223 | Request interrupt. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1224 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1225 | ts: private data. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1226 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1227 | Executive outcomes. |
| 1228 | 0: succeed, -1: failed. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1229 | *******************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1230 | static int gtp_request_irq(struct goodix_ts_data *ts) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1231 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1232 | int ret; |
| 1233 | const u8 irq_table[] = GTP_IRQ_TAB; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1234 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1235 | GTP_DEBUG("INT trigger type:%x, irq=%d", ts->int_trigger_type, |
| 1236 | ts->client->irq); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1237 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1238 | ret = request_irq(ts->client->irq, goodix_ts_irq_handler, |
| 1239 | irq_table[ts->int_trigger_type], |
| 1240 | ts->client->name, ts); |
| 1241 | if (ret) { |
| 1242 | dev_err(&ts->client->dev, "Request IRQ failed!ERRNO:%d.\n", |
| 1243 | ret); |
| 1244 | gpio_direction_input(ts->pdata->irq_gpio); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1245 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1246 | hrtimer_init(&ts->timer, CLOCK_MONOTONIC, |
| 1247 | HRTIMER_MODE_REL); |
| 1248 | ts->timer.function = goodix_ts_timer_handler; |
| 1249 | hrtimer_start(&ts->timer, ktime_set(1, 0), |
| 1250 | HRTIMER_MODE_REL); |
| 1251 | ts->use_irq = false; |
| 1252 | return ret; |
| 1253 | } else { |
| 1254 | gtp_irq_disable(ts); |
| 1255 | ts->use_irq = true; |
| 1256 | return 0; |
| 1257 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | /******************************************************* |
| 1261 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1262 | Request input device Function. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1263 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1264 | ts:private data. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1265 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1266 | Executive outcomes. |
| 1267 | 0: succeed, otherwise: failed. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1268 | *******************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1269 | static int gtp_request_input_dev(struct goodix_ts_data *ts) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1270 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1271 | int ret; |
| 1272 | char phys[PHY_BUF_SIZE]; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1273 | #if GTP_HAVE_TOUCH_KEY |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1274 | int index = 0; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1275 | #endif |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1276 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1277 | GTP_DEBUG_FUNC(); |
| 1278 | |
| 1279 | ts->input_dev = input_allocate_device(); |
| 1280 | if (ts->input_dev == NULL) { |
| 1281 | dev_err(&ts->client->dev, |
| 1282 | "Failed to allocate input device.\n"); |
| 1283 | return -ENOMEM; |
| 1284 | } |
| 1285 | |
| 1286 | ts->input_dev->evbit[0] = |
| 1287 | BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ; |
Bingzhe Cai | 6beb011 | 2013-08-27 00:27:26 +0800 | [diff] [blame] | 1288 | set_bit(BTN_TOOL_FINGER, ts->input_dev->keybit); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1289 | __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit); |
| 1290 | input_mt_init_slots(ts->input_dev, 10);/* in case of "out of memory" */ |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1291 | |
| 1292 | #if GTP_HAVE_TOUCH_KEY |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1293 | for (index = 0; index < GTP_MAX_KEY_NUM; index++) { |
| 1294 | input_set_capability(ts->input_dev, |
| 1295 | EV_KEY, touch_key_array[index]); |
| 1296 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1297 | #endif |
| 1298 | |
| 1299 | #if GTP_SLIDE_WAKEUP |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1300 | input_set_capability(ts->input_dev, EV_KEY, KEY_POWER); |
| 1301 | #endif |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1302 | |
| 1303 | #if GTP_WITH_PEN |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1304 | /* pen support */ |
| 1305 | __set_bit(BTN_TOOL_PEN, ts->input_dev->keybit); |
| 1306 | __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit); |
| 1307 | __set_bit(INPUT_PROP_POINTER, ts->input_dev->propbit); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1308 | #endif |
| 1309 | |
| 1310 | #if GTP_CHANGE_X2Y |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1311 | GTP_SWAP(ts->abs_x_max, ts->abs_y_max); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1312 | #endif |
| 1313 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1314 | input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, |
| 1315 | 0, ts->abs_x_max, 0, 0); |
| 1316 | input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, |
| 1317 | 0, ts->abs_y_max, 0, 0); |
| 1318 | input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, |
| 1319 | 0, 255, 0, 0); |
| 1320 | input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, |
| 1321 | 0, 255, 0, 0); |
| 1322 | input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, |
| 1323 | 0, 255, 0, 0); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1324 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1325 | snprintf(phys, PHY_BUF_SIZE, "input/ts"); |
| 1326 | ts->input_dev->name = GOODIX_DEV_NAME; |
| 1327 | ts->input_dev->phys = phys; |
| 1328 | ts->input_dev->id.bustype = BUS_I2C; |
| 1329 | ts->input_dev->id.vendor = 0xDEAD; |
| 1330 | ts->input_dev->id.product = 0xBEEF; |
| 1331 | ts->input_dev->id.version = 10427; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1332 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1333 | ret = input_register_device(ts->input_dev); |
| 1334 | if (ret) { |
| 1335 | dev_err(&ts->client->dev, |
| 1336 | "Register %s input device failed.\n", |
| 1337 | ts->input_dev->name); |
| 1338 | goto exit_free_inputdev; |
| 1339 | } |
| 1340 | |
| 1341 | return 0; |
| 1342 | |
| 1343 | exit_free_inputdev: |
| 1344 | input_free_device(ts->input_dev); |
| 1345 | ts->input_dev = NULL; |
| 1346 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
Bingzhe Cai | c68e611 | 2013-07-22 00:12:48 +0800 | [diff] [blame] | 1349 | static int reg_set_optimum_mode_check(struct regulator *reg, int load_uA) |
| 1350 | { |
| 1351 | return (regulator_count_voltages(reg) > 0) ? |
| 1352 | regulator_set_optimum_mode(reg, load_uA) : 0; |
| 1353 | } |
| 1354 | |
| 1355 | /** |
| 1356 | * goodix_power_on - Turn device power ON |
| 1357 | * @ts: driver private data |
| 1358 | * |
| 1359 | * Returns zero on success, else an error. |
| 1360 | */ |
| 1361 | static int goodix_power_on(struct goodix_ts_data *ts) |
| 1362 | { |
| 1363 | int ret; |
| 1364 | |
| 1365 | if (!IS_ERR(ts->avdd)) { |
| 1366 | ret = reg_set_optimum_mode_check(ts->avdd, |
| 1367 | GOODIX_VDD_LOAD_MAX_UA); |
| 1368 | if (ret < 0) { |
| 1369 | dev_err(&ts->client->dev, |
| 1370 | "Regulator avdd set_opt failed rc=%d\n", ret); |
| 1371 | goto err_set_opt_avdd; |
| 1372 | } |
| 1373 | ret = regulator_enable(ts->avdd); |
| 1374 | if (ret) { |
| 1375 | dev_err(&ts->client->dev, |
| 1376 | "Regulator avdd enable failed ret=%d\n", ret); |
| 1377 | goto err_enable_avdd; |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | if (!IS_ERR(ts->vdd)) { |
| 1382 | ret = regulator_set_voltage(ts->vdd, GOODIX_VTG_MIN_UV, |
| 1383 | GOODIX_VTG_MAX_UV); |
| 1384 | if (ret) { |
| 1385 | dev_err(&ts->client->dev, |
| 1386 | "Regulator set_vtg failed vdd ret=%d\n", ret); |
| 1387 | goto err_set_vtg_vdd; |
| 1388 | } |
| 1389 | ret = reg_set_optimum_mode_check(ts->vdd, |
| 1390 | GOODIX_VDD_LOAD_MAX_UA); |
| 1391 | if (ret < 0) { |
| 1392 | dev_err(&ts->client->dev, |
| 1393 | "Regulator vdd set_opt failed rc=%d\n", ret); |
| 1394 | goto err_set_opt_vdd; |
| 1395 | } |
| 1396 | ret = regulator_enable(ts->vdd); |
| 1397 | if (ret) { |
| 1398 | dev_err(&ts->client->dev, |
| 1399 | "Regulator vdd enable failed ret=%d\n", ret); |
| 1400 | goto err_enable_vdd; |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | if (!IS_ERR(ts->vcc_i2c)) { |
| 1405 | ret = regulator_set_voltage(ts->vcc_i2c, GOODIX_I2C_VTG_MIN_UV, |
| 1406 | GOODIX_I2C_VTG_MAX_UV); |
| 1407 | if (ret) { |
| 1408 | dev_err(&ts->client->dev, |
| 1409 | "Regulator set_vtg failed vcc_i2c ret=%d\n", |
| 1410 | ret); |
| 1411 | goto err_set_vtg_vcc_i2c; |
| 1412 | } |
| 1413 | ret = reg_set_optimum_mode_check(ts->vcc_i2c, |
| 1414 | GOODIX_VIO_LOAD_MAX_UA); |
| 1415 | if (ret < 0) { |
| 1416 | dev_err(&ts->client->dev, |
| 1417 | "Regulator vcc_i2c set_opt failed rc=%d\n", |
| 1418 | ret); |
| 1419 | goto err_set_opt_vcc_i2c; |
| 1420 | } |
| 1421 | ret = regulator_enable(ts->vcc_i2c); |
| 1422 | if (ret) { |
| 1423 | dev_err(&ts->client->dev, |
| 1424 | "Regulator vcc_i2c enable failed ret=%d\n", |
| 1425 | ret); |
| 1426 | regulator_disable(ts->vdd); |
| 1427 | goto err_enable_vcc_i2c; |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | return 0; |
| 1432 | |
| 1433 | err_enable_vcc_i2c: |
| 1434 | err_set_opt_vcc_i2c: |
| 1435 | if (!IS_ERR(ts->vcc_i2c)) |
| 1436 | regulator_set_voltage(ts->vcc_i2c, 0, GOODIX_I2C_VTG_MAX_UV); |
| 1437 | err_set_vtg_vcc_i2c: |
| 1438 | if (!IS_ERR(ts->vdd)) |
| 1439 | regulator_disable(ts->vdd); |
| 1440 | err_enable_vdd: |
| 1441 | err_set_opt_vdd: |
| 1442 | if (!IS_ERR(ts->vdd)) |
| 1443 | regulator_set_voltage(ts->vdd, 0, GOODIX_VTG_MAX_UV); |
| 1444 | err_set_vtg_vdd: |
| 1445 | if (!IS_ERR(ts->avdd)) |
| 1446 | regulator_disable(ts->avdd); |
| 1447 | err_enable_avdd: |
| 1448 | err_set_opt_avdd: |
| 1449 | return ret; |
| 1450 | } |
| 1451 | |
| 1452 | /** |
| 1453 | * goodix_power_off - Turn device power OFF |
| 1454 | * @ts: driver private data |
| 1455 | * |
| 1456 | * Returns zero on success, else an error. |
| 1457 | */ |
| 1458 | static int goodix_power_off(struct goodix_ts_data *ts) |
| 1459 | { |
| 1460 | int ret; |
| 1461 | |
| 1462 | if (!IS_ERR(ts->vcc_i2c)) { |
| 1463 | ret = regulator_set_voltage(ts->vcc_i2c, 0, |
| 1464 | GOODIX_I2C_VTG_MAX_UV); |
| 1465 | if (ret < 0) |
| 1466 | dev_err(&ts->client->dev, |
| 1467 | "Regulator vcc_i2c set_vtg failed ret=%d\n", |
| 1468 | ret); |
| 1469 | ret = regulator_disable(ts->vcc_i2c); |
| 1470 | if (ret) |
| 1471 | dev_err(&ts->client->dev, |
| 1472 | "Regulator vcc_i2c disable failed ret=%d\n", |
| 1473 | ret); |
| 1474 | } |
| 1475 | |
| 1476 | if (!IS_ERR(ts->vdd)) { |
| 1477 | ret = regulator_set_voltage(ts->vdd, 0, GOODIX_VTG_MAX_UV); |
| 1478 | if (ret < 0) |
| 1479 | dev_err(&ts->client->dev, |
| 1480 | "Regulator vdd set_vtg failed ret=%d\n", ret); |
| 1481 | ret = regulator_disable(ts->vdd); |
| 1482 | if (ret) |
| 1483 | dev_err(&ts->client->dev, |
| 1484 | "Regulator vdd disable failed ret=%d\n", ret); |
| 1485 | } |
| 1486 | |
| 1487 | if (!IS_ERR(ts->avdd)) { |
| 1488 | ret = regulator_disable(ts->avdd); |
| 1489 | if (ret) |
| 1490 | dev_err(&ts->client->dev, |
| 1491 | "Regulator avdd disable failed ret=%d\n", ret); |
| 1492 | } |
| 1493 | |
| 1494 | return 0; |
| 1495 | } |
| 1496 | |
| 1497 | /** |
| 1498 | * goodix_power_init - Initialize device power |
| 1499 | * @ts: driver private data |
| 1500 | * |
| 1501 | * Returns zero on success, else an error. |
| 1502 | */ |
| 1503 | static int goodix_power_init(struct goodix_ts_data *ts) |
| 1504 | { |
| 1505 | int ret; |
| 1506 | |
| 1507 | ts->avdd = regulator_get(&ts->client->dev, "avdd"); |
| 1508 | if (IS_ERR(ts->avdd)) { |
| 1509 | ret = PTR_ERR(ts->avdd); |
| 1510 | dev_info(&ts->client->dev, |
| 1511 | "Regulator get failed avdd ret=%d\n", ret); |
| 1512 | } |
| 1513 | |
| 1514 | ts->vdd = regulator_get(&ts->client->dev, "vdd"); |
| 1515 | if (IS_ERR(ts->vdd)) { |
| 1516 | ret = PTR_ERR(ts->vdd); |
| 1517 | dev_info(&ts->client->dev, |
| 1518 | "Regulator get failed vdd ret=%d\n", ret); |
| 1519 | } |
| 1520 | |
| 1521 | ts->vcc_i2c = regulator_get(&ts->client->dev, "vcc-i2c"); |
| 1522 | if (IS_ERR(ts->vcc_i2c)) { |
| 1523 | ret = PTR_ERR(ts->vcc_i2c); |
| 1524 | dev_info(&ts->client->dev, |
| 1525 | "Regulator get failed vcc_i2c ret=%d\n", ret); |
| 1526 | } |
| 1527 | |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
| 1531 | /** |
| 1532 | * goodix_power_deinit - Deinitialize device power |
| 1533 | * @ts: driver private data |
| 1534 | * |
| 1535 | * Returns zero on success, else an error. |
| 1536 | */ |
| 1537 | static int goodix_power_deinit(struct goodix_ts_data *ts) |
| 1538 | { |
| 1539 | regulator_put(ts->vdd); |
| 1540 | regulator_put(ts->vcc_i2c); |
| 1541 | regulator_put(ts->avdd); |
| 1542 | |
| 1543 | return 0; |
| 1544 | } |
| 1545 | |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 1546 | static int goodix_ts_get_dt_coords(struct device *dev, char *name, |
| 1547 | struct goodix_ts_platform_data *pdata) |
| 1548 | { |
| 1549 | struct property *prop; |
| 1550 | struct device_node *np = dev->of_node; |
| 1551 | int rc; |
| 1552 | u32 coords[GOODIX_COORDS_ARR_SIZE]; |
| 1553 | |
| 1554 | prop = of_find_property(np, name, NULL); |
| 1555 | if (!prop) |
| 1556 | return -EINVAL; |
| 1557 | if (!prop->value) |
| 1558 | return -ENODATA; |
| 1559 | |
| 1560 | rc = of_property_read_u32_array(np, name, coords, |
| 1561 | GOODIX_COORDS_ARR_SIZE); |
| 1562 | if (rc && (rc != -EINVAL)) { |
| 1563 | dev_err(dev, "Unable to read %s\n", name); |
| 1564 | return rc; |
| 1565 | } |
| 1566 | |
| 1567 | if (!strcmp(name, "goodix,panel-coords")) { |
| 1568 | pdata->panel_minx = coords[0]; |
| 1569 | pdata->panel_miny = coords[1]; |
| 1570 | pdata->panel_maxx = coords[2]; |
| 1571 | pdata->panel_maxy = coords[3]; |
| 1572 | } else if (!strcmp(name, "goodix,display-coords")) { |
| 1573 | pdata->x_min = coords[0]; |
| 1574 | pdata->y_min = coords[1]; |
| 1575 | pdata->x_max = coords[2]; |
| 1576 | pdata->y_max = coords[3]; |
| 1577 | } else { |
| 1578 | dev_err(dev, "unsupported property %s\n", name); |
| 1579 | return -EINVAL; |
| 1580 | } |
| 1581 | |
| 1582 | return 0; |
| 1583 | } |
| 1584 | |
| 1585 | static int goodix_parse_dt(struct device *dev, |
| 1586 | struct goodix_ts_platform_data *pdata) |
| 1587 | { |
| 1588 | int rc; |
| 1589 | struct device_node *np = dev->of_node; |
| 1590 | struct property *prop; |
| 1591 | u32 temp_val, num_buttons; |
| 1592 | u32 button_map[MAX_BUTTONS]; |
| 1593 | |
| 1594 | rc = goodix_ts_get_dt_coords(dev, "goodix,panel-coords", pdata); |
| 1595 | if (rc && (rc != -EINVAL)) |
| 1596 | return rc; |
| 1597 | |
| 1598 | rc = goodix_ts_get_dt_coords(dev, "goodix,display-coords", pdata); |
| 1599 | if (rc) |
| 1600 | return rc; |
| 1601 | |
| 1602 | pdata->i2c_pull_up = of_property_read_bool(np, |
| 1603 | "goodix,i2c-pull-up"); |
| 1604 | |
| 1605 | pdata->no_force_update = of_property_read_bool(np, |
| 1606 | "goodix,no-force-update"); |
| 1607 | /* reset, irq gpio info */ |
| 1608 | pdata->reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", |
| 1609 | 0, &pdata->reset_gpio_flags); |
| 1610 | if (pdata->reset_gpio < 0) |
| 1611 | return pdata->reset_gpio; |
| 1612 | |
| 1613 | pdata->irq_gpio = of_get_named_gpio_flags(np, "interrupt-gpios", |
| 1614 | 0, &pdata->irq_gpio_flags); |
| 1615 | if (pdata->irq_gpio < 0) |
| 1616 | return pdata->irq_gpio; |
| 1617 | |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1618 | rc = of_property_read_string(np, "goodix,product-id", |
| 1619 | &pdata->product_id); |
| 1620 | if (rc < 0 || strlen(pdata->product_id) > GTP_PRODUCT_ID_MAXSIZE) |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 1621 | return rc; |
| 1622 | |
| 1623 | prop = of_find_property(np, "goodix,button-map", NULL); |
| 1624 | if (prop) { |
| 1625 | num_buttons = prop->length / sizeof(temp_val); |
| 1626 | if (num_buttons > MAX_BUTTONS) |
| 1627 | return -EINVAL; |
| 1628 | |
| 1629 | rc = of_property_read_u32_array(np, |
| 1630 | "goodix,button-map", button_map, |
| 1631 | num_buttons); |
| 1632 | if (rc) { |
| 1633 | dev_err(dev, "Unable to read key codes\n"); |
| 1634 | return rc; |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | prop = of_find_property(np, "goodix,cfg-data", &pdata->gtp_cfg_len); |
| 1639 | if (prop && prop->value) { |
| 1640 | pdata->config_data = devm_kzalloc(dev, |
| 1641 | GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH, GFP_KERNEL); |
| 1642 | if (!pdata->config_data) { |
| 1643 | dev_err(dev, "Not enough memory for panel config data\n"); |
| 1644 | return -ENOMEM; |
| 1645 | } |
| 1646 | |
| 1647 | pdata->config_data[0] = GTP_REG_CONFIG_DATA >> 8; |
| 1648 | pdata->config_data[1] = GTP_REG_CONFIG_DATA & 0xff; |
| 1649 | memset(&pdata->config_data[GTP_ADDR_LENGTH], 0, |
| 1650 | GTP_CONFIG_MAX_LENGTH); |
| 1651 | memcpy(&pdata->config_data[GTP_ADDR_LENGTH], |
| 1652 | prop->value, pdata->gtp_cfg_len); |
| 1653 | } else { |
| 1654 | dev_err(dev, |
| 1655 | "Unable to get configure data, default will be used.\n"); |
| 1656 | pdata->gtp_cfg_len = 0; |
| 1657 | } |
| 1658 | |
| 1659 | return 0; |
| 1660 | } |
Bingzhe Cai | c68e611 | 2013-07-22 00:12:48 +0800 | [diff] [blame] | 1661 | |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1662 | /******************************************************* |
| 1663 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1664 | I2c probe. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1665 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1666 | client: i2c device struct. |
| 1667 | id: device id. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1668 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1669 | Executive outcomes. |
| 1670 | 0: succeed. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1671 | *******************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1672 | |
| 1673 | static int goodix_ts_probe(struct i2c_client *client, |
| 1674 | const struct i2c_device_id *id) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1675 | { |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 1676 | struct goodix_ts_platform_data *pdata; |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1677 | struct goodix_ts_data *ts; |
| 1678 | u16 version_info; |
| 1679 | int ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1680 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1681 | dev_dbg(&client->dev, "GTP I2C Address: 0x%02x\n", client->addr); |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 1682 | if (client->dev.of_node) { |
| 1683 | pdata = devm_kzalloc(&client->dev, |
| 1684 | sizeof(struct goodix_ts_platform_data), GFP_KERNEL); |
| 1685 | if (!pdata) { |
| 1686 | dev_err(&client->dev, |
| 1687 | "GTP Failed to allocate memory for pdata\n"); |
| 1688 | return -ENOMEM; |
| 1689 | } |
| 1690 | |
| 1691 | ret = goodix_parse_dt(&client->dev, pdata); |
| 1692 | if (ret) |
| 1693 | return ret; |
| 1694 | } else { |
| 1695 | pdata = client->dev.platform_data; |
| 1696 | } |
| 1697 | |
| 1698 | if (!pdata) { |
| 1699 | dev_err(&client->dev, "GTP invalid pdata\n"); |
| 1700 | return -EINVAL; |
| 1701 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1702 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1703 | #if GTP_ESD_PROTECT |
| 1704 | i2c_connect_client = client; |
| 1705 | #endif |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 1706 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1707 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
| 1708 | dev_err(&client->dev, "GTP I2C not supported\n"); |
| 1709 | return -ENODEV; |
| 1710 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1711 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1712 | ts = kzalloc(sizeof(*ts), GFP_KERNEL); |
| 1713 | if (!ts) { |
| 1714 | dev_err(&client->dev, "GTP not enough memory for ts\n"); |
| 1715 | return -ENOMEM; |
| 1716 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1717 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1718 | memset(ts, 0, sizeof(*ts)); |
| 1719 | ts->client = client; |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 1720 | ts->pdata = pdata; |
| 1721 | /* For 2.6.39 & later use spin_lock_init(&ts->irq_lock) |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1722 | * For 2.6.39 & before, use ts->irq_lock = SPIN_LOCK_UNLOCKED |
| 1723 | */ |
| 1724 | spin_lock_init(&ts->irq_lock); |
| 1725 | i2c_set_clientdata(client, ts); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1726 | ts->gtp_rawdiff_mode = 0; |
| 1727 | |
Bingzhe Cai | c68e611 | 2013-07-22 00:12:48 +0800 | [diff] [blame] | 1728 | ret = goodix_power_init(ts); |
| 1729 | if (ret) { |
| 1730 | dev_err(&client->dev, "GTP power init failed\n"); |
| 1731 | goto exit_free_client_data; |
| 1732 | } |
| 1733 | |
| 1734 | ret = goodix_power_on(ts); |
| 1735 | if (ret) { |
| 1736 | dev_err(&client->dev, "GTP power on failed\n"); |
| 1737 | goto exit_deinit_power; |
| 1738 | } |
| 1739 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1740 | ret = gtp_request_io_port(ts); |
| 1741 | if (ret) { |
| 1742 | dev_err(&client->dev, "GTP request IO port failed.\n"); |
| 1743 | goto exit_power_off; |
| 1744 | } |
| 1745 | |
| 1746 | gtp_reset_guitar(ts, 20); |
| 1747 | |
| 1748 | ret = gtp_i2c_test(client); |
| 1749 | if (ret != 2) { |
| 1750 | dev_err(&client->dev, "I2C communication ERROR!\n"); |
| 1751 | goto exit_free_io_port; |
| 1752 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1753 | |
| 1754 | #if GTP_AUTO_UPDATE |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1755 | ret = gup_init_update_proc(ts); |
| 1756 | if (ret < 0) { |
| 1757 | dev_err(&client->dev, |
| 1758 | "GTP Create firmware update thread error.\n"); |
| 1759 | goto exit_free_io_port; |
| 1760 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1761 | #endif |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1762 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1763 | ret = gtp_init_panel(ts); |
| 1764 | if (ret < 0) { |
| 1765 | dev_err(&client->dev, "GTP init panel failed.\n"); |
| 1766 | ts->abs_x_max = GTP_MAX_WIDTH; |
| 1767 | ts->abs_y_max = GTP_MAX_HEIGHT; |
| 1768 | ts->int_trigger_type = GTP_INT_TRIGGER; |
| 1769 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1770 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1771 | ret = gtp_request_input_dev(ts); |
| 1772 | if (ret) { |
| 1773 | dev_err(&client->dev, "GTP request input dev failed.\n"); |
| 1774 | goto exit_free_inputdev; |
| 1775 | } |
| 1776 | |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 1777 | #if defined(CONFIG_FB) |
| 1778 | ts->fb_notif.notifier_call = fb_notifier_callback; |
| 1779 | ret = fb_register_client(&ts->fb_notif); |
| 1780 | if (ret) |
| 1781 | dev_err(&ts->client->dev, |
| 1782 | "Unable to register fb_notifier: %d\n", |
| 1783 | ret); |
| 1784 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
| 1785 | ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; |
| 1786 | ts->early_suspend.suspend = goodix_ts_early_suspend; |
| 1787 | ts->early_suspend.resume = goodix_ts_late_resume; |
| 1788 | register_early_suspend(&ts->early_suspend); |
| 1789 | #endif |
| 1790 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1791 | ts->goodix_wq = create_singlethread_workqueue("goodix_wq"); |
| 1792 | INIT_WORK(&ts->work, goodix_ts_work_func); |
| 1793 | |
| 1794 | ret = gtp_request_irq(ts); |
| 1795 | if (ret < 0) |
| 1796 | dev_info(&client->dev, "GTP works in polling mode.\n"); |
| 1797 | else |
| 1798 | dev_info(&client->dev, "GTP works in interrupt mode.\n"); |
| 1799 | |
Shantanu Jain | 3f80bef | 2013-09-18 12:05:02 +0530 | [diff] [blame^] | 1800 | ret = gtp_read_fw_version(client, &version_info); |
| 1801 | if (ret != 0) |
| 1802 | dev_err(&client->dev, "GTP firmware version read failed.\n"); |
| 1803 | |
| 1804 | ret = gtp_check_product_id(client); |
| 1805 | if (ret != 0) { |
| 1806 | dev_err(&client->dev, "GTP Product id doesn't match.\n"); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1807 | goto exit_free_irq; |
| 1808 | } |
| 1809 | if (ts->use_irq) |
| 1810 | gtp_irq_enable(ts); |
| 1811 | |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1812 | #if GTP_CREATE_WR_NODE |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1813 | init_wr_node(client); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1814 | #endif |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1815 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1816 | #if GTP_ESD_PROTECT |
| 1817 | gtp_esd_switch(client, SWITCH_ON); |
| 1818 | #endif |
| 1819 | init_done = true; |
| 1820 | return 0; |
| 1821 | exit_free_irq: |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 1822 | #if defined(CONFIG_FB) |
| 1823 | if (fb_unregister_client(&ts->fb_notif)) |
| 1824 | dev_err(&client->dev, |
| 1825 | "Error occurred while unregistering fb_notifier.\n"); |
| 1826 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
| 1827 | unregister_early_suspend(&ts->early_suspend); |
| 1828 | #endif |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1829 | if (ts->use_irq) |
| 1830 | free_irq(client->irq, ts); |
| 1831 | else |
| 1832 | hrtimer_cancel(&ts->timer); |
| 1833 | cancel_work_sync(&ts->work); |
| 1834 | flush_workqueue(ts->goodix_wq); |
| 1835 | destroy_workqueue(ts->goodix_wq); |
| 1836 | |
| 1837 | input_unregister_device(ts->input_dev); |
| 1838 | if (ts->input_dev) { |
| 1839 | input_free_device(ts->input_dev); |
| 1840 | ts->input_dev = NULL; |
| 1841 | } |
| 1842 | exit_free_inputdev: |
| 1843 | kfree(ts->config_data); |
| 1844 | exit_free_io_port: |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 1845 | if (gpio_is_valid(pdata->reset_gpio)) |
| 1846 | gpio_free(pdata->reset_gpio); |
| 1847 | if (gpio_is_valid(pdata->irq_gpio)) |
| 1848 | gpio_free(pdata->irq_gpio); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1849 | exit_power_off: |
Bingzhe Cai | c68e611 | 2013-07-22 00:12:48 +0800 | [diff] [blame] | 1850 | goodix_power_off(ts); |
| 1851 | exit_deinit_power: |
| 1852 | goodix_power_deinit(ts); |
| 1853 | exit_free_client_data: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1854 | i2c_set_clientdata(client, NULL); |
| 1855 | kfree(ts); |
| 1856 | return ret; |
| 1857 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1858 | |
| 1859 | /******************************************************* |
| 1860 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1861 | Goodix touchscreen driver release function. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1862 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1863 | client: i2c device struct. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1864 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1865 | Executive outcomes. 0---succeed. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1866 | *******************************************************/ |
| 1867 | static int goodix_ts_remove(struct i2c_client *client) |
| 1868 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1869 | struct goodix_ts_data *ts = i2c_get_clientdata(client); |
| 1870 | |
| 1871 | GTP_DEBUG_FUNC(); |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 1872 | #if defined(CONFIG_FB) |
| 1873 | if (fb_unregister_client(&ts->fb_notif)) |
| 1874 | dev_err(&client->dev, |
| 1875 | "Error occurred while unregistering fb_notifier.\n"); |
| 1876 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1877 | unregister_early_suspend(&ts->early_suspend); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1878 | #endif |
| 1879 | |
| 1880 | #if GTP_CREATE_WR_NODE |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1881 | uninit_wr_node(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1882 | #endif |
| 1883 | |
| 1884 | #if GTP_ESD_PROTECT |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1885 | cancel_work_sync(gtp_esd_check_workqueue); |
| 1886 | flush_workqueue(gtp_esd_check_workqueue); |
| 1887 | destroy_workqueue(gtp_esd_check_workqueue); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1888 | #endif |
| 1889 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1890 | if (ts) { |
| 1891 | if (ts->use_irq) |
| 1892 | free_irq(client->irq, ts); |
| 1893 | else |
| 1894 | hrtimer_cancel(&ts->timer); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1895 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1896 | cancel_work_sync(&ts->work); |
| 1897 | flush_workqueue(ts->goodix_wq); |
| 1898 | destroy_workqueue(ts->goodix_wq); |
| 1899 | |
| 1900 | input_unregister_device(ts->input_dev); |
| 1901 | if (ts->input_dev) { |
| 1902 | input_free_device(ts->input_dev); |
| 1903 | ts->input_dev = NULL; |
| 1904 | } |
| 1905 | kfree(ts->config_data); |
| 1906 | |
| 1907 | if (gpio_is_valid(ts->pdata->reset_gpio)) |
| 1908 | gpio_free(ts->pdata->reset_gpio); |
| 1909 | if (gpio_is_valid(ts->pdata->irq_gpio)) |
| 1910 | gpio_free(ts->pdata->irq_gpio); |
| 1911 | |
Bingzhe Cai | c68e611 | 2013-07-22 00:12:48 +0800 | [diff] [blame] | 1912 | goodix_power_off(ts); |
| 1913 | goodix_power_deinit(ts); |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1914 | i2c_set_clientdata(client, NULL); |
| 1915 | kfree(ts); |
| 1916 | } |
| 1917 | |
| 1918 | return 0; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 1921 | #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_FB) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1922 | /******************************************************* |
| 1923 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1924 | Early suspend function. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1925 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1926 | h: early_suspend struct. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1927 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1928 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1929 | *******************************************************/ |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 1930 | static void goodix_ts_suspend(struct goodix_ts_data *ts) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1931 | { |
Shantanu Jain | 33b1aee | 2013-08-05 16:52:47 +0530 | [diff] [blame] | 1932 | int ret = -1, i; |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1933 | |
| 1934 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1935 | |
| 1936 | #if GTP_ESD_PROTECT |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1937 | ts->gtp_is_suspend = 1; |
| 1938 | gtp_esd_switch(ts->client, SWITCH_OFF); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1939 | #endif |
| 1940 | |
| 1941 | #if GTP_SLIDE_WAKEUP |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1942 | ret = gtp_enter_doze(ts); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1943 | #else |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1944 | if (ts->use_irq) |
| 1945 | gtp_irq_disable(ts); |
| 1946 | else |
| 1947 | hrtimer_cancel(&ts->timer); |
Shantanu Jain | 33b1aee | 2013-08-05 16:52:47 +0530 | [diff] [blame] | 1948 | |
| 1949 | for (i = 0; i < GTP_MAX_TOUCH; i++) |
| 1950 | gtp_touch_up(ts, i); |
| 1951 | |
Shantanu Jain | 33b1aee | 2013-08-05 16:52:47 +0530 | [diff] [blame] | 1952 | input_sync(ts->input_dev); |
| 1953 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1954 | ret = gtp_enter_sleep(ts); |
| 1955 | #endif |
| 1956 | if (ret < 0) |
| 1957 | dev_err(&ts->client->dev, "GTP early suspend failed.\n"); |
| 1958 | /* to avoid waking up while not sleeping, |
| 1959 | * delay 48 + 10ms to ensure reliability |
| 1960 | */ |
| 1961 | msleep(58); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | /******************************************************* |
| 1965 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1966 | Late resume function. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1967 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1968 | h: early_suspend struct. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1969 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1970 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1971 | *******************************************************/ |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 1972 | static void goodix_ts_resume(struct goodix_ts_data *ts) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1973 | { |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 1974 | int ret = -1; |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1975 | |
| 1976 | GTP_DEBUG_FUNC(); |
| 1977 | |
| 1978 | ret = gtp_wakeup_sleep(ts); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1979 | |
| 1980 | #if GTP_SLIDE_WAKEUP |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1981 | doze_status = DOZE_DISABLED; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1982 | #endif |
| 1983 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1984 | if (ret < 0) |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 1985 | dev_err(&ts->client->dev, "GTP resume failed.\n"); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1986 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1987 | if (ts->use_irq) |
| 1988 | gtp_irq_enable(ts); |
| 1989 | else |
| 1990 | hrtimer_start(&ts->timer, |
| 1991 | ktime_set(1, 0), HRTIMER_MODE_REL); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1992 | |
| 1993 | #if GTP_ESD_PROTECT |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 1994 | ts->gtp_is_suspend = 0; |
| 1995 | gtp_esd_switch(ts->client, SWITCH_ON); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1996 | #endif |
| 1997 | } |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 1998 | |
| 1999 | #if defined(CONFIG_FB) |
| 2000 | static int fb_notifier_callback(struct notifier_block *self, |
| 2001 | unsigned long event, void *data) |
| 2002 | { |
| 2003 | struct fb_event *evdata = data; |
| 2004 | int *blank; |
| 2005 | struct goodix_ts_data *ts = |
| 2006 | container_of(self, struct goodix_ts_data, fb_notif); |
| 2007 | |
| 2008 | if (evdata && evdata->data && event == FB_EVENT_BLANK && |
| 2009 | ts && ts->client) { |
| 2010 | blank = evdata->data; |
| 2011 | if (*blank == FB_BLANK_UNBLANK) |
| 2012 | goodix_ts_resume(ts); |
| 2013 | else if (*blank == FB_BLANK_POWERDOWN) |
| 2014 | goodix_ts_suspend(ts); |
| 2015 | } |
| 2016 | |
| 2017 | return 0; |
| 2018 | } |
| 2019 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
| 2020 | /******************************************************* |
| 2021 | Function: |
| 2022 | Early suspend function. |
| 2023 | Input: |
| 2024 | h: early_suspend struct. |
| 2025 | Output: |
| 2026 | None. |
| 2027 | *******************************************************/ |
| 2028 | static void goodix_ts_early_suspend(struct early_suspend *h) |
| 2029 | { |
| 2030 | struct goodix_ts_data *ts; |
| 2031 | |
| 2032 | ts = container_of(h, struct goodix_ts_data, early_suspend); |
| 2033 | goodix_ts_suspend(ts); |
| 2034 | return; |
| 2035 | } |
| 2036 | |
| 2037 | /******************************************************* |
| 2038 | Function: |
| 2039 | Late resume function. |
| 2040 | Input: |
| 2041 | h: early_suspend struct. |
| 2042 | Output: |
| 2043 | None. |
| 2044 | *******************************************************/ |
| 2045 | static void goodix_ts_late_resume(struct early_suspend *h) |
| 2046 | { |
| 2047 | struct goodix_ts_data *ts; |
| 2048 | |
| 2049 | ts = container_of(h, struct goodix_ts_data, early_suspend); |
| 2050 | goodix_ts_late_resume(ts); |
| 2051 | return; |
| 2052 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2053 | #endif |
Bingzhe Cai | 7d49bb3 | 2013-07-22 18:23:20 +0800 | [diff] [blame] | 2054 | #endif /* !CONFIG_HAS_EARLYSUSPEND && !CONFIG_FB*/ |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2055 | |
| 2056 | #if GTP_ESD_PROTECT |
| 2057 | /******************************************************* |
| 2058 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2059 | switch on & off esd delayed work |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2060 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2061 | client: i2c device |
| 2062 | on: SWITCH_ON / SWITCH_OFF |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2063 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2064 | void |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2065 | *********************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2066 | void gtp_esd_switch(struct i2c_client *client, int on) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2067 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2068 | struct goodix_ts_data *ts; |
| 2069 | |
| 2070 | ts = i2c_get_clientdata(client); |
| 2071 | if (SWITCH_ON == on) { |
| 2072 | /* switch on esd */ |
| 2073 | if (!ts->esd_running) { |
| 2074 | ts->esd_running = 1; |
| 2075 | dev_dbg(&client->dev, "Esd started\n"); |
| 2076 | queue_delayed_work(gtp_esd_check_workqueue, |
| 2077 | >p_esd_check_work, GTP_ESD_CHECK_CIRCLE); |
| 2078 | } |
| 2079 | } else { |
| 2080 | /* switch off esd */ |
| 2081 | if (ts->esd_running) { |
| 2082 | ts->esd_running = 0; |
| 2083 | dev_dbg(&client->dev, "Esd cancelled\n"); |
| 2084 | cancel_delayed_work_sync(>p_esd_check_work); |
| 2085 | } |
| 2086 | } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | /******************************************************* |
| 2090 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2091 | Initialize external watchdog for esd protect |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2092 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2093 | client: i2c device. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2094 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2095 | result of i2c write operation. |
| 2096 | 1: succeed, otherwise: failed |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2097 | *********************************************************/ |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2098 | static int gtp_init_ext_watchdog(struct i2c_client *client) |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2099 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2100 | /* in case of recursively reset by calling gtp_i2c_write*/ |
| 2101 | struct i2c_msg msg; |
| 2102 | u8 opr_buffer[4] = {0x80, 0x40, 0xAA, 0xAA}; |
| 2103 | int ret; |
| 2104 | int retries = 0; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2105 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2106 | GTP_DEBUG("Init external watchdog..."); |
| 2107 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2108 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2109 | msg.flags = !I2C_M_RD; |
| 2110 | msg.addr = client->addr; |
| 2111 | msg.len = 4; |
| 2112 | msg.buf = opr_buffer; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2113 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2114 | while (retries < 5) { |
| 2115 | ret = i2c_transfer(client->adapter, &msg, 1); |
| 2116 | if (ret == 1) |
| 2117 | return 1; |
| 2118 | retries++; |
| 2119 | } |
| 2120 | if (retries >= 5) |
| 2121 | dev_err(&client->dev, "init external watchdog failed!"); |
| 2122 | return 0; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | /******************************************************* |
| 2126 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2127 | Esd protect function. |
| 2128 | Added external watchdog by meta, 2013/03/07 |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2129 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2130 | work: delayed work |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2131 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2132 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2133 | *******************************************************/ |
| 2134 | static void gtp_esd_check_func(struct work_struct *work) |
| 2135 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2136 | s32 i; |
| 2137 | s32 ret = -1; |
| 2138 | struct goodix_ts_data *ts = NULL; |
| 2139 | u8 test[4] = {0x80, 0x40}; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2140 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2141 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2142 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2143 | ts = i2c_get_clientdata(i2c_connect_client); |
| 2144 | |
| 2145 | if (ts->gtp_is_suspend) { |
| 2146 | dev_dbg(&ts->client->dev, "Esd terminated!\n"); |
| 2147 | ts->esd_running = 0; |
| 2148 | return; |
| 2149 | } |
| 2150 | #ifdef CONFIG_GT9XX_TOUCHPANEL_UPDATE |
| 2151 | if (ts->enter_update) |
| 2152 | return; |
| 2153 | #endif |
| 2154 | |
| 2155 | for (i = 0; i < 3; i++) { |
| 2156 | ret = gtp_i2c_read(ts->client, test, 4); |
| 2157 | |
| 2158 | GTP_DEBUG("0x8040 = 0x%02X, 0x8041 = 0x%02X", test[2], test[3]); |
| 2159 | if ((ret < 0)) { |
| 2160 | /* IC works abnormally..*/ |
| 2161 | continue; |
| 2162 | } else { |
| 2163 | if ((test[2] == 0xAA) || (test[3] != 0xAA)) { |
| 2164 | /* IC works abnormally..*/ |
| 2165 | i = 3; |
| 2166 | break; |
| 2167 | } else { |
| 2168 | /* IC works normally, Write 0x8040 0xAA*/ |
| 2169 | test[2] = 0xAA; |
| 2170 | gtp_i2c_write(ts->client, test, 3); |
| 2171 | break; |
| 2172 | } |
| 2173 | } |
| 2174 | } |
| 2175 | if (i >= 3) { |
| 2176 | dev_err(&ts->client->dev, |
| 2177 | "IC Working ABNORMALLY, Resetting Guitar...\n"); |
| 2178 | gtp_reset_guitar(ts, 50); |
| 2179 | } |
| 2180 | |
| 2181 | if (!ts->gtp_is_suspend) |
| 2182 | queue_delayed_work(gtp_esd_check_workqueue, |
| 2183 | >p_esd_check_work, GTP_ESD_CHECK_CIRCLE); |
| 2184 | else { |
| 2185 | dev_dbg(&ts->client->dev, "Esd terminated!\n"); |
| 2186 | ts->esd_running = 0; |
| 2187 | } |
| 2188 | |
| 2189 | return; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2190 | } |
| 2191 | #endif |
| 2192 | |
| 2193 | static const struct i2c_device_id goodix_ts_id[] = { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2194 | { GTP_I2C_NAME, 0 }, |
| 2195 | { } |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2196 | }; |
| 2197 | |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 2198 | static struct of_device_id goodix_match_table[] = { |
| 2199 | { .compatible = "goodix,gt9xx", }, |
| 2200 | { }, |
| 2201 | }; |
| 2202 | |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2203 | static struct i2c_driver goodix_ts_driver = { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2204 | .probe = goodix_ts_probe, |
| 2205 | .remove = goodix_ts_remove, |
| 2206 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 2207 | .suspend = goodix_ts_early_suspend, |
| 2208 | .resume = goodix_ts_late_resume, |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2209 | #endif |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2210 | .id_table = goodix_ts_id, |
| 2211 | .driver = { |
| 2212 | .name = GTP_I2C_NAME, |
| 2213 | .owner = THIS_MODULE, |
Bingzhe Cai | d036117 | 2013-07-18 19:22:11 +0800 | [diff] [blame] | 2214 | .of_match_table = goodix_match_table, |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2215 | }, |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2216 | }; |
| 2217 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2218 | /******************************************************* |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2219 | Function: |
| 2220 | Driver Install function. |
| 2221 | Input: |
| 2222 | None. |
| 2223 | Output: |
| 2224 | Executive Outcomes. 0---succeed. |
| 2225 | ********************************************************/ |
| 2226 | static int __devinit goodix_ts_init(void) |
| 2227 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2228 | int ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2229 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2230 | GTP_DEBUG_FUNC(); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2231 | #if GTP_ESD_PROTECT |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2232 | INIT_DELAYED_WORK(>p_esd_check_work, gtp_esd_check_func); |
| 2233 | gtp_esd_check_workqueue = create_workqueue("gtp_esd_check"); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2234 | #endif |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2235 | ret = i2c_add_driver(&goodix_ts_driver); |
| 2236 | return ret; |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2239 | /******************************************************* |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2240 | Function: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2241 | Driver uninstall function. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2242 | Input: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2243 | None. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2244 | Output: |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2245 | Executive Outcomes. 0---succeed. |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2246 | ********************************************************/ |
| 2247 | static void __exit goodix_ts_exit(void) |
| 2248 | { |
Bingzhe Cai | 83caeea | 2013-07-16 17:57:37 +0800 | [diff] [blame] | 2249 | GTP_DEBUG_FUNC(); |
| 2250 | i2c_del_driver(&goodix_ts_driver); |
Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | late_initcall(goodix_ts_init); |
| 2254 | module_exit(goodix_ts_exit); |
| 2255 | |
| 2256 | MODULE_DESCRIPTION("GTP Series Driver"); |
| 2257 | MODULE_LICENSE("GPL"); |