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