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