diff options
author | Maxime Ripard <maxime.ripard@free-electrons.com> | 2015-03-21 23:17:48 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2015-03-24 15:00:39 -0400 |
commit | 3eea8b5d68c801fec788b411582b803463834752 (patch) | |
tree | f164f747c44980092ac997122320690f550f53cd /drivers/input/touchscreen/of_touchscreen.c | |
parent | 5037a17966967bde3f561cc543c9b3596afabf70 (diff) |
Input: of_touchscreen - rework the DT parsing function
The DT parsing function currently duplicates a lot of the code to parse the
touchscreen DT properties. In order to ease further additions to this
parsing routine, rework it slightly to create new helper functions.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/touchscreen/of_touchscreen.c')
-rw-r--r-- | drivers/input/touchscreen/of_touchscreen.c | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/drivers/input/touchscreen/of_touchscreen.c b/drivers/input/touchscreen/of_touchscreen.c index f8f9b84230b1..fe80d8ba7efa 100644 --- a/drivers/input/touchscreen/of_touchscreen.c +++ b/drivers/input/touchscreen/of_touchscreen.c | |||
@@ -13,6 +13,33 @@ | |||
13 | #include <linux/input.h> | 13 | #include <linux/input.h> |
14 | #include <linux/input/touchscreen.h> | 14 | #include <linux/input/touchscreen.h> |
15 | 15 | ||
16 | static 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 | |||
26 | static 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 | |||
16 | /** | 43 | /** |
17 | * touchscreen_parse_of_params - parse common touchscreen DT properties | 44 | * touchscreen_parse_of_params - parse common touchscreen DT properties |
18 | * @dev: device that should be parsed | 45 | * @dev: device that should be parsed |
@@ -24,22 +51,25 @@ | |||
24 | void touchscreen_parse_of_params(struct input_dev *dev) | 51 | void touchscreen_parse_of_params(struct input_dev *dev) |
25 | { | 52 | { |
26 | struct device_node *np = dev->dev.parent->of_node; | 53 | struct device_node *np = dev->dev.parent->of_node; |
27 | struct input_absinfo *absinfo; | 54 | u32 maximum, fuzz; |
28 | 55 | ||
29 | input_alloc_absinfo(dev); | 56 | input_alloc_absinfo(dev); |
30 | if (!dev->absinfo) | 57 | if (!dev->absinfo) |
31 | return; | 58 | return; |
32 | 59 | ||
33 | absinfo = &dev->absinfo[ABS_X]; | 60 | maximum = of_get_optional_u32(np, "touchscreen-size-x"); |
34 | of_property_read_u32(np, "touchscreen-size-x", &absinfo->maximum); | 61 | fuzz = of_get_optional_u32(np, "touchscreen-fuzz-x"); |
35 | of_property_read_u32(np, "touchscreen-fuzz-x", &absinfo->fuzz); | 62 | if (maximum || fuzz) |
63 | touchscreen_set_params(dev, ABS_X, maximum, fuzz); | ||
36 | 64 | ||
37 | absinfo = &dev->absinfo[ABS_Y]; | 65 | maximum = of_get_optional_u32(np, "touchscreen-size-y"); |
38 | of_property_read_u32(np, "touchscreen-size-y", &absinfo->maximum); | 66 | fuzz = of_get_optional_u32(np, "touchscreen-fuzz-y"); |
39 | of_property_read_u32(np, "touchscreen-fuzz-y", &absinfo->fuzz); | 67 | if (maximum || fuzz) |
68 | touchscreen_set_params(dev, ABS_Y, maximum, fuzz); | ||
40 | 69 | ||
41 | absinfo = &dev->absinfo[ABS_PRESSURE]; | 70 | maximum = of_get_optional_u32(np, "touchscreen-max-pressure"); |
42 | of_property_read_u32(np, "touchscreen-max-pressure", &absinfo->maximum); | 71 | fuzz = of_get_optional_u32(np, "touchscreen-fuzz-pressure"); |
43 | of_property_read_u32(np, "touchscreen-fuzz-pressure", &absinfo->fuzz); | 72 | if (maximum || fuzz) |
73 | touchscreen_set_params(dev, ABS_PRESSURE, maximum, fuzz); | ||
44 | } | 74 | } |
45 | EXPORT_SYMBOL(touchscreen_parse_of_params); | 75 | EXPORT_SYMBOL(touchscreen_parse_of_params); |