mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:04:41 +01:00
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. Tested-by: 卢国宏 <luguohong@xiaomi.com> Signed-off-by: José Expósito <jose.exposito89@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
This commit is contained in:
parent
afa17a09c6
commit
a82231b2a8
2 changed files with 26 additions and 26 deletions
|
|
@ -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),
|
||||
{ }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,15 +642,15 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
|
|||
{
|
||||
}
|
||||
|
||||
static void hidinput_update_battery(struct hid_device *dev, int value)
|
||||
{
|
||||
}
|
||||
|
||||
static bool hidinput_set_battery_charge_status(struct hid_device *dev,
|
||||
unsigned int usage, int value)
|
||||
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)
|
||||
{
|
||||
}
|
||||
#endif /* CONFIG_HID_BATTERY_STRENGTH */
|
||||
|
||||
static bool hidinput_field_in_collection(struct hid_device *device, struct hid_field *field,
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue