[PATCH 4/6] input: elants: detect max_x/y from hardware

From: MichaÅ MirosÅaw
Date: Mon Dec 09 2019 - 19:19:35 EST


Read max_x/y from hardware when not specified in devicetree.

elants_i2c_initialize() call is moved after inputdev allocation (but
still before making it visible) to allow the function to see DT-provided
values.

Signed-off-by: MichaÅ MirosÅaw <mirq-linux@xxxxxxxxxxxx>
---
drivers/input/touchscreen/elants_i2c.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
index 02bd5e3e2171..2e6c9aa60496 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -498,9 +498,11 @@ static int elants_i2c_query_ts_info(struct elants_data *ts)
rows, cols, osr);
} else {
/* translate trace number to TS resolution */
- ts->prop.max_x = ELAN_TS_RESOLUTION(rows, osr);
+ if (!ts->prop.max_x)
+ ts->prop.max_x = ELAN_TS_RESOLUTION(rows, osr);
ts->x_res = DIV_ROUND_CLOSEST(ts->prop.max_x, phy_x);
- ts->prop.max_y = ELAN_TS_RESOLUTION(cols, osr);
+ if (!ts->prop.max_y)
+ ts->prop.max_y = ELAN_TS_RESOLUTION(cols, osr);
ts->y_res = DIV_ROUND_CLOSEST(ts->prop.max_y, phy_y);
}

@@ -1235,12 +1237,6 @@ static int elants_i2c_probe(struct i2c_client *client,
return -ENXIO;
}

- error = elants_i2c_initialize(ts);
- if (error) {
- dev_err(&client->dev, "failed to initialize: %d\n", error);
- return error;
- }
-
ts->input = devm_input_allocate_device(&client->dev);
if (!ts->input) {
dev_err(&client->dev, "Failed to allocate input device\n");
@@ -1252,6 +1248,12 @@ static int elants_i2c_probe(struct i2c_client *client,

touchscreen_parse_properties(ts->input, true, &ts->prop);

+ error = elants_i2c_initialize(ts);
+ if (error) {
+ dev_err(&client->dev, "failed to initialize: %d\n", error);
+ return error;
+ }
+
__set_bit(BTN_TOUCH, ts->input->keybit);
__set_bit(EV_ABS, ts->input->evbit);
__set_bit(EV_KEY, ts->input->evbit);
--
2.20.1