aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/test_power.c
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2012-05-29 05:37:43 -0400
committerAnton Vorontsov <cbouatmailru@gmail.com>2012-06-21 01:45:10 -0400
commit7384737588165e268887be09ad05c8664625dc43 (patch)
tree68d5eda1ee434ff09ad30823a03e4629cc2503e3 /drivers/power/test_power.c
parentecb7a8ebdc4b063715d5a37919f9118c3f1031a8 (diff)
test_power: Add support for USB AC source
Usually a device has both AC plug and UDC plug usable for charging. Provide both AC sources. Signed-off-by: Dmitry Eremin-Solenikov <dmitry_eremin@mentor.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power/test_power.c')
-rw-r--r--drivers/power/test_power.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/drivers/power/test_power.c b/drivers/power/test_power.c
index b527c93bf2f3..99aec3b38b23 100644
--- a/drivers/power/test_power.c
+++ b/drivers/power/test_power.c
@@ -22,6 +22,7 @@
22#include <linux/vermagic.h> 22#include <linux/vermagic.h>
23 23
24static int ac_online = 1; 24static int ac_online = 1;
25static int usb_online = 1;
25static int battery_status = POWER_SUPPLY_STATUS_DISCHARGING; 26static int battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
26static int battery_health = POWER_SUPPLY_HEALTH_GOOD; 27static int battery_health = POWER_SUPPLY_HEALTH_GOOD;
27static int battery_present = 1; /* true */ 28static int battery_present = 1; /* true */
@@ -42,6 +43,20 @@ static int test_power_get_ac_property(struct power_supply *psy,
42 return 0; 43 return 0;
43} 44}
44 45
46static int test_power_get_usb_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 = usb_online;
53 break;
54 default:
55 return -EINVAL;
56 }
57 return 0;
58}
59
45static int test_power_get_battery_property(struct power_supply *psy, 60static int test_power_get_battery_property(struct power_supply *psy,
46 enum power_supply_property psp, 61 enum power_supply_property psp,
47 union power_supply_propval *val) 62 union power_supply_propval *val)
@@ -135,6 +150,14 @@ static struct power_supply test_power_supplies[] = {
135 .properties = test_power_battery_props, 150 .properties = test_power_battery_props,
136 .num_properties = ARRAY_SIZE(test_power_battery_props), 151 .num_properties = ARRAY_SIZE(test_power_battery_props),
137 .get_property = test_power_get_battery_property, 152 .get_property = test_power_get_battery_property,
153 }, {
154 .name = "test_usb",
155 .type = POWER_SUPPLY_TYPE_USB,
156 .supplied_to = test_power_ac_supplied_to,
157 .num_supplicants = ARRAY_SIZE(test_power_ac_supplied_to),
158 .properties = test_power_ac_props,
159 .num_properties = ARRAY_SIZE(test_power_ac_props),
160 .get_property = test_power_get_usb_property,
138 }, 161 },
139}; 162};
140 163
@@ -167,6 +190,7 @@ static void __exit test_power_exit(void)
167 190
168 /* Let's see how we handle changes... */ 191 /* Let's see how we handle changes... */
169 ac_online = 0; 192 ac_online = 0;
193 usb_online = 0;
170 battery_status = POWER_SUPPLY_STATUS_DISCHARGING; 194 battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
171 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) 195 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++)
172 power_supply_changed(&test_power_supplies[i]); 196 power_supply_changed(&test_power_supplies[i]);
@@ -275,6 +299,19 @@ static int param_get_ac_online(char *buffer, const struct kernel_param *kp)
275 return strlen(buffer); 299 return strlen(buffer);
276} 300}
277 301
302static int param_set_usb_online(const char *key, const struct kernel_param *kp)
303{
304 usb_online = map_get_value(map_ac_online, key, usb_online);
305 power_supply_changed(&test_power_supplies[2]);
306 return 0;
307}
308
309static int param_get_usb_online(char *buffer, const struct kernel_param *kp)
310{
311 strcpy(buffer, map_get_key(map_ac_online, usb_online, "unknown"));
312 return strlen(buffer);
313}
314
278static int param_set_battery_status(const char *key, 315static int param_set_battery_status(const char *key,
279 const struct kernel_param *kp) 316 const struct kernel_param *kp)
280{ 317{
@@ -350,13 +387,16 @@ static int param_set_battery_capacity(const char *key,
350 387
351#define param_get_battery_capacity param_get_int 388#define param_get_battery_capacity param_get_int
352 389
353
354
355static struct kernel_param_ops param_ops_ac_online = { 390static struct kernel_param_ops param_ops_ac_online = {
356 .set = param_set_ac_online, 391 .set = param_set_ac_online,
357 .get = param_get_ac_online, 392 .get = param_get_ac_online,
358}; 393};
359 394
395static struct kernel_param_ops param_ops_usb_online = {
396 .set = param_set_usb_online,
397 .get = param_get_usb_online,
398};
399
360static struct kernel_param_ops param_ops_battery_status = { 400static struct kernel_param_ops param_ops_battery_status = {
361 .set = param_set_battery_status, 401 .set = param_set_battery_status,
362 .get = param_get_battery_status, 402 .get = param_get_battery_status,
@@ -384,6 +424,7 @@ static struct kernel_param_ops param_ops_battery_capacity = {
384 424
385 425
386#define param_check_ac_online(name, p) __param_check(name, p, void); 426#define param_check_ac_online(name, p) __param_check(name, p, void);
427#define param_check_usb_online(name, p) __param_check(name, p, void);
387#define param_check_battery_status(name, p) __param_check(name, p, void); 428#define param_check_battery_status(name, p) __param_check(name, p, void);
388#define param_check_battery_present(name, p) __param_check(name, p, void); 429#define param_check_battery_present(name, p) __param_check(name, p, void);
389#define param_check_battery_technology(name, p) __param_check(name, p, void); 430#define param_check_battery_technology(name, p) __param_check(name, p, void);
@@ -394,6 +435,9 @@ static struct kernel_param_ops param_ops_battery_capacity = {
394module_param(ac_online, ac_online, 0644); 435module_param(ac_online, ac_online, 0644);
395MODULE_PARM_DESC(ac_online, "AC charging state <on|off>"); 436MODULE_PARM_DESC(ac_online, "AC charging state <on|off>");
396 437
438module_param(usb_online, usb_online, 0644);
439MODULE_PARM_DESC(usb_online, "USB charging state <on|off>");
440
397module_param(battery_status, battery_status, 0644); 441module_param(battery_status, battery_status, 0644);
398MODULE_PARM_DESC(battery_status, 442MODULE_PARM_DESC(battery_status,
399 "battery status <charging|discharging|not-charging|full>"); 443 "battery status <charging|discharging|not-charging|full>");