Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793795195; b=JtRbPiLmjwt7ykKqrPUNhA+Tx2t2Js/CMS73oMt/GPmxmYluNhQHdaotkOM1OzAYorIa a/WGdoh0XkNJ5ndlvUc2Z3UB5msoA7RSuHsnDu/KNI19oIeOA2FOZTfEKBgcqpPAxpLhP U6wGcOQb+s0Jin3AyB3DZ+rX9vjDH9zSXfugX2QAaIHf7aRxY2lvWOJzJSalma3aP4e0p DwJk/Fn9Wsemd/niQ/hqw8Zpri8zuif1kTneFoN/H3VK7XLaKxQQj4H2r6eeu2i3Zy07B aNt0RoxqHSDqPBme0grv80mdXOPnQQJBDQyyrJ/8sqyWqhlNuL9LmyAV55vtdQChG8A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793795195; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=ZrqYmFboseaWvyfG7gkwsiYJ19YZHfBqxK9w3RRraM0=; b=js4FhvSplwcGgKfu6Uh+mdPtuF6HpPzSEhs03FeTEfFSd26yngBIWjtZ99jp6k6ajSQ2 gTX38V8YprPaUmhhC83KO7lhIAD5m8cmwt6eQ3pIPQeqUYA5tXcyFaCGDq/v0hQ1gOV0J vkBtBuw2zxIFyHce06ZHDBaZvrxej2kJCRoKs28KuYxm+eiQjPkBltMViT30upTI/2gPo 9h1a5PUs/EB1Cr1E+rEboMM1QlDzU2mVUq9140jHDH+stUSq69cCVdLjeOShVge0ysEdn uPaPyru6ovqGoYmlbhZRIMB1mS+T3/jkrtbH/0WPsFxadTBOd6q5Vckde/qt9YfiYOA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0fsrhQFl; arc=none smtp.remote-ip=209.85.221.49 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF1CC606EE92 for ; Wed, 4 Nov 2026 12:26:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CF1CC606EE92 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0fsrhQFl Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-48e3b22e971so323011f8f.0 for ; Wed, 04 Nov 2026 04:26:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793795193; x=1794399993; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ZrqYmFboseaWvyfG7gkwsiYJ19YZHfBqxK9w3RRraM0=; b=0fsrhQFlHNe2dyMAfTb9BQT9b3x/mmwIHn3FdwVoZmg7CJ9hFyIvSgdTCpZNoRzx/D BhhLO50OeSr0Q5h5QB2VItHYe3vzmkg/REA4sfo9sdvhcoAaEs0xZSjG+1r0+V2OvZVj kZ+Ul0eJ4D4C0Z9njF1Ho5HUM3CFWNZQZviF9P4FcQSDxaoeNrZTrF5/dfG8AMPbpAcP EK06LJ/70AONmf5TDaY2A/74yFnUydVOHm3iqVS5y8HUXKEQ97cVGlQ6hMtvz4RmtvPt H1wqrk6bMZYAi4/WXMQYyWMzWLGQbe3f6v6WJ+Vlz9t6Lh1UgtWA/r7VN0QIFpKGqYtj jtGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793795193; x=1794399993; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ZrqYmFboseaWvyfG7gkwsiYJ19YZHfBqxK9w3RRraM0=; b=tXRapIYymmsAA3SzPla299LSIEGriprAKk/DiOx8s5jqaAc2dwjxNFf44pMufvP+wD 1i+9oue0Po9e83yDh4dKiI3FHgW3vDBInv3vHzgM3c23SORRz6Ev0A7wWP80IBIMeGWW XYcTz1LBkQ7GkxTqlpgV1i0hxych745/2F7lElrmEX0rtvvfaBHaykmTFw8HthJzEyCx xioVpbIKeY7kgfVm5Mv4wBtRfNJxd0ije7Z+/xNeHnIegfFa2QdjkbYZMgpI/94WZ4fH i2C0xwPhtK9EsK/worA3gXEQO1aL68qYJv0E9EAib2NPGnJTy8JxuNUZxzu1MYUP/sBL 5wBA== X-Gm-Message-State: APuU4Z+B7NyhOHnLB3jGjST3u2p9N/ZLVloPpR8P0g0uQJJIgqzV332Z m71GQ2HYsOXOMBolGpIqMI2z4Hgjh4rINr0qucJkgxu3NvWqiMDAlg1Z X-Gm-Gg: AYBFou1eCLqUYQYUEvxPYPvKhUYIMD+yxzzybm3bl9GdsN5+E0QchUXNADFSgVM8dO8 8NGobyAW/3bhkfXXhSAY8J8rkEB6Yq1Ft2Bj/eWVyp5YLrbM00mwok/64Bh/UwFi7mHWTNYUP6z ifCa5G4Nus0pBj4hrs1olZBZFrhg3sjjg2OR8y+3Ai9YzYP12q0bCRzz2zllifwR+49dHFrQeyA AXxqPahiKrIbs7154RWRC0F+jjRJRTnLrM6b0D31RpxIySLXMiewh3KKXnEbWkvhvZ78YQE+Pne c5vXdoU+RTtodX78fZg9NvwhAr9SaKWhleL2hyOGt+C42mSjTqYxKzdJCaUge7G8fLjCj4/gOJz AILPGWQ/lVtP3Pntx93BMnSumi9Wf3x/zPCMxT+pBNXNztfaiwib6LwzRpU9AgkP3aXkxncjnGe s7aqqrT6x7S89pM22KO2WXD7PdASkcPF8drPd1y4oG3MkIAFSQHFkEDADK9kQHrIcTa/uFzK/ui tJVaAWaEox+nASUGrWKdquq6fv2EC+45vD+VRe2tHlWbeTCVmZEeW0HAZYHKSiw7yBsiEFqYkmY Q8KrUFEq5bn4moh/bxCPyBcYKOmEsK/zhCGOJo9kVXOq2Zh/UA== X-Received: by 2002:a05:600c:a012:b0:49f:fd2d:23c7 with SMTP id 5b1f17b1804b1-4ac17b2ce18mr354317305e9.27.1793795193089; Wed, 04 Nov 2026 04:26:33 -0800 (PST) Received: from xeon ([188.163.112.62]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4b43da9825bsm50492415e9.15.2026.11.04.04.26.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2026 04:26:31 -0800 (PST) From: Svyatoslav Ryhel To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Dmitry Torokhov , Lee Jones , Pavel Machek , Griffin Kroah-Hartman , Sebastian Reichel , Svyatoslav Ryhel , Ion Agorria , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Florian Krischer Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, mfd@lists.linux.dev, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v13 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys Date: Wed, 4 Nov 2026 14:26:03 +0200 Message-ID: <20261104122606.215629-5-clamor95@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261104122606.215629-1-clamor95@gmail.com> References: <20261104122606.215629-1-clamor95@gmail.com> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Michał Mirosław Add support for multimedia top button row of ASUS Transformer's Mobile Dock keyboard. Driver is made that function keys (F1-F12) are used by default which suits average Linux use better and with pressing ScreenLock + AltGr function keys layout is switched to multimedia keys. Only Dock keyboard input events are tracked for AltGr pressing. Co-developed-by: Ion Agorria Signed-off-by: Ion Agorria Signed-off-by: Michał Mirosław Acked-by: Dmitry Torokhov Signed-off-by: Svyatoslav Ryhel --- drivers/input/keyboard/Kconfig | 10 + drivers/input/keyboard/Makefile | 1 + .../input/keyboard/asus-transformer-ec-keys.c | 216 ++++++++++++++++++ 3 files changed, 227 insertions(+) create mode 100644 drivers/input/keyboard/asus-transformer-ec-keys.c diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index d8c64f333462c..728bc068667e7 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -89,6 +89,16 @@ config KEYBOARD_APPLESPI To compile this driver as a module, choose M here: the module will be called applespi. +config KEYBOARD_ASUS_TRANSFORMER_EC + tristate "Asus Transformer's Mobile Dock multimedia keys" + depends on MFD_ASUS_TRANSFORMER_EC + help + Say Y here if you want to use multimedia keys present on Asus + Transformer's Mobile Dock. + + To compile this driver as a module, choose M here: the + module will be called asus-transformer-ec-keys. + config KEYBOARD_ATARI tristate "Atari keyboard" depends on ATARI diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 60bb7baf802f7..0d81096887ada 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_KEYBOARD_ADP5585) += adp5585-keys.o obj-$(CONFIG_KEYBOARD_ADP5588) += adp5588-keys.o obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o obj-$(CONFIG_KEYBOARD_APPLESPI) += applespi.o +obj-$(CONFIG_KEYBOARD_ASUS_TRANSFORMER_EC) += asus-transformer-ec-keys.o obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o obj-$(CONFIG_KEYBOARD_BCM) += bcm-keypad.o diff --git a/drivers/input/keyboard/asus-transformer-ec-keys.c b/drivers/input/keyboard/asus-transformer-ec-keys.c new file mode 100644 index 0000000000000..5a8fb86a97555 --- /dev/null +++ b/drivers/input/keyboard/asus-transformer-ec-keys.c @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include +#include +#include +#include + +#define ASUSEC_EXT_KEY_CODES 0x20 + +struct asus_ec_keys_data { + struct notifier_block nb; + struct asusec_core *ec; + struct input_dev *xidev; + unsigned short keymap[ASUSEC_EXT_KEY_CODES * 2]; + bool special_key_mode; +}; + +static const unsigned short asus_ec_dock_ext_keys[] = { + /* Function keys [0x00 - 0x19] */ + [0x01] = KEY_DELETE, + [0x02] = KEY_F1, + [0x03] = KEY_F2, + [0x04] = KEY_F3, + [0x05] = KEY_F4, + [0x06] = KEY_F5, + [0x07] = KEY_F6, + [0x08] = KEY_F7, + [0x10] = KEY_F8, + [0x11] = KEY_F9, + [0x12] = KEY_F10, + [0x13] = KEY_F11, + [0x14] = KEY_F12, + [0x15] = KEY_MUTE, + [0x16] = KEY_VOLUMEDOWN, + [0x17] = KEY_VOLUMEUP, + /* Multimedia keys [0x20 - 0x39] */ + [0x21] = KEY_SCREENLOCK, + [0x22] = KEY_WLAN, + [0x23] = KEY_BLUETOOTH, + [0x24] = KEY_TOUCHPAD_TOGGLE, + [0x25] = KEY_BRIGHTNESSDOWN, + [0x26] = KEY_BRIGHTNESSUP, + [0x27] = KEY_BRIGHTNESS_AUTO, + [0x28] = KEY_PRINT, + [0x30] = KEY_WWW, + [0x31] = KEY_CONFIG, + [0x32] = KEY_PREVIOUSSONG, + [0x33] = KEY_PLAYPAUSE, + [0x34] = KEY_NEXTSONG, + [0x35] = KEY_MUTE, + [0x36] = KEY_VOLUMEDOWN, + [0x37] = KEY_VOLUMEUP, +}; + +static void asus_ec_keys_report_key(struct input_dev *dev, unsigned int code, + unsigned int key, bool value) +{ + input_event(dev, EV_MSC, MSC_SCAN, code); + input_report_key(dev, key, value); + input_sync(dev); +} + +static int asus_ec_keys_process_key(struct input_dev *dev, u8 code) +{ + struct asus_ec_keys_data *priv = dev_get_drvdata(dev->dev.parent); + unsigned int key = 0; + + if (code == 0) + return NOTIFY_DONE; + + if (priv->ec->right_alt_pressed) { + priv->ec->special_combo_triggered = true; + + /* Flip special key mode state when pressing SCREEN LOCK + R ALT */ + if (code == 1) { + priv->special_key_mode = !priv->special_key_mode; + return NOTIFY_OK; + } + } + + /* + * Relocate code to second "page" if pressed state XOR's mode state + * This way special key will invert the current mode + */ + if (priv->special_key_mode ^ priv->ec->right_alt_pressed) + code += ASUSEC_EXT_KEY_CODES; + + if (code < dev->keycodemax) { + unsigned short *map = dev->keycode; + + key = map[code]; + } + + if (!key) + key = KEY_UNKNOWN; + + asus_ec_keys_report_key(dev, code, key, 1); + asus_ec_keys_report_key(dev, code, key, 0); + + return NOTIFY_OK; +} + +static int asus_ec_keys_notify(struct notifier_block *nb, unsigned long action, void *data_) +{ + struct asus_ec_keys_data *priv = + container_of(nb, struct asus_ec_keys_data, nb); + u8 *data = data_; + + if (action & ASUSEC_SMI_MASK) + return NOTIFY_DONE; + + if (action & ASUSEC_SCI_MASK) + return asus_ec_keys_process_key(priv->xidev, data[2]); + + return NOTIFY_DONE; +} + +static void asus_ec_keys_setup_keymap(struct asus_ec_keys_data *priv) +{ + struct input_dev *dev = priv->xidev; + unsigned int i; + + BUILD_BUG_ON(ARRAY_SIZE(priv->keymap) < ARRAY_SIZE(asus_ec_dock_ext_keys)); + + dev->keycode = priv->keymap; + dev->keycodesize = sizeof(*priv->keymap); + dev->keycodemax = ARRAY_SIZE(priv->keymap); + + input_set_capability(dev, EV_MSC, MSC_SCAN); + input_set_capability(dev, EV_KEY, KEY_UNKNOWN); + + for (i = 0; i < ARRAY_SIZE(asus_ec_dock_ext_keys); i++) { + unsigned int code = asus_ec_dock_ext_keys[i]; + + __set_bit(code, dev->keybit); + priv->keymap[i] = code; + } +} + +static int asus_ec_keys_open(struct input_dev *input) +{ + struct asus_ec_keys_data *priv = input_get_drvdata(input); + struct asusec_core *ec = priv->ec; + int error; + + priv->nb.notifier_call = asus_ec_keys_notify; + error = blocking_notifier_chain_register(&ec->notify_list, &priv->nb); + if (error) + return error; + + ec->ext_keys_enabled = true; + + return 0; +} + +static void asus_ec_keys_close(struct input_dev *input) +{ + struct asus_ec_keys_data *priv = input_get_drvdata(input); + struct asusec_core *ec = priv->ec; + + ec->ext_keys_enabled = false; + blocking_notifier_chain_unregister(&ec->notify_list, &priv->nb); +} + +static int asus_ec_keys_probe(struct platform_device *pdev) +{ + struct i2c_client *parent = to_i2c_client(pdev->dev.parent); + struct asusec_core *ec = dev_get_drvdata(pdev->dev.parent); + struct device *dev = &pdev->dev; + struct asus_ec_keys_data *priv; + int error; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + platform_set_drvdata(pdev, priv); + priv->ec = ec; + + priv->xidev = devm_input_allocate_device(dev); + if (!priv->xidev) + return -ENOMEM; + + priv->xidev->name = devm_kasprintf(dev, GFP_KERNEL, "%s Keyboard Ext", ec->model); + priv->xidev->phys = devm_kasprintf(dev, GFP_KERNEL, "i2c-%u-%04x", + i2c_adapter_id(parent->adapter), parent->addr); + + if (!priv->xidev->name || !priv->xidev->phys) + return -ENOMEM; + + priv->xidev->open = asus_ec_keys_open; + priv->xidev->close = asus_ec_keys_close; + input_set_drvdata(priv->xidev, priv); + + asus_ec_keys_setup_keymap(priv); + + error = input_register_device(priv->xidev); + if (error) + return dev_err_probe(dev, error, "Failed to register extension keys\n"); + + return 0; +} + +static struct platform_driver asus_ec_keys_driver = { + .driver.name = "asus-transformer-ec-keys", + .probe = asus_ec_keys_probe, +}; +module_platform_driver(asus_ec_keys_driver); + +MODULE_ALIAS("platform:asus-transformer-ec-keys"); +MODULE_AUTHOR("Michał Mirosław "); +MODULE_DESCRIPTION("ASUS Transformer's multimedia keys driver"); +MODULE_LICENSE("GPL"); -- 2.53.0