hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/input/touchscreen/ads7846.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ADS7846 based touchscreen and sensor driver
34 *
....@@ -12,10 +13,6 @@
1213 * Copyright (C) 2002 MontaVista Software
1314 * Copyright (C) 2004 Texas Instruments
1415 * Copyright (C) 2005 Dirk Behme
15
- *
16
- * This program is free software; you can redistribute it and/or modify
17
- * it under the terms of the GNU General Public License version 2 as
18
- * published by the Free Software Foundation.
1916 */
2017 #include <linux/types.h>
2118 #include <linux/hwmon.h>
....@@ -23,6 +20,7 @@
2320 #include <linux/sched.h>
2421 #include <linux/delay.h>
2522 #include <linux/input.h>
23
+#include <linux/input/touchscreen.h>
2624 #include <linux/interrupt.h>
2725 #include <linux/slab.h>
2826 #include <linux/pm.h>
....@@ -132,6 +130,8 @@
132130 u16 debounce_rep;
133131
134132 u16 penirq_recheck_delay_usecs;
133
+
134
+ struct touchscreen_properties core_prop;
135135
136136 struct mutex lock;
137137 bool stopped; /* P: lock */
....@@ -358,7 +358,8 @@
358358 req->xfer[1].len = 2;
359359
360360 /* for 1uF, settle for 800 usec; no cap, 100 usec. */
361
- req->xfer[1].delay_usecs = ts->vref_delay_usecs;
361
+ req->xfer[1].delay.value = ts->vref_delay_usecs;
362
+ req->xfer[1].delay.unit = SPI_DELAY_UNIT_USECS;
362363 spi_message_add_tail(&req->xfer[1], &req->msg);
363364
364365 /* Enable reference voltage */
....@@ -844,17 +845,13 @@
844845 if (Rt) {
845846 struct input_dev *input = ts->input;
846847
847
- if (ts->swap_xy)
848
- swap(x, y);
849
-
850848 if (!ts->pendown) {
851849 input_report_key(input, BTN_TOUCH, 1);
852850 ts->pendown = true;
853851 dev_vdbg(&ts->spi->dev, "DOWN\n");
854852 }
855853
856
- input_report_abs(input, ABS_X, x);
857
- input_report_abs(input, ABS_Y, y);
854
+ touchscreen_report_pos(input, &ts->core_prop, x, y, false);
858855 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt);
859856
860857 input_sync(input);
....@@ -1032,7 +1029,8 @@
10321029 * have had enough time to stabilize.
10331030 */
10341031 if (pdata->settle_delay_usecs) {
1035
- x->delay_usecs = pdata->settle_delay_usecs;
1032
+ x->delay.value = pdata->settle_delay_usecs;
1033
+ x->delay.unit = SPI_DELAY_UNIT_USECS;
10361034
10371035 x++;
10381036 x->tx_buf = &packet->read_y;
....@@ -1075,7 +1073,8 @@
10751073
10761074 /* ... maybe discard first sample ... */
10771075 if (pdata->settle_delay_usecs) {
1078
- x->delay_usecs = pdata->settle_delay_usecs;
1076
+ x->delay.value = pdata->settle_delay_usecs;
1077
+ x->delay.unit = SPI_DELAY_UNIT_USECS;
10791078
10801079 x++;
10811080 x->tx_buf = &packet->read_x;
....@@ -1108,7 +1107,8 @@
11081107
11091108 /* ... maybe discard first sample ... */
11101109 if (pdata->settle_delay_usecs) {
1111
- x->delay_usecs = pdata->settle_delay_usecs;
1110
+ x->delay.value = pdata->settle_delay_usecs;
1111
+ x->delay.unit = SPI_DELAY_UNIT_USECS;
11121112
11131113 x++;
11141114 x->tx_buf = &packet->read_z1;
....@@ -1139,7 +1139,8 @@
11391139
11401140 /* ... maybe discard first sample ... */
11411141 if (pdata->settle_delay_usecs) {
1142
- x->delay_usecs = pdata->settle_delay_usecs;
1142
+ x->delay.value = pdata->settle_delay_usecs;
1143
+ x->delay.unit = SPI_DELAY_UNIT_USECS;
11431144
11441145 x++;
11451146 x->tx_buf = &packet->read_z2;
....@@ -1198,6 +1199,7 @@
11981199 struct ads7846_platform_data *pdata;
11991200 struct device_node *node = dev->of_node;
12001201 const struct of_device_id *match;
1202
+ u32 value;
12011203
12021204 if (!node) {
12031205 dev_err(dev, "Device does not have associated DT data\n");
....@@ -1236,10 +1238,18 @@
12361238 of_property_read_u16(node, "ti,x-max", &pdata->x_max);
12371239 of_property_read_u16(node, "ti,y-max", &pdata->y_max);
12381240
1241
+ /*
1242
+ * touchscreen-max-pressure gets parsed during
1243
+ * touchscreen_parse_properties()
1244
+ */
12391245 of_property_read_u16(node, "ti,pressure-min", &pdata->pressure_min);
1246
+ if (!of_property_read_u32(node, "touchscreen-min-pressure", &value))
1247
+ pdata->pressure_min = (u16) value;
12401248 of_property_read_u16(node, "ti,pressure-max", &pdata->pressure_max);
12411249
12421250 of_property_read_u16(node, "ti,debounce-max", &pdata->debounce_max);
1251
+ if (!of_property_read_u32(node, "touchscreen-average-samples", &value))
1252
+ pdata->debounce_max = (u16) value;
12431253 of_property_read_u16(node, "ti,debounce-tol", &pdata->debounce_tol);
12441254 of_property_read_u16(node, "ti,debounce-rep", &pdata->debounce_rep);
12451255
....@@ -1322,10 +1332,7 @@
13221332 ts->model = pdata->model ? : 7846;
13231333 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
13241334 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
1325
- ts->pressure_max = pdata->pressure_max ? : ~0;
1326
-
13271335 ts->vref_mv = pdata->vref_mv;
1328
- ts->swap_xy = pdata->swap_xy;
13291336
13301337 if (pdata->filter != NULL) {
13311338 if (pdata->filter_init != NULL) {
....@@ -1377,6 +1384,23 @@
13771384 input_set_abs_params(input_dev, ABS_PRESSURE,
13781385 pdata->pressure_min, pdata->pressure_max, 0, 0);
13791386
1387
+ /*
1388
+ * Parse common framework properties. Must be done here to ensure the
1389
+ * correct behaviour in case of using the legacy vendor bindings. The
1390
+ * general binding value overrides the vendor specific one.
1391
+ */
1392
+ touchscreen_parse_properties(ts->input, false, &ts->core_prop);
1393
+ ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0;
1394
+
1395
+ /*
1396
+ * Check if legacy ti,swap-xy binding is used instead of
1397
+ * touchscreen-swapped-x-y
1398
+ */
1399
+ if (!ts->core_prop.swap_x_y && pdata->swap_xy) {
1400
+ swap(input_dev->absinfo[ABS_X], input_dev->absinfo[ABS_Y]);
1401
+ ts->core_prop.swap_x_y = true;
1402
+ }
1403
+
13801404 ads7846_setup_spi_msg(ts, pdata);
13811405
13821406 ts->reg = regulator_get(&spi->dev, "vcc");