public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "José Expósito" <jose.exposito89@gmail.com>
To: 卢国宏 <luguohong@xiaomi.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	jikos@kernel.org, bentiss@kernel.org, dmitry.torokhov@gmail.com
Cc: 李鹏 <lipeng43@xiaomi.com>, "Fei1 Jiang 蒋飞" <jiangfei1@xiaomi.com>,
	宋密密 <songmimi@xiaomi.com>
Subject: Re: The zero power level of the HID device in kernel 6.12 is not reported from the kernel to the upper layer.
Date: Fri, 19 Sep 2025 10:40:38 +0200	[thread overview]
Message-ID: <aM0XBudxlXuzALbg@fedora> (raw)
In-Reply-To: <d2cada7efe8d4436b6e638fa1e0aaefb@xiaomi.com>

Hi 卢国宏,

Thanks for reporting this issue.

In the furure, when reporting bugs, it is prefered to send them to the
mailing list (linux-input@vger.kernel.org and linux-kernel@vger.kernel.org)
to discuss them in public.

Let me forward your email to the mailing list and also CC Dmitry, the
author of that code, who might help us understand the problem.

On Tue, Sep 16, 2025 at 12:29:32PM +0000, 卢国宏 wrote:
> Hi, jose!
>
> We encountered a problem where the zero battery level of the HID device
> in kernel 6.12 was not reported from the kernel to the upper layer.
> I checked the HID protocol and it doesn't say that there is no need to
> report the zero power of the HID device. For details, see page 381 of
> the HID protocol, 31.4 Battery Measures. "Absolute State Of Charge DV
> The predicted remaining battery capacity expressed as a percentage of
> design capacity. (Units are %. The value may be greater than 100%.)".
> However, in the file hid-input.c in kernel 6.12, the following code:
> 
> static void hidinput_update_battery(struct hid_device *dev, unsigned int usage,
>                                     int value)
> {
>         int capacity;
> 
>         if (!dev->battery)
>                 return;
> 
>         if (hidinput_update_battery_charge_status(dev, usage, value)) {
>                 power_supply_changed(dev->battery);
>                 return;
>         }
> 
>         if (value == 0 || value < dev->battery_min || value > dev->battery_max)
>                 return;
> 
>         capacity = hidinput_scale_battery_capacity(dev, value);
> 
>          ......
> 
> }
> 
> The parameter value is the power level. When the value is 0, the above code
> returns without reporting.
> Is this a problem?
> We're currently experiencing this issue on Android 16. The upper layer of
> Android needs to receive a zero battery level before it can take appropriate
> action.
> Could you please help me evaluate whether we should remove the behavior of
> returning to zero battery?
>
> Thanks!
> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which 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 not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#

It indeed looks like it could be problematic.

Values are allowed ot be grater than 100, however, I didn't find
any references to negative values. Since it is a percentage, it
make sense to limit it to 0%, i.e., not allowing negative values.

I think that removing the "value == 0" check, or replacing it with
"value < 0" should fix the issue.

By the way, the "Fully Discharged" value (0x00850047), section 31.3.1,
is not handled by the kernel. Do you know if Android handles that
instead or in addition to a 0% battery?

Jose

       reply	other threads:[~2025-09-19  8:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <d2cada7efe8d4436b6e638fa1e0aaefb@xiaomi.com>
2025-09-19  8:40 ` José Expósito [this message]
2025-09-19 15:04   ` The zero power level of the HID device in kernel 6.12 is not reported from the kernel to the upper layer Dmitry Torokhov
2025-09-22  9:29     ` 答复: [External Mail]Re: " 卢国宏
2025-09-25  4:26       ` Dmitry Torokhov
2025-09-26 12:03         ` 答复: " 卢国宏
2025-09-29 12:10           ` 卢国宏
2025-10-10  2:25             ` 卢国宏
2025-10-10  6:13               ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aM0XBudxlXuzALbg@fedora \
    --to=jose.exposito89@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jiangfei1@xiaomi.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lipeng43@xiaomi.com \
    --cc=luguohong@xiaomi.com \
    --cc=songmimi@xiaomi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox