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> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/firmware.h> |
| 18 | #include <linux/i2c.h> |
Dmitry Torokhov | 964de52 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 19 | #include <linux/i2c/atmel_mxt_ts.h> |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 20 | #include <linux/input/mt.h> |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/slab.h> |
| 23 | |
| 24 | /* Version */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 25 | #define MXT_VER_20 20 |
| 26 | #define MXT_VER_21 21 |
| 27 | #define MXT_VER_22 22 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 28 | |
| 29 | /* Slave addresses */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 30 | #define MXT_APP_LOW 0x4a |
| 31 | #define MXT_APP_HIGH 0x4b |
| 32 | #define MXT_BOOT_LOW 0x24 |
| 33 | #define MXT_BOOT_HIGH 0x25 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 34 | |
| 35 | /* Firmware */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 36 | #define MXT_FW_NAME "maxtouch.fw" |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 37 | |
| 38 | /* Registers */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 39 | #define MXT_FAMILY_ID 0x00 |
| 40 | #define MXT_VARIANT_ID 0x01 |
| 41 | #define MXT_VERSION 0x02 |
| 42 | #define MXT_BUILD 0x03 |
| 43 | #define MXT_MATRIX_X_SIZE 0x04 |
| 44 | #define MXT_MATRIX_Y_SIZE 0x05 |
| 45 | #define MXT_OBJECT_NUM 0x06 |
| 46 | #define MXT_OBJECT_START 0x07 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 47 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 48 | #define MXT_OBJECT_SIZE 6 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 49 | |
| 50 | /* Object types */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 51 | #define MXT_DEBUG_DIAGNOSTIC_T37 37 |
| 52 | #define MXT_GEN_MESSAGE_T5 5 |
| 53 | #define MXT_GEN_COMMAND_T6 6 |
| 54 | #define MXT_GEN_POWER_T7 7 |
| 55 | #define MXT_GEN_ACQUIRE_T8 8 |
| 56 | #define MXT_GEN_DATASOURCE_T53 53 |
| 57 | #define MXT_TOUCH_MULTI_T9 9 |
| 58 | #define MXT_TOUCH_KEYARRAY_T15 15 |
| 59 | #define MXT_TOUCH_PROXIMITY_T23 23 |
| 60 | #define MXT_TOUCH_PROXKEY_T52 52 |
| 61 | #define MXT_PROCI_GRIPFACE_T20 20 |
| 62 | #define MXT_PROCG_NOISE_T22 22 |
| 63 | #define MXT_PROCI_ONETOUCH_T24 24 |
| 64 | #define MXT_PROCI_TWOTOUCH_T27 27 |
| 65 | #define MXT_PROCI_GRIP_T40 40 |
| 66 | #define MXT_PROCI_PALM_T41 41 |
| 67 | #define MXT_PROCI_TOUCHSUPPRESSION_T42 42 |
| 68 | #define MXT_PROCI_STYLUS_T47 47 |
| 69 | #define MXT_PROCG_NOISESUPPRESSION_T48 48 |
| 70 | #define MXT_SPT_COMMSCONFIG_T18 18 |
| 71 | #define MXT_SPT_GPIOPWM_T19 19 |
| 72 | #define MXT_SPT_SELFTEST_T25 25 |
| 73 | #define MXT_SPT_CTECONFIG_T28 28 |
| 74 | #define MXT_SPT_USERDATA_T38 38 |
| 75 | #define MXT_SPT_DIGITIZER_T43 43 |
| 76 | #define MXT_SPT_MESSAGECOUNT_T44 44 |
| 77 | #define MXT_SPT_CTECONFIG_T46 46 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 78 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 79 | /* MXT_GEN_COMMAND_T6 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 80 | #define MXT_COMMAND_RESET 0 |
| 81 | #define MXT_COMMAND_BACKUPNV 1 |
| 82 | #define MXT_COMMAND_CALIBRATE 2 |
| 83 | #define MXT_COMMAND_REPORTALL 3 |
| 84 | #define MXT_COMMAND_DIAGNOSTIC 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 85 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 86 | /* MXT_GEN_POWER_T7 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 87 | #define MXT_POWER_IDLEACQINT 0 |
| 88 | #define MXT_POWER_ACTVACQINT 1 |
| 89 | #define MXT_POWER_ACTV2IDLETO 2 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 90 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 91 | /* MXT_GEN_ACQUIRE_T8 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 92 | #define MXT_ACQUIRE_CHRGTIME 0 |
| 93 | #define MXT_ACQUIRE_TCHDRIFT 2 |
| 94 | #define MXT_ACQUIRE_DRIFTST 3 |
| 95 | #define MXT_ACQUIRE_TCHAUTOCAL 4 |
| 96 | #define MXT_ACQUIRE_SYNC 5 |
| 97 | #define MXT_ACQUIRE_ATCHCALST 6 |
| 98 | #define MXT_ACQUIRE_ATCHCALSTHR 7 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 99 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 100 | /* MXT_TOUCH_MULTI_T9 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 101 | #define MXT_TOUCH_CTRL 0 |
| 102 | #define MXT_TOUCH_XORIGIN 1 |
| 103 | #define MXT_TOUCH_YORIGIN 2 |
| 104 | #define MXT_TOUCH_XSIZE 3 |
| 105 | #define MXT_TOUCH_YSIZE 4 |
| 106 | #define MXT_TOUCH_BLEN 6 |
| 107 | #define MXT_TOUCH_TCHTHR 7 |
| 108 | #define MXT_TOUCH_TCHDI 8 |
| 109 | #define MXT_TOUCH_ORIENT 9 |
| 110 | #define MXT_TOUCH_MOVHYSTI 11 |
| 111 | #define MXT_TOUCH_MOVHYSTN 12 |
| 112 | #define MXT_TOUCH_NUMTOUCH 14 |
| 113 | #define MXT_TOUCH_MRGHYST 15 |
| 114 | #define MXT_TOUCH_MRGTHR 16 |
| 115 | #define MXT_TOUCH_AMPHYST 17 |
| 116 | #define MXT_TOUCH_XRANGE_LSB 18 |
| 117 | #define MXT_TOUCH_XRANGE_MSB 19 |
| 118 | #define MXT_TOUCH_YRANGE_LSB 20 |
| 119 | #define MXT_TOUCH_YRANGE_MSB 21 |
| 120 | #define MXT_TOUCH_XLOCLIP 22 |
| 121 | #define MXT_TOUCH_XHICLIP 23 |
| 122 | #define MXT_TOUCH_YLOCLIP 24 |
| 123 | #define MXT_TOUCH_YHICLIP 25 |
| 124 | #define MXT_TOUCH_XEDGECTRL 26 |
| 125 | #define MXT_TOUCH_XEDGEDIST 27 |
| 126 | #define MXT_TOUCH_YEDGECTRL 28 |
| 127 | #define MXT_TOUCH_YEDGEDIST 29 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 128 | #define MXT_TOUCH_JUMPLIMIT 30 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 129 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 130 | /* MXT_PROCI_GRIPFACE_T20 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 131 | #define MXT_GRIPFACE_CTRL 0 |
| 132 | #define MXT_GRIPFACE_XLOGRIP 1 |
| 133 | #define MXT_GRIPFACE_XHIGRIP 2 |
| 134 | #define MXT_GRIPFACE_YLOGRIP 3 |
| 135 | #define MXT_GRIPFACE_YHIGRIP 4 |
| 136 | #define MXT_GRIPFACE_MAXTCHS 5 |
| 137 | #define MXT_GRIPFACE_SZTHR1 7 |
| 138 | #define MXT_GRIPFACE_SZTHR2 8 |
| 139 | #define MXT_GRIPFACE_SHPTHR1 9 |
| 140 | #define MXT_GRIPFACE_SHPTHR2 10 |
| 141 | #define MXT_GRIPFACE_SUPEXTTO 11 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 142 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 143 | /* MXT_PROCI_NOISE field */ |
| 144 | #define MXT_NOISE_CTRL 0 |
| 145 | #define MXT_NOISE_OUTFLEN 1 |
| 146 | #define MXT_NOISE_GCAFUL_LSB 3 |
| 147 | #define MXT_NOISE_GCAFUL_MSB 4 |
| 148 | #define MXT_NOISE_GCAFLL_LSB 5 |
| 149 | #define MXT_NOISE_GCAFLL_MSB 6 |
| 150 | #define MXT_NOISE_ACTVGCAFVALID 7 |
| 151 | #define MXT_NOISE_NOISETHR 8 |
| 152 | #define MXT_NOISE_FREQHOPSCALE 10 |
| 153 | #define MXT_NOISE_FREQ0 11 |
| 154 | #define MXT_NOISE_FREQ1 12 |
| 155 | #define MXT_NOISE_FREQ2 13 |
| 156 | #define MXT_NOISE_FREQ3 14 |
| 157 | #define MXT_NOISE_FREQ4 15 |
| 158 | #define MXT_NOISE_IDLEGCAFVALID 16 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 159 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 160 | /* MXT_SPT_COMMSCONFIG_T18 */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 161 | #define MXT_COMMS_CTRL 0 |
| 162 | #define MXT_COMMS_CMD 1 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 163 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 164 | /* MXT_SPT_CTECONFIG_T28 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 165 | #define MXT_CTE_CTRL 0 |
| 166 | #define MXT_CTE_CMD 1 |
| 167 | #define MXT_CTE_MODE 2 |
| 168 | #define MXT_CTE_IDLEGCAFDEPTH 3 |
| 169 | #define MXT_CTE_ACTVGCAFDEPTH 4 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 170 | #define MXT_CTE_VOLTAGE 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 171 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 172 | #define MXT_VOLTAGE_DEFAULT 2700000 |
| 173 | #define MXT_VOLTAGE_STEP 10000 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 174 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 175 | /* Define for MXT_GEN_COMMAND_T6 */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 176 | #define MXT_BOOT_VALUE 0xa5 |
| 177 | #define MXT_BACKUP_VALUE 0x55 |
| 178 | #define MXT_BACKUP_TIME 25 /* msec */ |
| 179 | #define MXT_RESET_TIME 65 /* msec */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 180 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 181 | #define MXT_FWRESET_TIME 175 /* msec */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 182 | |
| 183 | /* Command to unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 184 | #define MXT_UNLOCK_CMD_MSB 0xaa |
| 185 | #define MXT_UNLOCK_CMD_LSB 0xdc |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 186 | |
| 187 | /* Bootloader mode status */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 188 | #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */ |
| 189 | #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */ |
| 190 | #define MXT_FRAME_CRC_CHECK 0x02 |
| 191 | #define MXT_FRAME_CRC_FAIL 0x03 |
| 192 | #define MXT_FRAME_CRC_PASS 0x04 |
| 193 | #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */ |
| 194 | #define MXT_BOOT_STATUS_MASK 0x3f |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 195 | |
| 196 | /* Touch status */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 197 | #define MXT_SUPPRESS (1 << 1) |
| 198 | #define MXT_AMP (1 << 2) |
| 199 | #define MXT_VECTOR (1 << 3) |
| 200 | #define MXT_MOVE (1 << 4) |
| 201 | #define MXT_RELEASE (1 << 5) |
| 202 | #define MXT_PRESS (1 << 6) |
| 203 | #define MXT_DETECT (1 << 7) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 204 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 205 | /* Touch orient bits */ |
| 206 | #define MXT_XY_SWITCH (1 << 0) |
| 207 | #define MXT_X_INVERT (1 << 1) |
| 208 | #define MXT_Y_INVERT (1 << 2) |
| 209 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 210 | /* Touchscreen absolute values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 211 | #define MXT_MAX_AREA 0xff |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 212 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 213 | #define MXT_MAX_FINGER 10 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 214 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 215 | struct mxt_info { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 216 | u8 family_id; |
| 217 | u8 variant_id; |
| 218 | u8 version; |
| 219 | u8 build; |
| 220 | u8 matrix_xsize; |
| 221 | u8 matrix_ysize; |
| 222 | u8 object_num; |
| 223 | }; |
| 224 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 225 | struct mxt_object { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 226 | u8 type; |
| 227 | u16 start_address; |
| 228 | u8 size; |
| 229 | u8 instances; |
| 230 | u8 num_report_ids; |
| 231 | |
| 232 | /* to map object and message */ |
| 233 | u8 max_reportid; |
| 234 | }; |
| 235 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 236 | struct mxt_message { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 237 | u8 reportid; |
| 238 | u8 message[7]; |
| 239 | u8 checksum; |
| 240 | }; |
| 241 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 242 | struct mxt_finger { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 243 | int status; |
| 244 | int x; |
| 245 | int y; |
| 246 | int area; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame^] | 247 | int pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | /* Each client has this additional data */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 251 | struct mxt_data { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 252 | struct i2c_client *client; |
| 253 | struct input_dev *input_dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 254 | const struct mxt_platform_data *pdata; |
| 255 | struct mxt_object *object_table; |
| 256 | struct mxt_info info; |
| 257 | struct mxt_finger finger[MXT_MAX_FINGER]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 258 | unsigned int irq; |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 259 | unsigned int max_x; |
| 260 | unsigned int max_y; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 261 | }; |
| 262 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 263 | static bool mxt_object_readable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 264 | { |
| 265 | switch (type) { |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 266 | case MXT_GEN_MESSAGE_T5: |
| 267 | case MXT_GEN_COMMAND_T6: |
| 268 | case MXT_GEN_POWER_T7: |
| 269 | case MXT_GEN_ACQUIRE_T8: |
| 270 | case MXT_GEN_DATASOURCE_T53: |
| 271 | case MXT_TOUCH_MULTI_T9: |
| 272 | case MXT_TOUCH_KEYARRAY_T15: |
| 273 | case MXT_TOUCH_PROXIMITY_T23: |
| 274 | case MXT_TOUCH_PROXKEY_T52: |
| 275 | case MXT_PROCI_GRIPFACE_T20: |
| 276 | case MXT_PROCG_NOISE_T22: |
| 277 | case MXT_PROCI_ONETOUCH_T24: |
| 278 | case MXT_PROCI_TWOTOUCH_T27: |
| 279 | case MXT_PROCI_GRIP_T40: |
| 280 | case MXT_PROCI_PALM_T41: |
| 281 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 282 | case MXT_PROCI_STYLUS_T47: |
| 283 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 284 | case MXT_SPT_COMMSCONFIG_T18: |
| 285 | case MXT_SPT_GPIOPWM_T19: |
| 286 | case MXT_SPT_SELFTEST_T25: |
| 287 | case MXT_SPT_CTECONFIG_T28: |
| 288 | case MXT_SPT_USERDATA_T38: |
| 289 | case MXT_SPT_DIGITIZER_T43: |
| 290 | case MXT_SPT_CTECONFIG_T46: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 291 | return true; |
| 292 | default: |
| 293 | return false; |
| 294 | } |
| 295 | } |
| 296 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 297 | static bool mxt_object_writable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 298 | { |
| 299 | switch (type) { |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 300 | case MXT_GEN_COMMAND_T6: |
| 301 | case MXT_GEN_POWER_T7: |
| 302 | case MXT_GEN_ACQUIRE_T8: |
| 303 | case MXT_TOUCH_MULTI_T9: |
| 304 | case MXT_TOUCH_KEYARRAY_T15: |
| 305 | case MXT_TOUCH_PROXIMITY_T23: |
| 306 | case MXT_TOUCH_PROXKEY_T52: |
| 307 | case MXT_PROCI_GRIPFACE_T20: |
| 308 | case MXT_PROCG_NOISE_T22: |
| 309 | case MXT_PROCI_ONETOUCH_T24: |
| 310 | case MXT_PROCI_TWOTOUCH_T27: |
| 311 | case MXT_PROCI_GRIP_T40: |
| 312 | case MXT_PROCI_PALM_T41: |
| 313 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 314 | case MXT_PROCI_STYLUS_T47: |
| 315 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 316 | case MXT_SPT_COMMSCONFIG_T18: |
| 317 | case MXT_SPT_GPIOPWM_T19: |
| 318 | case MXT_SPT_SELFTEST_T25: |
| 319 | case MXT_SPT_CTECONFIG_T28: |
| 320 | case MXT_SPT_DIGITIZER_T43: |
| 321 | case MXT_SPT_CTECONFIG_T46: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 322 | return true; |
| 323 | default: |
| 324 | return false; |
| 325 | } |
| 326 | } |
| 327 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 328 | static void mxt_dump_message(struct device *dev, |
| 329 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 330 | { |
| 331 | dev_dbg(dev, "reportid:\t0x%x\n", message->reportid); |
| 332 | dev_dbg(dev, "message1:\t0x%x\n", message->message[0]); |
| 333 | dev_dbg(dev, "message2:\t0x%x\n", message->message[1]); |
| 334 | dev_dbg(dev, "message3:\t0x%x\n", message->message[2]); |
| 335 | dev_dbg(dev, "message4:\t0x%x\n", message->message[3]); |
| 336 | dev_dbg(dev, "message5:\t0x%x\n", message->message[4]); |
| 337 | dev_dbg(dev, "message6:\t0x%x\n", message->message[5]); |
| 338 | dev_dbg(dev, "message7:\t0x%x\n", message->message[6]); |
| 339 | dev_dbg(dev, "checksum:\t0x%x\n", message->checksum); |
| 340 | } |
| 341 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 342 | static int mxt_check_bootloader(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 343 | unsigned int state) |
| 344 | { |
| 345 | u8 val; |
| 346 | |
| 347 | recheck: |
| 348 | if (i2c_master_recv(client, &val, 1) != 1) { |
| 349 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); |
| 350 | return -EIO; |
| 351 | } |
| 352 | |
| 353 | switch (state) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 354 | case MXT_WAITING_BOOTLOAD_CMD: |
| 355 | case MXT_WAITING_FRAME_DATA: |
| 356 | val &= ~MXT_BOOT_STATUS_MASK; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 357 | break; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 358 | case MXT_FRAME_CRC_PASS: |
| 359 | if (val == MXT_FRAME_CRC_CHECK) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 360 | goto recheck; |
| 361 | break; |
| 362 | default: |
| 363 | return -EINVAL; |
| 364 | } |
| 365 | |
| 366 | if (val != state) { |
| 367 | dev_err(&client->dev, "Unvalid bootloader mode state\n"); |
| 368 | return -EINVAL; |
| 369 | } |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 374 | static int mxt_unlock_bootloader(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 375 | { |
| 376 | u8 buf[2]; |
| 377 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 378 | buf[0] = MXT_UNLOCK_CMD_LSB; |
| 379 | buf[1] = MXT_UNLOCK_CMD_MSB; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 380 | |
| 381 | if (i2c_master_send(client, buf, 2) != 2) { |
| 382 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 383 | return -EIO; |
| 384 | } |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 389 | static int mxt_fw_write(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 390 | const u8 *data, unsigned int frame_size) |
| 391 | { |
| 392 | if (i2c_master_send(client, data, frame_size) != frame_size) { |
| 393 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 394 | return -EIO; |
| 395 | } |
| 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 400 | static int __mxt_read_reg(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 401 | u16 reg, u16 len, void *val) |
| 402 | { |
| 403 | struct i2c_msg xfer[2]; |
| 404 | u8 buf[2]; |
| 405 | |
| 406 | buf[0] = reg & 0xff; |
| 407 | buf[1] = (reg >> 8) & 0xff; |
| 408 | |
| 409 | /* Write register */ |
| 410 | xfer[0].addr = client->addr; |
| 411 | xfer[0].flags = 0; |
| 412 | xfer[0].len = 2; |
| 413 | xfer[0].buf = buf; |
| 414 | |
| 415 | /* Read data */ |
| 416 | xfer[1].addr = client->addr; |
| 417 | xfer[1].flags = I2C_M_RD; |
| 418 | xfer[1].len = len; |
| 419 | xfer[1].buf = val; |
| 420 | |
| 421 | if (i2c_transfer(client->adapter, xfer, 2) != 2) { |
| 422 | dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); |
| 423 | return -EIO; |
| 424 | } |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 429 | 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] | 430 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 431 | return __mxt_read_reg(client, reg, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 434 | 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] | 435 | { |
| 436 | u8 buf[3]; |
| 437 | |
| 438 | buf[0] = reg & 0xff; |
| 439 | buf[1] = (reg >> 8) & 0xff; |
| 440 | buf[2] = val; |
| 441 | |
| 442 | if (i2c_master_send(client, buf, 3) != 3) { |
| 443 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 444 | return -EIO; |
| 445 | } |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 450 | static int mxt_read_object_table(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 451 | u16 reg, u8 *object_buf) |
| 452 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 453 | return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 454 | object_buf); |
| 455 | } |
| 456 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 457 | static struct mxt_object * |
| 458 | mxt_get_object(struct mxt_data *data, u8 type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 459 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 460 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 461 | int i; |
| 462 | |
| 463 | for (i = 0; i < data->info.object_num; i++) { |
| 464 | object = data->object_table + i; |
| 465 | if (object->type == type) |
| 466 | return object; |
| 467 | } |
| 468 | |
| 469 | dev_err(&data->client->dev, "Invalid object type\n"); |
| 470 | return NULL; |
| 471 | } |
| 472 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 473 | static int mxt_read_message(struct mxt_data *data, |
| 474 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 475 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 476 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 477 | u16 reg; |
| 478 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 479 | object = mxt_get_object(data, MXT_GEN_MESSAGE_T5); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 480 | if (!object) |
| 481 | return -EINVAL; |
| 482 | |
| 483 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 484 | return __mxt_read_reg(data->client, reg, |
| 485 | sizeof(struct mxt_message), message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 488 | static int mxt_read_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 489 | u8 type, u8 offset, u8 *val) |
| 490 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 491 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 492 | u16 reg; |
| 493 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 494 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 495 | if (!object) |
| 496 | return -EINVAL; |
| 497 | |
| 498 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 499 | return __mxt_read_reg(data->client, reg + offset, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 502 | static int mxt_write_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 503 | u8 type, u8 offset, u8 val) |
| 504 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 505 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 506 | u16 reg; |
| 507 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 508 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 509 | if (!object) |
| 510 | return -EINVAL; |
| 511 | |
| 512 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 513 | return mxt_write_reg(data->client, reg + offset, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 516 | static void mxt_input_report(struct mxt_data *data, int single_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 517 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 518 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 519 | struct input_dev *input_dev = data->input_dev; |
| 520 | int status = finger[single_id].status; |
| 521 | int finger_num = 0; |
| 522 | int id; |
| 523 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 524 | for (id = 0; id < MXT_MAX_FINGER; id++) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 525 | if (!finger[id].status) |
| 526 | continue; |
| 527 | |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 528 | input_mt_slot(input_dev, id); |
| 529 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, |
| 530 | finger[id].status != MXT_RELEASE); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 531 | |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 532 | if (finger[id].status != MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 533 | finger_num++; |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 534 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, |
| 535 | finger[id].area); |
| 536 | input_report_abs(input_dev, ABS_MT_POSITION_X, |
| 537 | finger[id].x); |
| 538 | input_report_abs(input_dev, ABS_MT_POSITION_Y, |
| 539 | finger[id].y); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame^] | 540 | input_report_abs(input_dev, ABS_MT_PRESSURE, |
| 541 | finger[id].pressure); |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 542 | } else { |
| 543 | finger[id].status = 0; |
| 544 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | input_report_key(input_dev, BTN_TOUCH, finger_num > 0); |
| 548 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 549 | if (status != MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 550 | input_report_abs(input_dev, ABS_X, finger[single_id].x); |
| 551 | input_report_abs(input_dev, ABS_Y, finger[single_id].y); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame^] | 552 | input_report_abs(input_dev, |
| 553 | ABS_PRESSURE, finger[single_id].pressure); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | input_sync(input_dev); |
| 557 | } |
| 558 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 559 | static void mxt_input_touchevent(struct mxt_data *data, |
| 560 | struct mxt_message *message, int id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 561 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 562 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 563 | struct device *dev = &data->client->dev; |
| 564 | u8 status = message->message[0]; |
| 565 | int x; |
| 566 | int y; |
| 567 | int area; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame^] | 568 | int pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 569 | |
| 570 | /* Check the touch is present on the screen */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 571 | if (!(status & MXT_DETECT)) { |
| 572 | if (status & MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 573 | dev_dbg(dev, "[%d] released\n", id); |
| 574 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 575 | finger[id].status = MXT_RELEASE; |
| 576 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 577 | } |
| 578 | return; |
| 579 | } |
| 580 | |
| 581 | /* Check only AMP detection */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 582 | if (!(status & (MXT_PRESS | MXT_MOVE))) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 583 | return; |
| 584 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 585 | x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); |
| 586 | y = (message->message[2] << 4) | ((message->message[3] & 0xf)); |
| 587 | if (data->max_x < 1024) |
| 588 | x = x >> 2; |
| 589 | if (data->max_y < 1024) |
| 590 | y = y >> 2; |
| 591 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 592 | area = message->message[4]; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame^] | 593 | pressure = message->message[5]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 594 | |
| 595 | 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] | 596 | status & MXT_MOVE ? "moved" : "pressed", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 597 | x, y, area); |
| 598 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 599 | finger[id].status = status & MXT_MOVE ? |
| 600 | MXT_MOVE : MXT_PRESS; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 601 | finger[id].x = x; |
| 602 | finger[id].y = y; |
| 603 | finger[id].area = area; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame^] | 604 | finger[id].pressure = pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 605 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 606 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 609 | static irqreturn_t mxt_interrupt(int irq, void *dev_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 610 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 611 | struct mxt_data *data = dev_id; |
| 612 | struct mxt_message message; |
| 613 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 614 | struct device *dev = &data->client->dev; |
| 615 | int id; |
| 616 | u8 reportid; |
| 617 | u8 max_reportid; |
| 618 | u8 min_reportid; |
| 619 | |
| 620 | do { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 621 | if (mxt_read_message(data, &message)) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 622 | dev_err(dev, "Failed to read message\n"); |
| 623 | goto end; |
| 624 | } |
| 625 | |
| 626 | reportid = message.reportid; |
| 627 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 628 | /* whether reportid is thing of MXT_TOUCH_MULTI_T9 */ |
| 629 | object = mxt_get_object(data, MXT_TOUCH_MULTI_T9); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 630 | if (!object) |
| 631 | goto end; |
| 632 | |
| 633 | max_reportid = object->max_reportid; |
| 634 | min_reportid = max_reportid - object->num_report_ids + 1; |
| 635 | id = reportid - min_reportid; |
| 636 | |
| 637 | if (reportid >= min_reportid && reportid <= max_reportid) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 638 | mxt_input_touchevent(data, &message, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 639 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 640 | mxt_dump_message(dev, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 641 | } while (reportid != 0xff); |
| 642 | |
| 643 | end: |
| 644 | return IRQ_HANDLED; |
| 645 | } |
| 646 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 647 | static int mxt_check_reg_init(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 648 | { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 649 | const struct mxt_platform_data *pdata = data->pdata; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 650 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 651 | struct device *dev = &data->client->dev; |
| 652 | int index = 0; |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 653 | int i, j, config_offset; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 654 | |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 655 | if (!pdata->config) { |
| 656 | dev_dbg(dev, "No cfg data defined, skipping reg init\n"); |
| 657 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | for (i = 0; i < data->info.object_num; i++) { |
| 661 | object = data->object_table + i; |
| 662 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 663 | if (!mxt_object_writable(object->type)) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 664 | continue; |
| 665 | |
Iiro Valkonen | a93d4f2 | 2011-07-04 03:16:25 -0700 | [diff] [blame] | 666 | for (j = 0; |
| 667 | j < (object->size + 1) * (object->instances + 1); |
| 668 | j++) { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 669 | config_offset = index + j; |
| 670 | if (config_offset > pdata->config_length) { |
| 671 | dev_err(dev, "Not enough config data!\n"); |
| 672 | return -EINVAL; |
| 673 | } |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 674 | mxt_write_object(data, object->type, j, |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 675 | pdata->config[config_offset]); |
| 676 | } |
Iiro Valkonen | a93d4f2 | 2011-07-04 03:16:25 -0700 | [diff] [blame] | 677 | index += (object->size + 1) * (object->instances + 1); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 683 | static int mxt_make_highchg(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 684 | { |
| 685 | struct device *dev = &data->client->dev; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 686 | struct mxt_message message; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 687 | int count = 10; |
| 688 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 689 | |
| 690 | /* Read dummy message to make high CHG pin */ |
| 691 | do { |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 692 | error = mxt_read_message(data, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 693 | if (error) |
| 694 | return error; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 695 | } while (message.reportid != 0xff && --count); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 696 | |
| 697 | if (!count) { |
| 698 | dev_err(dev, "CHG pin isn't cleared\n"); |
| 699 | return -EBUSY; |
| 700 | } |
| 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 705 | static void mxt_handle_pdata(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 706 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 707 | const struct mxt_platform_data *pdata = data->pdata; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 708 | u8 voltage; |
| 709 | |
| 710 | /* Set touchscreen lines */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 711 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_XSIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 712 | pdata->x_line); |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 713 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_YSIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 714 | pdata->y_line); |
| 715 | |
| 716 | /* Set touchscreen orient */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 717 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_ORIENT, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 718 | pdata->orient); |
| 719 | |
| 720 | /* Set touchscreen burst length */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 721 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 722 | MXT_TOUCH_BLEN, pdata->blen); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 723 | |
| 724 | /* Set touchscreen threshold */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 725 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 726 | MXT_TOUCH_TCHTHR, pdata->threshold); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 727 | |
| 728 | /* Set touchscreen resolution */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 729 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 730 | MXT_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff); |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 731 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 732 | MXT_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8); |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 733 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 734 | MXT_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff); |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 735 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 736 | MXT_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 737 | |
| 738 | /* Set touchscreen voltage */ |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 739 | if (pdata->voltage) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 740 | if (pdata->voltage < MXT_VOLTAGE_DEFAULT) { |
| 741 | voltage = (MXT_VOLTAGE_DEFAULT - pdata->voltage) / |
| 742 | MXT_VOLTAGE_STEP; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 743 | voltage = 0xff - voltage + 1; |
| 744 | } else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 745 | voltage = (pdata->voltage - MXT_VOLTAGE_DEFAULT) / |
| 746 | MXT_VOLTAGE_STEP; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 747 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 748 | mxt_write_object(data, MXT_SPT_CTECONFIG_T28, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 749 | MXT_CTE_VOLTAGE, voltage); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 753 | static int mxt_get_info(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 754 | { |
| 755 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 756 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 757 | int error; |
| 758 | u8 val; |
| 759 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 760 | error = mxt_read_reg(client, MXT_FAMILY_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 761 | if (error) |
| 762 | return error; |
| 763 | info->family_id = val; |
| 764 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 765 | error = mxt_read_reg(client, MXT_VARIANT_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 766 | if (error) |
| 767 | return error; |
| 768 | info->variant_id = val; |
| 769 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 770 | error = mxt_read_reg(client, MXT_VERSION, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 771 | if (error) |
| 772 | return error; |
| 773 | info->version = val; |
| 774 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 775 | error = mxt_read_reg(client, MXT_BUILD, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 776 | if (error) |
| 777 | return error; |
| 778 | info->build = val; |
| 779 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 780 | error = mxt_read_reg(client, MXT_OBJECT_NUM, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 781 | if (error) |
| 782 | return error; |
| 783 | info->object_num = val; |
| 784 | |
| 785 | return 0; |
| 786 | } |
| 787 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 788 | static int mxt_get_object_table(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 789 | { |
| 790 | int error; |
| 791 | int i; |
| 792 | u16 reg; |
| 793 | u8 reportid = 0; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 794 | u8 buf[MXT_OBJECT_SIZE]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 795 | |
| 796 | for (i = 0; i < data->info.object_num; i++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 797 | struct mxt_object *object = data->object_table + i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 798 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 799 | reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; |
| 800 | error = mxt_read_object_table(data->client, reg, buf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 801 | if (error) |
| 802 | return error; |
| 803 | |
| 804 | object->type = buf[0]; |
| 805 | object->start_address = (buf[2] << 8) | buf[1]; |
| 806 | object->size = buf[3]; |
| 807 | object->instances = buf[4]; |
| 808 | object->num_report_ids = buf[5]; |
| 809 | |
| 810 | if (object->num_report_ids) { |
| 811 | reportid += object->num_report_ids * |
| 812 | (object->instances + 1); |
| 813 | object->max_reportid = reportid; |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 820 | static int mxt_initialize(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 821 | { |
| 822 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 823 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 824 | int error; |
| 825 | u8 val; |
| 826 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 827 | error = mxt_get_info(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 828 | if (error) |
| 829 | return error; |
| 830 | |
| 831 | data->object_table = kcalloc(info->object_num, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 832 | sizeof(struct mxt_object), |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 833 | GFP_KERNEL); |
| 834 | if (!data->object_table) { |
| 835 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 836 | return -ENOMEM; |
| 837 | } |
| 838 | |
| 839 | /* Get object table information */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 840 | error = mxt_get_object_table(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 841 | if (error) |
| 842 | return error; |
| 843 | |
| 844 | /* Check register init values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 845 | error = mxt_check_reg_init(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 846 | if (error) |
| 847 | return error; |
| 848 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 849 | mxt_handle_pdata(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 850 | |
| 851 | /* Backup to memory */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 852 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 853 | MXT_COMMAND_BACKUPNV, |
| 854 | MXT_BACKUP_VALUE); |
| 855 | msleep(MXT_BACKUP_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 856 | |
| 857 | /* Soft reset */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 858 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 859 | MXT_COMMAND_RESET, 1); |
| 860 | msleep(MXT_RESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 861 | |
| 862 | /* Update matrix size at info struct */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 863 | error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 864 | if (error) |
| 865 | return error; |
| 866 | info->matrix_xsize = val; |
| 867 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 868 | error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 869 | if (error) |
| 870 | return error; |
| 871 | info->matrix_ysize = val; |
| 872 | |
| 873 | dev_info(&client->dev, |
| 874 | "Family ID: %d Variant ID: %d Version: %d Build: %d\n", |
| 875 | info->family_id, info->variant_id, info->version, |
| 876 | info->build); |
| 877 | |
| 878 | dev_info(&client->dev, |
| 879 | "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", |
| 880 | info->matrix_xsize, info->matrix_ysize, |
| 881 | info->object_num); |
| 882 | |
| 883 | return 0; |
| 884 | } |
| 885 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 886 | static void mxt_calc_resolution(struct mxt_data *data) |
| 887 | { |
| 888 | unsigned int max_x = data->pdata->x_size - 1; |
| 889 | unsigned int max_y = data->pdata->y_size - 1; |
| 890 | |
| 891 | if (data->pdata->orient & MXT_XY_SWITCH) { |
| 892 | data->max_x = max_y; |
| 893 | data->max_y = max_x; |
| 894 | } else { |
| 895 | data->max_x = max_x; |
| 896 | data->max_y = max_y; |
| 897 | } |
| 898 | } |
| 899 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 900 | static ssize_t mxt_object_show(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 901 | struct device_attribute *attr, char *buf) |
| 902 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 903 | struct mxt_data *data = dev_get_drvdata(dev); |
| 904 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 905 | int count = 0; |
| 906 | int i, j; |
| 907 | int error; |
| 908 | u8 val; |
| 909 | |
| 910 | for (i = 0; i < data->info.object_num; i++) { |
| 911 | object = data->object_table + i; |
| 912 | |
| 913 | count += sprintf(buf + count, |
| 914 | "Object Table Element %d(Type %d)\n", |
| 915 | i + 1, object->type); |
| 916 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 917 | if (!mxt_object_readable(object->type)) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 918 | count += sprintf(buf + count, "\n"); |
| 919 | continue; |
| 920 | } |
| 921 | |
| 922 | for (j = 0; j < object->size + 1; j++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 923 | error = mxt_read_object(data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 924 | object->type, j, &val); |
| 925 | if (error) |
| 926 | return error; |
| 927 | |
| 928 | count += sprintf(buf + count, |
| 929 | " Byte %d: 0x%x (%d)\n", j, val, val); |
| 930 | } |
| 931 | |
| 932 | count += sprintf(buf + count, "\n"); |
| 933 | } |
| 934 | |
| 935 | return count; |
| 936 | } |
| 937 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 938 | static int mxt_load_fw(struct device *dev, const char *fn) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 939 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 940 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 941 | struct i2c_client *client = data->client; |
| 942 | const struct firmware *fw = NULL; |
| 943 | unsigned int frame_size; |
| 944 | unsigned int pos = 0; |
| 945 | int ret; |
| 946 | |
| 947 | ret = request_firmware(&fw, fn, dev); |
| 948 | if (ret) { |
| 949 | dev_err(dev, "Unable to open firmware %s\n", fn); |
| 950 | return ret; |
| 951 | } |
| 952 | |
| 953 | /* Change to the bootloader mode */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 954 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 955 | MXT_COMMAND_RESET, MXT_BOOT_VALUE); |
| 956 | msleep(MXT_RESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 957 | |
| 958 | /* Change to slave address of bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 959 | if (client->addr == MXT_APP_LOW) |
| 960 | client->addr = MXT_BOOT_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 961 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 962 | client->addr = MXT_BOOT_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 963 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 964 | ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 965 | if (ret) |
| 966 | goto out; |
| 967 | |
| 968 | /* Unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 969 | mxt_unlock_bootloader(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 970 | |
| 971 | while (pos < fw->size) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 972 | ret = mxt_check_bootloader(client, |
| 973 | MXT_WAITING_FRAME_DATA); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 974 | if (ret) |
| 975 | goto out; |
| 976 | |
| 977 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); |
| 978 | |
| 979 | /* We should add 2 at frame size as the the firmware data is not |
| 980 | * included the CRC bytes. |
| 981 | */ |
| 982 | frame_size += 2; |
| 983 | |
| 984 | /* Write one frame to device */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 985 | mxt_fw_write(client, fw->data + pos, frame_size); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 986 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 987 | ret = mxt_check_bootloader(client, |
| 988 | MXT_FRAME_CRC_PASS); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 989 | if (ret) |
| 990 | goto out; |
| 991 | |
| 992 | pos += frame_size; |
| 993 | |
| 994 | dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size); |
| 995 | } |
| 996 | |
| 997 | out: |
| 998 | release_firmware(fw); |
| 999 | |
| 1000 | /* Change to slave address of application */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1001 | if (client->addr == MXT_BOOT_LOW) |
| 1002 | client->addr = MXT_APP_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1003 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1004 | client->addr = MXT_APP_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1005 | |
| 1006 | return ret; |
| 1007 | } |
| 1008 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1009 | static ssize_t mxt_update_fw_store(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1010 | struct device_attribute *attr, |
| 1011 | const char *buf, size_t count) |
| 1012 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1013 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1014 | int error; |
| 1015 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1016 | disable_irq(data->irq); |
| 1017 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1018 | error = mxt_load_fw(dev, MXT_FW_NAME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1019 | if (error) { |
| 1020 | dev_err(dev, "The firmware update failed(%d)\n", error); |
| 1021 | count = error; |
| 1022 | } else { |
| 1023 | dev_dbg(dev, "The firmware update succeeded\n"); |
| 1024 | |
| 1025 | /* Wait for reset */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1026 | msleep(MXT_FWRESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1027 | |
| 1028 | kfree(data->object_table); |
| 1029 | data->object_table = NULL; |
| 1030 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1031 | mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | enable_irq(data->irq); |
| 1035 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1036 | error = mxt_make_highchg(data); |
| 1037 | if (error) |
| 1038 | return error; |
| 1039 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1040 | return count; |
| 1041 | } |
| 1042 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1043 | static DEVICE_ATTR(object, 0444, mxt_object_show, NULL); |
| 1044 | static DEVICE_ATTR(update_fw, 0664, NULL, mxt_update_fw_store); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1045 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1046 | static struct attribute *mxt_attrs[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1047 | &dev_attr_object.attr, |
| 1048 | &dev_attr_update_fw.attr, |
| 1049 | NULL |
| 1050 | }; |
| 1051 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1052 | static const struct attribute_group mxt_attr_group = { |
| 1053 | .attrs = mxt_attrs, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1054 | }; |
| 1055 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1056 | static void mxt_start(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1057 | { |
| 1058 | /* Touch enable */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1059 | mxt_write_object(data, |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 1060 | MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1063 | static void mxt_stop(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1064 | { |
| 1065 | /* Touch disable */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1066 | mxt_write_object(data, |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 1067 | MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1070 | static int mxt_input_open(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1071 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1072 | struct mxt_data *data = input_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1073 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1074 | mxt_start(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1075 | |
| 1076 | return 0; |
| 1077 | } |
| 1078 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1079 | static void mxt_input_close(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1080 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1081 | struct mxt_data *data = input_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1082 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1083 | mxt_stop(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1086 | static int __devinit mxt_probe(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1087 | const struct i2c_device_id *id) |
| 1088 | { |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1089 | const struct mxt_platform_data *pdata = client->dev.platform_data; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1090 | struct mxt_data *data; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1091 | struct input_dev *input_dev; |
| 1092 | int error; |
| 1093 | |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1094 | if (!pdata) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1095 | return -EINVAL; |
| 1096 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1097 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1098 | input_dev = input_allocate_device(); |
| 1099 | if (!data || !input_dev) { |
| 1100 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 1101 | error = -ENOMEM; |
| 1102 | goto err_free_mem; |
| 1103 | } |
| 1104 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1105 | input_dev->name = "Atmel maXTouch Touchscreen"; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1106 | input_dev->id.bustype = BUS_I2C; |
| 1107 | input_dev->dev.parent = &client->dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1108 | input_dev->open = mxt_input_open; |
| 1109 | input_dev->close = mxt_input_close; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1110 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1111 | data->client = client; |
| 1112 | data->input_dev = input_dev; |
| 1113 | data->pdata = pdata; |
| 1114 | data->irq = client->irq; |
| 1115 | |
| 1116 | mxt_calc_resolution(data); |
| 1117 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1118 | __set_bit(EV_ABS, input_dev->evbit); |
| 1119 | __set_bit(EV_KEY, input_dev->evbit); |
| 1120 | __set_bit(BTN_TOUCH, input_dev->keybit); |
| 1121 | |
| 1122 | /* For single touch */ |
| 1123 | input_set_abs_params(input_dev, ABS_X, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1124 | 0, data->max_x, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1125 | input_set_abs_params(input_dev, ABS_Y, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1126 | 0, data->max_y, 0, 0); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame^] | 1127 | input_set_abs_params(input_dev, ABS_PRESSURE, |
| 1128 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1129 | |
| 1130 | /* For multi touch */ |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 1131 | input_mt_init_slots(input_dev, MXT_MAX_FINGER); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1132 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1133 | 0, MXT_MAX_AREA, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1134 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1135 | 0, data->max_x, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1136 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1137 | 0, data->max_y, 0, 0); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame^] | 1138 | input_set_abs_params(input_dev, ABS_MT_PRESSURE, |
| 1139 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1140 | |
| 1141 | input_set_drvdata(input_dev, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1142 | i2c_set_clientdata(client, data); |
| 1143 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1144 | error = mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1145 | if (error) |
| 1146 | goto err_free_object; |
| 1147 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1148 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1149 | pdata->irqflags, client->dev.driver->name, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1150 | if (error) { |
| 1151 | dev_err(&client->dev, "Failed to register interrupt\n"); |
| 1152 | goto err_free_object; |
| 1153 | } |
| 1154 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1155 | error = mxt_make_highchg(data); |
| 1156 | if (error) |
| 1157 | goto err_free_irq; |
| 1158 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1159 | error = input_register_device(input_dev); |
| 1160 | if (error) |
| 1161 | goto err_free_irq; |
| 1162 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1163 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1164 | if (error) |
| 1165 | goto err_unregister_device; |
| 1166 | |
| 1167 | return 0; |
| 1168 | |
| 1169 | err_unregister_device: |
| 1170 | input_unregister_device(input_dev); |
| 1171 | input_dev = NULL; |
| 1172 | err_free_irq: |
| 1173 | free_irq(client->irq, data); |
| 1174 | err_free_object: |
| 1175 | kfree(data->object_table); |
| 1176 | err_free_mem: |
| 1177 | input_free_device(input_dev); |
| 1178 | kfree(data); |
| 1179 | return error; |
| 1180 | } |
| 1181 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1182 | static int __devexit mxt_remove(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1183 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1184 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1185 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1186 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1187 | free_irq(data->irq, data); |
| 1188 | input_unregister_device(data->input_dev); |
| 1189 | kfree(data->object_table); |
| 1190 | kfree(data); |
| 1191 | |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
| 1195 | #ifdef CONFIG_PM |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1196 | static int mxt_suspend(struct device *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1197 | { |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1198 | struct i2c_client *client = to_i2c_client(dev); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1199 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1200 | struct input_dev *input_dev = data->input_dev; |
| 1201 | |
| 1202 | mutex_lock(&input_dev->mutex); |
| 1203 | |
| 1204 | if (input_dev->users) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1205 | mxt_stop(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1206 | |
| 1207 | mutex_unlock(&input_dev->mutex); |
| 1208 | |
| 1209 | return 0; |
| 1210 | } |
| 1211 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1212 | static int mxt_resume(struct device *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1213 | { |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1214 | struct i2c_client *client = to_i2c_client(dev); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1215 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1216 | struct input_dev *input_dev = data->input_dev; |
| 1217 | |
| 1218 | /* Soft reset */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 1219 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1220 | MXT_COMMAND_RESET, 1); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1221 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1222 | msleep(MXT_RESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1223 | |
| 1224 | mutex_lock(&input_dev->mutex); |
| 1225 | |
| 1226 | if (input_dev->users) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1227 | mxt_start(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1228 | |
| 1229 | mutex_unlock(&input_dev->mutex); |
| 1230 | |
| 1231 | return 0; |
| 1232 | } |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1233 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1234 | static const struct dev_pm_ops mxt_pm_ops = { |
| 1235 | .suspend = mxt_suspend, |
| 1236 | .resume = mxt_resume, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1237 | }; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1238 | #endif |
| 1239 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1240 | static const struct i2c_device_id mxt_id[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1241 | { "qt602240_ts", 0 }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1242 | { "atmel_mxt_ts", 0 }, |
Chris Leech | 46ee2a0 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1243 | { "mXT224", 0 }, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1244 | { } |
| 1245 | }; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1246 | MODULE_DEVICE_TABLE(i2c, mxt_id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1247 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1248 | static struct i2c_driver mxt_driver = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1249 | .driver = { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1250 | .name = "atmel_mxt_ts", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1251 | .owner = THIS_MODULE, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1252 | #ifdef CONFIG_PM |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1253 | .pm = &mxt_pm_ops, |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1254 | #endif |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1255 | }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1256 | .probe = mxt_probe, |
| 1257 | .remove = __devexit_p(mxt_remove), |
| 1258 | .id_table = mxt_id, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1259 | }; |
| 1260 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1261 | static int __init mxt_init(void) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1262 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1263 | return i2c_add_driver(&mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1266 | static void __exit mxt_exit(void) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1267 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1268 | i2c_del_driver(&mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1271 | module_init(mxt_init); |
| 1272 | module_exit(mxt_exit); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1273 | |
| 1274 | /* Module information */ |
| 1275 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1276 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1277 | MODULE_LICENSE("GPL"); |