From patchwork Thu Feb 2 14:12:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 9551967 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 1FDD9604E0 for ; Thu, 2 Feb 2017 14:17:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0281827D29 for ; Thu, 2 Feb 2017 14:17:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB5E428408; Thu, 2 Feb 2017 14:17:17 +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=unavailable 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 8975C28411 for ; Thu, 2 Feb 2017 14:17:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751751AbdBBOPs (ORCPT ); Thu, 2 Feb 2017 09:15:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:10641 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750932AbdBBOMy (ORCPT ); Thu, 2 Feb 2017 09:12:54 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C64D63D945; Thu, 2 Feb 2017 14:12:45 +0000 (UTC) Received: from plouf.banquise.eu.com (ovpn-116-126.ams2.redhat.com [10.36.116.126]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v12ECXt2011601; Thu, 2 Feb 2017 09:12:43 -0500 From: Benjamin Tissoires To: Jiri Kosina , Bastien Nocera , Peter Hutterer , Nestor Lopez Casado , Olivier Gay , Simon Wood Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 04/15] HID: logitech-hidpp: battery: remove overloads and provide ONLINE Date: Thu, 2 Feb 2017 15:12:18 +0100 Message-Id: <20170202141229.17322-5-benjamin.tissoires@redhat.com> In-Reply-To: <20170202141229.17322-1-benjamin.tissoires@redhat.com> References: <20170202141229.17322-1-benjamin.tissoires@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 02 Feb 2017 14:12:45 +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 When ONLINE isn't set, upower should ignore the battery capacity, so there is no need to overload it with some random values. Signed-off-by: Benjamin Tissoires --- no changes in v2 --- drivers/hid/hid-logitech-hidpp.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 1cda29e..3c57886 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -632,48 +632,39 @@ static int hidpp20_batterylevel_map_status_level(u8 data[3], int *level, int *next_level) { int status; - int level_override; - *level = data[0]; + if (data[0]) + *level = data[0]; *next_level = 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 + * For all other states the device reports level 0 (unknown). */ switch (data[2]) { case 0: /* discharging (in use) */ status = POWER_SUPPLY_STATUS_DISCHARGING; - level_override = 0; break; case 1: /* recharging */ status = POWER_SUPPLY_STATUS_CHARGING; - level_override = 80; break; case 2: /* charge in final stage */ status = POWER_SUPPLY_STATUS_CHARGING; - level_override = 90; break; case 3: /* charge complete */ status = POWER_SUPPLY_STATUS_FULL; - level_override = 100; + *level = 100; break; case 4: /* recharging below optimal speed */ status = POWER_SUPPLY_STATUS_CHARGING; - level_override = 50; break; /* 5 = invalid battery type 6 = thermal error 7 = other charging error */ default: status = POWER_SUPPLY_STATUS_NOT_CHARGING; - level_override = 0; break; } - if (level_override != 0 && *level == 0) - *level = level_override; - return status; } @@ -719,6 +710,8 @@ static int hidpp20_query_battery_info(struct hidpp_device *hidpp) return ret; } + level = 0; + next_level = 0; ret = hidpp20_batterylevel_get_battery_level(hidpp, hidpp->battery.feature_index, &status, &level, &next_level); @@ -742,6 +735,8 @@ static int hidpp20_battery_event(struct hidpp_device *hidpp, report->fap.funcindex_clientid != EVENT_BATTERY_LEVEL_STATUS_BROADCAST) return 0; + level = hidpp->battery.level; + status = hidpp20_batterylevel_map_status_level(report->fap.params, &level, &next_level); @@ -759,6 +754,7 @@ static int hidpp20_battery_event(struct hidpp_device *hidpp, } static enum power_supply_property hidpp_battery_props[] = { + POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_SCOPE, @@ -781,6 +777,12 @@ static int hidpp_battery_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_SCOPE: val->intval = POWER_SUPPLY_SCOPE_DEVICE; break; + case POWER_SUPPLY_PROP_ONLINE: + val->intval = hidpp->battery.status == + POWER_SUPPLY_STATUS_DISCHARGING || + hidpp->battery.status == + POWER_SUPPLY_STATUS_FULL; + break; default: ret = -EINVAL; break;