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]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 239 | }; |
| 240 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 241 | struct mxt_finger { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 242 | int status; |
| 243 | int x; |
| 244 | int y; |
| 245 | int area; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 246 | int pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | /* Each client has this additional data */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 250 | struct mxt_data { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 251 | struct i2c_client *client; |
| 252 | struct input_dev *input_dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 253 | const struct mxt_platform_data *pdata; |
| 254 | struct mxt_object *object_table; |
| 255 | struct mxt_info info; |
| 256 | struct mxt_finger finger[MXT_MAX_FINGER]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 257 | unsigned int irq; |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 258 | unsigned int max_x; |
| 259 | unsigned int max_y; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 262 | static bool mxt_object_readable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 263 | { |
| 264 | switch (type) { |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 265 | case MXT_GEN_MESSAGE_T5: |
| 266 | case MXT_GEN_COMMAND_T6: |
| 267 | case MXT_GEN_POWER_T7: |
| 268 | case MXT_GEN_ACQUIRE_T8: |
| 269 | case MXT_GEN_DATASOURCE_T53: |
| 270 | case MXT_TOUCH_MULTI_T9: |
| 271 | case MXT_TOUCH_KEYARRAY_T15: |
| 272 | case MXT_TOUCH_PROXIMITY_T23: |
| 273 | case MXT_TOUCH_PROXKEY_T52: |
| 274 | case MXT_PROCI_GRIPFACE_T20: |
| 275 | case MXT_PROCG_NOISE_T22: |
| 276 | case MXT_PROCI_ONETOUCH_T24: |
| 277 | case MXT_PROCI_TWOTOUCH_T27: |
| 278 | case MXT_PROCI_GRIP_T40: |
| 279 | case MXT_PROCI_PALM_T41: |
| 280 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 281 | case MXT_PROCI_STYLUS_T47: |
| 282 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 283 | case MXT_SPT_COMMSCONFIG_T18: |
| 284 | case MXT_SPT_GPIOPWM_T19: |
| 285 | case MXT_SPT_SELFTEST_T25: |
| 286 | case MXT_SPT_CTECONFIG_T28: |
| 287 | case MXT_SPT_USERDATA_T38: |
| 288 | case MXT_SPT_DIGITIZER_T43: |
| 289 | case MXT_SPT_CTECONFIG_T46: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 290 | return true; |
| 291 | default: |
| 292 | return false; |
| 293 | } |
| 294 | } |
| 295 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 296 | static bool mxt_object_writable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 297 | { |
| 298 | switch (type) { |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 299 | case MXT_GEN_COMMAND_T6: |
| 300 | case MXT_GEN_POWER_T7: |
| 301 | case MXT_GEN_ACQUIRE_T8: |
| 302 | case MXT_TOUCH_MULTI_T9: |
| 303 | case MXT_TOUCH_KEYARRAY_T15: |
| 304 | case MXT_TOUCH_PROXIMITY_T23: |
| 305 | case MXT_TOUCH_PROXKEY_T52: |
| 306 | case MXT_PROCI_GRIPFACE_T20: |
| 307 | case MXT_PROCG_NOISE_T22: |
| 308 | case MXT_PROCI_ONETOUCH_T24: |
| 309 | case MXT_PROCI_TWOTOUCH_T27: |
| 310 | case MXT_PROCI_GRIP_T40: |
| 311 | case MXT_PROCI_PALM_T41: |
| 312 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 313 | case MXT_PROCI_STYLUS_T47: |
| 314 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 315 | case MXT_SPT_COMMSCONFIG_T18: |
| 316 | case MXT_SPT_GPIOPWM_T19: |
| 317 | case MXT_SPT_SELFTEST_T25: |
| 318 | case MXT_SPT_CTECONFIG_T28: |
| 319 | case MXT_SPT_DIGITIZER_T43: |
| 320 | case MXT_SPT_CTECONFIG_T46: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 321 | return true; |
| 322 | default: |
| 323 | return false; |
| 324 | } |
| 325 | } |
| 326 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 327 | static void mxt_dump_message(struct device *dev, |
| 328 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 329 | { |
| 330 | dev_dbg(dev, "reportid:\t0x%x\n", message->reportid); |
| 331 | dev_dbg(dev, "message1:\t0x%x\n", message->message[0]); |
| 332 | dev_dbg(dev, "message2:\t0x%x\n", message->message[1]); |
| 333 | dev_dbg(dev, "message3:\t0x%x\n", message->message[2]); |
| 334 | dev_dbg(dev, "message4:\t0x%x\n", message->message[3]); |
| 335 | dev_dbg(dev, "message5:\t0x%x\n", message->message[4]); |
| 336 | dev_dbg(dev, "message6:\t0x%x\n", message->message[5]); |
| 337 | dev_dbg(dev, "message7:\t0x%x\n", message->message[6]); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 340 | static int mxt_check_bootloader(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 341 | unsigned int state) |
| 342 | { |
| 343 | u8 val; |
| 344 | |
| 345 | recheck: |
| 346 | if (i2c_master_recv(client, &val, 1) != 1) { |
| 347 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); |
| 348 | return -EIO; |
| 349 | } |
| 350 | |
| 351 | switch (state) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 352 | case MXT_WAITING_BOOTLOAD_CMD: |
| 353 | case MXT_WAITING_FRAME_DATA: |
| 354 | val &= ~MXT_BOOT_STATUS_MASK; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 355 | break; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 356 | case MXT_FRAME_CRC_PASS: |
| 357 | if (val == MXT_FRAME_CRC_CHECK) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 358 | goto recheck; |
| 359 | break; |
| 360 | default: |
| 361 | return -EINVAL; |
| 362 | } |
| 363 | |
| 364 | if (val != state) { |
| 365 | dev_err(&client->dev, "Unvalid bootloader mode state\n"); |
| 366 | return -EINVAL; |
| 367 | } |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 372 | static int mxt_unlock_bootloader(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 373 | { |
| 374 | u8 buf[2]; |
| 375 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 376 | buf[0] = MXT_UNLOCK_CMD_LSB; |
| 377 | buf[1] = MXT_UNLOCK_CMD_MSB; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 378 | |
| 379 | if (i2c_master_send(client, buf, 2) != 2) { |
| 380 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 381 | return -EIO; |
| 382 | } |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 387 | static int mxt_fw_write(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 388 | const u8 *data, unsigned int frame_size) |
| 389 | { |
| 390 | if (i2c_master_send(client, data, frame_size) != frame_size) { |
| 391 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 392 | return -EIO; |
| 393 | } |
| 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 398 | static int __mxt_read_reg(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 399 | u16 reg, u16 len, void *val) |
| 400 | { |
| 401 | struct i2c_msg xfer[2]; |
| 402 | u8 buf[2]; |
| 403 | |
| 404 | buf[0] = reg & 0xff; |
| 405 | buf[1] = (reg >> 8) & 0xff; |
| 406 | |
| 407 | /* Write register */ |
| 408 | xfer[0].addr = client->addr; |
| 409 | xfer[0].flags = 0; |
| 410 | xfer[0].len = 2; |
| 411 | xfer[0].buf = buf; |
| 412 | |
| 413 | /* Read data */ |
| 414 | xfer[1].addr = client->addr; |
| 415 | xfer[1].flags = I2C_M_RD; |
| 416 | xfer[1].len = len; |
| 417 | xfer[1].buf = val; |
| 418 | |
| 419 | if (i2c_transfer(client->adapter, xfer, 2) != 2) { |
| 420 | dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); |
| 421 | return -EIO; |
| 422 | } |
| 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 427 | 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] | 428 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 429 | return __mxt_read_reg(client, reg, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 432 | 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] | 433 | { |
| 434 | u8 buf[3]; |
| 435 | |
| 436 | buf[0] = reg & 0xff; |
| 437 | buf[1] = (reg >> 8) & 0xff; |
| 438 | buf[2] = val; |
| 439 | |
| 440 | if (i2c_master_send(client, buf, 3) != 3) { |
| 441 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 442 | return -EIO; |
| 443 | } |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 448 | static int mxt_read_object_table(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 449 | u16 reg, u8 *object_buf) |
| 450 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 451 | return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 452 | object_buf); |
| 453 | } |
| 454 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 455 | static struct mxt_object * |
| 456 | mxt_get_object(struct mxt_data *data, u8 type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 457 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 458 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 459 | int i; |
| 460 | |
| 461 | for (i = 0; i < data->info.object_num; i++) { |
| 462 | object = data->object_table + i; |
| 463 | if (object->type == type) |
| 464 | return object; |
| 465 | } |
| 466 | |
| 467 | dev_err(&data->client->dev, "Invalid object type\n"); |
| 468 | return NULL; |
| 469 | } |
| 470 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 471 | static int mxt_read_message(struct mxt_data *data, |
| 472 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 473 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 474 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 475 | u16 reg; |
| 476 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 477 | object = mxt_get_object(data, MXT_GEN_MESSAGE_T5); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 478 | if (!object) |
| 479 | return -EINVAL; |
| 480 | |
| 481 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 482 | return __mxt_read_reg(data->client, reg, |
| 483 | sizeof(struct mxt_message), message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 486 | static int mxt_read_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 487 | u8 type, u8 offset, u8 *val) |
| 488 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 489 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 490 | u16 reg; |
| 491 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 492 | object = mxt_get_object(data, type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 493 | if (!object) |
| 494 | return -EINVAL; |
| 495 | |
| 496 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 497 | return __mxt_read_reg(data->client, reg + offset, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 500 | static int mxt_write_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 501 | u8 type, u8 offset, u8 val) |
| 502 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 503 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 504 | u16 reg; |
| 505 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 506 | object = mxt_get_object(data, type); |
Daniel Kurtz | d1ff320 | 2012-05-08 22:38:52 -0700 | [diff] [blame] | 507 | if (!object || offset >= object->size + 1) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 508 | return -EINVAL; |
| 509 | |
| 510 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 511 | return mxt_write_reg(data->client, reg + offset, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 514 | static void mxt_input_report(struct mxt_data *data, int single_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 515 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 516 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 517 | struct input_dev *input_dev = data->input_dev; |
| 518 | int status = finger[single_id].status; |
| 519 | int finger_num = 0; |
| 520 | int id; |
| 521 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 522 | for (id = 0; id < MXT_MAX_FINGER; id++) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 523 | if (!finger[id].status) |
| 524 | continue; |
| 525 | |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 526 | input_mt_slot(input_dev, id); |
| 527 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, |
| 528 | finger[id].status != MXT_RELEASE); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 529 | |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 530 | if (finger[id].status != MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 531 | finger_num++; |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 532 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, |
| 533 | finger[id].area); |
| 534 | input_report_abs(input_dev, ABS_MT_POSITION_X, |
| 535 | finger[id].x); |
| 536 | input_report_abs(input_dev, ABS_MT_POSITION_Y, |
| 537 | finger[id].y); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 538 | input_report_abs(input_dev, ABS_MT_PRESSURE, |
| 539 | finger[id].pressure); |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 540 | } else { |
| 541 | finger[id].status = 0; |
| 542 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | input_report_key(input_dev, BTN_TOUCH, finger_num > 0); |
| 546 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 547 | if (status != MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 548 | input_report_abs(input_dev, ABS_X, finger[single_id].x); |
| 549 | input_report_abs(input_dev, ABS_Y, finger[single_id].y); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 550 | input_report_abs(input_dev, |
| 551 | ABS_PRESSURE, finger[single_id].pressure); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | input_sync(input_dev); |
| 555 | } |
| 556 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 557 | static void mxt_input_touchevent(struct mxt_data *data, |
| 558 | struct mxt_message *message, int id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 559 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 560 | struct mxt_finger *finger = data->finger; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 561 | struct device *dev = &data->client->dev; |
| 562 | u8 status = message->message[0]; |
| 563 | int x; |
| 564 | int y; |
| 565 | int area; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 566 | int pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 567 | |
| 568 | /* Check the touch is present on the screen */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 569 | if (!(status & MXT_DETECT)) { |
| 570 | if (status & MXT_RELEASE) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 571 | dev_dbg(dev, "[%d] released\n", id); |
| 572 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 573 | finger[id].status = MXT_RELEASE; |
| 574 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 575 | } |
| 576 | return; |
| 577 | } |
| 578 | |
| 579 | /* Check only AMP detection */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 580 | if (!(status & (MXT_PRESS | MXT_MOVE))) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 581 | return; |
| 582 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 583 | x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); |
| 584 | y = (message->message[2] << 4) | ((message->message[3] & 0xf)); |
| 585 | if (data->max_x < 1024) |
| 586 | x = x >> 2; |
| 587 | if (data->max_y < 1024) |
| 588 | y = y >> 2; |
| 589 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 590 | area = message->message[4]; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 591 | pressure = message->message[5]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 592 | |
| 593 | 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] | 594 | status & MXT_MOVE ? "moved" : "pressed", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 595 | x, y, area); |
| 596 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 597 | finger[id].status = status & MXT_MOVE ? |
| 598 | MXT_MOVE : MXT_PRESS; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 599 | finger[id].x = x; |
| 600 | finger[id].y = y; |
| 601 | finger[id].area = area; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 602 | finger[id].pressure = pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 603 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 604 | mxt_input_report(data, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 607 | static irqreturn_t mxt_interrupt(int irq, void *dev_id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 608 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 609 | struct mxt_data *data = dev_id; |
| 610 | struct mxt_message message; |
| 611 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 612 | struct device *dev = &data->client->dev; |
| 613 | int id; |
| 614 | u8 reportid; |
| 615 | u8 max_reportid; |
| 616 | u8 min_reportid; |
| 617 | |
| 618 | do { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 619 | if (mxt_read_message(data, &message)) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 620 | dev_err(dev, "Failed to read message\n"); |
| 621 | goto end; |
| 622 | } |
| 623 | |
| 624 | reportid = message.reportid; |
| 625 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 626 | /* whether reportid is thing of MXT_TOUCH_MULTI_T9 */ |
| 627 | object = mxt_get_object(data, MXT_TOUCH_MULTI_T9); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 628 | if (!object) |
| 629 | goto end; |
| 630 | |
| 631 | max_reportid = object->max_reportid; |
| 632 | min_reportid = max_reportid - object->num_report_ids + 1; |
| 633 | id = reportid - min_reportid; |
| 634 | |
| 635 | if (reportid >= min_reportid && reportid <= max_reportid) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 636 | mxt_input_touchevent(data, &message, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 637 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 638 | mxt_dump_message(dev, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 639 | } while (reportid != 0xff); |
| 640 | |
| 641 | end: |
| 642 | return IRQ_HANDLED; |
| 643 | } |
| 644 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 645 | static int mxt_check_reg_init(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 646 | { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 647 | const struct mxt_platform_data *pdata = data->pdata; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 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 index = 0; |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 651 | int i, j, config_offset; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 652 | |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 653 | if (!pdata->config) { |
| 654 | dev_dbg(dev, "No cfg data defined, skipping reg init\n"); |
| 655 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | for (i = 0; i < data->info.object_num; i++) { |
| 659 | object = data->object_table + i; |
| 660 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 661 | if (!mxt_object_writable(object->type)) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 662 | continue; |
| 663 | |
Iiro Valkonen | a93d4f2 | 2011-07-04 03:16:25 -0700 | [diff] [blame] | 664 | for (j = 0; |
| 665 | j < (object->size + 1) * (object->instances + 1); |
| 666 | j++) { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 667 | config_offset = index + j; |
| 668 | if (config_offset > pdata->config_length) { |
| 669 | dev_err(dev, "Not enough config data!\n"); |
| 670 | return -EINVAL; |
| 671 | } |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 672 | mxt_write_object(data, object->type, j, |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 673 | pdata->config[config_offset]); |
| 674 | } |
Iiro Valkonen | a93d4f2 | 2011-07-04 03:16:25 -0700 | [diff] [blame] | 675 | index += (object->size + 1) * (object->instances + 1); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 681 | static int mxt_make_highchg(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 682 | { |
| 683 | struct device *dev = &data->client->dev; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 684 | struct mxt_message message; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 685 | int count = 10; |
| 686 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 687 | |
| 688 | /* Read dummy message to make high CHG pin */ |
| 689 | do { |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 690 | error = mxt_read_message(data, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 691 | if (error) |
| 692 | return error; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 693 | } while (message.reportid != 0xff && --count); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 694 | |
| 695 | if (!count) { |
| 696 | dev_err(dev, "CHG pin isn't cleared\n"); |
| 697 | return -EBUSY; |
| 698 | } |
| 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 703 | static void mxt_handle_pdata(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 704 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 705 | const struct mxt_platform_data *pdata = data->pdata; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 706 | u8 voltage; |
| 707 | |
| 708 | /* Set touchscreen lines */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 709 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_XSIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 710 | pdata->x_line); |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 711 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_YSIZE, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 712 | pdata->y_line); |
| 713 | |
| 714 | /* Set touchscreen orient */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 715 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, MXT_TOUCH_ORIENT, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 716 | pdata->orient); |
| 717 | |
| 718 | /* Set touchscreen burst length */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 719 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 720 | MXT_TOUCH_BLEN, pdata->blen); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 721 | |
| 722 | /* Set touchscreen threshold */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 723 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 724 | MXT_TOUCH_TCHTHR, pdata->threshold); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 725 | |
| 726 | /* Set touchscreen resolution */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 727 | mxt_write_object(data, MXT_TOUCH_MULTI_T9, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 728 | MXT_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff); |
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_MSB, (pdata->x_size - 1) >> 8); |
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_YRANGE_LSB, (pdata->y_size - 1) & 0xff); |
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_MSB, (pdata->y_size - 1) >> 8); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 735 | |
| 736 | /* Set touchscreen voltage */ |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 737 | if (pdata->voltage) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 738 | if (pdata->voltage < MXT_VOLTAGE_DEFAULT) { |
| 739 | voltage = (MXT_VOLTAGE_DEFAULT - pdata->voltage) / |
| 740 | MXT_VOLTAGE_STEP; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 741 | voltage = 0xff - voltage + 1; |
| 742 | } else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 743 | voltage = (pdata->voltage - MXT_VOLTAGE_DEFAULT) / |
| 744 | MXT_VOLTAGE_STEP; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 745 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 746 | mxt_write_object(data, MXT_SPT_CTECONFIG_T28, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 747 | MXT_CTE_VOLTAGE, voltage); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 751 | static int mxt_get_info(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 752 | { |
| 753 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 754 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 755 | int error; |
| 756 | u8 val; |
| 757 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 758 | error = mxt_read_reg(client, MXT_FAMILY_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 759 | if (error) |
| 760 | return error; |
| 761 | info->family_id = val; |
| 762 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 763 | error = mxt_read_reg(client, MXT_VARIANT_ID, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 764 | if (error) |
| 765 | return error; |
| 766 | info->variant_id = val; |
| 767 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 768 | error = mxt_read_reg(client, MXT_VERSION, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 769 | if (error) |
| 770 | return error; |
| 771 | info->version = val; |
| 772 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 773 | error = mxt_read_reg(client, MXT_BUILD, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 774 | if (error) |
| 775 | return error; |
| 776 | info->build = val; |
| 777 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 778 | error = mxt_read_reg(client, MXT_OBJECT_NUM, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 779 | if (error) |
| 780 | return error; |
| 781 | info->object_num = val; |
| 782 | |
| 783 | return 0; |
| 784 | } |
| 785 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 786 | static int mxt_get_object_table(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 787 | { |
| 788 | int error; |
| 789 | int i; |
| 790 | u16 reg; |
| 791 | u8 reportid = 0; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 792 | u8 buf[MXT_OBJECT_SIZE]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 793 | |
| 794 | for (i = 0; i < data->info.object_num; i++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 795 | struct mxt_object *object = data->object_table + i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 796 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 797 | reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; |
| 798 | error = mxt_read_object_table(data->client, reg, buf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 799 | if (error) |
| 800 | return error; |
| 801 | |
| 802 | object->type = buf[0]; |
| 803 | object->start_address = (buf[2] << 8) | buf[1]; |
| 804 | object->size = buf[3]; |
| 805 | object->instances = buf[4]; |
| 806 | object->num_report_ids = buf[5]; |
| 807 | |
| 808 | if (object->num_report_ids) { |
| 809 | reportid += object->num_report_ids * |
| 810 | (object->instances + 1); |
| 811 | object->max_reportid = reportid; |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 818 | static int mxt_initialize(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 819 | { |
| 820 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 821 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 822 | int error; |
| 823 | u8 val; |
| 824 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 825 | error = mxt_get_info(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 826 | if (error) |
| 827 | return error; |
| 828 | |
| 829 | data->object_table = kcalloc(info->object_num, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 830 | sizeof(struct mxt_object), |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 831 | GFP_KERNEL); |
| 832 | if (!data->object_table) { |
| 833 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 834 | return -ENOMEM; |
| 835 | } |
| 836 | |
| 837 | /* Get object table information */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 838 | error = mxt_get_object_table(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 839 | if (error) |
| 840 | return error; |
| 841 | |
| 842 | /* Check register init values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 843 | error = mxt_check_reg_init(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 844 | if (error) |
| 845 | return error; |
| 846 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 847 | mxt_handle_pdata(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 848 | |
| 849 | /* Backup to memory */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 850 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 851 | MXT_COMMAND_BACKUPNV, |
| 852 | MXT_BACKUP_VALUE); |
| 853 | msleep(MXT_BACKUP_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 854 | |
| 855 | /* Soft reset */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 856 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 857 | MXT_COMMAND_RESET, 1); |
| 858 | msleep(MXT_RESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 859 | |
| 860 | /* Update matrix size at info struct */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 861 | error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 862 | if (error) |
| 863 | return error; |
| 864 | info->matrix_xsize = val; |
| 865 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 866 | error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 867 | if (error) |
| 868 | return error; |
| 869 | info->matrix_ysize = val; |
| 870 | |
| 871 | dev_info(&client->dev, |
| 872 | "Family ID: %d Variant ID: %d Version: %d Build: %d\n", |
| 873 | info->family_id, info->variant_id, info->version, |
| 874 | info->build); |
| 875 | |
| 876 | dev_info(&client->dev, |
| 877 | "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", |
| 878 | info->matrix_xsize, info->matrix_ysize, |
| 879 | info->object_num); |
| 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 884 | static void mxt_calc_resolution(struct mxt_data *data) |
| 885 | { |
| 886 | unsigned int max_x = data->pdata->x_size - 1; |
| 887 | unsigned int max_y = data->pdata->y_size - 1; |
| 888 | |
| 889 | if (data->pdata->orient & MXT_XY_SWITCH) { |
| 890 | data->max_x = max_y; |
| 891 | data->max_y = max_x; |
| 892 | } else { |
| 893 | data->max_x = max_x; |
| 894 | data->max_y = max_y; |
| 895 | } |
| 896 | } |
| 897 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 898 | static ssize_t mxt_object_show(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 899 | struct device_attribute *attr, char *buf) |
| 900 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 901 | struct mxt_data *data = dev_get_drvdata(dev); |
| 902 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 903 | int count = 0; |
| 904 | int i, j; |
| 905 | int error; |
| 906 | u8 val; |
| 907 | |
| 908 | for (i = 0; i < data->info.object_num; i++) { |
| 909 | object = data->object_table + i; |
| 910 | |
Daniel Kurtz | 626af861 | 2011-10-06 15:43:20 -0700 | [diff] [blame] | 911 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 912 | "Object[%d] (Type %d)\n", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 913 | i + 1, object->type); |
Daniel Kurtz | 626af861 | 2011-10-06 15:43:20 -0700 | [diff] [blame] | 914 | if (count >= PAGE_SIZE) |
| 915 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 916 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 917 | if (!mxt_object_readable(object->type)) { |
Daniel Kurtz | 626af861 | 2011-10-06 15:43:20 -0700 | [diff] [blame] | 918 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 919 | "\n"); |
| 920 | if (count >= PAGE_SIZE) |
| 921 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 922 | continue; |
| 923 | } |
| 924 | |
| 925 | for (j = 0; j < object->size + 1; j++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 926 | error = mxt_read_object(data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 927 | object->type, j, &val); |
| 928 | if (error) |
| 929 | return error; |
| 930 | |
Daniel Kurtz | 626af861 | 2011-10-06 15:43:20 -0700 | [diff] [blame] | 931 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 932 | "\t[%2d]: %02x (%d)\n", j, val, val); |
| 933 | if (count >= PAGE_SIZE) |
| 934 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Daniel Kurtz | 626af861 | 2011-10-06 15:43:20 -0700 | [diff] [blame] | 937 | count += snprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 938 | if (count >= PAGE_SIZE) |
| 939 | return PAGE_SIZE - 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | return count; |
| 943 | } |
| 944 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 945 | static int mxt_load_fw(struct device *dev, const char *fn) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 946 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 947 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 948 | struct i2c_client *client = data->client; |
| 949 | const struct firmware *fw = NULL; |
| 950 | unsigned int frame_size; |
| 951 | unsigned int pos = 0; |
| 952 | int ret; |
| 953 | |
| 954 | ret = request_firmware(&fw, fn, dev); |
| 955 | if (ret) { |
| 956 | dev_err(dev, "Unable to open firmware %s\n", fn); |
| 957 | return ret; |
| 958 | } |
| 959 | |
| 960 | /* Change to the bootloader mode */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 961 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 962 | MXT_COMMAND_RESET, MXT_BOOT_VALUE); |
| 963 | msleep(MXT_RESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 964 | |
| 965 | /* Change to slave address of bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 966 | if (client->addr == MXT_APP_LOW) |
| 967 | client->addr = MXT_BOOT_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 968 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 969 | client->addr = MXT_BOOT_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 970 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 971 | ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 972 | if (ret) |
| 973 | goto out; |
| 974 | |
| 975 | /* Unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 976 | mxt_unlock_bootloader(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 977 | |
| 978 | while (pos < fw->size) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 979 | ret = mxt_check_bootloader(client, |
| 980 | MXT_WAITING_FRAME_DATA); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 981 | if (ret) |
| 982 | goto out; |
| 983 | |
| 984 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); |
| 985 | |
| 986 | /* We should add 2 at frame size as the the firmware data is not |
| 987 | * included the CRC bytes. |
| 988 | */ |
| 989 | frame_size += 2; |
| 990 | |
| 991 | /* Write one frame to device */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 992 | mxt_fw_write(client, fw->data + pos, frame_size); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 993 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 994 | ret = mxt_check_bootloader(client, |
| 995 | MXT_FRAME_CRC_PASS); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 996 | if (ret) |
| 997 | goto out; |
| 998 | |
| 999 | pos += frame_size; |
| 1000 | |
| 1001 | dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size); |
| 1002 | } |
| 1003 | |
| 1004 | out: |
| 1005 | release_firmware(fw); |
| 1006 | |
| 1007 | /* Change to slave address of application */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1008 | if (client->addr == MXT_BOOT_LOW) |
| 1009 | client->addr = MXT_APP_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1010 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1011 | client->addr = MXT_APP_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1012 | |
| 1013 | return ret; |
| 1014 | } |
| 1015 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1016 | static ssize_t mxt_update_fw_store(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1017 | struct device_attribute *attr, |
| 1018 | const char *buf, size_t count) |
| 1019 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1020 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1021 | int error; |
| 1022 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1023 | disable_irq(data->irq); |
| 1024 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1025 | error = mxt_load_fw(dev, MXT_FW_NAME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1026 | if (error) { |
| 1027 | dev_err(dev, "The firmware update failed(%d)\n", error); |
| 1028 | count = error; |
| 1029 | } else { |
| 1030 | dev_dbg(dev, "The firmware update succeeded\n"); |
| 1031 | |
| 1032 | /* Wait for reset */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1033 | msleep(MXT_FWRESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1034 | |
| 1035 | kfree(data->object_table); |
| 1036 | data->object_table = NULL; |
| 1037 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1038 | mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | enable_irq(data->irq); |
| 1042 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1043 | error = mxt_make_highchg(data); |
| 1044 | if (error) |
| 1045 | return error; |
| 1046 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1047 | return count; |
| 1048 | } |
| 1049 | |
Daniel Kurtz | 71b3e93 | 2012-05-08 22:30:14 -0700 | [diff] [blame] | 1050 | static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); |
| 1051 | static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1052 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1053 | static struct attribute *mxt_attrs[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1054 | &dev_attr_object.attr, |
| 1055 | &dev_attr_update_fw.attr, |
| 1056 | NULL |
| 1057 | }; |
| 1058 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1059 | static const struct attribute_group mxt_attr_group = { |
| 1060 | .attrs = mxt_attrs, |
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_start(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1064 | { |
| 1065 | /* Touch enable */ |
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, 0x83); |
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 void mxt_stop(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1071 | { |
| 1072 | /* Touch disable */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1073 | mxt_write_object(data, |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 1074 | MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1077 | static int mxt_input_open(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1078 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1079 | struct mxt_data *data = input_get_drvdata(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 | mxt_start(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1082 | |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1086 | static void mxt_input_close(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1087 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1088 | struct mxt_data *data = input_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1089 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1090 | mxt_stop(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1093 | static int __devinit mxt_probe(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1094 | const struct i2c_device_id *id) |
| 1095 | { |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1096 | const struct mxt_platform_data *pdata = client->dev.platform_data; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1097 | struct mxt_data *data; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1098 | struct input_dev *input_dev; |
| 1099 | int error; |
| 1100 | |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1101 | if (!pdata) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1102 | return -EINVAL; |
| 1103 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1104 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1105 | input_dev = input_allocate_device(); |
| 1106 | if (!data || !input_dev) { |
| 1107 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 1108 | error = -ENOMEM; |
| 1109 | goto err_free_mem; |
| 1110 | } |
| 1111 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1112 | input_dev->name = "Atmel maXTouch Touchscreen"; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1113 | input_dev->id.bustype = BUS_I2C; |
| 1114 | input_dev->dev.parent = &client->dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1115 | input_dev->open = mxt_input_open; |
| 1116 | input_dev->close = mxt_input_close; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1117 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1118 | data->client = client; |
| 1119 | data->input_dev = input_dev; |
| 1120 | data->pdata = pdata; |
| 1121 | data->irq = client->irq; |
| 1122 | |
| 1123 | mxt_calc_resolution(data); |
| 1124 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1125 | __set_bit(EV_ABS, input_dev->evbit); |
| 1126 | __set_bit(EV_KEY, input_dev->evbit); |
| 1127 | __set_bit(BTN_TOUCH, input_dev->keybit); |
| 1128 | |
| 1129 | /* For single touch */ |
| 1130 | input_set_abs_params(input_dev, ABS_X, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1131 | 0, data->max_x, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1132 | input_set_abs_params(input_dev, ABS_Y, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1133 | 0, data->max_y, 0, 0); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 1134 | input_set_abs_params(input_dev, ABS_PRESSURE, |
| 1135 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1136 | |
| 1137 | /* For multi touch */ |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 1138 | input_mt_init_slots(input_dev, MXT_MAX_FINGER); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1139 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1140 | 0, MXT_MAX_AREA, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1141 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1142 | 0, data->max_x, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1143 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1144 | 0, data->max_y, 0, 0); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 1145 | input_set_abs_params(input_dev, ABS_MT_PRESSURE, |
| 1146 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1147 | |
| 1148 | input_set_drvdata(input_dev, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1149 | i2c_set_clientdata(client, data); |
| 1150 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1151 | error = mxt_initialize(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1152 | if (error) |
| 1153 | goto err_free_object; |
| 1154 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1155 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1156 | pdata->irqflags, client->dev.driver->name, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1157 | if (error) { |
| 1158 | dev_err(&client->dev, "Failed to register interrupt\n"); |
| 1159 | goto err_free_object; |
| 1160 | } |
| 1161 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1162 | error = mxt_make_highchg(data); |
| 1163 | if (error) |
| 1164 | goto err_free_irq; |
| 1165 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1166 | error = input_register_device(input_dev); |
| 1167 | if (error) |
| 1168 | goto err_free_irq; |
| 1169 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1170 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1171 | if (error) |
| 1172 | goto err_unregister_device; |
| 1173 | |
| 1174 | return 0; |
| 1175 | |
| 1176 | err_unregister_device: |
| 1177 | input_unregister_device(input_dev); |
| 1178 | input_dev = NULL; |
| 1179 | err_free_irq: |
| 1180 | free_irq(client->irq, data); |
| 1181 | err_free_object: |
| 1182 | kfree(data->object_table); |
| 1183 | err_free_mem: |
| 1184 | input_free_device(input_dev); |
| 1185 | kfree(data); |
| 1186 | return error; |
| 1187 | } |
| 1188 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1189 | static int __devexit mxt_remove(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1190 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1191 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1192 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1193 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1194 | free_irq(data->irq, data); |
| 1195 | input_unregister_device(data->input_dev); |
| 1196 | kfree(data->object_table); |
| 1197 | kfree(data); |
| 1198 | |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
Daniel Kurtz | 3a73c81 | 2012-05-08 22:29:14 -0700 | [diff] [blame] | 1202 | #ifdef CONFIG_PM_SLEEP |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1203 | static int mxt_suspend(struct device *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1204 | { |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1205 | struct i2c_client *client = to_i2c_client(dev); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1206 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1207 | struct input_dev *input_dev = data->input_dev; |
| 1208 | |
| 1209 | mutex_lock(&input_dev->mutex); |
| 1210 | |
| 1211 | if (input_dev->users) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1212 | mxt_stop(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1213 | |
| 1214 | mutex_unlock(&input_dev->mutex); |
| 1215 | |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1219 | static int mxt_resume(struct device *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1220 | { |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1221 | struct i2c_client *client = to_i2c_client(dev); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1222 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1223 | struct input_dev *input_dev = data->input_dev; |
| 1224 | |
| 1225 | /* Soft reset */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 1226 | mxt_write_object(data, MXT_GEN_COMMAND_T6, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1227 | MXT_COMMAND_RESET, 1); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1228 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1229 | msleep(MXT_RESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1230 | |
| 1231 | mutex_lock(&input_dev->mutex); |
| 1232 | |
| 1233 | if (input_dev->users) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1234 | mxt_start(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1235 | |
| 1236 | mutex_unlock(&input_dev->mutex); |
| 1237 | |
| 1238 | return 0; |
| 1239 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1240 | #endif |
| 1241 | |
Daniel Kurtz | 3a73c81 | 2012-05-08 22:29:14 -0700 | [diff] [blame] | 1242 | static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume); |
| 1243 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1244 | static const struct i2c_device_id mxt_id[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1245 | { "qt602240_ts", 0 }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1246 | { "atmel_mxt_ts", 0 }, |
Chris Leech | 46ee2a0 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1247 | { "mXT224", 0 }, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1248 | { } |
| 1249 | }; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1250 | MODULE_DEVICE_TABLE(i2c, mxt_id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1251 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1252 | static struct i2c_driver mxt_driver = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1253 | .driver = { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1254 | .name = "atmel_mxt_ts", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1255 | .owner = THIS_MODULE, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1256 | .pm = &mxt_pm_ops, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1257 | }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1258 | .probe = mxt_probe, |
| 1259 | .remove = __devexit_p(mxt_remove), |
| 1260 | .id_table = mxt_id, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1261 | }; |
| 1262 | |
Axel Lin | 1b92c1c | 2012-03-16 23:05:41 -0700 | [diff] [blame] | 1263 | module_i2c_driver(mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1264 | |
| 1265 | /* Module information */ |
| 1266 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1267 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1268 | MODULE_LICENSE("GPL"); |