]> git.dujemihanovic.xyz Git - linux.git/commitdiff
input: touchscreen: imagis: Add touch key support
authorDuje Mihanović <duje.mihanovic@skole.hr>
Sun, 12 Nov 2023 19:13:02 +0000 (20:13 +0100)
committerDuje Mihanović <duje.mihanovic@skole.hr>
Wed, 27 Dec 2023 15:38:22 +0000 (16:38 +0100)
IST3032C (and possibly some other models) has touch keys. Add support
for them to the imagis driver.

Signed-off-by: Duje Mihanović <duje.mihanovic@skole.hr>
drivers/input/touchscreen/imagis.c

index 41f28e6e9cb18afec3774035a516d6184f9d6222..2b7a754d0049d0f65cd69ea6b7a3222562c6279e 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
+#include <linux/bitfield.h>
 #include <linux/bits.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
@@ -30,6 +31,7 @@
 #define IST3038C_FINGER_COUNT_MASK     GENMASK(15, 12)
 #define IST3038C_FINGER_COUNT_SHIFT    12
 #define IST3038C_FINGER_STATUS_MASK    GENMASK(9, 0)
+#define IST3032C_KEY_STATUS_MASK       GENMASK(20, 16)
 
 #define IST3038B_REG_STATUS            0x20
 #define IST3038B_REG_CHIPID            0x30
@@ -43,6 +45,7 @@ struct imagis_properties {
        unsigned int whoami_cmd;
        unsigned int whoami_val;
        bool protocol_b;
+       bool touch_keys_supported;
 };
 
 struct imagis_ts {
@@ -51,6 +54,8 @@ struct imagis_ts {
        struct input_dev *input_dev;
        struct touchscreen_properties prop;
        struct regulator_bulk_data supplies[2];
+       u32 keycodes[2];
+       int num_keycodes;
 };
 
 static int imagis_i2c_read_reg(struct imagis_ts *ts,
@@ -95,7 +100,7 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id)
 {
        struct imagis_ts *ts = dev_id;
        u32 intr_message, finger_status;
-       unsigned int finger_count, finger_pressed;
+       unsigned int finger_count, finger_pressed, key_pressed;
        int i;
        int error;
 
@@ -144,6 +149,11 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id)
                                        IST3038C_AREA_SHIFT);
        }
 
+       key_pressed = FIELD_GET(IST3032C_KEY_STATUS_MASK, intr_message);
+
+       for (int i = 0; i < ts->num_keycodes; i++)
+               input_report_key(ts->input_dev, ts->keycodes[i], (key_pressed & BIT(i)));
+
        input_mt_sync_frame(ts->input_dev);
        input_sync(ts->input_dev);
 
@@ -229,6 +239,19 @@ static int imagis_init_input_dev(struct imagis_ts *ts)
        input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
        input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
        input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 16, 0, 0);
+       if (ts->tdata->touch_keys_supported) {
+               ts->num_keycodes = of_property_read_variable_u32_array(
+                               ts->client->dev.of_node, "linux,keycodes",
+                               ts->keycodes, 0, ARRAY_SIZE(ts->keycodes));
+               if (ts->num_keycodes <= 0) {
+                       ts->keycodes[0] = KEY_APPSELECT;
+                       ts->keycodes[1] = KEY_BACK;
+                       ts->num_keycodes = 2;
+               }
+       }
+
+       for (int i = 0; i < ts->num_keycodes; i++)
+               input_set_capability(input_dev, EV_KEY, ts->keycodes[i]);
 
        touchscreen_parse_properties(input_dev, true, &ts->prop);
        if (!ts->prop.max_x || !ts->prop.max_y) {
@@ -370,6 +393,7 @@ static const struct imagis_properties imagis_3032c_data = {
        .touch_coord_cmd = IST3038C_REG_TOUCH_COORD,
        .whoami_cmd = IST3038C_REG_CHIPID,
        .whoami_val = IST3032C_WHOAMI,
+       .touch_keys_supported = true,
 };
 
 static const struct imagis_properties imagis_3038b_data = {