Skip to content

Commit 85a392d

Browse files
lumagenomsg
authored andcommitted
test_power: Add VOLTAGE_NOW and BATTERY_TEMP properties
Emulate battery temperature (fixed to 26) and battery voltage (variable) properties. Signed-off-by: Dmitry Eremin-Solenikov <dmitry_eremin@mentor.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
1 parent 7384737 commit 85a392d

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎drivers/power/test_power.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static int battery_health = POWER_SUPPLY_HEALTH_GOOD;
2828
static int battery_present = 1; /* true */
2929
static int battery_technology = POWER_SUPPLY_TECHNOLOGY_LION;
3030
static int battery_capacity = 50;
31+
static int battery_voltage = 3300;
3132

3233
static int test_power_get_ac_property(struct power_supply *psy,
3334
enum power_supply_property psp,
@@ -101,6 +102,12 @@ static int test_power_get_battery_property(struct power_supply *psy,
101102
case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
102103
val->intval = 3600;
103104
break;
105+
case POWER_SUPPLY_PROP_TEMP:
106+
val->intval = 26;
107+
break;
108+
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
109+
val->intval = battery_voltage;
110+
break;
104111
default:
105112
pr_info("%s: some properties deliberately report errors.\n",
106113
__func__);
@@ -129,6 +136,8 @@ static enum power_supply_property test_power_battery_props[] = {
129136
POWER_SUPPLY_PROP_MODEL_NAME,
130137
POWER_SUPPLY_PROP_MANUFACTURER,
131138
POWER_SUPPLY_PROP_SERIAL_NUMBER,
139+
POWER_SUPPLY_PROP_TEMP,
140+
POWER_SUPPLY_PROP_VOLTAGE_NOW,
132141
};
133142

134143
static char *test_power_ac_supplied_to[] = {
@@ -387,6 +396,21 @@ static int param_set_battery_capacity(const char *key,
387396

388397
#define param_get_battery_capacity param_get_int
389398

399+
static int param_set_battery_voltage(const char *key,
400+
const struct kernel_param *kp)
401+
{
402+
int tmp;
403+
404+
if (1 != sscanf(key, "%d", &tmp))
405+
return -EINVAL;
406+
407+
battery_voltage = tmp;
408+
power_supply_changed(&test_power_supplies[1]);
409+
return 0;
410+
}
411+
412+
#define param_get_battery_voltage param_get_int
413+
390414
static struct kernel_param_ops param_ops_ac_online = {
391415
.set = param_set_ac_online,
392416
.get = param_get_ac_online,
@@ -422,6 +446,10 @@ static struct kernel_param_ops param_ops_battery_capacity = {
422446
.get = param_get_battery_capacity,
423447
};
424448

449+
static struct kernel_param_ops param_ops_battery_voltage = {
450+
.set = param_set_battery_voltage,
451+
.get = param_get_battery_voltage,
452+
};
425453

426454
#define param_check_ac_online(name, p) __param_check(name, p, void);
427455
#define param_check_usb_online(name, p) __param_check(name, p, void);
@@ -430,6 +458,7 @@ static struct kernel_param_ops param_ops_battery_capacity = {
430458
#define param_check_battery_technology(name, p) __param_check(name, p, void);
431459
#define param_check_battery_health(name, p) __param_check(name, p, void);
432460
#define param_check_battery_capacity(name, p) __param_check(name, p, void);
461+
#define param_check_battery_voltage(name, p) __param_check(name, p, void);
433462

434463

435464
module_param(ac_online, ac_online, 0644);
@@ -457,6 +486,8 @@ MODULE_PARM_DESC(battery_health,
457486
module_param(battery_capacity, battery_capacity, 0644);
458487
MODULE_PARM_DESC(battery_capacity, "battery capacity (percentage)");
459488

489+
module_param(battery_voltage, battery_voltage, 0644);
490+
MODULE_PARM_DESC(battery_voltage, "battery voltage (millivolts)");
460491

461492
MODULE_DESCRIPTION("Power supply driver for testing");
462493
MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");

0 commit comments

Comments
 (0)