diff options
author | Krzysztof Kozlowski <k.kozlowski@samsung.com> | 2015-01-23 05:38:00 -0500 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2015-01-23 10:03:00 -0500 |
commit | a30067bb541f834b22c9cfa2dd99ebe3da709115 (patch) | |
tree | 0f84a1fa728a02228fb5ea19c11d063061c5b48b | |
parent | 24d3b15a1844e3d2c7f5b0d9c482ece98386ede1 (diff) |
power: test_power: Use enum as index for array of supplies
Replace hard-coded numbers for indices of power supply array with enum.
This improves a little the readability as one does not have to guess
which power supply is associated with number.
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
-rw-r--r-- | drivers/power/test_power.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/drivers/power/test_power.c b/drivers/power/test_power.c index 0152f35dca5c..f26b1fa00fe1 100644 --- a/drivers/power/test_power.c +++ b/drivers/power/test_power.c | |||
@@ -21,6 +21,13 @@ | |||
21 | #include <linux/delay.h> | 21 | #include <linux/delay.h> |
22 | #include <linux/vermagic.h> | 22 | #include <linux/vermagic.h> |
23 | 23 | ||
24 | enum test_power_id { | ||
25 | TEST_AC, | ||
26 | TEST_BATTERY, | ||
27 | TEST_USB, | ||
28 | TEST_POWER_NUM, | ||
29 | }; | ||
30 | |||
24 | static int ac_online = 1; | 31 | static int ac_online = 1; |
25 | static int usb_online = 1; | 32 | static int usb_online = 1; |
26 | static int battery_status = POWER_SUPPLY_STATUS_DISCHARGING; | 33 | static int battery_status = POWER_SUPPLY_STATUS_DISCHARGING; |
@@ -147,7 +154,7 @@ static char *test_power_ac_supplied_to[] = { | |||
147 | }; | 154 | }; |
148 | 155 | ||
149 | static struct power_supply test_power_supplies[] = { | 156 | static struct power_supply test_power_supplies[] = { |
150 | { | 157 | [TEST_AC] = { |
151 | .name = "test_ac", | 158 | .name = "test_ac", |
152 | .type = POWER_SUPPLY_TYPE_MAINS, | 159 | .type = POWER_SUPPLY_TYPE_MAINS, |
153 | .supplied_to = test_power_ac_supplied_to, | 160 | .supplied_to = test_power_ac_supplied_to, |
@@ -155,13 +162,15 @@ static struct power_supply test_power_supplies[] = { | |||
155 | .properties = test_power_ac_props, | 162 | .properties = test_power_ac_props, |
156 | .num_properties = ARRAY_SIZE(test_power_ac_props), | 163 | .num_properties = ARRAY_SIZE(test_power_ac_props), |
157 | .get_property = test_power_get_ac_property, | 164 | .get_property = test_power_get_ac_property, |
158 | }, { | 165 | }, |
166 | [TEST_BATTERY] = { | ||
159 | .name = "test_battery", | 167 | .name = "test_battery", |
160 | .type = POWER_SUPPLY_TYPE_BATTERY, | 168 | .type = POWER_SUPPLY_TYPE_BATTERY, |
161 | .properties = test_power_battery_props, | 169 | .properties = test_power_battery_props, |
162 | .num_properties = ARRAY_SIZE(test_power_battery_props), | 170 | .num_properties = ARRAY_SIZE(test_power_battery_props), |
163 | .get_property = test_power_get_battery_property, | 171 | .get_property = test_power_get_battery_property, |
164 | }, { | 172 | }, |
173 | [TEST_USB] = { | ||
165 | .name = "test_usb", | 174 | .name = "test_usb", |
166 | .type = POWER_SUPPLY_TYPE_USB, | 175 | .type = POWER_SUPPLY_TYPE_USB, |
167 | .supplied_to = test_power_ac_supplied_to, | 176 | .supplied_to = test_power_ac_supplied_to, |
@@ -178,6 +187,8 @@ static int __init test_power_init(void) | |||
178 | int i; | 187 | int i; |
179 | int ret; | 188 | int ret; |
180 | 189 | ||
190 | BUILD_BUG_ON(TEST_POWER_NUM != ARRAY_SIZE(test_power_supplies)); | ||
191 | |||
181 | for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) { | 192 | for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) { |
182 | ret = power_supply_register(NULL, &test_power_supplies[i]); | 193 | ret = power_supply_register(NULL, &test_power_supplies[i]); |
183 | if (ret) { | 194 | if (ret) { |
@@ -309,7 +320,7 @@ static inline void signal_power_supply_changed(struct power_supply *psy) | |||
309 | static int param_set_ac_online(const char *key, const struct kernel_param *kp) | 320 | static int param_set_ac_online(const char *key, const struct kernel_param *kp) |
310 | { | 321 | { |
311 | ac_online = map_get_value(map_ac_online, key, ac_online); | 322 | ac_online = map_get_value(map_ac_online, key, ac_online); |
312 | signal_power_supply_changed(&test_power_supplies[0]); | 323 | signal_power_supply_changed(&test_power_supplies[TEST_AC]); |
313 | return 0; | 324 | return 0; |
314 | } | 325 | } |
315 | 326 | ||
@@ -322,7 +333,7 @@ static int param_get_ac_online(char *buffer, const struct kernel_param *kp) | |||
322 | static int param_set_usb_online(const char *key, const struct kernel_param *kp) | 333 | static int param_set_usb_online(const char *key, const struct kernel_param *kp) |
323 | { | 334 | { |
324 | usb_online = map_get_value(map_ac_online, key, usb_online); | 335 | usb_online = map_get_value(map_ac_online, key, usb_online); |
325 | signal_power_supply_changed(&test_power_supplies[2]); | 336 | signal_power_supply_changed(&test_power_supplies[TEST_USB]); |
326 | return 0; | 337 | return 0; |
327 | } | 338 | } |
328 | 339 | ||
@@ -336,7 +347,7 @@ static int param_set_battery_status(const char *key, | |||
336 | const struct kernel_param *kp) | 347 | const struct kernel_param *kp) |
337 | { | 348 | { |
338 | battery_status = map_get_value(map_status, key, battery_status); | 349 | battery_status = map_get_value(map_status, key, battery_status); |
339 | signal_power_supply_changed(&test_power_supplies[1]); | 350 | signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]); |
340 | return 0; | 351 | return 0; |
341 | } | 352 | } |
342 | 353 | ||
@@ -350,7 +361,7 @@ static int param_set_battery_health(const char *key, | |||
350 | const struct kernel_param *kp) | 361 | const struct kernel_param *kp) |
351 | { | 362 | { |
352 | battery_health = map_get_value(map_health, key, battery_health); | 363 | battery_health = map_get_value(map_health, key, battery_health); |
353 | signal_power_supply_changed(&test_power_supplies[1]); | 364 | signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]); |
354 | return 0; | 365 | return 0; |
355 | } | 366 | } |
356 | 367 | ||
@@ -364,7 +375,7 @@ static int param_set_battery_present(const char *key, | |||
364 | const struct kernel_param *kp) | 375 | const struct kernel_param *kp) |
365 | { | 376 | { |
366 | battery_present = map_get_value(map_present, key, battery_present); | 377 | battery_present = map_get_value(map_present, key, battery_present); |
367 | signal_power_supply_changed(&test_power_supplies[0]); | 378 | signal_power_supply_changed(&test_power_supplies[TEST_AC]); |
368 | return 0; | 379 | return 0; |
369 | } | 380 | } |
370 | 381 | ||
@@ -380,7 +391,7 @@ static int param_set_battery_technology(const char *key, | |||
380 | { | 391 | { |
381 | battery_technology = map_get_value(map_technology, key, | 392 | battery_technology = map_get_value(map_technology, key, |
382 | battery_technology); | 393 | battery_technology); |
383 | signal_power_supply_changed(&test_power_supplies[1]); | 394 | signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]); |
384 | return 0; | 395 | return 0; |
385 | } | 396 | } |
386 | 397 | ||
@@ -401,7 +412,7 @@ static int param_set_battery_capacity(const char *key, | |||
401 | return -EINVAL; | 412 | return -EINVAL; |
402 | 413 | ||
403 | battery_capacity = tmp; | 414 | battery_capacity = tmp; |
404 | signal_power_supply_changed(&test_power_supplies[1]); | 415 | signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]); |
405 | return 0; | 416 | return 0; |
406 | } | 417 | } |
407 | 418 | ||
@@ -416,7 +427,7 @@ static int param_set_battery_voltage(const char *key, | |||
416 | return -EINVAL; | 427 | return -EINVAL; |
417 | 428 | ||
418 | battery_voltage = tmp; | 429 | battery_voltage = tmp; |
419 | signal_power_supply_changed(&test_power_supplies[1]); | 430 | signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]); |
420 | return 0; | 431 | return 0; |
421 | } | 432 | } |
422 | 433 | ||