From patchwork Mon Aug 19 04:58:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13767906 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E5043C52D7C for ; Mon, 19 Aug 2024 05:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=5L9I6imIfpvf63yPfkptA7xMzZO0c5Qjz4Mu6DS54Gw=; b=mqOrQKQ1i9Iq17x01dSwI6july IcP06QXtg/fdvSYRiuqYSQCa1fUqNEKf6jFda3cb7dkcYLlK98eoui3iEPoBxodJ+ISRw0a0nJRnU lSF2mC3H9ADYo7w2qIi2dgTX0LOzRwPo5Al1h1r7HY3/EQYmM1FgQCchVVDb5PDM8Nq+2nsFcz0gj 11pDMJzcIWhJCP5nTM67yzepNDnoCjJLQo7XrpU8Fc+g6KRTNGxFaP8b6ddvXaRRtaiDLq6EZlgaN MhgHxPnWpX8ib/A+uHW+WYRiqMy8AvEZHXkHAJ99Xpx0/9X/pWpgOKbOvdliFZ2Qb5kIPp9itqvOT 8/khKLnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfuaQ-00000000NT6-2DkN; Mon, 19 Aug 2024 05:05:46 +0000 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfuTW-00000000LZm-2lKA for linux-arm-kernel@lists.infradead.org; Mon, 19 Aug 2024 04:58:39 +0000 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-7c3d9a5e050so2414498a12.2 for ; Sun, 18 Aug 2024 21:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724043518; x=1724648318; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5L9I6imIfpvf63yPfkptA7xMzZO0c5Qjz4Mu6DS54Gw=; b=k85m8KOVT+xbLXlUegJjtVQj9HpzFlrgL7rD8RMBI957kJG3jgSp0nm/63Ql2uornD b4LBD8jAOid40ORiZ3bFv1axj2Zm1HBXFw+v3CJFfhaPVLwwSXn7TgybS7z6gAZwM+T/ QOajMRqHtXovRXL8PfGsJwzIp0t3Wa/gsVSL/StFFSJgmTAJUsBq4bhWt2MipGNS89Nd rDAGWD93Vvi1Jn4F0u1UkEmk9kxL1VzGmKfBxBWCi+3hx75F2rYoEJLZ8Bckvq6kIVAw QSb5kVsGigjnr5EUeH5H9CZ7MfGL0AMBpthTexe+Z5IwPGWEV/V0KYT3abkNJvnFVpqx p8Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724043518; x=1724648318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5L9I6imIfpvf63yPfkptA7xMzZO0c5Qjz4Mu6DS54Gw=; b=btUuN/2I7nHWKubSVAyWZUwuxoVaJC4pAOO6FkBr7NkoIZ/sBjgc/Q5kKYaFnfkO7k QsbSITi4FriPK8W707DusPi3NuIKUIFT3l9YWAonlZGzue0tJ0T0nYX61xWIdY2PYzrE m1FGmT5Tv2/i0mThBVa3KsxB86Jnju8vvk8jwj4ptXiHiW/d2typ2zlNvAs2VNFvnOQ9 VvZaiG7QlZJXoVhnFOe/ZUvVWR7NwgfEZ9RFF7GZyYGHUPdoBtMi/iIGymVWDXuJv1oY TCLnDn9mFHvy7Ke7TgzP5o5vdV2fIzFRtmnryt8OR/kxHyBPIUFOOlfrxBDvx+QCowB9 xg0Q== X-Forwarded-Encrypted: i=1; AJvYcCW6HOkGDoSEERe8C1DesfEYxkqqA7EOw2xNC4U9d9w33HVJuFC2f12Wi6IjIFBCdeAyrifKqNXRQnax22cWJZqbFGMBCZ1vyTC+Ocg7XoxoYswEXro= X-Gm-Message-State: AOJu0YyIMP8x7ugLZ1EQ0y8UG/st9RX16QYYAZ2+vS/6GU165qwSIBGR V9IhxQUpAHzOWGFt7yHQ4DqeEzNt3kN7SE3kPFczrEou6mIrvEwLDl0Wtg== X-Google-Smtp-Source: AGHT+IFOXUP47XrlReJyTvezC1ueWJrGGZqHqPG5DuxuErxhgxqYthREfB9dhnYaAiK/2wzqkmdXDQ== X-Received: by 2002:a05:6a21:8181:b0:1c9:bb89:4d66 with SMTP id adf61e73a8af0-1c9bb894f08mr7201660637.3.1724043517786; Sun, 18 Aug 2024 21:58:37 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:4eb5:4500:6efc:6c24]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-202068497b4sm43483445ad.269.2024.08.18.21.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 21:58:37 -0700 (PDT) From: Dmitry Torokhov To: Arnd Bergmann , Mark Brown , Krzysztof Kozlowski Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, patches@opensource.cirrus.com Subject: [PATCH 10/14] Input: samsung-keypad - handle compact binding Date: Sun, 18 Aug 2024 21:58:07 -0700 Message-ID: <20240819045813.2154642-11-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240819045813.2154642-1-dmitry.torokhov@gmail.com> References: <20240819045813.2154642-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240818_215838_721617_8A4CFBCE X-CRM114-Status: GOOD ( 21.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support for standard matrix keymap binding (in addition to the existing verbose binding with a sub-node for each key). This will allow easier conversions from platform data to device properties when using static device properties. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/samsung-keypad.c | 122 +++++++++++++----------- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c index e262137b6838..df2427ac63d7 100644 --- a/drivers/input/keyboard/samsung-keypad.c +++ b/drivers/input/keyboard/samsung-keypad.c @@ -231,78 +231,85 @@ static void samsung_keypad_close(struct input_dev *input_dev) samsung_keypad_stop(keypad); } -#ifdef CONFIG_OF -static struct samsung_keypad_platdata * -samsung_keypad_parse_dt(struct device *dev) +static const struct matrix_keymap_data * +samsung_parse_verbose_keymap(struct device *dev) { - struct samsung_keypad_platdata *pdata; struct matrix_keymap_data *keymap_data; - uint32_t *keymap, num_rows = 0, num_cols = 0; - struct device_node *np = dev->of_node, *key_np; + struct fwnode_handle *child; + u32 *keymap; unsigned int key_count; - if (!np) { - dev_err(dev, "missing device tree data\n"); - return ERR_PTR(-EINVAL); - } - - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); - if (!pdata) { - dev_err(dev, "could not allocate memory for platform data\n"); - return ERR_PTR(-ENOMEM); - } - - of_property_read_u32(np, "samsung,keypad-num-rows", &num_rows); - of_property_read_u32(np, "samsung,keypad-num-columns", &num_cols); - if (!num_rows || !num_cols) { - dev_err(dev, "number of keypad rows/columns not specified\n"); - return ERR_PTR(-EINVAL); - } - pdata->rows = num_rows; - pdata->cols = num_cols; - keymap_data = devm_kzalloc(dev, sizeof(*keymap_data), GFP_KERNEL); if (!keymap_data) { dev_err(dev, "could not allocate memory for keymap data\n"); return ERR_PTR(-ENOMEM); } - pdata->keymap_data = keymap_data; - key_count = of_get_child_count(np); - keymap_data->keymap_size = key_count; - keymap = devm_kcalloc(dev, key_count, sizeof(uint32_t), GFP_KERNEL); + key_count = device_get_child_node_count(dev); + keymap = devm_kcalloc(dev, key_count, sizeof(*keymap), GFP_KERNEL); if (!keymap) { dev_err(dev, "could not allocate memory for keymap\n"); return ERR_PTR(-ENOMEM); } + + keymap_data->keymap_size = key_count; keymap_data->keymap = keymap; - for_each_child_of_node(np, key_np) { + device_for_each_child_node(dev, child) { u32 row, col, key_code; - of_property_read_u32(key_np, "keypad,row", &row); - of_property_read_u32(key_np, "keypad,column", &col); - of_property_read_u32(key_np, "linux,code", &key_code); + + fwnode_property_read_u32(child, "keypad,row", &row); + fwnode_property_read_u32(child, "keypad,column", &col); + fwnode_property_read_u32(child, "linux,code", &key_code); + *keymap++ = KEY(row, col, key_code); } - pdata->no_autorepeat = of_property_read_bool(np, "linux,input-no-autorepeat"); + return keymap_data; +} - pdata->wakeup = of_property_read_bool(np, "wakeup-source") || - /* legacy name */ - of_property_read_bool(np, "linux,input-wakeup"); +static const struct samsung_keypad_platdata * +samsung_keypad_parse_properties(struct device *dev) +{ + const struct matrix_keymap_data *keymap_data; + struct samsung_keypad_platdata *pdata; + u32 num_rows = 0, num_cols = 0; + int error; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) { + dev_err(dev, "could not allocate memory for platform data\n"); + return ERR_PTR(-ENOMEM); + } + device_property_read_u32(dev, "samsung,keypad-num-rows", &num_rows); + device_property_read_u32(dev, "samsung,keypad-num-columns", &num_cols); + + error = matrix_keypad_parse_properties(dev, &num_rows, &num_cols); + if (error) + return ERR_PTR(error); + + pdata->rows = num_rows; + pdata->cols = num_cols; + + if (!device_property_present(dev, "linux,keymap")) { + keymap_data = samsung_parse_verbose_keymap(dev); + if (IS_ERR(keymap_data)) + return ERR_CAST(keymap_data); + + pdata->keymap_data = keymap_data; + } - return pdata; -} -#else -static struct samsung_keypad_platdata * -samsung_keypad_parse_dt(struct device *dev) -{ - dev_err(dev, "no platform data defined\n"); - return ERR_PTR(-EINVAL); + pdata->no_autorepeat = + device_property_read_bool(dev, "linux,input-no-autorepeat"); + + pdata->wakeup = device_property_read_bool(dev, "wakeup-source") || + /* legacy name */ + device_property_read_bool(dev, "linux,input-wakeup"); + + return pdata; } -#endif static void samsung_disable_runtime_pm(void *data) { @@ -314,7 +321,6 @@ static void samsung_disable_runtime_pm(void *data) static int samsung_keypad_probe(struct platform_device *pdev) { const struct samsung_keypad_platdata *pdata; - const struct matrix_keymap_data *keymap_data; const struct platform_device_id *id; struct samsung_keypad *keypad; struct resource *res; @@ -323,18 +329,17 @@ static int samsung_keypad_probe(struct platform_device *pdev) int error; pdata = dev_get_platdata(&pdev->dev); - if (!pdata) { - pdata = samsung_keypad_parse_dt(&pdev->dev); + if (pdata) { + if (!pdata->keymap_data) { + dev_err(&pdev->dev, "no keymap data defined\n"); + return -EINVAL; + } + } else { + pdata = samsung_keypad_parse_properties(&pdev->dev); if (IS_ERR(pdata)) return PTR_ERR(pdata); } - keymap_data = pdata->keymap_data; - if (!keymap_data) { - dev_err(&pdev->dev, "no keymap data defined\n"); - return -EINVAL; - } - if (!pdata->rows || pdata->rows > SAMSUNG_MAX_ROWS) return -EINVAL; @@ -398,7 +403,7 @@ static int samsung_keypad_probe(struct platform_device *pdev) input_dev->open = samsung_keypad_open; input_dev->close = samsung_keypad_close; - error = matrix_keypad_build_keymap(keymap_data, NULL, + error = matrix_keypad_build_keymap(pdata->keymap_data, NULL, pdata->rows, pdata->cols, keypad->keycodes, input_dev); if (error) { @@ -439,11 +444,12 @@ static int samsung_keypad_probe(struct platform_device *pdev) if (error) return error; - if (pdev->dev.of_node) { + if (!dev_get_platdata(&pdev->dev)) { devm_kfree(&pdev->dev, (void *)pdata->keymap_data->keymap); devm_kfree(&pdev->dev, (void *)pdata->keymap_data); devm_kfree(&pdev->dev, (void *)pdata); } + return 0; }