Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp864447ybb; Sat, 28 Mar 2020 12:01:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs4gSgQDinkRAA4j/vZCbdUje5oH+4HBKeuYmWJIqVYU45/0q4vvczUck6ChvUbOkpU7RbN X-Received: by 2002:a9d:6354:: with SMTP id y20mr3569110otk.171.1585422086529; Sat, 28 Mar 2020 12:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585422086; cv=none; d=google.com; s=arc-20160816; b=KkZ6EInvXZHIPLhZKvtqewErXV2UrRf3Aqg1hKNgWoQ8wzwwHgcLoQut1wpFzPUxy/ wJvFq6ujFS+VH0wZJlNPkG2eukAg17suizdp2z6rx9C2JTwMaVXX4U7JOKK6yJ8H+qTI cKr4f/agwlYoGHT8LIa0osJ0b34KvcDjoNqjAM79Tn2CHVyzYMaHNgIcay6hqVGyXJIY jH/HvYoZb9hnrSx+6b7Vt/wXjn0bG+zqicBZguKqcLd7wSopA+uHim7YK5wy2TxKciHq 63BebE+FQTL14XRXPDSH5pWUIPSwJODAP0mPEiSbFrV8xsOvl27QsAD8BDib7UvKnmAu yjfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=OGNXs3NwKjk0dDeSHSXg81YijfbEbudE8mDeHpkOVOE=; b=D6wTgTIc6QdOZTgsR32N2PpzI4YOMQup8WkKRrFT5KeDO4v4rkv7VuxsqQRZglcrVH 9KsS4ZtUQ/0IstZGe2OdpMUGTA3yDJtUcCKOjzjax+82cACqGnF6eL4FvXqd1yGGiKiO e9ZBOCB9Q7UCK27t3Yne9Kf8U3ltUYqpT5ra43YGWG/m1vIbUvQcJxXvCp+auh1kSvJj lDM04D92iboth1t+AoMiJOSn5prpMUmsRrIQQKFh6HoyLdT7AcicNgN5VLRXbvaVDkLz mFucn+Ri9XP3/qJEuabyI4Vo9EjI48SR/usQVsUnY1lsnGYzS0FCzd3MNnMSnxbTu+eg Si8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Sj3kS01e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b17si4224011ook.91.2020.03.28.12.01.13; Sat, 28 Mar 2020 12:01:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Sj3kS01e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbgC1S7f (ORCPT + 99 others); Sat, 28 Mar 2020 14:59:35 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:54371 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbgC1S7d (ORCPT ); Sat, 28 Mar 2020 14:59:33 -0400 Received: by mail-pg1-f202.google.com with SMTP id n6so11032689pgn.21 for ; Sat, 28 Mar 2020 11:59:32 -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=OGNXs3NwKjk0dDeSHSXg81YijfbEbudE8mDeHpkOVOE=; b=Sj3kS01eYr5WT4Fc1GvJ9Y3z7uu2N1FDeotd7kk6k8/7QydjsRgg7y84YBxLjH/5px Ja3168nhkht1ak+6owEmdvZ08ApoeSJby75xk4dDbRLESLOVZEpdwlNibYYRZQQVR8UD AailkVpZN+syYaACa2t7ZUmwNSo67n4iSXI6fsCP6dF7GaFSttHKThBML1fByuRpO8cX nuzAJhnN2SdaZDERJ9Hgi8AUVbkgX0onXkY2nklQcYdw4djr2Ql11NDBNULzqIisWuOg SPsyx5uT6uX9ed7pM+D7tbmKQjvbQICjbFQ8LwFFQF3x+vA/VV3VuIV5vBMFqV7vdPs/ edyw== 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=OGNXs3NwKjk0dDeSHSXg81YijfbEbudE8mDeHpkOVOE=; b=NNPie537sIPs7IJ4KEDF79qll/MSIPU62O16DT5wMMxYJc9RQwqMtLbS7oNuVTJzOF RmEUG8iaNB1wUefGj7FRjhjTK4muznlHywRm7jD+4IzCq/Pd6y/FZh53kjAGL4Z0HvEK hfyjtA6yaBMRyDNQDSkFMTKBq25OHtdlL+6lwBx2o9kBPL1UkyezmitymL5hecx503c/ vXoKIGXtlv1ETdWCVlDu+5IGxW6MgeRbFECaZBVWjUxAS9MyCxrYBPXK+SFpGERkQMoc Gc3H0Z7JYlkTlD4cRomN+9jvDH2ZnFWpSpfw0NXpPuwkqr/OXnmgobmyT26shl1eIUCn mOsw== X-Gm-Message-State: ANhLgQ2BWKt1bSKhPtzqsi/xHBqaGFpz9H9/OXb9kBqi7xKY0ZeNcNc/ Mfu/KaKQNGgRnOwbDOwBBBQl763Dswlu X-Received: by 2002:a63:6d43:: with SMTP id i64mr5379169pgc.201.1585421972254; Sat, 28 Mar 2020 11:59:32 -0700 (PDT) Date: Sat, 28 Mar 2020 11:59:15 -0700 In-Reply-To: <20200328185916.98423-1-rajatja@google.com> Message-Id: <20200328185916.98423-4-rajatja@google.com> Mime-Version: 1.0 References: <20200328185916.98423-1-rajatja@google.com> X-Mailer: git-send-email 2.26.0.rc2.310.g2932bb562d-goog Subject: [PATCH v4 4/5] 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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 3b20aba1861cd..3379fb5e7169b 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); } + } /* -- 2.26.0.rc2.310.g2932bb562d-goog