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