hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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>
....@@ -65,19 +63,15 @@
6563 /* this driver doesn't aim at the peak continuous sample rate */
6664 #define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */)
6765
68
-struct ts_event {
69
- /*
70
- * For portability, we can't read 12 bit values using SPI (which
71
- * would make the controller deliver them as native byte order u16
72
- * with msbs zeroed). Instead, we read them as two 8-bit values,
73
- * *** WHICH NEED BYTESWAPPING *** and range adjustment.
74
- */
75
- u16 x;
76
- u16 y;
77
- u16 z1, z2;
78
- bool ignore;
79
- u8 x_buf[3];
80
- u8 y_buf[3];
66
+struct ads7846_buf {
67
+ u8 cmd;
68
+ __be16 data;
69
+} __packed;
70
+
71
+struct ads7846_buf_layout {
72
+ unsigned int offset;
73
+ unsigned int count;
74
+ unsigned int skip;
8175 };
8276
8377 /*
....@@ -86,11 +80,18 @@
8680 * systems where main memory is not DMA-coherent (most non-x86 boards).
8781 */
8882 struct ads7846_packet {
89
- u8 read_x, read_y, read_z1, read_z2, pwrdown;
90
- u16 dummy; /* for the pwrdown read */
91
- struct ts_event tc;
92
- /* for ads7845 with mpc5121 psc spi we use 3-byte buffers */
93
- u8 read_x_cmd[3], read_y_cmd[3], pwrdown_cmd[3];
83
+ unsigned int count;
84
+ unsigned int count_skip;
85
+ unsigned int cmds;
86
+ unsigned int last_cmd_idx;
87
+ struct ads7846_buf_layout l[5];
88
+ struct ads7846_buf *rx;
89
+ struct ads7846_buf *tx;
90
+
91
+ struct ads7846_buf pwrdown_cmd;
92
+
93
+ bool ignore;
94
+ u16 x, y, z1, z2;
9495 };
9596
9697 struct ads7846 {
....@@ -132,6 +133,8 @@
132133 u16 debounce_rep;
133134
134135 u16 penirq_recheck_delay_usecs;
136
+
137
+ struct touchscreen_properties core_prop;
135138
136139 struct mutex lock;
137140 bool stopped; /* P: lock */
....@@ -187,7 +190,6 @@
187190 #define READ_Y(vref) (READ_12BIT_DFR(y, 1, vref))
188191 #define READ_Z1(vref) (READ_12BIT_DFR(z1, 1, vref))
189192 #define READ_Z2(vref) (READ_12BIT_DFR(z2, 1, vref))
190
-
191193 #define READ_X(vref) (READ_12BIT_DFR(x, 1, vref))
192194 #define PWRDOWN (READ_12BIT_DFR(y, 0, 0)) /* LAST */
193195
....@@ -199,6 +201,21 @@
199201
200202 #define REF_ON (READ_12BIT_DFR(x, 1, 1))
201203 #define REF_OFF (READ_12BIT_DFR(y, 0, 0))
204
+
205
+/* Order commands in the most optimal way to reduce Vref switching and
206
+ * settling time:
207
+ * Measure: X; Vref: X+, X-; IN: Y+
208
+ * Measure: Y; Vref: Y+, Y-; IN: X+
209
+ * Measure: Z1; Vref: Y+, X-; IN: X+
210
+ * Measure: Z2; Vref: Y+, X-; IN: Y-
211
+ */
212
+enum ads7846_cmds {
213
+ ADS7846_X,
214
+ ADS7846_Y,
215
+ ADS7846_Z1,
216
+ ADS7846_Z2,
217
+ ADS7846_PWDOWN,
218
+};
202219
203220 static int get_pendown_state(struct ads7846 *ts)
204221 {
....@@ -358,7 +375,8 @@
358375 req->xfer[1].len = 2;
359376
360377 /* for 1uF, settle for 800 usec; no cap, 100 usec. */
361
- req->xfer[1].delay_usecs = ts->vref_delay_usecs;
378
+ req->xfer[1].delay.value = ts->vref_delay_usecs;
379
+ req->xfer[1].delay.unit = SPI_DELAY_UNIT_USECS;
362380 spi_message_add_tail(&req->xfer[1], &req->msg);
363381
364382 /* Enable reference voltage */
....@@ -681,32 +699,109 @@
681699 return ADS7846_FILTER_OK;
682700 }
683701
684
-static int ads7846_get_value(struct ads7846 *ts, struct spi_message *m)
702
+static int ads7846_get_value(struct ads7846_buf *buf)
685703 {
686704 int value;
687
- struct spi_transfer *t =
688
- list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
689705
690
- if (ts->model == 7845) {
691
- value = be16_to_cpup((__be16 *)&(((char *)t->rx_buf)[1]));
692
- } else {
693
- /*
694
- * adjust: on-wire is a must-ignore bit, a BE12 value, then
695
- * padding; built from two 8 bit values written msb-first.
696
- */
697
- value = be16_to_cpup((__be16 *)t->rx_buf);
698
- }
706
+ value = be16_to_cpup(&buf->data);
699707
700708 /* enforce ADC output is 12 bits width */
701709 return (value >> 3) & 0xfff;
702710 }
703711
704
-static void ads7846_update_value(struct spi_message *m, int val)
712
+static void ads7846_set_cmd_val(struct ads7846 *ts, enum ads7846_cmds cmd_idx,
713
+ u16 val)
705714 {
706
- struct spi_transfer *t =
707
- list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
715
+ struct ads7846_packet *packet = ts->packet;
708716
709
- *(u16 *)t->rx_buf = val;
717
+ switch (cmd_idx) {
718
+ case ADS7846_Y:
719
+ packet->y = val;
720
+ break;
721
+ case ADS7846_X:
722
+ packet->x = val;
723
+ break;
724
+ case ADS7846_Z1:
725
+ packet->z1 = val;
726
+ break;
727
+ case ADS7846_Z2:
728
+ packet->z2 = val;
729
+ break;
730
+ default:
731
+ WARN_ON_ONCE(1);
732
+ }
733
+}
734
+
735
+static u8 ads7846_get_cmd(enum ads7846_cmds cmd_idx, int vref)
736
+{
737
+ switch (cmd_idx) {
738
+ case ADS7846_Y:
739
+ return READ_Y(vref);
740
+ case ADS7846_X:
741
+ return READ_X(vref);
742
+
743
+ /* 7846 specific commands */
744
+ case ADS7846_Z1:
745
+ return READ_Z1(vref);
746
+ case ADS7846_Z2:
747
+ return READ_Z2(vref);
748
+ case ADS7846_PWDOWN:
749
+ return PWRDOWN;
750
+ default:
751
+ WARN_ON_ONCE(1);
752
+ }
753
+
754
+ return 0;
755
+}
756
+
757
+static bool ads7846_cmd_need_settle(enum ads7846_cmds cmd_idx)
758
+{
759
+ switch (cmd_idx) {
760
+ case ADS7846_X:
761
+ case ADS7846_Y:
762
+ case ADS7846_Z1:
763
+ case ADS7846_Z2:
764
+ return true;
765
+ case ADS7846_PWDOWN:
766
+ return false;
767
+ default:
768
+ WARN_ON_ONCE(1);
769
+ }
770
+
771
+ return false;
772
+}
773
+
774
+static int ads7846_filter(struct ads7846 *ts)
775
+{
776
+ struct ads7846_packet *packet = ts->packet;
777
+ int action;
778
+ int val;
779
+ unsigned int cmd_idx, b;
780
+
781
+ packet->ignore = false;
782
+ for (cmd_idx = packet->last_cmd_idx; cmd_idx < packet->cmds - 1; cmd_idx++) {
783
+ struct ads7846_buf_layout *l = &packet->l[cmd_idx];
784
+
785
+ packet->last_cmd_idx = cmd_idx;
786
+
787
+ for (b = l->skip; b < l->count; b++) {
788
+ val = ads7846_get_value(&packet->rx[l->offset + b]);
789
+
790
+ action = ts->filter(ts->filter_data, cmd_idx, &val);
791
+ if (action == ADS7846_FILTER_REPEAT) {
792
+ if (b == l->count - 1)
793
+ return -EAGAIN;
794
+ } else if (action == ADS7846_FILTER_OK) {
795
+ ads7846_set_cmd_val(ts, cmd_idx, val);
796
+ break;
797
+ } else {
798
+ packet->ignore = true;
799
+ return 0;
800
+ }
801
+ }
802
+ }
803
+
804
+ return 0;
710805 }
711806
712807 static void ads7846_read_state(struct ads7846 *ts)
....@@ -714,52 +809,26 @@
714809 struct ads7846_packet *packet = ts->packet;
715810 struct spi_message *m;
716811 int msg_idx = 0;
717
- int val;
718
- int action;
719812 int error;
720813
721
- while (msg_idx < ts->msg_count) {
814
+ packet->last_cmd_idx = 0;
722815
816
+ while (true) {
723817 ts->wait_for_sync();
724818
725819 m = &ts->msg[msg_idx];
726820 error = spi_sync(ts->spi, m);
727821 if (error) {
728822 dev_err(&ts->spi->dev, "spi_sync --> %d\n", error);
729
- packet->tc.ignore = true;
823
+ packet->ignore = true;
730824 return;
731825 }
732826
733
- /*
734
- * Last message is power down request, no need to convert
735
- * or filter the value.
736
- */
737
- if (msg_idx < ts->msg_count - 1) {
827
+ error = ads7846_filter(ts);
828
+ if (error)
829
+ continue;
738830
739
- val = ads7846_get_value(ts, m);
740
-
741
- action = ts->filter(ts->filter_data, msg_idx, &val);
742
- switch (action) {
743
- case ADS7846_FILTER_REPEAT:
744
- continue;
745
-
746
- case ADS7846_FILTER_IGNORE:
747
- packet->tc.ignore = true;
748
- msg_idx = ts->msg_count - 1;
749
- continue;
750
-
751
- case ADS7846_FILTER_OK:
752
- ads7846_update_value(m, val);
753
- packet->tc.ignore = false;
754
- msg_idx++;
755
- break;
756
-
757
- default:
758
- BUG();
759
- }
760
- } else {
761
- msg_idx++;
762
- }
831
+ return;
763832 }
764833 }
765834
....@@ -769,35 +838,22 @@
769838 unsigned int Rt;
770839 u16 x, y, z1, z2;
771840
772
- /*
773
- * ads7846_get_value() does in-place conversion (including byte swap)
774
- * from on-the-wire format as part of debouncing to get stable
775
- * readings.
776
- */
841
+ x = packet->x;
842
+ y = packet->y;
777843 if (ts->model == 7845) {
778
- x = *(u16 *)packet->tc.x_buf;
779
- y = *(u16 *)packet->tc.y_buf;
780844 z1 = 0;
781845 z2 = 0;
782846 } else {
783
- x = packet->tc.x;
784
- y = packet->tc.y;
785
- z1 = packet->tc.z1;
786
- z2 = packet->tc.z2;
847
+ z1 = packet->z1;
848
+ z2 = packet->z2;
787849 }
788850
789851 /* range filtering */
790852 if (x == MAX_12BIT)
791853 x = 0;
792854
793
- if (ts->model == 7843) {
855
+ if (ts->model == 7843 || ts->model == 7845) {
794856 Rt = ts->pressure_max / 2;
795
- } else if (ts->model == 7845) {
796
- if (get_pendown_state(ts))
797
- Rt = ts->pressure_max / 2;
798
- else
799
- Rt = 0;
800
- dev_vdbg(&ts->spi->dev, "x/y: %d/%d, PD %d\n", x, y, Rt);
801857 } else if (likely(x && z1)) {
802858 /* compute touch pressure resistance using equation #2 */
803859 Rt = z2;
....@@ -816,9 +872,9 @@
816872 * the maximum. Don't report it to user space, repeat at least
817873 * once more the measurement
818874 */
819
- if (packet->tc.ignore || Rt > ts->pressure_max) {
875
+ if (packet->ignore || Rt > ts->pressure_max) {
820876 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n",
821
- packet->tc.ignore, Rt);
877
+ packet->ignore, Rt);
822878 return;
823879 }
824880
....@@ -844,17 +900,13 @@
844900 if (Rt) {
845901 struct input_dev *input = ts->input;
846902
847
- if (ts->swap_xy)
848
- swap(x, y);
849
-
850903 if (!ts->pendown) {
851904 input_report_key(input, BTN_TOUCH, 1);
852905 ts->pendown = true;
853906 dev_vdbg(&ts->spi->dev, "DOWN\n");
854907 }
855908
856
- input_report_abs(input, ABS_X, x);
857
- input_report_abs(input, ABS_Y, y);
909
+ touchscreen_report_pos(input, &ts->core_prop, x, y, false);
858910 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt);
859911
860912 input_sync(input);
....@@ -983,13 +1035,62 @@
9831035 * Set up the transfers to read touchscreen state; this assumes we
9841036 * use formula #2 for pressure, not #3.
9851037 */
986
-static void ads7846_setup_spi_msg(struct ads7846 *ts,
1038
+static int ads7846_setup_spi_msg(struct ads7846 *ts,
9871039 const struct ads7846_platform_data *pdata)
9881040 {
9891041 struct spi_message *m = &ts->msg[0];
9901042 struct spi_transfer *x = ts->xfer;
9911043 struct ads7846_packet *packet = ts->packet;
9921044 int vref = pdata->keep_vref_on;
1045
+ unsigned int count, offset = 0;
1046
+ unsigned int cmd_idx, b;
1047
+ unsigned long time;
1048
+ size_t size = 0;
1049
+
1050
+ /* time per bit */
1051
+ time = NSEC_PER_SEC / ts->spi->max_speed_hz;
1052
+
1053
+ count = pdata->settle_delay_usecs * NSEC_PER_USEC / time;
1054
+ packet->count_skip = DIV_ROUND_UP(count, 24);
1055
+
1056
+ if (ts->debounce_max && ts->debounce_rep)
1057
+ /* ads7846_debounce_filter() is making ts->debounce_rep + 2
1058
+ * reads. So we need to get all samples for normal case. */
1059
+ packet->count = ts->debounce_rep + 2;
1060
+ else
1061
+ packet->count = 1;
1062
+
1063
+ if (ts->model == 7846)
1064
+ packet->cmds = 5; /* x, y, z1, z2, pwdown */
1065
+ else
1066
+ packet->cmds = 3; /* x, y, pwdown */
1067
+
1068
+ for (cmd_idx = 0; cmd_idx < packet->cmds; cmd_idx++) {
1069
+ struct ads7846_buf_layout *l = &packet->l[cmd_idx];
1070
+ unsigned int max_count;
1071
+
1072
+ if (cmd_idx == packet->cmds - 1)
1073
+ cmd_idx = ADS7846_PWDOWN;
1074
+
1075
+ if (ads7846_cmd_need_settle(cmd_idx))
1076
+ max_count = packet->count + packet->count_skip;
1077
+ else
1078
+ max_count = packet->count;
1079
+
1080
+ l->offset = offset;
1081
+ offset += max_count;
1082
+ l->count = max_count;
1083
+ l->skip = packet->count_skip;
1084
+ size += sizeof(*packet->tx) * max_count;
1085
+ }
1086
+
1087
+ packet->tx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL);
1088
+ if (!packet->tx)
1089
+ return -ENOMEM;
1090
+
1091
+ packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL);
1092
+ if (!packet->rx)
1093
+ return -ENOMEM;
9931094
9941095 if (ts->model == 7873) {
9951096 /*
....@@ -1005,181 +1106,25 @@
10051106 spi_message_init(m);
10061107 m->context = ts;
10071108
1008
- if (ts->model == 7845) {
1009
- packet->read_y_cmd[0] = READ_Y(vref);
1010
- packet->read_y_cmd[1] = 0;
1011
- packet->read_y_cmd[2] = 0;
1012
- x->tx_buf = &packet->read_y_cmd[0];
1013
- x->rx_buf = &packet->tc.y_buf[0];
1014
- x->len = 3;
1015
- spi_message_add_tail(x, m);
1016
- } else {
1017
- /* y- still on; turn on only y+ (and ADC) */
1018
- packet->read_y = READ_Y(vref);
1019
- x->tx_buf = &packet->read_y;
1020
- x->len = 1;
1021
- spi_message_add_tail(x, m);
1109
+ for (cmd_idx = 0; cmd_idx < packet->cmds; cmd_idx++) {
1110
+ struct ads7846_buf_layout *l = &packet->l[cmd_idx];
1111
+ u8 cmd;
10221112
1023
- x++;
1024
- x->rx_buf = &packet->tc.y;
1025
- x->len = 2;
1026
- spi_message_add_tail(x, m);
1113
+ if (cmd_idx == packet->cmds - 1)
1114
+ cmd_idx = ADS7846_PWDOWN;
1115
+
1116
+ cmd = ads7846_get_cmd(cmd_idx, vref);
1117
+
1118
+ for (b = 0; b < l->count; b++)
1119
+ packet->tx[l->offset + b].cmd = cmd;
10271120 }
10281121
1029
- /*
1030
- * The first sample after switching drivers can be low quality;
1031
- * optionally discard it, using a second one after the signals
1032
- * have had enough time to stabilize.
1033
- */
1034
- if (pdata->settle_delay_usecs) {
1035
- x->delay_usecs = pdata->settle_delay_usecs;
1036
-
1037
- x++;
1038
- x->tx_buf = &packet->read_y;
1039
- x->len = 1;
1040
- spi_message_add_tail(x, m);
1041
-
1042
- x++;
1043
- x->rx_buf = &packet->tc.y;
1044
- x->len = 2;
1045
- spi_message_add_tail(x, m);
1046
- }
1047
-
1048
- ts->msg_count++;
1049
- m++;
1050
- spi_message_init(m);
1051
- m->context = ts;
1052
-
1053
- if (ts->model == 7845) {
1054
- x++;
1055
- packet->read_x_cmd[0] = READ_X(vref);
1056
- packet->read_x_cmd[1] = 0;
1057
- packet->read_x_cmd[2] = 0;
1058
- x->tx_buf = &packet->read_x_cmd[0];
1059
- x->rx_buf = &packet->tc.x_buf[0];
1060
- x->len = 3;
1061
- spi_message_add_tail(x, m);
1062
- } else {
1063
- /* turn y- off, x+ on, then leave in lowpower */
1064
- x++;
1065
- packet->read_x = READ_X(vref);
1066
- x->tx_buf = &packet->read_x;
1067
- x->len = 1;
1068
- spi_message_add_tail(x, m);
1069
-
1070
- x++;
1071
- x->rx_buf = &packet->tc.x;
1072
- x->len = 2;
1073
- spi_message_add_tail(x, m);
1074
- }
1075
-
1076
- /* ... maybe discard first sample ... */
1077
- if (pdata->settle_delay_usecs) {
1078
- x->delay_usecs = pdata->settle_delay_usecs;
1079
-
1080
- x++;
1081
- x->tx_buf = &packet->read_x;
1082
- x->len = 1;
1083
- spi_message_add_tail(x, m);
1084
-
1085
- x++;
1086
- x->rx_buf = &packet->tc.x;
1087
- x->len = 2;
1088
- spi_message_add_tail(x, m);
1089
- }
1090
-
1091
- /* turn y+ off, x- on; we'll use formula #2 */
1092
- if (ts->model == 7846) {
1093
- ts->msg_count++;
1094
- m++;
1095
- spi_message_init(m);
1096
- m->context = ts;
1097
-
1098
- x++;
1099
- packet->read_z1 = READ_Z1(vref);
1100
- x->tx_buf = &packet->read_z1;
1101
- x->len = 1;
1102
- spi_message_add_tail(x, m);
1103
-
1104
- x++;
1105
- x->rx_buf = &packet->tc.z1;
1106
- x->len = 2;
1107
- spi_message_add_tail(x, m);
1108
-
1109
- /* ... maybe discard first sample ... */
1110
- if (pdata->settle_delay_usecs) {
1111
- x->delay_usecs = pdata->settle_delay_usecs;
1112
-
1113
- x++;
1114
- x->tx_buf = &packet->read_z1;
1115
- x->len = 1;
1116
- spi_message_add_tail(x, m);
1117
-
1118
- x++;
1119
- x->rx_buf = &packet->tc.z1;
1120
- x->len = 2;
1121
- spi_message_add_tail(x, m);
1122
- }
1123
-
1124
- ts->msg_count++;
1125
- m++;
1126
- spi_message_init(m);
1127
- m->context = ts;
1128
-
1129
- x++;
1130
- packet->read_z2 = READ_Z2(vref);
1131
- x->tx_buf = &packet->read_z2;
1132
- x->len = 1;
1133
- spi_message_add_tail(x, m);
1134
-
1135
- x++;
1136
- x->rx_buf = &packet->tc.z2;
1137
- x->len = 2;
1138
- spi_message_add_tail(x, m);
1139
-
1140
- /* ... maybe discard first sample ... */
1141
- if (pdata->settle_delay_usecs) {
1142
- x->delay_usecs = pdata->settle_delay_usecs;
1143
-
1144
- x++;
1145
- x->tx_buf = &packet->read_z2;
1146
- x->len = 1;
1147
- spi_message_add_tail(x, m);
1148
-
1149
- x++;
1150
- x->rx_buf = &packet->tc.z2;
1151
- x->len = 2;
1152
- spi_message_add_tail(x, m);
1153
- }
1154
- }
1155
-
1156
- /* power down */
1157
- ts->msg_count++;
1158
- m++;
1159
- spi_message_init(m);
1160
- m->context = ts;
1161
-
1162
- if (ts->model == 7845) {
1163
- x++;
1164
- packet->pwrdown_cmd[0] = PWRDOWN;
1165
- packet->pwrdown_cmd[1] = 0;
1166
- packet->pwrdown_cmd[2] = 0;
1167
- x->tx_buf = &packet->pwrdown_cmd[0];
1168
- x->len = 3;
1169
- } else {
1170
- x++;
1171
- packet->pwrdown = PWRDOWN;
1172
- x->tx_buf = &packet->pwrdown;
1173
- x->len = 1;
1174
- spi_message_add_tail(x, m);
1175
-
1176
- x++;
1177
- x->rx_buf = &packet->dummy;
1178
- x->len = 2;
1179
- }
1180
-
1181
- CS_CHANGE(*x);
1122
+ x->tx_buf = packet->tx;
1123
+ x->rx_buf = packet->rx;
1124
+ x->len = size;
11821125 spi_message_add_tail(x, m);
1126
+
1127
+ return 0;
11831128 }
11841129
11851130 #ifdef CONFIG_OF
....@@ -1198,6 +1143,7 @@
11981143 struct ads7846_platform_data *pdata;
11991144 struct device_node *node = dev->of_node;
12001145 const struct of_device_id *match;
1146
+ u32 value;
12011147
12021148 if (!node) {
12031149 dev_err(dev, "Device does not have associated DT data\n");
....@@ -1236,10 +1182,18 @@
12361182 of_property_read_u16(node, "ti,x-max", &pdata->x_max);
12371183 of_property_read_u16(node, "ti,y-max", &pdata->y_max);
12381184
1185
+ /*
1186
+ * touchscreen-max-pressure gets parsed during
1187
+ * touchscreen_parse_properties()
1188
+ */
12391189 of_property_read_u16(node, "ti,pressure-min", &pdata->pressure_min);
1190
+ if (!of_property_read_u32(node, "touchscreen-min-pressure", &value))
1191
+ pdata->pressure_min = (u16) value;
12401192 of_property_read_u16(node, "ti,pressure-max", &pdata->pressure_max);
12411193
12421194 of_property_read_u16(node, "ti,debounce-max", &pdata->debounce_max);
1195
+ if (!of_property_read_u32(node, "touchscreen-average-samples", &value))
1196
+ pdata->debounce_max = (u16) value;
12431197 of_property_read_u16(node, "ti,debounce-tol", &pdata->debounce_tol);
12441198 of_property_read_u16(node, "ti,debounce-rep", &pdata->debounce_rep);
12451199
....@@ -1322,10 +1276,7 @@
13221276 ts->model = pdata->model ? : 7846;
13231277 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
13241278 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
1325
- ts->pressure_max = pdata->pressure_max ? : ~0;
1326
-
13271279 ts->vref_mv = pdata->vref_mv;
1328
- ts->swap_xy = pdata->swap_xy;
13291280
13301281 if (pdata->filter != NULL) {
13311282 if (pdata->filter_init != NULL) {
....@@ -1374,8 +1325,26 @@
13741325 pdata->y_min ? : 0,
13751326 pdata->y_max ? : MAX_12BIT,
13761327 0, 0);
1377
- input_set_abs_params(input_dev, ABS_PRESSURE,
1378
- pdata->pressure_min, pdata->pressure_max, 0, 0);
1328
+ if (ts->model != 7845)
1329
+ input_set_abs_params(input_dev, ABS_PRESSURE,
1330
+ pdata->pressure_min, pdata->pressure_max, 0, 0);
1331
+
1332
+ /*
1333
+ * Parse common framework properties. Must be done here to ensure the
1334
+ * correct behaviour in case of using the legacy vendor bindings. The
1335
+ * general binding value overrides the vendor specific one.
1336
+ */
1337
+ touchscreen_parse_properties(ts->input, false, &ts->core_prop);
1338
+ ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0;
1339
+
1340
+ /*
1341
+ * Check if legacy ti,swap-xy binding is used instead of
1342
+ * touchscreen-swapped-x-y
1343
+ */
1344
+ if (!ts->core_prop.swap_x_y && pdata->swap_xy) {
1345
+ swap(input_dev->absinfo[ABS_X], input_dev->absinfo[ABS_Y]);
1346
+ ts->core_prop.swap_x_y = true;
1347
+ }
13791348
13801349 ads7846_setup_spi_msg(ts, pdata);
13811350