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