xref: /linux/drivers/power/supply/test_power.c (revision f6695269dc52d133ecf6468aa7cbfe29987630ed)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Power supply driver for testing.
4  *
5  * Copyright 2010  Anton Vorontsov <cbouatmailru@gmail.com>
6  *
7  * Dynamic module parameter code from the Virtual Battery Driver
8  * Copyright (C) 2008 Pylone, Inc.
9  * By: Masashi YOKOTA <yokota@pylone.jp>
10  * Originally found here:
11  * http://downloads.pylone.jp/src/virtual_battery/virtual_battery-0.0.1.tar.bz2
12  */
13 
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/power_supply.h>
17 #include <linux/errno.h>
18 #include <linux/delay.h>
19 #include <generated/utsrelease.h>
20 
21 enum test_power_id {
22 	TEST_AC,
23 	TEST_BATTERY,
24 	TEST_USB,
25 	TEST_POWER_NUM,
26 };
27 
28 static int ac_online			= 1;
29 static int usb_online			= 1;
30 static int battery_status		= POWER_SUPPLY_STATUS_DISCHARGING;
31 static int battery_health		= POWER_SUPPLY_HEALTH_GOOD;
32 static int battery_present		= 1; /* true */
33 static int battery_technology		= POWER_SUPPLY_TECHNOLOGY_LION;
34 static int battery_capacity		= 50;
35 static int battery_voltage		= 3300;
36 static int battery_charge_counter	= -1000;
37 static int battery_current		= -1600;
38 static enum power_supply_charge_behaviour battery_charge_behaviour =
39 	POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO;
40 static enum power_supply_charge_type battery_charge_types =
41 	POWER_SUPPLY_CHARGE_TYPE_STANDARD;
42 static bool battery_extension;
43 
44 static bool module_initialized;
45 
46 static int test_power_get_ac_property(struct power_supply *psy,
47 				      enum power_supply_property psp,
48 				      union power_supply_propval *val)
49 {
50 	switch (psp) {
51 	case POWER_SUPPLY_PROP_ONLINE:
52 		val->intval = ac_online;
53 		break;
54 	default:
55 		return -EINVAL;
56 	}
57 	return 0;
58 }
59 
60 static int test_power_get_usb_property(struct power_supply *psy,
61 				      enum power_supply_property psp,
62 				      union power_supply_propval *val)
63 {
64 	switch (psp) {
65 	case POWER_SUPPLY_PROP_ONLINE:
66 		val->intval = usb_online;
67 		break;
68 	default:
69 		return -EINVAL;
70 	}
71 	return 0;
72 }
73 
74 static int test_power_get_battery_property(struct power_supply *psy,
75 					   enum power_supply_property psp,
76 					   union power_supply_propval *val)
77 {
78 	switch (psp) {
79 	case POWER_SUPPLY_PROP_MODEL_NAME:
80 		val->strval = "Test battery";
81 		break;
82 	case POWER_SUPPLY_PROP_MANUFACTURER:
83 		val->strval = "Linux";
84 		break;
85 	case POWER_SUPPLY_PROP_SERIAL_NUMBER:
86 		val->strval = UTS_RELEASE;
87 		break;
88 	case POWER_SUPPLY_PROP_STATUS:
89 		val->intval = battery_status;
90 		break;
91 	case POWER_SUPPLY_PROP_CHARGE_TYPE:
92 		val->intval = battery_charge_types;
93 		break;
94 	case POWER_SUPPLY_PROP_HEALTH:
95 		val->intval = battery_health;
96 		break;
97 	case POWER_SUPPLY_PROP_PRESENT:
98 		val->intval = battery_present;
99 		break;
100 	case POWER_SUPPLY_PROP_TECHNOLOGY:
101 		val->intval = battery_technology;
102 		break;
103 	case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
104 		val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
105 		break;
106 	case POWER_SUPPLY_PROP_CAPACITY:
107 	case POWER_SUPPLY_PROP_CHARGE_NOW:
108 		val->intval = battery_capacity;
109 		break;
110 	case POWER_SUPPLY_PROP_CHARGE_COUNTER:
111 		val->intval = battery_charge_counter;
112 		break;
113 	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
114 	case POWER_SUPPLY_PROP_CHARGE_FULL:
115 		val->intval = 100;
116 		break;
117 	case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
118 	case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
119 		val->intval = 3600;
120 		break;
121 	case POWER_SUPPLY_PROP_TEMP:
122 		val->intval = 26;
123 		break;
124 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
125 		val->intval = battery_voltage;
126 		break;
127 	case POWER_SUPPLY_PROP_CURRENT_AVG:
128 	case POWER_SUPPLY_PROP_CURRENT_NOW:
129 		val->intval = battery_current;
130 		break;
131 	case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
132 		val->intval = battery_charge_behaviour;
133 		break;
134 	case POWER_SUPPLY_PROP_CHARGE_TYPES:
135 		val->intval = battery_charge_types;
136 		break;
137 	default:
138 		pr_info("%s: some properties deliberately report errors.\n",
139 			__func__);
140 		return -EINVAL;
141 	}
142 	return 0;
143 }
144 
145 static int test_power_battery_property_is_writeable(struct power_supply *psy,
146 						    enum power_supply_property psp)
147 {
148 	return psp == POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR || psp == POWER_SUPPLY_PROP_CHARGE_TYPES;
149 }
150 
151 static int test_power_set_battery_property(struct power_supply *psy,
152 					   enum power_supply_property psp,
153 					   const union power_supply_propval *val)
154 {
155 	switch (psp) {
156 	case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
157 		if (val->intval < 0 ||
158 		    val->intval >= BITS_PER_TYPE(typeof(psy->desc->charge_behaviours)) ||
159 		    !(BIT(val->intval) & psy->desc->charge_behaviours)) {
160 			return -EINVAL;
161 		}
162 		battery_charge_behaviour = val->intval;
163 		break;
164 	case POWER_SUPPLY_PROP_CHARGE_TYPES:
165 		if (val->intval < 0 ||
166 		    val->intval >= BITS_PER_TYPE(typeof(psy->desc->charge_types)) ||
167 		    !(BIT(val->intval) & psy->desc->charge_types)) {
168 			return -EINVAL;
169 		}
170 		battery_charge_types = val->intval;
171 		break;
172 	default:
173 		return -EINVAL;
174 	}
175 	return 0;
176 }
177 
178 static enum power_supply_property test_power_ac_props[] = {
179 	POWER_SUPPLY_PROP_ONLINE,
180 };
181 
182 static enum power_supply_property test_power_battery_props[] = {
183 	POWER_SUPPLY_PROP_STATUS,
184 	POWER_SUPPLY_PROP_CHARGE_TYPE,
185 	POWER_SUPPLY_PROP_HEALTH,
186 	POWER_SUPPLY_PROP_PRESENT,
187 	POWER_SUPPLY_PROP_TECHNOLOGY,
188 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
189 	POWER_SUPPLY_PROP_CHARGE_FULL,
190 	POWER_SUPPLY_PROP_CHARGE_NOW,
191 	POWER_SUPPLY_PROP_CHARGE_COUNTER,
192 	POWER_SUPPLY_PROP_CAPACITY,
193 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
194 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
195 	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
196 	POWER_SUPPLY_PROP_MODEL_NAME,
197 	POWER_SUPPLY_PROP_MANUFACTURER,
198 	POWER_SUPPLY_PROP_SERIAL_NUMBER,
199 	POWER_SUPPLY_PROP_TEMP,
200 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
201 	POWER_SUPPLY_PROP_CURRENT_AVG,
202 	POWER_SUPPLY_PROP_CURRENT_NOW,
203 	POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
204 	POWER_SUPPLY_PROP_CHARGE_TYPES,
205 };
206 
207 static char *test_power_ac_supplied_to[] = {
208 	"test_battery",
209 };
210 
211 static struct power_supply *test_power_supplies[TEST_POWER_NUM];
212 
213 static const struct power_supply_desc test_power_desc[] = {
214 	[TEST_AC] = {
215 		.name = "test_ac",
216 		.type = POWER_SUPPLY_TYPE_MAINS,
217 		.properties = test_power_ac_props,
218 		.num_properties = ARRAY_SIZE(test_power_ac_props),
219 		.get_property = test_power_get_ac_property,
220 	},
221 	[TEST_BATTERY] = {
222 		.name = "test_battery",
223 		.type = POWER_SUPPLY_TYPE_BATTERY,
224 		.properties = test_power_battery_props,
225 		.num_properties = ARRAY_SIZE(test_power_battery_props),
226 		.get_property = test_power_get_battery_property,
227 		.set_property = test_power_set_battery_property,
228 		.property_is_writeable = test_power_battery_property_is_writeable,
229 		.charge_behaviours = BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO)
230 				   | BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE)
231 				   | BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE),
232 		.charge_types = BIT(POWER_SUPPLY_CHARGE_TYPE_STANDARD)
233 				   | BIT(POWER_SUPPLY_CHARGE_TYPE_LONGLIFE)
234 	},
235 	[TEST_USB] = {
236 		.name = "test_usb",
237 		.type = POWER_SUPPLY_TYPE_USB,
238 		.properties = test_power_ac_props,
239 		.num_properties = ARRAY_SIZE(test_power_ac_props),
240 		.get_property = test_power_get_usb_property,
241 	},
242 };
243 
244 static const struct power_supply_config test_power_configs[] = {
245 	{
246 		/* test_ac */
247 		.supplied_to = test_power_ac_supplied_to,
248 		.num_supplicants = ARRAY_SIZE(test_power_ac_supplied_to),
249 	}, {
250 		/* test_battery */
251 	}, {
252 		/* test_usb */
253 		.supplied_to = test_power_ac_supplied_to,
254 		.num_supplicants = ARRAY_SIZE(test_power_ac_supplied_to),
255 	},
256 };
257 
258 static int test_power_battery_extmanufacture_year = 1234;
259 static int test_power_battery_exttemp_max = 1000;
260 static const enum power_supply_property test_power_battery_extprops[] = {
261 	POWER_SUPPLY_PROP_MANUFACTURE_YEAR,
262 	POWER_SUPPLY_PROP_TEMP_MAX,
263 };
264 
265 static int test_power_battery_extget_property(struct power_supply *psy,
266 					      const struct power_supply_ext *ext,
267 					      void *ext_data,
268 					      enum power_supply_property psp,
269 					      union power_supply_propval *val)
270 {
271 	switch (psp) {
272 	case POWER_SUPPLY_PROP_MANUFACTURE_YEAR:
273 		val->intval = test_power_battery_extmanufacture_year;
274 		break;
275 	case POWER_SUPPLY_PROP_TEMP_MAX:
276 		val->intval = test_power_battery_exttemp_max;
277 		break;
278 	default:
279 		return -EINVAL;
280 	}
281 	return 0;
282 }
283 
284 static int test_power_battery_extset_property(struct power_supply *psy,
285 					      const struct power_supply_ext *ext,
286 					      void *ext_data,
287 					      enum power_supply_property psp,
288 					      const union power_supply_propval *val)
289 {
290 	switch (psp) {
291 	case POWER_SUPPLY_PROP_MANUFACTURE_YEAR:
292 		test_power_battery_extmanufacture_year = val->intval;
293 		break;
294 	case POWER_SUPPLY_PROP_TEMP_MAX:
295 		test_power_battery_exttemp_max = val->intval;
296 		break;
297 	default:
298 		return -EINVAL;
299 	}
300 	return 0;
301 }
302 
303 static int test_power_battery_extproperty_is_writeable(struct power_supply *psy,
304 						       const struct power_supply_ext *ext,
305 						       void *ext_data,
306 						       enum power_supply_property psp)
307 {
308 	return true;
309 }
310 
311 static const struct power_supply_ext test_power_battery_ext = {
312 	.name			= "test_power",
313 	.properties		= test_power_battery_extprops,
314 	.num_properties		= ARRAY_SIZE(test_power_battery_extprops),
315 	.get_property		= test_power_battery_extget_property,
316 	.set_property		= test_power_battery_extset_property,
317 	.property_is_writeable	= test_power_battery_extproperty_is_writeable,
318 };
319 
320 static void test_power_configure_battery_extension(bool enable)
321 {
322 	struct power_supply *psy;
323 
324 	psy = test_power_supplies[TEST_BATTERY];
325 
326 	if (enable) {
327 		if (power_supply_register_extension(psy, &test_power_battery_ext, &psy->dev,
328 						    NULL)) {
329 			pr_err("registering battery extension failed\n");
330 			return;
331 		}
332 	} else {
333 		power_supply_unregister_extension(psy, &test_power_battery_ext);
334 	}
335 
336 	battery_extension = enable;
337 }
338 
339 static int __init test_power_init(void)
340 {
341 	int i;
342 	int ret;
343 
344 	BUILD_BUG_ON(TEST_POWER_NUM != ARRAY_SIZE(test_power_supplies));
345 	BUILD_BUG_ON(TEST_POWER_NUM != ARRAY_SIZE(test_power_configs));
346 
347 	for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) {
348 		test_power_supplies[i] = power_supply_register(NULL,
349 						&test_power_desc[i],
350 						&test_power_configs[i]);
351 		if (IS_ERR(test_power_supplies[i])) {
352 			pr_err("%s: failed to register %s\n", __func__,
353 				test_power_desc[i].name);
354 			ret = PTR_ERR(test_power_supplies[i]);
355 			goto failed;
356 		}
357 	}
358 
359 	test_power_configure_battery_extension(true);
360 
361 	module_initialized = true;
362 	return 0;
363 failed:
364 	while (--i >= 0)
365 		power_supply_unregister(test_power_supplies[i]);
366 	return ret;
367 }
368 module_init(test_power_init);
369 
370 static void __exit test_power_exit(void)
371 {
372 	int i;
373 
374 	/* Let's see how we handle changes... */
375 	ac_online = 0;
376 	usb_online = 0;
377 	battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
378 	for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++)
379 		power_supply_changed(test_power_supplies[i]);
380 	pr_info("%s: 'changed' event sent, sleeping for 10 seconds...\n",
381 		__func__);
382 	ssleep(10);
383 
384 	for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++)
385 		power_supply_unregister(test_power_supplies[i]);
386 
387 	module_initialized = false;
388 }
389 module_exit(test_power_exit);
390 
391 
392 
393 #define MAX_KEYLENGTH 256
394 struct battery_property_map {
395 	int value;
396 	char const *key;
397 };
398 
399 static struct battery_property_map map_ac_online[] = {
400 	{ 0,  "off"  },
401 	{ 1,  "on" },
402 	{ -1, NULL  },
403 };
404 
405 static struct battery_property_map map_status[] = {
406 	{ POWER_SUPPLY_STATUS_CHARGING,     "charging"     },
407 	{ POWER_SUPPLY_STATUS_DISCHARGING,  "discharging"  },
408 	{ POWER_SUPPLY_STATUS_NOT_CHARGING, "not-charging" },
409 	{ POWER_SUPPLY_STATUS_FULL,         "full"         },
410 	{ -1,                               NULL           },
411 };
412 
413 static struct battery_property_map map_health[] = {
414 	{ POWER_SUPPLY_HEALTH_GOOD,           "good"        },
415 	{ POWER_SUPPLY_HEALTH_OVERHEAT,       "overheat"    },
416 	{ POWER_SUPPLY_HEALTH_DEAD,           "dead"        },
417 	{ POWER_SUPPLY_HEALTH_OVERVOLTAGE,    "overvoltage" },
418 	{ POWER_SUPPLY_HEALTH_UNSPEC_FAILURE, "failure"     },
419 	{ -1,                                 NULL          },
420 };
421 
422 static struct battery_property_map map_present[] = {
423 	{ 0,  "false" },
424 	{ 1,  "true"  },
425 	{ -1, NULL    },
426 };
427 
428 static struct battery_property_map map_technology[] = {
429 	{ POWER_SUPPLY_TECHNOLOGY_NiMH, "NiMH" },
430 	{ POWER_SUPPLY_TECHNOLOGY_LION, "LION" },
431 	{ POWER_SUPPLY_TECHNOLOGY_LIPO, "LIPO" },
432 	{ POWER_SUPPLY_TECHNOLOGY_LiFe, "LiFe" },
433 	{ POWER_SUPPLY_TECHNOLOGY_NiCd, "NiCd" },
434 	{ POWER_SUPPLY_TECHNOLOGY_LiMn, "LiMn" },
435 	{ -1,				NULL   },
436 };
437 
438 
439 static int map_get_value(struct battery_property_map *map, const char *key,
440 				int def_val)
441 {
442 	char buf[MAX_KEYLENGTH];
443 	int cr;
444 
445 	strscpy(buf, key, MAX_KEYLENGTH);
446 
447 	cr = strnlen(buf, MAX_KEYLENGTH) - 1;
448 	if (cr < 0)
449 		return def_val;
450 	if (buf[cr] == '\n')
451 		buf[cr] = '\0';
452 
453 	while (map->key) {
454 		if (strncasecmp(map->key, buf, MAX_KEYLENGTH) == 0)
455 			return map->value;
456 		map++;
457 	}
458 
459 	return def_val;
460 }
461 
462 
463 static const char *map_get_key(struct battery_property_map *map, int value,
464 				const char *def_key)
465 {
466 	while (map->key) {
467 		if (map->value == value)
468 			return map->key;
469 		map++;
470 	}
471 
472 	return def_key;
473 }
474 
475 static inline void signal_power_supply_changed(struct power_supply *psy)
476 {
477 	if (module_initialized)
478 		power_supply_changed(psy);
479 }
480 
481 static int param_set_ac_online(const char *key, const struct kernel_param *kp)
482 {
483 	ac_online = map_get_value(map_ac_online, key, ac_online);
484 	signal_power_supply_changed(test_power_supplies[TEST_AC]);
485 	return 0;
486 }
487 
488 static int param_get_ac_online(char *buffer, const struct kernel_param *kp)
489 {
490 	return sprintf(buffer, "%s\n",
491 			map_get_key(map_ac_online, ac_online, "unknown"));
492 }
493 
494 static int param_set_usb_online(const char *key, const struct kernel_param *kp)
495 {
496 	usb_online = map_get_value(map_ac_online, key, usb_online);
497 	signal_power_supply_changed(test_power_supplies[TEST_USB]);
498 	return 0;
499 }
500 
501 static int param_get_usb_online(char *buffer, const struct kernel_param *kp)
502 {
503 	return sprintf(buffer, "%s\n",
504 			map_get_key(map_ac_online, usb_online, "unknown"));
505 }
506 
507 static int param_set_battery_status(const char *key,
508 					const struct kernel_param *kp)
509 {
510 	battery_status = map_get_value(map_status, key, battery_status);
511 	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
512 	return 0;
513 }
514 
515 static int param_get_battery_status(char *buffer, const struct kernel_param *kp)
516 {
517 	return sprintf(buffer, "%s\n",
518 			map_get_key(map_ac_online, battery_status, "unknown"));
519 }
520 
521 static int param_set_battery_health(const char *key,
522 					const struct kernel_param *kp)
523 {
524 	battery_health = map_get_value(map_health, key, battery_health);
525 	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
526 	return 0;
527 }
528 
529 static int param_get_battery_health(char *buffer, const struct kernel_param *kp)
530 {
531 	return sprintf(buffer, "%s\n",
532 			map_get_key(map_ac_online, battery_health, "unknown"));
533 }
534 
535 static int param_set_battery_present(const char *key,
536 					const struct kernel_param *kp)
537 {
538 	battery_present = map_get_value(map_present, key, battery_present);
539 	signal_power_supply_changed(test_power_supplies[TEST_AC]);
540 	return 0;
541 }
542 
543 static int param_get_battery_present(char *buffer,
544 					const struct kernel_param *kp)
545 {
546 	return sprintf(buffer, "%s\n",
547 			map_get_key(map_ac_online, battery_present, "unknown"));
548 }
549 
550 static int param_set_battery_technology(const char *key,
551 					const struct kernel_param *kp)
552 {
553 	battery_technology = map_get_value(map_technology, key,
554 						battery_technology);
555 	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
556 	return 0;
557 }
558 
559 static int param_get_battery_technology(char *buffer,
560 					const struct kernel_param *kp)
561 {
562 	return sprintf(buffer, "%s\n",
563 			map_get_key(map_ac_online, battery_technology,
564 					"unknown"));
565 }
566 
567 static int param_set_battery_capacity(const char *key,
568 					const struct kernel_param *kp)
569 {
570 	int tmp;
571 
572 	if (1 != sscanf(key, "%d", &tmp))
573 		return -EINVAL;
574 
575 	battery_capacity = tmp;
576 	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
577 	return 0;
578 }
579 
580 #define param_get_battery_capacity param_get_int
581 
582 static int param_set_battery_voltage(const char *key,
583 					const struct kernel_param *kp)
584 {
585 	int tmp;
586 
587 	if (1 != sscanf(key, "%d", &tmp))
588 		return -EINVAL;
589 
590 	battery_voltage = tmp;
591 	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
592 	return 0;
593 }
594 
595 #define param_get_battery_voltage param_get_int
596 
597 static int param_set_battery_charge_counter(const char *key,
598 					const struct kernel_param *kp)
599 {
600 	int tmp;
601 
602 	if (1 != sscanf(key, "%d", &tmp))
603 		return -EINVAL;
604 
605 	battery_charge_counter = tmp;
606 	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
607 	return 0;
608 }
609 
610 #define param_get_battery_charge_counter param_get_int
611 
612 static int param_set_battery_current(const char *key,
613 					const struct kernel_param *kp)
614 {
615 	int tmp;
616 
617 	if (1 != sscanf(key, "%d", &tmp))
618 		return -EINVAL;
619 
620 	battery_current = tmp;
621 	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
622 	return 0;
623 }
624 
625 #define param_get_battery_current param_get_int
626 
627 static int param_set_battery_extension(const char *key,
628 				       const struct kernel_param *kp)
629 {
630 	bool prev_battery_extension;
631 	int ret;
632 
633 	prev_battery_extension = battery_extension;
634 
635 	ret = param_set_bool(key, kp);
636 	if (ret)
637 		return ret;
638 
639 	if (prev_battery_extension != battery_extension)
640 		test_power_configure_battery_extension(battery_extension);
641 
642 	return 0;
643 }
644 
645 #define param_get_battery_extension param_get_bool
646 
647 static const struct kernel_param_ops param_ops_ac_online = {
648 	.set = param_set_ac_online,
649 	.get = param_get_ac_online,
650 };
651 
652 static const struct kernel_param_ops param_ops_usb_online = {
653 	.set = param_set_usb_online,
654 	.get = param_get_usb_online,
655 };
656 
657 static const struct kernel_param_ops param_ops_battery_status = {
658 	.set = param_set_battery_status,
659 	.get = param_get_battery_status,
660 };
661 
662 static const struct kernel_param_ops param_ops_battery_present = {
663 	.set = param_set_battery_present,
664 	.get = param_get_battery_present,
665 };
666 
667 static const struct kernel_param_ops param_ops_battery_technology = {
668 	.set = param_set_battery_technology,
669 	.get = param_get_battery_technology,
670 };
671 
672 static const struct kernel_param_ops param_ops_battery_health = {
673 	.set = param_set_battery_health,
674 	.get = param_get_battery_health,
675 };
676 
677 static const struct kernel_param_ops param_ops_battery_capacity = {
678 	.set = param_set_battery_capacity,
679 	.get = param_get_battery_capacity,
680 };
681 
682 static const struct kernel_param_ops param_ops_battery_voltage = {
683 	.set = param_set_battery_voltage,
684 	.get = param_get_battery_voltage,
685 };
686 
687 static const struct kernel_param_ops param_ops_battery_charge_counter = {
688 	.set = param_set_battery_charge_counter,
689 	.get = param_get_battery_charge_counter,
690 };
691 
692 static const struct kernel_param_ops param_ops_battery_current = {
693 	.set = param_set_battery_current,
694 	.get = param_get_battery_current,
695 };
696 
697 static const struct kernel_param_ops param_ops_battery_extension = {
698 	.set = param_set_battery_extension,
699 	.get = param_get_battery_extension,
700 };
701 
702 #define param_check_ac_online(name, p) __param_check(name, p, void);
703 #define param_check_usb_online(name, p) __param_check(name, p, void);
704 #define param_check_battery_status(name, p) __param_check(name, p, void);
705 #define param_check_battery_present(name, p) __param_check(name, p, void);
706 #define param_check_battery_technology(name, p) __param_check(name, p, void);
707 #define param_check_battery_health(name, p) __param_check(name, p, void);
708 #define param_check_battery_capacity(name, p) __param_check(name, p, void);
709 #define param_check_battery_voltage(name, p) __param_check(name, p, void);
710 #define param_check_battery_charge_counter(name, p) __param_check(name, p, void);
711 #define param_check_battery_current(name, p) __param_check(name, p, void);
712 #define param_check_battery_extension(name, p) __param_check(name, p, void);
713 
714 
715 module_param(ac_online, ac_online, 0644);
716 MODULE_PARM_DESC(ac_online, "AC charging state <on|off>");
717 
718 module_param(usb_online, usb_online, 0644);
719 MODULE_PARM_DESC(usb_online, "USB charging state <on|off>");
720 
721 module_param(battery_status, battery_status, 0644);
722 MODULE_PARM_DESC(battery_status,
723 	"battery status <charging|discharging|not-charging|full>");
724 
725 module_param(battery_present, battery_present, 0644);
726 MODULE_PARM_DESC(battery_present,
727 	"battery presence state <good|overheat|dead|overvoltage|failure>");
728 
729 module_param(battery_technology, battery_technology, 0644);
730 MODULE_PARM_DESC(battery_technology,
731 	"battery technology <NiMH|LION|LIPO|LiFe|NiCd|LiMn>");
732 
733 module_param(battery_health, battery_health, 0644);
734 MODULE_PARM_DESC(battery_health,
735 	"battery health state <good|overheat|dead|overvoltage|failure>");
736 
737 module_param(battery_capacity, battery_capacity, 0644);
738 MODULE_PARM_DESC(battery_capacity, "battery capacity (percentage)");
739 
740 module_param(battery_voltage, battery_voltage, 0644);
741 MODULE_PARM_DESC(battery_voltage, "battery voltage (millivolts)");
742 
743 module_param(battery_charge_counter, battery_charge_counter, 0644);
744 MODULE_PARM_DESC(battery_charge_counter,
745 	"battery charge counter (microampere-hours)");
746 
747 module_param(battery_current, battery_current, 0644);
748 MODULE_PARM_DESC(battery_current, "battery current (milliampere)");
749 
750 module_param(battery_extension, battery_extension, 0644);
751 MODULE_PARM_DESC(battery_extension, "battery extension");
752 
753 MODULE_DESCRIPTION("Power supply driver for testing");
754 MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
755 MODULE_LICENSE("GPL");
756