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.
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_node
*np
,
19 unsigned int default_value
,
25 error
= of_property_read_u32(np
, 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_of_params - parse common touchscreen DT properties
55 * @dev: device that should be parsed
57 * This function parses common DT properties for touchscreens and setups the
58 * input device accordingly. The function keeps previously setuped default
59 * values if no value is specified via DT.
61 void touchscreen_parse_of_params(struct input_dev
*dev
, bool multitouch
)
63 struct device_node
*np
= dev
->dev
.parent
->of_node
;
65 unsigned int maximum
, fuzz
;
68 input_alloc_absinfo(dev
);
72 axis
= multitouch
? ABS_MT_POSITION_X
: ABS_X
;
73 data_present
= touchscreen_get_prop_u32(np
, "touchscreen-size-x",
74 input_abs_get_max(dev
,
77 touchscreen_get_prop_u32(np
, "touchscreen-fuzz-x",
78 input_abs_get_fuzz(dev
, axis
),
81 touchscreen_set_params(dev
, axis
, maximum
- 1, fuzz
);
83 axis
= multitouch
? ABS_MT_POSITION_Y
: ABS_Y
;
84 data_present
= touchscreen_get_prop_u32(np
, "touchscreen-size-y",
85 input_abs_get_max(dev
,
88 touchscreen_get_prop_u32(np
, "touchscreen-fuzz-y",
89 input_abs_get_fuzz(dev
, axis
),
92 touchscreen_set_params(dev
, axis
, maximum
- 1, fuzz
);
94 axis
= multitouch
? ABS_MT_PRESSURE
: ABS_PRESSURE
;
95 data_present
= touchscreen_get_prop_u32(np
, "touchscreen-max-pressure",
96 input_abs_get_max(dev
, axis
),
98 touchscreen_get_prop_u32(np
, "touchscreen-fuzz-pressure",
99 input_abs_get_fuzz(dev
, axis
),
102 touchscreen_set_params(dev
, axis
, maximum
, fuzz
);
104 EXPORT_SYMBOL(touchscreen_parse_of_params
);