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