drm/sti: removed optional dummy encoder mode_fixup function.
[deliverable/linux.git] / drivers / input / touchscreen / of_touchscreen.c
CommitLineData
b98abe52
SR
1/*
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
4200e831 12#include <linux/property.h>
b98abe52 13#include <linux/input.h>
0a363a38 14#include <linux/input/mt.h>
b98abe52
SR
15#include <linux/input/touchscreen.h>
16
4200e831 17static bool touchscreen_get_prop_u32(struct device *dev,
7c494375
DT
18 const char *property,
19 unsigned int default_value,
20 unsigned int *value)
3eea8b5d 21{
7c494375
DT
22 u32 val;
23 int error;
3eea8b5d 24
4200e831 25 error = device_property_read_u32(dev, property, &val);
7c494375
DT
26 if (error) {
27 *value = default_value;
28 return false;
29 }
3eea8b5d 30
7c494375
DT
31 *value = val;
32 return true;
3eea8b5d
MR
33}
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)) {
f61fd21d
DT
42 dev_warn(&dev->dev,
43 "DT specifies parameters but the axis %lu is not set up\n",
44 axis);
3eea8b5d
MR
45 return;
46 }
47
48 absinfo = &dev->absinfo[axis];
49 absinfo->maximum = max;
50 absinfo->fuzz = fuzz;
51}
52
b98abe52 53/**
4200e831
DT
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
b98abe52
SR
58 *
59 * This function parses common DT properties for touchscreens and setups the
4200e831 60 * input device accordingly. The function keeps previously set up default
b98abe52
SR
61 * values if no value is specified via DT.
62 */
4200e831 63void touchscreen_parse_properties(struct input_dev *input, bool multitouch)
b98abe52 64{
4200e831 65 struct device *dev = input->dev.parent;
7c494375
DT
66 unsigned int axis;
67 unsigned int maximum, fuzz;
68 bool data_present;
b98abe52 69
4200e831
DT
70 input_alloc_absinfo(input);
71 if (!input->absinfo)
b98abe52
SR
72 return;
73
7c494375 74 axis = multitouch ? ABS_MT_POSITION_X : ABS_X;
4200e831
DT
75 data_present = touchscreen_get_prop_u32(dev, "touchscreen-size-x",
76 input_abs_get_max(input,
51717869 77 axis) + 1,
7c494375 78 &maximum) |
4200e831
DT
79 touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x",
80 input_abs_get_fuzz(input, axis),
7c494375
DT
81 &fuzz);
82 if (data_present)
4200e831 83 touchscreen_set_params(input, axis, maximum - 1, fuzz);
b98abe52 84
7c494375 85 axis = multitouch ? ABS_MT_POSITION_Y : ABS_Y;
4200e831
DT
86 data_present = touchscreen_get_prop_u32(dev, "touchscreen-size-y",
87 input_abs_get_max(input,
51717869 88 axis) + 1,
7c494375 89 &maximum) |
4200e831
DT
90 touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y",
91 input_abs_get_fuzz(input, axis),
7c494375
DT
92 &fuzz);
93 if (data_present)
4200e831 94 touchscreen_set_params(input, axis, maximum - 1, fuzz);
b98abe52 95
7c494375 96 axis = multitouch ? ABS_MT_PRESSURE : ABS_PRESSURE;
4200e831
DT
97 data_present = touchscreen_get_prop_u32(dev,
98 "touchscreen-max-pressure",
99 input_abs_get_max(input, axis),
7c494375 100 &maximum) |
4200e831
DT
101 touchscreen_get_prop_u32(dev,
102 "touchscreen-fuzz-pressure",
103 input_abs_get_fuzz(input, axis),
7c494375
DT
104 &fuzz);
105 if (data_present)
4200e831 106 touchscreen_set_params(input, axis, maximum, fuzz);
b98abe52 107}
4200e831 108EXPORT_SYMBOL(touchscreen_parse_properties);
This page took 0.086013 seconds and 5 git commands to generate.