.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Generic DT helper functions for touchscreen devices |
---|
3 | 4 | * |
---|
4 | 5 | * 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 | | - * |
---|
10 | 6 | */ |
---|
11 | 7 | |
---|
12 | 8 | #include <linux/property.h> |
---|
.. | .. |
---|
35 | 31 | |
---|
36 | 32 | static void touchscreen_set_params(struct input_dev *dev, |
---|
37 | 33 | unsigned long axis, |
---|
38 | | - int max, int fuzz) |
---|
| 34 | + int min, int max, int fuzz) |
---|
39 | 35 | { |
---|
40 | 36 | struct input_absinfo *absinfo; |
---|
41 | 37 | |
---|
.. | .. |
---|
47 | 43 | } |
---|
48 | 44 | |
---|
49 | 45 | absinfo = &dev->absinfo[axis]; |
---|
| 46 | + absinfo->minimum = min; |
---|
50 | 47 | absinfo->maximum = max; |
---|
51 | 48 | absinfo->fuzz = fuzz; |
---|
52 | 49 | } |
---|
.. | .. |
---|
68 | 65 | struct touchscreen_properties *prop) |
---|
69 | 66 | { |
---|
70 | 67 | 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; |
---|
73 | 71 | bool data_present; |
---|
74 | 72 | |
---|
75 | 73 | input_alloc_absinfo(input); |
---|
76 | 74 | if (!input->absinfo) |
---|
77 | 75 | return; |
---|
78 | 76 | |
---|
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; |
---|
89 | 79 | |
---|
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); |
---|
98 | 90 | 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); |
---|
100 | 105 | |
---|
101 | 106 | axis = multitouch ? ABS_MT_PRESSURE : ABS_PRESSURE; |
---|
102 | 107 | data_present = touchscreen_get_prop_u32(dev, |
---|
.. | .. |
---|
108 | 113 | input_abs_get_fuzz(input, axis), |
---|
109 | 114 | &fuzz); |
---|
110 | 115 | if (data_present) |
---|
111 | | - touchscreen_set_params(input, axis, maximum, fuzz); |
---|
| 116 | + touchscreen_set_params(input, axis, 0, maximum, fuzz); |
---|
112 | 117 | |
---|
113 | 118 | if (!prop) |
---|
114 | 119 | return; |
---|
115 | 120 | |
---|
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); |
---|
117 | 123 | |
---|
118 | | - prop->max_x = input_abs_get_max(input, axis); |
---|
119 | | - prop->max_y = input_abs_get_max(input, axis + 1); |
---|
120 | 124 | prop->invert_x = |
---|
121 | 125 | 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 | + |
---|
122 | 132 | prop->invert_y = |
---|
123 | 133 | 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 | + |
---|
124 | 140 | prop->swap_x_y = |
---|
125 | 141 | device_property_read_bool(dev, "touchscreen-swapped-x-y"); |
---|
126 | | - |
---|
127 | 142 | if (prop->swap_x_y) |
---|
128 | | - swap(input->absinfo[axis], input->absinfo[axis + 1]); |
---|
| 143 | + swap(input->absinfo[axis_x], input->absinfo[axis_y]); |
---|
129 | 144 | } |
---|
130 | 145 | EXPORT_SYMBOL(touchscreen_parse_properties); |
---|
131 | 146 | |
---|