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