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