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