From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751601AbdAQOgi (ORCPT ); Tue, 17 Jan 2017 09:36:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54460 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751028AbdAQOg2 (ORCPT ); Tue, 17 Jan 2017 09:36:28 -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 10/17] HID: logitech-hidpp: notify battery on connect Date: Tue, 17 Jan 2017 15:35:40 +0100 Message-Id: <20170117143547.30488-11-benjamin.tissoires@redhat.com> In-Reply-To: <20170117143547.30488-1-benjamin.tissoires@redhat.com> References: <20170117143547.30488-1-benjamin.tissoires@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 17 Jan 2017 14:36:17 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a device reconnects, there is a high chance its power supply has been changed (for a battery replacement for instance). Just forward the battery state here. Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-logitech-hidpp.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 1fd95c2..3ae2f41 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -2557,9 +2557,6 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp) return ret; hidpp->quirks |= HIDPP_QUIRK_HIDPP20_BATTERY; } else { - ret = hidpp10_enable_battery_reporting(hidpp); - if (ret) - return -ENOENT; ret = hidpp10_query_battery_status(hidpp); if (ret) { ret = hidpp10_query_battery_mileage(hidpp); @@ -2693,6 +2690,17 @@ static void hidpp_connect_event(struct hidpp_device *hidpp) hidpp_initialize_battery(hidpp); + /* forward current battery state */ + if (hidpp->quirks & HIDPP_QUIRK_HIDPP10_BATTERY) { + hidpp10_enable_battery_reporting(hidpp); + hidpp10_query_battery_status(hidpp); + hidpp10_query_battery_mileage(hidpp); + } else if (hidpp->quirks & HIDPP_QUIRK_HIDPP20_BATTERY) { + hidpp20_query_battery_info(hidpp); + } + if (hidpp->battery.ps) + power_supply_changed(hidpp->battery.ps); + if (!(hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT)) /* if HID created the input nodes for us, we can stop now */ return; -- 2.9.3