Test code from linux kernel
This commit is contained in:
@@ -37,9 +37,6 @@ static int battery_charge_counter = -1000;
|
|||||||
static int battery_current = -1600;
|
static int battery_current = -1600;
|
||||||
static enum power_supply_charge_behaviour battery_charge_behaviour =
|
static enum power_supply_charge_behaviour battery_charge_behaviour =
|
||||||
POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO;
|
POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO;
|
||||||
static enum power_supply_charge_type battery_charge_types =
|
|
||||||
POWER_SUPPLY_CHARGE_TYPE_STANDARD;
|
|
||||||
static bool battery_extension;
|
|
||||||
|
|
||||||
static bool module_initialized;
|
static bool module_initialized;
|
||||||
|
|
||||||
@@ -89,7 +86,7 @@ static int test_power_get_battery_property(struct power_supply *psy,
|
|||||||
val->intval = battery_status;
|
val->intval = battery_status;
|
||||||
break;
|
break;
|
||||||
case POWER_SUPPLY_PROP_CHARGE_TYPE:
|
case POWER_SUPPLY_PROP_CHARGE_TYPE:
|
||||||
val->intval = battery_charge_types;
|
val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
|
||||||
break;
|
break;
|
||||||
case POWER_SUPPLY_PROP_HEALTH:
|
case POWER_SUPPLY_PROP_HEALTH:
|
||||||
val->intval = battery_health;
|
val->intval = battery_health;
|
||||||
@@ -131,9 +128,6 @@ static int test_power_get_battery_property(struct power_supply *psy,
|
|||||||
case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
|
case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
|
||||||
val->intval = battery_charge_behaviour;
|
val->intval = battery_charge_behaviour;
|
||||||
break;
|
break;
|
||||||
case POWER_SUPPLY_PROP_CHARGE_TYPES:
|
|
||||||
val->intval = battery_charge_types;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
pr_info("%s: some properties deliberately report errors.\n",
|
pr_info("%s: some properties deliberately report errors.\n",
|
||||||
__func__);
|
__func__);
|
||||||
@@ -145,7 +139,7 @@ static int test_power_get_battery_property(struct power_supply *psy,
|
|||||||
static int test_power_battery_property_is_writeable(struct power_supply *psy,
|
static int test_power_battery_property_is_writeable(struct power_supply *psy,
|
||||||
enum power_supply_property psp)
|
enum power_supply_property psp)
|
||||||
{
|
{
|
||||||
return psp == POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR || psp == POWER_SUPPLY_PROP_CHARGE_TYPES;
|
return psp == POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_power_set_battery_property(struct power_supply *psy,
|
static int test_power_set_battery_property(struct power_supply *psy,
|
||||||
@@ -161,14 +155,6 @@ static int test_power_set_battery_property(struct power_supply *psy,
|
|||||||
}
|
}
|
||||||
battery_charge_behaviour = val->intval;
|
battery_charge_behaviour = val->intval;
|
||||||
break;
|
break;
|
||||||
case POWER_SUPPLY_PROP_CHARGE_TYPES:
|
|
||||||
if (val->intval < 0 ||
|
|
||||||
val->intval >= BITS_PER_TYPE(typeof(psy->desc->charge_types)) ||
|
|
||||||
!(BIT(val->intval) & psy->desc->charge_types)) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
battery_charge_types = val->intval;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -201,7 +187,6 @@ static enum power_supply_property test_power_battery_props[] = {
|
|||||||
POWER_SUPPLY_PROP_CURRENT_AVG,
|
POWER_SUPPLY_PROP_CURRENT_AVG,
|
||||||
POWER_SUPPLY_PROP_CURRENT_NOW,
|
POWER_SUPPLY_PROP_CURRENT_NOW,
|
||||||
POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
|
POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
|
||||||
POWER_SUPPLY_PROP_CHARGE_TYPES,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *test_power_ac_supplied_to[] = {
|
static char *test_power_ac_supplied_to[] = {
|
||||||
@@ -228,10 +213,7 @@ static const struct power_supply_desc test_power_desc[] = {
|
|||||||
.property_is_writeable = test_power_battery_property_is_writeable,
|
.property_is_writeable = test_power_battery_property_is_writeable,
|
||||||
.charge_behaviours = BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO)
|
.charge_behaviours = BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO)
|
||||||
| BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE)
|
| BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE)
|
||||||
| BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE_AWAKE)
|
|
||||||
| BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE),
|
| BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE),
|
||||||
.charge_types = BIT(POWER_SUPPLY_CHARGE_TYPE_STANDARD)
|
|
||||||
| BIT(POWER_SUPPLY_CHARGE_TYPE_LONGLIFE)
|
|
||||||
},
|
},
|
||||||
[TEST_USB] = {
|
[TEST_USB] = {
|
||||||
.name = "test_usb",
|
.name = "test_usb",
|
||||||
@@ -256,91 +238,6 @@ static const struct power_supply_config test_power_configs[] = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int test_power_battery_extmanufacture_year = 1234;
|
|
||||||
static int test_power_battery_exttemp_max = 1000;
|
|
||||||
static const enum power_supply_property test_power_battery_extprops[] = {
|
|
||||||
POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
|
|
||||||
POWER_SUPPLY_PROP_MANUFACTURE_YEAR,
|
|
||||||
POWER_SUPPLY_PROP_TEMP_MAX,
|
|
||||||
};
|
|
||||||
|
|
||||||
static int test_power_battery_extget_property(struct power_supply *psy,
|
|
||||||
const struct power_supply_ext *ext,
|
|
||||||
void *ext_data,
|
|
||||||
enum power_supply_property psp,
|
|
||||||
union power_supply_propval *val)
|
|
||||||
{
|
|
||||||
switch (psp) {
|
|
||||||
case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
|
|
||||||
return power_supply_get_property_direct(psy, POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
|
|
||||||
val);
|
|
||||||
case POWER_SUPPLY_PROP_MANUFACTURE_YEAR:
|
|
||||||
val->intval = test_power_battery_extmanufacture_year;
|
|
||||||
break;
|
|
||||||
case POWER_SUPPLY_PROP_TEMP_MAX:
|
|
||||||
val->intval = test_power_battery_exttemp_max;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int test_power_battery_extset_property(struct power_supply *psy,
|
|
||||||
const struct power_supply_ext *ext,
|
|
||||||
void *ext_data,
|
|
||||||
enum power_supply_property psp,
|
|
||||||
const union power_supply_propval *val)
|
|
||||||
{
|
|
||||||
switch (psp) {
|
|
||||||
case POWER_SUPPLY_PROP_MANUFACTURE_YEAR:
|
|
||||||
test_power_battery_extmanufacture_year = val->intval;
|
|
||||||
break;
|
|
||||||
case POWER_SUPPLY_PROP_TEMP_MAX:
|
|
||||||
test_power_battery_exttemp_max = val->intval;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int test_power_battery_extproperty_is_writeable(struct power_supply *psy,
|
|
||||||
const struct power_supply_ext *ext,
|
|
||||||
void *ext_data,
|
|
||||||
enum power_supply_property psp)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct power_supply_ext test_power_battery_ext = {
|
|
||||||
.name = "test_power",
|
|
||||||
.properties = test_power_battery_extprops,
|
|
||||||
.num_properties = ARRAY_SIZE(test_power_battery_extprops),
|
|
||||||
.get_property = test_power_battery_extget_property,
|
|
||||||
.set_property = test_power_battery_extset_property,
|
|
||||||
.property_is_writeable = test_power_battery_extproperty_is_writeable,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void test_power_configure_battery_extension(bool enable)
|
|
||||||
{
|
|
||||||
struct power_supply *psy;
|
|
||||||
|
|
||||||
psy = test_power_supplies[TEST_BATTERY];
|
|
||||||
|
|
||||||
if (enable) {
|
|
||||||
if (power_supply_register_extension(psy, &test_power_battery_ext, &psy->dev,
|
|
||||||
NULL)) {
|
|
||||||
pr_err("registering battery extension failed\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
power_supply_unregister_extension(psy, &test_power_battery_ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
battery_extension = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __init test_power_init(void)
|
static int __init test_power_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -361,8 +258,6 @@ static int __init test_power_init(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test_power_configure_battery_extension(true);
|
|
||||||
|
|
||||||
module_initialized = true;
|
module_initialized = true;
|
||||||
return 0;
|
return 0;
|
||||||
failed:
|
failed:
|
||||||
@@ -440,6 +335,7 @@ static struct battery_property_map map_technology[] = {
|
|||||||
{ -1, NULL },
|
{ -1, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static int map_get_value(struct battery_property_map *map, const char *key,
|
static int map_get_value(struct battery_property_map *map, const char *key,
|
||||||
int def_val)
|
int def_val)
|
||||||
{
|
{
|
||||||
@@ -628,26 +524,6 @@ static int param_set_battery_current(const char *key,
|
|||||||
|
|
||||||
#define param_get_battery_current param_get_int
|
#define param_get_battery_current param_get_int
|
||||||
|
|
||||||
static int param_set_battery_extension(const char *key,
|
|
||||||
const struct kernel_param *kp)
|
|
||||||
{
|
|
||||||
bool prev_battery_extension;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
prev_battery_extension = battery_extension;
|
|
||||||
|
|
||||||
ret = param_set_bool(key, kp);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (prev_battery_extension != battery_extension)
|
|
||||||
test_power_configure_battery_extension(battery_extension);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define param_get_battery_extension param_get_bool
|
|
||||||
|
|
||||||
static const struct kernel_param_ops param_ops_ac_online = {
|
static const struct kernel_param_ops param_ops_ac_online = {
|
||||||
.set = param_set_ac_online,
|
.set = param_set_ac_online,
|
||||||
.get = param_get_ac_online,
|
.get = param_get_ac_online,
|
||||||
@@ -698,11 +574,6 @@ static const struct kernel_param_ops param_ops_battery_current = {
|
|||||||
.get = param_get_battery_current,
|
.get = param_get_battery_current,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct kernel_param_ops param_ops_battery_extension = {
|
|
||||||
.set = param_set_battery_extension,
|
|
||||||
.get = param_get_battery_extension,
|
|
||||||
};
|
|
||||||
|
|
||||||
#define param_check_ac_online(name, p) __param_check(name, p, void);
|
#define param_check_ac_online(name, p) __param_check(name, p, void);
|
||||||
#define param_check_usb_online(name, p) __param_check(name, p, void);
|
#define param_check_usb_online(name, p) __param_check(name, p, void);
|
||||||
#define param_check_battery_status(name, p) __param_check(name, p, void);
|
#define param_check_battery_status(name, p) __param_check(name, p, void);
|
||||||
@@ -713,7 +584,7 @@ static const struct kernel_param_ops param_ops_battery_extension = {
|
|||||||
#define param_check_battery_voltage(name, p) __param_check(name, p, void);
|
#define param_check_battery_voltage(name, p) __param_check(name, p, void);
|
||||||
#define param_check_battery_charge_counter(name, p) __param_check(name, p, void);
|
#define param_check_battery_charge_counter(name, p) __param_check(name, p, void);
|
||||||
#define param_check_battery_current(name, p) __param_check(name, p, void);
|
#define param_check_battery_current(name, p) __param_check(name, p, void);
|
||||||
#define param_check_battery_extension(name, p) __param_check(name, p, void);
|
|
||||||
|
|
||||||
module_param(ac_online, ac_online, 0644);
|
module_param(ac_online, ac_online, 0644);
|
||||||
MODULE_PARM_DESC(ac_online, "AC charging state <on|off>");
|
MODULE_PARM_DESC(ac_online, "AC charging state <on|off>");
|
||||||
@@ -750,9 +621,6 @@ MODULE_PARM_DESC(battery_charge_counter,
|
|||||||
module_param(battery_current, battery_current, 0644);
|
module_param(battery_current, battery_current, 0644);
|
||||||
MODULE_PARM_DESC(battery_current, "battery current (milliampere)");
|
MODULE_PARM_DESC(battery_current, "battery current (milliampere)");
|
||||||
|
|
||||||
module_param(battery_extension, battery_extension, 0644);
|
|
||||||
MODULE_PARM_DESC(battery_extension, "battery extension");
|
|
||||||
|
|
||||||
MODULE_DESCRIPTION("Power supply driver for testing");
|
MODULE_DESCRIPTION("Power supply driver for testing");
|
||||||
MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
|
MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
|
|||||||
Reference in New Issue
Block a user