mmc: rtsx_pci: Enable MMC_CAP_ERASE to allow erase/discard/trim requests
[linux/fpc-iii.git] / drivers / input / touchscreen / of_touchscreen.c
blobbb6f2fe1466728a8dc41e77b9f633b85a43404e1
1 /*
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,
18 const char *property,
19 unsigned int default_value,
20 unsigned int *value)
22 u32 val;
23 int error;
25 error = device_property_read_u32(dev, property, &val);
26 if (error) {
27 *value = default_value;
28 return false;
31 *value = val;
32 return true;
35 static void touchscreen_set_params(struct input_dev *dev,
36 unsigned long axis,
37 int max, int fuzz)
39 struct input_absinfo *absinfo;
41 if (!test_bit(axis, dev->absbit)) {
42 dev_warn(&dev->dev,
43 "DT specifies parameters but the axis %lu is not set up\n",
44 axis);
45 return;
48 absinfo = &dev->absinfo[axis];
49 absinfo->maximum = max;
50 absinfo->fuzz = fuzz;
53 /**
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;
66 unsigned int axis;
67 unsigned int maximum, fuzz;
68 bool data_present;
70 input_alloc_absinfo(input);
71 if (!input->absinfo)
72 return;
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,
77 axis) + 1,
78 &maximum) |
79 touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
80 input_abs_get_fuzz(input, axis),
81 &fuzz);
82 if (data_present)
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,
88 axis) + 1,
89 &maximum) |
90 touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
91 input_abs_get_fuzz(input, axis),
92 &fuzz);
93 if (data_present)
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),
100 &maximum) |
101 touchscreen_get_prop_u32(dev,
102 "touchscreen-fuzz-pressure",
103 input_abs_get_fuzz(input, axis),
104 &fuzz);
105 if (data_present)
106 touchscreen_set_params(input, axis, maximum, fuzz);
108 EXPORT_SYMBOL(touchscreen_parse_properties);