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 73B29C5479D for ; Wed, 11 Jan 2023 10:20:17 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 629E6854B8; Wed, 11 Jan 2023 11:19:51 +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="mn28vGEG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4EE718540C; Wed, 11 Jan 2023 11:19:42 +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 7CE4A8541F for ; Wed, 11 Jan 2023 11:19:38 +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 m21so21657499edc.3 for ; Wed, 11 Jan 2023 02:19:38 -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=ny+ZwKT0Fdk1e5qUVtX9zOwCG0wq7Nf3+nXu2ktMJzg=; b=mn28vGEGlZHvmQNow+NTjdlYoJq0Rbe109UtQzsBVTYdZFMLPRgyrsHWmBnm2t67T4 YJqmsriPdC8pfluzKrQK4lvXchnb1V8/P5BF7R+pnixtGl22L2Kb4pRkLfG4wv0DFscB Vlr1/Uhjnf0rc5HjRgBf+W1KnidXrvdT5S5XU6Pme0T5g0yCEwdI2Xj43wdOHGR3eK42 l2xDXacN1Ex0b6Vr+wIp8fN/r/3EZgFrlbQvYsr1Ob6eerkSZJXsGkI7RtFv3ctoFh2w MhOVkDpIERugJ2dUmSomoAR16285d42JMdnr1QD/Ilgy4HbH2SG7eSulGQ7fmOtOvZ9y RiQw== 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=ny+ZwKT0Fdk1e5qUVtX9zOwCG0wq7Nf3+nXu2ktMJzg=; b=Obb3QsyEssmqnlDWALYrIQSqERHgeBrCxTbllMJk2PKYCzc/wY+212vHRRSUEhuduJ dHT0lthxLDha22RxIteaB0xyGOnSQ+yarYs48rUdVtqFNQ8d64GE+/gj//W2J/TtMq9k ikhQby+BhQkH36uIaCtDTlh1539jPtz3eIz2WISFkIY5JSx7HNLr8ozeErTEaQtNp4BG V6ufq42R7lBnRI47D9tH9gvYpgksInNBv19oOY0sHxPrkd9/TRT2H7Ef0VQoMmxku3jU IEb7Pbbg/ku15vo2RUYxYruxr2tQs6P/zk8q8e0GTKfx7uKwKAqM8exb7sNOw0vo6++r hs2A== X-Gm-Message-State: AFqh2kpbzfXCQMvD+v5TGWkgbHqceGDJxycrbWrAxzQ0XEP71yN+dew+ Xea8FMVllRwa77E+bZLXJVcfxxnDVsM= X-Google-Smtp-Source: AMrXdXut4pAYIOuUsW/+YHHvbw76qx/2zC6Xsi4Qke+GdHyMWLQQORlyVZj6IuaL3vdNkNoGRS5rpQ== X-Received: by 2002:a05:6402:291a:b0:48b:c8de:9d1a with SMTP id ee26-20020a056402291a00b0048bc8de9d1amr31010369edb.37.1673432377872; Wed, 11 Jan 2023 02:19:37 -0800 (PST) Received: from localhost.localdomain ([46.216.42.4]) by smtp.googlemail.com with ESMTPSA id w5-20020a50fa85000000b00491c819d6d2sm5903764edr.44.2023.01.11.02.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 02:19:37 -0800 (PST) From: Dzmitry Sankouski To: u-boot@lists.denx.de Cc: Dzmitry Sankouski , Heinrich Schuchardt Subject: [PATCH 2/3] dm: button: add support for linux_code in button-gpio.c driver Date: Wed, 11 Jan 2023 13:19:30 +0300 Message-Id: <20230111101931.342454-3-dsankouski@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230111101931.342454-1-dsankouski@gmail.com> References: <20230111101931.342454-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 may be used in input devices, using buttons. Signed-off-by: Dzmitry Sankouski --- drivers/button/button-gpio.c | 20 ++++++++++++++++++++ drivers/button/button-uclass.c | 10 ++++++++++ include/button.h | 16 ++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c index dbb000622c..e6eff5c1da 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; + u32 linux_code; }; static enum button_state_t button_gpio_get_state(struct udevice *dev) @@ -29,10 +30,22 @@ static enum button_state_t button_gpio_get_state(struct udevice *dev) return ret ? BUTTON_ON : BUTTON_OFF; } +static u32 button_gpio_get_code(struct udevice *dev) +{ + struct button_gpio_priv *priv = dev_get_priv(dev); + u32 code = priv->linux_code; + + if (!code) + return 0; + + return code; +} + static int button_gpio_probe(struct udevice *dev) { struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev); struct button_gpio_priv *priv = dev_get_priv(dev); + u32 linux_code; int ret; /* Ignore the top-level button node */ @@ -43,6 +56,12 @@ static int button_gpio_probe(struct udevice *dev) if (ret) return ret; + linux_code = dev_read_u32_default(dev, "linux,code", -ENODATA); + debug("linux code value: %d, ret: %d", linux_code, ret); + if (ret) + return ret; + priv->linux_code = linux_code; + return 0; } @@ -92,6 +111,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..6d0c6f69c5 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); } +u32 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..27af4a6a1a 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 -ve on error + */ + u32 (*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 + */ +u32 button_get_code(struct udevice *dev); + #endif -- 2.30.2