Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4608917pxu; Mon, 21 Dec 2020 17:51:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJy82m3OCx/S7mM49dPjNzPy2gJBknyqLXIYHCIwe6rKlYEnGjwN0AVQ80GMXH1CSgC2IxU0 X-Received: by 2002:aa7:d915:: with SMTP id a21mr18137023edr.251.1608601878352; Mon, 21 Dec 2020 17:51:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608601878; cv=none; d=google.com; s=arc-20160816; b=WVbiO+o6v+M8PwhWGLb1i9ES30wzV5u77ezYq3jy5Bg7Souj90C2NhcXptH3xYMadA qP5WEmoAikZuymGXjptBConL9rNdY80Po9y5UhC8kntwEsjZL96ibod6Y4ywZotYh2lz 8gUFrCV2DoGSu5GC9UMlGJHE33H9eu+rMGn4p3jTOElVmVNOY/yugoHgVOQkqMJhnlAD WlwnIgQ4bri7JcUGCJYNsgteR/vO7TauNImt6TMRauoXcMe5f43bfB1+Y/+WC68Gq5ap sJZ2UoRHkgr3lm3Yr3iyDUMutr3IIsCvIkC6ShigXg5vVAG1F6vQG1BJ/15dk7vL2kCl fK+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=K1LHXBytfI76uJ+Q0fQC7ufBawjIu6kcWpfQ3+EC1Vw=; b=oAveTIwajOG4cYclQZxz5etuN8ApsVh64otYzGiwVbwoM+sq5r0bLx88MmIsiySD0e 7lq3Aocz5xfNwTgHSm6uvK1PapWw8pAG45kAw/HD18+savLXWkvHfl0lbYShOLHa+FK2 jcs+gFi9YAiYYfEHhFxKxXcuASXqwmyEJ13qlQ6qtnssDc9AHTphPWu+idi8fEFsvQqL Onp+Ju202mW8CMfjd7LIpZITxCxHirC1z800B0t7AUxQ3gjnFU0MclfMOiBpsaxYqNze GS6diHyhTr3NzSiJGzToLqJq7CtJubeRSEJwgQ4gwJ+efWiJfmlb08qpF8M8Gq+ghcCj qNVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KaSG8szV; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si10674488eju.355.2020.12.21.17.50.55; Mon, 21 Dec 2020 17:51:18 -0800 (PST) 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=@chromium.org header.s=google header.b=KaSG8szV; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726061AbgLVBtZ (ORCPT + 99 others); Mon, 21 Dec 2020 20:49:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgLVBtY (ORCPT ); Mon, 21 Dec 2020 20:49:24 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7108AC061257 for ; Mon, 21 Dec 2020 17:48:16 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id j1so6607173pld.3 for ; Mon, 21 Dec 2020 17:48:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K1LHXBytfI76uJ+Q0fQC7ufBawjIu6kcWpfQ3+EC1Vw=; b=KaSG8szVWROO86ga8ksTHNDZiv+58qdqkzV5S/UjWri1aHGqK9s8OqpplnuNAiKOPQ znDx/xFcTm8D/MNGGXsxPSmXygXlsazvJMr7DLh4ik3uqFPtKRmPuGRr39bFRwU0wgPk AuqlFycjlF2jpIdEGJpp+oF+3yOg5O/KBwvkU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K1LHXBytfI76uJ+Q0fQC7ufBawjIu6kcWpfQ3+EC1Vw=; b=WvbcbOZF0/pu4SLyysuUW/FwVXvPInfk5nEmB1xrcCw+UytN9SQPAVB3O/x643DDbc YOkg+YxDHvxmyu8pxrx1vGBLdUmgHy4RuEvogsAIwMYyy7SotZwSE6iBgH/qJMEq8o/N Jmns7LmAwpbmwv/bXTWmix7aZscTRVEr91kn1C3JN9kKcKkC6LZxc+B9FItHYeQX/L5K Hnvn9AIjSYbWhvCeP5UPNNnrrtiCT7Rml1HNHx/RK5Tn4/ZQ98QUnLZUm+lCPwnIwAVE /e0R0/UaX8O8oHFXkYXyryVqhT0c0qxHuGsjXb5nLHjhr7uWWnIY8j1YKxBlRyvyeHNC OE/g== X-Gm-Message-State: AOAM532/s1vAWwDqC8kQnHvTByMNUBRPlQgi6sOI+tmfCXh1iTjNi4GY oCfeYwleJ1nbNAiZFXV0jla1XVhhgzz5sg== X-Received: by 2002:a17:902:7205:b029:db:d2d5:fe79 with SMTP id ba5-20020a1709027205b02900dbd2d5fe79mr18880303plb.30.1608601695797; Mon, 21 Dec 2020 17:48:15 -0800 (PST) Received: from philipchen.mtv.corp.google.com ([2620:15c:202:201:a6ae:11ff:fe11:fd59]) by smtp.gmail.com with ESMTPSA id h8sm20164316pjc.2.2020.12.21.17.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 17:48:15 -0800 (PST) From: Philip Chen To: LKML Cc: dtor@chromium.org, swboyd@chromium.org, dianders@chromium.org, rajatja@chromium.org, Philip Chen , Benson Leung , Dmitry Torokhov , Enric Balletbo i Serra , Guenter Roeck , Lee Jones , Rajat Jain , linux-input@vger.kernel.org Subject: [PATCH 3/3] Input: cros-ec-keyb - Expose function row physical map to userspace Date: Mon, 21 Dec 2020 17:47:59 -0800 Message-Id: <20201221174751.3.I48f45bea10c670224ad7429835d1d00da478dc7d@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201221174751.1.I025fb861cd5fa0ef5286b7dce514728e9df7ae74@changeid> References: <20201221174751.1.I025fb861cd5fa0ef5286b7dce514728e9df7ae74@changeid> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The top-row keys in a keyboard usually have dual functionalities. E.g. A function key "F1" is also an action key "Browser back". Therefore, when an application receives an action key code from a top-row key press, the application needs to know how to correlate the action key code with the function key code and do the conversion whenever necessary. Since the userpace already knows the key scanlines (row/column) associated with a received key code. Essentially, the userspace only needs a mapping between the key row/column and the matching physical location in the top row. This patch enhances the cros-ec-keyb driver to create such a mapping and expose it to userspace in the form of a function-row-physmap attribute. The attribute would be a space separated ordered list of row/column codes, for the keys in the function row, in left-to-right order. The attribute will only be present when cros-ec-keyb sends action key codes for the top-row keys, otherwise the attribute shall not be visible. Signed-off-by: Philip Chen --- drivers/input/keyboard/cros_ec_keyb.c | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index c997ec5c5d469..4f2f98bb14663 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -658,6 +658,56 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev) return 0; } +static ssize_t function_row_physmap_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + ssize_t size = 0; + u8 i; + u16 code; + struct cros_ec_keyb *ckdev = dev_get_drvdata(dev); + + if (!ckdev->num_function_row_keys) + return 0; + + for (i = 0; i < ckdev->num_function_row_keys; i++) { + code = MATRIX_SCAN_CODE(top_row_key_pos[i].row, + top_row_key_pos[i].col, + ckdev->row_shift); + size += scnprintf(buf + size, PAGE_SIZE - size, "%02X ", code); + } + size += scnprintf(buf + size, PAGE_SIZE - size, "\n"); + + return size; +} + +static DEVICE_ATTR_RO(function_row_physmap); + +static struct attribute *cros_ec_keyb_attrs[] = { + &dev_attr_function_row_physmap.attr, + NULL, +}; + +static umode_t cros_ec_keyb_attr_is_visible(struct kobject *kobj, + struct attribute *attr, + int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct cros_ec_keyb *ckdev = dev_get_drvdata(dev); + + if (attr == &dev_attr_function_row_physmap.attr && + !ckdev->num_function_row_keys) + return 0; + + return attr->mode; +} + +static const struct attribute_group cros_ec_keyb_attr_group = { + .is_visible = cros_ec_keyb_attr_is_visible, + .attrs = cros_ec_keyb_attrs, +}; + + static int cros_ec_keyb_probe(struct platform_device *pdev) { struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent); @@ -688,6 +738,12 @@ static int cros_ec_keyb_probe(struct platform_device *pdev) return err; } + err = sysfs_create_group(&dev->kobj, &cros_ec_keyb_attr_group); + if (err) { + dev_err(dev, "failed to create attributes. err=%d\n", err); + return err; + } + ckdev->notifier.notifier_call = cros_ec_keyb_work; err = blocking_notifier_chain_register(&ckdev->ec->event_notifier, &ckdev->notifier); @@ -703,6 +759,9 @@ static int cros_ec_keyb_probe(struct platform_device *pdev) static int cros_ec_keyb_remove(struct platform_device *pdev) { struct cros_ec_keyb *ckdev = dev_get_drvdata(&pdev->dev); + struct device *dev = &pdev->dev; + + sysfs_remove_group(&dev->kobj, &cros_ec_keyb_attr_group); blocking_notifier_chain_unregister(&ckdev->ec->event_notifier, &ckdev->notifier); -- 2.26.2