From patchwork Thu May 26 23:12:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 12862893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58DD4C433FE for ; Thu, 26 May 2022 23:12:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349431AbiEZXMi (ORCPT ); Thu, 26 May 2022 19:12:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237020AbiEZXMh (ORCPT ); Thu, 26 May 2022 19:12:37 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3A00E5292; Thu, 26 May 2022 16:12:34 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id y189so2901872pfy.10; Thu, 26 May 2022 16:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NutntfjOLhm5vnkAI6J63aqPd+5lyjNYED2lB5Nzypc=; b=f9IpqER2Xa1o1NkAvhApl7mtUQdmcGuXMsiRmnB3lgDD79qA+7YHne14gqqXEQXZ/I y87scVcuqxVTTrdHaaBMwzKqKvRmsfN0Wag78E6gMOdpVU8TGDrtk0Iw+6YQes3zj8BF 7jW5wOk6oevitELnTQrTfLKxniws8dOaYzy7h8w+fqpSGZ84sPNC1X/IEHs3QofMz8v8 X33xA/SzSAKfeNvszIh1trFo3ILs0oXv7jWJv2PItAH/dxtxQ/Ze//ACjjjR6iXcPWU2 rB1e7FfvBRkIjm2mNmNCaW4W9LVA5J9RHt64zUD3k9lk+RlvxIP4rTMUA+DhGSSL4ojv GVsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NutntfjOLhm5vnkAI6J63aqPd+5lyjNYED2lB5Nzypc=; b=Mya6Wn87TnM8h7FMf8NldhevryyimHSOgW6ePiU0EGVkdVJ3sUpdzGlgt0ZqItPyUH fxTGmK3XfSsiA7nVhfUyLLmiHW8hDLYYjy3LL6Ck3xaSaSCaTwtVHn0Q2+hht/z0pzfy avZm/VYBE7w35dFkJj0+9ybWiTfC7dFv83A0nWNBrH2lCjYmhS7n9Aya14/Yj/GjWVeu wDUOmf7bIiw4nRw4nT3jQLXUYTZPysvifSe3gtPR8wzBxNCHRHBqhOjtjJMkbdhHte7P 4BNp/1TTP81oXOgLPt2nkxogYtURra77hU+0VFs+UMA25ZPAWVvL5g1tYvoJO1Xx/244 b6lA== X-Gm-Message-State: AOAM530oNTj8TxXhT2FER9kgAQNqqlC7Z2otPWz6moNhI51tthYEJkMU DT1tbFxJZ92n3B9OKNMyynNqIPc0DqY= X-Google-Smtp-Source: ABdhPJxkJjdZDo2Z6T+lu370swWNjkIxOT6aw9y8cApR96rtR1FFNioZcM/cwJuHaMwEcBA1iTNK8w== X-Received: by 2002:a62:1c50:0:b0:518:89bf:8b41 with SMTP id c77-20020a621c50000000b0051889bf8b41mr27372849pfc.60.1653606753742; Thu, 26 May 2022 16:12:33 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3206:ea0b:ce53:ea86]) by smtp.gmail.com with ESMTPSA id y129-20020a626487000000b0050dc76281b5sm2068978pfb.143.2022.05.26.16.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 16:12:32 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Stephen Boyd , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] Input: cros_ec_keyb - switch to using generic device properties Date: Thu, 26 May 2022 16:12:29 -0700 Message-Id: <20220526231230.2805147-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org In preparation to enabling this driver on x86 devices let's switch from OF-specific property API to the generic one. Signed-off-by: Dmitry Torokhov Reviewed-by: Stephen Boyd --- drivers/input/keyboard/cros_ec_keyb.c | 68 ++++++++++++++++++--------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index cc73a149da28..e8338b1c5776 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -518,6 +518,50 @@ static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev, return 0; } +static void cros_ec_keyb_parse_vivaldi_physmap(struct cros_ec_keyb *ckdev) +{ + u32 *physmap = ckdev->vdata.function_row_physmap; + unsigned int row, col, scancode; + int n_physmap; + int error; + int i; + + n_physmap = device_property_count_u32(ckdev->dev, + "function-row-physmap"); + if (n_physmap <= 0) + return; + + if (n_physmap >= VIVALDI_MAX_FUNCTION_ROW_KEYS) { + dev_warn(ckdev->dev, + "only up to %d top row keys is supported (%d specified)\n", + VIVALDI_MAX_FUNCTION_ROW_KEYS, n_physmap); + n_physmap = VIVALDI_MAX_FUNCTION_ROW_KEYS; + } + + error = device_property_read_u32_array(ckdev->dev, + "function-row-physmap", + physmap, n_physmap); + if (error) { + dev_warn(ckdev->dev, + "failed to parse function-row-physmap property: %d\n", + error); + return; + } + + /* + * Convert (in place) from row/column encoding to matrix "scancode" + * used by the driver. + */ + for (i = 0; i < n_physmap; i++) { + row = KEY_ROW(physmap[i]); + col = KEY_COL(physmap[i]); + scancode = MATRIX_SCAN_CODE(row, col, ckdev->row_shift); + physmap[i] = scancode; + } + + ckdev->vdata.num_function_row_keys = n_physmap; +} + /** * cros_ec_keyb_register_matrix - Register matrix keys * @@ -534,11 +578,6 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev) struct input_dev *idev; const char *phys; int err; - struct property *prop; - const __be32 *p; - u32 *physmap; - u32 key_pos; - unsigned int row, col, scancode, n_physmap; err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols); if (err) @@ -573,7 +612,7 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev) idev->id.product = 0; idev->dev.parent = dev; - ckdev->ghost_filter = of_property_read_bool(dev->of_node, + ckdev->ghost_filter = device_property_read_bool(dev, "google,needs-ghost-filter"); err = matrix_keypad_build_keymap(NULL, NULL, ckdev->rows, ckdev->cols, @@ -589,22 +628,7 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev) input_set_drvdata(idev, ckdev); ckdev->idev = idev; cros_ec_keyb_compute_valid_keys(ckdev); - - physmap = ckdev->vdata.function_row_physmap; - n_physmap = 0; - of_property_for_each_u32(dev->of_node, "function-row-physmap", - prop, p, key_pos) { - if (n_physmap == VIVALDI_MAX_FUNCTION_ROW_KEYS) { - dev_warn(dev, "Only support up to %d top row keys\n", - VIVALDI_MAX_FUNCTION_ROW_KEYS); - break; - } - row = KEY_ROW(key_pos); - col = KEY_COL(key_pos); - scancode = MATRIX_SCAN_CODE(row, col, ckdev->row_shift); - physmap[n_physmap++] = scancode; - } - ckdev->vdata.num_function_row_keys = n_physmap; + cros_ec_keyb_parse_vivaldi_physmap(ckdev); err = input_register_device(ckdev->idev); if (err) { From patchwork Thu May 26 23:12:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 12862894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9EA0C4332F for ; Thu, 26 May 2022 23:12:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349441AbiEZXMj (ORCPT ); Thu, 26 May 2022 19:12:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349391AbiEZXMi (ORCPT ); Thu, 26 May 2022 19:12:38 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8491FE529A; Thu, 26 May 2022 16:12:36 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id c22so2560173pgu.2; Thu, 26 May 2022 16:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6hESI7H4x1E9GmthOOatZOfLK2selcIJejOGX79+sAw=; b=V7bT9FFa1/aoyVCvlDzCiTnIi+qNUf55IayAHztYaU3eb2zh0NSSpLE6Hkciz9+y6D sZObhYAQoaqawPk/7SGRRbWB2eEaoMk+AsJJW0HDZmBV+eWRCW+vLIiWWwAHUDRaORZv n2R1WqfYc6Vw/5eZjztNHOE68ySbeqNugdqdQkoFmLo8i2sylgPvQiV/V+99TTZmiPqq P9zUnmcHzJNByYNjONJ/mGO9JxfzJsRFvbhTmylkzSgDSVqOyfrwb+Ww5p2V9teKWjsi +fOsE3ezY23PqqytAqKe2jW/YilNzfcYhHBV0Ap1JffV2p9rDg/YJwBg/+M7wmyEFem5 Imiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6hESI7H4x1E9GmthOOatZOfLK2selcIJejOGX79+sAw=; b=j3e0a+IqvDUA4DmzFeQKVgx0T192m7E3wtcjYD4JUdlrdclqhihTA0Lt0n2sHIC9bB d+2z/HQCKjeTr3yE2jzL27453WQY9kjoRQtuU8kCyU4WFQuz5H3xxsouWV+zddWVWJlD OTlajKg2a0ojmOR53rB57Ai47v9jSyq5oTFY1PK+iXwQ66yT0baQURdUtfhvkXPcgO06 yjTjumBoBetlAlqBjVsADH7mE2DUe0H7P4SHJVbke38vVJaC/N1un0TzV4JQwjzlY2Vg pxYnTosQiSXhiDdZHzLjcklrxxzX6Gbxdpba+fzntPvE//xNvwy5bIJFigKgvHO4qkXp 7RWQ== X-Gm-Message-State: AOAM5326Zxg6izjwdeVbbmGLKv0RZD7FIw+2OGNfHqcCgFdqSFNECrWt bmGty0SiwevVzCJa2DJiPxvSIfFVYTQ= X-Google-Smtp-Source: ABdhPJyWjmMeUGVUJKyEZ5wOno6L8FQOb0Yw1LrsplM3tTdY8EF9UGMOMM4IWVFT2zlBVBVfg5mCKg== X-Received: by 2002:a65:5c48:0:b0:382:2c7:28e9 with SMTP id v8-20020a655c48000000b0038202c728e9mr35433146pgr.472.1653606755402; Thu, 26 May 2022 16:12:35 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3206:ea0b:ce53:ea86]) by smtp.gmail.com with ESMTPSA id y129-20020a626487000000b0050dc76281b5sm2068978pfb.143.2022.05.26.16.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 16:12:34 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Furquan Shaikh , Stephen Boyd , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] Input: cros_ec_keyb - handle x86 detachable/convertible Chromebooks Date: Thu, 26 May 2022 16:12:30 -0700 Message-Id: <20220526231230.2805147-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog In-Reply-To: <20220526231230.2805147-1-dmitry.torokhov@gmail.com> References: <20220526231230.2805147-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Furquan Shaikh Some detachable/convertible x86 Chromebooks use EC buttons/switches interface to signal volume up/down and other buttons. This configuration is signalled via presence of GOOG0007 ACPI device. The main keyboard on such Chromebooks is still using the standard 8042/atkbd combo. Signed-off-by: Furquan Shaikh Signed-off-by: Dmitry Torokhov Reviewed-by: Stephen Boyd --- drivers/input/keyboard/cros_ec_keyb.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index e8338b1c5776..c14136b733a9 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -12,6 +12,7 @@ // expensive. #include +#include #include #include #include @@ -677,14 +678,19 @@ static const struct attribute_group cros_ec_keyb_attr_group = { static int cros_ec_keyb_probe(struct platform_device *pdev) { - struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent); + struct cros_ec_device *ec; struct device *dev = &pdev->dev; struct cros_ec_keyb *ckdev; bool buttons_switches_only = device_get_match_data(dev); int err; - if (!dev->of_node) - return -ENODEV; + /* + * If the parent ec device has not been probed yet, defer the probe of + * this keyboard/button driver until later. + */ + ec = dev_get_drvdata(pdev->dev.parent); + if (!ec) + return -EPROBE_DEFER; ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL); if (!ckdev) @@ -737,6 +743,14 @@ static int cros_ec_keyb_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_ACPI +static const struct acpi_device_id cros_ec_keyb_acpi_match[] = { + { "GOOG0007", true }, + { } +}; +MODULE_DEVICE_TABLE(acpi, cros_ec_keyb_acpi_match); +#endif + #ifdef CONFIG_OF static const struct of_device_id cros_ec_keyb_of_match[] = { { .compatible = "google,cros-ec-keyb" }, @@ -754,6 +768,7 @@ static struct platform_driver cros_ec_keyb_driver = { .driver = { .name = "cros-ec-keyb", .of_match_table = of_match_ptr(cros_ec_keyb_of_match), + .acpi_match_table = ACPI_PTR(cros_ec_keyb_acpi_match), .pm = &cros_ec_keyb_pm_ops, }, };