hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/input/touchscreen/of_touchscreen.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Generic DT helper functions for touchscreen devices
34 *
45 * Copyright (c) 2014 Sebastian Reichel <sre@kernel.org>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
9
- *
106 */
117
128 #include <linux/property.h>
....@@ -35,7 +31,7 @@
3531
3632 static void touchscreen_set_params(struct input_dev *dev,
3733 unsigned long axis,
38
- int max, int fuzz)
34
+ int min, int max, int fuzz)
3935 {
4036 struct input_absinfo *absinfo;
4137
....@@ -47,6 +43,7 @@
4743 }
4844
4945 absinfo = &dev->absinfo[axis];
46
+ absinfo->minimum = min;
5047 absinfo->maximum = max;
5148 absinfo->fuzz = fuzz;
5249 }
....@@ -68,35 +65,43 @@
6865 struct touchscreen_properties *prop)
6966 {
7067 struct device *dev = input->dev.parent;
71
- unsigned int axis;
72
- unsigned int maximum, fuzz;
68
+ struct input_absinfo *absinfo;
69
+ unsigned int axis, axis_x, axis_y;
70
+ unsigned int minimum, maximum, fuzz;
7371 bool data_present;
7472
7573 input_alloc_absinfo(input);
7674 if (!input->absinfo)
7775 return;
7876
79
- axis = multitouch ? ABS_MT_POSITION_X : ABS_X;
80
- data_present = touchscreen_get_prop_u32(dev, "touchscreen-size-x",
81
- input_abs_get_max(input,
82
- axis) + 1,
83
- &maximum);
84
- data_present |= touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
85
- input_abs_get_fuzz(input, axis),
86
- &fuzz);
87
- if (data_present)
88
- touchscreen_set_params(input, axis, maximum - 1, fuzz);
77
+ axis_x = multitouch ? ABS_MT_POSITION_X : ABS_X;
78
+ axis_y = multitouch ? ABS_MT_POSITION_Y : ABS_Y;
8979
90
- axis = multitouch ? ABS_MT_POSITION_Y : ABS_Y;
91
- data_present = touchscreen_get_prop_u32(dev, "touchscreen-size-y",
92
- input_abs_get_max(input,
93
- axis) + 1,
94
- &maximum);
95
- data_present |= touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
96
- input_abs_get_fuzz(input, axis),
97
- &fuzz);
80
+ data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-x",
81
+ input_abs_get_min(input, axis_x),
82
+ &minimum);
83
+ data_present |= touchscreen_get_prop_u32(dev, "touchscreen-size-x",
84
+ input_abs_get_max(input,
85
+ axis_x) + 1,
86
+ &maximum);
87
+ data_present |= touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
88
+ input_abs_get_fuzz(input, axis_x),
89
+ &fuzz);
9890 if (data_present)
99
- touchscreen_set_params(input, axis, maximum - 1, fuzz);
91
+ touchscreen_set_params(input, axis_x, minimum, maximum - 1, fuzz);
92
+
93
+ data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-y",
94
+ input_abs_get_min(input, axis_y),
95
+ &minimum);
96
+ data_present |= touchscreen_get_prop_u32(dev, "touchscreen-size-y",
97
+ input_abs_get_max(input,
98
+ axis_y) + 1,
99
+ &maximum);
100
+ data_present |= touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
101
+ input_abs_get_fuzz(input, axis_y),
102
+ &fuzz);
103
+ if (data_present)
104
+ touchscreen_set_params(input, axis_y, minimum, maximum - 1, fuzz);
100105
101106 axis = multitouch ? ABS_MT_PRESSURE : ABS_PRESSURE;
102107 data_present = touchscreen_get_prop_u32(dev,
....@@ -108,24 +113,34 @@
108113 input_abs_get_fuzz(input, axis),
109114 &fuzz);
110115 if (data_present)
111
- touchscreen_set_params(input, axis, maximum, fuzz);
116
+ touchscreen_set_params(input, axis, 0, maximum, fuzz);
112117
113118 if (!prop)
114119 return;
115120
116
- axis = multitouch ? ABS_MT_POSITION_X : ABS_X;
121
+ prop->max_x = input_abs_get_max(input, axis_x);
122
+ prop->max_y = input_abs_get_max(input, axis_y);
117123
118
- prop->max_x = input_abs_get_max(input, axis);
119
- prop->max_y = input_abs_get_max(input, axis + 1);
120124 prop->invert_x =
121125 device_property_read_bool(dev, "touchscreen-inverted-x");
126
+ if (prop->invert_x) {
127
+ absinfo = &input->absinfo[axis_x];
128
+ absinfo->maximum -= absinfo->minimum;
129
+ absinfo->minimum = 0;
130
+ }
131
+
122132 prop->invert_y =
123133 device_property_read_bool(dev, "touchscreen-inverted-y");
134
+ if (prop->invert_y) {
135
+ absinfo = &input->absinfo[axis_y];
136
+ absinfo->maximum -= absinfo->minimum;
137
+ absinfo->minimum = 0;
138
+ }
139
+
124140 prop->swap_x_y =
125141 device_property_read_bool(dev, "touchscreen-swapped-x-y");
126
-
127142 if (prop->swap_x_y)
128
- swap(input->absinfo[axis], input->absinfo[axis + 1]);
143
+ swap(input->absinfo[axis_x], input->absinfo[axis_y]);
129144 }
130145 EXPORT_SYMBOL(touchscreen_parse_properties);
131146