linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] HID: input: rename hidinput_set_battery_charge_status()
@ 2025-08-04  9:11 José Expósito
  2025-08-04  9:11 ` [PATCH 2/2] HID: input: report battery status changes immediately José Expósito
  0 siblings, 1 reply; 6+ messages in thread
From: José Expósito @ 2025-08-04  9:11 UTC (permalink / raw)
  To: jikos
  Cc: bentiss, luguohong, linux-input, linux-kernel,
	José Expósito

In preparation for a patch fixing a bug affecting
hidinput_set_battery_charge_status(), rename the function to
hidinput_update_battery_charge_status() and move it up so it can be used
by hidinput_update_battery().

Refactor, no functional changes.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/hid/hid-input-test.c | 10 +++++-----
 drivers/hid/hid-input.c      | 38 ++++++++++++++++++------------------
 2 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/hid/hid-input-test.c b/drivers/hid/hid-input-test.c
index 77c2d45ac62a..6f5c71660d82 100644
--- a/drivers/hid/hid-input-test.c
+++ b/drivers/hid/hid-input-test.c
@@ -7,7 +7,7 @@
 
 #include <kunit/test.h>
 
-static void hid_test_input_set_battery_charge_status(struct kunit *test)
+static void hid_test_input_update_battery_charge_status(struct kunit *test)
 {
 	struct hid_device *dev;
 	bool handled;
@@ -15,15 +15,15 @@ static void hid_test_input_set_battery_charge_status(struct kunit *test)
 	dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
 
-	handled = hidinput_set_battery_charge_status(dev, HID_DG_HEIGHT, 0);
+	handled = hidinput_update_battery_charge_status(dev, HID_DG_HEIGHT, 0);
 	KUNIT_EXPECT_FALSE(test, handled);
 	KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_UNKNOWN);
 
-	handled = hidinput_set_battery_charge_status(dev, HID_BAT_CHARGING, 0);
+	handled = hidinput_update_battery_charge_status(dev, HID_BAT_CHARGING, 0);
 	KUNIT_EXPECT_TRUE(test, handled);
 	KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_DISCHARGING);
 
-	handled = hidinput_set_battery_charge_status(dev, HID_BAT_CHARGING, 1);
+	handled = hidinput_update_battery_charge_status(dev, HID_BAT_CHARGING, 1);
 	KUNIT_EXPECT_TRUE(test, handled);
 	KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_CHARGING);
 }
@@ -63,7 +63,7 @@ static void hid_test_input_get_battery_property(struct kunit *test)
 }
 
 static struct kunit_case hid_input_tests[] = {
-	KUNIT_CASE(hid_test_input_set_battery_charge_status),
+	KUNIT_CASE(hid_test_input_update_battery_charge_status),
 	KUNIT_CASE(hid_test_input_get_battery_property),
 	{ }
 };
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index ff1784b5c2a4..262787e6eb20 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -595,6 +595,20 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
 	dev->battery = NULL;
 }
 
+static bool hidinput_update_battery_charge_status(struct hid_device *dev,
+						  unsigned int usage, int value)
+{
+	switch (usage) {
+	case HID_BAT_CHARGING:
+		dev->battery_charge_status = value ?
+					     POWER_SUPPLY_STATUS_CHARGING :
+					     POWER_SUPPLY_STATUS_DISCHARGING;
+		return true;
+	}
+
+	return false;
+}
+
 static void hidinput_update_battery(struct hid_device *dev, int value)
 {
 	int capacity;
@@ -617,20 +631,6 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
 		power_supply_changed(dev->battery);
 	}
 }
-
-static bool hidinput_set_battery_charge_status(struct hid_device *dev,
-					       unsigned int usage, int value)
-{
-	switch (usage) {
-	case HID_BAT_CHARGING:
-		dev->battery_charge_status = value ?
-					     POWER_SUPPLY_STATUS_CHARGING :
-					     POWER_SUPPLY_STATUS_DISCHARGING;
-		return true;
-	}
-
-	return false;
-}
 #else  /* !CONFIG_HID_BATTERY_STRENGTH */
 static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
 				  struct hid_field *field, bool is_percentage)
@@ -642,14 +642,14 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
 {
 }
 
-static void hidinput_update_battery(struct hid_device *dev, int value)
+static bool hidinput_update_battery_charge_status(struct hid_device *dev,
+						  unsigned int usage, int value)
 {
+	return false;
 }
 
-static bool hidinput_set_battery_charge_status(struct hid_device *dev,
-					       unsigned int usage, int value)
+static void hidinput_update_battery(struct hid_device *dev, int value)
 {
-	return false;
 }
 #endif	/* CONFIG_HID_BATTERY_STRENGTH */
 
@@ -1515,7 +1515,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
 		return;
 
 	if (usage->type == EV_PWR) {
-		bool handled = hidinput_set_battery_charge_status(hid, usage->hid, value);
+		bool handled = hidinput_update_battery_charge_status(hid, usage->hid, value);
 
 		if (!handled)
 			hidinput_update_battery(hid, value);
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] HID: input: report battery status changes immediately
  2025-08-04  9:11 [PATCH 1/2] HID: input: rename hidinput_set_battery_charge_status() José Expósito
@ 2025-08-04  9:11 ` José Expósito
  2025-08-04 15:34   ` kernel test robot
       [not found]   ` <a235549c5cf24205bb7ce7f05737c403@xiaomi.com>
  0 siblings, 2 replies; 6+ messages in thread
From: José Expósito @ 2025-08-04  9:11 UTC (permalink / raw)
  To: jikos
  Cc: bentiss, luguohong, linux-input, linux-kernel,
	José Expósito

When the battery status changes, report the change immediately to user
space.

Fixes: a608dc1c0639 ("HID: input: map battery system charging")
Reported-by: 卢国宏 <luguohong@xiaomi.com>
Closes: https://lore.kernel.org/linux-input/aI49Im0sGb6fpgc8@fedora/T/
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/hid/hid-input.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 262787e6eb20..277538a17b57 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -609,13 +609,19 @@ static bool hidinput_update_battery_charge_status(struct hid_device *dev,
 	return false;
 }
 
-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 (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;
 
@@ -648,7 +654,8 @@ static bool hidinput_update_battery_charge_status(struct hid_device *dev,
 	return false;
 }
 
-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)
 {
 }
 #endif	/* CONFIG_HID_BATTERY_STRENGTH */
@@ -1515,11 +1522,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
 		return;
 
 	if (usage->type == EV_PWR) {
-		bool handled = hidinput_update_battery_charge_status(hid, usage->hid, value);
-
-		if (!handled)
-			hidinput_update_battery(hid, value);
-
+		hidinput_update_battery(hid, usage->hid, value);
 		return;
 	}
 
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] HID: input: report battery status changes immediately
  2025-08-04  9:11 ` [PATCH 2/2] HID: input: report battery status changes immediately José Expósito
@ 2025-08-04 15:34   ` kernel test robot
       [not found]   ` <a235549c5cf24205bb7ce7f05737c403@xiaomi.com>
  1 sibling, 0 replies; 6+ messages in thread
From: kernel test robot @ 2025-08-04 15:34 UTC (permalink / raw)
  To: José Expósito, jikos
  Cc: oe-kbuild-all, bentiss, luguohong, linux-input, linux-kernel,
	José Expósito

Hi José,

kernel test robot noticed the following build warnings:

[auto build test WARNING on hid/for-next]
[also build test WARNING on linus/master v6.16 next-20250804]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jos-Exp-sito/HID-input-report-battery-status-changes-immediately/20250804-171355
base:   https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git for-next
patch link:    https://lore.kernel.org/r/20250804091215.6637-2-jose.exposito89%40gmail.com
patch subject: [PATCH 2/2] HID: input: report battery status changes immediately
config: arm-randconfig-004-20250804 (https://download.01.org/0day-ci/archive/20250804/202508042305.PBym6Evd-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250804/202508042305.PBym6Evd-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508042305.PBym6Evd-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/hid/hid-input.c:651:13: warning: 'hidinput_update_battery_charge_status' defined but not used [-Wunused-function]
     651 | static bool hidinput_update_battery_charge_status(struct hid_device *dev,
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/hidinput_update_battery_charge_status +651 drivers/hid/hid-input.c

581c4484769e69 Dmitry Torokhov 2017-08-01  650  
133568dfb5acfa José Expósito   2025-08-04 @651  static bool hidinput_update_battery_charge_status(struct hid_device *dev,
133568dfb5acfa José Expósito   2025-08-04  652  						  unsigned int usage, int value)
581c4484769e69 Dmitry Torokhov 2017-08-01  653  {
133568dfb5acfa José Expósito   2025-08-04  654  	return false;
581c4484769e69 Dmitry Torokhov 2017-08-01  655  }
a608dc1c06397d José Expósito   2022-11-24  656  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: 答复: [External Mail][PATCH 2/2] HID: input: report battery status changes immediately
       [not found]   ` <a235549c5cf24205bb7ce7f05737c403@xiaomi.com>
@ 2025-08-05  8:42     ` José Expósito
       [not found]       ` <b5aa18342f42420093db90ee2ead88ba@xiaomi.com>
  0 siblings, 1 reply; 6+ messages in thread
From: José Expósito @ 2025-08-05  8:42 UTC (permalink / raw)
  To: 卢国宏
  Cc: jikos@kernel.org, bentiss@kernel.org, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org, Fei1 Jiang 蒋飞

Hi!

On Tue, Aug 05, 2025 at 01:43:30AM +0000, 卢国宏 wrote:
> ________________________________
> 发件人: José Expósito <jose.exposito89@gmail.com>
> 发送时间: 2025年8月4日 17:11
> 收件人: jikos@kernel.org
> 抄送: bentiss@kernel.org; 卢国宏; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org; José Expósito
> 主题: [External Mail][PATCH 2/2] HID: input: report battery status changes immediately
> 
> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xiaomi.com进行反馈
> 
> When the battery status changes, report the change immediately to user
> space.
> 
> Fixes: a608dc1c0639 ("HID: input: map battery system charging")
> Reported-by: 卢国宏 <luguohong@xiaomi.com>
> Closes: https://lore.kernel.org/linux-input/aI49Im0sGb6fpgc8@fedora/T/
> Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> ---
>  drivers/hid/hid-input.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
> index 262787e6eb20..277538a17b57 100644
> --- a/drivers/hid/hid-input.c
> +++ b/drivers/hid/hid-input.c
> @@ -609,13 +609,19 @@ static bool hidinput_update_battery_charge_status(struct hid_device *dev,
>         return false;
>  }
> 
> -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 (hidinput_update_battery_charge_status(dev, usage, value)) {
> +               power_supply_changed(dev->battery);
> +               return;
> +       }
> +
> 
> > Hi, José. Shouldn't the return statement in this code be removed?
> > Otherwise, if both the battery level and the charging status change
> > simultaneously, the code following the if statement that updates the
> > battery level won't run, and the battery level won't be updated.
> > Thanks!

At least on the hardware I have access to, changes are reported independently.

I added a log at the beginning of this function to illustrate it.
This is the output when the battery of my device goes from 99% to 95%:

    New EV_PWR report:
        usage = 8716389
        value = 99
    New EV_PWR report:
        usage = 8716356 (HID_BAT_CHARGING)
        value = 0       (POWER_SUPPLY_STATUS_DISCHARGING)
    [...]
    New EV_PWR report:
        usage = 8716389
        value = 95
    New EV_PWR report:
        usage = 8716356 (HID_BAT_CHARGING)
        value = 0       (POWER_SUPPLY_STATUS_DISCHARGING)

If we remove that return, then "value" (0 or 1) would be used as battery level,
reporting wrong battery levels to user-space.

Isn't your device reporting its battery information in a similar way?

Jose

PS - I'll fix the warning in v2 and add a Tested-by: 卢国宏 tag once
     this is confirmed to work on the affected hardware.

> 
> 
>         if (value == 0 || value < dev->battery_min || value > dev->battery_max)
>                 return;
> 
> @@ -648,7 +654,8 @@ static bool hidinput_update_battery_charge_status(struct hid_device *dev,
>         return false;
>  }
> 
> -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)
>  {
>  }
>  #endif /* CONFIG_HID_BATTERY_STRENGTH */
> @@ -1515,11 +1522,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
>                 return;
> 
>         if (usage->type == EV_PWR) {
> -               bool handled = hidinput_update_battery_charge_status(hid, usage->hid, value);
> -
> -               if (!handled)
> -                       hidinput_update_battery(hid, value);
> -
> +               hidinput_update_battery(hid, usage->hid, value);
>                 return;
>         }
> 
> --
> 2.50.1
> 
> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! 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!******/#

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: 答复: 答复: [External Mail][PATCH 2/2] HID: input: report battery status changes immediately
       [not found]       ` <b5aa18342f42420093db90ee2ead88ba@xiaomi.com>
@ 2025-08-05 12:38         ` José Expósito
       [not found]           ` <6454c36ced0140df978f29a7b4208f4a@xiaomi.com>
  0 siblings, 1 reply; 6+ messages in thread
From: José Expósito @ 2025-08-05 12:38 UTC (permalink / raw)
  To: 卢国宏
  Cc: jikos@kernel.org, bentiss@kernel.org, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org, Fei1 Jiang 蒋飞

Hi,

On Tue, Aug 05, 2025 at 12:25:17PM +0000, 卢国宏 wrote:
> ________________________________
> 发件人: José Expósito <jose.exposito89@gmail.com>
> 发送时间: 2025年8月5日 16:42
> 收件人: 卢国宏
> 抄送: jikos@kernel.org; bentiss@kernel.org; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org; Fei1 Jiang 蒋飞
> 主题: Re: 答复: [External Mail][PATCH 2/2] HID: input: report battery status changes immediately
> 
> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xiaomi.com进行反馈
> 
> Hi!
> 
> On Tue, Aug 05, 2025 at 01:43:30AM +0000, 卢国宏 wrote:
> > ________________________________
> > 发件人: José Expósito <jose.exposito89@gmail.com>
> > 发送时间: 2025年8月4日 17:11
> > 收件人: jikos@kernel.org
> > 抄送: bentiss@kernel.org; 卢国宏; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org; José Expósito
> > 主题: [External Mail][PATCH 2/2] HID: input: report battery status changes immediately
> >
> > [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xiaomi.com进行反馈
> >
> > When the battery status changes, report the change immediately to user
> > space.
> >
> > Fixes: a608dc1c0639 ("HID: input: map battery system charging")
> > Reported-by: 卢国宏 <luguohong@xiaomi.com>
> > Closes: https://lore.kernel.org/linux-input/aI49Im0sGb6fpgc8@fedora/T/
> > Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> > ---
> >  drivers/hid/hid-input.c | 17 ++++++++++-------
> >  1 file changed, 10 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
> > index 262787e6eb20..277538a17b57 100644
> > --- a/drivers/hid/hid-input.c
> > +++ b/drivers/hid/hid-input.c
> > @@ -609,13 +609,19 @@ static bool hidinput_update_battery_charge_status(struct hid_device *dev,
> >         return false;
> >  }
> >
> > -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 (hidinput_update_battery_charge_status(dev, usage, value)) {
> > +               power_supply_changed(dev->battery);
> > +               return;
> > +       }
> > +
> >
> > > Hi, José. Shouldn't the return statement in this code be removed?
> > > Otherwise, if both the battery level and the charging status change
> > > simultaneously, the code following the if statement that updates the
> > > battery level won't run, and the battery level won't be updated.
> > > Thanks!
> 
> At least on the hardware I have access to, changes are reported independently.
> 
> I added a log at the beginning of this function to illustrate it.
> This is the output when the battery of my device goes from 99% to 95%:
> 
>     New EV_PWR report:
>         usage = 8716389
>         value = 99
>     New EV_PWR report:
>         usage = 8716356 (HID_BAT_CHARGING)
>         value = 0       (POWER_SUPPLY_STATUS_DISCHARGING)
>     [...]
>     New EV_PWR report:
>         usage = 8716389
>         value = 95
>     New EV_PWR report:
>         usage = 8716356 (HID_BAT_CHARGING)
>         value = 0       (POWER_SUPPLY_STATUS_DISCHARGING)
> 
> If we remove that return, then "value" (0 or 1) would be used as battery level,
> reporting wrong battery levels to user-space.
> 
> Isn't your device reporting its battery information in a similar way?
> 
> > --->>>
> > Hello, Jose!
> > You're right, this return can't be removed. I had previously only
> > theoretically assumed they would be reported simultaneously, but
> > that turned out to be incorrect. It seems your solution should be fine.
> > Finally, when will your patch be merged into the Linux kernel?
> > We're looking forward to using this feature. Thank you very much!

Would you be able to test that the patches work on your device?

I assume there won't be surprises, but better to double check if
you have access to the affected device.

Once you test it, I'll send a second version of the code fixing a
warning and adding you as tester of the patch. Then it is up to
the maintainers to merge it.

Looking forward for your testing,
Jose
 
> 
> Jose
> 
> PS - I'll fix the warning in v2 and add a Tested-by: 卢国宏 tag once
>      this is confirmed to work on the affected hardware.
> 
> >
> >
> >         if (value == 0 || value < dev->battery_min || value > dev->battery_max)
> >                 return;
> >
> > @@ -648,7 +654,8 @@ static bool hidinput_update_battery_charge_status(struct hid_device *dev,
> >         return false;
> >  }
> >
> > -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)
> >  {
> >  }
> >  #endif /* CONFIG_HID_BATTERY_STRENGTH */
> > @@ -1515,11 +1522,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
> >                 return;
> >
> >         if (usage->type == EV_PWR) {
> > -               bool handled = hidinput_update_battery_charge_status(hid, usage->hid, value);
> > -
> > -               if (!handled)
> > -                       hidinput_update_battery(hid, value);
> > -
> > +               hidinput_update_battery(hid, usage->hid, value);
> >                 return;
> >         }
> >
> > --
> > 2.50.1
> >
> > #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! 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!******/#
> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! 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!******/#

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: 答复: 答复: 答复: [External Mail][PATCH 2/2] HID: input: report battery status changes immediately
       [not found]             ` <9dbdee5aa8fa4b899bfbb8be3b4cd6c5@xiaomi.com>
@ 2025-08-06  7:42               ` José Expósito
  0 siblings, 0 replies; 6+ messages in thread
From: José Expósito @ 2025-08-06  7:42 UTC (permalink / raw)
  To: 卢国宏
  Cc: jikos@kernel.org, bentiss@kernel.org, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org, Fei1 Jiang 蒋飞

Hi 卢国宏,

On Wed, Aug 06, 2025 at 07:03:05AM +0000, 卢国宏 wrote:
> 
> Hello, Jose!
> I've completed testing on our devices. Your patch works fine for charging status reporting.
> Below is the switching log between partially charged state and uncharged state:
> 
> ...
> Xiaomi handler POWER_SUPPLY_STATUS=Charging
> ...
> Xiaomi handler POWER_SUPPLY_STATUS=Discharging
> ...
> Xiaomi handler POWER_SUPPLY_STATUS=Charging
> 
> In addition, the handle battery level can also be reported normally.
> Now you should be able to submit your patch to the Linux kernel. After submitting,
> please send me a copy of the official patch so I can contact Google to merge it into
> their GKI and enable this feature in our products first. Thank you very much!

Thanks a lot for testing it. Here is the link to the patch:
https://lore.kernel.org/linux-input/20250806073944.5310-1-jose.exposito89@gmail.com/T/

Best wishes,
Jose

> 
> luguohong
> 
> ________________________________
> 发件人: 卢国宏
> 发送时间: 2025年8月6日 9:41
> 收件人: José Expósito
> 抄送: jikos@kernel.org; bentiss@kernel.org; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org; Fei1 Jiang 蒋飞; 卢国宏
> 主题: 答复: 答复: 答复: [External Mail][PATCH 2/2] HID: input: report battery status changes immediately
> 
> 
> 
> 
> OK! I'll use your patch and finish testing it soon and let you know the results, thanks!
> 
> 
> ________________________________
> 发件人: José Expósito <jose.exposito89@gmail.com>
> 发送时间: 2025年8月5日 20:38
> 收件人: 卢国宏
> 抄送: jikos@kernel.org; bentiss@kernel.org; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org; Fei1 Jiang 蒋飞
> 主题: Re: 答复: 答复: [External Mail][PATCH 2/2] HID: input: report battery status changes immediately
> 
> [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xiaomi.com进行反馈
> 
> Hi,
> 
> On Tue, Aug 05, 2025 at 12:25:17PM +0000, 卢国宏 wrote:
> > ________________________________
> > 发件人: José Expósito <jose.exposito89@gmail.com>
> > 发送时间: 2025年8月5日 16:42
> > 收件人: 卢国宏
> > 抄送: jikos@kernel.org; bentiss@kernel.org; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org; Fei1 Jiang 蒋飞
> > 主题: Re: 答复: [External Mail][PATCH 2/2] HID: input: report battery status changes immediately
> >
> > [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xiaomi.com进行反馈
> >
> > Hi!
> >
> > On Tue, Aug 05, 2025 at 01:43:30AM +0000, 卢国宏 wrote:
> > > ________________________________
> > > 发件人: José Expósito <jose.exposito89@gmail.com>
> > > 发送时间: 2025年8月4日 17:11
> > > 收件人: jikos@kernel.org
> > > 抄送: bentiss@kernel.org; 卢国宏; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org; José Expósito
> > > 主题: [External Mail][PATCH 2/2] HID: input: report battery status changes immediately
> > >
> > > [外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xiaomi.com进行反馈
> > >
> > > When the battery status changes, report the change immediately to user
> > > space.
> > >
> > > Fixes: a608dc1c0639 ("HID: input: map battery system charging")
> > > Reported-by: 卢国宏 <luguohong@xiaomi.com>
> > > Closes: https://lore.kernel.org/linux-input/aI49Im0sGb6fpgc8@fedora/T/
> > > Signed-off-by: José Expósito <jose.exposito89@gmail.com>
> > > ---
> > >  drivers/hid/hid-input.c | 17 ++++++++++-------
> > >  1 file changed, 10 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
> > > index 262787e6eb20..277538a17b57 100644
> > > --- a/drivers/hid/hid-input.c
> > > +++ b/drivers/hid/hid-input.c
> > > @@ -609,13 +609,19 @@ static bool hidinput_update_battery_charge_status(struct hid_device *dev,
> > >         return false;
> > >  }
> > >
> > > -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 (hidinput_update_battery_charge_status(dev, usage, value)) {
> > > +               power_supply_changed(dev->battery);
> > > +               return;
> > > +       }
> > > +
> > >
> > > > Hi, José. Shouldn't the return statement in this code be removed?
> > > > Otherwise, if both the battery level and the charging status change
> > > > simultaneously, the code following the if statement that updates the
> > > > battery level won't run, and the battery level won't be updated.
> > > > Thanks!
> >
> > At least on the hardware I have access to, changes are reported independently.
> >
> > I added a log at the beginning of this function to illustrate it.
> > This is the output when the battery of my device goes from 99% to 95%:
> >
> >     New EV_PWR report:
> >         usage = 8716389
> >         value = 99
> >     New EV_PWR report:
> >         usage = 8716356 (HID_BAT_CHARGING)
> >         value = 0       (POWER_SUPPLY_STATUS_DISCHARGING)
> >     [...]
> >     New EV_PWR report:
> >         usage = 8716389
> >         value = 95
> >     New EV_PWR report:
> >         usage = 8716356 (HID_BAT_CHARGING)
> >         value = 0       (POWER_SUPPLY_STATUS_DISCHARGING)
> >
> > If we remove that return, then "value" (0 or 1) would be used as battery level,
> > reporting wrong battery levels to user-space.
> >
> > Isn't your device reporting its battery information in a similar way?
> >
> > > --->>>
> > > Hello, Jose!
> > > You're right, this return can't be removed. I had previously only
> > > theoretically assumed they would be reported simultaneously, but
> > > that turned out to be incorrect. It seems your solution should be fine.
> > > Finally, when will your patch be merged into the Linux kernel?
> > > We're looking forward to using this feature. Thank you very much!
> 
> Would you be able to test that the patches work on your device?
> 
> I assume there won't be surprises, but better to double check if
> you have access to the affected device.
> 
> Once you test it, I'll send a second version of the code fixing a
> warning and adding you as tester of the patch. Then it is up to
> the maintainers to merge it.
> 
> Looking forward for your testing,
> Jose
> 
> >
> > Jose
> >
> > PS - I'll fix the warning in v2 and add a Tested-by: 卢国宏 tag once
> >      this is confirmed to work on the affected hardware.
> >
> > >
> > >
> > >         if (value == 0 || value < dev->battery_min || value > dev->battery_max)
> > >                 return;
> > >
> > > @@ -648,7 +654,8 @@ static bool hidinput_update_battery_charge_status(struct hid_device *dev,
> > >         return false;
> > >  }
> > >
> > > -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)
> > >  {
> > >  }
> > >  #endif /* CONFIG_HID_BATTERY_STRENGTH */
> > > @@ -1515,11 +1522,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
> > >                 return;
> > >
> > >         if (usage->type == EV_PWR) {
> > > -               bool handled = hidinput_update_battery_charge_status(hid, usage->hid, value);
> > > -
> > > -               if (!handled)
> > > -                       hidinput_update_battery(hid, value);
> > > -
> > > +               hidinput_update_battery(hid, usage->hid, value);
> > >                 return;
> > >         }
> > >
> > > --
> > > 2.50.1
> > >
> > > #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! 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!******/#
> > #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! 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!******/#
> #/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! 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!******/#

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-06  7:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-04  9:11 [PATCH 1/2] HID: input: rename hidinput_set_battery_charge_status() José Expósito
2025-08-04  9:11 ` [PATCH 2/2] HID: input: report battery status changes immediately José Expósito
2025-08-04 15:34   ` kernel test robot
     [not found]   ` <a235549c5cf24205bb7ce7f05737c403@xiaomi.com>
2025-08-05  8:42     ` 答复: [External Mail][PATCH " José Expósito
     [not found]       ` <b5aa18342f42420093db90ee2ead88ba@xiaomi.com>
2025-08-05 12:38         ` 答复: " José Expósito
     [not found]           ` <6454c36ced0140df978f29a7b4208f4a@xiaomi.com>
     [not found]             ` <9dbdee5aa8fa4b899bfbb8be3b4cd6c5@xiaomi.com>
2025-08-06  7:42               ` 答复: " José Expósito

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).