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