|
@@ -21,6 +21,13 @@
|
|
#include <linux/delay.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/vermagic.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 ac_online = 1;
|
|
static int usb_online = 1;
|
|
static int usb_online = 1;
|
|
static int battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
|
|
static int battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
|
|
@@ -147,7 +154,7 @@ static char *test_power_ac_supplied_to[] = {
|
|
};
|
|
};
|
|
|
|
|
|
static struct power_supply test_power_supplies[] = {
|
|
static struct power_supply test_power_supplies[] = {
|
|
- {
|
|
|
|
|
|
+ [TEST_AC] = {
|
|
.name = "test_ac",
|
|
.name = "test_ac",
|
|
.type = POWER_SUPPLY_TYPE_MAINS,
|
|
.type = POWER_SUPPLY_TYPE_MAINS,
|
|
.supplied_to = test_power_ac_supplied_to,
|
|
.supplied_to = test_power_ac_supplied_to,
|
|
@@ -155,13 +162,15 @@ static struct power_supply test_power_supplies[] = {
|
|
.properties = test_power_ac_props,
|
|
.properties = test_power_ac_props,
|
|
.num_properties = ARRAY_SIZE(test_power_ac_props),
|
|
.num_properties = ARRAY_SIZE(test_power_ac_props),
|
|
.get_property = test_power_get_ac_property,
|
|
.get_property = test_power_get_ac_property,
|
|
- }, {
|
|
|
|
|
|
+ },
|
|
|
|
+ [TEST_BATTERY] = {
|
|
.name = "test_battery",
|
|
.name = "test_battery",
|
|
.type = POWER_SUPPLY_TYPE_BATTERY,
|
|
.type = POWER_SUPPLY_TYPE_BATTERY,
|
|
.properties = test_power_battery_props,
|
|
.properties = test_power_battery_props,
|
|
.num_properties = ARRAY_SIZE(test_power_battery_props),
|
|
.num_properties = ARRAY_SIZE(test_power_battery_props),
|
|
.get_property = test_power_get_battery_property,
|
|
.get_property = test_power_get_battery_property,
|
|
- }, {
|
|
|
|
|
|
+ },
|
|
|
|
+ [TEST_USB] = {
|
|
.name = "test_usb",
|
|
.name = "test_usb",
|
|
.type = POWER_SUPPLY_TYPE_USB,
|
|
.type = POWER_SUPPLY_TYPE_USB,
|
|
.supplied_to = test_power_ac_supplied_to,
|
|
.supplied_to = test_power_ac_supplied_to,
|
|
@@ -178,6 +187,8 @@ static int __init test_power_init(void)
|
|
int i;
|
|
int i;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
|
|
+ BUILD_BUG_ON(TEST_POWER_NUM != ARRAY_SIZE(test_power_supplies));
|
|
|
|
+
|
|
for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) {
|
|
for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) {
|
|
ret = power_supply_register(NULL, &test_power_supplies[i]);
|
|
ret = power_supply_register(NULL, &test_power_supplies[i]);
|
|
if (ret) {
|
|
if (ret) {
|
|
@@ -309,7 +320,7 @@ static inline void signal_power_supply_changed(struct power_supply *psy)
|
|
static int param_set_ac_online(const char *key, const struct kernel_param *kp)
|
|
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);
|
|
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;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -322,7 +333,7 @@ static int param_get_ac_online(char *buffer, const struct kernel_param *kp)
|
|
static int param_set_usb_online(const char *key, const struct kernel_param *kp)
|
|
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);
|
|
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;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -336,7 +347,7 @@ static int param_set_battery_status(const char *key,
|
|
const struct kernel_param *kp)
|
|
const struct kernel_param *kp)
|
|
{
|
|
{
|
|
battery_status = map_get_value(map_status, key, battery_status);
|
|
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;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -350,7 +361,7 @@ static int param_set_battery_health(const char *key,
|
|
const struct kernel_param *kp)
|
|
const struct kernel_param *kp)
|
|
{
|
|
{
|
|
battery_health = map_get_value(map_health, key, battery_health);
|
|
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;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -364,7 +375,7 @@ static int param_set_battery_present(const char *key,
|
|
const struct kernel_param *kp)
|
|
const struct kernel_param *kp)
|
|
{
|
|
{
|
|
battery_present = map_get_value(map_present, key, battery_present);
|
|
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;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -380,7 +391,7 @@ static int param_set_battery_technology(const char *key,
|
|
{
|
|
{
|
|
battery_technology = map_get_value(map_technology, key,
|
|
battery_technology = map_get_value(map_technology, key,
|
|
battery_technology);
|
|
battery_technology);
|
|
- signal_power_supply_changed(&test_power_supplies[1]);
|
|
|
|
|
|
+ signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -401,7 +412,7 @@ static int param_set_battery_capacity(const char *key,
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
battery_capacity = tmp;
|
|
battery_capacity = tmp;
|
|
- signal_power_supply_changed(&test_power_supplies[1]);
|
|
|
|
|
|
+ signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -416,7 +427,7 @@ static int param_set_battery_voltage(const char *key,
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
battery_voltage = tmp;
|
|
battery_voltage = tmp;
|
|
- signal_power_supply_changed(&test_power_supplies[1]);
|
|
|
|
|
|
+ signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|