From nobody Tue Dec 9 02:54:12 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 DAB5C36124 for ; Thu, 13 Nov 2025 00:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762992920; cv=none; b=VGdJC3zEb7u5FVtlybIizhkDdqC7e+ADPFkZb2KhSvR9YcQODBRv1IPHHrGy561+/9+iZGUJTdsSPaCJz3XjiqeXnPTYEU4xMRhiNb8jNIxY0MmgyMn3YLlu/U/4mtbIJ3QRxnziOsTGy6m1bkOsn48ooLN7Fgtt3XmArqfTHck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762992920; c=relaxed/simple; bh=ydcwlK/oAd5xKfTx+JL5DKXX5NzldMKD7eXI7AFie1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K5iI9ODXgFPoJD2K3OdjzADSoqNmzBOZkfkV6Pqk5gLIASSMC1THC9siSZnSdcKXlczg3XG8TyZpBFcuJjq8aUs4O9I/8UFaxWp3ezLvaC7/wdLjySt+HMZK+09eL0MvB69zdU6xjAebaV6JdLnP4b1h7r3WSahfWDKZvt2IdAY= 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=K+34FNMk; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=HaKbi++R; arc=none smtp.client-ip=170.10.133.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="K+34FNMk"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="HaKbi++R" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762992917; 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: in-reply-to:in-reply-to:references:references; bh=TDL7LoYP5gq9XMI4WP3Ykdi7uKdtvjM1bMJQ7leEYXw=; b=K+34FNMktdluipXabuCgWUJDAUoyHncbv/r+RD8nKNfEhXAmpdRBSd0dnOZ+Mu4rGBH5vK TZ3bcC87yaFcHQr9jcQRvQKywNemk0ujqw9Jk/nHo/ZPCWiAc8DvhsiPh782xUZeH2bS9U O3SGtKwEsFThjhFeXitWiE4qD+K2W5k= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-GexhWx9dPCOEzcWZCsqqOg-1; Wed, 12 Nov 2025 19:15:16 -0500 X-MC-Unique: GexhWx9dPCOEzcWZCsqqOg-1 X-Mimecast-MFC-AGG-ID: GexhWx9dPCOEzcWZCsqqOg_1762992915 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-47777158a85so2539455e9.3 for ; Wed, 12 Nov 2025 16:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762992915; x=1763597715; 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=TDL7LoYP5gq9XMI4WP3Ykdi7uKdtvjM1bMJQ7leEYXw=; b=HaKbi++R60K0/KueJmIxlS7t/IVYai39FyTNO31Wdao9i8mHLOSIOZJgB9s20IfBr0 Trasm41BzoJooztcYlb8PJQbwkAi1tAjk51oFzZYmjxCbw1ymLaqYE1iUYsp9kp8Qx6l KxD5NkPRjrWTbY6XSY/3XExgtb+TDvv7TS/++1uxrZLwiiNm6JHXgoLd/rMI+oZTZn+K sdi27i3LYccA+XFdb4/UPzH8Ixpkqgu0Ty2sSJR1bdHyczMlajPDyiCB0WkpVZTa4uEv 2cWNbbkQDx9gnn3/P7fjBajFeQjQVwBQvxRFosazcuLM2hsSMhjDNRm5d7+m+pgsmbvv oKuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762992915; x=1763597715; 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=TDL7LoYP5gq9XMI4WP3Ykdi7uKdtvjM1bMJQ7leEYXw=; b=e3w9d6qy9QfK6jLpJTdYtGDl0u1KWp9oJwJZmcPmva5bnkrkE9LxgvyoplA6cfomn+ LZTiGgGIZmzeKz+WfeZkg999kEnKy9U0pRANSUVQ4DGX7zKG72wyk5ubYu1KmFwYT7/p B23b7RWjrYjtcN8I7R5wHpvaKjJmei9U6eB7HOiPQobf86sFgcckrekF2iR9LVeHZrsi XFsAUNqrTFWqflgAPc/2j3Afpxf8iK+QWfTTKueFQLqxo+NhQzln8S8gwYcSfEiEYP6D wkPfQIT2I/2X2OdItcHZ3y8Qk2R4zAr/luq0vQBACUebXQ8bPlgLlq+oAI9KBUgBAHg+ WJug== X-Forwarded-Encrypted: i=1; AJvYcCUFLeHsqIVbPBl6rfbn/VXLzfty/UNCRKK2pDkQn0sQ4wbymCxTCv/gKIl/NehDPRKoMKPMloGiRaFUSUY=@vger.kernel.org X-Gm-Message-State: AOJu0Ywa18op59NB15AKzl3lAn2NuU39UprbgE8ujV26jjCXwaLRKtig nnJAv4oHKU5rQ13qLDnTnqlNcw/g3OG+J9pb2uOvszia/4XT8ln7ZSmQuZBPCL7CT+vkjIF4XpR +0LtwY06M6Tfc4VGZhXKCX/uHNrtfRQ9EDCcO+SSlxt/DMe+gXR+C49PM91PXIbiOfw== X-Gm-Gg: ASbGncsMglHYxINEiitQqdMEZ3AOVOGaJkndN5PVALC1JYy9v/6JcrI3SugBWpokJ84 IGpb55F6pmyg6lZb7HpKoozgaQn7YJ36RD8svfRykwdsQWX488wL3PFCNLI1xm6A+bbGhs0hZ/v XY5044hQVOZFRtYV01kVKYYMXNgCakmfRacUSz4ON6ir0YLfZJhYSmdWNNwRr+w2mjFGV8mr63A hnwX3FwyqdBqoXuVDQ8FiCdnHCECRgXEoLoJtJrGrbrAdpiSH7jAe7xGBiqsBM5lBRumKBD/Wap 3Ait69hppc8Li124E+K8ouz55aXzxnl1p8t5T2I7KMRLhNmbfcbmcTCVFJK4PpPk9WMtmqZWEaf H5wPSIQNVUAwZtg== X-Received: by 2002:a05:600c:1ca5:b0:477:c37:2ea7 with SMTP id 5b1f17b1804b1-47787093944mr51874555e9.21.1762992915198; Wed, 12 Nov 2025 16:15:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IH44t5VADhoiFQdYlbkmvZ6vHu5ra7JAo9+e2PeUxapHpCteCkYYf67077+vK51LHvqgAh/8w== X-Received: by 2002:a05:600c:1ca5:b0:477:c37:2ea7 with SMTP id 5b1f17b1804b1-47787093944mr51874445e9.21.1762992914844; Wed, 12 Nov 2025 16:15:14 -0800 (PST) Received: from sissix.lzampier.com ([2a06:5900:814a:ab00:3725:2991:6cf3:b3aa]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53f0b589sm432983f8f.23.2025.11.12.16.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 16:15:14 -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: [RFC PATCH v2 1/3] HID: input: Introduce struct hid_battery Date: Thu, 13 Nov 2025 00:15:03 +0000 Message-ID: <20251113001508.713574-2-lzampier@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251113001508.713574-1-lzampier@redhat.com> References: <20251113001508.713574-1-lzampier@redhat.com> 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" Add struct hid_battery to encapsulate battery state per HID device. This structure will allow tracking individual battery properties including capacity, min/max values, report information, and status. The structure includes a list node to enable support for multiple batteries per device in subsequent patches. This is a preparation step for transitioning from direct power_supply access to a more flexible battery management system. Signed-off-by: Lucas Zampieri --- include/linux/hid.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/linux/hid.h b/include/linux/hid.h index a4ddb94e3ee5..63422130de20 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -634,6 +634,36 @@ enum hid_battery_status { HID_BATTERY_REPORTED, /* Device sent unsolicited battery strength report= */ }; =20 +/** + * struct hid_battery - represents a single battery power supply + * @list: list node for linking into hid_device's battery list + * @dev: pointer to the parent hid_device + * @ps: the power supply device + * @capacity: current battery capacity + * @min: minimum battery value + * @max: maximum battery value + * @report_type: type of report (HID_INPUT_REPORT, HID_FEATURE_REPORT) + * @report_id: report ID for this battery + * @charge_status: current charge status + * @status: battery status (unknown, queried, reported) + * @avoid_query: if true, don't query battery (wait for device reports) + * @ratelimit_time: time for rate limiting battery updates + */ +struct hid_battery { + struct list_head list; + struct hid_device *dev; + struct power_supply *ps; + __s32 capacity; + __s32 min; + __s32 max; + __s32 report_type; + __s32 report_id; + __s32 charge_status; + enum hid_battery_status status; + bool avoid_query; + ktime_t ratelimit_time; +}; + struct hid_driver; struct hid_ll_driver; =20 --=20 2.51.1 From nobody Tue Dec 9 02:54:12 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 870A87081A for ; Thu, 13 Nov 2025 00:15:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762992923; cv=none; b=Y3Enu8aD1Gj6t/K6vsaWB5BDxlzmYc+Lj916GDe0ZjbgGJ7/5rVINc7AYDC0N3lI6K6KBSD1cCua5/8ZcFqj1sTQV2XcAfl+AJ5Ufsev2bbJ22grkOvIGne8WkXcU/RRYCHGNbwEAlMLGEVdMpXhCMxqsPtOpzzt2H7cHScASUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762992923; c=relaxed/simple; bh=iFZsqRH5eByoiejBJe2tCpiSPFSMdpwxoI77YoyNZXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V2sWWjVHioya2K58b99rH7CIw5tL3+NfkT5pKtkm5mJEl0cqQzmh4apZGONsBh+EOCklRiN3Q8XoaQqzUOXG28VoCFFq3nqSHR4kTGcAoAvIVWbri9swjddJ22FA2lDQn7eUesnUQFeJi8FqWg9e2UWZ1eHSOvQelK+MddN110o= 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=YaXiyMzl; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=DAQSbhmH; arc=none smtp.client-ip=170.10.133.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="YaXiyMzl"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="DAQSbhmH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762992919; 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: in-reply-to:in-reply-to:references:references; bh=+jraoxNmzCzqfQSJ06TY8sylDjJVSc0Y8i9xrHNp7CU=; b=YaXiyMzlTwPqGMpgc5eG83ZCjewJrPDw6X6NugAiccE3WwtFhxfSVZYaxStf+RxSSDA0O1 zkY0LpIPkya3lYaQDD9f2zoOZXUkrxqPCa7LaIrAKD/dmEHnwZipmU3Cug4Bq+pKMZDdcI dEKggD8T12UvY4QtxnfXJ2Q6GU3PgBc= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-284-K5FGzC7BPHWhlzKfqFb0Rw-1; Wed, 12 Nov 2025 19:15:17 -0500 X-MC-Unique: K5FGzC7BPHWhlzKfqFb0Rw-1 X-Mimecast-MFC-AGG-ID: K5FGzC7BPHWhlzKfqFb0Rw_1762992917 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-47788165c97so1545865e9.0 for ; Wed, 12 Nov 2025 16:15:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762992916; x=1763597716; 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=+jraoxNmzCzqfQSJ06TY8sylDjJVSc0Y8i9xrHNp7CU=; b=DAQSbhmH4LFfl+xKyVqupVADAuiQCm5i9F0DH6OFP7I/TliDuFJX2EnCsG8UUXsY3Y VZSPC4q34Q9CDDeR8BfcEDMmKYXm4mp2kZACoa4Elnv8L5GfXS23b1Qqr0zX/FEum9YF chVRKzWj354uCTjY05w5ctSV8gY4ktqdpZSoSAu1ClXDEvXSZ4ymWSju59Ulkq/pRTv7 Yo2fv2quRqcyx6Q0KAFGfU9JfHdvIg1ZKTTuoAdT2Qvn/7K7FSJkUlspKNz59eZvYDCL PP83+AMPE+8HcFyAWkDUTJLQbd73KoXG0zYpk1z82d07LUn2o9KEzXtEC65Bu5/UmkcM tCIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762992917; x=1763597717; 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=+jraoxNmzCzqfQSJ06TY8sylDjJVSc0Y8i9xrHNp7CU=; b=GTyeo22dXDoJ+prrTUuR8PrqvJISNg5VB8cS6dKgzINQpVCwRFa2LF+AxhySACnFhn YRx+/rXdAELJ1KegHwvyy/endeNA2W/uKmVk+4noMCacBpu8RZcKzm6BWVSaoHoYXdjx d4fEJfIQTEYfXStvwIWGmwpplv+YMStqefnTUpq5Zb+ncfSWsbnNyTszhXdZ2Tnyd62o UwC8zbZ0Uo6++vdlUm6ngWt8nNfsh7UXqy/M6e7zGxBOEaV72Ouj2vqq2BwMiQG09V9p dI+SYeJnK+FGHHaULTqNYjeZBteaifg+9t/h38ce+azp7BZFLdy0A5/aWLFXX1LnZrDB 3Ahg== X-Forwarded-Encrypted: i=1; AJvYcCXDouUmlaUUayrooSIKBRwQlVnDHtDOxzpqiDP15vHw1HPU1qK7upCfFfUkHS7Im+6p81+qqJrBgqscnBQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yyai3xT674jRePhdzq7y9o4MLxLO2U9qhi3Ybg0onUDxv6hJdrg vKYfEpaBA7vjwzgmtfWVUmZn+vp1qP+4cD6imGhtzcQrIGRI20MvwOpaeHGKPfC7E4kmbY6AoQI yRR6HKBXXVwWh0/k+WaiWHfJ+YsM0xyVkT0hUidBlcBgidLEDiWCZA74LyHGoRo1SwQ== X-Gm-Gg: ASbGncuAw7ZA0LpYIpUvPHipuewe1bZqCBsXqJlYUU5deErGiuTk0/9mw99YMlFzeSP qJEfrEaUrRmESCxTl398Yp7opDj6prxl8TI+tmD/gunj+Is5BVQxnHjv4BMXGmOkUkcxB0qaaDx lmII3Te7b1uzLJoIVFQfl99KFy7Ccd/4NGPBK4SYMiZFn4BFje5DAVAqCLaJCKR8UpSJWanMVQx mpgNwRY6DNmPSbBQuPOZfr4OTg7ryRf7U2s1PChLDIBqHesQrzT/wQN4bDSy0cZiMtRtIbfCbHi xaciCoL1tYF7gJKklePztyIQ3OUsaUoob4nGzSa5DPKMx1yaIiYc3SzTXuHgbQGdeiCq+dHIfl0 cjsV5v24kOcij/Q== X-Received: by 2002:a05:600c:138a:b0:477:19b7:d3c0 with SMTP id 5b1f17b1804b1-4778703d63emr49826545e9.2.1762992916536; Wed, 12 Nov 2025 16:15:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqqQ7G2RU6cj93XJDUMviHL5Kr7pxCjAO+RqdjhI94usTzWHkoFMclayr8p3zMJ/v1JLLkIQ== X-Received: by 2002:a05:600c:138a:b0:477:19b7:d3c0 with SMTP id 5b1f17b1804b1-4778703d63emr49826415e9.2.1762992916150; Wed, 12 Nov 2025 16:15:16 -0800 (PST) Received: from sissix.lzampier.com ([2a06:5900:814a:ab00:3725:2991:6cf3:b3aa]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53f0b589sm432983f8f.23.2025.11.12.16.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 16:15:15 -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: [RFC PATCH v2 2/3] HID: input: Refactor battery code to use struct hid_battery Date: Thu, 13 Nov 2025 00:15:04 +0000 Message-ID: <20251113001508.713574-3-lzampier@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251113001508.713574-1-lzampier@redhat.com> References: <20251113001508.713574-1-lzampier@redhat.com> 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" Refactor the battery handling code to use the newly introduced struct hid_battery internally, replacing direct access to individual power_supply and state fields. The legacy dev->battery and dev->battery_* fields are maintained and synchronized for backward compatibility. This refactoring prepares the code for supporting multiple batteries per device in a subsequent patch. Signed-off-by: Lucas Zampieri --- drivers/hid/hid-input.c | 125 ++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 42 deletions(-) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index e56e7de53279..0e71efea9da3 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -454,7 +454,8 @@ static int hidinput_get_battery_property(struct power_s= upply *psy, enum power_supply_property prop, union power_supply_propval *val) { - struct hid_device *dev =3D power_supply_get_drvdata(psy); + struct hid_battery *bat =3D power_supply_get_drvdata(psy); + struct hid_device *dev =3D bat->dev; int value; int ret =3D 0; @@ -465,13 +466,13 @@ static int hidinput_get_battery_property(struct power= _supply *psy, break; case POWER_SUPPLY_PROP_CAPACITY: - if (dev->battery_status !=3D HID_BATTERY_REPORTED && - !dev->battery_avoid_query) { + if (bat->status !=3D HID_BATTERY_REPORTED && + !bat->avoid_query) { value =3D hidinput_query_battery_capacity(dev); if (value < 0) return value; } else { - value =3D dev->battery_capacity; + value =3D bat->capacity; } val->intval =3D value; @@ -482,20 +483,20 @@ static int hidinput_get_battery_property(struct power= _supply *psy, break; case POWER_SUPPLY_PROP_STATUS: - if (dev->battery_status !=3D HID_BATTERY_REPORTED && - !dev->battery_avoid_query) { + if (bat->status !=3D HID_BATTERY_REPORTED && + !bat->avoid_query) { value =3D hidinput_query_battery_capacity(dev); if (value < 0) return value; - dev->battery_capacity =3D value; - dev->battery_status =3D HID_BATTERY_QUERIED; + bat->capacity =3D value; + bat->status =3D HID_BATTERY_QUERIED; } - if (dev->battery_status =3D=3D HID_BATTERY_UNKNOWN) + if (bat->status =3D=3D HID_BATTERY_UNKNOWN) val->intval =3D POWER_SUPPLY_STATUS_UNKNOWN; else - val->intval =3D dev->battery_charge_status; + val->intval =3D bat->charge_status; break; case POWER_SUPPLY_PROP_SCOPE: @@ -513,8 +514,9 @@ static int hidinput_get_battery_property(struct power_s= upply *psy, static int hidinput_setup_battery(struct hid_device *dev, unsigned report_= type, struct hid_field *field, bool is_percentage) { + struct hid_battery *bat; struct power_supply_desc *psy_desc; - struct power_supply_config psy_cfg =3D { .drv_data =3D dev, }; + struct power_supply_config psy_cfg; unsigned quirks; s32 min, max; int error; @@ -530,16 +532,22 @@ static int hidinput_setup_battery(struct hid_device *= dev, unsigned report_type, if (quirks & HID_BATTERY_QUIRK_IGNORE) return 0; - psy_desc =3D kzalloc(sizeof(*psy_desc), GFP_KERNEL); - if (!psy_desc) + bat =3D kzalloc(sizeof(*bat), GFP_KERNEL); + if (!bat) return -ENOMEM; + psy_desc =3D kzalloc(sizeof(*psy_desc), GFP_KERNEL); + if (!psy_desc) { + error =3D -ENOMEM; + goto err_free_bat; + } + psy_desc->name =3D kasprintf(GFP_KERNEL, "hid-%s-battery", strlen(dev->uniq) ? dev->uniq : dev_name(&dev->dev)); if (!psy_desc->name) { error =3D -ENOMEM; - goto err_free_mem; + goto err_free_desc; } psy_desc->type =3D POWER_SUPPLY_TYPE_BATTERY; @@ -559,63 +567,85 @@ static int hidinput_setup_battery(struct hid_device *= dev, unsigned report_type, if (quirks & HID_BATTERY_QUIRK_FEATURE) report_type =3D HID_FEATURE_REPORT; - dev->battery_min =3D min; - dev->battery_max =3D max; - dev->battery_report_type =3D report_type; - dev->battery_report_id =3D field->report->id; - dev->battery_charge_status =3D POWER_SUPPLY_STATUS_DISCHARGING; + /* Initialize battery structure */ + bat->dev =3D dev; + bat->min =3D min; + bat->max =3D max; + bat->report_type =3D report_type; + bat->report_id =3D field->report->id; + bat->charge_status =3D POWER_SUPPLY_STATUS_DISCHARGING; + bat->status =3D HID_BATTERY_UNKNOWN; /* * Stylus is normally not connected to the device and thus we * can't query the device and get meaningful battery strength. * We have to wait for the device to report it on its own. */ - dev->battery_avoid_query =3D report_type =3D=3D HID_INPUT_REPORT && - field->physical =3D=3D HID_DG_STYLUS; + bat->avoid_query =3D report_type =3D=3D HID_INPUT_REPORT && + field->physical =3D=3D HID_DG_STYLUS; if (quirks & HID_BATTERY_QUIRK_AVOID_QUERY) - dev->battery_avoid_query =3D true; + bat->avoid_query =3D true; - dev->battery =3D power_supply_register(&dev->dev, psy_desc, &psy_cfg); - if (IS_ERR(dev->battery)) { - error =3D PTR_ERR(dev->battery); + psy_cfg.drv_data =3D bat; + bat->ps =3D power_supply_register(&dev->dev, psy_desc, &psy_cfg); + if (IS_ERR(bat->ps)) { + error =3D PTR_ERR(bat->ps); hid_warn(dev, "can't register power supply: %d\n", error); goto err_free_name; } - power_supply_powers(dev->battery, &dev->dev); + power_supply_powers(bat->ps, &dev->dev); + + /* Maintain legacy single battery fields for backward compatibility */ + dev->battery =3D bat->ps; + dev->battery_min =3D bat->min; + dev->battery_max =3D bat->max; + dev->battery_report_type =3D bat->report_type; + dev->battery_report_id =3D bat->report_id; + dev->battery_charge_status =3D bat->charge_status; + dev->battery_status =3D bat->status; + dev->battery_avoid_query =3D bat->avoid_query; + return 0; err_free_name: kfree(psy_desc->name); -err_free_mem: +err_free_desc: kfree(psy_desc); - dev->battery =3D NULL; +err_free_bat: + kfree(bat); return error; } static void hidinput_cleanup_battery(struct hid_device *dev) { + struct hid_battery *bat; const struct power_supply_desc *psy_desc; if (!dev->battery) return; + bat =3D power_supply_get_drvdata(dev->battery); psy_desc =3D dev->battery->desc; power_supply_unregister(dev->battery); kfree(psy_desc->name); kfree(psy_desc); + kfree(bat); dev->battery =3D NULL; } -static bool hidinput_update_battery_charge_status(struct hid_device *dev, +static bool hidinput_update_battery_charge_status(struct hid_battery *bat, unsigned int usage, int value) { switch (usage) { case HID_BAT_CHARGING: - dev->battery_charge_status =3D value ? - POWER_SUPPLY_STATUS_CHARGING : - POWER_SUPPLY_STATUS_DISCHARGING; + bat->charge_status =3D value ? + POWER_SUPPLY_STATUS_CHARGING : + POWER_SUPPLY_STATUS_DISCHARGING; + /* Update legacy field for backward compatibility */ + if (bat->dev->battery =3D=3D bat->ps) + bat->dev->battery_charge_status =3D bat->charge_status; return true; } @@ -625,32 +655,43 @@ static bool hidinput_update_battery_charge_status(str= uct hid_device *dev, static void hidinput_update_battery(struct hid_device *dev, unsigned int u= sage, int value) { + struct hid_battery *bat; int capacity; if (!dev->battery) return; - if (hidinput_update_battery_charge_status(dev, usage, value)) { - power_supply_changed(dev->battery); + bat =3D power_supply_get_drvdata(dev->battery); + + if (hidinput_update_battery_charge_status(bat, usage, value)) { + power_supply_changed(bat->ps); return; } if ((usage & HID_USAGE_PAGE) =3D=3D HID_UP_DIGITIZER && value =3D=3D 0) return; - if (value < dev->battery_min || value > dev->battery_max) + if (value < bat->min || value > bat->max) return; capacity =3D hidinput_scale_battery_capacity(dev, value); - if (dev->battery_status !=3D HID_BATTERY_REPORTED || - capacity !=3D dev->battery_capacity || - ktime_after(ktime_get_coarse(), dev->battery_ratelimit_time)) { - dev->battery_capacity =3D capacity; - dev->battery_status =3D HID_BATTERY_REPORTED; - dev->battery_ratelimit_time =3D + if (bat->status !=3D HID_BATTERY_REPORTED || + capacity !=3D bat->capacity || + ktime_after(ktime_get_coarse(), bat->ratelimit_time)) { + bat->capacity =3D capacity; + bat->status =3D HID_BATTERY_REPORTED; + bat->ratelimit_time =3D ktime_add_ms(ktime_get_coarse(), 30 * 1000); - power_supply_changed(dev->battery); + + /* Update legacy fields for backward compatibility */ + if (dev->battery =3D=3D bat->ps) { + dev->battery_capacity =3D bat->capacity; + dev->battery_status =3D bat->status; + dev->battery_ratelimit_time =3D bat->ratelimit_time; + } + + power_supply_changed(bat->ps); } } #else /* !CONFIG_HID_BATTERY_STRENGTH */ -- 2.51.1 From nobody Tue Dec 9 02:54:12 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 7132913C9C4 for ; Thu, 13 Nov 2025 00:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762992923; cv=none; b=B4HHgO4v22fR28p7ezb1vDZ9BnZrIM5byyj3RM16imUJb05dQkV1ukShnvYkAweeyjiIesUL0Zg6hUM4cWvRrsPFvd9FGkN/ULGW3hhdEGJjUPE1PWco6x130+N2Jqr4v/x4qguiTAfrXD/e3CAReaWAcDtWIoGOD9Q2BQdITto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762992923; c=relaxed/simple; bh=rkZwVrkOadyDRR22lYKiSlNshpLUvze0UwNBJO2yDCE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tcqqrcjcqmAPP/la3a/435Q03qwOqDX1IByzuO4uxnai0wbXYHucs6rqqQDseOvW1fHlFYEdzhbm0ahjMKWspPQWEtRIZDSMFcSeIX/qHJaEGI78InrFRLdAuUCxDffVn2y0vDHwdWhPIGlYx9dJ6iMucfchCYyGoS4//MZZgAk= 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=QyRRBzY5; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=LPrwbDPU; arc=none smtp.client-ip=170.10.133.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="QyRRBzY5"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="LPrwbDPU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762992920; 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: in-reply-to:in-reply-to:references:references; bh=K1WcE71YI025D4IauzKZF0rnIgAKdLJAwYCr9A+FMYc=; b=QyRRBzY50+ZYtTIR8ZNS+gz3msSc0gwySrRFyXKr8xJPgcxSl13MZqPNHCif2gSSY2oZRx U4TyFZtMaQP+db8JK10FKNFEj6+qQkrQ142kd7fMY7WVKldpjeYLMqrnyYyftwHjvpHqaP GSvcr5Ze2kZ7VQ6R7fYLo/CPSxQ2SPY= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-sQ24RLi2MB-IlpfBis1FCQ-1; Wed, 12 Nov 2025 19:15:18 -0500 X-MC-Unique: sQ24RLi2MB-IlpfBis1FCQ-1 X-Mimecast-MFC-AGG-ID: sQ24RLi2MB-IlpfBis1FCQ_1762992917 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4776079ada3so1789195e9.1 for ; Wed, 12 Nov 2025 16:15:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762992917; x=1763597717; 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=K1WcE71YI025D4IauzKZF0rnIgAKdLJAwYCr9A+FMYc=; b=LPrwbDPURBroc32TcXP5i9B6kur4desTXNf1VtUtz6Sd9ihm5gSopv9C3x9XMW2UBS BEgY2k8Gg5xWkAmPfE2mAr6/2XYTZXyT/ZNL2+A8pJaeI4egiqXz6H+yijDycLJ+8jFF BFzCjQhLYAgwPqn8WCgD4irKWAmC0Tz3tkqQv6sh58d0pS+EKbsN+PyAu89SdIydq9Gh DRyxC12xE5ojceOnuZ96VBldcryNSDPS0Rz3fBlKl1n3OoVV9NUvdECpUsCWoDTiDqhg liBjj15CEpt6PO39M4Vq1YnEKqzr35C3VNmwMZa7YXys5BQKSCbVDooUq/tY6Cfwu2Mo tOog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762992917; x=1763597717; 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=K1WcE71YI025D4IauzKZF0rnIgAKdLJAwYCr9A+FMYc=; b=LdlT1xpkiMrKginZNRM1Xg74Ntb73ZLFLE+W3LDzWu3M8NvSdJnAv20C/IG+3fcF+o lqB5xFLh/r3C43Z9EkpoCPmTmdatyqXsrlg8cDDl3WIt7KGPbp3m3L3d6/KZPxixL6/K 9mqc4YHInw7x89Gn4LzwtLk7UHCrnTIRriIdO6u+uqgUYWBKSNF+0aEyG4VuaA4DhVkY t4gUQ9VmTEPFe6VhYeew5nW78RfHRUPpG2eGxPP5KtbpqYd64z8Eboi4PWuI9QtjJ6qS O20CC+0qQOo6igl9ZYZRxYZiPMX5RPPoi9lWyCI+rSzi1/g8tytF2jb1abKGNH6RJ/76 YPig== X-Forwarded-Encrypted: i=1; AJvYcCXv40xoUG2Y/3iKXQc1+gts9JvcAqRh8FLIVqlKc/LgItlSRmJIr4cSb11GC7hJF73vygzgmxHiPkHfPTU=@vger.kernel.org X-Gm-Message-State: AOJu0YwXjydyHP9grEKSWtBLGUVsxfSFqAPluhUfV1dmQDPH/whKg5zt fdaR72zhg0pKttTqPc384CKR/1RCtmIJG8gfEGVyO/zhy15QiWoN7kzGFaoRlmWgc4AzT0Li/X6 xmbIftaZuEaPhxD9mTvcpKAvAhDiT1MacmfDAwADtspI3BEPnznzmWzu2PL9TiE2TLg== X-Gm-Gg: ASbGncsjPAP4cxcVHe6b6gMqCQCAlxlfLnJLFLDfs6LyPl0Z85tSx2r5rpr7gsy3EF9 JjOdGdwd2ARGC6Rb54QXZHmjBj08HoVXOMMuOQ3zbafvjWTTzAU5VewlJ5sQ1zOqH12ppfYuQy8 Np2cMcejMruI89nwhx6kIOkApC4X2PSYJXm6LdK1x4rSgnSXD+OJqdAHGkxOTgiHhdaLMLUFz7N H60ZfgSrshrhyeSXZl9RRBgQu21BH68NmXQraXHneDfQ5AiXITgTqDkwm83aqeO+OCjr9NxvutV ObVKCksTkPl9WY+Kz+rj1CeJflvfnT8b8LCbxTe65SarODZkdaG+WjwRdAlap5THqU/ctsegj64 MDwzfxZtXrpMlhw== X-Received: by 2002:a05:600c:3145:b0:477:76c2:49c9 with SMTP id 5b1f17b1804b1-477870718cdmr46780925e9.2.1762992917433; Wed, 12 Nov 2025 16:15:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPbmxVbliqZZE2ij3N4XrtnplcTCMheZR9g48joM0Qg+CQVasHu64phvjG2+WlyX9GjLZJWA== X-Received: by 2002:a05:600c:3145:b0:477:76c2:49c9 with SMTP id 5b1f17b1804b1-477870718cdmr46780715e9.2.1762992917037; Wed, 12 Nov 2025 16:15:17 -0800 (PST) Received: from sissix.lzampier.com ([2a06:5900:814a:ab00:3725:2991:6cf3:b3aa]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53f0b589sm432983f8f.23.2025.11.12.16.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 16:15:16 -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: [RFC PATCH v2 3/3] HID: input: Add support for multiple batteries per device Date: Thu, 13 Nov 2025 00:15:05 +0000 Message-ID: <20251113001508.713574-4-lzampier@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251113001508.713574-1-lzampier@redhat.com> References: <20251113001508.713574-1-lzampier@redhat.com> 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" Enable HID devices to register and manage multiple batteries by maintaining a list of hid_battery structures, each identified by its report ID. The legacy dev->battery field and related fields are maintained for backward compatibility, pointing to the first battery in the list. This allows existing code to continue working unchanged while enabling new functionality for multi-battery devices. Example hardware that can benefit from this: - Gaming headsets with charging docks (e.g., SteelSeries Arctis Nova Pro Wireless) - Graphics tablets with stylus batteries (Wacom) - Wireless earbuds with per-earbud batteries plus charging case - Split keyboards with independent battery per side Signed-off-by: Lucas Zampieri --- drivers/hid/hid-core.c | 4 ++ drivers/hid/hid-input.c | 99 +++++++++++++++++++++++++++-------------- include/linux/hid.h | 12 ++++- 3 files changed, 80 insertions(+), 35 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index a5b3a8ca2fcb..76d628547e9a 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2990,6 +2990,10 @@ struct hid_device *hid_allocate_device(void) mutex_init(&hdev->ll_open_lock); kref_init(&hdev->ref); +#ifdef CONFIG_HID_BATTERY_STRENGTH + INIT_LIST_HEAD(&hdev->batteries); +#endif + ret =3D hid_bpf_device_init(hdev); if (ret) goto out_err; diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 0e71efea9da3..9d0be3d4ce04 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -520,14 +520,20 @@ static int hidinput_setup_battery(struct hid_device *= dev, unsigned report_type, unsigned quirks; s32 min, max; int error; + int battery_num =3D 0; - if (dev->battery) - return 0; /* already initialized? */ + /* Check if battery with this report_id already exists */ + list_for_each_entry(bat, &dev->batteries, list) { + if (bat->report_id =3D=3D field->report->id) + return 0; /* already initialized */ + battery_num++; + } quirks =3D find_battery_quirk(dev); - hid_dbg(dev, "device %x:%x:%x %d quirks %d\n", - dev->bus, dev->vendor, dev->product, dev->version, quirks); + hid_dbg(dev, "device %x:%x:%x %d quirks %d report_id %d\n", + dev->bus, dev->vendor, dev->product, dev->version, quirks, + field->report->id); if (quirks & HID_BATTERY_QUIRK_IGNORE) return 0; @@ -542,9 +548,17 @@ static int hidinput_setup_battery(struct hid_device *d= ev, unsigned report_type, goto err_free_bat; } - psy_desc->name =3D kasprintf(GFP_KERNEL, "hid-%s-battery", - strlen(dev->uniq) ? - dev->uniq : dev_name(&dev->dev)); + /* Create unique name for each battery based on report ID */ + if (battery_num =3D=3D 0) { + psy_desc->name =3D kasprintf(GFP_KERNEL, "hid-%s-battery", + strlen(dev->uniq) ? + dev->uniq : dev_name(&dev->dev)); + } else { + psy_desc->name =3D kasprintf(GFP_KERNEL, "hid-%s-battery-%d", + strlen(dev->uniq) ? + dev->uniq : dev_name(&dev->dev), + battery_num); + } if (!psy_desc->name) { error =3D -ENOMEM; goto err_free_desc; @@ -597,15 +611,23 @@ static int hidinput_setup_battery(struct hid_device *= dev, unsigned report_type, power_supply_powers(bat->ps, &dev->dev); - /* Maintain legacy single battery fields for backward compatibility */ - dev->battery =3D bat->ps; - dev->battery_min =3D bat->min; - dev->battery_max =3D bat->max; - dev->battery_report_type =3D bat->report_type; - dev->battery_report_id =3D bat->report_id; - dev->battery_charge_status =3D bat->charge_status; - dev->battery_status =3D bat->status; - dev->battery_avoid_query =3D bat->avoid_query; + list_add_tail(&bat->list, &dev->batteries); + + /* + * The legacy single battery API is preserved by exposing the first + * discovered battery. Systems relying on a single battery view maintain + * unchanged behavior. + */ + if (battery_num =3D=3D 0) { + dev->battery =3D bat->ps; + dev->battery_min =3D bat->min; + dev->battery_max =3D bat->max; + dev->battery_report_type =3D bat->report_type; + dev->battery_report_id =3D bat->report_id; + dev->battery_charge_status =3D bat->charge_status; + dev->battery_status =3D bat->status; + dev->battery_avoid_query =3D bat->avoid_query; + } return 0; @@ -620,21 +642,33 @@ static int hidinput_setup_battery(struct hid_device *= dev, unsigned report_type, static void hidinput_cleanup_battery(struct hid_device *dev) { - struct hid_battery *bat; + struct hid_battery *bat, *next; const struct power_supply_desc *psy_desc; - if (!dev->battery) - return; + list_for_each_entry_safe(bat, next, &dev->batteries, list) { + psy_desc =3D bat->ps->desc; + power_supply_unregister(bat->ps); + kfree(psy_desc->name); + kfree(psy_desc); + list_del(&bat->list); + kfree(bat); + } - bat =3D power_supply_get_drvdata(dev->battery); - psy_desc =3D dev->battery->desc; - power_supply_unregister(dev->battery); - kfree(psy_desc->name); - kfree(psy_desc); - kfree(bat); dev->battery =3D NULL; } +static struct hid_battery *hidinput_find_battery(struct hid_device *dev, + int report_id) +{ + struct hid_battery *bat; + + list_for_each_entry(bat, &dev->batteries, list) { + if (bat->report_id =3D=3D report_id) + return bat; + } + return NULL; +} + static bool hidinput_update_battery_charge_status(struct hid_battery *bat, unsigned int usage, int value) { @@ -652,17 +686,16 @@ static bool hidinput_update_battery_charge_status(str= uct hid_battery *bat, return false; } -static void hidinput_update_battery(struct hid_device *dev, unsigned int u= sage, - int value) +static void hidinput_update_battery(struct hid_device *dev, int report_id, + unsigned int usage, int value) { struct hid_battery *bat; int capacity; - if (!dev->battery) + bat =3D hidinput_find_battery(dev, report_id); + if (!bat) return; - bat =3D power_supply_get_drvdata(dev->battery); - if (hidinput_update_battery_charge_status(bat, usage, value)) { power_supply_changed(bat->ps); return; @@ -705,8 +738,8 @@ static void hidinput_cleanup_battery(struct hid_device = *dev) { } -static void hidinput_update_battery(struct hid_device *dev, unsigned int u= sage, - int value) +static void hidinput_update_battery(struct hid_device *dev, int report_id, + unsigned int usage, int value) { } #endif /* CONFIG_HID_BATTERY_STRENGTH */ @@ -1574,7 +1607,7 @@ void hidinput_hid_event(struct hid_device *hid, struc= t hid_field *field, struct return; if (usage->type =3D=3D EV_PWR) { - hidinput_update_battery(hid, usage->hid, value); + hidinput_update_battery(hid, report->id, usage->hid, value); return; } diff --git a/include/linux/hid.h b/include/linux/hid.h index 63422130de20..a6e36835fb3c 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -700,8 +700,16 @@ struct hid_device { #ifdef CONFIG_HID_BATTERY_STRENGTH /* * Power supply information for HID devices which report - * battery strength. power_supply was successfully registered if - * battery is non-NULL. + * battery strength. Each battery is tracked separately in the + * batteries list. + */ + struct list_head batteries; /* List of hid_battery structures */ + + /* + * Legacy single battery support - kept for backwards compatibility. + * Points to the first battery in the list if any exists. + * power_supply was successfully registered if battery is non-NULL. + * DEPRECATED: New code should iterate through batteries list instead. */ struct power_supply *battery; __s32 battery_capacity; -- 2.51.1