2 * Generic DT helper functions for touchscreen devices
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.
12 #include <linux/property.h>
13 #include <linux/input.h>
14 #include <linux/input/mt.h>
15 #include <linux/input/touchscreen.h>
16 #include <linux/module.h>
18 static bool touchscreen_get_prop_u32(struct device *dev,
20 unsigned int default_value,
26 error = device_property_read_u32(dev, property, &val);
28 *value = default_value;
36 static void touchscreen_set_params(struct input_dev *dev,
38 int min, int max, int fuzz)
40 struct input_absinfo *absinfo;
42 if (!test_bit(axis, dev->absbit)) {
44 "DT specifies parameters but the axis %lu is not set up\n",
49 absinfo = &dev->absinfo[axis];
50 absinfo->minimum = min;
51 absinfo->maximum = max;
56 * touchscreen_parse_properties - parse common touchscreen DT properties
57 * @input: input device that should be parsed
58 * @multitouch: specifies whether parsed properties should be applied to
59 * single-touch or multi-touch axes
60 * @prop: pointer to a struct touchscreen_properties into which to store
61 * axis swap and invert info for use with touchscreen_report_x_y();
64 * This function parses common DT properties for touchscreens and setups the
65 * input device accordingly. The function keeps previously set up default
66 * values if no value is specified via DT.
68 void touchscreen_parse_properties(struct input_dev *input, bool multitouch,
69 struct touchscreen_properties *prop)
71 struct device *dev = input->dev.parent;
72 struct input_absinfo *absinfo;
74 unsigned int minimum, maximum, fuzz;
77 input_alloc_absinfo(input);
81 axis = multitouch ? ABS_MT_POSITION_X : ABS_X;
82 data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-x",
83 input_abs_get_min(input, axis),
85 touchscreen_get_prop_u32(dev, "touchscreen-size-x",
86 input_abs_get_max(input,
89 touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
90 input_abs_get_fuzz(input, axis),
93 touchscreen_set_params(input, axis, minimum, maximum - 1, fuzz);
95 axis = multitouch ? ABS_MT_POSITION_Y : ABS_Y;
96 data_present = touchscreen_get_prop_u32(dev, "touchscreen-min-y",
97 input_abs_get_min(input, axis),
99 touchscreen_get_prop_u32(dev, "touchscreen-size-y",
100 input_abs_get_max(input,
103 touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
104 input_abs_get_fuzz(input, axis),
107 touchscreen_set_params(input, axis, minimum, maximum - 1, fuzz);
109 axis = multitouch ? ABS_MT_PRESSURE : ABS_PRESSURE;
110 data_present = touchscreen_get_prop_u32(dev,
111 "touchscreen-max-pressure",
112 input_abs_get_max(input, axis),
114 touchscreen_get_prop_u32(dev,
115 "touchscreen-fuzz-pressure",
116 input_abs_get_fuzz(input, axis),
119 touchscreen_set_params(input, axis, 0, maximum, fuzz);
124 axis = multitouch ? ABS_MT_POSITION_X : ABS_X;
126 prop->max_x = input_abs_get_max(input, axis);
127 prop->max_y = input_abs_get_max(input, axis + 1);
130 device_property_read_bool(dev, "touchscreen-inverted-x");
131 if (prop->invert_x) {
132 absinfo = &input->absinfo[axis];
133 absinfo->maximum -= absinfo->minimum;
134 absinfo->minimum = 0;
138 device_property_read_bool(dev, "touchscreen-inverted-y");
139 if (prop->invert_y) {
140 absinfo = &input->absinfo[axis + 1];
141 absinfo->maximum -= absinfo->minimum;
142 absinfo->minimum = 0;
146 device_property_read_bool(dev, "touchscreen-swapped-x-y");
148 swap(input->absinfo[axis], input->absinfo[axis + 1]);
150 EXPORT_SYMBOL(touchscreen_parse_properties);
153 touchscreen_apply_prop_to_x_y(const struct touchscreen_properties *prop,
154 unsigned int *x, unsigned int *y)
157 *x = prop->max_x - *x;
160 *y = prop->max_y - *y;
167 * touchscreen_set_mt_pos - Set input_mt_pos coordinates
168 * @pos: input_mt_pos to set coordinates of
169 * @prop: pointer to a struct touchscreen_properties
170 * @x: X coordinate to store in pos
171 * @y: Y coordinate to store in pos
173 * Adjust the passed in x and y values applying any axis inversion and
174 * swapping requested in the passed in touchscreen_properties and store
175 * the result in a struct input_mt_pos.
177 void touchscreen_set_mt_pos(struct input_mt_pos *pos,
178 const struct touchscreen_properties *prop,
179 unsigned int x, unsigned int y)
181 touchscreen_apply_prop_to_x_y(prop, &x, &y);
185 EXPORT_SYMBOL(touchscreen_set_mt_pos);
188 * touchscreen_report_pos - Report touchscreen coordinates
189 * @input: input_device to report coordinates for
190 * @prop: pointer to a struct touchscreen_properties
191 * @x: X coordinate to report
192 * @y: Y coordinate to report
193 * @multitouch: Report coordinates on single-touch or multi-touch axes
195 * Adjust the passed in x and y values applying any axis inversion and
196 * swapping requested in the passed in touchscreen_properties and then
197 * report the resulting coordinates on the input_dev's x and y axis.
199 void touchscreen_report_pos(struct input_dev *input,
200 const struct touchscreen_properties *prop,
201 unsigned int x, unsigned int y,
204 touchscreen_apply_prop_to_x_y(prop, &x, &y);
205 input_report_abs(input, multitouch ? ABS_MT_POSITION_X : ABS_X, x);
206 input_report_abs(input, multitouch ? ABS_MT_POSITION_Y : ABS_Y, y);
208 EXPORT_SYMBOL(touchscreen_report_pos);
210 MODULE_LICENSE("GPL v2");
211 MODULE_DESCRIPTION("Device-tree helpers functions for touchscreen devices");