From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A2F93246FE for ; Sun, 22 Mar 2026 11:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774179386; cv=none; b=O9NdsJ/TeeN/7894QrQmRNvAkN/sWp+Yooz3Uw/MR+LByGm6vYDSHR9uvrjQA4ahzTRmh7fIA7wIjxEoQpEJHURqTj7j/wjBkIpmJP68Cwjm5AcIICwOx1E6Q3sqoSNbH3JIaaseN8EA0gMXn4Mc6Lx3oHBXBs0BrdatWVjHyhk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774179386; c=relaxed/simple; bh=oP8iPYwELlN3bc8kEB9JSXu3FaAd0wPrhrPNSAWbHd0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s6LDO1ljRhLFBkbFxusLHEFz4+a1dCm709j9OrkiNE/WIEnZ9VcXFdpev5Tp956P6OSAccJbdvMZt/WeAEy7EMDS1HAdfJeaN+xgGwq8409qweXFMMHNgCbQ1jxP3+bGnfU27sgfvqnbOnaCgzeSeJxvH0QLJm20tf2DbE3vJ5g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FN6P88zU; arc=none smtp.client-ip=74.125.82.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FN6P88zU" Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-12a74039dc6so1328546c88.0 for ; Sun, 22 Mar 2026 04:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774179384; x=1774784184; darn=vger.kernel.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=UAgor4tni5JNj1fMi6G3//s4wOx2xwRy8ot6naCedx4=; b=FN6P88zUpGZuSL4sNmgYb3wHSIpkEokj3e9o/pF2JvU9UY2TUXxndErqC4AhQaObRh J2NltbrjSoFNAfUIc0g8e4b6KasqL9QOYxCafhdA+lSdQQrR2e0qovGXKw4wfxEbWrAU sUICmvP7B/Mr9yHaolINi7oyvvqnV35JqOfIJTqke5O9Cfjp1fwxnNwRz1vIYJ8YyLnQ 4rJc6xGadeaSu3s9W2brUI5AP2u+K4iI6MHi6NSVHHBBqs1ANWrA1vzwFiJnOM284eSE VyK8cO9TpWnh2mmg4mQS8LQQx4dUKe8UIL8u7ypDp9ml0sCt+eu34r8AVANu3z6jl5CQ DLaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774179384; x=1774784184; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UAgor4tni5JNj1fMi6G3//s4wOx2xwRy8ot6naCedx4=; b=VJQBl3oA90DDNjbzOAXLlaeIPTrGX3csXYSD9o3ENzxlfNDT5b9yq0yez2/4FORN2a Y5hMUs+Fn4MCBKiwcuUhHyhHEk8eQO3NG0bPAylT3IfV8gmF9qthBJGcdUTFwwVZwT/5 4ofvny8jgQaohuDPbVHQ67KCSpArofpbUK19/2NyqrsHD1F2iJEimhfLUD1pBdiy5sbC LLx1J61lKhoBpHgEE9nkL9Kn4eAFfvIEgl3TBK/hxVGbN4TVsVmxuSkEK/1soW3JdfL4 e3XJJOFiyQxU39iT4bX/hZOOQzcjXYMKAL8J+Kj2ZnPrErFVzFdk+TMb8wosnQe1P7os M/Ag== X-Forwarded-Encrypted: i=1; AJvYcCVVpgtdtm1cvf5lh+taDrw736S0hiCa4KNnBwbs8A0asGfimpBSVwPWmmJCaQreP10AuKoJPAagos76zl4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2aeJQqmCDiMdknae2qagwNhWFv9GgCKVIhMxz+vbKEvbyPFYO dICIygD4He09LYYral/EOPJcLFTORpwevYMac1atjGC6ZDqdCRmvSf4L X-Gm-Gg: ATEYQzwJAHI38mkA7zwaD0bXNbnIN/zaMhv2dmEqvWhZh67vinzqPVLx7vZCiVPS77s 5gLzhOm65rKn5fmZYv8SFEIwqVyrheXoxpKSiWJoO9GkeaqcEClj6aTeF7zsUTTBlJ1iaNKQnZE PZ3v2FE5h2v+i1DUQ7PRc6jlsXkBEHTyJUOCHJvXTAZ5vx0JXRc957VFBXdhu4v90qxjYpfUb2f DqeMyVtEthVRRe+D55+5Rv2hOikhrsADU/tTvG1twa6m2ly4FiNrhZUfYBNxfPDn0tjY9Ds+1e3 ra+KPb7B8BNmCvQQq2q2/De8weyT/IXbbDXAitZnyiQ9KI5xtgQlDKmPkwK2nIdEtgvyv0C/8fO jp4HjMwT58v3wAbYOzKOi22oqDviOP6XYqJoF9YdkSD6z+U/cA6dYvtoHIybc25B4hk1h6aEYI9 3phCIMG+tt7Yqt0Zh7tER+FmbMp+Si3eMR X-Received: by 2002:a05:7022:226:b0:128:d4be:7433 with SMTP id a92af1059eb24-12a726ced02mr3880711c88.34.1774179384391; Sun, 22 Mar 2026 04:36:24 -0700 (PDT) Received: from localhost.localdomain ([2408:8409:ce0:691:14fa:6bbc:50dd:e268]) by smtp.googlemail.com with ESMTPSA id a92af1059eb24-12a733fe80esm9022181c88.7.2026.03.22.04.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2026 04:36:23 -0700 (PDT) From: Xiong Nandi To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Xiong Nandi , Gatien Chevallier , Marco Crivellari , Ingo Molnar , Fabrice Gasnier , Thomas Gleixner Subject: [PATCH v2 2/3] Input: gpio-keys - use shared axis counter for EV_ABS events Date: Sun, 22 Mar 2026 19:35:07 +0800 Message-Id: <20260322113513.9380-3-xndchn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When two buttons share an EV_ABS axis code, releasing one button zeroes the axis while the other is still held. Add a shared atomic counter per (type, code) pair so the axis only resets to zero when the last button on it is released. Signed-off-by: Xiong Nandi --- drivers/input/keyboard/gpio_keys.c | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index f97ca8dd073a..4cbfd5a273bd 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -51,8 +51,10 @@ struct gpio_button_data { spinlock_t lock; bool disabled; bool key_pressed; + bool axis_active; bool suspended; bool debounce_use_hrtimer; + atomic_t *axis_count; }; struct gpio_keys_drvdata { @@ -374,8 +376,15 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata) } if (type == EV_ABS) { - if (state) + if (state && !bdata->axis_active) { + bdata->axis_active = true; + atomic_inc(bdata->axis_count); input_event(input, type, button->code, button->value); + } else if (!state && bdata->axis_active) { + bdata->axis_active = false; + if (atomic_dec_and_test(bdata->axis_count)) + input_event(input, type, button->code, 0); + } } else { input_event(input, type, *bdata->code, state); } @@ -951,6 +960,35 @@ static int gpio_keys_probe(struct platform_device *pdev) fwnode_handle_put(child); + /* Allocate shared axis counters for EV_ABS buttons */ + for (i = 0; i < pdata->nbuttons; i++) { + struct gpio_button_data *bdata = &ddata->data[i]; + unsigned int type = bdata->button->type ?: EV_KEY; + int j; + + if (type != EV_ABS) + continue; + + /* Reuse counter from an earlier button with same (type, code) */ + for (j = 0; j < i; j++) { + struct gpio_button_data *prev = &ddata->data[j]; + unsigned int prev_type = prev->button->type ?: EV_KEY; + + if (prev_type == type && + prev->button->code == bdata->button->code) { + bdata->axis_count = prev->axis_count; + break; + } + } + + if (!bdata->axis_count) { + bdata->axis_count = devm_kzalloc(dev, + sizeof(*bdata->axis_count), GFP_KERNEL); + if (!bdata->axis_count) + return -ENOMEM; + } + } + error = input_register_device(input); if (error) { dev_err(dev, "Unable to register input device, error: %d\n", -- 2.25.1