From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 920B232FA0D for ; Thu, 20 Nov 2025 10:55:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763636108; cv=none; b=r33QnlFj4A2ktNkb6ii0d0cWOSbg5kDWUVsk3TILbkst5GfOsuVXYEm3f7xD41EYzt4wPrVbciFbJjaILWEOPqg2qwrqlcEBk7krBI5kWJ1P6LbEelh/43XpA/F7dxGOnXGGXc3bCN99U+8hlSdcxNodbgpLGnEXtiGi5aRkBk8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763636108; c=relaxed/simple; bh=fdTVQGLc+cow9CihJGh/wotiz2R70DYSEcKQgAa4kTQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=sWIMSoADK51GRl1cp1s+MnBwNPDh6RcIB+cxcEIOILnHa2NeqOFdpBM2jXaOXYgg+hU1WRmWQqZA8Ry3RYPk1ACwzuBcuk0Zr/InCoRRJrzZrJB5ZlXF/gphslsvpVWFwkMYzODJhOSihnJdemT17P7arJ2DhYuB2ujQqbV8VyE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RXG8Vfhs; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=n1Fx5w9B; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RXG8Vfhs"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="n1Fx5w9B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763636104; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=mIehiDrNGkkZ06kT+cUGnm015h0IlinjcUbP3NML4m4=; b=RXG8Vfhs+ZtQM3Obwb+4ki4xMwNN6PvzGH+IGIkOo28Z+hdI49udkl1n1Cpl+Q/+6TMdM0 WEMSR3Yvg6KeJj9GN4jsp+A4bZD0OVlvkpyUk0W/ZLXs2eIb5BvmU8512YfFN1Zg0jPUlc rI1KKaQ4Y4aIagN8uqW69jE69epew0w= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-hL3rNOn-Oq28RL7HBBS_jQ-1; Thu, 20 Nov 2025 05:54:47 -0500 X-MC-Unique: hL3rNOn-Oq28RL7HBBS_jQ-1 X-Mimecast-MFC-AGG-ID: hL3rNOn-Oq28RL7HBBS_jQ_1763636086 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-37ba9fcc1b3so4434421fa.2 for ; Thu, 20 Nov 2025 02:54:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763636086; x=1764240886; 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=mIehiDrNGkkZ06kT+cUGnm015h0IlinjcUbP3NML4m4=; b=n1Fx5w9B+AImogO7Q2FHz0MHikIu03g0s0gmrP3cF2meepOTLNeXrpkuKE3rvXqTsm Ko2lTmLQGL5rZSM260vzh43QNxpu6Qj2MH+bQZnc4EnvwH8d0p1AjVe+vC2yPs04Gj3U lII1wBeeEnoHfK7cs5Q7G/Bld0OTBcvqhPhXC5SuR9tc0b3v6AvC1+4hDWwGfvgcxehp ibcKlWkLeIkcGUifH6gubMRI1M//+I2e/azt8kg+pbBiL1NoGqmRIWdxoPHmRmQANlir AuMZRmGvBxdOH49Vza5DTYTNTGfDF/BA0XnYt8p89pYWKsk6qlU8A73dJsbVwBxOUU5d Jvvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763636086; x=1764240886; 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=mIehiDrNGkkZ06kT+cUGnm015h0IlinjcUbP3NML4m4=; b=SGGL9BRJ72i/fifnBZez4KySVaVnk13a8XIoehfxnL0iFDonfXPRtSwCsAbmhycXQr SwZIVfXdotsZgDvHmcGJI3pz+bK7xVueM6YFOwjTDInVLSzPyYgQvHf1drUpuDK4g4v9 Pin/vs/LdgE3IxaT8s6tfso41RAV9xgyJXeN74GzmasM4VlArlWQZIr8Mr3EN+Exde1L DuU0kgtpK6Um+/uwhENQ+1rOqQzEq/INEWvUUKVmVB0FYKL7CF4lGZMtNDn6jQGqYWXp 5XlmDlQtxt2O9ghhuatqzvpIZfZ/zkltpxOV2d/EA+KPSRoPzDX74TeA+ipyneSMBp7Y q9pQ== X-Forwarded-Encrypted: i=1; AJvYcCWHo/YpjNpxCo/RGHDgbr4MbdEdE4EVE/9yNCCDpJLgorDRHNmHj3/QLhlUSb2p22TyMJrDrI4zz2bART4=@vger.kernel.org X-Gm-Message-State: AOJu0Ywp24hR8pXGjiJX33vKsoDZWLvQ8/35x52r13R+1nBfktggG0bz T20Ekv5KuMBC5+S/ZCTCF8gL4vIm45zJ3fI06tNOWyiWvxrb7ktjMHLfjeRaTCqyH1hIJCsv0Pv eSMqgZxnYZLmIa4+/X3iGyJNImUFmxB8xJjgNz+wGDfKykymYr3H2ihvI/aVHv21nRQ== X-Gm-Gg: ASbGncvdw308T7PtG5DPQd5VWNTJCvIbxOHJ95fs9Zl5S3O3hYIX5D9MVsXnB95ps8I OPc1X24gIJVYZv550CB1btmATJV6F9h0b/M6aISwsHAlOql1U8zL7vpPxTSdv75Oj70VHgTydHv 4xCb9a4aAjwhC8jQZwF6bCgFKtNGBhyXshCduu1V0MUNJy05Rg36an7FOVno8PECXkX88SINMDW zdrzrRvgmwNPdw4iY0ubt3uyWg2hEkgxPh/o7MC4bm9A64TlRw8JADkHR1e4Yr+NIdWn3tllCr0 sYrR5Ogkxgwko2XprHdgwr3VriQBsYe236/Asmrj/Mllh7ZOW7UOOc4jH59c/06rXQK2z5WTtIM pn6RxjgxdsGAb9CNYWESZakZjO6/XAhLA8CzhmbaBGFmvb+K68EIL5hxR2/m6GwhzVSE4uivl8P 02gJYaDTY= X-Received: by 2002:a05:6512:68f:b0:595:9d90:5dc8 with SMTP id 2adb3069b0e04-5969e327c18mr844825e87.49.1763636085821; Thu, 20 Nov 2025 02:54:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6PKZ/bmOk5ANU7D0YAMfciYDBFzN1/1j3WbPaFTEv1TVjSa/sX40erTY5hJ2gSBAt3tFwKg== X-Received: by 2002:a05:6512:68f:b0:595:9d90:5dc8 with SMTP id 2adb3069b0e04-5969e327c18mr844808e87.49.1763636085299; Thu, 20 Nov 2025 02:54:45 -0800 (PST) Received: from sissix.redhat.com ([2a06:5900:814a:ab00:3725:2991:6cf3:b3aa]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5969dbbefb8sm578218e87.46.2025.11.20.02.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Nov 2025 02:54:44 -0800 (PST) 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 v4 0/1] HID: Add support for multiple batteries per device Date: Thu, 20 Nov 2025 10:54:38 +0000 Message-ID: <20251120105442.150508-1-lzampier@redhat.com> X-Mailer: git-send-email 2.51.1 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. The implementation is fully backwards compatible with single-battery devices through a helper function. ## 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 (1): HID: input: Add support for multiple batteries per device Signed-off-by: Lucas Zampieri 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 | 196 +++++++++++++++++++---------------- drivers/hid/hid-magicmouse.c | 10 +- include/linux/hid.h | 54 +++++++--- 6 files changed, 187 insertions(+), 126 deletions(-) base-commit: 0678f5630429a5049d7663703b897e1bf8d13cd1 -- 2.51.0