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 |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 5 | * Copyright (C) 2011-2014 Atmel Corporation |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 6 | * Copyright (C) 2012 Google, Inc. |
| 7 | * |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 8 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 18 | #include <linux/init.h> |
| 19 | #include <linux/completion.h> |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> |
| 21 | #include <linux/firmware.h> |
| 22 | #include <linux/i2c.h> |
Dmitry Torokhov | 964de52 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 23 | #include <linux/i2c/atmel_mxt_ts.h> |
Joonyoung Shim | 8b86c1c | 2011-04-12 23:18:59 -0700 | [diff] [blame] | 24 | #include <linux/input/mt.h> |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
Stephen Warren | 78188be | 2014-07-23 12:23:23 -0700 | [diff] [blame] | 26 | #include <linux/of.h> |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 27 | #include <linux/slab.h> |
| 28 | |
| 29 | /* Version */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 30 | #define MXT_VER_20 20 |
| 31 | #define MXT_VER_21 21 |
| 32 | #define MXT_VER_22 22 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 33 | |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 34 | /* Firmware files */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 35 | #define MXT_FW_NAME "maxtouch.fw" |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 36 | #define MXT_CFG_NAME "maxtouch.cfg" |
| 37 | #define MXT_CFG_MAGIC "OBP_RAW V1" |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 38 | |
| 39 | /* Registers */ |
Daniel Kurtz | 23003a84 | 2012-06-28 21:08:14 +0800 | [diff] [blame] | 40 | #define MXT_INFO 0x00 |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 41 | #define MXT_FAMILY_ID 0x00 |
| 42 | #define MXT_VARIANT_ID 0x01 |
| 43 | #define MXT_VERSION 0x02 |
| 44 | #define MXT_BUILD 0x03 |
| 45 | #define MXT_MATRIX_X_SIZE 0x04 |
| 46 | #define MXT_MATRIX_Y_SIZE 0x05 |
| 47 | #define MXT_OBJECT_NUM 0x06 |
| 48 | #define MXT_OBJECT_START 0x07 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 49 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 50 | #define MXT_OBJECT_SIZE 6 |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 51 | #define MXT_INFO_CHECKSUM_SIZE 3 |
| 52 | #define MXT_MAX_BLOCK_WRITE 256 |
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 | |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 83 | /* MXT_GEN_MESSAGE_T5 object */ |
| 84 | #define MXT_RPTID_NOMSG 0xff |
| 85 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 86 | /* MXT_GEN_COMMAND_T6 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 87 | #define MXT_COMMAND_RESET 0 |
| 88 | #define MXT_COMMAND_BACKUPNV 1 |
| 89 | #define MXT_COMMAND_CALIBRATE 2 |
| 90 | #define MXT_COMMAND_REPORTALL 3 |
| 91 | #define MXT_COMMAND_DIAGNOSTIC 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 92 | |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 93 | /* Define for T6 status byte */ |
| 94 | #define MXT_T6_STATUS_RESET (1 << 7) |
Nick Dyer | 497767d | 2014-07-23 12:47:50 -0700 | [diff] [blame] | 95 | #define MXT_T6_STATUS_OFL (1 << 6) |
| 96 | #define MXT_T6_STATUS_SIGERR (1 << 5) |
| 97 | #define MXT_T6_STATUS_CAL (1 << 4) |
| 98 | #define MXT_T6_STATUS_CFGERR (1 << 3) |
| 99 | #define MXT_T6_STATUS_COMSERR (1 << 2) |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 100 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 101 | /* MXT_GEN_POWER_T7 field */ |
Linus Torvalds | 7f40548 | 2014-12-31 12:59:34 -0800 | [diff] [blame] | 102 | #define MXT_POWER_IDLEACQINT 0 |
| 103 | #define MXT_POWER_ACTVACQINT 1 |
| 104 | #define MXT_POWER_ACTV2IDLETO 2 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 105 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 106 | /* MXT_GEN_ACQUIRE_T8 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 107 | #define MXT_ACQUIRE_CHRGTIME 0 |
| 108 | #define MXT_ACQUIRE_TCHDRIFT 2 |
| 109 | #define MXT_ACQUIRE_DRIFTST 3 |
| 110 | #define MXT_ACQUIRE_TCHAUTOCAL 4 |
| 111 | #define MXT_ACQUIRE_SYNC 5 |
| 112 | #define MXT_ACQUIRE_ATCHCALST 6 |
| 113 | #define MXT_ACQUIRE_ATCHCALSTHR 7 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 114 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 115 | /* MXT_TOUCH_MULTI_T9 field */ |
Linus Torvalds | 7f40548 | 2014-12-31 12:59:34 -0800 | [diff] [blame] | 116 | #define MXT_TOUCH_CTRL 0 |
Nick Dyer | 61dc1ab | 2014-05-18 23:16:49 -0700 | [diff] [blame] | 117 | #define MXT_T9_ORIENT 9 |
| 118 | #define MXT_T9_RANGE 18 |
| 119 | |
Nick Dyer | f3889ed | 2014-05-18 23:22:04 -0700 | [diff] [blame] | 120 | /* MXT_TOUCH_MULTI_T9 status */ |
| 121 | #define MXT_T9_UNGRIP (1 << 0) |
| 122 | #define MXT_T9_SUPPRESS (1 << 1) |
| 123 | #define MXT_T9_AMP (1 << 2) |
| 124 | #define MXT_T9_VECTOR (1 << 3) |
| 125 | #define MXT_T9_MOVE (1 << 4) |
| 126 | #define MXT_T9_RELEASE (1 << 5) |
| 127 | #define MXT_T9_PRESS (1 << 6) |
| 128 | #define MXT_T9_DETECT (1 << 7) |
| 129 | |
Nick Dyer | 61dc1ab | 2014-05-18 23:16:49 -0700 | [diff] [blame] | 130 | struct t9_range { |
| 131 | u16 x; |
| 132 | u16 y; |
| 133 | } __packed; |
| 134 | |
Nick Dyer | f3889ed | 2014-05-18 23:22:04 -0700 | [diff] [blame] | 135 | /* MXT_TOUCH_MULTI_T9 orient */ |
| 136 | #define MXT_T9_ORIENT_SWITCH (1 << 0) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 137 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 138 | /* MXT_PROCI_GRIPFACE_T20 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 139 | #define MXT_GRIPFACE_CTRL 0 |
| 140 | #define MXT_GRIPFACE_XLOGRIP 1 |
| 141 | #define MXT_GRIPFACE_XHIGRIP 2 |
| 142 | #define MXT_GRIPFACE_YLOGRIP 3 |
| 143 | #define MXT_GRIPFACE_YHIGRIP 4 |
| 144 | #define MXT_GRIPFACE_MAXTCHS 5 |
| 145 | #define MXT_GRIPFACE_SZTHR1 7 |
| 146 | #define MXT_GRIPFACE_SZTHR2 8 |
| 147 | #define MXT_GRIPFACE_SHPTHR1 9 |
| 148 | #define MXT_GRIPFACE_SHPTHR2 10 |
| 149 | #define MXT_GRIPFACE_SUPEXTTO 11 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 150 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 151 | /* MXT_PROCI_NOISE field */ |
| 152 | #define MXT_NOISE_CTRL 0 |
| 153 | #define MXT_NOISE_OUTFLEN 1 |
| 154 | #define MXT_NOISE_GCAFUL_LSB 3 |
| 155 | #define MXT_NOISE_GCAFUL_MSB 4 |
| 156 | #define MXT_NOISE_GCAFLL_LSB 5 |
| 157 | #define MXT_NOISE_GCAFLL_MSB 6 |
| 158 | #define MXT_NOISE_ACTVGCAFVALID 7 |
| 159 | #define MXT_NOISE_NOISETHR 8 |
| 160 | #define MXT_NOISE_FREQHOPSCALE 10 |
| 161 | #define MXT_NOISE_FREQ0 11 |
| 162 | #define MXT_NOISE_FREQ1 12 |
| 163 | #define MXT_NOISE_FREQ2 13 |
| 164 | #define MXT_NOISE_FREQ3 14 |
| 165 | #define MXT_NOISE_FREQ4 15 |
| 166 | #define MXT_NOISE_IDLEGCAFVALID 16 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 167 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 168 | /* MXT_SPT_COMMSCONFIG_T18 */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 169 | #define MXT_COMMS_CTRL 0 |
| 170 | #define MXT_COMMS_CMD 1 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 171 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 172 | /* MXT_SPT_CTECONFIG_T28 field */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 173 | #define MXT_CTE_CTRL 0 |
| 174 | #define MXT_CTE_CMD 1 |
| 175 | #define MXT_CTE_MODE 2 |
| 176 | #define MXT_CTE_IDLEGCAFDEPTH 3 |
| 177 | #define MXT_CTE_ACTVGCAFDEPTH 4 |
Joonyoung Shim | 979a72d | 2011-03-14 21:41:34 -0700 | [diff] [blame] | 178 | #define MXT_CTE_VOLTAGE 5 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 179 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 180 | #define MXT_VOLTAGE_DEFAULT 2700000 |
| 181 | #define MXT_VOLTAGE_STEP 10000 |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 182 | |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 183 | /* Define for MXT_GEN_COMMAND_T6 */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 184 | #define MXT_BOOT_VALUE 0xa5 |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 185 | #define MXT_RESET_VALUE 0x01 |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 186 | #define MXT_BACKUP_VALUE 0x55 |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 187 | |
| 188 | /* Delay times */ |
Linus Torvalds | 8343bce | 2013-03-09 10:31:01 -0800 | [diff] [blame] | 189 | #define MXT_BACKUP_TIME 50 /* msec */ |
| 190 | #define MXT_RESET_TIME 200 /* msec */ |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 191 | #define MXT_RESET_TIMEOUT 3000 /* msec */ |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame] | 192 | #define MXT_CRC_TIMEOUT 1000 /* msec */ |
Benson Leung | a0434b7 | 2014-05-18 23:03:09 -0700 | [diff] [blame] | 193 | #define MXT_FW_RESET_TIME 3000 /* msec */ |
| 194 | #define MXT_FW_CHG_TIMEOUT 300 /* msec */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 195 | |
| 196 | /* Command to unlock bootloader */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 197 | #define MXT_UNLOCK_CMD_MSB 0xaa |
| 198 | #define MXT_UNLOCK_CMD_LSB 0xdc |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 199 | |
| 200 | /* Bootloader mode status */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 201 | #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */ |
| 202 | #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */ |
| 203 | #define MXT_FRAME_CRC_CHECK 0x02 |
| 204 | #define MXT_FRAME_CRC_FAIL 0x03 |
| 205 | #define MXT_FRAME_CRC_PASS 0x04 |
| 206 | #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */ |
| 207 | #define MXT_BOOT_STATUS_MASK 0x3f |
Nick Dyer | e57a66a | 2014-05-18 23:13:40 -0700 | [diff] [blame] | 208 | #define MXT_BOOT_EXTENDED_ID (1 << 5) |
| 209 | #define MXT_BOOT_ID_MASK 0x1f |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 210 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 211 | /* Touchscreen absolute values */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 212 | #define MXT_MAX_AREA 0xff |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 213 | |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 214 | #define MXT_PIXELS_PER_MM 20 |
| 215 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 216 | struct mxt_info { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 217 | u8 family_id; |
| 218 | u8 variant_id; |
| 219 | u8 version; |
| 220 | u8 build; |
| 221 | u8 matrix_xsize; |
| 222 | u8 matrix_ysize; |
| 223 | u8 object_num; |
| 224 | }; |
| 225 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 226 | struct mxt_object { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 227 | u8 type; |
| 228 | u16 start_address; |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 229 | u8 size_minus_one; |
| 230 | u8 instances_minus_one; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 231 | u8 num_report_ids; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 232 | } __packed; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 233 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 234 | /* Each client has this additional data */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 235 | struct mxt_data { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 236 | struct i2c_client *client; |
| 237 | struct input_dev *input_dev; |
Daniel Kurtz | ec02ac2 | 2012-06-28 21:08:02 +0800 | [diff] [blame] | 238 | char phys[64]; /* device physical location */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 239 | const struct mxt_platform_data *pdata; |
| 240 | struct mxt_object *object_table; |
| 241 | struct mxt_info info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 242 | unsigned int irq; |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 243 | unsigned int max_x; |
| 244 | unsigned int max_y; |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 245 | bool in_bootloader; |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 246 | u16 mem_size; |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 247 | u8 max_reportid; |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame] | 248 | u32 config_crc; |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 249 | u32 info_crc; |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 250 | u8 bootloader_addr; |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 251 | u8 *msg_buf; |
Nick Dyer | 497767d | 2014-07-23 12:47:50 -0700 | [diff] [blame] | 252 | u8 t6_status; |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 253 | bool update_input; |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 254 | u8 last_message_count; |
| 255 | u8 num_touchids; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 256 | |
| 257 | /* Cached parameters from object table */ |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 258 | u16 T5_address; |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 259 | u8 T5_msg_size; |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 260 | u8 T6_reportid; |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 261 | u16 T6_address; |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 262 | u16 T7_address; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 263 | u8 T9_reportid_min; |
| 264 | u8 T9_reportid_max; |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 265 | u8 T19_reportid; |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 266 | u16 T44_address; |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 267 | |
| 268 | /* for fw update in bootloader */ |
| 269 | struct completion bl_completion; |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 270 | |
| 271 | /* for reset handling */ |
| 272 | struct completion reset_completion; |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame] | 273 | |
| 274 | /* for config update handling */ |
| 275 | struct completion crc_completion; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 276 | }; |
| 277 | |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 278 | static size_t mxt_obj_size(const struct mxt_object *obj) |
| 279 | { |
| 280 | return obj->size_minus_one + 1; |
| 281 | } |
| 282 | |
| 283 | static size_t mxt_obj_instances(const struct mxt_object *obj) |
| 284 | { |
| 285 | return obj->instances_minus_one + 1; |
| 286 | } |
| 287 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 288 | static bool mxt_object_readable(unsigned int type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 289 | { |
| 290 | switch (type) { |
Iiro Valkonen | 81c88a7 | 2011-07-04 03:08:25 -0700 | [diff] [blame] | 291 | case MXT_GEN_COMMAND_T6: |
| 292 | case MXT_GEN_POWER_T7: |
| 293 | case MXT_GEN_ACQUIRE_T8: |
| 294 | case MXT_GEN_DATASOURCE_T53: |
| 295 | case MXT_TOUCH_MULTI_T9: |
| 296 | case MXT_TOUCH_KEYARRAY_T15: |
| 297 | case MXT_TOUCH_PROXIMITY_T23: |
| 298 | case MXT_TOUCH_PROXKEY_T52: |
| 299 | case MXT_PROCI_GRIPFACE_T20: |
| 300 | case MXT_PROCG_NOISE_T22: |
| 301 | case MXT_PROCI_ONETOUCH_T24: |
| 302 | case MXT_PROCI_TWOTOUCH_T27: |
| 303 | case MXT_PROCI_GRIP_T40: |
| 304 | case MXT_PROCI_PALM_T41: |
| 305 | case MXT_PROCI_TOUCHSUPPRESSION_T42: |
| 306 | case MXT_PROCI_STYLUS_T47: |
| 307 | case MXT_PROCG_NOISESUPPRESSION_T48: |
| 308 | case MXT_SPT_COMMSCONFIG_T18: |
| 309 | case MXT_SPT_GPIOPWM_T19: |
| 310 | case MXT_SPT_SELFTEST_T25: |
| 311 | case MXT_SPT_CTECONFIG_T28: |
| 312 | case MXT_SPT_USERDATA_T38: |
| 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 | |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 321 | static void mxt_dump_message(struct mxt_data *data, u8 *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 322 | { |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 323 | dev_dbg(&data->client->dev, "message: %*ph\n", |
| 324 | data->T5_msg_size, message); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 327 | static int mxt_wait_for_completion(struct mxt_data *data, |
| 328 | struct completion *comp, |
| 329 | unsigned int timeout_ms) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 330 | { |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 331 | struct device *dev = &data->client->dev; |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 332 | unsigned long timeout = msecs_to_jiffies(timeout_ms); |
| 333 | long ret; |
| 334 | |
| 335 | ret = wait_for_completion_interruptible_timeout(comp, timeout); |
| 336 | if (ret < 0) { |
| 337 | return ret; |
| 338 | } else if (ret == 0) { |
| 339 | dev_err(dev, "Wait for completion timed out.\n"); |
| 340 | return -ETIMEDOUT; |
| 341 | } |
| 342 | return 0; |
| 343 | } |
| 344 | |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 345 | static int mxt_bootloader_read(struct mxt_data *data, |
| 346 | u8 *val, unsigned int count) |
| 347 | { |
| 348 | int ret; |
| 349 | struct i2c_msg msg; |
| 350 | |
| 351 | msg.addr = data->bootloader_addr; |
| 352 | msg.flags = data->client->flags & I2C_M_TEN; |
| 353 | msg.flags |= I2C_M_RD; |
| 354 | msg.len = count; |
| 355 | msg.buf = val; |
| 356 | |
| 357 | ret = i2c_transfer(data->client->adapter, &msg, 1); |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 358 | if (ret == 1) { |
| 359 | ret = 0; |
| 360 | } else { |
| 361 | ret = ret < 0 ? ret : -EIO; |
| 362 | dev_err(&data->client->dev, "%s: i2c recv failed (%d)\n", |
| 363 | __func__, ret); |
| 364 | } |
| 365 | |
| 366 | return ret; |
| 367 | } |
| 368 | |
| 369 | static int mxt_bootloader_write(struct mxt_data *data, |
| 370 | const u8 * const val, unsigned int count) |
| 371 | { |
| 372 | int ret; |
| 373 | struct i2c_msg msg; |
| 374 | |
| 375 | msg.addr = data->bootloader_addr; |
| 376 | msg.flags = data->client->flags & I2C_M_TEN; |
| 377 | msg.len = count; |
| 378 | msg.buf = (u8 *)val; |
| 379 | |
| 380 | ret = i2c_transfer(data->client->adapter, &msg, 1); |
| 381 | if (ret == 1) { |
| 382 | ret = 0; |
| 383 | } else { |
| 384 | ret = ret < 0 ? ret : -EIO; |
| 385 | dev_err(&data->client->dev, "%s: i2c send failed (%d)\n", |
| 386 | __func__, ret); |
| 387 | } |
| 388 | |
| 389 | return ret; |
| 390 | } |
| 391 | |
Nick Dyer | 8efaa5e | 2014-07-23 12:45:49 -0700 | [diff] [blame] | 392 | static int mxt_lookup_bootloader_address(struct mxt_data *data, bool retry) |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 393 | { |
| 394 | u8 appmode = data->client->addr; |
| 395 | u8 bootloader; |
| 396 | |
| 397 | switch (appmode) { |
| 398 | case 0x4a: |
| 399 | case 0x4b: |
Nick Dyer | 44a0bab | 2014-07-23 12:45:26 -0700 | [diff] [blame] | 400 | /* Chips after 1664S use different scheme */ |
Nick Dyer | 8efaa5e | 2014-07-23 12:45:49 -0700 | [diff] [blame] | 401 | if (retry || data->info.family_id >= 0xa2) { |
Nick Dyer | 44a0bab | 2014-07-23 12:45:26 -0700 | [diff] [blame] | 402 | bootloader = appmode - 0x24; |
| 403 | break; |
| 404 | } |
| 405 | /* Fall through for normal case */ |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 406 | case 0x4c: |
| 407 | case 0x4d: |
| 408 | case 0x5a: |
| 409 | case 0x5b: |
| 410 | bootloader = appmode - 0x26; |
| 411 | break; |
Dmitry Torokhov | 6cd1ab0 | 2014-08-08 09:28:45 -0700 | [diff] [blame] | 412 | |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 413 | default: |
| 414 | dev_err(&data->client->dev, |
| 415 | "Appmode i2c address 0x%02x not found\n", |
| 416 | appmode); |
| 417 | return -EINVAL; |
| 418 | } |
| 419 | |
| 420 | data->bootloader_addr = bootloader; |
| 421 | return 0; |
| 422 | } |
| 423 | |
Dmitry Torokhov | 6cd1ab0 | 2014-08-08 09:28:45 -0700 | [diff] [blame] | 424 | static int mxt_probe_bootloader(struct mxt_data *data, bool alt_address) |
Nick Dyer | a9fdd1e | 2014-07-23 12:41:58 -0700 | [diff] [blame] | 425 | { |
| 426 | struct device *dev = &data->client->dev; |
Dmitry Torokhov | 6cd1ab0 | 2014-08-08 09:28:45 -0700 | [diff] [blame] | 427 | int error; |
Nick Dyer | a9fdd1e | 2014-07-23 12:41:58 -0700 | [diff] [blame] | 428 | u8 val; |
| 429 | bool crc_failure; |
| 430 | |
Dmitry Torokhov | 6cd1ab0 | 2014-08-08 09:28:45 -0700 | [diff] [blame] | 431 | error = mxt_lookup_bootloader_address(data, alt_address); |
| 432 | if (error) |
| 433 | return error; |
Nick Dyer | a9fdd1e | 2014-07-23 12:41:58 -0700 | [diff] [blame] | 434 | |
Dmitry Torokhov | 6cd1ab0 | 2014-08-08 09:28:45 -0700 | [diff] [blame] | 435 | error = mxt_bootloader_read(data, &val, 1); |
| 436 | if (error) |
| 437 | return error; |
Nick Dyer | a9fdd1e | 2014-07-23 12:41:58 -0700 | [diff] [blame] | 438 | |
| 439 | /* Check app crc fail mode */ |
| 440 | crc_failure = (val & ~MXT_BOOT_STATUS_MASK) == MXT_APP_CRC_FAIL; |
| 441 | |
| 442 | dev_err(dev, "Detected bootloader, status:%02X%s\n", |
| 443 | val, crc_failure ? ", APP_CRC_FAIL" : ""); |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
Nick Dyer | e57a66a | 2014-05-18 23:13:40 -0700 | [diff] [blame] | 448 | static u8 mxt_get_bootloader_version(struct mxt_data *data, u8 val) |
| 449 | { |
| 450 | struct device *dev = &data->client->dev; |
| 451 | u8 buf[3]; |
| 452 | |
| 453 | if (val & MXT_BOOT_EXTENDED_ID) { |
| 454 | if (mxt_bootloader_read(data, &buf[0], 3) != 0) { |
| 455 | dev_err(dev, "%s: i2c failure\n", __func__); |
Nick Dyer | 68807a0 | 2014-06-07 23:17:26 -0700 | [diff] [blame] | 456 | return val; |
Nick Dyer | e57a66a | 2014-05-18 23:13:40 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | dev_dbg(dev, "Bootloader ID:%d Version:%d\n", buf[1], buf[2]); |
| 460 | |
| 461 | return buf[0]; |
| 462 | } else { |
| 463 | dev_dbg(dev, "Bootloader ID:%d\n", val & MXT_BOOT_ID_MASK); |
| 464 | |
| 465 | return val; |
| 466 | } |
| 467 | } |
| 468 | |
Nick Dyer | 385deb9 | 2014-07-23 12:42:40 -0700 | [diff] [blame] | 469 | static int mxt_check_bootloader(struct mxt_data *data, unsigned int state, |
| 470 | bool wait) |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 471 | { |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 472 | struct device *dev = &data->client->dev; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 473 | u8 val; |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 474 | int ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 475 | |
| 476 | recheck: |
Nick Dyer | 385deb9 | 2014-07-23 12:42:40 -0700 | [diff] [blame] | 477 | if (wait) { |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 478 | /* |
| 479 | * In application update mode, the interrupt |
| 480 | * line signals state transitions. We must wait for the |
| 481 | * CHG assertion before reading the status byte. |
| 482 | * Once the status byte has been read, the line is deasserted. |
| 483 | */ |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 484 | ret = mxt_wait_for_completion(data, &data->bl_completion, |
| 485 | MXT_FW_CHG_TIMEOUT); |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 486 | if (ret) { |
| 487 | /* |
| 488 | * TODO: handle -ERESTARTSYS better by terminating |
| 489 | * fw update process before returning to userspace |
| 490 | * by writing length 0x000 to device (iff we are in |
| 491 | * WAITING_FRAME_DATA state). |
| 492 | */ |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 493 | dev_err(dev, "Update wait error %d\n", ret); |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 494 | return ret; |
| 495 | } |
| 496 | } |
| 497 | |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 498 | ret = mxt_bootloader_read(data, &val, 1); |
| 499 | if (ret) |
| 500 | return ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 501 | |
Nick Dyer | e57a66a | 2014-05-18 23:13:40 -0700 | [diff] [blame] | 502 | if (state == MXT_WAITING_BOOTLOAD_CMD) |
| 503 | val = mxt_get_bootloader_version(data, val); |
| 504 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 505 | switch (state) { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 506 | case MXT_WAITING_BOOTLOAD_CMD: |
| 507 | case MXT_WAITING_FRAME_DATA: |
Nick Dyer | a9fdd1e | 2014-07-23 12:41:58 -0700 | [diff] [blame] | 508 | case MXT_APP_CRC_FAIL: |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 509 | val &= ~MXT_BOOT_STATUS_MASK; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 510 | break; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 511 | case MXT_FRAME_CRC_PASS: |
Nick Dyer | f943c74 | 2014-05-18 23:14:20 -0700 | [diff] [blame] | 512 | if (val == MXT_FRAME_CRC_CHECK) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 513 | goto recheck; |
Nick Dyer | f943c74 | 2014-05-18 23:14:20 -0700 | [diff] [blame] | 514 | } else if (val == MXT_FRAME_CRC_FAIL) { |
| 515 | dev_err(dev, "Bootloader CRC fail\n"); |
| 516 | return -EINVAL; |
| 517 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 518 | break; |
| 519 | default: |
| 520 | return -EINVAL; |
| 521 | } |
| 522 | |
| 523 | if (val != state) { |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 524 | dev_err(dev, "Invalid bootloader state %02X != %02X\n", |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 525 | val, state); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 526 | return -EINVAL; |
| 527 | } |
| 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
Nick Dyer | 8efaa5e | 2014-07-23 12:45:49 -0700 | [diff] [blame] | 532 | static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 533 | { |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 534 | int ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 535 | u8 buf[2]; |
| 536 | |
Nick Dyer | 8efaa5e | 2014-07-23 12:45:49 -0700 | [diff] [blame] | 537 | if (unlock) { |
| 538 | buf[0] = MXT_UNLOCK_CMD_LSB; |
| 539 | buf[1] = MXT_UNLOCK_CMD_MSB; |
| 540 | } else { |
| 541 | buf[0] = 0x01; |
| 542 | buf[1] = 0x01; |
| 543 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 544 | |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 545 | ret = mxt_bootloader_write(data, buf, 2); |
| 546 | if (ret) |
| 547 | return ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 552 | static int __mxt_read_reg(struct i2c_client *client, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 553 | u16 reg, u16 len, void *val) |
| 554 | { |
| 555 | struct i2c_msg xfer[2]; |
| 556 | u8 buf[2]; |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 557 | int ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 558 | |
| 559 | buf[0] = reg & 0xff; |
| 560 | buf[1] = (reg >> 8) & 0xff; |
| 561 | |
| 562 | /* Write register */ |
| 563 | xfer[0].addr = client->addr; |
| 564 | xfer[0].flags = 0; |
| 565 | xfer[0].len = 2; |
| 566 | xfer[0].buf = buf; |
| 567 | |
| 568 | /* Read data */ |
| 569 | xfer[1].addr = client->addr; |
| 570 | xfer[1].flags = I2C_M_RD; |
| 571 | xfer[1].len = len; |
| 572 | xfer[1].buf = val; |
| 573 | |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 574 | ret = i2c_transfer(client->adapter, xfer, 2); |
| 575 | if (ret == 2) { |
| 576 | ret = 0; |
| 577 | } else { |
| 578 | if (ret >= 0) |
| 579 | ret = -EIO; |
| 580 | dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", |
| 581 | __func__, ret); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 584 | return ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 587 | static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, |
| 588 | const void *val) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 589 | { |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 590 | u8 *buf; |
| 591 | size_t count; |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 592 | int ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 593 | |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 594 | count = len + 2; |
| 595 | buf = kmalloc(count, GFP_KERNEL); |
| 596 | if (!buf) |
| 597 | return -ENOMEM; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 598 | |
| 599 | buf[0] = reg & 0xff; |
| 600 | buf[1] = (reg >> 8) & 0xff; |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 601 | memcpy(&buf[2], val, len); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 602 | |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 603 | ret = i2c_master_send(client, buf, count); |
| 604 | if (ret == count) { |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 605 | ret = 0; |
| 606 | } else { |
| 607 | if (ret >= 0) |
| 608 | ret = -EIO; |
| 609 | dev_err(&client->dev, "%s: i2c send failed (%d)\n", |
| 610 | __func__, ret); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 613 | kfree(buf); |
Daniel Kurtz | 771733e | 2012-06-28 21:08:11 +0800 | [diff] [blame] | 614 | return ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 617 | 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] | 618 | { |
Daniel Kurtz | 9638ab7 | 2012-06-28 21:08:12 +0800 | [diff] [blame] | 619 | return __mxt_write_reg(client, reg, 1, &val); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 622 | static struct mxt_object * |
| 623 | mxt_get_object(struct mxt_data *data, u8 type) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 624 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 625 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 626 | int i; |
| 627 | |
| 628 | for (i = 0; i < data->info.object_num; i++) { |
| 629 | object = data->object_table + i; |
| 630 | if (object->type == type) |
| 631 | return object; |
| 632 | } |
| 633 | |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 634 | dev_warn(&data->client->dev, "Invalid object type T%u\n", type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 635 | return NULL; |
| 636 | } |
| 637 | |
Nick Dyer | 497767d | 2014-07-23 12:47:50 -0700 | [diff] [blame] | 638 | static void mxt_proc_t6_messages(struct mxt_data *data, u8 *msg) |
| 639 | { |
| 640 | struct device *dev = &data->client->dev; |
| 641 | u8 status = msg[1]; |
| 642 | u32 crc = msg[2] | (msg[3] << 8) | (msg[4] << 16); |
| 643 | |
| 644 | complete(&data->crc_completion); |
| 645 | |
| 646 | if (crc != data->config_crc) { |
| 647 | data->config_crc = crc; |
| 648 | dev_dbg(dev, "T6 Config Checksum: 0x%06X\n", crc); |
| 649 | } |
| 650 | |
| 651 | /* Detect reset */ |
| 652 | if (status & MXT_T6_STATUS_RESET) |
| 653 | complete(&data->reset_completion); |
| 654 | |
| 655 | /* Output debug if status has changed */ |
| 656 | if (status != data->t6_status) |
| 657 | dev_dbg(dev, "T6 Status 0x%02X%s%s%s%s%s%s%s\n", |
| 658 | status, |
| 659 | status == 0 ? " OK" : "", |
| 660 | status & MXT_T6_STATUS_RESET ? " RESET" : "", |
| 661 | status & MXT_T6_STATUS_OFL ? " OFL" : "", |
| 662 | status & MXT_T6_STATUS_SIGERR ? " SIGERR" : "", |
| 663 | status & MXT_T6_STATUS_CAL ? " CAL" : "", |
| 664 | status & MXT_T6_STATUS_CFGERR ? " CFGERR" : "", |
| 665 | status & MXT_T6_STATUS_COMSERR ? " COMSERR" : ""); |
| 666 | |
| 667 | /* Save current status */ |
| 668 | data->t6_status = status; |
| 669 | } |
| 670 | |
Linus Torvalds | 7f40548 | 2014-12-31 12:59:34 -0800 | [diff] [blame] | 671 | static int mxt_write_object(struct mxt_data *data, |
| 672 | u8 type, u8 offset, u8 val) |
| 673 | { |
| 674 | struct mxt_object *object; |
| 675 | u16 reg; |
| 676 | |
| 677 | object = mxt_get_object(data, type); |
| 678 | if (!object || offset >= mxt_obj_size(object)) |
| 679 | return -EINVAL; |
| 680 | |
| 681 | reg = object->start_address; |
| 682 | return mxt_write_reg(data->client, reg + offset, val); |
| 683 | } |
| 684 | |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 685 | static void mxt_input_button(struct mxt_data *data, u8 *message) |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 686 | { |
| 687 | struct input_dev *input = data->input_dev; |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 688 | const struct mxt_platform_data *pdata = data->pdata; |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 689 | bool button; |
| 690 | int i; |
| 691 | |
| 692 | /* Active-low switch */ |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 693 | for (i = 0; i < pdata->t19_num_keys; i++) { |
| 694 | if (pdata->t19_keymap[i] == KEY_RESERVED) |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 695 | continue; |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 696 | button = !(message[1] & (1 << i)); |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 697 | input_report_key(input, pdata->t19_keymap[i], button); |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | |
Benson Leung | b735fbe | 2014-07-23 12:22:27 -0700 | [diff] [blame] | 701 | static void mxt_input_sync(struct mxt_data *data) |
Nick Dyer | eef820d | 2014-05-18 23:22:22 -0700 | [diff] [blame] | 702 | { |
Benson Leung | b735fbe | 2014-07-23 12:22:27 -0700 | [diff] [blame] | 703 | input_mt_report_pointer_emulation(data->input_dev, |
| 704 | data->pdata->t19_num_keys); |
| 705 | input_sync(data->input_dev); |
Nick Dyer | eef820d | 2014-05-18 23:22:22 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 708 | static void mxt_proc_t9_message(struct mxt_data *data, u8 *message) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 709 | { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 710 | struct device *dev = &data->client->dev; |
Daniel Kurtz | fba5bc3 | 2012-06-28 21:08:17 +0800 | [diff] [blame] | 711 | struct input_dev *input_dev = data->input_dev; |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 712 | int id; |
| 713 | u8 status; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 714 | int x; |
| 715 | int y; |
| 716 | int area; |
Nick Dyer | fea9e46 | 2014-05-18 23:21:48 -0700 | [diff] [blame] | 717 | int amplitude; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 718 | |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 719 | id = message[0] - data->T9_reportid_min; |
| 720 | status = message[1]; |
| 721 | x = (message[2] << 4) | ((message[4] >> 4) & 0xf); |
| 722 | y = (message[3] << 4) | ((message[4] & 0xf)); |
Nick Dyer | eef820d | 2014-05-18 23:22:22 -0700 | [diff] [blame] | 723 | |
| 724 | /* Handle 10/12 bit switching */ |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 725 | if (data->max_x < 1024) |
Nick Dyer | eef820d | 2014-05-18 23:22:22 -0700 | [diff] [blame] | 726 | x >>= 2; |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 727 | if (data->max_y < 1024) |
Nick Dyer | eef820d | 2014-05-18 23:22:22 -0700 | [diff] [blame] | 728 | y >>= 2; |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 729 | |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 730 | area = message[5]; |
| 731 | amplitude = message[6]; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 732 | |
Daniel Kurtz | b2e459b | 2012-06-28 21:08:18 +0800 | [diff] [blame] | 733 | dev_dbg(dev, |
| 734 | "[%u] %c%c%c%c%c%c%c%c x: %5u y: %5u area: %3u amp: %3u\n", |
| 735 | id, |
Nick Dyer | f3889ed | 2014-05-18 23:22:04 -0700 | [diff] [blame] | 736 | (status & MXT_T9_DETECT) ? 'D' : '.', |
| 737 | (status & MXT_T9_PRESS) ? 'P' : '.', |
| 738 | (status & MXT_T9_RELEASE) ? 'R' : '.', |
| 739 | (status & MXT_T9_MOVE) ? 'M' : '.', |
| 740 | (status & MXT_T9_VECTOR) ? 'V' : '.', |
| 741 | (status & MXT_T9_AMP) ? 'A' : '.', |
| 742 | (status & MXT_T9_SUPPRESS) ? 'S' : '.', |
| 743 | (status & MXT_T9_UNGRIP) ? 'U' : '.', |
Nick Dyer | fea9e46 | 2014-05-18 23:21:48 -0700 | [diff] [blame] | 744 | x, y, area, amplitude); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 745 | |
Daniel Kurtz | fba5bc3 | 2012-06-28 21:08:17 +0800 | [diff] [blame] | 746 | input_mt_slot(input_dev, id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 747 | |
Nick Dyer | f3889ed | 2014-05-18 23:22:04 -0700 | [diff] [blame] | 748 | if (status & MXT_T9_DETECT) { |
Nick Dyer | eef820d | 2014-05-18 23:22:22 -0700 | [diff] [blame] | 749 | /* |
| 750 | * Multiple bits may be set if the host is slow to read |
| 751 | * the status messages, indicating all the events that |
| 752 | * have happened. |
| 753 | */ |
| 754 | if (status & MXT_T9_RELEASE) { |
| 755 | input_mt_report_slot_state(input_dev, |
| 756 | MT_TOOL_FINGER, 0); |
Benson Leung | b735fbe | 2014-07-23 12:22:27 -0700 | [diff] [blame] | 757 | mxt_input_sync(data); |
Nick Dyer | eef820d | 2014-05-18 23:22:22 -0700 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /* Touch active */ |
| 761 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 1); |
Daniel Kurtz | fba5bc3 | 2012-06-28 21:08:17 +0800 | [diff] [blame] | 762 | input_report_abs(input_dev, ABS_MT_POSITION_X, x); |
| 763 | input_report_abs(input_dev, ABS_MT_POSITION_Y, y); |
Nick Dyer | fea9e46 | 2014-05-18 23:21:48 -0700 | [diff] [blame] | 764 | input_report_abs(input_dev, ABS_MT_PRESSURE, amplitude); |
Daniel Kurtz | fba5bc3 | 2012-06-28 21:08:17 +0800 | [diff] [blame] | 765 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area); |
Nick Dyer | eef820d | 2014-05-18 23:22:22 -0700 | [diff] [blame] | 766 | } else { |
| 767 | /* Touch no longer active, close out slot */ |
| 768 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0); |
Daniel Kurtz | fba5bc3 | 2012-06-28 21:08:17 +0800 | [diff] [blame] | 769 | } |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 770 | |
| 771 | data->update_input = true; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 774 | static int mxt_proc_message(struct mxt_data *data, u8 *message) |
Daniel Kurtz | 04a7918 | 2012-06-28 21:08:21 +0800 | [diff] [blame] | 775 | { |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 776 | u8 report_id = message[0]; |
| 777 | |
| 778 | if (report_id == MXT_RPTID_NOMSG) |
| 779 | return 0; |
| 780 | |
| 781 | if (report_id == data->T6_reportid) { |
| 782 | mxt_proc_t6_messages(data, message); |
| 783 | } else if (!data->input_dev) { |
| 784 | /* |
| 785 | * Do not report events if input device |
| 786 | * is not yet registered. |
| 787 | */ |
| 788 | mxt_dump_message(data, message); |
| 789 | } else if (report_id >= data->T9_reportid_min |
| 790 | && report_id <= data->T9_reportid_max) { |
| 791 | mxt_proc_t9_message(data, message); |
| 792 | } else if (report_id == data->T19_reportid) { |
| 793 | mxt_input_button(data, message); |
| 794 | data->update_input = true; |
| 795 | } else { |
| 796 | mxt_dump_message(data, message); |
| 797 | } |
| 798 | |
| 799 | return 1; |
| 800 | } |
| 801 | |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 802 | static int mxt_read_and_process_messages(struct mxt_data *data, u8 count) |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 803 | { |
| 804 | struct device *dev = &data->client->dev; |
| 805 | int ret; |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 806 | int i; |
| 807 | u8 num_valid = 0; |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 808 | |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 809 | /* Safety check for msg_buf */ |
| 810 | if (count > data->max_reportid) |
| 811 | return -EINVAL; |
| 812 | |
| 813 | /* Process remaining messages if necessary */ |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 814 | ret = __mxt_read_reg(data->client, data->T5_address, |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 815 | data->T5_msg_size * count, data->msg_buf); |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 816 | if (ret) { |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 817 | dev_err(dev, "Failed to read %u messages (%d)\n", count, ret); |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 818 | return ret; |
| 819 | } |
| 820 | |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 821 | for (i = 0; i < count; i++) { |
| 822 | ret = mxt_proc_message(data, |
| 823 | data->msg_buf + data->T5_msg_size * i); |
| 824 | |
| 825 | if (ret == 1) |
| 826 | num_valid++; |
| 827 | } |
| 828 | |
| 829 | /* return number of messages read */ |
| 830 | return num_valid; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 833 | static irqreturn_t mxt_process_messages_t44(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 834 | { |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 835 | struct device *dev = &data->client->dev; |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 836 | int ret; |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 837 | u8 count, num_left; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 838 | |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 839 | /* Read T44 and T5 together */ |
| 840 | ret = __mxt_read_reg(data->client, data->T44_address, |
| 841 | data->T5_msg_size + 1, data->msg_buf); |
| 842 | if (ret) { |
| 843 | dev_err(dev, "Failed to read T44 and T5 (%d)\n", ret); |
| 844 | return IRQ_NONE; |
| 845 | } |
| 846 | |
| 847 | count = data->msg_buf[0]; |
| 848 | |
| 849 | if (count == 0) { |
Nick Dyer | 651b460 | 2014-09-09 11:24:21 -0700 | [diff] [blame] | 850 | /* |
| 851 | * This condition is caused by the CHG line being configured |
| 852 | * in Mode 0. It results in unnecessary I2C operations but it |
| 853 | * is benign. |
| 854 | */ |
| 855 | dev_dbg(dev, "Interrupt triggered but zero messages\n"); |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 856 | return IRQ_NONE; |
| 857 | } else if (count > data->max_reportid) { |
| 858 | dev_err(dev, "T44 count %d exceeded max report id\n", count); |
| 859 | count = data->max_reportid; |
| 860 | } |
| 861 | |
| 862 | /* Process first message */ |
| 863 | ret = mxt_proc_message(data, data->msg_buf + 1); |
| 864 | if (ret < 0) { |
| 865 | dev_warn(dev, "Unexpected invalid message\n"); |
| 866 | return IRQ_NONE; |
| 867 | } |
| 868 | |
| 869 | num_left = count - 1; |
| 870 | |
| 871 | /* Process remaining messages if necessary */ |
| 872 | if (num_left) { |
| 873 | ret = mxt_read_and_process_messages(data, num_left); |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 874 | if (ret < 0) |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 875 | goto end; |
| 876 | else if (ret != num_left) |
| 877 | dev_warn(dev, "Unexpected invalid message\n"); |
| 878 | } |
| 879 | |
| 880 | end: |
| 881 | if (data->update_input) { |
| 882 | mxt_input_sync(data); |
| 883 | data->update_input = false; |
| 884 | } |
| 885 | |
| 886 | return IRQ_HANDLED; |
| 887 | } |
| 888 | |
| 889 | static int mxt_process_messages_until_invalid(struct mxt_data *data) |
| 890 | { |
| 891 | struct device *dev = &data->client->dev; |
| 892 | int count, read; |
| 893 | u8 tries = 2; |
| 894 | |
| 895 | count = data->max_reportid; |
| 896 | |
| 897 | /* Read messages until we force an invalid */ |
| 898 | do { |
| 899 | read = mxt_read_and_process_messages(data, count); |
| 900 | if (read < count) |
| 901 | return 0; |
| 902 | } while (--tries); |
| 903 | |
| 904 | if (data->update_input) { |
| 905 | mxt_input_sync(data); |
| 906 | data->update_input = false; |
| 907 | } |
| 908 | |
| 909 | dev_err(dev, "CHG pin isn't cleared\n"); |
| 910 | return -EBUSY; |
| 911 | } |
| 912 | |
| 913 | static irqreturn_t mxt_process_messages(struct mxt_data *data) |
| 914 | { |
| 915 | int total_handled, num_handled; |
| 916 | u8 count = data->last_message_count; |
| 917 | |
| 918 | if (count < 1 || count > data->max_reportid) |
| 919 | count = 1; |
| 920 | |
| 921 | /* include final invalid message */ |
| 922 | total_handled = mxt_read_and_process_messages(data, count + 1); |
| 923 | if (total_handled < 0) |
| 924 | return IRQ_NONE; |
| 925 | /* if there were invalid messages, then we are done */ |
| 926 | else if (total_handled <= count) |
| 927 | goto update_count; |
| 928 | |
| 929 | /* keep reading two msgs until one is invalid or reportid limit */ |
| 930 | do { |
| 931 | num_handled = mxt_read_and_process_messages(data, 2); |
| 932 | if (num_handled < 0) |
Nick Dyer | 8d4e163 | 2014-05-18 23:00:56 -0700 | [diff] [blame] | 933 | return IRQ_NONE; |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 934 | |
| 935 | total_handled += num_handled; |
| 936 | |
| 937 | if (num_handled < 2) |
| 938 | break; |
| 939 | } while (total_handled < data->num_touchids); |
| 940 | |
| 941 | update_count: |
| 942 | data->last_message_count = total_handled; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 943 | |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 944 | if (data->update_input) { |
Benson Leung | b735fbe | 2014-07-23 12:22:27 -0700 | [diff] [blame] | 945 | mxt_input_sync(data); |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 946 | data->update_input = false; |
| 947 | } |
Daniel Kurtz | 64464ae | 2012-06-28 21:08:23 +0800 | [diff] [blame] | 948 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 949 | return IRQ_HANDLED; |
| 950 | } |
| 951 | |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 952 | static irqreturn_t mxt_interrupt(int irq, void *dev_id) |
| 953 | { |
| 954 | struct mxt_data *data = dev_id; |
| 955 | |
| 956 | if (data->in_bootloader) { |
| 957 | /* bootloader state transition completion */ |
| 958 | complete(&data->bl_completion); |
| 959 | return IRQ_HANDLED; |
| 960 | } |
| 961 | |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 962 | if (!data->object_table) |
| 963 | return IRQ_HANDLED; |
| 964 | |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 965 | if (data->T44_address) { |
| 966 | return mxt_process_messages_t44(data); |
| 967 | } else { |
| 968 | return mxt_process_messages(data); |
| 969 | } |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 972 | static int mxt_t6_command(struct mxt_data *data, u16 cmd_offset, |
| 973 | u8 value, bool wait) |
| 974 | { |
| 975 | u16 reg; |
| 976 | u8 command_register; |
| 977 | int timeout_counter = 0; |
| 978 | int ret; |
| 979 | |
| 980 | reg = data->T6_address + cmd_offset; |
| 981 | |
| 982 | ret = mxt_write_reg(data->client, reg, value); |
| 983 | if (ret) |
| 984 | return ret; |
| 985 | |
| 986 | if (!wait) |
| 987 | return 0; |
| 988 | |
| 989 | do { |
| 990 | msleep(20); |
| 991 | ret = __mxt_read_reg(data->client, reg, 1, &command_register); |
| 992 | if (ret) |
| 993 | return ret; |
| 994 | } while (command_register != 0 && timeout_counter++ <= 100); |
| 995 | |
| 996 | if (timeout_counter > 100) { |
| 997 | dev_err(&data->client->dev, "Command failed!\n"); |
| 998 | return -EIO; |
| 999 | } |
| 1000 | |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | static int mxt_soft_reset(struct mxt_data *data) |
| 1005 | { |
| 1006 | struct device *dev = &data->client->dev; |
| 1007 | int ret = 0; |
| 1008 | |
| 1009 | dev_info(dev, "Resetting chip\n"); |
| 1010 | |
| 1011 | reinit_completion(&data->reset_completion); |
| 1012 | |
| 1013 | ret = mxt_t6_command(data, MXT_COMMAND_RESET, MXT_RESET_VALUE, false); |
| 1014 | if (ret) |
| 1015 | return ret; |
| 1016 | |
| 1017 | ret = mxt_wait_for_completion(data, &data->reset_completion, |
| 1018 | MXT_RESET_TIMEOUT); |
| 1019 | if (ret) |
| 1020 | return ret; |
| 1021 | |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame] | 1025 | static void mxt_update_crc(struct mxt_data *data, u8 cmd, u8 value) |
| 1026 | { |
| 1027 | /* |
| 1028 | * On failure, CRC is set to 0 and config will always be |
| 1029 | * downloaded. |
| 1030 | */ |
| 1031 | data->config_crc = 0; |
| 1032 | reinit_completion(&data->crc_completion); |
| 1033 | |
| 1034 | mxt_t6_command(data, cmd, value, true); |
| 1035 | |
| 1036 | /* |
| 1037 | * Wait for crc message. On failure, CRC is set to 0 and config will |
| 1038 | * always be downloaded. |
| 1039 | */ |
| 1040 | mxt_wait_for_completion(data, &data->crc_completion, MXT_CRC_TIMEOUT); |
| 1041 | } |
| 1042 | |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1043 | static void mxt_calc_crc24(u32 *crc, u8 firstbyte, u8 secondbyte) |
| 1044 | { |
| 1045 | static const unsigned int crcpoly = 0x80001B; |
| 1046 | u32 result; |
| 1047 | u32 data_word; |
| 1048 | |
| 1049 | data_word = (secondbyte << 8) | firstbyte; |
| 1050 | result = ((*crc << 1) ^ data_word); |
| 1051 | |
| 1052 | if (result & 0x1000000) |
| 1053 | result ^= crcpoly; |
| 1054 | |
| 1055 | *crc = result; |
| 1056 | } |
| 1057 | |
| 1058 | static u32 mxt_calculate_crc(u8 *base, off_t start_off, off_t end_off) |
| 1059 | { |
| 1060 | u32 crc = 0; |
| 1061 | u8 *ptr = base + start_off; |
| 1062 | u8 *last_val = base + end_off - 1; |
| 1063 | |
| 1064 | if (end_off < start_off) |
| 1065 | return -EINVAL; |
| 1066 | |
| 1067 | while (ptr < last_val) { |
| 1068 | mxt_calc_crc24(&crc, *ptr, *(ptr + 1)); |
| 1069 | ptr += 2; |
| 1070 | } |
| 1071 | |
| 1072 | /* if len is odd, fill the last byte with 0 */ |
| 1073 | if (ptr == last_val) |
| 1074 | mxt_calc_crc24(&crc, *ptr, 0); |
| 1075 | |
| 1076 | /* Mask to 24-bit */ |
| 1077 | crc &= 0x00FFFFFF; |
| 1078 | |
| 1079 | return crc; |
| 1080 | } |
| 1081 | |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1082 | static int mxt_prepare_cfg_mem(struct mxt_data *data, |
| 1083 | const struct firmware *cfg, |
| 1084 | unsigned int data_pos, |
| 1085 | unsigned int cfg_start_ofs, |
| 1086 | u8 *config_mem, |
| 1087 | size_t config_mem_size) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1088 | { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1089 | struct device *dev = &data->client->dev; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1090 | struct mxt_object *object; |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1091 | unsigned int type, instance, size, byte_offset; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1092 | int offset; |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1093 | int ret; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1094 | int i; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1095 | u16 reg; |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1096 | u8 val; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1097 | |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1098 | while (data_pos < cfg->size) { |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1099 | /* Read type, instance, length */ |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1100 | ret = sscanf(cfg->data + data_pos, "%x %x %x%n", |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1101 | &type, &instance, &size, &offset); |
| 1102 | if (ret == 0) { |
| 1103 | /* EOF */ |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1104 | break; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1105 | } else if (ret != 3) { |
| 1106 | dev_err(dev, "Bad format: failed to parse object\n"); |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1107 | return -EINVAL; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1108 | } |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1109 | data_pos += offset; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1110 | |
| 1111 | object = mxt_get_object(data, type); |
| 1112 | if (!object) { |
| 1113 | /* Skip object */ |
| 1114 | for (i = 0; i < size; i++) { |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1115 | ret = sscanf(cfg->data + data_pos, "%hhx%n", |
Dmitry Torokhov | 041fa15 | 2014-08-11 10:58:29 -0700 | [diff] [blame] | 1116 | &val, &offset); |
| 1117 | if (ret != 1) { |
| 1118 | dev_err(dev, "Bad format in T%d at %d\n", |
| 1119 | type, i); |
| 1120 | return -EINVAL; |
| 1121 | } |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1122 | data_pos += offset; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1123 | } |
| 1124 | continue; |
| 1125 | } |
| 1126 | |
| 1127 | if (size > mxt_obj_size(object)) { |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1128 | /* |
| 1129 | * Either we are in fallback mode due to wrong |
| 1130 | * config or config from a later fw version, |
| 1131 | * or the file is corrupt or hand-edited. |
| 1132 | */ |
| 1133 | dev_warn(dev, "Discarding %zu byte(s) in T%u\n", |
| 1134 | size - mxt_obj_size(object), type); |
| 1135 | } else if (mxt_obj_size(object) > size) { |
| 1136 | /* |
| 1137 | * If firmware is upgraded, new bytes may be added to |
| 1138 | * end of objects. It is generally forward compatible |
| 1139 | * to zero these bytes - previous behaviour will be |
| 1140 | * retained. However this does invalidate the CRC and |
| 1141 | * will force fallback mode until the configuration is |
| 1142 | * updated. We warn here but do nothing else - the |
| 1143 | * malloc has zeroed the entire configuration. |
| 1144 | */ |
| 1145 | dev_warn(dev, "Zeroing %zu byte(s) in T%d\n", |
| 1146 | mxt_obj_size(object) - size, type); |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | if (instance >= mxt_obj_instances(object)) { |
| 1150 | dev_err(dev, "Object instances exceeded!\n"); |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1151 | return -EINVAL; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | reg = object->start_address + mxt_obj_size(object) * instance; |
| 1155 | |
| 1156 | for (i = 0; i < size; i++) { |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1157 | ret = sscanf(cfg->data + data_pos, "%hhx%n", |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1158 | &val, |
| 1159 | &offset); |
| 1160 | if (ret != 1) { |
Dmitry Torokhov | 041fa15 | 2014-08-11 10:58:29 -0700 | [diff] [blame] | 1161 | dev_err(dev, "Bad format in T%d at %d\n", |
| 1162 | type, i); |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1163 | return -EINVAL; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1164 | } |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1165 | data_pos += offset; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1166 | |
| 1167 | if (i > mxt_obj_size(object)) |
| 1168 | continue; |
| 1169 | |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1170 | byte_offset = reg + i - cfg_start_ofs; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1171 | |
Dmitry Torokhov | 041fa15 | 2014-08-11 10:58:29 -0700 | [diff] [blame] | 1172 | if (byte_offset >= 0 && byte_offset < config_mem_size) { |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1173 | *(config_mem + byte_offset) = val; |
| 1174 | } else { |
| 1175 | dev_err(dev, "Bad object: reg:%d, T%d, ofs=%d\n", |
| 1176 | reg, object->type, byte_offset); |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1177 | return -EINVAL; |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1178 | } |
| 1179 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | static int mxt_upload_cfg_mem(struct mxt_data *data, unsigned int cfg_start, |
| 1186 | u8 *config_mem, size_t config_mem_size) |
| 1187 | { |
| 1188 | unsigned int byte_offset = 0; |
| 1189 | int error; |
| 1190 | |
| 1191 | /* Write configuration as blocks */ |
| 1192 | while (byte_offset < config_mem_size) { |
| 1193 | unsigned int size = config_mem_size - byte_offset; |
| 1194 | |
| 1195 | if (size > MXT_MAX_BLOCK_WRITE) |
| 1196 | size = MXT_MAX_BLOCK_WRITE; |
| 1197 | |
| 1198 | error = __mxt_write_reg(data->client, |
| 1199 | cfg_start + byte_offset, |
| 1200 | size, config_mem + byte_offset); |
| 1201 | if (error) { |
| 1202 | dev_err(&data->client->dev, |
| 1203 | "Config write error, ret=%d\n", error); |
| 1204 | return error; |
| 1205 | } |
| 1206 | |
| 1207 | byte_offset += size; |
| 1208 | } |
| 1209 | |
| 1210 | return 0; |
| 1211 | } |
| 1212 | |
| 1213 | /* |
| 1214 | * mxt_update_cfg - download configuration to chip |
| 1215 | * |
| 1216 | * Atmel Raw Config File Format |
| 1217 | * |
| 1218 | * The first four lines of the raw config file contain: |
| 1219 | * 1) Version |
| 1220 | * 2) Chip ID Information (first 7 bytes of device memory) |
| 1221 | * 3) Chip Information Block 24-bit CRC Checksum |
| 1222 | * 4) Chip Configuration 24-bit CRC Checksum |
| 1223 | * |
| 1224 | * The rest of the file consists of one line per object instance: |
| 1225 | * <TYPE> <INSTANCE> <SIZE> <CONTENTS> |
| 1226 | * |
| 1227 | * <TYPE> - 2-byte object type as hex |
| 1228 | * <INSTANCE> - 2-byte object instance number as hex |
| 1229 | * <SIZE> - 2-byte object size as hex |
| 1230 | * <CONTENTS> - array of <SIZE> 1-byte hex values |
| 1231 | */ |
| 1232 | static int mxt_update_cfg(struct mxt_data *data, const struct firmware *cfg) |
| 1233 | { |
| 1234 | struct device *dev = &data->client->dev; |
| 1235 | struct mxt_info cfg_info; |
| 1236 | int ret; |
| 1237 | int offset; |
| 1238 | int data_pos; |
| 1239 | int i; |
| 1240 | int cfg_start_ofs; |
| 1241 | u32 info_crc, config_crc, calculated_crc; |
| 1242 | u8 *config_mem; |
| 1243 | size_t config_mem_size; |
| 1244 | |
| 1245 | mxt_update_crc(data, MXT_COMMAND_REPORTALL, 1); |
| 1246 | |
| 1247 | if (strncmp(cfg->data, MXT_CFG_MAGIC, strlen(MXT_CFG_MAGIC))) { |
| 1248 | dev_err(dev, "Unrecognised config file\n"); |
| 1249 | return -EINVAL; |
| 1250 | } |
| 1251 | |
| 1252 | data_pos = strlen(MXT_CFG_MAGIC); |
| 1253 | |
| 1254 | /* Load information block and check */ |
| 1255 | for (i = 0; i < sizeof(struct mxt_info); i++) { |
| 1256 | ret = sscanf(cfg->data + data_pos, "%hhx%n", |
| 1257 | (unsigned char *)&cfg_info + i, |
| 1258 | &offset); |
| 1259 | if (ret != 1) { |
| 1260 | dev_err(dev, "Bad format\n"); |
| 1261 | return -EINVAL; |
| 1262 | } |
| 1263 | |
| 1264 | data_pos += offset; |
| 1265 | } |
| 1266 | |
| 1267 | if (cfg_info.family_id != data->info.family_id) { |
| 1268 | dev_err(dev, "Family ID mismatch!\n"); |
| 1269 | return -EINVAL; |
| 1270 | } |
| 1271 | |
| 1272 | if (cfg_info.variant_id != data->info.variant_id) { |
| 1273 | dev_err(dev, "Variant ID mismatch!\n"); |
| 1274 | return -EINVAL; |
| 1275 | } |
| 1276 | |
| 1277 | /* Read CRCs */ |
| 1278 | ret = sscanf(cfg->data + data_pos, "%x%n", &info_crc, &offset); |
| 1279 | if (ret != 1) { |
| 1280 | dev_err(dev, "Bad format: failed to parse Info CRC\n"); |
| 1281 | return -EINVAL; |
| 1282 | } |
| 1283 | data_pos += offset; |
| 1284 | |
| 1285 | ret = sscanf(cfg->data + data_pos, "%x%n", &config_crc, &offset); |
| 1286 | if (ret != 1) { |
| 1287 | dev_err(dev, "Bad format: failed to parse Config CRC\n"); |
| 1288 | return -EINVAL; |
| 1289 | } |
| 1290 | data_pos += offset; |
| 1291 | |
| 1292 | /* |
| 1293 | * The Info Block CRC is calculated over mxt_info and the object |
| 1294 | * table. If it does not match then we are trying to load the |
| 1295 | * configuration from a different chip or firmware version, so |
| 1296 | * the configuration CRC is invalid anyway. |
| 1297 | */ |
| 1298 | if (info_crc == data->info_crc) { |
| 1299 | if (config_crc == 0 || data->config_crc == 0) { |
| 1300 | dev_info(dev, "CRC zero, attempting to apply config\n"); |
| 1301 | } else if (config_crc == data->config_crc) { |
| 1302 | dev_dbg(dev, "Config CRC 0x%06X: OK\n", |
| 1303 | data->config_crc); |
| 1304 | return 0; |
| 1305 | } else { |
| 1306 | dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n", |
| 1307 | data->config_crc, config_crc); |
| 1308 | } |
| 1309 | } else { |
| 1310 | dev_warn(dev, |
| 1311 | "Warning: Info CRC error - device=0x%06X file=0x%06X\n", |
| 1312 | data->info_crc, info_crc); |
| 1313 | } |
| 1314 | |
| 1315 | /* Malloc memory to store configuration */ |
| 1316 | cfg_start_ofs = MXT_OBJECT_START + |
| 1317 | data->info.object_num * sizeof(struct mxt_object) + |
| 1318 | MXT_INFO_CHECKSUM_SIZE; |
| 1319 | config_mem_size = data->mem_size - cfg_start_ofs; |
| 1320 | config_mem = kzalloc(config_mem_size, GFP_KERNEL); |
| 1321 | if (!config_mem) { |
| 1322 | dev_err(dev, "Failed to allocate memory\n"); |
| 1323 | return -ENOMEM; |
| 1324 | } |
| 1325 | |
| 1326 | ret = mxt_prepare_cfg_mem(data, cfg, data_pos, cfg_start_ofs, |
| 1327 | config_mem, config_mem_size); |
| 1328 | if (ret) |
| 1329 | goto release_mem; |
| 1330 | |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1331 | /* Calculate crc of the received configs (not the raw config file) */ |
| 1332 | if (data->T7_address < cfg_start_ofs) { |
| 1333 | dev_err(dev, "Bad T7 address, T7addr = %x, config offset %x\n", |
| 1334 | data->T7_address, cfg_start_ofs); |
| 1335 | ret = 0; |
| 1336 | goto release_mem; |
| 1337 | } |
| 1338 | |
| 1339 | calculated_crc = mxt_calculate_crc(config_mem, |
| 1340 | data->T7_address - cfg_start_ofs, |
| 1341 | config_mem_size); |
| 1342 | |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1343 | if (config_crc > 0 && config_crc != calculated_crc) |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1344 | dev_warn(dev, "Config CRC error, calculated=%06X, file=%06X\n", |
| 1345 | calculated_crc, config_crc); |
| 1346 | |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1347 | ret = mxt_upload_cfg_mem(data, cfg_start_ofs, |
| 1348 | config_mem, config_mem_size); |
| 1349 | if (ret) |
| 1350 | goto release_mem; |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1351 | |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame] | 1352 | mxt_update_crc(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE); |
| 1353 | |
| 1354 | ret = mxt_soft_reset(data); |
| 1355 | if (ret) |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1356 | goto release_mem; |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame] | 1357 | |
| 1358 | dev_info(dev, "Config successfully updated\n"); |
| 1359 | |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1360 | release_mem: |
| 1361 | kfree(config_mem); |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1362 | return ret; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 1365 | static int mxt_acquire_irq(struct mxt_data *data) |
| 1366 | { |
| 1367 | int error; |
| 1368 | |
| 1369 | enable_irq(data->irq); |
| 1370 | |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 1371 | error = mxt_process_messages_until_invalid(data); |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 1372 | if (error) |
| 1373 | return error; |
| 1374 | |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1378 | static int mxt_get_info(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1379 | { |
| 1380 | struct i2c_client *client = data->client; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1381 | struct mxt_info *info = &data->info; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1382 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1383 | |
Daniel Kurtz | 23003a84 | 2012-06-28 21:08:14 +0800 | [diff] [blame] | 1384 | /* Read 7-byte info block starting at address 0 */ |
| 1385 | error = __mxt_read_reg(client, MXT_INFO, sizeof(*info), info); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1386 | if (error) |
| 1387 | return error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1388 | |
| 1389 | return 0; |
| 1390 | } |
| 1391 | |
Stephen Warren | 58e4aeee | 2014-09-10 10:01:10 -0700 | [diff] [blame] | 1392 | static void mxt_free_input_device(struct mxt_data *data) |
| 1393 | { |
| 1394 | if (data->input_dev) { |
| 1395 | input_unregister_device(data->input_dev); |
| 1396 | data->input_dev = NULL; |
| 1397 | } |
| 1398 | } |
| 1399 | |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 1400 | static void mxt_free_object_table(struct mxt_data *data) |
| 1401 | { |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 1402 | kfree(data->object_table); |
| 1403 | data->object_table = NULL; |
| 1404 | kfree(data->msg_buf); |
| 1405 | data->msg_buf = NULL; |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 1406 | data->T5_address = 0; |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 1407 | data->T5_msg_size = 0; |
| 1408 | data->T6_reportid = 0; |
| 1409 | data->T7_address = 0; |
| 1410 | data->T9_reportid_min = 0; |
| 1411 | data->T9_reportid_max = 0; |
| 1412 | data->T19_reportid = 0; |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 1413 | data->T44_address = 0; |
| 1414 | data->max_reportid = 0; |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1417 | static int mxt_get_object_table(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1418 | { |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1419 | struct i2c_client *client = data->client; |
| 1420 | size_t table_size; |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 1421 | struct mxt_object *object_table; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1422 | int error; |
| 1423 | int i; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1424 | u8 reportid; |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1425 | u16 end_address; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1426 | |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1427 | table_size = data->info.object_num * sizeof(struct mxt_object); |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 1428 | object_table = kzalloc(table_size, GFP_KERNEL); |
| 1429 | if (!object_table) { |
| 1430 | dev_err(&data->client->dev, "Failed to allocate memory\n"); |
| 1431 | return -ENOMEM; |
| 1432 | } |
| 1433 | |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1434 | error = __mxt_read_reg(client, MXT_OBJECT_START, table_size, |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 1435 | object_table); |
| 1436 | if (error) { |
| 1437 | kfree(object_table); |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1438 | return error; |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 1439 | } |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1440 | |
| 1441 | /* Valid Report IDs start counting from 1 */ |
| 1442 | reportid = 1; |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1443 | data->mem_size = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1444 | for (i = 0; i < data->info.object_num; i++) { |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 1445 | struct mxt_object *object = object_table + i; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1446 | u8 min_id, max_id; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1447 | |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1448 | le16_to_cpus(&object->start_address); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1449 | |
| 1450 | if (object->num_report_ids) { |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1451 | min_id = reportid; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1452 | reportid += object->num_report_ids * |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 1453 | mxt_obj_instances(object); |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1454 | max_id = reportid - 1; |
| 1455 | } else { |
| 1456 | min_id = 0; |
| 1457 | max_id = 0; |
| 1458 | } |
| 1459 | |
| 1460 | dev_dbg(&data->client->dev, |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 1461 | "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] | 1462 | object->type, object->start_address, |
| 1463 | mxt_obj_size(object), mxt_obj_instances(object), |
| 1464 | min_id, max_id); |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1465 | |
| 1466 | switch (object->type) { |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 1467 | case MXT_GEN_MESSAGE_T5: |
Nick Dyer | 437d4f3 | 2014-08-07 09:56:01 -0700 | [diff] [blame] | 1468 | if (data->info.family_id == 0x80 && |
| 1469 | data->info.version < 0x20) { |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 1470 | /* |
Nick Dyer | 437d4f3 | 2014-08-07 09:56:01 -0700 | [diff] [blame] | 1471 | * On mXT224 firmware versions prior to V2.0 |
| 1472 | * read and discard unused CRC byte otherwise |
| 1473 | * DMA reads are misaligned. |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 1474 | */ |
| 1475 | data->T5_msg_size = mxt_obj_size(object); |
| 1476 | } else { |
| 1477 | /* CRC not enabled, so skip last byte */ |
| 1478 | data->T5_msg_size = mxt_obj_size(object) - 1; |
| 1479 | } |
Nick Dyer | b9b05a8 | 2014-07-23 12:48:13 -0700 | [diff] [blame] | 1480 | data->T5_address = object->start_address; |
Dmitry Torokhov | 041fa15 | 2014-08-11 10:58:29 -0700 | [diff] [blame] | 1481 | break; |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 1482 | case MXT_GEN_COMMAND_T6: |
| 1483 | data->T6_reportid = min_id; |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 1484 | data->T6_address = object->start_address; |
Daniel Kurtz | fdf80421 | 2012-06-28 21:08:24 +0800 | [diff] [blame] | 1485 | break; |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1486 | case MXT_GEN_POWER_T7: |
| 1487 | data->T7_address = object->start_address; |
| 1488 | break; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1489 | case MXT_TOUCH_MULTI_T9: |
| 1490 | data->T9_reportid_min = min_id; |
| 1491 | data->T9_reportid_max = max_id; |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 1492 | data->num_touchids = object->num_report_ids |
| 1493 | * mxt_obj_instances(object); |
| 1494 | break; |
| 1495 | case MXT_SPT_MESSAGECOUNT_T44: |
| 1496 | data->T44_address = object->start_address; |
Daniel Kurtz | 333e5a9 | 2012-06-28 21:08:20 +0800 | [diff] [blame] | 1497 | break; |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 1498 | case MXT_SPT_GPIOPWM_T19: |
| 1499 | data->T19_reportid = min_id; |
| 1500 | break; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1501 | } |
Nick Dyer | 4ce6fa0 | 2014-07-23 12:40:09 -0700 | [diff] [blame] | 1502 | |
| 1503 | end_address = object->start_address |
| 1504 | + mxt_obj_size(object) * mxt_obj_instances(object) - 1; |
| 1505 | |
| 1506 | if (end_address >= data->mem_size) |
| 1507 | data->mem_size = end_address + 1; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Nick Dyer | 9d8dc3e | 2014-07-23 12:49:04 -0700 | [diff] [blame] | 1510 | /* Store maximum reportid */ |
| 1511 | data->max_reportid = reportid; |
| 1512 | |
| 1513 | /* If T44 exists, T5 position has to be directly after */ |
| 1514 | if (data->T44_address && (data->T5_address != data->T44_address + 1)) { |
| 1515 | dev_err(&client->dev, "Invalid T44 position\n"); |
| 1516 | error = -EINVAL; |
| 1517 | goto free_object_table; |
| 1518 | } |
| 1519 | |
| 1520 | data->msg_buf = kcalloc(data->max_reportid, |
| 1521 | data->T5_msg_size, GFP_KERNEL); |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 1522 | if (!data->msg_buf) { |
| 1523 | dev_err(&client->dev, "Failed to allocate message buffer\n"); |
| 1524 | error = -ENOMEM; |
| 1525 | goto free_object_table; |
| 1526 | } |
| 1527 | |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 1528 | data->object_table = object_table; |
| 1529 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1530 | return 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1531 | |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 1532 | free_object_table: |
| 1533 | mxt_free_object_table(data); |
| 1534 | return error; |
Daniel Kurtz | 7d4fa10 | 2012-06-28 21:08:19 +0800 | [diff] [blame] | 1535 | } |
| 1536 | |
Nick Dyer | 61dc1ab | 2014-05-18 23:16:49 -0700 | [diff] [blame] | 1537 | static int mxt_read_t9_resolution(struct mxt_data *data) |
| 1538 | { |
| 1539 | struct i2c_client *client = data->client; |
| 1540 | int error; |
| 1541 | struct t9_range range; |
| 1542 | unsigned char orient; |
| 1543 | struct mxt_object *object; |
| 1544 | |
| 1545 | object = mxt_get_object(data, MXT_TOUCH_MULTI_T9); |
| 1546 | if (!object) |
| 1547 | return -EINVAL; |
| 1548 | |
| 1549 | error = __mxt_read_reg(client, |
| 1550 | object->start_address + MXT_T9_RANGE, |
| 1551 | sizeof(range), &range); |
| 1552 | if (error) |
| 1553 | return error; |
| 1554 | |
| 1555 | le16_to_cpus(&range.x); |
| 1556 | le16_to_cpus(&range.y); |
| 1557 | |
| 1558 | error = __mxt_read_reg(client, |
| 1559 | object->start_address + MXT_T9_ORIENT, |
| 1560 | 1, &orient); |
| 1561 | if (error) |
| 1562 | return error; |
| 1563 | |
| 1564 | /* Handle default values */ |
| 1565 | if (range.x == 0) |
| 1566 | range.x = 1023; |
| 1567 | |
| 1568 | if (range.y == 0) |
| 1569 | range.y = 1023; |
| 1570 | |
Nick Dyer | f3889ed | 2014-05-18 23:22:04 -0700 | [diff] [blame] | 1571 | if (orient & MXT_T9_ORIENT_SWITCH) { |
Nick Dyer | 61dc1ab | 2014-05-18 23:16:49 -0700 | [diff] [blame] | 1572 | data->max_x = range.y; |
| 1573 | data->max_y = range.x; |
| 1574 | } else { |
| 1575 | data->max_x = range.x; |
| 1576 | data->max_y = range.y; |
| 1577 | } |
| 1578 | |
| 1579 | dev_dbg(&client->dev, |
| 1580 | "Touchscreen size X%uY%u\n", data->max_x, data->max_y); |
| 1581 | |
| 1582 | return 0; |
| 1583 | } |
| 1584 | |
Nick Dyer | 7a53d60 | 2014-07-23 12:21:26 -0700 | [diff] [blame] | 1585 | static int mxt_input_open(struct input_dev *dev); |
| 1586 | static void mxt_input_close(struct input_dev *dev); |
| 1587 | |
| 1588 | static int mxt_initialize_t9_input_device(struct mxt_data *data) |
| 1589 | { |
| 1590 | struct device *dev = &data->client->dev; |
| 1591 | const struct mxt_platform_data *pdata = data->pdata; |
| 1592 | struct input_dev *input_dev; |
| 1593 | int error; |
| 1594 | unsigned int num_mt_slots; |
| 1595 | unsigned int mt_flags = 0; |
| 1596 | int i; |
| 1597 | |
| 1598 | error = mxt_read_t9_resolution(data); |
| 1599 | if (error) |
| 1600 | dev_warn(dev, "Failed to initialize T9 resolution\n"); |
| 1601 | |
| 1602 | input_dev = input_allocate_device(); |
| 1603 | if (!input_dev) { |
| 1604 | dev_err(dev, "Failed to allocate memory\n"); |
| 1605 | return -ENOMEM; |
| 1606 | } |
| 1607 | |
| 1608 | input_dev->name = "Atmel maXTouch Touchscreen"; |
| 1609 | input_dev->phys = data->phys; |
| 1610 | input_dev->id.bustype = BUS_I2C; |
| 1611 | input_dev->dev.parent = dev; |
| 1612 | input_dev->open = mxt_input_open; |
| 1613 | input_dev->close = mxt_input_close; |
| 1614 | |
| 1615 | __set_bit(EV_ABS, input_dev->evbit); |
| 1616 | __set_bit(EV_KEY, input_dev->evbit); |
| 1617 | __set_bit(BTN_TOUCH, input_dev->keybit); |
| 1618 | |
| 1619 | if (pdata->t19_num_keys) { |
| 1620 | __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); |
| 1621 | |
| 1622 | for (i = 0; i < pdata->t19_num_keys; i++) |
| 1623 | if (pdata->t19_keymap[i] != KEY_RESERVED) |
| 1624 | input_set_capability(input_dev, EV_KEY, |
| 1625 | pdata->t19_keymap[i]); |
| 1626 | |
| 1627 | mt_flags |= INPUT_MT_POINTER; |
| 1628 | |
| 1629 | input_abs_set_res(input_dev, ABS_X, MXT_PIXELS_PER_MM); |
| 1630 | input_abs_set_res(input_dev, ABS_Y, MXT_PIXELS_PER_MM); |
| 1631 | input_abs_set_res(input_dev, ABS_MT_POSITION_X, |
| 1632 | MXT_PIXELS_PER_MM); |
| 1633 | input_abs_set_res(input_dev, ABS_MT_POSITION_Y, |
| 1634 | MXT_PIXELS_PER_MM); |
| 1635 | |
| 1636 | input_dev->name = "Atmel maXTouch Touchpad"; |
| 1637 | } |
| 1638 | |
| 1639 | /* For single touch */ |
| 1640 | input_set_abs_params(input_dev, ABS_X, |
| 1641 | 0, data->max_x, 0, 0); |
| 1642 | input_set_abs_params(input_dev, ABS_Y, |
| 1643 | 0, data->max_y, 0, 0); |
| 1644 | input_set_abs_params(input_dev, ABS_PRESSURE, |
| 1645 | 0, 255, 0, 0); |
| 1646 | |
| 1647 | /* For multi touch */ |
| 1648 | num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1; |
| 1649 | error = input_mt_init_slots(input_dev, num_mt_slots, mt_flags); |
| 1650 | if (error) { |
| 1651 | dev_err(dev, "Error %d initialising slots\n", error); |
| 1652 | goto err_free_mem; |
| 1653 | } |
| 1654 | |
| 1655 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, |
| 1656 | 0, MXT_MAX_AREA, 0, 0); |
| 1657 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, |
| 1658 | 0, data->max_x, 0, 0); |
| 1659 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, |
| 1660 | 0, data->max_y, 0, 0); |
| 1661 | input_set_abs_params(input_dev, ABS_MT_PRESSURE, |
| 1662 | 0, 255, 0, 0); |
| 1663 | |
| 1664 | input_set_drvdata(input_dev, data); |
| 1665 | |
| 1666 | error = input_register_device(input_dev); |
| 1667 | if (error) { |
| 1668 | dev_err(dev, "Error %d registering input device\n", error); |
| 1669 | goto err_free_mem; |
| 1670 | } |
| 1671 | |
| 1672 | data->input_dev = input_dev; |
| 1673 | |
| 1674 | return 0; |
| 1675 | |
| 1676 | err_free_mem: |
| 1677 | input_free_device(input_dev); |
| 1678 | return error; |
| 1679 | } |
| 1680 | |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1681 | static int mxt_configure_objects(struct mxt_data *data, |
| 1682 | const struct firmware *cfg); |
| 1683 | |
| 1684 | static void mxt_config_cb(const struct firmware *cfg, void *ctx) |
| 1685 | { |
| 1686 | mxt_configure_objects(ctx, cfg); |
Dmitry Torokhov | efdbd7a | 2014-08-08 09:29:06 -0700 | [diff] [blame] | 1687 | release_firmware(cfg); |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1690 | static int mxt_initialize(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1691 | { |
| 1692 | struct i2c_client *client = data->client; |
Dmitry Torokhov | 6cd1ab0 | 2014-08-08 09:28:45 -0700 | [diff] [blame] | 1693 | int recovery_attempts = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1694 | int error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1695 | |
Dmitry Torokhov | 6cd1ab0 | 2014-08-08 09:28:45 -0700 | [diff] [blame] | 1696 | while (1) { |
| 1697 | error = mxt_get_info(data); |
| 1698 | if (!error) |
| 1699 | break; |
| 1700 | |
| 1701 | /* Check bootloader state */ |
| 1702 | error = mxt_probe_bootloader(data, false); |
Nick Dyer | 8efaa5e | 2014-07-23 12:45:49 -0700 | [diff] [blame] | 1703 | if (error) { |
Dmitry Torokhov | 6cd1ab0 | 2014-08-08 09:28:45 -0700 | [diff] [blame] | 1704 | dev_info(&client->dev, "Trying alternate bootloader address\n"); |
| 1705 | error = mxt_probe_bootloader(data, true); |
| 1706 | if (error) { |
Nick Dyer | 8efaa5e | 2014-07-23 12:45:49 -0700 | [diff] [blame] | 1707 | /* Chip is not in appmode or bootloader mode */ |
| 1708 | return error; |
| 1709 | } |
Nick Dyer | 8efaa5e | 2014-07-23 12:45:49 -0700 | [diff] [blame] | 1710 | } |
Dmitry Torokhov | 6cd1ab0 | 2014-08-08 09:28:45 -0700 | [diff] [blame] | 1711 | |
| 1712 | /* OK, we are in bootloader, see if we can recover */ |
| 1713 | if (++recovery_attempts > 1) { |
| 1714 | dev_err(&client->dev, "Could not recover from bootloader mode\n"); |
| 1715 | /* |
| 1716 | * We can reflash from this state, so do not |
| 1717 | * abort initialization. |
| 1718 | */ |
| 1719 | data->in_bootloader = true; |
| 1720 | return 0; |
| 1721 | } |
| 1722 | |
| 1723 | /* Attempt to exit bootloader into app mode */ |
| 1724 | mxt_send_bootloader_cmd(data, false); |
| 1725 | msleep(MXT_FW_RESET_TIME); |
Nick Dyer | a9fdd1e | 2014-07-23 12:41:58 -0700 | [diff] [blame] | 1726 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1727 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1728 | /* Get object table information */ |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1729 | error = mxt_get_object_table(data); |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 1730 | if (error) { |
| 1731 | dev_err(&client->dev, "Error %d reading object table\n", error); |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 1732 | return error; |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 1733 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1734 | |
Dmitry Torokhov | 041fa15 | 2014-08-11 10:58:29 -0700 | [diff] [blame] | 1735 | error = mxt_acquire_irq(data); |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 1736 | if (error) |
| 1737 | goto err_free_object_table; |
| 1738 | |
Dmitry Torokhov | 6cd1ab0 | 2014-08-08 09:28:45 -0700 | [diff] [blame] | 1739 | error = request_firmware_nowait(THIS_MODULE, true, MXT_CFG_NAME, |
| 1740 | &client->dev, GFP_KERNEL, data, |
| 1741 | mxt_config_cb); |
| 1742 | if (error) { |
| 1743 | dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", |
| 1744 | error); |
| 1745 | goto err_free_object_table; |
| 1746 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1747 | |
| 1748 | return 0; |
Daniel Kurtz | 7d4fa10 | 2012-06-28 21:08:19 +0800 | [diff] [blame] | 1749 | |
| 1750 | err_free_object_table: |
| 1751 | mxt_free_object_table(data); |
| 1752 | return error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
Nick Dyer | 50a77c6 | 2014-07-23 12:38:48 -0700 | [diff] [blame] | 1755 | static int mxt_configure_objects(struct mxt_data *data, |
| 1756 | const struct firmware *cfg) |
| 1757 | { |
| 1758 | struct device *dev = &data->client->dev; |
| 1759 | struct mxt_info *info = &data->info; |
| 1760 | int error; |
| 1761 | |
| 1762 | if (cfg) { |
| 1763 | error = mxt_update_cfg(data, cfg); |
| 1764 | if (error) |
| 1765 | dev_warn(dev, "Error %d updating config\n", error); |
| 1766 | } |
| 1767 | |
| 1768 | error = mxt_initialize_t9_input_device(data); |
| 1769 | if (error) |
| 1770 | return error; |
| 1771 | |
| 1772 | dev_info(dev, |
| 1773 | "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n", |
| 1774 | info->family_id, info->variant_id, info->version >> 4, |
| 1775 | info->version & 0xf, info->build, info->object_num); |
| 1776 | |
| 1777 | return 0; |
| 1778 | } |
| 1779 | |
Daniel Kurtz | b19fc9e | 2012-06-28 21:08:16 +0800 | [diff] [blame] | 1780 | /* Firmware Version is returned as Major.Minor.Build */ |
| 1781 | static ssize_t mxt_fw_version_show(struct device *dev, |
| 1782 | struct device_attribute *attr, char *buf) |
| 1783 | { |
| 1784 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1785 | struct mxt_info *info = &data->info; |
| 1786 | return scnprintf(buf, PAGE_SIZE, "%u.%u.%02X\n", |
| 1787 | info->version >> 4, info->version & 0xf, info->build); |
| 1788 | } |
| 1789 | |
| 1790 | /* Hardware Version is returned as FamilyID.VariantID */ |
| 1791 | static ssize_t mxt_hw_version_show(struct device *dev, |
| 1792 | struct device_attribute *attr, char *buf) |
| 1793 | { |
| 1794 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1795 | struct mxt_info *info = &data->info; |
| 1796 | return scnprintf(buf, PAGE_SIZE, "%u.%u\n", |
| 1797 | info->family_id, info->variant_id); |
| 1798 | } |
| 1799 | |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1800 | static ssize_t mxt_show_instance(char *buf, int count, |
| 1801 | struct mxt_object *object, int instance, |
| 1802 | const u8 *val) |
| 1803 | { |
| 1804 | int i; |
| 1805 | |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 1806 | if (mxt_obj_instances(object) > 1) |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1807 | count += scnprintf(buf + count, PAGE_SIZE - count, |
| 1808 | "Instance %u\n", instance); |
| 1809 | |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 1810 | for (i = 0; i < mxt_obj_size(object); i++) |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1811 | count += scnprintf(buf + count, PAGE_SIZE - count, |
| 1812 | "\t[%2u]: %02x (%d)\n", i, val[i], val[i]); |
| 1813 | count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 1814 | |
| 1815 | return count; |
| 1816 | } |
| 1817 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1818 | static ssize_t mxt_object_show(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1819 | struct device_attribute *attr, char *buf) |
| 1820 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1821 | struct mxt_data *data = dev_get_drvdata(dev); |
| 1822 | struct mxt_object *object; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1823 | int count = 0; |
| 1824 | int i, j; |
| 1825 | int error; |
Daniel Kurtz | 43a91d5 | 2012-06-28 21:08:08 +0800 | [diff] [blame] | 1826 | u8 *obuf; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1827 | |
Daniel Kurtz | 43a91d5 | 2012-06-28 21:08:08 +0800 | [diff] [blame] | 1828 | /* Pre-allocate buffer large enough to hold max sized object. */ |
| 1829 | obuf = kmalloc(256, GFP_KERNEL); |
| 1830 | if (!obuf) |
| 1831 | return -ENOMEM; |
| 1832 | |
| 1833 | error = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1834 | for (i = 0; i < data->info.object_num; i++) { |
| 1835 | object = data->object_table + i; |
| 1836 | |
Daniel Kurtz | 9163095 | 2012-06-28 21:08:09 +0800 | [diff] [blame] | 1837 | if (!mxt_object_readable(object->type)) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1838 | continue; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1839 | |
Daniel Kurtz | 9163095 | 2012-06-28 21:08:09 +0800 | [diff] [blame] | 1840 | count += scnprintf(buf + count, PAGE_SIZE - count, |
| 1841 | "T%u:\n", object->type); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1842 | |
Daniel Kurtz | 1e0c0c5 | 2014-05-18 23:01:12 -0700 | [diff] [blame] | 1843 | for (j = 0; j < mxt_obj_instances(object); j++) { |
| 1844 | u16 size = mxt_obj_size(object); |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1845 | u16 addr = object->start_address + j * size; |
Daniel Kurtz | 43a91d5 | 2012-06-28 21:08:08 +0800 | [diff] [blame] | 1846 | |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1847 | error = __mxt_read_reg(data->client, addr, size, obuf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1848 | if (error) |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1849 | goto done; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1850 | |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1851 | count = mxt_show_instance(buf, count, object, j, obuf); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1852 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
Daniel Kurtz | 794eb67 | 2012-06-28 21:08:10 +0800 | [diff] [blame] | 1855 | done: |
Daniel Kurtz | 43a91d5 | 2012-06-28 21:08:08 +0800 | [diff] [blame] | 1856 | kfree(obuf); |
| 1857 | return error ?: count; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
Nick Dyer | f2ac6cb | 2014-05-18 23:15:01 -0700 | [diff] [blame] | 1860 | static int mxt_check_firmware_format(struct device *dev, |
| 1861 | const struct firmware *fw) |
| 1862 | { |
| 1863 | unsigned int pos = 0; |
| 1864 | char c; |
| 1865 | |
| 1866 | while (pos < fw->size) { |
| 1867 | c = *(fw->data + pos); |
| 1868 | |
| 1869 | if (c < '0' || (c > '9' && c < 'A') || c > 'F') |
| 1870 | return 0; |
| 1871 | |
| 1872 | pos++; |
| 1873 | } |
| 1874 | |
| 1875 | /* |
| 1876 | * To convert file try: |
| 1877 | * xxd -r -p mXTXXX__APP_VX-X-XX.enc > maxtouch.fw |
| 1878 | */ |
| 1879 | dev_err(dev, "Aborting: firmware file must be in binary format\n"); |
| 1880 | |
| 1881 | return -EINVAL; |
| 1882 | } |
| 1883 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1884 | static int mxt_load_fw(struct device *dev, const char *fn) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1885 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 1886 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1887 | const struct firmware *fw = NULL; |
| 1888 | unsigned int frame_size; |
| 1889 | unsigned int pos = 0; |
Nick Dyer | f943c74 | 2014-05-18 23:14:20 -0700 | [diff] [blame] | 1890 | unsigned int retry = 0; |
Nick Dyer | f477c75 | 2014-05-18 23:14:45 -0700 | [diff] [blame] | 1891 | unsigned int frame = 0; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1892 | int ret; |
| 1893 | |
| 1894 | ret = request_firmware(&fw, fn, dev); |
| 1895 | if (ret) { |
| 1896 | dev_err(dev, "Unable to open firmware %s\n", fn); |
| 1897 | return ret; |
| 1898 | } |
| 1899 | |
Nick Dyer | f2ac6cb | 2014-05-18 23:15:01 -0700 | [diff] [blame] | 1900 | /* Check for incorrect enc file */ |
| 1901 | ret = mxt_check_firmware_format(dev, fw); |
| 1902 | if (ret) |
| 1903 | goto release_firmware; |
| 1904 | |
Nick Dyer | a9fdd1e | 2014-07-23 12:41:58 -0700 | [diff] [blame] | 1905 | if (!data->in_bootloader) { |
| 1906 | /* Change to the bootloader mode */ |
| 1907 | data->in_bootloader = true; |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1908 | |
Nick Dyer | a9fdd1e | 2014-07-23 12:41:58 -0700 | [diff] [blame] | 1909 | ret = mxt_t6_command(data, MXT_COMMAND_RESET, |
| 1910 | MXT_BOOT_VALUE, false); |
| 1911 | if (ret) |
| 1912 | goto release_firmware; |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 1913 | |
Nick Dyer | a9fdd1e | 2014-07-23 12:41:58 -0700 | [diff] [blame] | 1914 | msleep(MXT_RESET_TIME); |
Nick Dyer | 8efaa5e | 2014-07-23 12:45:49 -0700 | [diff] [blame] | 1915 | |
| 1916 | /* Do not need to scan since we know family ID */ |
| 1917 | ret = mxt_lookup_bootloader_address(data, 0); |
| 1918 | if (ret) |
| 1919 | goto release_firmware; |
Stephen Warren | 58e4aeee | 2014-09-10 10:01:10 -0700 | [diff] [blame] | 1920 | |
| 1921 | mxt_free_input_device(data); |
| 1922 | mxt_free_object_table(data); |
Nick Dyer | 8efaa5e | 2014-07-23 12:45:49 -0700 | [diff] [blame] | 1923 | } else { |
| 1924 | enable_irq(data->irq); |
Nick Dyer | a9fdd1e | 2014-07-23 12:41:58 -0700 | [diff] [blame] | 1925 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1926 | |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1927 | reinit_completion(&data->bl_completion); |
| 1928 | |
Nick Dyer | 385deb9 | 2014-07-23 12:42:40 -0700 | [diff] [blame] | 1929 | ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD, false); |
| 1930 | if (ret) { |
| 1931 | /* Bootloader may still be unlocked from previous attempt */ |
| 1932 | ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, false); |
| 1933 | if (ret) |
| 1934 | goto disable_irq; |
| 1935 | } else { |
| 1936 | dev_info(dev, "Unlocking bootloader\n"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1937 | |
Nick Dyer | 385deb9 | 2014-07-23 12:42:40 -0700 | [diff] [blame] | 1938 | /* Unlock bootloader */ |
Nick Dyer | 8efaa5e | 2014-07-23 12:45:49 -0700 | [diff] [blame] | 1939 | ret = mxt_send_bootloader_cmd(data, true); |
Nick Dyer | 385deb9 | 2014-07-23 12:42:40 -0700 | [diff] [blame] | 1940 | if (ret) |
| 1941 | goto disable_irq; |
| 1942 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1943 | |
| 1944 | while (pos < fw->size) { |
Nick Dyer | 385deb9 | 2014-07-23 12:42:40 -0700 | [diff] [blame] | 1945 | ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, true); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1946 | if (ret) |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1947 | goto disable_irq; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1948 | |
| 1949 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); |
| 1950 | |
Nick Dyer | f943c74 | 2014-05-18 23:14:20 -0700 | [diff] [blame] | 1951 | /* Take account of CRC bytes */ |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1952 | frame_size += 2; |
| 1953 | |
| 1954 | /* Write one frame to device */ |
Nick Dyer | f28a842 | 2014-05-18 23:10:49 -0700 | [diff] [blame] | 1955 | ret = mxt_bootloader_write(data, fw->data + pos, frame_size); |
| 1956 | if (ret) |
| 1957 | goto disable_irq; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1958 | |
Nick Dyer | 385deb9 | 2014-07-23 12:42:40 -0700 | [diff] [blame] | 1959 | ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS, true); |
Nick Dyer | f943c74 | 2014-05-18 23:14:20 -0700 | [diff] [blame] | 1960 | if (ret) { |
| 1961 | retry++; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1962 | |
Nick Dyer | f943c74 | 2014-05-18 23:14:20 -0700 | [diff] [blame] | 1963 | /* Back off by 20ms per retry */ |
| 1964 | msleep(retry * 20); |
| 1965 | |
| 1966 | if (retry > 20) { |
| 1967 | dev_err(dev, "Retry count exceeded\n"); |
| 1968 | goto disable_irq; |
| 1969 | } |
| 1970 | } else { |
| 1971 | retry = 0; |
| 1972 | pos += frame_size; |
Nick Dyer | f477c75 | 2014-05-18 23:14:45 -0700 | [diff] [blame] | 1973 | frame++; |
Nick Dyer | f943c74 | 2014-05-18 23:14:20 -0700 | [diff] [blame] | 1974 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1975 | |
Nick Dyer | f477c75 | 2014-05-18 23:14:45 -0700 | [diff] [blame] | 1976 | if (frame % 50 == 0) |
| 1977 | dev_dbg(dev, "Sent %d frames, %d/%zd bytes\n", |
| 1978 | frame, pos, fw->size); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
Benson Leung | a0434b7 | 2014-05-18 23:03:09 -0700 | [diff] [blame] | 1981 | /* Wait for flash. */ |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 1982 | ret = mxt_wait_for_completion(data, &data->bl_completion, |
| 1983 | MXT_FW_RESET_TIME); |
Benson Leung | a0434b7 | 2014-05-18 23:03:09 -0700 | [diff] [blame] | 1984 | if (ret) |
| 1985 | goto disable_irq; |
| 1986 | |
Nick Dyer | f477c75 | 2014-05-18 23:14:45 -0700 | [diff] [blame] | 1987 | dev_dbg(dev, "Sent %d frames, %d bytes\n", frame, pos); |
| 1988 | |
Benson Leung | a0434b7 | 2014-05-18 23:03:09 -0700 | [diff] [blame] | 1989 | /* |
| 1990 | * Wait for device to reset. Some bootloader versions do not assert |
| 1991 | * the CHG line after bootloading has finished, so ignore potential |
| 1992 | * errors. |
| 1993 | */ |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 1994 | mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME); |
Benson Leung | a0434b7 | 2014-05-18 23:03:09 -0700 | [diff] [blame] | 1995 | |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 1996 | data->in_bootloader = false; |
| 1997 | |
| 1998 | disable_irq: |
| 1999 | disable_irq(data->irq); |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 2000 | release_firmware: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2001 | release_firmware(fw); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2002 | return ret; |
| 2003 | } |
| 2004 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2005 | static ssize_t mxt_update_fw_store(struct device *dev, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2006 | struct device_attribute *attr, |
| 2007 | const char *buf, size_t count) |
| 2008 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2009 | struct mxt_data *data = dev_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2010 | int error; |
| 2011 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2012 | error = mxt_load_fw(dev, MXT_FW_NAME); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2013 | if (error) { |
| 2014 | dev_err(dev, "The firmware update failed(%d)\n", error); |
| 2015 | count = error; |
| 2016 | } else { |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 2017 | dev_info(dev, "The firmware update succeeded\n"); |
| 2018 | |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 2019 | error = mxt_initialize(data); |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 2020 | if (error) |
| 2021 | return error; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2024 | return count; |
| 2025 | } |
| 2026 | |
Daniel Kurtz | b19fc9e | 2012-06-28 21:08:16 +0800 | [diff] [blame] | 2027 | static DEVICE_ATTR(fw_version, S_IRUGO, mxt_fw_version_show, NULL); |
| 2028 | static DEVICE_ATTR(hw_version, S_IRUGO, mxt_hw_version_show, NULL); |
Daniel Kurtz | 71b3e93 | 2012-05-08 22:30:14 -0700 | [diff] [blame] | 2029 | static DEVICE_ATTR(object, S_IRUGO, mxt_object_show, NULL); |
| 2030 | static DEVICE_ATTR(update_fw, S_IWUSR, NULL, mxt_update_fw_store); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2031 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2032 | static struct attribute *mxt_attrs[] = { |
Daniel Kurtz | b19fc9e | 2012-06-28 21:08:16 +0800 | [diff] [blame] | 2033 | &dev_attr_fw_version.attr, |
| 2034 | &dev_attr_hw_version.attr, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2035 | &dev_attr_object.attr, |
| 2036 | &dev_attr_update_fw.attr, |
| 2037 | NULL |
| 2038 | }; |
| 2039 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2040 | static const struct attribute_group mxt_attr_group = { |
| 2041 | .attrs = mxt_attrs, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2042 | }; |
| 2043 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2044 | static void mxt_start(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2045 | { |
Linus Torvalds | 7f40548 | 2014-12-31 12:59:34 -0800 | [diff] [blame] | 2046 | /* Touch enable */ |
| 2047 | mxt_write_object(data, |
| 2048 | MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0x83); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2051 | static void mxt_stop(struct mxt_data *data) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2052 | { |
Linus Torvalds | 7f40548 | 2014-12-31 12:59:34 -0800 | [diff] [blame] | 2053 | /* Touch disable */ |
| 2054 | mxt_write_object(data, |
| 2055 | MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2058 | static int mxt_input_open(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2059 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2060 | struct mxt_data *data = input_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2061 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2062 | mxt_start(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2063 | |
| 2064 | return 0; |
| 2065 | } |
| 2066 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2067 | static void mxt_input_close(struct input_dev *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2068 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2069 | struct mxt_data *data = input_get_drvdata(dev); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2070 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2071 | mxt_stop(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Stephen Warren | 78188be | 2014-07-23 12:23:23 -0700 | [diff] [blame] | 2074 | #ifdef CONFIG_OF |
| 2075 | static struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client) |
| 2076 | { |
| 2077 | struct mxt_platform_data *pdata; |
| 2078 | u32 *keymap; |
| 2079 | u32 keycode; |
| 2080 | int proplen, i, ret; |
| 2081 | |
| 2082 | if (!client->dev.of_node) |
| 2083 | return ERR_PTR(-ENODEV); |
| 2084 | |
| 2085 | pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); |
| 2086 | if (!pdata) |
| 2087 | return ERR_PTR(-ENOMEM); |
| 2088 | |
| 2089 | if (of_find_property(client->dev.of_node, "linux,gpio-keymap", |
| 2090 | &proplen)) { |
| 2091 | pdata->t19_num_keys = proplen / sizeof(u32); |
| 2092 | |
| 2093 | keymap = devm_kzalloc(&client->dev, |
| 2094 | pdata->t19_num_keys * sizeof(keymap[0]), |
| 2095 | GFP_KERNEL); |
| 2096 | if (!keymap) |
| 2097 | return ERR_PTR(-ENOMEM); |
| 2098 | |
| 2099 | for (i = 0; i < pdata->t19_num_keys; i++) { |
| 2100 | ret = of_property_read_u32_index(client->dev.of_node, |
| 2101 | "linux,gpio-keymap", i, &keycode); |
| 2102 | if (ret) |
| 2103 | keycode = KEY_RESERVED; |
| 2104 | |
| 2105 | keymap[i] = keycode; |
| 2106 | } |
| 2107 | |
| 2108 | pdata->t19_keymap = keymap; |
| 2109 | } |
| 2110 | |
| 2111 | return pdata; |
| 2112 | } |
| 2113 | #else |
| 2114 | static struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client) |
| 2115 | { |
| 2116 | dev_dbg(&client->dev, "No platform data specified\n"); |
| 2117 | return ERR_PTR(-EINVAL); |
| 2118 | } |
| 2119 | #endif |
| 2120 | |
| 2121 | static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2122 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2123 | struct mxt_data *data; |
Stephen Warren | 78188be | 2014-07-23 12:23:23 -0700 | [diff] [blame] | 2124 | const struct mxt_platform_data *pdata; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2125 | int error; |
| 2126 | |
Stephen Warren | 78188be | 2014-07-23 12:23:23 -0700 | [diff] [blame] | 2127 | pdata = dev_get_platdata(&client->dev); |
| 2128 | if (!pdata) { |
| 2129 | pdata = mxt_parse_dt(client); |
| 2130 | if (IS_ERR(pdata)) |
| 2131 | return PTR_ERR(pdata); |
| 2132 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2133 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2134 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); |
Nick Dyer | 7a53d60 | 2014-07-23 12:21:26 -0700 | [diff] [blame] | 2135 | if (!data) { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2136 | dev_err(&client->dev, "Failed to allocate memory\n"); |
Nick Dyer | 7a53d60 | 2014-07-23 12:21:26 -0700 | [diff] [blame] | 2137 | return -ENOMEM; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
Daniel Kurtz | ec02ac2 | 2012-06-28 21:08:02 +0800 | [diff] [blame] | 2140 | snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0", |
| 2141 | client->adapter->nr, client->addr); |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 2142 | |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 2143 | data->client = client; |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 2144 | data->pdata = pdata; |
| 2145 | data->irq = client->irq; |
Nick Dyer | 7a53d60 | 2014-07-23 12:21:26 -0700 | [diff] [blame] | 2146 | i2c_set_clientdata(client, data); |
Joonyoung Shim | 910d805 | 2011-04-12 23:14:38 -0700 | [diff] [blame] | 2147 | |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 2148 | init_completion(&data->bl_completion); |
Iiro Valkonen | a4a2ef4 | 2014-05-18 23:03:44 -0700 | [diff] [blame] | 2149 | init_completion(&data->reset_completion); |
Nick Dyer | c3f7804 | 2014-05-18 23:04:46 -0700 | [diff] [blame] | 2150 | init_completion(&data->crc_completion); |
Benson Leung | d79e7e4 | 2014-05-18 23:02:52 -0700 | [diff] [blame] | 2151 | |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 2152 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, |
| 2153 | pdata->irqflags | IRQF_ONESHOT, |
| 2154 | client->name, data); |
| 2155 | if (error) { |
| 2156 | dev_err(&client->dev, "Failed to register interrupt\n"); |
| 2157 | goto err_free_mem; |
| 2158 | } |
| 2159 | |
| 2160 | disable_irq(client->irq); |
| 2161 | |
Daniel Kurtz | cb15911 | 2012-06-28 21:08:22 +0800 | [diff] [blame] | 2162 | error = mxt_initialize(data); |
| 2163 | if (error) |
Nick Dyer | 7a53d60 | 2014-07-23 12:21:26 -0700 | [diff] [blame] | 2164 | goto err_free_irq; |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2165 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2166 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 2167 | if (error) { |
| 2168 | dev_err(&client->dev, "Failure %d creating sysfs group\n", |
| 2169 | error); |
Nick Dyer | 7a53d60 | 2014-07-23 12:21:26 -0700 | [diff] [blame] | 2170 | goto err_free_object; |
Nick Dyer | 7bed680 | 2014-05-18 23:04:09 -0700 | [diff] [blame] | 2171 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2172 | |
| 2173 | return 0; |
| 2174 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2175 | err_free_object: |
Stephen Warren | 58e4aeee | 2014-09-10 10:01:10 -0700 | [diff] [blame] | 2176 | mxt_free_input_device(data); |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 2177 | mxt_free_object_table(data); |
Nick Dyer | dd24dcf | 2014-07-23 11:25:55 -0700 | [diff] [blame] | 2178 | err_free_irq: |
| 2179 | free_irq(client->irq, data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2180 | err_free_mem: |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2181 | kfree(data); |
| 2182 | return error; |
| 2183 | } |
| 2184 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 2185 | static int mxt_remove(struct i2c_client *client) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2186 | { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2187 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2188 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2189 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2190 | free_irq(data->irq, data); |
Stephen Warren | 58e4aeee | 2014-09-10 10:01:10 -0700 | [diff] [blame] | 2191 | mxt_free_input_device(data); |
Nick Dyer | 5f3f9bc | 2014-07-23 12:46:55 -0700 | [diff] [blame] | 2192 | mxt_free_object_table(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2193 | kfree(data); |
| 2194 | |
| 2195 | return 0; |
| 2196 | } |
| 2197 | |
Jingoo Han | 02b6a58 | 2014-11-02 00:04:14 -0700 | [diff] [blame] | 2198 | static int __maybe_unused mxt_suspend(struct device *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2199 | { |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 2200 | struct i2c_client *client = to_i2c_client(dev); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2201 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2202 | struct input_dev *input_dev = data->input_dev; |
| 2203 | |
| 2204 | mutex_lock(&input_dev->mutex); |
| 2205 | |
| 2206 | if (input_dev->users) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2207 | mxt_stop(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2208 | |
| 2209 | mutex_unlock(&input_dev->mutex); |
| 2210 | |
| 2211 | return 0; |
| 2212 | } |
| 2213 | |
Jingoo Han | 02b6a58 | 2014-11-02 00:04:14 -0700 | [diff] [blame] | 2214 | static int __maybe_unused mxt_resume(struct device *dev) |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2215 | { |
Dmitry Torokhov | 8b5fce0 | 2010-11-18 00:14:03 -0800 | [diff] [blame] | 2216 | struct i2c_client *client = to_i2c_client(dev); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2217 | struct mxt_data *data = i2c_get_clientdata(client); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2218 | struct input_dev *input_dev = data->input_dev; |
| 2219 | |
Linus Torvalds | 7f40548 | 2014-12-31 12:59:34 -0800 | [diff] [blame] | 2220 | mxt_soft_reset(data); |
| 2221 | |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2222 | mutex_lock(&input_dev->mutex); |
| 2223 | |
| 2224 | if (input_dev->users) |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2225 | mxt_start(data); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2226 | |
| 2227 | mutex_unlock(&input_dev->mutex); |
| 2228 | |
| 2229 | return 0; |
| 2230 | } |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2231 | |
Daniel Kurtz | 3a73c81 | 2012-05-08 22:29:14 -0700 | [diff] [blame] | 2232 | static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume); |
| 2233 | |
Stephen Warren | 78188be | 2014-07-23 12:23:23 -0700 | [diff] [blame] | 2234 | static const struct of_device_id mxt_of_match[] = { |
| 2235 | { .compatible = "atmel,maxtouch", }, |
| 2236 | {}, |
| 2237 | }; |
| 2238 | MODULE_DEVICE_TABLE(of, mxt_of_match); |
| 2239 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2240 | static const struct i2c_device_id mxt_id[] = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2241 | { "qt602240_ts", 0 }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2242 | { "atmel_mxt_ts", 0 }, |
Daniel Kurtz | 22dfab7 | 2013-03-07 19:43:33 -0800 | [diff] [blame] | 2243 | { "atmel_mxt_tp", 0 }, |
Chris Leech | 46ee2a0 | 2011-02-15 13:36:52 -0800 | [diff] [blame] | 2244 | { "mXT224", 0 }, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2245 | { } |
| 2246 | }; |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2247 | MODULE_DEVICE_TABLE(i2c, mxt_id); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2248 | |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2249 | static struct i2c_driver mxt_driver = { |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2250 | .driver = { |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2251 | .name = "atmel_mxt_ts", |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2252 | .owner = THIS_MODULE, |
Stephen Warren | 78188be | 2014-07-23 12:23:23 -0700 | [diff] [blame] | 2253 | .of_match_table = of_match_ptr(mxt_of_match), |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2254 | .pm = &mxt_pm_ops, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2255 | }, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2256 | .probe = mxt_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 2257 | .remove = mxt_remove, |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2258 | .id_table = mxt_id, |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2259 | }; |
| 2260 | |
Axel Lin | 1b92c1c | 2012-03-16 23:05:41 -0700 | [diff] [blame] | 2261 | module_i2c_driver(mxt_driver); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2262 | |
| 2263 | /* Module information */ |
| 2264 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
Iiro Valkonen | 7686b10 | 2011-02-02 23:21:58 -0800 | [diff] [blame] | 2265 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); |
Joonyoung Shim | 4cf51c3 | 2010-07-14 21:55:30 -0700 | [diff] [blame] | 2266 | MODULE_LICENSE("GPL"); |