]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Input: synaptics-rmi4 - add support for F1A
authorAndré Apitzsch <git@apitzsch.eu>
Sun, 27 Jul 2025 07:32:14 +0000 (00:32 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Sun, 27 Jul 2025 08:41:19 +0000 (01:41 -0700)
RMI4 F1A implements capacitive keys. Add support for touch keys found in
some Synaptics touch controller configurations.

Signed-off-by: André Apitzsch <git@apitzsch.eu>
Link: https://lore.kernel.org/r/20250707-rmi4_f1a-v1-2-838d83c72e7f@apitzsch.eu
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/rmi4/Kconfig
drivers/input/rmi4/Makefile
drivers/input/rmi4/rmi_bus.c
drivers/input/rmi4/rmi_driver.h
drivers/input/rmi4/rmi_f1a.c [new file with mode: 0644]

index 1f91d620eadb28ac38accd6bc9697ef574037acb..5db58fc9e11b2ab86f38952ed79e2a30340c4c58 100644 (file)
@@ -82,6 +82,13 @@ config RMI4_F12
          touchpads. For sensors that support relative pointing, F12 also
          provides mouse input.
 
+config RMI4_F1A
+       bool "RMI4 Function 1A (0D pointing)"
+       help
+         Say Y here if you want to add support for RMI4 function 1A.
+
+         Function 1A provides capacitive keys support for RMI4 devices.
+
 config RMI4_F21
        bool "RMI4 Function 21 (PRESSURE)"
        help
index 484b97eca025014d81bdf73f5b9b581ae401211d..35ae29f724978df7e4f880569550dcac62c55663 100644 (file)
@@ -8,6 +8,7 @@ rmi_core-$(CONFIG_RMI4_2D_SENSOR) += rmi_2d_sensor.o
 rmi_core-$(CONFIG_RMI4_F03) += rmi_f03.o
 rmi_core-$(CONFIG_RMI4_F11) += rmi_f11.o
 rmi_core-$(CONFIG_RMI4_F12) += rmi_f12.o
+rmi_core-$(CONFIG_RMI4_F1A) += rmi_f1a.o
 rmi_core-$(CONFIG_RMI4_F21) += rmi_f21.o
 rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o
 rmi_core-$(CONFIG_RMI4_F34) += rmi_f34.o rmi_f34v7.o
index 47fe7a88c92ba631f5acf8d72404e78daec31345..5f98c3bcfd465e623e355d92a341ed594cd0be21 100644 (file)
@@ -360,6 +360,9 @@ static struct rmi_function_handler *fn_handlers[] = {
 #ifdef CONFIG_RMI4_F12
        &rmi_f12_handler,
 #endif
+#ifdef CONFIG_RMI4_F1A
+       &rmi_f1a_handler,
+#endif
 #ifdef CONFIG_RMI4_F21
        &rmi_f21_handler,
 #endif
index 21e1c766356119ffbbb3a74a7093e3b41af044d5..e84495caab1514f56b28a2144c32795b82039b1c 100644 (file)
@@ -133,6 +133,7 @@ extern struct rmi_function_handler rmi_f01_handler;
 extern struct rmi_function_handler rmi_f03_handler;
 extern struct rmi_function_handler rmi_f11_handler;
 extern struct rmi_function_handler rmi_f12_handler;
+extern struct rmi_function_handler rmi_f1a_handler;
 extern struct rmi_function_handler rmi_f21_handler;
 extern struct rmi_function_handler rmi_f30_handler;
 extern struct rmi_function_handler rmi_f34_handler;
diff --git a/drivers/input/rmi4/rmi_f1a.c b/drivers/input/rmi4/rmi_f1a.c
new file mode 100644 (file)
index 0000000..765e9ea
--- /dev/null
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2025 André Apitzsch <git@apitzsch.eu>
+ */
+
+#include <linux/input.h>
+#include <linux/property.h>
+#include "rmi_driver.h"
+
+struct f1a_data {
+       struct input_dev *input;
+
+       u32 *keymap;
+       unsigned int num_keys;
+};
+
+static int rmi_f1a_parse_device_properties(struct rmi_function *fn, struct f1a_data *f1a)
+{
+       static const char buttons_property[] = "linux,keycodes";
+       struct device *dev = &fn->dev;
+       u32 *buttonmap;
+       int n_keys;
+       int error;
+
+       if (!device_property_present(dev, buttons_property))
+               return 0;
+
+       n_keys = device_property_count_u32(dev, buttons_property);
+       if (n_keys <= 0) {
+               error = n_keys < 0 ? n_keys : -EINVAL;
+               dev_err(dev, "Invalid/malformed '%s' property: %d\n",
+                       buttons_property, error);
+               return error;
+       }
+
+       buttonmap = devm_kmalloc_array(dev, n_keys, sizeof(*buttonmap),
+                                      GFP_KERNEL);
+       if (!buttonmap)
+               return -ENOMEM;
+
+       error = device_property_read_u32_array(dev, buttons_property,
+                                              buttonmap, n_keys);
+       if (error) {
+               dev_err(dev, "Failed to parse '%s' property: %d\n",
+                       buttons_property, error);
+               return error;
+       }
+
+       f1a->keymap = buttonmap;
+       f1a->num_keys = n_keys;
+
+       return 0;
+}
+
+static irqreturn_t rmi_f1a_attention(int irq, void *ctx)
+{
+       struct rmi_function *fn = ctx;
+       struct f1a_data *f1a = dev_get_drvdata(&fn->dev);
+       char button_bitmask;
+       int key;
+       int error;
+
+       error = rmi_read_block(fn->rmi_dev, fn->fd.data_base_addr,
+                              &button_bitmask, sizeof(button_bitmask));
+       if (error) {
+               dev_err(&fn->dev, "Failed to read object data. Code: %d.\n",
+                       error);
+               return IRQ_RETVAL(error);
+       }
+
+       for (key = 0; key < f1a->num_keys; key++)
+               input_report_key(f1a->input, f1a->keymap[key],
+                                button_bitmask & BIT(key));
+
+       return IRQ_HANDLED;
+}
+
+static int rmi_f1a_config(struct rmi_function *fn)
+{
+       struct f1a_data *f1a = dev_get_drvdata(&fn->dev);
+       struct rmi_driver *drv = fn->rmi_dev->driver;
+
+       if (f1a->num_keys)
+               drv->set_irq_bits(fn->rmi_dev, fn->irq_mask);
+
+       return 0;
+}
+
+static int rmi_f1a_initialize(struct rmi_function *fn, struct f1a_data *f1a)
+{
+       int error;
+       int i;
+
+       error = rmi_f1a_parse_device_properties(fn, f1a);
+       if (error)
+               return error;
+
+       for (i = 0; i < f1a->num_keys; i++)
+               input_set_capability(f1a->input, EV_KEY, f1a->keymap[i]);
+
+       f1a->input->keycode = f1a->keymap;
+       f1a->input->keycodemax = f1a->num_keys;
+       f1a->input->keycodesize = sizeof(f1a->keymap[0]);
+
+       return 0;
+}
+
+static int rmi_f1a_probe(struct rmi_function *fn)
+{
+       struct rmi_device *rmi_dev = fn->rmi_dev;
+       struct rmi_driver_data *drv_data = dev_get_drvdata(&rmi_dev->dev);
+       struct f1a_data *f1a;
+       int error;
+
+       if (!drv_data->input) {
+               dev_info(&fn->dev, "F1A: no input device found, ignoring\n");
+               return -ENXIO;
+       }
+
+       f1a = devm_kzalloc(&fn->dev, sizeof(*f1a), GFP_KERNEL);
+       if (!f1a)
+               return -ENOMEM;
+
+       f1a->input = drv_data->input;
+
+       error = rmi_f1a_initialize(fn, f1a);
+       if (error)
+               return error;
+
+       dev_set_drvdata(&fn->dev, f1a);
+
+       return 0;
+}
+
+struct rmi_function_handler rmi_f1a_handler = {
+       .driver = {
+               .name = "rmi4_f1a",
+       },
+       .func = 0x1a,
+       .probe = rmi_f1a_probe,
+       .config = rmi_f1a_config,
+       .attention = rmi_f1a_attention,
+};