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