From patchwork Tue Dec 22 01:47:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Chen X-Patchwork-Id: 11985597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82023C433DB for ; Tue, 22 Dec 2020 01:49:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50E0322955 for ; Tue, 22 Dec 2020 01:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725962AbgLVBso (ORCPT ); Mon, 21 Dec 2020 20:48:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbgLVBso (ORCPT ); Mon, 21 Dec 2020 20:48:44 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3728FC0613D3 for ; Mon, 21 Dec 2020 17:48:04 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id x1so1814406pgh.12 for ; Mon, 21 Dec 2020 17:48:04 -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:mime-version :content-transfer-encoding; bh=EDIsemzKxtHAHJzZ7gM2znDYcSMfv5fCVTIAtVLgQq0=; b=XyBE7ix/IGBl2i/qY1H64EnvSZqbuoYHI08Fji/IL0onEa3zvWZKkG0A7t9q0zzwTm /L7+1P8Z8hLmOwcRheSvWcic9wqCI0ApgxaSMoQOSKS7Nc+CUbZSsraWjMT9TBfDUcvh CgFzHvDU6rSUaF8qY8Ah7Yg7IZxQso80+ThTE= 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:mime-version :content-transfer-encoding; bh=EDIsemzKxtHAHJzZ7gM2znDYcSMfv5fCVTIAtVLgQq0=; b=Ho+XXLjVGN4JJlPbRLnwWWzW4mKGbc4xz6ghyvSqEw1enfBJvVEbzzoO4MUwE8rzTR SwNeRRPVnfiRARQeJXLsys+OFumB+vVrrsjK358Wpt3V/lHg3rzsuMKnL3dgYSysB8Wc Zvz7w4yxGlNiErVyu4VqtyxWvxv6Qf3ru1t1KnvYQQeKbLpktyiYc+qDGPhi34/9T7wm 9s0fmV9AqEuIftd2ZOd6vfRbacghzr++6yQrSOBRe7Z9IExiOIt0I9GKGSdiaVQMKjl7 MPgbaKdRsMm/5Rg1jmcyy8BDCsh2Bmp4Ser2HMQodQ0XzriX++97JEzJ14TGnVyqx6Zg wfvw== X-Gm-Message-State: AOAM530TqvnS2d0gzgq1IYy6p4O+3dI3fydHCx7EWVid9rAZqYl8tAQA rWCd4bBSz33hLmbi9p9lv8QjsA== X-Google-Smtp-Source: ABdhPJyeOYYYdWY8GIzSUI6oLRjRJUQjm4MDkpIUwbwPAOv31gexN4eY7F8uUQDeD2+3ET+UKs8uDg== X-Received: by 2002:a62:764a:0:b029:19d:9fa8:5bc6 with SMTP id r71-20020a62764a0000b029019d9fa85bc6mr17274769pfc.76.1608601683803; Mon, 21 Dec 2020 17:48:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 17:48:03 -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 , Rob Herring , Simon Glass , devicetree@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH 1/3] dt-bindings: input: cros-ec-keyb: Add a new property Date: Mon, 21 Dec 2020 17:47:57 -0800 Message-Id: <20201221174751.1.I025fb861cd5fa0ef5286b7dce514728e9df7ae74@changeid> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This patch adds a new property `google,custom-keyb-top-row` to the device tree for the custom keyboard top row design. Signed-off-by: Philip Chen --- .../devicetree/bindings/input/google,cros-ec-keyb.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/input/google,cros-ec-keyb.yaml b/Documentation/devicetree/bindings/input/google,cros-ec-keyb.yaml index 8e50c14a9d778..f105eae1cf445 100644 --- a/Documentation/devicetree/bindings/input/google,cros-ec-keyb.yaml +++ b/Documentation/devicetree/bindings/input/google,cros-ec-keyb.yaml @@ -31,6 +31,13 @@ properties: if the EC does not have its own logic or hardware for this. type: boolean + google,custom-keyb-top-row: + $ref: '/schemas/types.yaml#/definitions/uint16-array' + description: | + An ordered u16 array containing the action keycode values of the function + keys, from left to right. Specified only when the board has a custom + design for the top row keys on the keyboard. + required: - compatible From patchwork Tue Dec 22 01:47:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Chen X-Patchwork-Id: 11985599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C14E4C433E0 for ; Tue, 22 Dec 2020 01:49:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97D4D22955 for ; Tue, 22 Dec 2020 01:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726070AbgLVBss (ORCPT ); Mon, 21 Dec 2020 20:48:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgLVBsr (ORCPT ); Mon, 21 Dec 2020 20:48:47 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C3B4C061282 for ; Mon, 21 Dec 2020 17:48:07 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id t22so7551189pfl.3 for ; Mon, 21 Dec 2020 17:48:07 -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=O9t6b/EdSq28Lw+fWM3V++IKje/SzmyL7ftmGtHYk+M=; b=meFiM90q7IuLgsrTTgMJTxUOJLl3ZDLh0qfjsn1QCJzMocLhnTPjJK0I91rGjVn9gX +MFrguH6C0A77CiGyVwOXWriC0LOfzoVOzATWTUZ6Hadh7oDqNOPFJPiNsIenxKSODFO bKIZ1hNb/SYcYA7iViJw+OQDnsvSzPpQWJIHE= 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=O9t6b/EdSq28Lw+fWM3V++IKje/SzmyL7ftmGtHYk+M=; b=K0xYAbHgoq8GX1tIAd9Et+cixOr0cKrvFy9WUuaiue3XJVfXKpsi9ZcFI+Odojst03 tPFohqE4MLQ7/J18anbgpRMTpl5tac6h0YNruDJUFG3Bz2uqk52xN8Vo+ZA/E/CqDiYo ecHiTulCIlIMjogOIl3Jsz6VOmVciUKTSLVZ0yhhj4GBf+s6OQ92FcyDszDvApODPwzl QMn77/iOAWOE/7Mg4WIGwanU8YoFT1oIxUTog4iTJLhuku5zQD21CzVjAHLyvkED0h9T aX8bGddud1oERpPcnQHR30/E6cbNyZCGiHHifz83L+fAb6ktPaBSv2Qp7f8ZF14Tan4I uWDQ== X-Gm-Message-State: AOAM531OmsR509/ElYQXtXrN4ljRBBzifZ8ip+tIML0E7G3ulBO//CyQ tvtAjdvOEFMMpwFdhCF1Wi86xQ== X-Google-Smtp-Source: ABdhPJxANW1O5zypjQ4Vp0PzOiCYfx2GQ+AuJwfYFxjk9yhY2MeC7Q/OJ/HR3FmPTmnHk75osMtP3A== X-Received: by 2002:a63:5f12:: with SMTP id t18mr17778958pgb.308.1608601687097; Mon, 21 Dec 2020 17:48:07 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 17:48:06 -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 , linux-input@vger.kernel.org Subject: [PATCH 2/3] Input: cros_ec_keyb - Support custom top-row keys Date: Mon, 21 Dec 2020 17:47:58 -0800 Message-Id: <20201221174751.2.If8dc0ec9d1a60e436d1e852eba1316313f45ac0e@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 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The function keys in a keyboard's top row are usually intended for certain actions such as "Browser back" and "Fullscreen". As of now, when a top-row key is pressed, cros_ec_keyb sends function key code (e.g. KEY_F1) instead of action key code (e.g. KEY_BACK) to applications. Because `linux,keymap` defined in cros-ec-keyboard.dtsi maps the scanlines of the top-row keys to the function key code. Therefore, an application can only convert each function key to different action based on a fixed mapping. This patch aims to support a more flexible keyboard top-row design. If a board specifies a custom layout for the top row keys in dt binding, cros_ec_keyb will explicitly sends action key code to applications when any top-row key is pressed, so the applications no longer have to make assumptions. Signed-off-by: Philip Chen --- drivers/input/keyboard/cros_ec_keyb.c | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index b379ed7628781..c997ec5c5d469 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -27,6 +27,34 @@ #include +#define MAX_NUM_TOP_ROW_KEYS 15 + +/* + * Row/column (in the scan matrix) of the function keys (T1-T15) + * defined in Chrome OS keyboard spec + */ +static const struct key_pos { + u8 row; + u8 col; +} top_row_key_pos[] = { + {.row = 0, .col = 2}, /* T1 */ + {.row = 3, .col = 2}, /* T2 */ + {.row = 2, .col = 2}, /* T3 */ + {.row = 1, .col = 2}, /* T4 */ + {.row = 3, .col = 4}, /* T5 */ + {.row = 2, .col = 4}, /* T6 */ + {.row = 1, .col = 4}, /* T7 */ + {.row = 2, .col = 9}, /* T8 */ + {.row = 1, .col = 9}, /* T9 */ + {.row = 0, .col = 4}, /* T10 */ + {.row = 0, .col = 1}, /* T11 */ + {.row = 1, .col = 5}, /* T12 */ + {.row = 3, .col = 5}, /* T13 */ + {.row = 0, .col = 9}, /* T14 */ + {.row = 0, .col = 11}, /* T15 */ +}; +BUILD_ASSERT(ARRAY_SIZE(top_row_key_pos) == MAX_NUM_TOP_ROW_KEYS); + /** * struct cros_ec_keyb - Structure representing EC keyboard device * @@ -42,6 +70,7 @@ * @idev: The input device for the matrix keys. * @bs_idev: The input device for non-matrix buttons and switches (or NULL). * @notifier: interrupt event notifier for transport devices + * @num_function_row_keys: The number of top row keys in a custom keyboard */ struct cros_ec_keyb { unsigned int rows; @@ -58,6 +87,8 @@ struct cros_ec_keyb { struct input_dev *idev; struct input_dev *bs_idev; struct notifier_block notifier; + + uint8_t num_function_row_keys; }; /** @@ -511,6 +542,44 @@ static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev) return 0; } +/** + * cros_ec_keyb_update_custom_keymap + * + * Update the keymap if the board has custom top row keys. + * + * @ckdev: The keyboard device + */ + +static void cros_ec_keyb_update_custom_keymap(struct cros_ec_keyb *ckdev) +{ + u8 i; + u16 code; + u16 top_row_key_code[MAX_NUM_TOP_ROW_KEYS] = {0}; + struct input_dev *idev = ckdev->idev; + unsigned short *keymap = idev->keycode; + + if (of_property_read_variable_u16_array(ckdev->dev->of_node, + "google,custom-keyb-top-row", + top_row_key_code, + 0, + MAX_NUM_TOP_ROW_KEYS) > 0) { + for (i = 0; i < MAX_NUM_TOP_ROW_KEYS; i++) { + if (!top_row_key_code[i]) + break; + code = MATRIX_SCAN_CODE(top_row_key_pos[i].row, + top_row_key_pos[i].col, + ckdev->row_shift); + /* + * Add the action key code for a top row key + * into the keymap. + */ + keymap[code] = top_row_key_code[i]; + __set_bit(keymap[code], idev->keybit); + } + ckdev->num_function_row_keys = i; + } +} + /** * cros_ec_keyb_register_bs - Register matrix keys * @@ -576,6 +645,8 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev) input_set_capability(idev, EV_MSC, MSC_SCAN); input_set_drvdata(idev, ckdev); ckdev->idev = idev; + + cros_ec_keyb_update_custom_keymap(ckdev); cros_ec_keyb_compute_valid_keys(ckdev); err = input_register_device(ckdev->idev); From patchwork Tue Dec 22 01:47:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Chen X-Patchwork-Id: 11985601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCE51C433E0 for ; Tue, 22 Dec 2020 01:49:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A92422A83 for ; Tue, 22 Dec 2020 01:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725807AbgLVBtZ (ORCPT ); Mon, 21 Dec 2020 20:49:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725790AbgLVBtY (ORCPT ); Mon, 21 Dec 2020 20:49:24 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34578C061248 for ; Mon, 21 Dec 2020 17:48:16 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id b8so6613213plx.0 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=VeGCFmZFxqZ2A9+jCO9oSMTnaoxXkWpdaoL3ovvsv9Uw7ywYQrD8K1lTa8zZ3qKv6g wyvI2vljFSkbH/cpk87syWfHpxMRkA443Sd1o+cEhgQ9ghvdXqIm4PAZkY77+Bh7uXRx s4lbhGq+WdwQ+/psY/mFv5vm4lisSn7HXDCvP/1fH4x0Q3uH+UrO5dSi0iztu9SC8jcU qnBT9KjXzI2cjkNMrRxS1wSy2eoNNofnX6yEiD7wJqduHXsiWbe+EAjt0AzIy3g5aV7l Xry3Rk/CWn4TE80f2Zc9ZHlFqmrgujNTohCgmXCKE6FcziQmCHx0HZkA27Q3mFNtMD5C WR7w== X-Gm-Message-State: AOAM530Ui48ycDcVxxrodTP4Lb1RazLBSvrr1PwoQLprOnrMRS8IyANj btoJI1W9KqdISwmCghb4U88MqA== X-Google-Smtp-Source: ABdhPJyBRfxwrU7hAsQuLM8YY5s4JGPgCC4cvg67S94IeDEdWEb7UWWeskQXWQX3HCGIpHEtPhO3HA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-input@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);