blob: fe80d8ba7efa44a2e46f3f31fc1af93fa6989aa5 [file] [log] [blame]
Sebastian Reichelb98abe52014-05-28 23:51:53 -07001/*
2 * Generic DT helper functions for touchscreen devices
3 *
4 * Copyright (c) 2014 Sebastian Reichel <sre@kernel.org>
5 *
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.
9 *
10 */
11
12#include <linux/of.h>
13#include <linux/input.h>
14#include <linux/input/touchscreen.h>
15
Maxime Ripard3eea8b52015-03-21 20:17:48 -070016static u32 of_get_optional_u32(struct device_node *np,
17 const char *property)
18{
19 u32 val = 0;
20
21 of_property_read_u32(np, property, &val);
22
23 return val;
24}
25
26static void touchscreen_set_params(struct input_dev *dev,
27 unsigned long axis,
28 int max, int fuzz)
29{
30 struct input_absinfo *absinfo;
31
32 if (!test_bit(axis, dev->absbit)) {
33 dev_warn(&dev->dev,
34 "DT specifies parameters but the axis is not set up\n");
35 return;
36 }
37
38 absinfo = &dev->absinfo[axis];
39 absinfo->maximum = max;
40 absinfo->fuzz = fuzz;
41}
42
Sebastian Reichelb98abe52014-05-28 23:51:53 -070043/**
44 * touchscreen_parse_of_params - parse common touchscreen DT properties
45 * @dev: device that should be parsed
46 *
47 * This function parses common DT properties for touchscreens and setups the
48 * input device accordingly. The function keeps previously setuped default
49 * values if no value is specified via DT.
50 */
51void touchscreen_parse_of_params(struct input_dev *dev)
52{
53 struct device_node *np = dev->dev.parent->of_node;
Maxime Ripard3eea8b52015-03-21 20:17:48 -070054 u32 maximum, fuzz;
Sebastian Reichelb98abe52014-05-28 23:51:53 -070055
56 input_alloc_absinfo(dev);
57 if (!dev->absinfo)
58 return;
59
Maxime Ripard3eea8b52015-03-21 20:17:48 -070060 maximum = of_get_optional_u32(np, "touchscreen-size-x");
61 fuzz = of_get_optional_u32(np, "touchscreen-fuzz-x");
62 if (maximum || fuzz)
63 touchscreen_set_params(dev, ABS_X, maximum, fuzz);
Sebastian Reichelb98abe52014-05-28 23:51:53 -070064
Maxime Ripard3eea8b52015-03-21 20:17:48 -070065 maximum = of_get_optional_u32(np, "touchscreen-size-y");
66 fuzz = of_get_optional_u32(np, "touchscreen-fuzz-y");
67 if (maximum || fuzz)
68 touchscreen_set_params(dev, ABS_Y, maximum, fuzz);
Sebastian Reichelb98abe52014-05-28 23:51:53 -070069
Maxime Ripard3eea8b52015-03-21 20:17:48 -070070 maximum = of_get_optional_u32(np, "touchscreen-max-pressure");
71 fuzz = of_get_optional_u32(np, "touchscreen-fuzz-pressure");
72 if (maximum || fuzz)
73 touchscreen_set_params(dev, ABS_PRESSURE, maximum, fuzz);
Sebastian Reichelb98abe52014-05-28 23:51:53 -070074}
75EXPORT_SYMBOL(touchscreen_parse_of_params);