#include <linux/delay.h>
#include <linux/vermagic.h>
+enum test_power_id {
+ TEST_AC,
+ TEST_BATTERY,
+ TEST_USB,
+ TEST_POWER_NUM,
+};
+
static int ac_online = 1;
static int usb_online = 1;
static int battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
};
static struct power_supply test_power_supplies[] = {
- {
+ [TEST_AC] = {
.name = "test_ac",
.type = POWER_SUPPLY_TYPE_MAINS,
.supplied_to = test_power_ac_supplied_to,
.properties = test_power_ac_props,
.num_properties = ARRAY_SIZE(test_power_ac_props),
.get_property = test_power_get_ac_property,
- }, {
+ },
+ [TEST_BATTERY] = {
.name = "test_battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = test_power_battery_props,
.num_properties = ARRAY_SIZE(test_power_battery_props),
.get_property = test_power_get_battery_property,
- }, {
+ },
+ [TEST_USB] = {
.name = "test_usb",
.type = POWER_SUPPLY_TYPE_USB,
.supplied_to = test_power_ac_supplied_to,
int i;
int ret;
+ BUILD_BUG_ON(TEST_POWER_NUM != ARRAY_SIZE(test_power_supplies));
+
for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) {
ret = power_supply_register(NULL, &test_power_supplies[i]);
if (ret) {
static int param_set_ac_online(const char *key, const struct kernel_param *kp)
{
ac_online = map_get_value(map_ac_online, key, ac_online);
- signal_power_supply_changed(&test_power_supplies[0]);
+ signal_power_supply_changed(&test_power_supplies[TEST_AC]);
return 0;
}
static int param_set_usb_online(const char *key, const struct kernel_param *kp)
{
usb_online = map_get_value(map_ac_online, key, usb_online);
- signal_power_supply_changed(&test_power_supplies[2]);
+ signal_power_supply_changed(&test_power_supplies[TEST_USB]);
return 0;
}
const struct kernel_param *kp)
{
battery_status = map_get_value(map_status, key, battery_status);
- signal_power_supply_changed(&test_power_supplies[1]);
+ signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
return 0;
}
const struct kernel_param *kp)
{
battery_health = map_get_value(map_health, key, battery_health);
- signal_power_supply_changed(&test_power_supplies[1]);
+ signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
return 0;
}
const struct kernel_param *kp)
{
battery_present = map_get_value(map_present, key, battery_present);
- signal_power_supply_changed(&test_power_supplies[0]);
+ signal_power_supply_changed(&test_power_supplies[TEST_AC]);
return 0;
}
{
battery_technology = map_get_value(map_technology, key,
battery_technology);
- signal_power_supply_changed(&test_power_supplies[1]);
+ signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
return 0;
}
return -EINVAL;
battery_capacity = tmp;
- signal_power_supply_changed(&test_power_supplies[1]);
+ signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
return 0;
}
return -EINVAL;
battery_voltage = tmp;
- signal_power_supply_changed(&test_power_supplies[1]);
+ signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
return 0;
}