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
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include <kunit/test.h>
|
#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;
|
struct hid_device *dev;
|
||||||
bool handled;
|
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);
|
dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
|
||||||
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
|
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_FALSE(test, handled);
|
||||||
KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_UNKNOWN);
|
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_TRUE(test, handled);
|
||||||
KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_DISCHARGING);
|
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_TRUE(test, handled);
|
||||||
KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_CHARGING);
|
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[] = {
|
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),
|
KUNIT_CASE(hid_test_input_get_battery_property),
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -595,6 +595,20 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
|
||||||
dev->battery = NULL;
|
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)
|
static void hidinput_update_battery(struct hid_device *dev, int value)
|
||||||
{
|
{
|
||||||
int capacity;
|
int capacity;
|
||||||
|
|
@ -617,20 +631,6 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
|
||||||
power_supply_changed(dev->battery);
|
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 */
|
#else /* !CONFIG_HID_BATTERY_STRENGTH */
|
||||||
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
|
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
|
||||||
struct hid_field *field, bool is_percentage)
|
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_update_battery_charge_status(struct hid_device *dev,
|
||||||
{
|
unsigned int usage, int value)
|
||||||
}
|
|
||||||
|
|
||||||
static bool hidinput_set_battery_charge_status(struct hid_device *dev,
|
|
||||||
unsigned int usage, int value)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hidinput_update_battery(struct hid_device *dev, int value)
|
||||||
|
{
|
||||||
|
}
|
||||||
#endif /* CONFIG_HID_BATTERY_STRENGTH */
|
#endif /* CONFIG_HID_BATTERY_STRENGTH */
|
||||||
|
|
||||||
static bool hidinput_field_in_collection(struct hid_device *device, struct hid_field *field,
|
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;
|
return;
|
||||||
|
|
||||||
if (usage->type == EV_PWR) {
|
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)
|
if (!handled)
|
||||||
hidinput_update_battery(hid, value);
|
hidinput_update_battery(hid, value);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue