From nobody Fri Jan 9 00:33:13 2026 Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) (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 978DE2F12D9 for ; Sun, 4 Jan 2026 21:31:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767562302; cv=none; b=TDk5yRqPc3/g5cOWR8KCqi/xUBZmRuFoZpI5Bn5mfqyXcoiDXhBDdzmHzGbx2BEwqS3ihAYR6XnA5WZDuip0/wIYwJahXQH7xXK5i2DdMYozsp0BHfLwOjWVuB4Ce20oGk594SUD294d7vi6R7Vfitq1uNAPUCQvTXefbQokn7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767562302; c=relaxed/simple; bh=/7YH+Zqpi8jckS9SwFkBwQ/lSUU/TC5vR/IH2liykg8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FT2AUk0DYqTHg+NoTVwbvwiI+Lvbg9CGSqMZ0GaQfb513A3aSC3jCS3oYaz0yGf9WizRN58a3YE0QO0ueWSwHORREOAZl9QKqu0REsmVHm1j55qp6YViT4ysf8FX8vFVPnLuSaaRzGD5mSYjoXxxgENDUuROaSjAvrb/lvvQ71I= 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=PDH+1W0b; arc=none smtp.client-ip=209.85.218.66 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="PDH+1W0b" Received: by mail-ej1-f66.google.com with SMTP id a640c23a62f3a-b769a872550so201154966b.3 for ; Sun, 04 Jan 2026 13:31:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767562298; x=1768167098; 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=PUUroYHtAt2Ce/xZZlgPaiIZoDgmPFJ5E5jP2+Tt7RI=; b=PDH+1W0bfnEngycIXKuGMWDCkfU9LUJIzAeuniNEg2H0dGcy6t+Y+dgclYAhzknDkq DMUYeagy2McjSc/dMnZCuLMkaLGTfDNKPMNblue7iZBzvLZqUtjKvwKEWaIuQeHBpTO8 jA2pHnN1JO/slsjG1JehdVHL3uuzgVIHNhx09suH1ozdQw59HPhl6cTWouJV0YZZWziR L0S+IHib71q5IIvuvmd9AsrsMYPis2ZyF7WRxhopUmu+TcJ7IA2wsZA9UINl1Z+K4ayQ 9HbllrB5AmzEI7Jh+LLDsOggahqYjXwMtAqY8Eb05rhrFrpKat9WNJoHxkUn8k4fd//s fLFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767562298; x=1768167098; 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=PUUroYHtAt2Ce/xZZlgPaiIZoDgmPFJ5E5jP2+Tt7RI=; b=UEn8FUqDqp9lsZohihYBE/+9hjx47n8xf+wzXBkCW+0ncCL0UW69HHezYMblIr0+TY nbEC3lYYJQIcc+LwD7nr99Ui7cAX6fsK4mPLY94DOeydfN+OT4DFB44MFDf8cbxksQpk JuDVyRF3BsYrmIYbfMkrMaBuVrs7dRKElsQvFVFdCvEowClhV9ba4xUh2FSZw30mFclp i+oHJVKPacdFzHpvriLEPTTmN3ZrJKLBaUU/yl1SwLiBK36BWjwbMiT69A2Gt9w+SpL2 m/tP9GYnYVAHrXvGdEVf04YlryoK5JXZOZmGduW5JGL2iIUCUnaZgWi+eBd3QU2Ai5w5 bsVA== X-Forwarded-Encrypted: i=1; AJvYcCX5oZxB8HYqb4fRsTh6EvMi83owWGp1sJT6GYotk4mrK7vQQZrv/Jt9+lvxA0Qbvy+DJDm0n3nS2rP+m4Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3PgawD9UGbvhVS8BmAyhxqC4D0FNapLNYLtMtF9JDZkcIzHUl pRU//eOQAJCHJTWlIlEKa8WNS8IhFaEvDVpAaMesryLGwPYS92EUqn0e X-Gm-Gg: AY/fxX4TfsB6DNHtS13S9wVoLGrRJ/fbfghd5nI/ur5TQF3fbXU0HO/V2RU8zJc0PeA 3fxh3DQe/4HDWSnbKjRHUPxAnAAsMtG29a7SKoyJvpjFA89NrmoeUjBJHwaCo1E/ZkNebWcEHNw 8JV7wYqHcayQ5MtBFpItsX4M4lk+DEV2RLytQNqJ9cmttmayTTDnYRPe3BbkRRFVZwur+mSLWpA j6ePeNJZ23Iqj0PwZoG4DniZ47L+wJz3ea3pYffO6Tq2Pfclq7N3m1MzNapO9eRKfWrLxK+LYID m0saR4GjrSThVqsLUWaNT4/sMGrVXdaxaioChYysSv5ZV+mauV1kSq7lbXnqlFhiCiyCxYSvAyA /UYNottZgWGInyctcyRQVkxR4HsaO12FBm4Co3O1N/nG/G3dCgQvqk/cus5s9dtoFcstPBhjTfe 4AJtHtP4NXEMoyW2d52UNW0LEPzaqM0psGTcMbT+f5I81qS15tI8Gl5Q6Nyq9hwwHU X-Google-Smtp-Source: AGHT+IG+AEIpwPtWYJYhI5A6ldFiprrP803Cg1B0GSU9VpFVObKxSmMNbMgLd9tAEXXNopAk8qcitQ== X-Received: by 2002:a05:6402:4311:b0:649:b47b:2ef7 with SMTP id 4fb4d7f45d1cf-64b8e93de10mr21587011a12.3.1767562297834; Sun, 04 Jan 2026 13:31:37 -0800 (PST) Received: from laptok.lan (87-205-5-123.static.ip.netia.com.pl. [87.205.5.123]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b9105a9c4sm51947772a12.12.2026.01.04.13.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jan 2026 13:31:37 -0800 (PST) From: =?UTF-8?q?Tomasz=20Paku=C5=82a?= To: dmitry.torokhov@gmail.com, corbet@lwn.net, jikos@kernel.org, bentiss@kernel.org Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, vi@endrift.com, linux-kernel@altimeter.info, peter.hutterer@who-t.net Subject: [RFC PATCH 4/6] Input: Assign EV_BTN event to HID Joysticks Date: Sun, 4 Jan 2026 22:31:30 +0100 Message-ID: <20260104213132.163904-5-tomasz.pakula.oficjalny@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260104213132.163904-1-tomasz.pakula.oficjalny@gmail.com> References: <20260104213132.163904-1-tomasz.pakula.oficjalny@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Joysticks will now fire EV_BTN for every of their buttons, even buttons that were previously ignored because they were cut off by KEY_MAX. This in turns enables joysticks to finally report buttons above 80 which was the previous limitation. Signed-off-by: Tomasz Paku=C5=82a --- drivers/hid/hid-input.c | 27 +++++++++++++++++++++------ include/linux/input.h | 2 ++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 900a6fc9813e..1c11077b1577 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -760,11 +760,15 @@ static void hidinput_configure_usage(struct hid_input= *hidinput, struct hid_fiel case HID_GD_MOUSE: case HID_GD_POINTER: code +=3D BTN_MOUSE; break; case HID_GD_JOYSTICK: - if (code <=3D 0xf) - code +=3D BTN_JOYSTICK; - else - code +=3D BTN_TRIGGER_HAPPY - 0x10; - break; + if (input->button_count >=3D INPUT_MAX_BUTTONS) + goto ignore; + + code +=3D BTN_JOYSTICK; + if (code > BTN_DEAD) + code +=3D BTN_TRIGGER_HAPPY - BTN_DEAD - 1; + if (code > KEY_MAX) + code =3D KEY_RESERVED; + break; case HID_GD_GAMEPAD: if (code <=3D 0xf) code +=3D BTN_GAMEPAD; @@ -1379,7 +1383,6 @@ static void hidinput_configure_usage(struct hid_input= *hidinput, struct hid_fiel } =20 set_bit(usage->type, input->evbit); - /* * This part is *really* controversial: * - HID aims at being generic so we should do our best to export @@ -1390,12 +1393,18 @@ static void hidinput_configure_usage(struct hid_inp= ut *hidinput, struct hid_fiel * *_MISC+N to overwrite a legitimate even, which confuses userspace * (for instance ABS_MISC + 7 is ABS_MT_SLOT, which has a different * processing) + * - Joysticks can have arbitrary number of buttons without defined + * usages. Buttons that extend beyond KEY_MAX are assigned to + * KEY_RESERVED thus deduplication must be disabled for them. * * If devices still want to use this (at their own risk), they will * have to use the quirk HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE, but * the default should be a reliable mapping. */ while (usage->code <=3D max && test_and_set_bit(usage->code, bit)) { + if (field->application =3D=3D HID_GD_JOYSTICK && usage->code =3D=3D KEY_= RESERVED) + break; + if (device->quirks & HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE) { usage->code =3D find_next_zero_bit(bit, max + 1, @@ -1455,6 +1464,12 @@ static void hidinput_configure_usage(struct hid_inpu= t *hidinput, struct hid_fiel if (usage->type =3D=3D EV_KEY) { set_bit(EV_MSC, input->evbit); set_bit(MSC_SCAN, input->mscbit); + + if (field->application =3D=3D HID_GD_JOYSTICK && + (usage->hid & HID_USAGE_PAGE) =3D=3D HID_UP_BUTTON) { + set_bit(EV_BTN, input->evbit); + ++input->button_count; + } } =20 return; diff --git a/include/linux/input.h b/include/linux/input.h index f6389de4a4d1..7f39c663fa85 100644 --- a/include/linux/input.h +++ b/include/linux/input.h @@ -214,6 +214,8 @@ struct input_dev { }; #define to_input_dev(d) container_of(d, struct input_dev, dev) =20 +#define INPUT_MAX_BUTTONS 2048 /* A sane limit of supported device buttons= */ + /* * Verify that we are in sync with input_device_id mod_devicetable.h #defi= nes */ --=20 2.52.0