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 |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 5 | * Copyright (C) 2012 Google, Inc. |
| 6 | * |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 7 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/module.h> |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 17 | #include <linux/init.h> |
| 18 | #include <linux/completion.h> |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 19 | #include <linux/delay.h> |
| 20 | #include <linux/firmware.h> |
| 21 | #include <linux/i2c.h> |
Dmitry Torokhov | 964de52 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 22 | #include <linux/i2c/atmel_mxt_ts.h> |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 23 | #include <linux/input/mt.h> |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/slab.h> |
| 26 | |
| 27 | /* Version */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 28 | #define MXT_VER_20 20 |
| 29 | #define MXT_VER_21 21 |
| 30 | #define MXT_VER_22 22 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 31 | |
| 32 | /* Slave addresses */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 33 | #define MXT_APP_LOW 0x4a |
| 34 | #define MXT_APP_HIGH 0x4b |
| 35 | #define MXT_BOOT_LOW 0x24 |
| 36 | #define MXT_BOOT_HIGH 0x25 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 37 | |
| 38 | /* Firmware */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 39 | #define MXT_FW_NAME "maxtouch.fw" |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 40 | |
| 41 | /* Registers */ |
Daniel Kurtz | 23003a84 | 2012-06-28 21:08:14 +0800 | [diff] [blame] | 42 | #define MXT_INFO 0x00 |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 43 | #define MXT_FAMILY_ID 0x00 |
| 44 | #define MXT_VARIANT_ID 0x01 |
| 45 | #define MXT_VERSION 0x02 |
| 46 | #define MXT_BUILD 0x03 |
| 47 | #define MXT_MATRIX_X_SIZE 0x04 |
| 48 | #define MXT_MATRIX_Y_SIZE 0x05 |
| 49 | #define MXT_OBJECT_NUM 0x06 |
| 50 | #define MXT_OBJECT_START 0x07 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 51 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 52 | #define MXT_OBJECT_SIZE 6 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 53 | |
| 54 | /* Object types */ |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 55 | #define MXT_DEBUG_DIAGNOSTIC_T37 37 |
| 56 | #define MXT_GEN_MESSAGE_T5 5 |
| 57 | #define MXT_GEN_COMMAND_T6 6 |
| 58 | #define MXT_GEN_POWER_T7 7 |
| 59 | #define MXT_GEN_ACQUIRE_T8 8 |
| 60 | #define MXT_GEN_DATASOURCE_T53 53 |
| 61 | #define MXT_TOUCH_MULTI_T9 9 |
| 62 | #define MXT_TOUCH_KEYARRAY_T15 15 |
| 63 | #define MXT_TOUCH_PROXIMITY_T23 23 |
| 64 | #define MXT_TOUCH_PROXKEY_T52 52 |
| 65 | #define MXT_PROCI_GRIPFACE_T20 20 |
| 66 | #define MXT_PROCG_NOISE_T22 22 |
| 67 | #define MXT_PROCI_ONETOUCH_T24 24 |
| 68 | #define MXT_PROCI_TWOTOUCH_T27 27 |
| 69 | #define MXT_PROCI_GRIP_T40 40 |
| 70 | #define MXT_PROCI_PALM_T41 41 |
| 71 | #define MXT_PROCI_TOUCHSUPPRESSION_T42 42 |
| 72 | #define MXT_PROCI_STYLUS_T47 47 |
| 73 | #define MXT_PROCG_NOISESUPPRESSION_T48 48 |
| 74 | #define MXT_SPT_COMMSCONFIG_T18 18 |
| 75 | #define MXT_SPT_GPIOPWM_T19 19 |
| 76 | #define MXT_SPT_SELFTEST_T25 25 |
| 77 | #define MXT_SPT_CTECONFIG_T28 28 |
| 78 | #define MXT_SPT_USERDATA_T38 38 |
| 79 | #define MXT_SPT_DIGITIZER_T43 43 |
| 80 | #define MXT_SPT_MESSAGECOUNT_T44 44 |
| 81 | #define MXT_SPT_CTECONFIG_T46 46 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 82 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 83 | /* MXT_GEN_COMMAND_T6 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 84 | #define MXT_COMMAND_RESET 0 |
| 85 | #define MXT_COMMAND_BACKUPNV 1 |
| 86 | #define MXT_COMMAND_CALIBRATE 2 |
| 87 | #define MXT_COMMAND_REPORTALL 3 |
| 88 | #define MXT_COMMAND_DIAGNOSTIC 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 89 | |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 90 | /* Define for T6 status byte */ |
| 91 | #define MXT_T6_STATUS_RESET (1 << 7) |
| 92 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 93 | /* MXT_GEN_POWER_T7 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 94 | #define MXT_POWER_IDLEACQINT 0 |
| 95 | #define MXT_POWER_ACTVACQINT 1 |
| 96 | #define MXT_POWER_ACTV2IDLETO 2 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 97 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 98 | /* MXT_GEN_ACQUIRE_T8 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 99 | #define MXT_ACQUIRE_CHRGTIME 0 |
| 100 | #define MXT_ACQUIRE_TCHDRIFT 2 |
| 101 | #define MXT_ACQUIRE_DRIFTST 3 |
| 102 | #define MXT_ACQUIRE_TCHAUTOCAL 4 |
| 103 | #define MXT_ACQUIRE_SYNC 5 |
| 104 | #define MXT_ACQUIRE_ATCHCALST 6 |
| 105 | #define MXT_ACQUIRE_ATCHCALSTHR 7 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 106 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 107 | /* MXT_TOUCH_MULTI_T9 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 108 | #define MXT_TOUCH_CTRL 0 |
| 109 | #define MXT_TOUCH_XORIGIN 1 |
| 110 | #define MXT_TOUCH_YORIGIN 2 |
| 111 | #define MXT_TOUCH_XSIZE 3 |
| 112 | #define MXT_TOUCH_YSIZE 4 |
| 113 | #define MXT_TOUCH_BLEN 6 |
| 114 | #define MXT_TOUCH_TCHTHR 7 |
| 115 | #define MXT_TOUCH_TCHDI 8 |
| 116 | #define MXT_TOUCH_ORIENT 9 |
| 117 | #define MXT_TOUCH_MOVHYSTI 11 |
| 118 | #define MXT_TOUCH_MOVHYSTN 12 |
| 119 | #define MXT_TOUCH_NUMTOUCH 14 |
| 120 | #define MXT_TOUCH_MRGHYST 15 |
| 121 | #define MXT_TOUCH_MRGTHR 16 |
| 122 | #define MXT_TOUCH_AMPHYST 17 |
| 123 | #define MXT_TOUCH_XRANGE_LSB 18 |
| 124 | #define MXT_TOUCH_XRANGE_MSB 19 |
| 125 | #define MXT_TOUCH_YRANGE_LSB 20 |
| 126 | #define MXT_TOUCH_YRANGE_MSB 21 |
| 127 | #define MXT_TOUCH_XLOCLIP 22 |
| 128 | #define MXT_TOUCH_XHICLIP 23 |
| 129 | #define MXT_TOUCH_YLOCLIP 24 |
| 130 | #define MXT_TOUCH_YHICLIP 25 |
| 131 | #define MXT_TOUCH_XEDGECTRL 26 |
| 132 | #define MXT_TOUCH_XEDGEDIST 27 |
| 133 | #define MXT_TOUCH_YEDGECTRL 28 |
| 134 | #define MXT_TOUCH_YEDGEDIST 29 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 135 | #define MXT_TOUCH_JUMPLIMIT 30 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 136 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 137 | /* MXT_PROCI_GRIPFACE_T20 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 138 | #define MXT_GRIPFACE_CTRL 0 |
| 139 | #define MXT_GRIPFACE_XLOGRIP 1 |
| 140 | #define MXT_GRIPFACE_XHIGRIP 2 |
| 141 | #define MXT_GRIPFACE_YLOGRIP 3 |
| 142 | #define MXT_GRIPFACE_YHIGRIP 4 |
| 143 | #define MXT_GRIPFACE_MAXTCHS 5 |
| 144 | #define MXT_GRIPFACE_SZTHR1 7 |
| 145 | #define MXT_GRIPFACE_SZTHR2 8 |
| 146 | #define MXT_GRIPFACE_SHPTHR1 9 |
| 147 | #define MXT_GRIPFACE_SHPTHR2 10 |
| 148 | #define MXT_GRIPFACE_SUPEXTTO 11 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 149 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 150 | /* MXT_PROCI_NOISE field */ |
| 151 | #define MXT_NOISE_CTRL 0 |
| 152 | #define MXT_NOISE_OUTFLEN 1 |
| 153 | #define MXT_NOISE_GCAFUL_LSB 3 |
| 154 | #define MXT_NOISE_GCAFUL_MSB 4 |
| 155 | #define MXT_NOISE_GCAFLL_LSB 5 |
| 156 | #define MXT_NOISE_GCAFLL_MSB 6 |
| 157 | #define MXT_NOISE_ACTVGCAFVALID 7 |
| 158 | #define MXT_NOISE_NOISETHR 8 |
| 159 | #define MXT_NOISE_FREQHOPSCALE 10 |
| 160 | #define MXT_NOISE_FREQ0 11 |
| 161 | #define MXT_NOISE_FREQ1 12 |
| 162 | #define MXT_NOISE_FREQ2 13 |
| 163 | #define MXT_NOISE_FREQ3 14 |
| 164 | #define MXT_NOISE_FREQ4 15 |
| 165 | #define MXT_NOISE_IDLEGCAFVALID 16 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 166 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 167 | /* MXT_SPT_COMMSCONFIG_T18 */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 168 | #define MXT_COMMS_CTRL 0 |
| 169 | #define MXT_COMMS_CMD 1 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 170 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 171 | /* MXT_SPT_CTECONFIG_T28 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 172 | #define MXT_CTE_CTRL 0 |
| 173 | #define MXT_CTE_CMD 1 |
| 174 | #define MXT_CTE_MODE 2 |
| 175 | #define MXT_CTE_IDLEGCAFDEPTH 3 |
| 176 | #define MXT_CTE_ACTVGCAFDEPTH 4 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 177 | #define MXT_CTE_VOLTAGE 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 178 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 179 | #define MXT_VOLTAGE_DEFAULT 2700000 |
| 180 | #define MXT_VOLTAGE_STEP 10000 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 181 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 182 | /* Define for MXT_GEN_COMMAND_T6 */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 183 | #define MXT_BOOT_VALUE 0xa5 |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 184 | #define MXT_RESET_VALUE 0x01 |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 185 | #define MXT_BACKUP_VALUE 0x55 |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 186 | |
| 187 | /* Delay times */ |
Linus Torvalds | 8343bce | 2013-03-09 10:31:01 -0800 | [diff] [blame] | 188 | #define MXT_BACKUP_TIME 50 /* msec */ |
| 189 | #define MXT_RESET_TIME 200 /* msec */ |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 190 | #define MXT_RESET_TIMEOUT 3000 /* msec */ |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 191 | #define MXT_CRC_TIMEOUT 1000 /* msec */ |
Benson Leung | a0434b7 | 2014-05-18 23:03:09 -0700 | [diff] [blame] | 192 | #define MXT_FW_RESET_TIME 3000 /* msec */ |
| 193 | #define MXT_FW_CHG_TIMEOUT 300 /* msec */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 194 | |
| 195 | /* Command to unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 196 | #define MXT_UNLOCK_CMD_MSB 0xaa |
| 197 | #define MXT_UNLOCK_CMD_LSB 0xdc |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 198 | |
| 199 | /* Bootloader mode status */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 200 | #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */ |
| 201 | #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */ |
| 202 | #define MXT_FRAME_CRC_CHECK 0x02 |
| 203 | #define MXT_FRAME_CRC_FAIL 0x03 |
| 204 | #define MXT_FRAME_CRC_PASS 0x04 |
| 205 | #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */ |
| 206 | #define MXT_BOOT_STATUS_MASK 0x3f |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 207 | |
| 208 | /* Touch status */ |
Daniel Kurtz | b2e459b | 2012-06-28 21:08:18 +0800 | [diff] [blame] | 209 | #define MXT_UNGRIP (1 << 0) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 210 | #define MXT_SUPPRESS (1 << 1) |
| 211 | #define MXT_AMP (1 << 2) |
| 212 | #define MXT_VECTOR (1 << 3) |
| 213 | #define MXT_MOVE (1 << 4) |
| 214 | #define MXT_RELEASE (1 << 5) |
| 215 | #define MXT_PRESS (1 << 6) |
| 216 | #define MXT_DETECT (1 << 7) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 217 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 218 | /* Touch orient bits */ |
| 219 | #define MXT_XY_SWITCH (1 << 0) |
| 220 | #define MXT_X_INVERT (1 << 1) |
| 221 | #define MXT_Y_INVERT (1 << 2) |
| 222 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 223 | /* Touchscreen absolute values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 224 | #define MXT_MAX_AREA 0xff |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 225 | |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 226 | #define MXT_PIXELS_PER_MM 20 |
| 227 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 228 | struct mxt_info { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 229 | u8 family_id; |
| 230 | u8 variant_id; |
| 231 | u8 version; |
| 232 | u8 build; |
| 233 | u8 matrix_xsize; |
| 234 | u8 matrix_ysize; |
| 235 | u8 object_num; |
| 236 | }; |
| 237 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 238 | struct mxt_object { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 239 | u8 type; |
| 240 | u16 start_address; |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 241 | u8 size_minus_one; |
| 242 | u8 instances_minus_one; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 243 | u8 num_report_ids; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 244 | } __packed; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 245 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 246 | struct mxt_message { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 247 | u8 reportid; |
| 248 | u8 message[7]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 249 | }; |
| 250 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 251 | /* Each client has this additional data */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 252 | struct mxt_data { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 253 | struct i2c_client *client; |
| 254 | struct input_dev *input_dev; |
Daniel Kurtz | ec02ac2 | 2012-06-28 21:08:02 +0800 | [diff] [blame] | 255 | char phys[64]; /* device physical location */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 256 | const struct mxt_platform_data *pdata; |
| 257 | struct mxt_object *object_table; |
| 258 | struct mxt_info info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 259 | unsigned int irq; |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 260 | unsigned int max_x; |
| 261 | unsigned int max_y; |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 262 | bool in_bootloader; |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 263 | u32 config_crc; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 264 | |
| 265 | /* Cached parameters from object table */ |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 266 | u8 T6_reportid; |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 267 | u16 T6_address; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 268 | u8 T9_reportid_min; |
| 269 | u8 T9_reportid_max; |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 270 | u8 T19_reportid; |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 271 | |
| 272 | /* for fw update in bootloader */ |
| 273 | struct completion bl_completion; |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 274 | |
| 275 | /* for reset handling */ |
| 276 | struct completion reset_completion; |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 277 | |
| 278 | /* for config update handling */ |
| 279 | struct completion crc_completion; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 280 | }; |
| 281 | |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 282 | static size_t mxt_obj_size(const struct mxt_object *obj) |
| 283 | { |
| 284 | return obj->size_minus_one + 1; |
| 285 | } |
| 286 | |
| 287 | static size_t mxt_obj_instances(const struct mxt_object *obj) |
| 288 | { |
| 289 | return obj->instances_minus_one + 1; |
| 290 | } |
| 291 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 292 | static bool mxt_object_readable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 293 | { |
| 294 | switch (type) { |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 295 | case MXT_GEN_COMMAND_T6: |
| 296 | case MXT_GEN_POWER_T7: |
| 297 | case MXT_GEN_ACQUIRE_T8: |
| 298 | case MXT_GEN_DATASOURCE_T53: |
| 299 | case MXT_TOUCH_MULTI_T9: |
| 300 | case MXT_TOUCH_KEYARRAY_T15: |
| 301 | case MXT_TOUCH_PROXIMITY_T23: |
| 302 | case MXT_TOUCH_PROXKEY_T52: |
| 303 | case MXT_PROCI_GRIPFACE_T20: |
| 304 | case MXT_PROCG_NOISE_T22: |
| 305 | case MXT_PROCI_ONETOUCH_T24: |
| 306 | case MXT_PROCI_TWOTOUCH_T27: |
| 307 | case MXT_PROCI_GRIP_T40: |
| 308 | case MXT_PROCI_PALM_T41: |
| 309 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 310 | case MXT_PROCI_STYLUS_T47: |
| 311 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 312 | case MXT_SPT_COMMSCONFIG_T18: |
| 313 | case MXT_SPT_GPIOPWM_T19: |
| 314 | case MXT_SPT_SELFTEST_T25: |
| 315 | case MXT_SPT_CTECONFIG_T28: |
| 316 | case MXT_SPT_USERDATA_T38: |
| 317 | case MXT_SPT_DIGITIZER_T43: |
| 318 | case MXT_SPT_CTECONFIG_T46: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 319 | return true; |
| 320 | default: |
| 321 | return false; |
| 322 | } |
| 323 | } |
| 324 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 325 | static bool mxt_object_writable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 326 | { |
| 327 | switch (type) { |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 328 | case MXT_GEN_COMMAND_T6: |
| 329 | case MXT_GEN_POWER_T7: |
| 330 | case MXT_GEN_ACQUIRE_T8: |
| 331 | case MXT_TOUCH_MULTI_T9: |
| 332 | case MXT_TOUCH_KEYARRAY_T15: |
| 333 | case MXT_TOUCH_PROXIMITY_T23: |
| 334 | case MXT_TOUCH_PROXKEY_T52: |
| 335 | case MXT_PROCI_GRIPFACE_T20: |
| 336 | case MXT_PROCG_NOISE_T22: |
| 337 | case MXT_PROCI_ONETOUCH_T24: |
| 338 | case MXT_PROCI_TWOTOUCH_T27: |
| 339 | case MXT_PROCI_GRIP_T40: |
| 340 | case MXT_PROCI_PALM_T41: |
| 341 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 342 | case MXT_PROCI_STYLUS_T47: |
| 343 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 344 | case MXT_SPT_COMMSCONFIG_T18: |
| 345 | case MXT_SPT_GPIOPWM_T19: |
| 346 | case MXT_SPT_SELFTEST_T25: |
| 347 | case MXT_SPT_CTECONFIG_T28: |
| 348 | case MXT_SPT_DIGITIZER_T43: |
| 349 | case MXT_SPT_CTECONFIG_T46: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 350 | return true; |
| 351 | default: |
| 352 | return false; |
| 353 | } |
| 354 | } |
| 355 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 356 | static void mxt_dump_message(struct device *dev, |
Daniel Kurtz | 6ee3dbf | 2012-05-08 22:40:29 -0700 | [diff] [blame] | 357 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 358 | { |
Andy Shevchenko | eb007c8 | 2012-10-04 00:02:59 -0700 | [diff] [blame] | 359 | dev_dbg(dev, "reportid: %u\tmessage: %*ph\n", |
| 360 | message->reportid, 7, message->message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 363 | static int mxt_wait_for_completion(struct mxt_data *data, |
| 364 | struct completion *comp, |
| 365 | unsigned int timeout_ms) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 366 | { |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 367 | struct device *dev = &data->client->dev; |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 368 | unsigned long timeout = msecs_to_jiffies(timeout_ms); |
| 369 | long ret; |
| 370 | |
| 371 | ret = wait_for_completion_interruptible_timeout(comp, timeout); |
| 372 | if (ret < 0) { |
| 373 | return ret; |
| 374 | } else if (ret == 0) { |
| 375 | dev_err(dev, "Wait for completion timed out.\n"); |
| 376 | return -ETIMEDOUT; |
| 377 | } |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | static int mxt_check_bootloader(struct mxt_data *data, unsigned int state) |
| 382 | { |
| 383 | struct i2c_client *client = data->client; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 384 | u8 val; |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 385 | int ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 386 | |
| 387 | recheck: |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 388 | if (state != MXT_WAITING_BOOTLOAD_CMD) { |
| 389 | /* |
| 390 | * In application update mode, the interrupt |
| 391 | * line signals state transitions. We must wait for the |
| 392 | * CHG assertion before reading the status byte. |
| 393 | * Once the status byte has been read, the line is deasserted. |
| 394 | */ |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 395 | ret = mxt_wait_for_completion(data, &data->bl_completion, |
| 396 | MXT_FW_CHG_TIMEOUT); |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 397 | if (ret) { |
| 398 | /* |
| 399 | * TODO: handle -ERESTARTSYS better by terminating |
| 400 | * fw update process before returning to userspace |
| 401 | * by writing length 0x000 to device (iff we are in |
| 402 | * WAITING_FRAME_DATA state). |
| 403 | */ |
| 404 | dev_err(&client->dev, "Update wait error %d\n", ret); |
| 405 | return ret; |
| 406 | } |
| 407 | } |
| 408 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 409 | if (i2c_master_recv(client, &val, 1) != 1) { |
| 410 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); |
| 411 | return -EIO; |
| 412 | } |
| 413 | |
| 414 | switch (state) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 415 | case MXT_WAITING_BOOTLOAD_CMD: |
| 416 | case MXT_WAITING_FRAME_DATA: |
| 417 | val &= ~MXT_BOOT_STATUS_MASK; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 418 | break; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 419 | case MXT_FRAME_CRC_PASS: |
| 420 | if (val == MXT_FRAME_CRC_CHECK) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 421 | goto recheck; |
| 422 | break; |
| 423 | default: |
| 424 | return -EINVAL; |
| 425 | } |
| 426 | |
| 427 | if (val != state) { |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 428 | dev_err(&client->dev, "Invalid bootloader state %02X != %02X\n", |
| 429 | val, state); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 430 | return -EINVAL; |
| 431 | } |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 436 | static int mxt_unlock_bootloader(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 437 | { |
| 438 | u8 buf[2]; |
| 439 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 440 | buf[0] = MXT_UNLOCK_CMD_LSB; |
| 441 | buf[1] = MXT_UNLOCK_CMD_MSB; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 442 | |
| 443 | if (i2c_master_send(client, buf, 2) != 2) { |
| 444 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 445 | return -EIO; |
| 446 | } |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 451 | static int mxt_fw_write(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 452 | const u8 *data, unsigned int frame_size) |
| 453 | { |
| 454 | if (i2c_master_send(client, data, frame_size) != frame_size) { |
| 455 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); |
| 456 | return -EIO; |
| 457 | } |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 462 | static int __mxt_read_reg(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 463 | u16 reg, u16 len, void *val) |
| 464 | { |
| 465 | struct i2c_msg xfer[2]; |
| 466 | u8 buf[2]; |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 467 | int ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 468 | |
| 469 | buf[0] = reg & 0xff; |
| 470 | buf[1] = (reg >> 8) & 0xff; |
| 471 | |
| 472 | /* Write register */ |
| 473 | xfer[0].addr = client->addr; |
| 474 | xfer[0].flags = 0; |
| 475 | xfer[0].len = 2; |
| 476 | xfer[0].buf = buf; |
| 477 | |
| 478 | /* Read data */ |
| 479 | xfer[1].addr = client->addr; |
| 480 | xfer[1].flags = I2C_M_RD; |
| 481 | xfer[1].len = len; |
| 482 | xfer[1].buf = val; |
| 483 | |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 484 | ret = i2c_transfer(client->adapter, xfer, 2); |
| 485 | if (ret == 2) { |
| 486 | ret = 0; |
| 487 | } else { |
| 488 | if (ret >= 0) |
| 489 | ret = -EIO; |
| 490 | dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", |
| 491 | __func__, ret); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 494 | return ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 497 | 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] | 498 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 499 | return __mxt_read_reg(client, reg, 1, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 502 | static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, |
| 503 | const void *val) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 504 | { |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 505 | u8 *buf; |
| 506 | size_t count; |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 507 | int ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 508 | |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 509 | count = len + 2; |
| 510 | buf = kmalloc(count, GFP_KERNEL); |
| 511 | if (!buf) |
| 512 | return -ENOMEM; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 513 | |
| 514 | buf[0] = reg & 0xff; |
| 515 | buf[1] = (reg >> 8) & 0xff; |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 516 | memcpy(&buf[2], val, len); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 517 | |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 518 | ret = i2c_master_send(client, buf, count); |
| 519 | if (ret == count) { |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 520 | ret = 0; |
| 521 | } else { |
| 522 | if (ret >= 0) |
| 523 | ret = -EIO; |
| 524 | dev_err(&client->dev, "%s: i2c send failed (%d)\n", |
| 525 | __func__, ret); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 528 | kfree(buf); |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 529 | return ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 532 | 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] | 533 | { |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 534 | return __mxt_write_reg(client, reg, 1, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 537 | static struct mxt_object * |
| 538 | mxt_get_object(struct mxt_data *data, u8 type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 539 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 540 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 541 | int i; |
| 542 | |
| 543 | for (i = 0; i < data->info.object_num; i++) { |
| 544 | object = data->object_table + i; |
| 545 | if (object->type == type) |
| 546 | return object; |
| 547 | } |
| 548 | |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 549 | dev_err(&data->client->dev, "Invalid object type T%u\n", type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 550 | return NULL; |
| 551 | } |
| 552 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 553 | static int mxt_read_message(struct mxt_data *data, |
| 554 | struct mxt_message *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 555 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 556 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 557 | u16 reg; |
| 558 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 559 | object = mxt_get_object(data, MXT_GEN_MESSAGE_T5); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 560 | if (!object) |
| 561 | return -EINVAL; |
| 562 | |
| 563 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 564 | return __mxt_read_reg(data->client, reg, |
| 565 | sizeof(struct mxt_message), message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 568 | static int mxt_write_object(struct mxt_data *data, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 569 | u8 type, u8 offset, u8 val) |
| 570 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 571 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 572 | u16 reg; |
| 573 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 574 | object = mxt_get_object(data, type); |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 575 | if (!object || offset >= mxt_obj_size(object)) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 576 | return -EINVAL; |
| 577 | |
| 578 | reg = object->start_address; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 579 | return mxt_write_reg(data->client, reg + offset, val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 582 | static void mxt_input_button(struct mxt_data *data, struct mxt_message *message) |
| 583 | { |
| 584 | struct input_dev *input = data->input_dev; |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 585 | const struct mxt_platform_data *pdata = data->pdata; |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 586 | bool button; |
| 587 | int i; |
| 588 | |
| 589 | /* Active-low switch */ |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 590 | for (i = 0; i < pdata->t19_num_keys; i++) { |
| 591 | if (pdata->t19_keymap[i] == KEY_RESERVED) |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 592 | continue; |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 593 | button = !(message->message[0] & (1 << i)); |
| 594 | input_report_key(input, pdata->t19_keymap[i], button); |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 598 | static void mxt_input_touchevent(struct mxt_data *data, |
| 599 | struct mxt_message *message, int id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 600 | { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 601 | struct device *dev = &data->client->dev; |
| 602 | u8 status = message->message[0]; |
Daniel Kurtz | fba5bc3 | 2012-06-28 21:08:17 +0800 | [diff] [blame] | 603 | struct input_dev *input_dev = data->input_dev; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 604 | int x; |
| 605 | int y; |
| 606 | int area; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 607 | int pressure; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 608 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 609 | x = (message->message[1] << 4) | ((message->message[3] >> 4) & 0xf); |
| 610 | y = (message->message[2] << 4) | ((message->message[3] & 0xf)); |
| 611 | if (data->max_x < 1024) |
| 612 | x = x >> 2; |
| 613 | if (data->max_y < 1024) |
| 614 | y = y >> 2; |
| 615 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 616 | area = message->message[4]; |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 617 | pressure = message->message[5]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 618 | |
Daniel Kurtz | b2e459b | 2012-06-28 21:08:18 +0800 | [diff] [blame] | 619 | dev_dbg(dev, |
| 620 | "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n", |
| 621 | id, |
| 622 | (status & MXT_DETECT) ? 'D' : '.', |
| 623 | (status & MXT_PRESS) ? 'P' : '.', |
| 624 | (status & MXT_RELEASE) ? 'R' : '.', |
| 625 | (status & MXT_MOVE) ? 'M' : '.', |
| 626 | (status & MXT_VECTOR) ? 'V' : '.', |
| 627 | (status & MXT_AMP) ? 'A' : '.', |
| 628 | (status & MXT_SUPPRESS) ? 'S' : '.', |
| 629 | (status & MXT_UNGRIP) ? 'U' : '.', |
| 630 | x, y, area, pressure); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 631 | |
Daniel Kurtz | fba5bc3 | 2012-06-28 21:08:17 +0800 | [diff] [blame] | 632 | input_mt_slot(input_dev, id); |
| 633 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, |
| 634 | status & MXT_DETECT); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 635 | |
Daniel Kurtz | fba5bc3 | 2012-06-28 21:08:17 +0800 | [diff] [blame] | 636 | if (status & MXT_DETECT) { |
| 637 | input_report_abs(input_dev, ABS_MT_POSITION_X, x); |
| 638 | input_report_abs(input_dev, ABS_MT_POSITION_Y, y); |
| 639 | input_report_abs(input_dev, ABS_MT_PRESSURE, pressure); |
| 640 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area); |
| 641 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 644 | static u16 mxt_extract_T6_csum(const u8 *csum) |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 645 | { |
| 646 | return csum[0] | (csum[1] << 8) | (csum[2] << 16); |
| 647 | } |
| 648 | |
Daniel Kurtz | 04a7918 | 2012-06-28 21:08:21 +0800 | [diff] [blame] | 649 | static bool mxt_is_T9_message(struct mxt_data *data, struct mxt_message *msg) |
| 650 | { |
| 651 | u8 id = msg->reportid; |
| 652 | return (id >= data->T9_reportid_min && id <= data->T9_reportid_max); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 655 | static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 656 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 657 | struct mxt_message message; |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 658 | const u8 *payload = &message.message[0]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 659 | struct device *dev = &data->client->dev; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 660 | u8 reportid; |
Daniel Kurtz | 64464ae | 2012-06-28 21:08:23 +0800 | [diff] [blame] | 661 | bool update_input = false; |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 662 | u32 crc; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 663 | |
| 664 | do { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 665 | if (mxt_read_message(data, &message)) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 666 | dev_err(dev, "Failed to read message\n"); |
Nick Dyer | 8d4e163 | 2014-05-18 23:00:56 -0700 | [diff] [blame] | 667 | return IRQ_NONE; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | reportid = message.reportid; |
| 671 | |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 672 | if (reportid == data->T6_reportid) { |
| 673 | u8 status = payload[0]; |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 674 | |
| 675 | crc = mxt_extract_T6_csum(&payload[1]); |
| 676 | if (crc != data->config_crc) { |
| 677 | data->config_crc = crc; |
| 678 | complete(&data->crc_completion); |
| 679 | } |
| 680 | |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 681 | dev_dbg(dev, "Status: %02x Config Checksum: %06x\n", |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 682 | status, data->config_crc); |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 683 | |
| 684 | if (status & MXT_T6_STATUS_RESET) |
| 685 | complete(&data->reset_completion); |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 686 | } else if (mxt_is_T9_message(data, &message)) { |
| 687 | int id = reportid - data->T9_reportid_min; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 688 | mxt_input_touchevent(data, &message, id); |
Daniel Kurtz | 64464ae | 2012-06-28 21:08:23 +0800 | [diff] [blame] | 689 | update_input = true; |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 690 | } else if (message.reportid == data->T19_reportid) { |
| 691 | mxt_input_button(data, &message); |
| 692 | update_input = true; |
Daniel Kurtz | 64464ae | 2012-06-28 21:08:23 +0800 | [diff] [blame] | 693 | } else { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 694 | mxt_dump_message(dev, &message); |
Daniel Kurtz | 64464ae | 2012-06-28 21:08:23 +0800 | [diff] [blame] | 695 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 696 | } while (reportid != 0xff); |
| 697 | |
Daniel Kurtz | 64464ae | 2012-06-28 21:08:23 +0800 | [diff] [blame] | 698 | if (update_input) { |
| 699 | input_mt_report_pointer_emulation(data->input_dev, false); |
| 700 | input_sync(data->input_dev); |
| 701 | } |
| 702 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 703 | return IRQ_HANDLED; |
| 704 | } |
| 705 | |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 706 | static irqreturn_t mxt_interrupt(int irq, void *dev_id) |
| 707 | { |
| 708 | struct mxt_data *data = dev_id; |
| 709 | |
| 710 | if (data->in_bootloader) { |
| 711 | /* bootloader state transition completion */ |
| 712 | complete(&data->bl_completion); |
| 713 | return IRQ_HANDLED; |
| 714 | } |
| 715 | |
| 716 | return mxt_process_messages_until_invalid(data); |
| 717 | } |
| 718 | |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 719 | static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, |
| 720 | u8 value, bool wait) |
| 721 | { |
| 722 | u16 reg; |
| 723 | u8 command_register; |
| 724 | int timeout_counter = 0; |
| 725 | int ret; |
| 726 | |
| 727 | reg = data->T6_address + cmd_offset; |
| 728 | |
| 729 | ret = mxt_write_reg(data->client, reg, value); |
| 730 | if (ret) |
| 731 | return ret; |
| 732 | |
| 733 | if (!wait) |
| 734 | return 0; |
| 735 | |
| 736 | do { |
| 737 | msleep(20); |
| 738 | ret = __mxt_read_reg(data->client, reg, 1, &command_register); |
| 739 | if (ret) |
| 740 | return ret; |
| 741 | } while (command_register != 0 && timeout_counter++ <= 100); |
| 742 | |
| 743 | if (timeout_counter > 100) { |
| 744 | dev_err(&data->client->dev, "Command failed!\n"); |
| 745 | return -EIO; |
| 746 | } |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static int mxt_soft_reset(struct mxt_data *data) |
| 752 | { |
| 753 | struct device *dev = &data->client->dev; |
| 754 | int ret = 0; |
| 755 | |
| 756 | dev_info(dev, "Resetting chip\n"); |
| 757 | |
| 758 | reinit_completion(&data->reset_completion); |
| 759 | |
| 760 | ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_RESET_VALUE, false); |
| 761 | if (ret) |
| 762 | return ret; |
| 763 | |
| 764 | ret = mxt_wait_for_completion(data, &data->reset_completion, |
| 765 | MXT_RESET_TIMEOUT); |
| 766 | if (ret) |
| 767 | return ret; |
| 768 | |
| 769 | return 0; |
| 770 | } |
| 771 | |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 772 | static void mxt_update_crc(struct mxt_data *data, u8 cmd, u8 value) |
| 773 | { |
| 774 | /* |
| 775 | * On failure, CRC is set to 0 and config will always be |
| 776 | * downloaded. |
| 777 | */ |
| 778 | data->config_crc = 0; |
| 779 | reinit_completion(&data->crc_completion); |
| 780 | |
| 781 | mxt_t6_command(data, cmd, value, true); |
| 782 | |
| 783 | /* |
| 784 | * Wait for crc message. On failure, CRC is set to 0 and config will |
| 785 | * always be downloaded. |
| 786 | */ |
| 787 | mxt_wait_for_completion(data, &data->crc_completion, MXT_CRC_TIMEOUT); |
| 788 | } |
| 789 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 790 | static int mxt_check_reg_init(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 791 | { |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 792 | const struct mxt_platform_data *pdata = data->pdata; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 793 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 794 | struct device *dev = &data->client->dev; |
| 795 | int index = 0; |
Daniel Kurtz | cf94bc0 | 2012-06-28 21:08:13 +0800 | [diff] [blame] | 796 | int i, size; |
| 797 | int ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 798 | |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 799 | if (!pdata->config) { |
| 800 | dev_dbg(dev, "No cfg data defined, skipping reg init\n"); |
| 801 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 804 | mxt_update_crc(data, MXT_COMMAND_REPORTALL, 1); |
| 805 | |
| 806 | if (data->config_crc == pdata->config_crc) { |
| 807 | dev_info(dev, "Config CRC 0x%06X: OK\n", data->config_crc); |
| 808 | return 0; |
| 809 | } |
| 810 | |
| 811 | dev_info(dev, "Config CRC 0x%06X: does not match 0x%06X\n", |
| 812 | data->config_crc, pdata->config_crc); |
| 813 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 814 | for (i = 0; i < data->info.object_num; i++) { |
| 815 | object = data->object_table + i; |
| 816 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 817 | if (!mxt_object_writable(object->type)) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 818 | continue; |
| 819 | |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 820 | size = mxt_obj_size(object) * mxt_obj_instances(object); |
Daniel Kurtz | cf94bc0 | 2012-06-28 21:08:13 +0800 | [diff] [blame] | 821 | if (index + size > pdata->config_length) { |
| 822 | dev_err(dev, "Not enough config data!\n"); |
| 823 | return -EINVAL; |
Iiro Valkonen | 71749f5 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 824 | } |
Daniel Kurtz | cf94bc0 | 2012-06-28 21:08:13 +0800 | [diff] [blame] | 825 | |
| 826 | ret = __mxt_write_reg(data->client, object->start_address, |
| 827 | size, &pdata->config[index]); |
| 828 | if (ret) |
| 829 | return ret; |
| 830 | index += size; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 833 | mxt_update_crc(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE); |
| 834 | |
| 835 | ret = mxt_soft_reset(data); |
| 836 | if (ret) |
| 837 | return ret; |
| 838 | |
| 839 | dev_info(dev, "Config successfully updated\n"); |
| 840 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 841 | return 0; |
| 842 | } |
| 843 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 844 | static int mxt_make_highchg(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 845 | { |
| 846 | struct device *dev = &data->client->dev; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 847 | struct mxt_message message; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 848 | int count = 10; |
| 849 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 850 | |
| 851 | /* Read dummy message to make high CHG pin */ |
| 852 | do { |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 853 | error = mxt_read_message(data, &message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 854 | if (error) |
| 855 | return error; |
Iiro Valkonen | 26cdb1a | 2011-02-04 00:51:05 -0800 | [diff] [blame] | 856 | } while (message.reportid != 0xff && --count); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 857 | |
| 858 | if (!count) { |
| 859 | dev_err(dev, "CHG pin isn't cleared\n"); |
| 860 | return -EBUSY; |
| 861 | } |
| 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 866 | static int mxt_get_info(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 867 | { |
| 868 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 869 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 870 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 871 | |
Daniel Kurtz | 23003a84 | 2012-06-28 21:08:14 +0800 | [diff] [blame] | 872 | /* Read 7-byte info block starting at address 0 */ |
| 873 | error = __mxt_read_reg(client, MXT_INFO, sizeof(*info), info); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 874 | if (error) |
| 875 | return error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 880 | static int mxt_get_object_table(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 881 | { |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 882 | struct i2c_client *client = data->client; |
| 883 | size_t table_size; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 884 | int error; |
| 885 | int i; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 886 | u8 reportid; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 887 | |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 888 | table_size = data->info.object_num * sizeof(struct mxt_object); |
| 889 | error = __mxt_read_reg(client, MXT_OBJECT_START, table_size, |
| 890 | data->object_table); |
| 891 | if (error) |
| 892 | return error; |
| 893 | |
| 894 | /* Valid Report IDs start counting from 1 */ |
| 895 | reportid = 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 896 | for (i = 0; i < data->info.object_num; i++) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 897 | struct mxt_object *object = data->object_table + i; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 898 | u8 min_id, max_id; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 899 | |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 900 | le16_to_cpus(&object->start_address); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 901 | |
| 902 | if (object->num_report_ids) { |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 903 | min_id = reportid; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 904 | reportid += object->num_report_ids * |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 905 | mxt_obj_instances(object); |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 906 | max_id = reportid - 1; |
| 907 | } else { |
| 908 | min_id = 0; |
| 909 | max_id = 0; |
| 910 | } |
| 911 | |
| 912 | dev_dbg(&data->client->dev, |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 913 | "T%u Start:%u Size:%zu Instances:%zu Report IDs:%u-%u\n", |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 914 | object->type, object->start_address, |
| 915 | mxt_obj_size(object), mxt_obj_instances(object), |
| 916 | min_id, max_id); |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 917 | |
| 918 | switch (object->type) { |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 919 | case MXT_GEN_COMMAND_T6: |
| 920 | data->T6_reportid = min_id; |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 921 | data->T6_address = object->start_address; |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 922 | break; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 923 | case MXT_TOUCH_MULTI_T9: |
| 924 | data->T9_reportid_min = min_id; |
| 925 | data->T9_reportid_max = max_id; |
| 926 | break; |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 927 | case MXT_SPT_GPIOPWM_T19: |
| 928 | data->T19_reportid = min_id; |
| 929 | break; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | |
| 933 | return 0; |
| 934 | } |
| 935 | |
Daniel Kurtz | 7d4fa10 | 2012-06-28 21:08:19 +0800 | [diff] [blame] | 936 | static void mxt_free_object_table(struct mxt_data *data) |
| 937 | { |
| 938 | kfree(data->object_table); |
| 939 | data->object_table = NULL; |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 940 | data->T6_reportid = 0; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 941 | data->T9_reportid_min = 0; |
| 942 | data->T9_reportid_max = 0; |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 943 | data->T19_reportid = 0; |
Daniel Kurtz | 7d4fa10 | 2012-06-28 21:08:19 +0800 | [diff] [blame] | 944 | } |
| 945 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 946 | static int mxt_initialize(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 947 | { |
| 948 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 949 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 950 | int error; |
| 951 | u8 val; |
| 952 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 953 | error = mxt_get_info(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 954 | if (error) |
| 955 | return error; |
| 956 | |
| 957 | data->object_table = kcalloc(info->object_num, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 958 | sizeof(struct mxt_object), |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 959 | GFP_KERNEL); |
| 960 | if (!data->object_table) { |
| 961 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 962 | return -ENOMEM; |
| 963 | } |
| 964 | |
| 965 | /* Get object table information */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 966 | error = mxt_get_object_table(data); |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 967 | if (error) { |
| 968 | dev_err(&client->dev, "Error %d reading object table\n", error); |
Daniel Kurtz | 7d4fa10 | 2012-06-28 21:08:19 +0800 | [diff] [blame] | 969 | goto err_free_object_table; |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 970 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 971 | |
| 972 | /* Check register init values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 973 | error = mxt_check_reg_init(data); |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 974 | if (error) { |
| 975 | dev_err(&client->dev, "Error %d initializing configuration\n", |
| 976 | error); |
Daniel Kurtz | 7d4fa10 | 2012-06-28 21:08:19 +0800 | [diff] [blame] | 977 | goto err_free_object_table; |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 978 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 979 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 980 | /* Update matrix size at info struct */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 981 | error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 982 | if (error) |
Daniel Kurtz | 7d4fa10 | 2012-06-28 21:08:19 +0800 | [diff] [blame] | 983 | goto err_free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 984 | info->matrix_xsize = val; |
| 985 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 986 | error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 987 | if (error) |
Daniel Kurtz | 7d4fa10 | 2012-06-28 21:08:19 +0800 | [diff] [blame] | 988 | goto err_free_object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 989 | info->matrix_ysize = val; |
| 990 | |
| 991 | dev_info(&client->dev, |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 992 | "Family: %u Variant: %u Firmware V%u.%u.%02X\n", |
Daniel Kurtz | e0e0269 | 2012-06-28 21:08:15 +0800 | [diff] [blame] | 993 | info->family_id, info->variant_id, info->version >> 4, |
| 994 | info->version & 0xf, info->build); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 995 | |
| 996 | dev_info(&client->dev, |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 997 | "Matrix X Size: %u Matrix Y Size: %u Objects: %u\n", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 998 | info->matrix_xsize, info->matrix_ysize, |
| 999 | info->object_num); |
| 1000 | |
| 1001 | return 0; |
Daniel Kurtz | 7d4fa10 | 2012-06-28 21:08:19 +0800 | [diff] [blame] | 1002 | |
| 1003 | err_free_object_table: |
| 1004 | mxt_free_object_table(data); |
| 1005 | return error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1008 | static void mxt_calc_resolution(struct mxt_data *data) |
| 1009 | { |
| 1010 | unsigned int max_x = data->pdata->x_size - 1; |
| 1011 | unsigned int max_y = data->pdata->y_size - 1; |
| 1012 | |
| 1013 | if (data->pdata->orient & MXT_XY_SWITCH) { |
| 1014 | data->max_x = max_y; |
| 1015 | data->max_y = max_x; |
| 1016 | } else { |
| 1017 | data->max_x = max_x; |
| 1018 | data->max_y = max_y; |
| 1019 | } |
| 1020 | } |
| 1021 | |
Daniel Kurtz | b19fc9e | 2012-06-28 21:08:16 +0800 | [diff] [blame] | 1022 | /* Firmware Version is returned as Major.Minor.Build */ |
| 1023 | static ssize_t mxt_fw_version_show(struct device *dev, |
| 1024 | struct device_attribute *attr, char *buf) |
| 1025 | { |
| 1026 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1027 | struct mxt_info *info = &data->info; |
| 1028 | return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n", |
| 1029 | info->version >> 4, info->version & 0xf, info->build); |
| 1030 | } |
| 1031 | |
| 1032 | /* Hardware Version is returned as FamilyID.VariantID */ |
| 1033 | static ssize_t mxt_hw_version_show(struct device *dev, |
| 1034 | struct device_attribute *attr, char *buf) |
| 1035 | { |
| 1036 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1037 | struct mxt_info *info = &data->info; |
| 1038 | return scnprintf(buf, PAGE_SIZE, "%u.%u\n", |
| 1039 | info->family_id, info->variant_id); |
| 1040 | } |
| 1041 | |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1042 | static ssize_t mxt_show_instance(char *buf, int count, |
| 1043 | struct mxt_object *object, int instance, |
| 1044 | const u8 *val) |
| 1045 | { |
| 1046 | int i; |
| 1047 | |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 1048 | if (mxt_obj_instances(object) > 1) |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1049 | count += scnprintf(buf + count, PAGE_SIZE - count, |
| 1050 | "Instance %u\n", instance); |
| 1051 | |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 1052 | for (i = 0; i < mxt_obj_size(object); i++) |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1053 | count += scnprintf(buf + count, PAGE_SIZE - count, |
| 1054 | "\t[%2u]: %02x (%d)\n", i, val[i], val[i]); |
| 1055 | count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 1056 | |
| 1057 | return count; |
| 1058 | } |
| 1059 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1060 | static ssize_t mxt_object_show(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1061 | struct device_attribute *attr, char *buf) |
| 1062 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1063 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1064 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1065 | int count = 0; |
| 1066 | int i, j; |
| 1067 | int error; |
Daniel Kurtz | 43a91d5 | 2012-06-28 21:08:08 +0800 | [diff] [blame] | 1068 | u8 *obuf; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1069 | |
Daniel Kurtz | 43a91d5 | 2012-06-28 21:08:08 +0800 | [diff] [blame] | 1070 | /* Pre-allocate buffer large enough to hold max sized object. */ |
| 1071 | obuf = kmalloc(256, GFP_KERNEL); |
| 1072 | if (!obuf) |
| 1073 | return -ENOMEM; |
| 1074 | |
| 1075 | error = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1076 | for (i = 0; i < data->info.object_num; i++) { |
| 1077 | object = data->object_table + i; |
| 1078 | |
Daniel Kurtz | 9163095 | 2012-06-28 21:08:09 +0800 | [diff] [blame] | 1079 | if (!mxt_object_readable(object->type)) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1080 | continue; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1081 | |
Daniel Kurtz | 9163095 | 2012-06-28 21:08:09 +0800 | [diff] [blame] | 1082 | count += scnprintf(buf + count, PAGE_SIZE - count, |
| 1083 | "T%u:\n", object->type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1084 | |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 1085 | for (j = 0; j < mxt_obj_instances(object); j++) { |
| 1086 | u16 size = mxt_obj_size(object); |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1087 | u16 addr = object->start_address + j * size; |
Daniel Kurtz | 43a91d5 | 2012-06-28 21:08:08 +0800 | [diff] [blame] | 1088 | |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1089 | error = __mxt_read_reg(data->client, addr, size, obuf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1090 | if (error) |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1091 | goto done; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1092 | |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1093 | count = mxt_show_instance(buf, count, object, j, obuf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1094 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1097 | done: |
Daniel Kurtz | 43a91d5 | 2012-06-28 21:08:08 +0800 | [diff] [blame] | 1098 | kfree(obuf); |
| 1099 | return error ?: count; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1102 | static int mxt_load_fw(struct device *dev, const char *fn) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1103 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1104 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1105 | struct i2c_client *client = data->client; |
| 1106 | const struct firmware *fw = NULL; |
| 1107 | unsigned int frame_size; |
| 1108 | unsigned int pos = 0; |
| 1109 | int ret; |
| 1110 | |
| 1111 | ret = request_firmware(&fw, fn, dev); |
| 1112 | if (ret) { |
| 1113 | dev_err(dev, "Unable to open firmware %s\n", fn); |
| 1114 | return ret; |
| 1115 | } |
| 1116 | |
| 1117 | /* Change to the bootloader mode */ |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1118 | data->in_bootloader = true; |
| 1119 | |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 1120 | ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_BOOT_VALUE, false); |
| 1121 | if (ret) |
| 1122 | goto release_firmware; |
| 1123 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1124 | msleep(MXT_RESET_TIME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1125 | |
| 1126 | /* Change to slave address of bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1127 | if (client->addr == MXT_APP_LOW) |
| 1128 | client->addr = MXT_BOOT_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1129 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1130 | client->addr = MXT_BOOT_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1131 | |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1132 | reinit_completion(&data->bl_completion); |
| 1133 | |
| 1134 | ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1135 | if (ret) |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1136 | goto disable_irq; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1137 | |
| 1138 | /* Unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1139 | mxt_unlock_bootloader(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1140 | |
| 1141 | while (pos < fw->size) { |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1142 | ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1143 | if (ret) |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1144 | goto disable_irq; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1145 | |
| 1146 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); |
| 1147 | |
| 1148 | /* We should add 2 at frame size as the the firmware data is not |
| 1149 | * included the CRC bytes. |
| 1150 | */ |
| 1151 | frame_size += 2; |
| 1152 | |
| 1153 | /* Write one frame to device */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1154 | mxt_fw_write(client, fw->data + pos, frame_size); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1155 | |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1156 | ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1157 | if (ret) |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1158 | goto disable_irq; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1159 | |
| 1160 | pos += frame_size; |
| 1161 | |
| 1162 | dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size); |
| 1163 | } |
| 1164 | |
Benson Leung | a0434b7 | 2014-05-18 23:03:09 -0700 | [diff] [blame] | 1165 | /* Wait for flash. */ |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 1166 | ret = mxt_wait_for_completion(data, &data->bl_completion, |
| 1167 | MXT_FW_RESET_TIME); |
Benson Leung | a0434b7 | 2014-05-18 23:03:09 -0700 | [diff] [blame] | 1168 | if (ret) |
| 1169 | goto disable_irq; |
| 1170 | |
| 1171 | /* |
| 1172 | * Wait for device to reset. Some bootloader versions do not assert |
| 1173 | * the CHG line after bootloading has finished, so ignore potential |
| 1174 | * errors. |
| 1175 | */ |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 1176 | mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME); |
Benson Leung | a0434b7 | 2014-05-18 23:03:09 -0700 | [diff] [blame] | 1177 | |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1178 | data->in_bootloader = false; |
| 1179 | |
| 1180 | disable_irq: |
| 1181 | disable_irq(data->irq); |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 1182 | release_firmware: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1183 | release_firmware(fw); |
| 1184 | |
| 1185 | /* Change to slave address of application */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1186 | if (client->addr == MXT_BOOT_LOW) |
| 1187 | client->addr = MXT_APP_LOW; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1188 | else |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1189 | client->addr = MXT_APP_HIGH; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1190 | |
| 1191 | return ret; |
| 1192 | } |
| 1193 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1194 | static ssize_t mxt_update_fw_store(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1195 | struct device_attribute *attr, |
| 1196 | const char *buf, size_t count) |
| 1197 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1198 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1199 | int error; |
| 1200 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1201 | error = mxt_load_fw(dev, MXT_FW_NAME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1202 | if (error) { |
| 1203 | dev_err(dev, "The firmware update failed(%d)\n", error); |
| 1204 | count = error; |
| 1205 | } else { |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 1206 | dev_info(dev, "The firmware update succeeded\n"); |
| 1207 | |
Daniel Kurtz | 7d4fa10 | 2012-06-28 21:08:19 +0800 | [diff] [blame] | 1208 | mxt_free_object_table(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1209 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1210 | mxt_initialize(data); |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1211 | |
| 1212 | enable_irq(data->irq); |
| 1213 | |
| 1214 | error = mxt_make_highchg(data); |
| 1215 | if (error) |
| 1216 | return error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1217 | } |
| 1218 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1219 | return count; |
| 1220 | } |
| 1221 | |
Daniel Kurtz | b19fc9e | 2012-06-28 21:08:16 +0800 | [diff] [blame] | 1222 | static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); |
| 1223 | static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); |
Daniel Kurtz | 71b3e93 | 2012-05-08 22:30:14 -0700 | [diff] [blame] | 1224 | static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); |
| 1225 | static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1226 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1227 | static struct attribute *mxt_attrs[] = { |
Daniel Kurtz | b19fc9e | 2012-06-28 21:08:16 +0800 | [diff] [blame] | 1228 | &dev_attr_fw_version.attr, |
| 1229 | &dev_attr_hw_version.attr, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1230 | &dev_attr_object.attr, |
| 1231 | &dev_attr_update_fw.attr, |
| 1232 | NULL |
| 1233 | }; |
| 1234 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1235 | static const struct attribute_group mxt_attr_group = { |
| 1236 | .attrs = mxt_attrs, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1237 | }; |
| 1238 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1239 | static void mxt_start(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1240 | { |
| 1241 | /* Touch enable */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1242 | mxt_write_object(data, |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 1243 | MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1246 | static void mxt_stop(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1247 | { |
| 1248 | /* Touch disable */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1249 | mxt_write_object(data, |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 1250 | MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1253 | static int mxt_input_open(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1254 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1255 | struct mxt_data *data = input_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1256 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1257 | mxt_start(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1258 | |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1262 | static void mxt_input_close(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1263 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1264 | struct mxt_data *data = input_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1265 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1266 | mxt_stop(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 1269 | static int mxt_probe(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1270 | const struct i2c_device_id *id) |
| 1271 | { |
Jingoo Han | c838cb3 | 2013-12-05 19:21:10 -0800 | [diff] [blame] | 1272 | const struct mxt_platform_data *pdata = dev_get_platdata(&client->dev); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1273 | struct mxt_data *data; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1274 | struct input_dev *input_dev; |
| 1275 | int error; |
Daniel Kurtz | cb15911 | 2012-06-28 21:08:22 +0800 | [diff] [blame] | 1276 | unsigned int num_mt_slots; |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 1277 | unsigned int mt_flags = 0; |
| 1278 | int i; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1279 | |
Iiro Valkonen | 919ed89 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1280 | if (!pdata) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1281 | return -EINVAL; |
| 1282 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1283 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1284 | input_dev = input_allocate_device(); |
| 1285 | if (!data || !input_dev) { |
| 1286 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 1287 | error = -ENOMEM; |
| 1288 | goto err_free_mem; |
| 1289 | } |
| 1290 | |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 1291 | input_dev->name = "Atmel maXTouch Touchscreen"; |
Daniel Kurtz | ec02ac2 | 2012-06-28 21:08:02 +0800 | [diff] [blame] | 1292 | snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0", |
| 1293 | client->adapter->nr, client->addr); |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 1294 | |
Daniel Kurtz | ec02ac2 | 2012-06-28 21:08:02 +0800 | [diff] [blame] | 1295 | input_dev->phys = data->phys; |
| 1296 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1297 | input_dev->id.bustype = BUS_I2C; |
| 1298 | input_dev->dev.parent = &client->dev; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1299 | input_dev->open = mxt_input_open; |
| 1300 | input_dev->close = mxt_input_close; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1301 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1302 | data->client = client; |
| 1303 | data->input_dev = input_dev; |
| 1304 | data->pdata = pdata; |
| 1305 | data->irq = client->irq; |
| 1306 | |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1307 | init_completion(&data->bl_completion); |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 1308 | init_completion(&data->reset_completion); |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame^] | 1309 | init_completion(&data->crc_completion); |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1310 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1311 | mxt_calc_resolution(data); |
| 1312 | |
Daniel Kurtz | cb15911 | 2012-06-28 21:08:22 +0800 | [diff] [blame] | 1313 | error = mxt_initialize(data); |
| 1314 | if (error) |
| 1315 | goto err_free_mem; |
| 1316 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1317 | __set_bit(EV_ABS, input_dev->evbit); |
| 1318 | __set_bit(EV_KEY, input_dev->evbit); |
| 1319 | __set_bit(BTN_TOUCH, input_dev->keybit); |
| 1320 | |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 1321 | if (pdata->t19_num_keys) { |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 1322 | __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); |
| 1323 | |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 1324 | for (i = 0; i < pdata->t19_num_keys; i++) |
| 1325 | if (pdata->t19_keymap[i] != KEY_RESERVED) |
| 1326 | input_set_capability(input_dev, EV_KEY, |
| 1327 | pdata->t19_keymap[i]); |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 1328 | |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 1329 | mt_flags |= INPUT_MT_POINTER; |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 1330 | |
| 1331 | input_abs_set_res(input_dev, ABS_X, MXT_PIXELS_PER_MM); |
| 1332 | input_abs_set_res(input_dev, ABS_Y, MXT_PIXELS_PER_MM); |
| 1333 | input_abs_set_res(input_dev, ABS_MT_POSITION_X, |
| 1334 | MXT_PIXELS_PER_MM); |
| 1335 | input_abs_set_res(input_dev, ABS_MT_POSITION_Y, |
| 1336 | MXT_PIXELS_PER_MM); |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 1337 | |
| 1338 | input_dev->name = "Atmel maXTouch Touchpad"; |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 1339 | } |
| 1340 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1341 | /* For single touch */ |
| 1342 | input_set_abs_params(input_dev, ABS_X, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1343 | 0, data->max_x, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1344 | input_set_abs_params(input_dev, ABS_Y, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1345 | 0, data->max_y, 0, 0); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 1346 | input_set_abs_params(input_dev, ABS_PRESSURE, |
| 1347 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1348 | |
| 1349 | /* For multi touch */ |
Daniel Kurtz | cb15911 | 2012-06-28 21:08:22 +0800 | [diff] [blame] | 1350 | num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1; |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 1351 | error = input_mt_init_slots(input_dev, num_mt_slots, mt_flags); |
Daniel Kurtz | e1e1658 | 2012-06-28 21:08:04 +0800 | [diff] [blame] | 1352 | if (error) |
Daniel Kurtz | cb15911 | 2012-06-28 21:08:22 +0800 | [diff] [blame] | 1353 | goto err_free_object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1354 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1355 | 0, MXT_MAX_AREA, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1356 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1357 | 0, data->max_x, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1358 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 1359 | 0, data->max_y, 0, 0); |
Yufeng Shen | 28ac293 | 2011-08-16 00:40:54 -0700 | [diff] [blame] | 1360 | input_set_abs_params(input_dev, ABS_MT_PRESSURE, |
| 1361 | 0, 255, 0, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1362 | |
| 1363 | input_set_drvdata(input_dev, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1364 | i2c_set_clientdata(client, data); |
| 1365 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1366 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, |
Lars-Peter Clausen | 9b7e31b | 2012-07-04 13:02:56 -0700 | [diff] [blame] | 1367 | pdata->irqflags | IRQF_ONESHOT, |
Dmitry Torokhov | f053ea8 | 2012-07-07 16:18:33 -0700 | [diff] [blame] | 1368 | client->name, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1369 | if (error) { |
| 1370 | dev_err(&client->dev, "Failed to register interrupt\n"); |
| 1371 | goto err_free_object; |
| 1372 | } |
| 1373 | |
Iiro Valkonen | 08960a0 | 2011-04-12 23:16:40 -0700 | [diff] [blame] | 1374 | error = mxt_make_highchg(data); |
| 1375 | if (error) |
| 1376 | goto err_free_irq; |
| 1377 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1378 | error = input_register_device(input_dev); |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 1379 | if (error) { |
| 1380 | dev_err(&client->dev, "Error %d registering input device\n", |
| 1381 | error); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1382 | goto err_free_irq; |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 1383 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1384 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1385 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 1386 | if (error) { |
| 1387 | dev_err(&client->dev, "Failure %d creating sysfs group\n", |
| 1388 | error); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1389 | goto err_unregister_device; |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 1390 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1391 | |
| 1392 | return 0; |
| 1393 | |
| 1394 | err_unregister_device: |
| 1395 | input_unregister_device(input_dev); |
| 1396 | input_dev = NULL; |
| 1397 | err_free_irq: |
| 1398 | free_irq(client->irq, data); |
| 1399 | err_free_object: |
| 1400 | kfree(data->object_table); |
| 1401 | err_free_mem: |
| 1402 | input_free_device(input_dev); |
| 1403 | kfree(data); |
| 1404 | return error; |
| 1405 | } |
| 1406 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 1407 | static int mxt_remove(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1408 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1409 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1410 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1411 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1412 | free_irq(data->irq, data); |
| 1413 | input_unregister_device(data->input_dev); |
| 1414 | kfree(data->object_table); |
| 1415 | kfree(data); |
| 1416 | |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
Daniel Kurtz | 3a73c81 | 2012-05-08 22:29:14 -0700 | [diff] [blame] | 1420 | #ifdef CONFIG_PM_SLEEP |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1421 | static int mxt_suspend(struct device *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1422 | { |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1423 | struct i2c_client *client = to_i2c_client(dev); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1424 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1425 | struct input_dev *input_dev = data->input_dev; |
| 1426 | |
| 1427 | mutex_lock(&input_dev->mutex); |
| 1428 | |
| 1429 | if (input_dev->users) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1430 | mxt_stop(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1431 | |
| 1432 | mutex_unlock(&input_dev->mutex); |
| 1433 | |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1437 | static int mxt_resume(struct device *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1438 | { |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 1439 | struct i2c_client *client = to_i2c_client(dev); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1440 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1441 | struct input_dev *input_dev = data->input_dev; |
| 1442 | |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 1443 | mxt_soft_reset(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1444 | |
| 1445 | mutex_lock(&input_dev->mutex); |
| 1446 | |
| 1447 | if (input_dev->users) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1448 | mxt_start(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1449 | |
| 1450 | mutex_unlock(&input_dev->mutex); |
| 1451 | |
| 1452 | return 0; |
| 1453 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1454 | #endif |
| 1455 | |
Daniel Kurtz | 3a73c81 | 2012-05-08 22:29:14 -0700 | [diff] [blame] | 1456 | static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume); |
| 1457 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1458 | static const struct i2c_device_id mxt_id[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1459 | { "qt602240_ts", 0 }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1460 | { "atmel_mxt_ts", 0 }, |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 1461 | { "atmel_mxt_tp", 0 }, |
Chris Leech | 46ee2a0 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 1462 | { "mXT224", 0 }, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1463 | { } |
| 1464 | }; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1465 | MODULE_DEVICE_TABLE(i2c, mxt_id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1466 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1467 | static struct i2c_driver mxt_driver = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1468 | .driver = { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1469 | .name = "atmel_mxt_ts", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1470 | .owner = THIS_MODULE, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1471 | .pm = &mxt_pm_ops, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1472 | }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1473 | .probe = mxt_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 1474 | .remove = mxt_remove, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1475 | .id_table = mxt_id, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1476 | }; |
| 1477 | |
Axel Lin | 1b92c1c | 2012-03-16 23:05:41 -0700 | [diff] [blame] | 1478 | module_i2c_driver(mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1479 | |
| 1480 | /* Module information */ |
| 1481 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1482 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1483 | MODULE_LICENSE("GPL"); |