1
2
3
4
5
6
7
8
9
10
11
12#include <linux/property.h>
13#include <linux/input.h>
14#include <linux/input/mt.h>
15#include <linux/input/touchscreen.h>
16
17static bool touchscreen_get_prop_u32(struct device *dev,
18 const char *property,
19 unsigned int default_value,
20 unsigned int *value)
21{
22 u32 val;
23 int error;
24
25 error = device_property_read_u32(dev, property, &val);
26 if (error) {
27 *value = default_value;
28 return false;
29 }
30
31 *value = val;
32 return true;
33}
34
35static void touchscreen_set_params(struct input_dev *dev,
36 unsigned long axis,
37 int max, int fuzz)
38{
39 struct input_absinfo *absinfo;
40
41 if (!test_bit(axis, dev->absbit)) {
42 dev_warn(&dev->dev,
43 "DT specifies parameters but the axis %lu is not set up\n",
44 axis);
45 return;
46 }
47
48 absinfo = &dev->absinfo[axis];
49 absinfo->maximum = max;
50 absinfo->fuzz = fuzz;
51}
52
53
54
55
56
57
58
59
60
61
62
63void touchscreen_parse_properties(struct input_dev *input, bool multitouch)
64{
65 struct device *dev = input->dev.parent;
66 unsigned int axis;
67 unsigned int maximum, fuzz;
68 bool data_present;
69
70 input_alloc_absinfo(input);
71 if (!input->absinfo)
72 return;
73
74 axis = multitouch ? ABS_MT_POSITION_X : ABS_X;
75 data_present = touchscreen_get_prop_u32(dev, "touchscreen-size-x",
76 input_abs_get_max(input,
77 axis) + 1,
78 &maximum) |
79 touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
80 input_abs_get_fuzz(input, axis),
81 &fuzz);
82 if (data_present)
83 touchscreen_set_params(input, axis, maximum - 1, fuzz);
84
85 axis = multitouch ? ABS_MT_POSITION_Y : ABS_Y;
86 data_present = touchscreen_get_prop_u32(dev, "touchscreen-size-y",
87 input_abs_get_max(input,
88 axis) + 1,
89 &maximum) |
90 touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
91 input_abs_get_fuzz(input, axis),
92 &fuzz);
93 if (data_present)
94 touchscreen_set_params(input, axis, maximum - 1, fuzz);
95
96 axis = multitouch ? ABS_MT_PRESSURE : ABS_PRESSURE;
97 data_present = touchscreen_get_prop_u32(dev,
98 "touchscreen-max-pressure",
99 input_abs_get_max(input, axis),
100 &maximum) |
101 touchscreen_get_prop_u32(dev,
102 "touchscreen-fuzz-pressure",
103 input_abs_get_fuzz(input, axis),
104 &fuzz);
105 if (data_present)
106 touchscreen_set_params(input, axis, maximum, fuzz);
107}
108EXPORT_SYMBOL(touchscreen_parse_properties);
109