Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3332516ybz; Mon, 27 Apr 2020 14:08:21 -0700 (PDT) X-Google-Smtp-Source: APiQypLVFAOehjDbWwv0faTtlEXkVtpKiCxWSzxgttdwqUKba7aYWizbZ88sx/781Y6h1sGG+mMy X-Received: by 2002:a17:906:3048:: with SMTP id d8mr21576973ejd.97.1588021701616; Mon, 27 Apr 2020 14:08:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588021701; cv=none; d=google.com; s=arc-20160816; b=rljGxnLWwaG453CWEo4yKoIUIo4IvN7lze8Mb+4NohyuH9Y0xm7F49zdYmv85NdW9B n9hNsqX2je9amrPLCykgeuVtyrzDWfqav9VIFdG1RVHHruqHTttuD2j6XQnOCUhH+prp m352EzRaapA/LyP26M/UZLBSm/wD+zQiPZsl2LXLcKRRTyMw7imjAr02mkTXmJSxaziz SPq5et98LdiwcqR5F1dmICXOW+CLVG6nhp2OAalUVQs/9Iffy9FNv8XnoANbGNJR9qBg fbyiwik5pD1Hho9aXumIi6+7JF8oX2Pi/GhDzcICXvRtz/62cYFUpkZhVYFooVPoowsx 7eLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=FRzDYtIIz0JW+6PZb2zruuBk+QvKYrYZ56R5C7QkFt4=; b=qNN991wga3CKUAL1CH4OwhCjdzCmudOKcdXdwDW5qoMCY/yP4eQXD4VGuRRt1Gpns2 r8nSL2NZ7WDufMz9Ri5S7ELgUWD71Vi9P0Pao+/qZW3JMiB13QlS8AYkfcpycfjWFeWb rSiAEthgzV1bzUy5Kgz/62x5YhxyKZTKwiWkW12MjxccTG6IXR3l0hMrR6xZSl63HmOU 18eAT3wIWt2pBjKxe6E6JFdm9DMtodQRtAPXP2wIoUxr2kfoHRnZFSe/DDLklSDnDruV YpjOdkLN0p/UBEaihQhLKUe/B7bzjO6FGutneSiSCRyDicyikCFRw+MBHClkoRUpTLE1 MlIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Veb/ERmM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id aq1si516937ejc.344.2020.04.27.14.07.57; Mon, 27 Apr 2020 14:08:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Veb/ERmM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726859AbgD0VFA (ORCPT + 99 others); Mon, 27 Apr 2020 17:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726486AbgD0VFA (ORCPT ); Mon, 27 Apr 2020 17:05:00 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88E8CC03C1A8 for ; Mon, 27 Apr 2020 14:04:59 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id e25so19179859ljg.5 for ; Mon, 27 Apr 2020 14:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FRzDYtIIz0JW+6PZb2zruuBk+QvKYrYZ56R5C7QkFt4=; b=Veb/ERmM/Fvq5x+hnKuzFr+Oi2EvWj3JMRKfS5dreGvXGR7HHDRzCltSvz8iL74KVf vvXa7kQbiusaDvTAOk156Mf7hON3TX2a0FzndnVBAxLoFchHk+njI5H4pAE1kRF3vJo9 NexN1jeZjghvsKd2uYooTEC2xo2RIMb7tJyhddQpRSVYJHnyIDBhUWfhvuemKFtWPkyv n+PH/T6Vl0pT7/m/aNwSdWgVFoULgg4DBzPqtfCljbt7hQFJVC+KhAx8/0MD/DpFChAt gnJ5gRLO3ljMyqRBuJAfJwiBuLZqD4q3UecBSDcPrZjGo6g2UuSmLpr+wyuN0e+GOLaF tUyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FRzDYtIIz0JW+6PZb2zruuBk+QvKYrYZ56R5C7QkFt4=; b=EzzluE1peKA3V3tAZ9azAIIyVyi8CK8xrYxcyYAfHNXbidD9AhBD0wM+VAuq8PAp1/ +w+oU23G27Z/C7mZfWVzSlAcvLVK4BkBYv00atkP1br7goKvEpjnlL1RjoZznXgcW/Tp BYpuV3FBhGQCnmhtunwNhtBQcTXCT0Ln5OeSjHdyPpoT1L0J3tKJgYVDY1lyr4XqJxnV ygvuiS32Yoo1TrYOQ/tTCaN/QDLagGF1Vu+pst8Xa1E31FvxJjRYrMmLS5M0xDwZPVi0 sVTT/PuBOPPlvdRnDujq0rquo8f54MbNrERA0wUvuh1+pP7aFl/dHidR9AhRwh+KBVH/ qGMw== X-Gm-Message-State: AGi0PuacYbBZkiDcWuylGo6qbxBEThXgUUPEBa98PSBZVkL61GOSHwLq 8Y2jUF8qpndpfvUxUQP6W1gc43xJSj/HYr53ju5QTw== X-Received: by 2002:a2e:9785:: with SMTP id y5mr14239323lji.66.1588021497399; Mon, 27 Apr 2020 14:04:57 -0700 (PDT) MIME-Version: 1.0 References: <20200328185916.98423-1-rajatja@google.com> <20200328185916.98423-2-rajatja@google.com> <20200424210316.GI125362@dtor-ws> In-Reply-To: <20200424210316.GI125362@dtor-ws> From: Rajat Jain Date: Mon, 27 Apr 2020 14:04:20 -0700 Message-ID: Subject: Re: [PATCH v4 2/5] Input: atkbd: Expose function row physical map to userspace To: Dmitry Torokhov Cc: Dmitry Torokhov , Rob Herring , Mark Rutland , Kate Stewart , Enrico Weigelt , Greg Kroah-Hartman , Thomas Gleixner , Allison Randal , "Rafael J. Wysocki" , Stephen Boyd , linux-input , devicetree@vger.kernel.org, Linux Kernel Mailing List , Furquan Shaikh , Duncan Laurie , Benson Leung , Zentaro Kavanagh , Dominik Behr , Rajat Jain 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 Hi Dmitry, On Fri, Apr 24, 2020 at 2:03 PM Dmitry Torokhov wrote: > > Hi Rajat, > > On Sat, Mar 28, 2020 at 11:59:13AM -0700, Rajat Jain wrote: > > 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 > > --- > > 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..3b20aba1861cd 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; > > + > > + u16 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 += sprintf(buf + size, "%02X ", > > + atkbd->function_row_physmap[i]); > > + size += sprintf(buf + size, "\n"); > > Can we change this to scnprintf() with PAGE_SIZE as the initial limit? Done. > > > + 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_u16(dev, "function-row-physmap"); > > I think for ACPI case it does not matter, but if we ever have device > tree using it, it will lead to less errors if we use u32 as the element > size. Do you mind switching to it? Done and posted the new patchset here: https://patchwork.kernel.org/patch/11513295/ Thanks, Rajat > > > + if (n > 0 && n <= MAX_FUNCTION_ROW_KEYS && > > + !device_property_read_u16_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); > > > > Thanks. > > -- > Dmitry