summaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard/dlink-dir685-touchkeys.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-08-23 13:28:57 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2026-08-23 13:28:57 -0700
commit4352b8aee98005853aa63f57d6377282de17a33f (patch)
tree27614d7a9ef05c32d089004e104364ce42324837 /drivers/input/keyboard/dlink-dir685-touchkeys.c
downloadlinux-stable-4352b8aee98005853aa63f57d6377282de17a33f.tar.gz
linux-stable-4352b8aee98005853aa63f57d6377282de17a33f.zip
Merge tag 'i3c/for-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linuxgrafted
Pull I3C updates from Alexandre Belloni: "A new driver this cycle, for the AMD AXI I3C controller. There are also new features such as IBI wakeup support, SETAASA device discovery and ACPI support for the the DAA methods, meaning we can now communicate with the SPD devices on DDR5 modules. New driver: - AMD AXI I3C master controller Subsystem: - I3C Common Command Code (CCC) handling improvements, especially around GET CCCs - SETAASA device discovery support - ACPI support for all existing DAA methods like SETDASA, SETNEWDA as well as I2C devices on I3C bus - IBI-based wakeup support Drivers: - dw: SETAASA support - mipi-i3c-hci: advertise IBI wakeup capability, AMD_PT I3C controller support, PIO queue management support for HCI v1.2 - renesas: improve suspend to RAM support, add runtime PM support" * tag 'i3c/for-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux: (70 commits) i3c: dw: reduce do_daa time if there's no client i3c: mipi-i3c-hci: Add support for AMD_PT I3C controller i3c: mipi-i3c-hci: Add PIO queue management support for HCI v1.2 i3c: mipi-i3c-hci: Fix missing STAT_IBI_STATUS_THLD in PIO mode i3c: dw: rename "pclk" to "apb" to match dt-binding i3c: dw: make struct dw_i3c_cmd smaller i3c: dw: use COMMAND_PORT_TRANSFER_ARG instead of hardcoding i3c: renesas: Don't register devices when ENTDAA times out i3c: master: dw-i3c-master: fix OD timing for first broadcast i3c: mipi-i3c-hci: Advertise IBI wakeup capability i3c: mipi-i3c-hci: Factor out i3c_hci_sysdev() i3c: mipi-i3c-hci-pci: Propagate I3C wakeup requirements to PCI i3c: master: Reject IBI requests from non-IBI-capable devices i3c: master: Add helper to query bus wakeup requirements i3c: master: Report wakeup events for IBIs i3c: master: Support IBI-based wakeup capability i3c: master: Fix potential UAF in i3c_device_match() i3c: master: Fix potential UAF in i3c_device_uevent() i3c: Make dev->desc locking assumptions explicit i3c: master: Fix use-after-free of master->this ...
Diffstat (limited to 'drivers/input/keyboard/dlink-dir685-touchkeys.c')
-rw-r--r--drivers/input/keyboard/dlink-dir685-touchkeys.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/drivers/input/keyboard/dlink-dir685-touchkeys.c b/drivers/input/keyboard/dlink-dir685-touchkeys.c
new file mode 100644
index 000000000..bf94367f6
--- /dev/null
+++ b/drivers/input/keyboard/dlink-dir685-touchkeys.c
@@ -0,0 +1,156 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * D-Link DIR-685 router I2C-based Touchkeys input driver
+ * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
+ *
+ * This is a one-off touchkey controller based on the Cypress Semiconductor
+ * CY8C214 MCU with some firmware in its internal 8KB flash. The circuit
+ * board inside the router is named E119921
+ */
+
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/input.h>
+#include <linux/slab.h>
+#include <linux/string_choices.h>
+#include <linux/bitops.h>
+
+struct dir685_touchkeys {
+ struct device *dev;
+ struct i2c_client *client;
+ struct input_dev *input;
+ unsigned long cur_key;
+ u16 codes[7];
+};
+
+static irqreturn_t dir685_tk_irq_thread(int irq, void *data)
+{
+ struct dir685_touchkeys *tk = data;
+ const int num_bits = min_t(int, ARRAY_SIZE(tk->codes), 16);
+ unsigned long changed;
+ u8 buf[6];
+ unsigned long key;
+ int i;
+ int err;
+
+ memset(buf, 0, sizeof(buf));
+ err = i2c_master_recv(tk->client, buf, sizeof(buf));
+ if (err != sizeof(buf)) {
+ dev_err(tk->dev, "short read %d\n", err);
+ return IRQ_HANDLED;
+ }
+
+ dev_dbg(tk->dev, "IN: %*ph\n", (int)sizeof(buf), buf);
+ key = be16_to_cpup((__be16 *) &buf[4]);
+
+ /* Figure out if any bits went high or low since last message */
+ changed = tk->cur_key ^ key;
+ for_each_set_bit(i, &changed, num_bits) {
+ dev_dbg(tk->dev, "key %d is %s\n", i,
+ str_down_up(test_bit(i, &key)));
+ input_report_key(tk->input, tk->codes[i], test_bit(i, &key));
+ }
+
+ /* Store currently down keys */
+ tk->cur_key = key;
+ input_sync(tk->input);
+
+ return IRQ_HANDLED;
+}
+
+static int dir685_tk_probe(struct i2c_client *client)
+{
+ static const u8 bl_data[] = { 0xa7, 0x40 };
+ struct device *dev = &client->dev;
+ struct dir685_touchkeys *tk;
+ int err;
+ int i;
+
+ tk = devm_kzalloc(&client->dev, sizeof(*tk), GFP_KERNEL);
+ if (!tk)
+ return -ENOMEM;
+
+ tk->input = devm_input_allocate_device(dev);
+ if (!tk->input)
+ return -ENOMEM;
+
+ tk->client = client;
+ tk->dev = dev;
+
+ tk->input->keycodesize = sizeof(u16);
+ tk->input->keycodemax = ARRAY_SIZE(tk->codes);
+ tk->input->keycode = tk->codes;
+ tk->codes[0] = KEY_UP;
+ tk->codes[1] = KEY_DOWN;
+ tk->codes[2] = KEY_LEFT;
+ tk->codes[3] = KEY_RIGHT;
+ tk->codes[4] = KEY_ENTER;
+ tk->codes[5] = KEY_WPS_BUTTON;
+ /*
+ * This key appears in the vendor driver, but I have
+ * not been able to activate it.
+ */
+ tk->codes[6] = KEY_RESERVED;
+
+ __set_bit(EV_KEY, tk->input->evbit);
+ for (i = 0; i < ARRAY_SIZE(tk->codes); i++)
+ __set_bit(tk->codes[i], tk->input->keybit);
+ __clear_bit(KEY_RESERVED, tk->input->keybit);
+
+ tk->input->name = "D-Link DIR-685 touchkeys";
+ tk->input->id.bustype = BUS_I2C;
+
+ err = input_register_device(tk->input);
+ if (err)
+ return err;
+
+ /* Set the brightness to max level */
+ err = i2c_master_send(client, bl_data, sizeof(bl_data));
+ if (err != sizeof(bl_data))
+ dev_warn(tk->dev, "error setting brightness level\n");
+
+ if (!client->irq) {
+ dev_err(dev, "no IRQ on the I2C device\n");
+ return -ENODEV;
+ }
+ err = devm_request_threaded_irq(dev, client->irq,
+ NULL, dir685_tk_irq_thread,
+ IRQF_ONESHOT,
+ "dir685-tk", tk);
+ if (err) {
+ dev_err(dev, "can't request IRQ\n");
+ return err;
+ }
+
+ return 0;
+}
+
+static const struct i2c_device_id dir685_tk_id[] = {
+ { .name = "dir685tk" },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, dir685_tk_id);
+
+#ifdef CONFIG_OF
+static const struct of_device_id dir685_tk_of_match[] = {
+ { .compatible = "dlink,dir685-touchkeys" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, dir685_tk_of_match);
+#endif
+
+static struct i2c_driver dir685_tk_i2c_driver = {
+ .driver = {
+ .name = "dlink-dir685-touchkeys",
+ .of_match_table = of_match_ptr(dir685_tk_of_match),
+ },
+ .probe = dir685_tk_probe,
+ .id_table = dir685_tk_id,
+};
+module_i2c_driver(dir685_tk_i2c_driver);
+
+MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
+MODULE_DESCRIPTION("D-Link DIR-685 touchkeys driver");
+MODULE_LICENSE("GPL");