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 | |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 12 | #include <linux/property.h> |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 13 | #include <linux/input.h> |
Maxime Ripard | 0a363a3 | 2015-03-21 20:17:57 -0700 | [diff] [blame] | 14 | #include <linux/input/mt.h> |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 15 | #include <linux/input/touchscreen.h> |
| 16 | |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 17 | static bool touchscreen_get_prop_u32(struct device *dev, |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 18 | const char *property, |
| 19 | unsigned int default_value, |
| 20 | unsigned int *value) |
Maxime Ripard | 3eea8b5 | 2015-03-21 20:17:48 -0700 | [diff] [blame] | 21 | { |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 22 | u32 val; |
| 23 | int error; |
Maxime Ripard | 3eea8b5 | 2015-03-21 20:17:48 -0700 | [diff] [blame] | 24 | |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 25 | error = device_property_read_u32(dev, property, &val); |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 26 | if (error) { |
| 27 | *value = default_value; |
| 28 | return false; |
| 29 | } |
Maxime Ripard | 3eea8b5 | 2015-03-21 20:17:48 -0700 | [diff] [blame] | 30 | |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 31 | *value = val; |
| 32 | return true; |
Maxime Ripard | 3eea8b5 | 2015-03-21 20:17:48 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static 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)) { |
Dmitry Torokhov | f61fd21 | 2015-07-06 14:45:25 -0700 | [diff] [blame] | 42 | dev_warn(&dev->dev, |
| 43 | "DT specifies parameters but the axis %lu is not set up\n", |
| 44 | axis); |
Maxime Ripard | 3eea8b5 | 2015-03-21 20:17:48 -0700 | [diff] [blame] | 45 | return; |
| 46 | } |
| 47 | |
| 48 | absinfo = &dev->absinfo[axis]; |
| 49 | absinfo->maximum = max; |
| 50 | absinfo->fuzz = fuzz; |
| 51 | } |
| 52 | |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 53 | /** |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 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 |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 58 | * |
| 59 | * This function parses common DT properties for touchscreens and setups the |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 60 | * input device accordingly. The function keeps previously set up default |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 61 | * values if no value is specified via DT. |
| 62 | */ |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 63 | void touchscreen_parse_properties(struct input_dev *input, bool multitouch) |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 64 | { |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 65 | struct device *dev = input->dev.parent; |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 66 | unsigned int axis; |
| 67 | unsigned int maximum, fuzz; |
| 68 | bool data_present; |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 69 | |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 70 | input_alloc_absinfo(input); |
| 71 | if (!input->absinfo) |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 72 | return; |
| 73 | |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 74 | axis = multitouch ? ABS_MT_POSITION_X : ABS_X; |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 75 | data_present = touchscreen_get_prop_u32(dev, "touchscreen-size-x", |
| 76 | input_abs_get_max(input, |
Dmitry Torokhov | 5171786 | 2015-07-06 14:57:54 -0700 | [diff] [blame] | 77 | axis) + 1, |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 78 | &maximum) | |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 79 | touchscreen_get_prop_u32(dev, "touchscreen-fuzz-x", |
| 80 | input_abs_get_fuzz(input, axis), |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 81 | &fuzz); |
| 82 | if (data_present) |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 83 | touchscreen_set_params(input, axis, maximum - 1, fuzz); |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 84 | |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 85 | axis = multitouch ? ABS_MT_POSITION_Y : ABS_Y; |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 86 | data_present = touchscreen_get_prop_u32(dev, "touchscreen-size-y", |
| 87 | input_abs_get_max(input, |
Dmitry Torokhov | 5171786 | 2015-07-06 14:57:54 -0700 | [diff] [blame] | 88 | axis) + 1, |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 89 | &maximum) | |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 90 | touchscreen_get_prop_u32(dev, "touchscreen-fuzz-y", |
| 91 | input_abs_get_fuzz(input, axis), |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 92 | &fuzz); |
| 93 | if (data_present) |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 94 | touchscreen_set_params(input, axis, maximum - 1, fuzz); |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 95 | |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 96 | axis = multitouch ? ABS_MT_PRESSURE : ABS_PRESSURE; |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 97 | data_present = touchscreen_get_prop_u32(dev, |
| 98 | "touchscreen-max-pressure", |
| 99 | input_abs_get_max(input, axis), |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 100 | &maximum) | |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 101 | touchscreen_get_prop_u32(dev, |
| 102 | "touchscreen-fuzz-pressure", |
| 103 | input_abs_get_fuzz(input, axis), |
Dmitry Torokhov | 7c49437 | 2015-06-01 10:35:16 -0700 | [diff] [blame] | 104 | &fuzz); |
| 105 | if (data_present) |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 106 | touchscreen_set_params(input, axis, maximum, fuzz); |
Sebastian Reichel | b98abe5 | 2014-05-28 23:51:53 -0700 | [diff] [blame] | 107 | } |
Dmitry Torokhov | 4200e83 | 2015-07-06 15:18:24 -0700 | [diff] [blame] | 108 | EXPORT_SYMBOL(touchscreen_parse_properties); |