17 #include <linux/kernel.h>
18 #include <linux/module.h>
20 #include <linux/errno.h>
24 static int ac_online = 1;
25 static int usb_online = 1;
28 static int battery_present = 1;
30 static int battery_capacity = 50;
31 static int battery_voltage = 3300;
33 static int test_power_get_ac_property(
struct power_supply *psy,
47 static int test_power_get_usb_property(
struct power_supply *psy,
61 static int test_power_get_battery_property(
struct power_supply *psy,
67 val->
strval =
"Test battery";
76 val->
intval = battery_status;
82 val->
intval = battery_health;
85 val->
intval = battery_present;
88 val->
intval = battery_technology;
95 val->
intval = battery_capacity;
109 val->
intval = battery_voltage;
112 pr_info(
"%s: some properties deliberately report errors.\n",
143 static char *test_power_ac_supplied_to[] = {
151 .supplied_to = test_power_ac_supplied_to,
152 .num_supplicants =
ARRAY_SIZE(test_power_ac_supplied_to),
153 .properties = test_power_ac_props,
154 .num_properties =
ARRAY_SIZE(test_power_ac_props),
155 .get_property = test_power_get_ac_property,
157 .name =
"test_battery",
159 .properties = test_power_battery_props,
160 .num_properties =
ARRAY_SIZE(test_power_battery_props),
161 .get_property = test_power_get_battery_property,
165 .supplied_to = test_power_ac_supplied_to,
166 .num_supplicants =
ARRAY_SIZE(test_power_ac_supplied_to),
167 .properties = test_power_ac_props,
168 .num_properties =
ARRAY_SIZE(test_power_ac_props),
169 .get_property = test_power_get_usb_property,
174 static int __init test_power_init(
void)
179 for (i = 0; i <
ARRAY_SIZE(test_power_supplies); i++) {
182 pr_err(
"%s: failed to register %s\n", __func__,
183 test_power_supplies[i].
name);
196 static void __exit test_power_exit(
void)
204 for (i = 0; i <
ARRAY_SIZE(test_power_supplies); i++)
206 pr_info(
"%s: 'changed' event sent, sleeping for 10 seconds...\n",
210 for (i = 0; i <
ARRAY_SIZE(test_power_supplies); i++)
217 #define MAX_KEYLENGTH 256
290 if (map->
value == value)
298 static int param_set_ac_online(
const char *key,
const struct kernel_param *kp)
300 ac_online = map_get_value(map_ac_online, key, ac_online);
307 strcpy(buffer, map_get_key(map_ac_online, ac_online,
"unknown"));
311 static int param_set_usb_online(
const char *key,
const struct kernel_param *kp)
313 usb_online = map_get_value(map_ac_online, key, usb_online);
318 static int param_get_usb_online(
char *buffer,
const struct kernel_param *kp)
320 strcpy(buffer, map_get_key(map_ac_online, usb_online,
"unknown"));
324 static int param_set_battery_status(
const char *key,
327 battery_status = map_get_value(map_status, key, battery_status);
332 static int param_get_battery_status(
char *buffer,
const struct kernel_param *kp)
334 strcpy(buffer, map_get_key(map_status, battery_status,
"unknown"));
338 static int param_set_battery_health(
const char *key,
341 battery_health = map_get_value(map_health, key, battery_health);
346 static int param_get_battery_health(
char *buffer,
const struct kernel_param *kp)
348 strcpy(buffer, map_get_key(map_health, battery_health,
"unknown"));
352 static int param_set_battery_present(
const char *key,
355 battery_present = map_get_value(map_present, key, battery_present);
360 static int param_get_battery_present(
char *buffer,
363 strcpy(buffer, map_get_key(map_present, battery_present,
"unknown"));
367 static int param_set_battery_technology(
const char *key,
370 battery_technology = map_get_value(map_technology, key,
376 static int param_get_battery_technology(
char *buffer,
380 map_get_key(map_technology, battery_technology,
"unknown"));
384 static int param_set_battery_capacity(
const char *key,
389 if (1 !=
sscanf(key,
"%d", &tmp))
392 battery_capacity =
tmp;
397 #define param_get_battery_capacity param_get_int
399 static int param_set_battery_voltage(
const char *key,
404 if (1 !=
sscanf(key,
"%d", &tmp))
407 battery_voltage =
tmp;
412 #define param_get_battery_voltage param_get_int
415 .set = param_set_ac_online,
416 .get = param_get_ac_online,
420 .set = param_set_usb_online,
421 .get = param_get_usb_online,
425 .set = param_set_battery_status,
426 .get = param_get_battery_status,
430 .set = param_set_battery_present,
431 .get = param_get_battery_present,
435 .set = param_set_battery_technology,
436 .get = param_get_battery_technology,
440 .set = param_set_battery_health,
441 .get = param_get_battery_health,
445 .set = param_set_battery_capacity,
450 .set = param_set_battery_voltage,
454 #define param_check_ac_online(name, p) __param_check(name, p, void);
455 #define param_check_usb_online(name, p) __param_check(name, p, void);
456 #define param_check_battery_status(name, p) __param_check(name, p, void);
457 #define param_check_battery_present(name, p) __param_check(name, p, void);
458 #define param_check_battery_technology(name, p) __param_check(name, p, void);
459 #define param_check_battery_health(name, p) __param_check(name, p, void);
460 #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);
472 "battery status <charging|discharging|not-charging|full>");
476 "battery presence state <good|overheat|dead|overvoltage|failure>");
478 module_param(battery_technology, battery_technology, 0644);
480 "battery technology <NiMH|LION|LIPO|LiFe|NiCd|LiMn>");
484 "battery health state <good|overheat|dead|overvoltage|failure>");