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