Skip to contentSkip to conversation

HID: input: rename hidinput_set_battery_charge_status()

PATCH Superseded José Expósito 3 participants 7 messages Aug 6, 2025 – Aug 18, 2025 2 messages not in the archive HID

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 HID: input: rename hidinput_set_battery_charge_status()

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.

---
 drivers/hid/hid-input-test.c | 10 +++++-----
 drivers/hid/hid-input.c      | 38 ++++++++++++++++++------------------
 2 files changed, 24 insertions(+), 24 deletions(-)
drivers/hid/hid-input-test.c +5 -5
index 77c2d45ac62a..6f5c71660d82 100644
@@ -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),
 	{ }
 };
drivers/hid/hid-input.c +19 -19
index ff1784b5c2a4..262787e6eb20 100644
@@ -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);
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 2/2 HID: input: report battery status changes immediately

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

---
 drivers/hid/hid-input.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
drivers/hid/hid-input.c +10 -13
index 262787e6eb20..f45f856a127f 100644
@@ -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;
 
@@ -642,13 +648,8 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
 {
 }
 
-static bool hidinput_update_battery_charge_status(struct hid_device *dev,
-						  unsigned int usage, int value)
-{
-	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 +1516,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;
 	}
 
Signature · 1 line
2.50.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Re: 答复: [External Mail][PATCH v2 2/2] HID: input: report battery status changes immediately

Hi 卢国宏,

The mailing list won't accept your emails unless you send them in plain text format. Forwarding it for awareness:

Quoted 26 lines · 卢国宏

Hello, José!
When I submitted your two changes to Google's Android GKI (The patch I compiled is: https://android-review.googlesource.com/c/kernel/common/+/3723411), they raised two issues:
1. This patch has no functional changes. Why is a cherry-pick needed?
2. FROMGIT patches must cite the source repository, branch, and sha. Please see https://android.googlesource.com/kernel/common/+/refs/heads/android-mainline/README.md

From their documentation, I learned that they recommend submitting the changes as follows:
Requirements for other backports: FROMGIT:, FROMLIST:,
If the patch has been merged into an upstream maintainer tree, but has not yet been merged into Linux mainline
tag the patch subject with FROMGIT:
add info on where the patch came from as (cherry picked from commit <sha1> <repo> <branch>). This must be a stable maintainer branch (not rebased, so don't use linux-next for example). if changes were required, use BACKPORT: FROMGIT:
Example:
if the commit message in the maintainer tree is
important patch from upstream

This is the detailed description of the important patch

then Joe Smith would upload the patch for the common kernel as
FROMGIT: important patch from upstream

This is the detailed description of the important patch

Quoted 7 lines

Bug: 135791357
(cherry picked from commit 878a2fd9de10b03d11d2f622250285c7e63deace
https://git.kernel.org/pub/scm/linux/kernel/git/foo/bar.git test-branch)

Change-Id I4caaaa566ea080fa148c5e768bb1a0b6f7201c01

However, I didn't find the information Google mentioned in your email: the source repo, branch, and sha.
Have you submitted these two patches to the kernel tree? Could you please provide a patch with the information Google needs? Thank you very much!

The patches are not merged yet, that's why you can not find the commit SHA that you need.

A maintainer will send an email to the ML once the patches are reviewed and accepted, but they are very busy, so it'll take some time.

Jose

Quoted 79 lines

________________________________
发件人: José Expósito <[email protected]>
发送时间: 2025年8月6日 15:39
收件人: [email protected]
抄送: [email protected]; 卢国宏; [email protected]; [email protected]; José Expósito 主题: [External Mail][PATCH v2 2/2] HID: input: report battery status changes immediately

[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈

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

---
 drivers/hid/hid-input.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
drivers/hid/hid-input.c +10 -14
index 262787e6eb20..f45f856a127f 100644
@@ -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;
 
@@ -642,13 +648,8 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
 {
 }
 
-static bool hidinput_update_battery_charge_status(struct hid_device *dev,
-                                                 unsigned int usage, int value)
-{
-       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 +1516,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!******/#

maintainer
#4 lore raw

Re: [PATCH v2 2/2] HID: input: report battery status changes immediately

In reply to José Expósito
Quoted 2 lines · José Expósito

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

Could you please make the changelog a little bit more elaborative, i.e. why is it needed, what user-visible behavior change/improvement it brings, etc.

I know it's in the e-mail thread, but at least some summary should go also to the commit itself.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

答复: [External Mail]Re: [PATCH v2 2/2] HID: input: report battery status changes immediately

Hello, José and Jiri!
When will this HID patch be merged into the Linux mainline? We are looking forward to using this feature, so please help us push it forward! Thank you very much!

________________________________________
发件人: 卢国宏
发送时间: 2025年8月12日 8:44
收件人: Jiri Kosina; José Expósito
抄送: [email protected]; [email protected]; [email protected]; Fei1 Jiang 蒋飞; 卢国宏 主题: 答复: [External Mail]Re: [PATCH v2 2/2] HID: input: report battery status changes immediately

Hello, Jiri!

Nowadays, there are more and more HID devices connected to Android and Linux devices. For example, we have already reached the third generation of controllers, a HID device. In each generation, we need to report the charging status of the controller, a HID device, to the Android phone. Only then can the phone know the charging status of the HID device. Based on this charging status, the phone can determine the PD fast charging logic and how to proceed. In addition to us, other mobile phone manufacturers, such as VIVO, have also made several generations of controllers. We also encountered this practical problem in the process of making the controller, so we raised this issue with you. Our solution is also based on the HID protocol. Thank you!

________________________________
发件人: Jiri Kosina <[email protected]>
发送时间: 2025年8月11日 19:48
收件人: José Expósito
抄送: [email protected]; 卢国宏; [email protected]; [email protected] 主题: [External Mail]Re: [PATCH v2 2/2] HID: input: report battery status changes immediately

[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈

Quoted 2 lines · José Expósito

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

Could you please make the changelog a little bit more elaborative, i.e. why is it needed, what user-visible behavior change/improvement it brings, etc.

I know it's in the e-mail thread, but at least some summary should go also to the commit itself.

Thanks,

--
Jiri Kosina
SUSE Labs

#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! 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!******/#

#7 lore raw

Re: [PATCH v2 2/2] HID: input: report battery status changes immediately

In reply to Jiri Kosina

Hi Jiri,

Quoted 11 lines · Jiri Kosina
Quoted 2 lines · José Expósito

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

Could you please make the changelog a little bit more elaborative, i.e. why is it needed, what user-visible behavior change/improvement it brings, etc.

I know it's in the e-mail thread, but at least some summary should go also to the commit itself.

Thanks a lot for reviewing these patches.

I sent v3 with a more detailed description of the fix:
https://lore.kernel.org/linux-input/[email protected]/

Jose

Quoted 6 lines

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#8 lore raw

答复: [External Mail]Re: [PATCH v2 2/2] HID: input: report battery status changes immediately

Hi Jiri,
How's your review of this patch going? We look forward to hearing from you. Thank you!
________________________________________
发件人: José Expósito <[email protected]>
发送时间: 2025年8月14日 18:43
收件人: Jiri Kosina
抄送: [email protected]; 卢国宏; [email protected]; [email protected] 主题: [External Mail]Re: [PATCH v2 2/2] HID: input: report battery status changes immediately

[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈

Hi Jiri,

Quoted 11 lines · Jiri Kosina
Quoted 2 lines · José Expósito

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

Could you please make the changelog a little bit more elaborative, i.e. why is it needed, what user-visible behavior change/improvement it brings, etc.

I know it's in the e-mail thread, but at least some summary should go also to the commit itself.

Thanks a lot for reviewing these patches.

I sent v3 with a more detailed description of the fix:
https://lore.kernel.org/linux-input/[email protected]/

Jose

Quoted 6 lines

Thanks,

--
Jiri Kosina
SUSE Labs

#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! 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!******/#