From nobody Mon Feb 9 15:26:12 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B2D5329E5A for ; Sun, 1 Feb 2026 10:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769942663; cv=none; b=e6fMdnGkPKl6PKZMa1I9v8QCYyZlTNqKgmnDGgFxrq8SOVjWungs9VOFQ1lw4rWTLkRDcXFgUABg3e5l0vU9p1tnMfbjas9WojE2Zn/ZfOPyTw8PwxS+q1RictN9Bs+kKdMWXmd+GMQiLhKp4cpXFOFqvA2pniEXLxuUcxT6VaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769942663; c=relaxed/simple; bh=3GFKhpWfEd4wx9op/cPLQRg9NIiBv/Np5fjkxtlpOAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mD0CppC8aufpzoZZZ7YDqAOqRhN577W/byDbZMjVthhJrqwXEKDePyrUX68fnNElqrUeT3Eyqcdstw8oJvECqGiih58oLUTPgssrbmo9X7D5gZ2VWCXIEaTNkcRZC1SA0tjMcqHzyngFH4pMbkWJxENd2gLg+zWYetm98oHyans= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Hc7KkNUu; arc=none smtp.client-ip=209.85.128.49 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) header.d=gmail.com header.i=@gmail.com header.b="Hc7KkNUu" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-47ee3a63300so38153995e9.2 for ; Sun, 01 Feb 2026 02:44:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769942658; x=1770547458; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tSm3jMIbP4801iaRvLpNxizE8IF0rCGULRQu9fembFY=; b=Hc7KkNUu8AYpubs78AjdVzEU6ssuUBW/B58xhwNUUXYvxG0IAgnSaviGteRtCC4pGg tEJnBdIbeMqV2EcsYM8EDTF7ebzgZw7oiJDVAgtiCKEN1QNnqdWo/iD5YWPEoIUJI+qt ezaMty+iFXPa3nqywnmKB+EmtRPL4bN8jJntRm01BYhtuNb0X2IVr7T9gYw8R4zTpKYx RknDAMSUsYCM+Oz8h8WQuRMe1IkshHQT55fP9HPetaXabfFLJmf/vwGAB2jc64XhRjtz XwWBQwZEdyoQCewt8y1745OpVH1qmz+rFx0aZowRRWBJ43jNGKb//G0rQamdecZR3BjZ lnhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769942658; x=1770547458; h=content-transfer-encoding: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; bh=tSm3jMIbP4801iaRvLpNxizE8IF0rCGULRQu9fembFY=; b=kAXmslIlNLwJH8EmMmfUh+g73TYv9Gf8zXoqvGWgwPH0Gnm3QyJeeBacNzgPwn61J6 F8AcP5bsZSdU9l7GAU0XbGFuNFwi98jBLT58/Lrdn+xxDE+BNwGYJWn0U1/6NwM7os6f MYw/SMiZIFf8oROHwWB+qiNCZumTomqCxg3koCaxubU6K3AgA/RrJRm/qGvt1hWkGsXa QzAnVD6z12+48ZC4rdvrolce8HBvdWVkj1S8yUttwSl+g2gxRTD00sW4aM5aSf3gB6jD 82bpgxCdf/oV6TMza6zsZTwf1fkSvo7awYobaOACfxBSMHYMZjsvXD3Xi2CiAS71tk0A sHwg== X-Forwarded-Encrypted: i=1; AJvYcCUu9/xLEfeit6zNqLFap2k8fLGXL3OYi89qEmF/6HoFVdCZXdP0FeA1vYiBbd25lPL743YdbmB9NyL9qYI=@vger.kernel.org X-Gm-Message-State: AOJu0YzDWwg5K4erW1Jjth9onbvf4+CR1VCww3bDQTiHPfJ61iJIkq6y h6teAyaT1FmWdsq3mKoUB0+cZoSlfeGXmWJHtI9sMnuQ5U1c5rgI4nzQ X-Gm-Gg: AZuq6aLFpIX3uy83pokSapE/dzZQndFpz2HnRqkkxLt+0KtjHzQDDwAhIQcpb4Zj2js C70vxVpYqLU86QETur9OVltciceQN3+SmcUoLlJdOej8PZUKUjfAgzX7awgQLR+lVsSvZo+XlEe sbM2TDqr9NfXBaNGcv6HIWdf2BDT200Tq3rP6FIfZRpGSV832Je4+U0cRt+5HwfQnBtpaaMPTc4 /QAd8B7fJ9Umv5yBpVlq2tyi9I5+xtnRbfi+LdMglyNzRfqHi92KWnb2QKUgz8KkemXYMoRbbdo ka1twVDRRlpzY3EhGgxAB8AUhneogeb8bLJz7RweldadrmsBS9E/EVlb7Gh/VflQ3peD/nWpjpZ ol+EX/TyDij9tKPIYHDak7yjZ6dabM7jOBu8USCRn1VyD1JYlUxu9UxClNRf2/K4e6ZQ7M47sIc 83 X-Received: by 2002:a05:600c:1f16:b0:47e:e712:aa88 with SMTP id 5b1f17b1804b1-482db4a0bb2mr124686615e9.31.1769942657686; Sun, 01 Feb 2026 02:44:17 -0800 (PST) Received: from xeon ([188.163.112.49]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4806ce56490sm308947455e9.12.2026.02.01.02.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Feb 2026 02:44:17 -0800 (PST) From: Svyatoslav Ryhel To: Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Dmitry Torokhov , Pavel Machek , Arnd Bergmann , Greg Kroah-Hartman , Sebastian Reichel , Svyatoslav Ryhel , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Ion Agorria Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v1 6/9] input: keyboard: Add driver for Asus Transformer dock multimedia keys Date: Sun, 1 Feb 2026 12:43:40 +0200 Message-ID: <20260201104343.79231-7-clamor95@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260201104343.79231-1-clamor95@gmail.com> References: <20260201104343.79231-1-clamor95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Micha=C5=82 Miros=C5=82aw 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. Since this only modifies codes sent by asus-ec-keys it doesn't affect normal keyboards at all. Co-developed-by: Ion Agorria Signed-off-by: Ion Agorria Signed-off-by: Micha=C5=82 Miros=C5=82aw Signed-off-by: Svyatoslav Ryhel --- drivers/input/keyboard/Kconfig | 10 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/asus-ec-keys.c | 285 ++++++++++++++++++++++++++ 3 files changed, 296 insertions(+) create mode 100644 drivers/input/keyboard/asus-ec-keys.c diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 2ff4fef322c2..9eef1ff279c3 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. =20 +config KEYBOARD_ASUSEC + tristate "Asus Transformer Mobile Dock multimedia keys" + depends on MFD_ASUSEC + 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 asusec-ext-keys. + config KEYBOARD_ATARI tristate "Atari keyboard" depends on ATARI diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makef= ile index 2d906e14f3e2..7226aafddf7a 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_KEYBOARD_ADP5585) +=3D adp5585-keys.o obj-$(CONFIG_KEYBOARD_ADP5588) +=3D adp5588-keys.o obj-$(CONFIG_KEYBOARD_AMIGA) +=3D amikbd.o obj-$(CONFIG_KEYBOARD_APPLESPI) +=3D applespi.o +obj-$(CONFIG_KEYBOARD_ASUSEC) +=3D asus-ec-keys.o obj-$(CONFIG_KEYBOARD_ATARI) +=3D atakbd.o obj-$(CONFIG_KEYBOARD_ATKBD) +=3D atkbd.o obj-$(CONFIG_KEYBOARD_BCM) +=3D bcm-keypad.o diff --git a/drivers/input/keyboard/asus-ec-keys.c b/drivers/input/keyboard= /asus-ec-keys.c new file mode 100644 index 000000000000..42365db63bdf --- /dev/null +++ b/drivers/input/keyboard/asus-ec-keys.c @@ -0,0 +1,285 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * ASUS Transformer Pad - multimedia keys + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ASUSEC_EXT_KEY_CODES 0x20 + +struct asus_ec_keys_data { + struct notifier_block nb; + struct asusec_info *ec; + struct input_dev *xidev; + bool special_key_pressed; + bool special_key_mode; + unsigned short keymap[ASUSEC_EXT_KEY_CODES * 2]; +}; + +static void asus_ec_input_event(struct input_handle *handle, + unsigned int event_type, + unsigned int event_code, int value) +{ + struct asus_ec_keys_data *priv =3D handle->handler->private; + + /* Store special key state */ + if (event_type =3D=3D EV_KEY && event_code =3D=3D KEY_RIGHTALT) + priv->special_key_pressed =3D !!value; +} + +static int asus_ec_input_connect(struct input_handler *handler, struct inp= ut_dev *dev, + const struct input_device_id *id) +{ + struct input_handle *handle; + int error; + + handle =3D kzalloc(sizeof(*handle), GFP_KERNEL); + if (!handle) + return -ENOMEM; + + handle->dev =3D dev; + handle->handler =3D handler; + handle->name =3D "asusec-media-handler"; + + error =3D input_register_handle(handle); + if (error) + goto err_free_handle; + + error =3D input_open_device(handle); + if (error) + goto err_unregister_handle; + + return 0; + + err_unregister_handle: + input_unregister_handle(handle); + err_free_handle: + kfree(handle); + + return error; +} + +static void asus_ec_input_disconnect(struct input_handle *handle) +{ + input_close_device(handle); + input_unregister_handle(handle); + kfree(handle); +} + +static const struct input_device_id asus_ec_input_ids[] =3D { + { + .flags =3D INPUT_DEVICE_ID_MATCH_EVBIT, + .evbit =3D { BIT_MASK(EV_KEY) }, + }, + { } +}; + +static struct input_handler asus_ec_input_handler =3D { + .name =3D "asusec-media-handler", + .event =3D asus_ec_input_event, + .connect =3D asus_ec_input_connect, + .disconnect =3D asus_ec_input_disconnect, + .id_table =3D asus_ec_input_ids, +}; + +static const unsigned short asus_ec_dock_ext_keys[] =3D { + /* Function keys [0x00 - 0x19] */ + [0x01] =3D KEY_DELETE, + [0x02] =3D KEY_F1, + [0x03] =3D KEY_F2, + [0x04] =3D KEY_F3, + [0x05] =3D KEY_F4, + [0x06] =3D KEY_F5, + [0x07] =3D KEY_F6, + [0x08] =3D KEY_F7, + [0x10] =3D KEY_F8, + [0x11] =3D KEY_F9, + [0x12] =3D KEY_F10, + [0x13] =3D KEY_F11, + [0x14] =3D KEY_F12, + [0x15] =3D KEY_MUTE, + [0x16] =3D KEY_VOLUMEDOWN, + [0x17] =3D KEY_VOLUMEUP, + /* Multimedia keys [0x20 - 0x39] */ + [0x21] =3D KEY_SCREENLOCK, + [0x22] =3D KEY_WLAN, + [0x23] =3D KEY_BLUETOOTH, + [0x24] =3D KEY_TOUCHPAD_TOGGLE, + [0x25] =3D KEY_BRIGHTNESSDOWN, + [0x26] =3D KEY_BRIGHTNESSUP, + [0x27] =3D KEY_BRIGHTNESS_AUTO, + [0x28] =3D KEY_PRINT, + [0x30] =3D KEY_WWW, + [0x31] =3D KEY_CONFIG, + [0x32] =3D KEY_PREVIOUSSONG, + [0x33] =3D KEY_PLAYPAUSE, + [0x34] =3D KEY_NEXTSONG, + [0x35] =3D KEY_MUTE, + [0x36] =3D KEY_VOLUMEDOWN, + [0x37] =3D KEY_VOLUMEUP, +}; + +static void asus_ec_keys_report_key(struct input_dev *dev, unsigned int co= de, + 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 =3D dev_get_drvdata(dev->dev.parent); + unsigned int key =3D 0; + + if (code =3D=3D 0) + return NOTIFY_DONE; + + /* Flip special key mode state when pressing key 1 with special key press= ed */ + if (priv->special_key_pressed && code =3D=3D 1) { + priv->special_key_mode =3D !priv->special_key_mode; + return NOTIFY_DONE; + } + + /* + * 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->special_key_pressed) + code +=3D ASUSEC_EXT_KEY_CODES; + + if (code < dev->keycodemax) { + unsigned short *map =3D dev->keycode; + + key =3D map[code]; + } + + if (!key) + key =3D 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 =3D container_of(nb, struct asus_ec_keys_d= ata, nb); + u8 *data =3D 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 =3D priv->xidev; + unsigned int i; + + BUILD_BUG_ON(ARRAY_SIZE(priv->keymap) < ARRAY_SIZE(asus_ec_dock_ext_keys)= ); + + dev->keycode =3D priv->keymap; + dev->keycodesize =3D sizeof(*priv->keymap); + dev->keycodemax =3D ARRAY_SIZE(priv->keymap); + + input_set_capability(dev, EV_MSC, MSC_SCAN); + input_set_capability(dev, EV_KEY, KEY_UNKNOWN); + + for (i =3D 0; i < ARRAY_SIZE(asus_ec_dock_ext_keys); i++) { + unsigned int code =3D asus_ec_dock_ext_keys[i]; + + if (!code) + continue; + + __set_bit(code, dev->keybit); + priv->keymap[i] =3D code; + } +} + +static void asus_ec_input_handler_deregister(void *priv) +{ + input_unregister_handler(&asus_ec_input_handler); +} + +static int asus_ec_keys_probe(struct platform_device *pdev) +{ + struct asusec_info *ec =3D cell_to_ec(pdev); + struct i2c_client *parent =3D to_i2c_client(pdev->dev.parent); + struct asus_ec_keys_data *priv; + int ret; + + priv =3D devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + platform_set_drvdata(pdev, priv); + priv->ec =3D ec; + + priv->xidev =3D devm_input_allocate_device(&pdev->dev); + if (!priv->xidev) + return -ENOMEM; + + priv->xidev->name =3D devm_kasprintf(&pdev->dev, GFP_KERNEL, + "%s Keyboard Ext", ec->model); + priv->xidev->phys =3D devm_kasprintf(&pdev->dev, GFP_KERNEL, + "i2c-%u-%04x", + i2c_adapter_id(parent->adapter), + parent->addr); + asus_ec_keys_setup_keymap(priv); + + ret =3D input_register_device(priv->xidev); + if (ret < 0) { + dev_err(&pdev->dev, "failed to register extension keys: %d\n", + ret); + return ret; + } + + asus_ec_input_handler.private =3D priv; + + ret =3D input_register_handler(&asus_ec_input_handler); + if (ret) + return ret; + + ret =3D devm_add_action_or_reset(&pdev->dev, asus_ec_input_handler_deregi= ster, + priv); + if (ret) + return ret; + + priv->nb.notifier_call =3D asus_ec_keys_notify; + + return devm_asus_ec_register_notifier(pdev, &priv->nb); +} + +static const struct of_device_id asus_ec_keys_match[] =3D { + { .compatible =3D "asus,ec-keys" }, + { } +}; +MODULE_DEVICE_TABLE(of, asus_ec_keys_match); + +static struct platform_driver asus_ec_keys_driver =3D { + .driver =3D { + .name =3D "asus-ec-keys", + .of_match_table =3D asus_ec_keys_match, + }, + .probe =3D asus_ec_keys_probe, +}; +module_platform_driver(asus_ec_keys_driver); + +MODULE_AUTHOR("Micha=C5=82 Miros=C5=82aw "); +MODULE_DESCRIPTION("ASUS Transformer's multimedia keys driver"); +MODULE_LICENSE("GPL"); --=20 2.51.0