Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 367496
b: refs/heads/master
c: 9239ebc
h: refs/heads/master
v: v3
  • Loading branch information
Andrey Gelman authored and Anton Vorontsov committed Mar 19, 2013
1 parent a562902 commit f9e6b30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6f8da5df8c451103e0043f73a00c90676da6be9e
refs/heads/master: 9239ebcffb9301eab75c638dcb702688884cc5d6
31 changes: 21 additions & 10 deletions trunk/drivers/power/test_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ static int battery_technology = POWER_SUPPLY_TECHNOLOGY_LION;
static int battery_capacity = 50;
static int battery_voltage = 3300;

static bool module_initialized;

static int test_power_get_ac_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
Expand Down Expand Up @@ -185,6 +187,7 @@ static int __init test_power_init(void)
}
}

module_initialized = true;
return 0;
failed:
while (--i >= 0)
Expand All @@ -209,6 +212,8 @@ static void __exit test_power_exit(void)

for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++)
power_supply_unregister(&test_power_supplies[i]);

module_initialized = false;
}
module_exit(test_power_exit);

Expand All @@ -221,8 +226,8 @@ struct battery_property_map {
};

static struct battery_property_map map_ac_online[] = {
{ 0, "on" },
{ 1, "off" },
{ 0, "off" },
{ 1, "on" },
{ -1, NULL },
};

Expand Down Expand Up @@ -295,10 +300,16 @@ static const char *map_get_key(struct battery_property_map *map, int value,
return def_key;
}

static inline void signal_power_supply_changed(struct power_supply *psy)
{
if (module_initialized)
power_supply_changed(psy);
}

static int param_set_ac_online(const char *key, const struct kernel_param *kp)
{
ac_online = map_get_value(map_ac_online, key, ac_online);
power_supply_changed(&test_power_supplies[0]);
signal_power_supply_changed(&test_power_supplies[0]);
return 0;
}

Expand All @@ -311,7 +322,7 @@ static int param_get_ac_online(char *buffer, const struct kernel_param *kp)
static int param_set_usb_online(const char *key, const struct kernel_param *kp)
{
usb_online = map_get_value(map_ac_online, key, usb_online);
power_supply_changed(&test_power_supplies[2]);
signal_power_supply_changed(&test_power_supplies[2]);
return 0;
}

Expand All @@ -325,7 +336,7 @@ static int param_set_battery_status(const char *key,
const struct kernel_param *kp)
{
battery_status = map_get_value(map_status, key, battery_status);
power_supply_changed(&test_power_supplies[1]);
signal_power_supply_changed(&test_power_supplies[1]);
return 0;
}

Expand All @@ -339,7 +350,7 @@ static int param_set_battery_health(const char *key,
const struct kernel_param *kp)
{
battery_health = map_get_value(map_health, key, battery_health);
power_supply_changed(&test_power_supplies[1]);
signal_power_supply_changed(&test_power_supplies[1]);
return 0;
}

Expand All @@ -353,7 +364,7 @@ static int param_set_battery_present(const char *key,
const struct kernel_param *kp)
{
battery_present = map_get_value(map_present, key, battery_present);
power_supply_changed(&test_power_supplies[0]);
signal_power_supply_changed(&test_power_supplies[0]);
return 0;
}

Expand All @@ -369,7 +380,7 @@ static int param_set_battery_technology(const char *key,
{
battery_technology = map_get_value(map_technology, key,
battery_technology);
power_supply_changed(&test_power_supplies[1]);
signal_power_supply_changed(&test_power_supplies[1]);
return 0;
}

Expand All @@ -390,7 +401,7 @@ static int param_set_battery_capacity(const char *key,
return -EINVAL;

battery_capacity = tmp;
power_supply_changed(&test_power_supplies[1]);
signal_power_supply_changed(&test_power_supplies[1]);
return 0;
}

Expand All @@ -405,7 +416,7 @@ static int param_set_battery_voltage(const char *key,
return -EINVAL;

battery_voltage = tmp;
power_supply_changed(&test_power_supplies[1]);
signal_power_supply_changed(&test_power_supplies[1]);
return 0;
}

Expand Down

0 comments on commit f9e6b30

Please sign in to comment.