Skip to content

Commit f27ad89

Browse files
ElanJohnnyChuangdtor
authored andcommitted
Input: elants_i2c - support palm detection
Elan uses the least significant bit of byte 33 to signal the type of contact (finger versus palm). The default value is 1 for all firmwares, which is reported as MT_TOOL_FINGER. If firmware supports palm detection, the bit will change to 0 and the driver will report such contact as MT_TOOL_PALM. Signed-off-by: Johnny Chuang <[email protected]> Reviewed-by: Peter Hutterer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent cd51067 commit f27ad89

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/input/touchscreen/elants_i2c.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121

22+
#include <linux/bits.h>
2223
#include <linux/module.h>
2324
#include <linux/input.h>
2425
#include <linux/interrupt.h>
@@ -73,6 +74,7 @@
7374
#define FW_POS_STATE 1
7475
#define FW_POS_TOTAL 2
7576
#define FW_POS_XY 3
77+
#define FW_POS_TOOL_TYPE 33
7678
#define FW_POS_CHECKSUM 34
7779
#define FW_POS_WIDTH 35
7880
#define FW_POS_PRESSURE 45
@@ -842,6 +844,7 @@ static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf)
842844
{
843845
struct input_dev *input = ts->input;
844846
unsigned int n_fingers;
847+
unsigned int tool_type;
845848
u16 finger_state;
846849
int i;
847850

@@ -852,6 +855,10 @@ static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf)
852855
dev_dbg(&ts->client->dev,
853856
"n_fingers: %u, state: %04x\n", n_fingers, finger_state);
854857

858+
/* Note: all fingers have the same tool type */
859+
tool_type = buf[FW_POS_TOOL_TYPE] & BIT(0) ?
860+
MT_TOOL_FINGER : MT_TOOL_PALM;
861+
855862
for (i = 0; i < MAX_CONTACT_NUM && n_fingers; i++) {
856863
if (finger_state & 1) {
857864
unsigned int x, y, p, w;
@@ -867,7 +874,7 @@ static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf)
867874
i, x, y, p, w);
868875

869876
input_mt_slot(input, i);
870-
input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
877+
input_mt_report_slot_state(input, tool_type, true);
871878
input_event(input, EV_ABS, ABS_MT_POSITION_X, x);
872879
input_event(input, EV_ABS, ABS_MT_POSITION_Y, y);
873880
input_event(input, EV_ABS, ABS_MT_PRESSURE, p);
@@ -1307,6 +1314,8 @@ static int elants_i2c_probe(struct i2c_client *client,
13071314
input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, ts->y_max, 0, 0);
13081315
input_set_abs_params(ts->input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
13091316
input_set_abs_params(ts->input, ABS_MT_PRESSURE, 0, 255, 0, 0);
1317+
input_set_abs_params(ts->input, ABS_MT_TOOL_TYPE,
1318+
0, MT_TOOL_PALM, 0, 0);
13101319
input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->x_res);
13111320
input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->y_res);
13121321
input_abs_set_res(ts->input, ABS_MT_TOUCH_MAJOR, 1);

0 commit comments

Comments
 (0)