aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>2017-03-27 10:59:35 -0400
committerJiri Kosina <jkosina@suse.cz>2017-04-06 08:36:38 -0400
commit14f437a1d7b49a2e873f63436526f9aed3a781c3 (patch)
tree8c9541300e7ce230292d4123c5c995276fe71d8d
parent284f8d7592673a7a6dae96d082806d324378f212 (diff)
HID: logitech-hidpp: rename battery level into capacity
The power_supply term for the percentage is capacity. Capacity level can be given when non accurate mileage is provided by the device, so better stick to the terms used in power_supply. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Tested-by: Bastien Nocera <hadess@hadess.net> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/hid-logitech-hidpp.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 7e4445a3d7aa..c59f7e5eedfa 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -119,7 +119,7 @@ struct hidpp_battery {
119 struct power_supply *ps; 119 struct power_supply *ps;
120 char name[64]; 120 char name[64];
121 int status; 121 int status;
122 int level; 122 int capacity;
123 bool online; 123 bool online;
124}; 124};
125 125
@@ -683,17 +683,16 @@ static char *hidpp_get_device_name(struct hidpp_device *hidpp)
683 683
684#define EVENT_BATTERY_LEVEL_STATUS_BROADCAST 0x00 684#define EVENT_BATTERY_LEVEL_STATUS_BROADCAST 0x00
685 685
686static int hidpp20_batterylevel_map_status_level(u8 data[3], int *level, 686static int hidpp20_batterylevel_map_status_capacity(u8 data[3], int *capacity,
687 int *next_level) 687 int *next_capacity)
688{ 688{
689 int status; 689 int status;
690 690
691 *level = data[0]; 691 *capacity = data[0];
692 *next_level = data[1]; 692 *next_capacity = data[1];
693 693
694 /* When discharging, we can rely on the device reported level. 694 /* When discharging, we can rely on the device reported capacity.
695 * For all other states the device reports level 0 (unknown). Make up 695 * For all other states the device reports 0 (unknown).
696 * a number instead
697 */ 696 */
698 switch (data[2]) { 697 switch (data[2]) {
699 case 0: /* discharging (in use) */ 698 case 0: /* discharging (in use) */
@@ -707,7 +706,7 @@ static int hidpp20_batterylevel_map_status_level(u8 data[3], int *level,
707 break; 706 break;
708 case 3: /* charge complete */ 707 case 3: /* charge complete */
709 status = POWER_SUPPLY_STATUS_FULL; 708 status = POWER_SUPPLY_STATUS_FULL;
710 *level = 100; 709 *capacity = 100;
711 break; 710 break;
712 case 4: /* recharging below optimal speed */ 711 case 4: /* recharging below optimal speed */
713 status = POWER_SUPPLY_STATUS_CHARGING; 712 status = POWER_SUPPLY_STATUS_CHARGING;
@@ -723,11 +722,11 @@ static int hidpp20_batterylevel_map_status_level(u8 data[3], int *level,
723 return status; 722 return status;
724} 723}
725 724
726static int hidpp20_batterylevel_get_battery_level(struct hidpp_device *hidpp, 725static int hidpp20_batterylevel_get_battery_capacity(struct hidpp_device *hidpp,
727 u8 feature_index, 726 u8 feature_index,
728 int *status, 727 int *status,
729 int *level, 728 int *capacity,
730 int *next_level) 729 int *next_capacity)
731{ 730{
732 struct hidpp_report response; 731 struct hidpp_report response;
733 int ret; 732 int ret;
@@ -744,8 +743,8 @@ static int hidpp20_batterylevel_get_battery_level(struct hidpp_device *hidpp,
744 if (ret) 743 if (ret)
745 return ret; 744 return ret;
746 745
747 *status = hidpp20_batterylevel_map_status_level(params, level, 746 *status = hidpp20_batterylevel_map_status_capacity(params, capacity,
748 next_level); 747 next_capacity);
749 748
750 return 0; 749 return 0;
751} 750}
@@ -754,7 +753,7 @@ static int hidpp20_query_battery_info(struct hidpp_device *hidpp)
754{ 753{
755 u8 feature_type; 754 u8 feature_type;
756 int ret; 755 int ret;
757 int status, level, next_level; 756 int status, capacity, next_capacity;
758 757
759 if (hidpp->battery.feature_index == 0) { 758 if (hidpp->battery.feature_index == 0) {
760 ret = hidpp_root_get_feature(hidpp, 759 ret = hidpp_root_get_feature(hidpp,
@@ -765,14 +764,15 @@ static int hidpp20_query_battery_info(struct hidpp_device *hidpp)
765 return ret; 764 return ret;
766 } 765 }
767 766
768 ret = hidpp20_batterylevel_get_battery_level(hidpp, 767 ret = hidpp20_batterylevel_get_battery_capacity(hidpp,
769 hidpp->battery.feature_index, 768 hidpp->battery.feature_index,
770 &status, &level, &next_level); 769 &status, &capacity,
770 &next_capacity);
771 if (ret) 771 if (ret)
772 return ret; 772 return ret;
773 773
774 hidpp->battery.status = status; 774 hidpp->battery.status = status;
775 hidpp->battery.level = level; 775 hidpp->battery.capacity = capacity;
776 /* the capacity is only available when discharging or full */ 776 /* the capacity is only available when discharging or full */
777 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || 777 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
778 status == POWER_SUPPLY_STATUS_FULL; 778 status == POWER_SUPPLY_STATUS_FULL;
@@ -784,25 +784,26 @@ static int hidpp20_battery_event(struct hidpp_device *hidpp,
784 u8 *data, int size) 784 u8 *data, int size)
785{ 785{
786 struct hidpp_report *report = (struct hidpp_report *)data; 786 struct hidpp_report *report = (struct hidpp_report *)data;
787 int status, level, next_level; 787 int status, capacity, next_capacity;
788 bool changed; 788 bool changed;
789 789
790 if (report->fap.feature_index != hidpp->battery.feature_index || 790 if (report->fap.feature_index != hidpp->battery.feature_index ||
791 report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST) 791 report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST)
792 return 0; 792 return 0;
793 793
794 status = hidpp20_batterylevel_map_status_level(report->fap.params, 794 status = hidpp20_batterylevel_map_status_capacity(report->fap.params,
795 &level, &next_level); 795 &capacity,
796 &next_capacity);
796 797
797 /* the capacity is only available when discharging or full */ 798 /* the capacity is only available when discharging or full */
798 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || 799 hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING ||
799 status == POWER_SUPPLY_STATUS_FULL; 800 status == POWER_SUPPLY_STATUS_FULL;
800 801
801 changed = level != hidpp->battery.level || 802 changed = capacity != hidpp->battery.capacity ||
802 status != hidpp->battery.status; 803 status != hidpp->battery.status;
803 804
804 if (changed) { 805 if (changed) {
805 hidpp->battery.level = level; 806 hidpp->battery.capacity = capacity;
806 hidpp->battery.status = status; 807 hidpp->battery.status = status;
807 if (hidpp->battery.ps) 808 if (hidpp->battery.ps)
808 power_supply_changed(hidpp->battery.ps); 809 power_supply_changed(hidpp->battery.ps);
@@ -833,7 +834,7 @@ static int hidpp_battery_get_property(struct power_supply *psy,
833 val->intval = hidpp->battery.status; 834 val->intval = hidpp->battery.status;
834 break; 835 break;
835 case POWER_SUPPLY_PROP_CAPACITY: 836 case POWER_SUPPLY_PROP_CAPACITY:
836 val->intval = hidpp->battery.level; 837 val->intval = hidpp->battery.capacity;
837 break; 838 break;
838 case POWER_SUPPLY_PROP_SCOPE: 839 case POWER_SUPPLY_PROP_SCOPE:
839 val->intval = POWER_SUPPLY_SCOPE_DEVICE; 840 val->intval = POWER_SUPPLY_SCOPE_DEVICE;