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> |
Mohan Pallaka | 5e7343f | 2012-01-02 18:30:16 +0800 | [diff] [blame] | 6 | * Copyright (c) 2011-2012, Code Aurora Forum. 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 | cd47322 | 2012-02-14 18:32:48 -0800 | [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> |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 28 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 29 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 30 | #include <linux/earlysuspend.h> |
| 31 | /* Early-suspend level */ |
| 32 | #define MXT_SUSPEND_LEVEL 1 |
| 33 | #endif |
| 34 | |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 35 | /* Family ID */ |
| 36 | #define MXT224_ID 0x80 |
Amy Maloche | 380cc0b | 2011-11-03 12:55:04 -0700 | [diff] [blame] | 37 | #define MXT224E_ID 0x81 |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 38 | #define MXT1386_ID 0xA0 |
| 39 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 40 | /* Version */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 41 | #define MXT_VER_20 20 |
| 42 | #define MXT_VER_21 21 |
| 43 | #define MXT_VER_22 22 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 44 | |
| 45 | /* Slave addresses */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 46 | #define MXT_APP_LOW 0x4a |
| 47 | #define MXT_APP_HIGH 0x4b |
| 48 | #define MXT_BOOT_LOW 0x24 |
| 49 | #define MXT_BOOT_HIGH 0x25 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 50 | |
| 51 | /* Firmware */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 52 | #define MXT_FW_NAME "maxtouch.fw" |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 53 | |
| 54 | /* Registers */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 55 | #define MXT_FAMILY_ID 0x00 |
| 56 | #define MXT_VARIANT_ID 0x01 |
| 57 | #define MXT_VERSION 0x02 |
| 58 | #define MXT_BUILD 0x03 |
| 59 | #define MXT_MATRIX_X_SIZE 0x04 |
| 60 | #define MXT_MATRIX_Y_SIZE 0x05 |
| 61 | #define MXT_OBJECT_NUM 0x06 |
| 62 | #define MXT_OBJECT_START 0x07 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 63 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 64 | #define MXT_OBJECT_SIZE 6 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 65 | |
| 66 | /* Object types */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 67 | #define MXT_DEBUG_DIAGNOSTIC_T37 37 |
| 68 | #define MXT_GEN_MESSAGE_T5 5 |
| 69 | #define MXT_GEN_COMMAND_T6 6 |
| 70 | #define MXT_GEN_POWER_T7 7 |
| 71 | #define MXT_GEN_ACQUIRE_T8 8 |
| 72 | #define MXT_GEN_DATASOURCE_T53 53 |
| 73 | #define MXT_TOUCH_MULTI_T9 9 |
| 74 | #define MXT_TOUCH_KEYARRAY_T15 15 |
| 75 | #define MXT_TOUCH_PROXIMITY_T23 23 |
| 76 | #define MXT_TOUCH_PROXKEY_T52 52 |
| 77 | #define MXT_PROCI_GRIPFACE_T20 20 |
| 78 | #define MXT_PROCG_NOISE_T22 22 |
| 79 | #define MXT_PROCI_ONETOUCH_T24 24 |
| 80 | #define MXT_PROCI_TWOTOUCH_T27 27 |
| 81 | #define MXT_PROCI_GRIP_T40 40 |
| 82 | #define MXT_PROCI_PALM_T41 41 |
| 83 | #define MXT_PROCI_TOUCHSUPPRESSION_T42 42 |
| 84 | #define MXT_PROCI_STYLUS_T47 47 |
Jing Lin | c7fc405 | 2011-12-21 16:16:19 -0800 | [diff] [blame] | 85 | #define MXT_PROCI_SHIELDLESS_T56 56 |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 86 | #define MXT_PROCG_NOISESUPPRESSION_T48 48 |
| 87 | #define MXT_SPT_COMMSCONFIG_T18 18 |
| 88 | #define MXT_SPT_GPIOPWM_T19 19 |
| 89 | #define MXT_SPT_SELFTEST_T25 25 |
| 90 | #define MXT_SPT_CTECONFIG_T28 28 |
| 91 | #define MXT_SPT_USERDATA_T38 38 |
| 92 | #define MXT_SPT_DIGITIZER_T43 43 |
| 93 | #define MXT_SPT_MESSAGECOUNT_T44 44 |
| 94 | #define MXT_SPT_CTECONFIG_T46 46 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 95 | |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 96 | /* MXT_GEN_COMMAND_T6 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 97 | #define MXT_COMMAND_RESET 0 |
| 98 | #define MXT_COMMAND_BACKUPNV 1 |
| 99 | #define MXT_COMMAND_CALIBRATE 2 |
| 100 | #define MXT_COMMAND_REPORTALL 3 |
| 101 | #define MXT_COMMAND_DIAGNOSTIC 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 102 | |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 103 | /* MXT_GEN_POWER_T7 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 104 | #define MXT_POWER_IDLEACQINT 0 |
| 105 | #define MXT_POWER_ACTVACQINT 1 |
| 106 | #define MXT_POWER_ACTV2IDLETO 2 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 107 | |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 108 | /* MXT_GEN_ACQUIRE_T8 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 109 | #define MXT_ACQUIRE_CHRGTIME 0 |
| 110 | #define MXT_ACQUIRE_TCHDRIFT 2 |
| 111 | #define MXT_ACQUIRE_DRIFTST 3 |
| 112 | #define MXT_ACQUIRE_TCHAUTOCAL 4 |
| 113 | #define MXT_ACQUIRE_SYNC 5 |
| 114 | #define MXT_ACQUIRE_ATCHCALST 6 |
| 115 | #define MXT_ACQUIRE_ATCHCALSTHR 7 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 116 | |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 117 | /* MXT_TOUCH_MULT_T9 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 118 | #define MXT_TOUCH_CTRL 0 |
| 119 | #define MXT_TOUCH_XORIGIN 1 |
| 120 | #define MXT_TOUCH_YORIGIN 2 |
| 121 | #define MXT_TOUCH_XSIZE 3 |
| 122 | #define MXT_TOUCH_YSIZE 4 |
| 123 | #define MXT_TOUCH_BLEN 6 |
| 124 | #define MXT_TOUCH_TCHTHR 7 |
| 125 | #define MXT_TOUCH_TCHDI 8 |
| 126 | #define MXT_TOUCH_ORIENT 9 |
| 127 | #define MXT_TOUCH_MOVHYSTI 11 |
| 128 | #define MXT_TOUCH_MOVHYSTN 12 |
| 129 | #define MXT_TOUCH_NUMTOUCH 14 |
| 130 | #define MXT_TOUCH_MRGHYST 15 |
| 131 | #define MXT_TOUCH_MRGTHR 16 |
| 132 | #define MXT_TOUCH_AMPHYST 17 |
| 133 | #define MXT_TOUCH_XRANGE_LSB 18 |
| 134 | #define MXT_TOUCH_XRANGE_MSB 19 |
| 135 | #define MXT_TOUCH_YRANGE_LSB 20 |
| 136 | #define MXT_TOUCH_YRANGE_MSB 21 |
| 137 | #define MXT_TOUCH_XLOCLIP 22 |
| 138 | #define MXT_TOUCH_XHICLIP 23 |
| 139 | #define MXT_TOUCH_YLOCLIP 24 |
| 140 | #define MXT_TOUCH_YHICLIP 25 |
| 141 | #define MXT_TOUCH_XEDGECTRL 26 |
| 142 | #define MXT_TOUCH_XEDGEDIST 27 |
| 143 | #define MXT_TOUCH_YEDGECTRL 28 |
| 144 | #define MXT_TOUCH_YEDGEDIST 29 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 145 | #define MXT_TOUCH_JUMPLIMIT 30 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 146 | |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 147 | /* MXT_PROCI_GRIPFACE_T20 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 148 | #define MXT_GRIPFACE_CTRL 0 |
| 149 | #define MXT_GRIPFACE_XLOGRIP 1 |
| 150 | #define MXT_GRIPFACE_XHIGRIP 2 |
| 151 | #define MXT_GRIPFACE_YLOGRIP 3 |
| 152 | #define MXT_GRIPFACE_YHIGRIP 4 |
| 153 | #define MXT_GRIPFACE_MAXTCHS 5 |
| 154 | #define MXT_GRIPFACE_SZTHR1 7 |
| 155 | #define MXT_GRIPFACE_SZTHR2 8 |
| 156 | #define MXT_GRIPFACE_SHPTHR1 9 |
| 157 | #define MXT_GRIPFACE_SHPTHR2 10 |
| 158 | #define MXT_GRIPFACE_SUPEXTTO 11 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 159 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 160 | /* MXT_PROCI_NOISE field */ |
| 161 | #define MXT_NOISE_CTRL 0 |
| 162 | #define MXT_NOISE_OUTFLEN 1 |
| 163 | #define MXT_NOISE_GCAFUL_LSB 3 |
| 164 | #define MXT_NOISE_GCAFUL_MSB 4 |
| 165 | #define MXT_NOISE_GCAFLL_LSB 5 |
| 166 | #define MXT_NOISE_GCAFLL_MSB 6 |
| 167 | #define MXT_NOISE_ACTVGCAFVALID 7 |
| 168 | #define MXT_NOISE_NOISETHR 8 |
| 169 | #define MXT_NOISE_FREQHOPSCALE 10 |
| 170 | #define MXT_NOISE_FREQ0 11 |
| 171 | #define MXT_NOISE_FREQ1 12 |
| 172 | #define MXT_NOISE_FREQ2 13 |
| 173 | #define MXT_NOISE_FREQ3 14 |
| 174 | #define MXT_NOISE_FREQ4 15 |
| 175 | #define MXT_NOISE_IDLEGCAFVALID 16 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 176 | |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 177 | /* MXT_SPT_COMMSCONFIG_T18 */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 178 | #define MXT_COMMS_CTRL 0 |
| 179 | #define MXT_COMMS_CMD 1 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 180 | |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 181 | /* MXT_SPT_CTECONFIG_T28 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 182 | #define MXT_CTE_CTRL 0 |
| 183 | #define MXT_CTE_CMD 1 |
| 184 | #define MXT_CTE_MODE 2 |
| 185 | #define MXT_CTE_IDLEGCAFDEPTH 3 |
| 186 | #define MXT_CTE_ACTVGCAFDEPTH 4 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 187 | #define MXT_CTE_VOLTAGE 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 188 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 189 | #define MXT_VOLTAGE_DEFAULT 2700000 |
| 190 | #define MXT_VOLTAGE_STEP 10000 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 191 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 192 | /* Analog voltage @2.7 V */ |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 193 | #define MXT_VTG_MIN_UV 2700000 |
| 194 | #define MXT_VTG_MAX_UV 3300000 |
| 195 | #define MXT_ACTIVE_LOAD_UA 15000 |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 196 | #define MXT_LPM_LOAD_UA 10 |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 197 | /* Digital voltage @1.8 V */ |
| 198 | #define MXT_VTG_DIG_MIN_UV 1800000 |
| 199 | #define MXT_VTG_DIG_MAX_UV 1800000 |
| 200 | #define MXT_ACTIVE_LOAD_DIG_UA 10000 |
| 201 | #define MXT_LPM_LOAD_DIG_UA 10 |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 202 | |
| 203 | #define MXT_I2C_VTG_MIN_UV 1800000 |
| 204 | #define MXT_I2C_VTG_MAX_UV 1800000 |
| 205 | #define MXT_I2C_LOAD_UA 10000 |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 206 | #define MXT_I2C_LPM_LOAD_UA 10 |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 207 | |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 208 | /* Define for MXT_GEN_COMMAND_T6 */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 209 | #define MXT_BOOT_VALUE 0xa5 |
| 210 | #define MXT_BACKUP_VALUE 0x55 |
| 211 | #define MXT_BACKUP_TIME 25 /* msec */ |
Jing Lin | c7fc405 | 2011-12-21 16:16:19 -0800 | [diff] [blame] | 212 | #define MXT224_RESET_TIME 65 /* msec */ |
| 213 | #define MXT224E_RESET_TIME 22 /* msec */ |
| 214 | #define MXT1386_RESET_TIME 250 /* msec */ |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 215 | #define MXT_RESET_TIME 250 /* msec */ |
Jing Lin | c7fc405 | 2011-12-21 16:16:19 -0800 | [diff] [blame] | 216 | #define MXT_RESET_NOCHGREAD 400 /* msec */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 217 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 218 | #define MXT_FWRESET_TIME 175 /* msec */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 219 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 220 | #define MXT_WAKE_TIME 25 |
| 221 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 222 | /* Command to unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 223 | #define MXT_UNLOCK_CMD_MSB 0xaa |
| 224 | #define MXT_UNLOCK_CMD_LSB 0xdc |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 225 | |
| 226 | /* Bootloader mode status */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 227 | #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */ |
| 228 | #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */ |
| 229 | #define MXT_FRAME_CRC_CHECK 0x02 |
| 230 | #define MXT_FRAME_CRC_FAIL 0x03 |
| 231 | #define MXT_FRAME_CRC_PASS 0x04 |
| 232 | #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */ |
| 233 | #define MXT_BOOT_STATUS_MASK 0x3f |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 234 | |
| 235 | /* Touch status */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 236 | #define MXT_SUPPRESS (1 << 1) |
| 237 | #define MXT_AMP (1 << 2) |
| 238 | #define MXT_VECTOR (1 << 3) |
| 239 | #define MXT_MOVE (1 << 4) |
| 240 | #define MXT_RELEASE (1 << 5) |
| 241 | #define MXT_PRESS (1 << 6) |
| 242 | #define MXT_DETECT (1 << 7) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 243 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 244 | /* Touch orient bits */ |
| 245 | #define MXT_XY_SWITCH (1 << 0) |
| 246 | #define MXT_X_INVERT (1 << 1) |
| 247 | #define MXT_Y_INVERT (1 << 2) |
| 248 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 249 | /* Touchscreen absolute values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 250 | #define MXT_MAX_AREA 0xff |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 251 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 252 | #define MXT_MAX_FINGER 10 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 253 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 254 | #define T7_DATA_SIZE 3 |
| 255 | #define MXT_MAX_RW_TRIES 3 |
| 256 | #define MXT_BLOCK_SIZE 256 |
Mohan Pallaka | ab51f2b | 2011-09-29 18:17:35 +0530 | [diff] [blame] | 257 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 258 | #define MXT_DEBUGFS_DIR "atmel_mxt_ts" |
| 259 | #define MXT_DEBUGFS_FILE "object" |
| 260 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 261 | struct mxt_info { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 262 | u8 family_id; |
| 263 | u8 variant_id; |
| 264 | u8 version; |
| 265 | u8 build; |
| 266 | u8 matrix_xsize; |
| 267 | u8 matrix_ysize; |
| 268 | u8 object_num; |
| 269 | }; |
| 270 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 271 | struct mxt_object { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 272 | u8 type; |
| 273 | u16 start_address; |
| 274 | u8 size; |
| 275 | u8 instances; |
| 276 | u8 num_report_ids; |
| 277 | |
| 278 | /* to map object and message */ |
| 279 | u8 max_reportid; |
| 280 | }; |
| 281 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 282 | struct mxt_message { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 283 | u8 reportid; |
| 284 | u8 message[7]; |
| 285 | u8 checksum; |
| 286 | }; |
| 287 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 288 | struct mxt_finger { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 289 | int status; |
| 290 | int x; |
| 291 | int y; |
| 292 | int area; |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 293 | int pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 294 | }; |
| 295 | |
| 296 | /* Each client has this additional data */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 297 | struct mxt_data { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 298 | struct i2c_client *client; |
| 299 | struct input_dev *input_dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 300 | const struct mxt_platform_data *pdata; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 301 | const struct mxt_config_info *config_info; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 302 | struct mxt_object *object_table; |
| 303 | struct mxt_info info; |
| 304 | struct mxt_finger finger[MXT_MAX_FINGER]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 305 | unsigned int irq; |
Amy Maloche | 83c385a | 2012-02-01 10:32:03 +0530 | [diff] [blame] | 306 | unsigned int touch_x_size; |
| 307 | unsigned int touch_y_size; |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 308 | struct regulator *vcc_ana; |
| 309 | struct regulator *vcc_dig; |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 310 | struct regulator *vcc_i2c; |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 311 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 312 | struct early_suspend early_suspend; |
| 313 | #endif |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 314 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 315 | u8 t7_data[T7_DATA_SIZE]; |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 316 | u16 t7_start_addr; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 317 | u8 t9_ctrl; |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 318 | u32 keyarray_old; |
| 319 | u32 keyarray_new; |
| 320 | u8 t9_max_reportid; |
| 321 | u8 t9_min_reportid; |
| 322 | u8 t15_max_reportid; |
| 323 | u8 t15_min_reportid; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 324 | u8 curr_cfg_version; |
| 325 | int cfg_version_idx; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 326 | }; |
| 327 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 328 | static struct dentry *debug_base; |
| 329 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 330 | static bool mxt_object_readable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 331 | { |
| 332 | switch (type) { |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 333 | case MXT_GEN_MESSAGE_T5: |
| 334 | case MXT_GEN_COMMAND_T6: |
| 335 | case MXT_GEN_POWER_T7: |
| 336 | case MXT_GEN_ACQUIRE_T8: |
| 337 | case MXT_GEN_DATASOURCE_T53: |
| 338 | case MXT_TOUCH_MULTI_T9: |
| 339 | case MXT_TOUCH_KEYARRAY_T15: |
| 340 | case MXT_TOUCH_PROXIMITY_T23: |
| 341 | case MXT_TOUCH_PROXKEY_T52: |
| 342 | case MXT_PROCI_GRIPFACE_T20: |
| 343 | case MXT_PROCG_NOISE_T22: |
| 344 | case MXT_PROCI_ONETOUCH_T24: |
| 345 | case MXT_PROCI_TWOTOUCH_T27: |
| 346 | case MXT_PROCI_GRIP_T40: |
| 347 | case MXT_PROCI_PALM_T41: |
| 348 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 349 | case MXT_PROCI_STYLUS_T47: |
Jing Lin | c7fc405 | 2011-12-21 16:16:19 -0800 | [diff] [blame] | 350 | case MXT_PROCI_SHIELDLESS_T56: |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 351 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 352 | case MXT_SPT_COMMSCONFIG_T18: |
| 353 | case MXT_SPT_GPIOPWM_T19: |
| 354 | case MXT_SPT_SELFTEST_T25: |
| 355 | case MXT_SPT_CTECONFIG_T28: |
| 356 | case MXT_SPT_USERDATA_T38: |
| 357 | case MXT_SPT_DIGITIZER_T43: |
| 358 | case MXT_SPT_CTECONFIG_T46: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 359 | return true; |
| 360 | default: |
| 361 | return false; |
| 362 | } |
| 363 | } |
| 364 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 365 | static bool mxt_object_writable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 366 | { |
| 367 | switch (type) { |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 368 | case MXT_GEN_COMMAND_T6: |
| 369 | case MXT_GEN_POWER_T7: |
| 370 | case MXT_GEN_ACQUIRE_T8: |
| 371 | case MXT_TOUCH_MULTI_T9: |
| 372 | case MXT_TOUCH_KEYARRAY_T15: |
| 373 | case MXT_TOUCH_PROXIMITY_T23: |
| 374 | case MXT_TOUCH_PROXKEY_T52: |
| 375 | case MXT_PROCI_GRIPFACE_T20: |
| 376 | case MXT_PROCG_NOISE_T22: |
| 377 | case MXT_PROCI_ONETOUCH_T24: |
| 378 | case MXT_PROCI_TWOTOUCH_T27: |
| 379 | case MXT_PROCI_GRIP_T40: |
| 380 | case MXT_PROCI_PALM_T41: |
| 381 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 382 | case MXT_PROCI_STYLUS_T47: |
Jing Lin | c7fc405 | 2011-12-21 16:16:19 -0800 | [diff] [blame] | 383 | case MXT_PROCI_SHIELDLESS_T56: |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 384 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 385 | case MXT_SPT_COMMSCONFIG_T18: |
| 386 | case MXT_SPT_GPIOPWM_T19: |
| 387 | case MXT_SPT_SELFTEST_T25: |
| 388 | case MXT_SPT_CTECONFIG_T28: |
| 389 | case MXT_SPT_USERDATA_T38: |
| 390 | case MXT_SPT_DIGITIZER_T43: |
| 391 | case MXT_SPT_CTECONFIG_T46: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 392 | return true; |
| 393 | default: |
| 394 | return false; |
| 395 | } |
| 396 | } |
| 397 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 398 | static void mxt_dump_message(struct device *dev, |
| 399 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 400 | { |
| 401 | dev_dbg(dev, "reportid:\t0x%x\n", message->reportid); |
| 402 | dev_dbg(dev, "message1:\t0x%x\n", message->message[0]); |
| 403 | dev_dbg(dev, "message2:\t0x%x\n", message->message[1]); |
| 404 | dev_dbg(dev, "message3:\t0x%x\n", message->message[2]); |
| 405 | dev_dbg(dev, "message4:\t0x%x\n", message->message[3]); |
| 406 | dev_dbg(dev, "message5:\t0x%x\n", message->message[4]); |
| 407 | dev_dbg(dev, "message6:\t0x%x\n", message->message[5]); |
| 408 | dev_dbg(dev, "message7:\t0x%x\n", message->message[6]); |
| 409 | dev_dbg(dev, "checksum:\t0x%x\n", message->checksum); |
| 410 | } |
| 411 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 412 | static int mxt_check_bootloader(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 413 | unsigned int state) |
| 414 | { |
| 415 | u8 val; |
| 416 | |
| 417 | recheck: |
| 418 | if (i2c_master_recv(client, &val, 1) != 1) { |
| 419 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); |
| 420 | return -EIO; |
| 421 | } |
| 422 | |
| 423 | switch (state) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 424 | case MXT_WAITING_BOOTLOAD_CMD: |
| 425 | case MXT_WAITING_FRAME_DATA: |
| 426 | val &= ~MXT_BOOT_STATUS_MASK; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 427 | break; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 428 | case MXT_FRAME_CRC_PASS: |
| 429 | if (val == MXT_FRAME_CRC_CHECK) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 430 | goto recheck; |
| 431 | break; |
| 432 | default: |
| 433 | return -EINVAL; |
| 434 | } |
| 435 | |
| 436 | if (val != state) { |
| 437 | dev_err(&client->dev, "Unvalid bootloader mode state\n"); |
| 438 | return -EINVAL; |
| 439 | } |
| 440 | |
| 441 | return 0; |
| 442 | } |
| 443 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 444 | static int mxt_unlock_bootloader(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 445 | { |
| 446 | u8 buf[2]; |
| 447 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 448 | buf[0] = MXT_UNLOCK_CMD_LSB; |
| 449 | buf[1] = MXT_UNLOCK_CMD_MSB; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 450 | |
| 451 | if (i2c_master_send(client, buf, 2) != 2) { |
| 452 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 453 | return -EIO; |
| 454 | } |
| 455 | |
| 456 | return 0; |
| 457 | } |
| 458 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 459 | static int mxt_fw_write(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 460 | const u8 *data, unsigned int frame_size) |
| 461 | { |
| 462 | if (i2c_master_send(client, data, frame_size) != frame_size) { |
| 463 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 464 | return -EIO; |
| 465 | } |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 470 | static int __mxt_read_reg(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 471 | u16 reg, u16 len, void *val) |
| 472 | { |
| 473 | struct i2c_msg xfer[2]; |
| 474 | u8 buf[2]; |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 475 | int i = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 476 | |
| 477 | buf[0] = reg & 0xff; |
| 478 | buf[1] = (reg >> 8) & 0xff; |
| 479 | |
| 480 | /* Write register */ |
| 481 | xfer[0].addr = client->addr; |
| 482 | xfer[0].flags = 0; |
| 483 | xfer[0].len = 2; |
| 484 | xfer[0].buf = buf; |
| 485 | |
| 486 | /* Read data */ |
| 487 | xfer[1].addr = client->addr; |
| 488 | xfer[1].flags = I2C_M_RD; |
| 489 | xfer[1].len = len; |
| 490 | xfer[1].buf = val; |
| 491 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 492 | do { |
| 493 | if (i2c_transfer(client->adapter, xfer, 2) == 2) |
| 494 | return 0; |
| 495 | msleep(MXT_WAKE_TIME); |
| 496 | } while (++i < MXT_MAX_RW_TRIES); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 497 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 498 | dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); |
| 499 | return -EIO; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 502 | 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] | 503 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 504 | return __mxt_read_reg(client, reg, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 507 | static int __mxt_write_reg(struct i2c_client *client, |
| 508 | u16 addr, u16 length, u8 *value) |
| 509 | { |
| 510 | u8 buf[MXT_BLOCK_SIZE + 2]; |
| 511 | int i, tries = 0; |
| 512 | |
| 513 | if (length > MXT_BLOCK_SIZE) |
| 514 | return -EINVAL; |
| 515 | |
| 516 | buf[0] = addr & 0xff; |
| 517 | buf[1] = (addr >> 8) & 0xff; |
| 518 | for (i = 0; i < length; i++) |
| 519 | buf[i + 2] = *value++; |
| 520 | |
| 521 | do { |
| 522 | if (i2c_master_send(client, buf, length + 2) == (length + 2)) |
| 523 | return 0; |
| 524 | msleep(MXT_WAKE_TIME); |
| 525 | } while (++tries < MXT_MAX_RW_TRIES); |
| 526 | |
| 527 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 528 | return -EIO; |
| 529 | } |
| 530 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 531 | 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] | 532 | { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 533 | return __mxt_write_reg(client, reg, 1, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 536 | static int mxt_read_object_table(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 537 | u16 reg, u8 *object_buf) |
| 538 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 539 | return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 540 | object_buf); |
| 541 | } |
| 542 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 543 | static struct mxt_object * |
| 544 | mxt_get_object(struct mxt_data *data, u8 type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 545 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 546 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 547 | int i; |
| 548 | |
| 549 | for (i = 0; i < data->info.object_num; i++) { |
| 550 | object = data->object_table + i; |
| 551 | if (object->type == type) |
| 552 | return object; |
| 553 | } |
| 554 | |
| 555 | dev_err(&data->client->dev, "Invalid object type\n"); |
| 556 | return NULL; |
| 557 | } |
| 558 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 559 | static int mxt_read_message(struct mxt_data *data, |
| 560 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 561 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 562 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 563 | u16 reg; |
| 564 | |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 565 | object = mxt_get_object(data, MXT_GEN_MESSAGE_T5); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 566 | if (!object) |
| 567 | return -EINVAL; |
| 568 | |
| 569 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 570 | return __mxt_read_reg(data->client, reg, |
| 571 | sizeof(struct mxt_message), message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 574 | static int mxt_read_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 575 | u8 type, u8 offset, u8 *val) |
| 576 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 577 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 578 | u16 reg; |
| 579 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 580 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 581 | if (!object) |
| 582 | return -EINVAL; |
| 583 | |
| 584 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 585 | return __mxt_read_reg(data->client, reg + offset, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 588 | static int mxt_write_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 589 | u8 type, u8 offset, u8 val) |
| 590 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 591 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 592 | u16 reg; |
| 593 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 594 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 595 | if (!object) |
| 596 | return -EINVAL; |
| 597 | |
| 598 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 599 | return mxt_write_reg(data->client, reg + offset, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 602 | static void mxt_input_report(struct mxt_data *data, int single_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 603 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 604 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 605 | struct input_dev *input_dev = data->input_dev; |
| 606 | int status = finger[single_id].status; |
| 607 | int finger_num = 0; |
| 608 | int id; |
| 609 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 610 | for (id = 0; id < MXT_MAX_FINGER; id++) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 611 | if (!finger[id].status) |
| 612 | continue; |
| 613 | |
Joonyoung Shim | cd47322 | 2012-02-14 18:32:48 -0800 | [diff] [blame] | 614 | input_mt_slot(input_dev, id); |
| 615 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, |
| 616 | finger[id].status != MXT_RELEASE); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 617 | |
Joonyoung Shim | cd47322 | 2012-02-14 18:32:48 -0800 | [diff] [blame] | 618 | if (finger[id].status != MXT_RELEASE) { |
Amy Maloche | 2b59bab | 2011-10-13 16:08:16 -0700 | [diff] [blame] | 619 | finger_num++; |
Joonyoung Shim | cd47322 | 2012-02-14 18:32:48 -0800 | [diff] [blame] | 620 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, |
| 621 | finger[id].area); |
| 622 | input_report_abs(input_dev, ABS_MT_POSITION_X, |
| 623 | finger[id].x); |
| 624 | input_report_abs(input_dev, ABS_MT_POSITION_Y, |
| 625 | finger[id].y); |
| 626 | input_report_abs(input_dev, ABS_MT_PRESSURE, |
| 627 | finger[id].area); |
| 628 | } else { |
| 629 | finger[id].status = 0; |
| 630 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | input_report_key(input_dev, BTN_TOUCH, finger_num > 0); |
| 634 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 635 | if (status != MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 636 | input_report_abs(input_dev, ABS_X, finger[single_id].x); |
| 637 | input_report_abs(input_dev, ABS_Y, finger[single_id].y); |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 638 | input_report_abs(input_dev, |
| 639 | ABS_PRESSURE, finger[single_id].pressure); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | input_sync(input_dev); |
| 643 | } |
| 644 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 645 | static void mxt_input_touchevent(struct mxt_data *data, |
| 646 | struct mxt_message *message, int id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 647 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 648 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 649 | struct device *dev = &data->client->dev; |
| 650 | u8 status = message->message[0]; |
| 651 | int x; |
| 652 | int y; |
| 653 | int area; |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 654 | int pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 655 | |
| 656 | /* Check the touch is present on the screen */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 657 | if (!(status & MXT_DETECT)) { |
| 658 | if (status & MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 659 | dev_dbg(dev, "[%d] released\n", id); |
| 660 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 661 | finger[id].status = MXT_RELEASE; |
| 662 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 663 | } |
| 664 | return; |
| 665 | } |
| 666 | |
| 667 | /* Check only AMP detection */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 668 | if (!(status & (MXT_PRESS | MXT_MOVE))) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 669 | return; |
| 670 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 671 | x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); |
| 672 | y = (message->message[2] << 4) | ((message->message[3] & 0xf)); |
Amy Maloche | 83c385a | 2012-02-01 10:32:03 +0530 | [diff] [blame] | 673 | if (data->touch_x_size < 1024) |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 674 | x = x >> 2; |
Amy Maloche | 83c385a | 2012-02-01 10:32:03 +0530 | [diff] [blame] | 675 | if (data->touch_y_size < 1024) |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 676 | y = y >> 2; |
| 677 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 678 | area = message->message[4]; |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 679 | pressure = message->message[5]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 680 | |
| 681 | 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] | 682 | status & MXT_MOVE ? "moved" : "pressed", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 683 | x, y, area); |
| 684 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 685 | finger[id].status = status & MXT_MOVE ? |
| 686 | MXT_MOVE : MXT_PRESS; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 687 | finger[id].x = x; |
| 688 | finger[id].y = y; |
| 689 | finger[id].area = area; |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 690 | finger[id].pressure = pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 691 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 692 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 695 | static void mxt_handle_key_array(struct mxt_data *data, |
| 696 | struct mxt_message *message) |
| 697 | { |
| 698 | u32 keys_changed; |
| 699 | int i; |
| 700 | |
| 701 | if (!data->pdata->key_codes) { |
| 702 | dev_err(&data->client->dev, "keyarray is not supported\n"); |
| 703 | return; |
| 704 | } |
| 705 | |
| 706 | data->keyarray_new = message->message[1] | |
| 707 | (message->message[2] << 8) | |
| 708 | (message->message[3] << 16) | |
| 709 | (message->message[4] << 24); |
| 710 | |
| 711 | keys_changed = data->keyarray_old ^ data->keyarray_new; |
| 712 | |
| 713 | if (!keys_changed) { |
| 714 | dev_dbg(&data->client->dev, "no keys changed\n"); |
| 715 | return; |
| 716 | } |
| 717 | |
| 718 | for (i = 0; i < MXT_KEYARRAY_MAX_KEYS; i++) { |
| 719 | if (!(keys_changed & (1 << i))) |
| 720 | continue; |
| 721 | |
| 722 | input_report_key(data->input_dev, data->pdata->key_codes[i], |
| 723 | (data->keyarray_new & (1 << i))); |
| 724 | input_sync(data->input_dev); |
| 725 | } |
| 726 | |
| 727 | data->keyarray_old = data->keyarray_new; |
| 728 | } |
| 729 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 730 | static irqreturn_t mxt_interrupt(int irq, void *dev_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 731 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 732 | struct mxt_data *data = dev_id; |
| 733 | struct mxt_message message; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 734 | struct device *dev = &data->client->dev; |
| 735 | int id; |
| 736 | u8 reportid; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 737 | |
| 738 | do { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 739 | if (mxt_read_message(data, &message)) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 740 | dev_err(dev, "Failed to read message\n"); |
| 741 | goto end; |
| 742 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 743 | reportid = message.reportid; |
| 744 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 745 | if (!reportid) { |
| 746 | dev_dbg(dev, "Report id 0 is reserved\n"); |
| 747 | continue; |
| 748 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 749 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 750 | /* check whether report id is part of T9 or T15 */ |
| 751 | id = reportid - data->t9_min_reportid; |
| 752 | |
| 753 | if (reportid >= data->t9_min_reportid && |
| 754 | reportid <= data->t9_max_reportid) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 755 | mxt_input_touchevent(data, &message, id); |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 756 | else if (reportid >= data->t15_min_reportid && |
| 757 | reportid <= data->t15_max_reportid) |
| 758 | mxt_handle_key_array(data, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 759 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 760 | mxt_dump_message(dev, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 761 | } while (reportid != 0xff); |
| 762 | |
| 763 | end: |
| 764 | return IRQ_HANDLED; |
| 765 | } |
| 766 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 767 | static int mxt_check_reg_init(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 768 | { |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 769 | const struct mxt_config_info *config_info = data->config_info; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 770 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 771 | struct device *dev = &data->client->dev; |
| 772 | int index = 0; |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 773 | int i, j, config_offset; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 774 | |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 775 | if (!config_info) { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 776 | dev_dbg(dev, "No cfg data defined, skipping reg init\n"); |
| 777 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | for (i = 0; i < data->info.object_num; i++) { |
| 781 | object = data->object_table + i; |
| 782 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 783 | if (!mxt_object_writable(object->type)) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 784 | continue; |
| 785 | |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 786 | for (j = 0; j < object->size + 1; j++) { |
| 787 | config_offset = index + j; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 788 | if (config_offset > config_info->config_length) { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 789 | dev_err(dev, "Not enough config data!\n"); |
| 790 | return -EINVAL; |
| 791 | } |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 792 | mxt_write_object(data, object->type, j, |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 793 | config_info->config[config_offset]); |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 794 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 795 | index += object->size + 1; |
| 796 | } |
| 797 | |
| 798 | return 0; |
| 799 | } |
| 800 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 801 | static int mxt_make_highchg(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 802 | { |
| 803 | struct device *dev = &data->client->dev; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 804 | struct mxt_message message; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 805 | int count = 10; |
| 806 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 807 | |
| 808 | /* Read dummy message to make high CHG pin */ |
| 809 | do { |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 810 | error = mxt_read_message(data, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 811 | if (error) |
| 812 | return error; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 813 | } while (message.reportid != 0xff && --count); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 814 | |
| 815 | if (!count) { |
| 816 | dev_err(dev, "CHG pin isn't cleared\n"); |
| 817 | return -EBUSY; |
| 818 | } |
| 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 823 | static int mxt_get_info(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 824 | { |
| 825 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 826 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 827 | int error; |
| 828 | u8 val; |
| 829 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 830 | error = mxt_read_reg(client, MXT_FAMILY_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 831 | if (error) |
| 832 | return error; |
| 833 | info->family_id = val; |
| 834 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 835 | error = mxt_read_reg(client, MXT_VARIANT_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 836 | if (error) |
| 837 | return error; |
| 838 | info->variant_id = val; |
| 839 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 840 | error = mxt_read_reg(client, MXT_VERSION, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 841 | if (error) |
| 842 | return error; |
| 843 | info->version = val; |
| 844 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 845 | error = mxt_read_reg(client, MXT_BUILD, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 846 | if (error) |
| 847 | return error; |
| 848 | info->build = val; |
| 849 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 850 | error = mxt_read_reg(client, MXT_OBJECT_NUM, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 851 | if (error) |
| 852 | return error; |
| 853 | info->object_num = val; |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 858 | static int mxt_get_object_table(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 859 | { |
| 860 | int error; |
| 861 | int i; |
| 862 | u16 reg; |
| 863 | u8 reportid = 0; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 864 | u8 buf[MXT_OBJECT_SIZE]; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 865 | bool found_t38 = false; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 866 | |
| 867 | for (i = 0; i < data->info.object_num; i++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 868 | struct mxt_object *object = data->object_table + i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 869 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 870 | reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; |
| 871 | error = mxt_read_object_table(data->client, reg, buf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 872 | if (error) |
| 873 | return error; |
| 874 | |
| 875 | object->type = buf[0]; |
| 876 | object->start_address = (buf[2] << 8) | buf[1]; |
| 877 | object->size = buf[3]; |
| 878 | object->instances = buf[4]; |
| 879 | object->num_report_ids = buf[5]; |
| 880 | |
| 881 | if (object->num_report_ids) { |
| 882 | reportid += object->num_report_ids * |
| 883 | (object->instances + 1); |
| 884 | object->max_reportid = reportid; |
| 885 | } |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 886 | |
| 887 | /* Calculate index for config major version in config array. |
| 888 | * Major version is the first byte in object T38. |
| 889 | */ |
| 890 | if (object->type == MXT_SPT_USERDATA_T38) |
| 891 | found_t38 = true; |
| 892 | if (!found_t38 && mxt_object_writable(object->type)) |
| 893 | data->cfg_version_idx += object->size + 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 899 | static int mxt_search_config_array(struct mxt_data *data, bool version_match) |
| 900 | { |
| 901 | |
| 902 | const struct mxt_platform_data *pdata = data->pdata; |
| 903 | const struct mxt_config_info *cfg_info; |
| 904 | struct mxt_info *info = &data->info; |
| 905 | int i; |
| 906 | u8 cfg_version; |
| 907 | |
| 908 | for (i = 0; i < pdata->config_array_size; i++) { |
| 909 | |
| 910 | cfg_info = &pdata->config_array[i]; |
| 911 | |
| 912 | if (!cfg_info->config || !cfg_info->config_length) |
| 913 | continue; |
| 914 | |
| 915 | if (info->family_id == cfg_info->family_id && |
| 916 | info->variant_id == cfg_info->variant_id && |
| 917 | info->version == cfg_info->version && |
| 918 | info->build == cfg_info->build) { |
| 919 | |
| 920 | cfg_version = cfg_info->config[data->cfg_version_idx]; |
| 921 | if (data->curr_cfg_version == cfg_version || |
| 922 | !version_match) { |
| 923 | data->config_info = cfg_info; |
| 924 | return 0; |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | dev_info(&data->client->dev, |
| 930 | "Config not found: F: %d, V: %d, FW: %d.%d.%d, CFG: %d\n", |
| 931 | info->family_id, info->variant_id, |
| 932 | info->version >> 4, info->version & 0xF, info->build, |
| 933 | data->curr_cfg_version); |
| 934 | return -EINVAL; |
| 935 | } |
| 936 | |
| 937 | static int mxt_get_config(struct mxt_data *data) |
| 938 | { |
| 939 | const struct mxt_platform_data *pdata = data->pdata; |
| 940 | struct device *dev = &data->client->dev; |
| 941 | struct mxt_object *object; |
| 942 | int error; |
| 943 | |
| 944 | if (!pdata->config_array || !pdata->config_array_size) { |
| 945 | dev_dbg(dev, "No cfg data provided by platform data\n"); |
| 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | /* Get current config version */ |
| 950 | object = mxt_get_object(data, MXT_SPT_USERDATA_T38); |
| 951 | if (!object) { |
| 952 | dev_err(dev, "Unable to obtain USERDATA object\n"); |
| 953 | return -EINVAL; |
| 954 | } |
| 955 | |
| 956 | error = mxt_read_reg(data->client, object->start_address, |
| 957 | &data->curr_cfg_version); |
| 958 | if (error) { |
| 959 | dev_err(dev, "Unable to read config version\n"); |
| 960 | return error; |
| 961 | } |
| 962 | |
| 963 | /* It is possible that the config data on the controller is not |
| 964 | * versioned and the version number returns 0. In this case, |
| 965 | * find a match without the config version checking. |
| 966 | */ |
| 967 | error = mxt_search_config_array(data, |
| 968 | data->curr_cfg_version != 0 ? true : false); |
| 969 | if (error) |
| 970 | return error; |
| 971 | |
| 972 | return 0; |
| 973 | } |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 974 | static void mxt_reset_delay(struct mxt_data *data) |
| 975 | { |
| 976 | struct mxt_info *info = &data->info; |
| 977 | |
| 978 | switch (info->family_id) { |
| 979 | case MXT224_ID: |
| 980 | msleep(MXT224_RESET_TIME); |
| 981 | break; |
Amy Maloche | 380cc0b | 2011-11-03 12:55:04 -0700 | [diff] [blame] | 982 | case MXT224E_ID: |
| 983 | msleep(MXT224E_RESET_TIME); |
| 984 | break; |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 985 | case MXT1386_ID: |
| 986 | msleep(MXT1386_RESET_TIME); |
| 987 | break; |
| 988 | default: |
| 989 | msleep(MXT_RESET_TIME); |
| 990 | } |
| 991 | } |
| 992 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 993 | static int mxt_initialize(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 994 | { |
| 995 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 996 | struct mxt_info *info = &data->info; |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 997 | int error; |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 998 | int timeout_counter = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 999 | u8 val; |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1000 | u8 command_register; |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1001 | struct mxt_object *t7_object; |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1002 | struct mxt_object *t9_object; |
| 1003 | struct mxt_object *t15_object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1004 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1005 | error = mxt_get_info(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1006 | if (error) |
| 1007 | return error; |
| 1008 | |
| 1009 | data->object_table = kcalloc(info->object_num, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1010 | sizeof(struct mxt_object), |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1011 | GFP_KERNEL); |
| 1012 | if (!data->object_table) { |
| 1013 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 1014 | return -ENOMEM; |
| 1015 | } |
| 1016 | |
| 1017 | /* Get object table information */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1018 | error = mxt_get_object_table(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1019 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1020 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1021 | |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1022 | /* Get config data from platform data */ |
| 1023 | error = mxt_get_config(data); |
| 1024 | if (error) |
| 1025 | dev_dbg(&client->dev, "Config info not found.\n"); |
| 1026 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1027 | /* Check register init values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1028 | error = mxt_check_reg_init(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1029 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1030 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1031 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1032 | /* Store T7 and T9 locally, used in suspend/resume operations */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1033 | t7_object = mxt_get_object(data, MXT_GEN_POWER_T7); |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1034 | if (!t7_object) { |
| 1035 | dev_err(&client->dev, "Failed to get T7 object\n"); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1036 | error = -EINVAL; |
| 1037 | goto free_object_table; |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | data->t7_start_addr = t7_object->start_address; |
| 1041 | error = __mxt_read_reg(client, data->t7_start_addr, |
| 1042 | T7_DATA_SIZE, data->t7_data); |
| 1043 | if (error < 0) { |
| 1044 | dev_err(&client->dev, |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1045 | "Failed to save current power state\n"); |
| 1046 | goto free_object_table; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1047 | } |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1048 | error = mxt_read_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1049 | &data->t9_ctrl); |
| 1050 | if (error < 0) { |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1051 | dev_err(&client->dev, "Failed to save current touch object\n"); |
| 1052 | goto free_object_table; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1055 | /* Store T9, T15's min and max report ids */ |
| 1056 | t9_object = mxt_get_object(data, MXT_TOUCH_MULTI_T9); |
| 1057 | if (!t9_object) { |
| 1058 | dev_err(&client->dev, "Failed to get T9 object\n"); |
| 1059 | error = -EINVAL; |
| 1060 | goto free_object_table; |
| 1061 | } |
| 1062 | data->t9_max_reportid = t9_object->max_reportid; |
| 1063 | data->t9_min_reportid = t9_object->max_reportid - |
| 1064 | t9_object->num_report_ids + 1; |
| 1065 | |
| 1066 | if (data->pdata->key_codes) { |
| 1067 | t15_object = mxt_get_object(data, MXT_TOUCH_KEYARRAY_T15); |
| 1068 | if (!t15_object) |
| 1069 | dev_dbg(&client->dev, "T15 object is not available\n"); |
| 1070 | else { |
| 1071 | data->t15_max_reportid = t15_object->max_reportid; |
| 1072 | data->t15_min_reportid = t15_object->max_reportid - |
| 1073 | t15_object->num_report_ids + 1; |
| 1074 | } |
| 1075 | } |
| 1076 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1077 | /* Backup to memory */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1078 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1079 | MXT_COMMAND_BACKUPNV, |
| 1080 | MXT_BACKUP_VALUE); |
| 1081 | msleep(MXT_BACKUP_TIME); |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1082 | do { |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1083 | error = mxt_read_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1084 | MXT_COMMAND_BACKUPNV, |
| 1085 | &command_register); |
| 1086 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1087 | goto free_object_table; |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1088 | usleep_range(1000, 2000); |
| 1089 | } while ((command_register != 0) && (++timeout_counter <= 100)); |
| 1090 | if (timeout_counter > 100) { |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1091 | dev_err(&client->dev, "No response after backup!\n"); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1092 | error = -EIO; |
| 1093 | goto free_object_table; |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1096 | |
| 1097 | /* Soft reset */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1098 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1099 | MXT_COMMAND_RESET, 1); |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1100 | |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1101 | mxt_reset_delay(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1102 | |
| 1103 | /* Update matrix size at info struct */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1104 | error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1105 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1106 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1107 | info->matrix_xsize = val; |
| 1108 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1109 | error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1110 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1111 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1112 | info->matrix_ysize = val; |
| 1113 | |
| 1114 | dev_info(&client->dev, |
| 1115 | "Family ID: %d Variant ID: %d Version: %d Build: %d\n", |
| 1116 | info->family_id, info->variant_id, info->version, |
| 1117 | info->build); |
| 1118 | |
| 1119 | dev_info(&client->dev, |
| 1120 | "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", |
| 1121 | info->matrix_xsize, info->matrix_ysize, |
| 1122 | info->object_num); |
| 1123 | |
| 1124 | return 0; |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1125 | |
| 1126 | free_object_table: |
| 1127 | kfree(data->object_table); |
| 1128 | return error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1131 | static ssize_t mxt_object_show(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1132 | struct device_attribute *attr, char *buf) |
| 1133 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1134 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1135 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1136 | int count = 0; |
| 1137 | int i, j; |
| 1138 | int error; |
| 1139 | u8 val; |
| 1140 | |
| 1141 | for (i = 0; i < data->info.object_num; i++) { |
| 1142 | object = data->object_table + i; |
| 1143 | |
Daniel Kurtz | 4ef11a8 | 2011-11-02 10:43:08 -0700 | [diff] [blame] | 1144 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 1145 | "Object[%d] (Type %d)\n", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1146 | i + 1, object->type); |
Daniel Kurtz | 4ef11a8 | 2011-11-02 10:43:08 -0700 | [diff] [blame] | 1147 | if (count >= PAGE_SIZE) |
| 1148 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1149 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1150 | if (!mxt_object_readable(object->type)) { |
Daniel Kurtz | 4ef11a8 | 2011-11-02 10:43:08 -0700 | [diff] [blame] | 1151 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 1152 | "\n"); |
| 1153 | if (count >= PAGE_SIZE) |
| 1154 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1155 | continue; |
| 1156 | } |
| 1157 | |
| 1158 | for (j = 0; j < object->size + 1; j++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1159 | error = mxt_read_object(data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1160 | object->type, j, &val); |
| 1161 | if (error) |
| 1162 | return error; |
| 1163 | |
Daniel Kurtz | 4ef11a8 | 2011-11-02 10:43:08 -0700 | [diff] [blame] | 1164 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 1165 | "\t[%2d]: %02x (%d)\n", j, val, val); |
| 1166 | if (count >= PAGE_SIZE) |
| 1167 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Daniel Kurtz | 4ef11a8 | 2011-11-02 10:43:08 -0700 | [diff] [blame] | 1170 | count += snprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 1171 | if (count >= PAGE_SIZE) |
| 1172 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | return count; |
| 1176 | } |
| 1177 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1178 | static int mxt_load_fw(struct device *dev, const char *fn) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1179 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1180 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1181 | struct i2c_client *client = data->client; |
| 1182 | const struct firmware *fw = NULL; |
| 1183 | unsigned int frame_size; |
| 1184 | unsigned int pos = 0; |
| 1185 | int ret; |
| 1186 | |
| 1187 | ret = request_firmware(&fw, fn, dev); |
| 1188 | if (ret) { |
| 1189 | dev_err(dev, "Unable to open firmware %s\n", fn); |
| 1190 | return ret; |
| 1191 | } |
| 1192 | |
| 1193 | /* Change to the bootloader mode */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1194 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1195 | MXT_COMMAND_RESET, MXT_BOOT_VALUE); |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1196 | |
| 1197 | mxt_reset_delay(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1198 | |
| 1199 | /* Change to slave address of bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1200 | if (client->addr == MXT_APP_LOW) |
| 1201 | client->addr = MXT_BOOT_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1202 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1203 | client->addr = MXT_BOOT_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1204 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1205 | ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1206 | if (ret) |
| 1207 | goto out; |
| 1208 | |
| 1209 | /* Unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1210 | mxt_unlock_bootloader(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1211 | |
| 1212 | while (pos < fw->size) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1213 | ret = mxt_check_bootloader(client, |
| 1214 | MXT_WAITING_FRAME_DATA); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1215 | if (ret) |
| 1216 | goto out; |
| 1217 | |
| 1218 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); |
| 1219 | |
| 1220 | /* We should add 2 at frame size as the the firmware data is not |
| 1221 | * included the CRC bytes. |
| 1222 | */ |
| 1223 | frame_size += 2; |
| 1224 | |
| 1225 | /* Write one frame to device */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1226 | mxt_fw_write(client, fw->data + pos, frame_size); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1227 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1228 | ret = mxt_check_bootloader(client, |
| 1229 | MXT_FRAME_CRC_PASS); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1230 | if (ret) |
| 1231 | goto out; |
| 1232 | |
| 1233 | pos += frame_size; |
| 1234 | |
| 1235 | dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size); |
| 1236 | } |
| 1237 | |
| 1238 | out: |
| 1239 | release_firmware(fw); |
| 1240 | |
| 1241 | /* Change to slave address of application */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1242 | if (client->addr == MXT_BOOT_LOW) |
| 1243 | client->addr = MXT_APP_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1244 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1245 | client->addr = MXT_APP_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1246 | |
| 1247 | return ret; |
| 1248 | } |
| 1249 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1250 | static ssize_t mxt_update_fw_store(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1251 | struct device_attribute *attr, |
| 1252 | const char *buf, size_t count) |
| 1253 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1254 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1255 | int error; |
| 1256 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1257 | disable_irq(data->irq); |
| 1258 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1259 | error = mxt_load_fw(dev, MXT_FW_NAME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1260 | if (error) { |
| 1261 | dev_err(dev, "The firmware update failed(%d)\n", error); |
| 1262 | count = error; |
| 1263 | } else { |
| 1264 | dev_dbg(dev, "The firmware update succeeded\n"); |
| 1265 | |
| 1266 | /* Wait for reset */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1267 | msleep(MXT_FWRESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1268 | |
| 1269 | kfree(data->object_table); |
| 1270 | data->object_table = NULL; |
| 1271 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1272 | mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | enable_irq(data->irq); |
| 1276 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1277 | error = mxt_make_highchg(data); |
| 1278 | if (error) |
| 1279 | return error; |
| 1280 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1281 | return count; |
| 1282 | } |
| 1283 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1284 | static DEVICE_ATTR(object, 0444, mxt_object_show, NULL); |
| 1285 | static DEVICE_ATTR(update_fw, 0664, NULL, mxt_update_fw_store); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1286 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1287 | static struct attribute *mxt_attrs[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1288 | &dev_attr_object.attr, |
| 1289 | &dev_attr_update_fw.attr, |
| 1290 | NULL |
| 1291 | }; |
| 1292 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1293 | static const struct attribute_group mxt_attr_group = { |
| 1294 | .attrs = mxt_attrs, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1295 | }; |
| 1296 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1297 | static int mxt_start(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1298 | { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1299 | int error; |
| 1300 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1301 | /* restore the old power state values and reenable touch */ |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1302 | error = __mxt_write_reg(data->client, data->t7_start_addr, |
| 1303 | T7_DATA_SIZE, data->t7_data); |
| 1304 | if (error < 0) { |
| 1305 | dev_err(&data->client->dev, |
| 1306 | "failed to restore old power state\n"); |
| 1307 | return error; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1308 | } |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1309 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1310 | error = mxt_write_object(data, |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1311 | MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, data->t9_ctrl); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1312 | if (error < 0) { |
| 1313 | dev_err(&data->client->dev, "failed to restore touch\n"); |
| 1314 | return error; |
| 1315 | } |
| 1316 | |
| 1317 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1320 | static int mxt_stop(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1321 | { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1322 | int error; |
| 1323 | u8 t7_data[T7_DATA_SIZE] = {0}; |
| 1324 | |
| 1325 | /* disable touch and configure deep sleep mode */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1326 | error = mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0); |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1327 | if (error < 0) { |
| 1328 | dev_err(&data->client->dev, "failed to disable touch\n"); |
| 1329 | return error; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1332 | error = __mxt_write_reg(data->client, data->t7_start_addr, |
| 1333 | T7_DATA_SIZE, t7_data); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1334 | if (error < 0) { |
| 1335 | dev_err(&data->client->dev, |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1336 | "failed to configure deep sleep mode\n"); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1337 | return error; |
| 1338 | } |
| 1339 | |
| 1340 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1343 | static int mxt_input_open(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1344 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1345 | struct mxt_data *data = input_get_drvdata(dev); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1346 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1347 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1348 | error = mxt_start(data); |
| 1349 | if (error < 0) { |
| 1350 | dev_err(&data->client->dev, "mxt_start failed in input_open\n"); |
| 1351 | return error; |
| 1352 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1353 | |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1357 | static void mxt_input_close(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1358 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1359 | struct mxt_data *data = input_get_drvdata(dev); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1360 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1361 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1362 | error = mxt_stop(data); |
| 1363 | if (error < 0) |
| 1364 | dev_err(&data->client->dev, "mxt_stop failed in input_close\n"); |
| 1365 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1368 | static int reg_set_optimum_mode_check(struct regulator *reg, int load_uA) |
| 1369 | { |
| 1370 | return (regulator_count_voltages(reg) > 0) ? |
| 1371 | regulator_set_optimum_mode(reg, load_uA) : 0; |
| 1372 | } |
| 1373 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1374 | static int mxt_power_on(struct mxt_data *data, bool on) |
| 1375 | { |
| 1376 | int rc; |
| 1377 | |
| 1378 | if (on == false) |
| 1379 | goto power_off; |
| 1380 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1381 | 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] | 1382 | if (rc < 0) { |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1383 | dev_err(&data->client->dev, |
| 1384 | "Regulator vcc_ana set_opt failed rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1385 | return rc; |
| 1386 | } |
| 1387 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1388 | rc = regulator_enable(data->vcc_ana); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1389 | if (rc) { |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1390 | dev_err(&data->client->dev, |
| 1391 | "Regulator vcc_ana enable failed rc=%d\n", rc); |
| 1392 | goto error_reg_en_vcc_ana; |
| 1393 | } |
| 1394 | |
| 1395 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1396 | rc = reg_set_optimum_mode_check(data->vcc_dig, |
| 1397 | MXT_ACTIVE_LOAD_DIG_UA); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1398 | if (rc < 0) { |
| 1399 | dev_err(&data->client->dev, |
| 1400 | "Regulator vcc_dig set_opt failed rc=%d\n", |
| 1401 | rc); |
| 1402 | goto error_reg_opt_vcc_dig; |
| 1403 | } |
| 1404 | |
| 1405 | rc = regulator_enable(data->vcc_dig); |
| 1406 | if (rc) { |
| 1407 | dev_err(&data->client->dev, |
| 1408 | "Regulator vcc_dig enable failed rc=%d\n", rc); |
| 1409 | goto error_reg_en_vcc_dig; |
| 1410 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1414 | 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] | 1415 | if (rc < 0) { |
| 1416 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1417 | "Regulator vcc_i2c set_opt failed rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1418 | goto error_reg_opt_i2c; |
| 1419 | } |
| 1420 | |
| 1421 | rc = regulator_enable(data->vcc_i2c); |
| 1422 | if (rc) { |
| 1423 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1424 | "Regulator vcc_i2c enable failed rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1425 | goto error_reg_en_vcc_i2c; |
| 1426 | } |
| 1427 | } |
| 1428 | |
Amy Maloche | f0d7b8d | 2011-10-17 12:10:51 -0700 | [diff] [blame] | 1429 | msleep(130); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1430 | |
| 1431 | return 0; |
| 1432 | |
| 1433 | error_reg_en_vcc_i2c: |
| 1434 | if (data->pdata->i2c_pull_up) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1435 | reg_set_optimum_mode_check(data->vcc_i2c, 0); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1436 | error_reg_opt_i2c: |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1437 | if (data->pdata->digital_pwr_regulator) |
| 1438 | regulator_disable(data->vcc_dig); |
| 1439 | error_reg_en_vcc_dig: |
| 1440 | if (data->pdata->digital_pwr_regulator) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1441 | reg_set_optimum_mode_check(data->vcc_dig, 0); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1442 | error_reg_opt_vcc_dig: |
| 1443 | regulator_disable(data->vcc_ana); |
| 1444 | error_reg_en_vcc_ana: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1445 | reg_set_optimum_mode_check(data->vcc_ana, 0); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1446 | return rc; |
| 1447 | |
| 1448 | power_off: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1449 | reg_set_optimum_mode_check(data->vcc_ana, 0); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1450 | regulator_disable(data->vcc_ana); |
| 1451 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1452 | reg_set_optimum_mode_check(data->vcc_dig, 0); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1453 | regulator_disable(data->vcc_dig); |
| 1454 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1455 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1456 | reg_set_optimum_mode_check(data->vcc_i2c, 0); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1457 | regulator_disable(data->vcc_i2c); |
| 1458 | } |
| 1459 | msleep(50); |
| 1460 | return 0; |
| 1461 | } |
| 1462 | |
| 1463 | static int mxt_regulator_configure(struct mxt_data *data, bool on) |
| 1464 | { |
| 1465 | int rc; |
| 1466 | |
| 1467 | if (on == false) |
| 1468 | goto hw_shutdown; |
| 1469 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1470 | data->vcc_ana = regulator_get(&data->client->dev, "vdd_ana"); |
| 1471 | if (IS_ERR(data->vcc_ana)) { |
| 1472 | rc = PTR_ERR(data->vcc_ana); |
| 1473 | dev_err(&data->client->dev, |
| 1474 | "Regulator get failed vcc_ana rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1475 | return rc; |
| 1476 | } |
| 1477 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1478 | if (regulator_count_voltages(data->vcc_ana) > 0) { |
| 1479 | rc = regulator_set_voltage(data->vcc_ana, MXT_VTG_MIN_UV, |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1480 | MXT_VTG_MAX_UV); |
| 1481 | if (rc) { |
| 1482 | dev_err(&data->client->dev, |
| 1483 | "regulator set_vtg failed rc=%d\n", rc); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1484 | goto error_set_vtg_vcc_ana; |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1485 | } |
| 1486 | } |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1487 | if (data->pdata->digital_pwr_regulator) { |
| 1488 | data->vcc_dig = regulator_get(&data->client->dev, "vdd_dig"); |
| 1489 | if (IS_ERR(data->vcc_dig)) { |
| 1490 | rc = PTR_ERR(data->vcc_dig); |
| 1491 | dev_err(&data->client->dev, |
| 1492 | "Regulator get dig failed rc=%d\n", rc); |
| 1493 | goto error_get_vtg_vcc_dig; |
| 1494 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1495 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1496 | if (regulator_count_voltages(data->vcc_dig) > 0) { |
| 1497 | rc = regulator_set_voltage(data->vcc_dig, |
| 1498 | MXT_VTG_DIG_MIN_UV, MXT_VTG_DIG_MAX_UV); |
| 1499 | if (rc) { |
| 1500 | dev_err(&data->client->dev, |
| 1501 | "regulator set_vtg failed rc=%d\n", rc); |
| 1502 | goto error_set_vtg_vcc_dig; |
| 1503 | } |
| 1504 | } |
| 1505 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1506 | if (data->pdata->i2c_pull_up) { |
| 1507 | data->vcc_i2c = regulator_get(&data->client->dev, "vcc_i2c"); |
| 1508 | if (IS_ERR(data->vcc_i2c)) { |
| 1509 | rc = PTR_ERR(data->vcc_i2c); |
| 1510 | dev_err(&data->client->dev, |
| 1511 | "Regulator get failed rc=%d\n", rc); |
| 1512 | goto error_get_vtg_i2c; |
| 1513 | } |
| 1514 | if (regulator_count_voltages(data->vcc_i2c) > 0) { |
| 1515 | rc = regulator_set_voltage(data->vcc_i2c, |
| 1516 | MXT_I2C_VTG_MIN_UV, MXT_I2C_VTG_MAX_UV); |
| 1517 | if (rc) { |
| 1518 | dev_err(&data->client->dev, |
| 1519 | "regulator set_vtg failed rc=%d\n", rc); |
| 1520 | goto error_set_vtg_i2c; |
| 1521 | } |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | return 0; |
| 1526 | |
| 1527 | error_set_vtg_i2c: |
| 1528 | regulator_put(data->vcc_i2c); |
| 1529 | error_get_vtg_i2c: |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1530 | if (data->pdata->digital_pwr_regulator) |
| 1531 | if (regulator_count_voltages(data->vcc_dig) > 0) |
| 1532 | regulator_set_voltage(data->vcc_dig, 0, |
| 1533 | MXT_VTG_DIG_MAX_UV); |
| 1534 | error_set_vtg_vcc_dig: |
| 1535 | if (data->pdata->digital_pwr_regulator) |
| 1536 | regulator_put(data->vcc_dig); |
| 1537 | error_get_vtg_vcc_dig: |
| 1538 | if (regulator_count_voltages(data->vcc_ana) > 0) |
| 1539 | regulator_set_voltage(data->vcc_ana, 0, MXT_VTG_MAX_UV); |
| 1540 | error_set_vtg_vcc_ana: |
| 1541 | regulator_put(data->vcc_ana); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1542 | return rc; |
| 1543 | |
| 1544 | hw_shutdown: |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1545 | if (regulator_count_voltages(data->vcc_ana) > 0) |
| 1546 | regulator_set_voltage(data->vcc_ana, 0, MXT_VTG_MAX_UV); |
| 1547 | regulator_put(data->vcc_ana); |
| 1548 | if (data->pdata->digital_pwr_regulator) { |
| 1549 | if (regulator_count_voltages(data->vcc_dig) > 0) |
| 1550 | regulator_set_voltage(data->vcc_dig, 0, |
| 1551 | MXT_VTG_DIG_MAX_UV); |
| 1552 | regulator_put(data->vcc_dig); |
| 1553 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1554 | if (data->pdata->i2c_pull_up) { |
| 1555 | if (regulator_count_voltages(data->vcc_i2c) > 0) |
| 1556 | regulator_set_voltage(data->vcc_i2c, 0, |
| 1557 | MXT_I2C_VTG_MAX_UV); |
| 1558 | regulator_put(data->vcc_i2c); |
| 1559 | } |
| 1560 | return 0; |
| 1561 | } |
| 1562 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1563 | #ifdef CONFIG_PM |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1564 | static int mxt_regulator_lpm(struct mxt_data *data, bool on) |
| 1565 | { |
| 1566 | |
| 1567 | int rc; |
| 1568 | |
| 1569 | if (on == false) |
| 1570 | goto regulator_hpm; |
| 1571 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1572 | 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] | 1573 | if (rc < 0) { |
| 1574 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1575 | "Regulator vcc_ana set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1576 | goto fail_regulator_lpm; |
| 1577 | } |
| 1578 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1579 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1580 | rc = reg_set_optimum_mode_check(data->vcc_dig, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1581 | MXT_LPM_LOAD_DIG_UA); |
| 1582 | if (rc < 0) { |
| 1583 | dev_err(&data->client->dev, |
| 1584 | "Regulator vcc_dig set_opt failed rc=%d\n", rc); |
| 1585 | goto fail_regulator_lpm; |
| 1586 | } |
| 1587 | } |
| 1588 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1589 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1590 | rc = reg_set_optimum_mode_check(data->vcc_i2c, |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1591 | MXT_I2C_LPM_LOAD_UA); |
| 1592 | if (rc < 0) { |
| 1593 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1594 | "Regulator vcc_i2c set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1595 | goto fail_regulator_lpm; |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | return 0; |
| 1600 | |
| 1601 | regulator_hpm: |
| 1602 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1603 | 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] | 1604 | if (rc < 0) { |
| 1605 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1606 | "Regulator vcc_ana set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1607 | goto fail_regulator_hpm; |
| 1608 | } |
| 1609 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1610 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1611 | rc = reg_set_optimum_mode_check(data->vcc_dig, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1612 | MXT_ACTIVE_LOAD_DIG_UA); |
| 1613 | if (rc < 0) { |
| 1614 | dev_err(&data->client->dev, |
| 1615 | "Regulator vcc_dig set_opt failed rc=%d\n", rc); |
| 1616 | goto fail_regulator_hpm; |
| 1617 | } |
| 1618 | } |
| 1619 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1620 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1621 | 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] | 1622 | if (rc < 0) { |
| 1623 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1624 | "Regulator vcc_i2c set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1625 | goto fail_regulator_hpm; |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | return 0; |
| 1630 | |
| 1631 | fail_regulator_lpm: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1632 | reg_set_optimum_mode_check(data->vcc_ana, MXT_ACTIVE_LOAD_UA); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1633 | if (data->pdata->digital_pwr_regulator) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1634 | reg_set_optimum_mode_check(data->vcc_dig, |
| 1635 | MXT_ACTIVE_LOAD_DIG_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1636 | if (data->pdata->i2c_pull_up) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1637 | reg_set_optimum_mode_check(data->vcc_i2c, MXT_I2C_LOAD_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1638 | |
| 1639 | return rc; |
| 1640 | |
| 1641 | fail_regulator_hpm: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1642 | reg_set_optimum_mode_check(data->vcc_ana, MXT_LPM_LOAD_UA); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1643 | if (data->pdata->digital_pwr_regulator) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1644 | 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] | 1645 | if (data->pdata->i2c_pull_up) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame] | 1646 | 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] | 1647 | |
| 1648 | return rc; |
| 1649 | } |
| 1650 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1651 | static int mxt_suspend(struct device *dev) |
| 1652 | { |
| 1653 | struct i2c_client *client = to_i2c_client(dev); |
| 1654 | struct mxt_data *data = i2c_get_clientdata(client); |
| 1655 | struct input_dev *input_dev = data->input_dev; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1656 | int error; |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1657 | |
| 1658 | mutex_lock(&input_dev->mutex); |
| 1659 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1660 | if (input_dev->users) { |
| 1661 | error = mxt_stop(data); |
| 1662 | if (error < 0) { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1663 | dev_err(dev, "mxt_stop failed in suspend\n"); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1664 | mutex_unlock(&input_dev->mutex); |
| 1665 | return error; |
| 1666 | } |
| 1667 | |
| 1668 | } |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1669 | |
| 1670 | mutex_unlock(&input_dev->mutex); |
| 1671 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1672 | /* put regulators in low power mode */ |
| 1673 | error = mxt_regulator_lpm(data, true); |
| 1674 | if (error < 0) { |
| 1675 | dev_err(dev, "failed to enter low power mode\n"); |
| 1676 | return error; |
| 1677 | } |
| 1678 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1679 | return 0; |
| 1680 | } |
| 1681 | |
| 1682 | static int mxt_resume(struct device *dev) |
| 1683 | { |
| 1684 | struct i2c_client *client = to_i2c_client(dev); |
| 1685 | struct mxt_data *data = i2c_get_clientdata(client); |
| 1686 | struct input_dev *input_dev = data->input_dev; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1687 | int error; |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1688 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1689 | /* put regulators in high power mode */ |
| 1690 | error = mxt_regulator_lpm(data, false); |
| 1691 | if (error < 0) { |
| 1692 | dev_err(dev, "failed to enter high power mode\n"); |
| 1693 | return error; |
| 1694 | } |
| 1695 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1696 | mutex_lock(&input_dev->mutex); |
| 1697 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1698 | if (input_dev->users) { |
| 1699 | error = mxt_start(data); |
| 1700 | if (error < 0) { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1701 | dev_err(dev, "mxt_start failed in resume\n"); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1702 | mutex_unlock(&input_dev->mutex); |
| 1703 | return error; |
| 1704 | } |
| 1705 | } |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1706 | |
| 1707 | mutex_unlock(&input_dev->mutex); |
| 1708 | |
| 1709 | return 0; |
| 1710 | } |
| 1711 | |
| 1712 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 1713 | static void mxt_early_suspend(struct early_suspend *h) |
| 1714 | { |
| 1715 | struct mxt_data *data = container_of(h, struct mxt_data, early_suspend); |
| 1716 | |
| 1717 | mxt_suspend(&data->client->dev); |
| 1718 | } |
| 1719 | |
| 1720 | static void mxt_late_resume(struct early_suspend *h) |
| 1721 | { |
| 1722 | struct mxt_data *data = container_of(h, struct mxt_data, early_suspend); |
| 1723 | |
| 1724 | mxt_resume(&data->client->dev); |
| 1725 | } |
| 1726 | #endif |
| 1727 | |
| 1728 | static const struct dev_pm_ops mxt_pm_ops = { |
| 1729 | #ifndef CONFIG_HAS_EARLYSUSPEND |
| 1730 | .suspend = mxt_suspend, |
| 1731 | .resume = mxt_resume, |
| 1732 | #endif |
| 1733 | }; |
| 1734 | #endif |
| 1735 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 1736 | static int mxt_debugfs_object_show(struct seq_file *m, void *v) |
| 1737 | { |
| 1738 | struct mxt_data *data = m->private; |
| 1739 | struct mxt_object *object; |
| 1740 | struct device *dev = &data->client->dev; |
| 1741 | int i, j, k; |
| 1742 | int error; |
| 1743 | int obj_size; |
| 1744 | u8 val; |
| 1745 | |
| 1746 | for (i = 0; i < data->info.object_num; i++) { |
| 1747 | object = data->object_table + i; |
| 1748 | obj_size = object->size + 1; |
| 1749 | |
| 1750 | seq_printf(m, "Object[%d] (Type %d)\n", i + 1, object->type); |
| 1751 | |
| 1752 | for (j = 0; j < object->instances + 1; j++) { |
| 1753 | seq_printf(m, "[Instance %d]\n", j); |
| 1754 | |
| 1755 | for (k = 0; k < obj_size; k++) { |
| 1756 | error = mxt_read_object(data, object->type, |
| 1757 | j * obj_size + k, &val); |
| 1758 | if (error) { |
| 1759 | dev_err(dev, |
| 1760 | "Failed to read object %d " |
| 1761 | "instance %d at offset %d\n", |
| 1762 | object->type, j, k); |
| 1763 | return error; |
| 1764 | } |
| 1765 | |
| 1766 | seq_printf(m, "Byte %d: 0x%02x (%d)\n", |
| 1767 | k, val, val); |
| 1768 | } |
| 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | return 0; |
| 1773 | } |
| 1774 | |
| 1775 | static int mxt_debugfs_object_open(struct inode *inode, struct file *file) |
| 1776 | { |
| 1777 | return single_open(file, mxt_debugfs_object_show, inode->i_private); |
| 1778 | } |
| 1779 | |
| 1780 | static const struct file_operations mxt_object_fops = { |
| 1781 | .owner = THIS_MODULE, |
| 1782 | .open = mxt_debugfs_object_open, |
| 1783 | .read = seq_read, |
| 1784 | .release = single_release, |
| 1785 | }; |
| 1786 | |
| 1787 | static void __init mxt_debugfs_init(struct mxt_data *data) |
| 1788 | { |
| 1789 | debug_base = debugfs_create_dir(MXT_DEBUGFS_DIR, NULL); |
| 1790 | if (IS_ERR_OR_NULL(debug_base)) |
| 1791 | pr_err("atmel_mxt_ts: Failed to create debugfs dir\n"); |
| 1792 | if (IS_ERR_OR_NULL(debugfs_create_file(MXT_DEBUGFS_FILE, |
| 1793 | 0444, |
| 1794 | debug_base, |
| 1795 | data, |
| 1796 | &mxt_object_fops))) { |
| 1797 | pr_err("atmel_mxt_ts: Failed to create object file\n"); |
| 1798 | debugfs_remove_recursive(debug_base); |
| 1799 | } |
| 1800 | } |
| 1801 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1802 | static int __devinit mxt_probe(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1803 | const struct i2c_device_id *id) |
| 1804 | { |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1805 | const struct mxt_platform_data *pdata = client->dev.platform_data; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1806 | struct mxt_data *data; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1807 | struct input_dev *input_dev; |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1808 | int error, i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1809 | |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1810 | if (!pdata) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1811 | return -EINVAL; |
| 1812 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1813 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1814 | input_dev = input_allocate_device(); |
| 1815 | if (!data || !input_dev) { |
| 1816 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 1817 | error = -ENOMEM; |
| 1818 | goto err_free_mem; |
| 1819 | } |
| 1820 | |
Amy Maloche | 83c385a | 2012-02-01 10:32:03 +0530 | [diff] [blame] | 1821 | input_dev->name = "atmel_mxt_ts"; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1822 | input_dev->id.bustype = BUS_I2C; |
| 1823 | input_dev->dev.parent = &client->dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1824 | input_dev->open = mxt_input_open; |
| 1825 | input_dev->close = mxt_input_close; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1826 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1827 | data->client = client; |
| 1828 | data->input_dev = input_dev; |
| 1829 | data->pdata = pdata; |
| 1830 | data->irq = client->irq; |
| 1831 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1832 | __set_bit(EV_ABS, input_dev->evbit); |
| 1833 | __set_bit(EV_KEY, input_dev->evbit); |
| 1834 | __set_bit(BTN_TOUCH, input_dev->keybit); |
| 1835 | |
| 1836 | /* For single touch */ |
| 1837 | input_set_abs_params(input_dev, ABS_X, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame] | 1838 | 0, data->pdata->x_size, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1839 | input_set_abs_params(input_dev, ABS_Y, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame] | 1840 | 0, data->pdata->y_size, 0, 0); |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 1841 | input_set_abs_params(input_dev, ABS_PRESSURE, |
| 1842 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1843 | |
| 1844 | /* For multi touch */ |
Joonyoung Shim | cd47322 | 2012-02-14 18:32:48 -0800 | [diff] [blame] | 1845 | input_mt_init_slots(input_dev, MXT_MAX_FINGER); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1846 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1847 | 0, MXT_MAX_AREA, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1848 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame] | 1849 | 0, data->pdata->x_size, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1850 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame] | 1851 | 0, data->pdata->y_size, 0, 0); |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 1852 | input_set_abs_params(input_dev, ABS_MT_PRESSURE, |
| 1853 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1854 | |
Amy Maloche | 83c385a | 2012-02-01 10:32:03 +0530 | [diff] [blame] | 1855 | if (pdata->touch_x_size) |
| 1856 | data->touch_x_size = pdata->touch_x_size; |
| 1857 | else |
| 1858 | data->touch_x_size = pdata->x_size; |
| 1859 | |
| 1860 | if (pdata->touch_y_size) |
| 1861 | data->touch_y_size = pdata->touch_y_size; |
| 1862 | else |
| 1863 | data->touch_y_size = pdata->y_size; |
| 1864 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1865 | /* set key array supported keys */ |
| 1866 | if (pdata->key_codes) { |
| 1867 | for (i = 0; i < MXT_KEYARRAY_MAX_KEYS; i++) { |
| 1868 | if (pdata->key_codes[i]) |
| 1869 | input_set_capability(input_dev, EV_KEY, |
| 1870 | pdata->key_codes[i]); |
| 1871 | } |
| 1872 | } |
| 1873 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1874 | input_set_drvdata(input_dev, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1875 | i2c_set_clientdata(client, data); |
| 1876 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1877 | if (pdata->init_hw) |
| 1878 | error = pdata->init_hw(true); |
| 1879 | else |
| 1880 | error = mxt_regulator_configure(data, true); |
| 1881 | if (error) { |
| 1882 | dev_err(&client->dev, "Failed to intialize hardware\n"); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1883 | goto err_free_mem; |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | if (pdata->power_on) |
| 1887 | error = pdata->power_on(true); |
| 1888 | else |
| 1889 | error = mxt_power_on(data, true); |
| 1890 | if (error) { |
| 1891 | dev_err(&client->dev, "Failed to power on hardware\n"); |
| 1892 | goto err_regulator_on; |
| 1893 | } |
| 1894 | |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 1895 | if (gpio_is_valid(pdata->irq_gpio)) { |
| 1896 | /* configure touchscreen irq gpio */ |
| 1897 | error = gpio_request(pdata->irq_gpio, |
| 1898 | "mxt_irq_gpio"); |
| 1899 | if (error) { |
| 1900 | pr_err("%s: unable to request gpio [%d]\n", __func__, |
| 1901 | pdata->irq_gpio); |
| 1902 | goto err_power_on; |
| 1903 | } |
| 1904 | error = gpio_direction_input(pdata->irq_gpio); |
| 1905 | if (error) { |
| 1906 | pr_err("%s: unable to set_direction for gpio [%d]\n", |
| 1907 | __func__, pdata->irq_gpio); |
| 1908 | goto err_irq_gpio_req; |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | if (gpio_is_valid(pdata->reset_gpio)) { |
| 1913 | /* configure touchscreen reset out gpio */ |
| 1914 | error = gpio_request(pdata->reset_gpio, |
| 1915 | "mxt_reset_gpio"); |
| 1916 | if (error) { |
| 1917 | pr_err("%s: unable to request reset gpio %d\n", |
| 1918 | __func__, pdata->reset_gpio); |
| 1919 | goto err_irq_gpio_req; |
| 1920 | } |
| 1921 | |
| 1922 | error = gpio_direction_output( |
| 1923 | pdata->reset_gpio, 1); |
| 1924 | if (error) { |
| 1925 | pr_err("%s: unable to set direction for gpio %d\n", |
| 1926 | __func__, pdata->reset_gpio); |
| 1927 | goto err_reset_gpio_req; |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | mxt_reset_delay(data); |
| 1932 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1933 | error = mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1934 | if (error) |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 1935 | goto err_reset_gpio_req; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1936 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1937 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1938 | pdata->irqflags, client->dev.driver->name, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1939 | if (error) { |
| 1940 | dev_err(&client->dev, "Failed to register interrupt\n"); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1941 | goto err_free_object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1944 | error = mxt_make_highchg(data); |
| 1945 | if (error) |
| 1946 | goto err_free_irq; |
| 1947 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1948 | error = input_register_device(input_dev); |
| 1949 | if (error) |
| 1950 | goto err_free_irq; |
| 1951 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1952 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1953 | if (error) |
| 1954 | goto err_unregister_device; |
| 1955 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1956 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 1957 | data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + |
| 1958 | MXT_SUSPEND_LEVEL; |
| 1959 | data->early_suspend.suspend = mxt_early_suspend; |
| 1960 | data->early_suspend.resume = mxt_late_resume; |
| 1961 | register_early_suspend(&data->early_suspend); |
| 1962 | #endif |
| 1963 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 1964 | mxt_debugfs_init(data); |
| 1965 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1966 | return 0; |
| 1967 | |
| 1968 | err_unregister_device: |
| 1969 | input_unregister_device(input_dev); |
| 1970 | input_dev = NULL; |
| 1971 | err_free_irq: |
| 1972 | free_irq(client->irq, data); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1973 | err_free_object: |
| 1974 | kfree(data->object_table); |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 1975 | err_reset_gpio_req: |
| 1976 | if (gpio_is_valid(pdata->reset_gpio)) |
| 1977 | gpio_free(pdata->reset_gpio); |
| 1978 | err_irq_gpio_req: |
| 1979 | if (gpio_is_valid(pdata->irq_gpio)) |
| 1980 | gpio_free(pdata->irq_gpio); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1981 | err_power_on: |
| 1982 | if (pdata->power_on) |
| 1983 | pdata->power_on(false); |
| 1984 | else |
| 1985 | mxt_power_on(data, false); |
| 1986 | err_regulator_on: |
| 1987 | if (pdata->init_hw) |
| 1988 | pdata->init_hw(false); |
| 1989 | else |
| 1990 | mxt_regulator_configure(data, false); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1991 | err_free_mem: |
| 1992 | input_free_device(input_dev); |
| 1993 | kfree(data); |
| 1994 | return error; |
| 1995 | } |
| 1996 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1997 | static int __devexit mxt_remove(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1998 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1999 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2000 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2001 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2002 | free_irq(data->irq, data); |
| 2003 | input_unregister_device(data->input_dev); |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2004 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 2005 | unregister_early_suspend(&data->early_suspend); |
| 2006 | #endif |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2007 | |
| 2008 | if (data->pdata->power_on) |
| 2009 | data->pdata->power_on(false); |
| 2010 | else |
| 2011 | mxt_power_on(data, false); |
| 2012 | |
| 2013 | if (data->pdata->init_hw) |
| 2014 | data->pdata->init_hw(false); |
| 2015 | else |
| 2016 | mxt_regulator_configure(data, false); |
| 2017 | |
Mohan Pallaka | bfe8f30 | 2012-01-02 18:32:08 +0800 | [diff] [blame] | 2018 | if (gpio_is_valid(data->pdata->reset_gpio)) |
| 2019 | gpio_free(data->pdata->reset_gpio); |
| 2020 | |
| 2021 | if (gpio_is_valid(data->pdata->irq_gpio)) |
| 2022 | gpio_free(data->pdata->irq_gpio); |
| 2023 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2024 | kfree(data->object_table); |
| 2025 | kfree(data); |
| 2026 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 2027 | debugfs_remove_recursive(debug_base); |
| 2028 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2029 | return 0; |
| 2030 | } |
| 2031 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2032 | static const struct i2c_device_id mxt_id[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2033 | { "qt602240_ts", 0 }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2034 | { "atmel_mxt_ts", 0 }, |
Chris Leech | 46ee2a0 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 2035 | { "mXT224", 0 }, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2036 | { } |
| 2037 | }; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2038 | MODULE_DEVICE_TABLE(i2c, mxt_id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2039 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2040 | static struct i2c_driver mxt_driver = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2041 | .driver = { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2042 | .name = "atmel_mxt_ts", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2043 | .owner = THIS_MODULE, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 2044 | #ifdef CONFIG_PM |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2045 | .pm = &mxt_pm_ops, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 2046 | #endif |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2047 | }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2048 | .probe = mxt_probe, |
| 2049 | .remove = __devexit_p(mxt_remove), |
| 2050 | .id_table = mxt_id, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2051 | }; |
| 2052 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2053 | static int __init mxt_init(void) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2054 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2055 | return i2c_add_driver(&mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2058 | static void __exit mxt_exit(void) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2059 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2060 | i2c_del_driver(&mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2063 | module_init(mxt_init); |
| 2064 | module_exit(mxt_exit); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2065 | |
| 2066 | /* Module information */ |
| 2067 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2068 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2069 | MODULE_LICENSE("GPL"); |