Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Dmitry Eremin-Solenikov and committed by
Anton Vorontsov
85a392d4 73847375

+31
+31
drivers/power/test_power.c
··· 28 28 static int battery_present = 1; /* true */ 29 29 static int battery_technology = POWER_SUPPLY_TECHNOLOGY_LION; 30 30 static int battery_capacity = 50; 31 + static int battery_voltage = 3300; 31 32 32 33 static int test_power_get_ac_property(struct power_supply *psy, 33 34 enum power_supply_property psp, ··· 102 101 case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: 103 102 val->intval = 3600; 104 103 break; 104 + case POWER_SUPPLY_PROP_TEMP: 105 + val->intval = 26; 106 + break; 107 + case POWER_SUPPLY_PROP_VOLTAGE_NOW: 108 + val->intval = battery_voltage; 109 + break; 105 110 default: 106 111 pr_info("%s: some properties deliberately report errors.\n", 107 112 __func__); ··· 136 129 POWER_SUPPLY_PROP_MODEL_NAME, 137 130 POWER_SUPPLY_PROP_MANUFACTURER, 138 131 POWER_SUPPLY_PROP_SERIAL_NUMBER, 132 + POWER_SUPPLY_PROP_TEMP, 133 + POWER_SUPPLY_PROP_VOLTAGE_NOW, 139 134 }; 140 135 141 136 static char *test_power_ac_supplied_to[] = { ··· 396 387 397 388 #define param_get_battery_capacity param_get_int 398 389 390 + static int param_set_battery_voltage(const char *key, 391 + const struct kernel_param *kp) 392 + { 393 + int tmp; 394 + 395 + if (1 != sscanf(key, "%d", &tmp)) 396 + return -EINVAL; 397 + 398 + battery_voltage = tmp; 399 + power_supply_changed(&test_power_supplies[1]); 400 + return 0; 401 + } 402 + 403 + #define param_get_battery_voltage param_get_int 404 + 399 405 static struct kernel_param_ops param_ops_ac_online = { 400 406 .set = param_set_ac_online, 401 407 .get = param_get_ac_online, ··· 446 422 .get = param_get_battery_capacity, 447 423 }; 448 424 425 + static struct kernel_param_ops param_ops_battery_voltage = { 426 + .set = param_set_battery_voltage, 427 + .get = param_get_battery_voltage, 428 + }; 449 429 450 430 #define param_check_ac_online(name, p) __param_check(name, p, void); 451 431 #define param_check_usb_online(name, p) __param_check(name, p, void); ··· 458 430 #define param_check_battery_technology(name, p) __param_check(name, p, void); 459 431 #define param_check_battery_health(name, p) __param_check(name, p, void); 460 432 #define param_check_battery_capacity(name, p) __param_check(name, p, void); 433 + #define param_check_battery_voltage(name, p) __param_check(name, p, void); 461 434 462 435 463 436 module_param(ac_online, ac_online, 0644); ··· 486 457 module_param(battery_capacity, battery_capacity, 0644); 487 458 MODULE_PARM_DESC(battery_capacity, "battery capacity (percentage)"); 488 459 460 + module_param(battery_voltage, battery_voltage, 0644); 461 + MODULE_PARM_DESC(battery_voltage, "battery voltage (millivolts)"); 489 462 490 463 MODULE_DESCRIPTION("Power supply driver for testing"); 491 464 MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");