From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 651A6218ACC for ; Sat, 14 Mar 2026 01:05:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773450341; cv=none; b=GOaY4jA/vlJlrChx2UESTEbpP2rGU2Vt5O64rU76x+gtc+ShNBo90n6NMzkJ3R5q0g1wGcCfCI5cNpmxJceOLPSb2pjcRLrAOl9S/BkNMuugIBaSCLAZW70dkPxpyriU1KTE4O09CApAmjyU1Ta6Vy9caeAqhn3VpbVMWGP0tJk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773450341; c=relaxed/simple; bh=QD8IJvX9VZieY8pcCZGgkNtS+hRqgT9Cvfmiv+Ifzpk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JCFF2pRH576DimE/iQ3PTDgRTMas7EedEbFKJ/YvQ+79EvNLOYslxcSKnLXULbbhGAo3cuQIikchvPWT8p6rWoVqULxiwFPhLQgxTt4V1qNWnd6LRWgrqP73L/9m/FBj6X/W4XENoWPOuQ5FcSoVG9hKj/goZE4MapaP0sw2Dn8= 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=JlQ8RUXW; arc=none smtp.client-ip=209.85.128.47 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="JlQ8RUXW" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-48334ee0aeaso25413235e9.1 for ; Fri, 13 Mar 2026 18:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773450337; x=1774055137; 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=6QzqL9Iv/Ww5wZvqSt/AhzZpe019G8OQviCfvAtV7Bk=; b=JlQ8RUXWJvqb+IZIm5avISRcPAjnEkppax5N3f9nOhWetdXDezQggAiptkpRDbOd0V cx03xY+3cEq+ike2og0Br8YN/ylmMfWEcblCnfMZXHu1/QGRHGGCyiWzz+mmwcrG4t6+ 1OxXiZJUKzHPtiXnxYGLsKgUGG9FEWyA1jPGwectEIl2gjlyq5hMxOauEHlkUMGbY/OX dgP2VaPEboSMkhgP2FtTHB9yfCs1rG+AktGyVQNKBSe1zIiMdFJ/k94MR2wOG6wryEeE qccNocTPAEF5KYnCOLFgR8+QFiUzMcYvr3FRRT7JIrsBW6Vtr3XfLS1A4rZT8P3WSGGD PxJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773450337; x=1774055137; 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=6QzqL9Iv/Ww5wZvqSt/AhzZpe019G8OQviCfvAtV7Bk=; b=PVPcmsB0FzxCNPIKKjWf7jh0bIi/Z5RWER+4u4YuUAYvA3b8m+H22LfaxrixSi8X26 3tbX19su6E3uHsFCE6nIBj/SaDEptcPdPOX+QuJRVOaclvKJp+0uuWduB/cuS515+Hr+ JJQkqugJiomAaG4XB+WNnD1TQEVHKa1EZpJuHHLJbtRER2GYOk8W0jNe042hAme688TY W6RWuI4iHK8gjT7oQtCXiizxS4ci+3m28C9FHDJdqUiuukxNzfn7W9I0oZDSYXktZ6Jg Yr2vG1wmmdN67s7sRTj3TtU6D722I/NZc4DHiMZa9NTBZWPnt/tdcV4eQKTnuPyjnuMf uaJQ== X-Forwarded-Encrypted: i=1; AJvYcCUKXOKURfzE8KZ7c4mPEqURM6QXLz0KAOQpyLb/WbwLQgptOXQrcLTk1qWEDMp7eTfwVADGVDKXV10H5YU=@vger.kernel.org X-Gm-Message-State: AOJu0YwrBJJASG2qmapz/BzyA3MBA08gu4j3eHsJggdtc54zFjbdI1nz MdKxV67MDLX+cfJEtp/TNgYVU7qcPZrIgvUtpYfRORJL8GAlTji8XnA= X-Gm-Gg: ATEYQzx77gqD5L3BuKciYbtjWkHeWe9H9UqdIA69OLwQPgLjB8tVPYgf13X25hc1aaz 1s6BPWK3BDiBp+W3gvrM6loPmRi/BgLpnJfI/KyEywpw0ykOcNAaL4QxIesKAsAvV+PEL1rvrNl yIxSs4bbHxiSWhozSEZhr+ft0tMIbFTv6lgZULOlJdYsxAyjT/qYUXJShyEOVZXSrkjlomgGDtr 2J/92l67jCVT2DvxCPlaHaU2Q6zkrvUOmcknzM7JLyyu+vO7jlDn8d7D8pvmpDToNkkBXiqAQL/ XQWHitxM+2NfKzUkN7/c3jg/COFX9gTuRUSr9/NGwOLUE76we+9y/m7PpEZmIWf0Gp8TiEfz/mv 8EJbu/xWhk5wPOUFKe6jtwdgN0k3hp4fwrrqbIb2FTl37+hbZ2VT72+GYBoj3G3NyYiNv3Id1Sm 8rk8p0EzbVWGGYBTcZSOqk4gJS2G6oJwwv2MdrY4YNanezhs/k/r4NZrHGPUo5kcW0YltRASmeX MIsHd4aM6i3Zu97ga5dSdXoDdGdPf8U8tNfmvP46+TY7xdtZAXFXbZW9NVHAQ/TzMBAPU8kSXvk WK9Dd0ymCX67WyQ= X-Received: by 2002:a05:600c:46d2:b0:485:3a03:ced1 with SMTP id 5b1f17b1804b1-4855672737fmr91652075e9.28.1773450336455; Fri, 13 Mar 2026 18:05:36 -0700 (PDT) Received: from sissix.lzampier.com (92.40.172.137.threembb.co.uk. [92.40.172.137]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43a03cfd18fsm13059963f8f.36.2026.03.13.18.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2026 18:05:36 -0700 (PDT) From: Lucas Zampieri To: linux-input@vger.kernel.org Cc: Lucas Zampieri , linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Sebastian Reichel , Bastien Nocera , linux-pm@vger.kernel.org Subject: [PATCH v7 0/3] HID: Add support for multiple batteries per device Date: Sat, 14 Mar 2026 01:05:27 +0000 Message-ID: <20260314010533.110278-1-lcasmz54@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series adds support for HID devices with multiple batteries. Currently, the HID battery reporting subsystem only supports one battery per device. There are several devices with multiple batteries that would benefit from this support: - Gaming headsets with batteries in both the headset and charging dock - Wireless earbuds with per-earbud batteries plus charging case - Split keyboards with per-side batteries ## Proposed Solution This series introduces struct hid_battery to encapsulate individual battery state, replaces the old battery fields with a list-based approach, and adds support for multiple batteries tracked within struct hid_device. Batteries are identified by report ID and named as hid-{uniq}-battery-{id}. The implementation is fully backwards compatible with single-battery devices through a helper function. The series first converts the battery code to devm_* as preparatory cleanup, which simplifies the subsequent refactoring and reduces risk of memory management bugs. ## Testing Tested with split keyboard hardware (Dactyl 5x6) using custom ZMK firmware that implements per-side HID battery reporting. Each battery (left and right keyboard halves) reports independently through the power supply interface with distinct report IDs (0x05 and 0x06). Test firmware available on my personal fork at: https://github.com/zampierilucas/zmk/tree/feat/individual-hid-battery-reporting If this series gets merged, these changes will be proposed to upstream ZMK. HID descriptor and recording captured with hid-recorder: D: 0 R: 162 05 01 09 06 a1 01 85 01 05 07 19 e0 29 e7 15 00 25 01 75 01 95 08 81 02 05 07 75 08 95 01 81 03 05 07 15 00 25 01 19 00 29 67 75 01 95 68 81 02 c0 05 0c 09 01 a1 01 85 02 05 0c 15 00 26 ff 0f 19 00 2a ff 0f 75 10 95 06 81 00 c0 05 84 09 05 a1 01 05 85 85 05 09 44 15 00 25 01 35 00 45 01 75 08 95 01 81 02 09 65 15 00 25 64 35 00 45 64 75 08 95 01 81 02 c0 05 84 09 05 a1 01 05 85 85 06 09 44 15 00 25 01 35 00 45 01 75 08 95 01 81 02 09 65 15 00 25 64 35 00 45 64 75 08 95 01 81 02 c0 N: ZMK Project Dactyl 5x6 P: usb-0000:2d:00.3-4.2/input2 I: 3 1d50 615e D: 0 E: 0.000000 3 05 00 56 E: 0.000977 3 05 00 56 E: 1.490974 3 06 00 52 E: 1.491958 3 06 00 52 E: 6.492979 3 06 00 53 E: 6.493962 3 06 00 53 The recording shows both batteries reporting with different charge levels (Report ID 05: 86%, Report ID 06: 82%-83%), demonstrating the multi-battery functionality. This can be used to verify UPower compatibility. ## Future Work: Userspace Integration As suggested by Bastien, semantic battery differentiation (e.g., "left earbud" vs "right earbud") requires userspace coordination, as HID reports typically lack role metadata. This will require: 1. systemd/hwdb entries for device-specific battery role mappings 2. UPower updates to enumerate and group multi-battery devices 3. Desktop environment changes to display batteries with meaningful labels This kernel infrastructure is a prerequisite for that userspace work. Lucas Zampieri (3): HID: input: Convert battery code to devm_* HID: input: Introduce struct hid_battery and refactor battery code HID: input: Add support for multiple batteries per device Signed-off-by: Lucas Zampieri Changes in v7: - Rebased on top of hid.git for-next branch as requested by Jiri - Adapted to new battery_present field and HID_BATTERY_QUIRK_DYNAMIC quirk introduced upstream - Adapted to kzalloc_obj() -> devm_kzalloc() and __free(kfree) cleanup guard changes in upstream Changes in v6: - Split v5 patch 2/2 into two separate patches as suggested by Benjamin: - Patch 2/3: Introduce struct hid_battery and convert existing code (no functional change for single-battery devices) - Patch 3/3: Add multi-battery list support - Renamed hid_get_first_battery() to hid_get_battery() as suggested by Benjamin - Added devm_kfree() calls in error path of hidinput_setup_battery() for proper cleanup if devm_power_supply_register() fails Changes in v5: - Split the monolithic v4 patch into two logical patches as suggested by Benjamin, devm_* conversion, then struct refactor and multi-battery support combined Changes in v4: - Added missing hidinput_update_battery() stub in #else block for CONFIG_HID_BATTERY_STRENGTH=n builds - Reported-by: kernel test robot - Closes: https://lore.kernel.org/oe-kbuild-all/202511201624.yUv4VtBv-lkp@intel.com/ Changes in v3: - Squashed the three v2 patches into a single patch as suggested by Benjamin - Removed all legacy dev->battery_* fields, using list-based storage only - Changed battery naming to include report ID: hid-{uniq}-battery-{report_id} - Converted battery memory management to devm_* for automatic cleanup - Updated hidinput_update_battery() to take struct hid_battery directly - Added hid_get_first_battery() helper for external driver compatibility - Updated hid-apple.c and hid-magicmouse.c to use new battery API - Simplified cover letter based on feedback Changes in v2: - Split the monolithic v1 patch into three logical patches for easier review: 1. Introduce struct hid_battery (pure structure addition) 2. Refactor existing code to use the new structure (internal changes) 3. Add multi-battery support (new functionality) - Added detailed testing section with hardware specifics - Added hid-recorder output (dactyl-hid-recording.txt) demonstrating two-battery HID descriptor for UPower validation - Added "Future Work: Userspace Integration" section addressing Bastien's feedback about semantic battery differentiation - Added hardware examples with product links to commit messages (per Bastien's suggestion) - No functional changes from v1, only improved patch organization and documentation drivers/hid/hid-apple.c | 10 +- drivers/hid/hid-core.c | 4 + drivers/hid/hid-input-test.c | 39 ++++--- drivers/hid/hid-input.c | 197 ++++++++++++++++++----------------- drivers/hid/hid-magicmouse.c | 10 +- include/linux/hid.h | 57 +++++++--- 6 files changed, 186 insertions(+), 131 deletions(-) base-commit: 73965d0aefc8ef6504552e5805f645d58a8727b0 -- 2.53.0