From patchwork Mon Apr 27 21:02:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 11513291 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BEAA81 for ; Mon, 27 Apr 2020 21:03:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01DBB2075E for ; Mon, 27 Apr 2020 21:03:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uJ3Wv2mn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726602AbgD0VDE (ORCPT ); Mon, 27 Apr 2020 17:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726442AbgD0VDE (ORCPT ); Mon, 27 Apr 2020 17:03:04 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D741EC03C1A8 for ; Mon, 27 Apr 2020 14:03:03 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id e44so21979950qta.9 for ; Mon, 27 Apr 2020 14:03:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=23GGnMwKYvt3Cgj/lhkkh8PS8CBiboCjGVStVTQoV58=; b=uJ3Wv2mn3Q1SH5G5z7pkpeKo+Y1QXqCq3ao34idnjbgsWSe8tTMKo/LZDfBDgSwvJ+ qKgsWq/UV2BvdfWYtfyu24Cylm6N4eRDHTln1it9IJvuHP1ObRvrToKe/rSJ2+l+alvv 9XkvWTgmrq0I6aQPz3sDLhld1zpVDIuSof8GyK70zVpvWSrELmm26BzrCygrOJbhaRDM Fe8NAjYYDc9VLols4zdTrk+lQtU8GmMBjIifckAuIXoWc9YbRChsliWre51Z6BJ02IG9 HbzlR3xAR3wg1ypOCeT+s0AGDNR2lOTapxoHwLqXz782WROtbY/WwoXiRhQBmT6Peh4O pUDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=23GGnMwKYvt3Cgj/lhkkh8PS8CBiboCjGVStVTQoV58=; b=XEwhB+8+0EHkFWL8Gud16Q//fupB7GKUMsFJKnQpmPK1w1uhjNOPkMuInffDPGfsoj xS1mtXrTL35HhlxIDloRgE+1oQx6q45fEgPTH0JVr78WWhF+EQUv1fWJ5NocmCGbIDpL b+sJ4cHLQvbMOu6mcOsmPfc2xL8E/UOej6c9imBlU6OcoPUIW6U7PPHYEz/3vqmb13j9 Iig5SwlZPj1e0ClmQjYGdf8KdGG5acYIqDFTqiAxlMtnzQ+EW1GNSgjpOR11DWy2+Cr4 XPR80NRoaAk8r+GSDc4cFydGF/BdXznmr/rUZL4l1OQfdynwQeZxiYhZjdXxkmZTJDUS Alsg== X-Gm-Message-State: AGi0PuYzhsYZmTjyMmSPRcKlYSIIGwxxeZMgP0wB7CC5KF7XpbuY1sMJ c8Q78B0wSM+ARKxOfKNFP7gUhXyUNZRs X-Google-Smtp-Source: APiQypKahN7ghxLa5ZMhrrRFTqL+QsRn5U1vupwEhsBNUqZHCzWOu1dqTKRMxgn9lK8zEQi9Upg4I8/GRiNS X-Received: by 2002:a0c:f8cf:: with SMTP id h15mr23168133qvo.22.1588021382826; Mon, 27 Apr 2020 14:03:02 -0700 (PDT) Date: Mon, 27 Apr 2020 14:02:57 -0700 Message-Id: <20200427210259.91330-1-rajatja@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog Subject: [PATCH v5 1/3] input/serio/i8042: Attach fwnode to serio i8042 kbd device From: Rajat Jain To: Dmitry Torokhov , dtor@google.com, Rob Herring , Mark Rutland , Rajat Jain , Kate Stewart , Enrico Weigelt , Greg Kroah-Hartman , Thomas Gleixner , Allison Randal , "Rafael J. Wysocki" , Stephen Boyd , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, furquan@google.com, dlaurie@google.com, bleung@google.com, zentaro@google.com, dbehr@google.com Cc: rajatxjain@gmail.com Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Attach the firmware node to the serio i8042 kbd device so that device properties can be passed from the firmware. Signed-off-by: Rajat Jain --- v5: Same as v4 v4: Same as v3 v3: same as v2 v2: Remove the Change-Id from the commit log drivers/input/serio/i8042-x86ia64io.h | 1 + drivers/input/serio/i8042.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h index 08e919dbeb5d1..d0c39426ca2c8 100644 --- a/drivers/input/serio/i8042-x86ia64io.h +++ b/drivers/input/serio/i8042-x86ia64io.h @@ -938,6 +938,7 @@ static int i8042_pnp_kbd_probe(struct pnp_dev *dev, const struct pnp_device_id * } i8042_pnp_id_to_string(dev->id, i8042_kbd_firmware_id, sizeof(i8042_kbd_firmware_id)); + i8042_kbd_fwnode = dev_fwnode(&dev->dev); /* Keyboard ports are always supposed to be wakeup-enabled */ device_set_wakeup_enable(&dev->dev, true); diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c index 20ff2bed3917a..0dddf273afd94 100644 --- a/drivers/input/serio/i8042.c +++ b/drivers/input/serio/i8042.c @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -124,6 +125,7 @@ MODULE_PARM_DESC(unmask_kbd_data, "Unconditional enable (may reveal sensitive da static bool i8042_bypass_aux_irq_test; static char i8042_kbd_firmware_id[128]; static char i8042_aux_firmware_id[128]; +static struct fwnode_handle *i8042_kbd_fwnode; #include "i8042.h" @@ -1335,6 +1337,7 @@ static int __init i8042_create_kbd_port(void) strlcpy(serio->phys, I8042_KBD_PHYS_DESC, sizeof(serio->phys)); strlcpy(serio->firmware_id, i8042_kbd_firmware_id, sizeof(serio->firmware_id)); + set_primary_fwnode(&serio->dev, i8042_kbd_fwnode); port->serio = serio; port->irq = I8042_KBD_IRQ; From patchwork Mon Apr 27 21:02:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 11513295 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7922881 for ; Mon, 27 Apr 2020 21:03:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B7812074F for ; Mon, 27 Apr 2020 21:03:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AUB+XdBR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726853AbgD0VDT (ORCPT ); Mon, 27 Apr 2020 17:03:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726773AbgD0VDG (ORCPT ); Mon, 27 Apr 2020 17:03:06 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADCEDC03C1A7 for ; Mon, 27 Apr 2020 14:03:05 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id m138so15674054ybf.12 for ; Mon, 27 Apr 2020 14:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=gCJ1P7w/B8waJVaF76DkEsZIBFFS53UPC6uYguZ6xnc=; b=AUB+XdBRKt+WboOX/CooIo/ZRHu1AEqIf5unABoym8B0e9Hvj+RoBiXu1dlmygQWS9 LJ2Wjr5zDiif8HnvMUmDVxtvcq/FqDnBBBbvGOP+8taxykMRRZ4pKSNsywLGXWCw431n u8N+rRGE3MURzUKz8Kl2xskf1nsbFz8Nu4Lt7Qi6+wCA0KJHs66v73u4W89shDiDX6kJ Gkb9m6cub+Ocu9cYv7tWPIPMN3HBvNJGt2GnjJpxXyKQq6svDGTA6gU+z/r8fFVUhk4E p4C6zhv6ElvMiCn/KQ2xszTlnK9H/SItb1uMH82b2Pj0Lf56svlS5WEtUCxMfiAJM3gi YpIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gCJ1P7w/B8waJVaF76DkEsZIBFFS53UPC6uYguZ6xnc=; b=WXUTul6ZNgEqz6zuVbUt0G2KUBzP8HmT9zsViebchzYWUMxax0HRwCXHoJbcdA1brL GzNxt2Z9TaJ1Nrk70uvDwZIehOhaYd799dTM9IdCJe78IaUbgPQ8fx/TL+KxIGjdpIxJ fJhR9A+C/OSx721hwX4L+g4qbqjWHua4fjWcV71aTwkpQJ0Q5GTrm84YqTPLBDKVSgah W/R5As37M4UX0jtjnMZRfKvsYqMruZoQiyya3H3G7iH0fQxoPMKecEz+4Cl5X9UQz+RC K5leF4SNTpc8Gw6E+ogqL/r+B+GnCiV6I69ciYQna02pk09GVZhm7tlrq0odNps+mq8E x10A== X-Gm-Message-State: AGi0PuZH5c+dv1ymWd1669I/3RTzNi7t5/sQxg0oEqlAZCEg4/kMuUPM grGQntRDKxQLynOEZpMcglm3tjnZLbRU X-Google-Smtp-Source: APiQypKIn13ROW7cWiMXEvyHycbRrpSGTVkj7EHJxI+D6rDUeiOeqvcPRXkeo8wT3rr53l5hESezBaYdVCI0 X-Received: by 2002:a25:bd6:: with SMTP id 205mr42019760ybl.93.1588021384843; Mon, 27 Apr 2020 14:03:04 -0700 (PDT) Date: Mon, 27 Apr 2020 14:02:58 -0700 In-Reply-To: <20200427210259.91330-1-rajatja@google.com> Message-Id: <20200427210259.91330-2-rajatja@google.com> Mime-Version: 1.0 References: <20200427210259.91330-1-rajatja@google.com> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog Subject: [PATCH v5 2/3] Input: atkbd: Expose function row physical map to userspace From: Rajat Jain To: Dmitry Torokhov , dtor@google.com, Rob Herring , Mark Rutland , Rajat Jain , Kate Stewart , Enrico Weigelt , Greg Kroah-Hartman , Thomas Gleixner , Allison Randal , "Rafael J. Wysocki" , Stephen Boyd , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, furquan@google.com, dlaurie@google.com, bleung@google.com, zentaro@google.com, dbehr@google.com Cc: rajatxjain@gmail.com Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Certain keyboards have their top-row keys intended for actions such as "Browser back", "Browser Refresh", "Fullscreen" etc as their primary mode, thus they will send physical codes for those actions. Further, they don't have a dedicated "Fn" key so don't have the capability to generate function key codes (e.g. F1, F2 etc..). However in this case, if userspace still wants to "synthesize" those function keys using the top row action keys, it needs to know the physical position of the top row keys. (Essentially a mapping between usage codes and a physical location in the top row). This patch enhances the atkbd driver to receive such a mapping from the firmware / device tree, and expose it to userspace in the form of a function-row-physmap attribute. The attribute would be a space separated ordered list of physical codes, for the keys in the function row, in left-to-right order. The attribute will only be present if the kernel knows about such mapping, otherwise the attribute shall not be visible. Signed-off-by: Rajat Jain --- v5: Change the size of each array element from u16 to u32 v4: Same as v3 v3: Change to dev_dbg and remove unecessary error check v2: Remove the Change-Id from the commit log drivers/input/keyboard/atkbd.c | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index 7e3eae54c1926..358e91f8888ff 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c @@ -24,6 +24,7 @@ #include #include #include +#include #define DRIVER_DESC "AT and PS/2 keyboard driver" @@ -63,6 +64,8 @@ static bool atkbd_terminal; module_param_named(terminal, atkbd_terminal, bool, 0); MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard connected via AT/PS2"); +#define MAX_FUNCTION_ROW_KEYS 24 + /* * Scancode to keycode tables. These are just the default setting, and * are loadable via a userland utility. @@ -230,6 +233,9 @@ struct atkbd { /* Serializes reconnect(), attr->set() and event work */ struct mutex mutex; + + u32 function_row_physmap[MAX_FUNCTION_ROW_KEYS]; + int num_function_row_keys; }; /* @@ -283,6 +289,7 @@ static struct device_attribute atkbd_attr_##_name = \ __ATTR(_name, S_IRUGO, atkbd_do_show_##_name, NULL); ATKBD_DEFINE_RO_ATTR(err_count); +ATKBD_DEFINE_RO_ATTR(function_row_physmap); static struct attribute *atkbd_attributes[] = { &atkbd_attr_extra.attr, @@ -292,11 +299,42 @@ static struct attribute *atkbd_attributes[] = { &atkbd_attr_softrepeat.attr, &atkbd_attr_softraw.attr, &atkbd_attr_err_count.attr, + &atkbd_attr_function_row_physmap.attr, NULL }; +static ssize_t atkbd_show_function_row_physmap(struct atkbd *atkbd, char *buf) +{ + ssize_t size = 0; + int i; + + if (!atkbd->num_function_row_keys) + return 0; + + for (i = 0; i < atkbd->num_function_row_keys; i++) + size += scnprintf(buf + size, PAGE_SIZE - size, "%02X ", + atkbd->function_row_physmap[i]); + size += scnprintf(buf + size, PAGE_SIZE - size, "\n"); + return size; +} + +static umode_t atkbd_attr_is_visible(struct kobject *kobj, + struct attribute *attr, int i) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct serio *serio = to_serio_port(dev); + struct atkbd *atkbd = serio_get_drvdata(serio); + + if (attr == &atkbd_attr_function_row_physmap.attr && + !atkbd->num_function_row_keys) + return 0; + + return attr->mode; +} + static struct attribute_group atkbd_attribute_group = { .attrs = atkbd_attributes, + .is_visible = atkbd_attr_is_visible, }; static const unsigned int xl_table[] = { @@ -1121,6 +1159,22 @@ static void atkbd_set_device_attrs(struct atkbd *atkbd) } } +static void atkbd_parse_fwnode_data(struct serio *serio) +{ + struct atkbd *atkbd = serio_get_drvdata(serio); + struct device *dev = &serio->dev; + int n; + + /* Parse "function-row-physmap" property */ + n = device_property_count_u32(dev, "function-row-physmap"); + if (n > 0 && n <= MAX_FUNCTION_ROW_KEYS && + !device_property_read_u32_array(dev, "function-row-physmap", + atkbd->function_row_physmap, n)) { + atkbd->num_function_row_keys = n; + dev_dbg(dev, "FW reported %d function-row key locations\n", n); + } +} + /* * atkbd_connect() is called when the serio module finds an interface * that isn't handled yet by an appropriate device driver. We check if @@ -1184,6 +1238,8 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv) atkbd->id = 0xab00; } + atkbd_parse_fwnode_data(serio); + atkbd_set_keycode_table(atkbd); atkbd_set_device_attrs(atkbd); From patchwork Mon Apr 27 21:02:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 11513293 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D09492C for ; Mon, 27 Apr 2020 21:03:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 353532074F for ; Mon, 27 Apr 2020 21:03:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bcE5NBfZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726817AbgD0VDI (ORCPT ); Mon, 27 Apr 2020 17:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726285AbgD0VDH (ORCPT ); Mon, 27 Apr 2020 17:03:07 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD1CBC03C1A8 for ; Mon, 27 Apr 2020 14:03:07 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id b6so22083814ybo.8 for ; Mon, 27 Apr 2020 14:03:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=UenMHbf1Eki3ulS1NlD3HIa7ITU5SNKYGq9xAbGt/6U=; b=bcE5NBfZAVrzbnAddyWS7c0iVSPd/JwzpbP4QwnsjnVArK/uRRruUd2axsbq+0TnN0 U/Azd5ePJ6WeL8AV44CNCYAkr+v9j1WOgH47+xiMyqeiUQ4LfauJL+KAPLNh/BqF3OaS bhyMRXx1R5FpRY4ZmYwCxumUcHTiLg1KnsCm5CIgy+XQa3EmE94baxY70dFJkBGiUFae V50w7uWX4DEXY33wE7/R2BnFuDb33r/JXiGhqmBpvXfW8QZ5vzxvleX0LBkcTquS4mBU JrlPZO4YLbGLrLkBsk3WtdldLEvqZGfftlIfubPN1vR8ENtZqs2YV+kzcv4kKtGJJl75 MVBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UenMHbf1Eki3ulS1NlD3HIa7ITU5SNKYGq9xAbGt/6U=; b=A7GEgqak76+2E3FX8G2G4b8NeG29cR4UiqRg6OpvFG0xIb9yVgONchJaswgxf7b/T1 M8iL0GS6heDF0vuk0TK/vXEDUd16jpYsTLzFDD2KGtqZfiE9ieEF45JPZpJW22u2//a+ zaWWEtjJ92fwjRSwEtUjo/m2y4AfqusQf3wvPEpeJTfIXPGklJQad7kCain7FkGz3KO7 ujG3KvTASTCdbwPUvgKD2kzewop3jFA83m4atEFia95VGgPQ75XrVAQKAfDtKWLdKxtf XagR0f6QfwsJ3fIZM+bNuncfX27Gs8yP6zTlNolS2FF0juIyGrQ/FXeQyAq2VtuXnPA8 oKDA== X-Gm-Message-State: AGi0PuYdDxTyL37aSRMyhC5jND0Wh2g9qeIdlVzzRE8652mZ0ktCedLz mwRWPqwWgnh8hanOJUys1Z/hNwRZBAls X-Google-Smtp-Source: APiQypLClia/FVip1IDfKvS3pnMgAelhu03KQxqvNpZqioUA8EOBX0jl45LmV2zoIB9uLpQlOd63SxmQVWHi X-Received: by 2002:a25:77d8:: with SMTP id s207mr37260773ybc.47.1588021386893; Mon, 27 Apr 2020 14:03:06 -0700 (PDT) Date: Mon, 27 Apr 2020 14:02:59 -0700 In-Reply-To: <20200427210259.91330-1-rajatja@google.com> Message-Id: <20200427210259.91330-3-rajatja@google.com> Mime-Version: 1.0 References: <20200427210259.91330-1-rajatja@google.com> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog Subject: [PATCH v5 3/3] Input: atkbd: Receive and use physcode->keycode mapping from FW From: Rajat Jain To: Dmitry Torokhov , dtor@google.com, Rob Herring , Mark Rutland , Rajat Jain , Kate Stewart , Enrico Weigelt , Greg Kroah-Hartman , Thomas Gleixner , Allison Randal , "Rafael J. Wysocki" , Stephen Boyd , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, furquan@google.com, dlaurie@google.com, bleung@google.com, zentaro@google.com, dbehr@google.com Cc: rajatxjain@gmail.com Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Allow the firmware to specify the mapping between the physical code and the linux keycode. This takes the form of a "linux,keymap" property which is an array of u32 values, each value specifying mapping for a key. Signed-off-by: Rajat Jain --- v5: Same as v4 v4: Property name "keymap" -> "linux,keymap" v3: Don't save the FW mapping in atkbd device. v2: Remove the Change-Id from the commit log drivers/input/keyboard/atkbd.c | 41 +++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index 358e91f8888ff..9d7594dcc4a47 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c @@ -66,6 +66,9 @@ MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard conne #define MAX_FUNCTION_ROW_KEYS 24 +#define PHYSCODE(keymap) ((keymap >> 16) & 0xFFFF) +#define KEYCODE(keymap) (keymap & 0xFFFF) + /* * Scancode to keycode tables. These are just the default setting, and * are loadable via a userland utility. @@ -1032,6 +1035,38 @@ static unsigned int atkbd_oqo_01plus_scancode_fixup(struct atkbd *atkbd, return code; } +static int atkbd_get_keymap_from_fwnode(struct atkbd *atkbd) +{ + struct device *dev = &atkbd->ps2dev.serio->dev; + int i, n; + u32 *ptr; + u16 physcode, keycode; + + /* Parse "linux,keymap" property */ + n = device_property_count_u32(dev, "linux,keymap"); + if (n <= 0 || n > ATKBD_KEYMAP_SIZE) + return -ENXIO; + + ptr = kcalloc(n, sizeof(u32), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + if (device_property_read_u32_array(dev, "linux,keymap", ptr, n)) { + dev_err(dev, "problem parsing FW keymap property\n"); + kfree(ptr); + return -EINVAL; + } + + memset(atkbd->keycode, 0, sizeof(atkbd->keycode)); + for (i = 0; i < n; i++) { + physcode = PHYSCODE(ptr[i]); + keycode = KEYCODE(ptr[i]); + atkbd->keycode[physcode] = keycode; + } + kfree(ptr); + return 0; +} + /* * atkbd_set_keycode_table() initializes keyboard's keycode table * according to the selected scancode set @@ -1039,13 +1074,16 @@ static unsigned int atkbd_oqo_01plus_scancode_fixup(struct atkbd *atkbd, static void atkbd_set_keycode_table(struct atkbd *atkbd) { + struct device *dev = &atkbd->ps2dev.serio->dev; unsigned int scancode; int i, j; memset(atkbd->keycode, 0, sizeof(atkbd->keycode)); bitmap_zero(atkbd->force_release_mask, ATKBD_KEYMAP_SIZE); - if (atkbd->translated) { + if (!atkbd_get_keymap_from_fwnode(atkbd)) { + dev_dbg(dev, "Using FW keymap\n"); + } else if (atkbd->translated) { for (i = 0; i < 128; i++) { scancode = atkbd_unxlate_table[i]; atkbd->keycode[i] = atkbd_set2_keycode[scancode]; @@ -1173,6 +1211,7 @@ static void atkbd_parse_fwnode_data(struct serio *serio) atkbd->num_function_row_keys = n; dev_dbg(dev, "FW reported %d function-row key locations\n", n); } + } /*