From patchwork Mon Mar 27 14:59:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 9646975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DAE61602D6 for ; Mon, 27 Mar 2017 15:04:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD0BF28437 for ; Mon, 27 Mar 2017 15:04:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1A7B28435; Mon, 27 Mar 2017 15:04:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2899028422 for ; Mon, 27 Mar 2017 15:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753558AbdC0PCr (ORCPT ); Mon, 27 Mar 2017 11:02:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23426 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753386AbdC0PA3 (ORCPT ); Mon, 27 Mar 2017 11:00:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C5CAC0528DA; Mon, 27 Mar 2017 15:00:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9C5CAC0528DA Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=benjamin.tissoires@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9C5CAC0528DA Received: from plouf.banquise.eu.com (ovpn-117-32.ams2.redhat.com [10.36.117.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 725B5852AD; Mon, 27 Mar 2017 15:00:08 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 15/19] HID: logitech-hidpp: rename battery level into capacity Date: Mon, 27 Mar 2017 16:59:35 +0200 Message-Id: <20170327145939.29824-16-benjamin.tissoires@redhat.com> In-Reply-To: <20170327145939.29824-1-benjamin.tissoires@redhat.com> References: <20170327145939.29824-1-benjamin.tissoires@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 27 Mar 2017 15:00:09 +0000 (UTC) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- new in v3 --- drivers/hid/hid-logitech-hidpp.c | 55 ++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 7e4445a..c59f7e5e 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -119,7 +119,7 @@ struct hidpp_battery { struct power_supply *ps; char name[64]; int status; - int level; + int capacity; bool online; }; @@ -683,17 +683,16 @@ static char *hidpp_get_device_name(struct hidpp_device *hidpp) #define EVENT_BATTERY_LEVEL_STATUS_BROADCAST 0x00 -static int hidpp20_batterylevel_map_status_level(u8 data[3], int *level, - int *next_level) +static int hidpp20_batterylevel_map_status_capacity(u8 data[3], int *capacity, + int *next_capacity) { int status; - *level = data[0]; - *next_level = data[1]; + *capacity = data[0]; + *next_capacity = data[1]; - /* When discharging, we can rely on the device reported level. - * For all other states the device reports level 0 (unknown). Make up - * a number instead + /* When discharging, we can rely on the device reported capacity. + * For all other states the device reports 0 (unknown). */ switch (data[2]) { case 0: /* discharging (in use) */ @@ -707,7 +706,7 @@ static int hidpp20_batterylevel_map_status_level(u8 data[3], int *level, break; case 3: /* charge complete */ status = POWER_SUPPLY_STATUS_FULL; - *level = 100; + *capacity = 100; break; case 4: /* recharging below optimal speed */ status = POWER_SUPPLY_STATUS_CHARGING; @@ -723,11 +722,11 @@ static int hidpp20_batterylevel_map_status_level(u8 data[3], int *level, return status; } -static int hidpp20_batterylevel_get_battery_level(struct hidpp_device *hidpp, - u8 feature_index, - int *status, - int *level, - int *next_level) +static int hidpp20_batterylevel_get_battery_capacity(struct hidpp_device *hidpp, + u8 feature_index, + int *status, + int *capacity, + int *next_capacity) { struct hidpp_report response; int ret; @@ -744,8 +743,8 @@ static int hidpp20_batterylevel_get_battery_level(struct hidpp_device *hidpp, if (ret) return ret; - *status = hidpp20_batterylevel_map_status_level(params, level, - next_level); + *status = hidpp20_batterylevel_map_status_capacity(params, capacity, + next_capacity); return 0; } @@ -754,7 +753,7 @@ static int hidpp20_query_battery_info(struct hidpp_device *hidpp) { u8 feature_type; int ret; - int status, level, next_level; + int status, capacity, next_capacity; if (hidpp->battery.feature_index == 0) { ret = hidpp_root_get_feature(hidpp, @@ -765,14 +764,15 @@ static int hidpp20_query_battery_info(struct hidpp_device *hidpp) return ret; } - ret = hidpp20_batterylevel_get_battery_level(hidpp, - hidpp->battery.feature_index, - &status, &level, &next_level); + ret = hidpp20_batterylevel_get_battery_capacity(hidpp, + hidpp->battery.feature_index, + &status, &capacity, + &next_capacity); if (ret) return ret; hidpp->battery.status = status; - hidpp->battery.level = level; + hidpp->battery.capacity = capacity; /* the capacity is only available when discharging or full */ hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || status == POWER_SUPPLY_STATUS_FULL; @@ -784,25 +784,26 @@ static int hidpp20_battery_event(struct hidpp_device *hidpp, u8 *data, int size) { struct hidpp_report *report = (struct hidpp_report *)data; - int status, level, next_level; + int status, capacity, next_capacity; bool changed; if (report->fap.feature_index != hidpp->battery.feature_index || report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST) return 0; - status = hidpp20_batterylevel_map_status_level(report->fap.params, - &level, &next_level); + status = hidpp20_batterylevel_map_status_capacity(report->fap.params, + &capacity, + &next_capacity); /* the capacity is only available when discharging or full */ hidpp->battery.online = status == POWER_SUPPLY_STATUS_DISCHARGING || status == POWER_SUPPLY_STATUS_FULL; - changed = level != hidpp->battery.level || + changed = capacity != hidpp->battery.capacity || status != hidpp->battery.status; if (changed) { - hidpp->battery.level = level; + hidpp->battery.capacity = capacity; hidpp->battery.status = status; if (hidpp->battery.ps) power_supply_changed(hidpp->battery.ps); @@ -833,7 +834,7 @@ static int hidpp_battery_get_property(struct power_supply *psy, val->intval = hidpp->battery.status; break; case POWER_SUPPLY_PROP_CAPACITY: - val->intval = hidpp->battery.level; + val->intval = hidpp->battery.capacity; break; case POWER_SUPPLY_PROP_SCOPE: val->intval = POWER_SUPPLY_SCOPE_DEVICE;