hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/input/touchscreen/atmel_mxt_ts.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Atmel maXTouch Touchscreen driver
34 *
....@@ -7,12 +8,6 @@
78 * Copyright (C) 2016 Zodiac Inflight Innovations
89 *
910 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
10
- *
11
- * This program is free software; you can redistribute it and/or modify it
12
- * under the terms of the GNU General Public License as published by the
13
- * Free Software Foundation; either version 2 of the License, or (at your
14
- * option) any later version.
15
- *
1611 */
1712
1813 #include <linux/acpi.h>
....@@ -25,11 +20,11 @@
2520 #include <linux/i2c.h>
2621 #include <linux/input/mt.h>
2722 #include <linux/interrupt.h>
23
+#include <linux/irq.h>
2824 #include <linux/of.h>
2925 #include <linux/property.h>
3026 #include <linux/slab.h>
3127 #include <linux/gpio/consumer.h>
32
-#include <linux/property.h>
3328 #include <asm/unaligned.h>
3429 #include <media/v4l2-device.h>
3530 #include <media/v4l2-ioctl.h>
....@@ -135,6 +130,7 @@
135130 /* MXT_SPT_COMMSCONFIG_T18 */
136131 #define MXT_COMMS_CTRL 0
137132 #define MXT_COMMS_CMD 1
133
+#define MXT_COMMS_RETRIGEN BIT(6)
138134
139135 /* MXT_DEBUG_DIAGNOSTIC_T37 */
140136 #define MXT_DIAGNOSTIC_PAGEUP 0x01
....@@ -262,16 +258,6 @@
262258 MXT_V4L_INPUT_MAX,
263259 };
264260
265
-static const struct v4l2_file_operations mxt_video_fops = {
266
- .owner = THIS_MODULE,
267
- .open = v4l2_fh_open,
268
- .release = vb2_fop_release,
269
- .unlocked_ioctl = video_ioctl2,
270
- .read = vb2_fop_read,
271
- .mmap = vb2_fop_mmap,
272
- .poll = vb2_fop_poll,
273
-};
274
-
275261 enum mxt_suspend_mode {
276262 MXT_SUSPEND_DEEP_SLEEP = 0,
277263 MXT_SUSPEND_T9_CTRL = 1,
....@@ -324,6 +310,7 @@
324310 struct t7_config t7_cfg;
325311 struct mxt_dbg dbg;
326312 struct gpio_desc *reset_gpio;
313
+ bool use_retrigen_workaround;
327314
328315 /* Cached parameters from object table */
329316 u16 T5_address;
....@@ -334,6 +321,7 @@
334321 u16 T71_address;
335322 u8 T9_reportid_min;
336323 u8 T9_reportid_max;
324
+ u16 T18_address;
337325 u8 T19_reportid;
338326 u16 T44_address;
339327 u8 T100_reportid_min;
....@@ -489,7 +477,7 @@
489477 bootloader = appmode - 0x24;
490478 break;
491479 }
492
- /* Fall through for normal case */
480
+ fallthrough; /* for normal case */
493481 case 0x4c:
494482 case 0x4d:
495483 case 0x5a:
....@@ -838,8 +826,7 @@
838826 * have happened.
839827 */
840828 if (status & MXT_T9_RELEASE) {
841
- input_mt_report_slot_state(input_dev,
842
- MT_TOOL_FINGER, 0);
829
+ input_mt_report_slot_inactive(input_dev);
843830 mxt_input_sync(data);
844831 }
845832
....@@ -855,7 +842,7 @@
855842 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area);
856843 } else {
857844 /* Touch no longer active, close out slot */
858
- input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0);
845
+ input_mt_report_slot_inactive(input_dev);
859846 }
860847
861848 data->update_input = true;
....@@ -963,7 +950,7 @@
963950 dev_dbg(dev, "[%u] release\n", id);
964951
965952 /* close out slot */
966
- input_mt_report_slot_state(input_dev, 0, 0);
953
+ input_mt_report_slot_inactive(input_dev);
967954 }
968955
969956 data->update_input = true;
....@@ -1207,9 +1194,11 @@
12071194
12081195 enable_irq(data->irq);
12091196
1210
- error = mxt_process_messages_until_invalid(data);
1211
- if (error)
1212
- return error;
1197
+ if (data->use_retrigen_workaround) {
1198
+ error = mxt_process_messages_until_invalid(data);
1199
+ if (error)
1200
+ return error;
1201
+ }
12131202
12141203 return 0;
12151204 }
....@@ -1297,6 +1286,38 @@
12971286 crc &= 0x00FFFFFF;
12981287
12991288 return crc;
1289
+}
1290
+
1291
+static int mxt_check_retrigen(struct mxt_data *data)
1292
+{
1293
+ struct i2c_client *client = data->client;
1294
+ int error;
1295
+ int val;
1296
+ struct irq_data *irqd;
1297
+
1298
+ data->use_retrigen_workaround = false;
1299
+
1300
+ irqd = irq_get_irq_data(data->irq);
1301
+ if (!irqd)
1302
+ return -EINVAL;
1303
+
1304
+ if (irqd_is_level_type(irqd))
1305
+ return 0;
1306
+
1307
+ if (data->T18_address) {
1308
+ error = __mxt_read_reg(client,
1309
+ data->T18_address + MXT_COMMS_CTRL,
1310
+ 1, &val);
1311
+ if (error)
1312
+ return error;
1313
+
1314
+ if (val & MXT_COMMS_RETRIGEN)
1315
+ return 0;
1316
+ }
1317
+
1318
+ dev_warn(&client->dev, "Enabling RETRIGEN workaround\n");
1319
+ data->use_retrigen_workaround = true;
1320
+ return 0;
13001321 }
13011322
13021323 static int mxt_prepare_cfg_mem(struct mxt_data *data, struct mxt_cfg *cfg)
....@@ -1527,7 +1548,8 @@
15271548 } else if (config_crc == data->config_crc) {
15281549 dev_dbg(dev, "Config CRC 0x%06X: OK\n",
15291550 data->config_crc);
1530
- return 0;
1551
+ ret = 0;
1552
+ goto release_raw;
15311553 } else {
15321554 dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n",
15331555 data->config_crc, config_crc);
....@@ -1577,6 +1599,10 @@
15771599
15781600 mxt_update_crc(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE);
15791601
1602
+ ret = mxt_check_retrigen(data);
1603
+ if (ret)
1604
+ goto release_mem;
1605
+
15801606 ret = mxt_soft_reset(data);
15811607 if (ret)
15821608 goto release_mem;
....@@ -1620,6 +1646,7 @@
16201646 data->T71_address = 0;
16211647 data->T9_reportid_min = 0;
16221648 data->T9_reportid_max = 0;
1649
+ data->T18_address = 0;
16231650 data->T19_reportid = 0;
16241651 data->T44_address = 0;
16251652 data->T100_reportid_min = 0;
....@@ -1693,6 +1720,9 @@
16931720 data->T9_reportid_max = min_id +
16941721 object->num_report_ids - 1;
16951722 data->num_touchids = object->num_report_ids;
1723
+ break;
1724
+ case MXT_SPT_COMMSCONFIG_T18:
1725
+ data->T18_address = object->start_address;
16961726 break;
16971727 case MXT_SPT_MESSAGECOUNT_T44:
16981728 data->T44_address = object->start_address;
....@@ -2153,6 +2183,10 @@
21532183 msleep(MXT_FW_RESET_TIME);
21542184 }
21552185
2186
+ error = mxt_check_retrigen(data);
2187
+ if (error)
2188
+ return error;
2189
+
21562190 error = mxt_acquire_irq(data);
21572191 if (error)
21582192 return error;
....@@ -2224,6 +2258,16 @@
22242258 }
22252259
22262260 #ifdef CONFIG_TOUCHSCREEN_ATMEL_MXT_T37
2261
+static const struct v4l2_file_operations mxt_video_fops = {
2262
+ .owner = THIS_MODULE,
2263
+ .open = v4l2_fh_open,
2264
+ .release = vb2_fop_release,
2265
+ .unlocked_ioctl = video_ioctl2,
2266
+ .read = vb2_fop_read,
2267
+ .mmap = vb2_fop_mmap,
2268
+ .poll = vb2_fop_poll,
2269
+};
2270
+
22272271 static u16 mxt_get_debug_value(struct mxt_data *data, unsigned int x,
22282272 unsigned int y)
22292273 {
....@@ -2995,8 +3039,7 @@
29953039 int error;
29963040
29973041 if (device_property_present(dev, keymap_property)) {
2998
- n_keys = device_property_read_u32_array(dev, keymap_property,
2999
- NULL, 0);
3042
+ n_keys = device_property_count_u32(dev, keymap_property);
30003043 if (n_keys <= 0) {
30013044 error = n_keys < 0 ? n_keys : -EINVAL;
30023045 dev_err(dev, "invalid/malformed '%s' property: %d\n",
....@@ -3091,8 +3134,9 @@
30913134 if (error)
30923135 return error;
30933136
3137
+ /* Request the RESET line as asserted so we go into reset */
30943138 data->reset_gpio = devm_gpiod_get_optional(&client->dev,
3095
- "reset", GPIOD_OUT_LOW);
3139
+ "reset", GPIOD_OUT_HIGH);
30963140 if (IS_ERR(data->reset_gpio)) {
30973141 error = PTR_ERR(data->reset_gpio);
30983142 dev_err(&client->dev, "Failed to get reset gpio: %d\n", error);
....@@ -3110,8 +3154,9 @@
31103154 disable_irq(client->irq);
31113155
31123156 if (data->reset_gpio) {
3157
+ /* Wait a while and then de-assert the RESET GPIO line */
31133158 msleep(MXT_RESET_GPIO_TIME);
3114
- gpiod_set_value(data->reset_gpio, 1);
3159
+ gpiod_set_value(data->reset_gpio, 0);
31153160 msleep(MXT_RESET_INVALID_CHG);
31163161 }
31173162