blob: 806cd0ad160f95c9b08e0bc4f9e9a33e2655f8bc [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>
Maxime Ripard0a363a32015-03-21 20:17:57 -070014#include <linux/input/mt.h>
Sebastian Reichelb98abe52014-05-28 23:51:53 -070015#include <linux/input/touchscreen.h>
16
Dmitry Torokhov7c494372015-06-01 10:35:16 -070017static bool touchscreen_get_prop_u32(struct device_node *np,
18 const char *property,
19 unsigned int default_value,
20 unsigned int *value)
Maxime Ripard3eea8b52015-03-21 20:17:48 -070021{
Dmitry Torokhov7c494372015-06-01 10:35:16 -070022 u32 val;
23 int error;
Maxime Ripard3eea8b52015-03-21 20:17:48 -070024
Dmitry Torokhov7c494372015-06-01 10:35:16 -070025 error = of_property_read_u32(np, property, &val);
26 if (error) {
27 *value = default_value;
28 return false;
29 }
Maxime Ripard3eea8b52015-03-21 20:17:48 -070030
Dmitry Torokhov7c494372015-06-01 10:35:16 -070031 *value = val;
32 return true;
Maxime Ripard3eea8b52015-03-21 20:17:48 -070033}
34
35static void touchscreen_set_params(struct input_dev *dev,
36 unsigned long axis,
37 int max, int fuzz)
38{
39 struct input_absinfo *absinfo;
40
41 if (!test_bit(axis, dev->absbit)) {
Maxime Ripard0a363a32015-03-21 20:17:57 -070042 /*
43 * Emit a warning only if the axis is not a multitouch
44 * axis, which might not be set by the driver.
45 */
46 if (!input_is_mt_axis(axis))
47 dev_warn(&dev->dev,
48 "DT specifies parameters but the axis is not set up\n");
Maxime Ripard3eea8b52015-03-21 20:17:48 -070049 return;
50 }
51
52 absinfo = &dev->absinfo[axis];
53 absinfo->maximum = max;
54 absinfo->fuzz = fuzz;
55}
56
Sebastian Reichelb98abe52014-05-28 23:51:53 -070057/**
58 * touchscreen_parse_of_params - parse common touchscreen DT properties
59 * @dev: device that should be parsed
60 *
61 * This function parses common DT properties for touchscreens and setups the
62 * input device accordingly. The function keeps previously setuped default
63 * values if no value is specified via DT.
64 */
Dmitry Torokhov7c494372015-06-01 10:35:16 -070065void touchscreen_parse_of_params(struct input_dev *dev, bool multitouch)
Sebastian Reichelb98abe52014-05-28 23:51:53 -070066{
67 struct device_node *np = dev->dev.parent->of_node;
Dmitry Torokhov7c494372015-06-01 10:35:16 -070068 unsigned int axis;
69 unsigned int maximum, fuzz;
70 bool data_present;
Sebastian Reichelb98abe52014-05-28 23:51:53 -070071
72 input_alloc_absinfo(dev);
73 if (!dev->absinfo)
74 return;
75
Dmitry Torokhov7c494372015-06-01 10:35:16 -070076 axis = multitouch ? ABS_MT_POSITION_X : ABS_X;
77 data_present = touchscreen_get_prop_u32(np, "touchscreen-size-x",
78 input_abs_get_max(dev, axis),
79 &maximum) |
80 touchscreen_get_prop_u32(np, "touchscreen-fuzz-x",
81 input_abs_get_fuzz(dev, axis),
82 &fuzz);
83 if (data_present)
84 touchscreen_set_params(dev, axis, maximum, fuzz);
Sebastian Reichelb98abe52014-05-28 23:51:53 -070085
Dmitry Torokhov7c494372015-06-01 10:35:16 -070086 axis = multitouch ? ABS_MT_POSITION_Y : ABS_Y;
87 data_present = touchscreen_get_prop_u32(np, "touchscreen-size-y",
88 input_abs_get_max(dev, axis),
89 &maximum) |
90 touchscreen_get_prop_u32(np, "touchscreen-fuzz-y",
91 input_abs_get_fuzz(dev, axis),
92 &fuzz);
93 if (data_present)
94 touchscreen_set_params(dev, axis, maximum, fuzz);
Sebastian Reichelb98abe52014-05-28 23:51:53 -070095
Dmitry Torokhov7c494372015-06-01 10:35:16 -070096 axis = multitouch ? ABS_MT_PRESSURE : ABS_PRESSURE;
97 data_present = touchscreen_get_prop_u32(np, "touchscreen-max-pressure",
98 input_abs_get_max(dev, axis),
99 &maximum) |
100 touchscreen_get_prop_u32(np, "touchscreen-fuzz-pressure",
101 input_abs_get_fuzz(dev, axis),
102 &fuzz);
103 if (data_present)
104 touchscreen_set_params(dev, axis, maximum, fuzz);
Sebastian Reichelb98abe52014-05-28 23:51:53 -0700105}
106EXPORT_SYMBOL(touchscreen_parse_of_params);