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