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> |
Amy Maloche | 2b59bab | 2011-10-13 16:08:16 -0700 | [diff] [blame] | 21 | #include <linux/input.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 | |
Amy Maloche | 2b59bab | 2011-10-13 16:08:16 -0700 | [diff] [blame] | 614 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, |
| 615 | finger[id].status != MXT_RELEASE ? |
| 616 | finger[id].area : 0); |
| 617 | input_report_abs(input_dev, ABS_MT_POSITION_X, |
| 618 | finger[id].x); |
| 619 | input_report_abs(input_dev, ABS_MT_POSITION_Y, |
| 620 | finger[id].y); |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 621 | input_report_abs(input_dev, ABS_MT_PRESSURE, |
Mohan Pallaka | 5e7343f | 2012-01-02 18:30:16 +0800 | [diff] [blame] | 622 | finger[id].status != MXT_RELEASE ? |
| 623 | finger[id].pressure : 0); |
Amy Maloche | 2b59bab | 2011-10-13 16:08:16 -0700 | [diff] [blame] | 624 | input_mt_sync(input_dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 625 | |
Amy Maloche | 2b59bab | 2011-10-13 16:08:16 -0700 | [diff] [blame] | 626 | if (finger[id].status == MXT_RELEASE) |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 627 | finger[id].status = 0; |
Amy Maloche | 2b59bab | 2011-10-13 16:08:16 -0700 | [diff] [blame] | 628 | else |
| 629 | finger_num++; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | input_report_key(input_dev, BTN_TOUCH, finger_num > 0); |
| 633 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 634 | if (status != MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 635 | input_report_abs(input_dev, ABS_X, finger[single_id].x); |
| 636 | input_report_abs(input_dev, ABS_Y, finger[single_id].y); |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 637 | input_report_abs(input_dev, |
| 638 | ABS_PRESSURE, finger[single_id].pressure); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | input_sync(input_dev); |
| 642 | } |
| 643 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 644 | static void mxt_input_touchevent(struct mxt_data *data, |
| 645 | struct mxt_message *message, int id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 646 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 647 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 648 | struct device *dev = &data->client->dev; |
| 649 | u8 status = message->message[0]; |
| 650 | int x; |
| 651 | int y; |
| 652 | int area; |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 653 | int pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 654 | |
| 655 | /* Check the touch is present on the screen */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 656 | if (!(status & MXT_DETECT)) { |
| 657 | if (status & MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 658 | dev_dbg(dev, "[%d] released\n", id); |
| 659 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 660 | finger[id].status = MXT_RELEASE; |
| 661 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 662 | } |
| 663 | return; |
| 664 | } |
| 665 | |
| 666 | /* Check only AMP detection */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 667 | if (!(status & (MXT_PRESS | MXT_MOVE))) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 668 | return; |
| 669 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 670 | x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); |
| 671 | y = (message->message[2] << 4) | ((message->message[3] & 0xf)); |
Amy Maloche | 83c385a | 2012-02-01 10:32:03 +0530 | [diff] [blame] | 672 | if (data->touch_x_size < 1024) |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 673 | x = x >> 2; |
Amy Maloche | 83c385a | 2012-02-01 10:32:03 +0530 | [diff] [blame] | 674 | if (data->touch_y_size < 1024) |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 675 | y = y >> 2; |
| 676 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 677 | area = message->message[4]; |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 678 | pressure = message->message[5]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 679 | |
| 680 | 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] | 681 | status & MXT_MOVE ? "moved" : "pressed", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 682 | x, y, area); |
| 683 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 684 | finger[id].status = status & MXT_MOVE ? |
| 685 | MXT_MOVE : MXT_PRESS; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 686 | finger[id].x = x; |
| 687 | finger[id].y = y; |
| 688 | finger[id].area = area; |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 689 | finger[id].pressure = pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 690 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 691 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 694 | static void mxt_handle_key_array(struct mxt_data *data, |
| 695 | struct mxt_message *message) |
| 696 | { |
| 697 | u32 keys_changed; |
| 698 | int i; |
| 699 | |
| 700 | if (!data->pdata->key_codes) { |
| 701 | dev_err(&data->client->dev, "keyarray is not supported\n"); |
| 702 | return; |
| 703 | } |
| 704 | |
| 705 | data->keyarray_new = message->message[1] | |
| 706 | (message->message[2] << 8) | |
| 707 | (message->message[3] << 16) | |
| 708 | (message->message[4] << 24); |
| 709 | |
| 710 | keys_changed = data->keyarray_old ^ data->keyarray_new; |
| 711 | |
| 712 | if (!keys_changed) { |
| 713 | dev_dbg(&data->client->dev, "no keys changed\n"); |
| 714 | return; |
| 715 | } |
| 716 | |
| 717 | for (i = 0; i < MXT_KEYARRAY_MAX_KEYS; i++) { |
| 718 | if (!(keys_changed & (1 << i))) |
| 719 | continue; |
| 720 | |
| 721 | input_report_key(data->input_dev, data->pdata->key_codes[i], |
| 722 | (data->keyarray_new & (1 << i))); |
| 723 | input_sync(data->input_dev); |
| 724 | } |
| 725 | |
| 726 | data->keyarray_old = data->keyarray_new; |
| 727 | } |
| 728 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 729 | static irqreturn_t mxt_interrupt(int irq, void *dev_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 730 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 731 | struct mxt_data *data = dev_id; |
| 732 | struct mxt_message message; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 733 | struct device *dev = &data->client->dev; |
| 734 | int id; |
| 735 | u8 reportid; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 736 | |
| 737 | do { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 738 | if (mxt_read_message(data, &message)) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 739 | dev_err(dev, "Failed to read message\n"); |
| 740 | goto end; |
| 741 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 742 | reportid = message.reportid; |
| 743 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 744 | if (!reportid) { |
| 745 | dev_dbg(dev, "Report id 0 is reserved\n"); |
| 746 | continue; |
| 747 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 748 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 749 | /* check whether report id is part of T9 or T15 */ |
| 750 | id = reportid - data->t9_min_reportid; |
| 751 | |
| 752 | if (reportid >= data->t9_min_reportid && |
| 753 | reportid <= data->t9_max_reportid) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 754 | mxt_input_touchevent(data, &message, id); |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 755 | else if (reportid >= data->t15_min_reportid && |
| 756 | reportid <= data->t15_max_reportid) |
| 757 | mxt_handle_key_array(data, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 758 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 759 | mxt_dump_message(dev, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 760 | } while (reportid != 0xff); |
| 761 | |
| 762 | end: |
| 763 | return IRQ_HANDLED; |
| 764 | } |
| 765 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 766 | static int mxt_check_reg_init(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 767 | { |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 768 | const struct mxt_config_info *config_info = data->config_info; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 769 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 770 | struct device *dev = &data->client->dev; |
| 771 | int index = 0; |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 772 | int i, j, config_offset; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 773 | |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 774 | if (!config_info) { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 775 | dev_dbg(dev, "No cfg data defined, skipping reg init\n"); |
| 776 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | for (i = 0; i < data->info.object_num; i++) { |
| 780 | object = data->object_table + i; |
| 781 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 782 | if (!mxt_object_writable(object->type)) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 783 | continue; |
| 784 | |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 785 | for (j = 0; j < object->size + 1; j++) { |
| 786 | config_offset = index + j; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 787 | if (config_offset > config_info->config_length) { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 788 | dev_err(dev, "Not enough config data!\n"); |
| 789 | return -EINVAL; |
| 790 | } |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 791 | mxt_write_object(data, object->type, j, |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 792 | config_info->config[config_offset]); |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 793 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 794 | index += object->size + 1; |
| 795 | } |
| 796 | |
| 797 | return 0; |
| 798 | } |
| 799 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 800 | static int mxt_make_highchg(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 801 | { |
| 802 | struct device *dev = &data->client->dev; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 803 | struct mxt_message message; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 804 | int count = 10; |
| 805 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 806 | |
| 807 | /* Read dummy message to make high CHG pin */ |
| 808 | do { |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 809 | error = mxt_read_message(data, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 810 | if (error) |
| 811 | return error; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 812 | } while (message.reportid != 0xff && --count); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 813 | |
| 814 | if (!count) { |
| 815 | dev_err(dev, "CHG pin isn't cleared\n"); |
| 816 | return -EBUSY; |
| 817 | } |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 822 | static int mxt_get_info(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 823 | { |
| 824 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 825 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 826 | int error; |
| 827 | u8 val; |
| 828 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 829 | error = mxt_read_reg(client, MXT_FAMILY_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 830 | if (error) |
| 831 | return error; |
| 832 | info->family_id = val; |
| 833 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 834 | error = mxt_read_reg(client, MXT_VARIANT_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 835 | if (error) |
| 836 | return error; |
| 837 | info->variant_id = val; |
| 838 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 839 | error = mxt_read_reg(client, MXT_VERSION, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 840 | if (error) |
| 841 | return error; |
| 842 | info->version = val; |
| 843 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 844 | error = mxt_read_reg(client, MXT_BUILD, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 845 | if (error) |
| 846 | return error; |
| 847 | info->build = val; |
| 848 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 849 | error = mxt_read_reg(client, MXT_OBJECT_NUM, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 850 | if (error) |
| 851 | return error; |
| 852 | info->object_num = val; |
| 853 | |
| 854 | return 0; |
| 855 | } |
| 856 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 857 | static int mxt_get_object_table(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 858 | { |
| 859 | int error; |
| 860 | int i; |
| 861 | u16 reg; |
| 862 | u8 reportid = 0; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 863 | u8 buf[MXT_OBJECT_SIZE]; |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 864 | bool found_t38 = false; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 865 | |
| 866 | for (i = 0; i < data->info.object_num; i++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 867 | struct mxt_object *object = data->object_table + i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 868 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 869 | reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; |
| 870 | error = mxt_read_object_table(data->client, reg, buf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 871 | if (error) |
| 872 | return error; |
| 873 | |
| 874 | object->type = buf[0]; |
| 875 | object->start_address = (buf[2] << 8) | buf[1]; |
| 876 | object->size = buf[3]; |
| 877 | object->instances = buf[4]; |
| 878 | object->num_report_ids = buf[5]; |
| 879 | |
| 880 | if (object->num_report_ids) { |
| 881 | reportid += object->num_report_ids * |
| 882 | (object->instances + 1); |
| 883 | object->max_reportid = reportid; |
| 884 | } |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 885 | |
| 886 | /* Calculate index for config major version in config array. |
| 887 | * Major version is the first byte in object T38. |
| 888 | */ |
| 889 | if (object->type == MXT_SPT_USERDATA_T38) |
| 890 | found_t38 = true; |
| 891 | if (!found_t38 && mxt_object_writable(object->type)) |
| 892 | data->cfg_version_idx += object->size + 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | return 0; |
| 896 | } |
| 897 | |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 898 | static int mxt_search_config_array(struct mxt_data *data, bool version_match) |
| 899 | { |
| 900 | |
| 901 | const struct mxt_platform_data *pdata = data->pdata; |
| 902 | const struct mxt_config_info *cfg_info; |
| 903 | struct mxt_info *info = &data->info; |
| 904 | int i; |
| 905 | u8 cfg_version; |
| 906 | |
| 907 | for (i = 0; i < pdata->config_array_size; i++) { |
| 908 | |
| 909 | cfg_info = &pdata->config_array[i]; |
| 910 | |
| 911 | if (!cfg_info->config || !cfg_info->config_length) |
| 912 | continue; |
| 913 | |
| 914 | if (info->family_id == cfg_info->family_id && |
| 915 | info->variant_id == cfg_info->variant_id && |
| 916 | info->version == cfg_info->version && |
| 917 | info->build == cfg_info->build) { |
| 918 | |
| 919 | cfg_version = cfg_info->config[data->cfg_version_idx]; |
| 920 | if (data->curr_cfg_version == cfg_version || |
| 921 | !version_match) { |
| 922 | data->config_info = cfg_info; |
| 923 | return 0; |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | dev_info(&data->client->dev, |
| 929 | "Config not found: F: %d, V: %d, FW: %d.%d.%d, CFG: %d\n", |
| 930 | info->family_id, info->variant_id, |
| 931 | info->version >> 4, info->version & 0xF, info->build, |
| 932 | data->curr_cfg_version); |
| 933 | return -EINVAL; |
| 934 | } |
| 935 | |
| 936 | static int mxt_get_config(struct mxt_data *data) |
| 937 | { |
| 938 | const struct mxt_platform_data *pdata = data->pdata; |
| 939 | struct device *dev = &data->client->dev; |
| 940 | struct mxt_object *object; |
| 941 | int error; |
| 942 | |
| 943 | if (!pdata->config_array || !pdata->config_array_size) { |
| 944 | dev_dbg(dev, "No cfg data provided by platform data\n"); |
| 945 | return 0; |
| 946 | } |
| 947 | |
| 948 | /* Get current config version */ |
| 949 | object = mxt_get_object(data, MXT_SPT_USERDATA_T38); |
| 950 | if (!object) { |
| 951 | dev_err(dev, "Unable to obtain USERDATA object\n"); |
| 952 | return -EINVAL; |
| 953 | } |
| 954 | |
| 955 | error = mxt_read_reg(data->client, object->start_address, |
| 956 | &data->curr_cfg_version); |
| 957 | if (error) { |
| 958 | dev_err(dev, "Unable to read config version\n"); |
| 959 | return error; |
| 960 | } |
| 961 | |
| 962 | /* It is possible that the config data on the controller is not |
| 963 | * versioned and the version number returns 0. In this case, |
| 964 | * find a match without the config version checking. |
| 965 | */ |
| 966 | error = mxt_search_config_array(data, |
| 967 | data->curr_cfg_version != 0 ? true : false); |
| 968 | if (error) |
| 969 | return error; |
| 970 | |
| 971 | return 0; |
| 972 | } |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 973 | static void mxt_reset_delay(struct mxt_data *data) |
| 974 | { |
| 975 | struct mxt_info *info = &data->info; |
| 976 | |
| 977 | switch (info->family_id) { |
| 978 | case MXT224_ID: |
| 979 | msleep(MXT224_RESET_TIME); |
| 980 | break; |
Amy Maloche | 380cc0b | 2011-11-03 12:55:04 -0700 | [diff] [blame] | 981 | case MXT224E_ID: |
| 982 | msleep(MXT224E_RESET_TIME); |
| 983 | break; |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 984 | case MXT1386_ID: |
| 985 | msleep(MXT1386_RESET_TIME); |
| 986 | break; |
| 987 | default: |
| 988 | msleep(MXT_RESET_TIME); |
| 989 | } |
| 990 | } |
| 991 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 992 | static int mxt_initialize(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 993 | { |
| 994 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 995 | struct mxt_info *info = &data->info; |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 996 | int error; |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 997 | int timeout_counter = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 998 | u8 val; |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 999 | u8 command_register; |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1000 | struct mxt_object *t7_object; |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1001 | struct mxt_object *t9_object; |
| 1002 | struct mxt_object *t15_object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1003 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1004 | error = mxt_get_info(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1005 | if (error) |
| 1006 | return error; |
| 1007 | |
| 1008 | data->object_table = kcalloc(info->object_num, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1009 | sizeof(struct mxt_object), |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1010 | GFP_KERNEL); |
| 1011 | if (!data->object_table) { |
| 1012 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 1013 | return -ENOMEM; |
| 1014 | } |
| 1015 | |
| 1016 | /* Get object table information */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1017 | error = mxt_get_object_table(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1018 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1019 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1020 | |
Jing Lin | dc4413c | 2012-01-16 15:22:52 -0800 | [diff] [blame] | 1021 | /* Get config data from platform data */ |
| 1022 | error = mxt_get_config(data); |
| 1023 | if (error) |
| 1024 | dev_dbg(&client->dev, "Config info not found.\n"); |
| 1025 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1026 | /* Check register init values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1027 | error = mxt_check_reg_init(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1028 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1029 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1030 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1031 | /* Store T7 and T9 locally, used in suspend/resume operations */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1032 | t7_object = mxt_get_object(data, MXT_GEN_POWER_T7); |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1033 | if (!t7_object) { |
| 1034 | dev_err(&client->dev, "Failed to get T7 object\n"); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1035 | error = -EINVAL; |
| 1036 | goto free_object_table; |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | data->t7_start_addr = t7_object->start_address; |
| 1040 | error = __mxt_read_reg(client, data->t7_start_addr, |
| 1041 | T7_DATA_SIZE, data->t7_data); |
| 1042 | if (error < 0) { |
| 1043 | dev_err(&client->dev, |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1044 | "Failed to save current power state\n"); |
| 1045 | goto free_object_table; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1046 | } |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1047 | error = mxt_read_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1048 | &data->t9_ctrl); |
| 1049 | if (error < 0) { |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1050 | dev_err(&client->dev, "Failed to save current touch object\n"); |
| 1051 | goto free_object_table; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1054 | /* Store T9, T15's min and max report ids */ |
| 1055 | t9_object = mxt_get_object(data, MXT_TOUCH_MULTI_T9); |
| 1056 | if (!t9_object) { |
| 1057 | dev_err(&client->dev, "Failed to get T9 object\n"); |
| 1058 | error = -EINVAL; |
| 1059 | goto free_object_table; |
| 1060 | } |
| 1061 | data->t9_max_reportid = t9_object->max_reportid; |
| 1062 | data->t9_min_reportid = t9_object->max_reportid - |
| 1063 | t9_object->num_report_ids + 1; |
| 1064 | |
| 1065 | if (data->pdata->key_codes) { |
| 1066 | t15_object = mxt_get_object(data, MXT_TOUCH_KEYARRAY_T15); |
| 1067 | if (!t15_object) |
| 1068 | dev_dbg(&client->dev, "T15 object is not available\n"); |
| 1069 | else { |
| 1070 | data->t15_max_reportid = t15_object->max_reportid; |
| 1071 | data->t15_min_reportid = t15_object->max_reportid - |
| 1072 | t15_object->num_report_ids + 1; |
| 1073 | } |
| 1074 | } |
| 1075 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1076 | /* Backup to memory */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1077 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1078 | MXT_COMMAND_BACKUPNV, |
| 1079 | MXT_BACKUP_VALUE); |
| 1080 | msleep(MXT_BACKUP_TIME); |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1081 | do { |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1082 | error = mxt_read_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1083 | MXT_COMMAND_BACKUPNV, |
| 1084 | &command_register); |
| 1085 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1086 | goto free_object_table; |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1087 | usleep_range(1000, 2000); |
| 1088 | } while ((command_register != 0) && (++timeout_counter <= 100)); |
| 1089 | if (timeout_counter > 100) { |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1090 | dev_err(&client->dev, "No response after backup!\n"); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1091 | error = -EIO; |
| 1092 | goto free_object_table; |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1095 | |
| 1096 | /* Soft reset */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1097 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1098 | MXT_COMMAND_RESET, 1); |
Iiro Valkonen | 4ac053c | 2011-09-08 11:10:52 -0700 | [diff] [blame] | 1099 | |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1100 | mxt_reset_delay(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1101 | |
| 1102 | /* Update matrix size at info struct */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1103 | error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1104 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1105 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1106 | info->matrix_xsize = val; |
| 1107 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1108 | error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1109 | if (error) |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1110 | goto free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1111 | info->matrix_ysize = val; |
| 1112 | |
| 1113 | dev_info(&client->dev, |
| 1114 | "Family ID: %d Variant ID: %d Version: %d Build: %d\n", |
| 1115 | info->family_id, info->variant_id, info->version, |
| 1116 | info->build); |
| 1117 | |
| 1118 | dev_info(&client->dev, |
| 1119 | "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", |
| 1120 | info->matrix_xsize, info->matrix_ysize, |
| 1121 | info->object_num); |
| 1122 | |
| 1123 | return 0; |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1124 | |
| 1125 | free_object_table: |
| 1126 | kfree(data->object_table); |
| 1127 | return error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1130 | static ssize_t mxt_object_show(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1131 | struct device_attribute *attr, char *buf) |
| 1132 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1133 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1134 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1135 | int count = 0; |
| 1136 | int i, j; |
| 1137 | int error; |
| 1138 | u8 val; |
| 1139 | |
| 1140 | for (i = 0; i < data->info.object_num; i++) { |
| 1141 | object = data->object_table + i; |
| 1142 | |
Daniel Kurtz | 4ef11a8 | 2011-11-02 10:43:08 -0700 | [diff] [blame] | 1143 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 1144 | "Object[%d] (Type %d)\n", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1145 | i + 1, object->type); |
Daniel Kurtz | 4ef11a8 | 2011-11-02 10:43:08 -0700 | [diff] [blame] | 1146 | if (count >= PAGE_SIZE) |
| 1147 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1148 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1149 | if (!mxt_object_readable(object->type)) { |
Daniel Kurtz | 4ef11a8 | 2011-11-02 10:43:08 -0700 | [diff] [blame] | 1150 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 1151 | "\n"); |
| 1152 | if (count >= PAGE_SIZE) |
| 1153 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1154 | continue; |
| 1155 | } |
| 1156 | |
| 1157 | for (j = 0; j < object->size + 1; j++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1158 | error = mxt_read_object(data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1159 | object->type, j, &val); |
| 1160 | if (error) |
| 1161 | return error; |
| 1162 | |
Daniel Kurtz | 4ef11a8 | 2011-11-02 10:43:08 -0700 | [diff] [blame] | 1163 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 1164 | "\t[%2d]: %02x (%d)\n", j, val, val); |
| 1165 | if (count >= PAGE_SIZE) |
| 1166 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Daniel Kurtz | 4ef11a8 | 2011-11-02 10:43:08 -0700 | [diff] [blame] | 1169 | count += snprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 1170 | if (count >= PAGE_SIZE) |
| 1171 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | return count; |
| 1175 | } |
| 1176 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1177 | static int mxt_load_fw(struct device *dev, const char *fn) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1178 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1179 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1180 | struct i2c_client *client = data->client; |
| 1181 | const struct firmware *fw = NULL; |
| 1182 | unsigned int frame_size; |
| 1183 | unsigned int pos = 0; |
| 1184 | int ret; |
| 1185 | |
| 1186 | ret = request_firmware(&fw, fn, dev); |
| 1187 | if (ret) { |
| 1188 | dev_err(dev, "Unable to open firmware %s\n", fn); |
| 1189 | return ret; |
| 1190 | } |
| 1191 | |
| 1192 | /* Change to the bootloader mode */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1193 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1194 | MXT_COMMAND_RESET, MXT_BOOT_VALUE); |
Amy Maloche | 7e44743 | 2011-09-14 11:36:30 -0700 | [diff] [blame] | 1195 | |
| 1196 | mxt_reset_delay(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1197 | |
| 1198 | /* Change to slave address of bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1199 | if (client->addr == MXT_APP_LOW) |
| 1200 | client->addr = MXT_BOOT_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1201 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1202 | client->addr = MXT_BOOT_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1203 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1204 | ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1205 | if (ret) |
| 1206 | goto out; |
| 1207 | |
| 1208 | /* Unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1209 | mxt_unlock_bootloader(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1210 | |
| 1211 | while (pos < fw->size) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1212 | ret = mxt_check_bootloader(client, |
| 1213 | MXT_WAITING_FRAME_DATA); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1214 | if (ret) |
| 1215 | goto out; |
| 1216 | |
| 1217 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); |
| 1218 | |
| 1219 | /* We should add 2 at frame size as the the firmware data is not |
| 1220 | * included the CRC bytes. |
| 1221 | */ |
| 1222 | frame_size += 2; |
| 1223 | |
| 1224 | /* Write one frame to device */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1225 | mxt_fw_write(client, fw->data + pos, frame_size); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1226 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1227 | ret = mxt_check_bootloader(client, |
| 1228 | MXT_FRAME_CRC_PASS); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1229 | if (ret) |
| 1230 | goto out; |
| 1231 | |
| 1232 | pos += frame_size; |
| 1233 | |
| 1234 | dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size); |
| 1235 | } |
| 1236 | |
| 1237 | out: |
| 1238 | release_firmware(fw); |
| 1239 | |
| 1240 | /* Change to slave address of application */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1241 | if (client->addr == MXT_BOOT_LOW) |
| 1242 | client->addr = MXT_APP_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1243 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1244 | client->addr = MXT_APP_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1245 | |
| 1246 | return ret; |
| 1247 | } |
| 1248 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1249 | static ssize_t mxt_update_fw_store(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1250 | struct device_attribute *attr, |
| 1251 | const char *buf, size_t count) |
| 1252 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1253 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1254 | int error; |
| 1255 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1256 | disable_irq(data->irq); |
| 1257 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1258 | error = mxt_load_fw(dev, MXT_FW_NAME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1259 | if (error) { |
| 1260 | dev_err(dev, "The firmware update failed(%d)\n", error); |
| 1261 | count = error; |
| 1262 | } else { |
| 1263 | dev_dbg(dev, "The firmware update succeeded\n"); |
| 1264 | |
| 1265 | /* Wait for reset */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1266 | msleep(MXT_FWRESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1267 | |
| 1268 | kfree(data->object_table); |
| 1269 | data->object_table = NULL; |
| 1270 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1271 | mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | enable_irq(data->irq); |
| 1275 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1276 | error = mxt_make_highchg(data); |
| 1277 | if (error) |
| 1278 | return error; |
| 1279 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1280 | return count; |
| 1281 | } |
| 1282 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1283 | static DEVICE_ATTR(object, 0444, mxt_object_show, NULL); |
| 1284 | static DEVICE_ATTR(update_fw, 0664, NULL, mxt_update_fw_store); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1285 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1286 | static struct attribute *mxt_attrs[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1287 | &dev_attr_object.attr, |
| 1288 | &dev_attr_update_fw.attr, |
| 1289 | NULL |
| 1290 | }; |
| 1291 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1292 | static const struct attribute_group mxt_attr_group = { |
| 1293 | .attrs = mxt_attrs, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1294 | }; |
| 1295 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1296 | static int mxt_start(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1297 | { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1298 | int error; |
| 1299 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1300 | /* restore the old power state values and reenable touch */ |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1301 | error = __mxt_write_reg(data->client, data->t7_start_addr, |
| 1302 | T7_DATA_SIZE, data->t7_data); |
| 1303 | if (error < 0) { |
| 1304 | dev_err(&data->client->dev, |
| 1305 | "failed to restore old power state\n"); |
| 1306 | return error; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1307 | } |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1308 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1309 | error = mxt_write_object(data, |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1310 | MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, data->t9_ctrl); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1311 | if (error < 0) { |
| 1312 | dev_err(&data->client->dev, "failed to restore touch\n"); |
| 1313 | return error; |
| 1314 | } |
| 1315 | |
| 1316 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1319 | static int mxt_stop(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1320 | { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1321 | int error; |
| 1322 | u8 t7_data[T7_DATA_SIZE] = {0}; |
| 1323 | |
| 1324 | /* disable touch and configure deep sleep mode */ |
Iiro Valkonen | e864559 | 2011-11-18 12:56:19 -0800 | [diff] [blame] | 1325 | 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] | 1326 | if (error < 0) { |
| 1327 | dev_err(&data->client->dev, "failed to disable touch\n"); |
| 1328 | return error; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1331 | error = __mxt_write_reg(data->client, data->t7_start_addr, |
| 1332 | T7_DATA_SIZE, t7_data); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1333 | if (error < 0) { |
| 1334 | dev_err(&data->client->dev, |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1335 | "failed to configure deep sleep mode\n"); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1336 | return error; |
| 1337 | } |
| 1338 | |
| 1339 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1342 | static int mxt_input_open(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1343 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1344 | struct mxt_data *data = input_get_drvdata(dev); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1345 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1346 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1347 | error = mxt_start(data); |
| 1348 | if (error < 0) { |
| 1349 | dev_err(&data->client->dev, "mxt_start failed in input_open\n"); |
| 1350 | return error; |
| 1351 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1352 | |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1356 | static void mxt_input_close(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1357 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1358 | struct mxt_data *data = input_get_drvdata(dev); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1359 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1360 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1361 | error = mxt_stop(data); |
| 1362 | if (error < 0) |
| 1363 | dev_err(&data->client->dev, "mxt_stop failed in input_close\n"); |
| 1364 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1367 | static int reg_set_optimum_mode_check(struct regulator *reg, int load_uA) |
| 1368 | { |
| 1369 | return (regulator_count_voltages(reg) > 0) ? |
| 1370 | regulator_set_optimum_mode(reg, load_uA) : 0; |
| 1371 | } |
| 1372 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1373 | static int mxt_power_on(struct mxt_data *data, bool on) |
| 1374 | { |
| 1375 | int rc; |
| 1376 | |
| 1377 | if (on == false) |
| 1378 | goto power_off; |
| 1379 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1380 | 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] | 1381 | if (rc < 0) { |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1382 | dev_err(&data->client->dev, |
| 1383 | "Regulator vcc_ana set_opt failed rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1384 | return rc; |
| 1385 | } |
| 1386 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1387 | rc = regulator_enable(data->vcc_ana); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1388 | if (rc) { |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1389 | dev_err(&data->client->dev, |
| 1390 | "Regulator vcc_ana enable failed rc=%d\n", rc); |
| 1391 | goto error_reg_en_vcc_ana; |
| 1392 | } |
| 1393 | |
| 1394 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1395 | rc = reg_set_optimum_mode_check(data->vcc_dig, |
| 1396 | MXT_ACTIVE_LOAD_DIG_UA); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1397 | if (rc < 0) { |
| 1398 | dev_err(&data->client->dev, |
| 1399 | "Regulator vcc_dig set_opt failed rc=%d\n", |
| 1400 | rc); |
| 1401 | goto error_reg_opt_vcc_dig; |
| 1402 | } |
| 1403 | |
| 1404 | rc = regulator_enable(data->vcc_dig); |
| 1405 | if (rc) { |
| 1406 | dev_err(&data->client->dev, |
| 1407 | "Regulator vcc_dig enable failed rc=%d\n", rc); |
| 1408 | goto error_reg_en_vcc_dig; |
| 1409 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1413 | 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] | 1414 | if (rc < 0) { |
| 1415 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1416 | "Regulator vcc_i2c set_opt failed rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1417 | goto error_reg_opt_i2c; |
| 1418 | } |
| 1419 | |
| 1420 | rc = regulator_enable(data->vcc_i2c); |
| 1421 | if (rc) { |
| 1422 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1423 | "Regulator vcc_i2c enable failed rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1424 | goto error_reg_en_vcc_i2c; |
| 1425 | } |
| 1426 | } |
| 1427 | |
Amy Maloche | f0d7b8d | 2011-10-17 12:10:51 -0700 | [diff] [blame] | 1428 | msleep(130); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1429 | |
| 1430 | return 0; |
| 1431 | |
| 1432 | error_reg_en_vcc_i2c: |
| 1433 | if (data->pdata->i2c_pull_up) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1434 | reg_set_optimum_mode_check(data->vcc_i2c, 0); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1435 | error_reg_opt_i2c: |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1436 | if (data->pdata->digital_pwr_regulator) |
| 1437 | regulator_disable(data->vcc_dig); |
| 1438 | error_reg_en_vcc_dig: |
| 1439 | if (data->pdata->digital_pwr_regulator) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1440 | reg_set_optimum_mode_check(data->vcc_dig, 0); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1441 | error_reg_opt_vcc_dig: |
| 1442 | regulator_disable(data->vcc_ana); |
| 1443 | error_reg_en_vcc_ana: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1444 | reg_set_optimum_mode_check(data->vcc_ana, 0); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1445 | return rc; |
| 1446 | |
| 1447 | power_off: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1448 | reg_set_optimum_mode_check(data->vcc_ana, 0); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1449 | regulator_disable(data->vcc_ana); |
| 1450 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1451 | reg_set_optimum_mode_check(data->vcc_dig, 0); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1452 | regulator_disable(data->vcc_dig); |
| 1453 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1454 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1455 | reg_set_optimum_mode_check(data->vcc_i2c, 0); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1456 | regulator_disable(data->vcc_i2c); |
| 1457 | } |
| 1458 | msleep(50); |
| 1459 | return 0; |
| 1460 | } |
| 1461 | |
| 1462 | static int mxt_regulator_configure(struct mxt_data *data, bool on) |
| 1463 | { |
| 1464 | int rc; |
| 1465 | |
| 1466 | if (on == false) |
| 1467 | goto hw_shutdown; |
| 1468 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1469 | data->vcc_ana = regulator_get(&data->client->dev, "vdd_ana"); |
| 1470 | if (IS_ERR(data->vcc_ana)) { |
| 1471 | rc = PTR_ERR(data->vcc_ana); |
| 1472 | dev_err(&data->client->dev, |
| 1473 | "Regulator get failed vcc_ana rc=%d\n", rc); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1474 | return rc; |
| 1475 | } |
| 1476 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1477 | if (regulator_count_voltages(data->vcc_ana) > 0) { |
| 1478 | rc = regulator_set_voltage(data->vcc_ana, MXT_VTG_MIN_UV, |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1479 | MXT_VTG_MAX_UV); |
| 1480 | if (rc) { |
| 1481 | dev_err(&data->client->dev, |
| 1482 | "regulator set_vtg failed rc=%d\n", rc); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1483 | goto error_set_vtg_vcc_ana; |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1484 | } |
| 1485 | } |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1486 | if (data->pdata->digital_pwr_regulator) { |
| 1487 | data->vcc_dig = regulator_get(&data->client->dev, "vdd_dig"); |
| 1488 | if (IS_ERR(data->vcc_dig)) { |
| 1489 | rc = PTR_ERR(data->vcc_dig); |
| 1490 | dev_err(&data->client->dev, |
| 1491 | "Regulator get dig failed rc=%d\n", rc); |
| 1492 | goto error_get_vtg_vcc_dig; |
| 1493 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1494 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1495 | if (regulator_count_voltages(data->vcc_dig) > 0) { |
| 1496 | rc = regulator_set_voltage(data->vcc_dig, |
| 1497 | MXT_VTG_DIG_MIN_UV, MXT_VTG_DIG_MAX_UV); |
| 1498 | if (rc) { |
| 1499 | dev_err(&data->client->dev, |
| 1500 | "regulator set_vtg failed rc=%d\n", rc); |
| 1501 | goto error_set_vtg_vcc_dig; |
| 1502 | } |
| 1503 | } |
| 1504 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1505 | if (data->pdata->i2c_pull_up) { |
| 1506 | data->vcc_i2c = regulator_get(&data->client->dev, "vcc_i2c"); |
| 1507 | if (IS_ERR(data->vcc_i2c)) { |
| 1508 | rc = PTR_ERR(data->vcc_i2c); |
| 1509 | dev_err(&data->client->dev, |
| 1510 | "Regulator get failed rc=%d\n", rc); |
| 1511 | goto error_get_vtg_i2c; |
| 1512 | } |
| 1513 | if (regulator_count_voltages(data->vcc_i2c) > 0) { |
| 1514 | rc = regulator_set_voltage(data->vcc_i2c, |
| 1515 | MXT_I2C_VTG_MIN_UV, MXT_I2C_VTG_MAX_UV); |
| 1516 | if (rc) { |
| 1517 | dev_err(&data->client->dev, |
| 1518 | "regulator set_vtg failed rc=%d\n", rc); |
| 1519 | goto error_set_vtg_i2c; |
| 1520 | } |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | return 0; |
| 1525 | |
| 1526 | error_set_vtg_i2c: |
| 1527 | regulator_put(data->vcc_i2c); |
| 1528 | error_get_vtg_i2c: |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1529 | if (data->pdata->digital_pwr_regulator) |
| 1530 | if (regulator_count_voltages(data->vcc_dig) > 0) |
| 1531 | regulator_set_voltage(data->vcc_dig, 0, |
| 1532 | MXT_VTG_DIG_MAX_UV); |
| 1533 | error_set_vtg_vcc_dig: |
| 1534 | if (data->pdata->digital_pwr_regulator) |
| 1535 | regulator_put(data->vcc_dig); |
| 1536 | error_get_vtg_vcc_dig: |
| 1537 | if (regulator_count_voltages(data->vcc_ana) > 0) |
| 1538 | regulator_set_voltage(data->vcc_ana, 0, MXT_VTG_MAX_UV); |
| 1539 | error_set_vtg_vcc_ana: |
| 1540 | regulator_put(data->vcc_ana); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1541 | return rc; |
| 1542 | |
| 1543 | hw_shutdown: |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1544 | if (regulator_count_voltages(data->vcc_ana) > 0) |
| 1545 | regulator_set_voltage(data->vcc_ana, 0, MXT_VTG_MAX_UV); |
| 1546 | regulator_put(data->vcc_ana); |
| 1547 | if (data->pdata->digital_pwr_regulator) { |
| 1548 | if (regulator_count_voltages(data->vcc_dig) > 0) |
| 1549 | regulator_set_voltage(data->vcc_dig, 0, |
| 1550 | MXT_VTG_DIG_MAX_UV); |
| 1551 | regulator_put(data->vcc_dig); |
| 1552 | } |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1553 | if (data->pdata->i2c_pull_up) { |
| 1554 | if (regulator_count_voltages(data->vcc_i2c) > 0) |
| 1555 | regulator_set_voltage(data->vcc_i2c, 0, |
| 1556 | MXT_I2C_VTG_MAX_UV); |
| 1557 | regulator_put(data->vcc_i2c); |
| 1558 | } |
| 1559 | return 0; |
| 1560 | } |
| 1561 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1562 | #ifdef CONFIG_PM |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1563 | static int mxt_regulator_lpm(struct mxt_data *data, bool on) |
| 1564 | { |
| 1565 | |
| 1566 | int rc; |
| 1567 | |
| 1568 | if (on == false) |
| 1569 | goto regulator_hpm; |
| 1570 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1571 | 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] | 1572 | if (rc < 0) { |
| 1573 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1574 | "Regulator vcc_ana set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1575 | goto fail_regulator_lpm; |
| 1576 | } |
| 1577 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1578 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1579 | rc = reg_set_optimum_mode_check(data->vcc_dig, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1580 | MXT_LPM_LOAD_DIG_UA); |
| 1581 | if (rc < 0) { |
| 1582 | dev_err(&data->client->dev, |
| 1583 | "Regulator vcc_dig set_opt failed rc=%d\n", rc); |
| 1584 | goto fail_regulator_lpm; |
| 1585 | } |
| 1586 | } |
| 1587 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1588 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1589 | rc = reg_set_optimum_mode_check(data->vcc_i2c, |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1590 | MXT_I2C_LPM_LOAD_UA); |
| 1591 | if (rc < 0) { |
| 1592 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1593 | "Regulator vcc_i2c set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1594 | goto fail_regulator_lpm; |
| 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | return 0; |
| 1599 | |
| 1600 | regulator_hpm: |
| 1601 | |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1602 | 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] | 1603 | if (rc < 0) { |
| 1604 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1605 | "Regulator vcc_ana set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1606 | goto fail_regulator_hpm; |
| 1607 | } |
| 1608 | |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1609 | if (data->pdata->digital_pwr_regulator) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1610 | rc = reg_set_optimum_mode_check(data->vcc_dig, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1611 | MXT_ACTIVE_LOAD_DIG_UA); |
| 1612 | if (rc < 0) { |
| 1613 | dev_err(&data->client->dev, |
| 1614 | "Regulator vcc_dig set_opt failed rc=%d\n", rc); |
| 1615 | goto fail_regulator_hpm; |
| 1616 | } |
| 1617 | } |
| 1618 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1619 | if (data->pdata->i2c_pull_up) { |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1620 | 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] | 1621 | if (rc < 0) { |
| 1622 | dev_err(&data->client->dev, |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1623 | "Regulator vcc_i2c set_opt failed rc=%d\n", rc); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1624 | goto fail_regulator_hpm; |
| 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | return 0; |
| 1629 | |
| 1630 | fail_regulator_lpm: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1631 | reg_set_optimum_mode_check(data->vcc_ana, MXT_ACTIVE_LOAD_UA); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1632 | if (data->pdata->digital_pwr_regulator) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1633 | reg_set_optimum_mode_check(data->vcc_dig, |
| 1634 | MXT_ACTIVE_LOAD_DIG_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1635 | if (data->pdata->i2c_pull_up) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1636 | reg_set_optimum_mode_check(data->vcc_i2c, MXT_I2C_LOAD_UA); |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1637 | |
| 1638 | return rc; |
| 1639 | |
| 1640 | fail_regulator_hpm: |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1641 | reg_set_optimum_mode_check(data->vcc_ana, MXT_LPM_LOAD_UA); |
Amy Maloche | 21115eb | 2011-11-02 09:04:37 -0700 | [diff] [blame] | 1642 | if (data->pdata->digital_pwr_regulator) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1643 | 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] | 1644 | if (data->pdata->i2c_pull_up) |
Amy Maloche | c331f84 | 2012-01-24 10:33:47 -0800 | [diff] [blame^] | 1645 | 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] | 1646 | |
| 1647 | return rc; |
| 1648 | } |
| 1649 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1650 | static int mxt_suspend(struct device *dev) |
| 1651 | { |
| 1652 | struct i2c_client *client = to_i2c_client(dev); |
| 1653 | struct mxt_data *data = i2c_get_clientdata(client); |
| 1654 | struct input_dev *input_dev = data->input_dev; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1655 | int error; |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1656 | |
| 1657 | mutex_lock(&input_dev->mutex); |
| 1658 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1659 | if (input_dev->users) { |
| 1660 | error = mxt_stop(data); |
| 1661 | if (error < 0) { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1662 | dev_err(dev, "mxt_stop failed in suspend\n"); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1663 | mutex_unlock(&input_dev->mutex); |
| 1664 | return error; |
| 1665 | } |
| 1666 | |
| 1667 | } |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1668 | |
| 1669 | mutex_unlock(&input_dev->mutex); |
| 1670 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1671 | /* put regulators in low power mode */ |
| 1672 | error = mxt_regulator_lpm(data, true); |
| 1673 | if (error < 0) { |
| 1674 | dev_err(dev, "failed to enter low power mode\n"); |
| 1675 | return error; |
| 1676 | } |
| 1677 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1678 | return 0; |
| 1679 | } |
| 1680 | |
| 1681 | static int mxt_resume(struct device *dev) |
| 1682 | { |
| 1683 | struct i2c_client *client = to_i2c_client(dev); |
| 1684 | struct mxt_data *data = i2c_get_clientdata(client); |
| 1685 | struct input_dev *input_dev = data->input_dev; |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1686 | int error; |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1687 | |
Jing Lin | bace50b | 2011-10-18 22:55:47 -0700 | [diff] [blame] | 1688 | /* put regulators in high power mode */ |
| 1689 | error = mxt_regulator_lpm(data, false); |
| 1690 | if (error < 0) { |
| 1691 | dev_err(dev, "failed to enter high power mode\n"); |
| 1692 | return error; |
| 1693 | } |
| 1694 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1695 | mutex_lock(&input_dev->mutex); |
| 1696 | |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1697 | if (input_dev->users) { |
| 1698 | error = mxt_start(data); |
| 1699 | if (error < 0) { |
Jing Lin | 36aee81 | 2011-10-17 17:17:28 -0700 | [diff] [blame] | 1700 | dev_err(dev, "mxt_start failed in resume\n"); |
Amy Maloche | 5226221 | 2011-09-15 16:46:57 -0700 | [diff] [blame] | 1701 | mutex_unlock(&input_dev->mutex); |
| 1702 | return error; |
| 1703 | } |
| 1704 | } |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1705 | |
| 1706 | mutex_unlock(&input_dev->mutex); |
| 1707 | |
| 1708 | return 0; |
| 1709 | } |
| 1710 | |
| 1711 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 1712 | static void mxt_early_suspend(struct early_suspend *h) |
| 1713 | { |
| 1714 | struct mxt_data *data = container_of(h, struct mxt_data, early_suspend); |
| 1715 | |
| 1716 | mxt_suspend(&data->client->dev); |
| 1717 | } |
| 1718 | |
| 1719 | static void mxt_late_resume(struct early_suspend *h) |
| 1720 | { |
| 1721 | struct mxt_data *data = container_of(h, struct mxt_data, early_suspend); |
| 1722 | |
| 1723 | mxt_resume(&data->client->dev); |
| 1724 | } |
| 1725 | #endif |
| 1726 | |
| 1727 | static const struct dev_pm_ops mxt_pm_ops = { |
| 1728 | #ifndef CONFIG_HAS_EARLYSUSPEND |
| 1729 | .suspend = mxt_suspend, |
| 1730 | .resume = mxt_resume, |
| 1731 | #endif |
| 1732 | }; |
| 1733 | #endif |
| 1734 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 1735 | static int mxt_debugfs_object_show(struct seq_file *m, void *v) |
| 1736 | { |
| 1737 | struct mxt_data *data = m->private; |
| 1738 | struct mxt_object *object; |
| 1739 | struct device *dev = &data->client->dev; |
| 1740 | int i, j, k; |
| 1741 | int error; |
| 1742 | int obj_size; |
| 1743 | u8 val; |
| 1744 | |
| 1745 | for (i = 0; i < data->info.object_num; i++) { |
| 1746 | object = data->object_table + i; |
| 1747 | obj_size = object->size + 1; |
| 1748 | |
| 1749 | seq_printf(m, "Object[%d] (Type %d)\n", i + 1, object->type); |
| 1750 | |
| 1751 | for (j = 0; j < object->instances + 1; j++) { |
| 1752 | seq_printf(m, "[Instance %d]\n", j); |
| 1753 | |
| 1754 | for (k = 0; k < obj_size; k++) { |
| 1755 | error = mxt_read_object(data, object->type, |
| 1756 | j * obj_size + k, &val); |
| 1757 | if (error) { |
| 1758 | dev_err(dev, |
| 1759 | "Failed to read object %d " |
| 1760 | "instance %d at offset %d\n", |
| 1761 | object->type, j, k); |
| 1762 | return error; |
| 1763 | } |
| 1764 | |
| 1765 | seq_printf(m, "Byte %d: 0x%02x (%d)\n", |
| 1766 | k, val, val); |
| 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | return 0; |
| 1772 | } |
| 1773 | |
| 1774 | static int mxt_debugfs_object_open(struct inode *inode, struct file *file) |
| 1775 | { |
| 1776 | return single_open(file, mxt_debugfs_object_show, inode->i_private); |
| 1777 | } |
| 1778 | |
| 1779 | static const struct file_operations mxt_object_fops = { |
| 1780 | .owner = THIS_MODULE, |
| 1781 | .open = mxt_debugfs_object_open, |
| 1782 | .read = seq_read, |
| 1783 | .release = single_release, |
| 1784 | }; |
| 1785 | |
| 1786 | static void __init mxt_debugfs_init(struct mxt_data *data) |
| 1787 | { |
| 1788 | debug_base = debugfs_create_dir(MXT_DEBUGFS_DIR, NULL); |
| 1789 | if (IS_ERR_OR_NULL(debug_base)) |
| 1790 | pr_err("atmel_mxt_ts: Failed to create debugfs dir\n"); |
| 1791 | if (IS_ERR_OR_NULL(debugfs_create_file(MXT_DEBUGFS_FILE, |
| 1792 | 0444, |
| 1793 | debug_base, |
| 1794 | data, |
| 1795 | &mxt_object_fops))) { |
| 1796 | pr_err("atmel_mxt_ts: Failed to create object file\n"); |
| 1797 | debugfs_remove_recursive(debug_base); |
| 1798 | } |
| 1799 | } |
| 1800 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1801 | static int __devinit mxt_probe(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1802 | const struct i2c_device_id *id) |
| 1803 | { |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1804 | const struct mxt_platform_data *pdata = client->dev.platform_data; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1805 | struct mxt_data *data; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1806 | struct input_dev *input_dev; |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1807 | int error, i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1808 | |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1809 | if (!pdata) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1810 | return -EINVAL; |
| 1811 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1812 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1813 | input_dev = input_allocate_device(); |
| 1814 | if (!data || !input_dev) { |
| 1815 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 1816 | error = -ENOMEM; |
| 1817 | goto err_free_mem; |
| 1818 | } |
| 1819 | |
Amy Maloche | 83c385a | 2012-02-01 10:32:03 +0530 | [diff] [blame] | 1820 | input_dev->name = "atmel_mxt_ts"; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1821 | input_dev->id.bustype = BUS_I2C; |
| 1822 | input_dev->dev.parent = &client->dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1823 | input_dev->open = mxt_input_open; |
| 1824 | input_dev->close = mxt_input_close; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1825 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1826 | data->client = client; |
| 1827 | data->input_dev = input_dev; |
| 1828 | data->pdata = pdata; |
| 1829 | data->irq = client->irq; |
| 1830 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1831 | __set_bit(EV_ABS, input_dev->evbit); |
| 1832 | __set_bit(EV_KEY, input_dev->evbit); |
| 1833 | __set_bit(BTN_TOUCH, input_dev->keybit); |
| 1834 | |
| 1835 | /* For single touch */ |
| 1836 | input_set_abs_params(input_dev, ABS_X, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame] | 1837 | 0, data->pdata->x_size, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1838 | input_set_abs_params(input_dev, ABS_Y, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame] | 1839 | 0, data->pdata->y_size, 0, 0); |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 1840 | input_set_abs_params(input_dev, ABS_PRESSURE, |
| 1841 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1842 | |
| 1843 | /* For multi touch */ |
| 1844 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1845 | 0, MXT_MAX_AREA, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1846 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame] | 1847 | 0, data->pdata->x_size, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1848 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, |
Jing Lin | 2f86317 | 2011-10-17 10:56:58 -0700 | [diff] [blame] | 1849 | 0, data->pdata->y_size, 0, 0); |
Yufeng Shen | e6eb36a | 2011-10-11 12:28:21 -0700 | [diff] [blame] | 1850 | input_set_abs_params(input_dev, ABS_MT_PRESSURE, |
| 1851 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1852 | |
Amy Maloche | 83c385a | 2012-02-01 10:32:03 +0530 | [diff] [blame] | 1853 | if (pdata->touch_x_size) |
| 1854 | data->touch_x_size = pdata->touch_x_size; |
| 1855 | else |
| 1856 | data->touch_x_size = pdata->x_size; |
| 1857 | |
| 1858 | if (pdata->touch_y_size) |
| 1859 | data->touch_y_size = pdata->touch_y_size; |
| 1860 | else |
| 1861 | data->touch_y_size = pdata->y_size; |
| 1862 | |
Mohan Pallaka | 382d3ce | 2012-01-02 20:24:28 +0800 | [diff] [blame] | 1863 | /* set key array supported keys */ |
| 1864 | if (pdata->key_codes) { |
| 1865 | for (i = 0; i < MXT_KEYARRAY_MAX_KEYS; i++) { |
| 1866 | if (pdata->key_codes[i]) |
| 1867 | input_set_capability(input_dev, EV_KEY, |
| 1868 | pdata->key_codes[i]); |
| 1869 | } |
| 1870 | } |
| 1871 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1872 | input_set_drvdata(input_dev, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1873 | i2c_set_clientdata(client, data); |
| 1874 | |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1875 | if (pdata->init_hw) |
| 1876 | error = pdata->init_hw(true); |
| 1877 | else |
| 1878 | error = mxt_regulator_configure(data, true); |
| 1879 | if (error) { |
| 1880 | dev_err(&client->dev, "Failed to intialize hardware\n"); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1881 | goto err_free_mem; |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | if (pdata->power_on) |
| 1885 | error = pdata->power_on(true); |
| 1886 | else |
| 1887 | error = mxt_power_on(data, true); |
| 1888 | if (error) { |
| 1889 | dev_err(&client->dev, "Failed to power on hardware\n"); |
| 1890 | goto err_regulator_on; |
| 1891 | } |
| 1892 | |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 1893 | if (gpio_is_valid(pdata->irq_gpio)) { |
| 1894 | /* configure touchscreen irq gpio */ |
| 1895 | error = gpio_request(pdata->irq_gpio, |
| 1896 | "mxt_irq_gpio"); |
| 1897 | if (error) { |
| 1898 | pr_err("%s: unable to request gpio [%d]\n", __func__, |
| 1899 | pdata->irq_gpio); |
| 1900 | goto err_power_on; |
| 1901 | } |
| 1902 | error = gpio_direction_input(pdata->irq_gpio); |
| 1903 | if (error) { |
| 1904 | pr_err("%s: unable to set_direction for gpio [%d]\n", |
| 1905 | __func__, pdata->irq_gpio); |
| 1906 | goto err_irq_gpio_req; |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | if (gpio_is_valid(pdata->reset_gpio)) { |
| 1911 | /* configure touchscreen reset out gpio */ |
| 1912 | error = gpio_request(pdata->reset_gpio, |
| 1913 | "mxt_reset_gpio"); |
| 1914 | if (error) { |
| 1915 | pr_err("%s: unable to request reset gpio %d\n", |
| 1916 | __func__, pdata->reset_gpio); |
| 1917 | goto err_irq_gpio_req; |
| 1918 | } |
| 1919 | |
| 1920 | error = gpio_direction_output( |
| 1921 | pdata->reset_gpio, 1); |
| 1922 | if (error) { |
| 1923 | pr_err("%s: unable to set direction for gpio %d\n", |
| 1924 | __func__, pdata->reset_gpio); |
| 1925 | goto err_reset_gpio_req; |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | mxt_reset_delay(data); |
| 1930 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1931 | error = mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1932 | if (error) |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 1933 | goto err_reset_gpio_req; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1934 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1935 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1936 | pdata->irqflags, client->dev.driver->name, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1937 | if (error) { |
| 1938 | dev_err(&client->dev, "Failed to register interrupt\n"); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1939 | goto err_free_object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1942 | error = mxt_make_highchg(data); |
| 1943 | if (error) |
| 1944 | goto err_free_irq; |
| 1945 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1946 | error = input_register_device(input_dev); |
| 1947 | if (error) |
| 1948 | goto err_free_irq; |
| 1949 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1950 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1951 | if (error) |
| 1952 | goto err_unregister_device; |
| 1953 | |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 1954 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 1955 | data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + |
| 1956 | MXT_SUSPEND_LEVEL; |
| 1957 | data->early_suspend.suspend = mxt_early_suspend; |
| 1958 | data->early_suspend.resume = mxt_late_resume; |
| 1959 | register_early_suspend(&data->early_suspend); |
| 1960 | #endif |
| 1961 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 1962 | mxt_debugfs_init(data); |
| 1963 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1964 | return 0; |
| 1965 | |
| 1966 | err_unregister_device: |
| 1967 | input_unregister_device(input_dev); |
| 1968 | input_dev = NULL; |
| 1969 | err_free_irq: |
| 1970 | free_irq(client->irq, data); |
Jing Lin | 32c7253 | 2011-11-03 12:02:33 -0700 | [diff] [blame] | 1971 | err_free_object: |
| 1972 | kfree(data->object_table); |
Amy Maloche | 08266db | 2011-11-04 11:07:16 -0700 | [diff] [blame] | 1973 | err_reset_gpio_req: |
| 1974 | if (gpio_is_valid(pdata->reset_gpio)) |
| 1975 | gpio_free(pdata->reset_gpio); |
| 1976 | err_irq_gpio_req: |
| 1977 | if (gpio_is_valid(pdata->irq_gpio)) |
| 1978 | gpio_free(pdata->irq_gpio); |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 1979 | err_power_on: |
| 1980 | if (pdata->power_on) |
| 1981 | pdata->power_on(false); |
| 1982 | else |
| 1983 | mxt_power_on(data, false); |
| 1984 | err_regulator_on: |
| 1985 | if (pdata->init_hw) |
| 1986 | pdata->init_hw(false); |
| 1987 | else |
| 1988 | mxt_regulator_configure(data, false); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1989 | err_free_mem: |
| 1990 | input_free_device(input_dev); |
| 1991 | kfree(data); |
| 1992 | return error; |
| 1993 | } |
| 1994 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1995 | static int __devexit mxt_remove(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1996 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1997 | struct mxt_data *data = i2c_get_clientdata(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 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2000 | free_irq(data->irq, data); |
| 2001 | input_unregister_device(data->input_dev); |
Anirudh Ghayal | 253ce12 | 2011-08-09 19:32:57 +0530 | [diff] [blame] | 2002 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
| 2003 | unregister_early_suspend(&data->early_suspend); |
| 2004 | #endif |
Anirudh Ghayal | a498e4d | 2011-08-09 19:10:12 +0530 | [diff] [blame] | 2005 | |
| 2006 | if (data->pdata->power_on) |
| 2007 | data->pdata->power_on(false); |
| 2008 | else |
| 2009 | mxt_power_on(data, false); |
| 2010 | |
| 2011 | if (data->pdata->init_hw) |
| 2012 | data->pdata->init_hw(false); |
| 2013 | else |
| 2014 | mxt_regulator_configure(data, false); |
| 2015 | |
Mohan Pallaka | bfe8f30 | 2012-01-02 18:32:08 +0800 | [diff] [blame] | 2016 | if (gpio_is_valid(data->pdata->reset_gpio)) |
| 2017 | gpio_free(data->pdata->reset_gpio); |
| 2018 | |
| 2019 | if (gpio_is_valid(data->pdata->irq_gpio)) |
| 2020 | gpio_free(data->pdata->irq_gpio); |
| 2021 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2022 | kfree(data->object_table); |
| 2023 | kfree(data); |
| 2024 | |
Jing Lin | 6cfc00e | 2011-11-02 15:15:30 -0700 | [diff] [blame] | 2025 | debugfs_remove_recursive(debug_base); |
| 2026 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2027 | return 0; |
| 2028 | } |
| 2029 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2030 | static const struct i2c_device_id mxt_id[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2031 | { "qt602240_ts", 0 }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2032 | { "atmel_mxt_ts", 0 }, |
Chris Leech | 46ee2a0 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 2033 | { "mXT224", 0 }, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2034 | { } |
| 2035 | }; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2036 | MODULE_DEVICE_TABLE(i2c, mxt_id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2037 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2038 | static struct i2c_driver mxt_driver = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2039 | .driver = { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2040 | .name = "atmel_mxt_ts", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2041 | .owner = THIS_MODULE, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 2042 | #ifdef CONFIG_PM |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2043 | .pm = &mxt_pm_ops, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 2044 | #endif |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2045 | }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2046 | .probe = mxt_probe, |
| 2047 | .remove = __devexit_p(mxt_remove), |
| 2048 | .id_table = mxt_id, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2049 | }; |
| 2050 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2051 | static int __init mxt_init(void) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2052 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2053 | return i2c_add_driver(&mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2056 | static void __exit mxt_exit(void) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2057 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2058 | i2c_del_driver(&mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2059 | } |
| 2060 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2061 | module_init(mxt_init); |
| 2062 | module_exit(mxt_exit); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2063 | |
| 2064 | /* Module information */ |
| 2065 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2066 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2067 | MODULE_LICENSE("GPL"); |