Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 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 | |
| 12 | #include <linux/of.h> |
| 13 | #include <linux/input.h> |
| 14 | #include <linux/input/touchscreen.h> |
| 15 | |
Maxime Ripard | 3eea8b5 | 2015-03-21 20:17:48 -0700 | [diff] [blame^] | 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 | |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 43 | /** |
| 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 | */ |
| 51 | void touchscreen_parse_of_params(struct input_dev *dev) |
| 52 | { |
| 53 | struct device_node *np = dev->dev.parent->of_node; |
Maxime Ripard | 3eea8b5 | 2015-03-21 20:17:48 -0700 | [diff] [blame^] | 54 | u32 maximum, fuzz; |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 55 | |
| 56 | input_alloc_absinfo(dev); |
| 57 | if (!dev->absinfo) |
| 58 | return; |
| 59 | |
Maxime Ripard | 3eea8b5 | 2015-03-21 20:17:48 -0700 | [diff] [blame^] | 60 | 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 Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 64 | |
Maxime Ripard | 3eea8b5 | 2015-03-21 20:17:48 -0700 | [diff] [blame^] | 65 | 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 Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 69 | |
Maxime Ripard | 3eea8b5 | 2015-03-21 20:17:48 -0700 | [diff] [blame^] | 70 | 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 Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 74 | } |
| 75 | EXPORT_SYMBOL(touchscreen_parse_of_params); |