From nobody Wed Oct 1 22:31:24 2025 Received: from outboundhk.mxmail.xiaomi.com (outboundhk.mxmail.xiaomi.com [118.143.206.90]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11D5C10E3; Fri, 26 Sep 2025 12:03:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.143.206.90 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758888210; cv=none; b=ulEIzF0O4mKEm0daQPjaXhb1WGL8zA/EV1xPYbI+FnIm6iRMZd1x1Qmn9nDD+4Y5Gk9cukRQmC8ngDAZmxTDvFnva5Br50LUDHon2kkXaOFeeownI2ygpeJCSWpsnNi50tgX5bDG30J6I5olpup4Imyr7NHL0SnKx756iRzvM1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758888210; c=relaxed/simple; bh=WjCqIiFfZ75RdZ0O8KNeP5eb/Iq3S4nT4LUk9qeScVM=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=qZKECkF18cFo/QxHjur64h0yttYdMNY2gobo8OFroApATdjb8NH3pV8lhZXW73KMDFEAfxVKiUcbtosG/51vkytn+o/lA6oP6uwWXj40yYO2CND3WKuQ3AbVcdxJ9nzZLl6gL6hPi+dDC0DJsBxDcim18f4uAc8MLT4lklGczQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=xiaomi.com; spf=pass smtp.mailfrom=xiaomi.com; arc=none smtp.client-ip=118.143.206.90 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=xiaomi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaomi.com X-CSE-ConnectionGUID: JNgtOul1R5G7qDX6S5sh5w== X-CSE-MsgGUID: jL0ClaEQQ6+hcwRp3hxS1g== X-IronPort-AV: E=Sophos;i="6.18,295,1751212800"; d="scan'208";a="127915875" From: =?gb2312?B?wqy5+rrq?= To: Dmitry Torokhov CC: =?gb2312?B?Sm9zqKYgRXhwqK5zaXRv?= , "linux-input@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "jikos@kernel.org" , "bentiss@kernel.org" , =?gb2312?B?wO7F9A==?= , =?gb2312?B?RmVpMSBKaWFuZyC9r7fJ?= , =?gb2312?B?y87D3MPc?= , =?gb2312?B?wqy5+rrq?= Subject: =?gb2312?B?tPC4tDogtPC4tDogW0V4dGVybmFsIE1haWxdUmU6IFRoZSB6ZXJvIHBvd2Vy?= =?gb2312?B?IGxldmVsIG9mIHRoZSBISUQgZGV2aWNlIGluIGtlcm5lbCA2LjEyIGlzIG5v?= =?gb2312?Q?t_reported_from_the_kernel_to_the_upper_layer.?= Thread-Topic: =?gb2312?B?tPC4tDogW0V4dGVybmFsIE1haWxdUmU6IFRoZSB6ZXJvIHBvd2VyIGxldmVs?= =?gb2312?B?IG9mIHRoZSBISUQgZGV2aWNlIGluIGtlcm5lbCA2LjEyIGlzIG5vdCByZXBv?= =?gb2312?Q?rted_from_the_kernel_to_the_upper_layer.?= Thread-Index: AQHcJwWA1Pv1UPoVhEyxSk6qnb4viLSZrf4AgABrXICABNg0/oAD42UAgAKWVzk= Date: Fri, 26 Sep 2025 12:03:19 +0000 Message-ID: References: <91e0d952fd774e769e2d24ce2165df18@xiaomi.com>, In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Transfer-Encoding: quoted-printable 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" Hi Dmitry, After testing, we found that your proposed method can solve our problem. Pl= ease help merge this method into the Linux kernel as soon as possible! Plea= se remember to send us the relevant information of the merged git so that w= e can contact Google and merge their Android GKI as well. Our project is lo= oking forward to using this feature. Thank you very much! ________________________________________ =E5=8F=91=E4=BB=B6=E4=BA=BA: Dmitry Torokhov =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2025=E5=B9=B49=E6=9C=8825=E6=97=A5 12= :26 =E6=94=B6=E4=BB=B6=E4=BA=BA: =E5=8D=A2=E5=9B=BD=E5=AE=8F =E6=8A=84=E9=80=81: Jos=C3=A9 Exp=C3=B3sito; linux-input@vger.kernel.org; l= inux-kernel@vger.kernel.org; jikos@kernel.org; bentiss@kernel.org; =E6=9D= =8E=E9=B9=8F; Fei1 Jiang =E8=92=8B=E9=A3=9E; =E5=AE=8B=E5=AF=86=E5=AF=86 =E4=B8=BB=E9=A2=98: Re: =E7=AD=94=E5=A4=8D: [External Mail]Re: The zero pow= er level of the HID device in kernel 6.12 is not reported from the kernel t= o the upper layer. [=E5=A4=96=E9=83=A8=E9=82=AE=E4=BB=B6] =E6=AD=A4=E9=82=AE=E4=BB=B6=E6=9D=A5= =E6=BA=90=E4=BA=8E=E5=B0=8F=E7=B1=B3=E5=85=AC=E5=8F=B8=E5=A4=96=E9=83=A8=EF= =BC=8C=E8=AF=B7=E8=B0=A8=E6=85=8E=E5=A4=84=E7=90=86=E3=80=82=E8=8B=A5=E5=AF= =B9=E9=82=AE=E4=BB=B6=E5=AE=89=E5=85=A8=E6=80=A7=E5=AD=98=E7=96=91=EF=BC=8C= =E8=AF=B7=E5=B0=86=E9=82=AE=E4=BB=B6=E8=BD=AC=E5=8F=91=E7=BB=99misec@xiaomi= .com=E8=BF=9B=E8=A1=8C=E5=8F=8D=E9=A6=88 On Mon, Sep 22, 2025 at 09:29:20AM +0000, =E5=8D=A2=E5=9B=BD=E5=AE=8F wrote: > > What kind of action are we talking about? Section 31 of the HID > specification defines events for "Smart Battery" ("To comply with the > Smart Battery Specification, the Battery System must support the > functions defined in the Battery and Charger usage tables. For details, > see Section 4.2, =E2=80=9CBattery System Page (x85).=E2=80=9D) and is typ= ically used for > "battery pack for cellular phones (principal source), the battery > pack(s) for notebook computers (auxiliary source), and the sealed > batteries in uninterruptible power supplies (auxiliary source)." > > Is your use case main battery or battery in a stylus or some other > peripheral? > > > --->>> > What we are discussing is the code implementation of Section 31 of the > HID protocol: 31 Battery System Page (0x85). Our scenario is: an > Android phone is connected to a handle via USB. The handle is a HID > device with a battery. The power of the battery in the handle is sent > to the bottom layer (kernel) of the phone via USB. The bottom layer of > the phone then reports this power to the upper layer of Android > through the HID driver. I see. I guess we can try only filtering out 0 reports for the digitizers, leaving other devices with batteries alone. Something like this: diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index ff1784b5c2a4..ba3f6655af9e 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -595,14 +595,18 @@ static void hidinput_cleanup_battery(struct hid_devic= e *dev) dev->battery =3D NULL; } -static void hidinput_update_battery(struct hid_device *dev, int value) +static void hidinput_update_battery(struct hid_device *dev, + unsigned int usage, int value) { int capacity; if (!dev->battery) return; - if (value =3D=3D 0 || value < dev->battery_min || value > dev->batt= ery_max) + if ((usage & HID_USAGE_PAGE) =3D=3D HID_UP_DIGITIZER && value =3D= =3D 0) + return; + + if (value < dev->battery_min || value > dev->battery_max) return; capacity =3D hidinput_scale_battery_capacity(dev, value); @@ -1518,7 +1522,7 @@ void hidinput_hid_event(struct hid_device *hid, struc= t hid_field *field, struct bool handled =3D hidinput_set_battery_charge_status(hid, us= age->hid, value); if (!handled) - hidinput_update_battery(hid, value); + hidinput_update_battery(hid, usage->hid, value); return; } Thanks. -- Dmitry #/******=E6=9C=AC=E9=82=AE=E4=BB=B6=E5=8F=8A=E5=85=B6=E9=99=84=E4=BB=B6=E5= =90=AB=E6=9C=89=E5=B0=8F=E7=B1=B3=E5=85=AC=E5=8F=B8=E7=9A=84=E4=BF=9D=E5=AF= =86=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=BB=85=E9=99=90=E4=BA=8E=E5=8F=91=E9=80=81= =E7=BB=99=E4=B8=8A=E9=9D=A2=E5=9C=B0=E5=9D=80=E4=B8=AD=E5=88=97=E5=87=BA=E7= =9A=84=E4=B8=AA=E4=BA=BA=E6=88=96=E7=BE=A4=E7=BB=84=E3=80=82=E7=A6=81=E6=AD= =A2=E4=BB=BB=E4=BD=95=E5=85=B6=E4=BB=96=E4=BA=BA=E4=BB=A5=E4=BB=BB=E4=BD=95= =E5=BD=A2=E5=BC=8F=E4=BD=BF=E7=94=A8=EF=BC=88=E5=8C=85=E6=8B=AC=E4=BD=86=E4= =B8=8D=E9=99=90=E4=BA=8E=E5=85=A8=E9=83=A8=E6=88=96=E9=83=A8=E5=88=86=E5=9C= =B0=E6=B3=84=E9=9C=B2=E3=80=81=E5=A4=8D=E5=88=B6=E3=80=81=E6=88=96=E6=95=A3= =E5=8F=91=EF=BC=89=E6=9C=AC=E9=82=AE=E4=BB=B6=E4=B8=AD=E7=9A=84=E4=BF=A1=E6= =81=AF=E3=80=82=E5=A6=82=E6=9E=9C=E6=82=A8=E9=94=99=E6=94=B6=E4=BA=86=E6=9C= =AC=E9=82=AE=E4=BB=B6=EF=BC=8C=E8=AF=B7=E6=82=A8=E7=AB=8B=E5=8D=B3=E7=94=B5= =E8=AF=9D=E6=88=96=E9=82=AE=E4=BB=B6=E9=80=9A=E7=9F=A5=E5=8F=91=E4=BB=B6=E4= =BA=BA=E5=B9=B6=E5=88=A0=E9=99=A4=E6=9C=AC=E9=82=AE=E4=BB=B6=EF=BC=81 This = e-mail and its attachments contain confidential information from XIAOMI, wh= ich is intended only for the person or entity whose address is listed above= . Any use of the information contained herein in any way (including, but no= t limited to, total or partial disclosure, reproduction, or dissemination) = by persons other than the intended recipient(s) is prohibited. If you recei= ve this e-mail in error, please notify the sender by phone or email immedia= tely and delete it!******/#