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