.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * ADS7846 based touchscreen and sensor driver |
---|
3 | 4 | * |
---|
.. | .. |
---|
12 | 13 | * Copyright (C) 2002 MontaVista Software |
---|
13 | 14 | * Copyright (C) 2004 Texas Instruments |
---|
14 | 15 | * 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. |
---|
19 | 16 | */ |
---|
20 | 17 | #include <linux/types.h> |
---|
21 | 18 | #include <linux/hwmon.h> |
---|
.. | .. |
---|
23 | 20 | #include <linux/sched.h> |
---|
24 | 21 | #include <linux/delay.h> |
---|
25 | 22 | #include <linux/input.h> |
---|
| 23 | +#include <linux/input/touchscreen.h> |
---|
26 | 24 | #include <linux/interrupt.h> |
---|
27 | 25 | #include <linux/slab.h> |
---|
28 | 26 | #include <linux/pm.h> |
---|
.. | .. |
---|
132 | 130 | u16 debounce_rep; |
---|
133 | 131 | |
---|
134 | 132 | u16 penirq_recheck_delay_usecs; |
---|
| 133 | + |
---|
| 134 | + struct touchscreen_properties core_prop; |
---|
135 | 135 | |
---|
136 | 136 | struct mutex lock; |
---|
137 | 137 | bool stopped; /* P: lock */ |
---|
.. | .. |
---|
358 | 358 | req->xfer[1].len = 2; |
---|
359 | 359 | |
---|
360 | 360 | /* 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; |
---|
362 | 363 | spi_message_add_tail(&req->xfer[1], &req->msg); |
---|
363 | 364 | |
---|
364 | 365 | /* Enable reference voltage */ |
---|
.. | .. |
---|
844 | 845 | if (Rt) { |
---|
845 | 846 | struct input_dev *input = ts->input; |
---|
846 | 847 | |
---|
847 | | - if (ts->swap_xy) |
---|
848 | | - swap(x, y); |
---|
849 | | - |
---|
850 | 848 | if (!ts->pendown) { |
---|
851 | 849 | input_report_key(input, BTN_TOUCH, 1); |
---|
852 | 850 | ts->pendown = true; |
---|
853 | 851 | dev_vdbg(&ts->spi->dev, "DOWN\n"); |
---|
854 | 852 | } |
---|
855 | 853 | |
---|
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); |
---|
858 | 855 | input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); |
---|
859 | 856 | |
---|
860 | 857 | input_sync(input); |
---|
.. | .. |
---|
1032 | 1029 | * have had enough time to stabilize. |
---|
1033 | 1030 | */ |
---|
1034 | 1031 | 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; |
---|
1036 | 1034 | |
---|
1037 | 1035 | x++; |
---|
1038 | 1036 | x->tx_buf = &packet->read_y; |
---|
.. | .. |
---|
1075 | 1073 | |
---|
1076 | 1074 | /* ... maybe discard first sample ... */ |
---|
1077 | 1075 | 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; |
---|
1079 | 1078 | |
---|
1080 | 1079 | x++; |
---|
1081 | 1080 | x->tx_buf = &packet->read_x; |
---|
.. | .. |
---|
1108 | 1107 | |
---|
1109 | 1108 | /* ... maybe discard first sample ... */ |
---|
1110 | 1109 | 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; |
---|
1112 | 1112 | |
---|
1113 | 1113 | x++; |
---|
1114 | 1114 | x->tx_buf = &packet->read_z1; |
---|
.. | .. |
---|
1139 | 1139 | |
---|
1140 | 1140 | /* ... maybe discard first sample ... */ |
---|
1141 | 1141 | 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; |
---|
1143 | 1144 | |
---|
1144 | 1145 | x++; |
---|
1145 | 1146 | x->tx_buf = &packet->read_z2; |
---|
.. | .. |
---|
1198 | 1199 | struct ads7846_platform_data *pdata; |
---|
1199 | 1200 | struct device_node *node = dev->of_node; |
---|
1200 | 1201 | const struct of_device_id *match; |
---|
| 1202 | + u32 value; |
---|
1201 | 1203 | |
---|
1202 | 1204 | if (!node) { |
---|
1203 | 1205 | dev_err(dev, "Device does not have associated DT data\n"); |
---|
.. | .. |
---|
1236 | 1238 | of_property_read_u16(node, "ti,x-max", &pdata->x_max); |
---|
1237 | 1239 | of_property_read_u16(node, "ti,y-max", &pdata->y_max); |
---|
1238 | 1240 | |
---|
| 1241 | + /* |
---|
| 1242 | + * touchscreen-max-pressure gets parsed during |
---|
| 1243 | + * touchscreen_parse_properties() |
---|
| 1244 | + */ |
---|
1239 | 1245 | 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; |
---|
1240 | 1248 | of_property_read_u16(node, "ti,pressure-max", &pdata->pressure_max); |
---|
1241 | 1249 | |
---|
1242 | 1250 | 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; |
---|
1243 | 1253 | of_property_read_u16(node, "ti,debounce-tol", &pdata->debounce_tol); |
---|
1244 | 1254 | of_property_read_u16(node, "ti,debounce-rep", &pdata->debounce_rep); |
---|
1245 | 1255 | |
---|
.. | .. |
---|
1322 | 1332 | ts->model = pdata->model ? : 7846; |
---|
1323 | 1333 | ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; |
---|
1324 | 1334 | ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; |
---|
1325 | | - ts->pressure_max = pdata->pressure_max ? : ~0; |
---|
1326 | | - |
---|
1327 | 1335 | ts->vref_mv = pdata->vref_mv; |
---|
1328 | | - ts->swap_xy = pdata->swap_xy; |
---|
1329 | 1336 | |
---|
1330 | 1337 | if (pdata->filter != NULL) { |
---|
1331 | 1338 | if (pdata->filter_init != NULL) { |
---|
.. | .. |
---|
1377 | 1384 | input_set_abs_params(input_dev, ABS_PRESSURE, |
---|
1378 | 1385 | pdata->pressure_min, pdata->pressure_max, 0, 0); |
---|
1379 | 1386 | |
---|
| 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 | + |
---|
1380 | 1404 | ads7846_setup_spi_msg(ts, pdata); |
---|
1381 | 1405 | |
---|
1382 | 1406 | ts->reg = regulator_get(&spi->dev, "vcc"); |
---|