Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1 | /* |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2 | * Atmel maXTouch Touchscreen driver |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd |
| 5 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> |
Anurag Singh | 49d7613 | 2013-01-29 12:07:00 -0800 | [diff] [blame] | 6 | * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/firmware.h> |
| 19 | #include <linux/i2c.h> |
Dmitry Torokhov | 964de52 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 20 | #include <linux/i2c/atmel_mxt_ts.h> |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 21 | #include <linux/input/mt.h> |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/slab.h> |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 24 | #include <linux/gpio.h> |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 25 | #include <linux/debugfs.h> |
| 26 | #include <linux/seq_file.h> |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 27 | #include <linux/regulator/consumer.h> |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 28 | #include <linux/string.h> |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 29 | #include <linux/of_gpio.h> |
Anurag Singh | 49d7613 | 2013-01-29 12:07:00 -0800 | [diff] [blame] | 30 | |
| 31 | #if defined(CONFIG_FB) |
| 32 | #include <linux/notifier.h> |
| 33 | #include <linux/fb.h> |
| 34 | |
| 35 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 36 | #include <linux/earlysuspend.h> |
| 37 | /* Early-suspend level */ |
| 38 | #define MXT_SUSPEND_LEVEL 1 |
| 39 | #endif |
| 40 | |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 41 | #if defined(CONFIG_SECURE_TOUCH) |
| 42 | #include <linux/completion.h> |
| 43 | #include <linux/pm_runtime.h> |
| 44 | #include <linux/errno.h> |
| 45 | #include <asm/system.h> |
| 46 | #include <linux/atomic.h> |
| 47 | #endif |
| 48 | |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 49 | /* Family ID */ |
| 50 | #define MXT224_ID 0x80 |
Amy Maloche | 380cc0b | 2011-11-03 12:55:04 -0700 | [diff] [blame] | 51 | #define MXT224E_ID 0x81 |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 52 | #define MXT336S_ID 0x82 |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 53 | #define MXT1386_ID 0xA0 |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 54 | #define MXT1664S_ID 0xA2 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 55 | |
| 56 | /* Version */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 57 | #define MXT_VER_20 20 |
| 58 | #define MXT_VER_21 21 |
| 59 | #define MXT_VER_22 22 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 60 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 61 | /* I2C slave address pairs */ |
| 62 | struct mxt_address_pair { |
| 63 | int bootloader; |
| 64 | int application; |
| 65 | }; |
| 66 | |
| 67 | static const struct mxt_address_pair mxt_slave_addresses[] = { |
| 68 | { 0x24, 0x4a }, |
| 69 | { 0x25, 0x4b }, |
| 70 | { 0x25, 0x4b }, |
| 71 | { 0x26, 0x4c }, |
| 72 | { 0x27, 0x4d }, |
| 73 | { 0x34, 0x5a }, |
| 74 | { 0x35, 0x5b }, |
| 75 | { 0 }, |
| 76 | }; |
| 77 | |
| 78 | enum mxt_device_state { INIT, APPMODE, BOOTLOADER }; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 79 | |
| 80 | /* Firmware */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 81 | #define MXT_FW_NAME "maxtouch.fw" |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 82 | |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 83 | /* Firmware frame size including frame data and CRC */ |
| 84 | #define MXT_SINGLE_FW_MAX_FRAME_SIZE 278 |
| 85 | #define MXT_CHIPSET_FW_MAX_FRAME_SIZE 534 |
| 86 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 87 | /* Registers */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 88 | #define MXT_FAMILY_ID 0x00 |
| 89 | #define MXT_VARIANT_ID 0x01 |
| 90 | #define MXT_VERSION 0x02 |
| 91 | #define MXT_BUILD 0x03 |
| 92 | #define MXT_MATRIX_X_SIZE 0x04 |
| 93 | #define MXT_MATRIX_Y_SIZE 0x05 |
| 94 | #define MXT_OBJECT_NUM 0x06 |
| 95 | #define MXT_OBJECT_START 0x07 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 96 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 97 | #define MXT_OBJECT_SIZE 6 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 98 | |
| 99 | /* Object types */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 100 | #define MXT_DEBUG_DIAGNOSTIC_T37 37 |
| 101 | #define MXT_GEN_MESSAGE_T5 5 |
| 102 | #define MXT_GEN_COMMAND_T6 6 |
| 103 | #define MXT_GEN_POWER_T7 7 |
| 104 | #define MXT_GEN_ACQUIRE_T8 8 |
| 105 | #define MXT_GEN_DATASOURCE_T53 53 |
| 106 | #define MXT_TOUCH_MULTI_T9 9 |
| 107 | #define MXT_TOUCH_KEYARRAY_T15 15 |
| 108 | #define MXT_TOUCH_PROXIMITY_T23 23 |
| 109 | #define MXT_TOUCH_PROXKEY_T52 52 |
| 110 | #define MXT_PROCI_GRIPFACE_T20 20 |
| 111 | #define MXT_PROCG_NOISE_T22 22 |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 112 | #define MXT_PROCG_NOISE_T62 62 |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 113 | #define MXT_PROCI_ONETOUCH_T24 24 |
| 114 | #define MXT_PROCI_TWOTOUCH_T27 27 |
| 115 | #define MXT_PROCI_GRIP_T40 40 |
| 116 | #define MXT_PROCI_PALM_T41 41 |
| 117 | #define MXT_PROCI_TOUCHSUPPRESSION_T42 42 |
| 118 | #define MXT_PROCI_STYLUS_T47 47 |
Mohan Pallaka | 78fe53c | 2012-07-09 14:32:28 +0530 | [diff] [blame] | 119 | #define MXT_PROCI_ADAPTIVETHRESHOLD_T55 55 |
Jing Lin | c7fc405 | 2011-12-21 16:16:19 -0800 | [diff] [blame] | 120 | #define MXT_PROCI_SHIELDLESS_T56 56 |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 121 | #define MXT_PROCI_EXTRATSDATA_T57 57 |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 122 | #define MXT_PROCG_NOISESUPPRESSION_T48 48 |
| 123 | #define MXT_SPT_COMMSCONFIG_T18 18 |
| 124 | #define MXT_SPT_GPIOPWM_T19 19 |
| 125 | #define MXT_SPT_SELFTEST_T25 25 |
| 126 | #define MXT_SPT_CTECONFIG_T28 28 |
| 127 | #define MXT_SPT_USERDATA_T38 38 |
| 128 | #define MXT_SPT_DIGITIZER_T43 43 |
| 129 | #define MXT_SPT_MESSAGECOUNT_T44 44 |
| 130 | #define MXT_SPT_CTECONFIG_T46 46 |
Amy Maloche | e3146fb | 2013-04-12 14:59:16 -0700 | [diff] [blame] | 131 | #define MXT_SPT_EXTRANOISESUPCTRLS_T58 58 |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 132 | #define MXT_SPT_TIMER_T61 61 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 133 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 134 | /* MXT_GEN_COMMAND_T6 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 135 | #define MXT_COMMAND_RESET 0 |
| 136 | #define MXT_COMMAND_BACKUPNV 1 |
| 137 | #define MXT_COMMAND_CALIBRATE 2 |
| 138 | #define MXT_COMMAND_REPORTALL 3 |
| 139 | #define MXT_COMMAND_DIAGNOSTIC 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 140 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 141 | /* MXT_GEN_POWER_T7 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 142 | #define MXT_POWER_IDLEACQINT 0 |
| 143 | #define MXT_POWER_ACTVACQINT 1 |
| 144 | #define MXT_POWER_ACTV2IDLETO 2 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 145 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 146 | /* MXT_GEN_ACQUIRE_T8 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 147 | #define MXT_ACQUIRE_CHRGTIME 0 |
| 148 | #define MXT_ACQUIRE_TCHDRIFT 2 |
| 149 | #define MXT_ACQUIRE_DRIFTST 3 |
| 150 | #define MXT_ACQUIRE_TCHAUTOCAL 4 |
| 151 | #define MXT_ACQUIRE_SYNC 5 |
| 152 | #define MXT_ACQUIRE_ATCHCALST 6 |
| 153 | #define MXT_ACQUIRE_ATCHCALSTHR 7 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 154 | |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 155 | /* MXT_TOUCH_MULT_T9 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 156 | #define MXT_TOUCH_CTRL 0 |
| 157 | #define MXT_TOUCH_XORIGIN 1 |
| 158 | #define MXT_TOUCH_YORIGIN 2 |
| 159 | #define MXT_TOUCH_XSIZE 3 |
| 160 | #define MXT_TOUCH_YSIZE 4 |
| 161 | #define MXT_TOUCH_BLEN 6 |
| 162 | #define MXT_TOUCH_TCHTHR 7 |
| 163 | #define MXT_TOUCH_TCHDI 8 |
| 164 | #define MXT_TOUCH_ORIENT 9 |
| 165 | #define MXT_TOUCH_MOVHYSTI 11 |
| 166 | #define MXT_TOUCH_MOVHYSTN 12 |
| 167 | #define MXT_TOUCH_NUMTOUCH 14 |
| 168 | #define MXT_TOUCH_MRGHYST 15 |
| 169 | #define MXT_TOUCH_MRGTHR 16 |
| 170 | #define MXT_TOUCH_AMPHYST 17 |
| 171 | #define MXT_TOUCH_XRANGE_LSB 18 |
| 172 | #define MXT_TOUCH_XRANGE_MSB 19 |
| 173 | #define MXT_TOUCH_YRANGE_LSB 20 |
| 174 | #define MXT_TOUCH_YRANGE_MSB 21 |
| 175 | #define MXT_TOUCH_XLOCLIP 22 |
| 176 | #define MXT_TOUCH_XHICLIP 23 |
| 177 | #define MXT_TOUCH_YLOCLIP 24 |
| 178 | #define MXT_TOUCH_YHICLIP 25 |
| 179 | #define MXT_TOUCH_XEDGECTRL 26 |
| 180 | #define MXT_TOUCH_XEDGEDIST 27 |
| 181 | #define MXT_TOUCH_YEDGECTRL 28 |
| 182 | #define MXT_TOUCH_YEDGEDIST 29 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 183 | #define MXT_TOUCH_JUMPLIMIT 30 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 184 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 185 | /* MXT_PROCI_GRIPFACE_T20 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 186 | #define MXT_GRIPFACE_CTRL 0 |
| 187 | #define MXT_GRIPFACE_XLOGRIP 1 |
| 188 | #define MXT_GRIPFACE_XHIGRIP 2 |
| 189 | #define MXT_GRIPFACE_YLOGRIP 3 |
| 190 | #define MXT_GRIPFACE_YHIGRIP 4 |
| 191 | #define MXT_GRIPFACE_MAXTCHS 5 |
| 192 | #define MXT_GRIPFACE_SZTHR1 7 |
| 193 | #define MXT_GRIPFACE_SZTHR2 8 |
| 194 | #define MXT_GRIPFACE_SHPTHR1 9 |
| 195 | #define MXT_GRIPFACE_SHPTHR2 10 |
| 196 | #define MXT_GRIPFACE_SUPEXTTO 11 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 197 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 198 | /* MXT_PROCI_NOISE field */ |
| 199 | #define MXT_NOISE_CTRL 0 |
| 200 | #define MXT_NOISE_OUTFLEN 1 |
| 201 | #define MXT_NOISE_GCAFUL_LSB 3 |
| 202 | #define MXT_NOISE_GCAFUL_MSB 4 |
| 203 | #define MXT_NOISE_GCAFLL_LSB 5 |
| 204 | #define MXT_NOISE_GCAFLL_MSB 6 |
| 205 | #define MXT_NOISE_ACTVGCAFVALID 7 |
| 206 | #define MXT_NOISE_NOISETHR 8 |
| 207 | #define MXT_NOISE_FREQHOPSCALE 10 |
| 208 | #define MXT_NOISE_FREQ0 11 |
| 209 | #define MXT_NOISE_FREQ1 12 |
| 210 | #define MXT_NOISE_FREQ2 13 |
| 211 | #define MXT_NOISE_FREQ3 14 |
| 212 | #define MXT_NOISE_FREQ4 15 |
| 213 | #define MXT_NOISE_IDLEGCAFVALID 16 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 214 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 215 | /* MXT_SPT_COMMSCONFIG_T18 */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 216 | #define MXT_COMMS_CTRL 0 |
| 217 | #define MXT_COMMS_CMD 1 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 218 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 219 | /* MXT_SPT_CTECONFIG_T28 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 220 | #define MXT_CTE_CTRL 0 |
| 221 | #define MXT_CTE_CMD 1 |
| 222 | #define MXT_CTE_MODE 2 |
| 223 | #define MXT_CTE_IDLEGCAFDEPTH 3 |
| 224 | #define MXT_CTE_ACTVGCAFDEPTH 4 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 225 | #define MXT_CTE_VOLTAGE 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 226 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 227 | #define MXT_VOLTAGE_DEFAULT 2700000 |
| 228 | #define MXT_VOLTAGE_STEP 10000 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 229 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 230 | /* Analog voltage @2.7 V */ |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 231 | #define MXT_VTG_MIN_UV 2700000 |
| 232 | #define MXT_VTG_MAX_UV 3300000 |
| 233 | #define MXT_ACTIVE_LOAD_UA 15000 |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 234 | #define MXT_LPM_LOAD_UA 10 |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 235 | /* Digital voltage @1.8 V */ |
| 236 | #define MXT_VTG_DIG_MIN_UV 1800000 |
| 237 | #define MXT_VTG_DIG_MAX_UV 1800000 |
| 238 | #define MXT_ACTIVE_LOAD_DIG_UA 10000 |
| 239 | #define MXT_LPM_LOAD_DIG_UA 10 |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 240 | |
| 241 | #define MXT_I2C_VTG_MIN_UV 1800000 |
| 242 | #define MXT_I2C_VTG_MAX_UV 1800000 |
| 243 | #define MXT_I2C_LOAD_UA 10000 |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 244 | #define MXT_I2C_LPM_LOAD_UA 10 |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 245 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 246 | /* Define for MXT_GEN_COMMAND_T6 */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 247 | #define MXT_BOOT_VALUE 0xa5 |
| 248 | #define MXT_BACKUP_VALUE 0x55 |
| 249 | #define MXT_BACKUP_TIME 25 /* msec */ |
Jing Lin | 64fdd1f | 2012-12-20 17:08:28 -0800 | [diff] [blame] | 250 | |
| 251 | /* Software reset delay */ |
| 252 | #define MXT224_RESET_TIME 64 /* msec */ |
| 253 | #define MXT224E_RESET_TIME 21 /* msec */ |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 254 | #define MXT336S_RESET_TIME 25 /* msec */ |
Jing Lin | 64fdd1f | 2012-12-20 17:08:28 -0800 | [diff] [blame] | 255 | #define MXT1386_RESET_TIME 250 /* msec */ |
| 256 | #define MXT1386E_RESET_TIME 229 /* msec */ |
| 257 | #define MXT1664S_RESET_TIME 280 /* msec */ |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 258 | #define MXT_RESET_TIME 250 /* msec */ |
Jing Lin | c7fc405 | 2011-12-21 16:16:19 -0800 | [diff] [blame] | 259 | #define MXT_RESET_NOCHGREAD 400 /* msec */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 260 | |
Jing Lin | 64fdd1f | 2012-12-20 17:08:28 -0800 | [diff] [blame] | 261 | /* Power on delay */ |
| 262 | #define MXT224_POWER_ON_TIME 40 /* msec */ |
| 263 | #define MXT224E_POWER_ON_TIME 21 /* msec */ |
| 264 | #define MXT336S_POWER_ON_TIME 25 /* msec */ |
| 265 | #define MXT1386_POWER_ON_TIME 90 /* msec */ |
| 266 | #define MXT1386E_POWER_ON_TIME 81 /* msec */ |
| 267 | #define MXT1664S_POWER_ON_TIME 65 /* msec */ |
| 268 | #define MXT_POWER_ON_TIME 100 /* msec */ |
| 269 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 270 | #define MXT_FWRESET_TIME 1000 /* msec */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 271 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 272 | #define MXT_WAKE_TIME 25 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 273 | |
| 274 | /* Command to unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 275 | #define MXT_UNLOCK_CMD_MSB 0xaa |
| 276 | #define MXT_UNLOCK_CMD_LSB 0xdc |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 277 | |
| 278 | /* Bootloader mode status */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 279 | #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */ |
| 280 | #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */ |
| 281 | #define MXT_FRAME_CRC_CHECK 0x02 |
| 282 | #define MXT_FRAME_CRC_FAIL 0x03 |
| 283 | #define MXT_FRAME_CRC_PASS 0x04 |
| 284 | #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */ |
| 285 | #define MXT_BOOT_STATUS_MASK 0x3f |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 286 | #define MXT_BOOT_EXTENDED_ID (1 << 5) |
| 287 | #define MXT_BOOT_ID_MASK 0x1f |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 288 | |
| 289 | /* Touch status */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 290 | #define MXT_SUPPRESS (1 << 1) |
| 291 | #define MXT_AMP (1 << 2) |
| 292 | #define MXT_VECTOR (1 << 3) |
| 293 | #define MXT_MOVE (1 << 4) |
| 294 | #define MXT_RELEASE (1 << 5) |
| 295 | #define MXT_PRESS (1 << 6) |
| 296 | #define MXT_DETECT (1 << 7) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 297 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 298 | /* Touch orient bits */ |
| 299 | #define MXT_XY_SWITCH (1 << 0) |
| 300 | #define MXT_X_INVERT (1 << 1) |
| 301 | #define MXT_Y_INVERT (1 << 2) |
| 302 | |
Mohan Pallaka | b6acab4 | 2012-06-13 11:59:04 +0530 | [diff] [blame] | 303 | /* Touch suppression */ |
| 304 | #define MXT_TCHSUP_ACTIVE (1 << 0) |
| 305 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 306 | /* Touchscreen absolute values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 307 | #define MXT_MAX_AREA 0xff |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 308 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 309 | #define MXT_MAX_FINGER 10 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 310 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 311 | #define T7_DATA_SIZE 3 |
| 312 | #define MXT_MAX_RW_TRIES 3 |
| 313 | #define MXT_BLOCK_SIZE 256 |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 314 | #define MXT_CFG_VERSION_LEN 3 |
| 315 | #define MXT_CFG_VERSION_EQUAL 0 |
| 316 | #define MXT_CFG_VERSION_LESS 1 |
| 317 | #define MXT_CFG_VERSION_GREATER 2 |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame] | 318 | |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 319 | #define MXT_COORDS_ARR_SIZE 4 |
| 320 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 321 | #define MXT_DEBUGFS_DIR "atmel_mxt_ts" |
| 322 | #define MXT_DEBUGFS_FILE "object" |
| 323 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 324 | struct mxt_info { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 325 | u8 family_id; |
| 326 | u8 variant_id; |
| 327 | u8 version; |
| 328 | u8 build; |
| 329 | u8 matrix_xsize; |
| 330 | u8 matrix_ysize; |
| 331 | u8 object_num; |
| 332 | }; |
| 333 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 334 | struct mxt_object { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 335 | u8 type; |
| 336 | u16 start_address; |
| 337 | u8 size; |
| 338 | u8 instances; |
| 339 | u8 num_report_ids; |
| 340 | |
| 341 | /* to map object and message */ |
| 342 | u8 max_reportid; |
| 343 | }; |
| 344 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 345 | struct mxt_message { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 346 | u8 reportid; |
| 347 | u8 message[7]; |
| 348 | u8 checksum; |
| 349 | }; |
| 350 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 351 | struct mxt_finger { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 352 | int status; |
| 353 | int x; |
| 354 | int y; |
| 355 | int area; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 356 | int pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | /* Each client has this additional data */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 360 | struct mxt_data { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 361 | struct i2c_client *client; |
| 362 | struct input_dev *input_dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 363 | const struct mxt_platform_data *pdata; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 364 | const struct mxt_config_info *config_info; |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 365 | enum mxt_device_state state; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 366 | struct mxt_object *object_table; |
| 367 | struct mxt_info info; |
| 368 | struct mxt_finger finger[MXT_MAX_FINGER]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 369 | unsigned int irq; |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 370 | struct regulator *vcc_ana; |
| 371 | struct regulator *vcc_dig; |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 372 | struct regulator *vcc_i2c; |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 373 | struct mxt_address_pair addr_pair; |
Anurag Singh | 49d7613 | 2013-01-29 12:07:00 -0800 | [diff] [blame] | 374 | #if defined(CONFIG_FB) |
| 375 | struct notifier_block fb_notif; |
| 376 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 377 | struct early_suspend early_suspend; |
| 378 | #endif |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 379 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 380 | u8 t7_data[T7_DATA_SIZE]; |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 381 | u16 t7_start_addr; |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 382 | u32 keyarray_old; |
| 383 | u32 keyarray_new; |
| 384 | u8 t9_max_reportid; |
| 385 | u8 t9_min_reportid; |
| 386 | u8 t15_max_reportid; |
| 387 | u8 t15_min_reportid; |
Mohan Pallaka | b6acab4 | 2012-06-13 11:59:04 +0530 | [diff] [blame] | 388 | u8 t42_max_reportid; |
| 389 | u8 t42_min_reportid; |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 390 | u8 cfg_version[MXT_CFG_VERSION_LEN]; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 391 | int cfg_version_idx; |
Jing Lin | 8a9472d | 2012-03-21 15:43:45 -0700 | [diff] [blame] | 392 | int t38_start_addr; |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 393 | bool update_cfg; |
Anirudh Ghayal | 0bcb5b5 | 2012-02-17 14:58:25 -0800 | [diff] [blame] | 394 | const char *fw_name; |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 395 | bool no_force_update; |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 396 | bool lpm_support; |
| 397 | bool regs_enabled; |
| 398 | |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 399 | #if defined(CONFIG_SECURE_TOUCH) |
| 400 | atomic_t st_enabled; |
| 401 | atomic_t st_pending_irqs; |
| 402 | struct completion st_completion; |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 403 | struct completion st_powerdown; |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 404 | #endif |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 405 | }; |
| 406 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 407 | static struct dentry *debug_base; |
| 408 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 409 | static bool mxt_object_readable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 410 | { |
| 411 | switch (type) { |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 412 | case MXT_GEN_MESSAGE_T5: |
| 413 | case MXT_GEN_COMMAND_T6: |
| 414 | case MXT_GEN_POWER_T7: |
| 415 | case MXT_GEN_ACQUIRE_T8: |
| 416 | case MXT_GEN_DATASOURCE_T53: |
| 417 | case MXT_TOUCH_MULTI_T9: |
| 418 | case MXT_TOUCH_KEYARRAY_T15: |
| 419 | case MXT_TOUCH_PROXIMITY_T23: |
| 420 | case MXT_TOUCH_PROXKEY_T52: |
| 421 | case MXT_PROCI_GRIPFACE_T20: |
| 422 | case MXT_PROCG_NOISE_T22: |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 423 | case MXT_PROCG_NOISE_T62: |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 424 | case MXT_PROCI_ONETOUCH_T24: |
| 425 | case MXT_PROCI_TWOTOUCH_T27: |
| 426 | case MXT_PROCI_GRIP_T40: |
| 427 | case MXT_PROCI_PALM_T41: |
| 428 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 429 | case MXT_PROCI_STYLUS_T47: |
Jing Lin | c7fc405 | 2011-12-21 16:16:19 -0800 | [diff] [blame] | 430 | case MXT_PROCI_SHIELDLESS_T56: |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 431 | case MXT_PROCI_EXTRATSDATA_T57: |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 432 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 433 | case MXT_SPT_COMMSCONFIG_T18: |
| 434 | case MXT_SPT_GPIOPWM_T19: |
| 435 | case MXT_SPT_SELFTEST_T25: |
| 436 | case MXT_SPT_CTECONFIG_T28: |
| 437 | case MXT_SPT_USERDATA_T38: |
| 438 | case MXT_SPT_DIGITIZER_T43: |
| 439 | case MXT_SPT_CTECONFIG_T46: |
Amy Maloche | e3146fb | 2013-04-12 14:59:16 -0700 | [diff] [blame] | 440 | case MXT_SPT_EXTRANOISESUPCTRLS_T58: |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 441 | case MXT_SPT_TIMER_T61: |
Mohan Pallaka | 78fe53c | 2012-07-09 14:32:28 +0530 | [diff] [blame] | 442 | case MXT_PROCI_ADAPTIVETHRESHOLD_T55: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 443 | return true; |
| 444 | default: |
| 445 | return false; |
| 446 | } |
| 447 | } |
| 448 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 449 | static bool mxt_object_writable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 450 | { |
| 451 | switch (type) { |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 452 | case MXT_GEN_COMMAND_T6: |
| 453 | case MXT_GEN_POWER_T7: |
| 454 | case MXT_GEN_ACQUIRE_T8: |
| 455 | case MXT_TOUCH_MULTI_T9: |
| 456 | case MXT_TOUCH_KEYARRAY_T15: |
| 457 | case MXT_TOUCH_PROXIMITY_T23: |
| 458 | case MXT_TOUCH_PROXKEY_T52: |
| 459 | case MXT_PROCI_GRIPFACE_T20: |
| 460 | case MXT_PROCG_NOISE_T22: |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 461 | case MXT_PROCG_NOISE_T62: |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 462 | case MXT_PROCI_ONETOUCH_T24: |
| 463 | case MXT_PROCI_TWOTOUCH_T27: |
| 464 | case MXT_PROCI_GRIP_T40: |
| 465 | case MXT_PROCI_PALM_T41: |
| 466 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 467 | case MXT_PROCI_STYLUS_T47: |
Jing Lin | c7fc405 | 2011-12-21 16:16:19 -0800 | [diff] [blame] | 468 | case MXT_PROCI_SHIELDLESS_T56: |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 469 | case MXT_PROCI_EXTRATSDATA_T57: |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 470 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 471 | case MXT_SPT_COMMSCONFIG_T18: |
| 472 | case MXT_SPT_GPIOPWM_T19: |
| 473 | case MXT_SPT_SELFTEST_T25: |
| 474 | case MXT_SPT_CTECONFIG_T28: |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 475 | case MXT_SPT_USERDATA_T38: |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 476 | case MXT_SPT_DIGITIZER_T43: |
| 477 | case MXT_SPT_CTECONFIG_T46: |
Amy Maloche | e3146fb | 2013-04-12 14:59:16 -0700 | [diff] [blame] | 478 | case MXT_SPT_EXTRANOISESUPCTRLS_T58: |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 479 | case MXT_SPT_TIMER_T61: |
Mohan Pallaka | 78fe53c | 2012-07-09 14:32:28 +0530 | [diff] [blame] | 480 | case MXT_PROCI_ADAPTIVETHRESHOLD_T55: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 481 | return true; |
| 482 | default: |
| 483 | return false; |
| 484 | } |
| 485 | } |
| 486 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 487 | static void mxt_dump_message(struct device *dev, |
| 488 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 489 | { |
| 490 | dev_dbg(dev, "reportid:\t0x%x\n", message->reportid); |
| 491 | dev_dbg(dev, "message1:\t0x%x\n", message->message[0]); |
| 492 | dev_dbg(dev, "message2:\t0x%x\n", message->message[1]); |
| 493 | dev_dbg(dev, "message3:\t0x%x\n", message->message[2]); |
| 494 | dev_dbg(dev, "message4:\t0x%x\n", message->message[3]); |
| 495 | dev_dbg(dev, "message5:\t0x%x\n", message->message[4]); |
| 496 | dev_dbg(dev, "message6:\t0x%x\n", message->message[5]); |
| 497 | dev_dbg(dev, "message7:\t0x%x\n", message->message[6]); |
| 498 | dev_dbg(dev, "checksum:\t0x%x\n", message->checksum); |
| 499 | } |
| 500 | |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 501 | static int mxt_lookup_bootloader_address(struct mxt_data *data) |
Amy Maloche | 71b8f02 | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 502 | { |
Steve Muckle | e153354 | 2013-02-13 15:03:16 -0800 | [diff] [blame] | 503 | int i; |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 504 | |
| 505 | for (i = 0; mxt_slave_addresses[i].application != 0; i++) { |
| 506 | if (mxt_slave_addresses[i].application == |
| 507 | data->client->addr) { |
| 508 | data->addr_pair.bootloader = |
| 509 | mxt_slave_addresses[i].bootloader; |
| 510 | return 0; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | dev_err(&data->client->dev, "Address 0x%02x not found in address table", |
| 515 | data->client->addr); |
| 516 | return -EINVAL; |
| 517 | |
| 518 | }; |
| 519 | |
| 520 | static int mxt_switch_to_bootloader_address(struct mxt_data *data) |
| 521 | { |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 522 | struct i2c_client *client = data->client; |
| 523 | |
| 524 | if (data->state == BOOTLOADER) { |
| 525 | dev_err(&client->dev, "Already in BOOTLOADER state\n"); |
| 526 | return -EINVAL; |
| 527 | } |
| 528 | |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 529 | dev_info(&client->dev, "Changing to bootloader address: 0x%02x -> 0x%02x", |
| 530 | client->addr, data->addr_pair.bootloader); |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 531 | |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 532 | client->addr = data->addr_pair.bootloader; |
| 533 | data->state = BOOTLOADER; |
| 534 | return 0; |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | static int mxt_switch_to_appmode_address(struct mxt_data *data) |
| 538 | { |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 539 | struct i2c_client *client = data->client; |
| 540 | |
| 541 | if (data->state == APPMODE) { |
| 542 | dev_err(&client->dev, "Already in APPMODE state\n"); |
| 543 | return -EINVAL; |
| 544 | } |
| 545 | |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 546 | dev_info(&client->dev, "Changing to application mode address: " \ |
| 547 | "0x%02x -> 0x%02x", client->addr, |
| 548 | data->addr_pair.application); |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 549 | |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 550 | client->addr = data->addr_pair.application; |
| 551 | data->state = APPMODE; |
| 552 | return 0; |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | static int mxt_get_bootloader_version(struct i2c_client *client, u8 val) |
| 556 | { |
| 557 | u8 buf[3]; |
| 558 | |
| 559 | if (val | MXT_BOOT_EXTENDED_ID) { |
| 560 | dev_dbg(&client->dev, |
| 561 | "Retrieving extended mode ID information"); |
| 562 | |
| 563 | if (i2c_master_recv(client, &buf[0], 3) != 3) { |
| 564 | dev_err(&client->dev, "%s: i2c recv failed\n", |
| 565 | __func__); |
| 566 | return -EIO; |
| 567 | } |
| 568 | |
| 569 | dev_info(&client->dev, "Bootloader ID:%d Version:%d", |
| 570 | buf[1], buf[2]); |
| 571 | |
| 572 | return buf[0]; |
| 573 | } else { |
| 574 | dev_info(&client->dev, "Bootloader ID:%d", |
| 575 | val & MXT_BOOT_ID_MASK); |
| 576 | |
| 577 | return val; |
| 578 | } |
| 579 | } |
| 580 | |
Anirudh Ghayal | 6c3b37b | 2012-02-23 18:39:42 -0800 | [diff] [blame] | 581 | static int mxt_get_bootloader_id(struct i2c_client *client) |
| 582 | { |
| 583 | u8 val; |
| 584 | u8 buf[3]; |
| 585 | |
| 586 | if (i2c_master_recv(client, &val, 1) != 1) { |
| 587 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); |
| 588 | return -EIO; |
| 589 | } |
| 590 | |
| 591 | if (val | MXT_BOOT_EXTENDED_ID) { |
| 592 | if (i2c_master_recv(client, &buf[0], 3) != 3) { |
| 593 | dev_err(&client->dev, "%s: i2c recv failed\n", |
| 594 | __func__); |
| 595 | return -EIO; |
| 596 | } |
| 597 | return buf[1]; |
| 598 | } else { |
| 599 | dev_info(&client->dev, "Bootloader ID:%d", |
| 600 | val & MXT_BOOT_ID_MASK); |
| 601 | |
| 602 | return val & MXT_BOOT_ID_MASK; |
| 603 | } |
| 604 | } |
| 605 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 606 | static int mxt_check_bootloader(struct i2c_client *client, |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 607 | unsigned int state) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 608 | { |
| 609 | u8 val; |
| 610 | |
| 611 | recheck: |
| 612 | if (i2c_master_recv(client, &val, 1) != 1) { |
| 613 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); |
| 614 | return -EIO; |
| 615 | } |
| 616 | |
| 617 | switch (state) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 618 | case MXT_WAITING_BOOTLOAD_CMD: |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 619 | val = mxt_get_bootloader_version(client, val); |
| 620 | val &= ~MXT_BOOT_STATUS_MASK; |
| 621 | break; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 622 | case MXT_WAITING_FRAME_DATA: |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 623 | case MXT_APP_CRC_FAIL: |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 624 | val &= ~MXT_BOOT_STATUS_MASK; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 625 | break; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 626 | case MXT_FRAME_CRC_PASS: |
| 627 | if (val == MXT_FRAME_CRC_CHECK) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 628 | goto recheck; |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 629 | if (val == MXT_FRAME_CRC_FAIL) { |
| 630 | dev_err(&client->dev, "Bootloader CRC fail\n"); |
| 631 | return -EINVAL; |
| 632 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 633 | break; |
| 634 | default: |
| 635 | return -EINVAL; |
| 636 | } |
| 637 | |
| 638 | if (val != state) { |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 639 | dev_err(&client->dev, "Invalid bootloader mode state %X\n", |
| 640 | val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 641 | return -EINVAL; |
| 642 | } |
| 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 647 | static int mxt_unlock_bootloader(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 648 | { |
| 649 | u8 buf[2]; |
| 650 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 651 | buf[0] = MXT_UNLOCK_CMD_LSB; |
| 652 | buf[1] = MXT_UNLOCK_CMD_MSB; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 653 | |
| 654 | if (i2c_master_send(client, buf, 2) != 2) { |
| 655 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 656 | return -EIO; |
| 657 | } |
| 658 | |
| 659 | return 0; |
| 660 | } |
| 661 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 662 | static int mxt_fw_write(struct i2c_client *client, |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 663 | const u8 *data, unsigned int frame_size) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 664 | { |
| 665 | if (i2c_master_send(client, data, frame_size) != frame_size) { |
| 666 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 667 | return -EIO; |
| 668 | } |
| 669 | |
| 670 | return 0; |
| 671 | } |
| 672 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 673 | static int __mxt_read_reg(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 674 | u16 reg, u16 len, void *val) |
| 675 | { |
| 676 | struct i2c_msg xfer[2]; |
| 677 | u8 buf[2]; |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 678 | int i = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 679 | |
| 680 | buf[0] = reg & 0xff; |
| 681 | buf[1] = (reg >> 8) & 0xff; |
| 682 | |
| 683 | /* Write register */ |
| 684 | xfer[0].addr = client->addr; |
| 685 | xfer[0].flags = 0; |
| 686 | xfer[0].len = 2; |
| 687 | xfer[0].buf = buf; |
| 688 | |
| 689 | /* Read data */ |
| 690 | xfer[1].addr = client->addr; |
| 691 | xfer[1].flags = I2C_M_RD; |
| 692 | xfer[1].len = len; |
| 693 | xfer[1].buf = val; |
| 694 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 695 | do { |
| 696 | if (i2c_transfer(client->adapter, xfer, 2) == 2) |
| 697 | return 0; |
| 698 | msleep(MXT_WAKE_TIME); |
| 699 | } while (++i < MXT_MAX_RW_TRIES); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 700 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 701 | dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); |
| 702 | return -EIO; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 705 | static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 706 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 707 | return __mxt_read_reg(client, reg, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 710 | static int __mxt_write_reg(struct i2c_client *client, |
| 711 | u16 addr, u16 length, u8 *value) |
| 712 | { |
| 713 | u8 buf[MXT_BLOCK_SIZE + 2]; |
| 714 | int i, tries = 0; |
| 715 | |
| 716 | if (length > MXT_BLOCK_SIZE) |
| 717 | return -EINVAL; |
| 718 | |
| 719 | buf[0] = addr & 0xff; |
| 720 | buf[1] = (addr >> 8) & 0xff; |
| 721 | for (i = 0; i < length; i++) |
| 722 | buf[i + 2] = *value++; |
| 723 | |
| 724 | do { |
| 725 | if (i2c_master_send(client, buf, length + 2) == (length + 2)) |
| 726 | return 0; |
| 727 | msleep(MXT_WAKE_TIME); |
| 728 | } while (++tries < MXT_MAX_RW_TRIES); |
| 729 | |
| 730 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 731 | return -EIO; |
| 732 | } |
| 733 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 734 | static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 735 | { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 736 | return __mxt_write_reg(client, reg, 1, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 739 | static int mxt_read_object_table(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 740 | u16 reg, u8 *object_buf) |
| 741 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 742 | return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 743 | object_buf); |
| 744 | } |
| 745 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 746 | static struct mxt_object * |
| 747 | mxt_get_object(struct mxt_data *data, u8 type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 748 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 749 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 750 | int i; |
| 751 | |
| 752 | for (i = 0; i < data->info.object_num; i++) { |
| 753 | object = data->object_table + i; |
| 754 | if (object->type == type) |
| 755 | return object; |
| 756 | } |
| 757 | |
| 758 | dev_err(&data->client->dev, "Invalid object type\n"); |
| 759 | return NULL; |
| 760 | } |
| 761 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 762 | static int mxt_read_message(struct mxt_data *data, |
| 763 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 764 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 765 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 766 | u16 reg; |
| 767 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 768 | object = mxt_get_object(data, MXT_GEN_MESSAGE_T5); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 769 | if (!object) |
| 770 | return -EINVAL; |
| 771 | |
| 772 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 773 | return __mxt_read_reg(data->client, reg, |
| 774 | sizeof(struct mxt_message), message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 777 | static int mxt_read_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 778 | u8 type, u8 offset, u8 *val) |
| 779 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 780 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 781 | u16 reg; |
| 782 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 783 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 784 | if (!object) |
| 785 | return -EINVAL; |
| 786 | |
| 787 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 788 | return __mxt_read_reg(data->client, reg + offset, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Mohan Pallaka | 78fe53c | 2012-07-09 14:32:28 +0530 | [diff] [blame] | 791 | static int mxt_get_object_address(struct device *dev, u8 type) |
| 792 | { |
| 793 | struct mxt_data *data = dev_get_drvdata(dev); |
| 794 | u8 obj_num, obj_buf[MXT_OBJECT_SIZE]; |
| 795 | u16 reg; |
| 796 | int i, error; |
| 797 | |
| 798 | error = mxt_read_reg(data->client, MXT_OBJECT_NUM, &obj_num); |
| 799 | |
| 800 | if (error) { |
| 801 | dev_err(dev, "reading number of objects failed\n"); |
| 802 | return -EINVAL; |
| 803 | } |
| 804 | |
| 805 | for (i = 0; i < obj_num; i++) { |
| 806 | reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; |
| 807 | error = mxt_read_object_table(data->client, |
| 808 | reg, obj_buf); |
| 809 | if (error) |
| 810 | return error; |
| 811 | |
| 812 | if (obj_buf[0] == type) |
| 813 | return obj_buf[2] << 8 | obj_buf[1]; |
| 814 | } |
| 815 | /* If control reaches here, i = obj_num and object not found */ |
| 816 | dev_err(dev, "Requested object %d not found.\n", type); |
| 817 | return -EINVAL; |
| 818 | |
| 819 | } |
| 820 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 821 | static int mxt_write_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 822 | u8 type, u8 offset, u8 val) |
| 823 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 824 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 825 | u16 reg; |
| 826 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 827 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 828 | if (!object) |
| 829 | return -EINVAL; |
| 830 | |
| 831 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 832 | return mxt_write_reg(data->client, reg + offset, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 835 | static void mxt_input_report(struct mxt_data *data, int single_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 836 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 837 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 838 | struct input_dev *input_dev = data->input_dev; |
| 839 | int status = finger[single_id].status; |
| 840 | int finger_num = 0; |
| 841 | int id; |
| 842 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 843 | for (id = 0; id < MXT_MAX_FINGER; id++) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 844 | if (!finger[id].status) |
| 845 | continue; |
| 846 | |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 847 | input_mt_slot(input_dev, id); |
Mohan Pallaka | 56a1a5d | 2012-02-23 12:05:13 -0800 | [diff] [blame] | 848 | /* Firmware reports min/max values when the touch is |
| 849 | * outside screen area. Send a release event in |
| 850 | * such cases to avoid unwanted touches. |
| 851 | */ |
| 852 | if (finger[id].x <= data->pdata->panel_minx || |
| 853 | finger[id].x >= data->pdata->panel_maxx || |
| 854 | finger[id].y <= data->pdata->panel_miny || |
| 855 | finger[id].y >= data->pdata->panel_maxy) { |
| 856 | finger[id].status = MXT_RELEASE; |
| 857 | } |
| 858 | |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 859 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, |
| 860 | finger[id].status != MXT_RELEASE); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 861 | |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 862 | if (finger[id].status != MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 863 | finger_num++; |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 864 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, |
| 865 | finger[id].area); |
| 866 | input_report_abs(input_dev, ABS_MT_POSITION_X, |
| 867 | finger[id].x); |
| 868 | input_report_abs(input_dev, ABS_MT_POSITION_Y, |
| 869 | finger[id].y); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 870 | input_report_abs(input_dev, ABS_MT_PRESSURE, |
Anirudh Ghayal | 279a2ae5 | 2012-05-18 18:07:46 +0530 | [diff] [blame] | 871 | finger[id].pressure); |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 872 | } else { |
| 873 | finger[id].status = 0; |
| 874 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | input_report_key(input_dev, BTN_TOUCH, finger_num > 0); |
| 878 | |
Mohan Pallaka | 56a1a5d | 2012-02-23 12:05:13 -0800 | [diff] [blame] | 879 | if (finger[single_id].x <= data->pdata->panel_minx || |
| 880 | finger[single_id].x >= data->pdata->panel_maxx || |
| 881 | finger[single_id].y <= data->pdata->panel_miny || |
| 882 | finger[single_id].y >= data->pdata->panel_maxy) { |
| 883 | status = MXT_RELEASE; |
| 884 | } |
| 885 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 886 | if (status != MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 887 | input_report_abs(input_dev, ABS_X, finger[single_id].x); |
| 888 | input_report_abs(input_dev, ABS_Y, finger[single_id].y); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 889 | input_report_abs(input_dev, |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 890 | ABS_PRESSURE, finger[single_id].pressure); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | input_sync(input_dev); |
| 894 | } |
| 895 | |
Amy Maloche | 1b7ac70 | 2013-02-21 19:47:53 -0800 | [diff] [blame] | 896 | static void mxt_release_all(struct mxt_data *data) |
| 897 | { |
| 898 | int id; |
| 899 | |
| 900 | for (id = 0; id < MXT_MAX_FINGER; id++) |
| 901 | if (data->finger[id].status) |
| 902 | data->finger[id].status = MXT_RELEASE; |
| 903 | |
| 904 | mxt_input_report(data, 0); |
| 905 | } |
| 906 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 907 | static void mxt_input_touchevent(struct mxt_data *data, |
| 908 | struct mxt_message *message, int id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 909 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 910 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 911 | struct device *dev = &data->client->dev; |
| 912 | u8 status = message->message[0]; |
| 913 | int x; |
| 914 | int y; |
| 915 | int area; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 916 | int pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 917 | |
Amy Maloche | 1b7ac70 | 2013-02-21 19:47:53 -0800 | [diff] [blame] | 918 | if (status & MXT_SUPPRESS) { |
| 919 | mxt_release_all(data); |
| 920 | return; |
| 921 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 922 | /* Check the touch is present on the screen */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 923 | if (!(status & MXT_DETECT)) { |
| 924 | if (status & MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 925 | dev_dbg(dev, "[%d] released\n", id); |
| 926 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 927 | finger[id].status = MXT_RELEASE; |
| 928 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 929 | } |
| 930 | return; |
| 931 | } |
| 932 | |
| 933 | /* Check only AMP detection */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 934 | if (!(status & (MXT_PRESS | MXT_MOVE))) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 935 | return; |
| 936 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 937 | x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); |
| 938 | y = (message->message[2] << 4) | ((message->message[3] & 0xf)); |
Mohan Pallaka | 56a1a5d | 2012-02-23 12:05:13 -0800 | [diff] [blame] | 939 | if (data->pdata->panel_maxx < 1024) |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 940 | x = x >> 2; |
Mohan Pallaka | 56a1a5d | 2012-02-23 12:05:13 -0800 | [diff] [blame] | 941 | if (data->pdata->panel_maxy < 1024) |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 942 | y = y >> 2; |
| 943 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 944 | area = message->message[4]; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 945 | pressure = message->message[5]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 946 | |
| 947 | dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 948 | status & MXT_MOVE ? "moved" : "pressed", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 949 | x, y, area); |
| 950 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 951 | finger[id].status = status & MXT_MOVE ? |
| 952 | MXT_MOVE : MXT_PRESS; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 953 | finger[id].x = x; |
| 954 | finger[id].y = y; |
| 955 | finger[id].area = area; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 956 | finger[id].pressure = pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 957 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 958 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 959 | } |
| 960 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 961 | static void mxt_handle_key_array(struct mxt_data *data, |
| 962 | struct mxt_message *message) |
| 963 | { |
| 964 | u32 keys_changed; |
| 965 | int i; |
| 966 | |
| 967 | if (!data->pdata->key_codes) { |
| 968 | dev_err(&data->client->dev, "keyarray is not supported\n"); |
| 969 | return; |
| 970 | } |
| 971 | |
| 972 | data->keyarray_new = message->message[1] | |
| 973 | (message->message[2] << 8) | |
| 974 | (message->message[3] << 16) | |
| 975 | (message->message[4] << 24); |
| 976 | |
| 977 | keys_changed = data->keyarray_old ^ data->keyarray_new; |
| 978 | |
| 979 | if (!keys_changed) { |
| 980 | dev_dbg(&data->client->dev, "no keys changed\n"); |
| 981 | return; |
| 982 | } |
| 983 | |
| 984 | for (i = 0; i < MXT_KEYARRAY_MAX_KEYS; i++) { |
| 985 | if (!(keys_changed & (1 << i))) |
| 986 | continue; |
| 987 | |
| 988 | input_report_key(data->input_dev, data->pdata->key_codes[i], |
| 989 | (data->keyarray_new & (1 << i))); |
| 990 | input_sync(data->input_dev); |
| 991 | } |
| 992 | |
| 993 | data->keyarray_old = data->keyarray_new; |
| 994 | } |
| 995 | |
Amy Maloche | 1b7ac70 | 2013-02-21 19:47:53 -0800 | [diff] [blame] | 996 | static void mxt_handle_touch_suppression(struct mxt_data *data, u8 status) |
Mohan Pallaka | b6acab4 | 2012-06-13 11:59:04 +0530 | [diff] [blame] | 997 | { |
| 998 | dev_dbg(&data->client->dev, "touch suppression\n"); |
| 999 | /* release all touches */ |
| 1000 | if (status & MXT_TCHSUP_ACTIVE) |
| 1001 | mxt_release_all(data); |
| 1002 | } |
| 1003 | |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 1004 | #if defined(CONFIG_SECURE_TOUCH) |
| 1005 | static irqreturn_t mxt_filter_interrupt(struct mxt_data *data) |
| 1006 | { |
| 1007 | if (atomic_read(&data->st_enabled)) { |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 1008 | if (atomic_cmpxchg(&data->st_pending_irqs, 0, 1) == 0) |
| 1009 | complete(&data->st_completion); |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 1010 | return IRQ_HANDLED; |
| 1011 | } |
| 1012 | return IRQ_NONE; |
| 1013 | } |
| 1014 | #else |
| 1015 | static irqreturn_t mxt_filter_interrupt(struct mxt_data *data) |
| 1016 | { |
| 1017 | return IRQ_NONE; |
| 1018 | } |
| 1019 | #endif |
| 1020 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1021 | static irqreturn_t mxt_interrupt(int irq, void *dev_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1022 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1023 | struct mxt_data *data = dev_id; |
| 1024 | struct mxt_message message; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1025 | struct device *dev = &data->client->dev; |
| 1026 | int id; |
| 1027 | u8 reportid; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1028 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1029 | if (data->state != APPMODE) { |
| 1030 | dev_err(dev, "Ignoring IRQ - not in APPMODE state\n"); |
| 1031 | return IRQ_HANDLED; |
| 1032 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1033 | |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 1034 | if (IRQ_HANDLED == mxt_filter_interrupt(data)) |
| 1035 | goto end; |
| 1036 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1037 | do { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1038 | if (mxt_read_message(data, &message)) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1039 | dev_err(dev, "Failed to read message\n"); |
| 1040 | goto end; |
| 1041 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1042 | reportid = message.reportid; |
| 1043 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1044 | if (!reportid) { |
| 1045 | dev_dbg(dev, "Report id 0 is reserved\n"); |
| 1046 | continue; |
| 1047 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1048 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1049 | id = reportid - data->t9_min_reportid; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1050 | |
Amy Maloche | 1b7ac70 | 2013-02-21 19:47:53 -0800 | [diff] [blame] | 1051 | /* check whether report id is part of T9, T15 or T42 */ |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1052 | if (reportid >= data->t9_min_reportid && |
| 1053 | reportid <= data->t9_max_reportid) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1054 | mxt_input_touchevent(data, &message, id); |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1055 | else if (reportid >= data->t15_min_reportid && |
| 1056 | reportid <= data->t15_max_reportid) |
| 1057 | mxt_handle_key_array(data, &message); |
Mohan Pallaka | b6acab4 | 2012-06-13 11:59:04 +0530 | [diff] [blame] | 1058 | else if (reportid >= data->t42_min_reportid && |
Amy Maloche | 1b7ac70 | 2013-02-21 19:47:53 -0800 | [diff] [blame] | 1059 | reportid <= data->t42_max_reportid) |
| 1060 | mxt_handle_touch_suppression(data, |
| 1061 | message.message[0]); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1062 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1063 | mxt_dump_message(dev, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1064 | } while (reportid != 0xff); |
| 1065 | |
| 1066 | end: |
| 1067 | return IRQ_HANDLED; |
| 1068 | } |
| 1069 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1070 | static int mxt_check_reg_init(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1071 | { |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1072 | const struct mxt_config_info *config_info = data->config_info; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1073 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1074 | struct device *dev = &data->client->dev; |
| 1075 | int index = 0; |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1076 | int i, j, config_offset; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1077 | |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1078 | if (!config_info) { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1079 | dev_dbg(dev, "No cfg data defined, skipping reg init\n"); |
| 1080 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | for (i = 0; i < data->info.object_num; i++) { |
| 1084 | object = data->object_table + i; |
| 1085 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1086 | if (!mxt_object_writable(object->type)) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1087 | continue; |
| 1088 | |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1089 | for (j = 0; j < object->size + 1; j++) { |
| 1090 | config_offset = index + j; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1091 | if (config_offset > config_info->config_length) { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1092 | dev_err(dev, "Not enough config data!\n"); |
| 1093 | return -EINVAL; |
| 1094 | } |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1095 | mxt_write_object(data, object->type, j, |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1096 | config_info->config[config_offset]); |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1097 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1098 | index += object->size + 1; |
| 1099 | } |
| 1100 | |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1104 | static int mxt_make_highchg(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1105 | { |
| 1106 | struct device *dev = &data->client->dev; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 1107 | struct mxt_message message; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1108 | int count = 10; |
| 1109 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1110 | |
| 1111 | /* Read dummy message to make high CHG pin */ |
| 1112 | do { |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 1113 | error = mxt_read_message(data, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1114 | if (error) |
| 1115 | return error; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 1116 | } while (message.reportid != 0xff && --count); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1117 | |
| 1118 | if (!count) { |
| 1119 | dev_err(dev, "CHG pin isn't cleared\n"); |
| 1120 | return -EBUSY; |
| 1121 | } |
| 1122 | |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1126 | static int mxt_get_info(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1127 | { |
| 1128 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1129 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1130 | int error; |
| 1131 | u8 val; |
| 1132 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1133 | error = mxt_read_reg(client, MXT_FAMILY_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1134 | if (error) |
| 1135 | return error; |
| 1136 | info->family_id = val; |
| 1137 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1138 | error = mxt_read_reg(client, MXT_VARIANT_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1139 | if (error) |
| 1140 | return error; |
| 1141 | info->variant_id = val; |
| 1142 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1143 | error = mxt_read_reg(client, MXT_VERSION, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1144 | if (error) |
| 1145 | return error; |
| 1146 | info->version = val; |
| 1147 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1148 | error = mxt_read_reg(client, MXT_BUILD, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1149 | if (error) |
| 1150 | return error; |
| 1151 | info->build = val; |
| 1152 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1153 | error = mxt_read_reg(client, MXT_OBJECT_NUM, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1154 | if (error) |
| 1155 | return error; |
| 1156 | info->object_num = val; |
| 1157 | |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1161 | static int mxt_get_object_table(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1162 | { |
| 1163 | int error; |
| 1164 | int i; |
| 1165 | u16 reg; |
| 1166 | u8 reportid = 0; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1167 | u8 buf[MXT_OBJECT_SIZE]; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1168 | bool found_t38 = false; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1169 | |
| 1170 | for (i = 0; i < data->info.object_num; i++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1171 | struct mxt_object *object = data->object_table + i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1172 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1173 | reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; |
| 1174 | error = mxt_read_object_table(data->client, reg, buf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1175 | if (error) |
| 1176 | return error; |
| 1177 | |
| 1178 | object->type = buf[0]; |
| 1179 | object->start_address = (buf[2] << 8) | buf[1]; |
| 1180 | object->size = buf[3]; |
| 1181 | object->instances = buf[4]; |
| 1182 | object->num_report_ids = buf[5]; |
| 1183 | |
| 1184 | if (object->num_report_ids) { |
| 1185 | reportid += object->num_report_ids * |
| 1186 | (object->instances + 1); |
| 1187 | object->max_reportid = reportid; |
| 1188 | } |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1189 | |
| 1190 | /* Calculate index for config major version in config array. |
| 1191 | * Major version is the first byte in object T38. |
| 1192 | */ |
Jing Lin | 8a9472d | 2012-03-21 15:43:45 -0700 | [diff] [blame] | 1193 | if (object->type == MXT_SPT_USERDATA_T38) { |
| 1194 | data->t38_start_addr = object->start_address; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1195 | found_t38 = true; |
Jing Lin | 8a9472d | 2012-03-21 15:43:45 -0700 | [diff] [blame] | 1196 | } |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1197 | if (!found_t38 && mxt_object_writable(object->type)) |
| 1198 | data->cfg_version_idx += object->size + 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1204 | static int compare_versions(const u8 *v1, const u8 *v2) |
| 1205 | { |
| 1206 | int i; |
| 1207 | |
| 1208 | if (!v1 || !v2) |
| 1209 | return -EINVAL; |
| 1210 | |
| 1211 | /* The major version number stays the same across different versions for |
| 1212 | * a particular controller on a target. The minor and sub-minor version |
| 1213 | * numbers indicate which version is newer. |
| 1214 | */ |
| 1215 | if (v1[0] != v2[0]) |
| 1216 | return -EINVAL; |
| 1217 | |
| 1218 | for (i = 1; i < MXT_CFG_VERSION_LEN; i++) { |
| 1219 | if (v1[i] > v2[i]) |
| 1220 | return MXT_CFG_VERSION_LESS; /* v2 is older */ |
| 1221 | |
| 1222 | if (v1[i] < v2[i]) |
| 1223 | return MXT_CFG_VERSION_GREATER; /* v2 is newer */ |
| 1224 | } |
| 1225 | |
| 1226 | return MXT_CFG_VERSION_EQUAL; /* v1 and v2 are equal */ |
| 1227 | } |
| 1228 | |
| 1229 | static void mxt_check_config_version(struct mxt_data *data, |
| 1230 | const struct mxt_config_info *cfg_info, |
| 1231 | bool match_major, |
| 1232 | const u8 **cfg_version_found, |
| 1233 | bool *found_cfg_major_match) |
| 1234 | { |
| 1235 | const u8 *cfg_version; |
| 1236 | int result = -EINVAL; |
| 1237 | |
| 1238 | cfg_version = cfg_info->config + data->cfg_version_idx; |
| 1239 | |
| 1240 | if (*cfg_version_found) |
| 1241 | result = compare_versions(*cfg_version_found, cfg_version); |
| 1242 | |
| 1243 | if (match_major) { |
| 1244 | if (result >= MXT_CFG_VERSION_EQUAL) |
| 1245 | *found_cfg_major_match = true; |
| 1246 | |
| 1247 | if (result == MXT_CFG_VERSION_EQUAL || |
| 1248 | result == MXT_CFG_VERSION_GREATER) { |
| 1249 | data->config_info = cfg_info; |
| 1250 | data->fw_name = cfg_info->fw_name; |
| 1251 | *cfg_version_found = cfg_version; |
| 1252 | } |
| 1253 | |
| 1254 | if (result == MXT_CFG_VERSION_GREATER) |
| 1255 | data->update_cfg = true; |
| 1256 | } else if (!*cfg_version_found || result == MXT_CFG_VERSION_GREATER) { |
| 1257 | data->config_info = cfg_info; |
| 1258 | data->fw_name = cfg_info->fw_name; |
| 1259 | data->update_cfg = true; |
| 1260 | *cfg_version_found = cfg_version; |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | /* If the controller's config version has a non-zero major number, call this |
| 1265 | * function with match_major = true to look for the latest config present in |
| 1266 | * the pdata based on matching family id, variant id, f/w version, build, and |
| 1267 | * config major number. If the controller is programmed with wrong config data |
| 1268 | * previously, call this function with match_major = false to look for latest |
| 1269 | * config based on based on matching family id, variant id, f/w version and |
| 1270 | * build only. |
| 1271 | */ |
| 1272 | static int mxt_search_config_array(struct mxt_data *data, bool match_major) |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1273 | { |
| 1274 | |
| 1275 | const struct mxt_platform_data *pdata = data->pdata; |
| 1276 | const struct mxt_config_info *cfg_info; |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1277 | const struct mxt_info *info = &data->info; |
| 1278 | const u8 *cfg_version_found; |
| 1279 | bool found_cfg_major_match = false; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1280 | int i; |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1281 | |
| 1282 | cfg_version_found = match_major ? data->cfg_version : NULL; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1283 | |
| 1284 | for (i = 0; i < pdata->config_array_size; i++) { |
| 1285 | |
| 1286 | cfg_info = &pdata->config_array[i]; |
| 1287 | |
| 1288 | if (!cfg_info->config || !cfg_info->config_length) |
| 1289 | continue; |
| 1290 | |
| 1291 | if (info->family_id == cfg_info->family_id && |
| 1292 | info->variant_id == cfg_info->variant_id && |
| 1293 | info->version == cfg_info->version && |
| 1294 | info->build == cfg_info->build) { |
| 1295 | |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1296 | mxt_check_config_version(data, cfg_info, match_major, |
| 1297 | &cfg_version_found, &found_cfg_major_match); |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1298 | } |
| 1299 | } |
| 1300 | |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1301 | if (data->config_info || found_cfg_major_match) |
| 1302 | return 0; |
| 1303 | |
| 1304 | data->config_info = NULL; |
Anirudh Ghayal | 0bcb5b5 | 2012-02-17 14:58:25 -0800 | [diff] [blame] | 1305 | data->fw_name = NULL; |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1306 | |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1307 | return -EINVAL; |
| 1308 | } |
| 1309 | |
| 1310 | static int mxt_get_config(struct mxt_data *data) |
| 1311 | { |
| 1312 | const struct mxt_platform_data *pdata = data->pdata; |
| 1313 | struct device *dev = &data->client->dev; |
| 1314 | struct mxt_object *object; |
| 1315 | int error; |
| 1316 | |
| 1317 | if (!pdata->config_array || !pdata->config_array_size) { |
| 1318 | dev_dbg(dev, "No cfg data provided by platform data\n"); |
| 1319 | return 0; |
| 1320 | } |
| 1321 | |
| 1322 | /* Get current config version */ |
| 1323 | object = mxt_get_object(data, MXT_SPT_USERDATA_T38); |
| 1324 | if (!object) { |
| 1325 | dev_err(dev, "Unable to obtain USERDATA object\n"); |
| 1326 | return -EINVAL; |
| 1327 | } |
| 1328 | |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1329 | error = __mxt_read_reg(data->client, object->start_address, |
| 1330 | sizeof(data->cfg_version), data->cfg_version); |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1331 | if (error) { |
| 1332 | dev_err(dev, "Unable to read config version\n"); |
| 1333 | return error; |
| 1334 | } |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1335 | dev_info(dev, "Current config version on the controller is %d.%d.%d\n", |
| 1336 | data->cfg_version[0], data->cfg_version[1], |
| 1337 | data->cfg_version[2]); |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1338 | |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 1339 | /* configuration update requires major match */ |
| 1340 | error = mxt_search_config_array(data, true); |
| 1341 | |
| 1342 | /* if no_force_update is false , try again with false |
| 1343 | as the second parameter to mxt_search_config_array */ |
| 1344 | if (error && (data->no_force_update == false)) |
| 1345 | error = mxt_search_config_array(data, false); |
| 1346 | |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1347 | if (error) { |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 1348 | dev_err(dev, |
| 1349 | "Unable to find matching config in pdata\n"); |
| 1350 | return error; |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1351 | } |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1352 | |
| 1353 | return 0; |
| 1354 | } |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1355 | |
Jing Lin | 64fdd1f | 2012-12-20 17:08:28 -0800 | [diff] [blame] | 1356 | static void mxt_power_on_delay(struct mxt_data *data) |
| 1357 | { |
| 1358 | const struct mxt_platform_data *pdata = data->pdata; |
| 1359 | const struct mxt_config_info *cfg_info; |
| 1360 | u32 delay = 0; |
| 1361 | int i; |
| 1362 | |
| 1363 | for (i = 0; i < pdata->config_array_size; i++) { |
| 1364 | cfg_info = &pdata->config_array[i]; |
| 1365 | |
| 1366 | switch (cfg_info->family_id) { |
| 1367 | case MXT224_ID: |
| 1368 | delay = max_t(u32, delay, MXT224_POWER_ON_TIME); |
| 1369 | break; |
| 1370 | case MXT224E_ID: |
| 1371 | delay = max_t(u32, delay, MXT224E_POWER_ON_TIME); |
| 1372 | break; |
| 1373 | case MXT336S_ID: |
| 1374 | delay = max_t(u32, delay, MXT336S_POWER_ON_TIME); |
| 1375 | break; |
| 1376 | case MXT1386_ID: |
| 1377 | delay = max_t(u32, delay, |
| 1378 | max_t(u32, MXT1386_POWER_ON_TIME, |
| 1379 | MXT1386E_POWER_ON_TIME)); |
| 1380 | break; |
| 1381 | case MXT1664S_ID: |
| 1382 | delay = max_t(u32, delay, MXT1664S_POWER_ON_TIME); |
| 1383 | break; |
| 1384 | default: |
| 1385 | delay = max_t(u32, delay, MXT_POWER_ON_TIME); |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | msleep(delay); |
| 1390 | } |
| 1391 | |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1392 | static void mxt_reset_delay(struct mxt_data *data) |
| 1393 | { |
| 1394 | struct mxt_info *info = &data->info; |
| 1395 | |
| 1396 | switch (info->family_id) { |
| 1397 | case MXT224_ID: |
| 1398 | msleep(MXT224_RESET_TIME); |
| 1399 | break; |
Amy Maloche | 380cc0b | 2011-11-03 12:55:04 -0700 | [diff] [blame] | 1400 | case MXT224E_ID: |
| 1401 | msleep(MXT224E_RESET_TIME); |
| 1402 | break; |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 1403 | case MXT336S_ID: |
| 1404 | msleep(MXT336S_RESET_TIME); |
Jing Lin | 64fdd1f | 2012-12-20 17:08:28 -0800 | [diff] [blame] | 1405 | break; |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1406 | case MXT1386_ID: |
Jing Lin | 64fdd1f | 2012-12-20 17:08:28 -0800 | [diff] [blame] | 1407 | msleep(max_t(u32, MXT1386_RESET_TIME, MXT1386E_RESET_TIME)); |
| 1408 | break; |
Amy Maloche | 41f1cc3 | 2012-07-12 13:02:27 -0700 | [diff] [blame] | 1409 | case MXT1664S_ID: |
| 1410 | msleep(MXT1664S_RESET_TIME); |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1411 | break; |
| 1412 | default: |
| 1413 | msleep(MXT_RESET_TIME); |
| 1414 | } |
| 1415 | } |
| 1416 | |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1417 | static int mxt_backup_nv(struct mxt_data *data) |
| 1418 | { |
| 1419 | int error; |
| 1420 | u8 command_register; |
| 1421 | int timeout_counter = 0; |
| 1422 | |
| 1423 | /* Backup to memory */ |
| 1424 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
| 1425 | MXT_COMMAND_BACKUPNV, |
| 1426 | MXT_BACKUP_VALUE); |
| 1427 | msleep(MXT_BACKUP_TIME); |
| 1428 | |
| 1429 | do { |
| 1430 | error = mxt_read_object(data, MXT_GEN_COMMAND_T6, |
| 1431 | MXT_COMMAND_BACKUPNV, |
| 1432 | &command_register); |
| 1433 | if (error) |
| 1434 | return error; |
| 1435 | |
| 1436 | usleep_range(1000, 2000); |
| 1437 | |
| 1438 | } while ((command_register != 0) && (++timeout_counter <= 100)); |
| 1439 | |
| 1440 | if (timeout_counter > 100) { |
| 1441 | dev_err(&data->client->dev, "No response after backup!\n"); |
| 1442 | return -EIO; |
| 1443 | } |
| 1444 | |
| 1445 | /* Soft reset */ |
| 1446 | mxt_write_object(data, MXT_GEN_COMMAND_T6, MXT_COMMAND_RESET, 1); |
| 1447 | |
| 1448 | mxt_reset_delay(data); |
| 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
Jing Lin | 412aedc | 2012-02-28 13:57:19 -0800 | [diff] [blame] | 1453 | static int mxt_save_objects(struct mxt_data *data) |
| 1454 | { |
| 1455 | struct i2c_client *client = data->client; |
| 1456 | struct mxt_object *t7_object; |
| 1457 | struct mxt_object *t9_object; |
| 1458 | struct mxt_object *t15_object; |
Mohan Pallaka | b6acab4 | 2012-06-13 11:59:04 +0530 | [diff] [blame] | 1459 | struct mxt_object *t42_object; |
Jing Lin | 412aedc | 2012-02-28 13:57:19 -0800 | [diff] [blame] | 1460 | int error; |
| 1461 | |
| 1462 | /* Store T7 and T9 locally, used in suspend/resume operations */ |
| 1463 | t7_object = mxt_get_object(data, MXT_GEN_POWER_T7); |
| 1464 | if (!t7_object) { |
| 1465 | dev_err(&client->dev, "Failed to get T7 object\n"); |
| 1466 | return -EINVAL; |
| 1467 | } |
| 1468 | |
| 1469 | data->t7_start_addr = t7_object->start_address; |
| 1470 | error = __mxt_read_reg(client, data->t7_start_addr, |
| 1471 | T7_DATA_SIZE, data->t7_data); |
| 1472 | if (error < 0) { |
| 1473 | dev_err(&client->dev, |
| 1474 | "Failed to save current power state\n"); |
| 1475 | return error; |
| 1476 | } |
| 1477 | |
Jing Lin | 412aedc | 2012-02-28 13:57:19 -0800 | [diff] [blame] | 1478 | /* Store T9, T15's min and max report ids */ |
| 1479 | t9_object = mxt_get_object(data, MXT_TOUCH_MULTI_T9); |
| 1480 | if (!t9_object) { |
| 1481 | dev_err(&client->dev, "Failed to get T9 object\n"); |
| 1482 | return -EINVAL; |
| 1483 | } |
| 1484 | data->t9_max_reportid = t9_object->max_reportid; |
| 1485 | data->t9_min_reportid = t9_object->max_reportid - |
Amy Maloche | e8a03c5 | 2012-09-24 16:33:35 -0700 | [diff] [blame] | 1486 | (t9_object->num_report_ids * |
| 1487 | (t9_object->instances + 1)) + 1; |
Jing Lin | 412aedc | 2012-02-28 13:57:19 -0800 | [diff] [blame] | 1488 | |
| 1489 | if (data->pdata->key_codes) { |
| 1490 | t15_object = mxt_get_object(data, MXT_TOUCH_KEYARRAY_T15); |
| 1491 | if (!t15_object) |
| 1492 | dev_dbg(&client->dev, "T15 object is not available\n"); |
| 1493 | else { |
| 1494 | data->t15_max_reportid = t15_object->max_reportid; |
| 1495 | data->t15_min_reportid = t15_object->max_reportid - |
Amy Maloche | e8a03c5 | 2012-09-24 16:33:35 -0700 | [diff] [blame] | 1496 | (t15_object->num_report_ids * |
| 1497 | (t15_object->instances + 1)) + 1; |
Jing Lin | 412aedc | 2012-02-28 13:57:19 -0800 | [diff] [blame] | 1498 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
Mohan Pallaka | b6acab4 | 2012-06-13 11:59:04 +0530 | [diff] [blame] | 1501 | /* Store T42 min and max report ids */ |
| 1502 | t42_object = mxt_get_object(data, MXT_PROCI_TOUCHSUPPRESSION_T42); |
| 1503 | if (!t42_object) |
| 1504 | dev_dbg(&client->dev, "T42 object is not available\n"); |
| 1505 | else { |
| 1506 | data->t42_max_reportid = t42_object->max_reportid; |
| 1507 | data->t42_min_reportid = t42_object->max_reportid - |
Amy Maloche | e8a03c5 | 2012-09-24 16:33:35 -0700 | [diff] [blame] | 1508 | (t42_object->num_report_ids * |
| 1509 | (t42_object->instances + 1)) + 1; |
Mohan Pallaka | b6acab4 | 2012-06-13 11:59:04 +0530 | [diff] [blame] | 1510 | } |
| 1511 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1512 | return 0; |
| 1513 | } |
| 1514 | |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 1515 | static int mxt_update_cfg(struct mxt_data *data) |
| 1516 | { |
| 1517 | int error; |
| 1518 | const u8 *cfg_ver; |
| 1519 | |
| 1520 | /* Get config data from platform data */ |
| 1521 | error = mxt_get_config(data); |
| 1522 | if (error) |
| 1523 | dev_dbg(&data->client->dev, "Config info not found.\n"); |
| 1524 | |
| 1525 | /* Check register init values */ |
| 1526 | if (data->config_info && data->config_info->config) { |
| 1527 | if (data->update_cfg) { |
| 1528 | error = mxt_check_reg_init(data); |
| 1529 | if (error) { |
| 1530 | dev_err(&data->client->dev, |
| 1531 | "Failed to check reg init value\n"); |
| 1532 | return error; |
| 1533 | } |
| 1534 | |
| 1535 | error = mxt_backup_nv(data); |
| 1536 | if (error) { |
| 1537 | dev_err(&data->client->dev, "Failed to back up NV\n"); |
| 1538 | return error; |
| 1539 | } |
| 1540 | |
| 1541 | cfg_ver = data->config_info->config + |
| 1542 | data->cfg_version_idx; |
| 1543 | dev_info(&data->client->dev, |
| 1544 | "Config updated from %d.%d.%d to %d.%d.%d\n", |
| 1545 | data->cfg_version[0], data->cfg_version[1], |
| 1546 | data->cfg_version[2], |
| 1547 | cfg_ver[0], cfg_ver[1], cfg_ver[2]); |
| 1548 | |
| 1549 | memcpy(data->cfg_version, cfg_ver, MXT_CFG_VERSION_LEN); |
| 1550 | } |
| 1551 | } else { |
| 1552 | dev_info(&data->client->dev, |
| 1553 | "No cfg data defined, skipping check reg init\n"); |
| 1554 | } |
| 1555 | |
| 1556 | error = mxt_save_objects(data); |
| 1557 | if (error) |
| 1558 | return error; |
| 1559 | |
| 1560 | return 0; |
| 1561 | } |
| 1562 | |
| 1563 | |
| 1564 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1565 | static int mxt_initialize(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1566 | { |
| 1567 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1568 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1569 | int error; |
| 1570 | u8 val; |
| 1571 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1572 | error = mxt_get_info(data); |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1573 | if (error) { |
| 1574 | /* Try bootloader mode */ |
| 1575 | error = mxt_switch_to_bootloader_address(data); |
| 1576 | if (error) |
| 1577 | return error; |
| 1578 | |
| 1579 | error = mxt_check_bootloader(client, MXT_APP_CRC_FAIL); |
| 1580 | if (error) |
| 1581 | return error; |
| 1582 | |
| 1583 | dev_err(&client->dev, "Application CRC failure\n"); |
| 1584 | data->state = BOOTLOADER; |
| 1585 | |
| 1586 | return 0; |
| 1587 | } |
| 1588 | |
| 1589 | dev_info(&client->dev, |
| 1590 | "Family ID: %d Variant ID: %d Version: %d.%d " |
| 1591 | "Build: 0x%02X Object Num: %d\n", |
| 1592 | info->family_id, info->variant_id, |
| 1593 | info->version >> 4, info->version & 0xf, |
| 1594 | info->build, info->object_num); |
| 1595 | |
| 1596 | data->state = APPMODE; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1597 | |
| 1598 | data->object_table = kcalloc(info->object_num, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1599 | sizeof(struct mxt_object), |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1600 | GFP_KERNEL); |
| 1601 | if (!data->object_table) { |
| 1602 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 1603 | return -ENOMEM; |
| 1604 | } |
| 1605 | |
| 1606 | /* Get object table information */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1607 | error = mxt_get_object_table(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1608 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1609 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1610 | |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 1611 | error = mxt_update_cfg(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1612 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1613 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1614 | /* Update matrix size at info struct */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1615 | error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1616 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1617 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1618 | info->matrix_xsize = val; |
| 1619 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1620 | error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1621 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1622 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1623 | info->matrix_ysize = val; |
| 1624 | |
| 1625 | dev_info(&client->dev, |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1626 | "Matrix X Size: %d Matrix Y Size: %d\n", |
| 1627 | info->matrix_xsize, info->matrix_ysize); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1628 | |
| 1629 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1630 | |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1631 | free_object_table: |
| 1632 | kfree(data->object_table); |
| 1633 | return error; |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1636 | static ssize_t mxt_object_show(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1637 | struct device_attribute *attr, char *buf) |
| 1638 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1639 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1640 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1641 | int count = 0; |
| 1642 | int i, j; |
| 1643 | int error; |
| 1644 | u8 val; |
| 1645 | |
| 1646 | for (i = 0; i < data->info.object_num; i++) { |
| 1647 | object = data->object_table + i; |
| 1648 | |
Daniel Kurtz | 626af86 | 2011-10-06 15:43:20 -0700 | [diff] [blame] | 1649 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 1650 | "Object[%d] (Type %d)\n", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1651 | i + 1, object->type); |
Daniel Kurtz | 626af86 | 2011-10-06 15:43:20 -0700 | [diff] [blame] | 1652 | if (count >= PAGE_SIZE) |
| 1653 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1654 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1655 | if (!mxt_object_readable(object->type)) { |
Daniel Kurtz | 626af86 | 2011-10-06 15:43:20 -0700 | [diff] [blame] | 1656 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 1657 | "\n"); |
| 1658 | if (count >= PAGE_SIZE) |
| 1659 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1660 | continue; |
| 1661 | } |
| 1662 | |
| 1663 | for (j = 0; j < object->size + 1; j++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1664 | error = mxt_read_object(data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1665 | object->type, j, &val); |
| 1666 | if (error) |
| 1667 | return error; |
| 1668 | |
Daniel Kurtz | 626af86 | 2011-10-06 15:43:20 -0700 | [diff] [blame] | 1669 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 1670 | "\t[%2d]: %02x (%d)\n", j, val, val); |
| 1671 | if (count >= PAGE_SIZE) |
| 1672 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
Daniel Kurtz | 626af86 | 2011-10-06 15:43:20 -0700 | [diff] [blame] | 1675 | count += snprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 1676 | if (count >= PAGE_SIZE) |
| 1677 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | return count; |
| 1681 | } |
| 1682 | |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1683 | static int strtobyte(const char *data, u8 *value) |
| 1684 | { |
| 1685 | char str[3]; |
| 1686 | |
| 1687 | str[0] = data[0]; |
| 1688 | str[1] = data[1]; |
| 1689 | str[2] = '\0'; |
| 1690 | |
| 1691 | return kstrtou8(str, 16, value); |
| 1692 | } |
| 1693 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1694 | static int mxt_load_fw(struct device *dev, const char *fn) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1695 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1696 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1697 | struct i2c_client *client = data->client; |
| 1698 | const struct firmware *fw = NULL; |
| 1699 | unsigned int frame_size; |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1700 | unsigned int retry = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1701 | unsigned int pos = 0; |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1702 | int ret, i, max_frame_size; |
| 1703 | u8 *frame; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1704 | |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1705 | switch (data->info.family_id) { |
| 1706 | case MXT224_ID: |
Mohan Pallaka | 78fe53c | 2012-07-09 14:32:28 +0530 | [diff] [blame] | 1707 | case MXT224E_ID: |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 1708 | case MXT336S_ID: |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1709 | max_frame_size = MXT_SINGLE_FW_MAX_FRAME_SIZE; |
| 1710 | break; |
| 1711 | case MXT1386_ID: |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 1712 | case MXT1664S_ID: |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1713 | max_frame_size = MXT_CHIPSET_FW_MAX_FRAME_SIZE; |
| 1714 | break; |
| 1715 | default: |
| 1716 | return -EINVAL; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1719 | frame = kmalloc(max_frame_size, GFP_KERNEL); |
| 1720 | if (!frame) { |
| 1721 | dev_err(dev, "Unable to allocate memory for frame data\n"); |
| 1722 | return -ENOMEM; |
| 1723 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1724 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1725 | ret = request_firmware(&fw, fn, dev); |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1726 | if (ret < 0) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1727 | dev_err(dev, "Unable to open firmware %s\n", fn); |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1728 | goto free_frame; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1729 | } |
| 1730 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1731 | if (data->state != BOOTLOADER) { |
| 1732 | /* Change to the bootloader mode */ |
| 1733 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
| 1734 | MXT_COMMAND_RESET, MXT_BOOT_VALUE); |
| 1735 | mxt_reset_delay(data); |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1736 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1737 | ret = mxt_switch_to_bootloader_address(data); |
| 1738 | if (ret) |
| 1739 | goto release_firmware; |
| 1740 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1741 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1742 | ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD); |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1743 | if (ret) { |
| 1744 | /* Bootloader may still be unlocked from previous update |
| 1745 | * attempt */ |
| 1746 | ret = mxt_check_bootloader(client, |
| 1747 | MXT_WAITING_FRAME_DATA); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1748 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1749 | if (ret) |
| 1750 | goto return_to_app_mode; |
| 1751 | } else { |
| 1752 | dev_info(dev, "Unlocking bootloader\n"); |
| 1753 | /* Unlock bootloader */ |
| 1754 | mxt_unlock_bootloader(client); |
| 1755 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1756 | |
| 1757 | while (pos < fw->size) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1758 | ret = mxt_check_bootloader(client, |
| 1759 | MXT_WAITING_FRAME_DATA); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1760 | if (ret) |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1761 | goto release_firmware; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1762 | |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1763 | /* Get frame length MSB */ |
| 1764 | ret = strtobyte(fw->data + pos, frame); |
| 1765 | if (ret) |
| 1766 | goto release_firmware; |
| 1767 | |
| 1768 | /* Get frame length LSB */ |
| 1769 | ret = strtobyte(fw->data + pos + 2, frame + 1); |
| 1770 | if (ret) |
| 1771 | goto release_firmware; |
| 1772 | |
| 1773 | frame_size = ((*frame << 8) | *(frame + 1)); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1774 | |
| 1775 | /* We should add 2 at frame size as the the firmware data is not |
| 1776 | * included the CRC bytes. |
| 1777 | */ |
| 1778 | frame_size += 2; |
| 1779 | |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1780 | if (frame_size > max_frame_size) { |
| 1781 | dev_err(dev, "Invalid frame size - %d\n", frame_size); |
| 1782 | ret = -EINVAL; |
| 1783 | goto release_firmware; |
| 1784 | } |
| 1785 | |
| 1786 | /* Convert frame data and CRC from hex to binary */ |
| 1787 | for (i = 2; i < frame_size; i++) { |
| 1788 | ret = strtobyte(fw->data + pos + i * 2, frame + i); |
| 1789 | if (ret) |
| 1790 | goto release_firmware; |
| 1791 | } |
| 1792 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1793 | /* Write one frame to device */ |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1794 | mxt_fw_write(client, frame, frame_size); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1795 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1796 | ret = mxt_check_bootloader(client, |
| 1797 | MXT_FRAME_CRC_PASS); |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1798 | if (ret) { |
| 1799 | retry++; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1800 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1801 | /* Back off by 20ms per retry */ |
| 1802 | msleep(retry * 20); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1803 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1804 | if (retry > 20) |
| 1805 | goto release_firmware; |
| 1806 | } else { |
| 1807 | retry = 0; |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1808 | pos += frame_size * 2; |
| 1809 | dev_dbg(dev, "Updated %d/%zd bytes\n", pos, fw->size); |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1810 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1813 | return_to_app_mode: |
| 1814 | mxt_switch_to_appmode_address(data); |
| 1815 | release_firmware: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1816 | release_firmware(fw); |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1817 | free_frame: |
| 1818 | kfree(frame); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1819 | |
| 1820 | return ret; |
| 1821 | } |
| 1822 | |
Anirudh Ghayal | 6c3b37b | 2012-02-23 18:39:42 -0800 | [diff] [blame] | 1823 | static const char * |
| 1824 | mxt_search_fw_name(struct mxt_data *data, u8 bootldr_id) |
| 1825 | { |
| 1826 | const struct mxt_platform_data *pdata = data->pdata; |
| 1827 | const struct mxt_config_info *cfg_info; |
| 1828 | const char *fw_name = NULL; |
| 1829 | int i; |
| 1830 | |
| 1831 | for (i = 0; i < pdata->config_array_size; i++) { |
| 1832 | cfg_info = &pdata->config_array[i]; |
| 1833 | if (bootldr_id == cfg_info->bootldr_id && cfg_info->fw_name) { |
| 1834 | data->config_info = cfg_info; |
| 1835 | data->info.family_id = cfg_info->family_id; |
| 1836 | fw_name = cfg_info->fw_name; |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | return fw_name; |
| 1841 | } |
| 1842 | |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 1843 | static ssize_t mxt_force_cfg_update_store(struct device *dev, |
| 1844 | struct device_attribute *attr, |
| 1845 | const char *buf, size_t count) |
| 1846 | { |
| 1847 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1848 | int flag = buf[0]-'0'; |
| 1849 | int error; |
| 1850 | data->no_force_update = !flag; |
| 1851 | |
| 1852 | if (data->state == APPMODE) { |
| 1853 | disable_irq(data->irq); |
| 1854 | error = mxt_update_cfg(data); |
| 1855 | enable_irq(data->irq); |
| 1856 | if (error) |
| 1857 | return error; |
| 1858 | } else { |
| 1859 | dev_err(dev, |
| 1860 | "Not in APPMODE, Unable to force cfg update\n"); |
| 1861 | return -EINVAL; |
| 1862 | } |
| 1863 | |
| 1864 | return count; |
| 1865 | } |
| 1866 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1867 | static ssize_t mxt_update_fw_store(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1868 | struct device_attribute *attr, |
| 1869 | const char *buf, size_t count) |
| 1870 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1871 | struct mxt_data *data = dev_get_drvdata(dev); |
Mohan Pallaka | 78fe53c | 2012-07-09 14:32:28 +0530 | [diff] [blame] | 1872 | int error, address; |
Anirudh Ghayal | 6c3b37b | 2012-02-23 18:39:42 -0800 | [diff] [blame] | 1873 | const char *fw_name; |
| 1874 | u8 bootldr_id; |
Jing Lin | 8a9472d | 2012-03-21 15:43:45 -0700 | [diff] [blame] | 1875 | u8 cfg_version[MXT_CFG_VERSION_LEN] = {0}; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1876 | |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 1877 | data->no_force_update = false; |
Anirudh Ghayal | 0bcb5b5 | 2012-02-17 14:58:25 -0800 | [diff] [blame] | 1878 | /* If fw_name is set, then the existing firmware has an upgrade */ |
| 1879 | if (!data->fw_name) { |
Anirudh Ghayal | 6c3b37b | 2012-02-23 18:39:42 -0800 | [diff] [blame] | 1880 | /* |
| 1881 | * If the device boots up in the bootloader mode, check if |
| 1882 | * there is a firmware to upgrade. |
| 1883 | */ |
| 1884 | if (data->state == BOOTLOADER) { |
| 1885 | bootldr_id = mxt_get_bootloader_id(data->client); |
| 1886 | if (bootldr_id <= 0) { |
| 1887 | dev_err(dev, |
| 1888 | "Unable to retrieve bootloader id\n"); |
| 1889 | return -EINVAL; |
| 1890 | } |
| 1891 | fw_name = mxt_search_fw_name(data, bootldr_id); |
| 1892 | if (fw_name == NULL) { |
| 1893 | dev_err(dev, |
| 1894 | "Unable to find fw from bootloader id\n"); |
| 1895 | return -EINVAL; |
| 1896 | } |
| 1897 | } else { |
| 1898 | /* In APPMODE, if the f/w name does not exist, quit */ |
| 1899 | dev_err(dev, |
| 1900 | "Firmware name not specified in platform data\n"); |
| 1901 | return -EINVAL; |
| 1902 | } |
| 1903 | } else { |
| 1904 | fw_name = data->fw_name; |
Anirudh Ghayal | 0bcb5b5 | 2012-02-17 14:58:25 -0800 | [diff] [blame] | 1905 | } |
| 1906 | |
Anirudh Ghayal | 6c3b37b | 2012-02-23 18:39:42 -0800 | [diff] [blame] | 1907 | dev_info(dev, "Upgrading the firmware file to %s\n", fw_name); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1908 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1909 | disable_irq(data->irq); |
| 1910 | |
Anirudh Ghayal | 6c3b37b | 2012-02-23 18:39:42 -0800 | [diff] [blame] | 1911 | error = mxt_load_fw(dev, fw_name); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1912 | if (error) { |
| 1913 | dev_err(dev, "The firmware update failed(%d)\n", error); |
| 1914 | count = error; |
| 1915 | } else { |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1916 | dev_info(dev, "The firmware update succeeded\n"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1917 | |
| 1918 | /* Wait for reset */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1919 | msleep(MXT_FWRESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1920 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1921 | data->state = INIT; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1922 | kfree(data->object_table); |
| 1923 | data->object_table = NULL; |
Jing Lin | cc974cb | 2012-02-01 23:13:14 -0800 | [diff] [blame] | 1924 | data->cfg_version_idx = 0; |
Jing Lin | a962ba3 | 2012-12-03 09:46:33 -0800 | [diff] [blame] | 1925 | data->config_info = NULL; |
Jing Lin | 8fadad7 | 2012-02-24 10:10:50 -0800 | [diff] [blame] | 1926 | data->update_cfg = false; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1927 | |
Mohan Pallaka | 78fe53c | 2012-07-09 14:32:28 +0530 | [diff] [blame] | 1928 | /* T38 object address might have changed, read it from |
| 1929 | touch controller */ |
| 1930 | address = mxt_get_object_address(dev, MXT_SPT_USERDATA_T38); |
| 1931 | if (address < 0) { |
| 1932 | dev_err(dev, "T38 required for touch operation\n"); |
| 1933 | return -EINVAL; |
| 1934 | } |
| 1935 | |
| 1936 | data->t38_start_addr = address; |
| 1937 | |
Jing Lin | 8a9472d | 2012-03-21 15:43:45 -0700 | [diff] [blame] | 1938 | error = __mxt_write_reg(data->client, data->t38_start_addr, |
| 1939 | sizeof(cfg_version), cfg_version); |
| 1940 | if (error) |
| 1941 | dev_err(dev, |
| 1942 | "Unable to zero out config version after fw upgrade\n"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1943 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1944 | mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1947 | if (data->state == APPMODE) { |
| 1948 | enable_irq(data->irq); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1949 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 1950 | error = mxt_make_highchg(data); |
| 1951 | if (error) |
| 1952 | return error; |
| 1953 | } |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1954 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1955 | return count; |
| 1956 | } |
| 1957 | |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 1958 | #if defined(CONFIG_SECURE_TOUCH) |
| 1959 | |
| 1960 | static ssize_t mxt_secure_touch_enable_show(struct device *dev, |
| 1961 | struct device_attribute *attr, char *buf) |
| 1962 | { |
| 1963 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1964 | return scnprintf(buf, PAGE_SIZE, "%d", atomic_read(&data->st_enabled)); |
| 1965 | } |
| 1966 | /* |
| 1967 | * Accept only "0" and "1" valid values. |
| 1968 | * "0" will reset the st_enabled flag, then wake up the reading process. |
| 1969 | * The bus driver is notified via pm_runtime that it is not required to stay |
| 1970 | * awake anymore. |
| 1971 | * It will also make sure the queue of events is emptied in the controller, |
| 1972 | * in case a touch happened in between the secure touch being disabled and |
| 1973 | * the local ISR being ungated. |
| 1974 | * "1" will set the st_enabled flag and clear the st_pending_irqs flag. |
| 1975 | * The bus driver is requested via pm_runtime to stay awake. |
| 1976 | */ |
| 1977 | static ssize_t mxt_secure_touch_enable_store(struct device *dev, |
| 1978 | struct device_attribute *attr, |
| 1979 | const char *buf, size_t count) |
| 1980 | { |
| 1981 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1982 | unsigned long value; |
| 1983 | int err = 0; |
| 1984 | |
| 1985 | if (count > 2) |
| 1986 | return -EINVAL; |
| 1987 | |
| 1988 | err = kstrtoul(buf, 10, &value); |
| 1989 | if (err != 0) |
| 1990 | return err; |
| 1991 | |
| 1992 | err = count; |
| 1993 | |
| 1994 | switch (value) { |
| 1995 | case 0: |
| 1996 | if (atomic_read(&data->st_enabled) == 0) |
| 1997 | break; |
| 1998 | |
| 1999 | pm_runtime_put(&data->client->adapter->dev); |
| 2000 | atomic_set(&data->st_enabled, 0); |
| 2001 | complete(&data->st_completion); |
| 2002 | mxt_interrupt(data->client->irq, data); |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 2003 | complete(&data->st_powerdown); |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 2004 | break; |
| 2005 | case 1: |
| 2006 | if (atomic_read(&data->st_enabled)) { |
| 2007 | err = -EBUSY; |
| 2008 | break; |
| 2009 | } |
| 2010 | |
| 2011 | if (pm_runtime_get(data->client->adapter->dev.parent) < 0) { |
| 2012 | dev_err(&data->client->dev, "pm_runtime_get failed\n"); |
| 2013 | err = -EIO; |
| 2014 | break; |
| 2015 | } |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 2016 | INIT_COMPLETION(data->st_completion); |
| 2017 | INIT_COMPLETION(data->st_powerdown); |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 2018 | atomic_set(&data->st_pending_irqs, 0); |
| 2019 | atomic_set(&data->st_enabled, 1); |
| 2020 | break; |
| 2021 | default: |
| 2022 | dev_err(&data->client->dev, "unsupported value: %lu\n", value); |
| 2023 | err = -EINVAL; |
| 2024 | break; |
| 2025 | } |
| 2026 | |
| 2027 | return err; |
| 2028 | } |
| 2029 | |
| 2030 | static ssize_t mxt_secure_touch_show(struct device *dev, |
| 2031 | struct device_attribute *attr, char *buf) |
| 2032 | { |
| 2033 | struct mxt_data *data = dev_get_drvdata(dev); |
| 2034 | int err; |
| 2035 | |
| 2036 | if (atomic_read(&data->st_enabled) == 0) |
| 2037 | return -EBADF; |
| 2038 | |
| 2039 | err = wait_for_completion_interruptible(&data->st_completion); |
| 2040 | |
| 2041 | if (err) |
| 2042 | return err; |
| 2043 | |
| 2044 | if (atomic_cmpxchg(&data->st_pending_irqs, 1, 0) != 1) |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 2045 | return -EINVAL; |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 2046 | |
| 2047 | return scnprintf(buf, PAGE_SIZE, "%u", 1); |
| 2048 | } |
| 2049 | |
| 2050 | static DEVICE_ATTR(secure_touch_enable, 0666, mxt_secure_touch_enable_show, |
| 2051 | mxt_secure_touch_enable_store); |
| 2052 | static DEVICE_ATTR(secure_touch, 0444, mxt_secure_touch_show, NULL); |
| 2053 | #endif |
| 2054 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2055 | static DEVICE_ATTR(object, 0444, mxt_object_show, NULL); |
| 2056 | static DEVICE_ATTR(update_fw, 0664, NULL, mxt_update_fw_store); |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 2057 | static DEVICE_ATTR(force_cfg_update, 0664, NULL, mxt_force_cfg_update_store); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2058 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2059 | static struct attribute *mxt_attrs[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2060 | &dev_attr_object.attr, |
| 2061 | &dev_attr_update_fw.attr, |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 2062 | &dev_attr_force_cfg_update.attr, |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 2063 | #if defined(CONFIG_SECURE_TOUCH) |
| 2064 | &dev_attr_secure_touch_enable.attr, |
| 2065 | &dev_attr_secure_touch.attr, |
| 2066 | #endif |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2067 | NULL |
| 2068 | }; |
| 2069 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2070 | static const struct attribute_group mxt_attr_group = { |
| 2071 | .attrs = mxt_attrs, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2072 | }; |
| 2073 | |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 2074 | |
| 2075 | #if defined(CONFIG_SECURE_TOUCH) |
| 2076 | static void mxt_secure_touch_stop(struct mxt_data *data) |
| 2077 | { |
| 2078 | if (atomic_read(&data->st_enabled)) { |
| 2079 | complete(&data->st_completion); |
| 2080 | wait_for_completion_interruptible(&data->st_powerdown); |
| 2081 | } |
| 2082 | } |
| 2083 | #else |
| 2084 | static void mxt_secure_touch_stop(struct mxt_data *data) |
| 2085 | { |
| 2086 | } |
| 2087 | #endif |
| 2088 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2089 | static int mxt_start(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2090 | { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 2091 | int error; |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 2092 | mxt_secure_touch_stop(data); |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 2093 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2094 | /* restore the old power state values and reenable touch */ |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 2095 | error = __mxt_write_reg(data->client, data->t7_start_addr, |
| 2096 | T7_DATA_SIZE, data->t7_data); |
| 2097 | if (error < 0) { |
| 2098 | dev_err(&data->client->dev, |
| 2099 | "failed to restore old power state\n"); |
| 2100 | return error; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2101 | } |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 2102 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2103 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2106 | static int mxt_stop(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2107 | { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 2108 | int error; |
| 2109 | u8 t7_data[T7_DATA_SIZE] = {0}; |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 2110 | mxt_secure_touch_stop(data); |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 2111 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 2112 | error = __mxt_write_reg(data->client, data->t7_start_addr, |
| 2113 | T7_DATA_SIZE, t7_data); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2114 | if (error < 0) { |
| 2115 | dev_err(&data->client->dev, |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 2116 | "failed to configure deep sleep mode\n"); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2117 | return error; |
| 2118 | } |
| 2119 | |
| 2120 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2123 | static int mxt_input_open(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2124 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2125 | struct mxt_data *data = input_get_drvdata(dev); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2126 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2127 | |
Anirudh Ghayal | 6c3b37b | 2012-02-23 18:39:42 -0800 | [diff] [blame] | 2128 | if (data->state == APPMODE) { |
| 2129 | error = mxt_start(data); |
| 2130 | if (error < 0) { |
| 2131 | dev_err(&data->client->dev, "mxt_start failed in input_open\n"); |
| 2132 | return error; |
| 2133 | } |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2134 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2135 | |
| 2136 | return 0; |
| 2137 | } |
| 2138 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2139 | static void mxt_input_close(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2140 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2141 | struct mxt_data *data = input_get_drvdata(dev); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2142 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2143 | |
Anirudh Ghayal | 6c3b37b | 2012-02-23 18:39:42 -0800 | [diff] [blame] | 2144 | if (data->state == APPMODE) { |
| 2145 | error = mxt_stop(data); |
| 2146 | if (error < 0) |
| 2147 | dev_err(&data->client->dev, "mxt_stop failed in input_close\n"); |
| 2148 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2151 | static int reg_set_optimum_mode_check(struct regulator *reg, int load_uA) |
| 2152 | { |
| 2153 | return (regulator_count_voltages(reg) > 0) ? |
| 2154 | regulator_set_optimum_mode(reg, load_uA) : 0; |
| 2155 | } |
| 2156 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2157 | static int mxt_power_on(struct mxt_data *data, bool on) |
| 2158 | { |
| 2159 | int rc; |
| 2160 | |
| 2161 | if (on == false) |
| 2162 | goto power_off; |
| 2163 | |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2164 | if (data->regs_enabled) { |
| 2165 | dev_dbg(&data->client->dev, "regs are already enabled\n"); |
| 2166 | return 0; |
| 2167 | } |
| 2168 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2169 | rc = reg_set_optimum_mode_check(data->vcc_ana, MXT_ACTIVE_LOAD_UA); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2170 | if (rc < 0) { |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2171 | dev_err(&data->client->dev, |
| 2172 | "Regulator vcc_ana set_opt failed rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2173 | return rc; |
| 2174 | } |
| 2175 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2176 | rc = regulator_enable(data->vcc_ana); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2177 | if (rc) { |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2178 | dev_err(&data->client->dev, |
| 2179 | "Regulator vcc_ana enable failed rc=%d\n", rc); |
| 2180 | goto error_reg_en_vcc_ana; |
| 2181 | } |
| 2182 | |
| 2183 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2184 | rc = reg_set_optimum_mode_check(data->vcc_dig, |
| 2185 | MXT_ACTIVE_LOAD_DIG_UA); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2186 | if (rc < 0) { |
| 2187 | dev_err(&data->client->dev, |
| 2188 | "Regulator vcc_dig set_opt failed rc=%d\n", |
| 2189 | rc); |
| 2190 | goto error_reg_opt_vcc_dig; |
| 2191 | } |
| 2192 | |
| 2193 | rc = regulator_enable(data->vcc_dig); |
| 2194 | if (rc) { |
| 2195 | dev_err(&data->client->dev, |
| 2196 | "Regulator vcc_dig enable failed rc=%d\n", rc); |
| 2197 | goto error_reg_en_vcc_dig; |
| 2198 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2202 | rc = reg_set_optimum_mode_check(data->vcc_i2c, MXT_I2C_LOAD_UA); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2203 | if (rc < 0) { |
| 2204 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2205 | "Regulator vcc_i2c set_opt failed rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2206 | goto error_reg_opt_i2c; |
| 2207 | } |
| 2208 | |
| 2209 | rc = regulator_enable(data->vcc_i2c); |
| 2210 | if (rc) { |
| 2211 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2212 | "Regulator vcc_i2c enable failed rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2213 | goto error_reg_en_vcc_i2c; |
| 2214 | } |
| 2215 | } |
| 2216 | |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2217 | data->regs_enabled = true; |
| 2218 | |
Amy Maloche | f0d7b8d | 2011-10-17 12:10:51 -0700 | [diff] [blame] | 2219 | msleep(130); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2220 | |
| 2221 | return 0; |
| 2222 | |
| 2223 | error_reg_en_vcc_i2c: |
| 2224 | if (data->pdata->i2c_pull_up) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2225 | reg_set_optimum_mode_check(data->vcc_i2c, 0); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2226 | error_reg_opt_i2c: |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2227 | if (data->pdata->digital_pwr_regulator) |
| 2228 | regulator_disable(data->vcc_dig); |
| 2229 | error_reg_en_vcc_dig: |
| 2230 | if (data->pdata->digital_pwr_regulator) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2231 | reg_set_optimum_mode_check(data->vcc_dig, 0); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2232 | error_reg_opt_vcc_dig: |
| 2233 | regulator_disable(data->vcc_ana); |
| 2234 | error_reg_en_vcc_ana: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2235 | reg_set_optimum_mode_check(data->vcc_ana, 0); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2236 | return rc; |
| 2237 | |
| 2238 | power_off: |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2239 | |
| 2240 | if (!data->regs_enabled) { |
| 2241 | dev_dbg(&data->client->dev, "regs are already disabled\n"); |
| 2242 | return 0; |
| 2243 | } |
| 2244 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2245 | reg_set_optimum_mode_check(data->vcc_ana, 0); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2246 | regulator_disable(data->vcc_ana); |
| 2247 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2248 | reg_set_optimum_mode_check(data->vcc_dig, 0); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2249 | regulator_disable(data->vcc_dig); |
| 2250 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2251 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2252 | reg_set_optimum_mode_check(data->vcc_i2c, 0); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2253 | regulator_disable(data->vcc_i2c); |
| 2254 | } |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2255 | |
| 2256 | data->regs_enabled = false; |
| 2257 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2258 | msleep(50); |
| 2259 | return 0; |
| 2260 | } |
| 2261 | |
| 2262 | static int mxt_regulator_configure(struct mxt_data *data, bool on) |
| 2263 | { |
| 2264 | int rc; |
| 2265 | |
| 2266 | if (on == false) |
| 2267 | goto hw_shutdown; |
| 2268 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2269 | data->vcc_ana = regulator_get(&data->client->dev, "vdd_ana"); |
| 2270 | if (IS_ERR(data->vcc_ana)) { |
| 2271 | rc = PTR_ERR(data->vcc_ana); |
| 2272 | dev_err(&data->client->dev, |
| 2273 | "Regulator get failed vcc_ana rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2274 | return rc; |
| 2275 | } |
| 2276 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2277 | if (regulator_count_voltages(data->vcc_ana) > 0) { |
| 2278 | rc = regulator_set_voltage(data->vcc_ana, MXT_VTG_MIN_UV, |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2279 | MXT_VTG_MAX_UV); |
| 2280 | if (rc) { |
| 2281 | dev_err(&data->client->dev, |
| 2282 | "regulator set_vtg failed rc=%d\n", rc); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2283 | goto error_set_vtg_vcc_ana; |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2284 | } |
| 2285 | } |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2286 | if (data->pdata->digital_pwr_regulator) { |
| 2287 | data->vcc_dig = regulator_get(&data->client->dev, "vdd_dig"); |
| 2288 | if (IS_ERR(data->vcc_dig)) { |
| 2289 | rc = PTR_ERR(data->vcc_dig); |
| 2290 | dev_err(&data->client->dev, |
| 2291 | "Regulator get dig failed rc=%d\n", rc); |
| 2292 | goto error_get_vtg_vcc_dig; |
| 2293 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2294 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2295 | if (regulator_count_voltages(data->vcc_dig) > 0) { |
| 2296 | rc = regulator_set_voltage(data->vcc_dig, |
| 2297 | MXT_VTG_DIG_MIN_UV, MXT_VTG_DIG_MAX_UV); |
| 2298 | if (rc) { |
| 2299 | dev_err(&data->client->dev, |
| 2300 | "regulator set_vtg failed rc=%d\n", rc); |
| 2301 | goto error_set_vtg_vcc_dig; |
| 2302 | } |
| 2303 | } |
| 2304 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2305 | if (data->pdata->i2c_pull_up) { |
| 2306 | data->vcc_i2c = regulator_get(&data->client->dev, "vcc_i2c"); |
| 2307 | if (IS_ERR(data->vcc_i2c)) { |
| 2308 | rc = PTR_ERR(data->vcc_i2c); |
| 2309 | dev_err(&data->client->dev, |
| 2310 | "Regulator get failed rc=%d\n", rc); |
| 2311 | goto error_get_vtg_i2c; |
| 2312 | } |
| 2313 | if (regulator_count_voltages(data->vcc_i2c) > 0) { |
| 2314 | rc = regulator_set_voltage(data->vcc_i2c, |
| 2315 | MXT_I2C_VTG_MIN_UV, MXT_I2C_VTG_MAX_UV); |
| 2316 | if (rc) { |
| 2317 | dev_err(&data->client->dev, |
| 2318 | "regulator set_vtg failed rc=%d\n", rc); |
| 2319 | goto error_set_vtg_i2c; |
| 2320 | } |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | return 0; |
| 2325 | |
| 2326 | error_set_vtg_i2c: |
| 2327 | regulator_put(data->vcc_i2c); |
| 2328 | error_get_vtg_i2c: |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2329 | if (data->pdata->digital_pwr_regulator) |
| 2330 | if (regulator_count_voltages(data->vcc_dig) > 0) |
| 2331 | regulator_set_voltage(data->vcc_dig, 0, |
| 2332 | MXT_VTG_DIG_MAX_UV); |
| 2333 | error_set_vtg_vcc_dig: |
| 2334 | if (data->pdata->digital_pwr_regulator) |
| 2335 | regulator_put(data->vcc_dig); |
| 2336 | error_get_vtg_vcc_dig: |
| 2337 | if (regulator_count_voltages(data->vcc_ana) > 0) |
| 2338 | regulator_set_voltage(data->vcc_ana, 0, MXT_VTG_MAX_UV); |
| 2339 | error_set_vtg_vcc_ana: |
| 2340 | regulator_put(data->vcc_ana); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2341 | return rc; |
| 2342 | |
| 2343 | hw_shutdown: |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2344 | if (regulator_count_voltages(data->vcc_ana) > 0) |
| 2345 | regulator_set_voltage(data->vcc_ana, 0, MXT_VTG_MAX_UV); |
| 2346 | regulator_put(data->vcc_ana); |
| 2347 | if (data->pdata->digital_pwr_regulator) { |
| 2348 | if (regulator_count_voltages(data->vcc_dig) > 0) |
| 2349 | regulator_set_voltage(data->vcc_dig, 0, |
| 2350 | MXT_VTG_DIG_MAX_UV); |
| 2351 | regulator_put(data->vcc_dig); |
| 2352 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2353 | if (data->pdata->i2c_pull_up) { |
| 2354 | if (regulator_count_voltages(data->vcc_i2c) > 0) |
| 2355 | regulator_set_voltage(data->vcc_i2c, 0, |
| 2356 | MXT_I2C_VTG_MAX_UV); |
| 2357 | regulator_put(data->vcc_i2c); |
| 2358 | } |
| 2359 | return 0; |
| 2360 | } |
| 2361 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2362 | #ifdef CONFIG_PM |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2363 | static int mxt_regulator_lpm(struct mxt_data *data, bool on) |
| 2364 | { |
| 2365 | |
| 2366 | int rc; |
| 2367 | |
| 2368 | if (on == false) |
| 2369 | goto regulator_hpm; |
| 2370 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2371 | rc = reg_set_optimum_mode_check(data->vcc_ana, MXT_LPM_LOAD_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2372 | if (rc < 0) { |
| 2373 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2374 | "Regulator vcc_ana set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2375 | goto fail_regulator_lpm; |
| 2376 | } |
| 2377 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2378 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2379 | rc = reg_set_optimum_mode_check(data->vcc_dig, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2380 | MXT_LPM_LOAD_DIG_UA); |
| 2381 | if (rc < 0) { |
| 2382 | dev_err(&data->client->dev, |
| 2383 | "Regulator vcc_dig set_opt failed rc=%d\n", rc); |
| 2384 | goto fail_regulator_lpm; |
| 2385 | } |
| 2386 | } |
| 2387 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2388 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2389 | rc = reg_set_optimum_mode_check(data->vcc_i2c, |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2390 | MXT_I2C_LPM_LOAD_UA); |
| 2391 | if (rc < 0) { |
| 2392 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2393 | "Regulator vcc_i2c set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2394 | goto fail_regulator_lpm; |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | return 0; |
| 2399 | |
| 2400 | regulator_hpm: |
| 2401 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2402 | rc = reg_set_optimum_mode_check(data->vcc_ana, MXT_ACTIVE_LOAD_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2403 | if (rc < 0) { |
| 2404 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2405 | "Regulator vcc_ana set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2406 | goto fail_regulator_hpm; |
| 2407 | } |
| 2408 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2409 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2410 | rc = reg_set_optimum_mode_check(data->vcc_dig, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2411 | MXT_ACTIVE_LOAD_DIG_UA); |
| 2412 | if (rc < 0) { |
| 2413 | dev_err(&data->client->dev, |
| 2414 | "Regulator vcc_dig set_opt failed rc=%d\n", rc); |
| 2415 | goto fail_regulator_hpm; |
| 2416 | } |
| 2417 | } |
| 2418 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2419 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2420 | rc = reg_set_optimum_mode_check(data->vcc_i2c, MXT_I2C_LOAD_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2421 | if (rc < 0) { |
| 2422 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2423 | "Regulator vcc_i2c set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2424 | goto fail_regulator_hpm; |
| 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | return 0; |
| 2429 | |
| 2430 | fail_regulator_lpm: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2431 | reg_set_optimum_mode_check(data->vcc_ana, MXT_ACTIVE_LOAD_UA); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2432 | if (data->pdata->digital_pwr_regulator) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2433 | reg_set_optimum_mode_check(data->vcc_dig, |
| 2434 | MXT_ACTIVE_LOAD_DIG_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2435 | if (data->pdata->i2c_pull_up) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2436 | reg_set_optimum_mode_check(data->vcc_i2c, MXT_I2C_LOAD_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2437 | |
| 2438 | return rc; |
| 2439 | |
| 2440 | fail_regulator_hpm: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2441 | reg_set_optimum_mode_check(data->vcc_ana, MXT_LPM_LOAD_UA); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 2442 | if (data->pdata->digital_pwr_regulator) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2443 | reg_set_optimum_mode_check(data->vcc_dig, MXT_LPM_LOAD_DIG_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2444 | if (data->pdata->i2c_pull_up) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 2445 | reg_set_optimum_mode_check(data->vcc_i2c, MXT_I2C_LPM_LOAD_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2446 | |
| 2447 | return rc; |
| 2448 | } |
| 2449 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2450 | static int mxt_suspend(struct device *dev) |
| 2451 | { |
| 2452 | struct i2c_client *client = to_i2c_client(dev); |
| 2453 | struct mxt_data *data = i2c_get_clientdata(client); |
| 2454 | struct input_dev *input_dev = data->input_dev; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2455 | int error; |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2456 | |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2457 | disable_irq(data->irq); |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2458 | |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2459 | mutex_lock(&input_dev->mutex); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2460 | if (input_dev->users) { |
| 2461 | error = mxt_stop(data); |
| 2462 | if (error < 0) { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 2463 | dev_err(dev, "mxt_stop failed in suspend\n"); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2464 | mutex_unlock(&input_dev->mutex); |
| 2465 | return error; |
| 2466 | } |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2467 | } |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2468 | |
| 2469 | mutex_unlock(&input_dev->mutex); |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2470 | mxt_release_all(data); |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2471 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2472 | /* put regulators in low power mode */ |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2473 | if (data->lpm_support) { |
| 2474 | error = mxt_regulator_lpm(data, true); |
| 2475 | if (error < 0) { |
| 2476 | dev_err(dev, "failed to enter low power mode\n"); |
| 2477 | return error; |
| 2478 | } |
| 2479 | } else { |
| 2480 | error = mxt_power_on(data, false); |
| 2481 | if (error < 0) { |
| 2482 | dev_err(dev, "failed to disable regulators\n"); |
| 2483 | return error; |
| 2484 | } |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2487 | return 0; |
| 2488 | } |
| 2489 | |
| 2490 | static int mxt_resume(struct device *dev) |
| 2491 | { |
| 2492 | struct i2c_client *client = to_i2c_client(dev); |
| 2493 | struct mxt_data *data = i2c_get_clientdata(client); |
| 2494 | struct input_dev *input_dev = data->input_dev; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2495 | int error; |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2496 | |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2497 | /* put regulators back in active power mode */ |
| 2498 | if (data->lpm_support) { |
| 2499 | error = mxt_regulator_lpm(data, false); |
| 2500 | if (error < 0) { |
| 2501 | dev_err(dev, "failed to enter high power mode\n"); |
| 2502 | return error; |
| 2503 | } |
| 2504 | } else { |
| 2505 | error = mxt_power_on(data, true); |
| 2506 | if (error < 0) { |
| 2507 | dev_err(dev, "failed to enable regulators\n"); |
| 2508 | return error; |
| 2509 | } |
| 2510 | mxt_power_on_delay(data); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2513 | mxt_write_object(data, MXT_GEN_COMMAND_T6, MXT_COMMAND_RESET, 1); |
| 2514 | mxt_reset_delay(data); |
| 2515 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2516 | mutex_lock(&input_dev->mutex); |
| 2517 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2518 | if (input_dev->users) { |
| 2519 | error = mxt_start(data); |
| 2520 | if (error < 0) { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 2521 | dev_err(dev, "mxt_start failed in resume\n"); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 2522 | mutex_unlock(&input_dev->mutex); |
| 2523 | return error; |
| 2524 | } |
| 2525 | } |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2526 | |
Mohan Pallaka | 63a5f65 | 2012-09-21 16:51:44 +0530 | [diff] [blame] | 2527 | /* calibrate */ |
| 2528 | if (data->pdata->need_calibration) { |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 2529 | mxt_secure_touch_stop(data); |
Mohan Pallaka | 63a5f65 | 2012-09-21 16:51:44 +0530 | [diff] [blame] | 2530 | error = mxt_write_object(data, MXT_GEN_COMMAND_T6, |
| 2531 | MXT_COMMAND_CALIBRATE, 1); |
| 2532 | if (error < 0) |
| 2533 | dev_dbg(dev, "sending calibration command failed\n"); |
| 2534 | } |
| 2535 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2536 | mutex_unlock(&input_dev->mutex); |
| 2537 | |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2538 | enable_irq(data->irq); |
| 2539 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2540 | return 0; |
| 2541 | } |
| 2542 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2543 | static const struct dev_pm_ops mxt_pm_ops = { |
Anurag Singh | 49d7613 | 2013-01-29 12:07:00 -0800 | [diff] [blame] | 2544 | #if (!defined(CONFIG_FB) && !defined(CONFIG_HAS_EARLYSUSPEND)) |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2545 | .suspend = mxt_suspend, |
| 2546 | .resume = mxt_resume, |
| 2547 | #endif |
| 2548 | }; |
| 2549 | #endif |
| 2550 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 2551 | static int mxt_debugfs_object_show(struct seq_file *m, void *v) |
| 2552 | { |
| 2553 | struct mxt_data *data = m->private; |
| 2554 | struct mxt_object *object; |
| 2555 | struct device *dev = &data->client->dev; |
| 2556 | int i, j, k; |
| 2557 | int error; |
| 2558 | int obj_size; |
| 2559 | u8 val; |
| 2560 | |
| 2561 | for (i = 0; i < data->info.object_num; i++) { |
| 2562 | object = data->object_table + i; |
| 2563 | obj_size = object->size + 1; |
| 2564 | |
| 2565 | seq_printf(m, "Object[%d] (Type %d)\n", i + 1, object->type); |
| 2566 | |
| 2567 | for (j = 0; j < object->instances + 1; j++) { |
| 2568 | seq_printf(m, "[Instance %d]\n", j); |
| 2569 | |
| 2570 | for (k = 0; k < obj_size; k++) { |
| 2571 | error = mxt_read_object(data, object->type, |
| 2572 | j * obj_size + k, &val); |
| 2573 | if (error) { |
| 2574 | dev_err(dev, |
| 2575 | "Failed to read object %d " |
| 2576 | "instance %d at offset %d\n", |
| 2577 | object->type, j, k); |
| 2578 | return error; |
| 2579 | } |
| 2580 | |
| 2581 | seq_printf(m, "Byte %d: 0x%02x (%d)\n", |
| 2582 | k, val, val); |
| 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | return 0; |
| 2588 | } |
| 2589 | |
| 2590 | static int mxt_debugfs_object_open(struct inode *inode, struct file *file) |
| 2591 | { |
| 2592 | return single_open(file, mxt_debugfs_object_show, inode->i_private); |
| 2593 | } |
| 2594 | |
| 2595 | static const struct file_operations mxt_object_fops = { |
| 2596 | .owner = THIS_MODULE, |
| 2597 | .open = mxt_debugfs_object_open, |
| 2598 | .read = seq_read, |
| 2599 | .release = single_release, |
| 2600 | }; |
| 2601 | |
Stephen Boyd | 0d57869 | 2012-04-25 11:49:18 -0700 | [diff] [blame] | 2602 | static void __devinit mxt_debugfs_init(struct mxt_data *data) |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 2603 | { |
| 2604 | debug_base = debugfs_create_dir(MXT_DEBUGFS_DIR, NULL); |
| 2605 | if (IS_ERR_OR_NULL(debug_base)) |
| 2606 | pr_err("atmel_mxt_ts: Failed to create debugfs dir\n"); |
| 2607 | if (IS_ERR_OR_NULL(debugfs_create_file(MXT_DEBUGFS_FILE, |
| 2608 | 0444, |
| 2609 | debug_base, |
| 2610 | data, |
| 2611 | &mxt_object_fops))) { |
| 2612 | pr_err("atmel_mxt_ts: Failed to create object file\n"); |
| 2613 | debugfs_remove_recursive(debug_base); |
| 2614 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2615 | } |
| 2616 | |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 2617 | #ifdef CONFIG_OF |
| 2618 | static int mxt_get_dt_coords(struct device *dev, char *name, |
| 2619 | struct mxt_platform_data *pdata) |
| 2620 | { |
| 2621 | u32 coords[MXT_COORDS_ARR_SIZE]; |
| 2622 | struct property *prop; |
| 2623 | struct device_node *np = dev->of_node; |
| 2624 | int coords_size, rc; |
| 2625 | |
| 2626 | prop = of_find_property(np, name, NULL); |
| 2627 | if (!prop) |
| 2628 | return -EINVAL; |
| 2629 | if (!prop->value) |
| 2630 | return -ENODATA; |
| 2631 | |
| 2632 | coords_size = prop->length / sizeof(u32); |
| 2633 | if (coords_size != MXT_COORDS_ARR_SIZE) { |
| 2634 | dev_err(dev, "invalid %s\n", name); |
| 2635 | return -EINVAL; |
| 2636 | } |
| 2637 | |
| 2638 | rc = of_property_read_u32_array(np, name, coords, coords_size); |
| 2639 | if (rc && (rc != -EINVAL)) { |
| 2640 | dev_err(dev, "Unable to read %s\n", name); |
| 2641 | return rc; |
| 2642 | } |
| 2643 | |
| 2644 | if (strncmp(name, "atmel,panel-coords", |
| 2645 | sizeof("atmel,panel-coords")) == 0) { |
| 2646 | pdata->panel_minx = coords[0]; |
| 2647 | pdata->panel_miny = coords[1]; |
| 2648 | pdata->panel_maxx = coords[2]; |
| 2649 | pdata->panel_maxy = coords[3]; |
| 2650 | } else if (strncmp(name, "atmel,display-coords", |
| 2651 | sizeof("atmel,display-coords")) == 0) { |
| 2652 | pdata->disp_minx = coords[0]; |
| 2653 | pdata->disp_miny = coords[1]; |
| 2654 | pdata->disp_maxx = coords[2]; |
| 2655 | pdata->disp_maxy = coords[3]; |
| 2656 | } else { |
| 2657 | dev_err(dev, "unsupported property %s\n", name); |
| 2658 | return -EINVAL; |
| 2659 | } |
| 2660 | |
| 2661 | return 0; |
| 2662 | } |
| 2663 | |
| 2664 | static int mxt_parse_config(struct device *dev, struct device_node *np, |
| 2665 | struct mxt_config_info *info) |
| 2666 | { |
| 2667 | struct property *prop; |
| 2668 | u8 *temp_cfg; |
| 2669 | |
| 2670 | prop = of_find_property(np, "atmel,config", &info->config_length); |
| 2671 | if (!prop) { |
| 2672 | dev_err(dev, "Looking up %s property in node %s failed", |
| 2673 | "atmel,config", np->full_name); |
| 2674 | return -ENODEV; |
| 2675 | } else if (!info->config_length) { |
| 2676 | dev_err(dev, "Invalid length of configuration data\n"); |
| 2677 | return -EINVAL; |
| 2678 | } |
| 2679 | |
| 2680 | temp_cfg = devm_kzalloc(dev, |
| 2681 | info->config_length * sizeof(u8), GFP_KERNEL); |
| 2682 | if (!temp_cfg) { |
| 2683 | dev_err(dev, "Unable to allocate memory to store cfg\n"); |
| 2684 | return -ENOMEM; |
| 2685 | } |
| 2686 | |
| 2687 | memcpy(temp_cfg, prop->value, info->config_length); |
| 2688 | info->config = temp_cfg; |
| 2689 | |
| 2690 | return 0; |
| 2691 | } |
| 2692 | |
| 2693 | static int mxt_parse_dt(struct device *dev, struct mxt_platform_data *pdata) |
| 2694 | { |
| 2695 | int rc; |
| 2696 | struct mxt_config_info *info; |
| 2697 | struct device_node *temp, *np = dev->of_node; |
| 2698 | struct property *prop; |
| 2699 | u32 temp_val; |
| 2700 | |
| 2701 | rc = mxt_get_dt_coords(dev, "atmel,panel-coords", pdata); |
| 2702 | if (rc) |
| 2703 | return rc; |
| 2704 | |
| 2705 | rc = mxt_get_dt_coords(dev, "atmel,display-coords", pdata); |
| 2706 | if (rc) |
| 2707 | return rc; |
| 2708 | |
| 2709 | /* regulator info */ |
| 2710 | pdata->i2c_pull_up = of_property_read_bool(np, "atmel,i2c-pull-up"); |
| 2711 | pdata->digital_pwr_regulator = of_property_read_bool(np, |
| 2712 | "atmel,dig-reg-support"); |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 2713 | |
| 2714 | pdata->no_force_update = of_property_read_bool(np, |
| 2715 | "atmel,no-force-update"); |
| 2716 | |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2717 | pdata->no_lpm_support = of_property_read_bool(np, |
| 2718 | "atmel,no-lpm-support"); |
| 2719 | |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 2720 | /* reset, irq gpio info */ |
| 2721 | pdata->reset_gpio = of_get_named_gpio_flags(np, "atmel,reset-gpio", |
| 2722 | 0, &pdata->reset_gpio_flags); |
| 2723 | pdata->irq_gpio = of_get_named_gpio_flags(np, "atmel,irq-gpio", |
| 2724 | 0, &pdata->irq_gpio_flags); |
| 2725 | |
| 2726 | /* keycodes for keyarray object*/ |
| 2727 | prop = of_find_property(np, "atmel,key-codes", NULL); |
| 2728 | if (prop) { |
| 2729 | pdata->key_codes = devm_kzalloc(dev, |
| 2730 | sizeof(int) * MXT_KEYARRAY_MAX_KEYS, |
| 2731 | GFP_KERNEL); |
| 2732 | if (!pdata->key_codes) |
| 2733 | return -ENOMEM; |
| 2734 | if ((prop->length/sizeof(u32)) == MXT_KEYARRAY_MAX_KEYS) { |
| 2735 | rc = of_property_read_u32_array(np, "atmel,key-codes", |
| 2736 | pdata->key_codes, MXT_KEYARRAY_MAX_KEYS); |
| 2737 | if (rc) { |
| 2738 | dev_err(dev, "Unable to read key codes\n"); |
| 2739 | return rc; |
| 2740 | } |
| 2741 | } else |
| 2742 | return -EINVAL; |
| 2743 | } |
| 2744 | |
Mohan Pallaka | 63a5f65 | 2012-09-21 16:51:44 +0530 | [diff] [blame] | 2745 | /* need calibration during wakeup? */ |
| 2746 | pdata->need_calibration = of_property_read_bool(np, |
| 2747 | "atmel,need-calibration"); |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 2748 | /* config array size */ |
| 2749 | pdata->config_array_size = 0; |
| 2750 | temp = NULL; |
| 2751 | while ((temp = of_get_next_child(np, temp))) |
| 2752 | pdata->config_array_size++; |
| 2753 | |
| 2754 | if (!pdata->config_array_size) |
| 2755 | return 0; |
| 2756 | |
| 2757 | info = devm_kzalloc(dev, pdata->config_array_size * |
| 2758 | sizeof(struct mxt_config_info), GFP_KERNEL); |
| 2759 | if (!info) { |
| 2760 | dev_err(dev, "Unable to allocate memory\n"); |
| 2761 | return -ENOMEM; |
| 2762 | } |
| 2763 | |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 2764 | rc = of_property_read_u32(np, "atmel,bl-addr", &temp_val); |
| 2765 | if (rc && (rc != -EINVAL)) |
| 2766 | dev_err(dev, "Unable to read bootloader address\n"); |
| 2767 | else if (rc != -EINVAL) |
| 2768 | pdata->bl_addr = (u8) temp_val; |
| 2769 | |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 2770 | pdata->config_array = info; |
| 2771 | |
| 2772 | for_each_child_of_node(np, temp) { |
| 2773 | rc = of_property_read_string(temp, "atmel,fw-name", |
| 2774 | &info->fw_name); |
| 2775 | if (rc && (rc != -EINVAL)) { |
| 2776 | dev_err(dev, "Unable to read fw name\n"); |
| 2777 | return rc; |
| 2778 | } |
| 2779 | |
| 2780 | rc = of_property_read_u32(temp, "atmel,family-id", &temp_val); |
| 2781 | if (rc) { |
| 2782 | dev_err(dev, "Unable to read family id\n"); |
| 2783 | return rc; |
| 2784 | } else |
| 2785 | info->family_id = (u8) temp_val; |
| 2786 | |
| 2787 | rc = of_property_read_u32(temp, "atmel,variant-id", &temp_val); |
| 2788 | if (rc) { |
| 2789 | dev_err(dev, "Unable to read variant id\n"); |
| 2790 | return rc; |
| 2791 | } else |
| 2792 | info->variant_id = (u8) temp_val; |
| 2793 | |
| 2794 | rc = of_property_read_u32(temp, "atmel,version", &temp_val); |
| 2795 | if (rc) { |
| 2796 | dev_err(dev, "Unable to read controller version\n"); |
| 2797 | return rc; |
| 2798 | } else |
| 2799 | info->version = (u8) temp_val; |
| 2800 | |
| 2801 | rc = of_property_read_u32(temp, "atmel,build", &temp_val); |
| 2802 | if (rc) { |
| 2803 | dev_err(dev, "Unable to read build id\n"); |
| 2804 | return rc; |
| 2805 | } else |
| 2806 | info->build = (u8) temp_val; |
| 2807 | |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 2808 | rc = of_property_read_u32(temp, |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 2809 | "atmel,bootldr-id", &temp_val); |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 2810 | if (rc && (rc != -EINVAL)) |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 2811 | dev_err(dev, "Unable to read bootldr-id\n"); |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 2812 | else if (rc != -EINVAL) |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 2813 | info->bootldr_id = (u8) temp_val; |
| 2814 | |
| 2815 | rc = mxt_parse_config(dev, temp, info); |
| 2816 | if (rc) { |
| 2817 | dev_err(dev, "Unable to parse config data\n"); |
| 2818 | return rc; |
| 2819 | } |
| 2820 | info++; |
| 2821 | } |
| 2822 | |
| 2823 | return 0; |
| 2824 | } |
| 2825 | #else |
| 2826 | static int mxt_parse_dt(struct device *dev, struct mxt_platform_data *pdata) |
| 2827 | { |
| 2828 | return -ENODEV; |
| 2829 | } |
| 2830 | #endif |
| 2831 | |
Anurag Singh | 49d7613 | 2013-01-29 12:07:00 -0800 | [diff] [blame] | 2832 | #if defined(CONFIG_FB) |
| 2833 | static int fb_notifier_callback(struct notifier_block *self, |
| 2834 | unsigned long event, void *data) |
| 2835 | { |
| 2836 | struct fb_event *evdata = data; |
| 2837 | int *blank; |
| 2838 | struct mxt_data *mxt_dev_data = |
| 2839 | container_of(self, struct mxt_data, fb_notif); |
| 2840 | |
| 2841 | if (evdata && evdata->data && event == FB_EVENT_BLANK && mxt_dev_data && |
| 2842 | mxt_dev_data->client) { |
| 2843 | blank = evdata->data; |
| 2844 | if (*blank == FB_BLANK_UNBLANK) |
| 2845 | mxt_resume(&mxt_dev_data->client->dev); |
| 2846 | else if (*blank == FB_BLANK_POWERDOWN) |
| 2847 | mxt_suspend(&mxt_dev_data->client->dev); |
| 2848 | } |
| 2849 | |
| 2850 | return 0; |
| 2851 | } |
| 2852 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
| 2853 | static void mxt_early_suspend(struct early_suspend *h) |
| 2854 | { |
| 2855 | struct mxt_data *data = container_of(h, struct mxt_data, |
| 2856 | early_suspend); |
| 2857 | mxt_suspend(&data->client->dev); |
| 2858 | } |
| 2859 | |
| 2860 | static void mxt_late_resume(struct early_suspend *h) |
| 2861 | { |
| 2862 | struct mxt_data *data = container_of(h, struct mxt_data, |
| 2863 | early_suspend); |
| 2864 | mxt_resume(&data->client->dev); |
| 2865 | } |
| 2866 | |
| 2867 | #endif |
| 2868 | |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 2869 | #if defined(CONFIG_SECURE_TOUCH) |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 2870 | static void __devinit mxt_secure_touch_init(struct mxt_data *data) |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 2871 | { |
| 2872 | init_completion(&data->st_completion); |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 2873 | init_completion(&data->st_powerdown); |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 2874 | } |
| 2875 | #else |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 2876 | static void __devinit mxt_secure_touch_init(struct mxt_data *data) |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 2877 | { |
| 2878 | } |
| 2879 | #endif |
| 2880 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2881 | static int __devinit mxt_probe(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2882 | const struct i2c_device_id *id) |
| 2883 | { |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 2884 | struct mxt_platform_data *pdata; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2885 | struct mxt_data *data; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2886 | struct input_dev *input_dev; |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 2887 | int error, i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2888 | |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 2889 | if (client->dev.of_node) { |
| 2890 | pdata = devm_kzalloc(&client->dev, |
| 2891 | sizeof(struct mxt_platform_data), GFP_KERNEL); |
| 2892 | if (!pdata) { |
| 2893 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 2894 | return -ENOMEM; |
| 2895 | } |
| 2896 | |
| 2897 | error = mxt_parse_dt(&client->dev, pdata); |
| 2898 | if (error) |
| 2899 | return error; |
| 2900 | } else |
| 2901 | pdata = client->dev.platform_data; |
| 2902 | |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 2903 | if (!pdata) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2904 | return -EINVAL; |
| 2905 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2906 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2907 | input_dev = input_allocate_device(); |
| 2908 | if (!data || !input_dev) { |
| 2909 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 2910 | error = -ENOMEM; |
| 2911 | goto err_free_mem; |
| 2912 | } |
| 2913 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 2914 | data->state = INIT; |
Amy Maloche | 83c385a | 2012-02-01 10:32:03 +0530 | [diff] [blame] | 2915 | input_dev->name = "atmel_mxt_ts"; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2916 | input_dev->id.bustype = BUS_I2C; |
| 2917 | input_dev->dev.parent = &client->dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2918 | input_dev->open = mxt_input_open; |
| 2919 | input_dev->close = mxt_input_close; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2920 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 2921 | data->client = client; |
| 2922 | data->input_dev = input_dev; |
| 2923 | data->pdata = pdata; |
Sreenivasulu Chalam Charla | a339ef7 | 2012-09-20 08:25:04 +0530 | [diff] [blame] | 2924 | data->no_force_update = pdata->no_force_update; |
Mohan Pallaka | b74e348 | 2013-07-09 16:39:56 +0530 | [diff] [blame] | 2925 | data->lpm_support = !pdata->no_lpm_support; |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 2926 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2927 | __set_bit(EV_ABS, input_dev->evbit); |
| 2928 | __set_bit(EV_KEY, input_dev->evbit); |
| 2929 | __set_bit(BTN_TOUCH, input_dev->keybit); |
Amy Maloche | 9d0faa0 | 2012-06-19 12:37:39 -0700 | [diff] [blame] | 2930 | __set_bit(INPUT_PROP_DIRECT, input_dev->propbit); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2931 | |
| 2932 | /* For single touch */ |
| 2933 | input_set_abs_params(input_dev, ABS_X, |
Mohan Pallaka | 56a1a5d | 2012-02-23 12:05:13 -0800 | [diff] [blame] | 2934 | pdata->disp_minx, pdata->disp_maxx, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2935 | input_set_abs_params(input_dev, ABS_Y, |
Mohan Pallaka | 56a1a5d | 2012-02-23 12:05:13 -0800 | [diff] [blame] | 2936 | pdata->disp_miny, pdata->disp_maxy, 0, 0); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 2937 | input_set_abs_params(input_dev, ABS_PRESSURE, |
| 2938 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2939 | |
| 2940 | /* For multi touch */ |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 2941 | input_mt_init_slots(input_dev, MXT_MAX_FINGER); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2942 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2943 | 0, MXT_MAX_AREA, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2944 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, |
Mohan Pallaka | 56a1a5d | 2012-02-23 12:05:13 -0800 | [diff] [blame] | 2945 | pdata->disp_minx, pdata->disp_maxx, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2946 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, |
Mohan Pallaka | 56a1a5d | 2012-02-23 12:05:13 -0800 | [diff] [blame] | 2947 | pdata->disp_miny, pdata->disp_maxy, 0, 0); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 2948 | input_set_abs_params(input_dev, ABS_MT_PRESSURE, |
| 2949 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2950 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 2951 | /* set key array supported keys */ |
| 2952 | if (pdata->key_codes) { |
| 2953 | for (i = 0; i < MXT_KEYARRAY_MAX_KEYS; i++) { |
| 2954 | if (pdata->key_codes[i]) |
| 2955 | input_set_capability(input_dev, EV_KEY, |
| 2956 | pdata->key_codes[i]); |
| 2957 | } |
| 2958 | } |
| 2959 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2960 | input_set_drvdata(input_dev, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2961 | i2c_set_clientdata(client, data); |
| 2962 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2963 | if (pdata->init_hw) |
| 2964 | error = pdata->init_hw(true); |
| 2965 | else |
| 2966 | error = mxt_regulator_configure(data, true); |
| 2967 | if (error) { |
| 2968 | dev_err(&client->dev, "Failed to intialize hardware\n"); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 2969 | goto err_free_mem; |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2970 | } |
| 2971 | |
Eugene Yasman | c18bc1f | 2013-06-11 12:29:24 +0300 | [diff] [blame] | 2972 | if (gpio_is_valid(pdata->reset_gpio)) { |
| 2973 | /* configure touchscreen reset out gpio */ |
| 2974 | error = gpio_request(pdata->reset_gpio, "mxt_reset_gpio"); |
| 2975 | if (error) { |
| 2976 | dev_err(&client->dev, "unable to request gpio [%d]\n", |
| 2977 | pdata->reset_gpio); |
| 2978 | goto err_regulator_on; |
| 2979 | } |
| 2980 | |
| 2981 | error = gpio_direction_output(pdata->reset_gpio, 0); |
| 2982 | if (error) { |
| 2983 | dev_err(&client->dev, |
| 2984 | "unable to set direction for gpio [%d]\n", |
| 2985 | pdata->reset_gpio); |
| 2986 | goto err_reset_gpio_req; |
| 2987 | } |
| 2988 | mxt_reset_delay(data); |
| 2989 | } |
| 2990 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2991 | if (pdata->power_on) |
| 2992 | error = pdata->power_on(true); |
| 2993 | else |
| 2994 | error = mxt_power_on(data, true); |
| 2995 | if (error) { |
| 2996 | dev_err(&client->dev, "Failed to power on hardware\n"); |
Eugene Yasman | c18bc1f | 2013-06-11 12:29:24 +0300 | [diff] [blame] | 2997 | goto err_reset_gpio_req; |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2998 | } |
| 2999 | |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 3000 | if (gpio_is_valid(pdata->irq_gpio)) { |
| 3001 | /* configure touchscreen irq gpio */ |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 3002 | error = gpio_request(pdata->irq_gpio, "mxt_irq_gpio"); |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 3003 | if (error) { |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 3004 | dev_err(&client->dev, "unable to request gpio [%d]\n", |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 3005 | pdata->irq_gpio); |
| 3006 | goto err_power_on; |
| 3007 | } |
| 3008 | error = gpio_direction_input(pdata->irq_gpio); |
| 3009 | if (error) { |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 3010 | dev_err(&client->dev, |
| 3011 | "unable to set direction for gpio [%d]\n", |
| 3012 | pdata->irq_gpio); |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 3013 | goto err_irq_gpio_req; |
| 3014 | } |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 3015 | data->irq = client->irq = gpio_to_irq(pdata->irq_gpio); |
| 3016 | } else { |
| 3017 | dev_err(&client->dev, "irq gpio not provided\n"); |
| 3018 | goto err_power_on; |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | if (gpio_is_valid(pdata->reset_gpio)) { |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 3022 | error = gpio_direction_output(pdata->reset_gpio, 1); |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 3023 | if (error) { |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 3024 | dev_err(&client->dev, |
| 3025 | "unable to set direction for gpio [%d]\n", |
| 3026 | pdata->reset_gpio); |
Eugene Yasman | c18bc1f | 2013-06-11 12:29:24 +0300 | [diff] [blame] | 3027 | goto err_irq_gpio_req; |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 3028 | } |
| 3029 | } |
| 3030 | |
Jing Lin | 64fdd1f | 2012-12-20 17:08:28 -0800 | [diff] [blame] | 3031 | mxt_power_on_delay(data); |
| 3032 | |
Amy Maloche | 265fc3c | 2013-01-17 11:50:24 -0800 | [diff] [blame] | 3033 | data->addr_pair.application = data->client->addr; |
| 3034 | |
| 3035 | if (pdata->bl_addr) |
| 3036 | data->addr_pair.bootloader = pdata->bl_addr; |
| 3037 | else |
| 3038 | mxt_lookup_bootloader_address(data); |
| 3039 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3040 | error = mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3041 | if (error) |
Eugene Yasman | c18bc1f | 2013-06-11 12:29:24 +0300 | [diff] [blame] | 3042 | goto err_irq_gpio_req; |
Jing Lin | 64fdd1f | 2012-12-20 17:08:28 -0800 | [diff] [blame] | 3043 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3044 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 3045 | pdata->irqflags, client->dev.driver->name, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3046 | if (error) { |
| 3047 | dev_err(&client->dev, "Failed to register interrupt\n"); |
| 3048 | goto err_free_object; |
| 3049 | } |
| 3050 | |
Nick Dyer | 0a4016c | 2012-01-18 15:17:59 +0530 | [diff] [blame] | 3051 | if (data->state == APPMODE) { |
| 3052 | error = mxt_make_highchg(data); |
| 3053 | if (error) { |
| 3054 | dev_err(&client->dev, "Failed to make high CHG\n"); |
| 3055 | goto err_free_irq; |
| 3056 | } |
| 3057 | } |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 3058 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3059 | error = input_register_device(input_dev); |
| 3060 | if (error) |
| 3061 | goto err_free_irq; |
| 3062 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3063 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3064 | if (error) |
| 3065 | goto err_unregister_device; |
| 3066 | |
Anurag Singh | 49d7613 | 2013-01-29 12:07:00 -0800 | [diff] [blame] | 3067 | #if defined(CONFIG_FB) |
| 3068 | data->fb_notif.notifier_call = fb_notifier_callback; |
| 3069 | |
| 3070 | error = fb_register_client(&data->fb_notif); |
| 3071 | |
| 3072 | if (error) |
| 3073 | dev_err(&client->dev, "Unable to register fb_notifier: %d\n", |
| 3074 | error); |
| 3075 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 3076 | data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + |
| 3077 | MXT_SUSPEND_LEVEL; |
| 3078 | data->early_suspend.suspend = mxt_early_suspend; |
| 3079 | data->early_suspend.resume = mxt_late_resume; |
| 3080 | register_early_suspend(&data->early_suspend); |
| 3081 | #endif |
| 3082 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 3083 | mxt_debugfs_init(data); |
| 3084 | |
Amy Maloche | 20f970c | 2013-04-10 13:04:52 +0100 | [diff] [blame] | 3085 | mxt_secure_touch_init(data); |
Amy Maloche | 434b7d8 | 2013-02-15 11:11:05 +0000 | [diff] [blame] | 3086 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3087 | return 0; |
| 3088 | |
| 3089 | err_unregister_device: |
| 3090 | input_unregister_device(input_dev); |
| 3091 | input_dev = NULL; |
| 3092 | err_free_irq: |
| 3093 | free_irq(client->irq, data); |
| 3094 | err_free_object: |
| 3095 | kfree(data->object_table); |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 3096 | err_irq_gpio_req: |
| 3097 | if (gpio_is_valid(pdata->irq_gpio)) |
| 3098 | gpio_free(pdata->irq_gpio); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 3099 | err_power_on: |
| 3100 | if (pdata->power_on) |
| 3101 | pdata->power_on(false); |
| 3102 | else |
| 3103 | mxt_power_on(data, false); |
Eugene Yasman | c18bc1f | 2013-06-11 12:29:24 +0300 | [diff] [blame] | 3104 | err_reset_gpio_req: |
| 3105 | if (gpio_is_valid(pdata->reset_gpio)) |
| 3106 | gpio_free(pdata->reset_gpio); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 3107 | err_regulator_on: |
| 3108 | if (pdata->init_hw) |
| 3109 | pdata->init_hw(false); |
| 3110 | else |
| 3111 | mxt_regulator_configure(data, false); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3112 | err_free_mem: |
| 3113 | input_free_device(input_dev); |
| 3114 | kfree(data); |
| 3115 | return error; |
| 3116 | } |
| 3117 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3118 | static int __devexit mxt_remove(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3119 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3120 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3121 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3122 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3123 | free_irq(data->irq, data); |
| 3124 | input_unregister_device(data->input_dev); |
Anurag Singh | 49d7613 | 2013-01-29 12:07:00 -0800 | [diff] [blame] | 3125 | #if defined(CONFIG_FB) |
| 3126 | if (fb_unregister_client(&data->fb_notif)) |
| 3127 | dev_err(&client->dev, "Error occurred while unregistering fb_notifier.\n"); |
| 3128 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 3129 | unregister_early_suspend(&data->early_suspend); |
| 3130 | #endif |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 3131 | |
| 3132 | if (data->pdata->power_on) |
| 3133 | data->pdata->power_on(false); |
| 3134 | else |
| 3135 | mxt_power_on(data, false); |
| 3136 | |
| 3137 | if (data->pdata->init_hw) |
| 3138 | data->pdata->init_hw(false); |
| 3139 | else |
| 3140 | mxt_regulator_configure(data, false); |
| 3141 | |
Mohan Pallaka | bfe8f30 | 2012-01-02 18:32:08 +0800 | [diff] [blame] | 3142 | if (gpio_is_valid(data->pdata->reset_gpio)) |
| 3143 | gpio_free(data->pdata->reset_gpio); |
| 3144 | |
| 3145 | if (gpio_is_valid(data->pdata->irq_gpio)) |
| 3146 | gpio_free(data->pdata->irq_gpio); |
| 3147 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3148 | kfree(data->object_table); |
| 3149 | kfree(data); |
| 3150 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 3151 | debugfs_remove_recursive(debug_base); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3152 | |
| 3153 | return 0; |
| 3154 | } |
| 3155 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3156 | static const struct i2c_device_id mxt_id[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3157 | { "qt602240_ts", 0 }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3158 | { "atmel_mxt_ts", 0 }, |
Chris Leech | 46ee2a0 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 3159 | { "mXT224", 0 }, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3160 | { } |
| 3161 | }; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3162 | MODULE_DEVICE_TABLE(i2c, mxt_id); |
Amy Maloche | 56cb58c | 2012-08-23 13:21:03 -0700 | [diff] [blame] | 3163 | #ifdef CONFIG_OF |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 3164 | static struct of_device_id mxt_match_table[] = { |
| 3165 | { .compatible = "atmel,mxt-ts",}, |
| 3166 | { }, |
| 3167 | }; |
| 3168 | #else |
| 3169 | #define mxt_match_table NULL |
| 3170 | #endif |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3171 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3172 | static struct i2c_driver mxt_driver = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3173 | .driver = { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3174 | .name = "atmel_mxt_ts", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3175 | .owner = THIS_MODULE, |
Mohan Pallaka | d96f503 | 2012-06-18 22:49:10 +0530 | [diff] [blame] | 3176 | .of_match_table = mxt_match_table, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 3177 | #ifdef CONFIG_PM |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3178 | .pm = &mxt_pm_ops, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 3179 | #endif |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3180 | }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3181 | .probe = mxt_probe, |
| 3182 | .remove = __devexit_p(mxt_remove), |
| 3183 | .id_table = mxt_id, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3184 | }; |
| 3185 | |
Axel Lin | 1b92c1c | 2012-03-16 23:05:41 -0700 | [diff] [blame] | 3186 | module_i2c_driver(mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3187 | |
| 3188 | /* Module information */ |
| 3189 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 3190 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 3191 | MODULE_LICENSE("GPL"); |