From patchwork Thu Aug 22 20:18:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Vanzella X-Patchwork-Id: 11110073 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F02F14DE for ; Thu, 22 Aug 2019 20:19:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2E17F233FC for ; Thu, 22 Aug 2019 20:19:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pedrovanzella.com header.i=@pedrovanzella.com header.b="4e8V43r8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="h76D8Cxf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391021AbfHVUTC (ORCPT ); Thu, 22 Aug 2019 16:19:02 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:41161 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388389AbfHVUTB (ORCPT ); Thu, 22 Aug 2019 16:19:01 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 74EA621731; Thu, 22 Aug 2019 16:19:00 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 22 Aug 2019 16:19:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= pedrovanzella.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=fm3; bh=4c/lgLrm3F1n9YEmiMR6OTt64iylYrDgHb9+YtfNw1E=; b=4e8V4 3r8ASOsXBF5O+3zQlbspZ9VW6EYKXlYm8NKto2VRtHRVhKXcGg390t0vukjJQRZk YzFtz5mXJzoVInMEnJnwFEdqLmLWmIC5tF5dYSzKsWI9NNvQ5abpUwYSIu35JitF +C9ZhfY49gOlzr7dHwxhOxGTjg4B2DymlbbuGyvYrqvsCTjXFlsFW4KvNeA/WSOD KYln6znTkJGoMigsSuQ0X1LT0nPgeQbn2MeyK3ARd1zbwtmzMDAZJ9D1eZU+mN+Y 2atz0iZ+WSvYH4S39Du0djmNlV05CCrLzuFCS2K6NniUwUE2RAmODWCKgthGx2pP 5EhfmdoJUYh3IBqUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=4c/lgLrm3F1n9YEmiMR6OTt64iylYrDgHb9+YtfNw1E=; b=h76D8Cxf cjRYlUVHunWd4EbFsOsR7eZNe8kalymLglb6xv3wPGb0+IhxagfZeCIEz5rEJhZK 7nppRXiq+nYrQ/y4zRdJag2vNDHlRoyHAr9fbIMizh9PIcqR25laTPQOgjWHFvzW mY37kXTZYRA8zJZJHUuoPy2G0uv1GX+JqphKzrrNgE0ZwoPhWfQVTdF5dKJWLxtv VPv96ra4HkYG45DE52d1QmVR20gfoJzsfTqg82umgj+y2BzWgzdP1jrh0evHIqTC PxSSffP766ZkYSIXFeaZvDWg/Ydt3eZgk8ozTYgpNbtHqip8YZ6HZ5Iu2ZZAzVeG TCNLnZe/TjWcMQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudegiedguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomheprfgvughr ohcugggrnhiivghllhgruceophgvughrohesphgvughrohhvrghniigvlhhlrgdrtghomh eqnecukfhppedujeegrdekkedrledrudegleenucfrrghrrghmpehmrghilhhfrhhomhep phgvughrohesphgvughrohhvrghniigvlhhlrgdrtghomhenucevlhhushhtvghrufhiii gvpedt X-ME-Proxy: Received: from localhost (toroon020aw-lp130-07-174-88-9-149.dsl.bell.ca [174.88.9.149]) by mail.messagingengine.com (Postfix) with ESMTPA id CBECED6005B; Thu, 22 Aug 2019 16:18:59 -0400 (EDT) From: Pedro Vanzella To: linux-input@vger.kernel.org Cc: lains@archlinux.org, Pedro Vanzella , Jiri Kosina , Benjamin Tissoires , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] hid-logitech-hidpp: add quirk to handle battery voltage Date: Thu, 22 Aug 2019 16:18:45 -0400 Message-Id: <20190822201849.28924-2-pedro@pedrovanzella.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822201849.28924-1-pedro@pedrovanzella.com> References: <20190822201849.28924-1-pedro@pedrovanzella.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This quirk allows us to pick which devices support the 0x1001 hidpp feature to read the battery voltage. Signed-off-by: Pedro Vanzella --- drivers/hid/hid-logitech-hidpp.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 0179f7ed77e5..402ddba93adc 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -59,7 +59,8 @@ MODULE_PARM_DESC(disable_tap_to_click, #define HIDPP_QUIRK_CLASS_G920 BIT(3) #define HIDPP_QUIRK_CLASS_K750 BIT(4) -/* bits 2..20 are reserved for classes */ +/* bits 2..1f are reserved for classes */ +#define HIDPP_QUIRK_BATTERY_VOLTAGE_X1001 BIT(20) /* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */ #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22) #define HIDPP_QUIRK_NO_HIDINPUT BIT(23) @@ -3732,6 +3733,13 @@ static const struct hid_device_id hidpp_devices[] = { LDJ_DEVICE(0xb30b), .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS }, + { /* Logitech G403 Gaming Mouse over Lightspeed */ + LDJ_DEVICE(0x405d), + .driver_data = HIDPP_QUIRK_BATTERY_VOLTAGE_X1001 }, + { /* Logitech G900 Gaming Mouse over Lightspeed */ + LDJ_DEVICE(0x4053), + .driver_data = HIDPP_QUIRK_BATTERY_VOLTAGE_X1001 }, + { LDJ_DEVICE(HID_ANY_ID) }, { /* Keyboard LX501 (Y-RR53) */ @@ -3750,13 +3758,15 @@ static const struct hid_device_id hidpp_devices[] = { { L27MHZ_DEVICE(HID_ANY_ID) }, { /* Logitech G403 Wireless Gaming Mouse over USB */ - HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC082) }, + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC082), + .driver_data = HIDPP_QUIRK_BATTERY_VOLTAGE_X1001 }, { /* Logitech G703 Gaming Mouse over USB */ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC087) }, { /* Logitech G703 Hero Gaming Mouse over USB */ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC090) }, { /* Logitech G900 Gaming Mouse over USB */ - HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC081) }, + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC081), + .driver_data = HIDPP_QUIRK_BATTERY_VOLTAGE_X1001 }, { /* Logitech G903 Gaming Mouse over USB */ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC086) }, { /* Logitech G903 Hero Gaming Mouse over USB */ From patchwork Thu Aug 22 20:18:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Vanzella X-Patchwork-Id: 11110067 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAF9614DE for ; Thu, 22 Aug 2019 20:19:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7F14C23401 for ; Thu, 22 Aug 2019 20:19:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pedrovanzella.com header.i=@pedrovanzella.com header.b="LR1heJJ6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="W357AqkZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392883AbfHVUTC (ORCPT ); Thu, 22 Aug 2019 16:19:02 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:43823 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391015AbfHVUTB (ORCPT ); Thu, 22 Aug 2019 16:19:01 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 0901C21785; Thu, 22 Aug 2019 16:19:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 22 Aug 2019 16:19:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= pedrovanzella.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=fm3; bh=qkfXD75N/WbVbWSZPQ2M/eiRK0PmPJET2OhfHsAzWVk=; b=LR1he JJ6T/Op3zCVqhd06cp44GaLC3CkMYAjYhF0GU5zk+TYynbbsnGEVV6vpozitbCOl q9hXchBqzJ0OEqiNENSLKsVLpaQQ7dNPt2bzI2IGgxGIZDVl0joZ5Q2lw7zYBYCh d8nruZ+OSdYZSr31VqSI2H6EbOPqjLmPpTH5Uxf/bFZgSwkDCAbZYhxJpnFtITkm JwlSdLI0ymczggty4DnJ6CZry3Rv5PKjIp2G5+7JwWusu7sDa2YpwbqtyYQYSWp2 BwBCvVEpL45waHEt0/3Sk86TRdP5cfOvHxNweKKOdxa/BmdMMtFOo01xNwJN8ofc GI90GMbvGQI0X24Dw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=qkfXD75N/WbVbWSZPQ2M/eiRK0PmPJET2OhfHsAzWVk=; b=W357AqkZ MvZnz89PYjnZQFIEf20jYNb954c4aJOseJYbGX3Xcubk2l/RyAit3nhjddDG9M1W c2xLjcTnQKGj+HJzYe7I+5CnAXxcSv5Yy0UyDWgfOL0oHYBChNaUJmfbWutYyxd3 Nbgrd8+Wgo/eLPhiUDWFFytq3sjGSsJGor/3NpAMUrlPPAfg030TqiOltT3XwiQd f7dCP9R4imNPxwqKJwK6riLl1iLwxPv3X2zIvy3O9PmuCKpSCsCEpkiKRIruKgTj VJzAh2/vfWtihXX+8lHOcci06ZZkThzeI8vozKwTPfEdTYITMir7NwvA5uqMdrYX M3vtanV/PHPOQg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudegiedguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomheprfgvughr ohcugggrnhiivghllhgruceophgvughrohesphgvughrohhvrghniigvlhhlrgdrtghomh eqnecukfhppedujeegrdekkedrledrudegleenucfrrghrrghmpehmrghilhhfrhhomhep phgvughrohesphgvughrohhvrghniigvlhhlrgdrtghomhenucevlhhushhtvghrufhiii gvpedt X-ME-Proxy: Received: from localhost (toroon020aw-lp130-07-174-88-9-149.dsl.bell.ca [174.88.9.149]) by mail.messagingengine.com (Postfix) with ESMTPA id 85F5F80059; Thu, 22 Aug 2019 16:19:00 -0400 (EDT) From: Pedro Vanzella To: linux-input@vger.kernel.org Cc: lains@archlinux.org, Pedro Vanzella , Jiri Kosina , Benjamin Tissoires , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/4] hid-logitech-hidpp: add function to query battery voltage Date: Thu, 22 Aug 2019 16:18:46 -0400 Message-Id: <20190822201849.28924-3-pedro@pedrovanzella.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822201849.28924-1-pedro@pedrovanzella.com> References: <20190822201849.28924-1-pedro@pedrovanzella.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org When the device is brought up, if it's one of the devices we know supports battery voltage checking, figure out the feature index and get the battery voltage and status. If everything went correctly, record the fact that we're capable of querying battery voltage. Signed-off-by: Pedro Vanzella --- drivers/hid/hid-logitech-hidpp.c | 95 ++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 402ddba93adc..e1ddc9cdcc8b 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -88,6 +88,7 @@ MODULE_PARM_DESC(disable_tap_to_click, #define HIDPP_CAPABILITY_HIDPP20_BATTERY BIT(1) #define HIDPP_CAPABILITY_BATTERY_MILEAGE BIT(2) #define HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS BIT(3) +#define HIDPP_CAPABILITY_BATTERY_VOLTAGE BIT(4) /* * There are two hidpp protocols in use, the first version hidpp10 is known @@ -136,12 +137,14 @@ struct hidpp_report { struct hidpp_battery { u8 feature_index; u8 solar_feature_index; + u8 voltage_feature_index; struct power_supply_desc desc; struct power_supply *ps; char name[64]; int status; int capacity; int level; + int voltage; /* in millivolts */ bool online; }; @@ -1220,6 +1223,93 @@ static int hidpp20_battery_event(struct hidpp_device *hidpp, return 0; } +/* -------------------------------------------------------------------------- */ +/* 0x1001: Battery voltage */ +/* -------------------------------------------------------------------------- */ + +#define HIDPP_PAGE_BATTERY_VOLTAGE 0x1001 + +#define CMD_BATTERY_VOLTAGE_GET_BATTERY_VOLTAGE 0x00 + +static int hidpp20_battery_map_status_voltage(u8 data[3], int *voltage) +{ + int status; + + switch (data[2]) { + case 0x00: /* discharging */ + status = POWER_SUPPLY_STATUS_DISCHARGING; + break; + case 0x10: /* wireless charging */ + case 0x80: /* charging */ + status = POWER_SUPPLY_STATUS_CHARGING; + break; + case 0x81: /* fully charged */ + status = POWER_SUPPLY_STATUS_FULL; + break; + default: + status = POWER_SUPPLY_STATUS_NOT_CHARGING; + } + + *voltage = (data[0] << 8) + data[1]; + + return status; +} + +static int hidpp20_battery_get_battery_voltage(struct hidpp_device *hidpp, + u8 feature_index, + int *status, int *voltage) +{ + struct hidpp_report response; + int ret; + u8 *params = (u8 *)response.fap.params; + + ret = hidpp_send_fap_command_sync(hidpp, feature_index, + CMD_BATTERY_VOLTAGE_GET_BATTERY_VOLTAGE, + NULL, 0, &response); + + if (ret > 0) { + hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", + __func__, ret); + return -EPROTO; + } + if (ret) + return ret; + + hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_VOLTAGE; + + *status = hidpp20_battery_map_status_voltage(params, voltage); + + return 0; +} + +static int hidpp20_query_battery_voltage_info(struct hidpp_device *hidpp) +{ + u8 feature_type; + int ret; + int status, voltage; + + if (hidpp->battery.voltage_feature_index == 0xff) { + ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_BATTERY_VOLTAGE, + &hidpp->battery.voltage_feature_index, + &feature_type); + if (ret) + return ret; + } + + ret = hidpp20_battery_get_battery_voltage(hidpp, + hidpp->battery.voltage_feature_index, + &status, &voltage); + + if (ret) + return ret; + + hidpp->battery.status = status; + hidpp->battery.voltage = voltage; + hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING; + + return 0; +} + static enum power_supply_property hidpp_battery_props[] = { POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_STATUS, @@ -3205,10 +3295,13 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp) hidpp->battery.feature_index = 0xff; hidpp->battery.solar_feature_index = 0xff; + hidpp->battery.voltage_feature_index = 0xff; if (hidpp->protocol_major >= 2) { if (hidpp->quirks & HIDPP_QUIRK_CLASS_K750) ret = hidpp_solar_request_battery_event(hidpp); + else if (hidpp->quirks & HIDPP_QUIRK_BATTERY_VOLTAGE_X1001) + ret = hidpp20_query_battery_voltage_info(hidpp); else ret = hidpp20_query_battery_info(hidpp); @@ -3409,6 +3502,8 @@ static void hidpp_connect_event(struct hidpp_device *hidpp) hidpp10_query_battery_status(hidpp); } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { hidpp20_query_battery_info(hidpp); + if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE) + hidpp20_query_battery_voltage_info(hidpp); } if (hidpp->battery.ps) power_supply_changed(hidpp->battery.ps); From patchwork Thu Aug 22 20:18:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Vanzella X-Patchwork-Id: 11110071 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B8C514DE for ; Thu, 22 Aug 2019 20:19:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78D9920856 for ; Thu, 22 Aug 2019 20:19:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pedrovanzella.com header.i=@pedrovanzella.com header.b="p4BMh2MM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GdAAh8cT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393087AbfHVUT1 (ORCPT ); Thu, 22 Aug 2019 16:19:27 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:53003 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387441AbfHVUTC (ORCPT ); Thu, 22 Aug 2019 16:19:02 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id A7E1321B6A; Thu, 22 Aug 2019 16:19:01 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 22 Aug 2019 16:19:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= pedrovanzella.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=fm3; bh=4AYGKsZjK6lV5gVZkcpia3kXkgKi2R2J1lgMhrGMRvc=; b=p4BMh 2MMNJIF/anLj+ZlvOJhAzBVaGZWA9Uft4lN3TnfBJN6ZgSvvxYjRL8XmNw2Qsh/y kVSNQN8ELNHscjr5y4vQGbfwX0VDUqO7qagd8TVzyJKfV+fVHPxtPxQnfp9bgNXY AJDXwnJ+rFf9IAo7qaPHj6z9SN+fa/xeFpgb8xhr5i/Yo3MeCLrxVY4RNK9+1p9T xC2OrffkDrLc+cHiYvEEZNsO2HoBFBSP73BnLwQIZjU2nJrgfbAWqQcHy1AS9nIp 1+RiFU8/zp87xYhso4ObJJvBONGiQRH7k9DxU6TgGu9VMaNGqc9J/YevY/n/DZnD JkUI8SJpnRz0K4CFw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=4AYGKsZjK6lV5gVZkcpia3kXkgKi2R2J1lgMhrGMRvc=; b=GdAAh8cT emhjM0Lw+E1yCOOYtIrz1PUPgGl7f2gEfrMDlpw0lz9zjcNwjoa2A22Fi7W2mXr3 mdy9UaxWBPojhwASRUwVH6rJwsztCL6d5f6INbi3beXLgEzO+AVmLVl+LKhrnCiy WYaQz3nlbsBjls5MOkAI6uqaf22wmDC62qlyXcrZ9FM5Z+l1KZz4pe7r2LI7tMrr Hyrd5SFceA4rI1bMW8IAguvxBCZfCKAgOaMp5cdCGoflQ7vj7nB4+G7++z8mj+Zv wnRnTUSBrquWnfBcNxt6UXv9DnNUiKW8Rudr/6zwqobG/HDDIWODI0a12tuuZTCu 8lepU19F+AQSmQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudegiedguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomheprfgvughr ohcugggrnhiivghllhgruceophgvughrohesphgvughrohhvrghniigvlhhlrgdrtghomh eqnecukfhppedujeegrdekkedrledrudegleenucfrrghrrghmpehmrghilhhfrhhomhep phgvughrohesphgvughrohhvrghniigvlhhlrgdrtghomhenucevlhhushhtvghrufhiii gvpedt X-ME-Proxy: Received: from localhost (toroon020aw-lp130-07-174-88-9-149.dsl.bell.ca [174.88.9.149]) by mail.messagingengine.com (Postfix) with ESMTPA id 44C7AD6005B; Thu, 22 Aug 2019 16:19:01 -0400 (EDT) From: Pedro Vanzella To: linux-input@vger.kernel.org Cc: lains@archlinux.org, Pedro Vanzella , Jiri Kosina , Benjamin Tissoires , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] hid-logitech-hidpp: report battery voltage to the power supply Date: Thu, 22 Aug 2019 16:18:47 -0400 Message-Id: <20190822201849.28924-4-pedro@pedrovanzella.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822201849.28924-1-pedro@pedrovanzella.com> References: <20190822201849.28924-1-pedro@pedrovanzella.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org If we know the device supports reading its voltage, report that. Note that the protocol only gives us the current voltage in millivolts. Signed-off-by: Pedro Vanzella --- drivers/hid/hid-logitech-hidpp.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index e1ddc9cdcc8b..06bee97d33b4 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -1319,6 +1319,7 @@ static enum power_supply_property hidpp_battery_props[] = { POWER_SUPPLY_PROP_SERIAL_NUMBER, 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY, */ 0, /* placeholder for POWER_SUPPLY_PROP_CAPACITY_LEVEL, */ + 0, /* placeholder for POWER_SUPPLY_PROP_VOLTAGE_NOW, */ }; static int hidpp_battery_get_property(struct power_supply *psy, @@ -1356,6 +1357,9 @@ static int hidpp_battery_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_SERIAL_NUMBER: val->strval = hidpp->hid_dev->uniq; break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + val->intval = hidpp->battery.voltage; + break; default: ret = -EINVAL; break; @@ -3328,7 +3332,7 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp) if (!battery_props) return -ENOMEM; - num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 2; + num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 3; if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE) battery_props[num_battery_props++] = @@ -3338,6 +3342,10 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp) battery_props[num_battery_props++] = POWER_SUPPLY_PROP_CAPACITY_LEVEL; + if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE) + battery_props[num_battery_props++] = + POWER_SUPPLY_PROP_VOLTAGE_NOW; + battery = &hidpp->battery; n = atomic_inc_return(&battery_no) - 1; From patchwork Thu Aug 22 20:18:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Vanzella X-Patchwork-Id: 11110069 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02D4914DB for ; Thu, 22 Aug 2019 20:19:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D523B20856 for ; Thu, 22 Aug 2019 20:19:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pedrovanzella.com header.i=@pedrovanzella.com header.b="ljLXxfEE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="P3m3D40b" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393015AbfHVUTP (ORCPT ); Thu, 22 Aug 2019 16:19:15 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:47373 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392859AbfHVUTD (ORCPT ); Thu, 22 Aug 2019 16:19:03 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5DC2F21F4C; Thu, 22 Aug 2019 16:19:02 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 22 Aug 2019 16:19:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= pedrovanzella.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=fm3; bh=dJnrPuaV25ABykzS4FLNIsBUys6IgKfAK34wtssm9ns=; b=ljLXx fEEMW22wAPO67cdymHSP1ujN73zY9csukL3ZPBLtgNjFmIOkSlkaTPoJqcpgHmGw uHlp5PwUmloNJWR8amT2eIa/KTbtcSsmHYPSUJiyZFPJALPz6Vj3k5jaxWB3qFNH IPtG/s9/IvQU59rshFpJDpxTAIIXyJcNFE4XtD0BVrqOlpRFJD0Zu7hPFpJZ2g5a KNYaBK5yiwYXqrQQdrPmfQyBdXhD4Hw8oEZpx/aEnXCZH9l8YziUED+2YmF/bOFz amBiW/Jf2ybhKVZWXb6KU0W+k6Lbj2BI9xkKWUrCwVDpvSLFVvDAjKmYiyiKDUYN hS5zzglzziKlndVqw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=dJnrPuaV25ABykzS4FLNIsBUys6IgKfAK34wtssm9ns=; b=P3m3D40b uZw9fNhdPu+G1c911m0LD78EN+vfLnvOlQ/QZEA+EXzSFr3pWKZQ0E4uH7ZggnLS tY7CBxR0cEqXVuVbWAVvTF9hS+oSDEBE3w/paTq5oy1Fpl/ipoTTvAlvXKZINBdX UUAtwqzpAKIRgL+pi9SIZSTXvJ/FJFzxEPx7wlaeCLITsT44X4X3pYuqDxUcTn8U m8OmVRMIrrsHH6tgQ9db7qrwIGwO+zmmvt2bY/vQBXOtv7uxw5IF0efXnN0G5c+U TxWE/NGHCPtImXdiO9gGGKzbhyAfQ5KYcBAZRuI7ooxtZAyYa8YSbMLwN+4loYKl iPP19lRYLE7K4A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudegiedguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomheprfgvughr ohcugggrnhiivghllhgruceophgvughrohesphgvughrohhvrghniigvlhhlrgdrtghomh eqnecukfhppedujeegrdekkedrledrudegleenucfrrghrrghmpehmrghilhhfrhhomhep phgvughrohesphgvughrohhvrghniigvlhhlrgdrtghomhenucevlhhushhtvghrufhiii gvpedt X-ME-Proxy: Received: from localhost (toroon020aw-lp130-07-174-88-9-149.dsl.bell.ca [174.88.9.149]) by mail.messagingengine.com (Postfix) with ESMTPA id E8A768005B; Thu, 22 Aug 2019 16:19:01 -0400 (EDT) From: Pedro Vanzella To: linux-input@vger.kernel.org Cc: lains@archlinux.org, Pedro Vanzella , Jiri Kosina , Benjamin Tissoires , linux-kernel@vger.kernel.org Subject: [PATCH v3 4/4] hid-logitech-hidpp: subscribe to battery voltage events Date: Thu, 22 Aug 2019 16:18:48 -0400 Message-Id: <20190822201849.28924-5-pedro@pedrovanzella.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822201849.28924-1-pedro@pedrovanzella.com> References: <20190822201849.28924-1-pedro@pedrovanzella.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Like we do for other ways of interacting with the battery for other devices, refresh the battery status and notify the power supply subsystem of the changes in voltage and status. Signed-off-by: Pedro Vanzella --- drivers/hid/hid-logitech-hidpp.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 06bee97d33b4..9f09ed6abbad 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -1310,6 +1310,35 @@ static int hidpp20_query_battery_voltage_info(struct hidpp_device *hidpp) return 0; } +static int hidpp20_battery_voltage_event(struct hidpp_device *hidpp, + u8 *data, int size) +{ + struct hidpp_report *report = (struct hidpp_report *)data; + int status, voltage; + bool changed; + + if (report->fap.feature_index != hidpp->battery.voltage_feature_index || + report->fap.funcindex_clientid != + EVENT_BATTERY_LEVEL_STATUS_BROADCAST) + return 0; + + status = hidpp20_battery_map_status_voltage(report->fap.params, + &voltage); + + hidpp->battery.online = status != POWER_SUPPLY_STATUS_NOT_CHARGING; + + changed = voltage != hidpp->battery.voltage || + status != hidpp->battery.status; + + if (changed) { + hidpp->battery.voltage = voltage; + hidpp->battery.status = status; + if (hidpp->battery.ps) + power_supply_changed(hidpp->battery.ps); + } + return 0; +} + static enum power_supply_property hidpp_battery_props[] = { POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_STATUS, @@ -3178,6 +3207,9 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data, ret = hidpp_solar_battery_event(hidpp, data, size); if (ret != 0) return ret; + ret = hidpp20_battery_voltage_event(hidpp, data, size); + if (ret != 0) + return ret; } if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP10_BATTERY) {