From mboxrd@z Thu Jan 1 00:00:00 1970 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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0200AC25B4E for ; Sun, 22 Jan 2023 15:22:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 46794856B8; Sun, 22 Jan 2023 16:21:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="T6KGWFM7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 31692850CC; Sun, 22 Jan 2023 16:21:44 +0100 (CET) Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2791C856AE for ; Sun, 22 Jan 2023 16:21:40 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=dsankouski@gmail.com Received: by mail-ed1-x532.google.com with SMTP id w14so11890206edi.5 for ; Sun, 22 Jan 2023 07:21:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=oSAYgLIsRdEI3cuU3xRCcIUy7qW17BFN+x/FB0x0JxA=; b=T6KGWFM75/kPWpCVo8+xWLtDGXK9EOMH2glLFCof9D2UAiO1UXj1SUaK14LhyLNaI/ RXL89OFlyUP1CmGBEy3Mgwa+TVBC0aGJlaqrErr+2o3KbC4GXOEQg2Wr55U7gKOhTp13 1pl5hXMpy8sZmcXCHOx7cLVaAaISErGlNPQ2okL2vOZG4JCyZ22YPGTbfNUOvxcG9VPT nyjRiEzeekfLr+dCHnLx+u/l1b5izUVbcqq2dCJYyEEI0vM4lOcwMwoI9g6n6Pk+ua0C BOhuvE/BraZa6PmA8hmywW8+HavUM6R3e7bnm0dF0N1z/EG2jg2TJikv7/1lOLdav56b GIjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=oSAYgLIsRdEI3cuU3xRCcIUy7qW17BFN+x/FB0x0JxA=; b=j+JJgd6oRGD/VysoCzfy2Qw70A6s5NT1010ywZsb1k+VCQ9/vRrWNZdhPW35Nxls10 xCApIRzAbwW0wQ9jqWhpeHfxVlEc6reH0+wmBYi95O6Z95XirBgRJs7qyEO1a0281y+N +6FWgieuW5ZnGWXoeELMM3qoOBPfYh2I21Qvv7RtzhmAm3mQflxjgZMPo3X4va6VDHWz R+crCqM2QOCGpJG5FVq3MZxp0oU+dkSwKfgzMvCUVOmYYSte5ddMiMPLAeNTNiq6iYUy ZhKIVTk7nzoiOaTTdwjiPOkaCAf2fPKru45JRev1qqF/1+ahuZxE5llGWbc1YhvesdhG rhlQ== X-Gm-Message-State: AFqh2kp9HACmJ3VWTGe8F666ZrI1oiST2NWcgPWq0g0g/bf+y0DIQbI7 fhT/z3dWWEZp8FNW6prgYXuGKksnkqY= X-Google-Smtp-Source: AMrXdXvH+6Dqvt+L0lBHTDcbzk0shu4GNoaVTBMMQy1RAFw023ediabasVTqCb7v+OrGlQu0+mHyrA== X-Received: by 2002:aa7:ccd9:0:b0:495:d1f4:7609 with SMTP id y25-20020aa7ccd9000000b00495d1f47609mr33260537edt.19.1674400899285; Sun, 22 Jan 2023 07:21:39 -0800 (PST) Received: from localhost.localdomain ([46.216.42.4]) by smtp.googlemail.com with ESMTPSA id a8-20020aa7d908000000b0049dfd6bdc25sm11190075edr.84.2023.01.22.07.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jan 2023 07:21:38 -0800 (PST) From: Dzmitry Sankouski To: u-boot@lists.denx.de Cc: Dzmitry Sankouski , Heinrich Schuchardt Subject: [PATCH v3 4/5] dm: button: add support for linux_code in button-gpio.c driver Date: Sun, 22 Jan 2023 18:21:24 +0300 Message-Id: <20230122152125.858085-5-dsankouski@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230122152125.858085-1-dsankouski@gmail.com> References: <20230122152125.858085-1-dsankouski@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Linux event code must be used in input devices, using buttons. Signed-off-by: Dzmitry Sankouski --- Changes for v2: - fail, if linux,code not found Changes for v3: - add test for linux,code - change linux,code type to int - new line after return - add specific error code in function docs arch/sandbox/dts/test.dts | 2 ++ drivers/button/button-gpio.c | 17 ++++++++++++++++- drivers/button/button-uclass.c | 10 ++++++++++ include/button.h | 16 ++++++++++++++++ test/dm/button.c | 13 +++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 06ad027638..f8d59f1ce1 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -172,11 +172,13 @@ btn1 { gpios = <&gpio_a 3 0>; label = "button1"; + linux,code = ; }; btn2 { gpios = <&gpio_a 4 0>; label = "button2"; + linux,code = ; }; }; diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c index dbb000622c..7b5b3affe2 100644 --- a/drivers/button/button-gpio.c +++ b/drivers/button/button-gpio.c @@ -13,6 +13,7 @@ struct button_gpio_priv { struct gpio_desc gpio; + int linux_code; }; static enum button_state_t button_gpio_get_state(struct udevice *dev) @@ -29,6 +30,17 @@ static enum button_state_t button_gpio_get_state(struct udevice *dev) return ret ? BUTTON_ON : BUTTON_OFF; } +static int button_gpio_get_code(struct udevice *dev) +{ + struct button_gpio_priv *priv = dev_get_priv(dev); + int code = priv->linux_code; + + if (!code) + return -ENODATA; + + return code; +} + static int button_gpio_probe(struct udevice *dev) { struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev); @@ -43,7 +55,9 @@ static int button_gpio_probe(struct udevice *dev) if (ret) return ret; - return 0; + ret = dev_read_u32(dev, "linux,code", &priv->linux_code); + + return ret; } static int button_gpio_remove(struct udevice *dev) @@ -92,6 +106,7 @@ static int button_gpio_bind(struct udevice *parent) static const struct button_ops button_gpio_ops = { .get_state = button_gpio_get_state, + .get_code = button_gpio_get_code, }; static const struct udevice_id button_gpio_ids[] = { diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c index e33ed7d01d..032191d61a 100644 --- a/drivers/button/button-uclass.c +++ b/drivers/button/button-uclass.c @@ -38,6 +38,16 @@ enum button_state_t button_get_state(struct udevice *dev) return ops->get_state(dev); } +int button_get_code(struct udevice *dev) +{ + struct button_ops *ops = button_get_ops(dev); + + if (!ops->get_code) + return -ENOSYS; + + return ops->get_code(dev); +} + UCLASS_DRIVER(button) = { .id = UCLASS_BUTTON, .name = "button", diff --git a/include/button.h b/include/button.h index 96e6b1901f..207f4a0f4d 100644 --- a/include/button.h +++ b/include/button.h @@ -37,6 +37,14 @@ struct button_ops { * @return button state button_state_t, or -ve on error */ enum button_state_t (*get_state)(struct udevice *dev); + + /** + * get_code() - get linux event code of a button + * + * @dev: button device to change + * @return button code, or -ENODATA on error + */ + int (*get_code)(struct udevice *dev); }; #define button_get_ops(dev) ((struct button_ops *)(dev)->driver->ops) @@ -58,4 +66,12 @@ int button_get_by_label(const char *label, struct udevice **devp); */ enum button_state_t button_get_state(struct udevice *dev); +/** + * button_get_code() - get linux event code of a button + * + * @dev: button device to change + * @return button code, or -ve on error + */ +int button_get_code(struct udevice *dev); + #endif diff --git a/test/dm/button.c b/test/dm/button.c index e76c1ad030..3318668df2 100644 --- a/test/dm/button.c +++ b/test/dm/button.c @@ -13,6 +13,7 @@ #include #include #include +#include #include /* Base test of the button uclass */ @@ -85,6 +86,18 @@ static int dm_test_button_label(struct unit_test_state *uts) } DM_TEST(dm_test_button_label, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); +/* Test button has linux,code */ +static int dm_test_button_linux_code(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, &dev)); + ut_asserteq(BTN_1, button_get_code(dev)); + + return 0; +} +DM_TEST(dm_test_button_linux_code, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + /* Test adc-keys driver */ static int dm_test_button_keys_adc(struct unit_test_state *uts) { -- 2.30.2