diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2019-10-21 10:11:23 -0700 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2019-10-28 21:01:12 -0700 |
commit | 95c9ea96adb3c7be6295d017c7e2f594f0871c16 (patch) | |
tree | 23189974099e16b868cb7e7e6c7237b57b1a7bed /drivers | |
parent | 78e45917bf7a066fffbeb3d87f4031109df6da55 (diff) | |
download | linux-next-95c9ea96adb3c7be6295d017c7e2f594f0871c16.tar.gz |
Input: st1232 - simplify parsing of read buffer
Avoid complex 2-variable loop when parsing touchscreen data to make the
code clearer.
Acked-by: Martin Kepplinger <martink@posteo.de>
Tested-by: Matthias Fend <Matthias.Fend@wolfvision.net>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/input/touchscreen/st1232.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c index 1139714e72e2..47033ef3749a 100644 --- a/drivers/input/touchscreen/st1232.c +++ b/drivers/input/touchscreen/st1232.c @@ -57,38 +57,38 @@ static int st1232_ts_read_data(struct st1232_ts_data *ts) { struct st1232_ts_finger *finger = ts->finger; struct i2c_client *client = ts->client; - struct i2c_msg msg[2]; - int error; - int i, y; u8 start_reg = ts->chip_info->start_reg; - u8 *buf = ts->read_buf; - - /* read touchscreen data */ - msg[0].addr = client->addr; - msg[0].flags = 0; - msg[0].len = 1; - msg[0].buf = &start_reg; - - msg[1].addr = ts->client->addr; - msg[1].flags = I2C_M_RD; - msg[1].len = ts->read_buf_len; - msg[1].buf = buf; + struct i2c_msg msg[] = { + { + .addr = client->addr, + .len = sizeof(start_reg), + .buf = &start_reg, + }, + { + .addr = client->addr, + .flags = I2C_M_RD, + .len = ts->read_buf_len, + .buf = ts->read_buf, + } + }; + int ret; + int i; + u8 *buf; - error = i2c_transfer(client->adapter, msg, 2); - if (error < 0) - return error; + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); + if (ret != ARRAY_SIZE(msg)) + return ret < 0 ? ret : -EIO; - for (i = 0, y = 0; i < ts->chip_info->max_fingers; i++, y += 3) { - finger[i].is_valid = buf[i + y] >> 7; + for (i = 0; i < ts->chip_info->max_fingers; i++) { + buf = &ts->read_buf[i * 4]; + finger[i].is_valid = buf[0] >> 7; if (finger[i].is_valid) { - finger[i].x = ((buf[i + y] & 0x0070) << 4) | - buf[i + y + 1]; - finger[i].y = ((buf[i + y] & 0x0007) << 8) | - buf[i + y + 2]; + finger[i].x = ((buf[0] & 0x70) << 4) | buf[1]; + finger[i].y = ((buf[0] & 0x07) << 8) | buf[2]; /* st1232 includes a z-axis / touch strength */ if (ts->chip_info->have_z) - finger[i].t = buf[i + 6]; + finger[i].t = ts->read_buf[i + 6]; } } |