From nobody Sat Apr 4 07:47:59 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 557D63C3455 for ; Fri, 20 Mar 2026 14:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774018355; cv=none; b=bX4O6+HOjpeGXfrlwx/VuBUHNIbaRFBDkxq/hesX2vkO5OlEeJLd3A0DSBv+XF2FgWWiO+tKG9wmZ3TP8Ojc0tiIWdXyMA5t0qCfPetl5w7m+nadTW78x9rI/8cNi1w7FcE13zixR7v36BGwFHQvYsT38Of49okWLHlfzKkZpEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774018355; c=relaxed/simple; bh=bWCB5i98GUVHu1D5jnVWtk9sfTwm6mgsEF0tfg9BkZA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=lDZUD3CZUf5qmU0pOFru+fAyuki/6qWhZpxLJyVSlLJY+e0/6DrDREZUDboWZI++VClPB1izTioTG8dP3Lv243ZUWKE/UcwuFqkw5695vK/6vz/aJQ1Nok0+8wfWfKYmTZrmEZbrEsm3SC1HoQ/Nzj1BkTFEIZwia+MzAP4o+14= 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=T2p3Z0gF; arc=none smtp.client-ip=209.85.214.181 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="T2p3Z0gF" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2ad9a9be502so4274685ad.0 for ; Fri, 20 Mar 2026 07:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774018354; x=1774623154; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=pXjhDdnDa0ijg1VTlgOl74pUpfJvpd6csZYcFWFPCgY=; b=T2p3Z0gFLTqDYgZO1GwicXmQv/TUC6xsWNSn2qajH/NeCmayoduGHjoHWyxXEOiz9r 4XpM7H09vqLc0DJIEt3rGIbAH3uLRGb00XC1wMEs8esXj8bsRNQb5pEpScrjEvuTkG35 UNWE3CDPE+Cz3N9104wy84XcfBoryYYlhfuiO1nD9QlNyb+zJcy3cANqFCkMaVszF94e AL96lNtQDcpoRffXLE7aqmdO6yDKI7N6kqlCvfc5rJIk8WOv9XySxJj4ojz6ZykETkwt cefPE6X4t1wtT2ZctG3drf9+8xcm5r3zJIsd8o1semcFsB/utirY7blICVyOD64AXdZd im3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774018354; x=1774623154; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pXjhDdnDa0ijg1VTlgOl74pUpfJvpd6csZYcFWFPCgY=; b=pxxzdhkbCZ3xvqjMK2yZzmC3kJ1NZ6B+XzabwvDhR5oU+q0R5RpLaMTttS1QnVr9U1 GoqxRZ+REKJ3efsar+33x3IbMwrazJWHujrwOGdgAw2Gvax1rw9WK1qQSBj7MjiCn3+l NAZjyYewbud5y6X8cbBGU3ZmQ8TtVYLZQKs1f8+0LeVC36cZg9YB7OZV8d+yK3LUNRMn eWVV6aH6N0rMuzWaGFLcon7GSe5qcor02V85UFBQM9+2J4hOz03PwxThD+X13YzKfR2Z /l4w+7Iml+nx78oEn+jAYLaVe82vuV/4gL1w4OL0tJOyREk7SGLwxLjaME8dvPBwom4e fvoA== X-Forwarded-Encrypted: i=1; AJvYcCW9BRofDd5D35zgmp2+fAO/iEL1xUDHPV1xcid56KcpvLGvomJklD09I307AkcMlJGHJem9LQIMRn+qWf4=@vger.kernel.org X-Gm-Message-State: AOJu0YykX7sYWIKU5ljllCGLqI0Eev6d4IA2h6t6HJTFRelHNRTe0Uuw I5382w7P0slW1KsWowTmsVtymPfaA75b1M0aLd2L0rUaIwVEpBeUXalb X-Gm-Gg: ATEYQzy3PE6S0tahoJnWuSUiEQle0In15AulaIBRSRzj2nmAIDdt7V1RZtduml6ybR4 xsr4J25UnbEkMDtaMFOMJAvvmktJB18EM/s/8U//XqMgqyDvwRq79VnpQCIH15ph3RS20JBy0ac LayTtWFSBIqY4/ehGV0oUNp5k5U/hT+Q9MxlUjwYYGvdYzoGXwSKPW0oOOAUB44yejhWyzxEi2V /obpP7zyJStc0p7wNRVMqdjt+4dfE6Z/ikVeY1Z7Er0xACNSNk0H9J4r0cJC2At2uaAwFPUyIjE F6pH5FWmEmmqlTqLZ0o8kVzKP8FjgLD3okK1cL0rGxbintT0YJdlx3KGdWtbUGFcHXSMAivkVyE 86oOVus37pJJAVN84YHZxDLx7xvvcgJoCcv1MC1zaGPvqfvrvoJTnlLuIwTW6YuC/2qWbBLvsP5 i/CkinEa0SRBUMf/KTMFoUeASOzxil1U1gKfk= X-Received: by 2002:a17:903:198c:b0:2b0:774b:d89e with SMTP id d9443c01a7336-2b0827b413bmr32815915ad.37.1774018353699; Fri, 20 Mar 2026 07:52:33 -0700 (PDT) Received: from localhost.localdomain ([2408:8207:c90:e790:3de6:403c:8f43:3629]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2b08353e94asm24623225ad.25.2026.03.20.07.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Mar 2026 07:52:33 -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 , Ingo Molnar , Thomas Gleixner , Marco Crivellari , Fabrice Gasnier Subject: [PATCH] Input: gpio-keys - add full support of EV_REL and EV_ABS Date: Fri, 20 Mar 2026 22:52:14 +0800 Message-Id: <20260320145217.9088-1-xndchn@gmail.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" gpio_keys_gpio_report_event() handled EV_ABS but silently ignored EV_REL, while the polled driver supports both. Extend the interrupt-driven driver to fire an EV_REL event on button press. For EV_ABS, use a shared atomic counter per (type, code) pair so that a zero-value reset is sent only when the last active button on an axis is released, avoiding premature axis resets when multiple buttons share the same axis code. Add gpio_keys_set_abs_params() to call input_set_abs_params() at setup time, deriving the axis min/max from the configured button values. Without this the input subsystem reports unbounded axis ranges. Signed-off-by: Xiong Nandi --- drivers/input/keyboard/gpio_keys.c | 65 +++++++++++++++++++++++++++++- include/linux/gpio_keys.h | 4 +- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gp= io_keys.c index e19617485679..652a6932c52f 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; }; =20 struct gpio_keys_drvdata { @@ -373,9 +375,16 @@ static void gpio_keys_gpio_report_event(struct gpio_bu= tton_data *bdata) return; } =20 - if (type =3D=3D EV_ABS) { - if (state) + if (type =3D=3D EV_ABS || type =3D=3D EV_REL) { + if (state && !bdata->axis_active) { + bdata->axis_active =3D true; + atomic_inc(bdata->axis_count); input_event(input, type, button->code, button->value); + } else if (!state && bdata->axis_active) { + bdata->axis_active =3D false; + if (atomic_dec_and_test(bdata->axis_count)) + input_event(input, type, button->code, 0); + } } else { input_event(input, type, *bdata->code, state); } @@ -493,6 +502,27 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *de= v_id) return IRQ_HANDLED; } =20 +static void gpio_keys_set_abs_params(struct input_dev *input, + struct gpio_keys_drvdata *ddata, + unsigned int code) +{ + int i, min =3D 0, max =3D 0; + + for (i =3D 0; i < ddata->pdata->nbuttons; i++) { + const struct gpio_keys_button *button =3D &ddata->pdata->buttons[i]; + + if (button->type !=3D EV_ABS || button->code !=3D code) + continue; + + if (button->value < min) + min =3D button->value; + if (button->value > max) + max =3D button->value; + } + + input_set_abs_params(input, code, min, max, 0, 0); +} + static int gpio_keys_setup_key(struct platform_device *pdev, struct input_dev *input, struct gpio_keys_drvdata *ddata, @@ -651,6 +681,8 @@ static int gpio_keys_setup_key(struct platform_device *= pdev, bdata->code =3D &ddata->keymap[idx]; *bdata->code =3D button->code; input_set_capability(input, button->type ?: EV_KEY, *bdata->code); + if ((button->type ?: EV_KEY) =3D=3D EV_ABS) + gpio_keys_set_abs_params(input, ddata, button->code); =20 /* * Install custom action to cancel release timer and @@ -928,6 +960,35 @@ static int gpio_keys_probe(struct platform_device *pde= v) =20 fwnode_handle_put(child); =20 + /* Allocate shared axis counters for EV_ABS/EV_REL buttons */ + for (i =3D 0; i < pdata->nbuttons; i++) { + struct gpio_button_data *bdata =3D &ddata->data[i]; + unsigned int type =3D bdata->button->type ?: EV_KEY; + int j; + + if (type !=3D EV_ABS && type !=3D EV_REL) + continue; + + /* Reuse counter from an earlier button with same (type, code) */ + for (j =3D 0; j < i; j++) { + struct gpio_button_data *prev =3D &ddata->data[j]; + unsigned int prev_type =3D prev->button->type ?: EV_KEY; + + if (prev_type =3D=3D type && + prev->button->code =3D=3D bdata->button->code) { + bdata->axis_count =3D prev->axis_count; + break; + } + } + + if (!bdata->axis_count) { + bdata->axis_count =3D devm_kzalloc(dev, + sizeof(*bdata->axis_count), GFP_KERNEL); + if (!bdata->axis_count) + return -ENOMEM; + } + } + error =3D input_register_device(input); if (error) { dev_err(dev, "Unable to register input device, error: %d\n", diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h index 80fa930b04c6..75a745a32fe1 100644 --- a/include/linux/gpio_keys.h +++ b/include/linux/gpio_keys.h @@ -13,13 +13,13 @@ struct device; * @active_low: %true indicates that button is considered * depressed when gpio is low * @desc: label that will be attached to button's gpio - * @type: input event type (%EV_KEY, %EV_SW, %EV_ABS) + * @type: input event type (%EV_KEY, %EV_SW, %EV_ABS, %EV_REL) * @wakeup: configure the button as a wake-up source * @wakeup_event_action: event action to trigger wakeup * @debounce_interval: debounce ticks interval in msecs * @can_disable: %true indicates that userspace is allowed to * disable button via sysfs - * @value: axis value for %EV_ABS + * @value: axis value for %EV_ABS/%EV_REL * @irq: Irq number in case of interrupt keys * @wakeirq: Optional dedicated wake-up interrupt */ --=20 2.25.1