Commit 50dd9f66 authored by Hans de Goede's avatar Hans de Goede Committed by Dmitry Torokhov

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: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent ad368eb2
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/input/mt.h> #include <linux/input/mt.h>
#include <linux/input/touchscreen.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
...@@ -52,11 +53,7 @@ struct icn8318_data { ...@@ -52,11 +53,7 @@ struct icn8318_data {
struct i2c_client *client; struct i2c_client *client;
struct input_dev *input; struct input_dev *input;
struct gpio_desc *wake_gpio; struct gpio_desc *wake_gpio;
u32 max_x; struct touchscreen_properties prop;
u32 max_y;
bool invert_x;
bool invert_y;
bool swap_x_y;
}; };
static int icn8318_read_touch_data(struct i2c_client *client, 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,7 +88,7 @@ static irqreturn_t icn8318_irq(int irq, void *dev_id)
struct icn8318_data *data = dev_id; struct icn8318_data *data = dev_id;
struct device *dev = &data->client->dev; struct device *dev = &data->client->dev;
struct icn8318_touch_data touch_data; struct icn8318_touch_data touch_data;
int i, ret, x, y; int i, ret;
ret = icn8318_read_touch_data(data->client, &touch_data); ret = icn8318_read_touch_data(data->client, &touch_data);
if (ret < 0) { if (ret < 0) {
...@@ -124,22 +121,9 @@ static irqreturn_t icn8318_irq(int irq, void *dev_id) ...@@ -124,22 +121,9 @@ static irqreturn_t icn8318_irq(int irq, void *dev_id)
if (!act) if (!act)
continue; continue;
x = be16_to_cpu(touch->x); touchscreen_report_pos(data->input, &data->prop,
y = be16_to_cpu(touch->y); be16_to_cpu(touch->x),
be16_to_cpu(touch->y), true);
if (data->invert_x)
x = data->max_x - x;
if (data->invert_y)
y = data->max_y - y;
if (!data->swap_x_y) {
input_event(data->input, EV_ABS, ABS_MT_POSITION_X, x);
input_event(data->input, EV_ABS, ABS_MT_POSITION_Y, y);
} else {
input_event(data->input, EV_ABS, ABS_MT_POSITION_X, y);
input_event(data->input, EV_ABS, ABS_MT_POSITION_Y, x);
}
} }
input_mt_sync_frame(data->input); input_mt_sync_frame(data->input);
...@@ -200,10 +184,8 @@ static int icn8318_probe(struct i2c_client *client, ...@@ -200,10 +184,8 @@ static int icn8318_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev; struct device *dev = &client->dev;
struct device_node *np = dev->of_node;
struct icn8318_data *data; struct icn8318_data *data;
struct input_dev *input; struct input_dev *input;
u32 fuzz_x = 0, fuzz_y = 0;
int error; int error;
if (!client->irq) { if (!client->irq) {
...@@ -223,19 +205,6 @@ static int icn8318_probe(struct i2c_client *client, ...@@ -223,19 +205,6 @@ static int icn8318_probe(struct i2c_client *client,
return error; return error;
} }
if (of_property_read_u32(np, "touchscreen-size-x", &data->max_x) ||
of_property_read_u32(np, "touchscreen-size-y", &data->max_y)) {
dev_err(dev, "Error touchscreen-size-x and/or -y missing\n");
return -EINVAL;
}
/* Optional */
of_property_read_u32(np, "touchscreen-fuzz-x", &fuzz_x);
of_property_read_u32(np, "touchscreen-fuzz-y", &fuzz_y);
data->invert_x = of_property_read_bool(np, "touchscreen-inverted-x");
data->invert_y = of_property_read_bool(np, "touchscreen-inverted-y");
data->swap_x_y = of_property_read_bool(np, "touchscreen-swapped-x-y");
input = devm_input_allocate_device(dev); input = devm_input_allocate_device(dev);
if (!input) if (!input)
return -ENOMEM; return -ENOMEM;
...@@ -246,16 +215,14 @@ static int icn8318_probe(struct i2c_client *client, ...@@ -246,16 +215,14 @@ static int icn8318_probe(struct i2c_client *client,
input->close = icn8318_stop; input->close = icn8318_stop;
input->dev.parent = dev; input->dev.parent = dev;
if (!data->swap_x_y) { input_set_capability(input, EV_ABS, ABS_MT_POSITION_X);
input_set_abs_params(input, ABS_MT_POSITION_X, 0, input_set_capability(input, EV_ABS, ABS_MT_POSITION_Y);
data->max_x, fuzz_x, 0);
input_set_abs_params(input, ABS_MT_POSITION_Y, 0, touchscreen_parse_properties(input, true, &data->prop);
data->max_y, fuzz_y, 0); if (!input_abs_get_max(input, ABS_MT_POSITION_X) ||
} else { !input_abs_get_max(input, ABS_MT_POSITION_Y)) {
input_set_abs_params(input, ABS_MT_POSITION_X, 0, dev_err(dev, "Error touchscreen-size-x and/or -y missing\n");
data->max_y, fuzz_y, 0); return -EINVAL;
input_set_abs_params(input, ABS_MT_POSITION_Y, 0,
data->max_x, fuzz_x, 0);
} }
error = input_mt_init_slots(input, ICN8318_MAX_TOUCHES, error = input_mt_init_slots(input, ICN8318_MAX_TOUCHES,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment