2 * Generic DT helper functions for touchscreen devices
4 * Copyright (c) 2014 Sebastian Reichel <sre@kernel.org>
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>
17 static bool touchscreen_get_prop_u32(struct device *dev,
19 unsigned int default_value,
25 error = device_property_read_u32(dev, property, &val);
27 *value = default_value;
35 static void touchscreen_set_params(struct input_dev *dev,
39 struct input_absinfo *absinfo;
41 if (!test_bit(axis, dev->absbit)) {
43 "DT specifies parameters but the axis %lu is not set up\n",
48 absinfo = &dev->absinfo[axis];
49 absinfo->maximum = max;
54 * touchscreen_parse_properties - parse common touchscreen DT properties
55 * @input: input device that should be parsed
56 * @multitouch: specifies whether parsed properties should be applied to
57 * single-touch or multi-touch axes
59 * This function parses common DT properties for touchscreens and setups the
60 * input device accordingly. The function keeps previously set up default
61 * values if no value is specified via DT.
63 void touchscreen_parse_properties(struct input_dev *input, bool multitouch)
65 struct device *dev = input->dev.parent;
67 unsigned int maximum, fuzz;
70 input_alloc_absinfo(input);
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,
79 touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
80 input_abs_get_fuzz(input, axis),
83 touchscreen_set_params(input, axis, maximum - 1, fuzz);
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,
90 touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
91 input_abs_get_fuzz(input, axis),
94 touchscreen_set_params(input, axis, maximum - 1, fuzz);
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),
101 touchscreen_get_prop_u32(dev,
102 "touchscreen-fuzz-pressure",
103 input_abs_get_fuzz(input, axis),
106 touchscreen_set_params(input, axis, maximum, fuzz);
108 EXPORT_SYMBOL(touchscreen_parse_properties);