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