diff options
author | Hans de Goede <hdegoede@redhat.com> | 2016-07-15 17:28:11 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2016-07-15 17:50:56 -0400 |
commit | 50dd9f66e54cb415138695944975d4ee51d8b4a5 (patch) | |
tree | 04e4e2871841791c0afb204e9338e8dcd7721707 /drivers/input/touchscreen | |
parent | ad368eb2da8f7ae8d40a299e5982e02affc879fd (diff) |
Input: icn8318 - use of_touchscreen helpers for inverting / swapping axes
Use the touchscreen_parse_properties() and touchscreen_report_pos() to
perform coordinates transformation, instead of DIY code, which results in a
nice cleanup.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r-- | drivers/input/touchscreen/chipone_icn8318.c | 61 |
1 files changed, 14 insertions, 47 deletions
diff --git a/drivers/input/touchscreen/chipone_icn8318.c b/drivers/input/touchscreen/chipone_icn8318.c index 22a6fead8cfb..0bf14067c167 100644 --- a/drivers/input/touchscreen/chipone_icn8318.c +++ b/drivers/input/touchscreen/chipone_icn8318.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/i2c.h> | 17 | #include <linux/i2c.h> |
18 | #include <linux/input.h> | 18 | #include <linux/input.h> |
19 | #include <linux/input/mt.h> | 19 | #include <linux/input/mt.h> |
20 | #include <linux/input/touchscreen.h> | ||
20 | #include <linux/module.h> | 21 | #include <linux/module.h> |
21 | #include <linux/of.h> | 22 | #include <linux/of.h> |
22 | 23 | ||
@@ -52,11 +53,7 @@ struct icn8318_data { | |||
52 | struct i2c_client *client; | 53 | struct i2c_client *client; |
53 | struct input_dev *input; | 54 | struct input_dev *input; |
54 | struct gpio_desc *wake_gpio; | 55 | struct gpio_desc *wake_gpio; |
55 | u32 max_x; | 56 | struct touchscreen_properties prop; |
56 | u32 max_y; | ||
57 | bool invert_x; | ||
58 | bool invert_y; | ||
59 | bool swap_x_y; | ||
60 | }; | 57 | }; |
61 | 58 | ||
62 | static int icn8318_read_touch_data(struct i2c_client *client, | 59 | static int icn8318_read_touch_data(struct i2c_client *client, |
@@ -91,7 +88,7 @@ static irqreturn_t icn8318_irq(int irq, void *dev_id) | |||
91 | struct icn8318_data *data = dev_id; | 88 | struct icn8318_data *data = dev_id; |
92 | struct device *dev = &data->client->dev; | 89 | struct device *dev = &data->client->dev; |
93 | struct icn8318_touch_data touch_data; | 90 | struct icn8318_touch_data touch_data; |
94 | int i, ret, x, y; | 91 | int i, ret; |
95 | 92 | ||
96 | ret = icn8318_read_touch_data(data->client, &touch_data); | 93 | ret = icn8318_read_touch_data(data->client, &touch_data); |
97 | if (ret < 0) { | 94 | if (ret < 0) { |
@@ -124,22 +121,9 @@ static irqreturn_t icn8318_irq(int irq, void *dev_id) | |||
124 | if (!act) | 121 | if (!act) |
125 | continue; | 122 | continue; |
126 | 123 | ||
127 | x = be16_to_cpu(touch->x); | 124 | touchscreen_report_pos(data->input, &data->prop, |
128 | y = be16_to_cpu(touch->y); | 125 | be16_to_cpu(touch->x), |
129 | 126 | be16_to_cpu(touch->y), true); | |
130 | if (data->invert_x) | ||
131 | x = data->max_x - x; | ||
132 | |||
133 | if (data->invert_y) | ||
134 | y = data->max_y - y; | ||
135 | |||
136 | if (!data->swap_x_y) { | ||
137 | input_event(data->input, EV_ABS, ABS_MT_POSITION_X, x); | ||
138 | input_event(data->input, EV_ABS, ABS_MT_POSITION_Y, y); | ||
139 | } else { | ||
140 | input_event(data->input, EV_ABS, ABS_MT_POSITION_X, y); | ||
141 | input_event(data->input, EV_ABS, ABS_MT_POSITION_Y, x); | ||
142 | } | ||
143 | } | 127 | } |
144 | 128 | ||
145 | input_mt_sync_frame(data->input); | 129 | input_mt_sync_frame(data->input); |
@@ -200,10 +184,8 @@ static int icn8318_probe(struct i2c_client *client, | |||
200 | const struct i2c_device_id *id) | 184 | const struct i2c_device_id *id) |
201 | { | 185 | { |
202 | struct device *dev = &client->dev; | 186 | struct device *dev = &client->dev; |
203 | struct device_node *np = dev->of_node; | ||
204 | struct icn8318_data *data; | 187 | struct icn8318_data *data; |
205 | struct input_dev *input; | 188 | struct input_dev *input; |
206 | u32 fuzz_x = 0, fuzz_y = 0; | ||
207 | int error; | 189 | int error; |
208 | 190 | ||
209 | if (!client->irq) { | 191 | if (!client->irq) { |
@@ -223,19 +205,6 @@ static int icn8318_probe(struct i2c_client *client, | |||
223 | return error; | 205 | return error; |
224 | } | 206 | } |
225 | 207 | ||
226 | if (of_property_read_u32(np, "touchscreen-size-x", &data->max_x) || | ||
227 | of_property_read_u32(np, "touchscreen-size-y", &data->max_y)) { | ||
228 | dev_err(dev, "Error touchscreen-size-x and/or -y missing\n"); | ||
229 | return -EINVAL; | ||
230 | } | ||
231 | |||
232 | /* Optional */ | ||
233 | of_property_read_u32(np, "touchscreen-fuzz-x", &fuzz_x); | ||
234 | of_property_read_u32(np, "touchscreen-fuzz-y", &fuzz_y); | ||
235 | data->invert_x = of_property_read_bool(np, "touchscreen-inverted-x"); | ||
236 | data->invert_y = of_property_read_bool(np, "touchscreen-inverted-y"); | ||
237 | data->swap_x_y = of_property_read_bool(np, "touchscreen-swapped-x-y"); | ||
238 | |||
239 | input = devm_input_allocate_device(dev); | 208 | input = devm_input_allocate_device(dev); |
240 | if (!input) | 209 | if (!input) |
241 | return -ENOMEM; | 210 | return -ENOMEM; |
@@ -246,16 +215,14 @@ static int icn8318_probe(struct i2c_client *client, | |||
246 | input->close = icn8318_stop; | 215 | input->close = icn8318_stop; |
247 | input->dev.parent = dev; | 216 | input->dev.parent = dev; |
248 | 217 | ||
249 | if (!data->swap_x_y) { | 218 | input_set_capability(input, EV_ABS, ABS_MT_POSITION_X); |
250 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, | 219 | input_set_capability(input, EV_ABS, ABS_MT_POSITION_Y); |
251 | data->max_x, fuzz_x, 0); | 220 | |
252 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, | 221 | touchscreen_parse_properties(input, true, &data->prop); |
253 | data->max_y, fuzz_y, 0); | 222 | if (!input_abs_get_max(input, ABS_MT_POSITION_X) || |
254 | } else { | 223 | !input_abs_get_max(input, ABS_MT_POSITION_Y)) { |
255 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, | 224 | dev_err(dev, "Error touchscreen-size-x and/or -y missing\n"); |
256 | data->max_y, fuzz_y, 0); | 225 | return -EINVAL; |
257 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, | ||
258 | data->max_x, fuzz_x, 0); | ||
259 | } | 226 | } |
260 | 227 | ||
261 | error = input_mt_init_slots(input, ICN8318_MAX_TOUCHES, | 228 | error = input_mt_init_slots(input, ICN8318_MAX_TOUCHES, |