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