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>
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
,
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
->maximum
= max
;
55 * touchscreen_parse_properties - parse common touchscreen DT properties
56 * @input: input device that should be parsed
57 * @multitouch: specifies whether parsed properties should be applied to
58 * single-touch or multi-touch axes
59 * @prop: pointer to a struct touchscreen_properties into which to store
60 * axis swap and invert info for use with touchscreen_report_x_y();
63 * This function parses common DT properties for touchscreens and setups the
64 * input device accordingly. The function keeps previously set up default
65 * values if no value is specified via DT.
67 void touchscreen_parse_properties(struct input_dev
*input
, bool multitouch
,
68 struct touchscreen_properties
*prop
)
70 struct device
*dev
= input
->dev
.parent
;
72 unsigned int maximum
, fuzz
;
75 input_alloc_absinfo(input
);
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
,
84 touchscreen_get_prop_u32(dev
, "touchscreen-fuzz-x",
85 input_abs_get_fuzz(input
, axis
),
88 touchscreen_set_params(input
, axis
, maximum
- 1, fuzz
);
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
,
95 touchscreen_get_prop_u32(dev
, "touchscreen-fuzz-y",
96 input_abs_get_fuzz(input
, axis
),
99 touchscreen_set_params(input
, axis
, maximum
- 1, fuzz
);
101 axis
= multitouch
? ABS_MT_PRESSURE
: ABS_PRESSURE
;
102 data_present
= touchscreen_get_prop_u32(dev
,
103 "touchscreen-max-pressure",
104 input_abs_get_max(input
, axis
),
106 touchscreen_get_prop_u32(dev
,
107 "touchscreen-fuzz-pressure",
108 input_abs_get_fuzz(input
, axis
),
111 touchscreen_set_params(input
, axis
, maximum
, fuzz
);
116 axis
= multitouch
? ABS_MT_POSITION_X
: ABS_X
;
118 prop
->max_x
= input_abs_get_max(input
, axis
);
119 prop
->max_y
= input_abs_get_max(input
, axis
+ 1);
121 device_property_read_bool(dev
, "touchscreen-inverted-x");
123 device_property_read_bool(dev
, "touchscreen-inverted-y");
125 device_property_read_bool(dev
, "touchscreen-swapped-x-y");
128 swap(input
->absinfo
[axis
], input
->absinfo
[axis
+ 1]);
130 EXPORT_SYMBOL(touchscreen_parse_properties
);
133 touchscreen_apply_prop_to_x_y(const struct touchscreen_properties
*prop
,
134 unsigned int *x
, unsigned int *y
)
137 *x
= prop
->max_x
- *x
;
140 *y
= prop
->max_y
- *y
;
147 * touchscreen_set_mt_pos - Set input_mt_pos coordinates
148 * @pos: input_mt_pos to set coordinates of
149 * @prop: pointer to a struct touchscreen_properties
150 * @x: X coordinate to store in pos
151 * @y: Y coordinate to store in pos
153 * Adjust the passed in x and y values applying any axis inversion and
154 * swapping requested in the passed in touchscreen_properties and store
155 * the result in a struct input_mt_pos.
157 void touchscreen_set_mt_pos(struct input_mt_pos
*pos
,
158 const struct touchscreen_properties
*prop
,
159 unsigned int x
, unsigned int y
)
161 touchscreen_apply_prop_to_x_y(prop
, &x
, &y
);
165 EXPORT_SYMBOL(touchscreen_set_mt_pos
);
168 * touchscreen_report_pos - Report touchscreen coordinates
169 * @input: input_device to report coordinates for
170 * @prop: pointer to a struct touchscreen_properties
171 * @x: X coordinate to report
172 * @y: Y coordinate to report
173 * @multitouch: Report coordinates on single-touch or multi-touch axes
175 * Adjust the passed in x and y values applying any axis inversion and
176 * swapping requested in the passed in touchscreen_properties and then
177 * report the resulting coordinates on the input_dev's x and y axis.
179 void touchscreen_report_pos(struct input_dev
*input
,
180 const struct touchscreen_properties
*prop
,
181 unsigned int x
, unsigned int y
,
184 touchscreen_apply_prop_to_x_y(prop
, &x
, &y
);
185 input_report_abs(input
, multitouch
? ABS_MT_POSITION_X
: ABS_X
, x
);
186 input_report_abs(input
, multitouch
? ABS_MT_POSITION_Y
: ABS_Y
, y
);
188 EXPORT_SYMBOL(touchscreen_report_pos
);
190 MODULE_LICENSE("GPL v2");
191 MODULE_DESCRIPTION("Device-tree helpers functions for touchscreen devices");