From patchwork Wed Nov 13 04:51:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 842871 Delivered-To: patch@linaro.org Received: by 2002:a5d:6392:0:b0:381:e71e:8f7b with SMTP id p18csp19683wru; Tue, 12 Nov 2024 20:51:26 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXMTmmv2Q27+PpqHmM9DectwiEI2eUF8Sr7PZkELdYiBm50u4MHpgYCOI1aSvUWYZDAs2Y+cA==@linaro.org X-Google-Smtp-Source: AGHT+IF15GiZjuP9Ltd0uBcPeU1wCd3ktN0iNeV1HFPMzp99eUZeuLDfmpJ3PjY4Zu7Q6bz7zqx5 X-Received: by 2002:a17:907:868b:b0:a99:e326:53f2 with SMTP id a640c23a62f3a-a9eeff44654mr1891543166b.28.1731473485957; Tue, 12 Nov 2024 20:51:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731473485; cv=none; d=google.com; s=arc-20240605; b=MvsQnfq8k7G4O4nPHrZzN3ZI99KNbiP00O02ZMdLJIbluQCVFZVUP1TtuhLhpte5eW CYJWk/21GBRwPVYDmJ+Zuzxyset7PrhpeUMG0SRATsbVsqTlHvs18ANcH/GPJ1dxJuOP fN1brn4cSFdT0ZqSMXursfIFEhN6jp6y+UsxFpQj+MaRdTwlXmWYfWvCNMUFuSV2buLd XeOT7qX1nUlK5AK236KLylf8+mwvI1hdUCWQZBazy1OwMeFBpX5RPu5RMSKgdcC/g/oP OH99wg6FRAqOViisBSciUsscRvLU65z45TQuqh4A8VAxibPi3V+4+rUpKp+MqJ/34Q4B 5wfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=Q+d27EHy4nK6DJLg2swyyaE+M9hsP0XLhsXn2iIUys8=; fh=NqNMXmYNPCBeQCfAczVKQWd2wlbkcRzWQyqI3wjgtQI=; b=iikutP4YJE0GL8mo7iAIcOxfyd7A8tJpq5tVAssxNR8oSRaPu6CifbXTTH5r8lsOuN RMj3MV4rLnObvGj7N8ecV9Ed8W9lGe+vSgBb5ile5oMNL55Rm9hZCEeJ36z+0Z3MDe3R g+hOT8CUgr/8dGnaHMIxcv+TNh3gUgHKro4TQMB0kKY1ZVVgPlFRV7UXbbxT7o5YZ3a8 NGEfsLp/FstGXeH1tsmte/CXcI1+xTktqxEbI2sosADc8brxUk3ZtqBsm6YsmFkuyU22 +0LYwI031u14YIypGrbrwaQP6jriDoOPNRDJXTsFjrgev1K4M4O/q64GpY5ciKvb5YMp +2fw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xs9E+THl; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-a9ee0a08d6csi946143566b.151.2024.11.12.20.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 20:51:25 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xs9E+THl; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6128089537; Wed, 13 Nov 2024 05:51:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="Xs9E+THl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3C3A489515; Wed, 13 Nov 2024 05:51:24 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SORTED_RECIPS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (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 577AB89539 for ; Wed, 13 Nov 2024 05:51:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=caleb.connolly@linaro.org Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a9a0ef5179dso1088777066b.1 for ; Tue, 12 Nov 2024 20:51:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731473482; x=1732078282; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Q+d27EHy4nK6DJLg2swyyaE+M9hsP0XLhsXn2iIUys8=; b=Xs9E+THlRAvS0uMAYiBqyaoiLWPnhDN7viON2SKc8s1z3RV8b7dvC6ZfN0OFgUXYQs q6/n9ryvUTNqmZ930QzyhbrzR9NrUnFV67M21TYQiqzctXXaYt0Cm/KY984zzhwggnRt hf418Uh3TpyOA5GKBiYW0a5+11wLozjcrR4QrC4U3ecQmHfRRolBlCuV/XZn+Zr0JMmm jOMBpP4hoLNEup0K22PE4WyRIUeCHAJHKnOKXZYp80UV3/IFlYCaJDW+EQ9Hwzhoihji 2FnOFlzlGHgKAyraIoGutxmwxB2XLX5GmKFsoNaLPm25VjhUa8Hx0exDu3JLpvw2DFrS sP2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731473482; x=1732078282; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Q+d27EHy4nK6DJLg2swyyaE+M9hsP0XLhsXn2iIUys8=; b=iUOu2atKCkOQlTqIm3pusF+iTJPUuZ8XkXB+ktObLKSsYwY/F4WkJLVfsejh4jF9UJ 3/rNRvi0xl1vaaASjVbsvN9NfUu3lveGufDoTI/blCoZplC1HP6RJhQGs6CIe6oQcy4i rXtYQzjVb99Grt0P0WTpgbMD2uVj47emAkZJmVdc3DPO+Looi0UEhT7hngCAzcODI+ii S5aq9JCK1UAoePeCGm6ACWLo7Ymk8ldof5YpVmtcAUITeILsA1uMN3/tN92ieOmKgfAZ oVkV7oHg8tNLpnGrvTyBg0SMb/yJETO0AdehdTevwzq4sfI8es4VhgPsJ3rCHIY6MqeA Sg5w== X-Forwarded-Encrypted: i=1; AJvYcCVGmryXIbid1ZxFlpbphMzB0wHN/7udXvvxlgrn+kGipWGVdhCDBNYshUzgpeL0QsUEQ+eR+7M=@lists.denx.de X-Gm-Message-State: AOJu0YxLIutKlbWz6DS5+u28kudzMiHOVj1sakWVKcP7lS0QBncE2eG+ rpLYLf1GPX1CVdO6FFs7AwnQOAwk2QMBNxudDKM/DsOnhPXtnP9Q34Ub22xReNw= X-Received: by 2002:a17:907:7b86:b0:a9d:e01e:ffa9 with SMTP id a640c23a62f3a-a9eeff449femr1836855366b.33.1731473481695; Tue, 12 Nov 2024 20:51:21 -0800 (PST) Received: from lion.caleb.rex.connolly.tech ([2a02:8109:888d:ff00:ca7f:54ff:fe52:4519]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9ee0a17651sm809267666b.38.2024.11.12.20.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 20:51:21 -0800 (PST) From: Caleb Connolly To: Caleb Connolly , Dan Carpenter , Neil Armstrong , Simon Glass , Sumit Garg , Tom Rini Cc: u-boot-qcom@groups.io, u-boot@lists.denx.de Subject: [PATCH] button: qcom-pmic: add software debounce Date: Wed, 13 Nov 2024 05:51:03 +0100 Message-ID: <20241113045109.1838241-1-caleb.connolly@linaro.org> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean This helps with reliability on some platforms. We should probably also configure the hardware debounce timer eventually. Signed-off-by: Caleb Connolly --- drivers/button/button-qcom-pmic.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/button/button-qcom-pmic.c b/drivers/button/button-qcom-pmic.c index ad7fed3ddaaa..f9f0948ae095 100644 --- a/drivers/button/button-qcom-pmic.c +++ b/drivers/button/button-qcom-pmic.c @@ -14,8 +14,9 @@ #include #include #include #include +#include #define REG_TYPE 0x4 #define REG_SUBTYPE 0x5 @@ -30,8 +31,9 @@ struct qcom_pmic_btn_priv { u32 base; u32 status_bit; int code; struct udevice *pmic; + ulong last_release_time; }; #define PON_INT_RT_STS 0x10 #define PON_KPDPWR_N_SET 0 @@ -41,15 +43,23 @@ struct qcom_pmic_btn_priv { static enum button_state_t qcom_pwrkey_get_state(struct udevice *dev) { struct qcom_pmic_btn_priv *priv = dev_get_priv(dev); + bool pressed; + int reg; - int reg = pmic_reg_read(priv->pmic, priv->base + PON_INT_RT_STS); + if (get_timer_us(0) - priv->last_release_time < 25000) + return BUTTON_OFF; + reg = pmic_reg_read(priv->pmic, priv->base + PON_INT_RT_STS); if (reg < 0) return 0; - return (reg & BIT(priv->status_bit)) != 0; + pressed = !!(reg & BIT(priv->status_bit)); + if (!pressed) + priv->last_release_time = get_timer_us(0); + + return pressed; } static int qcom_pwrkey_get_code(struct udevice *dev) {